@@ -1,124 +1,345 | |||||
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 "qboxset.h" |
|
23 | #include "qboxset.h" | |
24 | #include "qvboxplotmodelmapper.h" |
|
24 | #include "qvboxplotmodelmapper.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
|
28 | /*! | |||
|
29 | \qmlclass BoxSet QBoxSet | |||
|
30 | ||||
|
31 | BoxSet represents one box-and-whiskers item. It takes five values to create a graphical representation | |||
|
32 | of range and three medians. There are two ways to give the values. The first one is with constructor | |||
|
33 | or with append method. In these the values have to be given in the following order: lower extreme, lower quartile, median, | |||
|
34 | upper quartile and upper extreme. The second method is to create an empty QBoxSet instance and give the values using | |||
|
35 | value specific methods. | |||
|
36 | \sa BoxPlotSeries | |||
|
37 | */ | |||
|
38 | /*! | |||
|
39 | \qmlproperty string BoxSet::values | |||
|
40 | The values on the box-and-whiskers set. | |||
|
41 | */ | |||
|
42 | /*! | |||
|
43 | \qmlproperty string BoxSet::label | |||
|
44 | Defines the label of the box-and-whiskers set. | |||
|
45 | */ | |||
|
46 | /*! | |||
|
47 | \qmlproperty int BoxSet::count | |||
|
48 | The count of values on the box-and-whiskers set | |||
|
49 | */ | |||
|
50 | /*! | |||
|
51 | \qmlmethod void BoxSet::at(int index) | |||
|
52 | Returns the value at \a index position. | |||
|
53 | */ | |||
|
54 | /*! | |||
|
55 | \qmlmethod void BoxSet::append(qreal value) | |||
|
56 | Appends new value \a value to the end of set. | |||
|
57 | */ | |||
|
58 | /*! | |||
|
59 | \qmlmethod void BoxSet::clear() | |||
|
60 | Sets all values on the set to 0. | |||
|
61 | */ | |||
|
62 | /*! | |||
|
63 | \qmlmethod void BoxSet::setValue(int index, qreal value) | |||
|
64 | Sets a new \a value on the \a index position. | |||
|
65 | */ | |||
|
66 | /*! | |||
|
67 | \qmlsignal BoxSet::onClicked() | |||
|
68 | This signal is emitted when the user clicks with a mouse on top of box-and-whiskers item. | |||
|
69 | */ | |||
|
70 | /*! | |||
|
71 | \qmlsignal BoxSet::onHovered(bool status) | |||
|
72 | The signal is emitted if mouse is hovered on top of box-and-whiskers item. | |||
|
73 | Parameter \a status is true, if mouse entered on top of the item, and false if mouse left from top of the item. | |||
|
74 | */ | |||
|
75 | /*! | |||
|
76 | \qmlsignal BoxSet::onPenChanged() | |||
|
77 | This signal is emitted when the pen of the box-and-whiskers item has changed. | |||
|
78 | */ | |||
|
79 | /*! | |||
|
80 | \qmlsignal BoxSet::onBrushChanged() | |||
|
81 | This signal is emitted when the brush of the box-and-whiskers item has changed. | |||
|
82 | */ | |||
|
83 | /*! | |||
|
84 | \qmlsignal BoxSet::onChangedValues() | |||
|
85 | This signal is emitted when multiple values have been changed on the box-and-whiskers item. | |||
|
86 | */ | |||
|
87 | /*! | |||
|
88 | \qmlsignal BoxSet::onChangedValue(int index) | |||
|
89 | This signal is emitted values the value in the box-and-whiskers item has been modified. | |||
|
90 | Parameter \a index indicates the position of the modified value. | |||
|
91 | */ | |||
|
92 | /*! | |||
|
93 | \qmlsignal BoxSet::onCleared() | |||
|
94 | This signal is emitted when all the values on the set are cleared to 0. | |||
|
95 | */ | |||
|
96 | ||||
|
97 | ||||
|
98 | /*! | |||
|
99 | \qmlclass BoxPlotSeries QBoxPlotSeries | |||
|
100 | \inherits QAbstractSeries | |||
|
101 | ||||
|
102 | BoxPlotSeries represents a series of data shown as box-and-whiskers bars. The purpose of this class is to act as | |||
|
103 | a container for single box-and-whiskers items. Each item is drawn to own slot. If chart includes multiple instances of | |||
|
104 | BoxPlotSeries then box-and-whiskers items with the same index are drawn to same slot. | |||
|
105 | ||||
|
106 | The following QML shows how to create a simple box-and-whiskers chart: | |||
|
107 | \code | |||
|
108 | import QtQuick 1.0 | |||
|
109 | import QtCommercial.Chart 1.3 | |||
|
110 | ||||
|
111 | ChartView { | |||
|
112 | title: "Box Plot series" | |||
|
113 | width: 400 | |||
|
114 | height: 300 | |||
|
115 | theme: ChartView.ChartThemeBrownSand | |||
|
116 | legend.alignment: Qt.AlignBottom | |||
|
117 | ||||
|
118 | BoxPlotSeries { | |||
|
119 | id: plotSeries | |||
|
120 | name: "Income" | |||
|
121 | BoxSet { label: "Jan"; values: [3, 4, 5.1, 6.2, 8.5] } | |||
|
122 | BoxSet { label: "Feb"; values: [5, 6, 7.5, 8.6, 11.8] } | |||
|
123 | BoxSet { label: "Mar"; values: [3.2, 5, 5.7, 8, 9.2] } | |||
|
124 | BoxSet { label: "Apr"; values: [3.8, 5, 6.4, 7, 8] } | |||
|
125 | BoxSet { label: "May"; values: [4, 5, 5.2, 6, 7] } | |||
|
126 | } | |||
|
127 | } | |||
|
128 | \endcode | |||
|
129 | ||||
|
130 | \beginfloatleft | |||
|
131 | \image examples_qmlboxplot.png | |||
|
132 | \endfloat | |||
|
133 | \clearfloat | |||
|
134 | */ | |||
|
135 | /*! | |||
|
136 | \qmlmethod BoxPlotSeries::append(string label, VariantList values) | |||
|
137 | Appends a new box-and-whiskers set with \a label and \a values to the series. | |||
|
138 | */ | |||
|
139 | /*! | |||
|
140 | \qmlmethod BoxPlotSeries::append(BoxSet box) | |||
|
141 | Appends the \a box to the series. | |||
|
142 | */ | |||
|
143 | /*! | |||
|
144 | \qmlmethod BoxPlotSeries::insert(int index, string label, VariantList values) | |||
|
145 | Inserts a new box-and-whiskers set with \a label and \a values at the \a index position. | |||
|
146 | */ | |||
|
147 | /*! | |||
|
148 | \qmlmethod BoxPlotSeries::remove(QBoxSet boxset) | |||
|
149 | Removes the \a boxset from the series. | |||
|
150 | */ | |||
|
151 | /*! | |||
|
152 | \qmlmethod BoxPlotSeries::clear() | |||
|
153 | Removes all boxsets from the series. Deletes removed sets. | |||
|
154 | */ | |||
|
155 | /*! | |||
|
156 | \qmlsignal BoxPlotSeries::onClicked(BoxSet boxset); | |||
|
157 | Signal is emitted when the user clicks the \a boxset on the chart. | |||
|
158 | */ | |||
|
159 | /*! | |||
|
160 | \qmlsignal BoxPlotSeries::onHovered(bool status, BoxSet boxset); | |||
|
161 | Signal is emitted when there is change in hover \a status over \a boxset. | |||
|
162 | */ | |||
|
163 | /*! | |||
|
164 | \qmlsignal BoxPlotSeries::onCountChanged(); | |||
|
165 | Signal is emitted when there is change in count of box-and-whiskers items in the series. | |||
|
166 | */ | |||
|
167 | /*! | |||
|
168 | \qmlsignal BoxPlotSeries::onBoxsetsAdded() | |||
|
169 | Signal is emitted when new box-and-whiskers sets are added to the series. | |||
|
170 | */ | |||
|
171 | /*! | |||
|
172 | \qmlsignal BoxPlotSeries::onBoxsetsRemoved() | |||
|
173 | Signal is emitted when new box-and-whiskers sets are removed from the series. | |||
|
174 | */ | |||
|
175 | /*! | |||
|
176 | \qmlproperty AbstractAxis BoxPlotSeries::axisX | |||
|
177 | The x axis used for the series. If you leave both axisX and axisXTop undefined, a BarCategoriesAxis is created for | |||
|
178 | the series. | |||
|
179 | \sa axisXTop | |||
|
180 | */ | |||
|
181 | /*! | |||
|
182 | \qmlproperty AbstractAxis BoxPlotSeries::axisY | |||
|
183 | The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for | |||
|
184 | the series. | |||
|
185 | \sa axisYRight | |||
|
186 | */ | |||
|
187 | /*! | |||
|
188 | \qmlproperty AbstractAxis BoxPlotSeries::axisXTop | |||
|
189 | The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or | |||
|
190 | axisXTop, but not both. | |||
|
191 | \sa axisX | |||
|
192 | */ | |||
|
193 | /*! | |||
|
194 | \qmlproperty AbstractAxis BoxPlotSeries::axisYRight | |||
|
195 | The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY | |||
|
196 | or axisYRight, but not both. | |||
|
197 | \sa axisY | |||
|
198 | */ | |||
|
199 | /*! | |||
|
200 | \qmlproperty bool BoxPlotSeries::boxOutlineVisible | |||
|
201 | This property configures the visibility of the middle box outline. | |||
|
202 | */ | |||
|
203 | /*! | |||
|
204 | \qmlproperty Pen BoxPlotSeries::pen | |||
|
205 | This property configures the pen of the box-and-whiskers items. | |||
|
206 | */ | |||
|
207 | /*! | |||
|
208 | \qmlproperty Brush BoxPlotSeries::brush | |||
|
209 | This property configures the brush of the box-and-whiskers items. | |||
|
210 | */ | |||
|
211 | /*! | |||
|
212 | \qmlsignal BoxPlotSeries::onBoxOutlineVisibilityChanged() | |||
|
213 | Signal is emitted when the middle box outline visibility is changed. | |||
|
214 | */ | |||
|
215 | /*! | |||
|
216 | \qmlsignal BoxPlotSeries::onPenChanged() | |||
|
217 | Signal is emitted when the pen for box-and-whiskers items has changed. | |||
|
218 | */ | |||
|
219 | /*! | |||
|
220 | \qmlsignal BoxPlotSeries::onBrushChanged() | |||
|
221 | Signal is emitted when the brush for box-and-whiskers items has changed. | |||
|
222 | */ | |||
|
223 | /*! | |||
|
224 | \qmlsignal BoxPlotSeries::onClicked(BoxSet boxset) | |||
|
225 | Signal is emitted when the user clicks the \a boxset on the chart. | |||
|
226 | */ | |||
|
227 | /*! | |||
|
228 | \qmlsignal BoxPlotSeries::onHovered(bool status, BoxSet boxset) | |||
|
229 | Signal is emitted when there is change in hover \a status over \a boxset. | |||
|
230 | */ | |||
|
231 | /*! | |||
|
232 | \qmlsignal BoxPlotSeries::onAxisXChanged(AbstractAxis axis) | |||
|
233 | Signal is emitted when there is change in X axis. | |||
|
234 | */ | |||
|
235 | /*! | |||
|
236 | \qmlsignal BoxPlotSeries::onAxisYChanged(AbstractAxis axis) | |||
|
237 | Signal is emitted when there is change in Y axis. | |||
|
238 | */ | |||
|
239 | /*! | |||
|
240 | \qmlsignal BoxPlotSeries::onAxisXTopChanged(AbstractAxis axis) | |||
|
241 | Signal is emitted when there is change in top X axis. | |||
|
242 | */ | |||
|
243 | /*! | |||
|
244 | \qmlsignal BoxPlotSeries::onAxisYRightChanged(AbstractAxis axis) | |||
|
245 | Signal is emitted when there is change in Y right axis. | |||
|
246 | */ | |||
|
247 | ||||
|
248 | ||||
28 | DeclarativeBoxSet::DeclarativeBoxSet(const QString label, QObject *parent) |
|
249 | DeclarativeBoxSet::DeclarativeBoxSet(const QString label, QObject *parent) | |
29 | : QBoxSet(label, parent) |
|
250 | : QBoxSet(label, parent) | |
30 | { |
|
251 | { | |
31 | connect(this, SIGNAL(valuesChanged()), this, SIGNAL(changedValues())); |
|
252 | connect(this, SIGNAL(valuesChanged()), this, SIGNAL(changedValues())); | |
32 | connect(this, SIGNAL(valueChanged(int)), this, SIGNAL(changedValue(int))); |
|
253 | connect(this, SIGNAL(valueChanged(int)), this, SIGNAL(changedValue(int))); | |
33 | } |
|
254 | } | |
34 |
|
255 | |||
35 | QVariantList DeclarativeBoxSet::values() |
|
256 | QVariantList DeclarativeBoxSet::values() | |
36 | { |
|
257 | { | |
37 | QVariantList values; |
|
258 | QVariantList values; | |
38 | for (int i(0); i < 5; i++) |
|
259 | for (int i(0); i < 5; i++) | |
39 | values.append(QVariant(QBoxSet::at(i))); |
|
260 | values.append(QVariant(QBoxSet::at(i))); | |
40 | return values; |
|
261 | return values; | |
41 | } |
|
262 | } | |
42 |
|
263 | |||
43 | void DeclarativeBoxSet::setValues(QVariantList values) |
|
264 | void DeclarativeBoxSet::setValues(QVariantList values) | |
44 | { |
|
265 | { | |
45 | for (int i(0); i < values.count(); i++) { |
|
266 | for (int i(0); i < values.count(); i++) { | |
46 | if (values.at(i).canConvert(QVariant::Double)) |
|
267 | if (values.at(i).canConvert(QVariant::Double)) | |
47 | QBoxSet::append(values[i].toDouble()); |
|
268 | QBoxSet::append(values[i].toDouble()); | |
48 | } |
|
269 | } | |
49 | } |
|
270 | } | |
50 |
|
271 | |||
51 | // ===================================================== |
|
272 | // ===================================================== | |
52 |
|
273 | |||
53 | DeclarativeBoxPlotSeries::DeclarativeBoxPlotSeries(QDECLARATIVE_ITEM *parent) : |
|
274 | DeclarativeBoxPlotSeries::DeclarativeBoxPlotSeries(QDECLARATIVE_ITEM *parent) : | |
54 | QBoxPlotSeries(parent), |
|
275 | QBoxPlotSeries(parent), | |
55 | m_axes(new DeclarativeAxes(this)) |
|
276 | m_axes(new DeclarativeAxes(this)) | |
56 | { |
|
277 | { | |
57 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); |
|
278 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); | |
58 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); |
|
279 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); | |
59 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
|
280 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); | |
60 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
|
281 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); | |
61 | connect(this, SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(onHovered(bool, QBoxSet*))); |
|
282 | connect(this, SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(onHovered(bool, QBoxSet*))); | |
62 | connect(this, SIGNAL(clicked(QBoxSet*)), this, SLOT(onClicked(QBoxSet*))); |
|
283 | connect(this, SIGNAL(clicked(QBoxSet*)), this, SLOT(onClicked(QBoxSet*))); | |
63 | } |
|
284 | } | |
64 |
|
285 | |||
65 | void DeclarativeBoxPlotSeries::classBegin() |
|
286 | void DeclarativeBoxPlotSeries::classBegin() | |
66 | { |
|
287 | { | |
67 | } |
|
288 | } | |
68 |
|
289 | |||
69 | void DeclarativeBoxPlotSeries::componentComplete() |
|
290 | void DeclarativeBoxPlotSeries::componentComplete() | |
70 | { |
|
291 | { | |
71 | foreach (QObject *child, children()) { |
|
292 | foreach (QObject *child, children()) { | |
72 | if (qobject_cast<DeclarativeBoxSet *>(child)) { |
|
293 | if (qobject_cast<DeclarativeBoxSet *>(child)) { | |
73 | QBoxPlotSeries::append(qobject_cast<DeclarativeBoxSet *>(child)); |
|
294 | QBoxPlotSeries::append(qobject_cast<DeclarativeBoxSet *>(child)); | |
74 | } else if (qobject_cast<QVBoxPlotModelMapper *>(child)) { |
|
295 | } else if (qobject_cast<QVBoxPlotModelMapper *>(child)) { | |
75 | QVBoxPlotModelMapper *mapper = qobject_cast<QVBoxPlotModelMapper *>(child); |
|
296 | QVBoxPlotModelMapper *mapper = qobject_cast<QVBoxPlotModelMapper *>(child); | |
76 | mapper->setSeries(this); |
|
297 | mapper->setSeries(this); | |
77 | } |
|
298 | } | |
78 | } |
|
299 | } | |
79 | } |
|
300 | } | |
80 |
|
301 | |||
81 | QDECLARATIVE_LIST_PROPERTY<QObject> DeclarativeBoxPlotSeries::seriesChildren() |
|
302 | QDECLARATIVE_LIST_PROPERTY<QObject> DeclarativeBoxPlotSeries::seriesChildren() | |
82 | { |
|
303 | { | |
83 | return QDECLARATIVE_LIST_PROPERTY<QObject>(this, 0, &DeclarativeBoxPlotSeries::appendSeriesChildren LIST_PROPERTY_PARAM_DEFAULTS); |
|
304 | return QDECLARATIVE_LIST_PROPERTY<QObject>(this, 0, &DeclarativeBoxPlotSeries::appendSeriesChildren LIST_PROPERTY_PARAM_DEFAULTS); | |
84 | } |
|
305 | } | |
85 |
|
306 | |||
86 | void DeclarativeBoxPlotSeries::appendSeriesChildren(QDECLARATIVE_LIST_PROPERTY<QObject> *list, QObject *element) |
|
307 | void DeclarativeBoxPlotSeries::appendSeriesChildren(QDECLARATIVE_LIST_PROPERTY<QObject> *list, QObject *element) | |
87 | { |
|
308 | { | |
88 | // Empty implementation; the children are parsed in componentComplete instead |
|
309 | // Empty implementation; the children are parsed in componentComplete instead | |
89 | Q_UNUSED(list); |
|
310 | Q_UNUSED(list); | |
90 | Q_UNUSED(element); |
|
311 | Q_UNUSED(element); | |
91 | } |
|
312 | } | |
92 |
|
313 | |||
93 | DeclarativeBoxSet *DeclarativeBoxPlotSeries::at(int index) |
|
314 | DeclarativeBoxSet *DeclarativeBoxPlotSeries::at(int index) | |
94 | { |
|
315 | { | |
95 | QList<QBoxSet *> setList = boxSets(); |
|
316 | QList<QBoxSet *> setList = boxSets(); | |
96 | if (index >= 0 && index < setList.count()) |
|
317 | if (index >= 0 && index < setList.count()) | |
97 | return qobject_cast<DeclarativeBoxSet *>(setList[index]); |
|
318 | return qobject_cast<DeclarativeBoxSet *>(setList[index]); | |
98 |
|
319 | |||
99 | return 0; |
|
320 | return 0; | |
100 | } |
|
321 | } | |
101 |
|
322 | |||
102 | DeclarativeBoxSet *DeclarativeBoxPlotSeries::insert(int index, const QString label, QVariantList values) |
|
323 | DeclarativeBoxSet *DeclarativeBoxPlotSeries::insert(int index, const QString label, QVariantList values) | |
103 | { |
|
324 | { | |
104 | DeclarativeBoxSet *barset = new DeclarativeBoxSet(label, this); |
|
325 | DeclarativeBoxSet *barset = new DeclarativeBoxSet(label, this); | |
105 | barset->setValues(values); |
|
326 | barset->setValues(values); | |
106 | if (QBoxPlotSeries::insert(index, barset)) |
|
327 | if (QBoxPlotSeries::insert(index, barset)) | |
107 | return barset; |
|
328 | return barset; | |
108 | delete barset; |
|
329 | delete barset; | |
109 | return 0; |
|
330 | return 0; | |
110 | } |
|
331 | } | |
111 |
|
332 | |||
112 | void DeclarativeBoxPlotSeries::onHovered(bool status, QBoxSet *boxset) |
|
333 | void DeclarativeBoxPlotSeries::onHovered(bool status, QBoxSet *boxset) | |
113 | { |
|
334 | { | |
114 | emit hovered(status, qobject_cast<DeclarativeBoxSet *>(boxset)); |
|
335 | emit hovered(status, qobject_cast<DeclarativeBoxSet *>(boxset)); | |
115 | } |
|
336 | } | |
116 |
|
337 | |||
117 | void DeclarativeBoxPlotSeries::onClicked(QBoxSet *boxset) |
|
338 | void DeclarativeBoxPlotSeries::onClicked(QBoxSet *boxset) | |
118 | { |
|
339 | { | |
119 | emit clicked(qobject_cast<DeclarativeBoxSet *>(boxset)); |
|
340 | emit clicked(qobject_cast<DeclarativeBoxSet *>(boxset)); | |
120 | } |
|
341 | } | |
121 |
|
342 | |||
122 | #include "moc_declarativeboxplotseries.cpp" |
|
343 | #include "moc_declarativeboxplotseries.cpp" | |
123 |
|
344 | |||
124 | QTCOMMERCIALCHART_END_NAMESPACE |
|
345 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,202 +1,204 | |||||
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 "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 "qboxset_p.h" |
|
24 | #include "qboxset_p.h" | |
25 | #include "qabstractbarseries_p.h" |
|
25 | #include "qabstractbarseries_p.h" | |
26 | #include "qboxset.h" |
|
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 | { |
|
36 | { | |
37 | connect(series, SIGNAL(boxsetsRemoved(QList<QBoxSet *>)), this, SLOT(handleBoxsetRemove(QList<QBoxSet *>))); |
|
37 | connect(series, SIGNAL(boxsetsRemoved(QList<QBoxSet *>)), this, SLOT(handleBoxsetRemove(QList<QBoxSet *>))); | |
38 | connect(series->d_func(), SIGNAL(restructuredBoxes()), this, SLOT(handleDataStructureChanged())); |
|
38 | connect(series->d_func(), SIGNAL(restructuredBoxes()), this, SLOT(handleDataStructureChanged())); | |
39 | connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); |
|
39 | connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); | |
40 | connect(series->d_func(), SIGNAL(updatedBoxes()), this, SLOT(handleUpdatedBars())); |
|
40 | connect(series->d_func(), SIGNAL(updatedBoxes()), this, SLOT(handleUpdatedBars())); | |
41 | connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars())); |
|
41 | connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars())); | |
42 | // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here |
|
42 | // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here | |
43 | setZValue(ChartPresenter::BoxPlotSeriesZValue); |
|
43 | setZValue(ChartPresenter::BoxPlotSeriesZValue); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | BoxPlotChartItem::~BoxPlotChartItem() |
|
46 | BoxPlotChartItem::~BoxPlotChartItem() | |
47 | { |
|
47 | { | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | void BoxPlotChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
50 | void BoxPlotChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
51 | { |
|
51 | { | |
52 | Q_UNUSED(painter); |
|
52 | Q_UNUSED(painter); | |
53 | Q_UNUSED(option); |
|
53 | Q_UNUSED(option); | |
54 | Q_UNUSED(widget); |
|
54 | Q_UNUSED(widget); | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation) |
|
57 | void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation) | |
58 | { |
|
58 | { | |
59 | m_animation = animation; |
|
59 | m_animation = animation; | |
60 | if (m_animation) { |
|
60 | if (m_animation) { | |
61 | foreach (BoxWhiskers *item, m_boxTable.values()) |
|
61 | foreach (BoxWhiskers *item, m_boxTable.values()) | |
62 | m_animation->addBox(item); |
|
62 | m_animation->addBox(item); | |
63 | handleDomainUpdated(); |
|
63 | handleDomainUpdated(); | |
64 | } |
|
64 | } | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | void BoxPlotChartItem::handleDataStructureChanged() |
|
67 | void BoxPlotChartItem::handleDataStructureChanged() | |
68 | { |
|
68 | { | |
69 | int setCount = m_series->count(); |
|
69 | int setCount = m_series->count(); | |
70 |
|
70 | |||
71 | for (int s = 0; s < setCount; s++) { |
|
71 | for (int s = 0; s < setCount; s++) { | |
72 | QBoxSet *set = m_series->d_func()->boxSetAt(s); |
|
72 | QBoxSet *set = m_series->d_func()->boxSetAt(s); | |
73 |
|
73 | |||
74 | BoxWhiskers *box = m_boxTable.value(set); |
|
74 | BoxWhiskers *box = m_boxTable.value(set); | |
75 | if (!box) { |
|
75 | if (!box) { | |
76 | // Item is not yet created, make a box and add it to hash table |
|
76 | // Item is not yet created, make a box and add it to hash table | |
77 | box = new BoxWhiskers(set, domain(), this); |
|
77 | box = new BoxWhiskers(set, domain(), this); | |
78 | m_boxTable.insert(set, box); |
|
78 | m_boxTable.insert(set, box); | |
79 | connect(box, SIGNAL(clicked(QBoxSet *)), m_series, SIGNAL(clicked(QBoxSet *))); |
|
79 | connect(box, SIGNAL(clicked(QBoxSet *)), m_series, SIGNAL(clicked(QBoxSet *))); | |
80 | connect(box, SIGNAL(hovered(bool, QBoxSet *)), m_series, SIGNAL(hovered(bool, QBoxSet *))); |
|
80 | connect(box, SIGNAL(hovered(bool, QBoxSet *)), m_series, SIGNAL(hovered(bool, QBoxSet *))); | |
81 | connect(box, SIGNAL(clicked(QBoxSet *)), set, SIGNAL(clicked())); |
|
81 | connect(box, SIGNAL(clicked(QBoxSet *)), set, SIGNAL(clicked())); | |
82 | connect(box, SIGNAL(hovered(bool, QBoxSet *)), set, SIGNAL(hovered(bool))); |
|
82 | connect(box, SIGNAL(hovered(bool, QBoxSet *)), set, SIGNAL(hovered(bool))); | |
83 |
|
83 | |||
84 | // Set the decorative issues for the newly created box |
|
84 | // Set the decorative issues for the newly created box | |
85 | box->setBrush(m_series->brush()); |
|
85 | box->setBrush(m_series->brush()); | |
86 | box->setPen(m_series->pen()); |
|
86 | box->setPen(m_series->pen()); | |
|
87 | box->setBoxOutlined(m_series->boxOutlineVisible()); | |||
87 | } |
|
88 | } | |
88 | updateBoxGeometry(box, s); |
|
89 | updateBoxGeometry(box, s); | |
89 |
|
90 | |||
90 | box->updateGeometry(domain()); |
|
91 | box->updateGeometry(domain()); | |
91 |
|
92 | |||
92 | if (m_animation) |
|
93 | if (m_animation) | |
93 | m_animation->addBox(box); |
|
94 | m_animation->addBox(box); | |
94 | } |
|
95 | } | |
95 |
|
96 | |||
96 | handleDomainUpdated(); |
|
97 | handleDomainUpdated(); | |
97 | } |
|
98 | } | |
98 |
|
99 | |||
99 | void BoxPlotChartItem::handleUpdatedBars() |
|
100 | void BoxPlotChartItem::handleUpdatedBars() | |
100 | { |
|
101 | { | |
101 | foreach (BoxWhiskers *item, m_boxTable.values()) { |
|
102 | foreach (BoxWhiskers *item, m_boxTable.values()) { | |
102 | item->setBrush(m_series->brush()); |
|
103 | item->setBrush(m_series->brush()); | |
103 | item->setPen(m_series->pen()); |
|
104 | item->setPen(m_series->pen()); | |
|
105 | item->setBoxOutlined(m_series->boxOutlineVisible()); | |||
104 | } |
|
106 | } | |
105 | // Override with QBoxSet specific settings |
|
107 | // Override with QBoxSet specific settings | |
106 | foreach (QBoxSet *set, m_boxTable.keys()) { |
|
108 | foreach (QBoxSet *set, m_boxTable.keys()) { | |
107 | if (set->brush().style() != Qt::NoBrush) |
|
109 | if (set->brush().style() != Qt::NoBrush) | |
108 | m_boxTable.value(set)->setBrush(set->brush()); |
|
110 | m_boxTable.value(set)->setBrush(set->brush()); | |
109 | if (set->pen().style() != Qt::NoPen) |
|
111 | if (set->pen().style() != Qt::NoPen) | |
110 | m_boxTable.value(set)->setPen(set->pen()); |
|
112 | m_boxTable.value(set)->setPen(set->pen()); | |
111 | } |
|
113 | } | |
112 | } |
|
114 | } | |
113 |
|
115 | |||
114 | void BoxPlotChartItem::handleBoxsetRemove(QList<QBoxSet*> barSets) |
|
116 | void BoxPlotChartItem::handleBoxsetRemove(QList<QBoxSet*> barSets) | |
115 | { |
|
117 | { | |
116 | foreach (QBoxSet *set, barSets) { |
|
118 | foreach (QBoxSet *set, barSets) { | |
117 | BoxWhiskers *boxItem = m_boxTable.value(set); |
|
119 | BoxWhiskers *boxItem = m_boxTable.value(set); | |
118 | m_boxTable.remove(set); |
|
120 | m_boxTable.remove(set); | |
119 | delete boxItem; |
|
121 | delete boxItem; | |
120 | } |
|
122 | } | |
121 | } |
|
123 | } | |
122 |
|
124 | |||
123 | void BoxPlotChartItem::handleDomainUpdated() |
|
125 | void BoxPlotChartItem::handleDomainUpdated() | |
124 | { |
|
126 | { | |
125 | if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0)) |
|
127 | if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0)) | |
126 | return; |
|
128 | return; | |
127 |
|
129 | |||
128 | // Set my bounding rect to same as domain size. Add one pixel at the top (-1.0) and the bottom as 0.0 would |
|
130 | // Set my bounding rect to same as domain size. Add one pixel at the top (-1.0) and the bottom as 0.0 would | |
129 | // snip a bit off from the whisker at the grid line |
|
131 | // snip a bit off from the whisker at the grid line | |
130 | m_boundingRect.setRect(0.0, -1.0, domain()->size().width(), domain()->size().height() + 1.0); |
|
132 | m_boundingRect.setRect(0.0, -1.0, domain()->size().width(), domain()->size().height() + 1.0); | |
131 |
|
133 | |||
132 | foreach (BoxWhiskers *item, m_boxTable.values()) { |
|
134 | foreach (BoxWhiskers *item, m_boxTable.values()) { | |
133 | item->updateGeometry(domain()); |
|
135 | item->updateGeometry(domain()); | |
134 |
|
136 | |||
135 | // If the animation is set, start the animation for each BoxWhisker item |
|
137 | // If the animation is set, start the animation for each BoxWhisker item | |
136 | if (m_animation) |
|
138 | if (m_animation) | |
137 | presenter()->startAnimation(m_animation->boxAnimation(item)); |
|
139 | presenter()->startAnimation(m_animation->boxAnimation(item)); | |
138 | } |
|
140 | } | |
139 | } |
|
141 | } | |
140 |
|
142 | |||
141 | void BoxPlotChartItem::handleLayoutChanged() |
|
143 | void BoxPlotChartItem::handleLayoutChanged() | |
142 | { |
|
144 | { | |
143 | foreach (BoxWhiskers *item, m_boxTable.values()) { |
|
145 | foreach (BoxWhiskers *item, m_boxTable.values()) { | |
144 | if (m_animation) |
|
146 | if (m_animation) | |
145 | m_animation->setAnimationStart(item); |
|
147 | m_animation->setAnimationStart(item); | |
146 |
|
148 | |||
147 | bool dirty = updateBoxGeometry(item, item->m_data.m_index); |
|
149 | bool dirty = updateBoxGeometry(item, item->m_data.m_index); | |
148 | if (dirty && m_animation) |
|
150 | if (dirty && m_animation) | |
149 | presenter()->startAnimation(m_animation->boxChangeAnimation(item)); |
|
151 | presenter()->startAnimation(m_animation->boxChangeAnimation(item)); | |
150 | else |
|
152 | else | |
151 | item->updateGeometry(domain()); |
|
153 | item->updateGeometry(domain()); | |
152 | } |
|
154 | } | |
153 | } |
|
155 | } | |
154 |
|
156 | |||
155 | QRectF BoxPlotChartItem::boundingRect() const |
|
157 | QRectF BoxPlotChartItem::boundingRect() const | |
156 | { |
|
158 | { | |
157 | return m_boundingRect; |
|
159 | return m_boundingRect; | |
158 | } |
|
160 | } | |
159 |
|
161 | |||
160 | void BoxPlotChartItem::initializeLayout() |
|
162 | void BoxPlotChartItem::initializeLayout() | |
161 | { |
|
163 | { | |
162 | } |
|
164 | } | |
163 |
|
165 | |||
164 | QVector<QRectF> BoxPlotChartItem::calculateLayout() |
|
166 | QVector<QRectF> BoxPlotChartItem::calculateLayout() | |
165 | { |
|
167 | { | |
166 | return QVector<QRectF>(); |
|
168 | return QVector<QRectF>(); | |
167 | } |
|
169 | } | |
168 |
|
170 | |||
169 | bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index) |
|
171 | bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index) | |
170 | { |
|
172 | { | |
171 | bool changed = false; |
|
173 | bool changed = false; | |
172 |
|
174 | |||
173 | QBoxSet *set = m_series->d_func()->boxSetAt(index); |
|
175 | QBoxSet *set = m_series->d_func()->boxSetAt(index); | |
174 | BoxWhiskersData &data = box->m_data; |
|
176 | BoxWhiskersData &data = box->m_data; | |
175 |
|
177 | |||
176 | if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) || |
|
178 | if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) || | |
177 | (data.m_median != set->at(2)) || (data.m_upperQuartile != set->at(3)) || (data.m_upperExtreme != set->at(4))) { |
|
179 | (data.m_median != set->at(2)) || (data.m_upperQuartile != set->at(3)) || (data.m_upperExtreme != set->at(4))) { | |
178 | changed = true; |
|
180 | changed = true; | |
179 | } |
|
181 | } | |
180 |
|
182 | |||
181 | data.m_lowerExtreme = set->at(0); |
|
183 | data.m_lowerExtreme = set->at(0); | |
182 | data.m_lowerQuartile = set->at(1); |
|
184 | data.m_lowerQuartile = set->at(1); | |
183 | data.m_median = set->at(2); |
|
185 | data.m_median = set->at(2); | |
184 | data.m_upperQuartile = set->at(3); |
|
186 | data.m_upperQuartile = set->at(3); | |
185 | data.m_upperExtreme = set->at(4); |
|
187 | data.m_upperExtreme = set->at(4); | |
186 | data.m_index = index; |
|
188 | data.m_index = index; | |
187 | data.m_boxItems = m_series->count(); |
|
189 | data.m_boxItems = m_series->count(); | |
188 |
|
190 | |||
189 | data.m_maxX = domain()->maxX(); |
|
191 | data.m_maxX = domain()->maxX(); | |
190 | data.m_minX = domain()->minX(); |
|
192 | data.m_minX = domain()->minX(); | |
191 | data.m_maxY = domain()->maxY(); |
|
193 | data.m_maxY = domain()->maxY(); | |
192 | data.m_minY = domain()->minY(); |
|
194 | data.m_minY = domain()->minY(); | |
193 |
|
195 | |||
194 | data.m_seriesIndex = m_seriesIndex; |
|
196 | data.m_seriesIndex = m_seriesIndex; | |
195 | data.m_seriesCount = m_seriesCount; |
|
197 | data.m_seriesCount = m_seriesCount; | |
196 |
|
198 | |||
197 | return changed; |
|
199 | return changed; | |
198 | } |
|
200 | } | |
199 |
|
201 | |||
200 | #include "moc_boxplotchartitem_p.cpp" |
|
202 | #include "moc_boxplotchartitem_p.cpp" | |
201 |
|
203 | |||
202 | QTCOMMERCIALCHART_END_NAMESPACE |
|
204 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,174 +1,187 | |||||
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 "boxwhiskers_p.h" |
|
21 | #include "boxwhiskers_p.h" | |
22 | #include <QPainter> |
|
22 | #include <QPainter> | |
23 | #include <QWidget> |
|
23 | #include <QWidget> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | BoxWhiskers::BoxWhiskers(QBoxSet *set, AbstractDomain *domain, QGraphicsObject *parent) : |
|
27 | BoxWhiskers::BoxWhiskers(QBoxSet *set, AbstractDomain *domain, QGraphicsObject *parent) : | |
28 | QGraphicsObject(parent), |
|
28 | QGraphicsObject(parent), | |
29 | m_boxSet(set), |
|
29 | m_boxSet(set), | |
30 | m_domain(domain) |
|
30 | m_domain(domain) | |
31 | { |
|
31 | { | |
32 | setAcceptHoverEvents(true); |
|
32 | setAcceptHoverEvents(true); | |
33 | setAcceptedMouseButtons(Qt::MouseButtonMask); |
|
33 | setAcceptedMouseButtons(Qt::MouseButtonMask); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | BoxWhiskers::~BoxWhiskers() |
|
36 | BoxWhiskers::~BoxWhiskers() | |
37 | { |
|
37 | { | |
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 | emit clicked(m_boxSet); |
|
43 | emit clicked(m_boxSet); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void BoxWhiskers::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
46 | void BoxWhiskers::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
47 | { |
|
47 | { | |
48 | Q_UNUSED(event) |
|
48 | Q_UNUSED(event) | |
49 | emit hovered(true, m_boxSet); |
|
49 | emit hovered(true, m_boxSet); | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
52 | void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
53 | { |
|
53 | { | |
54 | Q_UNUSED(event) |
|
54 | Q_UNUSED(event) | |
55 | emit hovered(false, m_boxSet); |
|
55 | emit hovered(false, m_boxSet); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | void BoxWhiskers::setBrush(const QBrush &brush) |
|
58 | void BoxWhiskers::setBrush(const QBrush &brush) | |
59 | { |
|
59 | { | |
60 | m_brush = brush; |
|
60 | m_brush = brush; | |
|
61 | m_outlinePen.setColor(m_brush.color()); | |||
61 | update(); |
|
62 | update(); | |
62 | } |
|
63 | } | |
63 |
|
64 | |||
64 | void BoxWhiskers::setPen(const QPen &pen) |
|
65 | void BoxWhiskers::setPen(const QPen &pen) | |
65 | { |
|
66 | { | |
|
67 | qreal widthDiff = pen.widthF() - m_pen.widthF(); | |||
|
68 | m_boundingRect.adjust(-widthDiff, -widthDiff, widthDiff, widthDiff); | |||
|
69 | ||||
66 | m_pen = pen; |
|
70 | m_pen = pen; | |
|
71 | m_medianPen = pen; | |||
|
72 | m_medianPen.setCapStyle(Qt::FlatCap); | |||
|
73 | m_outlinePen = pen; | |||
|
74 | m_outlinePen.setStyle(Qt::SolidLine); | |||
|
75 | m_outlinePen.setColor(m_brush.color()); | |||
|
76 | ||||
67 | update(); |
|
77 | update(); | |
68 | } |
|
78 | } | |
69 |
|
79 | |||
70 | void BoxWhiskers::setLayout(const BoxWhiskersData &data) |
|
80 | void BoxWhiskers::setLayout(const BoxWhiskersData &data) | |
71 | { |
|
81 | { | |
72 | m_data = data; |
|
82 | m_data = data; | |
73 |
|
83 | |||
74 | updateGeometry(m_domain); |
|
84 | updateGeometry(m_domain); | |
75 | update(); |
|
85 | update(); | |
76 | } |
|
86 | } | |
77 |
|
87 | |||
78 | QSizeF BoxWhiskers::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
88 | QSizeF BoxWhiskers::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
79 | { |
|
89 | { | |
80 | Q_UNUSED(which) |
|
90 | Q_UNUSED(which) | |
81 | Q_UNUSED(constraint) |
|
91 | Q_UNUSED(constraint) | |
82 |
|
92 | |||
83 | return QSizeF(); |
|
93 | return QSizeF(); | |
84 | } |
|
94 | } | |
85 |
|
95 | |||
86 | void BoxWhiskers::setGeometry(const QRectF &rect) |
|
96 | void BoxWhiskers::setGeometry(const QRectF &rect) | |
87 | { |
|
97 | { | |
88 | Q_UNUSED(rect) |
|
98 | Q_UNUSED(rect) | |
89 | } |
|
99 | } | |
90 |
|
100 | |||
91 | QRectF BoxWhiskers::boundingRect() const |
|
101 | QRectF BoxWhiskers::boundingRect() const | |
92 | { |
|
102 | { | |
93 | return m_boundingRect; |
|
103 | return m_boundingRect; | |
94 | } |
|
104 | } | |
95 |
|
105 | |||
96 | void BoxWhiskers::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
106 | void BoxWhiskers::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
97 | { |
|
107 | { | |
98 | Q_UNUSED(option) |
|
108 | Q_UNUSED(option) | |
99 | Q_UNUSED(widget) |
|
109 | Q_UNUSED(widget) | |
100 |
|
110 | |||
101 | painter->setPen(m_pen); |
|
|||
102 | painter->setBrush(m_brush); |
|
111 | painter->setBrush(m_brush); | |
103 | painter->setClipRect(parentItem()->boundingRect()); |
|
112 | painter->setClipRect(parentItem()->boundingRect()); | |
|
113 | painter->setPen(m_pen); | |||
104 | painter->drawPath(m_boxPath); |
|
114 | painter->drawPath(m_boxPath); | |
|
115 | if (!m_boxOutlined) | |||
|
116 | painter->setPen(m_outlinePen); | |||
|
117 | painter->drawRect(m_middleBox); | |||
|
118 | painter->setPen(m_medianPen); | |||
|
119 | qreal halfLine = m_pen.widthF() / 2.0; | |||
|
120 | painter->drawLine(QLineF(m_geometryLeft - halfLine, m_geometryMedian, | |||
|
121 | m_geometryRight + halfLine, m_geometryMedian)); | |||
105 | } |
|
122 | } | |
106 |
|
123 | |||
107 | void BoxWhiskers::updateGeometry(AbstractDomain *domain) |
|
124 | void BoxWhiskers::updateGeometry(AbstractDomain *domain) | |
108 | { |
|
125 | { | |
109 | m_domain = domain; |
|
126 | m_domain = domain; | |
110 |
|
127 | |||
111 | prepareGeometryChange(); |
|
128 | prepareGeometryChange(); | |
112 |
|
129 | |||
113 | QPainterPath path; |
|
130 | QPainterPath path; | |
114 | m_boxPath = path; |
|
131 | m_boxPath = path; | |
115 | m_boundingRect = m_boxPath.boundingRect(); |
|
132 | m_boundingRect = m_boxPath.boundingRect(); | |
116 |
|
133 | |||
117 | qreal columnWidth = 1.0 / m_data.m_seriesCount; |
|
134 | qreal columnWidth = 1.0 / m_data.m_seriesCount; | |
118 | qreal left = 0.25 * columnWidth + columnWidth * m_data.m_seriesIndex + m_data.m_index - 0.5; |
|
135 | qreal left = 0.25 * columnWidth + columnWidth * m_data.m_seriesIndex + m_data.m_index - 0.5; | |
119 | qreal barWidth = columnWidth / 2.0; |
|
136 | qreal barWidth = columnWidth / 2.0; | |
120 |
|
137 | |||
121 | QPointF geometryPoint = m_domain->calculateGeometryPoint(QPointF(left, m_data.m_upperExtreme), m_validData); |
|
138 | QPointF geometryPoint = m_domain->calculateGeometryPoint(QPointF(left, m_data.m_upperExtreme), m_validData); | |
122 | if (!m_validData) |
|
139 | if (!m_validData) | |
123 | return; |
|
140 | return; | |
124 |
|
|
141 | m_geometryLeft = geometryPoint.x(); | |
125 | qreal geometryUpperExtreme = geometryPoint.y(); |
|
142 | qreal geometryUpperExtreme = geometryPoint.y(); | |
126 | geometryPoint = m_domain->calculateGeometryPoint(QPointF(left + barWidth, m_data.m_upperQuartile), m_validData); |
|
143 | geometryPoint = m_domain->calculateGeometryPoint(QPointF(left + barWidth, m_data.m_upperQuartile), m_validData); | |
127 | if (!m_validData) |
|
144 | if (!m_validData) | |
128 | return; |
|
145 | return; | |
129 |
|
|
146 | m_geometryRight = geometryPoint.x(); | |
130 | qreal geometryUpperQuartile = geometryPoint.y(); |
|
147 | qreal geometryUpperQuartile = geometryPoint.y(); | |
131 | geometryPoint = m_domain->calculateGeometryPoint(QPointF(left, m_data.m_lowerQuartile), m_validData); |
|
148 | geometryPoint = m_domain->calculateGeometryPoint(QPointF(left, m_data.m_lowerQuartile), m_validData); | |
132 | if (!m_validData) |
|
149 | if (!m_validData) | |
133 | return; |
|
150 | return; | |
134 | qreal geometryLowerQuartile = geometryPoint.y(); |
|
151 | qreal geometryLowerQuartile = geometryPoint.y(); | |
135 | geometryPoint = m_domain->calculateGeometryPoint(QPointF(left, m_data.m_lowerExtreme), m_validData); |
|
152 | geometryPoint = m_domain->calculateGeometryPoint(QPointF(left, m_data.m_lowerExtreme), m_validData); | |
136 | if (!m_validData) |
|
153 | if (!m_validData) | |
137 | return; |
|
154 | return; | |
138 | qreal geometryLowerExtreme = geometryPoint.y(); |
|
155 | qreal geometryLowerExtreme = geometryPoint.y(); | |
139 | geometryPoint = m_domain->calculateGeometryPoint(QPointF(left, m_data.m_median), m_validData); |
|
156 | geometryPoint = m_domain->calculateGeometryPoint(QPointF(left, m_data.m_median), m_validData); | |
140 | if (!m_validData) |
|
157 | if (!m_validData) | |
141 | return; |
|
158 | return; | |
142 |
|
|
159 | m_geometryMedian = geometryPoint.y(); | |
143 |
|
160 | |||
144 | // Upper whisker |
|
161 | // Upper whisker | |
145 | path.moveTo(geometryLeft, geometryUpperExtreme); |
|
162 | path.moveTo(m_geometryLeft, geometryUpperExtreme); | |
146 | path.lineTo(geometryRight, geometryUpperExtreme); |
|
163 | path.lineTo(m_geometryRight, geometryUpperExtreme); | |
147 | path.moveTo((geometryLeft + geometryRight) / 2.0, geometryUpperExtreme); |
|
164 | path.moveTo((m_geometryLeft + m_geometryRight) / 2.0, geometryUpperExtreme); | |
148 | path.lineTo((geometryLeft + geometryRight) / 2.0, geometryUpperQuartile); |
|
165 | path.lineTo((m_geometryLeft + m_geometryRight) / 2.0, geometryUpperQuartile); | |
149 |
|
166 | |||
150 | // Middle Box |
|
167 | // Middle Box | |
151 |
|
|
168 | m_middleBox.setCoords(m_geometryLeft, geometryUpperQuartile, m_geometryRight, geometryLowerQuartile); | |
152 |
|
||||
153 | // Median line |
|
|||
154 | path.moveTo(geometryLeft, geometryMedian); |
|
|||
155 | path.lineTo(geometryRight, geometryMedian); |
|
|||
156 |
|
169 | |||
157 | // Lower whisker |
|
170 | // Lower whisker | |
158 | path.moveTo(geometryLeft, geometryLowerExtreme); |
|
171 | path.moveTo(m_geometryLeft, geometryLowerExtreme); | |
159 | path.lineTo(geometryRight, geometryLowerExtreme); |
|
172 | path.lineTo(m_geometryRight, geometryLowerExtreme); | |
160 | path.moveTo((geometryLeft + geometryRight) / 2.0, geometryLowerQuartile); |
|
173 | path.moveTo((m_geometryLeft + m_geometryRight) / 2.0, geometryLowerQuartile); | |
161 | path.lineTo((geometryLeft + geometryRight) / 2.0, geometryLowerExtreme); |
|
174 | path.lineTo((m_geometryLeft + m_geometryRight) / 2.0, geometryLowerExtreme); | |
162 |
|
175 | |||
163 | path.closeSubpath(); |
|
176 | path.closeSubpath(); | |
164 |
|
177 | |||
165 | m_boxPath = path; |
|
178 | m_boxPath = path; | |
166 | m_boundingRect = m_boxPath.boundingRect(); |
|
179 | m_boundingRect = m_boxPath.boundingRect(); | |
167 |
|
180 | |||
168 | qreal extra = (m_pen.width() / 2.0); |
|
181 | qreal extra = (m_pen.widthF() / 2.0); | |
169 | m_boundingRect.adjust(-extra, -extra, extra, extra); |
|
182 | m_boundingRect.adjust(-extra, -extra, extra, extra); | |
170 | } |
|
183 | } | |
171 |
|
184 | |||
172 | #include "moc_boxwhiskers_p.cpp" |
|
185 | #include "moc_boxwhiskers_p.cpp" | |
173 |
|
186 | |||
174 | QTCOMMERCIALCHART_END_NAMESPACE |
|
187 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,92 +1,100 | |||||
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 | // 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 BOXWHISKERS_H |
|
30 | #ifndef BOXWHISKERS_H | |
31 | #define BOXWHISKERS_H |
|
31 | #define BOXWHISKERS_H | |
32 |
|
32 | |||
33 | #include "boxwhiskersdata_p.h" |
|
33 | #include "boxwhiskersdata_p.h" | |
34 | #include "qchartglobal.h" |
|
34 | #include "qchartglobal.h" | |
35 | #include "abstractdomain_p.h" |
|
35 | #include "abstractdomain_p.h" | |
36 | #include <QBoxSet> |
|
36 | #include <QBoxSet> | |
37 | #include <QGraphicsRectItem> |
|
37 | #include <QGraphicsRectItem> | |
38 | #include <QGraphicsLineItem> |
|
38 | #include <QGraphicsLineItem> | |
39 | #include <QGraphicsLayoutItem> |
|
39 | #include <QGraphicsLayoutItem> | |
40 | #include <QPainterPath> |
|
40 | #include <QPainterPath> | |
41 |
|
41 | |||
42 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
42 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
43 |
|
43 | |||
44 | class QBarSet; |
|
44 | class QBarSet; | |
45 |
|
45 | |||
46 | class BoxWhiskers : public QGraphicsObject |
|
46 | class BoxWhiskers : public QGraphicsObject | |
47 | { |
|
47 | { | |
48 | Q_OBJECT |
|
48 | Q_OBJECT | |
49 |
|
49 | |||
50 | public: |
|
50 | public: | |
51 | BoxWhiskers(QBoxSet *set, AbstractDomain *domain, QGraphicsObject *parent); |
|
51 | BoxWhiskers(QBoxSet *set, AbstractDomain *domain, QGraphicsObject *parent); | |
52 | ~BoxWhiskers(); |
|
52 | ~BoxWhiskers(); | |
53 |
|
53 | |||
54 | void setBrush(const QBrush &brush); |
|
54 | void setBrush(const QBrush &brush); | |
55 | void setPen(const QPen &pen); |
|
55 | void setPen(const QPen &pen); | |
56 | void setLayout(const BoxWhiskersData &data); |
|
56 | void setLayout(const BoxWhiskersData &data); | |
|
57 | void setBoxOutlined(const bool outlined) { m_boxOutlined = outlined; } | |||
57 |
|
58 | |||
58 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
59 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
59 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); |
|
60 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); | |
60 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); |
|
61 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); | |
61 |
|
62 | |||
62 | QRectF boundingRect() const; |
|
63 | QRectF boundingRect() const; | |
63 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
64 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
64 |
|
65 | |||
65 | void updateGeometry(AbstractDomain *domain); |
|
66 | void updateGeometry(AbstractDomain *domain); | |
66 | protected: |
|
67 | protected: | |
67 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
|
68 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; | |
68 | void setGeometry(const QRectF &rect); |
|
69 | void setGeometry(const QRectF &rect); | |
69 |
|
70 | |||
70 | Q_SIGNALS: |
|
71 | Q_SIGNALS: | |
71 | void clicked(QBoxSet *boxset); |
|
72 | void clicked(QBoxSet *boxset); | |
72 | void hovered(bool status, QBoxSet *boxset); |
|
73 | void hovered(bool status, QBoxSet *boxset); | |
73 |
|
74 | |||
74 | private: |
|
75 | private: | |
75 | friend class BoxPlotChartItem; |
|
76 | friend class BoxPlotChartItem; | |
76 | friend class BoxPlotAnimation; |
|
77 | friend class BoxPlotAnimation; | |
77 |
|
78 | |||
78 | QBoxSet *m_boxSet; |
|
79 | QBoxSet *m_boxSet; | |
79 | AbstractDomain *m_domain; |
|
80 | AbstractDomain *m_domain; | |
80 | QPainterPath m_boxPath; |
|
81 | QPainterPath m_boxPath; | |
81 | QRectF m_boundingRect; |
|
82 | QRectF m_boundingRect; | |
82 | bool m_hovering; |
|
83 | bool m_hovering; | |
83 | bool m_validData; |
|
84 | bool m_validData; | |
84 | QBrush m_brush; |
|
85 | QBrush m_brush; | |
85 | QPen m_pen; |
|
86 | QPen m_pen; | |
|
87 | QPen m_medianPen; | |||
|
88 | QPen m_outlinePen; | |||
|
89 | bool m_boxOutlined; | |||
86 | BoxWhiskersData m_data; |
|
90 | BoxWhiskersData m_data; | |
87 | QSizeF m_domainSize; |
|
91 | QSizeF m_domainSize; | |
|
92 | QRectF m_middleBox; | |||
|
93 | qreal m_geometryMedian; | |||
|
94 | qreal m_geometryLeft; | |||
|
95 | qreal m_geometryRight; | |||
88 | }; |
|
96 | }; | |
89 |
|
97 | |||
90 | QTCOMMERCIALCHART_END_NAMESPACE |
|
98 | QTCOMMERCIALCHART_END_NAMESPACE | |
91 |
|
99 | |||
92 | #endif // BOXWHISKERS_H |
|
100 | #endif // BOXWHISKERS_H |
@@ -1,694 +1,647 | |||||
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 "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 "qbarcategoryaxis.h" | |
25 | #include "boxplotchartitem_p.h" |
|
25 | #include "boxplotchartitem_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "charttheme_p.h" |
|
27 | #include "charttheme_p.h" | |
28 | #include "qvalueaxis.h" |
|
28 | #include "qvalueaxis.h" | |
29 | #include "charttheme_p.h" |
|
29 | #include "charttheme_p.h" | |
30 | #include "boxplotanimation_p.h" |
|
30 | #include "boxplotanimation_p.h" | |
31 | #include "qchart_p.h" |
|
31 | #include "qchart_p.h" | |
32 | #include "qboxset.h" |
|
32 | #include "qboxset.h" | |
33 | #include "qboxset_p.h" |
|
33 | #include "qboxset_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | /*! |
|
37 | /*! | |
38 | \class QBoxPlotSeries |
|
38 | \class QBoxPlotSeries | |
39 | \brief Series for creating box-and-whiskers chart |
|
39 | \brief Series for creating box-and-whiskers chart | |
40 | \mainclass |
|
40 | \mainclass | |
41 |
|
41 | |||
42 | QBoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this class is to act as |
|
42 | QBoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this class is to act as | |
43 | a container for single box-and-whisker items. Each item is drawn to own slot. If chart includes multiple instances of |
|
43 | a container for single box-and-whisker items. Each item is drawn to own slot. If chart includes multiple instances of | |
44 | QBoxPlotSeries then box-and-whiskers items with the same index are drawn to same slot. |
|
44 | QBoxPlotSeries then box-and-whiskers items with the same index are drawn to same slot. | |
45 |
|
45 | |||
46 | See the \l {Box and Whiskers Example} {box-and-whiskers chart example} to learn how to create a box-and-whiskers chart. |
|
46 | See the \l {Box and Whiskers Example} {box-and-whiskers chart example} to learn how to create a box-and-whiskers chart. | |
47 | \image examples_boxplotchart.png |
|
47 | \image examples_boxplotchart.png | |
48 |
|
48 | |||
49 | \sa QBoxSet |
|
49 | \sa QBoxSet | |
50 | */ |
|
50 | */ | |
51 |
|
||||
52 | /*! |
|
|||
53 | \qmlclass BoxPlotSeries QBoxPlotSeries |
|
|||
54 | \inherits QAbstractSeries |
|
|||
55 |
|
||||
56 | BoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this class is to act as |
|
|||
57 | a container for single box-and-whisker items. Each item is drawn to own slot. If chart includes multiple instances of |
|
|||
58 | BoxPlotSeries then box-and-whiskers items with the same index are drawn to same slot. |
|
|||
59 |
|
||||
60 | The following QML shows how to create a simple box-and-whiskers chart: |
|
|||
61 | \code |
|
|||
62 | import QtQuick 1.0 |
|
|||
63 | import QtCommercial.Chart 1.1 |
|
|||
64 |
|
||||
65 | ChartView { |
|
|||
66 | title: "Box Plot series" |
|
|||
67 | width: 400 |
|
|||
68 | height: 300 |
|
|||
69 | theme: ChartView.ChartThemeBrownSand |
|
|||
70 | legend.alignment: Qt.AlignBottom |
|
|||
71 |
|
||||
72 | BoxPlotSeries { |
|
|||
73 | id: plotSeries |
|
|||
74 | name: "Income" |
|
|||
75 | BoxSet { label: "Jan"; values: [3, 4, 5.1, 6.2, 8.5] } |
|
|||
76 | BoxSet { label: "Feb"; values: [5, 6, 7.5, 8.6, 11.8] } |
|
|||
77 | BoxSet { label: "Mar"; values: [3.2, 5, 5.7, 8, 9.2] } |
|
|||
78 | BoxSet { label: "Apr"; values: [3.8, 5, 6.4, 7, 8] } |
|
|||
79 | BoxSet { label: "May"; values: [4, 5, 5.2, 6, 7] } |
|
|||
80 | } |
|
|||
81 | } |
|
|||
82 | \endcode |
|
|||
83 |
|
||||
84 | \beginfloatleft |
|
|||
85 | \image examples_qmlboxplot.png |
|
|||
86 | \endfloat |
|
|||
87 | \clearfloat |
|
|||
88 | */ |
|
|||
89 |
|
||||
90 | /*! |
|
51 | /*! | |
91 | \fn QBoxPlotSeries::boxsetsAdded(QList<QBoxSet *> sets) |
|
52 | \fn QBoxPlotSeries::boxsetsAdded(QList<QBoxSet *> sets) | |
92 | \brief Signal is emitted when a new \a sets of box-and-whiskers data is added to the series. |
|
53 | \brief Signal is emitted when a new \a sets of box-and-whiskers data is added to the series. | |
93 | */ |
|
54 | */ | |
94 |
|
||||
95 | /*! |
|
55 | /*! | |
96 | \fn QBoxPlotSeries::boxsetsRemoved(QList<QBoxSet *> sets) |
|
56 | \fn QBoxPlotSeries::boxsetsRemoved(QList<QBoxSet *> sets) | |
97 | \brief Signal is emitted when \a sets of box-and-whiskers data is removed from the series. |
|
57 | \brief Signal is emitted when \a sets of box-and-whiskers data is removed from the series. | |
98 | */ |
|
58 | */ | |
99 |
|
||||
100 | /*! |
|
59 | /*! | |
101 | \fn QBoxPlotSeries::clicked(QBoxSet *boxset) |
|
60 | \fn QBoxPlotSeries::clicked(QBoxSet *boxset) | |
102 | \brief Signal is emitted when the user clicks the \a boxset on the chart. |
|
61 | \brief Signal is emitted when the user clicks the \a boxset on the chart. | |
103 | */ |
|
62 | */ | |
104 |
|
||||
105 | /*! |
|
63 | /*! | |
106 | \fn QBoxPlotSeries::hovered(bool status, QBoxSet *boxset) |
|
64 | \fn QBoxPlotSeries::hovered(bool status, QBoxSet *boxset) | |
107 | \brief Signal is emitted when there is change in hover \a status over \a boxset. |
|
65 | \brief Signal is emitted when there is change in hover \a status over \a boxset. | |
108 | */ |
|
66 | */ | |
109 |
|
||||
110 | /*! |
|
67 | /*! | |
111 | \fn QBoxPlotSeries::countChanged() |
|
68 | \fn QBoxPlotSeries::countChanged() | |
112 | \brief Signal is emitted when there is change in count of box-and-whiskers items in the series. |
|
69 | \brief Signal is emitted when there is change in count of box-and-whiskers items in the series. | |
113 | */ |
|
70 | */ | |
114 | /*! |
|
71 | /*! | |
115 | \fn virtual SeriesType QBoxPlotSeries::type() const |
|
72 | \property QBoxPlotSeries::boxOutlineVisible | |
116 | \brief Returns type of series. |
|
73 | \brief This property configures the visibility of the middle box outline. | |
117 | \sa QAbstractSeries, SeriesType |
|
|||
118 | */ |
|
74 | */ | |
119 | /*! |
|
75 | /*! | |
120 | \qmlmethod BoxPlotSeries::append(const QString label, QVariantList values) |
|
76 | \property QBoxPlotSeries::pen | |
121 | Appends a new box-and-whiskers set with \a label and \a values to the series. |
|
77 | \brief This property configures the pen of the box-and-whiskers items. | |
122 | */ |
|
|||
123 | /*! |
|
|||
124 | \qmlmethod BoxPlotSeries::append(BoxSet *box) |
|
|||
125 | Appends the \a box to the series. |
|
|||
126 | */ |
|
78 | */ | |
127 | /*! |
|
79 | /*! | |
128 | \qmlmethod BoxPlotSeries::insert(int index, const QString label, QVariantList values) |
|
80 | \property QBoxPlotSeries::brush | |
129 | Inserts a new box-and-whiskers set with \a label and \a values at the \a index position. |
|
81 | \brief This property configures the brush of the box-and-whiskers items. | |
130 | */ |
|
82 | */ | |
131 | /*! |
|
83 | /*! | |
132 | \qmlmethod BoxPlotSeries::remove(QBoxSet *boxset) |
|
84 | \fn void QBoxPlotSeries::boxOutlineVisibilityChanged() | |
133 | Removes the \a boxset from the series. |
|
85 | Signal is emitted when the middle box outline visibility is changed. | |
134 | */ |
|
86 | */ | |
135 | /*! |
|
87 | /*! | |
136 |
\ |
|
88 | \fn void QBoxPlotSeries::penChanged() | |
137 | Removes all boxsets from the series. Deletes removed sets. |
|
89 | This signal is emitted when the pen of the box-and-whiskers has changed. | |
|
90 | \sa brush | |||
138 | */ |
|
91 | */ | |
139 |
|
||||
140 | /*! |
|
92 | /*! | |
141 | \qmlsignal BoxPlotSeries::onClicked(BoxSet boxset); |
|
93 | \fn void QBoxPlotSeries::brushChanged() | |
142 |
|
|
94 | This signal is emitted when the brush of the box-and-whiskers has changed. | |
143 | */ |
|
95 | \sa brush | |
144 | /*! |
|
|||
145 | \qmlsignal BoxPlotSeries::onHovered(bool status, BoxSet boxset); |
|
|||
146 | Signal is emitted when there is change in hover \a status over \a boxset. |
|
|||
147 | */ |
|
96 | */ | |
|
97 | ||||
|
98 | ||||
148 | /*! |
|
99 | /*! | |
149 | \qmlsignal BoxPlotSeries::onCountChanged(); |
|
100 | \fn virtual SeriesType QBoxPlotSeries::type() const | |
150 | Signal is emitted when there is change in count of box-and-whiskers items in the series. |
|
101 | \brief Returns type of series. | |
|
102 | \sa QAbstractSeries, SeriesType | |||
151 | */ |
|
103 | */ | |
152 | /*! |
|
|||
153 | \qmlsignal BoxPlotSeries::onBoxsetsAdded() |
|
|||
154 | Signal is emitted when new box-and-whiskers sets are added to the series. |
|
|||
155 | */ |
|
|||
156 | /*! |
|
|||
157 | \qmlsignal BoxPlotSeries::boxsetsRemoved() |
|
|||
158 | Signal is emitted when new box-and-whiskers sets are removed from the series. |
|
|||
159 | */ |
|
|||
160 |
|
104 | |||
161 | /*! |
|
105 | /*! | |
162 | Constructs empty QBoxPlotSeries. |
|
106 | Constructs empty QBoxPlotSeries. | |
163 | QBoxPlotSeries is QObject which is a child of a \a parent. |
|
107 | QBoxPlotSeries is QObject which is a child of a \a parent. | |
164 | */ |
|
108 | */ | |
165 | QBoxPlotSeries::QBoxPlotSeries(QObject *parent) |
|
109 | QBoxPlotSeries::QBoxPlotSeries(QObject *parent) | |
166 | : QAbstractSeries(*new QBoxPlotSeriesPrivate(this), parent) |
|
110 | : QAbstractSeries(*new QBoxPlotSeriesPrivate(this), parent) | |
167 | { |
|
111 | { | |
168 | } |
|
112 | } | |
169 |
|
113 | |||
170 | /*! |
|
114 | /*! | |
171 | Destructor. Removes series from chart. |
|
115 | Destructor. Removes series from chart. | |
172 | */ |
|
116 | */ | |
173 | QBoxPlotSeries::~QBoxPlotSeries() |
|
117 | QBoxPlotSeries::~QBoxPlotSeries() | |
174 | { |
|
118 | { | |
175 | Q_D(QBoxPlotSeries); |
|
119 | Q_D(QBoxPlotSeries); | |
176 | if (d->m_chart) |
|
120 | if (d->m_chart) | |
177 | d->m_chart->removeSeries(this); |
|
121 | d->m_chart->removeSeries(this); | |
178 | } |
|
122 | } | |
179 |
|
123 | |||
180 | /*! |
|
124 | /*! | |
181 | Adds a single box and whiskers set to series. Takes ownership of the \a set. If the set is null or is already in series, it won't be appended. |
|
125 | Adds a single box and whiskers set to series. Takes ownership of the \a set. If the set is null or is already in series, it won't be appended. | |
182 | Returns true, if appending succeeded. |
|
126 | Returns true, if appending succeeded. | |
183 | */ |
|
127 | */ | |
184 | bool QBoxPlotSeries::append(QBoxSet *set) |
|
128 | bool QBoxPlotSeries::append(QBoxSet *set) | |
185 | { |
|
129 | { | |
186 | Q_D(QBoxPlotSeries); |
|
130 | Q_D(QBoxPlotSeries); | |
187 |
|
131 | |||
188 | bool success = d->append(set); |
|
132 | bool success = d->append(set); | |
189 | if (success) { |
|
133 | if (success) { | |
190 | QList<QBoxSet *> sets; |
|
134 | QList<QBoxSet *> sets; | |
191 | sets.append(set); |
|
135 | sets.append(set); | |
192 | set->setParent(this); |
|
136 | set->setParent(this); | |
193 | emit boxsetsAdded(sets); |
|
137 | emit boxsetsAdded(sets); | |
194 | emit countChanged(); |
|
138 | emit countChanged(); | |
195 | } |
|
139 | } | |
196 | return success; |
|
140 | return success; | |
197 | } |
|
141 | } | |
198 |
|
142 | |||
199 | /*! |
|
143 | /*! | |
200 | Removes boxset from the series. Deletes the \a set and returns true if successful. |
|
144 | Removes boxset from the series. Deletes the \a set and returns true if successful. | |
201 | */ |
|
145 | */ | |
202 | bool QBoxPlotSeries::remove(QBoxSet *set) |
|
146 | bool QBoxPlotSeries::remove(QBoxSet *set) | |
203 | { |
|
147 | { | |
204 | Q_D(QBoxPlotSeries); |
|
148 | Q_D(QBoxPlotSeries); | |
205 | bool success = d->remove(set); |
|
149 | bool success = d->remove(set); | |
206 | if (success) { |
|
150 | if (success) { | |
207 | QList<QBoxSet *> sets; |
|
151 | QList<QBoxSet *> sets; | |
208 | sets.append(set); |
|
152 | sets.append(set); | |
209 | set->setParent(0); |
|
153 | set->setParent(0); | |
210 | emit boxsetsRemoved(sets); |
|
154 | emit boxsetsRemoved(sets); | |
211 | emit countChanged(); |
|
155 | emit countChanged(); | |
212 | delete set; |
|
156 | delete set; | |
213 | set = 0; |
|
157 | set = 0; | |
214 | } |
|
158 | } | |
215 | return success; |
|
159 | return success; | |
216 | } |
|
160 | } | |
217 |
|
161 | |||
218 | /*! |
|
162 | /*! | |
219 | Takes a single \a set from the series. Does not delete the boxset object. |
|
163 | Takes a single \a set from the series. Does not delete the boxset object. | |
220 |
|
164 | |||
221 | NOTE: The series remains as the boxset's parent object. You must set the |
|
165 | NOTE: The series remains as the boxset's parent object. You must set the | |
222 | parent object to take full ownership. |
|
166 | parent object to take full ownership. | |
223 |
|
167 | |||
224 | Returns true if take was successful. |
|
168 | Returns true if take was successful. | |
225 | */ |
|
169 | */ | |
226 | bool QBoxPlotSeries::take(QBoxSet *set) |
|
170 | bool QBoxPlotSeries::take(QBoxSet *set) | |
227 | { |
|
171 | { | |
228 | Q_D(QBoxPlotSeries); |
|
172 | Q_D(QBoxPlotSeries); | |
229 |
|
173 | |||
230 | bool success = d->remove(set); |
|
174 | bool success = d->remove(set); | |
231 | if (success) { |
|
175 | if (success) { | |
232 | QList<QBoxSet *> sets; |
|
176 | QList<QBoxSet *> sets; | |
233 | sets.append(set); |
|
177 | sets.append(set); | |
234 | emit boxsetsRemoved(sets); |
|
178 | emit boxsetsRemoved(sets); | |
235 | emit countChanged(); |
|
179 | emit countChanged(); | |
236 | } |
|
180 | } | |
237 | return success; |
|
181 | return success; | |
238 | } |
|
182 | } | |
239 |
|
183 | |||
240 | /*! |
|
184 | /*! | |
241 | Adds a list of boxsets to series. Takes ownership of the \a sets. |
|
185 | Adds a list of boxsets to series. Takes ownership of the \a sets. | |
242 | Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series, |
|
186 | Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series, | |
243 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
187 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
244 | and function returns false. |
|
188 | and function returns false. | |
245 | */ |
|
189 | */ | |
246 | bool QBoxPlotSeries::append(QList<QBoxSet *> sets) |
|
190 | bool QBoxPlotSeries::append(QList<QBoxSet *> sets) | |
247 | { |
|
191 | { | |
248 | Q_D(QBoxPlotSeries); |
|
192 | Q_D(QBoxPlotSeries); | |
249 | bool success = d->append(sets); |
|
193 | bool success = d->append(sets); | |
250 | if (success) { |
|
194 | if (success) { | |
251 | emit boxsetsAdded(sets); |
|
195 | emit boxsetsAdded(sets); | |
252 | emit countChanged(); |
|
196 | emit countChanged(); | |
253 | } |
|
197 | } | |
254 | return success; |
|
198 | return success; | |
255 | } |
|
199 | } | |
256 |
|
200 | |||
257 | /*! |
|
201 | /*! | |
258 | Insert a box-and-whiskers set to the series at \a index postion. Takes ownership of the \a set. If the set is null or |
|
202 | Insert a box-and-whiskers set to the series at \a index postion. Takes ownership of the \a set. If the set is null or | |
259 | is already in series, it won't be appended. Returns true, if inserting succeeded. |
|
203 | is already in series, it won't be appended. Returns true, if inserting succeeded. | |
260 |
|
204 | |||
261 | */ |
|
205 | */ | |
262 | bool QBoxPlotSeries::insert(int index, QBoxSet *set) |
|
206 | bool QBoxPlotSeries::insert(int index, QBoxSet *set) | |
263 | { |
|
207 | { | |
264 | Q_D(QBoxPlotSeries); |
|
208 | Q_D(QBoxPlotSeries); | |
265 | bool success = d->insert(index, set); |
|
209 | bool success = d->insert(index, set); | |
266 | if (success) { |
|
210 | if (success) { | |
267 | QList<QBoxSet *> sets; |
|
211 | QList<QBoxSet *> sets; | |
268 | sets.append(set); |
|
212 | sets.append(set); | |
269 | emit boxsetsAdded(sets); |
|
213 | emit boxsetsAdded(sets); | |
270 | emit countChanged(); |
|
214 | emit countChanged(); | |
271 | } |
|
215 | } | |
272 | return success; |
|
216 | return success; | |
273 | } |
|
217 | } | |
274 |
|
218 | |||
275 | /*! |
|
219 | /*! | |
276 | Removes all boxsets from the series. Deletes removed sets. |
|
220 | Removes all boxsets from the series. Deletes removed sets. | |
277 | */ |
|
221 | */ | |
278 | void QBoxPlotSeries::clear() |
|
222 | void QBoxPlotSeries::clear() | |
279 | { |
|
223 | { | |
280 | Q_D(QBoxPlotSeries); |
|
224 | Q_D(QBoxPlotSeries); | |
281 | QList<QBoxSet *> sets = boxSets(); |
|
225 | QList<QBoxSet *> sets = boxSets(); | |
282 | bool success = d->remove(sets); |
|
226 | bool success = d->remove(sets); | |
283 | if (success) { |
|
227 | if (success) { | |
284 | emit boxsetsRemoved(sets); |
|
228 | emit boxsetsRemoved(sets); | |
285 | emit countChanged(); |
|
229 | emit countChanged(); | |
286 | foreach (QBoxSet *set, sets) |
|
230 | foreach (QBoxSet *set, sets) | |
287 | delete set; |
|
231 | delete set; | |
288 | } |
|
232 | } | |
289 | } |
|
233 | } | |
290 |
|
234 | |||
291 | /*! |
|
235 | /*! | |
292 | Returns number of sets in series. |
|
236 | Returns number of sets in series. | |
293 | */ |
|
237 | */ | |
294 | int QBoxPlotSeries::count() const |
|
238 | int QBoxPlotSeries::count() const | |
295 | { |
|
239 | { | |
296 | Q_D(const QBoxPlotSeries); |
|
240 | Q_D(const QBoxPlotSeries); | |
297 | return d->m_boxSets.count(); |
|
241 | return d->m_boxSets.count(); | |
298 | } |
|
242 | } | |
299 |
|
243 | |||
300 | /*! |
|
244 | /*! | |
301 | Returns a list of sets in series. Keeps ownership of sets. |
|
245 | Returns a list of sets in series. Keeps ownership of sets. | |
302 | */ |
|
246 | */ | |
303 | QList<QBoxSet *> QBoxPlotSeries::boxSets() const |
|
247 | QList<QBoxSet *> QBoxPlotSeries::boxSets() const | |
304 | { |
|
248 | { | |
305 | Q_D(const QBoxPlotSeries); |
|
249 | Q_D(const QBoxPlotSeries); | |
306 | return d->m_boxSets; |
|
250 | return d->m_boxSets; | |
307 | } |
|
251 | } | |
308 |
|
252 | |||
309 | /* |
|
253 | /* | |
310 | Returns QAbstractSeries::SeriesTypeBoxPlot. |
|
254 | Returns QAbstractSeries::SeriesTypeBoxPlot. | |
311 | */ |
|
255 | */ | |
312 | QAbstractSeries::SeriesType QBoxPlotSeries::type() const |
|
256 | QAbstractSeries::SeriesType QBoxPlotSeries::type() const | |
313 | { |
|
257 | { | |
314 | return QAbstractSeries::SeriesTypeBoxPlot; |
|
258 | return QAbstractSeries::SeriesTypeBoxPlot; | |
315 | } |
|
259 | } | |
316 |
|
260 | |||
317 | /*! |
|
261 | void QBoxPlotSeries::setBoxOutlineVisible(bool visible) | |
318 | Sets brush for the series. Box-and-whiskers items are drawn using \a brush |
|
262 | { | |
319 | */ |
|
263 | Q_D(QBoxPlotSeries); | |
|
264 | ||||
|
265 | if (d->m_boxOutlineVisible != visible) { | |||
|
266 | d->m_boxOutlineVisible = visible; | |||
|
267 | emit d->updated(); | |||
|
268 | emit boxOutlineVisibilityChanged(); | |||
|
269 | } | |||
|
270 | } | |||
|
271 | ||||
|
272 | bool QBoxPlotSeries::boxOutlineVisible() | |||
|
273 | { | |||
|
274 | Q_D(QBoxPlotSeries); | |||
|
275 | ||||
|
276 | return d->m_boxOutlineVisible; | |||
|
277 | } | |||
|
278 | ||||
320 | void QBoxPlotSeries::setBrush(const QBrush &brush) |
|
279 | void QBoxPlotSeries::setBrush(const QBrush &brush) | |
321 | { |
|
280 | { | |
322 | Q_D(QBoxPlotSeries); |
|
281 | Q_D(QBoxPlotSeries); | |
323 |
|
282 | |||
324 | if (d->m_brush != brush) { |
|
283 | if (d->m_brush != brush) { | |
325 | d->m_brush = brush; |
|
284 | d->m_brush = brush; | |
326 | emit d->updated(); |
|
285 | emit d->updated(); | |
|
286 | emit brushChanged(); | |||
327 | } |
|
287 | } | |
328 | } |
|
288 | } | |
329 |
|
289 | |||
330 | /*! |
|
|||
331 | Returns brush of the series. |
|
|||
332 | */ |
|
|||
333 | QBrush QBoxPlotSeries::brush() const |
|
290 | QBrush QBoxPlotSeries::brush() const | |
334 | { |
|
291 | { | |
335 | Q_D(const QBoxPlotSeries); |
|
292 | Q_D(const QBoxPlotSeries); | |
336 |
|
293 | |||
337 | return d->m_brush; |
|
294 | return d->m_brush; | |
338 | } |
|
295 | } | |
339 |
|
296 | |||
340 | /*! |
|
|||
341 | Sets pen for the series. Box-and-whiskers items are drawn using \a pen |
|
|||
342 | */ |
|
|||
343 | void QBoxPlotSeries::setPen(const QPen &pen) |
|
297 | void QBoxPlotSeries::setPen(const QPen &pen) | |
344 | { |
|
298 | { | |
345 | Q_D(QBoxPlotSeries); |
|
299 | Q_D(QBoxPlotSeries); | |
346 |
|
300 | |||
347 | if (d->m_pen != pen) { |
|
301 | if (d->m_pen != pen) { | |
348 | d->m_pen = pen; |
|
302 | d->m_pen = pen; | |
349 | emit d->updated(); |
|
303 | emit d->updated(); | |
|
304 | emit penChanged(); | |||
350 | } |
|
305 | } | |
351 | } |
|
306 | } | |
352 |
|
307 | |||
353 | /*! |
|
|||
354 | Returns the pen of this series. |
|
|||
355 | */ |
|
|||
356 | QPen QBoxPlotSeries::pen() const |
|
308 | QPen QBoxPlotSeries::pen() const | |
357 | { |
|
309 | { | |
358 | Q_D(const QBoxPlotSeries); |
|
310 | Q_D(const QBoxPlotSeries); | |
359 |
|
311 | |||
360 | return d->m_pen; |
|
312 | return d->m_pen; | |
361 | } |
|
313 | } | |
362 |
|
314 | |||
363 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
315 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
364 |
|
316 | |||
365 | QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q) |
|
317 | QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q) | |
366 | : QAbstractSeriesPrivate(q), |
|
318 | : QAbstractSeriesPrivate(q), | |
367 | m_pen(QChartPrivate::defaultPen()), |
|
319 | m_pen(QChartPrivate::defaultPen()), | |
368 | m_brush(QChartPrivate::defaultBrush()) |
|
320 | m_brush(QChartPrivate::defaultBrush()), | |
|
321 | m_boxOutlineVisible(true) | |||
369 | { |
|
322 | { | |
370 | } |
|
323 | } | |
371 |
|
324 | |||
372 | QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate() |
|
325 | QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate() | |
373 | { |
|
326 | { | |
374 | disconnect(this, 0, 0, 0); |
|
327 | disconnect(this, 0, 0, 0); | |
375 | } |
|
328 | } | |
376 |
|
329 | |||
377 | void QBoxPlotSeriesPrivate::initializeDomain() |
|
330 | void QBoxPlotSeriesPrivate::initializeDomain() | |
378 | { |
|
331 | { | |
379 | qreal minX(domain()->minX()); |
|
332 | qreal minX(domain()->minX()); | |
380 | qreal minY(domain()->minY()); |
|
333 | qreal minY(domain()->minY()); | |
381 | qreal maxX(domain()->maxX()); |
|
334 | qreal maxX(domain()->maxX()); | |
382 | qreal maxY(domain()->maxY()); |
|
335 | qreal maxY(domain()->maxY()); | |
383 |
|
336 | |||
384 | qreal x = m_boxSets.count(); |
|
337 | qreal x = m_boxSets.count(); | |
385 | minX = qMin(minX, qreal(-0.5)); |
|
338 | minX = qMin(minX, qreal(-0.5)); | |
386 | minY = qMin(minY, min()); |
|
339 | minY = qMin(minY, min()); | |
387 | maxX = qMax(maxX, x - qreal(0.5)); |
|
340 | maxX = qMax(maxX, x - qreal(0.5)); | |
388 | maxY = qMax(maxY, max()); |
|
341 | maxY = qMax(maxY, max()); | |
389 |
|
342 | |||
390 | domain()->setRange(minX, maxX, minY, maxY); |
|
343 | domain()->setRange(minX, maxX, minY, maxY); | |
391 | } |
|
344 | } | |
392 |
|
345 | |||
393 | void QBoxPlotSeriesPrivate::initializeAxes() |
|
346 | void QBoxPlotSeriesPrivate::initializeAxes() | |
394 | { |
|
347 | { | |
395 | foreach (QAbstractAxis* axis, m_axes) { |
|
348 | foreach (QAbstractAxis* axis, m_axes) { | |
396 | if (axis->type() == QAbstractAxis::AxisTypeBarCategory) { |
|
349 | if (axis->type() == QAbstractAxis::AxisTypeBarCategory) { | |
397 | if (axis->orientation() == Qt::Horizontal) |
|
350 | if (axis->orientation() == Qt::Horizontal) | |
398 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); |
|
351 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); | |
399 | } |
|
352 | } | |
400 | } |
|
353 | } | |
401 | } |
|
354 | } | |
402 |
|
355 | |||
403 | QAbstractAxis::AxisType QBoxPlotSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
356 | QAbstractAxis::AxisType QBoxPlotSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
404 | { |
|
357 | { | |
405 | if (orientation == Qt::Horizontal) |
|
358 | if (orientation == Qt::Horizontal) | |
406 | return QAbstractAxis::AxisTypeBarCategory; |
|
359 | return QAbstractAxis::AxisTypeBarCategory; | |
407 |
|
360 | |||
408 | return QAbstractAxis::AxisTypeValue; |
|
361 | return QAbstractAxis::AxisTypeValue; | |
409 | } |
|
362 | } | |
410 |
|
363 | |||
411 | QAbstractAxis* QBoxPlotSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
364 | QAbstractAxis* QBoxPlotSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |
412 | { |
|
365 | { | |
413 | Q_UNUSED(orientation); |
|
366 | Q_UNUSED(orientation); | |
414 |
|
367 | |||
415 | return 0; |
|
368 | return 0; | |
416 | } |
|
369 | } | |
417 |
|
370 | |||
418 | void QBoxPlotSeriesPrivate::populateCategories(QBarCategoryAxis *axis) |
|
371 | void QBoxPlotSeriesPrivate::populateCategories(QBarCategoryAxis *axis) | |
419 | { |
|
372 | { | |
420 | QStringList categories; |
|
373 | QStringList categories; | |
421 | if (axis->categories().isEmpty()) { |
|
374 | if (axis->categories().isEmpty()) { | |
422 | for (int i(1); i < m_boxSets.count() + 1; i++) { |
|
375 | for (int i(1); i < m_boxSets.count() + 1; i++) { | |
423 | QBoxSet *set = m_boxSets.at(i - 1); |
|
376 | QBoxSet *set = m_boxSets.at(i - 1); | |
424 | if (set->label().isEmpty()) |
|
377 | if (set->label().isEmpty()) | |
425 | categories << QString::number(i); |
|
378 | categories << QString::number(i); | |
426 | else |
|
379 | else | |
427 | categories << set->label(); |
|
380 | categories << set->label(); | |
428 | } |
|
381 | } | |
429 | axis->append(categories); |
|
382 | axis->append(categories); | |
430 | } |
|
383 | } | |
431 | } |
|
384 | } | |
432 |
|
385 | |||
433 | void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem *parent) |
|
386 | void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem *parent) | |
434 | { |
|
387 | { | |
435 | Q_Q(QBoxPlotSeries); |
|
388 | Q_Q(QBoxPlotSeries); | |
436 |
|
389 | |||
437 | BoxPlotChartItem *boxPlot = new BoxPlotChartItem(q, parent); |
|
390 | BoxPlotChartItem *boxPlot = new BoxPlotChartItem(q, parent); | |
438 | m_item.reset(boxPlot); |
|
391 | m_item.reset(boxPlot); | |
439 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
392 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
440 |
|
393 | |||
441 | if (m_chart) { |
|
394 | if (m_chart) { | |
442 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesChange(QAbstractSeries*)) ); |
|
395 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesChange(QAbstractSeries*)) ); | |
443 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) ); |
|
396 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) ); | |
444 |
|
397 | |||
445 | QList<QAbstractSeries *> serieses = m_chart->series(); |
|
398 | QList<QAbstractSeries *> serieses = m_chart->series(); | |
446 |
|
399 | |||
447 | // Tries to find this series from the Chart's list of series and deduce the index |
|
400 | // Tries to find this series from the Chart's list of series and deduce the index | |
448 | int index = 0; |
|
401 | int index = 0; | |
449 | foreach (QAbstractSeries *s, serieses) { |
|
402 | foreach (QAbstractSeries *s, serieses) { | |
450 | if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) { |
|
403 | if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) { | |
451 | if (q == static_cast<QBoxPlotSeries *>(s)) { |
|
404 | if (q == static_cast<QBoxPlotSeries *>(s)) { | |
452 | boxPlot->m_seriesIndex = index; |
|
405 | boxPlot->m_seriesIndex = index; | |
453 | m_index = index; |
|
406 | m_index = index; | |
454 | } |
|
407 | } | |
455 | index++; |
|
408 | index++; | |
456 | } |
|
409 | } | |
457 | } |
|
410 | } | |
458 | boxPlot->m_seriesCount = index; |
|
411 | boxPlot->m_seriesCount = index; | |
459 | } |
|
412 | } | |
460 |
|
413 | |||
461 | // Make BoxPlotChartItem to instantiate box & whisker items |
|
414 | // Make BoxPlotChartItem to instantiate box & whisker items | |
462 | boxPlot->handleDataStructureChanged(); |
|
415 | boxPlot->handleDataStructureChanged(); | |
463 | } |
|
416 | } | |
464 |
|
417 | |||
465 | void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
418 | void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |
466 | { |
|
419 | { | |
467 | Q_Q(QBoxPlotSeries); |
|
420 | Q_Q(QBoxPlotSeries); | |
468 |
|
421 | |||
469 | const QList<QGradient> gradients = theme->seriesGradients(); |
|
422 | const QList<QGradient> gradients = theme->seriesGradients(); | |
470 |
|
423 | |||
471 | if (forced || QChartPrivate::defaultBrush() == m_brush) { |
|
424 | if (forced || QChartPrivate::defaultBrush() == m_brush) { | |
472 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.5); |
|
425 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.5); | |
473 | q->setBrush(brushColor); |
|
426 | q->setBrush(brushColor); | |
474 | } |
|
427 | } | |
475 |
|
428 | |||
476 | if (forced || QChartPrivate::defaultPen() == m_pen) { |
|
429 | if (forced || QChartPrivate::defaultPen() == m_pen) { | |
477 | QPen pen = theme->outlinePen(); |
|
430 | QPen pen = theme->outlinePen(); | |
478 | pen.setCosmetic(true); |
|
431 | pen.setCosmetic(true); | |
479 | q->setPen(pen); |
|
432 | q->setPen(pen); | |
480 | } |
|
433 | } | |
481 | } |
|
434 | } | |
482 |
|
435 | |||
483 | void QBoxPlotSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
436 | void QBoxPlotSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) | |
484 | { |
|
437 | { | |
485 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); |
|
438 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); | |
486 | Q_ASSERT(item); |
|
439 | Q_ASSERT(item); | |
487 | if (item->animation()) |
|
440 | if (item->animation()) | |
488 | item->animation()->stopAndDestroyLater(); |
|
441 | item->animation()->stopAndDestroyLater(); | |
489 |
|
442 | |||
490 | if (options.testFlag(QChart::SeriesAnimations)) |
|
443 | if (options.testFlag(QChart::SeriesAnimations)) | |
491 | m_animation = new BoxPlotAnimation(item); |
|
444 | m_animation = new BoxPlotAnimation(item); | |
492 | else |
|
445 | else | |
493 | m_animation = 0; |
|
446 | m_animation = 0; | |
494 | item->setAnimation(m_animation); |
|
447 | item->setAnimation(m_animation); | |
495 |
|
448 | |||
496 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
449 | QAbstractSeriesPrivate::initializeAnimations(options); | |
497 | } |
|
450 | } | |
498 |
|
451 | |||
499 | QList<QLegendMarker*> QBoxPlotSeriesPrivate::createLegendMarkers(QLegend *legend) |
|
452 | QList<QLegendMarker*> QBoxPlotSeriesPrivate::createLegendMarkers(QLegend *legend) | |
500 | { |
|
453 | { | |
501 | Q_Q(QBoxPlotSeries); |
|
454 | Q_Q(QBoxPlotSeries); | |
502 | QList<QLegendMarker *> list; |
|
455 | QList<QLegendMarker *> list; | |
503 | return list << new QBoxPlotLegendMarker(q, legend); |
|
456 | return list << new QBoxPlotLegendMarker(q, legend); | |
504 | } |
|
457 | } | |
505 |
|
458 | |||
506 | void QBoxPlotSeriesPrivate::handleSeriesRemove(QAbstractSeries *series) |
|
459 | void QBoxPlotSeriesPrivate::handleSeriesRemove(QAbstractSeries *series) | |
507 | { |
|
460 | { | |
508 | Q_Q(QBoxPlotSeries); |
|
461 | Q_Q(QBoxPlotSeries); | |
509 |
|
462 | |||
510 | QBoxPlotSeries *removedSeries = static_cast<QBoxPlotSeries *>(series); |
|
463 | QBoxPlotSeries *removedSeries = static_cast<QBoxPlotSeries *>(series); | |
511 |
|
464 | |||
512 | if (q == removedSeries && m_animation) { |
|
465 | if (q == removedSeries && m_animation) { | |
513 | m_animation->stopAll(); |
|
466 | m_animation->stopAll(); | |
514 | QObject::disconnect(m_chart->d_ptr->m_dataset, 0, removedSeries->d_func(), 0); |
|
467 | QObject::disconnect(m_chart->d_ptr->m_dataset, 0, removedSeries->d_func(), 0); | |
515 | } |
|
468 | } | |
516 |
|
469 | |||
517 | // Test if series removed is me, then don't do anything |
|
470 | // Test if series removed is me, then don't do anything | |
518 | if (q != removedSeries) { |
|
471 | if (q != removedSeries) { | |
519 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); |
|
472 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); | |
520 | if (item) { |
|
473 | if (item) { | |
521 | item->m_seriesCount = item->m_seriesCount - 1; |
|
474 | item->m_seriesCount = item->m_seriesCount - 1; | |
522 | if (removedSeries->d_func()->m_index < m_index) { |
|
475 | if (removedSeries->d_func()->m_index < m_index) { | |
523 | m_index--; |
|
476 | m_index--; | |
524 | item->m_seriesIndex = m_index; |
|
477 | item->m_seriesIndex = m_index; | |
525 | } |
|
478 | } | |
526 |
|
479 | |||
527 | item->handleDataStructureChanged(); |
|
480 | item->handleDataStructureChanged(); | |
528 | } |
|
481 | } | |
529 | } |
|
482 | } | |
530 | } |
|
483 | } | |
531 |
|
484 | |||
532 | void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series) |
|
485 | void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series) | |
533 | { |
|
486 | { | |
534 | Q_UNUSED(series); |
|
487 | Q_UNUSED(series); | |
535 |
|
488 | |||
536 | Q_Q(QBoxPlotSeries); |
|
489 | Q_Q(QBoxPlotSeries); | |
537 |
|
490 | |||
538 | BoxPlotChartItem *boxPlot = static_cast<BoxPlotChartItem *>(m_item.data()); |
|
491 | BoxPlotChartItem *boxPlot = static_cast<BoxPlotChartItem *>(m_item.data()); | |
539 |
|
492 | |||
540 | if (m_chart) { |
|
493 | if (m_chart) { | |
541 | QList<QAbstractSeries *> serieses = m_chart->series(); |
|
494 | QList<QAbstractSeries *> serieses = m_chart->series(); | |
542 |
|
495 | |||
543 | // Tries to find this series from the Chart's list of series and deduce the index |
|
496 | // Tries to find this series from the Chart's list of series and deduce the index | |
544 | int index = 0; |
|
497 | int index = 0; | |
545 | foreach (QAbstractSeries *s, serieses) { |
|
498 | foreach (QAbstractSeries *s, serieses) { | |
546 | if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) { |
|
499 | if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) { | |
547 | if (q == static_cast<QBoxPlotSeries *>(s)) { |
|
500 | if (q == static_cast<QBoxPlotSeries *>(s)) { | |
548 | boxPlot->m_seriesIndex = index; |
|
501 | boxPlot->m_seriesIndex = index; | |
549 | m_index = index; |
|
502 | m_index = index; | |
550 | } |
|
503 | } | |
551 | index++; |
|
504 | index++; | |
552 | } |
|
505 | } | |
553 | } |
|
506 | } | |
554 | boxPlot->m_seriesCount = index; |
|
507 | boxPlot->m_seriesCount = index; | |
555 | } |
|
508 | } | |
556 |
|
509 | |||
557 | boxPlot->handleDataStructureChanged(); |
|
510 | boxPlot->handleDataStructureChanged(); | |
558 | } |
|
511 | } | |
559 |
|
512 | |||
560 | bool QBoxPlotSeriesPrivate::append(QBoxSet *set) |
|
513 | bool QBoxPlotSeriesPrivate::append(QBoxSet *set) | |
561 | { |
|
514 | { | |
562 | if (m_boxSets.contains(set) || (set == 0) || set->d_ptr->m_series) |
|
515 | if (m_boxSets.contains(set) || (set == 0) || set->d_ptr->m_series) | |
563 | return false; // Fail if set is already in list or set is null. |
|
516 | return false; // Fail if set is already in list or set is null. | |
564 |
|
517 | |||
565 | m_boxSets.append(set); |
|
518 | m_boxSets.append(set); | |
566 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
519 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
567 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); |
|
520 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); | |
568 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); |
|
521 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); | |
569 | set->d_ptr->m_series = this; |
|
522 | set->d_ptr->m_series = this; | |
570 |
|
523 | |||
571 | emit restructuredBoxes(); // this notifies boxplotchartitem |
|
524 | emit restructuredBoxes(); // this notifies boxplotchartitem | |
572 | return true; |
|
525 | return true; | |
573 | } |
|
526 | } | |
574 |
|
527 | |||
575 | bool QBoxPlotSeriesPrivate::remove(QBoxSet *set) |
|
528 | bool QBoxPlotSeriesPrivate::remove(QBoxSet *set) | |
576 | { |
|
529 | { | |
577 | if (!m_boxSets.contains(set)) |
|
530 | if (!m_boxSets.contains(set)) | |
578 | return false; // Fail if set is not in list |
|
531 | return false; // Fail if set is not in list | |
579 |
|
532 | |||
580 | set->d_ptr->m_series = 0; |
|
533 | set->d_ptr->m_series = 0; | |
581 | m_boxSets.removeOne(set); |
|
534 | m_boxSets.removeOne(set); | |
582 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
535 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
583 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); |
|
536 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); | |
584 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); |
|
537 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); | |
585 |
|
538 | |||
586 | emit restructuredBoxes(); // this notifies boxplotchartitem |
|
539 | emit restructuredBoxes(); // this notifies boxplotchartitem | |
587 | return true; |
|
540 | return true; | |
588 | } |
|
541 | } | |
589 |
|
542 | |||
590 | bool QBoxPlotSeriesPrivate::append(QList<QBoxSet *> sets) |
|
543 | bool QBoxPlotSeriesPrivate::append(QList<QBoxSet *> sets) | |
591 | { |
|
544 | { | |
592 | foreach (QBoxSet *set, sets) { |
|
545 | foreach (QBoxSet *set, sets) { | |
593 | if ((set == 0) || m_boxSets.contains(set) || set->d_ptr->m_series) |
|
546 | if ((set == 0) || m_boxSets.contains(set) || set->d_ptr->m_series) | |
594 | return false; // Fail if any of the sets is null or is already appended. |
|
547 | return false; // Fail if any of the sets is null or is already appended. | |
595 | if (sets.count(set) != 1) |
|
548 | if (sets.count(set) != 1) | |
596 | return false; // Also fail if same set is more than once in given list. |
|
549 | return false; // Also fail if same set is more than once in given list. | |
597 | } |
|
550 | } | |
598 |
|
551 | |||
599 | foreach (QBoxSet *set, sets) { |
|
552 | foreach (QBoxSet *set, sets) { | |
600 | m_boxSets.append(set); |
|
553 | m_boxSets.append(set); | |
601 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
554 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
602 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); |
|
555 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); | |
603 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); |
|
556 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); | |
604 | set->d_ptr->m_series = this; |
|
557 | set->d_ptr->m_series = this; | |
605 | } |
|
558 | } | |
606 |
|
559 | |||
607 | emit restructuredBoxes(); // this notifies boxplotchartitem |
|
560 | emit restructuredBoxes(); // this notifies boxplotchartitem | |
608 | return true; |
|
561 | return true; | |
609 | } |
|
562 | } | |
610 |
|
563 | |||
611 | bool QBoxPlotSeriesPrivate::remove(QList<QBoxSet *> sets) |
|
564 | bool QBoxPlotSeriesPrivate::remove(QList<QBoxSet *> sets) | |
612 | { |
|
565 | { | |
613 | if (sets.count() == 0) |
|
566 | if (sets.count() == 0) | |
614 | return false; |
|
567 | return false; | |
615 |
|
568 | |||
616 | foreach (QBoxSet *set, sets) { |
|
569 | foreach (QBoxSet *set, sets) { | |
617 | if ((set == 0) || (!m_boxSets.contains(set))) |
|
570 | if ((set == 0) || (!m_boxSets.contains(set))) | |
618 | return false; // Fail if any of the sets is null or is not in series |
|
571 | return false; // Fail if any of the sets is null or is not in series | |
619 | if (sets.count(set) != 1) |
|
572 | if (sets.count(set) != 1) | |
620 | return false; // Also fail if same set is more than once in given list. |
|
573 | return false; // Also fail if same set is more than once in given list. | |
621 | } |
|
574 | } | |
622 |
|
575 | |||
623 | foreach (QBoxSet *set, sets) { |
|
576 | foreach (QBoxSet *set, sets) { | |
624 | set->d_ptr->m_series = 0; |
|
577 | set->d_ptr->m_series = 0; | |
625 | m_boxSets.removeOne(set); |
|
578 | m_boxSets.removeOne(set); | |
626 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
579 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
627 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); |
|
580 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); | |
628 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); |
|
581 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); | |
629 | } |
|
582 | } | |
630 |
|
583 | |||
631 | emit restructuredBoxes(); // this notifies boxplotchartitem |
|
584 | emit restructuredBoxes(); // this notifies boxplotchartitem | |
632 |
|
585 | |||
633 | return true; |
|
586 | return true; | |
634 | } |
|
587 | } | |
635 |
|
588 | |||
636 | bool QBoxPlotSeriesPrivate::insert(int index, QBoxSet *set) |
|
589 | bool QBoxPlotSeriesPrivate::insert(int index, QBoxSet *set) | |
637 | { |
|
590 | { | |
638 | if ((m_boxSets.contains(set)) || (set == 0) || set->d_ptr->m_series) |
|
591 | if ((m_boxSets.contains(set)) || (set == 0) || set->d_ptr->m_series) | |
639 | return false; // Fail if set is already in list or set is null. |
|
592 | return false; // Fail if set is already in list or set is null. | |
640 |
|
593 | |||
641 | m_boxSets.insert(index, set); |
|
594 | m_boxSets.insert(index, set); | |
642 | set->d_ptr->m_series = this; |
|
595 | set->d_ptr->m_series = this; | |
643 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
596 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
644 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); |
|
597 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); | |
645 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); |
|
598 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); | |
646 |
|
599 | |||
647 | emit restructuredBoxes(); // this notifies boxplotchartitem |
|
600 | emit restructuredBoxes(); // this notifies boxplotchartitem | |
648 | return true; |
|
601 | return true; | |
649 | } |
|
602 | } | |
650 |
|
603 | |||
651 | QBoxSet *QBoxPlotSeriesPrivate::boxSetAt(int index) |
|
604 | QBoxSet *QBoxPlotSeriesPrivate::boxSetAt(int index) | |
652 | { |
|
605 | { | |
653 | return m_boxSets.at(index); |
|
606 | return m_boxSets.at(index); | |
654 | } |
|
607 | } | |
655 |
|
608 | |||
656 | qreal QBoxPlotSeriesPrivate::min() |
|
609 | qreal QBoxPlotSeriesPrivate::min() | |
657 | { |
|
610 | { | |
658 | if (m_boxSets.count() <= 0) |
|
611 | if (m_boxSets.count() <= 0) | |
659 | return 0; |
|
612 | return 0; | |
660 |
|
613 | |||
661 | qreal min = m_boxSets.at(0)->at(0); |
|
614 | qreal min = m_boxSets.at(0)->at(0); | |
662 |
|
615 | |||
663 | foreach (QBoxSet *set, m_boxSets) { |
|
616 | foreach (QBoxSet *set, m_boxSets) { | |
664 | for (int i = 0; i < 5; i++) { |
|
617 | for (int i = 0; i < 5; i++) { | |
665 | if (set->at(i) < min) |
|
618 | if (set->at(i) < min) | |
666 | min = set->at(i); |
|
619 | min = set->at(i); | |
667 | } |
|
620 | } | |
668 | } |
|
621 | } | |
669 |
|
622 | |||
670 | return min; |
|
623 | return min; | |
671 | } |
|
624 | } | |
672 |
|
625 | |||
673 | qreal QBoxPlotSeriesPrivate::max() |
|
626 | qreal QBoxPlotSeriesPrivate::max() | |
674 | { |
|
627 | { | |
675 | if (m_boxSets.count() <= 0) |
|
628 | if (m_boxSets.count() <= 0) | |
676 | return 0; |
|
629 | return 0; | |
677 |
|
630 | |||
678 | qreal max = m_boxSets.at(0)->at(0); |
|
631 | qreal max = m_boxSets.at(0)->at(0); | |
679 |
|
632 | |||
680 | foreach (QBoxSet *set, m_boxSets) { |
|
633 | foreach (QBoxSet *set, m_boxSets) { | |
681 | for (int i = 0; i < 5; i++) { |
|
634 | for (int i = 0; i < 5; i++) { | |
682 | if (set->at(i) > max) |
|
635 | if (set->at(i) > max) | |
683 | max = set->at(i); |
|
636 | max = set->at(i); | |
684 | } |
|
637 | } | |
685 | } |
|
638 | } | |
686 |
|
639 | |||
687 | return max; |
|
640 | return max; | |
688 | } |
|
641 | } | |
689 |
|
642 | |||
690 | #include "moc_qboxplotseries.cpp" |
|
643 | #include "moc_qboxplotseries.cpp" | |
691 | #include "moc_qboxplotseries_p.cpp" |
|
644 | #include "moc_qboxplotseries_p.cpp" | |
692 |
|
645 | |||
693 | QTCOMMERCIALCHART_END_NAMESPACE |
|
646 | QTCOMMERCIALCHART_END_NAMESPACE | |
694 |
|
647 |
@@ -1,72 +1,80 | |||||
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 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 <qboxset.h> |
|
25 | #include <qboxset.h> | |
26 | #include <qabstractseries.h> |
|
26 | #include <qabstractseries.h> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | class QBoxPlotSeriesPrivate; |
|
30 | class QBoxPlotSeriesPrivate; | |
31 |
|
31 | |||
32 | class QTCOMMERCIALCHART_EXPORT QBoxPlotSeries : public QAbstractSeries |
|
32 | class QTCOMMERCIALCHART_EXPORT QBoxPlotSeries : public QAbstractSeries | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
|
35 | Q_PROPERTY(bool boxOutlineVisible READ boxOutlineVisible WRITE setBoxOutlineVisible NOTIFY boxOutlineVisibilityChanged) | |||
|
36 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) | |||
|
37 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) | |||
35 | public: |
|
38 | public: | |
36 | explicit QBoxPlotSeries(QObject *parent = 0); |
|
39 | explicit QBoxPlotSeries(QObject *parent = 0); | |
37 | ~QBoxPlotSeries(); |
|
40 | ~QBoxPlotSeries(); | |
38 |
|
41 | |||
39 | bool append(QBoxSet *box); |
|
42 | bool append(QBoxSet *box); | |
40 | bool remove(QBoxSet *box); |
|
43 | bool remove(QBoxSet *box); | |
41 | bool take(QBoxSet *box); |
|
44 | bool take(QBoxSet *box); | |
42 | bool append(QList<QBoxSet *> boxes); |
|
45 | bool append(QList<QBoxSet *> boxes); | |
43 | bool insert(int index, QBoxSet *box); |
|
46 | bool insert(int index, QBoxSet *box); | |
44 | int count() const; |
|
47 | int count() const; | |
45 | QList<QBoxSet *> boxSets() const; |
|
48 | QList<QBoxSet *> boxSets() const; | |
46 | void clear(); |
|
49 | void clear(); | |
47 |
|
50 | |||
48 | QAbstractSeries::SeriesType type() const; |
|
51 | QAbstractSeries::SeriesType type() const; | |
49 |
|
52 | |||
|
53 | void setBoxOutlineVisible(bool visible); | |||
|
54 | bool boxOutlineVisible(); | |||
50 | void setBrush(const QBrush &brush); |
|
55 | void setBrush(const QBrush &brush); | |
51 | QBrush brush() const; |
|
56 | QBrush brush() const; | |
52 | void setPen(const QPen &pen); |
|
57 | void setPen(const QPen &pen); | |
53 | QPen pen() const; |
|
58 | QPen pen() const; | |
54 |
|
59 | |||
55 | Q_SIGNALS: |
|
60 | Q_SIGNALS: | |
56 | void clicked(QBoxSet *boxset); |
|
61 | void clicked(QBoxSet *boxset); | |
57 | void hovered(bool status, QBoxSet *boxset); |
|
62 | void hovered(bool status, QBoxSet *boxset); | |
58 | void countChanged(); |
|
63 | void countChanged(); | |
|
64 | void penChanged(); | |||
|
65 | void brushChanged(); | |||
|
66 | void boxOutlineVisibilityChanged(); | |||
59 |
|
67 | |||
60 | void boxsetsAdded(QList<QBoxSet *> sets); |
|
68 | void boxsetsAdded(QList<QBoxSet *> sets); | |
61 | void boxsetsRemoved(QList<QBoxSet *> sets); |
|
69 | void boxsetsRemoved(QList<QBoxSet *> sets); | |
62 |
|
70 | |||
63 | private: |
|
71 | private: | |
64 | Q_DECLARE_PRIVATE(QBoxPlotSeries) |
|
72 | Q_DECLARE_PRIVATE(QBoxPlotSeries) | |
65 | Q_DISABLE_COPY(QBoxPlotSeries) |
|
73 | Q_DISABLE_COPY(QBoxPlotSeries) | |
66 | friend class BoxPlotChartItem; |
|
74 | friend class BoxPlotChartItem; | |
67 | friend class QBoxPlotLegendMarkerPrivate; |
|
75 | friend class QBoxPlotLegendMarkerPrivate; | |
68 | }; |
|
76 | }; | |
69 |
|
77 | |||
70 | QTCOMMERCIALCHART_END_NAMESPACE |
|
78 | QTCOMMERCIALCHART_END_NAMESPACE | |
71 |
|
79 | |||
72 | #endif // QBOXPLOTSERIES_H |
|
80 | #endif // QBOXPLOTSERIES_H |
@@ -1,98 +1,99 | |||||
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 | // 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 BoxPlotAnimation; |
|
40 | class BoxPlotAnimation; | |
41 |
|
41 | |||
42 | class QBoxPlotSeriesPrivate : public QAbstractSeriesPrivate |
|
42 | class QBoxPlotSeriesPrivate : public QAbstractSeriesPrivate | |
43 | { |
|
43 | { | |
44 | Q_OBJECT |
|
44 | Q_OBJECT | |
45 |
|
45 | |||
46 | public: |
|
46 | public: | |
47 | QBoxPlotSeriesPrivate(QBoxPlotSeries *q); |
|
47 | QBoxPlotSeriesPrivate(QBoxPlotSeries *q); | |
48 | ~QBoxPlotSeriesPrivate(); |
|
48 | ~QBoxPlotSeriesPrivate(); | |
49 |
|
49 | |||
50 | void initializeGraphics(QGraphicsItem *parent); |
|
50 | void initializeGraphics(QGraphicsItem *parent); | |
51 | void initializeDomain(); |
|
51 | void initializeDomain(); | |
52 | void initializeAxes(); |
|
52 | void initializeAxes(); | |
53 | void initializeAnimations(QChart::AnimationOptions options); |
|
53 | void initializeAnimations(QChart::AnimationOptions options); | |
54 | void initializeTheme(int index, ChartTheme *theme, bool forced = false); |
|
54 | void initializeTheme(int index, ChartTheme *theme, bool forced = false); | |
55 |
|
55 | |||
56 | QList<QLegendMarker*> createLegendMarkers(QLegend *legend); |
|
56 | QList<QLegendMarker*> createLegendMarkers(QLegend *legend); | |
57 |
|
57 | |||
58 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
58 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; | |
59 | QAbstractAxis *createDefaultAxis(Qt::Orientation orientation) const; |
|
59 | QAbstractAxis *createDefaultAxis(Qt::Orientation orientation) const; | |
60 |
|
60 | |||
61 | bool append(QBoxSet *set); |
|
61 | bool append(QBoxSet *set); | |
62 | bool remove(QBoxSet *set); |
|
62 | bool remove(QBoxSet *set); | |
63 | bool append(QList<QBoxSet *> sets); |
|
63 | bool append(QList<QBoxSet *> sets); | |
64 | bool remove(QList<QBoxSet *> sets); |
|
64 | bool remove(QList<QBoxSet *> sets); | |
65 | bool insert(int index, QBoxSet *set); |
|
65 | bool insert(int index, QBoxSet *set); | |
66 | QBoxSet *boxSetAt(int index); |
|
66 | QBoxSet *boxSetAt(int index); | |
67 |
|
67 | |||
68 | qreal max(); |
|
68 | qreal max(); | |
69 | qreal min(); |
|
69 | qreal min(); | |
70 |
|
70 | |||
71 | private: |
|
71 | private: | |
72 | void populateCategories(QBarCategoryAxis *axis); |
|
72 | void populateCategories(QBarCategoryAxis *axis); | |
73 |
|
73 | |||
74 | Q_SIGNALS: |
|
74 | Q_SIGNALS: | |
75 | void updated(); |
|
75 | void updated(); | |
76 | void clicked(int index, QBoxSet *barset); |
|
76 | void clicked(int index, QBoxSet *barset); | |
77 | void updatedBoxes(); |
|
77 | void updatedBoxes(); | |
78 | void updatedLayout(); |
|
78 | void updatedLayout(); | |
79 | void restructuredBoxes(); |
|
79 | void restructuredBoxes(); | |
80 |
|
80 | |||
81 | private slots: |
|
81 | private slots: | |
82 | void handleSeriesChange(QAbstractSeries *series); |
|
82 | void handleSeriesChange(QAbstractSeries *series); | |
83 | void handleSeriesRemove(QAbstractSeries *series); |
|
83 | void handleSeriesRemove(QAbstractSeries *series); | |
84 |
|
84 | |||
85 | protected: |
|
85 | protected: | |
86 | QList<QBoxSet *> m_boxSets; |
|
86 | QList<QBoxSet *> m_boxSets; | |
87 | QPen m_pen; |
|
87 | QPen m_pen; | |
88 | QBrush m_brush; |
|
88 | QBrush m_brush; | |
|
89 | bool m_boxOutlineVisible; | |||
89 | int m_index; |
|
90 | int m_index; | |
90 | BoxPlotAnimation *m_animation; |
|
91 | BoxPlotAnimation *m_animation; | |
91 |
|
92 | |||
92 | private: |
|
93 | private: | |
93 | Q_DECLARE_PUBLIC(QBoxPlotSeries) |
|
94 | Q_DECLARE_PUBLIC(QBoxPlotSeries) | |
94 | }; |
|
95 | }; | |
95 |
|
96 | |||
96 | QTCOMMERCIALCHART_END_NAMESPACE |
|
97 | QTCOMMERCIALCHART_END_NAMESPACE | |
97 |
|
98 | |||
98 | #endif |
|
99 | #endif |
@@ -1,392 +1,329 | |||||
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 "qboxset.h" |
|
21 | #include "qboxset.h" | |
22 | #include "qboxset_p.h" |
|
22 | #include "qboxset_p.h" | |
23 | #include "charthelpers_p.h" |
|
23 | #include "charthelpers_p.h" | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \class QBoxSet |
|
28 | \class QBoxSet | |
29 | \brief Building block for box-and-whiskers chart |
|
29 | \brief Building block for box-and-whiskers chart | |
30 |
|
30 | |||
31 | QBoxSet represents one box-and-whiskers item. It takes five values to create a graphical representation |
|
31 | QBoxSet represents one box-and-whiskers item. It takes five values to create a graphical representation | |
32 | of range and three medians. There are two ways to give the values. The first one is with constructor |
|
32 | of range and three medians. There are two ways to give the values. The first one is with constructor | |
33 | or stream operator (<<). The values have to be given in the following order: lower extreme, |
|
33 | or stream operator (<<). The values have to be given in the following order: lower extreme, | |
34 | lower quartile, median, upper quartile and upper extreme. The Second method is to create an empty QBoxSet instance and |
|
34 | lower quartile, median, upper quartile and upper extreme. The Second method is to create an empty QBoxSet instance and | |
35 | give the values using setValue method. |
|
35 | give the values using setValue method. | |
36 |
|
36 | |||
37 | \mainclass |
|
37 | \mainclass | |
38 |
|
38 | |||
39 | \sa QBoxPlotSeries |
|
39 | \sa QBoxPlotSeries | |
40 | */ |
|
40 | */ | |
41 | /*! |
|
41 | /*! | |
42 | \qmlclass BoxSet QBoxSet |
|
|||
43 |
|
||||
44 | BoxSet represents one box-and-whiskers item. It takes five values to create a graphical representation |
|
|||
45 | of range and three medians. There are two ways to give the values. The first one is with constructor |
|
|||
46 | or with append method. In these the values have to be given in the following order: lower extreme, lower quartile, median, |
|
|||
47 | upper quartile and upper extre. The second method is to create an empty QBoxSet instance and give the values using |
|
|||
48 | value specific methods. |
|
|||
49 | \sa BoxPlotSeries |
|
|||
50 | */ |
|
|||
51 | /*! |
|
|||
52 | \enum QBoxSet::ValuePositions |
|
42 | \enum QBoxSet::ValuePositions | |
53 |
|
43 | |||
54 | \value LowerExtreme |
|
44 | \value LowerExtreme | |
55 | \value LowerQuartile |
|
45 | \value LowerQuartile | |
56 | \value Median |
|
46 | \value Median | |
57 | \value UpperQuartile |
|
47 | \value UpperQuartile | |
58 | \value UpperExtreme |
|
48 | \value UpperExtreme | |
59 | */ |
|
49 | */ | |
60 |
|
||||
61 | /*! |
|
|||
62 | \qmlproperty string BoxSet::label |
|
|||
63 | Defines the label of the boxSet. |
|
|||
64 | */ |
|
|||
65 | /*! |
|
|||
66 | \qmlproperty int BoxSet::count |
|
|||
67 | The count of values on the box-and-whiskers set |
|
|||
68 | */ |
|
|||
69 |
|
||||
70 | /*! |
|
50 | /*! | |
71 | \property QBoxSet::pen |
|
51 | \property QBoxSet::pen | |
72 | \brief Defines the pen used by the box-and-whiskers set. |
|
52 | \brief Defines the pen used by the box-and-whiskers set. | |
73 | */ |
|
53 | */ | |
74 |
|
||||
75 | /*! |
|
54 | /*! | |
76 | \property QBoxSet::brush |
|
55 | \property QBoxSet::brush | |
77 | \brief Defines the brush used by the box-and-whiskers set. |
|
56 | \brief Defines the brush used by the box-and-whiskers set. | |
78 | */ |
|
57 | */ | |
79 |
|
||||
80 | /*! |
|
|||
81 | \qmlmethod void BoxSet::setValue(int index, qreal value) |
|
|||
82 | Sets a new \a value on the \a index position. |
|
|||
83 | */ |
|
|||
84 | /*! |
|
58 | /*! | |
85 | \fn void QBoxSet::clicked() |
|
59 | \fn void QBoxSet::clicked() | |
86 | The signal is emitted if the user clicks with a mouse on top of box-and-whisker item. |
|
60 | The signal is emitted if the user clicks with a mouse on top of box-and-whisker item. | |
87 | */ |
|
61 | */ | |
88 | /*! |
|
62 | /*! | |
89 | \qmlsignal BoxSet::onClicked() |
|
|||
90 | This signal is emitted when the user clicks with a mouse on top of box-and-whisker item. |
|
|||
91 | */ |
|
|||
92 |
|
||||
93 | /*! |
|
|||
94 | \fn void QBoxSet::hovered(bool status) |
|
63 | \fn void QBoxSet::hovered(bool status) | |
95 |
|
64 | |||
96 | The signal is emitted if mouse is hovered on top of box-and-whisker item. |
|
65 | The signal is emitted if mouse is hovered on top of box-and-whisker item. | |
97 | Parameter \a status is true, if mouse entered on top of item, false if mouse left from top of item. |
|
66 | Parameter \a status is true, if mouse entered on top of item, false if mouse left from top of item. | |
98 | */ |
|
67 | */ | |
99 | /*! |
|
68 | /*! | |
100 | \qmlsignal BoxSet::onHovered(bool status) |
|
|||
101 |
|
||||
102 | The signal is emitted if mouse is hovered on top of box-and-whisker item. |
|
|||
103 | Parameter \a status is true, if mouse entered on top of item, false if mouse left from top of item. |
|
|||
104 | */ |
|
|||
105 |
|
||||
106 | /*! |
|
|||
107 | \fn void QBoxSet::penChanged() |
|
69 | \fn void QBoxSet::penChanged() | |
108 | This signal is emitted when the pen of the box-and-whisker item has changed. |
|
70 | This signal is emitted when the pen of the box-and-whisker item has changed. | |
109 | \sa pen |
|
71 | \sa pen | |
110 | */ |
|
72 | */ | |
111 | /*! |
|
73 | /*! | |
112 | \qmlsignal BoxSet::onPenChanged() |
|
|||
113 | This signal is emitted when the pen of the box-and-whisker item has changed. |
|
|||
114 | */ |
|
|||
115 | /*! |
|
|||
116 | \fn void QBoxSet::brushChanged() |
|
74 | \fn void QBoxSet::brushChanged() | |
117 | This signal is emitted when the brush of the box-and-whisker item has changed. |
|
75 | This signal is emitted when the brush of the box-and-whisker item has changed. | |
118 | \sa brush |
|
76 | \sa brush | |
119 | */ |
|
77 | */ | |
120 | /*! |
|
78 | /*! | |
121 | \qmlsignal BoxSet::onBrushChanged() |
|
|||
122 | This signal is emitted when the brush of the box-and-whisker item has changed. |
|
|||
123 | */ |
|
|||
124 |
|
||||
125 | /*! |
|
|||
126 | \fn void QBoxSet::valuesChanged() |
|
79 | \fn void QBoxSet::valuesChanged() | |
127 | This signal is emitted when multiple values have been changed on the box-and-whisker item. |
|
80 | This signal is emitted when multiple values have been changed on the box-and-whisker item. | |
128 | \sa append() |
|
81 | \sa append() | |
129 | */ |
|
82 | */ | |
130 | /*! |
|
83 | /*! | |
131 | \qmlsignal BoxSet::onChangedValues() |
|
|||
132 | This signal is emitted when multiple values have been changed on the box-and-whisker item. |
|
|||
133 | */ |
|
|||
134 |
|
||||
135 | /*! |
|
|||
136 | \fn void QBoxSet::valueChanged(int index) |
|
84 | \fn void QBoxSet::valueChanged(int index) | |
137 | This signal is emitted values the value in the box-and-whisker item has been modified. |
|
85 | This signal is emitted values the value in the box-and-whisker item has been modified. | |
138 | Parameter \a index indicates the position of the modified value. |
|
86 | Parameter \a index indicates the position of the modified value. | |
139 | \sa at() |
|
87 | \sa at() | |
140 | */ |
|
88 | */ | |
141 | /*! |
|
89 | /*! | |
142 | \qmlsignal BoxSet::onChangedValue(int index) |
|
|||
143 | This signal is emitted values the value in the box-and-whisker item has been modified. |
|
|||
144 | Parameter \a index indicates the position of the modified value. |
|
|||
145 | */ |
|
|||
146 |
|
||||
147 | /*! |
|
|||
148 | \fn void QBoxSet::cleared() |
|
90 | \fn void QBoxSet::cleared() | |
149 | This signal is emitted when all the values on the set are cleared to 0. |
|
91 | This signal is emitted when all the values on the set are cleared to 0. | |
150 | */ |
|
92 | */ | |
151 | /*! |
|
|||
152 | \qmlsignal BoxSet::onCleared() |
|
|||
153 | This signal is emitted when all the values on the set are cleared to 0. |
|
|||
154 | */ |
|
|||
155 |
|
||||
156 |
|
93 | |||
157 | /*! |
|
94 | /*! | |
158 | Constructs QBoxSet with optional \a label and parent of \a parent |
|
95 | Constructs QBoxSet with optional \a label and parent of \a parent | |
159 | */ |
|
96 | */ | |
160 | QBoxSet::QBoxSet(const QString label, QObject *parent) |
|
97 | QBoxSet::QBoxSet(const QString label, QObject *parent) | |
161 | : QObject(parent), |
|
98 | : QObject(parent), | |
162 | d_ptr(new QBoxSetPrivate(label, this)) |
|
99 | d_ptr(new QBoxSetPrivate(label, this)) | |
163 | { |
|
100 | { | |
164 | } |
|
101 | } | |
165 |
|
102 | |||
166 | /*! |
|
103 | /*! | |
167 | Constructs QBoxSet with given ordered values. \a le for lower extreme, \a lq for lower quartile, \a m for median, |
|
104 | Constructs QBoxSet with given ordered values. \a le for lower extreme, \a lq for lower quartile, \a m for median, | |
168 | \a uq for upper quartile and \a ue for upper quartile. \a label and \a parent are optional. |
|
105 | \a uq for upper quartile and \a ue for upper quartile. \a label and \a parent are optional. | |
169 | */ |
|
106 | */ | |
170 | QBoxSet::QBoxSet(const qreal le, const qreal lq, const qreal m, const qreal uq, const qreal ue, const QString label, QObject *parent) |
|
107 | QBoxSet::QBoxSet(const qreal le, const qreal lq, const qreal m, const qreal uq, const qreal ue, const QString label, QObject *parent) | |
171 | : QObject(parent), |
|
108 | : QObject(parent), | |
172 | d_ptr(new QBoxSetPrivate(label, this)) |
|
109 | d_ptr(new QBoxSetPrivate(label, this)) | |
173 | { |
|
110 | { | |
174 | d_ptr->append(le); |
|
111 | d_ptr->append(le); | |
175 | d_ptr->append(lq); |
|
112 | d_ptr->append(lq); | |
176 | d_ptr->append(m); |
|
113 | d_ptr->append(m); | |
177 | d_ptr->append(uq); |
|
114 | d_ptr->append(uq); | |
178 | d_ptr->append(ue); |
|
115 | d_ptr->append(ue); | |
179 | } |
|
116 | } | |
180 |
|
117 | |||
181 | /*! |
|
118 | /*! | |
182 | Destroys the boxset |
|
119 | Destroys the boxset | |
183 | */ |
|
120 | */ | |
184 | QBoxSet::~QBoxSet() |
|
121 | QBoxSet::~QBoxSet() | |
185 | { |
|
122 | { | |
186 | } |
|
123 | } | |
187 |
|
124 | |||
188 | /*! |
|
125 | /*! | |
189 | Appends new value \a value to the end of set. |
|
126 | Appends new value \a value to the end of set. | |
190 | */ |
|
127 | */ | |
191 | void QBoxSet::append(const qreal value) |
|
128 | void QBoxSet::append(const qreal value) | |
192 | { |
|
129 | { | |
193 | if (d_ptr->append(value)) |
|
130 | if (d_ptr->append(value)) | |
194 | emit valueChanged(d_ptr->m_appendCount - 1); |
|
131 | emit valueChanged(d_ptr->m_appendCount - 1); | |
195 | } |
|
132 | } | |
196 |
|
133 | |||
197 | /*! |
|
134 | /*! | |
198 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
135 | Appends a list of reals to set. Works like append with single real value. The \a values in list | |
199 | are appended to end of boxset. |
|
136 | are appended to end of boxset. | |
200 | \sa append() |
|
137 | \sa append() | |
201 | */ |
|
138 | */ | |
202 | void QBoxSet::append(const QList<qreal> &values) |
|
139 | void QBoxSet::append(const QList<qreal> &values) | |
203 | { |
|
140 | { | |
204 | if (d_ptr->append(values)) |
|
141 | if (d_ptr->append(values)) | |
205 | emit valuesChanged(); |
|
142 | emit valuesChanged(); | |
206 | } |
|
143 | } | |
207 |
|
144 | |||
208 | /*! |
|
145 | /*! | |
209 | Sets new \a label for set. |
|
146 | Sets new \a label for set. | |
210 | */ |
|
147 | */ | |
211 | void QBoxSet::setLabel(const QString label) |
|
148 | void QBoxSet::setLabel(const QString label) | |
212 | { |
|
149 | { | |
213 | d_ptr->m_label = label; |
|
150 | d_ptr->m_label = label; | |
214 | } |
|
151 | } | |
215 |
|
152 | |||
216 | /*! |
|
153 | /*! | |
217 | Returns label of the set. |
|
154 | Returns label of the set. | |
218 | */ |
|
155 | */ | |
219 | QString QBoxSet::label() const |
|
156 | QString QBoxSet::label() const | |
220 | { |
|
157 | { | |
221 | return d_ptr->m_label; |
|
158 | return d_ptr->m_label; | |
222 | } |
|
159 | } | |
223 |
|
160 | |||
224 | /*! |
|
161 | /*! | |
225 | Convenience operator. Same as append, with real \a value. |
|
162 | Convenience operator. Same as append, with real \a value. | |
226 | \sa append() |
|
163 | \sa append() | |
227 | */ |
|
164 | */ | |
228 | QBoxSet &QBoxSet::operator << (const qreal &value) |
|
165 | QBoxSet &QBoxSet::operator << (const qreal &value) | |
229 | { |
|
166 | { | |
230 | append(value); |
|
167 | append(value); | |
231 | return *this; |
|
168 | return *this; | |
232 | } |
|
169 | } | |
233 |
|
170 | |||
234 | /*! |
|
171 | /*! | |
235 | Sets a new \a value on the \a index position. For \a index ValuePositions can be used. |
|
172 | Sets a new \a value on the \a index position. For \a index ValuePositions can be used. | |
236 | */ |
|
173 | */ | |
237 | void QBoxSet::setValue(const int index, const qreal value) |
|
174 | void QBoxSet::setValue(const int index, const qreal value) | |
238 | { |
|
175 | { | |
239 | d_ptr->setValue(index, value); |
|
176 | d_ptr->setValue(index, value); | |
240 | emit valueChanged(index); |
|
177 | emit valueChanged(index); | |
241 | } |
|
178 | } | |
242 |
|
179 | |||
243 | /*! |
|
180 | /*! | |
244 | Sets all values on the set to 0. |
|
181 | Sets all values on the set to 0. | |
245 | */ |
|
182 | */ | |
246 | void QBoxSet::clear() |
|
183 | void QBoxSet::clear() | |
247 | { |
|
184 | { | |
248 | d_ptr->clear(); |
|
185 | d_ptr->clear(); | |
249 | emit cleared(); |
|
186 | emit cleared(); | |
250 | } |
|
187 | } | |
251 |
|
188 | |||
252 | /*! |
|
189 | /*! | |
253 | Returns value of set indexed by \a index. For \a index ValuePositions can be used. |
|
190 | Returns value of set indexed by \a index. For \a index ValuePositions can be used. | |
254 | If the index is out of bounds 0.0 is returned. |
|
191 | If the index is out of bounds 0.0 is returned. | |
255 | */ |
|
192 | */ | |
256 | qreal QBoxSet::at(const int index) const |
|
193 | qreal QBoxSet::at(const int index) const | |
257 | { |
|
194 | { | |
258 | if (index < 0 || index >= 5) |
|
195 | if (index < 0 || index >= 5) | |
259 | return 0; |
|
196 | return 0; | |
260 | return d_ptr->m_values[index]; |
|
197 | return d_ptr->m_values[index]; | |
261 | } |
|
198 | } | |
262 |
|
199 | |||
263 | /*! |
|
200 | /*! | |
264 | Returns value of set indexed by \a index. For \a index ValuePositions can be used. |
|
201 | Returns value of set indexed by \a index. For \a index ValuePositions can be used. | |
265 | If the index is out of bounds 0.0 is returned. |
|
202 | If the index is out of bounds 0.0 is returned. | |
266 | */ |
|
203 | */ | |
267 | qreal QBoxSet::operator [](const int index) const |
|
204 | qreal QBoxSet::operator [](const int index) const | |
268 | { |
|
205 | { | |
269 | return at(index); |
|
206 | return at(index); | |
270 | } |
|
207 | } | |
271 |
|
208 | |||
272 | /*! |
|
209 | /*! | |
273 | Returns count of values appended to the set. |
|
210 | Returns count of values appended to the set. | |
274 | */ |
|
211 | */ | |
275 | int QBoxSet::count() const |
|
212 | int QBoxSet::count() const | |
276 | { |
|
213 | { | |
277 | return d_ptr->m_appendCount; |
|
214 | return d_ptr->m_appendCount; | |
278 | } |
|
215 | } | |
279 |
|
216 | |||
280 | /*! |
|
217 | /*! | |
281 | Sets pen for set. Boxes of this set are drawn using \a pen |
|
218 | Sets pen for set. Boxes of this set are drawn using \a pen | |
282 | */ |
|
219 | */ | |
283 | void QBoxSet::setPen(const QPen &pen) |
|
220 | void QBoxSet::setPen(const QPen &pen) | |
284 | { |
|
221 | { | |
285 | if (d_ptr->m_pen != pen) { |
|
222 | if (d_ptr->m_pen != pen) { | |
286 | d_ptr->m_pen = pen; |
|
223 | d_ptr->m_pen = pen; | |
287 | emit d_ptr->updatedBox(); |
|
224 | emit d_ptr->updatedBox(); | |
288 | emit penChanged(); |
|
225 | emit penChanged(); | |
289 | } |
|
226 | } | |
290 | } |
|
227 | } | |
291 |
|
228 | |||
292 | /*! |
|
229 | /*! | |
293 | Returns pen of the set. |
|
230 | Returns pen of the set. | |
294 | */ |
|
231 | */ | |
295 | QPen QBoxSet::pen() const |
|
232 | QPen QBoxSet::pen() const | |
296 | { |
|
233 | { | |
297 | return d_ptr->m_pen; |
|
234 | return d_ptr->m_pen; | |
298 | } |
|
235 | } | |
299 |
|
236 | |||
300 | /*! |
|
237 | /*! | |
301 | Sets brush for the set. Boxes of this set are drawn using \a brush |
|
238 | Sets brush for the set. Boxes of this set are drawn using \a brush | |
302 | */ |
|
239 | */ | |
303 | void QBoxSet::setBrush(const QBrush &brush) |
|
240 | void QBoxSet::setBrush(const QBrush &brush) | |
304 | { |
|
241 | { | |
305 | if (d_ptr->m_brush != brush) { |
|
242 | if (d_ptr->m_brush != brush) { | |
306 | d_ptr->m_brush = brush; |
|
243 | d_ptr->m_brush = brush; | |
307 | emit d_ptr->updatedBox(); |
|
244 | emit d_ptr->updatedBox(); | |
308 | emit brushChanged(); |
|
245 | emit brushChanged(); | |
309 | } |
|
246 | } | |
310 | } |
|
247 | } | |
311 |
|
248 | |||
312 | /*! |
|
249 | /*! | |
313 | Returns brush of the set. |
|
250 | Returns brush of the set. | |
314 | */ |
|
251 | */ | |
315 | QBrush QBoxSet::brush() const |
|
252 | QBrush QBoxSet::brush() const | |
316 | { |
|
253 | { | |
317 | return d_ptr->m_brush; |
|
254 | return d_ptr->m_brush; | |
318 | } |
|
255 | } | |
319 |
|
256 | |||
320 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
257 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
321 |
|
258 | |||
322 | QBoxSetPrivate::QBoxSetPrivate(const QString label, QBoxSet *parent) : QObject(parent), |
|
259 | QBoxSetPrivate::QBoxSetPrivate(const QString label, QBoxSet *parent) : QObject(parent), | |
323 | q_ptr(parent), |
|
260 | q_ptr(parent), | |
324 | m_label(label), |
|
261 | m_label(label), | |
325 | m_valuesCount(5), |
|
262 | m_valuesCount(5), | |
326 | m_appendCount(0), |
|
263 | m_appendCount(0), | |
327 | m_pen(QPen(Qt::NoPen)), |
|
264 | m_pen(QPen(Qt::NoPen)), | |
328 | m_brush(QBrush(Qt::NoBrush)), |
|
265 | m_brush(QBrush(Qt::NoBrush)), | |
329 | m_series(0) |
|
266 | m_series(0) | |
330 | { |
|
267 | { | |
331 | m_values = new qreal[m_valuesCount]; |
|
268 | m_values = new qreal[m_valuesCount]; | |
332 | } |
|
269 | } | |
333 |
|
270 | |||
334 | QBoxSetPrivate::~QBoxSetPrivate() |
|
271 | QBoxSetPrivate::~QBoxSetPrivate() | |
335 | { |
|
272 | { | |
336 | } |
|
273 | } | |
337 |
|
274 | |||
338 | bool QBoxSetPrivate::append(qreal value) |
|
275 | bool QBoxSetPrivate::append(qreal value) | |
339 | { |
|
276 | { | |
340 | if (isValidValue(value) && m_appendCount < m_valuesCount) { |
|
277 | if (isValidValue(value) && m_appendCount < m_valuesCount) { | |
341 | m_values[m_appendCount++] = value; |
|
278 | m_values[m_appendCount++] = value; | |
342 | emit restructuredBox(); |
|
279 | emit restructuredBox(); | |
343 |
|
280 | |||
344 | return true; |
|
281 | return true; | |
345 | } |
|
282 | } | |
346 | return false; |
|
283 | return false; | |
347 | } |
|
284 | } | |
348 |
|
285 | |||
349 | bool QBoxSetPrivate::append(QList<qreal> values) |
|
286 | bool QBoxSetPrivate::append(QList<qreal> values) | |
350 | { |
|
287 | { | |
351 | bool success = false; |
|
288 | bool success = false; | |
352 |
|
289 | |||
353 | for (int i = 0; i < values.count(); i++) { |
|
290 | for (int i = 0; i < values.count(); i++) { | |
354 | if (isValidValue(values.at(i)) && m_appendCount < m_valuesCount) { |
|
291 | if (isValidValue(values.at(i)) && m_appendCount < m_valuesCount) { | |
355 | success = true; |
|
292 | success = true; | |
356 | m_values[m_appendCount++] = values.at(i); |
|
293 | m_values[m_appendCount++] = values.at(i); | |
357 | } |
|
294 | } | |
358 | } |
|
295 | } | |
359 |
|
296 | |||
360 | if (success) |
|
297 | if (success) | |
361 | emit restructuredBox(); |
|
298 | emit restructuredBox(); | |
362 |
|
299 | |||
363 | return success; |
|
300 | return success; | |
364 | } |
|
301 | } | |
365 |
|
302 | |||
366 | void QBoxSetPrivate::clear() |
|
303 | void QBoxSetPrivate::clear() | |
367 | { |
|
304 | { | |
368 | m_appendCount = 0; |
|
305 | m_appendCount = 0; | |
369 | for (int i = 0; i < m_valuesCount; i++) |
|
306 | for (int i = 0; i < m_valuesCount; i++) | |
370 | m_values[i] = 0.0; |
|
307 | m_values[i] = 0.0; | |
371 | emit restructuredBox(); |
|
308 | emit restructuredBox(); | |
372 | } |
|
309 | } | |
373 |
|
310 | |||
374 | void QBoxSetPrivate::setValue(const int index, const qreal value) |
|
311 | void QBoxSetPrivate::setValue(const int index, const qreal value) | |
375 | { |
|
312 | { | |
376 | if (index < m_valuesCount) { |
|
313 | if (index < m_valuesCount) { | |
377 | m_values[index] = value; |
|
314 | m_values[index] = value; | |
378 | emit updatedLayout(); |
|
315 | emit updatedLayout(); | |
379 | } |
|
316 | } | |
380 | } |
|
317 | } | |
381 |
|
318 | |||
382 | qreal QBoxSetPrivate::value(const int index) |
|
319 | qreal QBoxSetPrivate::value(const int index) | |
383 | { |
|
320 | { | |
384 | if (index < 0 || index >= m_valuesCount) |
|
321 | if (index < 0 || index >= m_valuesCount) | |
385 | return 0; |
|
322 | return 0; | |
386 | return m_values[index]; |
|
323 | return m_values[index]; | |
387 | } |
|
324 | } | |
388 |
|
325 | |||
389 | #include "moc_qboxset.cpp" |
|
326 | #include "moc_qboxset.cpp" | |
390 | #include "moc_qboxset_p.cpp" |
|
327 | #include "moc_qboxset_p.cpp" | |
391 |
|
328 | |||
392 | QTCOMMERCIALCHART_END_NAMESPACE |
|
329 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,449 +1,461 | |||||
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 "pentool.h" |
|
23 | #include "pentool.h" | |
24 | #include <QVBoxPlotModelMapper> |
|
24 | #include <QVBoxPlotModelMapper> | |
25 | #include <QTableView> |
|
25 | #include <QTableView> | |
26 | #include <QHeaderView> |
|
26 | #include <QHeaderView> | |
27 | #include <QChartView> |
|
27 | #include <QChartView> | |
28 | #include <QBoxPlotSeries> |
|
28 | #include <QBoxPlotSeries> | |
29 | #include <QBoxSet> |
|
29 | #include <QBoxSet> | |
30 | #include <QLegend> |
|
30 | #include <QLegend> | |
31 | #include <QBarCategoryAxis> |
|
31 | #include <QBarCategoryAxis> | |
32 | #include <QBrush> |
|
32 | #include <QBrush> | |
33 | #include <QColor> |
|
33 | #include <QColor> | |
34 | #include <QPushButton> |
|
34 | #include <QPushButton> | |
35 | #include <QComboBox> |
|
35 | #include <QComboBox> | |
36 | #include <QSpinBox> |
|
36 | #include <QSpinBox> | |
37 | #include <QCheckBox> |
|
37 | #include <QCheckBox> | |
38 | #include <QGridLayout> |
|
38 | #include <QGridLayout> | |
39 | #include <QHBoxLayout> |
|
39 | #include <QHBoxLayout> | |
40 | #include <QLabel> |
|
40 | #include <QLabel> | |
41 | #include <QSpacerItem> |
|
41 | #include <QSpacerItem> | |
42 | #include <QMessageBox> |
|
42 | #include <QMessageBox> | |
43 | #include <cmath> |
|
43 | #include <cmath> | |
44 | #include <QDebug> |
|
44 | #include <QDebug> | |
45 | #include <QStandardItemModel> |
|
45 | #include <QStandardItemModel> | |
46 | #include <QBarCategoryAxis> |
|
46 | #include <QBarCategoryAxis> | |
47 | #include <QLogValueAxis> |
|
47 | #include <QLogValueAxis> | |
48 |
|
48 | |||
49 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
49 | QTCOMMERCIALCHART_USE_NAMESPACE | |
50 |
|
50 | |||
51 | static const QString allCategories[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
|
51 | static const QString allCategories[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; | |
52 | static const int maxCategories = 12; |
|
52 | static const int maxCategories = 12; | |
53 |
|
53 | |||
54 | MainWidget::MainWidget(QWidget *parent) : |
|
54 | MainWidget::MainWidget(QWidget *parent) : | |
55 | QWidget(parent), |
|
55 | QWidget(parent), | |
56 | m_chart(0), |
|
56 | m_chart(0), | |
57 | m_axis(0), |
|
57 | m_axis(0), | |
58 | m_rowPos(0), |
|
58 | m_rowPos(0), | |
59 | m_seriesCount(0) |
|
59 | m_seriesCount(0) | |
60 | { |
|
60 | { | |
61 | m_chart = new QChart(); |
|
61 | m_chart = new QChart(); | |
62 |
|
62 | |||
63 | m_penTool = new PenTool("Whiskers pen", this); |
|
63 | m_penTool = new PenTool("Whiskers pen", this); | |
64 |
|
64 | |||
65 | // Grid layout for the controls for configuring the chart widget |
|
65 | // Grid layout for the controls for configuring the chart widget | |
66 | QGridLayout *grid = new QGridLayout(); |
|
66 | QGridLayout *grid = new QGridLayout(); | |
67 |
|
67 | |||
68 | // Create add a series button |
|
68 | // Create add a series button | |
69 | QPushButton *addSeriesButton = new QPushButton("Add a series"); |
|
69 | QPushButton *addSeriesButton = new QPushButton("Add a series"); | |
70 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
70 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
71 | grid->addWidget(addSeriesButton, m_rowPos++, 1); |
|
71 | grid->addWidget(addSeriesButton, m_rowPos++, 1); | |
72 |
|
72 | |||
73 | // Create remove a series button |
|
73 | // Create remove a series button | |
74 | QPushButton *removeSeriesButton = new QPushButton("Remove a series"); |
|
74 | QPushButton *removeSeriesButton = new QPushButton("Remove a series"); | |
75 | connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries())); |
|
75 | connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries())); | |
76 | grid->addWidget(removeSeriesButton, m_rowPos++, 1); |
|
76 | grid->addWidget(removeSeriesButton, m_rowPos++, 1); | |
77 |
|
77 | |||
78 | // Create add a single box button |
|
78 | // Create add a single box button | |
79 | QPushButton *addBoxButton = new QPushButton("Add a box"); |
|
79 | QPushButton *addBoxButton = new QPushButton("Add a box"); | |
80 | connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox())); |
|
80 | connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox())); | |
81 | grid->addWidget(addBoxButton, m_rowPos++, 1); |
|
81 | grid->addWidget(addBoxButton, m_rowPos++, 1); | |
82 |
|
82 | |||
83 | // Create insert a box button |
|
83 | // Create insert a box button | |
84 | QPushButton *insertBoxButton = new QPushButton("Insert a box"); |
|
84 | QPushButton *insertBoxButton = new QPushButton("Insert a box"); | |
85 | connect(insertBoxButton, SIGNAL(clicked()), this, SLOT(insertBox())); |
|
85 | connect(insertBoxButton, SIGNAL(clicked()), this, SLOT(insertBox())); | |
86 | grid->addWidget(insertBoxButton, m_rowPos++, 1); |
|
86 | grid->addWidget(insertBoxButton, m_rowPos++, 1); | |
87 |
|
87 | |||
88 | // Create add a single box button |
|
88 | // Create add a single box button | |
89 | QPushButton *removeBoxButton = new QPushButton("Remove a box"); |
|
89 | QPushButton *removeBoxButton = new QPushButton("Remove a box"); | |
90 | connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox())); |
|
90 | connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox())); | |
91 | grid->addWidget(removeBoxButton, m_rowPos++, 1); |
|
91 | grid->addWidget(removeBoxButton, m_rowPos++, 1); | |
92 |
|
92 | |||
93 | // Create clear button |
|
93 | // Create clear button | |
94 | QPushButton *clearButton = new QPushButton("Clear"); |
|
94 | QPushButton *clearButton = new QPushButton("Clear"); | |
95 | connect(clearButton, SIGNAL(clicked()), this, SLOT(clear())); |
|
95 | connect(clearButton, SIGNAL(clicked()), this, SLOT(clear())); | |
96 | grid->addWidget(clearButton, m_rowPos++, 1); |
|
96 | grid->addWidget(clearButton, m_rowPos++, 1); | |
97 |
|
97 | |||
98 | // Create clear button |
|
98 | // Create clear button | |
99 | QPushButton *clearBoxButton = new QPushButton("ClearBox"); |
|
99 | QPushButton *clearBoxButton = new QPushButton("ClearBox"); | |
100 | connect(clearBoxButton, SIGNAL(clicked()), this, SLOT(clearBox())); |
|
100 | connect(clearBoxButton, SIGNAL(clicked()), this, SLOT(clearBox())); | |
101 | grid->addWidget(clearBoxButton, m_rowPos++, 1); |
|
101 | grid->addWidget(clearBoxButton, m_rowPos++, 1); | |
102 |
|
102 | |||
103 | // Create set brush button |
|
103 | // Create set brush button | |
104 | QPushButton *setBrushButton = new QPushButton("Set brush"); |
|
104 | QPushButton *setBrushButton = new QPushButton("Set brush"); | |
105 | connect(setBrushButton, SIGNAL(clicked()), this, SLOT(setBrush())); |
|
105 | connect(setBrushButton, SIGNAL(clicked()), this, SLOT(setBrush())); | |
106 | grid->addWidget(setBrushButton, m_rowPos++, 1); |
|
106 | grid->addWidget(setBrushButton, m_rowPos++, 1); | |
107 |
|
107 | |||
108 | // Create set whiskers pen button |
|
108 | // Create set whiskers pen button | |
109 | QPushButton *setWhiskersButton = new QPushButton("Whiskers pen"); |
|
109 | QPushButton *setWhiskersButton = new QPushButton("Whiskers pen"); | |
110 | connect(setWhiskersButton, SIGNAL(clicked()), m_penTool, SLOT(show())); |
|
110 | connect(setWhiskersButton, SIGNAL(clicked()), m_penTool, SLOT(show())); | |
111 | connect(m_penTool, SIGNAL(changed()), this, SLOT(changePen())); |
|
111 | connect(m_penTool, SIGNAL(changed()), this, SLOT(changePen())); | |
112 | grid->addWidget(setWhiskersButton, m_rowPos++, 1); |
|
112 | grid->addWidget(setWhiskersButton, m_rowPos++, 1); | |
113 |
|
113 | |||
114 | initThemeCombo(grid); |
|
114 | initThemeCombo(grid); | |
115 | initCheckboxes(grid); |
|
115 | initCheckboxes(grid); | |
116 |
|
116 | |||
117 | m_model = new CustomTableModel(); |
|
117 | m_model = new CustomTableModel(); | |
118 | QTableView *tableView = new QTableView; |
|
118 | QTableView *tableView = new QTableView; | |
119 | tableView->setModel(m_model); |
|
119 | tableView->setModel(m_model); | |
120 | tableView->setMaximumWidth(200); |
|
120 | tableView->setMaximumWidth(200); | |
121 | grid->addWidget(tableView, m_rowPos++, 0, 3, 2, Qt::AlignLeft); |
|
121 | grid->addWidget(tableView, m_rowPos++, 0, 3, 2, Qt::AlignLeft); | |
122 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
|
122 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | |
123 | tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
|
123 | tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); | |
124 | tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
|
124 | tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); | |
125 | #else |
|
125 | #else | |
126 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
126 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); | |
127 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
127 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); | |
128 | #endif |
|
128 | #endif | |
129 |
|
129 | |||
130 | // add row with empty label to make all the other rows static |
|
130 | // add row with empty label to make all the other rows static | |
131 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
131 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
132 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
132 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
133 |
|
133 | |||
134 | // Create chart view with the chart |
|
134 | // Create chart view with the chart | |
135 | m_chartView = new QChartView(m_chart, this); |
|
135 | m_chartView = new QChartView(m_chart, this); | |
136 |
|
136 | |||
137 | // As a default antialiasing is off |
|
137 | // As a default antialiasing is off | |
138 | m_chartView->setRenderHint(QPainter::Antialiasing, false); |
|
138 | m_chartView->setRenderHint(QPainter::Antialiasing, false); | |
139 |
|
139 | |||
140 | // Another grid layout as a main layout |
|
140 | // Another grid layout as a main layout | |
141 | QGridLayout *mainLayout = new QGridLayout(); |
|
141 | QGridLayout *mainLayout = new QGridLayout(); | |
142 | mainLayout->addLayout(grid, 0, 0); |
|
142 | mainLayout->addLayout(grid, 0, 0); | |
143 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
143 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
144 | setLayout(mainLayout); |
|
144 | setLayout(mainLayout); | |
145 |
|
145 | |||
146 | legendToggled(false); |
|
146 | legendToggled(false); | |
147 | animationToggled(false); |
|
147 | animationToggled(false); | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | // Combo box for selecting theme |
|
150 | // Combo box for selecting theme | |
151 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
151 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
152 | { |
|
152 | { | |
153 | QComboBox *chartTheme = new QComboBox(); |
|
153 | QComboBox *chartTheme = new QComboBox(); | |
154 | chartTheme->addItem("Default"); |
|
154 | chartTheme->addItem("Default"); | |
155 | chartTheme->addItem("Light"); |
|
155 | chartTheme->addItem("Light"); | |
156 | chartTheme->addItem("Blue Cerulean"); |
|
156 | chartTheme->addItem("Blue Cerulean"); | |
157 | chartTheme->addItem("Dark"); |
|
157 | chartTheme->addItem("Dark"); | |
158 | chartTheme->addItem("Brown Sand"); |
|
158 | chartTheme->addItem("Brown Sand"); | |
159 | chartTheme->addItem("Blue NCS"); |
|
159 | chartTheme->addItem("Blue NCS"); | |
160 | chartTheme->addItem("High Contrast"); |
|
160 | chartTheme->addItem("High Contrast"); | |
161 | chartTheme->addItem("Blue Icy"); |
|
161 | chartTheme->addItem("Blue Icy"); | |
162 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
162 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
163 | this, SLOT(changeChartTheme(int))); |
|
163 | this, SLOT(changeChartTheme(int))); | |
164 | grid->addWidget(new QLabel("Chart theme:"), m_rowPos, 0); |
|
164 | grid->addWidget(new QLabel("Chart theme:"), m_rowPos, 0); | |
165 | grid->addWidget(chartTheme, m_rowPos++, 1); |
|
165 | grid->addWidget(chartTheme, m_rowPos++, 1); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | // Different check boxes for customizing chart |
|
168 | // Different check boxes for customizing chart | |
169 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
169 | void MainWidget::initCheckboxes(QGridLayout *grid) | |
170 | { |
|
170 | { | |
171 | QCheckBox *animationCheckBox = new QCheckBox("Animation"); |
|
171 | QCheckBox *animationCheckBox = new QCheckBox("Animation"); | |
172 | connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool))); |
|
172 | connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool))); | |
173 | animationCheckBox->setChecked(false); |
|
173 | animationCheckBox->setChecked(false); | |
174 | grid->addWidget(animationCheckBox, m_rowPos++, 0); |
|
174 | grid->addWidget(animationCheckBox, m_rowPos++, 0); | |
175 |
|
175 | |||
176 | QCheckBox *legendCheckBox = new QCheckBox("Legend"); |
|
176 | QCheckBox *legendCheckBox = new QCheckBox("Legend"); | |
177 | connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool))); |
|
177 | connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool))); | |
178 | legendCheckBox->setChecked(false); |
|
178 | legendCheckBox->setChecked(false); | |
179 | grid->addWidget(legendCheckBox, m_rowPos++, 0); |
|
179 | grid->addWidget(legendCheckBox, m_rowPos++, 0); | |
180 |
|
180 | |||
181 | QCheckBox *titleCheckBox = new QCheckBox("Title"); |
|
181 | QCheckBox *titleCheckBox = new QCheckBox("Title"); | |
182 | connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool))); |
|
182 | connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool))); | |
183 | titleCheckBox->setChecked(false); |
|
183 | titleCheckBox->setChecked(false); | |
184 | grid->addWidget(titleCheckBox, m_rowPos++, 0); |
|
184 | grid->addWidget(titleCheckBox, m_rowPos++, 0); | |
185 |
|
185 | |||
186 | QCheckBox *antialiasingCheckBox = new QCheckBox("Antialiasing"); |
|
186 | QCheckBox *antialiasingCheckBox = new QCheckBox("Antialiasing"); | |
187 | connect(antialiasingCheckBox, SIGNAL(toggled(bool)), this, SLOT(antialiasingToggled(bool))); |
|
187 | connect(antialiasingCheckBox, SIGNAL(toggled(bool)), this, SLOT(antialiasingToggled(bool))); | |
188 | antialiasingCheckBox->setChecked(false); |
|
188 | antialiasingCheckBox->setChecked(false); | |
189 | grid->addWidget(antialiasingCheckBox, m_rowPos++, 0); |
|
189 | grid->addWidget(antialiasingCheckBox, m_rowPos++, 0); | |
190 |
|
190 | |||
191 | QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper"); |
|
191 | QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper"); | |
192 | connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool))); |
|
192 | connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool))); | |
193 | modelMapperCheckBox->setChecked(false); |
|
193 | modelMapperCheckBox->setChecked(false); | |
194 | grid->addWidget(modelMapperCheckBox, m_rowPos++, 0); |
|
194 | grid->addWidget(modelMapperCheckBox, m_rowPos++, 0); | |
195 |
|
195 | |||
|
196 | m_boxOutlined = new QCheckBox("Box outlined"); | |||
|
197 | connect(m_boxOutlined, SIGNAL(toggled(bool)), this, SLOT(boxOutlineToggled(bool))); | |||
|
198 | m_boxOutlined->setChecked(true); | |||
|
199 | grid->addWidget(m_boxOutlined, m_rowPos++, 0); | |||
196 | } |
|
200 | } | |
197 |
|
201 | |||
198 | void MainWidget::updateAxis(int categoryCount) |
|
202 | void MainWidget::updateAxis(int categoryCount) | |
199 | { |
|
203 | { | |
200 | if (!m_axis) { |
|
204 | if (!m_axis) { | |
201 | m_chart->createDefaultAxes(); |
|
205 | m_chart->createDefaultAxes(); | |
202 | m_axis = new QBarCategoryAxis(); |
|
206 | m_axis = new QBarCategoryAxis(); | |
203 | } |
|
207 | } | |
204 | QStringList categories; |
|
208 | QStringList categories; | |
205 | for (int i = 0; i < categoryCount; i++) |
|
209 | for (int i = 0; i < categoryCount; i++) | |
206 | categories << allCategories[i]; |
|
210 | categories << allCategories[i]; | |
207 | m_axis->setCategories(categories); |
|
211 | m_axis->setCategories(categories); | |
208 | } |
|
212 | } | |
209 |
|
213 | |||
210 | void MainWidget::addSeries() |
|
214 | void MainWidget::addSeries() | |
211 | { |
|
215 | { | |
212 | qDebug() << "BoxPlotTester::MainWidget::addSeries()"; |
|
216 | qDebug() << "BoxPlotTester::MainWidget::addSeries()"; | |
213 |
|
217 | |||
214 | if (m_seriesCount > 9) |
|
218 | if (m_seriesCount > 9) | |
215 | return; |
|
219 | return; | |
216 |
|
220 | |||
217 | // Initial data |
|
221 | // Initial data | |
218 | QBoxSet *set0 = new QBoxSet(); |
|
222 | QBoxSet *set0 = new QBoxSet(); | |
219 | QBoxSet *set1 = new QBoxSet(); |
|
223 | QBoxSet *set1 = new QBoxSet(); | |
220 | QBoxSet *set2 = new QBoxSet(); |
|
224 | QBoxSet *set2 = new QBoxSet(); | |
221 | QBoxSet *set3 = new QBoxSet(); |
|
225 | QBoxSet *set3 = new QBoxSet(); | |
222 | QBoxSet *set4 = new QBoxSet(); |
|
226 | QBoxSet *set4 = new QBoxSet(); | |
223 | QBoxSet *set5 = new QBoxSet(); |
|
227 | QBoxSet *set5 = new QBoxSet(); | |
224 |
|
228 | |||
225 | // low bot med top upp |
|
229 | // low bot med top upp | |
226 | *set0 << -1 << 2 << 4 << 13 << 15; |
|
230 | *set0 << -1 << 2 << 4 << 13 << 15; | |
227 | *set1 << 5 << 6 << 7.5 << 8 << 12; |
|
231 | *set1 << 5 << 6 << 7.5 << 8 << 12; | |
228 | *set2 << 3 << 5 << 5.7 << 8 << 9; |
|
232 | *set2 << 3 << 5 << 5.7 << 8 << 9; | |
229 | *set3 << 5 << 6 << 6.8 << 7 << 8; |
|
233 | *set3 << 5 << 6 << 6.8 << 7 << 8; | |
230 | *set4 << 4 << 5 << 5.2 << 6 << 7; |
|
234 | *set4 << 4 << 5 << 5.2 << 6 << 7; | |
231 | *set5 << 4 << 7 << 8.2 << 9 << 10; |
|
235 | *set5 << 4 << 7 << 8.2 << 9 << 10; | |
232 |
|
236 | |||
233 | m_series[m_seriesCount] = new QBoxPlotSeries(); |
|
237 | m_series[m_seriesCount] = new QBoxPlotSeries(); | |
234 | m_series[m_seriesCount]->append(set0); |
|
238 | m_series[m_seriesCount]->append(set0); | |
235 | m_series[m_seriesCount]->append(set1); |
|
239 | m_series[m_seriesCount]->append(set1); | |
236 | m_series[m_seriesCount]->append(set2); |
|
240 | m_series[m_seriesCount]->append(set2); | |
237 | m_series[m_seriesCount]->append(set3); |
|
241 | m_series[m_seriesCount]->append(set3); | |
238 | m_series[m_seriesCount]->append(set4); |
|
242 | m_series[m_seriesCount]->append(set4); | |
239 | m_series[m_seriesCount]->append(set5); |
|
243 | m_series[m_seriesCount]->append(set5); | |
240 | m_series[m_seriesCount]->setName("Box & Whiskers"); |
|
244 | m_series[m_seriesCount]->setName("Box & Whiskers"); | |
241 |
|
245 | |||
242 | connect(m_series[m_seriesCount], SIGNAL(clicked(QBoxSet*)), this, SLOT(boxClicked(QBoxSet*))); |
|
246 | connect(m_series[m_seriesCount], SIGNAL(clicked(QBoxSet*)), this, SLOT(boxClicked(QBoxSet*))); | |
243 | connect(m_series[m_seriesCount], SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(boxHovered(bool, QBoxSet*))); |
|
247 | connect(m_series[m_seriesCount], SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(boxHovered(bool, QBoxSet*))); | |
244 | connect(set1, SIGNAL(clicked()), this, SLOT(singleBoxClicked())); |
|
248 | connect(set1, SIGNAL(clicked()), this, SLOT(singleBoxClicked())); | |
245 | connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool))); |
|
249 | connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool))); | |
246 |
|
250 | |||
|
251 | m_series[m_seriesCount]->setBoxOutlineVisible(m_boxOutlined->checkState()); | |||
|
252 | ||||
247 | m_chart->addSeries(m_series[m_seriesCount]); |
|
253 | m_chart->addSeries(m_series[m_seriesCount]); | |
248 |
|
254 | |||
249 | updateAxis(m_series[0]->count()); |
|
255 | updateAxis(m_series[0]->count()); | |
250 | m_chart->setAxisX(m_axis, m_series[m_seriesCount]); |
|
256 | m_chart->setAxisX(m_axis, m_series[m_seriesCount]); | |
251 |
|
257 | |||
252 | m_seriesCount++; |
|
258 | m_seriesCount++; | |
253 | } |
|
259 | } | |
254 |
|
260 | |||
255 | void MainWidget::removeSeries() |
|
261 | void MainWidget::removeSeries() | |
256 | { |
|
262 | { | |
257 | qDebug() << "BoxPlotTester::MainWidget::removeSeries()"; |
|
263 | qDebug() << "BoxPlotTester::MainWidget::removeSeries()"; | |
258 |
|
264 | |||
259 | if (m_seriesCount > 0) { |
|
265 | if (m_seriesCount > 0) { | |
260 | m_seriesCount--; |
|
266 | m_seriesCount--; | |
261 | m_chart->removeSeries(m_series[m_seriesCount]); |
|
267 | m_chart->removeSeries(m_series[m_seriesCount]); | |
262 | delete m_series[m_seriesCount]; |
|
268 | delete m_series[m_seriesCount]; | |
263 | m_series[m_seriesCount] = 0; |
|
269 | m_series[m_seriesCount] = 0; | |
264 | } else { |
|
270 | } else { | |
265 | qDebug() << "Create a series first"; |
|
271 | qDebug() << "Create a series first"; | |
266 | } |
|
272 | } | |
267 | } |
|
273 | } | |
268 |
|
274 | |||
269 | void MainWidget::addBox() |
|
275 | void MainWidget::addBox() | |
270 | { |
|
276 | { | |
271 | qDebug() << "BoxPlotTester::MainWidget::addBox()"; |
|
277 | qDebug() << "BoxPlotTester::MainWidget::addBox()"; | |
272 |
|
278 | |||
273 | if (m_seriesCount > 0 && m_series[0]->count() < maxCategories) { |
|
279 | if (m_seriesCount > 0 && m_series[0]->count() < maxCategories) { | |
274 | QBoxSet *newSet = new QBoxSet(); |
|
280 | QBoxSet *newSet = new QBoxSet(); | |
275 | newSet->setValue(QBoxSet::LowerExtreme, 5.0); |
|
281 | newSet->setValue(QBoxSet::LowerExtreme, 5.0); | |
276 | newSet->setValue(QBoxSet::LowerQuartile, 6.0); |
|
282 | newSet->setValue(QBoxSet::LowerQuartile, 6.0); | |
277 | newSet->setValue(QBoxSet::Median, 6.8); |
|
283 | newSet->setValue(QBoxSet::Median, 6.8); | |
278 | newSet->setValue(QBoxSet::UpperQuartile, 7.0); |
|
284 | newSet->setValue(QBoxSet::UpperQuartile, 7.0); | |
279 | newSet->setValue(QBoxSet::UpperExtreme, 8.0); |
|
285 | newSet->setValue(QBoxSet::UpperExtreme, 8.0); | |
280 |
|
286 | |||
281 | updateAxis(m_series[0]->count() + 1); |
|
287 | updateAxis(m_series[0]->count() + 1); | |
282 |
|
288 | |||
283 | m_series[0]->append(newSet); |
|
289 | m_series[0]->append(newSet); | |
284 | } |
|
290 | } | |
285 | } |
|
291 | } | |
286 |
|
292 | |||
287 | void MainWidget::insertBox() |
|
293 | void MainWidget::insertBox() | |
288 | { |
|
294 | { | |
289 | qDebug() << "BoxPlotTester::MainWidget::insertBox()"; |
|
295 | qDebug() << "BoxPlotTester::MainWidget::insertBox()"; | |
290 |
|
296 | |||
291 | if (m_seriesCount > 0 && m_series[0]->count() < maxCategories) { |
|
297 | if (m_seriesCount > 0 && m_series[0]->count() < maxCategories) { | |
292 | updateAxis(m_series[0]->count() + 1); |
|
298 | updateAxis(m_series[0]->count() + 1); | |
293 | for (int i = 0; i < m_seriesCount; i++) { |
|
299 | for (int i = 0; i < m_seriesCount; i++) { | |
294 | QBoxSet *newSet = new QBoxSet(); |
|
300 | QBoxSet *newSet = new QBoxSet(); | |
295 | *newSet << 2 << 6 << 6.8 << 7 << 10; |
|
301 | *newSet << 2 << 6 << 6.8 << 7 << 10; | |
296 | m_series[i]->insert(1, newSet); |
|
302 | m_series[i]->insert(1, newSet); | |
297 | } |
|
303 | } | |
298 | } |
|
304 | } | |
299 | } |
|
305 | } | |
300 |
|
306 | |||
301 | void MainWidget::removeBox() |
|
307 | void MainWidget::removeBox() | |
302 | { |
|
308 | { | |
303 | qDebug() << "BoxPlotTester::MainWidget::removeBox"; |
|
309 | qDebug() << "BoxPlotTester::MainWidget::removeBox"; | |
304 |
|
310 | |||
305 | if (m_seriesCount > 0) { |
|
311 | if (m_seriesCount > 0) { | |
306 | for (int i = 0; i < m_seriesCount; i++) { |
|
312 | for (int i = 0; i < m_seriesCount; i++) { | |
307 | qDebug() << "m_series[i]->count() = " << m_series[i]->count(); |
|
313 | qDebug() << "m_series[i]->count() = " << m_series[i]->count(); | |
308 | if (m_series[i]->count()) { |
|
314 | if (m_series[i]->count()) { | |
309 | QList<QBoxSet *> sets = m_series[i]->boxSets(); |
|
315 | QList<QBoxSet *> sets = m_series[i]->boxSets(); | |
310 | m_series[i]->remove(sets.at(m_series[i]->count() - 1)); |
|
316 | m_series[i]->remove(sets.at(m_series[i]->count() - 1)); | |
311 | } |
|
317 | } | |
312 | } |
|
318 | } | |
313 |
|
319 | |||
314 | updateAxis(m_series[0]->count()); |
|
320 | updateAxis(m_series[0]->count()); | |
315 | } else { |
|
321 | } else { | |
316 | qDebug() << "Create a series first"; |
|
322 | qDebug() << "Create a series first"; | |
317 | } |
|
323 | } | |
318 | } |
|
324 | } | |
319 |
|
325 | |||
320 | void MainWidget::clear() |
|
326 | void MainWidget::clear() | |
321 | { |
|
327 | { | |
322 | qDebug() << "BoxPlotTester::MainWidget::clear"; |
|
328 | qDebug() << "BoxPlotTester::MainWidget::clear"; | |
323 |
|
329 | |||
324 | if (m_seriesCount > 0) |
|
330 | if (m_seriesCount > 0) | |
325 | m_series[0]->clear(); |
|
331 | m_series[0]->clear(); | |
326 | else |
|
332 | else | |
327 | qDebug() << "Create a series first"; |
|
333 | qDebug() << "Create a series first"; | |
328 | } |
|
334 | } | |
329 |
|
335 | |||
330 | void MainWidget::clearBox() |
|
336 | void MainWidget::clearBox() | |
331 | { |
|
337 | { | |
332 | qDebug() << "BoxPlotTester::MainWidget::clearBox"; |
|
338 | qDebug() << "BoxPlotTester::MainWidget::clearBox"; | |
333 |
|
339 | |||
334 | if (m_seriesCount > 0) { |
|
340 | if (m_seriesCount > 0) { | |
335 | QList<QBoxSet *> sets = m_series[0]->boxSets(); |
|
341 | QList<QBoxSet *> sets = m_series[0]->boxSets(); | |
336 | sets.at(1)->clear(); |
|
342 | sets.at(1)->clear(); | |
337 | } else { |
|
343 | } else { | |
338 | qDebug() << "Create a series first"; |
|
344 | qDebug() << "Create a series first"; | |
339 | } |
|
345 | } | |
340 | } |
|
346 | } | |
341 |
|
347 | |||
342 | void MainWidget::setBrush() |
|
348 | void MainWidget::setBrush() | |
343 | { |
|
349 | { | |
344 | qDebug() << "BoxPlotTester::MainWidget::setBrush"; |
|
350 | qDebug() << "BoxPlotTester::MainWidget::setBrush"; | |
345 |
|
351 | |||
346 | if (m_seriesCount > 0) { |
|
352 | if (m_seriesCount > 0) { | |
347 | QList<QBoxSet *> sets = m_series[0]->boxSets(); |
|
353 | QList<QBoxSet *> sets = m_series[0]->boxSets(); | |
348 | sets.at(1)->setBrush(QBrush(QColor(Qt::yellow))); |
|
354 | sets.at(1)->setBrush(QBrush(QColor(Qt::yellow))); | |
349 | } else { |
|
355 | } else { | |
350 | qDebug() << "Create a series first"; |
|
356 | qDebug() << "Create a series first"; | |
351 | } |
|
357 | } | |
352 | } |
|
358 | } | |
353 |
|
359 | |||
354 | void MainWidget::animationToggled(bool enabled) |
|
360 | void MainWidget::animationToggled(bool enabled) | |
355 | { |
|
361 | { | |
356 | qDebug() << "BoxPlotTester::Animation toggled to " << enabled; |
|
362 | qDebug() << "BoxPlotTester::Animation toggled to " << enabled; | |
357 | if (enabled) |
|
363 | if (enabled) | |
358 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
364 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
359 | else |
|
365 | else | |
360 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
366 | m_chart->setAnimationOptions(QChart::NoAnimation); | |
361 | } |
|
367 | } | |
362 |
|
368 | |||
363 | void MainWidget::legendToggled(bool enabled) |
|
369 | void MainWidget::legendToggled(bool enabled) | |
364 | { |
|
370 | { | |
365 | qDebug() << "BoxPlotTester::Legend toggled to " << enabled; |
|
371 | qDebug() << "BoxPlotTester::Legend toggled to " << enabled; | |
366 | m_chart->legend()->setVisible(enabled); |
|
372 | m_chart->legend()->setVisible(enabled); | |
367 | if (enabled) |
|
373 | if (enabled) | |
368 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
374 | m_chart->legend()->setAlignment(Qt::AlignBottom); | |
369 | } |
|
375 | } | |
370 |
|
376 | |||
371 | void MainWidget::titleToggled(bool enabled) |
|
377 | void MainWidget::titleToggled(bool enabled) | |
372 | { |
|
378 | { | |
373 | qDebug() << "BoxPlotTester::Title toggled to " << enabled; |
|
379 | qDebug() << "BoxPlotTester::Title toggled to " << enabled; | |
374 | if (enabled) |
|
380 | if (enabled) | |
375 | m_chart->setTitle("Simple boxplotchart example"); |
|
381 | m_chart->setTitle("Simple boxplotchart example"); | |
376 | else |
|
382 | else | |
377 | m_chart->setTitle(""); |
|
383 | m_chart->setTitle(""); | |
378 | } |
|
384 | } | |
379 |
|
385 | |||
380 | void MainWidget::antialiasingToggled(bool enabled) |
|
386 | void MainWidget::antialiasingToggled(bool enabled) | |
381 | { |
|
387 | { | |
382 | qDebug() << "BoxPlotTester::antialiasingToggled toggled to " << enabled; |
|
388 | qDebug() << "BoxPlotTester::antialiasingToggled toggled to " << enabled; | |
383 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
389 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); | |
384 | } |
|
390 | } | |
385 |
|
391 | |||
|
392 | void MainWidget::boxOutlineToggled(bool visible) | |||
|
393 | { | |||
|
394 | qDebug() << "BoxPlotTester::boxOutlineToggled toggled to " << visible; | |||
|
395 | for (int i = 0; i < m_seriesCount; i++) | |||
|
396 | m_series[i]->setBoxOutlineVisible(visible); | |||
|
397 | } | |||
|
398 | ||||
386 | void MainWidget::modelMapperToggled(bool enabled) |
|
399 | void MainWidget::modelMapperToggled(bool enabled) | |
387 | { |
|
400 | { | |
388 | if (enabled) { |
|
401 | if (enabled) { | |
389 | m_series[m_seriesCount] = new QBoxPlotSeries(); |
|
402 | m_series[m_seriesCount] = new QBoxPlotSeries(); | |
390 |
|
403 | |||
391 | int first = 0; |
|
404 | int first = 0; | |
392 | int count = 5; |
|
405 | int count = 5; | |
393 | QVBoxPlotModelMapper *mapper = new QVBoxPlotModelMapper(this); |
|
406 | QVBoxPlotModelMapper *mapper = new QVBoxPlotModelMapper(this); | |
394 | mapper->setFirstBoxSetColumn(0); |
|
407 | mapper->setFirstBoxSetColumn(0); | |
395 | mapper->setLastBoxSetColumn(5); |
|
408 | mapper->setLastBoxSetColumn(5); | |
396 | mapper->setFirstRow(first); |
|
409 | mapper->setFirstRow(first); | |
397 | mapper->setRowCount(count); |
|
410 | mapper->setRowCount(count); | |
398 | mapper->setSeries(m_series[m_seriesCount]); |
|
411 | mapper->setSeries(m_series[m_seriesCount]); | |
399 | mapper->setModel(m_model); |
|
412 | mapper->setModel(m_model); | |
400 | m_chart->addSeries(m_series[m_seriesCount]); |
|
413 | m_chart->addSeries(m_series[m_seriesCount]); | |
401 |
|
414 | |||
402 | m_seriesCount++; |
|
415 | m_seriesCount++; | |
403 | } else { |
|
416 | } else { | |
404 | removeSeries(); |
|
417 | removeSeries(); | |
405 | } |
|
418 | } | |
406 | } |
|
419 | } | |
407 |
|
420 | |||
408 | void MainWidget::changeChartTheme(int themeIndex) |
|
421 | void MainWidget::changeChartTheme(int themeIndex) | |
409 | { |
|
422 | { | |
410 | qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex; |
|
423 | qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex; | |
411 | if (themeIndex == 0) |
|
424 | if (themeIndex == 0) | |
412 | m_chart->setTheme(QChart::ChartThemeLight); |
|
425 | m_chart->setTheme(QChart::ChartThemeLight); | |
413 | else |
|
426 | else | |
414 | m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1)); |
|
427 | m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1)); | |
415 | } |
|
428 | } | |
416 |
|
429 | |||
417 | void MainWidget::boxClicked(QBoxSet *set) |
|
430 | void MainWidget::boxClicked(QBoxSet *set) | |
418 | { |
|
431 | { | |
419 | qDebug() << "boxClicked, median = " << set->at(QBoxSet::Median); |
|
432 | qDebug() << "boxClicked, median = " << set->at(QBoxSet::Median); | |
420 | } |
|
433 | } | |
421 |
|
434 | |||
422 | void MainWidget::boxHovered(bool state, QBoxSet *set) |
|
435 | void MainWidget::boxHovered(bool state, QBoxSet *set) | |
423 | { |
|
436 | { | |
424 | if (state) |
|
437 | if (state) | |
425 | qDebug() << "box median " << set->at(QBoxSet::Median) << " hover started"; |
|
438 | qDebug() << "box median " << set->at(QBoxSet::Median) << " hover started"; | |
426 | else |
|
439 | else | |
427 | qDebug() << "box median " << set->at(QBoxSet::Median) << " hover ended"; |
|
440 | qDebug() << "box median " << set->at(QBoxSet::Median) << " hover ended"; | |
428 | } |
|
441 | } | |
429 |
|
442 | |||
430 | void MainWidget::singleBoxClicked() |
|
443 | void MainWidget::singleBoxClicked() | |
431 | { |
|
444 | { | |
432 | qDebug() << "singleBoxClicked"; |
|
445 | qDebug() << "singleBoxClicked"; | |
433 | } |
|
446 | } | |
434 |
|
447 | |||
435 | void MainWidget::singleBoxHovered(bool state) |
|
448 | void MainWidget::singleBoxHovered(bool state) | |
436 | { |
|
449 | { | |
437 | if (state) |
|
450 | if (state) | |
438 | qDebug() << "single box hover started"; |
|
451 | qDebug() << "single box hover started"; | |
439 | else |
|
452 | else | |
440 | qDebug() << "single box hover ended"; |
|
453 | qDebug() << "single box hover ended"; | |
441 | } |
|
454 | } | |
442 |
|
455 | |||
443 | void MainWidget::changePen() |
|
456 | void MainWidget::changePen() | |
444 | { |
|
457 | { | |
445 | qDebug() << "changePen() = " << m_penTool->pen(); |
|
458 | qDebug() << "changePen() = " << m_penTool->pen(); | |
446 | for (int i = 0; i < m_seriesCount; i++) |
|
459 | for (int i = 0; i < m_seriesCount; i++) | |
447 | m_series[i]->setPen(m_penTool->pen()); |
|
460 | m_series[i]->setPen(m_penTool->pen()); | |
448 |
|
||||
449 | } |
|
461 | } |
@@ -1,84 +1,87 | |||||
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 MAINWIDGET_H |
|
21 | #ifndef MAINWIDGET_H | |
22 | #define MAINWIDGET_H |
|
22 | #define MAINWIDGET_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "qchart.h" |
|
25 | #include "qchart.h" | |
26 | #include "qchartview.h" |
|
26 | #include "qchartview.h" | |
27 | #include "customtablemodel.h" |
|
27 | #include "customtablemodel.h" | |
28 | #include "pentool.h" |
|
28 | #include "pentool.h" | |
29 | #include <QWidget> |
|
29 | #include <QWidget> | |
30 | #include <QBoxPlotSeries> |
|
30 | #include <QBoxPlotSeries> | |
31 | #include <QBarCategoryAxis> |
|
31 | #include <QBarCategoryAxis> | |
32 | #include <QBoxSet> |
|
32 | #include <QBoxSet> | |
|
33 | #include <QCheckBox> | |||
33 |
|
34 | |||
34 | class QGridLayout; |
|
35 | class QGridLayout; | |
35 |
|
36 | |||
36 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
37 | QTCOMMERCIALCHART_USE_NAMESPACE | |
37 |
|
38 | |||
38 | class MainWidget : public QWidget |
|
39 | class MainWidget : public QWidget | |
39 | { |
|
40 | { | |
40 | Q_OBJECT |
|
41 | Q_OBJECT | |
41 | public: |
|
42 | public: | |
42 | explicit MainWidget(QWidget *parent = 0); |
|
43 | explicit MainWidget(QWidget *parent = 0); | |
43 |
|
44 | |||
44 | signals: |
|
45 | signals: | |
45 |
|
46 | |||
46 | private: |
|
47 | private: | |
47 | void initThemeCombo(QGridLayout *grid); |
|
48 | void initThemeCombo(QGridLayout *grid); | |
48 | void initCheckboxes(QGridLayout *grid); |
|
49 | void initCheckboxes(QGridLayout *grid); | |
49 | void updateAxis(int categoryCount); |
|
50 | void updateAxis(int categoryCount); | |
50 |
|
51 | |||
51 | private slots: |
|
52 | private slots: | |
52 | void addSeries(); |
|
53 | void addSeries(); | |
53 | void removeSeries(); |
|
54 | void removeSeries(); | |
54 | void addBox(); |
|
55 | void addBox(); | |
55 | void insertBox(); |
|
56 | void insertBox(); | |
56 | void removeBox(); |
|
57 | void removeBox(); | |
57 | void clear(); |
|
58 | void clear(); | |
58 | void clearBox(); |
|
59 | void clearBox(); | |
59 | void setBrush(); |
|
60 | void setBrush(); | |
60 | void animationToggled(bool enabled); |
|
61 | void animationToggled(bool enabled); | |
61 | void legendToggled(bool enabled); |
|
62 | void legendToggled(bool enabled); | |
62 | void titleToggled(bool enabled); |
|
63 | void titleToggled(bool enabled); | |
63 | void modelMapperToggled(bool enabled); |
|
64 | void modelMapperToggled(bool enabled); | |
64 | void changeChartTheme(int themeIndex); |
|
65 | void changeChartTheme(int themeIndex); | |
65 | void boxClicked(QBoxSet *set); |
|
66 | void boxClicked(QBoxSet *set); | |
66 | void boxHovered(bool state, QBoxSet *set); |
|
67 | void boxHovered(bool state, QBoxSet *set); | |
67 | void singleBoxClicked(); |
|
68 | void singleBoxClicked(); | |
68 | void singleBoxHovered(bool state); |
|
69 | void singleBoxHovered(bool state); | |
69 | void changePen(); |
|
70 | void changePen(); | |
70 | void antialiasingToggled(bool); |
|
71 | void antialiasingToggled(bool); | |
|
72 | void boxOutlineToggled(bool); | |||
71 |
|
73 | |||
72 | private: |
|
74 | private: | |
73 | QChart *m_chart; |
|
75 | QChart *m_chart; | |
74 | QChartView *m_chartView; |
|
76 | QChartView *m_chartView; | |
75 | QGridLayout *m_scatterLayout; |
|
77 | QGridLayout *m_scatterLayout; | |
76 | QBarCategoryAxis *m_axis; |
|
78 | QBarCategoryAxis *m_axis; | |
77 | CustomTableModel *m_model; |
|
79 | CustomTableModel *m_model; | |
78 | PenTool *m_penTool; |
|
80 | PenTool *m_penTool; | |
79 | int m_rowPos; |
|
81 | int m_rowPos; | |
80 | int m_seriesCount; |
|
82 | int m_seriesCount; | |
81 | QBoxPlotSeries *m_series[10]; |
|
83 | QBoxPlotSeries *m_series[10]; | |
|
84 | QCheckBox *m_boxOutlined; | |||
82 | }; |
|
85 | }; | |
83 |
|
86 | |||
84 | #endif // MAINWIDGET_H |
|
87 | #endif // MAINWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now