##// END OF EJS Templates
Scatterseries docs update
Marek Rosa -
r1651:03f0dcabe652
parent child
Show More
@@ -1,254 +1,264
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qscatterseries.h"
21 #include "qscatterseries.h"
22 #include "qscatterseries_p.h"
22 #include "qscatterseries_p.h"
23 #include "scatterchartitem_p.h"
23 #include "scatterchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28 /*!
28 /*!
29 \class QScatterSeries
29 \class QScatterSeries
30 \brief The QScatterSeries class is used for making scatter charts.
30 \brief The QScatterSeries class is used for making scatter charts.
31
31
32 \mainclass
32 \mainclass
33
33
34 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
34 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
35 and the vertical axis.
35 and the vertical axis.
36
36
37 \image examples_scatterchart.png
37 \image examples_scatterchart.png
38
38
39 Creating basic scatter chart is simple:
39 Creating basic scatter chart is simple:
40 \code
40 \code
41 QScatterSeries* series = new QScatterSeries();
41 QScatterSeries* series = new QScatterSeries();
42 series->append(0, 6);
42 series->append(0, 6);
43 series->append(2, 4);
43 series->append(2, 4);
44 ...
44 ...
45 chart->addSeries(series);
45 chart->addSeries(series);
46 \endcode
46 \endcode
47 */
47 */
48 /*!
48 /*!
49 \qmlclass ScatterSeries QScatterSeries
49 \qmlclass ScatterSeries QScatterSeries
50 \inherits XYSeries
50 \inherits XYSeries
51
51
52 The following QML shows how to create a chart with two simple scatter series:
52 The following QML shows how to create a chart with two simple scatter series:
53 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
53 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
54 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 2
54 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 2
55
55
56 \beginfloatleft
56 \beginfloatleft
57 \image demos_qmlchart5.png
57 \image demos_qmlchart5.png
58 \endfloat
58 \endfloat
59 \clearfloat
59 \clearfloat
60 */
60 */
61
61
62 /*!
62 /*!
63 \enum QScatterSeries::MarkerShape
63 \enum QScatterSeries::MarkerShape
64
64
65 This enum describes the shape used when rendering marker items.
65 This enum describes the shape used when rendering marker items.
66
66
67 \value MarkerShapeCircle
67 \value MarkerShapeCircle
68 \value MarkerShapeRectangle
68 \value MarkerShapeRectangle
69 */
69 */
70
70
71 /*!
71 /*!
72 \property QScatterSeries::color
72 \property QScatterSeries::color
73 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
73 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
74 \sa QScatterSeries::brush()
74 \sa QScatterSeries::brush()
75 */
75 */
76
76
77 /*!
77 /*!
78 \property QScatterSeries::borderColor
78 \property QScatterSeries::borderColor
79 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
79 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
80 \sa QScatterSeries::pen()
80 \sa QScatterSeries::pen()
81 */
81 */
82
82
83 /*!
83 /*!
84 \property QScatterSeries::markerShape
84 \property QScatterSeries::markerShape
85 Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle.
85 Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle.
86 */
86 */
87 /*!
87 /*!
88 \qmlproperty MarkerShape ScatterSeries::markerShape
88 \qmlproperty MarkerShape ScatterSeries::markerShape
89 Defines the shape of the marker used to draw the points in the series. One of ScatterSeries
89 Defines the shape of the marker used to draw the points in the series. One of ScatterSeries
90 ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle.
90 ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle.
91 The default shape is ScatterSeries.MarkerShapeCircle.
91 The default shape is ScatterSeries.MarkerShapeCircle.
92 */
92 */
93
93
94 /*!
94 /*!
95 \property QScatterSeries::markerSize
95 \property QScatterSeries::markerSize
96 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
96 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
97 */
97 */
98 /*!
98 /*!
99 \qmlproperty real ScatterSeries::markerSize
99 \qmlproperty real ScatterSeries::markerSize
100 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
100 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
101 */
101 */
102
102
103 /*!
103 /*!
104 \fn void QScatterSeries::colorChanged(QColor color)
104 \fn void QScatterSeries::colorChanged(QColor color)
105 Signal is emitted when the fill (brush) color has changed to \a color.
105 Signal is emitted when the fill (brush) color has changed to \a color.
106 */
106 */
107
107
108 /*!
108 /*!
109 \fn void QScatterSeries::borderColorChanged(QColor color)
109 \fn void QScatterSeries::borderColorChanged(QColor color)
110 Signal is emitted when the line (pen) color has changed to \a color.
110 Signal is emitted when the line (pen) color has changed to \a color.
111 */
111 */
112 /*!
112 /*!
113 \qmlsignal ScatterSeries::borderColorChanged(color color)
113 \qmlsignal ScatterSeries::borderColorChanged(color color)
114 Signal is emitted when the line (pen) color has changed to \a color.
114 Signal is emitted when the line (pen) color has changed to \a color.
115 */
115 */
116
116
117 /*!
117 /*!
118 \fn QChartSeriesType QScatterSeries::type() const
118 \fn QChartSeriesType QScatterSeries::type() const
119 Returns QChartSeries::SeriesTypeScatter.
119 Returns QChartSeries::SeriesTypeScatter.
120 \sa QAbstractSeries, SeriesType
120 \sa QAbstractSeries, SeriesType
121 */
121 */
122
122
123 QTCOMMERCIALCHART_BEGIN_NAMESPACE
123 QTCOMMERCIALCHART_BEGIN_NAMESPACE
124
124
125 /*!
125 /*!
126 Constructs a series object which is a child of \a parent.
126 Constructs a series object which is a child of \a parent.
127 */
127 */
128 QScatterSeries::QScatterSeries(QObject *parent) : QXYSeries(*new QScatterSeriesPrivate(this),parent)
128 QScatterSeries::QScatterSeries(QObject *parent) : QXYSeries(*new QScatterSeriesPrivate(this),parent)
129 {
129 {
130 }
130 }
131
131
132 /*!
132 /*!
133 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
133 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
134 */
134 */
135 QScatterSeries::~QScatterSeries()
135 QScatterSeries::~QScatterSeries()
136 {
136 {
137 Q_D(QScatterSeries);
137 Q_D(QScatterSeries);
138 if(d->m_dataset) {
138 if(d->m_dataset) {
139 d->m_dataset->removeSeries(this);
139 d->m_dataset->removeSeries(this);
140 }
140 }
141 }
141 }
142
142
143 QAbstractSeries::SeriesType QScatterSeries::type() const
143 QAbstractSeries::SeriesType QScatterSeries::type() const
144 {
144 {
145 return QAbstractSeries::SeriesTypeScatter;
145 return QAbstractSeries::SeriesTypeScatter;
146 }
146 }
147
147
148 /*!
149 Sets \a pen used for drawing points' border on the chart. If the pen is not defined, the
150 pen from chart theme is used.
151 \sa QChart::setTheme()
152 */
148 void QScatterSeries::setPen(const QPen &pen)
153 void QScatterSeries::setPen(const QPen &pen)
149 {
154 {
150 Q_D(QXYSeries);
155 Q_D(QXYSeries);
151 if (d->m_pen != pen) {
156 if (d->m_pen != pen) {
152 bool emitColorChanged = d->m_pen.color() != pen.color();
157 bool emitColorChanged = d->m_pen.color() != pen.color();
153 d->m_pen = pen;
158 d->m_pen = pen;
154 emit d->updated();
159 emit d->updated();
155 if (emitColorChanged)
160 if (emitColorChanged)
156 emit borderColorChanged(pen.color());
161 emit borderColorChanged(pen.color());
157 }
162 }
158 }
163 }
159
164
165 /*!
166 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
167 from chart theme setting is used.
168 \sa QChart::setTheme()
169 */
160 void QScatterSeries::setBrush(const QBrush &brush)
170 void QScatterSeries::setBrush(const QBrush &brush)
161 {
171 {
162 Q_D(QScatterSeries);
172 Q_D(QScatterSeries);
163 if (d->m_brush != brush) {
173 if (d->m_brush != brush) {
164 bool emitColorChanged = d->m_brush.color() != brush.color();
174 bool emitColorChanged = d->m_brush.color() != brush.color();
165 d->m_brush = brush;
175 d->m_brush = brush;
166 emit d->updated();
176 emit d->updated();
167 if (emitColorChanged)
177 if (emitColorChanged)
168 emit colorChanged(brush.color());
178 emit colorChanged(brush.color());
169 }
179 }
170 }
180 }
171
181
172 void QScatterSeries::setColor(const QColor &color)
182 void QScatterSeries::setColor(const QColor &color)
173 {
183 {
174 QBrush b = brush();
184 QBrush b = brush();
175 if (b.color() != color) {
185 if (b.color() != color) {
176 b.setColor(color);
186 b.setColor(color);
177 setBrush(b);
187 setBrush(b);
178 }
188 }
179 }
189 }
180
190
181 QColor QScatterSeries::color() const
191 QColor QScatterSeries::color() const
182 {
192 {
183 return brush().color();
193 return brush().color();
184 }
194 }
185
195
186 void QScatterSeries::setBorderColor(const QColor &color)
196 void QScatterSeries::setBorderColor(const QColor &color)
187 {
197 {
188 QPen p = pen();
198 QPen p = pen();
189 if (p.color() != color) {
199 if (p.color() != color) {
190 p.setColor(color);
200 p.setColor(color);
191 setPen(p);
201 setPen(p);
192 }
202 }
193 }
203 }
194
204
195 QColor QScatterSeries::borderColor() const
205 QColor QScatterSeries::borderColor() const
196 {
206 {
197 return pen().color();
207 return pen().color();
198 }
208 }
199
209
200 QScatterSeries::MarkerShape QScatterSeries::markerShape() const
210 QScatterSeries::MarkerShape QScatterSeries::markerShape() const
201 {
211 {
202 Q_D(const QScatterSeries);
212 Q_D(const QScatterSeries);
203 return d->m_shape;
213 return d->m_shape;
204 }
214 }
205
215
206 void QScatterSeries::setMarkerShape(MarkerShape shape)
216 void QScatterSeries::setMarkerShape(MarkerShape shape)
207 {
217 {
208 Q_D(QScatterSeries);
218 Q_D(QScatterSeries);
209 if (d->m_shape != shape) {
219 if (d->m_shape != shape) {
210 d->m_shape = shape;
220 d->m_shape = shape;
211 emit d->updated();
221 emit d->updated();
212 }
222 }
213 }
223 }
214
224
215 qreal QScatterSeries::markerSize() const
225 qreal QScatterSeries::markerSize() const
216 {
226 {
217 Q_D(const QScatterSeries);
227 Q_D(const QScatterSeries);
218 return d->m_size;
228 return d->m_size;
219 }
229 }
220
230
221 void QScatterSeries::setMarkerSize(qreal size)
231 void QScatterSeries::setMarkerSize(qreal size)
222 {
232 {
223 Q_D(QScatterSeries);
233 Q_D(QScatterSeries);
224
234
225 if (!qFuzzyIsNull(d->m_size - size)) {
235 if (!qFuzzyIsNull(d->m_size - size)) {
226 d->m_size = size;
236 d->m_size = size;
227 emit d->updated();
237 emit d->updated();
228 }
238 }
229 }
239 }
230
240
231 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
241 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
232
242
233 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q) :
243 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q) :
234 QXYSeriesPrivate(q),
244 QXYSeriesPrivate(q),
235 m_shape(QScatterSeries::MarkerShapeCircle),
245 m_shape(QScatterSeries::MarkerShapeCircle),
236 m_size(15.0)
246 m_size(15.0)
237 {
247 {
238 }
248 }
239
249
240 Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter)
250 Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter)
241 {
251 {
242 Q_Q(QScatterSeries);
252 Q_Q(QScatterSeries);
243 ScatterChartItem *scatter = new ScatterChartItem(q,presenter);
253 ScatterChartItem *scatter = new ScatterChartItem(q,presenter);
244 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
254 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
245 scatter->setAnimator(presenter->animator());
255 scatter->setAnimator(presenter->animator());
246 scatter->setAnimation(new XYAnimation(scatter));
256 scatter->setAnimation(new XYAnimation(scatter));
247 }
257 }
248 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
258 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
249 return scatter;
259 return scatter;
250 }
260 }
251
261
252 #include "moc_qscatterseries.cpp"
262 #include "moc_qscatterseries.cpp"
253
263
254 QTCOMMERCIALCHART_END_NAMESPACE
264 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now