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