@@ -0,0 +1,397 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2013 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #include "qboxset.h" | |||
|
22 | #include "qboxset_p.h" | |||
|
23 | #include "charthelpers_p.h" | |||
|
24 | ||||
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
26 | ||||
|
27 | /*! | |||
|
28 | Constructs QBoxSet with parent of \a parent | |||
|
29 | */ | |||
|
30 | QBoxSet::QBoxSet(QObject *parent) | |||
|
31 | : QObject(parent), | |||
|
32 | d_ptr(new QBoxSetPrivate(this)) | |||
|
33 | { | |||
|
34 | } | |||
|
35 | ||||
|
36 | QBoxSet::QBoxSet(qreal value1, qreal value2, qreal value3, qreal value4, qreal value5, QObject *parent) | |||
|
37 | : QObject(parent), | |||
|
38 | d_ptr(new QBoxSetPrivate(this)) | |||
|
39 | { | |||
|
40 | d_ptr->append(value1); | |||
|
41 | d_ptr->append(value2); | |||
|
42 | d_ptr->append(value3); | |||
|
43 | d_ptr->append(value4); | |||
|
44 | d_ptr->append(value5); | |||
|
45 | } | |||
|
46 | ||||
|
47 | /*! | |||
|
48 | Destroys the boxset | |||
|
49 | */ | |||
|
50 | QBoxSet::~QBoxSet() | |||
|
51 | { | |||
|
52 | // NOTE: d_ptr destroyed by QObject | |||
|
53 | } | |||
|
54 | ||||
|
55 | /*! | |||
|
56 | Appends new value \a value to the end of set. | |||
|
57 | */ | |||
|
58 | void QBoxSet::append(const qreal value) | |||
|
59 | { | |||
|
60 | int index = d_ptr->m_values.count(); | |||
|
61 | d_ptr->append(value); | |||
|
62 | ||||
|
63 | emit valuesAdded(index, 1); | |||
|
64 | } | |||
|
65 | ||||
|
66 | /*! | |||
|
67 | Appends a list of reals to set. Works like append with single real value. The \a values in list | |||
|
68 | are appended to end of boxset | |||
|
69 | \sa append() | |||
|
70 | */ | |||
|
71 | void QBoxSet::append(const QList<qreal> &values) | |||
|
72 | { | |||
|
73 | int index = d_ptr->m_values.count(); | |||
|
74 | d_ptr->append(values); | |||
|
75 | emit valuesAdded(index, values.count()); | |||
|
76 | } | |||
|
77 | ||||
|
78 | /*! | |||
|
79 | Sets new value \a value as the lower extreme for the set. | |||
|
80 | */ | |||
|
81 | void QBoxSet::setLowerExtreme(const qreal value) | |||
|
82 | { | |||
|
83 | d_ptr->replace(QBoxSetPrivate::PosLowerExtreme, value); | |||
|
84 | emit valueChanged(QBoxSetPrivate::PosLowerExtreme); | |||
|
85 | } | |||
|
86 | ||||
|
87 | /*! | |||
|
88 | Returns the lower extreme value of the set. | |||
|
89 | */ | |||
|
90 | qreal QBoxSet::lowerExtreme() | |||
|
91 | { | |||
|
92 | return d_ptr->m_values.at(QBoxSetPrivate::PosLowerExtreme); | |||
|
93 | } | |||
|
94 | ||||
|
95 | /*! | |||
|
96 | Sets new value \a value as the lower quartile for the set. | |||
|
97 | */ | |||
|
98 | void QBoxSet::setLowerQuartile(const qreal value) | |||
|
99 | { | |||
|
100 | d_ptr->replace(QBoxSetPrivate::PosLowerQuartile, value); | |||
|
101 | emit valueChanged(QBoxSetPrivate::PosLowerQuartile); | |||
|
102 | } | |||
|
103 | ||||
|
104 | /*! | |||
|
105 | Returns the lower quartile value of the set. | |||
|
106 | */ | |||
|
107 | qreal QBoxSet::lowerQuartile() | |||
|
108 | { | |||
|
109 | return d_ptr->m_values.at(QBoxSetPrivate::PosLowerQuartile); | |||
|
110 | } | |||
|
111 | ||||
|
112 | /*! | |||
|
113 | Sets new value \a value as the median for the set. | |||
|
114 | */ | |||
|
115 | void QBoxSet::setMedian(const qreal value) | |||
|
116 | { | |||
|
117 | d_ptr->replace(QBoxSetPrivate::PosMedian, value); | |||
|
118 | emit valueChanged(QBoxSetPrivate::PosMedian); | |||
|
119 | } | |||
|
120 | ||||
|
121 | /*! | |||
|
122 | Returns the median value of the set. | |||
|
123 | */ | |||
|
124 | qreal QBoxSet::median() | |||
|
125 | { | |||
|
126 | return d_ptr->m_values.at(QBoxSetPrivate::PosMedian); | |||
|
127 | } | |||
|
128 | ||||
|
129 | /*! | |||
|
130 | Sets new value \a value as the upper quartile for the set. | |||
|
131 | */ | |||
|
132 | void QBoxSet::setUpperQuartile(const qreal value) | |||
|
133 | { | |||
|
134 | d_ptr->replace(QBoxSetPrivate::PosUpperQuartile, value); | |||
|
135 | emit valueChanged(QBoxSetPrivate::PosUpperQuartile); | |||
|
136 | } | |||
|
137 | ||||
|
138 | /*! | |||
|
139 | Returns the upper quartile value of the set. | |||
|
140 | */ | |||
|
141 | qreal QBoxSet::upperQuartile() | |||
|
142 | { | |||
|
143 | return d_ptr->m_values.at(QBoxSetPrivate::PosUpperQuartile); | |||
|
144 | } | |||
|
145 | ||||
|
146 | /*! | |||
|
147 | Sets new value \a value as the upper extreme for the set. | |||
|
148 | */ | |||
|
149 | void QBoxSet::setUpperExtreme(const qreal value) | |||
|
150 | { | |||
|
151 | d_ptr->replace(QBoxSetPrivate::PosUpperQuartile, value); | |||
|
152 | emit valueChanged(QBoxSetPrivate::PosUpperQuartile); | |||
|
153 | } | |||
|
154 | ||||
|
155 | /*! | |||
|
156 | Returns the upper extreme value of the set. | |||
|
157 | */ | |||
|
158 | qreal QBoxSet::upperExtreme() | |||
|
159 | { | |||
|
160 | return d_ptr->m_values.at(QBoxSetPrivate::PosUpperExtreme); | |||
|
161 | } | |||
|
162 | ||||
|
163 | /*! | |||
|
164 | Convenience operator. Same as append, with real \a value. | |||
|
165 | \sa append() | |||
|
166 | */ | |||
|
167 | QBoxSet &QBoxSet::operator << (const qreal &value) | |||
|
168 | { | |||
|
169 | append(value); | |||
|
170 | return *this; | |||
|
171 | } | |||
|
172 | ||||
|
173 | /*! | |||
|
174 | Inserts new \a value on the \a index position. | |||
|
175 | The value that is currently at this postion is moved to postion index + 1 | |||
|
176 | \sa remove() | |||
|
177 | */ | |||
|
178 | void QBoxSet::insert(const int index, const qreal value) | |||
|
179 | { | |||
|
180 | d_ptr->insert(index, value); | |||
|
181 | emit valuesAdded(index, 1); | |||
|
182 | } | |||
|
183 | ||||
|
184 | /*! | |||
|
185 | Removes \a count number of values from the set starting at \a index. | |||
|
186 | \sa insert() | |||
|
187 | */ | |||
|
188 | void QBoxSet::remove(const int index, const int count) | |||
|
189 | { | |||
|
190 | int removedCount = d_ptr->remove(index, count); | |||
|
191 | if (removedCount > 0) | |||
|
192 | emit valuesRemoved(index, removedCount); | |||
|
193 | return; | |||
|
194 | } | |||
|
195 | ||||
|
196 | /*! | |||
|
197 | Sets a new value \a value to set, indexed by \a index | |||
|
198 | */ | |||
|
199 | void QBoxSet::replace(const int index, const qreal value) | |||
|
200 | { | |||
|
201 | if (index >= 0 && index < d_ptr->m_values.count()) { | |||
|
202 | d_ptr->replace(index, value); | |||
|
203 | emit valueChanged(index); | |||
|
204 | } | |||
|
205 | } | |||
|
206 | ||||
|
207 | ||||
|
208 | /*! | |||
|
209 | Returns value of set indexed by \a index. | |||
|
210 | If the index is out of bounds 0.0 is returned. | |||
|
211 | */ | |||
|
212 | qreal QBoxSet::at(const int index) const | |||
|
213 | { | |||
|
214 | if (index < 0 || index >= d_ptr->m_values.count()) | |||
|
215 | return 0; | |||
|
216 | return d_ptr->m_values.at(index); | |||
|
217 | } | |||
|
218 | ||||
|
219 | /*! | |||
|
220 | Returns value of set indexed by \a index. | |||
|
221 | If the index is out of bounds 0.0 is returned. | |||
|
222 | */ | |||
|
223 | qreal QBoxSet::operator [](const int index) const | |||
|
224 | { | |||
|
225 | return at(index); | |||
|
226 | } | |||
|
227 | ||||
|
228 | /*! | |||
|
229 | Returns count of values in set. | |||
|
230 | */ | |||
|
231 | int QBoxSet::count() const | |||
|
232 | { | |||
|
233 | return d_ptr->m_values.count(); | |||
|
234 | } | |||
|
235 | ||||
|
236 | /*! | |||
|
237 | Sets pen for set. Boxes of this set are drawn using \a pen | |||
|
238 | */ | |||
|
239 | void QBoxSet::setPen(const QPen &pen) | |||
|
240 | { | |||
|
241 | if (d_ptr->m_pen != pen) { | |||
|
242 | d_ptr->m_pen = pen; | |||
|
243 | emit d_ptr->updatedBox(); | |||
|
244 | emit penChanged(); | |||
|
245 | } | |||
|
246 | } | |||
|
247 | ||||
|
248 | /*! | |||
|
249 | Returns pen of the set. | |||
|
250 | */ | |||
|
251 | QPen QBoxSet::pen() const | |||
|
252 | { | |||
|
253 | return d_ptr->m_pen; | |||
|
254 | } | |||
|
255 | ||||
|
256 | /*! | |||
|
257 | Sets brush for the set. Boxes of this set are drawn using \a brush | |||
|
258 | */ | |||
|
259 | void QBoxSet::setBrush(const QBrush &brush) | |||
|
260 | { | |||
|
261 | if (d_ptr->m_brush != brush) { | |||
|
262 | d_ptr->m_brush = brush; | |||
|
263 | emit d_ptr->updatedBox(); | |||
|
264 | emit brushChanged(); | |||
|
265 | } | |||
|
266 | } | |||
|
267 | ||||
|
268 | /*! | |||
|
269 | Returns brush of the set. | |||
|
270 | */ | |||
|
271 | QBrush QBoxSet::brush() const | |||
|
272 | { | |||
|
273 | return d_ptr->m_brush; | |||
|
274 | } | |||
|
275 | ||||
|
276 | /*! | |||
|
277 | Returns the color of the brush of boxset. | |||
|
278 | */ | |||
|
279 | QColor QBoxSet::color() | |||
|
280 | { | |||
|
281 | return brush().color(); | |||
|
282 | } | |||
|
283 | ||||
|
284 | /*! | |||
|
285 | Sets the \a color of brush for this boxset | |||
|
286 | */ | |||
|
287 | void QBoxSet::setColor(QColor color) | |||
|
288 | { | |||
|
289 | QBrush b = brush(); | |||
|
290 | if ((b.color() != color) || (b.style() == Qt::NoBrush)) { | |||
|
291 | b.setColor(color); | |||
|
292 | if (b.style() == Qt::NoBrush) { | |||
|
293 | // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush) | |||
|
294 | // This prevents theme to override color defined in QML side: | |||
|
295 | // BoxSet { label: "Bob"; color:"red"; values: [1,2,3] } | |||
|
296 | // The color must be obeyed, since user wanted it. | |||
|
297 | b.setStyle(Qt::SolidPattern); | |||
|
298 | } | |||
|
299 | setBrush(b); | |||
|
300 | emit colorChanged(color); | |||
|
301 | } | |||
|
302 | } | |||
|
303 | ||||
|
304 | /*! | |||
|
305 | Returns the color of pen of this boxset | |||
|
306 | */ | |||
|
307 | QColor QBoxSet::borderColor() | |||
|
308 | { | |||
|
309 | return pen().color(); | |||
|
310 | } | |||
|
311 | ||||
|
312 | /*! | |||
|
313 | Sets the color of pen for this boxset | |||
|
314 | */ | |||
|
315 | void QBoxSet::setBorderColor(QColor color) | |||
|
316 | { | |||
|
317 | QPen p = pen(); | |||
|
318 | if (p.color() != color) { | |||
|
319 | p.setColor(color); | |||
|
320 | setPen(p); | |||
|
321 | emit borderColorChanged(color); | |||
|
322 | } | |||
|
323 | } | |||
|
324 | ||||
|
325 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
326 | ||||
|
327 | QBoxSetPrivate::QBoxSetPrivate(QBoxSet *parent) : QObject(parent), | |||
|
328 | q_ptr(parent), | |||
|
329 | m_pen(QPen(Qt::NoPen)), | |||
|
330 | m_brush(QBrush(Qt::NoBrush)) | |||
|
331 | { | |||
|
332 | } | |||
|
333 | ||||
|
334 | QBoxSetPrivate::~QBoxSetPrivate() | |||
|
335 | { | |||
|
336 | } | |||
|
337 | ||||
|
338 | void QBoxSetPrivate::append(qreal value) | |||
|
339 | { | |||
|
340 | if (isValidValue(value)) { | |||
|
341 | m_values.append(value); | |||
|
342 | emit restructuredBox(); | |||
|
343 | } | |||
|
344 | } | |||
|
345 | ||||
|
346 | void QBoxSetPrivate::append(QList<qreal> values) | |||
|
347 | { | |||
|
348 | for (int i = 0; i < values.count(); i++) { | |||
|
349 | if (isValidValue(values.at(i))) | |||
|
350 | m_values.append(values.at(i)); | |||
|
351 | } | |||
|
352 | emit restructuredBox(); | |||
|
353 | } | |||
|
354 | ||||
|
355 | void QBoxSetPrivate::insert(const int index, const qreal value) | |||
|
356 | { | |||
|
357 | if (isValidValue(value)) { | |||
|
358 | m_values.insert(index, value); | |||
|
359 | emit restructuredBox(); | |||
|
360 | } | |||
|
361 | } | |||
|
362 | ||||
|
363 | int QBoxSetPrivate::remove(const int index, const int count) | |||
|
364 | { | |||
|
365 | int removeCount = count; | |||
|
366 | ||||
|
367 | if ((index < 0) || (m_values.count() == 0)) | |||
|
368 | return 0; // Invalid index or not values in list, remove nothing. | |||
|
369 | else if ((index + count) > m_values.count()) | |||
|
370 | removeCount = m_values.count() - index; // Trying to remove more items than list has. Limit amount to be removed. | |||
|
371 | ||||
|
372 | int c = 0; | |||
|
373 | while (c < removeCount) { | |||
|
374 | m_values.removeAt(index); | |||
|
375 | c++; | |||
|
376 | } | |||
|
377 | emit restructuredBox(); | |||
|
378 | return removeCount; | |||
|
379 | } | |||
|
380 | ||||
|
381 | void QBoxSetPrivate::replace(const int index, const qreal value) | |||
|
382 | { | |||
|
383 | m_values.replace(index, value); | |||
|
384 | emit updatedLayout(); | |||
|
385 | } | |||
|
386 | ||||
|
387 | qreal QBoxSetPrivate::value(const int index) | |||
|
388 | { | |||
|
389 | if (index < 0 || index >= m_values.count()) | |||
|
390 | return 0; | |||
|
391 | return m_values.at(index); | |||
|
392 | } | |||
|
393 | ||||
|
394 | #include "moc_qboxset.cpp" | |||
|
395 | #include "moc_qboxset_p.cpp" | |||
|
396 | ||||
|
397 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,104 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2013 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #ifndef QBOXSET_H | |||
|
22 | #define QBOXSET_H | |||
|
23 | ||||
|
24 | #include <qchartglobal.h> | |||
|
25 | #include <QPen> | |||
|
26 | #include <QBrush> | |||
|
27 | #include <QFont> | |||
|
28 | ||||
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
30 | class QBoxSetPrivate; | |||
|
31 | ||||
|
32 | class QTCOMMERCIALCHART_EXPORT QBoxSet : public QObject | |||
|
33 | { | |||
|
34 | Q_OBJECT | |||
|
35 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) | |||
|
36 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) | |||
|
37 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) | |||
|
38 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) | |||
|
39 | ||||
|
40 | public: | |||
|
41 | explicit QBoxSet(QObject *parent = 0); | |||
|
42 | explicit QBoxSet(qreal value1, qreal value2, qreal value3, qreal value4, qreal value5, QObject *parent = 0); | |||
|
43 | virtual ~QBoxSet(); | |||
|
44 | ||||
|
45 | void append(const qreal value); | |||
|
46 | void append(const QList<qreal> &values); | |||
|
47 | ||||
|
48 | void setLowerExtreme(const qreal value); | |||
|
49 | qreal lowerExtreme(); | |||
|
50 | void setLowerQuartile(const qreal value); | |||
|
51 | qreal lowerQuartile(); | |||
|
52 | void setMedian(const qreal value); | |||
|
53 | qreal median(); | |||
|
54 | void setUpperQuartile(const qreal value); | |||
|
55 | qreal upperQuartile(); | |||
|
56 | void setUpperExtreme(const qreal value); | |||
|
57 | qreal upperExtreme(); | |||
|
58 | ||||
|
59 | QBoxSet &operator << (const qreal &value); | |||
|
60 | ||||
|
61 | void insert(const int index, const qreal value); | |||
|
62 | void remove(const int index, const int count = 1); | |||
|
63 | void replace(const int index, const qreal value); | |||
|
64 | qreal at(const int index) const; | |||
|
65 | qreal operator [](const int index) const; | |||
|
66 | int count() const; | |||
|
67 | ||||
|
68 | void setPen(const QPen &pen); | |||
|
69 | QPen pen() const; | |||
|
70 | ||||
|
71 | void setBrush(const QBrush &brush); | |||
|
72 | QBrush brush() const; | |||
|
73 | ||||
|
74 | QColor color(); | |||
|
75 | void setColor(QColor color); | |||
|
76 | ||||
|
77 | QColor borderColor(); | |||
|
78 | void setBorderColor(QColor color); | |||
|
79 | ||||
|
80 | ||||
|
81 | Q_SIGNALS: | |||
|
82 | void clicked(int index); | |||
|
83 | void hovered(bool status); | |||
|
84 | void penChanged(); | |||
|
85 | void brushChanged(); | |||
|
86 | void colorChanged(QColor color); | |||
|
87 | void borderColorChanged(QColor color); | |||
|
88 | ||||
|
89 | void valuesAdded(int index, int count); | |||
|
90 | void valuesRemoved(int index, int count); | |||
|
91 | void valueChanged(int index); | |||
|
92 | ||||
|
93 | private: | |||
|
94 | QScopedPointer<QBoxSetPrivate> d_ptr; | |||
|
95 | Q_DISABLE_COPY(QBoxSet) | |||
|
96 | friend class BarLegendMarker; | |||
|
97 | friend class BarChartItem; | |||
|
98 | friend class BoxPlotChartItem; | |||
|
99 | friend class QBoxPlotSeriesPrivate; | |||
|
100 | }; | |||
|
101 | ||||
|
102 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
103 | ||||
|
104 | #endif // QBOXSET_H |
@@ -0,0 +1,87 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2013 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | // W A R N I N G | |||
|
22 | // ------------- | |||
|
23 | // | |||
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |||
|
25 | // implementation detail. This header file may change from version to | |||
|
26 | // version without notice, or even be removed. | |||
|
27 | // | |||
|
28 | // We mean it. | |||
|
29 | ||||
|
30 | #ifndef QBOXSET_P_H | |||
|
31 | #define QBOXSET_P_H | |||
|
32 | ||||
|
33 | #include "qboxset.h" | |||
|
34 | #include <QMap> | |||
|
35 | #include <QPen> | |||
|
36 | #include <QBrush> | |||
|
37 | #include <QFont> | |||
|
38 | ||||
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
40 | ||||
|
41 | class QBoxSetPrivate : public QObject | |||
|
42 | { | |||
|
43 | Q_OBJECT | |||
|
44 | ||||
|
45 | public: | |||
|
46 | enum DataPositions { | |||
|
47 | PosLowerExtreme, | |||
|
48 | PosLowerQuartile, | |||
|
49 | PosMedian, | |||
|
50 | PosUpperQuartile, | |||
|
51 | PosUpperExtreme | |||
|
52 | }; | |||
|
53 | ||||
|
54 | public: | |||
|
55 | QBoxSetPrivate(QBoxSet *parent); | |||
|
56 | ~QBoxSetPrivate(); | |||
|
57 | ||||
|
58 | void append(qreal value); | |||
|
59 | void append(QList<qreal> values); | |||
|
60 | ||||
|
61 | void insert(const int index, const qreal value); | |||
|
62 | int remove(const int index, const int count); | |||
|
63 | ||||
|
64 | void replace(const int index, const qreal value); | |||
|
65 | ||||
|
66 | qreal value(const int index); | |||
|
67 | ||||
|
68 | Q_SIGNALS: | |||
|
69 | void restructuredBox(); | |||
|
70 | void updatedBox(); | |||
|
71 | void updatedLayout(); | |||
|
72 | ||||
|
73 | public: | |||
|
74 | QBoxSet * const q_ptr; | |||
|
75 | //QString m_label; | |||
|
76 | QList<qreal> m_values; | |||
|
77 | QPen m_pen; | |||
|
78 | QBrush m_brush; | |||
|
79 | QBrush m_labelBrush; | |||
|
80 | QFont m_labelFont; | |||
|
81 | ||||
|
82 | friend class QBoxSet; | |||
|
83 | }; | |||
|
84 | ||||
|
85 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
86 | ||||
|
87 | #endif // QBOXSET_P_H |
@@ -1,137 +1,151 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QBoxPlotSeries> |
|
24 | #include <QBoxPlotSeries> | |
25 |
#include <QB |
|
25 | #include <QBoxSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 | #include <QBarCategoryAxis> |
|
27 | #include <QBarCategoryAxis> | |
28 | #include <QLineSeries> |
|
28 | #include <QLineSeries> | |
|
29 | #include <QScatterSeries> | |||
29 |
|
30 | |||
30 | #include <QBrush> |
|
31 | #include <QBrush> | |
31 | #include <QColor> |
|
32 | #include <QColor> | |
32 |
|
33 | |||
33 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
34 | QTCOMMERCIALCHART_USE_NAMESPACE | |
34 |
|
35 | |||
35 | int main(int argc, char *argv[]) |
|
36 | int main(int argc, char *argv[]) | |
36 | { |
|
37 | { | |
37 | QApplication a(argc, argv); |
|
38 | QApplication a(argc, argv); | |
38 |
|
39 | |||
39 | //![1] |
|
40 | //![1] | |
40 |
QB |
|
41 | QBoxSet *set0 = new QBoxSet(); | |
41 |
QB |
|
42 | QBoxSet *set1 = new QBoxSet(); | |
42 |
QB |
|
43 | QBoxSet *set2 = new QBoxSet(); | |
43 |
QB |
|
44 | QBoxSet *set3 = new QBoxSet(); | |
44 |
QB |
|
45 | QBoxSet *set4 = new QBoxSet(); | |
45 |
QB |
|
46 | QBoxSet *set5 = new QBoxSet(); | |
46 |
QB |
|
47 | QBoxSet *set6 = new QBoxSet(); | |
47 |
QB |
|
48 | QBoxSet *set7 = new QBoxSet(); | |
48 |
QB |
|
49 | QBoxSet *set8 = new QBoxSet(); | |
49 |
QB |
|
50 | QBoxSet *set9 = new QBoxSet(); | |
50 |
QB |
|
51 | QBoxSet *set10 = new QBoxSet(); | |
51 |
QB |
|
52 | QBoxSet *set11 = new QBoxSet(); | |
52 |
|
53 | |||
53 | // low bot med top upp |
|
54 | // low bot med top upp | |
54 | *set0 << 3 << 4 << 4.4 << 6 << 7; |
|
55 | *set0 << 3 << 4 << 4.4 << 6 << 7; | |
55 | *set1 << 5 << 6 << 7.5 << 8 << 12; |
|
56 | *set1 << 5 << 6 << 7.5 << 8 << 12; | |
56 | *set2 << 3 << 5 << 5.7 << 8 << 9; |
|
57 | *set2 << 3 << 5 << 5.7 << 8 << 9; | |
57 | *set3 << 5 << 6 << 6.8 << 7 << 8; |
|
58 | *set3 << 5 << 6 << 6.8 << 7 << 8; | |
58 | *set4 << 4 << 5 << 5.2 << 6 << 7; |
|
59 | *set4 << 4 << 5 << 5.2 << 6 << 7; | |
59 | *set5 << 4 << 7 << 8.2 << 9 << 10; |
|
60 | *set5 << 4 << 7 << 8.2 << 9 << 10; | |
60 | *set6 << 2.5 << 5 << 5.4 << 6 << 7; |
|
61 | *set6 << 2.5 << 5 << 5.4 << 6 << 7; | |
61 | *set7 << 5 << 6.3 << 7.5 << 8 << 12; |
|
62 | *set7 << 5 << 6.3 << 7.5 << 8 << 12; | |
62 | *set8 << 2.6 << 5.1 << 5.7 << 8 << 9; |
|
63 | *set8 << 2.6 << 5.1 << 5.7 << 8 << 9; | |
63 | *set9 << 3.1 << 5.8 << 6.8 << 7 << 8; |
|
64 | *set9 << 3.1 << 5.8 << 6.8 << 7 << 8; | |
64 | *set10 << 4.2 << 5 << 5.8 << 6 << 7; |
|
65 | *set10 << 4.2 << 5 << 5.8 << 6 << 7; | |
65 | *set11 << 4.7 << 7 << 8.2 << 9 << 10; |
|
66 | *set11 << 4.7 << 7 << 8.2 << 9 << 10; | |
66 |
|
67 | |||
67 | //![1] |
|
68 | //![1] | |
68 |
|
69 | |||
69 | //![2] |
|
70 | //![2] | |
70 | QBoxPlotSeries *series = new QBoxPlotSeries(); |
|
71 | QBoxPlotSeries *series = new QBoxPlotSeries(); | |
71 | series->append(set0); |
|
72 | series->append(set0); | |
72 | series->append(set1); |
|
73 | series->append(set1); | |
73 | series->append(set2); |
|
74 | series->append(set2); | |
74 | series->append(set3); |
|
75 | series->append(set3); | |
75 | series->append(set4); |
|
76 | series->append(set4); | |
76 | series->append(set5); |
|
77 | series->append(set5); | |
77 | series->append(set6); |
|
78 | series->append(set6); | |
78 | series->append(set7); |
|
79 | series->append(set7); | |
79 | series->append(set8); |
|
80 | series->append(set8); | |
80 | series->append(set9); |
|
81 | series->append(set9); | |
81 | series->append(set10); |
|
82 | series->append(set10); | |
82 | series->append(set11); |
|
83 | series->append(set11); | |
83 | series->setName("Box & Whiskers"); |
|
84 | series->setName("Box & Whiskers"); | |
84 | //![2] |
|
85 | //![2] | |
85 |
|
86 | |||
86 | QLineSeries *lineSeries = new QLineSeries(); |
|
87 | QLineSeries *lineSeries = new QLineSeries(); | |
87 | lineSeries->append(0, 4.4); |
|
88 | lineSeries->append(0, 4.4); | |
88 | lineSeries->append(1, 7.5); |
|
89 | lineSeries->append(1, 7.5); | |
89 | lineSeries->append(2, 5.7); |
|
90 | lineSeries->append(2, 5.7); | |
90 | lineSeries->append(3, 6.8); |
|
91 | lineSeries->append(3, 6.8); | |
91 | lineSeries->append(4, 5.2); |
|
92 | lineSeries->append(4, 5.2); | |
92 | lineSeries->append(5, 8.2); |
|
93 | lineSeries->append(5, 8.2); | |
93 | lineSeries->append(6, 5.4); |
|
94 | lineSeries->append(6, 5.4); | |
94 | lineSeries->append(7, 7.5); |
|
95 | lineSeries->append(7, 7.5); | |
95 | lineSeries->append(8, 5.7); |
|
96 | lineSeries->append(8, 5.7); | |
96 | lineSeries->append(9, 6.8); |
|
97 | lineSeries->append(9, 6.8); | |
97 | lineSeries->append(10, 5.2); |
|
98 | lineSeries->append(10, 5.2); | |
98 | lineSeries->append(11, 8.2); |
|
99 | lineSeries->append(11, 8.2); | |
99 | lineSeries->setName("Medians"); |
|
100 | lineSeries->setName("Medians"); | |
100 |
|
101 | |||
|
102 | QScatterSeries *scatterSeries = new QScatterSeries(); | |||
|
103 | scatterSeries->setName("Outliers"); | |||
|
104 | scatterSeries->setMarkerShape(QScatterSeries::MarkerShapeCircle); | |||
|
105 | scatterSeries->setMarkerSize(7.0); | |||
|
106 | scatterSeries->setBrush(QBrush(Qt::white)); | |||
|
107 | scatterSeries->setPen(QPen(Qt::black, 1.0)); | |||
|
108 | scatterSeries->append(1, 4); | |||
|
109 | scatterSeries->append(1, 4.1); | |||
|
110 | scatterSeries->append(1, 4.2); | |||
|
111 | scatterSeries->append(1, 4.3); | |||
|
112 | *scatterSeries << QPointF(3, 8.5) << QPointF(3, 8.6); | |||
|
113 | ||||
101 | //![3] |
|
114 | //![3] | |
102 | QChart *chart = new QChart(); |
|
115 | QChart *chart = new QChart(); | |
103 | chart->addSeries(series); |
|
116 | chart->addSeries(series); | |
104 | chart->addSeries(lineSeries); |
|
117 | chart->addSeries(lineSeries); | |
|
118 | chart->addSeries(scatterSeries); | |||
105 | chart->setTitle("Simple boxplotchart example"); |
|
119 | chart->setTitle("Simple boxplotchart example"); | |
106 | chart->setAnimationOptions(QChart::SeriesAnimations); |
|
120 | chart->setAnimationOptions(QChart::SeriesAnimations); | |
107 | //![3] |
|
121 | //![3] | |
108 |
|
122 | |||
109 | //![4] |
|
123 | //![4] | |
110 | QStringList categories; |
|
124 | QStringList categories; | |
111 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
125 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
112 | QBarCategoryAxis *axis = new QBarCategoryAxis(); |
|
126 | QBarCategoryAxis *axis = new QBarCategoryAxis(); | |
113 | axis->append(categories); |
|
127 | axis->append(categories); | |
114 | chart->createDefaultAxes(); |
|
128 | chart->createDefaultAxes(); | |
115 | chart->setAxisX(axis, series); |
|
129 | chart->setAxisX(axis, series); | |
116 | //![4] |
|
130 | //![4] | |
117 |
|
131 | |||
118 | //![5] |
|
132 | //![5] | |
119 | chart->legend()->setVisible(true); |
|
133 | chart->legend()->setVisible(true); | |
120 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
134 | chart->legend()->setAlignment(Qt::AlignBottom); | |
121 | //![5] |
|
135 | //![5] | |
122 |
|
136 | |||
123 | //![6] |
|
137 | //![6] | |
124 | QChartView *chartView = new QChartView(chart); |
|
138 | QChartView *chartView = new QChartView(chart); | |
125 | chartView->setRenderHint(QPainter::Antialiasing); |
|
139 | chartView->setRenderHint(QPainter::Antialiasing); | |
126 | //![6] |
|
140 | //![6] | |
127 |
|
141 | |||
128 | //![7] |
|
142 | //![7] | |
129 | QMainWindow window; |
|
143 | QMainWindow window; | |
130 | window.setCentralWidget(chartView); |
|
144 | window.setCentralWidget(chartView); | |
131 |
window.resize( |
|
145 | window.resize(600, 400); | |
132 | window.show(); |
|
146 | window.show(); | |
133 | //![7] |
|
147 | //![7] | |
134 |
|
148 | |||
135 | return a.exec(); |
|
149 | return a.exec(); | |
136 | } |
|
150 | } | |
137 |
|
151 |
@@ -1,49 +1,49 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | //![1] |
|
21 | //![1] | |
22 | import QtQuick 1.0 |
|
22 | import QtQuick 1.0 | |
23 | import QtCommercial.Chart 1.1 |
|
23 | import QtCommercial.Chart 1.1 | |
24 |
|
24 | |||
25 | ChartView { |
|
25 | ChartView { | |
26 | title: "Box Plot series" |
|
26 | title: "Box Plot series" | |
27 | width: 400 |
|
27 | width: 400 | |
28 | height: 300 |
|
28 | height: 300 | |
29 | theme: ChartView.ChartThemeBrownSand |
|
29 | theme: ChartView.ChartThemeBrownSand | |
30 | legend.alignment: Qt.AlignBottom |
|
30 | legend.alignment: Qt.AlignBottom | |
31 |
|
31 | |||
32 | //![1] |
|
32 | //![1] | |
33 | //![2] |
|
33 | //![2] | |
34 | BoxPlotSeries { |
|
34 | BoxPlotSeries { | |
35 | id: plotSeries |
|
35 | id: plotSeries | |
36 | name: "Income" |
|
36 | name: "Income" | |
37 | axisX: BarCategoryAxis { categories: ["Jan", "Feb", "Mar", "Apr", "May"] } |
|
37 | axisX: BarCategoryAxis { categories: ["Jan", "Feb", "Mar", "Apr", "May"] } | |
38 |
B |
|
38 | BoxSet { values: [3, 4, 4.4, 6, 7] } | |
39 |
B |
|
39 | BoxSet { values: [5, 6, 7.5, 8, 12] } | |
40 |
B |
|
40 | BoxSet { values: [2, 5, 5.7, 8, 9] } | |
41 |
B |
|
41 | BoxSet { values: [5, 6, 6.8, 7, 8] } | |
42 |
B |
|
42 | BoxSet { values: [4, 5, 5.2, 6, 7] } | |
43 | } |
|
43 | } | |
44 | //![2] |
|
44 | //![2] | |
45 |
|
45 | |||
46 |
|
46 | |||
47 | //![3] |
|
47 | //![3] | |
48 | } |
|
48 | } | |
49 | //![3] |
|
49 | //![3] |
@@ -1,93 +1,126 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "declarativebarseries.h" |
|
21 | #include "declarativebarseries.h" | |
22 | #include "declarativeboxplotseries.h" |
|
22 | #include "declarativeboxplotseries.h" | |
23 |
#include "qb |
|
23 | #include "qboxset.h" | |
24 | #include "qvbarmodelmapper.h" |
|
24 | #include "qvbarmodelmapper.h" | |
25 | #include "qhbarmodelmapper.h" |
|
25 | #include "qhbarmodelmapper.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
|
29 | DeclarativeBoxSet::DeclarativeBoxSet(QObject *parent) | |||
|
30 | : QBoxSet(parent) | |||
|
31 | { | |||
|
32 | connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int,int))); | |||
|
33 | connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int,int))); | |||
|
34 | } | |||
|
35 | ||||
|
36 | void DeclarativeBoxSet::handleCountChanged(int index, int count) | |||
|
37 | { | |||
|
38 | Q_UNUSED(index) | |||
|
39 | Q_UNUSED(count) | |||
|
40 | emit countChanged(QBoxSet::count()); | |||
|
41 | } | |||
|
42 | ||||
|
43 | QVariantList DeclarativeBoxSet::values() | |||
|
44 | { | |||
|
45 | QVariantList values; | |||
|
46 | for (int i(0); i < count(); i++) | |||
|
47 | values.append(QVariant(QBoxSet::at(i))); | |||
|
48 | return values; | |||
|
49 | } | |||
|
50 | ||||
|
51 | void DeclarativeBoxSet::setValues(QVariantList values) | |||
|
52 | { | |||
|
53 | while (count()) | |||
|
54 | remove(count() - 1); | |||
|
55 | ||||
|
56 | for (int i(0); i < values.count(); i++) { | |||
|
57 | if (values.at(i).canConvert(QVariant::Double)) | |||
|
58 | QBoxSet::append(values[i].toDouble()); | |||
|
59 | } | |||
|
60 | } | |||
|
61 | ||||
|
62 | ||||
29 | DeclarativeBoxPlotSeries::DeclarativeBoxPlotSeries(QDeclarativeItem *parent) : |
|
63 | DeclarativeBoxPlotSeries::DeclarativeBoxPlotSeries(QDeclarativeItem *parent) : | |
30 | QBoxPlotSeries(parent), |
|
64 | QBoxPlotSeries(parent), | |
31 | m_axes(new DeclarativeAxes(this)) |
|
65 | m_axes(new DeclarativeAxes(this)) | |
32 | { |
|
66 | { | |
33 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); |
|
67 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); | |
34 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); |
|
68 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); | |
35 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
|
69 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); | |
36 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
|
70 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); | |
37 | } |
|
71 | } | |
38 |
|
72 | |||
39 | void DeclarativeBoxPlotSeries::classBegin() |
|
73 | void DeclarativeBoxPlotSeries::classBegin() | |
40 | { |
|
74 | { | |
41 | } |
|
75 | } | |
42 |
|
76 | |||
43 | void DeclarativeBoxPlotSeries::componentComplete() |
|
77 | void DeclarativeBoxPlotSeries::componentComplete() | |
44 | { |
|
78 | { | |
45 | foreach (QObject *child, children()) { |
|
79 | foreach (QObject *child, children()) { | |
46 |
if (qobject_cast<DeclarativeB |
|
80 | if (qobject_cast<DeclarativeBoxSet *>(child)) { | |
47 |
Q |
|
81 | QBoxPlotSeries::append(qobject_cast<DeclarativeBoxSet *>(child)); | |
48 | } else if (qobject_cast<QVBarModelMapper *>(child)) { |
|
82 | } else if (qobject_cast<QVBarModelMapper *>(child)) { | |
49 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
83 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
50 | mapper->setSeries(this); |
|
84 | //mapper->setSeries(this); | |
51 | } else if (qobject_cast<QHBarModelMapper *>(child)) { |
|
85 | } else if (qobject_cast<QHBarModelMapper *>(child)) { | |
52 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
86 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
53 | mapper->setSeries(this); |
|
87 | //mapper->setSeries(this); | |
54 | } |
|
88 | } | |
55 | } |
|
89 | } | |
56 | } |
|
90 | } | |
57 |
|
91 | |||
58 | QDeclarativeListProperty<QObject> DeclarativeBoxPlotSeries::seriesChildren() |
|
92 | QDeclarativeListProperty<QObject> DeclarativeBoxPlotSeries::seriesChildren() | |
59 | { |
|
93 | { | |
60 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBoxPlotSeries::appendSeriesChildren); |
|
94 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBoxPlotSeries::appendSeriesChildren); | |
61 | } |
|
95 | } | |
62 |
|
96 | |||
63 | void DeclarativeBoxPlotSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
97 | void DeclarativeBoxPlotSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
64 | { |
|
98 | { | |
65 | // Empty implementation; the children are parsed in componentComplete instead |
|
99 | // Empty implementation; the children are parsed in componentComplete instead | |
66 | Q_UNUSED(list); |
|
100 | Q_UNUSED(list); | |
67 | Q_UNUSED(element); |
|
101 | Q_UNUSED(element); | |
68 | } |
|
102 | } | |
69 |
|
103 | |||
70 |
DeclarativeB |
|
104 | DeclarativeBoxSet *DeclarativeBoxPlotSeries::at(int index) | |
71 | { |
|
105 | { | |
72 |
QList<QB |
|
106 | QList<QBoxSet *> setList = boxSets(); | |
73 | if (index >= 0 && index < setList.count()) |
|
107 | if (index >= 0 && index < setList.count()) | |
74 |
return qobject_cast<DeclarativeB |
|
108 | return qobject_cast<DeclarativeBoxSet *>(setList[index]); | |
75 |
|
109 | |||
76 | return 0; |
|
110 | return 0; | |
77 | } |
|
111 | } | |
78 |
|
112 | |||
79 |
DeclarativeB |
|
113 | DeclarativeBoxSet *DeclarativeBoxPlotSeries::insert(int index, QVariantList values) | |
80 | { |
|
114 | { | |
81 |
DeclarativeB |
|
115 | DeclarativeBoxSet *barset = new DeclarativeBoxSet(this); | |
82 | barset->setLabel(label); |
|
|||
83 | barset->setValues(values); |
|
116 | barset->setValues(values); | |
84 | if (QBoxPlotSeries::insert(index, barset)) |
|
117 | if (QBoxPlotSeries::insert(index, barset)) | |
85 | return barset; |
|
118 | return barset; | |
86 | delete barset; |
|
119 | delete barset; | |
87 | return 0; |
|
120 | return 0; | |
88 | } |
|
121 | } | |
89 |
|
122 | |||
90 |
|
123 | |||
91 | #include "moc_declarativeboxplotseries.cpp" |
|
124 | #include "moc_declarativeboxplotseries.cpp" | |
92 |
|
125 | |||
93 | QTCOMMERCIALCHART_END_NAMESPACE |
|
126 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,81 +1,105 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef DECLARATIVEBOXPLOT_H |
|
21 | #ifndef DECLARATIVEBOXPLOT_H | |
22 | #define DECLARATIVEBOXPLOT_H |
|
22 | #define DECLARATIVEBOXPLOT_H | |
23 |
|
23 | |||
24 |
#include "qb |
|
24 | #include "qboxset.h" | |
25 | #include "declarativeaxes.h" |
|
25 | #include "declarativeaxes.h" | |
26 | #include "qboxplotseries.h" |
|
26 | #include "qboxplotseries.h" | |
27 | #include <QtDeclarative/QDeclarativeItem> |
|
27 | #include <QtDeclarative/QDeclarativeItem> | |
28 | #include <QtDeclarative/QDeclarativeParserStatus> |
|
28 | #include <QtDeclarative/QDeclarativeParserStatus> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
|
32 | class DeclarativeBoxSet : public QBoxSet | |||
|
33 | { | |||
|
34 | Q_OBJECT | |||
|
35 | Q_PROPERTY(QVariantList values READ values WRITE setValues) | |||
|
36 | Q_PROPERTY(int count READ count NOTIFY countChanged) | |||
|
37 | ||||
|
38 | public: | |||
|
39 | explicit DeclarativeBoxSet(QObject *parent = 0); | |||
|
40 | QVariantList values(); | |||
|
41 | void setValues(QVariantList values); | |||
|
42 | ||||
|
43 | public: // From QBoxSet | |||
|
44 | Q_INVOKABLE void append(qreal value) { QBoxSet::append(value); } | |||
|
45 | Q_INVOKABLE void remove(const int index, const int count = 1) { QBoxSet::remove(index, count); } | |||
|
46 | Q_INVOKABLE void replace(int index, qreal value) { QBoxSet::replace(index, value); } | |||
|
47 | Q_INVOKABLE qreal at(int index) { return QBoxSet::at(index); } | |||
|
48 | ||||
|
49 | Q_SIGNALS: | |||
|
50 | void countChanged(int count); | |||
|
51 | ||||
|
52 | private Q_SLOTS: | |||
|
53 | void handleCountChanged(int index, int count); | |||
|
54 | }; | |||
|
55 | ||||
32 | class DeclarativeBoxPlotSeries : public QBoxPlotSeries, public QDeclarativeParserStatus |
|
56 | class DeclarativeBoxPlotSeries : public QBoxPlotSeries, public QDeclarativeParserStatus | |
33 | { |
|
57 | { | |
34 | Q_OBJECT |
|
58 | Q_OBJECT | |
35 | Q_INTERFACES(QDeclarativeParserStatus) |
|
59 | Q_INTERFACES(QDeclarativeParserStatus) | |
36 | Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged REVISION 1) |
|
60 | Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged REVISION 1) | |
37 | Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1) |
|
61 | Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1) | |
38 | Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2) |
|
62 | Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2) | |
39 | Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2) |
|
63 | Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2) | |
40 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
64 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) | |
41 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
65 | Q_CLASSINFO("DefaultProperty", "seriesChildren") | |
42 |
|
66 | |||
43 | public: |
|
67 | public: | |
44 | explicit DeclarativeBoxPlotSeries(QDeclarativeItem *parent = 0); |
|
68 | explicit DeclarativeBoxPlotSeries(QDeclarativeItem *parent = 0); | |
45 | QAbstractAxis *axisX() { return m_axes->axisX(); } |
|
69 | QAbstractAxis *axisX() { return m_axes->axisX(); } | |
46 | void setAxisX(QAbstractAxis *axis) { m_axes->setAxisX(axis); } |
|
70 | void setAxisX(QAbstractAxis *axis) { m_axes->setAxisX(axis); } | |
47 | QAbstractAxis *axisY() { return m_axes->axisY(); } |
|
71 | QAbstractAxis *axisY() { return m_axes->axisY(); } | |
48 | void setAxisY(QAbstractAxis *axis) { m_axes->setAxisY(axis); } |
|
72 | void setAxisY(QAbstractAxis *axis) { m_axes->setAxisY(axis); } | |
49 | Q_REVISION(2) QAbstractAxis *axisXTop() { return m_axes->axisXTop(); } |
|
73 | Q_REVISION(2) QAbstractAxis *axisXTop() { return m_axes->axisXTop(); } | |
50 | Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); } |
|
74 | Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); } | |
51 | Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); } |
|
75 | Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); } | |
52 | Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); } |
|
76 | Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); } | |
53 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
77 | QDeclarativeListProperty<QObject> seriesChildren(); | |
54 |
|
78 | |||
55 | public: |
|
79 | public: | |
56 |
Q_INVOKABLE DeclarativeB |
|
80 | Q_INVOKABLE DeclarativeBoxSet *at(int index); | |
57 |
Q_INVOKABLE DeclarativeB |
|
81 | Q_INVOKABLE DeclarativeBoxSet *append(QVariantList values) { return insert(count(), values); } | |
58 |
Q_INVOKABLE DeclarativeB |
|
82 | Q_INVOKABLE DeclarativeBoxSet *insert(int index, QVariantList values); | |
59 |
Q_INVOKABLE bool remove(QB |
|
83 | Q_INVOKABLE bool remove(QBoxSet *boxset) { return QBoxPlotSeries::remove(boxset); } | |
60 | Q_INVOKABLE void clear() { return QBoxPlotSeries::clear(); } |
|
84 | Q_INVOKABLE void clear() { return QBoxPlotSeries::clear(); } | |
61 |
|
85 | |||
62 | public: // from QDeclarativeParserStatus |
|
86 | public: // from QDeclarativeParserStatus | |
63 | void classBegin(); |
|
87 | void classBegin(); | |
64 | void componentComplete(); |
|
88 | void componentComplete(); | |
65 |
|
89 | |||
66 | Q_SIGNALS: |
|
90 | Q_SIGNALS: | |
67 | Q_REVISION(1) void axisXChanged(QAbstractAxis *axis); |
|
91 | Q_REVISION(1) void axisXChanged(QAbstractAxis *axis); | |
68 | Q_REVISION(1) void axisYChanged(QAbstractAxis *axis); |
|
92 | Q_REVISION(1) void axisYChanged(QAbstractAxis *axis); | |
69 | Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis); |
|
93 | Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis); | |
70 | Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis); |
|
94 | Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis); | |
71 |
|
95 | |||
72 | public Q_SLOTS: |
|
96 | public Q_SLOTS: | |
73 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
97 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); | |
74 |
|
98 | |||
75 | public: |
|
99 | public: | |
76 | DeclarativeAxes *m_axes; |
|
100 | DeclarativeAxes *m_axes; | |
77 | }; |
|
101 | }; | |
78 |
|
102 | |||
79 | QTCOMMERCIALCHART_END_NAMESPACE |
|
103 | QTCOMMERCIALCHART_END_NAMESPACE | |
80 |
|
104 | |||
81 | #endif // DECLARATIVEBOXPLOT_H |
|
105 | #endif // DECLARATIVEBOXPLOT_H |
@@ -1,232 +1,233 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "qvalueaxis.h" |
|
23 | #include "qvalueaxis.h" | |
24 | #include "declarativecategoryaxis.h" |
|
24 | #include "declarativecategoryaxis.h" | |
25 | #include "qbarcategoryaxis.h" |
|
25 | #include "qbarcategoryaxis.h" | |
26 | #include "declarativechart.h" |
|
26 | #include "declarativechart.h" | |
27 | #include "declarativexypoint.h" |
|
27 | #include "declarativexypoint.h" | |
28 | #include "declarativelineseries.h" |
|
28 | #include "declarativelineseries.h" | |
29 | #include "declarativesplineseries.h" |
|
29 | #include "declarativesplineseries.h" | |
30 | #include "declarativeareaseries.h" |
|
30 | #include "declarativeareaseries.h" | |
31 | #include "declarativescatterseries.h" |
|
31 | #include "declarativescatterseries.h" | |
32 | #include "declarativebarseries.h" |
|
32 | #include "declarativebarseries.h" | |
33 | #include "declarativeboxplotseries.h" |
|
33 | #include "declarativeboxplotseries.h" | |
34 | #include "declarativepieseries.h" |
|
34 | #include "declarativepieseries.h" | |
35 | #include "declarativeaxes.h" |
|
35 | #include "declarativeaxes.h" | |
36 | #include "qvxymodelmapper.h" |
|
36 | #include "qvxymodelmapper.h" | |
37 | #include "qhxymodelmapper.h" |
|
37 | #include "qhxymodelmapper.h" | |
38 | #include "qhpiemodelmapper.h" |
|
38 | #include "qhpiemodelmapper.h" | |
39 | #include "qvpiemodelmapper.h" |
|
39 | #include "qvpiemodelmapper.h" | |
40 | #include "qhbarmodelmapper.h" |
|
40 | #include "qhbarmodelmapper.h" | |
41 | #include "qvbarmodelmapper.h" |
|
41 | #include "qvbarmodelmapper.h" | |
42 | #include "declarativemargins.h" |
|
42 | #include "declarativemargins.h" | |
43 | #include "qarealegendmarker.h" |
|
43 | #include "qarealegendmarker.h" | |
44 | #include "qbarlegendmarker.h" |
|
44 | #include "qbarlegendmarker.h" | |
45 | #include "qpielegendmarker.h" |
|
45 | #include "qpielegendmarker.h" | |
46 | #include "qxylegendmarker.h" |
|
46 | #include "qxylegendmarker.h" | |
47 | #ifndef QT_ON_ARM |
|
47 | #ifndef QT_ON_ARM | |
48 | #include "qdatetimeaxis.h" |
|
48 | #include "qdatetimeaxis.h" | |
49 | #endif |
|
49 | #endif | |
50 | #include <QAbstractItemModel> |
|
50 | #include <QAbstractItemModel> | |
51 | #include <QtDeclarative/qdeclarativeextensionplugin.h> |
|
51 | #include <QtDeclarative/qdeclarativeextensionplugin.h> | |
52 | #include <QtDeclarative/qdeclarative.h> |
|
52 | #include <QtDeclarative/qdeclarative.h> | |
53 |
|
53 | |||
54 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
54 | QTCOMMERCIALCHART_USE_NAMESPACE | |
55 |
|
55 | |||
56 | Q_DECLARE_METATYPE(QList<QPieSlice *>) |
|
56 | Q_DECLARE_METATYPE(QList<QPieSlice *>) | |
57 | Q_DECLARE_METATYPE(QList<QBarSet *>) |
|
57 | Q_DECLARE_METATYPE(QList<QBarSet *>) | |
58 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
58 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) | |
59 |
|
59 | |||
60 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
|
60 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | |
61 |
|
61 | |||
62 | // NOTE: Hackish fixes for Qt5 (beta2). |
|
62 | // NOTE: Hackish fixes for Qt5 (beta2). | |
63 | // These should not be needed or at least they are not needed in Qt4. |
|
63 | // These should not be needed or at least they are not needed in Qt4. | |
64 |
|
64 | |||
65 | Q_DECLARE_METATYPE(DeclarativeChart *) |
|
65 | Q_DECLARE_METATYPE(DeclarativeChart *) | |
66 | Q_DECLARE_METATYPE(DeclarativeMargins *) |
|
66 | Q_DECLARE_METATYPE(DeclarativeMargins *) | |
67 | Q_DECLARE_METATYPE(DeclarativeAreaSeries *) |
|
67 | Q_DECLARE_METATYPE(DeclarativeAreaSeries *) | |
68 | Q_DECLARE_METATYPE(DeclarativeBarSeries *) |
|
68 | Q_DECLARE_METATYPE(DeclarativeBarSeries *) | |
69 | Q_DECLARE_METATYPE(DeclarativeBoxPlotSeries *) |
|
69 | Q_DECLARE_METATYPE(DeclarativeBoxPlotSeries *) | |
70 | Q_DECLARE_METATYPE(DeclarativeLineSeries *) |
|
70 | Q_DECLARE_METATYPE(DeclarativeLineSeries *) | |
71 | Q_DECLARE_METATYPE(DeclarativePieSeries *) |
|
71 | Q_DECLARE_METATYPE(DeclarativePieSeries *) | |
72 | Q_DECLARE_METATYPE(DeclarativeScatterSeries *) |
|
72 | Q_DECLARE_METATYPE(DeclarativeScatterSeries *) | |
73 | Q_DECLARE_METATYPE(DeclarativeSplineSeries *) |
|
73 | Q_DECLARE_METATYPE(DeclarativeSplineSeries *) | |
74 |
|
74 | |||
75 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
75 | Q_DECLARE_METATYPE(QAbstractAxis *) | |
76 | Q_DECLARE_METATYPE(QValueAxis *) |
|
76 | Q_DECLARE_METATYPE(QValueAxis *) | |
77 | Q_DECLARE_METATYPE(QBarCategoryAxis *) |
|
77 | Q_DECLARE_METATYPE(QBarCategoryAxis *) | |
78 | Q_DECLARE_METATYPE(QCategoryAxis *) |
|
78 | Q_DECLARE_METATYPE(QCategoryAxis *) | |
79 | Q_DECLARE_METATYPE(QDateTimeAxis *) |
|
79 | Q_DECLARE_METATYPE(QDateTimeAxis *) | |
80 |
|
80 | |||
81 | Q_DECLARE_METATYPE(QLegend *) |
|
81 | Q_DECLARE_METATYPE(QLegend *) | |
82 | Q_DECLARE_METATYPE(QLegendMarker *) |
|
82 | Q_DECLARE_METATYPE(QLegendMarker *) | |
83 | Q_DECLARE_METATYPE(QAreaLegendMarker *) |
|
83 | Q_DECLARE_METATYPE(QAreaLegendMarker *) | |
84 | Q_DECLARE_METATYPE(QBarLegendMarker *) |
|
84 | Q_DECLARE_METATYPE(QBarLegendMarker *) | |
85 | Q_DECLARE_METATYPE(QPieLegendMarker *) |
|
85 | Q_DECLARE_METATYPE(QPieLegendMarker *) | |
86 |
|
86 | |||
87 | Q_DECLARE_METATYPE(QHPieModelMapper *) |
|
87 | Q_DECLARE_METATYPE(QHPieModelMapper *) | |
88 | Q_DECLARE_METATYPE(QHXYModelMapper *) |
|
88 | Q_DECLARE_METATYPE(QHXYModelMapper *) | |
89 | Q_DECLARE_METATYPE(QPieModelMapper *) |
|
89 | Q_DECLARE_METATYPE(QPieModelMapper *) | |
90 | Q_DECLARE_METATYPE(QHBarModelMapper *) |
|
90 | Q_DECLARE_METATYPE(QHBarModelMapper *) | |
91 | Q_DECLARE_METATYPE(QBarModelMapper *) |
|
91 | Q_DECLARE_METATYPE(QBarModelMapper *) | |
92 | Q_DECLARE_METATYPE(QVBarModelMapper *) |
|
92 | Q_DECLARE_METATYPE(QVBarModelMapper *) | |
93 | Q_DECLARE_METATYPE(QVPieModelMapper *) |
|
93 | Q_DECLARE_METATYPE(QVPieModelMapper *) | |
94 | Q_DECLARE_METATYPE(QVXYModelMapper *) |
|
94 | Q_DECLARE_METATYPE(QVXYModelMapper *) | |
95 | Q_DECLARE_METATYPE(QXYLegendMarker *) |
|
95 | Q_DECLARE_METATYPE(QXYLegendMarker *) | |
96 | Q_DECLARE_METATYPE(QXYModelMapper *) |
|
96 | Q_DECLARE_METATYPE(QXYModelMapper *) | |
97 |
|
97 | |||
98 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
98 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
99 | Q_DECLARE_METATYPE(QXYSeries *) |
|
99 | Q_DECLARE_METATYPE(QXYSeries *) | |
100 | Q_DECLARE_METATYPE(QAbstractBarSeries *) |
|
100 | Q_DECLARE_METATYPE(QAbstractBarSeries *) | |
101 | Q_DECLARE_METATYPE(QBarSeries *) |
|
101 | Q_DECLARE_METATYPE(QBarSeries *) | |
102 | Q_DECLARE_METATYPE(QBarSet *) |
|
102 | Q_DECLARE_METATYPE(QBarSet *) | |
103 | Q_DECLARE_METATYPE(QAreaSeries *) |
|
103 | Q_DECLARE_METATYPE(QAreaSeries *) | |
104 | Q_DECLARE_METATYPE(QHorizontalBarSeries *) |
|
104 | Q_DECLARE_METATYPE(QHorizontalBarSeries *) | |
105 | Q_DECLARE_METATYPE(QHorizontalPercentBarSeries *) |
|
105 | Q_DECLARE_METATYPE(QHorizontalPercentBarSeries *) | |
106 | Q_DECLARE_METATYPE(QHorizontalStackedBarSeries *) |
|
106 | Q_DECLARE_METATYPE(QHorizontalStackedBarSeries *) | |
107 | Q_DECLARE_METATYPE(QLineSeries *) |
|
107 | Q_DECLARE_METATYPE(QLineSeries *) | |
108 | Q_DECLARE_METATYPE(QPercentBarSeries *) |
|
108 | Q_DECLARE_METATYPE(QPercentBarSeries *) | |
109 | Q_DECLARE_METATYPE(QPieSeries *) |
|
109 | Q_DECLARE_METATYPE(QPieSeries *) | |
110 | Q_DECLARE_METATYPE(QPieSlice *) |
|
110 | Q_DECLARE_METATYPE(QPieSlice *) | |
111 | Q_DECLARE_METATYPE(QScatterSeries *) |
|
111 | Q_DECLARE_METATYPE(QScatterSeries *) | |
112 | Q_DECLARE_METATYPE(QSplineSeries *) |
|
112 | Q_DECLARE_METATYPE(QSplineSeries *) | |
113 | Q_DECLARE_METATYPE(QStackedBarSeries *) |
|
113 | Q_DECLARE_METATYPE(QStackedBarSeries *) | |
114 |
|
114 | |||
115 | #endif |
|
115 | #endif | |
116 |
|
116 | |||
117 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
117 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
118 |
|
118 | |||
119 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin |
|
119 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin | |
120 | { |
|
120 | { | |
121 | Q_OBJECT |
|
121 | Q_OBJECT | |
122 |
|
122 | |||
123 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
|
123 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | |
124 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDeclarativeExtensionInterface") |
|
124 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDeclarativeExtensionInterface") | |
125 | #endif |
|
125 | #endif | |
126 |
|
126 | |||
127 | public: |
|
127 | public: | |
128 | virtual void registerTypes(const char *uri) |
|
128 | virtual void registerTypes(const char *uri) | |
129 | { |
|
129 | { | |
130 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); |
|
130 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); | |
131 |
|
131 | |||
132 | qRegisterMetaType<QList<QPieSlice *> >(); |
|
132 | qRegisterMetaType<QList<QPieSlice *> >(); | |
133 | qRegisterMetaType<QList<QBarSet *> >(); |
|
133 | qRegisterMetaType<QList<QBarSet *> >(); | |
134 | qRegisterMetaType<QList<QAbstractAxis *> >(); |
|
134 | qRegisterMetaType<QList<QAbstractAxis *> >(); | |
135 |
|
135 | |||
136 | // QtCommercial.Chart 1.0 |
|
136 | // QtCommercial.Chart 1.0 | |
137 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); |
|
137 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); | |
138 | qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint"); |
|
138 | qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint"); | |
139 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); |
|
139 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); | |
140 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); |
|
140 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); | |
141 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); |
|
141 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); | |
142 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); |
|
142 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); | |
143 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); |
|
143 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); | |
144 | qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries"); |
|
144 | qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries"); | |
145 | qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries"); |
|
145 | qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries"); | |
146 | qmlRegisterType<DeclarativeBoxPlotSeries>(uri, 1, 0, "BoxPlotSeries"); |
|
146 | qmlRegisterType<DeclarativeBoxPlotSeries>(uri, 1, 0, "BoxPlotSeries"); | |
147 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); |
|
147 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); | |
148 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); |
|
148 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); | |
149 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); |
|
149 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); | |
150 | qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper"); |
|
150 | qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper"); | |
151 | qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper"); |
|
151 | qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper"); | |
152 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); |
|
152 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); | |
153 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); |
|
153 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); | |
154 | qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper"); |
|
154 | qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper"); | |
155 | qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper"); |
|
155 | qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper"); | |
156 | qmlRegisterType<QValueAxis>(uri, 1, 0, "ValuesAxis"); |
|
156 | qmlRegisterType<QValueAxis>(uri, 1, 0, "ValuesAxis"); | |
157 | qmlRegisterType<QBarCategoryAxis>(uri, 1, 0, "BarCategoriesAxis"); |
|
157 | qmlRegisterType<QBarCategoryAxis>(uri, 1, 0, "BarCategoriesAxis"); | |
158 | qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend", |
|
158 | qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend", | |
159 | QLatin1String("Trying to create uncreatable: Legend.")); |
|
159 | QLatin1String("Trying to create uncreatable: Legend.")); | |
160 | qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries", |
|
160 | qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries", | |
161 | QLatin1String("Trying to create uncreatable: XYSeries.")); |
|
161 | QLatin1String("Trying to create uncreatable: XYSeries.")); | |
162 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", |
|
162 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", | |
163 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); |
|
163 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); | |
164 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", |
|
164 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", | |
165 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
165 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); | |
166 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
166 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", | |
167 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
167 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); | |
168 | qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper", |
|
168 | qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper", | |
169 | QLatin1String("Trying to create uncreatable: BarModelMapper.")); |
|
169 | QLatin1String("Trying to create uncreatable: BarModelMapper.")); | |
170 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", |
|
170 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", | |
171 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); |
|
171 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); | |
172 | qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries", |
|
172 | qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries", | |
173 | QLatin1String("Trying to create uncreatable: AbstractBarSeries.")); |
|
173 | QLatin1String("Trying to create uncreatable: AbstractBarSeries.")); | |
174 | qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis", |
|
174 | qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis", | |
175 | QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead.")); |
|
175 | QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead.")); | |
176 | qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "BarSetBase", |
|
176 | qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "BarSetBase", | |
177 | QLatin1String("Trying to create uncreatable: BarsetBase.")); |
|
177 | QLatin1String("Trying to create uncreatable: BarsetBase.")); | |
178 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries", |
|
178 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries", | |
179 | QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead.")); |
|
179 | QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead.")); | |
180 | qmlRegisterUncreatableType<DeclarativeAxes>(uri, 1, 0, "DeclarativeAxes", |
|
180 | qmlRegisterUncreatableType<DeclarativeAxes>(uri, 1, 0, "DeclarativeAxes", | |
181 | QLatin1String("Trying to create uncreatable: DeclarativeAxes.")); |
|
181 | QLatin1String("Trying to create uncreatable: DeclarativeAxes.")); | |
182 |
|
182 | |||
183 | // QtCommercial.Chart 1.1 |
|
183 | // QtCommercial.Chart 1.1 | |
184 | qmlRegisterType<DeclarativeChart, 1>(uri, 1, 1, "ChartView"); |
|
184 | qmlRegisterType<DeclarativeChart, 1>(uri, 1, 1, "ChartView"); | |
185 | qmlRegisterType<DeclarativeScatterSeries, 1>(uri, 1, 1, "ScatterSeries"); |
|
185 | qmlRegisterType<DeclarativeScatterSeries, 1>(uri, 1, 1, "ScatterSeries"); | |
186 | qmlRegisterType<DeclarativeLineSeries, 1>(uri, 1, 1, "LineSeries"); |
|
186 | qmlRegisterType<DeclarativeLineSeries, 1>(uri, 1, 1, "LineSeries"); | |
187 | qmlRegisterType<DeclarativeSplineSeries, 1>(uri, 1, 1, "SplineSeries"); |
|
187 | qmlRegisterType<DeclarativeSplineSeries, 1>(uri, 1, 1, "SplineSeries"); | |
188 | qmlRegisterType<DeclarativeAreaSeries, 1>(uri, 1, 1, "AreaSeries"); |
|
188 | qmlRegisterType<DeclarativeAreaSeries, 1>(uri, 1, 1, "AreaSeries"); | |
189 | qmlRegisterType<DeclarativeBarSeries, 1>(uri, 1, 1, "BarSeries"); |
|
189 | qmlRegisterType<DeclarativeBarSeries, 1>(uri, 1, 1, "BarSeries"); | |
190 | qmlRegisterType<DeclarativeStackedBarSeries, 1>(uri, 1, 1, "StackedBarSeries"); |
|
190 | qmlRegisterType<DeclarativeStackedBarSeries, 1>(uri, 1, 1, "StackedBarSeries"); | |
191 | qmlRegisterType<DeclarativePercentBarSeries, 1>(uri, 1, 1, "PercentBarSeries"); |
|
191 | qmlRegisterType<DeclarativePercentBarSeries, 1>(uri, 1, 1, "PercentBarSeries"); | |
192 | qmlRegisterType<DeclarativeBoxPlotSeries, 1>(uri, 1, 1, "BoxPlotSeries"); |
|
192 | qmlRegisterType<DeclarativeBoxPlotSeries, 1>(uri, 1, 1, "BoxPlotSeries"); | |
193 | qmlRegisterType<DeclarativeHorizontalBarSeries, 1>(uri, 1, 1, "HorizontalBarSeries"); |
|
193 | qmlRegisterType<DeclarativeHorizontalBarSeries, 1>(uri, 1, 1, "HorizontalBarSeries"); | |
194 | qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 1>(uri, 1, 1, "HorizontalStackedBarSeries"); |
|
194 | qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 1>(uri, 1, 1, "HorizontalStackedBarSeries"); | |
195 | qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 1>(uri, 1, 1, "HorizontalPercentBarSeries"); |
|
195 | qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 1>(uri, 1, 1, "HorizontalPercentBarSeries"); | |
196 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 1, "PieSeries"); |
|
196 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 1, "PieSeries"); | |
197 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 1, "BarSet"); |
|
197 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 1, "BarSet"); | |
|
198 | qmlRegisterType<DeclarativeBoxSet>(uri, 1, 1, "BoxSet"); | |||
198 | qmlRegisterType<QValueAxis>(uri, 1, 1, "ValueAxis"); |
|
199 | qmlRegisterType<QValueAxis>(uri, 1, 1, "ValueAxis"); | |
199 | #ifndef QT_ON_ARM |
|
200 | #ifndef QT_ON_ARM | |
200 | qmlRegisterType<QDateTimeAxis>(uri, 1, 1, "DateTimeAxis"); |
|
201 | qmlRegisterType<QDateTimeAxis>(uri, 1, 1, "DateTimeAxis"); | |
201 | #endif |
|
202 | #endif | |
202 | qmlRegisterType<DeclarativeCategoryAxis>(uri, 1, 1, "CategoryAxis"); |
|
203 | qmlRegisterType<DeclarativeCategoryAxis>(uri, 1, 1, "CategoryAxis"); | |
203 | qmlRegisterType<DeclarativeCategoryRange>(uri, 1, 1, "CategoryRange"); |
|
204 | qmlRegisterType<DeclarativeCategoryRange>(uri, 1, 1, "CategoryRange"); | |
204 | qmlRegisterType<QBarCategoryAxis>(uri, 1, 1, "BarCategoryAxis"); |
|
205 | qmlRegisterType<QBarCategoryAxis>(uri, 1, 1, "BarCategoryAxis"); | |
205 | qmlRegisterUncreatableType<DeclarativeMargins>(uri, 1, 1, "Margins", |
|
206 | qmlRegisterUncreatableType<DeclarativeMargins>(uri, 1, 1, "Margins", | |
206 | QLatin1String("Trying to create uncreatable: Margins.")); |
|
207 | QLatin1String("Trying to create uncreatable: Margins.")); | |
207 |
|
208 | |||
208 | // QtCommercial.Chart 1.2 |
|
209 | // QtCommercial.Chart 1.2 | |
209 | qmlRegisterType<DeclarativeChart, 2>(uri, 1, 2, "ChartView"); |
|
210 | qmlRegisterType<DeclarativeChart, 2>(uri, 1, 2, "ChartView"); | |
210 | qmlRegisterType<DeclarativeScatterSeries, 2>(uri, 1, 2, "ScatterSeries"); |
|
211 | qmlRegisterType<DeclarativeScatterSeries, 2>(uri, 1, 2, "ScatterSeries"); | |
211 | qmlRegisterType<DeclarativeLineSeries, 2>(uri, 1, 2, "LineSeries"); |
|
212 | qmlRegisterType<DeclarativeLineSeries, 2>(uri, 1, 2, "LineSeries"); | |
212 | qmlRegisterType<DeclarativeSplineSeries, 2>(uri, 1, 2, "SplineSeries"); |
|
213 | qmlRegisterType<DeclarativeSplineSeries, 2>(uri, 1, 2, "SplineSeries"); | |
213 | qmlRegisterType<DeclarativeAreaSeries, 2>(uri, 1, 2, "AreaSeries"); |
|
214 | qmlRegisterType<DeclarativeAreaSeries, 2>(uri, 1, 2, "AreaSeries"); | |
214 | qmlRegisterType<DeclarativeBarSeries, 2>(uri, 1, 2, "BarSeries"); |
|
215 | qmlRegisterType<DeclarativeBarSeries, 2>(uri, 1, 2, "BarSeries"); | |
215 | qmlRegisterType<DeclarativeStackedBarSeries, 2>(uri, 1, 2, "StackedBarSeries"); |
|
216 | qmlRegisterType<DeclarativeStackedBarSeries, 2>(uri, 1, 2, "StackedBarSeries"); | |
216 | qmlRegisterType<DeclarativePercentBarSeries, 2>(uri, 1, 2, "PercentBarSeries"); |
|
217 | qmlRegisterType<DeclarativePercentBarSeries, 2>(uri, 1, 2, "PercentBarSeries"); | |
217 | qmlRegisterType<DeclarativeBoxPlotSeries, 2>(uri, 1, 2, "BoxPlotSeries"); |
|
218 | qmlRegisterType<DeclarativeBoxPlotSeries, 2>(uri, 1, 2, "BoxPlotSeries"); | |
218 | qmlRegisterType<DeclarativeHorizontalBarSeries, 2>(uri, 1, 2, "HorizontalBarSeries"); |
|
219 | qmlRegisterType<DeclarativeHorizontalBarSeries, 2>(uri, 1, 2, "HorizontalBarSeries"); | |
219 | qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 2>(uri, 1, 2, "HorizontalStackedBarSeries"); |
|
220 | qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 2>(uri, 1, 2, "HorizontalStackedBarSeries"); | |
220 | qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 2>(uri, 1, 2, "HorizontalPercentBarSeries"); |
|
221 | qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 2>(uri, 1, 2, "HorizontalPercentBarSeries"); | |
221 | } |
|
222 | } | |
222 | }; |
|
223 | }; | |
223 |
|
224 | |||
224 | #include "plugin.moc" |
|
225 | #include "plugin.moc" | |
225 |
|
226 | |||
226 | QTCOMMERCIALCHART_END_NAMESPACE |
|
227 | QTCOMMERCIALCHART_END_NAMESPACE | |
227 |
|
228 | |||
228 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
229 | QTCOMMERCIALCHART_USE_NAMESPACE | |
229 |
|
230 | |||
230 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) |
|
231 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) | |
231 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
|
232 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) | |
232 | #endif |
|
233 | #endif |
@@ -1,16 +1,19 | |||||
1 | INCLUDEPATH += $$PWD |
|
1 | INCLUDEPATH += $$PWD | |
2 | DEPENDPATH += $$PWD |
|
2 | DEPENDPATH += $$PWD | |
3 |
|
3 | |||
4 | SOURCES += \ |
|
4 | SOURCES += \ | |
5 | $$PWD/boxplotchartitem.cpp \ |
|
5 | $$PWD/boxplotchartitem.cpp \ | |
6 | $$PWD/qboxplotseries.cpp \ |
|
6 | $$PWD/qboxplotseries.cpp \ | |
7 | $$PWD/boxwhiskers.cpp |
|
7 | $$PWD/boxwhiskers.cpp \ | |
|
8 | $$PWD/qboxset.cpp | |||
8 |
|
9 | |||
9 | PRIVATE_HEADERS += \ |
|
10 | PRIVATE_HEADERS += \ | |
10 | $$PWD/boxplotchartitem_p.h \ |
|
11 | $$PWD/boxplotchartitem_p.h \ | |
11 | $$PWD/qboxplotseries_p.h \ |
|
12 | $$PWD/qboxplotseries_p.h \ | |
12 | $$PWD/boxwhiskers_p.h \ |
|
13 | $$PWD/boxwhiskers_p.h \ | |
13 | $$PWD/boxwhiskersdata_p.h |
|
14 | $$PWD/boxwhiskersdata_p.h \ | |
|
15 | $$PWD/qboxset_p.h | |||
14 |
|
16 | |||
15 | PUBLIC_HEADERS += \ |
|
17 | PUBLIC_HEADERS += \ | |
16 | $$PWD/qboxplotseries.h |
|
18 | $$PWD/qboxplotseries.h \ | |
|
19 | $$PWD/qboxset.h |
@@ -1,224 +1,223 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "boxplotchartitem_p.h" |
|
21 | #include "boxplotchartitem_p.h" | |
22 | #include "qboxplotseries_p.h" |
|
22 | #include "qboxplotseries_p.h" | |
23 | #include "bar_p.h" |
|
23 | #include "bar_p.h" | |
24 |
#include "qb |
|
24 | #include "qboxset_p.h" | |
25 | #include "qabstractbarseries_p.h" |
|
25 | #include "qabstractbarseries_p.h" | |
26 |
#include "qb |
|
26 | #include "qboxset.h" | |
27 | #include "boxwhiskers_p.h" |
|
27 | #include "boxwhiskers_p.h" | |
28 | #include <QPainter> |
|
28 | #include <QPainter> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | BoxPlotChartItem::BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item) : |
|
32 | BoxPlotChartItem::BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item) : | |
33 | ChartItem(series->d_func(), item), |
|
33 | ChartItem(series->d_func(), item), | |
34 | m_series(series), |
|
34 | m_series(series), | |
35 | m_animation(0), |
|
35 | m_animation(0), | |
36 | m_animate(0) |
|
36 | m_animate(0) | |
37 | { |
|
37 | { | |
38 |
connect(series, SIGNAL(b |
|
38 | connect(series, SIGNAL(boxsetsRemoved(QList<QBoxSet*>)), this, SLOT(handleBoxsetRemove(QList<QBoxSet*>))); | |
39 |
connect(series->d_func(), SIGNAL(restructuredB |
|
39 | connect(series->d_func(), SIGNAL(restructuredBoxes()), this, SLOT(handleDataStructureChanged())); | |
40 | connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); |
|
40 | connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); | |
41 |
connect(series->d_func(), SIGNAL(updatedB |
|
41 | connect(series->d_func(), SIGNAL(updatedBoxes()), this, SLOT(handleUpdatedBars())); | |
42 | connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars())); |
|
42 | connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars())); | |
43 | // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here |
|
43 | // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here | |
44 | setZValue(ChartPresenter::BoxPlotSeriesZValue); |
|
44 | setZValue(ChartPresenter::BoxPlotSeriesZValue); | |
45 |
|
||||
46 | m_barSets = m_series->barSets(); |
|
|||
47 | } |
|
45 | } | |
48 |
|
46 | |||
49 | BoxPlotChartItem::~BoxPlotChartItem() |
|
47 | BoxPlotChartItem::~BoxPlotChartItem() | |
50 | { |
|
48 | { | |
51 | qDebug() << "BoxPlotChartItem::~BoxPlotChartItem() " << m_seriesIndex; |
|
49 | qDebug() << "BoxPlotChartItem::~BoxPlotChartItem() " << m_seriesIndex; | |
52 | } |
|
50 | } | |
53 |
|
51 | |||
54 | void BoxPlotChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
52 | void BoxPlotChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
55 | { |
|
53 | { | |
56 | Q_UNUSED(painter); |
|
54 | Q_UNUSED(painter); | |
57 | Q_UNUSED(option); |
|
55 | Q_UNUSED(option); | |
58 | Q_UNUSED(widget); |
|
56 | Q_UNUSED(widget); | |
59 |
|
57 | |||
60 | //painter->setClipRect(QRectF(QPointF(0,0),domain()->size())); |
|
58 | //painter->setClipRect(QRectF(QPointF(0,0),domain()->size())); | |
61 |
|
59 | |||
62 | //qDebug() << "ALERT EMPTY: BoxPlotChartItem::paint"; |
|
60 | //qDebug() << "ALERT EMPTY: BoxPlotChartItem::paint"; | |
63 | } |
|
61 | } | |
64 |
|
62 | |||
65 | void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation) |
|
63 | void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation) | |
66 | { |
|
64 | { | |
67 | //qDebug() << "BoxPlotChartItem::setAnimation :" << animation; |
|
65 | //qDebug() << "BoxPlotChartItem::setAnimation :" << animation; | |
68 |
|
66 | |||
69 | m_animation = animation; |
|
67 | m_animation = animation; | |
70 | if (m_animation) { |
|
68 | if (m_animation) { | |
71 | foreach (BoxWhiskers *item, m_boxTable.values()) { |
|
69 | foreach (BoxWhiskers *item, m_boxTable.values()) { | |
72 | m_animation->addBox(item); |
|
70 | m_animation->addBox(item); | |
73 | } |
|
71 | } | |
74 | handleDomainUpdated(); |
|
72 | handleDomainUpdated(); | |
75 | } |
|
73 | } | |
76 | } |
|
74 | } | |
77 |
|
75 | |||
78 | void BoxPlotChartItem::handleDataStructureChanged() |
|
76 | void BoxPlotChartItem::handleDataStructureChanged() | |
79 | { |
|
77 | { | |
80 | qDebug() << "BoxPlotChartItem::handleDataStructureChanged()"; |
|
78 | qDebug() << "BoxPlotChartItem::handleDataStructureChanged()"; | |
81 |
|
79 | |||
82 | int setCount = m_series->count(); |
|
80 | int setCount = m_series->count(); | |
83 |
|
81 | |||
84 | for (int s = 0; s < setCount; s++) { |
|
82 | for (int s = 0; s < setCount; s++) { | |
85 |
QB |
|
83 | QBoxSet *set = m_series->d_func()->boxsetAt(s); | |
86 |
|
84 | |||
87 | BoxWhiskers *boxWhiskersItem = m_boxTable.value(set); |
|
85 | BoxWhiskers *boxWhiskersItem = m_boxTable.value(set); | |
88 | if (boxWhiskersItem == 0) { |
|
86 | if (boxWhiskersItem == 0) { | |
89 | // Item is not yet created, make a box and add it to hash table |
|
87 | // Item is not yet created, make a box and add it to hash table | |
90 | boxWhiskersItem = new BoxWhiskers(domain(), this); |
|
88 | boxWhiskersItem = new BoxWhiskers(domain(), this); | |
91 | m_boxTable.insert(set, boxWhiskersItem); |
|
89 | m_boxTable.insert(set, boxWhiskersItem); | |
92 |
|
90 | |||
|
91 | // Set the decorative issues for the newly created box | |||
93 | boxWhiskersItem->setBrush(m_series->brush()); |
|
92 | boxWhiskersItem->setBrush(m_series->brush()); | |
94 | boxWhiskersItem->setPen(m_series->pen()); |
|
93 | boxWhiskersItem->setPen(m_series->pen()); | |
95 | } |
|
94 | } | |
96 | updateBoxGeometry(boxWhiskersItem, s); |
|
95 | updateBoxGeometry(boxWhiskersItem, s); | |
97 |
|
96 | |||
98 | boxWhiskersItem->updateGeometry(); |
|
97 | boxWhiskersItem->updateGeometry(); | |
99 |
|
98 | |||
100 | if (m_animation) |
|
99 | if (m_animation) | |
101 | m_animation->addBox(boxWhiskersItem); |
|
100 | m_animation->addBox(boxWhiskersItem); | |
102 | } |
|
101 | } | |
103 |
|
102 | |||
104 | // |
|
103 | // | |
105 | handleDomainUpdated(); |
|
104 | handleDomainUpdated(); | |
106 | } |
|
105 | } | |
107 |
|
106 | |||
108 | void BoxPlotChartItem::handleUpdatedBars() |
|
107 | void BoxPlotChartItem::handleUpdatedBars() | |
109 | { |
|
108 | { | |
110 | qDebug() << "BoxPlotChartItem::handleUpdatedBars()"; |
|
109 | qDebug() << "BoxPlotChartItem::handleUpdatedBars()"; | |
111 |
|
110 | |||
112 | foreach (BoxWhiskers *item, m_boxTable.values()) { |
|
111 | foreach (BoxWhiskers *item, m_boxTable.values()) { | |
113 | item->setBrush(m_series->brush()); |
|
112 | item->setBrush(m_series->brush()); | |
114 | item->setPen(m_series->pen()); |
|
113 | item->setPen(m_series->pen()); | |
115 | } |
|
114 | } | |
116 |
// Override with QB |
|
115 | // Override with QBoxSet specific settings | |
117 |
foreach (QB |
|
116 | foreach (QBoxSet *set, m_boxTable.keys()) { | |
118 | if (set->brush().style() != Qt::NoBrush) |
|
117 | if (set->brush().style() != Qt::NoBrush) | |
119 | m_boxTable.value(set)->setBrush(set->brush()); |
|
118 | m_boxTable.value(set)->setBrush(set->brush()); | |
120 | if (set->pen().style() != Qt::NoPen) |
|
119 | if (set->pen().style() != Qt::NoPen) | |
121 | m_boxTable.value(set)->setPen(set->pen()); |
|
120 | m_boxTable.value(set)->setPen(set->pen()); | |
122 | } |
|
121 | } | |
123 | } |
|
122 | } | |
124 |
|
123 | |||
125 |
void BoxPlotChartItem::handleB |
|
124 | void BoxPlotChartItem::handleBoxsetRemove(QList<QBoxSet*> barSets) | |
126 | { |
|
125 | { | |
127 | //qDebug() << "BoxPlotChartItem::handleBarsetRemove"; |
|
126 | //qDebug() << "BoxPlotChartItem::handleBarsetRemove"; | |
128 |
|
127 | |||
129 |
foreach (QB |
|
128 | foreach (QBoxSet *set, barSets) { | |
130 | BoxWhiskers *boxItem = m_boxTable.value(set); |
|
129 | BoxWhiskers *boxItem = m_boxTable.value(set); | |
131 | m_boxTable.remove(set); |
|
130 | m_boxTable.remove(set); | |
132 | delete boxItem; |
|
131 | delete boxItem; | |
133 | } |
|
132 | } | |
134 |
|
133 | |||
135 | // We trust that series emits the restructuredBars, which handles restructuring |
|
134 | // We trust that series emits the restructuredBars, which handles restructuring | |
136 | } |
|
135 | } | |
137 |
|
136 | |||
138 | void BoxPlotChartItem::handleDomainUpdated() |
|
137 | void BoxPlotChartItem::handleDomainUpdated() | |
139 | { |
|
138 | { | |
140 | //qDebug() << "BoxPlotChartItem::handleDomainUpdated() domain()->size() = " << domain()->size(); |
|
139 | //qDebug() << "BoxPlotChartItem::handleDomainUpdated() domain()->size() = " << domain()->size(); | |
141 |
|
140 | |||
142 | if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0)) |
|
141 | if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0)) | |
143 | return; |
|
142 | return; | |
144 |
|
143 | |||
145 | // Set my bounding rect to same as domain size |
|
144 | // Set my bounding rect to same as domain size | |
146 | m_boundingRect.setRect(0.0, 0.0, domain()->size().width(), domain()->size().height()); |
|
145 | m_boundingRect.setRect(0.0, 0.0, domain()->size().width(), domain()->size().height()); | |
147 |
|
146 | |||
148 | foreach (BoxWhiskers *item, m_boxTable.values()) { |
|
147 | foreach (BoxWhiskers *item, m_boxTable.values()) { | |
149 | // Update the domain size for each BoxWhisker item |
|
148 | // Update the domain size for each BoxWhisker item | |
150 | item->setDomainSize(domain()->size()); |
|
149 | item->setDomainSize(domain()->size()); | |
151 |
|
150 | |||
152 | // If the animation is set, start the animation for each BoxWhisker item |
|
151 | // If the animation is set, start the animation for each BoxWhisker item | |
153 | if (m_animation) { |
|
152 | if (m_animation) { | |
154 | presenter()->startAnimation(m_animation->boxAnimation(item)); |
|
153 | presenter()->startAnimation(m_animation->boxAnimation(item)); | |
155 | } |
|
154 | } | |
156 | } |
|
155 | } | |
157 | } |
|
156 | } | |
158 |
|
157 | |||
159 | void BoxPlotChartItem::handleLayoutChanged() |
|
158 | void BoxPlotChartItem::handleLayoutChanged() | |
160 | { |
|
159 | { | |
161 | qDebug() << "BoxPlotChartItem::handleLayoutChanged"; |
|
160 | qDebug() << "BoxPlotChartItem::handleLayoutChanged"; | |
162 |
|
161 | |||
163 | foreach (BoxWhiskers *item, m_boxTable.values()) { |
|
162 | foreach (BoxWhiskers *item, m_boxTable.values()) { | |
164 | if (m_animation) |
|
163 | if (m_animation) | |
165 | m_animation->setAnimationStart(item); |
|
164 | m_animation->setAnimationStart(item); | |
166 |
|
165 | |||
167 | bool dirty = updateBoxGeometry(item, item->m_data.m_index); |
|
166 | bool dirty = updateBoxGeometry(item, item->m_data.m_index); | |
168 | if (dirty && m_animation) |
|
167 | if (dirty && m_animation) | |
169 | presenter()->startAnimation(m_animation->boxChangeAnimation(item)); |
|
168 | presenter()->startAnimation(m_animation->boxChangeAnimation(item)); | |
170 | else |
|
169 | else | |
171 | item->updateGeometry(); |
|
170 | item->updateGeometry(); | |
172 | } |
|
171 | } | |
173 | } |
|
172 | } | |
174 |
|
173 | |||
175 | QRectF BoxPlotChartItem::boundingRect() const |
|
174 | QRectF BoxPlotChartItem::boundingRect() const | |
176 | { |
|
175 | { | |
177 | return m_boundingRect; |
|
176 | return m_boundingRect; | |
178 | } |
|
177 | } | |
179 |
|
178 | |||
180 | void BoxPlotChartItem::initializeLayout() |
|
179 | void BoxPlotChartItem::initializeLayout() | |
181 | { |
|
180 | { | |
182 | qDebug() << "ALERT EMPTY: BoxPlotChartItem::initializeLayout"; |
|
181 | qDebug() << "ALERT EMPTY: BoxPlotChartItem::initializeLayout"; | |
183 | } |
|
182 | } | |
184 |
|
183 | |||
185 | QVector<QRectF> BoxPlotChartItem::calculateLayout() |
|
184 | QVector<QRectF> BoxPlotChartItem::calculateLayout() | |
186 | { |
|
185 | { | |
187 | qDebug() << "ALERT EMPTY: BoxPlotChartItem::calculateLayout()"; |
|
186 | qDebug() << "ALERT EMPTY: BoxPlotChartItem::calculateLayout()"; | |
188 |
|
187 | |||
189 | return QVector<QRectF>(); |
|
188 | return QVector<QRectF>(); | |
190 | } |
|
189 | } | |
191 |
|
190 | |||
192 | bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index) |
|
191 | bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index) | |
193 | { |
|
192 | { | |
194 | bool changed = false; |
|
193 | bool changed = false; | |
195 |
|
194 | |||
196 |
QB |
|
195 | QBoxSet *set = m_series->d_func()->boxsetAt(index); | |
197 | BoxWhiskersData &data = box->m_data; |
|
196 | BoxWhiskersData &data = box->m_data; | |
198 |
|
197 | |||
199 | if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) || |
|
198 | if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) || | |
200 | (data.m_median != set->at(2)) || (data.m_upperQuartile != set->at(3)) || (data.m_upperExtreme != set->at(4))) |
|
199 | (data.m_median != set->at(2)) || (data.m_upperQuartile != set->at(3)) || (data.m_upperExtreme != set->at(4))) | |
201 | changed = true; |
|
200 | changed = true; | |
202 |
|
201 | |||
203 | data.m_lowerExtreme = set->at(0); |
|
202 | data.m_lowerExtreme = set->at(0); | |
204 | data.m_lowerQuartile = set->at(1); |
|
203 | data.m_lowerQuartile = set->at(1); | |
205 | data.m_median = set->at(2); |
|
204 | data.m_median = set->at(2); | |
206 | data.m_upperQuartile = set->at(3); |
|
205 | data.m_upperQuartile = set->at(3); | |
207 | data.m_upperExtreme = set->at(4); |
|
206 | data.m_upperExtreme = set->at(4); | |
208 | data.m_index = index; |
|
207 | data.m_index = index; | |
209 | data.m_boxItems = m_series->count(); |
|
208 | data.m_boxItems = m_series->count(); | |
210 |
|
209 | |||
211 | data.m_maxX = domain()->maxX(); |
|
210 | data.m_maxX = domain()->maxX(); | |
212 | data.m_minX = domain()->minX(); |
|
211 | data.m_minX = domain()->minX(); | |
213 | data.m_maxY = domain()->maxY(); |
|
212 | data.m_maxY = domain()->maxY(); | |
214 | data.m_minY = domain()->minY(); |
|
213 | data.m_minY = domain()->minY(); | |
215 |
|
214 | |||
216 | data.m_seriesIndex = m_seriesIndex; |
|
215 | data.m_seriesIndex = m_seriesIndex; | |
217 | data.m_seriesCount = m_seriesCount; |
|
216 | data.m_seriesCount = m_seriesCount; | |
218 |
|
217 | |||
219 | return changed; |
|
218 | return changed; | |
220 | } |
|
219 | } | |
221 |
|
220 | |||
222 | #include "moc_boxplotchartitem_p.cpp" |
|
221 | #include "moc_boxplotchartitem_p.cpp" | |
223 |
|
222 | |||
224 | QTCOMMERCIALCHART_END_NAMESPACE |
|
223 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,88 +1,87 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | #ifndef BOXPLOTCHARTITEM_H |
|
31 | #ifndef BOXPLOTCHARTITEM_H | |
32 | #define BOXPLOTCHARTITEM_H |
|
32 | #define BOXPLOTCHARTITEM_H | |
33 |
|
33 | |||
34 | #include "boxwhiskers_p.h" |
|
34 | #include "boxwhiskers_p.h" | |
35 | #include "qboxplotseries.h" |
|
35 | #include "qboxplotseries.h" | |
36 | #include "chartitem_p.h" |
|
36 | #include "chartitem_p.h" | |
37 | #include "boxplotanimation_p.h" |
|
37 | #include "boxplotanimation_p.h" | |
38 |
#include "qb |
|
38 | #include "qboxset.h" | |
39 | #include <QGraphicsItem> |
|
39 | #include <QGraphicsItem> | |
40 |
|
40 | |||
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
42 |
|
42 | |||
43 | class BoxPlotSeriesPrivate; |
|
43 | class BoxPlotSeriesPrivate; | |
44 |
|
44 | |||
45 | class BoxPlotChartItem : public ChartItem |
|
45 | class BoxPlotChartItem : public ChartItem | |
46 | { |
|
46 | { | |
47 | Q_OBJECT |
|
47 | Q_OBJECT | |
48 | public: |
|
48 | public: | |
49 | BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item =0); |
|
49 | BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item =0); | |
50 | ~BoxPlotChartItem(); |
|
50 | ~BoxPlotChartItem(); | |
51 |
|
51 | |||
52 | void setAnimation(BoxPlotAnimation *animation); |
|
52 | void setAnimation(BoxPlotAnimation *animation); | |
53 |
|
53 | |||
54 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
54 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
55 | QRectF boundingRect() const; |
|
55 | QRectF boundingRect() const; | |
56 |
|
56 | |||
57 | public Q_SLOTS: |
|
57 | public Q_SLOTS: | |
58 | void handleDataStructureChanged(); |
|
58 | void handleDataStructureChanged(); | |
59 | void handleDomainUpdated(); |
|
59 | void handleDomainUpdated(); | |
60 | void handleLayoutChanged(); |
|
60 | void handleLayoutChanged(); | |
61 | void handleUpdatedBars(); |
|
61 | void handleUpdatedBars(); | |
62 |
void handleB |
|
62 | void handleBoxsetRemove(QList<QBoxSet*> barSets); | |
63 |
|
63 | |||
64 | private: |
|
64 | private: | |
65 | virtual QVector<QRectF> calculateLayout(); |
|
65 | virtual QVector<QRectF> calculateLayout(); | |
66 | void initializeLayout(); |
|
66 | void initializeLayout(); | |
67 | bool updateBoxGeometry(BoxWhiskers *box, int index); |
|
67 | bool updateBoxGeometry(BoxWhiskers *box, int index); | |
68 |
|
68 | |||
69 | protected: |
|
69 | protected: | |
70 | friend class QBoxPlotSeriesPrivate; |
|
70 | friend class QBoxPlotSeriesPrivate; | |
71 | QBoxPlotSeries *m_series; // Not owned. |
|
71 | QBoxPlotSeries *m_series; // Not owned. | |
72 | QList<BoxWhiskers *> m_boxes; |
|
72 | QList<BoxWhiskers *> m_boxes; | |
73 |
QHash<QB |
|
73 | QHash<QBoxSet *, BoxWhiskers *> m_boxTable; | |
74 | QList<QBarSet *> m_barSets; |
|
|||
75 | int m_seriesIndex; |
|
74 | int m_seriesIndex; | |
76 | int m_seriesCount; |
|
75 | int m_seriesCount; | |
77 |
|
76 | |||
78 | BoxPlotAnimation *m_animation; |
|
77 | BoxPlotAnimation *m_animation; | |
79 | bool m_animate; |
|
78 | bool m_animate; | |
80 |
|
79 | |||
81 | QRectF m_boundingRect; |
|
80 | QRectF m_boundingRect; | |
82 |
|
81 | |||
83 | //QList<BoxPlotAnimation *> m_animations; |
|
82 | //QList<BoxPlotAnimation *> m_animations; | |
84 | }; |
|
83 | }; | |
85 |
|
84 | |||
86 | QTCOMMERCIALCHART_END_NAMESPACE |
|
85 | QTCOMMERCIALCHART_END_NAMESPACE | |
87 |
|
86 | |||
88 | #endif // BOXPLOTCHARTITEM_H |
|
87 | #endif // BOXPLOTCHARTITEM_H |
@@ -1,192 +1,191 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "boxwhiskers_p.h" |
|
21 | #include "boxwhiskers_p.h" | |
22 | #include <QPainter> |
|
22 | #include <QPainter> | |
23 | #include <QDebug> |
|
23 | #include <QDebug> | |
24 | #include <QWidget> |
|
24 | #include <QWidget> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | BoxWhiskers::BoxWhiskers(AbstractDomain *domain, QGraphicsObject *parent) : |
|
28 | BoxWhiskers::BoxWhiskers(AbstractDomain *domain, QGraphicsObject *parent) : | |
29 | QGraphicsObject(parent), |
|
29 | QGraphicsObject(parent), | |
30 | m_domain(domain) |
|
30 | m_domain(domain) | |
31 | { |
|
31 | { | |
32 | //qDebug() << "BoxWhiskers::BoxWhiskers()"; |
|
32 | //qDebug() << "BoxWhiskers::BoxWhiskers()"; | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | BoxWhiskers::~BoxWhiskers() |
|
35 | BoxWhiskers::~BoxWhiskers() | |
36 | { |
|
36 | { | |
37 | //qDebug() << "BoxWhiskers::~BoxWhiskers()"; |
|
37 | //qDebug() << "BoxWhiskers::~BoxWhiskers()"; | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | void BoxWhiskers::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
40 | void BoxWhiskers::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
41 | { |
|
41 | { | |
42 | Q_UNUSED(event) |
|
42 | Q_UNUSED(event) | |
43 |
|
43 | |||
44 | qDebug() << "BoxWhiskers::mousePressEvent"; |
|
44 | qDebug() << "BoxWhiskers::mousePressEvent"; | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void BoxWhiskers::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
47 | void BoxWhiskers::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
48 | { |
|
48 | { | |
49 | Q_UNUSED(event) |
|
49 | Q_UNUSED(event) | |
50 |
|
50 | |||
51 | qDebug() << "BoxWhiskers::hoverEnterEvent"; |
|
51 | qDebug() << "BoxWhiskers::hoverEnterEvent"; | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
54 | void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
55 | { |
|
55 | { | |
56 | Q_UNUSED(event) |
|
56 | Q_UNUSED(event) | |
57 |
|
57 | |||
58 | qDebug() << "BoxWhiskers::hoverLeaveEvent"; |
|
58 | qDebug() << "BoxWhiskers::hoverLeaveEvent"; | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | void BoxWhiskers::setBrush(const QBrush &brush) |
|
61 | void BoxWhiskers::setBrush(const QBrush &brush) | |
62 | { |
|
62 | { | |
63 | m_brush = brush; |
|
63 | m_brush = brush; | |
64 | update(); |
|
64 | update(); | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | void BoxWhiskers::setPen(const QPen &pen) |
|
67 | void BoxWhiskers::setPen(const QPen &pen) | |
68 | { |
|
68 | { | |
69 | m_pen = pen; |
|
69 | m_pen = pen; | |
70 | update(); |
|
70 | update(); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void BoxWhiskers::setLayout(const BoxWhiskersData &data) |
|
73 | void BoxWhiskers::setLayout(const BoxWhiskersData &data) | |
74 | { |
|
74 | { | |
75 | m_data = data; |
|
75 | m_data = data; | |
76 | // if (m_data.m_index == 1) |
|
76 | ||
77 | // qDebug() << "BoxWhiskers::setLayout"; |
|
|||
78 | updateGeometry(); |
|
77 | updateGeometry(); | |
79 | update(); |
|
78 | update(); | |
80 | } |
|
79 | } | |
81 |
|
80 | |||
82 |
|
81 | |||
83 | QSizeF BoxWhiskers::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
82 | QSizeF BoxWhiskers::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
84 | { |
|
83 | { | |
85 | //Q_UNUSED(which) |
|
84 | //Q_UNUSED(which) | |
86 | Q_UNUSED(constraint) |
|
85 | Q_UNUSED(constraint) | |
87 |
|
86 | |||
88 | qDebug() << "BoxWhiskers::sizeHint, which = " << which; |
|
87 | qDebug() << "BoxWhiskers::sizeHint, which = " << which; | |
89 |
|
88 | |||
90 | return QSizeF(); |
|
89 | return QSizeF(); | |
91 | } |
|
90 | } | |
92 |
|
91 | |||
93 | void BoxWhiskers::setGeometry(const QRectF &rect) // TODO: Unused? |
|
92 | void BoxWhiskers::setGeometry(const QRectF &rect) // TODO: Unused? | |
94 | { |
|
93 | { | |
95 | Q_UNUSED(rect) |
|
94 | Q_UNUSED(rect) | |
96 |
|
95 | |||
97 | qDebug() << "BoxWhiskers::setGeometry"; |
|
96 | qDebug() << "BoxWhiskers::setGeometry"; | |
98 | } |
|
97 | } | |
99 |
|
98 | |||
100 | void BoxWhiskers::setDomainSize(const QSizeF &size) |
|
99 | void BoxWhiskers::setDomainSize(const QSizeF &size) | |
101 | { |
|
100 | { | |
102 | m_domainSize = size; |
|
101 | m_domainSize = size; | |
103 |
|
102 | |||
104 | updateBoundingRect(); |
|
103 | updateBoundingRect(); | |
105 | } |
|
104 | } | |
106 |
|
105 | |||
107 | QRectF BoxWhiskers::boundingRect() const |
|
106 | QRectF BoxWhiskers::boundingRect() const | |
108 | { |
|
107 | { | |
109 | return m_boundingRect; |
|
108 | return m_boundingRect; | |
110 | } |
|
109 | } | |
111 |
|
110 | |||
112 | void BoxWhiskers::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
111 | void BoxWhiskers::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
113 | { |
|
112 | { | |
114 | Q_UNUSED(option) |
|
113 | Q_UNUSED(option) | |
115 | Q_UNUSED(widget) |
|
114 | Q_UNUSED(widget) | |
116 | //Q_UNUSED(painter) |
|
115 | //Q_UNUSED(painter) | |
117 |
|
116 | |||
118 | //painter->save(); |
|
117 | //painter->save(); | |
119 | //painter->setClipRect(parentItem()->boundingRect()); |
|
118 | //painter->setClipRect(parentItem()->boundingRect()); | |
120 | painter->setPen(m_pen); |
|
119 | painter->setPen(m_pen); | |
121 | painter->setBrush(m_brush); |
|
120 | painter->setBrush(m_brush); | |
122 | qreal spanY = m_data.m_maxY - m_data.m_minY; |
|
121 | qreal spanY = m_data.m_maxY - m_data.m_minY; | |
123 | //painter->setClipRect(parentItem()->boundingRect()); |
|
122 | //painter->setClipRect(parentItem()->boundingRect()); | |
124 | painter->scale(m_domainSize.width() / m_data.m_boxItems, m_domainSize.height() / spanY); |
|
123 | painter->scale(m_domainSize.width() / m_data.m_boxItems, m_domainSize.height() / spanY); | |
125 | painter->drawPath(m_boxPath); |
|
124 | painter->drawPath(m_boxPath); | |
126 | //painter->restore(); |
|
125 | //painter->restore(); | |
127 | } |
|
126 | } | |
128 |
|
127 | |||
129 | void BoxWhiskers::updateGeometry() |
|
128 | void BoxWhiskers::updateGeometry() | |
130 | { |
|
129 | { | |
131 | prepareGeometryChange(); |
|
130 | prepareGeometryChange(); | |
132 |
|
131 | |||
133 | QPainterPath path; |
|
132 | QPainterPath path; | |
134 |
|
133 | |||
135 | qreal columnWidth = 1.0 / m_data.m_seriesCount; |
|
134 | qreal columnWidth = 1.0 / m_data.m_seriesCount; | |
136 | qreal left = 0.25 * columnWidth + columnWidth * m_data.m_seriesIndex; |
|
135 | qreal left = 0.25 * columnWidth + columnWidth * m_data.m_seriesIndex; | |
137 | qreal right = 0.75 * columnWidth + columnWidth * m_data.m_seriesIndex; |
|
136 | qreal right = 0.75 * columnWidth + columnWidth * m_data.m_seriesIndex; | |
138 | qreal middle = 0.5 * columnWidth + columnWidth * m_data.m_seriesIndex; |
|
137 | qreal middle = 0.5 * columnWidth + columnWidth * m_data.m_seriesIndex; | |
139 |
|
138 | |||
140 | //whisker = 0.35 0.75 |
|
139 | //whisker = 0.35 0.75 | |
141 |
|
140 | |||
142 | // Upper whisker |
|
141 | // Upper whisker | |
143 | path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme); |
|
142 | path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme); | |
144 | path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme); |
|
143 | path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme); | |
145 | path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme); |
|
144 | path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme); | |
146 | path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile); |
|
145 | path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile); | |
147 | path.closeSubpath(); |
|
146 | path.closeSubpath(); | |
148 |
|
147 | |||
149 | // Middle Box |
|
148 | // Middle Box | |
150 | path.addRect(left + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile, |
|
149 | path.addRect(left + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile, | |
151 | 0.5 * columnWidth, m_data.m_upperQuartile - m_data.m_lowerQuartile); |
|
150 | 0.5 * columnWidth, m_data.m_upperQuartile - m_data.m_lowerQuartile); | |
152 |
|
151 | |||
153 | // Median/mean line |
|
152 | // Median/mean line | |
154 | path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_median); |
|
153 | path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_median); | |
155 | path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_median); |
|
154 | path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_median); | |
156 |
|
155 | |||
157 | // Lower whisker |
|
156 | // Lower whisker | |
158 | path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme); |
|
157 | path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme); | |
159 | path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme); |
|
158 | path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme); | |
160 | path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme); |
|
159 | path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme); | |
161 | path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerQuartile); |
|
160 | path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerQuartile); | |
162 | path.closeSubpath(); |
|
161 | path.closeSubpath(); | |
163 |
|
162 | |||
164 | m_boxPath = path; |
|
163 | m_boxPath = path; | |
165 |
|
164 | |||
166 | updateBoundingRect(); |
|
165 | updateBoundingRect(); | |
167 |
|
166 | |||
168 | // qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY); |
|
167 | // qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY); | |
169 | // qreal scaleX = m_domainSize.width() / m_data.m_boxItems; |
|
168 | // qreal scaleX = m_domainSize.width() / m_data.m_boxItems; | |
170 | // QRectF br = path.boundingRect(); |
|
169 | // QRectF br = path.boundingRect(); | |
171 | // m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY); |
|
170 | // m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY); | |
172 |
|
171 | |||
173 | if (m_data.m_index == 5) { |
|
172 | if (m_data.m_index == 5) { | |
174 | //qDebug() << "myValue = " << myValue; |
|
173 | //qDebug() << "myValue = " << myValue; | |
175 | //qDebug() << "m_data.m_upperExtreme" << m_data.m_upperExtreme; |
|
174 | //qDebug() << "m_data.m_upperExtreme" << m_data.m_upperExtreme; | |
176 | //qDebug() << "m_boundingRect = " << m_boundingRect; |
|
175 | //qDebug() << "m_boundingRect = " << m_boundingRect; | |
177 | // qDebug() << "x = " << m_boundingRect.x() << ", y = " << m_boundingRect.y() << ", width = " |
|
176 | // qDebug() << "x = " << m_boundingRect.x() << ", y = " << m_boundingRect.y() << ", width = " | |
178 | // << m_boundingRect.width() << ", height = " << m_boundingRect.height(); |
|
177 | // << m_boundingRect.width() << ", height = " << m_boundingRect.height(); | |
179 | } |
|
178 | } | |
180 | } |
|
179 | } | |
181 |
|
180 | |||
182 | void BoxWhiskers::updateBoundingRect() |
|
181 | void BoxWhiskers::updateBoundingRect() | |
183 | { |
|
182 | { | |
184 | qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY); |
|
183 | qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY); | |
185 | qreal scaleX = m_domainSize.width() / m_data.m_boxItems; |
|
184 | qreal scaleX = m_domainSize.width() / m_data.m_boxItems; | |
186 | QRectF br = m_boxPath.boundingRect(); |
|
185 | QRectF br = m_boxPath.boundingRect(); | |
187 | m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY); |
|
186 | m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY); | |
188 | } |
|
187 | } | |
189 |
|
188 | |||
190 | #include "moc_boxwhiskers_p.cpp" |
|
189 | #include "moc_boxwhiskers_p.cpp" | |
191 |
|
190 | |||
192 | QTCOMMERCIALCHART_END_NAMESPACE |
|
191 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,283 +1,576 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qboxplotseries.h" |
|
21 | #include "qboxplotseries.h" | |
22 | #include "qboxplotseries_p.h" |
|
22 | #include "qboxplotseries_p.h" | |
23 | #include "qboxplotlegendmarker.h" |
|
23 | #include "qboxplotlegendmarker.h" | |
|
24 | #include "qbarcategoryaxis.h" | |||
24 | #include "boxplotchartitem_p.h" |
|
25 | #include "boxplotchartitem_p.h" | |
25 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
26 | #include "charttheme_p.h" |
|
27 | #include "charttheme_p.h" | |
27 | #include "qvalueaxis.h" |
|
28 | #include "qvalueaxis.h" | |
28 | #include "charttheme_p.h" |
|
29 | #include "charttheme_p.h" | |
29 | #include "boxplotanimation_p.h" |
|
30 | #include "boxplotanimation_p.h" | |
30 | #include "qchart_p.h" |
|
31 | #include "qchart_p.h" | |
|
32 | #include "qboxset.h" | |||
|
33 | #include "qboxset_p.h" | |||
31 |
|
34 | |||
32 | #include <QDebug> |
|
35 | #include <QDebug> | |
33 |
|
36 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
38 | |||
36 | /*! |
|
39 | /*! | |
37 | \class QBoxPlotSeries |
|
40 | \class QBoxPlotSeries | |
38 | \brief Series for creating stacked bar chart |
|
41 | \brief Series for creating stacked bar chart | |
39 | \mainclass |
|
42 | \mainclass | |
40 |
|
43 | |||
41 | QBoxPlotSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
44 | QBoxPlotSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
42 | as stacks, where bars in same category are stacked on top of each other. |
|
45 | as stacks, where bars in same category are stacked on top of each other. | |
43 | QBoxPlotSeries groups the data from sets to categories, which are defined by QStringList. |
|
46 | QBoxPlotSeries groups the data from sets to categories, which are defined by QStringList. | |
44 |
|
47 | |||
45 | See the \l {BoxPlotChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
|
48 | See the \l {BoxPlotChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. | |
46 | \image examples_boxplotchart.png |
|
49 | \image examples_boxplotchart.png | |
47 |
|
50 | |||
48 |
\sa QB |
|
51 | \sa QBoxSet, QPercentBarSeries, QAbstractBarSeries | |
49 | */ |
|
52 | */ | |
50 |
|
53 | |||
51 | /*! |
|
54 | /*! | |
52 | \qmlclass BoxPlotSeries QBoxPlotSeries |
|
55 | \qmlclass BoxPlotSeries QBoxPlotSeries | |
53 | \inherits AbstractBarSeries |
|
56 | \inherits AbstractBarSeries | |
54 |
|
57 | |||
55 | The following QML shows how to create a simple stacked bar chart: |
|
58 | The following QML shows how to create a simple stacked bar chart: | |
56 | \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1 |
|
59 | \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1 | |
57 | \beginfloatleft |
|
60 | \beginfloatleft | |
58 | \image demos_qmlchart7.png |
|
61 | \image demos_qmlchart7.png | |
59 | \endfloat |
|
62 | \endfloat | |
60 | \clearfloat |
|
63 | \clearfloat | |
61 | */ |
|
64 | */ | |
62 |
|
65 | |||
63 | /*! |
|
66 | /*! | |
64 | Constructs empty QBoxPlotSeries. |
|
67 | Constructs empty QBoxPlotSeries. | |
65 | QBoxPlotSeries is QObject which is a child of a \a parent. |
|
68 | QBoxPlotSeries is QObject which is a child of a \a parent. | |
66 | */ |
|
69 | */ | |
67 | QBoxPlotSeries::QBoxPlotSeries(QObject *parent) |
|
70 | QBoxPlotSeries::QBoxPlotSeries(QObject *parent) | |
68 |
: QAbstract |
|
71 | : QAbstractSeries(*new QBoxPlotSeriesPrivate(this), parent) | |
69 | { |
|
72 | { | |
70 | } |
|
73 | } | |
71 |
|
74 | |||
72 | /*! |
|
75 | /*! | |
73 | Destructor. Removes series from chart. |
|
76 | Destructor. Removes series from chart. | |
74 | */ |
|
77 | */ | |
75 | QBoxPlotSeries::~QBoxPlotSeries() |
|
78 | QBoxPlotSeries::~QBoxPlotSeries() | |
76 | { |
|
79 | { | |
77 | qDebug() << "QBoxPlotSeries::~QBoxPlotSeries"; |
|
80 | qDebug() << "QBoxPlotSeries::~QBoxPlotSeries"; | |
78 |
|
81 | |||
79 | Q_D(QBoxPlotSeries); |
|
82 | Q_D(QBoxPlotSeries); | |
80 | if (d->m_chart) |
|
83 | if (d->m_chart) | |
81 | d->m_chart->removeSeries(this); |
|
84 | d->m_chart->removeSeries(this); | |
82 | } |
|
85 | } | |
83 |
|
86 | |||
84 | /*! |
|
87 | /*! | |
|
88 | Adds a single box and whiskers item to series. Takes ownership of \a the box. If the box is null or is already in series, it won't be appended. | |||
|
89 | Returns true, if appending succeeded. | |||
|
90 | */ | |||
|
91 | bool QBoxPlotSeries::append(QBoxSet *set) | |||
|
92 | { | |||
|
93 | Q_D(QBoxPlotSeries); | |||
|
94 | ||||
|
95 | bool success = d->append(set); | |||
|
96 | if (success) { | |||
|
97 | QList<QBoxSet *> sets; | |||
|
98 | sets.append(set); | |||
|
99 | set->setParent(this); | |||
|
100 | emit boxsetsAdded(sets); | |||
|
101 | emit countChanged(); | |||
|
102 | } | |||
|
103 | return success; | |||
|
104 | } | |||
|
105 | ||||
|
106 | /*! | |||
|
107 | Removes boxset from the series. Releases ownership of the \a set. Deletes the set, if remove | |||
|
108 | was successful. | |||
|
109 | Returns true, if the set was removed. | |||
|
110 | */ | |||
|
111 | bool QBoxPlotSeries::remove(QBoxSet *set) | |||
|
112 | { | |||
|
113 | Q_D(QBoxPlotSeries); | |||
|
114 | bool success = d->remove(set); | |||
|
115 | if (success) { | |||
|
116 | QList<QBoxSet *> sets; | |||
|
117 | sets.append(set); | |||
|
118 | set->setParent(0); | |||
|
119 | emit boxsetsRemoved(sets); | |||
|
120 | emit countChanged(); | |||
|
121 | delete set; | |||
|
122 | set = 0; | |||
|
123 | } | |||
|
124 | return success; | |||
|
125 | } | |||
|
126 | ||||
|
127 | /*! | |||
|
128 | Takes a single \a set from the series. Does not delete the boxset object. | |||
|
129 | ||||
|
130 | NOTE: The series remains as the boxset's parent object. You must set the | |||
|
131 | parent object to take full ownership. | |||
|
132 | ||||
|
133 | Returns true if take was successful. | |||
|
134 | */ | |||
|
135 | bool QBoxPlotSeries::take(QBoxSet *set) | |||
|
136 | { | |||
|
137 | Q_D(QBoxPlotSeries); | |||
|
138 | ||||
|
139 | bool success = d->remove(set); | |||
|
140 | if (success) { | |||
|
141 | QList<QBoxSet *> sets; | |||
|
142 | sets.append(set); | |||
|
143 | emit boxsetsRemoved(sets); | |||
|
144 | emit countChanged(); | |||
|
145 | } | |||
|
146 | return success; | |||
|
147 | } | |||
|
148 | ||||
|
149 | /*! | |||
|
150 | Adds a list of boxsets to series. Takes ownership of the \a sets. | |||
|
151 | Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series, | |||
|
152 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |||
|
153 | and function returns false. | |||
|
154 | */ | |||
|
155 | bool QBoxPlotSeries::append(QList<QBoxSet *> sets) | |||
|
156 | { | |||
|
157 | Q_D(QBoxPlotSeries); | |||
|
158 | bool success = d->append(sets); | |||
|
159 | if (success) { | |||
|
160 | emit boxsetsAdded(sets); | |||
|
161 | emit countChanged(); | |||
|
162 | } | |||
|
163 | return success; | |||
|
164 | } | |||
|
165 | ||||
|
166 | /*! | |||
|
167 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |||
|
168 | Returns true, if inserting succeeded. | |||
|
169 | ||||
|
170 | */ | |||
|
171 | bool QBoxPlotSeries::insert(int index, QBoxSet *set) | |||
|
172 | { | |||
|
173 | Q_D(QBoxPlotSeries); | |||
|
174 | bool success = d->insert(index, set); | |||
|
175 | if (success) { | |||
|
176 | QList<QBoxSet *> sets; | |||
|
177 | sets.append(set); | |||
|
178 | emit boxsetsAdded(sets); | |||
|
179 | emit countChanged(); | |||
|
180 | } | |||
|
181 | return success; | |||
|
182 | } | |||
|
183 | ||||
|
184 | /*! | |||
|
185 | Removes all boxsets from the series. Deletes removed sets. | |||
|
186 | */ | |||
|
187 | void QBoxPlotSeries::clear() | |||
|
188 | { | |||
|
189 | Q_D(QBoxPlotSeries); | |||
|
190 | QList<QBoxSet *> sets = boxSets(); | |||
|
191 | bool success = d->remove(sets); | |||
|
192 | if (success) { | |||
|
193 | emit boxsetsRemoved(sets); | |||
|
194 | emit countChanged(); | |||
|
195 | foreach (QBoxSet *set, sets) | |||
|
196 | delete set; | |||
|
197 | } | |||
|
198 | } | |||
|
199 | ||||
|
200 | /*! | |||
|
201 | Returns number of sets in series. | |||
|
202 | */ | |||
|
203 | int QBoxPlotSeries::count() const | |||
|
204 | { | |||
|
205 | Q_D(const QBoxPlotSeries); | |||
|
206 | return d->m_boxSets.count(); | |||
|
207 | } | |||
|
208 | ||||
|
209 | /*! | |||
|
210 | Returns a list of sets in series. Keeps ownership of sets. | |||
|
211 | */ | |||
|
212 | QList<QBoxSet *> QBoxPlotSeries::boxSets() const | |||
|
213 | { | |||
|
214 | Q_D(const QBoxPlotSeries); | |||
|
215 | return d->m_boxSets; | |||
|
216 | } | |||
|
217 | ||||
|
218 | /*! | |||
85 | Returns QChartSeries::SeriesTypeBoxPlot. |
|
219 | Returns QChartSeries::SeriesTypeBoxPlot. | |
86 | */ |
|
220 | */ | |
87 | QAbstractSeries::SeriesType QBoxPlotSeries::type() const |
|
221 | QAbstractSeries::SeriesType QBoxPlotSeries::type() const | |
88 | { |
|
222 | { | |
89 | return QAbstractSeries::SeriesTypeBoxPlot; |
|
223 | return QAbstractSeries::SeriesTypeBoxPlot; | |
90 | } |
|
224 | } | |
91 |
|
225 | |||
92 | void QBoxPlotSeries::setBrush(const QBrush &brush) |
|
226 | void QBoxPlotSeries::setBrush(const QBrush &brush) | |
93 | { |
|
227 | { | |
94 | Q_D(QBoxPlotSeries); |
|
228 | Q_D(QBoxPlotSeries); | |
95 |
|
229 | |||
96 | if (d->m_brush != brush) { |
|
230 | if (d->m_brush != brush) { | |
97 | d->m_brush = brush; |
|
231 | d->m_brush = brush; | |
98 | emit d->updated(); |
|
232 | emit d->updated(); | |
99 | } |
|
233 | } | |
100 | } |
|
234 | } | |
101 |
|
235 | |||
102 | QBrush QBoxPlotSeries::brush() const |
|
236 | QBrush QBoxPlotSeries::brush() const | |
103 | { |
|
237 | { | |
104 | Q_D(const QBoxPlotSeries); |
|
238 | Q_D(const QBoxPlotSeries); | |
105 |
|
239 | |||
106 | return d->m_brush; |
|
240 | return d->m_brush; | |
107 | } |
|
241 | } | |
108 |
|
242 | |||
109 | void QBoxPlotSeries::setPen(const QPen &pen) |
|
243 | void QBoxPlotSeries::setPen(const QPen &pen) | |
110 | { |
|
244 | { | |
111 | Q_D(QBoxPlotSeries); |
|
245 | Q_D(QBoxPlotSeries); | |
112 |
|
246 | |||
113 | if (d->m_pen != pen) { |
|
247 | if (d->m_pen != pen) { | |
114 | d->m_pen = pen; |
|
248 | d->m_pen = pen; | |
115 | emit d->updated(); |
|
249 | emit d->updated(); | |
116 | } |
|
250 | } | |
117 | } |
|
251 | } | |
118 |
|
252 | |||
119 | QPen QBoxPlotSeries::pen() const |
|
253 | QPen QBoxPlotSeries::pen() const | |
120 | { |
|
254 | { | |
121 | Q_D(const QBoxPlotSeries); |
|
255 | Q_D(const QBoxPlotSeries); | |
122 |
|
256 | |||
123 | return d->m_pen; |
|
257 | return d->m_pen; | |
124 | } |
|
258 | } | |
125 |
|
259 | |||
126 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
260 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
127 |
|
261 | |||
128 | QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q) |
|
262 | QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q) | |
129 |
: QAbstract |
|
263 | : QAbstractSeriesPrivate(q), | |
130 | m_pen(QPen(Qt::NoPen)), |
|
264 | m_pen(QPen(Qt::NoPen)), | |
131 | m_brush(QBrush(Qt::NoBrush)) |
|
265 | m_brush(QBrush(Qt::NoBrush)) | |
132 | { |
|
266 | { | |
133 | } |
|
267 | } | |
134 |
|
268 | |||
135 | QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate() |
|
269 | QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate() | |
136 | { |
|
270 | { | |
137 | qDebug() << "QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate()"; |
|
271 | qDebug() << "QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate()"; | |
138 | disconnect(this, 0, 0, 0); |
|
272 | disconnect(this, 0, 0, 0); | |
139 | } |
|
273 | } | |
140 |
|
274 | |||
141 | void QBoxPlotSeriesPrivate::initializeDomain() |
|
275 | void QBoxPlotSeriesPrivate::initializeDomain() | |
142 | { |
|
276 | { | |
143 | qreal minX(domain()->minX()); |
|
277 | qreal minX(domain()->minX()); | |
144 | qreal minY(domain()->minY()); |
|
278 | qreal minY(domain()->minY()); | |
145 | qreal maxX(domain()->maxX()); |
|
279 | qreal maxX(domain()->maxX()); | |
146 | qreal maxY(domain()->maxY()); |
|
280 | qreal maxY(domain()->maxY()); | |
147 |
|
281 | |||
148 |
qreal x = |
|
282 | qreal x = m_boxSets.count(); | |
149 | minX = qMin(minX, - (qreal)0.5); |
|
283 | minX = qMin(minX, - (qreal)0.5); | |
150 | minY = qMin(minY, bottom()); |
|
284 | minY = qMin(minY, bottom()); | |
151 | maxX = qMax(maxX, x - (qreal)0.5); |
|
285 | maxX = qMax(maxX, x - (qreal)0.5); | |
152 | //maxY = qMax(maxY, top()); |
|
|||
153 | maxY = qMax(maxY, max()); |
|
286 | maxY = qMax(maxY, max()); | |
154 |
|
287 | |||
155 | domain()->setRange(minX, maxX, minY, maxY); |
|
288 | domain()->setRange(minX, maxX, minY, maxY); | |
156 | } |
|
289 | } | |
157 |
|
290 | |||
|
291 | void QBoxPlotSeriesPrivate::initializeAxes() | |||
|
292 | { | |||
|
293 | foreach (QAbstractAxis* axis, m_axes) { | |||
|
294 | if (axis->type() == QAbstractAxis::AxisTypeBarCategory) { | |||
|
295 | if (axis->orientation() == Qt::Horizontal) | |||
|
296 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); | |||
|
297 | else | |||
|
298 | qDebug() << "ALERT: QBoxPlotSeriesPrivate::initializeAxes implement #1"; | |||
|
299 | } | |||
|
300 | } | |||
|
301 | } | |||
|
302 | ||||
|
303 | QAbstractAxis::AxisType QBoxPlotSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |||
|
304 | { | |||
|
305 | if (orientation == Qt::Horizontal) | |||
|
306 | return QAbstractAxis::AxisTypeBarCategory; | |||
|
307 | ||||
|
308 | return QAbstractAxis::AxisTypeValue; | |||
|
309 | } | |||
|
310 | ||||
|
311 | QAbstractAxis* QBoxPlotSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |||
|
312 | { | |||
|
313 | Q_UNUSED(orientation); | |||
|
314 | // This is not implemented even in barseries, keep in touch if something needs this | |||
|
315 | qDebug() << "ALERT: QBoxPlotSeriesPrivate::createDefaultAxis implement"; | |||
|
316 | return 0; | |||
|
317 | } | |||
|
318 | ||||
|
319 | void QBoxPlotSeriesPrivate::populateCategories(QBarCategoryAxis *axis) | |||
|
320 | { | |||
|
321 | QStringList categories; | |||
|
322 | if (axis->categories().isEmpty()) { | |||
|
323 | for (int i(1); i < m_boxSets.count() + 1; i++) | |||
|
324 | categories << QString::number(i); | |||
|
325 | axis->append(categories); | |||
|
326 | } | |||
|
327 | } | |||
|
328 | ||||
158 | void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
329 | void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
159 | { |
|
330 | { | |
160 | Q_Q(QBoxPlotSeries); |
|
331 | Q_Q(QBoxPlotSeries); | |
161 |
|
332 | |||
162 | BoxPlotChartItem *boxPlot = new BoxPlotChartItem(q,parent); |
|
333 | BoxPlotChartItem *boxPlot = new BoxPlotChartItem(q,parent); | |
163 | m_item.reset(boxPlot); |
|
334 | m_item.reset(boxPlot); | |
164 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
335 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
165 |
|
336 | |||
166 | if (m_chart) { |
|
337 | if (m_chart) { | |
167 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesChange(QAbstractSeries*)) ); |
|
338 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesChange(QAbstractSeries*)) ); | |
168 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) ); |
|
339 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) ); | |
169 |
|
340 | |||
170 | QList<QAbstractSeries *> serieses = m_chart->series(); |
|
341 | QList<QAbstractSeries *> serieses = m_chart->series(); | |
171 |
|
342 | |||
172 | // Tries to find this series from the Chart's list of serieses and deduce the index |
|
343 | // Tries to find this series from the Chart's list of serieses and deduce the index | |
173 | int index = 0; |
|
344 | int index = 0; | |
174 | foreach (QAbstractSeries *s, serieses) { |
|
345 | foreach (QAbstractSeries *s, serieses) { | |
175 | if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) { |
|
346 | if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) { | |
176 | if (q == static_cast<QBoxPlotSeries *>(s)) { |
|
347 | if (q == static_cast<QBoxPlotSeries *>(s)) { | |
177 | boxPlot->m_seriesIndex = index; |
|
348 | boxPlot->m_seriesIndex = index; | |
178 | m_index = index; |
|
349 | m_index = index; | |
179 | } |
|
350 | } | |
180 | index++; |
|
351 | index++; | |
181 | } |
|
352 | } | |
182 | } |
|
353 | } | |
183 | boxPlot->m_seriesCount = index; |
|
354 | boxPlot->m_seriesCount = index; | |
184 | } |
|
355 | } | |
185 |
|
356 | |||
186 | // Make BoxPlotChartItem to instantiate box & whisker items |
|
357 | // Make BoxPlotChartItem to instantiate box & whisker items | |
187 | boxPlot->handleDataStructureChanged(); |
|
358 | boxPlot->handleDataStructureChanged(); | |
188 | } |
|
359 | } | |
189 |
|
360 | |||
190 | void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
361 | void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |
191 | { |
|
362 | { | |
192 | Q_Q(QBoxPlotSeries); |
|
363 | Q_Q(QBoxPlotSeries); | |
193 | qDebug() << "QBoxPlotSeriesPrivate::initializeTheme"; |
|
364 | qDebug() << "QBoxPlotSeriesPrivate::initializeTheme"; | |
194 |
|
365 | |||
195 | const QList<QGradient> gradients = theme->seriesGradients(); |
|
366 | const QList<QGradient> gradients = theme->seriesGradients(); | |
196 |
|
367 | |||
197 | if (forced || m_brush == QBrush(Qt::NoBrush)) { |
|
368 | if (forced || m_brush == QBrush(Qt::NoBrush)) { | |
198 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.5); |
|
369 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.5); | |
199 | q->setBrush(brushColor); |
|
370 | q->setBrush(brushColor); | |
200 | } |
|
371 | } | |
201 |
|
372 | |||
202 | if (forced || m_pen == QPen(Qt::NoPen)) { |
|
373 | if (forced || m_pen == QPen(Qt::NoPen)) { | |
203 | QPen pen = theme->outlinePen(); |
|
374 | QPen pen = theme->outlinePen(); | |
204 | pen.setCosmetic(true); |
|
375 | pen.setCosmetic(true); | |
205 | q->setPen(pen); |
|
376 | q->setPen(pen); | |
206 | } |
|
377 | } | |
207 | } |
|
378 | } | |
208 |
|
379 | |||
209 | void QBoxPlotSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) |
|
380 | void QBoxPlotSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |
210 | { |
|
381 | { | |
211 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); |
|
382 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); | |
212 | Q_ASSERT(item); |
|
383 | Q_ASSERT(item); | |
213 | if (options.testFlag(QChart::SeriesAnimations)) { |
|
384 | if (options.testFlag(QChart::SeriesAnimations)) { | |
214 | item->setAnimation(new BoxPlotAnimation(item)); |
|
385 | item->setAnimation(new BoxPlotAnimation(item)); | |
215 | }else{ |
|
386 | }else{ | |
216 | item->setAnimation((BoxPlotAnimation *)0); |
|
387 | item->setAnimation((BoxPlotAnimation *)0); | |
217 | } |
|
388 | } | |
218 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
389 | QAbstractSeriesPrivate::initializeAnimations(options); | |
219 | } |
|
390 | } | |
220 |
|
391 | |||
221 | QList<QLegendMarker*> QBoxPlotSeriesPrivate::createLegendMarkers(QLegend *legend) |
|
392 | QList<QLegendMarker*> QBoxPlotSeriesPrivate::createLegendMarkers(QLegend *legend) | |
222 | { |
|
393 | { | |
223 | Q_Q(QBoxPlotSeries); |
|
394 | Q_Q(QBoxPlotSeries); | |
224 | QList<QLegendMarker*> list; |
|
395 | QList<QLegendMarker*> list; | |
225 | return list << new QBoxPlotLegendMarker(q, legend); |
|
396 | return list << new QBoxPlotLegendMarker(q, legend); | |
226 | } |
|
397 | } | |
227 |
|
398 | |||
228 | void QBoxPlotSeriesPrivate::handleSeriesRemove(QAbstractSeries *series) |
|
399 | void QBoxPlotSeriesPrivate::handleSeriesRemove(QAbstractSeries *series) | |
229 | { |
|
400 | { | |
230 | qDebug() << "QBoxPlotSeriesPrivate::handleSeriesRemove"; |
|
401 | qDebug() << "QBoxPlotSeriesPrivate::handleSeriesRemove"; | |
231 | Q_Q(QBoxPlotSeries); |
|
402 | Q_Q(QBoxPlotSeries); | |
232 |
|
403 | |||
233 | QBoxPlotSeries *removedSeries = static_cast<QBoxPlotSeries *>(series); |
|
404 | QBoxPlotSeries *removedSeries = static_cast<QBoxPlotSeries *>(series); | |
234 | QObject::disconnect(m_chart->d_ptr->m_dataset, 0, removedSeries->d_func(), 0); |
|
405 | QObject::disconnect(m_chart->d_ptr->m_dataset, 0, removedSeries->d_func(), 0); | |
235 |
|
406 | |||
236 | // Test if series removed is me, then don't do anything |
|
407 | // Test if series removed is me, then don't do anything | |
237 | if (q != removedSeries) { |
|
408 | if (q != removedSeries) { | |
238 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); |
|
409 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); | |
239 | if (item) { |
|
410 | if (item) { | |
240 | item->m_seriesCount = item->m_seriesCount - 1; |
|
411 | item->m_seriesCount = item->m_seriesCount - 1; | |
241 | if (removedSeries->d_func()->m_index < m_index) { |
|
412 | if (removedSeries->d_func()->m_index < m_index) { | |
242 | m_index--; |
|
413 | m_index--; | |
243 | item->m_seriesIndex = m_index; |
|
414 | item->m_seriesIndex = m_index; | |
244 | } |
|
415 | } | |
245 |
|
416 | |||
246 | item->handleDataStructureChanged(); |
|
417 | item->handleDataStructureChanged(); | |
247 | } |
|
418 | } | |
248 | } |
|
419 | } | |
249 | } |
|
420 | } | |
250 |
|
421 | |||
251 | void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series) |
|
422 | void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series) | |
252 | { |
|
423 | { | |
253 | Q_UNUSED(series); |
|
424 | Q_UNUSED(series); | |
254 |
|
425 | |||
255 | Q_Q(QBoxPlotSeries); |
|
426 | Q_Q(QBoxPlotSeries); | |
256 |
|
427 | |||
257 | BoxPlotChartItem *boxPlot = static_cast<BoxPlotChartItem *>(m_item.data()); |
|
428 | BoxPlotChartItem *boxPlot = static_cast<BoxPlotChartItem *>(m_item.data()); | |
258 |
|
429 | |||
259 | if (m_chart) { |
|
430 | if (m_chart) { | |
260 | QList<QAbstractSeries *> serieses = m_chart->series(); |
|
431 | QList<QAbstractSeries *> serieses = m_chart->series(); | |
261 |
|
432 | |||
262 | // Tries to find this series from the Chart's list of serieses and deduce the index |
|
433 | // Tries to find this series from the Chart's list of serieses and deduce the index | |
263 | int index = 0; |
|
434 | int index = 0; | |
264 | foreach (QAbstractSeries *s, serieses) { |
|
435 | foreach (QAbstractSeries *s, serieses) { | |
265 | if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) { |
|
436 | if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) { | |
266 | if (q == static_cast<QBoxPlotSeries *>(s)) { |
|
437 | if (q == static_cast<QBoxPlotSeries *>(s)) { | |
267 | boxPlot->m_seriesIndex = index; |
|
438 | boxPlot->m_seriesIndex = index; | |
268 | m_index = index; |
|
439 | m_index = index; | |
269 | } |
|
440 | } | |
270 | index++; |
|
441 | index++; | |
271 | } |
|
442 | } | |
272 | } |
|
443 | } | |
273 | boxPlot->m_seriesCount = index; |
|
444 | boxPlot->m_seriesCount = index; | |
274 | } |
|
445 | } | |
275 |
|
446 | |||
276 | boxPlot->handleDataStructureChanged(); |
|
447 | boxPlot->handleDataStructureChanged(); | |
277 | } |
|
448 | } | |
278 |
|
449 | |||
|
450 | bool QBoxPlotSeriesPrivate::append(QBoxSet *set) | |||
|
451 | { | |||
|
452 | if ((m_boxSets.contains(set)) || (set == 0)) | |||
|
453 | return false; // Fail if set is already in list or set is null. | |||
|
454 | ||||
|
455 | m_boxSets.append(set); | |||
|
456 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |||
|
457 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); | |||
|
458 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); | |||
|
459 | ||||
|
460 | emit restructuredBoxes(); // this notifies boxplotchartitem | |||
|
461 | return true; | |||
|
462 | } | |||
|
463 | ||||
|
464 | bool QBoxPlotSeriesPrivate::remove(QBoxSet *set) | |||
|
465 | { | |||
|
466 | if (!m_boxSets.contains(set)) | |||
|
467 | return false; // Fail if set is not in list | |||
|
468 | ||||
|
469 | m_boxSets.removeOne(set); | |||
|
470 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |||
|
471 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); | |||
|
472 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); | |||
|
473 | ||||
|
474 | emit restructuredBoxes(); // this notifies boxplotchartitem | |||
|
475 | return true; | |||
|
476 | } | |||
|
477 | ||||
|
478 | bool QBoxPlotSeriesPrivate::append(QList<QBoxSet * > sets) | |||
|
479 | { | |||
|
480 | foreach (QBoxSet *set, sets) { | |||
|
481 | if ((set == 0) || (m_boxSets.contains(set))) | |||
|
482 | return false; // Fail if any of the sets is null or is already appended. | |||
|
483 | if (sets.count(set) != 1) | |||
|
484 | return false; // Also fail if same set is more than once in given list. | |||
|
485 | } | |||
|
486 | ||||
|
487 | foreach (QBoxSet *set, sets) { | |||
|
488 | m_boxSets.append(set); | |||
|
489 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |||
|
490 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); | |||
|
491 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); | |||
|
492 | } | |||
|
493 | ||||
|
494 | emit restructuredBoxes(); // this notifies boxplotchartitem | |||
|
495 | return true; | |||
|
496 | } | |||
|
497 | ||||
|
498 | bool QBoxPlotSeriesPrivate::remove(QList<QBoxSet * > sets) | |||
|
499 | { | |||
|
500 | if (sets.count() == 0) | |||
|
501 | return false; | |||
|
502 | ||||
|
503 | foreach (QBoxSet *set, sets) { | |||
|
504 | if ((set == 0) || (!m_boxSets.contains(set))) | |||
|
505 | return false; // Fail if any of the sets is null or is not in series | |||
|
506 | if (sets.count(set) != 1) | |||
|
507 | return false; // Also fail if same set is more than once in given list. | |||
|
508 | } | |||
|
509 | ||||
|
510 | foreach (QBoxSet *set, sets) { | |||
|
511 | m_boxSets.removeOne(set); | |||
|
512 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |||
|
513 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); | |||
|
514 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); | |||
|
515 | } | |||
|
516 | ||||
|
517 | emit restructuredBoxes(); // this notifies boxplotchartitem | |||
|
518 | ||||
|
519 | return true; | |||
|
520 | } | |||
|
521 | ||||
|
522 | bool QBoxPlotSeriesPrivate::insert(int index, QBoxSet *set) | |||
|
523 | { | |||
|
524 | if ((m_boxSets.contains(set)) || (set == 0)) | |||
|
525 | return false; // Fail if set is already in list or set is null. | |||
|
526 | ||||
|
527 | m_boxSets.insert(index, set); | |||
|
528 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |||
|
529 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); | |||
|
530 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); | |||
|
531 | ||||
|
532 | emit restructuredBoxes(); // this notifies boxplotchartitem | |||
|
533 | return true; | |||
|
534 | } | |||
|
535 | ||||
|
536 | QBoxSet *QBoxPlotSeriesPrivate::boxsetAt(int index) | |||
|
537 | { | |||
|
538 | return m_boxSets.at(index); | |||
|
539 | } | |||
|
540 | ||||
|
541 | qreal QBoxPlotSeriesPrivate::bottom() | |||
|
542 | { | |||
|
543 | // Returns bottom of all boxes | |||
|
544 | qreal bottom(0); | |||
|
545 | foreach (QBoxSet *set, m_boxSets) { | |||
|
546 | for (int i = 0; i < set->count(); i++) { | |||
|
547 | if (set->at(i) < bottom) | |||
|
548 | bottom = set->at(i); | |||
|
549 | } | |||
|
550 | } | |||
|
551 | ||||
|
552 | return bottom; | |||
|
553 | } | |||
|
554 | ||||
|
555 | qreal QBoxPlotSeriesPrivate::max() | |||
|
556 | { | |||
|
557 | if (m_boxSets.count() <= 0) | |||
|
558 | return 0; | |||
|
559 | ||||
|
560 | qreal max = INT_MIN; | |||
|
561 | ||||
|
562 | foreach (QBoxSet *set, m_boxSets) { | |||
|
563 | for (int i = 0; i < set->count(); i++) { | |||
|
564 | if (set->at(i) > max) | |||
|
565 | max = set->at(i); | |||
|
566 | } | |||
|
567 | } | |||
|
568 | ||||
|
569 | return max; | |||
|
570 | } | |||
|
571 | ||||
279 | #include "moc_qboxplotseries.cpp" |
|
572 | #include "moc_qboxplotseries.cpp" | |
280 | #include "moc_qboxplotseries_p.cpp" |
|
573 | #include "moc_qboxplotseries_p.cpp" | |
281 |
|
574 | |||
282 | QTCOMMERCIALCHART_END_NAMESPACE |
|
575 | QTCOMMERCIALCHART_END_NAMESPACE | |
283 |
|
576 |
@@ -1,55 +1,78 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QBOXPLOTSERIES_H |
|
21 | #ifndef QBOXPLOTSERIES_H | |
22 | #define QBOXPLOTSERIES_H |
|
22 | #define QBOXPLOTSERIES_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 |
#include <q |
|
25 | #include <qboxset.h> | |
|
26 | //#include <qabstractbarseries.h> | |||
|
27 | #include <qabstractseries.h> | |||
26 |
|
28 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
30 | |||
29 | class QBoxPlotSeriesPrivate; |
|
31 | class QBoxPlotSeriesPrivate; | |
30 | //class QBarSet; |
|
32 | //class QBarSet; | |
31 |
|
33 | |||
32 |
class QTCOMMERCIALCHART_EXPORT QBoxPlotSeries : public QAbstract |
|
34 | class QTCOMMERCIALCHART_EXPORT QBoxPlotSeries : public QAbstractSeries | |
33 | { |
|
35 | { | |
34 | Q_OBJECT |
|
36 | Q_OBJECT | |
35 | public: |
|
37 | public: | |
36 | explicit QBoxPlotSeries(QObject *parent = 0); |
|
38 | explicit QBoxPlotSeries(QObject *parent = 0); | |
37 | ~QBoxPlotSeries(); |
|
39 | ~QBoxPlotSeries(); | |
38 |
|
40 | |||
|
41 | bool append(QBoxSet *box); | |||
|
42 | bool remove(QBoxSet *box); | |||
|
43 | bool take(QBoxSet *box); | |||
|
44 | bool append(QList<QBoxSet *> boxes); | |||
|
45 | bool insert(int index, QBoxSet *box); | |||
|
46 | int count() const; | |||
|
47 | QList<QBoxSet *> boxSets() const; | |||
|
48 | void clear(); | |||
|
49 | ||||
|
50 | void setLabelsVisible(bool visible = true); | |||
|
51 | bool isLabelsVisible() const; | |||
|
52 | ||||
39 | QAbstractSeries::SeriesType type() const; |
|
53 | QAbstractSeries::SeriesType type() const; | |
40 |
|
54 | |||
41 | void setBrush(const QBrush &brush); |
|
55 | void setBrush(const QBrush &brush); | |
42 | QBrush brush() const; |
|
56 | QBrush brush() const; | |
43 | void setPen(const QPen &pen); |
|
57 | void setPen(const QPen &pen); | |
44 | QPen pen() const; |
|
58 | QPen pen() const; | |
45 |
|
59 | |||
|
60 | Q_SIGNALS: | |||
|
61 | void clicked(int index, QBoxSet *boxset); | |||
|
62 | void hovered(bool status, QBoxSet *boxset); | |||
|
63 | void countChanged(); | |||
|
64 | void labelsVisibleChanged(); | |||
|
65 | ||||
|
66 | void boxsetsAdded(QList<QBoxSet *> sets); | |||
|
67 | void boxsetsRemoved(QList<QBoxSet *> sets); | |||
|
68 | ||||
46 | private: |
|
69 | private: | |
47 | Q_DECLARE_PRIVATE(QBoxPlotSeries) |
|
70 | Q_DECLARE_PRIVATE(QBoxPlotSeries) | |
48 | Q_DISABLE_COPY(QBoxPlotSeries) |
|
71 | Q_DISABLE_COPY(QBoxPlotSeries) | |
49 | friend class BoxPlotChartItem; |
|
72 | friend class BoxPlotChartItem; | |
50 | friend class QBoxPlotLegendMarkerPrivate; |
|
73 | friend class QBoxPlotLegendMarkerPrivate; | |
51 | }; |
|
74 | }; | |
52 |
|
75 | |||
53 | QTCOMMERCIALCHART_END_NAMESPACE |
|
76 | QTCOMMERCIALCHART_END_NAMESPACE | |
54 |
|
77 | |||
55 | #endif // QBOXPLOTSERIES_H |
|
78 | #endif // QBOXPLOTSERIES_H |
@@ -1,73 +1,95 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QBOXPLOTSERIES_P_H |
|
30 | #ifndef QBOXPLOTSERIES_P_H | |
31 | #define QBOXPLOTSERIES_P_H |
|
31 | #define QBOXPLOTSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qboxplotseries.h" |
|
33 | #include "qboxplotseries.h" | |
34 | #include "qabstractbarseries_p.h" |
|
34 | #include "qabstractbarseries_p.h" | |
35 | #include "abstractdomain_p.h" |
|
35 | #include "abstractdomain_p.h" | |
36 | #include "qbarset.h" |
|
36 | #include "qbarset.h" | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 |
class QBoxPlotSeriesPrivate : public QAbstract |
|
40 | class QBoxPlotSeriesPrivate : public QAbstractSeriesPrivate | |
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 |
|
43 | |||
44 | public: |
|
44 | public: | |
45 | QBoxPlotSeriesPrivate(QBoxPlotSeries *q); |
|
45 | QBoxPlotSeriesPrivate(QBoxPlotSeries *q); | |
46 | ~QBoxPlotSeriesPrivate(); |
|
46 | ~QBoxPlotSeriesPrivate(); | |
47 |
|
47 | |||
48 | void initializeGraphics(QGraphicsItem* parent); |
|
48 | void initializeGraphics(QGraphicsItem* parent); | |
49 | void initializeDomain(); |
|
49 | void initializeDomain(); | |
|
50 | void initializeAxes(); | |||
50 | void initializeAnimations(QChart::AnimationOptions options); |
|
51 | void initializeAnimations(QChart::AnimationOptions options); | |
51 | void initializeTheme(int index, ChartTheme* theme, bool forced = false); |
|
52 | void initializeTheme(int index, ChartTheme* theme, bool forced = false); | |
52 |
|
53 | |||
53 | QList<QLegendMarker*> createLegendMarkers(QLegend *legend); |
|
54 | QList<QLegendMarker*> createLegendMarkers(QLegend *legend); | |
54 |
|
55 | |||
|
56 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; | |||
|
57 | QAbstractAxis* createDefaultAxis(Qt::Orientation orientation) const; | |||
|
58 | ||||
|
59 | bool append(QBoxSet *set); | |||
|
60 | bool remove(QBoxSet *set); | |||
|
61 | bool append(QList<QBoxSet *> sets); | |||
|
62 | bool remove(QList<QBoxSet *> sets); | |||
|
63 | bool insert(int index, QBoxSet *set); | |||
|
64 | QBoxSet *boxsetAt(int index); | |||
|
65 | ||||
|
66 | qreal max(); | |||
|
67 | qreal bottom(); | |||
|
68 | ||||
|
69 | private: | |||
|
70 | void populateCategories(QBarCategoryAxis *axis); | |||
|
71 | ||||
55 | Q_SIGNALS: |
|
72 | Q_SIGNALS: | |
56 | void updated(); |
|
73 | void updated(); | |
|
74 | void clicked(int index, QBoxSet *barset); | |||
|
75 | void updatedBoxes(); | |||
|
76 | void updatedLayout(); | |||
|
77 | void restructuredBoxes(); | |||
57 |
|
78 | |||
58 | private slots: |
|
79 | private slots: | |
59 | void handleSeriesChange(QAbstractSeries *series); |
|
80 | void handleSeriesChange(QAbstractSeries *series); | |
60 | void handleSeriesRemove(QAbstractSeries *series); |
|
81 | void handleSeriesRemove(QAbstractSeries *series); | |
61 |
|
82 | |||
62 | protected: |
|
83 | protected: | |
|
84 | QList<QBoxSet *> m_boxSets; | |||
63 | QPen m_pen; |
|
85 | QPen m_pen; | |
64 | QBrush m_brush; |
|
86 | QBrush m_brush; | |
65 | int m_index; |
|
87 | int m_index; | |
66 |
|
88 | |||
67 | private: |
|
89 | private: | |
68 | Q_DECLARE_PUBLIC(QBoxPlotSeries) |
|
90 | Q_DECLARE_PUBLIC(QBoxPlotSeries) | |
69 | }; |
|
91 | }; | |
70 |
|
92 | |||
71 | QTCOMMERCIALCHART_END_NAMESPACE |
|
93 | QTCOMMERCIALCHART_END_NAMESPACE | |
72 |
|
94 | |||
73 | #endif |
|
95 | #endif |
@@ -1,359 +1,358 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "mainwidget.h" |
|
21 | #include "mainwidget.h" | |
22 | #include "customtablemodel.h" |
|
22 | #include "customtablemodel.h" | |
23 | #include <QVBarModelMapper> |
|
23 | #include <QVBarModelMapper> | |
24 | #include <QTableView> |
|
24 | #include <QTableView> | |
25 | #include <QHeaderView> |
|
25 | #include <QHeaderView> | |
26 | #include <QChartView> |
|
26 | #include <QChartView> | |
27 | #include <QBoxPlotSeries> |
|
27 | #include <QBoxPlotSeries> | |
28 |
#include <QB |
|
28 | #include <QBoxSet> | |
29 | #include <QLegend> |
|
29 | #include <QLegend> | |
30 | #include <QBarCategoryAxis> |
|
30 | #include <QBarCategoryAxis> | |
31 | #include <QBrush> |
|
31 | #include <QBrush> | |
32 | #include <QColor> |
|
32 | #include <QColor> | |
33 | #include <QPushButton> |
|
33 | #include <QPushButton> | |
34 | #include <QComboBox> |
|
34 | #include <QComboBox> | |
35 | #include <QSpinBox> |
|
35 | #include <QSpinBox> | |
36 | #include <QCheckBox> |
|
36 | #include <QCheckBox> | |
37 | #include <QGridLayout> |
|
37 | #include <QGridLayout> | |
38 | #include <QHBoxLayout> |
|
38 | #include <QHBoxLayout> | |
39 | #include <QLabel> |
|
39 | #include <QLabel> | |
40 | #include <QSpacerItem> |
|
40 | #include <QSpacerItem> | |
41 | #include <QMessageBox> |
|
41 | #include <QMessageBox> | |
42 | #include <cmath> |
|
42 | #include <cmath> | |
43 | #include <QDebug> |
|
43 | #include <QDebug> | |
44 | #include <QStandardItemModel> |
|
44 | #include <QStandardItemModel> | |
45 | #include <QBarCategoryAxis> |
|
45 | #include <QBarCategoryAxis> | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
48 | QTCOMMERCIALCHART_USE_NAMESPACE | |
49 |
|
49 | |||
50 | QString addCategories[] = {"Jul", "Aug", "Sep", "Nov", "Dec"}; |
|
50 | QString addCategories[] = {"Jul", "Aug", "Sep", "Nov", "Dec"}; | |
51 |
|
51 | |||
52 | MainWidget::MainWidget(QWidget *parent) : |
|
52 | MainWidget::MainWidget(QWidget *parent) : | |
53 | QWidget(parent), |
|
53 | QWidget(parent), | |
54 | m_chart(0), |
|
54 | m_chart(0), | |
55 | rowPos(0), |
|
55 | rowPos(0), | |
56 | nSeries(0), |
|
56 | nSeries(0), | |
57 | nNewBoxes(0) |
|
57 | nNewBoxes(0) | |
58 | { |
|
58 | { | |
59 | m_chart = new QChart(); |
|
59 | m_chart = new QChart(); | |
60 |
|
60 | |||
61 | // Grid layout for the controls for configuring the chart widget |
|
61 | // Grid layout for the controls for configuring the chart widget | |
62 | QGridLayout *grid = new QGridLayout(); |
|
62 | QGridLayout *grid = new QGridLayout(); | |
63 |
|
63 | |||
64 | // Create add a series button |
|
64 | // Create add a series button | |
65 | QPushButton *addSeriesButton = new QPushButton("Add a series"); |
|
65 | QPushButton *addSeriesButton = new QPushButton("Add a series"); | |
66 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
66 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
67 | grid->addWidget(addSeriesButton, rowPos++, 1); |
|
67 | grid->addWidget(addSeriesButton, rowPos++, 1); | |
68 |
|
68 | |||
69 | // Create remove a series button |
|
69 | // Create remove a series button | |
70 | QPushButton *removeSeriesButton = new QPushButton("Remove a series"); |
|
70 | QPushButton *removeSeriesButton = new QPushButton("Remove a series"); | |
71 | connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries())); |
|
71 | connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries())); | |
72 | grid->addWidget(removeSeriesButton, rowPos++, 1); |
|
72 | grid->addWidget(removeSeriesButton, rowPos++, 1); | |
73 |
|
73 | |||
74 | // Create add a single box button |
|
74 | // Create add a single box button | |
75 | QPushButton *addBoxButton = new QPushButton("Add a box"); |
|
75 | QPushButton *addBoxButton = new QPushButton("Add a box"); | |
76 | connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox())); |
|
76 | connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox())); | |
77 | grid->addWidget(addBoxButton, rowPos++, 1); |
|
77 | grid->addWidget(addBoxButton, rowPos++, 1); | |
78 |
|
78 | |||
79 | // Create insert a box button |
|
79 | // Create insert a box button | |
80 | QPushButton *insertBoxButton = new QPushButton("Insert a box"); |
|
80 | QPushButton *insertBoxButton = new QPushButton("Insert a box"); | |
81 | connect(insertBoxButton, SIGNAL(clicked()), this, SLOT(insertBox())); |
|
81 | connect(insertBoxButton, SIGNAL(clicked()), this, SLOT(insertBox())); | |
82 | grid->addWidget(insertBoxButton, rowPos++, 1); |
|
82 | grid->addWidget(insertBoxButton, rowPos++, 1); | |
83 |
|
83 | |||
84 | // Create add a single box button |
|
84 | // Create add a single box button | |
85 | QPushButton *removeBoxButton = new QPushButton("Remove a box"); |
|
85 | QPushButton *removeBoxButton = new QPushButton("Remove a box"); | |
86 | connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox())); |
|
86 | connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox())); | |
87 | grid->addWidget(removeBoxButton, rowPos++, 1); |
|
87 | grid->addWidget(removeBoxButton, rowPos++, 1); | |
88 |
|
88 | |||
89 | // Create clear button |
|
89 | // Create clear button | |
90 | QPushButton *clearButton = new QPushButton("Clear"); |
|
90 | QPushButton *clearButton = new QPushButton("Clear"); | |
91 | connect(clearButton, SIGNAL(clicked()), this, SLOT(clear())); |
|
91 | connect(clearButton, SIGNAL(clicked()), this, SLOT(clear())); | |
92 | grid->addWidget(clearButton, rowPos++, 1); |
|
92 | grid->addWidget(clearButton, rowPos++, 1); | |
93 |
|
93 | |||
94 | // Create set brush button |
|
94 | // Create set brush button | |
95 | QPushButton *setBrushButton = new QPushButton("Set brush"); |
|
95 | QPushButton *setBrushButton = new QPushButton("Set brush"); | |
96 | connect(setBrushButton, SIGNAL(clicked()), this, SLOT(setBrush())); |
|
96 | connect(setBrushButton, SIGNAL(clicked()), this, SLOT(setBrush())); | |
97 | grid->addWidget(setBrushButton, rowPos++, 1); |
|
97 | grid->addWidget(setBrushButton, rowPos++, 1); | |
98 |
|
98 | |||
99 | initThemeCombo(grid); |
|
99 | initThemeCombo(grid); | |
100 | initCheckboxes(grid); |
|
100 | initCheckboxes(grid); | |
101 |
|
101 | |||
102 | m_model = new CustomTableModel; |
|
102 | m_model = new CustomTableModel; | |
103 | QTableView *tableView = new QTableView; |
|
103 | QTableView *tableView = new QTableView; | |
104 | tableView->setModel(m_model); |
|
104 | tableView->setModel(m_model); | |
105 | tableView->setMaximumWidth(200); |
|
105 | tableView->setMaximumWidth(200); | |
106 | grid->addWidget(tableView, rowPos++, 0, 3, 2, Qt::AlignLeft); |
|
106 | grid->addWidget(tableView, rowPos++, 0, 3, 2, Qt::AlignLeft); | |
107 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
|
107 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | |
108 | tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
|
108 | tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); | |
109 | tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
|
109 | tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); | |
110 | #else |
|
110 | #else | |
111 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
111 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); | |
112 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
112 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); | |
113 | #endif |
|
113 | #endif | |
114 |
|
114 | |||
115 | // add row with empty label to make all the other rows static |
|
115 | // add row with empty label to make all the other rows static | |
116 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
116 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
117 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
117 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
118 |
|
118 | |||
119 | // Create chart view with the chart |
|
119 | // Create chart view with the chart | |
120 | m_chartView = new QChartView(m_chart, this); |
|
120 | m_chartView = new QChartView(m_chart, this); | |
121 | //m_chartView->setRubberBand(QChartView::HorizonalRubberBand); |
|
121 | //m_chartView->setRubberBand(QChartView::HorizonalRubberBand); | |
122 |
|
122 | |||
123 | // Another grid layout as a main layout |
|
123 | // Another grid layout as a main layout | |
124 | QGridLayout *mainLayout = new QGridLayout(); |
|
124 | QGridLayout *mainLayout = new QGridLayout(); | |
125 | mainLayout->addLayout(grid, 0, 0); |
|
125 | mainLayout->addLayout(grid, 0, 0); | |
126 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
126 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
127 | setLayout(mainLayout); |
|
127 | setLayout(mainLayout); | |
128 |
|
128 | |||
129 | legendToggled(false); |
|
129 | legendToggled(false); | |
130 | animationToggled(false); |
|
130 | animationToggled(false); | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | // Combo box for selecting theme |
|
133 | // Combo box for selecting theme | |
134 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
134 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
135 | { |
|
135 | { | |
136 | QComboBox *chartTheme = new QComboBox(); |
|
136 | QComboBox *chartTheme = new QComboBox(); | |
137 | chartTheme->addItem("Default"); |
|
137 | chartTheme->addItem("Default"); | |
138 | chartTheme->addItem("Light"); |
|
138 | chartTheme->addItem("Light"); | |
139 | chartTheme->addItem("Blue Cerulean"); |
|
139 | chartTheme->addItem("Blue Cerulean"); | |
140 | chartTheme->addItem("Dark"); |
|
140 | chartTheme->addItem("Dark"); | |
141 | chartTheme->addItem("Brown Sand"); |
|
141 | chartTheme->addItem("Brown Sand"); | |
142 | chartTheme->addItem("Blue NCS"); |
|
142 | chartTheme->addItem("Blue NCS"); | |
143 | chartTheme->addItem("High Contrast"); |
|
143 | chartTheme->addItem("High Contrast"); | |
144 | chartTheme->addItem("Blue Icy"); |
|
144 | chartTheme->addItem("Blue Icy"); | |
145 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
145 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
146 | this, SLOT(changeChartTheme(int))); |
|
146 | this, SLOT(changeChartTheme(int))); | |
147 | grid->addWidget(new QLabel("Chart theme:"), rowPos, 0); |
|
147 | grid->addWidget(new QLabel("Chart theme:"), rowPos, 0); | |
148 | grid->addWidget(chartTheme, rowPos++, 1); |
|
148 | grid->addWidget(chartTheme, rowPos++, 1); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | // Different check boxes for customizing chart |
|
151 | // Different check boxes for customizing chart | |
152 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
152 | void MainWidget::initCheckboxes(QGridLayout *grid) | |
153 | { |
|
153 | { | |
154 | QCheckBox *animationCheckBox = new QCheckBox("Animation"); |
|
154 | QCheckBox *animationCheckBox = new QCheckBox("Animation"); | |
155 | connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool))); |
|
155 | connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool))); | |
156 | animationCheckBox->setChecked(false); |
|
156 | animationCheckBox->setChecked(false); | |
157 | grid->addWidget(animationCheckBox, rowPos++, 0); |
|
157 | grid->addWidget(animationCheckBox, rowPos++, 0); | |
158 |
|
158 | |||
159 | QCheckBox *legendCheckBox = new QCheckBox("Legend"); |
|
159 | QCheckBox *legendCheckBox = new QCheckBox("Legend"); | |
160 | connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool))); |
|
160 | connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool))); | |
161 | legendCheckBox->setChecked(false); |
|
161 | legendCheckBox->setChecked(false); | |
162 | grid->addWidget(legendCheckBox, rowPos++, 0); |
|
162 | grid->addWidget(legendCheckBox, rowPos++, 0); | |
163 |
|
163 | |||
164 | QCheckBox *titleCheckBox = new QCheckBox("Title"); |
|
164 | QCheckBox *titleCheckBox = new QCheckBox("Title"); | |
165 | connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool))); |
|
165 | connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool))); | |
166 | titleCheckBox->setChecked(false); |
|
166 | titleCheckBox->setChecked(false); | |
167 | grid->addWidget(titleCheckBox, rowPos++, 0); |
|
167 | grid->addWidget(titleCheckBox, rowPos++, 0); | |
168 |
|
168 | |||
169 | QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper"); |
|
169 | QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper"); | |
170 | connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool))); |
|
170 | connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool))); | |
171 | modelMapperCheckBox->setChecked(false); |
|
171 | modelMapperCheckBox->setChecked(false); | |
172 | grid->addWidget(modelMapperCheckBox, rowPos++, 0); |
|
172 | grid->addWidget(modelMapperCheckBox, rowPos++, 0); | |
173 |
|
173 | |||
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void MainWidget::addSeries() |
|
176 | void MainWidget::addSeries() | |
177 | { |
|
177 | { | |
178 | qDebug() << "BoxPlotTester::MainWidget::addSeries()"; |
|
178 | qDebug() << "BoxPlotTester::MainWidget::addSeries()"; | |
179 |
|
179 | |||
180 | if (nSeries > 9) |
|
180 | if (nSeries > 9) | |
181 | return; |
|
181 | return; | |
182 |
|
182 | |||
183 | // Initial data |
|
183 | // Initial data | |
184 | //![1] |
|
184 | //![1] | |
185 |
QB |
|
185 | QBoxSet *set0 = new QBoxSet(); | |
186 |
QB |
|
186 | QBoxSet *set1 = new QBoxSet(); | |
187 |
QB |
|
187 | QBoxSet *set2 = new QBoxSet(); | |
188 |
QB |
|
188 | QBoxSet *set3 = new QBoxSet(); | |
189 |
QB |
|
189 | QBoxSet *set4 = new QBoxSet(); | |
190 |
QB |
|
190 | QBoxSet *set5 = new QBoxSet(); | |
191 |
|
191 | |||
192 | // low bot med top upp |
|
192 | // low bot med top upp | |
193 | *set0 << 3 << 4 << 4.4 << 6 << 7; |
|
193 | *set0 << 3 << 4 << 4.4 << 6 << 7; | |
194 | *set1 << 5 << 6 << 7.5 << 8 << 12; |
|
194 | *set1 << 5 << 6 << 7.5 << 8 << 12; | |
195 | *set2 << 3 << 5 << 5.7 << 8 << 9; |
|
195 | *set2 << 3 << 5 << 5.7 << 8 << 9; | |
196 | *set3 << 5 << 6 << 6.8 << 7 << 8; |
|
196 | *set3 << 5 << 6 << 6.8 << 7 << 8; | |
197 | *set4 << 4 << 5 << 5.2 << 6 << 7; |
|
197 | *set4 << 4 << 5 << 5.2 << 6 << 7; | |
198 | *set5 << 4 << 7 << 8.2 << 9 << 10; |
|
198 | *set5 << 4 << 7 << 8.2 << 9 << 10; | |
199 |
|
199 | |||
200 | m_series[nSeries] = new QBoxPlotSeries(); |
|
200 | m_series[nSeries] = new QBoxPlotSeries(); | |
201 | m_series[nSeries]->append(set0); |
|
201 | m_series[nSeries]->append(set0); | |
202 | m_series[nSeries]->append(set1); |
|
202 | m_series[nSeries]->append(set1); | |
203 | m_series[nSeries]->append(set2); |
|
203 | m_series[nSeries]->append(set2); | |
204 | m_series[nSeries]->append(set3); |
|
204 | m_series[nSeries]->append(set3); | |
205 | m_series[nSeries]->append(set4); |
|
205 | m_series[nSeries]->append(set4); | |
206 | m_series[nSeries]->append(set5); |
|
206 | m_series[nSeries]->append(set5); | |
207 | m_series[nSeries]->type(); |
|
|||
208 | m_series[nSeries]->setName("Box & Whiskers"); |
|
207 | m_series[nSeries]->setName("Box & Whiskers"); | |
209 |
|
208 | |||
210 | m_chart->addSeries(m_series[nSeries]); |
|
209 | m_chart->addSeries(m_series[nSeries]); | |
211 |
|
210 | |||
212 | if (nSeries == 0) { |
|
211 | if (nSeries == 0) { | |
213 | QStringList categories; |
|
212 | QStringList categories; | |
214 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
213 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
215 | m_axis = new QBarCategoryAxis(); |
|
214 | m_axis = new QBarCategoryAxis(); | |
216 | m_axis->append(categories); |
|
215 | m_axis->append(categories); | |
217 | m_chart->createDefaultAxes(); |
|
216 | m_chart->createDefaultAxes(); | |
218 | m_chart->setAxisX(m_axis, m_series[nSeries]); |
|
217 | //m_chart->setAxisX(m_axis, m_series[nSeries]); | |
219 | } |
|
218 | } | |
220 |
|
219 | |||
221 | nSeries++; |
|
220 | nSeries++; | |
222 | } |
|
221 | } | |
223 |
|
222 | |||
224 | void MainWidget::removeSeries() |
|
223 | void MainWidget::removeSeries() | |
225 | { |
|
224 | { | |
226 | qDebug() << "BoxPlotTester::MainWidget::removeSeries()"; |
|
225 | qDebug() << "BoxPlotTester::MainWidget::removeSeries()"; | |
227 |
|
226 | |||
228 | if (nSeries > 0) { |
|
227 | if (nSeries > 0) { | |
229 | nSeries--; |
|
228 | nSeries--; | |
230 | m_chart->removeSeries(m_series[nSeries]); |
|
229 | m_chart->removeSeries(m_series[nSeries]); | |
231 | delete m_series[nSeries]; |
|
230 | delete m_series[nSeries]; | |
232 | } else { |
|
231 | } else { | |
233 | qDebug() << "Create a series first"; |
|
232 | qDebug() << "Create a series first"; | |
234 | } |
|
233 | } | |
235 | } |
|
234 | } | |
236 |
|
235 | |||
237 | void MainWidget::addBox() |
|
236 | void MainWidget::addBox() | |
238 | { |
|
237 | { | |
239 | qDebug() << "BoxPlotTester::MainWidget::addBox()"; |
|
238 | qDebug() << "BoxPlotTester::MainWidget::addBox()"; | |
240 |
|
239 | |||
241 | if (nSeries > 0) { |
|
240 | if (nSeries > 0) { | |
242 |
QB |
|
241 | QBoxSet *newSet = new QBoxSet(); | |
243 | *newSet << 5 << 6 << 6.8 << 7 << 8; |
|
242 | *newSet << 5 << 6 << 6.8 << 7 << 8; | |
244 |
|
243 | |||
245 | m_series[0]->append(newSet); |
|
244 | m_series[0]->append(newSet); | |
246 |
|
245 | |||
247 | m_axis->append(addCategories[nNewBoxes]); |
|
246 | m_axis->append(addCategories[nNewBoxes]); | |
248 |
|
247 | |||
249 | nNewBoxes++; |
|
248 | nNewBoxes++; | |
250 | } |
|
249 | } | |
251 | } |
|
250 | } | |
252 |
|
251 | |||
253 | void MainWidget::insertBox() |
|
252 | void MainWidget::insertBox() | |
254 | { |
|
253 | { | |
255 | qDebug() << "BoxPlotTester::MainWidget::insertBox()"; |
|
254 | qDebug() << "BoxPlotTester::MainWidget::insertBox()"; | |
256 |
|
255 | |||
257 | if (nSeries > 0) { |
|
256 | if (nSeries > 0) { | |
258 |
QB |
|
257 | QBoxSet *newSet = new QBoxSet(); | |
259 | *newSet << 2 << 6 << 6.8 << 7 << 10; |
|
258 | *newSet << 2 << 6 << 6.8 << 7 << 10; | |
260 |
|
259 | |||
261 | m_series[0]->insert(1, newSet); |
|
260 | m_series[0]->insert(1, newSet); | |
262 |
|
261 | |||
263 | m_axis->append(addCategories[nNewBoxes]); |
|
262 | m_axis->append(addCategories[nNewBoxes]); | |
264 |
|
263 | |||
265 | nNewBoxes++; |
|
264 | nNewBoxes++; | |
266 | } |
|
265 | } | |
267 | } |
|
266 | } | |
268 |
|
267 | |||
269 | void MainWidget::removeBox() |
|
268 | void MainWidget::removeBox() | |
270 | { |
|
269 | { | |
271 | qDebug() << "BoxPlotTester::MainWidget::removeBox"; |
|
270 | qDebug() << "BoxPlotTester::MainWidget::removeBox"; | |
272 |
|
271 | |||
273 | if (nSeries > 0) { |
|
272 | if (nSeries > 0) { | |
274 |
QList<QB |
|
273 | QList<QBoxSet *> sets = m_series[0]->boxSets(); | |
275 | m_series[0]->remove(sets.at(m_series[0]->count() - 3)); |
|
274 | m_series[0]->remove(sets.at(m_series[0]->count() - 3)); | |
276 | } else { |
|
275 | } else { | |
277 | qDebug() << "Create a series first"; |
|
276 | qDebug() << "Create a series first"; | |
278 | } |
|
277 | } | |
279 | } |
|
278 | } | |
280 |
|
279 | |||
281 | void MainWidget::clear() |
|
280 | void MainWidget::clear() | |
282 | { |
|
281 | { | |
283 | qDebug() << "BoxPlotTester::MainWidget::clear"; |
|
282 | qDebug() << "BoxPlotTester::MainWidget::clear"; | |
284 |
|
283 | |||
285 | if (nSeries > 0) { |
|
284 | if (nSeries > 0) { | |
286 | m_series[0]->clear(); |
|
285 | m_series[0]->clear(); | |
287 | } else { |
|
286 | } else { | |
288 | qDebug() << "Create a series first"; |
|
287 | qDebug() << "Create a series first"; | |
289 | } |
|
288 | } | |
290 | } |
|
289 | } | |
291 |
|
290 | |||
292 | void MainWidget::setBrush() |
|
291 | void MainWidget::setBrush() | |
293 | { |
|
292 | { | |
294 | qDebug() << "BoxPlotTester::MainWidget::setBrush"; |
|
293 | qDebug() << "BoxPlotTester::MainWidget::setBrush"; | |
295 |
|
294 | |||
296 | if (nSeries > 0) { |
|
295 | if (nSeries > 0) { | |
297 |
QList<QB |
|
296 | QList<QBoxSet *> sets = m_series[0]->boxSets(); | |
298 | sets.at(1)->setBrush(QBrush(QColor(Qt::yellow))); |
|
297 | sets.at(1)->setBrush(QBrush(QColor(Qt::yellow))); | |
299 | } else { |
|
298 | } else { | |
300 | qDebug() << "Create a series first"; |
|
299 | qDebug() << "Create a series first"; | |
301 | } |
|
300 | } | |
302 | } |
|
301 | } | |
303 |
|
302 | |||
304 | void MainWidget::animationToggled(bool enabled) |
|
303 | void MainWidget::animationToggled(bool enabled) | |
305 | { |
|
304 | { | |
306 | qDebug() << "BoxPlotTester::Animation toggled to " << enabled; |
|
305 | qDebug() << "BoxPlotTester::Animation toggled to " << enabled; | |
307 | if (enabled) |
|
306 | if (enabled) | |
308 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
307 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
309 | else |
|
308 | else | |
310 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
309 | m_chart->setAnimationOptions(QChart::NoAnimation); | |
311 | } |
|
310 | } | |
312 |
|
311 | |||
313 | void MainWidget::legendToggled(bool enabled) |
|
312 | void MainWidget::legendToggled(bool enabled) | |
314 | { |
|
313 | { | |
315 | qDebug() << "BoxPlotTester::Legend toggled to " << enabled; |
|
314 | qDebug() << "BoxPlotTester::Legend toggled to " << enabled; | |
316 | m_chart->legend()->setVisible(enabled); |
|
315 | m_chart->legend()->setVisible(enabled); | |
317 | if (enabled) |
|
316 | if (enabled) | |
318 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
317 | m_chart->legend()->setAlignment(Qt::AlignBottom); | |
319 | } |
|
318 | } | |
320 |
|
319 | |||
321 | void MainWidget::titleToggled(bool enabled) |
|
320 | void MainWidget::titleToggled(bool enabled) | |
322 | { |
|
321 | { | |
323 | qDebug() << "BoxPlotTester::Title toggled to " << enabled; |
|
322 | qDebug() << "BoxPlotTester::Title toggled to " << enabled; | |
324 | if (enabled) |
|
323 | if (enabled) | |
325 | m_chart->setTitle("Simple boxplotchart example"); |
|
324 | m_chart->setTitle("Simple boxplotchart example"); | |
326 | else |
|
325 | else | |
327 | m_chart->setTitle(""); |
|
326 | m_chart->setTitle(""); | |
328 | } |
|
327 | } | |
329 |
|
328 | |||
330 | void MainWidget::modelMapperToggled(bool enabled) |
|
329 | void MainWidget::modelMapperToggled(bool enabled) | |
331 | { |
|
330 | { | |
332 | if (enabled) { |
|
331 | if (enabled) { | |
333 | m_series[nSeries] = new QBoxPlotSeries(); |
|
332 | m_series[nSeries] = new QBoxPlotSeries(); | |
334 |
|
333 | |||
335 | int first = 0; |
|
334 | int first = 0; | |
336 | int count = 5; |
|
335 | int count = 5; | |
337 | QVBarModelMapper *mapper = new QVBarModelMapper(this); |
|
336 | QVBarModelMapper *mapper = new QVBarModelMapper(this); | |
338 | mapper->setFirstBarSetColumn(0); |
|
337 | mapper->setFirstBarSetColumn(0); | |
339 | mapper->setLastBarSetColumn(5); |
|
338 | mapper->setLastBarSetColumn(5); | |
340 | mapper->setFirstRow(first); |
|
339 | mapper->setFirstRow(first); | |
341 | mapper->setRowCount(count); |
|
340 | mapper->setRowCount(count); | |
342 | mapper->setSeries(m_series[nSeries]); |
|
341 | //mapper->setSeries(m_series[nSeries]); | |
343 | mapper->setModel(m_model); |
|
342 | mapper->setModel(m_model); | |
344 | m_chart->addSeries(m_series[nSeries]); |
|
343 | m_chart->addSeries(m_series[nSeries]); | |
345 |
|
344 | |||
346 | nSeries++; |
|
345 | nSeries++; | |
347 | } else { |
|
346 | } else { | |
348 | removeSeries(); |
|
347 | removeSeries(); | |
349 | } |
|
348 | } | |
350 | } |
|
349 | } | |
351 |
|
350 | |||
352 | void MainWidget::changeChartTheme(int themeIndex) |
|
351 | void MainWidget::changeChartTheme(int themeIndex) | |
353 | { |
|
352 | { | |
354 | qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex; |
|
353 | qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex; | |
355 | if (themeIndex == 0) |
|
354 | if (themeIndex == 0) | |
356 | m_chart->setTheme(QChart::ChartThemeLight); |
|
355 | m_chart->setTheme(QChart::ChartThemeLight); | |
357 | else |
|
356 | else | |
358 | m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1)); |
|
357 | m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1)); | |
359 | } |
|
358 | } |
General Comments 0
You need to be logged in to leave comments.
Login now