qscatterseries.cpp
207 lines
| 4.6 KiB
| text/x-c
|
CppLexer
Tero Ahola
|
r42 | #include "qscatterseries.h" | ||
Tero Ahola
|
r194 | #include "scatterseries_p.h" | ||
Tero Ahola
|
r42 | #include "qchart.h" | ||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Tero Ahola
|
r158 | QScatterSeriesPrivate::QScatterSeriesPrivate() : | ||
Tero Ahola
|
r195 | m_data(QList<QPointF>()), | ||
m_markerPen(QPen()), | ||||
m_markerBrush(QBrush()), | ||||
m_markerShape(QScatterSeries::MarkerShapeDefault) | ||||
Tero Ahola
|
r42 | { | ||
Tero Ahola
|
r195 | // Initialize pen color to invalid to use a theme color by default | ||
m_markerPen.setColor(QColor::Invalid); | ||||
m_markerBrush.setColor(QColor::Invalid); | ||||
Tero Ahola
|
r42 | } | ||
Tero Ahola
|
r261 | /*! | ||
\enum QScatterSeries::MarkerShape | ||||
This enum describes the shape used when rendering marker items. | ||||
\value MarkerShapeDefault | ||||
\value MarkerShapePoint | ||||
\value MarkerShapeX | ||||
\value MarkerShapeRectangle | ||||
\value MarkerShapeTiltedRectangle | ||||
\value MarkerShapeTriangle | ||||
\value MarkerShapeCircle | ||||
*/ | ||||
Tero Ahola
|
r260 | /*! | ||
\class QScatterSeries | ||||
\brief QtCommercial Chart series API for showing scatter series. | ||||
Example on how to create a chart with scatter series: | ||||
\code | ||||
#include <qchartglobal.h> | ||||
#include <qchartview.h> | ||||
#include <qscatterseries.h> | ||||
... | ||||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
// Create chart widget | ||||
QChartView *chartView = new QChartView(); | ||||
QScatterSeries *scatter = new QScatterSeries(); | ||||
*scatter << QPointF(0.5, 5.0) << QPointF(1.0, 4.5) << QPointF(1.0, 5.5) << QPointF(1.5, 5.0); | ||||
chartView->addSeries(scatter); | ||||
// Then add the QChartView into a layout... | ||||
\endcode | ||||
The example code would result the following: | ||||
\image scatter_example1.jpg | ||||
*/ | ||||
Tero Ahola
|
r261 | |||
/*! | ||||
Constructs a series object which is a child of \a parent. | ||||
*/ | ||||
Tero Ahola
|
r158 | QScatterSeries::QScatterSeries(QObject *parent) : | ||
QChartSeries(parent), | ||||
d(new QScatterSeriesPrivate()) | ||||
Tero Ahola
|
r42 | { | ||
} | ||||
Tero Ahola
|
r260 | /*! | ||
Tero Ahola
|
r261 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. | ||
Tero Ahola
|
r260 | */ | ||
Tero Ahola
|
r158 | QScatterSeries::~QScatterSeries() | ||
Tero Ahola
|
r42 | { | ||
Tero Ahola
|
r158 | delete d; | ||
Tero Ahola
|
r48 | } | ||
Tero Ahola
|
r260 | /*! | ||
Add single data point to the series. | ||||
Tero Ahola
|
r261 | For example: | ||
\code | ||||
mySeries.addData(QPointF(0.5, 5.0)); | ||||
\endcode | ||||
Tero Ahola
|
r260 | */ | ||
Tero Ahola
|
r180 | void QScatterSeries::addData(QPointF value) | ||
Tero Ahola
|
r61 | { | ||
Tero Ahola
|
r180 | d->m_data.append(value); | ||
emit changed(); | ||||
} | ||||
Tero Ahola
|
r260 | /*! | ||
Stream operator for adding a data point to the series. | ||||
\sa addData(), QScatterSeries::addData(QPointF value) | ||||
For example: | ||||
\code | ||||
mySeries << QPointF(0.5, 5.0) | ||||
<< QPointF(1.0, 4.5); | ||||
\endcode | ||||
*/ | ||||
Tero Ahola
|
r180 | QScatterSeries& QScatterSeries::operator << (const QPointF &value) | ||
{ | ||||
d->m_data.append(value); | ||||
Tero Ahola
|
r179 | emit changed(); | ||
Tero Ahola
|
r180 | return *this; | ||
Tero Ahola
|
r179 | } | ||
Tero Ahola
|
r158 | |||
Tero Ahola
|
r260 | /*! | ||
Replaces the data of the series with the given list of data points. | ||||
*/ | ||||
Tero Ahola
|
r180 | void QScatterSeries::setData(QList<QPointF> data) | ||
Tero Ahola
|
r179 | { | ||
Tero Ahola
|
r180 | d->m_data = data; | ||
Tero Ahola
|
r158 | emit changed(); | ||
Tero Ahola
|
r61 | } | ||
Tero Ahola
|
r260 | /*! | ||
Tero Ahola
|
r261 | Returns the current list of data points of the series. | ||
Tero Ahola
|
r260 | */ | ||
Tero Ahola
|
r158 | QList<QPointF> QScatterSeries::data() | ||
Tero Ahola
|
r64 | { | ||
Tero Ahola
|
r158 | return d->m_data; | ||
Tero Ahola
|
r64 | } | ||
Tero Ahola
|
r260 | /*! | ||
Tero Ahola
|
r261 | Overrides the default pen used for drawing a marker item with a user defined pen. The default | ||
pen is defined by chart theme setting. | ||||
For example: | ||||
\code | ||||
QPen pen(QColor(0, 255, 0, 80), 3); | ||||
myScatter->setMarkerPen(pen); | ||||
\endcode | ||||
Would present your scatter markers with an opaque, uglyish green outlines: | ||||
\image scatter_example_pen.jpg | ||||
\sa setMarkerBrush() | ||||
\sa QChart::setTheme() | ||||
Tero Ahola
|
r260 | */ | ||
Tero Ahola
|
r179 | void QScatterSeries::setMarkerPen(QPen pen) | ||
Tero Ahola
|
r75 | { | ||
Tero Ahola
|
r179 | d->m_markerPen = pen; | ||
Tero Ahola
|
r75 | } | ||
Tero Ahola
|
r260 | /*! | ||
Tero Ahola
|
r261 | Returns the pen used for drawing markers. | ||
Tero Ahola
|
r260 | */ | ||
Tero Ahola
|
r179 | QPen QScatterSeries::markerPen() | ||
Tero Ahola
|
r42 | { | ||
Tero Ahola
|
r179 | return d->m_markerPen; | ||
Tero Ahola
|
r42 | } | ||
Tero Ahola
|
r261 | /*! | ||
Overrides the default brush of the marker items with a user defined brush. The default | ||||
brush is defined by chart theme setting. | ||||
For example: | ||||
\code | ||||
QBrush brush(QColor(255, 0, 0, 100), Qt::SolidPattern); | ||||
myRandomScatter->setMarkerBrush(brush); | ||||
\endcode | ||||
Would fill your scatter markers with an opaque red color: | ||||
\image scatter_example_brush.jpg | ||||
\sa setMarkerPen() | ||||
\sa QChart::setTheme() | ||||
*/ | ||||
Tero Ahola
|
r195 | void QScatterSeries::setMarkerBrush(QBrush brush) | ||
{ | ||||
d->m_markerBrush = brush; | ||||
} | ||||
Tero Ahola
|
r261 | /*! | ||
Returns the brush used for drawing markers. | ||||
*/ | ||||
Tero Ahola
|
r195 | QBrush QScatterSeries::markerBrush() | ||
{ | ||||
return d->m_markerBrush; | ||||
} | ||||
Tero Ahola
|
r261 | /*! | ||
Overrides the default shape of the marker items with a user defined shape. The default | ||||
shape is defined by chart theme setting. | ||||
For example: | ||||
\code | ||||
myScatter->setMarkerShape(QScatterSeries::MarkerShapeRectangle); | ||||
\endcode | ||||
Would make your scatter marker items rectangle: | ||||
\image scatter_example_shape.jpg | ||||
*/ | ||||
Tero Ahola
|
r195 | void QScatterSeries::setMarkerShape(MarkerShape shape) | ||
{ | ||||
d->m_markerShape = shape; | ||||
} | ||||
Tero Ahola
|
r261 | /*! | ||
Returns the shape used for drawing markers. | ||||
*/ | ||||
Tero Ahola
|
r195 | QScatterSeries::MarkerShape QScatterSeries::markerShape() | ||
{ | ||||
return (QScatterSeries::MarkerShape) d->m_markerShape; | ||||
} | ||||
Tero Ahola
|
r42 | #include "moc_qscatterseries.cpp" | ||
QTCOMMERCIALCHART_END_NAMESPACE | ||||