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