@@ -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 |
@@ -22,10 +22,11 | |||||
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> | |
@@ -37,18 +38,18 int main(int argc, char *argv[]) | |||||
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; | |
@@ -98,10 +99,23 int main(int argc, char *argv[]) | |||||
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] | |
@@ -128,7 +142,7 int main(int argc, char *argv[]) | |||||
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 |
@@ -35,11 +35,11 ChartView { | |||||
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 |
@@ -20,12 +20,46 | |||||
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)) | |
@@ -43,14 +77,14 void DeclarativeBoxPlotSeries::classBegin() | |||||
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 | } | |
@@ -67,19 +101,18 void DeclarativeBoxPlotSeries::appendSeriesChildren(QDeclarativeListProperty<QOb | |||||
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; |
@@ -21,7 +21,7 | |||||
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> | |
@@ -29,6 +29,30 | |||||
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 | |
@@ -53,10 +77,10 public: | |||||
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 |
@@ -195,6 +195,7 public: | |||||
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"); |
@@ -4,13 +4,16 DEPENDPATH += $$PWD | |||||
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 |
@@ -21,9 +21,9 | |||||
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 | |||
@@ -35,15 +35,13 BoxPlotChartItem::BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item) | |||||
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() | |
@@ -82,7 +80,7 void BoxPlotChartItem::handleDataStructureChanged() | |||||
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) { | |
@@ -90,6 +88,7 void BoxPlotChartItem::handleDataStructureChanged() | |||||
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 | } | |
@@ -113,8 +112,8 void BoxPlotChartItem::handleUpdatedBars() | |||||
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) | |
@@ -122,11 +121,11 void BoxPlotChartItem::handleUpdatedBars() | |||||
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; | |
@@ -193,7 +192,7 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)) || |
@@ -35,7 +35,7 | |||||
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 | |
@@ -59,7 +59,7 public Q_SLOTS: | |||||
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(); | |
@@ -70,8 +70,7 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 |
@@ -73,8 +73,7 void BoxWhiskers::setPen(const QPen &pen) | |||||
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 | } |
@@ -21,6 +21,7 | |||||
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" | |
@@ -28,6 +29,8 | |||||
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 | |||
@@ -45,7 +48,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
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 | /*! | |
@@ -65,7 +68,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
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 | |||
@@ -82,6 +85,137 QBoxPlotSeries::~QBoxPlotSeries() | |||||
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 | |
@@ -126,7 +260,7 QPen QBoxPlotSeries::pen() const | |||||
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 | { | |
@@ -145,16 +279,53 void QBoxPlotSeriesPrivate::initializeDomain() | |||||
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); | |
@@ -276,6 +447,128 void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series) | |||||
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 |
@@ -22,20 +22,34 | |||||
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); | |
@@ -43,6 +57,15 public: | |||||
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) |
@@ -37,7 +37,7 | |||||
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 | |||
@@ -47,19 +47,41 public: | |||||
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; |
@@ -25,7 +25,7 | |||||
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> | |
@@ -182,12 +182,12 void MainWidget::addSeries() | |||||
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; | |
@@ -204,7 +204,6 void MainWidget::addSeries() | |||||
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]); | |
@@ -215,7 +214,7 void MainWidget::addSeries() | |||||
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++; | |
@@ -239,7 +238,7 void MainWidget::addBox() | |||||
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); | |
@@ -255,7 +254,7 void MainWidget::insertBox() | |||||
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); | |
@@ -271,7 +270,7 void MainWidget::removeBox() | |||||
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"; | |
@@ -294,7 +293,7 void MainWidget::setBrush() | |||||
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"; | |
@@ -339,7 +338,7 void MainWidget::modelMapperToggled(bool enabled) | |||||
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 |
General Comments 0
You need to be logged in to leave comments.
Login now