@@ -1,308 +1,310 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "scatteranimation_p.h" |
|
27 | 27 | #include "qchart_p.h" |
|
28 | 28 | |
|
29 | 29 | /*! |
|
30 | 30 | \class QScatterSeries |
|
31 | 31 | \inmodule Qt Charts |
|
32 | 32 | \brief The QScatterSeries class is used for making scatter charts. |
|
33 | 33 | |
|
34 | 34 | \mainclass |
|
35 | 35 | |
|
36 | 36 | The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis |
|
37 | 37 | and the vertical axis. |
|
38 | 38 | |
|
39 | 39 | \image examples_scatterchart.png |
|
40 | 40 | |
|
41 | 41 | Creating basic scatter chart is simple: |
|
42 | 42 | \code |
|
43 | 43 | QScatterSeries* series = new QScatterSeries(); |
|
44 | 44 | series->append(0, 6); |
|
45 | 45 | series->append(2, 4); |
|
46 | 46 | ... |
|
47 | 47 | chart->addSeries(series); |
|
48 | 48 | \endcode |
|
49 | 49 | */ |
|
50 | 50 | #ifdef QDOC_QT5 |
|
51 | 51 | /*! |
|
52 | 52 | \qmltype ScatterSeries |
|
53 | 53 | \instantiates QScatterSeries |
|
54 | 54 | \inqmlmodule QtCommercial.Chart |
|
55 | 55 | |
|
56 | 56 | \include doc/src/scatterseries.qdocinc |
|
57 | 57 | */ |
|
58 | 58 | #else |
|
59 | 59 | /*! |
|
60 | 60 | \qmlclass ScatterSeries QScatterSeries |
|
61 | 61 | |
|
62 | 62 | \include ../doc/src/scatterseries.qdocinc |
|
63 | 63 | */ |
|
64 | 64 | #endif |
|
65 | 65 | |
|
66 | 66 | /*! |
|
67 | 67 | \enum QScatterSeries::MarkerShape |
|
68 | 68 | |
|
69 | 69 | This enum describes the shape used when rendering marker items. |
|
70 | 70 | |
|
71 | 71 | \value MarkerShapeCircle |
|
72 | 72 | \value MarkerShapeRectangle |
|
73 | 73 | */ |
|
74 | 74 | |
|
75 | 75 | /*! |
|
76 | 76 | \property QScatterSeries::color |
|
77 | 77 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. |
|
78 | 78 | \sa QScatterSeries::brush() |
|
79 | 79 | */ |
|
80 | 80 | |
|
81 | 81 | /*! |
|
82 | 82 | \property QScatterSeries::borderColor |
|
83 | 83 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. |
|
84 | 84 | \sa QScatterSeries::pen() |
|
85 | 85 | */ |
|
86 | 86 | /*! |
|
87 | 87 | \qmlproperty color ScatterSeries::borderColor |
|
88 | 88 | Border (pen) color of the series. |
|
89 | 89 | */ |
|
90 | 90 | |
|
91 | 91 | /*! |
|
92 | 92 | \qmlproperty real ScatterSeries::borderWidth |
|
93 | 93 | The width of the border line. By default the width is 2.0. |
|
94 | 94 | */ |
|
95 | 95 | |
|
96 | 96 | /*! |
|
97 | 97 | \property QScatterSeries::markerShape |
|
98 | 98 | Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle. |
|
99 | 99 | */ |
|
100 | 100 | /*! |
|
101 | 101 | \qmlproperty MarkerShape ScatterSeries::markerShape |
|
102 | 102 | Defines the shape of the marker used to draw the points in the series. One of ScatterSeries |
|
103 | 103 | ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle. |
|
104 | 104 | The default shape is ScatterSeries.MarkerShapeCircle. |
|
105 | 105 | */ |
|
106 | 106 | |
|
107 | 107 | /*! |
|
108 | 108 | \property QScatterSeries::markerSize |
|
109 | 109 | Defines the size of the marker used to draw the points in the series. The default size is 15.0. |
|
110 | 110 | */ |
|
111 | 111 | /*! |
|
112 | 112 | \qmlproperty real ScatterSeries::markerSize |
|
113 | 113 | Defines the size of the marker used to draw the points in the series. The default size is 15.0. |
|
114 | 114 | */ |
|
115 | 115 | |
|
116 | 116 | /*! |
|
117 | 117 | \fn void QScatterSeries::colorChanged(QColor color) |
|
118 | 118 | Signal is emitted when the fill (brush) color has changed to \a color. |
|
119 | 119 | */ |
|
120 | 120 | |
|
121 | 121 | /*! |
|
122 | 122 | \fn void QScatterSeries::borderColorChanged(QColor color) |
|
123 | 123 | Signal is emitted when the line (pen) color has changed to \a color. |
|
124 | 124 | */ |
|
125 | 125 | /*! |
|
126 | 126 | \qmlsignal ScatterSeries::borderColorChanged(color color) |
|
127 | 127 | Signal is emitted when the line (pen) color has changed to \a color. |
|
128 | 128 | */ |
|
129 | 129 | |
|
130 | 130 | /*! |
|
131 | 131 | \fn QAbstractSeries::SeriesType QScatterSeries::type() const |
|
132 | 132 | Returns QAbstractSeries::SeriesTypeScatter. |
|
133 | 133 | \sa QAbstractSeries, SeriesType |
|
134 | 134 | */ |
|
135 | 135 | |
|
136 | 136 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
137 | 137 | |
|
138 | 138 | /*! |
|
139 | 139 | Constructs a series object which is a child of \a parent. |
|
140 | 140 | */ |
|
141 | 141 | QScatterSeries::QScatterSeries(QObject *parent) |
|
142 | 142 | : QXYSeries(*new QScatterSeriesPrivate(this), parent) |
|
143 | 143 | { |
|
144 | 144 | } |
|
145 | 145 | |
|
146 | 146 | /*! |
|
147 | 147 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. |
|
148 | 148 | */ |
|
149 | 149 | QScatterSeries::~QScatterSeries() |
|
150 | 150 | { |
|
151 | 151 | Q_D(QScatterSeries); |
|
152 | 152 | if (d->m_chart) |
|
153 | 153 | d->m_chart->removeSeries(this); |
|
154 | 154 | } |
|
155 | 155 | |
|
156 | 156 | QAbstractSeries::SeriesType QScatterSeries::type() const |
|
157 | 157 | { |
|
158 | 158 | return QAbstractSeries::SeriesTypeScatter; |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | /*! |
|
162 | 162 | Sets \a pen used for drawing points' border on the chart. If the pen is not defined, the |
|
163 | 163 | pen from chart theme is used. |
|
164 | 164 | \sa QChart::setTheme() |
|
165 | 165 | */ |
|
166 | 166 | void QScatterSeries::setPen(const QPen &pen) |
|
167 | 167 | { |
|
168 | 168 | Q_D(QXYSeries); |
|
169 | 169 | if (d->m_pen != pen) { |
|
170 | 170 | bool emitColorChanged = d->m_pen.color() != pen.color(); |
|
171 | 171 | d->m_pen = pen; |
|
172 | 172 | emit d->updated(); |
|
173 | 173 | if (emitColorChanged) |
|
174 | 174 | emit borderColorChanged(pen.color()); |
|
175 | 175 | } |
|
176 | 176 | } |
|
177 | 177 | |
|
178 | 178 | /*! |
|
179 | 179 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
180 | 180 | from chart theme setting is used. |
|
181 | 181 | \sa QChart::setTheme() |
|
182 | 182 | */ |
|
183 | 183 | void QScatterSeries::setBrush(const QBrush &brush) |
|
184 | 184 | { |
|
185 | 185 | Q_D(QScatterSeries); |
|
186 | 186 | if (d->m_brush != brush) { |
|
187 | 187 | bool emitColorChanged = d->m_brush.color() != brush.color(); |
|
188 | 188 | d->m_brush = brush; |
|
189 | 189 | emit d->updated(); |
|
190 | 190 | if (emitColorChanged) |
|
191 | 191 | emit colorChanged(brush.color()); |
|
192 | 192 | } |
|
193 | 193 | } |
|
194 | 194 | |
|
195 | 195 | void QScatterSeries::setColor(const QColor &color) |
|
196 | 196 | { |
|
197 | 197 | QBrush b = brush(); |
|
198 | if (b == QChartPrivate::defaultBrush()) | |
|
199 | b = QBrush(); | |
|
198 | 200 | if (b == QBrush()) |
|
199 | 201 | b.setStyle(Qt::SolidPattern); |
|
200 | 202 | b.setColor(color); |
|
201 | 203 | setBrush(b); |
|
202 | 204 | } |
|
203 | 205 | |
|
204 | 206 | QColor QScatterSeries::color() const |
|
205 | 207 | { |
|
206 | 208 | return brush().color(); |
|
207 | 209 | } |
|
208 | 210 | |
|
209 | 211 | void QScatterSeries::setBorderColor(const QColor &color) |
|
210 | 212 | { |
|
211 | 213 | QPen p = pen(); |
|
212 | if (p.color() != color) { | |
|
213 | p.setColor(color); | |
|
214 | setPen(p); | |
|
215 | } | |
|
214 | if (p == QChartPrivate::defaultPen()) | |
|
215 | p = QPen(); | |
|
216 | p.setColor(color); | |
|
217 | setPen(p); | |
|
216 | 218 | } |
|
217 | 219 | |
|
218 | 220 | QColor QScatterSeries::borderColor() const |
|
219 | 221 | { |
|
220 | 222 | return pen().color(); |
|
221 | 223 | } |
|
222 | 224 | |
|
223 | 225 | QScatterSeries::MarkerShape QScatterSeries::markerShape() const |
|
224 | 226 | { |
|
225 | 227 | Q_D(const QScatterSeries); |
|
226 | 228 | return d->m_shape; |
|
227 | 229 | } |
|
228 | 230 | |
|
229 | 231 | void QScatterSeries::setMarkerShape(MarkerShape shape) |
|
230 | 232 | { |
|
231 | 233 | Q_D(QScatterSeries); |
|
232 | 234 | if (d->m_shape != shape) { |
|
233 | 235 | d->m_shape = shape; |
|
234 | 236 | emit d->updated(); |
|
235 | 237 | } |
|
236 | 238 | } |
|
237 | 239 | |
|
238 | 240 | qreal QScatterSeries::markerSize() const |
|
239 | 241 | { |
|
240 | 242 | Q_D(const QScatterSeries); |
|
241 | 243 | return d->m_size; |
|
242 | 244 | } |
|
243 | 245 | |
|
244 | 246 | void QScatterSeries::setMarkerSize(qreal size) |
|
245 | 247 | { |
|
246 | 248 | Q_D(QScatterSeries); |
|
247 | 249 | |
|
248 | 250 | if (!qFuzzyCompare(d->m_size, size)) { |
|
249 | 251 | d->m_size = size; |
|
250 | 252 | emit d->updated(); |
|
251 | 253 | } |
|
252 | 254 | } |
|
253 | 255 | |
|
254 | 256 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
255 | 257 | |
|
256 | 258 | QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries *q) |
|
257 | 259 | : QXYSeriesPrivate(q), |
|
258 | 260 | m_shape(QScatterSeries::MarkerShapeCircle), |
|
259 | 261 | m_size(15.0) |
|
260 | 262 | { |
|
261 | 263 | } |
|
262 | 264 | |
|
263 | 265 | void QScatterSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
264 | 266 | { |
|
265 | 267 | Q_Q(QScatterSeries); |
|
266 | 268 | ScatterChartItem *scatter = new ScatterChartItem(q,parent); |
|
267 | 269 | m_item.reset(scatter); |
|
268 | 270 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
269 | 271 | } |
|
270 | 272 | |
|
271 | 273 | void QScatterSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
272 | 274 | { |
|
273 | 275 | Q_Q(QScatterSeries); |
|
274 | 276 | const QList<QColor> colors = theme->seriesColors(); |
|
275 | 277 | const QList<QGradient> gradients = theme->seriesGradients(); |
|
276 | 278 | |
|
277 | 279 | if (forced || QChartPrivate::defaultPen() == m_pen) { |
|
278 | 280 | QPen pen; |
|
279 | 281 | pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0)); |
|
280 | 282 | pen.setWidthF(2); |
|
281 | 283 | q->setPen(pen); |
|
282 | 284 | } |
|
283 | 285 | |
|
284 | 286 | if (forced || QChartPrivate::defaultBrush() == m_brush) { |
|
285 | 287 | QBrush brush(colors.at(index % colors.size())); |
|
286 | 288 | q->setBrush(brush); |
|
287 | 289 | } |
|
288 | 290 | } |
|
289 | 291 | |
|
290 | 292 | void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
291 | 293 | { |
|
292 | 294 | ScatterChartItem *item = static_cast<ScatterChartItem *>(m_item.data()); |
|
293 | 295 | Q_ASSERT(item); |
|
294 | 296 | |
|
295 | 297 | if (item->animation()) |
|
296 | 298 | item->animation()->stopAndDestroyLater(); |
|
297 | 299 | |
|
298 | 300 | if (options.testFlag(QChart::SeriesAnimations)) |
|
299 | 301 | item->setAnimation(new ScatterAnimation(item)); |
|
300 | 302 | else |
|
301 | 303 | item->setAnimation(0); |
|
302 | 304 | |
|
303 | 305 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
304 | 306 | } |
|
305 | 307 | |
|
306 | 308 | #include "moc_qscatterseries.cpp" |
|
307 | 309 | |
|
308 | 310 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now