@@ -1,333 +1,356 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2015 The Qt Company Ltd |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to The Qt Company, please use contact form at http://qt.io |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Charts module. |
|
8 | 8 | ** |
|
9 | 9 | ** Licensees holding valid commercial license for Qt may use this file in |
|
10 | 10 | ** accordance with the Qt License Agreement provided with the Software |
|
11 | 11 | ** or, alternatively, in accordance with the terms contained in a written |
|
12 | 12 | ** agreement between you and The Qt Company. |
|
13 | 13 | ** |
|
14 | 14 | ** If you have questions regarding the use of this file, please use |
|
15 | 15 | ** contact form at http://qt.io |
|
16 | 16 | ** |
|
17 | 17 | ****************************************************************************/ |
|
18 | 18 | |
|
19 | 19 | #include <QtCharts/QScatterSeries> |
|
20 | 20 | #include <private/qscatterseries_p.h> |
|
21 | 21 | #include <private/scatterchartitem_p.h> |
|
22 | 22 | #include <private/chartdataset_p.h> |
|
23 | 23 | #include <private/charttheme_p.h> |
|
24 | 24 | #include <private/scatteranimation_p.h> |
|
25 | 25 | #include <private/qchart_p.h> |
|
26 | 26 | |
|
27 | 27 | /*! |
|
28 | 28 | \class QScatterSeries |
|
29 | 29 | \inmodule Qt Charts |
|
30 | 30 | \brief The QScatterSeries class is used for making scatter charts. |
|
31 | 31 | |
|
32 | 32 | The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis |
|
33 | 33 | and the vertical axis. |
|
34 | 34 | |
|
35 | 35 | \image examples_scatterchart.png |
|
36 | 36 | |
|
37 | 37 | Creating basic scatter chart is simple: |
|
38 | 38 | \code |
|
39 | 39 | QScatterSeries* series = new QScatterSeries(); |
|
40 | 40 | series->append(0, 6); |
|
41 | 41 | series->append(2, 4); |
|
42 | 42 | ... |
|
43 | 43 | chart->addSeries(series); |
|
44 | 44 | \endcode |
|
45 | 45 | */ |
|
46 | 46 | /*! |
|
47 | 47 | \qmltype ScatterSeries |
|
48 | 48 | \instantiates QScatterSeries |
|
49 | 49 | \inqmlmodule QtCharts |
|
50 | 50 | |
|
51 | 51 | \inherits XYSeries |
|
52 | 52 | |
|
53 | 53 | \brief The ScatterSeries type is used for making scatter charts. |
|
54 | 54 | |
|
55 | 55 | The following QML shows how to create a chart with two simple scatter series: |
|
56 | 56 | \snippet qmlchart/qml/qmlchart/View5.qml 1 |
|
57 | 57 | |
|
58 | 58 | \beginfloatleft |
|
59 | 59 | \image examples_qmlchart5.png |
|
60 | 60 | \endfloat |
|
61 | 61 | \clearfloat |
|
62 | 62 | */ |
|
63 | 63 | |
|
64 | 64 | /*! |
|
65 | 65 | \enum QScatterSeries::MarkerShape |
|
66 | 66 | |
|
67 | 67 | This enum describes the shape used when rendering marker items. |
|
68 | 68 | |
|
69 | 69 | \value MarkerShapeCircle |
|
70 | 70 | \value MarkerShapeRectangle |
|
71 | 71 | */ |
|
72 | 72 | |
|
73 | 73 | /*! |
|
74 | 74 | \property QScatterSeries::brush |
|
75 | 75 | Brush used to draw the series. |
|
76 | 76 | */ |
|
77 | 77 | |
|
78 | 78 | /*! |
|
79 | 79 | \property QScatterSeries::color |
|
80 | 80 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. |
|
81 | 81 | \sa QScatterSeries::brush() |
|
82 | 82 | */ |
|
83 | 83 | |
|
84 | 84 | /*! |
|
85 | 85 | \property QScatterSeries::borderColor |
|
86 | 86 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. |
|
87 | 87 | \sa QScatterSeries::pen() |
|
88 | 88 | */ |
|
89 | 89 | /*! |
|
90 | 90 | \qmlproperty color ScatterSeries::borderColor |
|
91 | 91 | Border (pen) color of the series. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \qmlproperty real ScatterSeries::borderWidth |
|
96 | 96 | The width of the border line. By default the width is 2.0. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \property QScatterSeries::markerShape |
|
101 | 101 | Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle. |
|
102 | 102 | */ |
|
103 | 103 | /*! |
|
104 | 104 | \qmlproperty MarkerShape ScatterSeries::markerShape |
|
105 | 105 | Defines the shape of the marker used to draw the points in the series. One of ScatterSeries |
|
106 | 106 | ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle. |
|
107 | 107 | The default shape is ScatterSeries.MarkerShapeCircle. |
|
108 | 108 | */ |
|
109 | 109 | |
|
110 | 110 | /*! |
|
111 | 111 | \property QScatterSeries::markerSize |
|
112 | 112 | Defines the size of the marker used to draw the points in the series. The default size is 15.0. |
|
113 | 113 | */ |
|
114 | 114 | /*! |
|
115 | 115 | \qmlproperty real ScatterSeries::markerSize |
|
116 | 116 | Defines the size of the marker used to draw the points in the series. The default size is 15.0. |
|
117 | 117 | */ |
|
118 | 118 | |
|
119 | 119 | /*! |
|
120 | 120 | \qmlproperty QString ScatterSeries::brushFilename |
|
121 | 121 | The name of the file used as a brush for the series. |
|
122 | 122 | */ |
|
123 | 123 | |
|
124 | 124 | /*! |
|
125 | 125 | \fn void QScatterSeries::colorChanged(QColor color) |
|
126 | 126 | Signal is emitted when the fill (brush) color has changed to \a color. |
|
127 | 127 | */ |
|
128 | /*! | |
|
129 | \qmlsignal ScatterSeries::onColorChanged(color color) | |
|
130 | Signal is emitted when the fill (brush) color has changed to \a color. | |
|
131 | */ | |
|
128 | 132 | |
|
129 | 133 | /*! |
|
130 | 134 | \fn void QScatterSeries::borderColorChanged(QColor color) |
|
131 | 135 | Signal is emitted when the line (pen) color has changed to \a color. |
|
132 | 136 | */ |
|
133 | 137 | /*! |
|
134 |
\qmlsignal ScatterSeries:: |
|
|
138 | \qmlsignal ScatterSeries::onBorderColorChanged(color color) | |
|
135 | 139 | Signal is emitted when the line (pen) color has changed to \a color. |
|
136 | 140 | */ |
|
137 | 141 | |
|
138 | 142 | /*! |
|
139 | 143 | \fn QAbstractSeries::SeriesType QScatterSeries::type() const |
|
140 | 144 | Returns QAbstractSeries::SeriesTypeScatter. |
|
141 | 145 | \sa QAbstractSeries, SeriesType |
|
142 | 146 | */ |
|
143 | 147 | |
|
148 | /*! | |
|
149 | \fn void QScatterSeries::markerShapeChanged(MarkerShape shape) | |
|
150 | Signal is emitted when the marker shape has changed to \a shape. | |
|
151 | */ | |
|
152 | /*! | |
|
153 | \qmlsignal ScatterSeries::onMarkerShapeChanged(MarkerShape shape) | |
|
154 | Signal is emitted when the marker shape has changed to \a shape. | |
|
155 | */ | |
|
156 | /*! | |
|
157 | \fn void QScatterSeries::markerSizeChanged(qreal size) | |
|
158 | Signal is emitted when the marker size has changed to \a size. | |
|
159 | */ | |
|
160 | /*! | |
|
161 | \qmlsignal ScatterSeries::onMarkerSizeChanged(real size) | |
|
162 | Signal is emitted when the marker size has changed to \a size. | |
|
163 | */ | |
|
164 | ||
|
144 | 165 | QT_CHARTS_BEGIN_NAMESPACE |
|
145 | 166 | |
|
146 | 167 | /*! |
|
147 | 168 | Constructs a series object which is a child of \a parent. |
|
148 | 169 | */ |
|
149 | 170 | QScatterSeries::QScatterSeries(QObject *parent) |
|
150 | 171 | : QXYSeries(*new QScatterSeriesPrivate(this), parent) |
|
151 | 172 | { |
|
152 | 173 | } |
|
153 | 174 | |
|
154 | 175 | /*! |
|
155 | 176 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. |
|
156 | 177 | */ |
|
157 | 178 | QScatterSeries::~QScatterSeries() |
|
158 | 179 | { |
|
159 | 180 | Q_D(QScatterSeries); |
|
160 | 181 | if (d->m_chart) |
|
161 | 182 | d->m_chart->removeSeries(this); |
|
162 | 183 | } |
|
163 | 184 | |
|
164 | 185 | QAbstractSeries::SeriesType QScatterSeries::type() const |
|
165 | 186 | { |
|
166 | 187 | return QAbstractSeries::SeriesTypeScatter; |
|
167 | 188 | } |
|
168 | 189 | |
|
169 | 190 | /*! |
|
170 | 191 | Sets \a pen used for drawing points' border on the chart. If the pen is not defined, the |
|
171 | 192 | pen from chart theme is used. |
|
172 | 193 | \sa QChart::setTheme() |
|
173 | 194 | */ |
|
174 | 195 | void QScatterSeries::setPen(const QPen &pen) |
|
175 | 196 | { |
|
176 | 197 | Q_D(QXYSeries); |
|
177 | 198 | if (d->m_pen != pen) { |
|
178 | 199 | bool emitColorChanged = d->m_pen.color() != pen.color(); |
|
179 | 200 | d->m_pen = pen; |
|
180 | 201 | emit d->updated(); |
|
181 | 202 | if (emitColorChanged) |
|
182 | 203 | emit borderColorChanged(pen.color()); |
|
183 | 204 | } |
|
184 | 205 | } |
|
185 | 206 | |
|
186 | 207 | /*! |
|
187 | 208 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
188 | 209 | from chart theme setting is used. |
|
189 | 210 | \sa QChart::setTheme() |
|
190 | 211 | */ |
|
191 | 212 | void QScatterSeries::setBrush(const QBrush &brush) |
|
192 | 213 | { |
|
193 | 214 | Q_D(QScatterSeries); |
|
194 | 215 | if (d->m_brush != brush) { |
|
195 | 216 | bool emitColorChanged = d->m_brush.color() != brush.color(); |
|
196 | 217 | d->m_brush = brush; |
|
197 | 218 | emit d->updated(); |
|
198 | 219 | if (emitColorChanged) |
|
199 | 220 | emit colorChanged(brush.color()); |
|
200 | 221 | } |
|
201 | 222 | } |
|
202 | 223 | |
|
203 | 224 | QBrush QScatterSeries::brush() const |
|
204 | 225 | { |
|
205 | 226 | Q_D(const QScatterSeries); |
|
206 | 227 | if (d->m_brush == QChartPrivate::defaultBrush()) |
|
207 | 228 | return QBrush(); |
|
208 | 229 | else |
|
209 | 230 | return d->m_brush; |
|
210 | 231 | } |
|
211 | 232 | |
|
212 | 233 | void QScatterSeries::setColor(const QColor &color) |
|
213 | 234 | { |
|
214 | 235 | QBrush b = brush(); |
|
215 | 236 | if (b == QChartPrivate::defaultBrush()) |
|
216 | 237 | b = QBrush(); |
|
217 | 238 | if (b == QBrush()) |
|
218 | 239 | b.setStyle(Qt::SolidPattern); |
|
219 | 240 | b.setColor(color); |
|
220 | 241 | setBrush(b); |
|
221 | 242 | } |
|
222 | 243 | |
|
223 | 244 | QColor QScatterSeries::color() const |
|
224 | 245 | { |
|
225 | 246 | return brush().color(); |
|
226 | 247 | } |
|
227 | 248 | |
|
228 | 249 | void QScatterSeries::setBorderColor(const QColor &color) |
|
229 | 250 | { |
|
230 | 251 | QPen p = pen(); |
|
231 | 252 | if (p == QChartPrivate::defaultPen()) |
|
232 | 253 | p = QPen(); |
|
233 | 254 | p.setColor(color); |
|
234 | 255 | setPen(p); |
|
235 | 256 | } |
|
236 | 257 | |
|
237 | 258 | QColor QScatterSeries::borderColor() const |
|
238 | 259 | { |
|
239 | 260 | return pen().color(); |
|
240 | 261 | } |
|
241 | 262 | |
|
242 | 263 | QScatterSeries::MarkerShape QScatterSeries::markerShape() const |
|
243 | 264 | { |
|
244 | 265 | Q_D(const QScatterSeries); |
|
245 | 266 | return d->m_shape; |
|
246 | 267 | } |
|
247 | 268 | |
|
248 | 269 | void QScatterSeries::setMarkerShape(MarkerShape shape) |
|
249 | 270 | { |
|
250 | 271 | Q_D(QScatterSeries); |
|
251 | 272 | if (d->m_shape != shape) { |
|
252 | 273 | d->m_shape = shape; |
|
253 | 274 | emit d->updated(); |
|
275 | emit markerShapeChanged(shape); | |
|
254 | 276 | } |
|
255 | 277 | } |
|
256 | 278 | |
|
257 | 279 | qreal QScatterSeries::markerSize() const |
|
258 | 280 | { |
|
259 | 281 | Q_D(const QScatterSeries); |
|
260 | 282 | return d->m_size; |
|
261 | 283 | } |
|
262 | 284 | |
|
263 | 285 | void QScatterSeries::setMarkerSize(qreal size) |
|
264 | 286 | { |
|
265 | 287 | Q_D(QScatterSeries); |
|
266 | 288 | |
|
267 | 289 | if (!qFuzzyCompare(d->m_size, size)) { |
|
268 | 290 | d->m_size = size; |
|
269 | 291 | emit d->updated(); |
|
292 | emit markerSizeChanged(size); | |
|
270 | 293 | } |
|
271 | 294 | } |
|
272 | 295 | |
|
273 | 296 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
274 | 297 | |
|
275 | 298 | QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries *q) |
|
276 | 299 | : QXYSeriesPrivate(q), |
|
277 | 300 | m_shape(QScatterSeries::MarkerShapeCircle), |
|
278 | 301 | m_size(15.0) |
|
279 | 302 | { |
|
280 | 303 | } |
|
281 | 304 | |
|
282 | 305 | void QScatterSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
283 | 306 | { |
|
284 | 307 | Q_Q(QScatterSeries); |
|
285 | 308 | ScatterChartItem *scatter = new ScatterChartItem(q,parent); |
|
286 | 309 | m_item.reset(scatter); |
|
287 | 310 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
288 | 311 | } |
|
289 | 312 | |
|
290 | 313 | void QScatterSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
291 | 314 | { |
|
292 | 315 | Q_Q(QScatterSeries); |
|
293 | 316 | const QList<QColor> colors = theme->seriesColors(); |
|
294 | 317 | const QList<QGradient> gradients = theme->seriesGradients(); |
|
295 | 318 | |
|
296 | 319 | if (forced || QChartPrivate::defaultPen() == m_pen) { |
|
297 | 320 | QPen pen; |
|
298 | 321 | pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0)); |
|
299 | 322 | pen.setWidthF(2); |
|
300 | 323 | q->setPen(pen); |
|
301 | 324 | } |
|
302 | 325 | |
|
303 | 326 | if (forced || QChartPrivate::defaultBrush() == m_brush) { |
|
304 | 327 | QBrush brush(colors.at(index % colors.size())); |
|
305 | 328 | q->setBrush(brush); |
|
306 | 329 | } |
|
307 | 330 | |
|
308 | 331 | if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) { |
|
309 | 332 | QColor color = theme->labelBrush().color(); |
|
310 | 333 | q->setPointLabelsColor(color); |
|
311 | 334 | } |
|
312 | 335 | } |
|
313 | 336 | |
|
314 | 337 | void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions options, int duration, |
|
315 | 338 | QEasingCurve &curve) |
|
316 | 339 | { |
|
317 | 340 | ScatterChartItem *item = static_cast<ScatterChartItem *>(m_item.data()); |
|
318 | 341 | Q_ASSERT(item); |
|
319 | 342 | |
|
320 | 343 | if (item->animation()) |
|
321 | 344 | item->animation()->stopAndDestroyLater(); |
|
322 | 345 | |
|
323 | 346 | if (options.testFlag(QChart::SeriesAnimations)) |
|
324 | 347 | item->setAnimation(new ScatterAnimation(item, duration, curve)); |
|
325 | 348 | else |
|
326 | 349 | item->setAnimation(0); |
|
327 | 350 | |
|
328 | 351 | QAbstractSeriesPrivate::initializeAnimations(options, duration, curve); |
|
329 | 352 | } |
|
330 | 353 | |
|
331 | 354 | #include "moc_qscatterseries.cpp" |
|
332 | 355 | |
|
333 | 356 | QT_CHARTS_END_NAMESPACE |
@@ -1,73 +1,75 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2015 The Qt Company Ltd |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to The Qt Company, please use contact form at http://qt.io |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Charts module. |
|
8 | 8 | ** |
|
9 | 9 | ** Licensees holding valid commercial license for Qt may use this file in |
|
10 | 10 | ** accordance with the Qt License Agreement provided with the Software |
|
11 | 11 | ** or, alternatively, in accordance with the terms contained in a written |
|
12 | 12 | ** agreement between you and The Qt Company. |
|
13 | 13 | ** |
|
14 | 14 | ** If you have questions regarding the use of this file, please use |
|
15 | 15 | ** contact form at http://qt.io |
|
16 | 16 | ** |
|
17 | 17 | ****************************************************************************/ |
|
18 | 18 | |
|
19 | 19 | #ifndef QSCATTERSERIES_H |
|
20 | 20 | #define QSCATTERSERIES_H |
|
21 | 21 | |
|
22 | 22 | #include <QtCharts/QChartGlobal> |
|
23 | 23 | #include <QtCharts/qxyseries.h> |
|
24 | 24 | |
|
25 | 25 | QT_CHARTS_BEGIN_NAMESPACE |
|
26 | 26 | |
|
27 | 27 | class QScatterSeriesPrivate; |
|
28 | 28 | |
|
29 | 29 | class QT_CHARTS_EXPORT QScatterSeries : public QXYSeries |
|
30 | 30 | { |
|
31 | 31 | Q_OBJECT |
|
32 | 32 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
33 | 33 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
34 | Q_PROPERTY(MarkerShape markerShape READ markerShape WRITE setMarkerShape) | |
|
35 | Q_PROPERTY(qreal markerSize READ markerSize WRITE setMarkerSize) | |
|
34 | Q_PROPERTY(MarkerShape markerShape READ markerShape WRITE setMarkerShape NOTIFY markerShapeChanged) | |
|
35 | Q_PROPERTY(qreal markerSize READ markerSize WRITE setMarkerSize NOTIFY markerSizeChanged) | |
|
36 | 36 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush) |
|
37 | 37 | Q_ENUMS(MarkerShape) |
|
38 | 38 | |
|
39 | 39 | public: |
|
40 | 40 | enum MarkerShape { |
|
41 | 41 | MarkerShapeCircle, |
|
42 | 42 | MarkerShapeRectangle |
|
43 | 43 | }; |
|
44 | 44 | |
|
45 | 45 | public: |
|
46 | 46 | explicit QScatterSeries(QObject *parent = 0); |
|
47 | 47 | ~QScatterSeries(); |
|
48 | 48 | QAbstractSeries::SeriesType type() const; |
|
49 | 49 | void setPen(const QPen &pen); |
|
50 | 50 | void setBrush(const QBrush &brush); |
|
51 | 51 | QBrush brush() const; |
|
52 | 52 | void setColor(const QColor &color); |
|
53 | 53 | QColor color() const; |
|
54 | 54 | void setBorderColor(const QColor &color); |
|
55 | 55 | QColor borderColor() const; |
|
56 | 56 | MarkerShape markerShape() const; |
|
57 | 57 | void setMarkerShape(MarkerShape shape); |
|
58 | 58 | qreal markerSize() const; |
|
59 | 59 | void setMarkerSize(qreal size); |
|
60 | 60 | |
|
61 | 61 | Q_SIGNALS: |
|
62 | 62 | void colorChanged(QColor color); |
|
63 | 63 | void borderColorChanged(QColor color); |
|
64 | void markerShapeChanged(MarkerShape shape); | |
|
65 | void markerSizeChanged(qreal size); | |
|
64 | 66 | |
|
65 | 67 | private: |
|
66 | 68 | Q_DECLARE_PRIVATE(QScatterSeries) |
|
67 | 69 | Q_DISABLE_COPY(QScatterSeries) |
|
68 | 70 | friend class ScatterChartItem; |
|
69 | 71 | }; |
|
70 | 72 | |
|
71 | 73 | QT_CHARTS_END_NAMESPACE |
|
72 | 74 | |
|
73 | 75 | #endif // QSCATTERSERIES_H |
@@ -1,147 +1,178 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2015 The Qt Company Ltd |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to The Qt Company, please use contact form at http://qt.io |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Charts module. |
|
8 | 8 | ** |
|
9 | 9 | ** Licensees holding valid commercial license for Qt may use this file in |
|
10 | 10 | ** accordance with the Qt License Agreement provided with the Software |
|
11 | 11 | ** or, alternatively, in accordance with the terms contained in a written |
|
12 | 12 | ** agreement between you and The Qt Company. |
|
13 | 13 | ** |
|
14 | 14 | ** If you have questions regarding the use of this file, please use |
|
15 | 15 | ** contact form at http://qt.io |
|
16 | 16 | ** |
|
17 | 17 | ****************************************************************************/ |
|
18 | 18 | |
|
19 | 19 | #include "private/glxyseriesdata_p.h" |
|
20 | 20 | #include "private/abstractdomain_p.h" |
|
21 | 21 | #include <QtCharts/QScatterSeries> |
|
22 | 22 | |
|
23 | 23 | QT_CHARTS_BEGIN_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | GLXYSeriesDataManager::GLXYSeriesDataManager(QObject *parent) |
|
26 | 26 | : QObject(parent), |
|
27 | 27 | m_mapDirty(false) |
|
28 | 28 | { |
|
29 | 29 | } |
|
30 | 30 | |
|
31 | 31 | GLXYSeriesDataManager::~GLXYSeriesDataManager() |
|
32 | 32 | { |
|
33 | 33 | cleanup(); |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | 36 | void GLXYSeriesDataManager::setPoints(QXYSeries *series, const AbstractDomain *domain) |
|
37 | 37 | { |
|
38 | 38 | GLXYSeriesData *data = m_seriesDataMap.value(series); |
|
39 | 39 | if (!data) { |
|
40 | 40 | data = new GLXYSeriesData; |
|
41 | 41 | data->type = series->type(); |
|
42 | 42 | QColor sc; |
|
43 | 43 | if (data->type == QAbstractSeries::SeriesTypeScatter) { |
|
44 | 44 | QScatterSeries *scatter = static_cast<QScatterSeries *>(series); |
|
45 | 45 | data->width = float(scatter->markerSize()); |
|
46 | 46 | sc = scatter->color(); // Scatter overwrites color property |
|
47 | connect(scatter, &QScatterSeries::colorChanged, this, | |
|
48 | &GLXYSeriesDataManager::handleScatterColorChange); | |
|
49 | connect(scatter, &QScatterSeries::markerSizeChanged, this, | |
|
50 | &GLXYSeriesDataManager::handleScatterMarkerSizeChange); | |
|
47 | 51 | } else { |
|
48 | 52 | data->width = float(series->pen().widthF()); |
|
49 | 53 | sc = series->color(); |
|
54 | connect(series, &QXYSeries::penChanged, this, | |
|
55 | &GLXYSeriesDataManager::handleSeriesPenChange); | |
|
50 | 56 | } |
|
51 | 57 | data->color = QVector3D(float(sc.redF()), float(sc.greenF()), float(sc.blueF())); |
|
52 | connect(series, &QXYSeries::penChanged, this, | |
|
53 | &GLXYSeriesDataManager::handleSeriesPenChange); | |
|
54 | 58 | connect(series, &QXYSeries::useOpenGLChanged, this, |
|
55 | 59 | &GLXYSeriesDataManager::handleSeriesOpenGLChange); |
|
56 | 60 | m_seriesDataMap.insert(series, data); |
|
57 | 61 | m_mapDirty = true; |
|
58 | 62 | } |
|
59 | 63 | QVector<float> &array = data->array; |
|
60 | 64 | |
|
61 | 65 | bool logAxis = false; |
|
62 | 66 | foreach (QAbstractAxis* axis, series->attachedAxes()) { |
|
63 | 67 | if (axis->type() == QAbstractAxis::AxisTypeLogValue) { |
|
64 | 68 | logAxis = true; |
|
65 | 69 | break; |
|
66 | 70 | } |
|
67 | 71 | } |
|
68 | 72 | |
|
69 | 73 | int count = series->count(); |
|
70 | 74 | int index = 0; |
|
71 | 75 | array.resize(count * 2); |
|
72 | 76 | if (logAxis) { |
|
73 | 77 | // Use domain to resolve geometry points. Not as fast as shaders, but simpler that way |
|
74 | 78 | QVector<QPointF> geometryPoints = domain->calculateGeometryPoints(series->pointsVector()); |
|
75 | 79 | const float height = domain->size().height(); |
|
76 | 80 | if (geometryPoints.size()) { |
|
77 | 81 | for (int i = 0; i < count; i++) { |
|
78 | 82 | const QPointF &point = geometryPoints.at(i); |
|
79 | 83 | array[index++] = float(point.x()); |
|
80 | 84 | array[index++] = float(height - point.y()); |
|
81 | 85 | } |
|
82 | 86 | } else { |
|
83 | 87 | // If there are invalid log values, geometry points generation fails |
|
84 | 88 | for (int i = 0; i < count; i++) { |
|
85 | 89 | array[index++] = 0.0f; |
|
86 | 90 | array[index++] = 0.0f; |
|
87 | 91 | } |
|
88 | 92 | } |
|
89 | 93 | data->min = QVector2D(0, 0); |
|
90 | 94 | data->delta = QVector2D(domain->size().width() / 2.0f, domain->size().height() / 2.0f); |
|
91 | 95 | } else { |
|
92 | 96 | // Regular value axes, so we can do the math easily on shaders. |
|
93 | 97 | QVector<QPointF> seriesPoints = series->pointsVector(); |
|
94 | 98 | for (int i = 0; i < count; i++) { |
|
95 | 99 | const QPointF &point = seriesPoints.at(i); |
|
96 | 100 | array[index++] = float(point.x()); |
|
97 | 101 | array[index++] = float(point.y()); |
|
98 | 102 | } |
|
99 | 103 | data->min = QVector2D(domain->minX(), domain->minY()); |
|
100 | 104 | data->delta = QVector2D((domain->maxX() - domain->minX()) / 2.0f, |
|
101 | 105 | (domain->maxY() - domain->minY()) / 2.0f); |
|
102 | 106 | } |
|
103 | 107 | data->dirty = true; |
|
104 | 108 | } |
|
105 | 109 | |
|
106 | 110 | void GLXYSeriesDataManager::removeSeries(const QXYSeries *series) |
|
107 | 111 | { |
|
108 | 112 | GLXYSeriesData *data = m_seriesDataMap.take(series); |
|
109 | 113 | if (data) { |
|
110 | 114 | disconnect(series, 0, this, 0); |
|
111 | 115 | delete data; |
|
112 | 116 | emit seriesRemoved(series); |
|
113 | 117 | m_mapDirty = true; |
|
114 | 118 | } |
|
115 | 119 | } |
|
116 | 120 | |
|
117 | 121 | void GLXYSeriesDataManager::cleanup() |
|
118 | 122 | { |
|
119 | 123 | foreach (GLXYSeriesData *data, m_seriesDataMap.values()) |
|
120 | 124 | delete data; |
|
121 | 125 | m_seriesDataMap.clear(); |
|
122 | 126 | m_mapDirty = true; |
|
123 | 127 | // Signal all series removal by using zero as parameter |
|
124 | 128 | emit seriesRemoved(0); |
|
125 | 129 | } |
|
126 | 130 | |
|
127 | 131 | void GLXYSeriesDataManager::handleSeriesPenChange() |
|
128 | 132 | { |
|
129 | 133 | QXYSeries *series = qobject_cast<QXYSeries *>(sender()); |
|
130 | 134 | if (series) { |
|
131 | 135 | GLXYSeriesData *data = m_seriesDataMap.value(series); |
|
132 | 136 | if (data) { |
|
133 | 137 | QColor sc = series->color(); |
|
134 | 138 | data->color = QVector3D(float(sc.redF()), float(sc.greenF()), float(sc.blueF())); |
|
135 | 139 | data->width = float(series->pen().widthF()); |
|
140 | data->dirty = true; | |
|
136 | 141 | } |
|
137 | 142 | } |
|
138 | 143 | } |
|
139 | 144 | |
|
140 | 145 | void GLXYSeriesDataManager::handleSeriesOpenGLChange() |
|
141 | 146 | { |
|
142 | 147 | QXYSeries *series = qobject_cast<QXYSeries *>(sender()); |
|
143 | 148 | if (!series->useOpenGL()) |
|
144 | 149 | removeSeries(series); |
|
145 | 150 | } |
|
146 | 151 | |
|
152 | void GLXYSeriesDataManager::handleScatterColorChange() | |
|
153 | { | |
|
154 | QScatterSeries *series = qobject_cast<QScatterSeries *>(sender()); | |
|
155 | if (series) { | |
|
156 | GLXYSeriesData *data = m_seriesDataMap.value(series); | |
|
157 | if (data) { | |
|
158 | QColor sc = series->color(); | |
|
159 | data->color = QVector3D(float(sc.redF()), float(sc.greenF()), float(sc.blueF())); | |
|
160 | data->dirty = true; | |
|
161 | } | |
|
162 | } | |
|
163 | } | |
|
164 | ||
|
165 | void GLXYSeriesDataManager::handleScatterMarkerSizeChange() | |
|
166 | { | |
|
167 | QScatterSeries *series = qobject_cast<QScatterSeries *>(sender()); | |
|
168 | if (series) { | |
|
169 | GLXYSeriesData *data = m_seriesDataMap.value(series); | |
|
170 | if (data) { | |
|
171 | data->width =float(series->markerSize()); | |
|
172 | data->dirty = true; | |
|
173 | } | |
|
174 | } | |
|
175 | } | |
|
176 | ||
|
147 | 177 | QT_CHARTS_END_NAMESPACE |
|
178 |
@@ -1,91 +1,93 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2015 The Qt Company Ltd |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to The Qt Company, please use contact form at http://qt.io |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Charts module. |
|
8 | 8 | ** |
|
9 | 9 | ** Licensees holding valid commercial license for Qt may use this file in |
|
10 | 10 | ** accordance with the Qt License Agreement provided with the Software |
|
11 | 11 | ** or, alternatively, in accordance with the terms contained in a written |
|
12 | 12 | ** agreement between you and The Qt Company. |
|
13 | 13 | ** |
|
14 | 14 | ** If you have questions regarding the use of this file, please use |
|
15 | 15 | ** contact form at http://qt.io |
|
16 | 16 | ** |
|
17 | 17 | ****************************************************************************/ |
|
18 | 18 | |
|
19 | 19 | // W A R N I N G |
|
20 | 20 | // ------------- |
|
21 | 21 | // |
|
22 | 22 | // This file is not part of the Qt Chart API. It exists purely as an |
|
23 | 23 | // implementation detail. This header file may change from version to |
|
24 | 24 | // version without notice, or even be removed. |
|
25 | 25 | // |
|
26 | 26 | // We mean it. |
|
27 | 27 | |
|
28 | 28 | #ifndef GLXYSERIESDATA_H |
|
29 | 29 | #define GLXYSERIESDATA_H |
|
30 | 30 | |
|
31 | 31 | #include <QtCore/QMap> |
|
32 | 32 | #include <QtCharts/QAbstractSeries> |
|
33 | 33 | #include <QtCharts/QXYSeries> |
|
34 | 34 | #include <QtGui/QVector3D> |
|
35 | 35 | #include <QtGui/QVector2D> |
|
36 | 36 | |
|
37 | 37 | QT_CHARTS_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | class AbstractDomain; |
|
40 | 40 | |
|
41 | 41 | struct GLXYSeriesData { |
|
42 | 42 | QVector<float> array; |
|
43 | 43 | bool dirty; |
|
44 | 44 | QVector3D color; |
|
45 | 45 | float width; |
|
46 | 46 | QAbstractSeries::SeriesType type; |
|
47 | 47 | QVector2D min; |
|
48 | 48 | QVector2D delta; |
|
49 | 49 | }; |
|
50 | 50 | |
|
51 | 51 | typedef QMap<const QXYSeries *, GLXYSeriesData *> GLXYDataMap; |
|
52 | 52 | typedef QMapIterator<const QXYSeries *, GLXYSeriesData *> GLXYDataMapIterator; |
|
53 | 53 | |
|
54 | 54 | class GLXYSeriesDataManager : public QObject |
|
55 | 55 | { |
|
56 | 56 | Q_OBJECT |
|
57 | 57 | |
|
58 | 58 | public: |
|
59 | 59 | GLXYSeriesDataManager(QObject *parent = 0); |
|
60 | 60 | ~GLXYSeriesDataManager(); |
|
61 | 61 | |
|
62 | 62 | void setPoints(QXYSeries *series, const AbstractDomain *domain); |
|
63 | 63 | |
|
64 | 64 | void removeSeries(const QXYSeries *series); |
|
65 | 65 | |
|
66 | 66 | GLXYDataMap &dataMap() { return m_seriesDataMap; } |
|
67 | 67 | |
|
68 | 68 | // These functions are needed by qml side, so they must be inline |
|
69 | 69 | bool mapDirty() const { return m_mapDirty; } |
|
70 | 70 | void clearAllDirty() { |
|
71 | 71 | m_mapDirty = false; |
|
72 | 72 | foreach (GLXYSeriesData *data, m_seriesDataMap.values()) |
|
73 | 73 | data->dirty = false; |
|
74 | 74 | } |
|
75 | 75 | |
|
76 | 76 | public Q_SLOTS: |
|
77 | 77 | void cleanup(); |
|
78 | 78 | void handleSeriesPenChange(); |
|
79 | 79 | void handleSeriesOpenGLChange(); |
|
80 | void handleScatterColorChange(); | |
|
81 | void handleScatterMarkerSizeChange(); | |
|
80 | 82 | |
|
81 | 83 | Q_SIGNALS: |
|
82 | 84 | void seriesRemoved(const QXYSeries *series); |
|
83 | 85 | |
|
84 | 86 | private: |
|
85 | 87 | GLXYDataMap m_seriesDataMap; |
|
86 | 88 | bool m_mapDirty; |
|
87 | 89 | }; |
|
88 | 90 | |
|
89 | 91 | QT_CHARTS_END_NAMESPACE |
|
90 | 92 | |
|
91 | 93 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now