@@ -1,703 +1,709 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2015 The Qt Company Ltd |
|
3 | ** Copyright (C) 2015 The Qt Company Ltd | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to The Qt Company, please use contact form at http://qt.io |
|
5 | ** For any questions to The Qt Company, please use contact form at http://qt.io | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Charts module. |
|
7 | ** This file is part of the Qt Charts module. | |
8 | ** |
|
8 | ** | |
9 | ** Licensees holding valid commercial license for Qt may use this file in |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
10 | ** accordance with the Qt License Agreement provided with the Software |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
11 | ** or, alternatively, in accordance with the terms contained in a written |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
12 | ** agreement between you and The Qt Company. |
|
12 | ** agreement between you and The Qt Company. | |
13 | ** |
|
13 | ** | |
14 | ** If you have questions regarding the use of this file, please use |
|
14 | ** If you have questions regarding the use of this file, please use | |
15 | ** contact form at http://qt.io |
|
15 | ** contact form at http://qt.io | |
16 | ** |
|
16 | ** | |
17 | ****************************************************************************/ |
|
17 | ****************************************************************************/ | |
18 |
|
18 | |||
19 | #include <QtCharts/QBoxPlotSeries> |
|
19 | #include <QtCharts/QBoxPlotSeries> | |
20 | #include <private/qboxplotseries_p.h> |
|
20 | #include <private/qboxplotseries_p.h> | |
21 | #include <QtCharts/QBoxPlotLegendMarker> |
|
21 | #include <QtCharts/QBoxPlotLegendMarker> | |
22 | #include <QtCharts/QBarCategoryAxis> |
|
22 | #include <QtCharts/QBarCategoryAxis> | |
23 | #include <private/boxplotchartitem_p.h> |
|
23 | #include <private/boxplotchartitem_p.h> | |
24 | #include <private/chartdataset_p.h> |
|
24 | #include <private/chartdataset_p.h> | |
25 | #include <private/charttheme_p.h> |
|
25 | #include <private/charttheme_p.h> | |
26 | #include <QtCharts/QValueAxis> |
|
26 | #include <QtCharts/QValueAxis> | |
27 | #include <private/charttheme_p.h> |
|
27 | #include <private/charttheme_p.h> | |
28 | #include <private/boxplotanimation_p.h> |
|
28 | #include <private/boxplotanimation_p.h> | |
29 | #include <private/qchart_p.h> |
|
29 | #include <private/qchart_p.h> | |
30 | #include <QtCharts/QBoxSet> |
|
30 | #include <QtCharts/QBoxSet> | |
31 | #include <private/qboxset_p.h> |
|
31 | #include <private/qboxset_p.h> | |
32 |
|
32 | |||
33 | QT_CHARTS_BEGIN_NAMESPACE |
|
33 | QT_CHARTS_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 | /*! |
|
35 | /*! | |
36 | \class QBoxPlotSeries |
|
36 | \class QBoxPlotSeries | |
37 | \inmodule Qt Charts |
|
37 | \inmodule Qt Charts | |
38 | \brief Series for creating box-and-whiskers chart. |
|
38 | \brief Series for creating box-and-whiskers chart. | |
39 |
|
39 | |||
40 |
QBoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this |
|
40 | QBoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this | |
41 |
a container for single box-and-whisker items. Each item is drawn to own slot. |
|
41 | class is to act as a container for single box-and-whisker items. Each item is drawn to own slot. | |
42 |
QBoxPlotSeries then box-and-whiskers items with the same |
|
42 | If chart includes multiple instances of QBoxPlotSeries then box-and-whiskers items with the same | |
|
43 | index are drawn to same slot. | |||
43 |
|
44 | |||
44 | See the \l {Box and Whiskers Example} {box-and-whiskers chart example} to learn how to create a box-and-whiskers chart. |
|
45 | \note The slot, each item in QBoxPlotSeries is drawn, represents a category in QBarCategoryAxis. | |
|
46 | The category labels have to be unique. If same category label is defined for several | |||
|
47 | box-and-whisker items only the first one is drawn. | |||
|
48 | ||||
|
49 | See the \l {Box and Whiskers Example} {box-and-whiskers chart example} to learn how to create a | |||
|
50 | box-and-whiskers chart. | |||
45 | \image examples_boxplotchart.png |
|
51 | \image examples_boxplotchart.png | |
46 |
|
52 | |||
47 | \sa QBoxSet |
|
53 | \sa QBoxSet, QBarCategoryAxis | |
48 | */ |
|
54 | */ | |
49 | /*! |
|
55 | /*! | |
50 | \fn QBoxPlotSeries::boxsetsAdded(QList<QBoxSet *> sets) |
|
56 | \fn QBoxPlotSeries::boxsetsAdded(QList<QBoxSet *> sets) | |
51 | \brief Signal is emitted when a new \a sets of box-and-whiskers data is added to the series. |
|
57 | \brief Signal is emitted when a new \a sets of box-and-whiskers data is added to the series. | |
52 | */ |
|
58 | */ | |
53 | /*! |
|
59 | /*! | |
54 | \fn QBoxPlotSeries::boxsetsRemoved(QList<QBoxSet *> sets) |
|
60 | \fn QBoxPlotSeries::boxsetsRemoved(QList<QBoxSet *> sets) | |
55 | \brief Signal is emitted when \a sets of box-and-whiskers data is removed from the series. |
|
61 | \brief Signal is emitted when \a sets of box-and-whiskers data is removed from the series. | |
56 | */ |
|
62 | */ | |
57 | /*! |
|
63 | /*! | |
58 | \fn QBoxPlotSeries::clicked(QBoxSet *boxset) |
|
64 | \fn QBoxPlotSeries::clicked(QBoxSet *boxset) | |
59 | \brief Signal is emitted when the user clicks the \a boxset on the chart. |
|
65 | \brief Signal is emitted when the user clicks the \a boxset on the chart. | |
60 | */ |
|
66 | */ | |
61 | /*! |
|
67 | /*! | |
62 | \fn QBoxPlotSeries::pressed(QBoxSet *boxset) |
|
68 | \fn QBoxPlotSeries::pressed(QBoxSet *boxset) | |
63 | \brief Signal is emitted when the user presses the \a boxset on the chart. |
|
69 | \brief Signal is emitted when the user presses the \a boxset on the chart. | |
64 | */ |
|
70 | */ | |
65 | /*! |
|
71 | /*! | |
66 | \fn QBoxPlotSeries::released(QBoxSet *boxset) |
|
72 | \fn QBoxPlotSeries::released(QBoxSet *boxset) | |
67 | \brief Signal is emitted when the user releases the \a boxset on the chart. |
|
73 | \brief Signal is emitted when the user releases the \a boxset on the chart. | |
68 | */ |
|
74 | */ | |
69 | /*! |
|
75 | /*! | |
70 | \fn QBoxPlotSeries::doubleClicked(QBoxSet *boxset) |
|
76 | \fn QBoxPlotSeries::doubleClicked(QBoxSet *boxset) | |
71 | \brief Signal is emitted when the user doubleclicks the \a boxset on the chart. |
|
77 | \brief Signal is emitted when the user doubleclicks the \a boxset on the chart. | |
72 | */ |
|
78 | */ | |
73 | /*! |
|
79 | /*! | |
74 | \fn QBoxPlotSeries::hovered(bool status, QBoxSet *boxset) |
|
80 | \fn QBoxPlotSeries::hovered(bool status, QBoxSet *boxset) | |
75 | \brief Signal is emitted when there is change in hover \a status over \a boxset. |
|
81 | \brief Signal is emitted when there is change in hover \a status over \a boxset. | |
76 | */ |
|
82 | */ | |
77 | /*! |
|
83 | /*! | |
78 | \fn QBoxPlotSeries::countChanged() |
|
84 | \fn QBoxPlotSeries::countChanged() | |
79 | \brief Signal is emitted when there is change in count of box-and-whiskers items in the series. |
|
85 | \brief Signal is emitted when there is change in count of box-and-whiskers items in the series. | |
80 | */ |
|
86 | */ | |
81 | /*! |
|
87 | /*! | |
82 | \property QBoxPlotSeries::boxOutlineVisible |
|
88 | \property QBoxPlotSeries::boxOutlineVisible | |
83 | \brief This property configures the visibility of the middle box outline. |
|
89 | \brief This property configures the visibility of the middle box outline. | |
84 | */ |
|
90 | */ | |
85 | /*! |
|
91 | /*! | |
86 | \property QBoxPlotSeries::boxWidth |
|
92 | \property QBoxPlotSeries::boxWidth | |
87 | \brief This property configures the width of the box-and-whiskers item. The value signifies the relative |
|
93 | \brief This property configures the width of the box-and-whiskers item. The value signifies the relative | |
88 | width of the box-and-whiskers item inside its own slot. The value can between 0.0 and 1.0. Negative values |
|
94 | width of the box-and-whiskers item inside its own slot. The value can between 0.0 and 1.0. Negative values | |
89 | are clamped to 0.0 and values over 1.0 are clamped to 1.0. |
|
95 | are clamped to 0.0 and values over 1.0 are clamped to 1.0. | |
90 | */ |
|
96 | */ | |
91 | /*! |
|
97 | /*! | |
92 | \property QBoxPlotSeries::pen |
|
98 | \property QBoxPlotSeries::pen | |
93 | \brief This property configures the pen of the box-and-whiskers items. |
|
99 | \brief This property configures the pen of the box-and-whiskers items. | |
94 | */ |
|
100 | */ | |
95 | /*! |
|
101 | /*! | |
96 | \property QBoxPlotSeries::brush |
|
102 | \property QBoxPlotSeries::brush | |
97 | \brief This property configures the brush of the box-and-whiskers items. |
|
103 | \brief This property configures the brush of the box-and-whiskers items. | |
98 | */ |
|
104 | */ | |
99 | /*! |
|
105 | /*! | |
100 | \property QBoxPlotSeries::count |
|
106 | \property QBoxPlotSeries::count | |
101 | \brief The count of sets in series. |
|
107 | \brief The count of sets in series. | |
102 | */ |
|
108 | */ | |
103 |
|
109 | |||
104 | /*! |
|
110 | /*! | |
105 | \qmlproperty QString BoxPlotSeries::brushFilename |
|
111 | \qmlproperty QString BoxPlotSeries::brushFilename | |
106 | The name of the file used as a brush for the series. |
|
112 | The name of the file used as a brush for the series. | |
107 | */ |
|
113 | */ | |
108 |
|
114 | |||
109 | /*! |
|
115 | /*! | |
110 | \fn void QBoxPlotSeries::boxOutlineVisibilityChanged() |
|
116 | \fn void QBoxPlotSeries::boxOutlineVisibilityChanged() | |
111 | Signal is emitted when the middle box outline visibility is changed. |
|
117 | Signal is emitted when the middle box outline visibility is changed. | |
112 | */ |
|
118 | */ | |
113 | /*! |
|
119 | /*! | |
114 | \fn void QBoxPlotSeries::boxWidthChanged() |
|
120 | \fn void QBoxPlotSeries::boxWidthChanged() | |
115 | Signal is emitted when the width of the box-and-whiskers item is changed. |
|
121 | Signal is emitted when the width of the box-and-whiskers item is changed. | |
116 | */ |
|
122 | */ | |
117 | /*! |
|
123 | /*! | |
118 | \fn void QBoxPlotSeries::penChanged() |
|
124 | \fn void QBoxPlotSeries::penChanged() | |
119 | This signal is emitted when the pen of the box-and-whiskers has changed. |
|
125 | This signal is emitted when the pen of the box-and-whiskers has changed. | |
120 | \sa brush |
|
126 | \sa brush | |
121 | */ |
|
127 | */ | |
122 | /*! |
|
128 | /*! | |
123 | \fn void QBoxPlotSeries::brushChanged() |
|
129 | \fn void QBoxPlotSeries::brushChanged() | |
124 | This signal is emitted when the brush of the box-and-whiskers has changed. |
|
130 | This signal is emitted when the brush of the box-and-whiskers has changed. | |
125 | \sa brush |
|
131 | \sa brush | |
126 | */ |
|
132 | */ | |
127 | /*! |
|
133 | /*! | |
128 | \fn virtual SeriesType QBoxPlotSeries::type() const |
|
134 | \fn virtual SeriesType QBoxPlotSeries::type() const | |
129 | \brief Returns type of series. |
|
135 | \brief Returns type of series. | |
130 | \sa QAbstractSeries, SeriesType |
|
136 | \sa QAbstractSeries, SeriesType | |
131 | */ |
|
137 | */ | |
132 |
|
138 | |||
133 | /*! |
|
139 | /*! | |
134 | Constructs empty QBoxPlotSeries. |
|
140 | Constructs empty QBoxPlotSeries. | |
135 | QBoxPlotSeries is QObject which is a child of a \a parent. |
|
141 | QBoxPlotSeries is QObject which is a child of a \a parent. | |
136 | */ |
|
142 | */ | |
137 | QBoxPlotSeries::QBoxPlotSeries(QObject *parent) |
|
143 | QBoxPlotSeries::QBoxPlotSeries(QObject *parent) | |
138 | : QAbstractSeries(*new QBoxPlotSeriesPrivate(this), parent) |
|
144 | : QAbstractSeries(*new QBoxPlotSeriesPrivate(this), parent) | |
139 | { |
|
145 | { | |
140 | } |
|
146 | } | |
141 |
|
147 | |||
142 | /*! |
|
148 | /*! | |
143 | Destructor. Removes series from chart. |
|
149 | Destructor. Removes series from chart. | |
144 | */ |
|
150 | */ | |
145 | QBoxPlotSeries::~QBoxPlotSeries() |
|
151 | QBoxPlotSeries::~QBoxPlotSeries() | |
146 | { |
|
152 | { | |
147 | Q_D(QBoxPlotSeries); |
|
153 | Q_D(QBoxPlotSeries); | |
148 | if (d->m_chart) |
|
154 | if (d->m_chart) | |
149 | d->m_chart->removeSeries(this); |
|
155 | d->m_chart->removeSeries(this); | |
150 | } |
|
156 | } | |
151 |
|
157 | |||
152 | /*! |
|
158 | /*! | |
153 | 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. |
|
159 | 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. | |
154 | Returns true, if appending succeeded. |
|
160 | Returns true, if appending succeeded. | |
155 | */ |
|
161 | */ | |
156 | bool QBoxPlotSeries::append(QBoxSet *set) |
|
162 | bool QBoxPlotSeries::append(QBoxSet *set) | |
157 | { |
|
163 | { | |
158 | Q_D(QBoxPlotSeries); |
|
164 | Q_D(QBoxPlotSeries); | |
159 |
|
165 | |||
160 | bool success = d->append(set); |
|
166 | bool success = d->append(set); | |
161 | if (success) { |
|
167 | if (success) { | |
162 | QList<QBoxSet *> sets; |
|
168 | QList<QBoxSet *> sets; | |
163 | sets.append(set); |
|
169 | sets.append(set); | |
164 | set->setParent(this); |
|
170 | set->setParent(this); | |
165 | emit boxsetsAdded(sets); |
|
171 | emit boxsetsAdded(sets); | |
166 | emit countChanged(); |
|
172 | emit countChanged(); | |
167 | } |
|
173 | } | |
168 | return success; |
|
174 | return success; | |
169 | } |
|
175 | } | |
170 |
|
176 | |||
171 | /*! |
|
177 | /*! | |
172 | Removes boxset from the series. Deletes the \a set and returns true if successful. |
|
178 | Removes boxset from the series. Deletes the \a set and returns true if successful. | |
173 | */ |
|
179 | */ | |
174 | bool QBoxPlotSeries::remove(QBoxSet *set) |
|
180 | bool QBoxPlotSeries::remove(QBoxSet *set) | |
175 | { |
|
181 | { | |
176 | Q_D(QBoxPlotSeries); |
|
182 | Q_D(QBoxPlotSeries); | |
177 | bool success = d->remove(set); |
|
183 | bool success = d->remove(set); | |
178 | if (success) { |
|
184 | if (success) { | |
179 | QList<QBoxSet *> sets; |
|
185 | QList<QBoxSet *> sets; | |
180 | sets.append(set); |
|
186 | sets.append(set); | |
181 | set->setParent(0); |
|
187 | set->setParent(0); | |
182 | emit boxsetsRemoved(sets); |
|
188 | emit boxsetsRemoved(sets); | |
183 | emit countChanged(); |
|
189 | emit countChanged(); | |
184 | delete set; |
|
190 | delete set; | |
185 | set = 0; |
|
191 | set = 0; | |
186 | } |
|
192 | } | |
187 | return success; |
|
193 | return success; | |
188 | } |
|
194 | } | |
189 |
|
195 | |||
190 | /*! |
|
196 | /*! | |
191 | Takes a single \a set from the series. Does not delete the boxset object. |
|
197 | Takes a single \a set from the series. Does not delete the boxset object. | |
192 |
|
198 | |||
193 | NOTE: The series remains as the boxset's parent object. You must set the |
|
199 | NOTE: The series remains as the boxset's parent object. You must set the | |
194 | parent object to take full ownership. |
|
200 | parent object to take full ownership. | |
195 |
|
201 | |||
196 | Returns true if take was successful. |
|
202 | Returns true if take was successful. | |
197 | */ |
|
203 | */ | |
198 | bool QBoxPlotSeries::take(QBoxSet *set) |
|
204 | bool QBoxPlotSeries::take(QBoxSet *set) | |
199 | { |
|
205 | { | |
200 | Q_D(QBoxPlotSeries); |
|
206 | Q_D(QBoxPlotSeries); | |
201 |
|
207 | |||
202 | bool success = d->remove(set); |
|
208 | bool success = d->remove(set); | |
203 | if (success) { |
|
209 | if (success) { | |
204 | QList<QBoxSet *> sets; |
|
210 | QList<QBoxSet *> sets; | |
205 | sets.append(set); |
|
211 | sets.append(set); | |
206 | emit boxsetsRemoved(sets); |
|
212 | emit boxsetsRemoved(sets); | |
207 | emit countChanged(); |
|
213 | emit countChanged(); | |
208 | } |
|
214 | } | |
209 | return success; |
|
215 | return success; | |
210 | } |
|
216 | } | |
211 |
|
217 | |||
212 | /*! |
|
218 | /*! | |
213 | Adds a list of boxsets to series. Takes ownership of the \a sets. |
|
219 | Adds a list of boxsets to series. Takes ownership of the \a sets. | |
214 | Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series, |
|
220 | Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series, | |
215 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
221 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
216 | and function returns false. |
|
222 | and function returns false. | |
217 | */ |
|
223 | */ | |
218 | bool QBoxPlotSeries::append(QList<QBoxSet *> sets) |
|
224 | bool QBoxPlotSeries::append(QList<QBoxSet *> sets) | |
219 | { |
|
225 | { | |
220 | Q_D(QBoxPlotSeries); |
|
226 | Q_D(QBoxPlotSeries); | |
221 | bool success = d->append(sets); |
|
227 | bool success = d->append(sets); | |
222 | if (success) { |
|
228 | if (success) { | |
223 | emit boxsetsAdded(sets); |
|
229 | emit boxsetsAdded(sets); | |
224 | emit countChanged(); |
|
230 | emit countChanged(); | |
225 | } |
|
231 | } | |
226 | return success; |
|
232 | return success; | |
227 | } |
|
233 | } | |
228 |
|
234 | |||
229 | /*! |
|
235 | /*! | |
230 | 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 |
|
236 | 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 | |
231 | is already in series, it won't be appended. Returns true, if inserting succeeded. |
|
237 | is already in series, it won't be appended. Returns true, if inserting succeeded. | |
232 |
|
238 | |||
233 | */ |
|
239 | */ | |
234 | bool QBoxPlotSeries::insert(int index, QBoxSet *set) |
|
240 | bool QBoxPlotSeries::insert(int index, QBoxSet *set) | |
235 | { |
|
241 | { | |
236 | Q_D(QBoxPlotSeries); |
|
242 | Q_D(QBoxPlotSeries); | |
237 | bool success = d->insert(index, set); |
|
243 | bool success = d->insert(index, set); | |
238 | if (success) { |
|
244 | if (success) { | |
239 | QList<QBoxSet *> sets; |
|
245 | QList<QBoxSet *> sets; | |
240 | sets.append(set); |
|
246 | sets.append(set); | |
241 | emit boxsetsAdded(sets); |
|
247 | emit boxsetsAdded(sets); | |
242 | emit countChanged(); |
|
248 | emit countChanged(); | |
243 | } |
|
249 | } | |
244 | return success; |
|
250 | return success; | |
245 | } |
|
251 | } | |
246 |
|
252 | |||
247 | /*! |
|
253 | /*! | |
248 | Removes all boxsets from the series. Deletes removed sets. |
|
254 | Removes all boxsets from the series. Deletes removed sets. | |
249 | */ |
|
255 | */ | |
250 | void QBoxPlotSeries::clear() |
|
256 | void QBoxPlotSeries::clear() | |
251 | { |
|
257 | { | |
252 | Q_D(QBoxPlotSeries); |
|
258 | Q_D(QBoxPlotSeries); | |
253 | QList<QBoxSet *> sets = boxSets(); |
|
259 | QList<QBoxSet *> sets = boxSets(); | |
254 | bool success = d->remove(sets); |
|
260 | bool success = d->remove(sets); | |
255 | if (success) { |
|
261 | if (success) { | |
256 | emit boxsetsRemoved(sets); |
|
262 | emit boxsetsRemoved(sets); | |
257 | emit countChanged(); |
|
263 | emit countChanged(); | |
258 | foreach (QBoxSet *set, sets) |
|
264 | foreach (QBoxSet *set, sets) | |
259 | delete set; |
|
265 | delete set; | |
260 | } |
|
266 | } | |
261 | } |
|
267 | } | |
262 |
|
268 | |||
263 | /*! |
|
269 | /*! | |
264 | Returns number of sets in series. |
|
270 | Returns number of sets in series. | |
265 | */ |
|
271 | */ | |
266 | int QBoxPlotSeries::count() const |
|
272 | int QBoxPlotSeries::count() const | |
267 | { |
|
273 | { | |
268 | Q_D(const QBoxPlotSeries); |
|
274 | Q_D(const QBoxPlotSeries); | |
269 | return d->m_boxSets.count(); |
|
275 | return d->m_boxSets.count(); | |
270 | } |
|
276 | } | |
271 |
|
277 | |||
272 | /*! |
|
278 | /*! | |
273 | Returns a list of sets in series. Keeps ownership of sets. |
|
279 | Returns a list of sets in series. Keeps ownership of sets. | |
274 | */ |
|
280 | */ | |
275 | QList<QBoxSet *> QBoxPlotSeries::boxSets() const |
|
281 | QList<QBoxSet *> QBoxPlotSeries::boxSets() const | |
276 | { |
|
282 | { | |
277 | Q_D(const QBoxPlotSeries); |
|
283 | Q_D(const QBoxPlotSeries); | |
278 | return d->m_boxSets; |
|
284 | return d->m_boxSets; | |
279 | } |
|
285 | } | |
280 |
|
286 | |||
281 | /* |
|
287 | /* | |
282 | Returns QAbstractSeries::SeriesTypeBoxPlot. |
|
288 | Returns QAbstractSeries::SeriesTypeBoxPlot. | |
283 | */ |
|
289 | */ | |
284 | QAbstractSeries::SeriesType QBoxPlotSeries::type() const |
|
290 | QAbstractSeries::SeriesType QBoxPlotSeries::type() const | |
285 | { |
|
291 | { | |
286 | return QAbstractSeries::SeriesTypeBoxPlot; |
|
292 | return QAbstractSeries::SeriesTypeBoxPlot; | |
287 | } |
|
293 | } | |
288 |
|
294 | |||
289 | void QBoxPlotSeries::setBoxOutlineVisible(bool visible) |
|
295 | void QBoxPlotSeries::setBoxOutlineVisible(bool visible) | |
290 | { |
|
296 | { | |
291 | Q_D(QBoxPlotSeries); |
|
297 | Q_D(QBoxPlotSeries); | |
292 |
|
298 | |||
293 | if (d->m_boxOutlineVisible != visible) { |
|
299 | if (d->m_boxOutlineVisible != visible) { | |
294 | d->m_boxOutlineVisible = visible; |
|
300 | d->m_boxOutlineVisible = visible; | |
295 | emit d->updated(); |
|
301 | emit d->updated(); | |
296 | emit boxOutlineVisibilityChanged(); |
|
302 | emit boxOutlineVisibilityChanged(); | |
297 | } |
|
303 | } | |
298 | } |
|
304 | } | |
299 |
|
305 | |||
300 | bool QBoxPlotSeries::boxOutlineVisible() |
|
306 | bool QBoxPlotSeries::boxOutlineVisible() | |
301 | { |
|
307 | { | |
302 | Q_D(QBoxPlotSeries); |
|
308 | Q_D(QBoxPlotSeries); | |
303 |
|
309 | |||
304 | return d->m_boxOutlineVisible; |
|
310 | return d->m_boxOutlineVisible; | |
305 | } |
|
311 | } | |
306 |
|
312 | |||
307 | void QBoxPlotSeries::setBoxWidth(qreal width) |
|
313 | void QBoxPlotSeries::setBoxWidth(qreal width) | |
308 | { |
|
314 | { | |
309 | Q_D(QBoxPlotSeries); |
|
315 | Q_D(QBoxPlotSeries); | |
310 |
|
316 | |||
311 | if (width != d->m_boxWidth) { |
|
317 | if (width != d->m_boxWidth) { | |
312 | if (width < 0.0) |
|
318 | if (width < 0.0) | |
313 | width = 0.0; |
|
319 | width = 0.0; | |
314 | if (width > 1.0) |
|
320 | if (width > 1.0) | |
315 | width = 1.0; |
|
321 | width = 1.0; | |
316 | d->m_boxWidth = width; |
|
322 | d->m_boxWidth = width; | |
317 | emit d->updatedLayout(); |
|
323 | emit d->updatedLayout(); | |
318 | emit boxWidthChanged(); |
|
324 | emit boxWidthChanged(); | |
319 | } |
|
325 | } | |
320 | } |
|
326 | } | |
321 |
|
327 | |||
322 | qreal QBoxPlotSeries::boxWidth() |
|
328 | qreal QBoxPlotSeries::boxWidth() | |
323 | { |
|
329 | { | |
324 | Q_D(QBoxPlotSeries); |
|
330 | Q_D(QBoxPlotSeries); | |
325 |
|
331 | |||
326 | return d->m_boxWidth; |
|
332 | return d->m_boxWidth; | |
327 | } |
|
333 | } | |
328 |
|
334 | |||
329 | void QBoxPlotSeries::setBrush(const QBrush &brush) |
|
335 | void QBoxPlotSeries::setBrush(const QBrush &brush) | |
330 | { |
|
336 | { | |
331 | Q_D(QBoxPlotSeries); |
|
337 | Q_D(QBoxPlotSeries); | |
332 |
|
338 | |||
333 | if (d->m_brush != brush) { |
|
339 | if (d->m_brush != brush) { | |
334 | d->m_brush = brush; |
|
340 | d->m_brush = brush; | |
335 | emit d->updated(); |
|
341 | emit d->updated(); | |
336 | emit brushChanged(); |
|
342 | emit brushChanged(); | |
337 | } |
|
343 | } | |
338 | } |
|
344 | } | |
339 |
|
345 | |||
340 | QBrush QBoxPlotSeries::brush() const |
|
346 | QBrush QBoxPlotSeries::brush() const | |
341 | { |
|
347 | { | |
342 | Q_D(const QBoxPlotSeries); |
|
348 | Q_D(const QBoxPlotSeries); | |
343 |
|
349 | |||
344 | return d->m_brush; |
|
350 | return d->m_brush; | |
345 | } |
|
351 | } | |
346 |
|
352 | |||
347 | void QBoxPlotSeries::setPen(const QPen &pen) |
|
353 | void QBoxPlotSeries::setPen(const QPen &pen) | |
348 | { |
|
354 | { | |
349 | Q_D(QBoxPlotSeries); |
|
355 | Q_D(QBoxPlotSeries); | |
350 |
|
356 | |||
351 | if (d->m_pen != pen) { |
|
357 | if (d->m_pen != pen) { | |
352 | d->m_pen = pen; |
|
358 | d->m_pen = pen; | |
353 | emit d->updated(); |
|
359 | emit d->updated(); | |
354 | emit penChanged(); |
|
360 | emit penChanged(); | |
355 | } |
|
361 | } | |
356 | } |
|
362 | } | |
357 |
|
363 | |||
358 | QPen QBoxPlotSeries::pen() const |
|
364 | QPen QBoxPlotSeries::pen() const | |
359 | { |
|
365 | { | |
360 | Q_D(const QBoxPlotSeries); |
|
366 | Q_D(const QBoxPlotSeries); | |
361 |
|
367 | |||
362 | return d->m_pen; |
|
368 | return d->m_pen; | |
363 | } |
|
369 | } | |
364 |
|
370 | |||
365 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
371 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
366 |
|
372 | |||
367 | QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q) |
|
373 | QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q) | |
368 | : QAbstractSeriesPrivate(q), |
|
374 | : QAbstractSeriesPrivate(q), | |
369 | m_pen(QChartPrivate::defaultPen()), |
|
375 | m_pen(QChartPrivate::defaultPen()), | |
370 | m_brush(QChartPrivate::defaultBrush()), |
|
376 | m_brush(QChartPrivate::defaultBrush()), | |
371 | m_boxOutlineVisible(true), |
|
377 | m_boxOutlineVisible(true), | |
372 | m_boxWidth(0.5) |
|
378 | m_boxWidth(0.5) | |
373 | { |
|
379 | { | |
374 | } |
|
380 | } | |
375 |
|
381 | |||
376 | QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate() |
|
382 | QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate() | |
377 | { |
|
383 | { | |
378 | disconnect(this, 0, 0, 0); |
|
384 | disconnect(this, 0, 0, 0); | |
379 | } |
|
385 | } | |
380 |
|
386 | |||
381 | void QBoxPlotSeriesPrivate::initializeDomain() |
|
387 | void QBoxPlotSeriesPrivate::initializeDomain() | |
382 | { |
|
388 | { | |
383 | qreal minX(domain()->minX()); |
|
389 | qreal minX(domain()->minX()); | |
384 | qreal minY(domain()->minY()); |
|
390 | qreal minY(domain()->minY()); | |
385 | qreal maxX(domain()->maxX()); |
|
391 | qreal maxX(domain()->maxX()); | |
386 | qreal maxY(domain()->maxY()); |
|
392 | qreal maxY(domain()->maxY()); | |
387 |
|
393 | |||
388 | qreal x = m_boxSets.count(); |
|
394 | qreal x = m_boxSets.count(); | |
389 | minX = qMin(minX, qreal(-0.5)); |
|
395 | minX = qMin(minX, qreal(-0.5)); | |
390 | minY = qMin(minY, min()); |
|
396 | minY = qMin(minY, min()); | |
391 | maxX = qMax(maxX, x - qreal(0.5)); |
|
397 | maxX = qMax(maxX, x - qreal(0.5)); | |
392 | maxY = qMax(maxY, max()); |
|
398 | maxY = qMax(maxY, max()); | |
393 |
|
399 | |||
394 | domain()->setRange(minX, maxX, minY, maxY); |
|
400 | domain()->setRange(minX, maxX, minY, maxY); | |
395 | } |
|
401 | } | |
396 |
|
402 | |||
397 | void QBoxPlotSeriesPrivate::initializeAxes() |
|
403 | void QBoxPlotSeriesPrivate::initializeAxes() | |
398 | { |
|
404 | { | |
399 | foreach (QAbstractAxis* axis, m_axes) { |
|
405 | foreach (QAbstractAxis* axis, m_axes) { | |
400 | if (axis->type() == QAbstractAxis::AxisTypeBarCategory) { |
|
406 | if (axis->type() == QAbstractAxis::AxisTypeBarCategory) { | |
401 | if (axis->orientation() == Qt::Horizontal) |
|
407 | if (axis->orientation() == Qt::Horizontal) | |
402 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); |
|
408 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); | |
403 | } |
|
409 | } | |
404 | } |
|
410 | } | |
405 | } |
|
411 | } | |
406 |
|
412 | |||
407 | QAbstractAxis::AxisType QBoxPlotSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
413 | QAbstractAxis::AxisType QBoxPlotSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
408 | { |
|
414 | { | |
409 | if (orientation == Qt::Horizontal) |
|
415 | if (orientation == Qt::Horizontal) | |
410 | return QAbstractAxis::AxisTypeBarCategory; |
|
416 | return QAbstractAxis::AxisTypeBarCategory; | |
411 |
|
417 | |||
412 | return QAbstractAxis::AxisTypeValue; |
|
418 | return QAbstractAxis::AxisTypeValue; | |
413 | } |
|
419 | } | |
414 |
|
420 | |||
415 | QAbstractAxis* QBoxPlotSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
421 | QAbstractAxis* QBoxPlotSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |
416 | { |
|
422 | { | |
417 | if (defaultAxisType(orientation) == QAbstractAxis::AxisTypeBarCategory) |
|
423 | if (defaultAxisType(orientation) == QAbstractAxis::AxisTypeBarCategory) | |
418 | return new QBarCategoryAxis; |
|
424 | return new QBarCategoryAxis; | |
419 | else |
|
425 | else | |
420 | return new QValueAxis; |
|
426 | return new QValueAxis; | |
421 | } |
|
427 | } | |
422 |
|
428 | |||
423 | void QBoxPlotSeriesPrivate::populateCategories(QBarCategoryAxis *axis) |
|
429 | void QBoxPlotSeriesPrivate::populateCategories(QBarCategoryAxis *axis) | |
424 | { |
|
430 | { | |
425 | QStringList categories; |
|
431 | QStringList categories; | |
426 | if (axis->categories().isEmpty()) { |
|
432 | if (axis->categories().isEmpty()) { | |
427 | for (int i(1); i < m_boxSets.count() + 1; i++) { |
|
433 | for (int i(1); i < m_boxSets.count() + 1; i++) { | |
428 | QBoxSet *set = m_boxSets.at(i - 1); |
|
434 | QBoxSet *set = m_boxSets.at(i - 1); | |
429 | if (set->label().isEmpty()) |
|
435 | if (set->label().isEmpty()) | |
430 | categories << presenter()->numberToString(i); |
|
436 | categories << presenter()->numberToString(i); | |
431 | else |
|
437 | else | |
432 | categories << set->label(); |
|
438 | categories << set->label(); | |
433 | } |
|
439 | } | |
434 | axis->append(categories); |
|
440 | axis->append(categories); | |
435 | } |
|
441 | } | |
436 | } |
|
442 | } | |
437 |
|
443 | |||
438 | void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem *parent) |
|
444 | void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem *parent) | |
439 | { |
|
445 | { | |
440 | Q_Q(QBoxPlotSeries); |
|
446 | Q_Q(QBoxPlotSeries); | |
441 |
|
447 | |||
442 | BoxPlotChartItem *boxPlot = new BoxPlotChartItem(q, parent); |
|
448 | BoxPlotChartItem *boxPlot = new BoxPlotChartItem(q, parent); | |
443 | m_item.reset(boxPlot); |
|
449 | m_item.reset(boxPlot); | |
444 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
450 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
445 |
|
451 | |||
446 | if (m_chart) { |
|
452 | if (m_chart) { | |
447 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesChange(QAbstractSeries*)) ); |
|
453 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesChange(QAbstractSeries*)) ); | |
448 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) ); |
|
454 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) ); | |
449 |
|
455 | |||
450 | QList<QAbstractSeries *> serieses = m_chart->series(); |
|
456 | QList<QAbstractSeries *> serieses = m_chart->series(); | |
451 |
|
457 | |||
452 | // Tries to find this series from the Chart's list of series and deduce the index |
|
458 | // Tries to find this series from the Chart's list of series and deduce the index | |
453 | int index = 0; |
|
459 | int index = 0; | |
454 | foreach (QAbstractSeries *s, serieses) { |
|
460 | foreach (QAbstractSeries *s, serieses) { | |
455 | if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) { |
|
461 | if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) { | |
456 | if (q == static_cast<QBoxPlotSeries *>(s)) { |
|
462 | if (q == static_cast<QBoxPlotSeries *>(s)) { | |
457 | boxPlot->m_seriesIndex = index; |
|
463 | boxPlot->m_seriesIndex = index; | |
458 | m_index = index; |
|
464 | m_index = index; | |
459 | } |
|
465 | } | |
460 | index++; |
|
466 | index++; | |
461 | } |
|
467 | } | |
462 | } |
|
468 | } | |
463 | boxPlot->m_seriesCount = index; |
|
469 | boxPlot->m_seriesCount = index; | |
464 | } |
|
470 | } | |
465 |
|
471 | |||
466 | // Make BoxPlotChartItem to instantiate box & whisker items |
|
472 | // Make BoxPlotChartItem to instantiate box & whisker items | |
467 | boxPlot->handleDataStructureChanged(); |
|
473 | boxPlot->handleDataStructureChanged(); | |
468 | } |
|
474 | } | |
469 |
|
475 | |||
470 | void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
476 | void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |
471 | { |
|
477 | { | |
472 | Q_Q(QBoxPlotSeries); |
|
478 | Q_Q(QBoxPlotSeries); | |
473 |
|
479 | |||
474 | const QList<QGradient> gradients = theme->seriesGradients(); |
|
480 | const QList<QGradient> gradients = theme->seriesGradients(); | |
475 |
|
481 | |||
476 | if (forced || QChartPrivate::defaultBrush() == m_brush) { |
|
482 | if (forced || QChartPrivate::defaultBrush() == m_brush) { | |
477 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.5); |
|
483 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.5); | |
478 | q->setBrush(brushColor); |
|
484 | q->setBrush(brushColor); | |
479 | } |
|
485 | } | |
480 |
|
486 | |||
481 | if (forced || QChartPrivate::defaultPen() == m_pen) { |
|
487 | if (forced || QChartPrivate::defaultPen() == m_pen) { | |
482 | QPen pen = theme->outlinePen(); |
|
488 | QPen pen = theme->outlinePen(); | |
483 | pen.setCosmetic(true); |
|
489 | pen.setCosmetic(true); | |
484 | q->setPen(pen); |
|
490 | q->setPen(pen); | |
485 | } |
|
491 | } | |
486 | } |
|
492 | } | |
487 |
|
493 | |||
488 | void QBoxPlotSeriesPrivate::initializeAnimations(QChart::AnimationOptions options, int duration, |
|
494 | void QBoxPlotSeriesPrivate::initializeAnimations(QChart::AnimationOptions options, int duration, | |
489 | QEasingCurve &curve) |
|
495 | QEasingCurve &curve) | |
490 | { |
|
496 | { | |
491 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); |
|
497 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); | |
492 | Q_ASSERT(item); |
|
498 | Q_ASSERT(item); | |
493 | if (item->animation()) |
|
499 | if (item->animation()) | |
494 | item->animation()->stopAndDestroyLater(); |
|
500 | item->animation()->stopAndDestroyLater(); | |
495 |
|
501 | |||
496 | if (options.testFlag(QChart::SeriesAnimations)) |
|
502 | if (options.testFlag(QChart::SeriesAnimations)) | |
497 | m_animation = new BoxPlotAnimation(item, duration, curve); |
|
503 | m_animation = new BoxPlotAnimation(item, duration, curve); | |
498 | else |
|
504 | else | |
499 | m_animation = 0; |
|
505 | m_animation = 0; | |
500 | item->setAnimation(m_animation); |
|
506 | item->setAnimation(m_animation); | |
501 |
|
507 | |||
502 | QAbstractSeriesPrivate::initializeAnimations(options, duration, curve); |
|
508 | QAbstractSeriesPrivate::initializeAnimations(options, duration, curve); | |
503 |
|
509 | |||
504 | // Make BoxPlotChartItem to instantiate box & whisker items |
|
510 | // Make BoxPlotChartItem to instantiate box & whisker items | |
505 | item->handleDataStructureChanged(); |
|
511 | item->handleDataStructureChanged(); | |
506 | } |
|
512 | } | |
507 |
|
513 | |||
508 | QList<QLegendMarker*> QBoxPlotSeriesPrivate::createLegendMarkers(QLegend *legend) |
|
514 | QList<QLegendMarker*> QBoxPlotSeriesPrivate::createLegendMarkers(QLegend *legend) | |
509 | { |
|
515 | { | |
510 | Q_Q(QBoxPlotSeries); |
|
516 | Q_Q(QBoxPlotSeries); | |
511 | QList<QLegendMarker *> list; |
|
517 | QList<QLegendMarker *> list; | |
512 | return list << new QBoxPlotLegendMarker(q, legend); |
|
518 | return list << new QBoxPlotLegendMarker(q, legend); | |
513 | } |
|
519 | } | |
514 |
|
520 | |||
515 | void QBoxPlotSeriesPrivate::handleSeriesRemove(QAbstractSeries *series) |
|
521 | void QBoxPlotSeriesPrivate::handleSeriesRemove(QAbstractSeries *series) | |
516 | { |
|
522 | { | |
517 | Q_Q(QBoxPlotSeries); |
|
523 | Q_Q(QBoxPlotSeries); | |
518 |
|
524 | |||
519 | QBoxPlotSeries *removedSeries = static_cast<QBoxPlotSeries *>(series); |
|
525 | QBoxPlotSeries *removedSeries = static_cast<QBoxPlotSeries *>(series); | |
520 |
|
526 | |||
521 | if (q == removedSeries && m_animation) { |
|
527 | if (q == removedSeries && m_animation) { | |
522 | m_animation->stopAll(); |
|
528 | m_animation->stopAll(); | |
523 | QObject::disconnect(m_chart->d_ptr->m_dataset, 0, removedSeries->d_func(), 0); |
|
529 | QObject::disconnect(m_chart->d_ptr->m_dataset, 0, removedSeries->d_func(), 0); | |
524 | } |
|
530 | } | |
525 |
|
531 | |||
526 | // Test if series removed is me, then don't do anything |
|
532 | // Test if series removed is me, then don't do anything | |
527 | if (q != removedSeries) { |
|
533 | if (q != removedSeries) { | |
528 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); |
|
534 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); | |
529 | if (item) { |
|
535 | if (item) { | |
530 | item->m_seriesCount = item->m_seriesCount - 1; |
|
536 | item->m_seriesCount = item->m_seriesCount - 1; | |
531 | if (removedSeries->d_func()->m_index < m_index) { |
|
537 | if (removedSeries->d_func()->m_index < m_index) { | |
532 | m_index--; |
|
538 | m_index--; | |
533 | item->m_seriesIndex = m_index; |
|
539 | item->m_seriesIndex = m_index; | |
534 | } |
|
540 | } | |
535 |
|
541 | |||
536 | item->handleDataStructureChanged(); |
|
542 | item->handleDataStructureChanged(); | |
537 | } |
|
543 | } | |
538 | } |
|
544 | } | |
539 | } |
|
545 | } | |
540 |
|
546 | |||
541 | void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series) |
|
547 | void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series) | |
542 | { |
|
548 | { | |
543 | Q_UNUSED(series); |
|
549 | Q_UNUSED(series); | |
544 |
|
550 | |||
545 | Q_Q(QBoxPlotSeries); |
|
551 | Q_Q(QBoxPlotSeries); | |
546 |
|
552 | |||
547 | BoxPlotChartItem *boxPlot = static_cast<BoxPlotChartItem *>(m_item.data()); |
|
553 | BoxPlotChartItem *boxPlot = static_cast<BoxPlotChartItem *>(m_item.data()); | |
548 |
|
554 | |||
549 | if (m_chart) { |
|
555 | if (m_chart) { | |
550 | QList<QAbstractSeries *> serieses = m_chart->series(); |
|
556 | QList<QAbstractSeries *> serieses = m_chart->series(); | |
551 |
|
557 | |||
552 | // Tries to find this series from the Chart's list of series and deduce the index |
|
558 | // Tries to find this series from the Chart's list of series and deduce the index | |
553 | int index = 0; |
|
559 | int index = 0; | |
554 | foreach (QAbstractSeries *s, serieses) { |
|
560 | foreach (QAbstractSeries *s, serieses) { | |
555 | if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) { |
|
561 | if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) { | |
556 | if (q == static_cast<QBoxPlotSeries *>(s)) { |
|
562 | if (q == static_cast<QBoxPlotSeries *>(s)) { | |
557 | boxPlot->m_seriesIndex = index; |
|
563 | boxPlot->m_seriesIndex = index; | |
558 | m_index = index; |
|
564 | m_index = index; | |
559 | } |
|
565 | } | |
560 | index++; |
|
566 | index++; | |
561 | } |
|
567 | } | |
562 | } |
|
568 | } | |
563 | boxPlot->m_seriesCount = index; |
|
569 | boxPlot->m_seriesCount = index; | |
564 | } |
|
570 | } | |
565 |
|
571 | |||
566 | boxPlot->handleDataStructureChanged(); |
|
572 | boxPlot->handleDataStructureChanged(); | |
567 | } |
|
573 | } | |
568 |
|
574 | |||
569 | bool QBoxPlotSeriesPrivate::append(QBoxSet *set) |
|
575 | bool QBoxPlotSeriesPrivate::append(QBoxSet *set) | |
570 | { |
|
576 | { | |
571 | if (m_boxSets.contains(set) || (set == 0) || set->d_ptr->m_series) |
|
577 | if (m_boxSets.contains(set) || (set == 0) || set->d_ptr->m_series) | |
572 | return false; // Fail if set is already in list or set is null. |
|
578 | return false; // Fail if set is already in list or set is null. | |
573 |
|
579 | |||
574 | m_boxSets.append(set); |
|
580 | m_boxSets.append(set); | |
575 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
581 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
576 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); |
|
582 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); | |
577 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); |
|
583 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); | |
578 | set->d_ptr->m_series = this; |
|
584 | set->d_ptr->m_series = this; | |
579 |
|
585 | |||
580 | emit restructuredBoxes(); // this notifies boxplotchartitem |
|
586 | emit restructuredBoxes(); // this notifies boxplotchartitem | |
581 | return true; |
|
587 | return true; | |
582 | } |
|
588 | } | |
583 |
|
589 | |||
584 | bool QBoxPlotSeriesPrivate::remove(QBoxSet *set) |
|
590 | bool QBoxPlotSeriesPrivate::remove(QBoxSet *set) | |
585 | { |
|
591 | { | |
586 | if (!m_boxSets.contains(set)) |
|
592 | if (!m_boxSets.contains(set)) | |
587 | return false; // Fail if set is not in list |
|
593 | return false; // Fail if set is not in list | |
588 |
|
594 | |||
589 | set->d_ptr->m_series = 0; |
|
595 | set->d_ptr->m_series = 0; | |
590 | m_boxSets.removeOne(set); |
|
596 | m_boxSets.removeOne(set); | |
591 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
597 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
592 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); |
|
598 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); | |
593 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); |
|
599 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); | |
594 |
|
600 | |||
595 | emit restructuredBoxes(); // this notifies boxplotchartitem |
|
601 | emit restructuredBoxes(); // this notifies boxplotchartitem | |
596 | return true; |
|
602 | return true; | |
597 | } |
|
603 | } | |
598 |
|
604 | |||
599 | bool QBoxPlotSeriesPrivate::append(QList<QBoxSet *> sets) |
|
605 | bool QBoxPlotSeriesPrivate::append(QList<QBoxSet *> sets) | |
600 | { |
|
606 | { | |
601 | foreach (QBoxSet *set, sets) { |
|
607 | foreach (QBoxSet *set, sets) { | |
602 | if ((set == 0) || m_boxSets.contains(set) || set->d_ptr->m_series) |
|
608 | if ((set == 0) || m_boxSets.contains(set) || set->d_ptr->m_series) | |
603 | return false; // Fail if any of the sets is null or is already appended. |
|
609 | return false; // Fail if any of the sets is null or is already appended. | |
604 | if (sets.count(set) != 1) |
|
610 | if (sets.count(set) != 1) | |
605 | return false; // Also fail if same set is more than once in given list. |
|
611 | return false; // Also fail if same set is more than once in given list. | |
606 | } |
|
612 | } | |
607 |
|
613 | |||
608 | foreach (QBoxSet *set, sets) { |
|
614 | foreach (QBoxSet *set, sets) { | |
609 | m_boxSets.append(set); |
|
615 | m_boxSets.append(set); | |
610 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
616 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
611 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); |
|
617 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); | |
612 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); |
|
618 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); | |
613 | set->d_ptr->m_series = this; |
|
619 | set->d_ptr->m_series = this; | |
614 | } |
|
620 | } | |
615 |
|
621 | |||
616 | emit restructuredBoxes(); // this notifies boxplotchartitem |
|
622 | emit restructuredBoxes(); // this notifies boxplotchartitem | |
617 | return true; |
|
623 | return true; | |
618 | } |
|
624 | } | |
619 |
|
625 | |||
620 | bool QBoxPlotSeriesPrivate::remove(QList<QBoxSet *> sets) |
|
626 | bool QBoxPlotSeriesPrivate::remove(QList<QBoxSet *> sets) | |
621 | { |
|
627 | { | |
622 | if (sets.count() == 0) |
|
628 | if (sets.count() == 0) | |
623 | return false; |
|
629 | return false; | |
624 |
|
630 | |||
625 | foreach (QBoxSet *set, sets) { |
|
631 | foreach (QBoxSet *set, sets) { | |
626 | if ((set == 0) || (!m_boxSets.contains(set))) |
|
632 | if ((set == 0) || (!m_boxSets.contains(set))) | |
627 | return false; // Fail if any of the sets is null or is not in series |
|
633 | return false; // Fail if any of the sets is null or is not in series | |
628 | if (sets.count(set) != 1) |
|
634 | if (sets.count(set) != 1) | |
629 | return false; // Also fail if same set is more than once in given list. |
|
635 | return false; // Also fail if same set is more than once in given list. | |
630 | } |
|
636 | } | |
631 |
|
637 | |||
632 | foreach (QBoxSet *set, sets) { |
|
638 | foreach (QBoxSet *set, sets) { | |
633 | set->d_ptr->m_series = 0; |
|
639 | set->d_ptr->m_series = 0; | |
634 | m_boxSets.removeOne(set); |
|
640 | m_boxSets.removeOne(set); | |
635 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
641 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
636 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); |
|
642 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); | |
637 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); |
|
643 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); | |
638 | } |
|
644 | } | |
639 |
|
645 | |||
640 | emit restructuredBoxes(); // this notifies boxplotchartitem |
|
646 | emit restructuredBoxes(); // this notifies boxplotchartitem | |
641 |
|
647 | |||
642 | return true; |
|
648 | return true; | |
643 | } |
|
649 | } | |
644 |
|
650 | |||
645 | bool QBoxPlotSeriesPrivate::insert(int index, QBoxSet *set) |
|
651 | bool QBoxPlotSeriesPrivate::insert(int index, QBoxSet *set) | |
646 | { |
|
652 | { | |
647 | if ((m_boxSets.contains(set)) || (set == 0) || set->d_ptr->m_series) |
|
653 | if ((m_boxSets.contains(set)) || (set == 0) || set->d_ptr->m_series) | |
648 | return false; // Fail if set is already in list or set is null. |
|
654 | return false; // Fail if set is already in list or set is null. | |
649 |
|
655 | |||
650 | m_boxSets.insert(index, set); |
|
656 | m_boxSets.insert(index, set); | |
651 | set->d_ptr->m_series = this; |
|
657 | set->d_ptr->m_series = this; | |
652 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
658 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
653 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); |
|
659 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); | |
654 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); |
|
660 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); | |
655 |
|
661 | |||
656 | emit restructuredBoxes(); // this notifies boxplotchartitem |
|
662 | emit restructuredBoxes(); // this notifies boxplotchartitem | |
657 | return true; |
|
663 | return true; | |
658 | } |
|
664 | } | |
659 |
|
665 | |||
660 | QBoxSet *QBoxPlotSeriesPrivate::boxSetAt(int index) |
|
666 | QBoxSet *QBoxPlotSeriesPrivate::boxSetAt(int index) | |
661 | { |
|
667 | { | |
662 | return m_boxSets.at(index); |
|
668 | return m_boxSets.at(index); | |
663 | } |
|
669 | } | |
664 |
|
670 | |||
665 | qreal QBoxPlotSeriesPrivate::min() |
|
671 | qreal QBoxPlotSeriesPrivate::min() | |
666 | { |
|
672 | { | |
667 | if (m_boxSets.count() <= 0) |
|
673 | if (m_boxSets.count() <= 0) | |
668 | return 0; |
|
674 | return 0; | |
669 |
|
675 | |||
670 | qreal min = m_boxSets.at(0)->at(0); |
|
676 | qreal min = m_boxSets.at(0)->at(0); | |
671 |
|
677 | |||
672 | foreach (QBoxSet *set, m_boxSets) { |
|
678 | foreach (QBoxSet *set, m_boxSets) { | |
673 | for (int i = 0; i < 5; i++) { |
|
679 | for (int i = 0; i < 5; i++) { | |
674 | if (set->at(i) < min) |
|
680 | if (set->at(i) < min) | |
675 | min = set->at(i); |
|
681 | min = set->at(i); | |
676 | } |
|
682 | } | |
677 | } |
|
683 | } | |
678 |
|
684 | |||
679 | return min; |
|
685 | return min; | |
680 | } |
|
686 | } | |
681 |
|
687 | |||
682 | qreal QBoxPlotSeriesPrivate::max() |
|
688 | qreal QBoxPlotSeriesPrivate::max() | |
683 | { |
|
689 | { | |
684 | if (m_boxSets.count() <= 0) |
|
690 | if (m_boxSets.count() <= 0) | |
685 | return 0; |
|
691 | return 0; | |
686 |
|
692 | |||
687 | qreal max = m_boxSets.at(0)->at(0); |
|
693 | qreal max = m_boxSets.at(0)->at(0); | |
688 |
|
694 | |||
689 | foreach (QBoxSet *set, m_boxSets) { |
|
695 | foreach (QBoxSet *set, m_boxSets) { | |
690 | for (int i = 0; i < 5; i++) { |
|
696 | for (int i = 0; i < 5; i++) { | |
691 | if (set->at(i) > max) |
|
697 | if (set->at(i) > max) | |
692 | max = set->at(i); |
|
698 | max = set->at(i); | |
693 | } |
|
699 | } | |
694 | } |
|
700 | } | |
695 |
|
701 | |||
696 | return max; |
|
702 | return max; | |
697 | } |
|
703 | } | |
698 |
|
704 | |||
699 | #include "moc_qboxplotseries.cpp" |
|
705 | #include "moc_qboxplotseries.cpp" | |
700 | #include "moc_qboxplotseries_p.cpp" |
|
706 | #include "moc_qboxplotseries_p.cpp" | |
701 |
|
707 | |||
702 | QT_CHARTS_END_NAMESPACE |
|
708 | QT_CHARTS_END_NAMESPACE | |
703 |
|
709 |
@@ -1,349 +1,349 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2015 The Qt Company Ltd |
|
3 | ** Copyright (C) 2015 The Qt Company Ltd | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to The Qt Company, please use contact form at http://qt.io |
|
5 | ** For any questions to The Qt Company, please use contact form at http://qt.io | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Charts module. |
|
7 | ** This file is part of the Qt Charts module. | |
8 | ** |
|
8 | ** | |
9 | ** Licensees holding valid commercial license for Qt may use this file in |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
10 | ** accordance with the Qt License Agreement provided with the Software |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
11 | ** or, alternatively, in accordance with the terms contained in a written |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
12 | ** agreement between you and The Qt Company. |
|
12 | ** agreement between you and The Qt Company. | |
13 | ** |
|
13 | ** | |
14 | ** If you have questions regarding the use of this file, please use |
|
14 | ** If you have questions regarding the use of this file, please use | |
15 | ** contact form at http://qt.io |
|
15 | ** contact form at http://qt.io | |
16 | ** |
|
16 | ** | |
17 | ****************************************************************************/ |
|
17 | ****************************************************************************/ | |
18 |
|
18 | |||
19 | #include <QtCharts/QBoxSet> |
|
19 | #include <QtCharts/QBoxSet> | |
20 | #include <private/qboxset_p.h> |
|
20 | #include <private/qboxset_p.h> | |
21 | #include <private/charthelpers_p.h> |
|
21 | #include <private/charthelpers_p.h> | |
22 |
|
22 | |||
23 | QT_CHARTS_BEGIN_NAMESPACE |
|
23 | QT_CHARTS_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QBoxSet |
|
26 | \class QBoxSet | |
27 | \inmodule Qt Charts |
|
27 | \inmodule Qt Charts | |
28 | \brief Building block for box-and-whiskers chart. |
|
28 | \brief Building block for box-and-whiskers chart. | |
29 |
|
29 | |||
30 | QBoxSet represents one box-and-whiskers item. It takes five values to create a graphical representation |
|
30 | QBoxSet represents one box-and-whiskers item. It takes five values to create a graphical representation | |
31 | of range and three medians. There are two ways to give the values. The first one is with constructor |
|
31 | of range and three medians. There are two ways to give the values. The first one is with constructor | |
32 | or stream operator (<<). The values have to be given in the following order: lower extreme, |
|
32 | or stream operator (<<). The values have to be given in the following order: lower extreme, | |
33 | lower quartile, median, upper quartile and upper extreme. The Second method is to create an empty QBoxSet instance and |
|
33 | lower quartile, median, upper quartile and upper extreme. The Second method is to create an empty QBoxSet instance and | |
34 | give the values using setValue method. |
|
34 | give the values using setValue method. | |
35 |
|
35 | |||
36 | \sa QBoxPlotSeries |
|
36 | \sa QBoxPlotSeries | |
37 | */ |
|
37 | */ | |
38 | /*! |
|
38 | /*! | |
39 | \enum QBoxSet::ValuePositions |
|
39 | \enum QBoxSet::ValuePositions | |
40 |
|
40 | |||
41 | \value LowerExtreme |
|
41 | \value LowerExtreme | |
42 | \value LowerQuartile |
|
42 | \value LowerQuartile | |
43 | \value Median |
|
43 | \value Median | |
44 | \value UpperQuartile |
|
44 | \value UpperQuartile | |
45 | \value UpperExtreme |
|
45 | \value UpperExtreme | |
46 | */ |
|
46 | */ | |
47 | /*! |
|
47 | /*! | |
48 | \property QBoxSet::pen |
|
48 | \property QBoxSet::pen | |
49 | \brief Defines the pen used by the box-and-whiskers set. |
|
49 | \brief Defines the pen used by the box-and-whiskers set. | |
50 | */ |
|
50 | */ | |
51 | /*! |
|
51 | /*! | |
52 | \property QBoxSet::brush |
|
52 | \property QBoxSet::brush | |
53 | \brief Defines the brush used by the box-and-whiskers set. |
|
53 | \brief Defines the brush used by the box-and-whiskers set. | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | \qmlproperty QString BoxSet::brushFilename |
|
57 | \qmlproperty QString BoxSet::brushFilename | |
58 | The name of the file used as a brush for the box-and-whiskers set. |
|
58 | The name of the file used as a brush for the box-and-whiskers set. | |
59 | */ |
|
59 | */ | |
60 |
|
60 | |||
61 | /*! |
|
61 | /*! | |
62 | \fn void QBoxSet::clicked() |
|
62 | \fn void QBoxSet::clicked() | |
63 | The signal is emitted if the user clicks with a mouse on top of box-and-whisker item. |
|
63 | The signal is emitted if the user clicks with a mouse on top of box-and-whisker item. | |
64 | */ |
|
64 | */ | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | \fn void QBoxSet::pressed() |
|
67 | \fn void QBoxSet::pressed() | |
68 | The signal is emitted if the user presses with a mouse on top of box-and-whisker item. |
|
68 | The signal is emitted if the user presses with a mouse on top of box-and-whisker item. | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \fn void QBoxSet::released() |
|
72 | \fn void QBoxSet::released() | |
73 | The signal is emitted if the user releases with a mouse on top of box-and-whisker item. |
|
73 | The signal is emitted if the user releases with a mouse on top of box-and-whisker item. | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \fn void QBoxSet::doubleClicked() |
|
77 | \fn void QBoxSet::doubleClicked() | |
78 | The signal is emitted if the user doubleclicks with a mouse on top of box-and-whisker item. |
|
78 | The signal is emitted if the user doubleclicks with a mouse on top of box-and-whisker item. | |
79 | */ |
|
79 | */ | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | \fn void QBoxSet::hovered(bool status) |
|
82 | \fn void QBoxSet::hovered(bool status) | |
83 |
|
83 | |||
84 | The signal is emitted if mouse is hovered on top of box-and-whisker item. |
|
84 | The signal is emitted if mouse is hovered on top of box-and-whisker item. | |
85 | Parameter \a status is true, if mouse entered on top of item, false if mouse left from top of item. |
|
85 | Parameter \a status is true, if mouse entered on top of item, false if mouse left from top of item. | |
86 | */ |
|
86 | */ | |
87 | /*! |
|
87 | /*! | |
88 | \fn void QBoxSet::penChanged() |
|
88 | \fn void QBoxSet::penChanged() | |
89 | This signal is emitted when the pen of the box-and-whisker item has changed. |
|
89 | This signal is emitted when the pen of the box-and-whisker item has changed. | |
90 | \sa pen |
|
90 | \sa pen | |
91 | */ |
|
91 | */ | |
92 | /*! |
|
92 | /*! | |
93 | \fn void QBoxSet::brushChanged() |
|
93 | \fn void QBoxSet::brushChanged() | |
94 | This signal is emitted when the brush of the box-and-whisker item has changed. |
|
94 | This signal is emitted when the brush of the box-and-whisker item has changed. | |
95 | \sa brush |
|
95 | \sa brush | |
96 | */ |
|
96 | */ | |
97 | /*! |
|
97 | /*! | |
98 | \fn void QBoxSet::valuesChanged() |
|
98 | \fn void QBoxSet::valuesChanged() | |
99 | This signal is emitted when multiple values have been changed on the box-and-whisker item. |
|
99 | This signal is emitted when multiple values have been changed on the box-and-whisker item. | |
100 | \sa append() |
|
100 | \sa append() | |
101 | */ |
|
101 | */ | |
102 | /*! |
|
102 | /*! | |
103 | \fn void QBoxSet::valueChanged(int index) |
|
103 | \fn void QBoxSet::valueChanged(int index) | |
104 | This signal is emitted values the value in the box-and-whisker item has been modified. |
|
104 | This signal is emitted values the value in the box-and-whisker item has been modified. | |
105 | Parameter \a index indicates the position of the modified value. |
|
105 | Parameter \a index indicates the position of the modified value. | |
106 | \sa at() |
|
106 | \sa at() | |
107 | */ |
|
107 | */ | |
108 | /*! |
|
108 | /*! | |
109 | \fn void QBoxSet::cleared() |
|
109 | \fn void QBoxSet::cleared() | |
110 | This signal is emitted when all the values on the set are cleared to 0. |
|
110 | This signal is emitted when all the values on the set are cleared to 0. | |
111 | */ |
|
111 | */ | |
112 |
|
112 | |||
113 | /*! |
|
113 | /*! | |
114 | Constructs QBoxSet with optional \a label and parent of \a parent |
|
114 | Constructs QBoxSet with optional \a label and parent of \a parent | |
115 | */ |
|
115 | */ | |
116 | QBoxSet::QBoxSet(const QString label, QObject *parent) |
|
116 | QBoxSet::QBoxSet(const QString label, QObject *parent) | |
117 | : QObject(parent), |
|
117 | : QObject(parent), | |
118 | d_ptr(new QBoxSetPrivate(label, this)) |
|
118 | d_ptr(new QBoxSetPrivate(label, this)) | |
119 | { |
|
119 | { | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | Constructs QBoxSet with given ordered values. \a le for lower extreme, \a lq for lower quartile, \a m for median, |
|
123 | Constructs QBoxSet with given ordered values. \a le for lower extreme, \a lq for lower quartile, \a m for median, | |
124 | \a uq for upper quartile and \a ue for upper quartile. \a label and \a parent are optional. |
|
124 | \a uq for upper quartile and \a ue for upper quartile. \a label and \a parent are optional. | |
125 | */ |
|
125 | */ | |
126 | QBoxSet::QBoxSet(const qreal le, const qreal lq, const qreal m, const qreal uq, const qreal ue, const QString label, QObject *parent) |
|
126 | QBoxSet::QBoxSet(const qreal le, const qreal lq, const qreal m, const qreal uq, const qreal ue, const QString label, QObject *parent) | |
127 | : QObject(parent), |
|
127 | : QObject(parent), | |
128 | d_ptr(new QBoxSetPrivate(label, this)) |
|
128 | d_ptr(new QBoxSetPrivate(label, this)) | |
129 | { |
|
129 | { | |
130 | d_ptr->append(le); |
|
130 | d_ptr->append(le); | |
131 | d_ptr->append(lq); |
|
131 | d_ptr->append(lq); | |
132 | d_ptr->append(m); |
|
132 | d_ptr->append(m); | |
133 | d_ptr->append(uq); |
|
133 | d_ptr->append(uq); | |
134 | d_ptr->append(ue); |
|
134 | d_ptr->append(ue); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | Destroys the boxset |
|
138 | Destroys the boxset | |
139 | */ |
|
139 | */ | |
140 | QBoxSet::~QBoxSet() |
|
140 | QBoxSet::~QBoxSet() | |
141 | { |
|
141 | { | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | Appends new value \a value to the end of set. |
|
145 | Appends new value \a value to the end of set. | |
146 | */ |
|
146 | */ | |
147 | void QBoxSet::append(const qreal value) |
|
147 | void QBoxSet::append(const qreal value) | |
148 | { |
|
148 | { | |
149 | if (d_ptr->append(value)) |
|
149 | if (d_ptr->append(value)) | |
150 | emit valueChanged(d_ptr->m_appendCount - 1); |
|
150 | emit valueChanged(d_ptr->m_appendCount - 1); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | /*! |
|
153 | /*! | |
154 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
154 | Appends a list of reals to set. Works like append with single real value. The \a values in list | |
155 | are appended to end of boxset. |
|
155 | are appended to end of boxset. | |
156 | \sa append() |
|
156 | \sa append() | |
157 | */ |
|
157 | */ | |
158 | void QBoxSet::append(const QList<qreal> &values) |
|
158 | void QBoxSet::append(const QList<qreal> &values) | |
159 | { |
|
159 | { | |
160 | if (d_ptr->append(values)) |
|
160 | if (d_ptr->append(values)) | |
161 | emit valuesChanged(); |
|
161 | emit valuesChanged(); | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | Sets new \a label for set. |
|
165 | Sets new \a label for the category of the set. | |
166 | */ |
|
166 | */ | |
167 | void QBoxSet::setLabel(const QString label) |
|
167 | void QBoxSet::setLabel(const QString label) | |
168 | { |
|
168 | { | |
169 | d_ptr->m_label = label; |
|
169 | d_ptr->m_label = label; | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | Returns label of the set. |
|
173 | Returns the label of the the category of the set. | |
174 | */ |
|
174 | */ | |
175 | QString QBoxSet::label() const |
|
175 | QString QBoxSet::label() const | |
176 | { |
|
176 | { | |
177 | return d_ptr->m_label; |
|
177 | return d_ptr->m_label; | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | /*! |
|
180 | /*! | |
181 | Convenience operator. Same as append, with real \a value. |
|
181 | Convenience operator. Same as append, with real \a value. | |
182 | \sa append() |
|
182 | \sa append() | |
183 | */ |
|
183 | */ | |
184 | QBoxSet &QBoxSet::operator << (const qreal &value) |
|
184 | QBoxSet &QBoxSet::operator << (const qreal &value) | |
185 | { |
|
185 | { | |
186 | append(value); |
|
186 | append(value); | |
187 | return *this; |
|
187 | return *this; | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | /*! |
|
190 | /*! | |
191 | Sets a new \a value on the \a index position. For \a index ValuePositions can be used. |
|
191 | Sets a new \a value on the \a index position. For \a index ValuePositions can be used. | |
192 | */ |
|
192 | */ | |
193 | void QBoxSet::setValue(const int index, const qreal value) |
|
193 | void QBoxSet::setValue(const int index, const qreal value) | |
194 | { |
|
194 | { | |
195 | d_ptr->setValue(index, value); |
|
195 | d_ptr->setValue(index, value); | |
196 | emit valueChanged(index); |
|
196 | emit valueChanged(index); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | /*! |
|
199 | /*! | |
200 | Sets all values on the set to 0. |
|
200 | Sets all values on the set to 0. | |
201 | */ |
|
201 | */ | |
202 | void QBoxSet::clear() |
|
202 | void QBoxSet::clear() | |
203 | { |
|
203 | { | |
204 | d_ptr->clear(); |
|
204 | d_ptr->clear(); | |
205 | emit cleared(); |
|
205 | emit cleared(); | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | /*! |
|
208 | /*! | |
209 | Returns value of set indexed by \a index. For \a index ValuePositions can be used. |
|
209 | Returns value of set indexed by \a index. For \a index ValuePositions can be used. | |
210 | If the index is out of bounds 0.0 is returned. |
|
210 | If the index is out of bounds 0.0 is returned. | |
211 | */ |
|
211 | */ | |
212 | qreal QBoxSet::at(const int index) const |
|
212 | qreal QBoxSet::at(const int index) const | |
213 | { |
|
213 | { | |
214 | if (index < 0 || index >= 5) |
|
214 | if (index < 0 || index >= 5) | |
215 | return 0; |
|
215 | return 0; | |
216 | return d_ptr->m_values[index]; |
|
216 | return d_ptr->m_values[index]; | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | /*! |
|
219 | /*! | |
220 | Returns value of set indexed by \a index. For \a index ValuePositions can be used. |
|
220 | Returns value of set indexed by \a index. For \a index ValuePositions can be used. | |
221 | If the index is out of bounds 0.0 is returned. |
|
221 | If the index is out of bounds 0.0 is returned. | |
222 | */ |
|
222 | */ | |
223 | qreal QBoxSet::operator [](const int index) const |
|
223 | qreal QBoxSet::operator [](const int index) const | |
224 | { |
|
224 | { | |
225 | return at(index); |
|
225 | return at(index); | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | /*! |
|
228 | /*! | |
229 | Returns count of values appended to the set. |
|
229 | Returns count of values appended to the set. | |
230 | */ |
|
230 | */ | |
231 | int QBoxSet::count() const |
|
231 | int QBoxSet::count() const | |
232 | { |
|
232 | { | |
233 | return d_ptr->m_appendCount; |
|
233 | return d_ptr->m_appendCount; | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | /*! |
|
236 | /*! | |
237 | Sets pen for set. Boxes of this set are drawn using \a pen |
|
237 | Sets pen for set. Boxes of this set are drawn using \a pen | |
238 | */ |
|
238 | */ | |
239 | void QBoxSet::setPen(const QPen &pen) |
|
239 | void QBoxSet::setPen(const QPen &pen) | |
240 | { |
|
240 | { | |
241 | if (d_ptr->m_pen != pen) { |
|
241 | if (d_ptr->m_pen != pen) { | |
242 | d_ptr->m_pen = pen; |
|
242 | d_ptr->m_pen = pen; | |
243 | emit d_ptr->updatedBox(); |
|
243 | emit d_ptr->updatedBox(); | |
244 | emit penChanged(); |
|
244 | emit penChanged(); | |
245 | } |
|
245 | } | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | /*! |
|
248 | /*! | |
249 | Returns pen of the set. |
|
249 | Returns pen of the set. | |
250 | */ |
|
250 | */ | |
251 | QPen QBoxSet::pen() const |
|
251 | QPen QBoxSet::pen() const | |
252 | { |
|
252 | { | |
253 | return d_ptr->m_pen; |
|
253 | return d_ptr->m_pen; | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | /*! |
|
256 | /*! | |
257 | Sets brush for the set. Boxes of this set are drawn using \a brush |
|
257 | Sets brush for the set. Boxes of this set are drawn using \a brush | |
258 | */ |
|
258 | */ | |
259 | void QBoxSet::setBrush(const QBrush &brush) |
|
259 | void QBoxSet::setBrush(const QBrush &brush) | |
260 | { |
|
260 | { | |
261 | if (d_ptr->m_brush != brush) { |
|
261 | if (d_ptr->m_brush != brush) { | |
262 | d_ptr->m_brush = brush; |
|
262 | d_ptr->m_brush = brush; | |
263 | emit d_ptr->updatedBox(); |
|
263 | emit d_ptr->updatedBox(); | |
264 | emit brushChanged(); |
|
264 | emit brushChanged(); | |
265 | } |
|
265 | } | |
266 | } |
|
266 | } | |
267 |
|
267 | |||
268 | /*! |
|
268 | /*! | |
269 | Returns brush of the set. |
|
269 | Returns brush of the set. | |
270 | */ |
|
270 | */ | |
271 | QBrush QBoxSet::brush() const |
|
271 | QBrush QBoxSet::brush() const | |
272 | { |
|
272 | { | |
273 | return d_ptr->m_brush; |
|
273 | return d_ptr->m_brush; | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
276 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
277 |
|
277 | |||
278 | QBoxSetPrivate::QBoxSetPrivate(const QString label, QBoxSet *parent) : QObject(parent), |
|
278 | QBoxSetPrivate::QBoxSetPrivate(const QString label, QBoxSet *parent) : QObject(parent), | |
279 | q_ptr(parent), |
|
279 | q_ptr(parent), | |
280 | m_label(label), |
|
280 | m_label(label), | |
281 | m_valuesCount(5), |
|
281 | m_valuesCount(5), | |
282 | m_appendCount(0), |
|
282 | m_appendCount(0), | |
283 | m_pen(QPen(Qt::NoPen)), |
|
283 | m_pen(QPen(Qt::NoPen)), | |
284 | m_brush(QBrush(Qt::NoBrush)), |
|
284 | m_brush(QBrush(Qt::NoBrush)), | |
285 | m_series(0) |
|
285 | m_series(0) | |
286 | { |
|
286 | { | |
287 | m_values = new qreal[m_valuesCount]; |
|
287 | m_values = new qreal[m_valuesCount]; | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | QBoxSetPrivate::~QBoxSetPrivate() |
|
290 | QBoxSetPrivate::~QBoxSetPrivate() | |
291 | { |
|
291 | { | |
292 | delete[] m_values; |
|
292 | delete[] m_values; | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | bool QBoxSetPrivate::append(qreal value) |
|
295 | bool QBoxSetPrivate::append(qreal value) | |
296 | { |
|
296 | { | |
297 | if (isValidValue(value) && m_appendCount < m_valuesCount) { |
|
297 | if (isValidValue(value) && m_appendCount < m_valuesCount) { | |
298 | m_values[m_appendCount++] = value; |
|
298 | m_values[m_appendCount++] = value; | |
299 | emit restructuredBox(); |
|
299 | emit restructuredBox(); | |
300 |
|
300 | |||
301 | return true; |
|
301 | return true; | |
302 | } |
|
302 | } | |
303 | return false; |
|
303 | return false; | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | bool QBoxSetPrivate::append(QList<qreal> values) |
|
306 | bool QBoxSetPrivate::append(QList<qreal> values) | |
307 | { |
|
307 | { | |
308 | bool success = false; |
|
308 | bool success = false; | |
309 |
|
309 | |||
310 | for (int i = 0; i < values.count(); i++) { |
|
310 | for (int i = 0; i < values.count(); i++) { | |
311 | if (isValidValue(values.at(i)) && m_appendCount < m_valuesCount) { |
|
311 | if (isValidValue(values.at(i)) && m_appendCount < m_valuesCount) { | |
312 | success = true; |
|
312 | success = true; | |
313 | m_values[m_appendCount++] = values.at(i); |
|
313 | m_values[m_appendCount++] = values.at(i); | |
314 | } |
|
314 | } | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | if (success) |
|
317 | if (success) | |
318 | emit restructuredBox(); |
|
318 | emit restructuredBox(); | |
319 |
|
319 | |||
320 | return success; |
|
320 | return success; | |
321 | } |
|
321 | } | |
322 |
|
322 | |||
323 | void QBoxSetPrivate::clear() |
|
323 | void QBoxSetPrivate::clear() | |
324 | { |
|
324 | { | |
325 | m_appendCount = 0; |
|
325 | m_appendCount = 0; | |
326 | for (int i = 0; i < m_valuesCount; i++) |
|
326 | for (int i = 0; i < m_valuesCount; i++) | |
327 | m_values[i] = 0.0; |
|
327 | m_values[i] = 0.0; | |
328 | emit restructuredBox(); |
|
328 | emit restructuredBox(); | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | void QBoxSetPrivate::setValue(const int index, const qreal value) |
|
331 | void QBoxSetPrivate::setValue(const int index, const qreal value) | |
332 | { |
|
332 | { | |
333 | if (index < m_valuesCount) { |
|
333 | if (index < m_valuesCount) { | |
334 | m_values[index] = value; |
|
334 | m_values[index] = value; | |
335 | emit updatedLayout(); |
|
335 | emit updatedLayout(); | |
336 | } |
|
336 | } | |
337 | } |
|
337 | } | |
338 |
|
338 | |||
339 | qreal QBoxSetPrivate::value(const int index) |
|
339 | qreal QBoxSetPrivate::value(const int index) | |
340 | { |
|
340 | { | |
341 | if (index < 0 || index >= m_valuesCount) |
|
341 | if (index < 0 || index >= m_valuesCount) | |
342 | return 0; |
|
342 | return 0; | |
343 | return m_values[index]; |
|
343 | return m_values[index]; | |
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 | #include "moc_qboxset.cpp" |
|
346 | #include "moc_qboxset.cpp" | |
347 | #include "moc_qboxset_p.cpp" |
|
347 | #include "moc_qboxset_p.cpp" | |
348 |
|
348 | |||
349 | QT_CHARTS_END_NAMESPACE |
|
349 | QT_CHARTS_END_NAMESPACE |
@@ -1,459 +1,465 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2015 The Qt Company Ltd |
|
3 | ** Copyright (C) 2015 The Qt Company Ltd | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to The Qt Company, please use contact form at http://qt.io |
|
5 | ** For any questions to The Qt Company, please use contact form at http://qt.io | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Charts module. |
|
7 | ** This file is part of the Qt Charts module. | |
8 | ** |
|
8 | ** | |
9 | ** Licensees holding valid commercial license for Qt may use this file in |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
10 | ** accordance with the Qt License Agreement provided with the Software |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
11 | ** or, alternatively, in accordance with the terms contained in a written |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
12 | ** agreement between you and The Qt Company. |
|
12 | ** agreement between you and The Qt Company. | |
13 | ** |
|
13 | ** | |
14 | ** If you have questions regarding the use of this file, please use |
|
14 | ** If you have questions regarding the use of this file, please use | |
15 | ** contact form at http://qt.io |
|
15 | ** contact form at http://qt.io | |
16 | ** |
|
16 | ** | |
17 | ****************************************************************************/ |
|
17 | ****************************************************************************/ | |
18 |
|
18 | |||
19 | #include "declarativebarseries.h" |
|
19 | #include "declarativebarseries.h" | |
20 | #include "declarativeboxplotseries.h" |
|
20 | #include "declarativeboxplotseries.h" | |
21 | #include <QtCharts/QBoxSet> |
|
21 | #include <QtCharts/QBoxSet> | |
22 | #include <QtCharts/QVBoxPlotModelMapper> |
|
22 | #include <QtCharts/QVBoxPlotModelMapper> | |
23 |
|
23 | |||
24 | QT_CHARTS_BEGIN_NAMESPACE |
|
24 | QT_CHARTS_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \qmltype BoxSet |
|
27 | \qmltype BoxSet | |
28 | \instantiates QBoxSet |
|
28 | \instantiates QBoxSet | |
29 | \inqmlmodule QtCharts |
|
29 | \inqmlmodule QtCharts | |
30 |
|
30 | |||
31 | \brief Building block for box-and-whiskers chart. |
|
31 | \brief Building block for box-and-whiskers chart. | |
32 |
|
32 | |||
33 | BoxSet represents one box-and-whiskers item. It takes five values to create a graphical |
|
33 | BoxSet represents one box-and-whiskers item. It takes five values to create a graphical | |
34 | representation of range and three medians. There are two ways to give the values. The first one |
|
34 | representation of range and three medians. There are two ways to give the values. The first one | |
35 | is with constructor or with append method. In these the values have to be given in the following |
|
35 | is with constructor or with append method. In these the values have to be given in the following | |
36 | order: lower extreme, lower quartile, median, upper quartile and upper extreme. The second |
|
36 | order: lower extreme, lower quartile, median, upper quartile and upper extreme. The second | |
37 | method is to create an empty QBoxSet instance and give the values using value specific methods. |
|
37 | method is to create an empty QBoxSet instance and give the values using value specific methods. | |
38 | \sa BoxPlotSeries |
|
38 | \sa BoxPlotSeries | |
39 | */ |
|
39 | */ | |
40 | /*! |
|
40 | /*! | |
41 | \qmlproperty string BoxSet::values |
|
41 | \qmlproperty string BoxSet::values | |
42 | The values on the box-and-whiskers set. |
|
42 | The values on the box-and-whiskers set. | |
43 | */ |
|
43 | */ | |
44 | /*! |
|
44 | /*! | |
45 | \qmlproperty string BoxSet::label |
|
45 | \qmlproperty string BoxSet::label | |
46 | Defines the label of the box-and-whiskers set. |
|
46 | Defines the label of the category of the box-and-whiskers set. | |
47 | */ |
|
47 | */ | |
48 | /*! |
|
48 | /*! | |
49 | \qmlproperty int BoxSet::count |
|
49 | \qmlproperty int BoxSet::count | |
50 | The count of values on the box-and-whiskers set |
|
50 | The count of values on the box-and-whiskers set | |
51 | */ |
|
51 | */ | |
52 | /*! |
|
52 | /*! | |
53 | \qmlmethod void BoxSet::at(int index) |
|
53 | \qmlmethod void BoxSet::at(int index) | |
54 | Returns the value at \a index position. |
|
54 | Returns the value at \a index position. | |
55 | */ |
|
55 | */ | |
56 | /*! |
|
56 | /*! | |
57 | \qmlmethod void BoxSet::append(qreal value) |
|
57 | \qmlmethod void BoxSet::append(qreal value) | |
58 | Appends new value \a value to the end of set. |
|
58 | Appends new value \a value to the end of set. | |
59 | */ |
|
59 | */ | |
60 | /*! |
|
60 | /*! | |
61 | \qmlmethod void BoxSet::clear() |
|
61 | \qmlmethod void BoxSet::clear() | |
62 | Sets all values on the set to 0. |
|
62 | Sets all values on the set to 0. | |
63 | */ |
|
63 | */ | |
64 | /*! |
|
64 | /*! | |
65 | \qmlmethod void BoxSet::setValue(int index, qreal value) |
|
65 | \qmlmethod void BoxSet::setValue(int index, qreal value) | |
66 | Sets a new \a value on the \a index position. |
|
66 | Sets a new \a value on the \a index position. | |
67 | */ |
|
67 | */ | |
68 | /*! |
|
68 | /*! | |
69 | \qmlsignal BoxSet::onClicked() |
|
69 | \qmlsignal BoxSet::onClicked() | |
70 | This signal is emitted when the user clicks with a mouse on top of box-and-whiskers item. |
|
70 | This signal is emitted when the user clicks with a mouse on top of box-and-whiskers item. | |
71 | */ |
|
71 | */ | |
72 | /*! |
|
72 | /*! | |
73 | \qmlsignal BoxSet::onPressed() |
|
73 | \qmlsignal BoxSet::onPressed() | |
74 | This signal is emitted when the user presses with a mouse on top of box-and-whiskers item. |
|
74 | This signal is emitted when the user presses with a mouse on top of box-and-whiskers item. | |
75 | */ |
|
75 | */ | |
76 | /*! |
|
76 | /*! | |
77 | \qmlsignal BoxSet::onReleased() |
|
77 | \qmlsignal BoxSet::onReleased() | |
78 | This signal is emitted when the user releases with a mouse on top of box-and-whiskers item. |
|
78 | This signal is emitted when the user releases with a mouse on top of box-and-whiskers item. | |
79 | */ |
|
79 | */ | |
80 | /*! |
|
80 | /*! | |
81 | \qmlsignal BoxSet::onDoubleClicked() |
|
81 | \qmlsignal BoxSet::onDoubleClicked() | |
82 | This signal is emitted when the user doubleclicks with a mouse on top of box-and-whiskers item. |
|
82 | This signal is emitted when the user doubleclicks with a mouse on top of box-and-whiskers item. | |
83 | */ |
|
83 | */ | |
84 | /*! |
|
84 | /*! | |
85 | \qmlsignal BoxSet::onHovered(bool status) |
|
85 | \qmlsignal BoxSet::onHovered(bool status) | |
86 | The signal is emitted if mouse is hovered on top of box-and-whiskers item. |
|
86 | The signal is emitted if mouse is hovered on top of box-and-whiskers item. | |
87 | Parameter \a status is true, if mouse entered on top of the item, and false if mouse left from top of the item. |
|
87 | Parameter \a status is true, if mouse entered on top of the item, and false if mouse left from top of the item. | |
88 | */ |
|
88 | */ | |
89 | /*! |
|
89 | /*! | |
90 | \qmlsignal BoxSet::onPenChanged() |
|
90 | \qmlsignal BoxSet::onPenChanged() | |
91 | This signal is emitted when the pen of the box-and-whiskers item has changed. |
|
91 | This signal is emitted when the pen of the box-and-whiskers item has changed. | |
92 | */ |
|
92 | */ | |
93 | /*! |
|
93 | /*! | |
94 | \qmlsignal BoxSet::onBrushChanged() |
|
94 | \qmlsignal BoxSet::onBrushChanged() | |
95 | This signal is emitted when the brush of the box-and-whiskers item has changed. |
|
95 | This signal is emitted when the brush of the box-and-whiskers item has changed. | |
96 | */ |
|
96 | */ | |
97 | /*! |
|
97 | /*! | |
98 | \qmlsignal BoxSet::onChangedValues() |
|
98 | \qmlsignal BoxSet::onChangedValues() | |
99 | This signal is emitted when multiple values have been changed on the box-and-whiskers item. |
|
99 | This signal is emitted when multiple values have been changed on the box-and-whiskers item. | |
100 | */ |
|
100 | */ | |
101 | /*! |
|
101 | /*! | |
102 | \qmlsignal BoxSet::onChangedValue(int index) |
|
102 | \qmlsignal BoxSet::onChangedValue(int index) | |
103 | This signal is emitted values the value in the box-and-whiskers item has been modified. |
|
103 | This signal is emitted values the value in the box-and-whiskers item has been modified. | |
104 | Parameter \a index indicates the position of the modified value. |
|
104 | Parameter \a index indicates the position of the modified value. | |
105 | */ |
|
105 | */ | |
106 | /*! |
|
106 | /*! | |
107 | \qmlsignal BoxSet::onCleared() |
|
107 | \qmlsignal BoxSet::onCleared() | |
108 | This signal is emitted when all the values on the set are cleared to 0. |
|
108 | This signal is emitted when all the values on the set are cleared to 0. | |
109 | */ |
|
109 | */ | |
110 |
|
110 | |||
111 | /*! |
|
111 | /*! | |
112 | \qmltype BoxPlotSeries |
|
112 | \qmltype BoxPlotSeries | |
113 | \instantiates QBoxPlotSeries |
|
113 | \instantiates QBoxPlotSeries | |
114 | \inqmlmodule QtCharts |
|
114 | \inqmlmodule QtCharts | |
115 |
|
115 | |||
116 | \inherits AbstractSeries |
|
116 | \inherits AbstractSeries | |
117 |
|
117 | |||
118 | \brief Series for creating box-and-whiskers chart. |
|
118 | \brief Series for creating box-and-whiskers chart. | |
119 |
|
119 | |||
120 | BoxPlotSeries represents a series of data shown as box-and-whiskers bars. The purpose of this |
|
120 | BoxPlotSeries represents a series of data shown as box-and-whiskers bars. The purpose of this | |
121 | class is to act as a container for single box-and-whiskers items. Each item is drawn to own |
|
121 | class is to act as a container for single box-and-whiskers items. Each item is drawn to own | |
122 | slot. If chart includes multiple instances of BoxPlotSeries then box-and-whiskers items with the |
|
122 | slot. If chart includes multiple instances of BoxPlotSeries then box-and-whiskers items with the | |
123 | same index are drawn to same slot. |
|
123 | same index are drawn to same slot. | |
124 |
|
124 | |||
|
125 | \note The slot, each item in BoxPlotSeries is drawn, represents a category in BarCategoryAxis. | |||
|
126 | The category labels have to be unique. If same category label is defined for several | |||
|
127 | box-and-whisker items only the first one is drawn. | |||
|
128 | ||||
125 | The following QML shows how to create a simple box-and-whiskers chart: |
|
129 | The following QML shows how to create a simple box-and-whiskers chart: | |
126 | \code |
|
130 | \code | |
127 | import QtQuick 2.0 |
|
131 | import QtQuick 2.0 | |
128 | import QtCharts 2.0 |
|
132 | import QtCharts 2.0 | |
129 |
|
133 | |||
130 | ChartView { |
|
134 | ChartView { | |
131 | title: "Box Plot series" |
|
135 | title: "Box Plot series" | |
132 | width: 400 |
|
136 | width: 400 | |
133 | height: 300 |
|
137 | height: 300 | |
134 | theme: ChartView.ChartThemeBrownSand |
|
138 | theme: ChartView.ChartThemeBrownSand | |
135 | legend.alignment: Qt.AlignBottom |
|
139 | legend.alignment: Qt.AlignBottom | |
136 |
|
140 | |||
137 | BoxPlotSeries { |
|
141 | BoxPlotSeries { | |
138 | id: plotSeries |
|
142 | id: plotSeries | |
139 | name: "Income" |
|
143 | name: "Income" | |
140 | BoxSet { label: "Jan"; values: [3, 4, 5.1, 6.2, 8.5] } |
|
144 | BoxSet { label: "Jan"; values: [3, 4, 5.1, 6.2, 8.5] } | |
141 | BoxSet { label: "Feb"; values: [5, 6, 7.5, 8.6, 11.8] } |
|
145 | BoxSet { label: "Feb"; values: [5, 6, 7.5, 8.6, 11.8] } | |
142 | BoxSet { label: "Mar"; values: [3.2, 5, 5.7, 8, 9.2] } |
|
146 | BoxSet { label: "Mar"; values: [3.2, 5, 5.7, 8, 9.2] } | |
143 | BoxSet { label: "Apr"; values: [3.8, 5, 6.4, 7, 8] } |
|
147 | BoxSet { label: "Apr"; values: [3.8, 5, 6.4, 7, 8] } | |
144 | BoxSet { label: "May"; values: [4, 5, 5.2, 6, 7] } |
|
148 | BoxSet { label: "May"; values: [4, 5, 5.2, 6, 7] } | |
145 | } |
|
149 | } | |
146 | } |
|
150 | } | |
147 | \endcode |
|
151 | \endcode | |
148 |
|
152 | |||
149 | \beginfloatleft |
|
153 | \beginfloatleft | |
150 | \image examples_qmlboxplot.png |
|
154 | \image examples_qmlboxplot.png | |
151 | \endfloat |
|
155 | \endfloat | |
152 | \clearfloat |
|
156 | \clearfloat | |
|
157 | ||||
|
158 | \sa BoxSet, BarCategoryAxis | |||
153 | */ |
|
159 | */ | |
154 |
|
160 | |||
155 | /*! |
|
161 | /*! | |
156 | \qmlmethod BoxPlotSeries::append(string label, VariantList values) |
|
162 | \qmlmethod BoxPlotSeries::append(string label, VariantList values) | |
157 | Appends a new box-and-whiskers set with \a label and \a values to the series. |
|
163 | Appends a new box-and-whiskers set with \a label and \a values to the series. | |
158 | */ |
|
164 | */ | |
159 | /*! |
|
165 | /*! | |
160 | \qmlmethod BoxPlotSeries::append(BoxSet box) |
|
166 | \qmlmethod BoxPlotSeries::append(BoxSet box) | |
161 | Appends the \a box to the series. |
|
167 | Appends the \a box to the series. | |
162 | */ |
|
168 | */ | |
163 | /*! |
|
169 | /*! | |
164 | \qmlmethod BoxPlotSeries::insert(int index, string label, VariantList values) |
|
170 | \qmlmethod BoxPlotSeries::insert(int index, string label, VariantList values) | |
165 | Inserts a new box-and-whiskers set with \a label and \a values at the \a index position. |
|
171 | Inserts a new box-and-whiskers set with \a label and \a values at the \a index position. | |
166 | */ |
|
172 | */ | |
167 | /*! |
|
173 | /*! | |
168 | \qmlmethod BoxPlotSeries::remove(QBoxSet boxset) |
|
174 | \qmlmethod BoxPlotSeries::remove(QBoxSet boxset) | |
169 | Removes the \a boxset from the series. |
|
175 | Removes the \a boxset from the series. | |
170 | */ |
|
176 | */ | |
171 | /*! |
|
177 | /*! | |
172 | \qmlmethod BoxPlotSeries::clear() |
|
178 | \qmlmethod BoxPlotSeries::clear() | |
173 | Removes all boxsets from the series. Deletes removed sets. |
|
179 | Removes all boxsets from the series. Deletes removed sets. | |
174 | */ |
|
180 | */ | |
175 | /*! |
|
181 | /*! | |
176 | \qmlsignal BoxPlotSeries::onClicked(BoxSet boxset); |
|
182 | \qmlsignal BoxPlotSeries::onClicked(BoxSet boxset); | |
177 | Signal is emitted when the user clicks the \a boxset on the chart. |
|
183 | Signal is emitted when the user clicks the \a boxset on the chart. | |
178 | */ |
|
184 | */ | |
179 | /*! |
|
185 | /*! | |
180 | \qmlsignal BoxPlotSeries::onHovered(bool status, BoxSet boxset); |
|
186 | \qmlsignal BoxPlotSeries::onHovered(bool status, BoxSet boxset); | |
181 | Signal is emitted when there is change in hover \a status over \a boxset. |
|
187 | Signal is emitted when there is change in hover \a status over \a boxset. | |
182 | */ |
|
188 | */ | |
183 | /*! |
|
189 | /*! | |
184 | \qmlsignal BoxPlotSeries::onPressed(BoxSet boxset) |
|
190 | \qmlsignal BoxPlotSeries::onPressed(BoxSet boxset) | |
185 | This signal is emitted when the user presses the \a boxset on the chart. |
|
191 | This signal is emitted when the user presses the \a boxset on the chart. | |
186 | */ |
|
192 | */ | |
187 | /*! |
|
193 | /*! | |
188 | \qmlsignal BoxPlotSeries::onReleased(BoxSet boxset) |
|
194 | \qmlsignal BoxPlotSeries::onReleased(BoxSet boxset) | |
189 | This signal is emitted when the user releases the \a boxset on the chart. |
|
195 | This signal is emitted when the user releases the \a boxset on the chart. | |
190 | */ |
|
196 | */ | |
191 | /*! |
|
197 | /*! | |
192 | \qmlsignal BoxPlotSeries::onDoubleClicked(BoxSet boxset) |
|
198 | \qmlsignal BoxPlotSeries::onDoubleClicked(BoxSet boxset) | |
193 | This signal is emitted when the user doubleclicks the \a boxset on the chart. |
|
199 | This signal is emitted when the user doubleclicks the \a boxset on the chart. | |
194 | */ |
|
200 | */ | |
195 | /*! |
|
201 | /*! | |
196 | \qmlsignal BoxPlotSeries::onCountChanged(); |
|
202 | \qmlsignal BoxPlotSeries::onCountChanged(); | |
197 | Signal is emitted when there is change in count of box-and-whiskers items in the series. |
|
203 | Signal is emitted when there is change in count of box-and-whiskers items in the series. | |
198 | */ |
|
204 | */ | |
199 | /*! |
|
205 | /*! | |
200 | \qmlsignal BoxPlotSeries::onBoxsetsAdded() |
|
206 | \qmlsignal BoxPlotSeries::onBoxsetsAdded() | |
201 | Signal is emitted when new box-and-whiskers sets are added to the series. |
|
207 | Signal is emitted when new box-and-whiskers sets are added to the series. | |
202 | */ |
|
208 | */ | |
203 | /*! |
|
209 | /*! | |
204 | \qmlsignal BoxPlotSeries::onBoxsetsRemoved() |
|
210 | \qmlsignal BoxPlotSeries::onBoxsetsRemoved() | |
205 | Signal is emitted when new box-and-whiskers sets are removed from the series. |
|
211 | Signal is emitted when new box-and-whiskers sets are removed from the series. | |
206 | */ |
|
212 | */ | |
207 | /*! |
|
213 | /*! | |
208 | \qmlproperty AbstractAxis BoxPlotSeries::axisX |
|
214 | \qmlproperty AbstractAxis BoxPlotSeries::axisX | |
209 | The x axis used for the series. If you leave both axisX and axisXTop undefined, a BarCategoriesAxis is created for |
|
215 | The x axis used for the series. If you leave both axisX and axisXTop undefined, a BarCategoriesAxis is created for | |
210 | the series. |
|
216 | the series. | |
211 | \sa axisXTop |
|
217 | \sa axisXTop | |
212 | */ |
|
218 | */ | |
213 | /*! |
|
219 | /*! | |
214 | \qmlproperty AbstractAxis BoxPlotSeries::axisY |
|
220 | \qmlproperty AbstractAxis BoxPlotSeries::axisY | |
215 | The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for |
|
221 | The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for | |
216 | the series. |
|
222 | the series. | |
217 | \sa axisYRight |
|
223 | \sa axisYRight | |
218 | */ |
|
224 | */ | |
219 | /*! |
|
225 | /*! | |
220 | \qmlproperty AbstractAxis BoxPlotSeries::axisXTop |
|
226 | \qmlproperty AbstractAxis BoxPlotSeries::axisXTop | |
221 | The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or |
|
227 | The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or | |
222 | axisXTop, but not both. |
|
228 | axisXTop, but not both. | |
223 | \sa axisX |
|
229 | \sa axisX | |
224 | */ |
|
230 | */ | |
225 | /*! |
|
231 | /*! | |
226 | \qmlproperty AbstractAxis BoxPlotSeries::axisYRight |
|
232 | \qmlproperty AbstractAxis BoxPlotSeries::axisYRight | |
227 | The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY |
|
233 | The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY | |
228 | or axisYRight, but not both. |
|
234 | or axisYRight, but not both. | |
229 | \sa axisY |
|
235 | \sa axisY | |
230 | */ |
|
236 | */ | |
231 | /*! |
|
237 | /*! | |
232 | \qmlproperty bool BoxPlotSeries::boxOutlineVisible |
|
238 | \qmlproperty bool BoxPlotSeries::boxOutlineVisible | |
233 | This property configures the visibility of the middle box outline. |
|
239 | This property configures the visibility of the middle box outline. | |
234 | */ |
|
240 | */ | |
235 | /*! |
|
241 | /*! | |
236 | \qmlproperty qreal BoxPlotSeries::boxWidth |
|
242 | \qmlproperty qreal BoxPlotSeries::boxWidth | |
237 | This property configures the width of the box-and-whiskers item. The value signifies the relative |
|
243 | This property configures the width of the box-and-whiskers item. The value signifies the relative | |
238 | width of the box-and-whiskers item inside its own slot. The value can between 0.0 and 1.0. Negative values |
|
244 | width of the box-and-whiskers item inside its own slot. The value can between 0.0 and 1.0. Negative values | |
239 | are clamped to 0.0 and values over 1.0 are clamped to 1.0. |
|
245 | are clamped to 0.0 and values over 1.0 are clamped to 1.0. | |
240 | */ |
|
246 | */ | |
241 | /*! |
|
247 | /*! | |
242 | \qmlproperty Pen BoxPlotSeries::pen |
|
248 | \qmlproperty Pen BoxPlotSeries::pen | |
243 | This property configures the pen of the box-and-whiskers items. |
|
249 | This property configures the pen of the box-and-whiskers items. | |
244 | */ |
|
250 | */ | |
245 | /*! |
|
251 | /*! | |
246 | \qmlproperty Brush BoxPlotSeries::brush |
|
252 | \qmlproperty Brush BoxPlotSeries::brush | |
247 | This property configures the brush of the box-and-whiskers items. |
|
253 | This property configures the brush of the box-and-whiskers items. | |
248 | */ |
|
254 | */ | |
249 | /*! |
|
255 | /*! | |
250 | \qmlproperty int BoxPlotSeries::count |
|
256 | \qmlproperty int BoxPlotSeries::count | |
251 | The count of sets in series. |
|
257 | The count of sets in series. | |
252 | */ |
|
258 | */ | |
253 | /*! |
|
259 | /*! | |
254 | \qmlsignal BoxPlotSeries::onBoxOutlineVisibilityChanged() |
|
260 | \qmlsignal BoxPlotSeries::onBoxOutlineVisibilityChanged() | |
255 | Signal is emitted when the middle box outline visibility is changed. |
|
261 | Signal is emitted when the middle box outline visibility is changed. | |
256 | */ |
|
262 | */ | |
257 | /*! |
|
263 | /*! | |
258 | \qmlsignal BoxPlotSeries::onBoxWidthChanged() |
|
264 | \qmlsignal BoxPlotSeries::onBoxWidthChanged() | |
259 | Signal is emitted when the width of the box-and-whiskers item is changed. |
|
265 | Signal is emitted when the width of the box-and-whiskers item is changed. | |
260 | */ |
|
266 | */ | |
261 | /*! |
|
267 | /*! | |
262 | \qmlsignal BoxPlotSeries::onPenChanged() |
|
268 | \qmlsignal BoxPlotSeries::onPenChanged() | |
263 | Signal is emitted when the pen for box-and-whiskers items has changed. |
|
269 | Signal is emitted when the pen for box-and-whiskers items has changed. | |
264 | */ |
|
270 | */ | |
265 | /*! |
|
271 | /*! | |
266 | \qmlsignal BoxPlotSeries::onBrushChanged() |
|
272 | \qmlsignal BoxPlotSeries::onBrushChanged() | |
267 | Signal is emitted when the brush for box-and-whiskers items has changed. |
|
273 | Signal is emitted when the brush for box-and-whiskers items has changed. | |
268 | */ |
|
274 | */ | |
269 | /*! |
|
275 | /*! | |
270 | \qmlsignal BoxPlotSeries::onAxisXChanged(AbstractAxis axis) |
|
276 | \qmlsignal BoxPlotSeries::onAxisXChanged(AbstractAxis axis) | |
271 | Signal is emitted when there is change in X axis. |
|
277 | Signal is emitted when there is change in X axis. | |
272 | */ |
|
278 | */ | |
273 | /*! |
|
279 | /*! | |
274 | \qmlsignal BoxPlotSeries::onAxisYChanged(AbstractAxis axis) |
|
280 | \qmlsignal BoxPlotSeries::onAxisYChanged(AbstractAxis axis) | |
275 | Signal is emitted when there is change in Y axis. |
|
281 | Signal is emitted when there is change in Y axis. | |
276 | */ |
|
282 | */ | |
277 | /*! |
|
283 | /*! | |
278 | \qmlsignal BoxPlotSeries::onAxisXTopChanged(AbstractAxis axis) |
|
284 | \qmlsignal BoxPlotSeries::onAxisXTopChanged(AbstractAxis axis) | |
279 | Signal is emitted when there is change in top X axis. |
|
285 | Signal is emitted when there is change in top X axis. | |
280 | */ |
|
286 | */ | |
281 | /*! |
|
287 | /*! | |
282 | \qmlsignal BoxPlotSeries::onAxisYRightChanged(AbstractAxis axis) |
|
288 | \qmlsignal BoxPlotSeries::onAxisYRightChanged(AbstractAxis axis) | |
283 | Signal is emitted when there is change in Y right axis. |
|
289 | Signal is emitted when there is change in Y right axis. | |
284 | */ |
|
290 | */ | |
285 |
|
291 | |||
286 |
|
292 | |||
287 | DeclarativeBoxSet::DeclarativeBoxSet(const QString label, QObject *parent) |
|
293 | DeclarativeBoxSet::DeclarativeBoxSet(const QString label, QObject *parent) | |
288 | : QBoxSet(label, parent) |
|
294 | : QBoxSet(label, parent) | |
289 | { |
|
295 | { | |
290 | connect(this, SIGNAL(valuesChanged()), this, SIGNAL(changedValues())); |
|
296 | connect(this, SIGNAL(valuesChanged()), this, SIGNAL(changedValues())); | |
291 | connect(this, SIGNAL(valueChanged(int)), this, SIGNAL(changedValue(int))); |
|
297 | connect(this, SIGNAL(valueChanged(int)), this, SIGNAL(changedValue(int))); | |
292 | connect(this, SIGNAL(brushChanged()), this, SLOT(handleBrushChanged())); |
|
298 | connect(this, SIGNAL(brushChanged()), this, SLOT(handleBrushChanged())); | |
293 | } |
|
299 | } | |
294 |
|
300 | |||
295 | QVariantList DeclarativeBoxSet::values() |
|
301 | QVariantList DeclarativeBoxSet::values() | |
296 | { |
|
302 | { | |
297 | QVariantList values; |
|
303 | QVariantList values; | |
298 | for (int i(0); i < 5; i++) |
|
304 | for (int i(0); i < 5; i++) | |
299 | values.append(QVariant(QBoxSet::at(i))); |
|
305 | values.append(QVariant(QBoxSet::at(i))); | |
300 | return values; |
|
306 | return values; | |
301 | } |
|
307 | } | |
302 |
|
308 | |||
303 | void DeclarativeBoxSet::setValues(QVariantList values) |
|
309 | void DeclarativeBoxSet::setValues(QVariantList values) | |
304 | { |
|
310 | { | |
305 | for (int i(0); i < values.count(); i++) { |
|
311 | for (int i(0); i < values.count(); i++) { | |
306 | if (values.at(i).canConvert(QVariant::Double)) |
|
312 | if (values.at(i).canConvert(QVariant::Double)) | |
307 | QBoxSet::append(values[i].toDouble()); |
|
313 | QBoxSet::append(values[i].toDouble()); | |
308 | } |
|
314 | } | |
309 | } |
|
315 | } | |
310 |
|
316 | |||
311 | QString DeclarativeBoxSet::brushFilename() const |
|
317 | QString DeclarativeBoxSet::brushFilename() const | |
312 | { |
|
318 | { | |
313 | return m_brushFilename; |
|
319 | return m_brushFilename; | |
314 | } |
|
320 | } | |
315 |
|
321 | |||
316 | void DeclarativeBoxSet::setBrushFilename(const QString &brushFilename) |
|
322 | void DeclarativeBoxSet::setBrushFilename(const QString &brushFilename) | |
317 | { |
|
323 | { | |
318 | QImage brushImage(brushFilename); |
|
324 | QImage brushImage(brushFilename); | |
319 | if (QBoxSet::brush().textureImage() != brushImage) { |
|
325 | if (QBoxSet::brush().textureImage() != brushImage) { | |
320 | QBrush brush = QBoxSet::brush(); |
|
326 | QBrush brush = QBoxSet::brush(); | |
321 | brush.setTextureImage(brushImage); |
|
327 | brush.setTextureImage(brushImage); | |
322 | QBoxSet::setBrush(brush); |
|
328 | QBoxSet::setBrush(brush); | |
323 | m_brushFilename = brushFilename; |
|
329 | m_brushFilename = brushFilename; | |
324 | m_brushImage = brushImage; |
|
330 | m_brushImage = brushImage; | |
325 | emit brushFilenameChanged(brushFilename); |
|
331 | emit brushFilenameChanged(brushFilename); | |
326 | } |
|
332 | } | |
327 | } |
|
333 | } | |
328 |
|
334 | |||
329 | void DeclarativeBoxSet::handleBrushChanged() |
|
335 | void DeclarativeBoxSet::handleBrushChanged() | |
330 | { |
|
336 | { | |
331 | // If the texture image of the brush has changed along the brush |
|
337 | // If the texture image of the brush has changed along the brush | |
332 | // the brush file name needs to be cleared. |
|
338 | // the brush file name needs to be cleared. | |
333 | if (!m_brushFilename.isEmpty() && QBoxSet::brush().textureImage() != m_brushImage) { |
|
339 | if (!m_brushFilename.isEmpty() && QBoxSet::brush().textureImage() != m_brushImage) { | |
334 | m_brushFilename.clear(); |
|
340 | m_brushFilename.clear(); | |
335 | emit brushFilenameChanged(QString("")); |
|
341 | emit brushFilenameChanged(QString("")); | |
336 | } |
|
342 | } | |
337 | } |
|
343 | } | |
338 |
|
344 | |||
339 | // ===================================================== |
|
345 | // ===================================================== | |
340 |
|
346 | |||
341 | DeclarativeBoxPlotSeries::DeclarativeBoxPlotSeries(QQuickItem *parent) : |
|
347 | DeclarativeBoxPlotSeries::DeclarativeBoxPlotSeries(QQuickItem *parent) : | |
342 | QBoxPlotSeries(parent), |
|
348 | QBoxPlotSeries(parent), | |
343 | m_axes(new DeclarativeAxes(this)) |
|
349 | m_axes(new DeclarativeAxes(this)) | |
344 | { |
|
350 | { | |
345 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); |
|
351 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); | |
346 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); |
|
352 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); | |
347 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
|
353 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); | |
348 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
|
354 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); | |
349 | connect(this, SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(onHovered(bool, QBoxSet*))); |
|
355 | connect(this, SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(onHovered(bool, QBoxSet*))); | |
350 | connect(this, SIGNAL(clicked(QBoxSet*)), this, SLOT(onClicked(QBoxSet*))); |
|
356 | connect(this, SIGNAL(clicked(QBoxSet*)), this, SLOT(onClicked(QBoxSet*))); | |
351 | connect(this, SIGNAL(brushChanged()), this, SLOT(handleBrushChanged())); |
|
357 | connect(this, SIGNAL(brushChanged()), this, SLOT(handleBrushChanged())); | |
352 | connect(this, SIGNAL(pressed(QBoxSet*)), this, SLOT(onPressed(QBoxSet*))); |
|
358 | connect(this, SIGNAL(pressed(QBoxSet*)), this, SLOT(onPressed(QBoxSet*))); | |
353 | connect(this, SIGNAL(released(QBoxSet*)), this, SLOT(onReleased(QBoxSet*))); |
|
359 | connect(this, SIGNAL(released(QBoxSet*)), this, SLOT(onReleased(QBoxSet*))); | |
354 | connect(this, SIGNAL(doubleClicked(QBoxSet*)), this, SLOT(onDoubleClicked(QBoxSet*))); |
|
360 | connect(this, SIGNAL(doubleClicked(QBoxSet*)), this, SLOT(onDoubleClicked(QBoxSet*))); | |
355 | } |
|
361 | } | |
356 |
|
362 | |||
357 | void DeclarativeBoxPlotSeries::classBegin() |
|
363 | void DeclarativeBoxPlotSeries::classBegin() | |
358 | { |
|
364 | { | |
359 | } |
|
365 | } | |
360 |
|
366 | |||
361 | void DeclarativeBoxPlotSeries::componentComplete() |
|
367 | void DeclarativeBoxPlotSeries::componentComplete() | |
362 | { |
|
368 | { | |
363 | foreach (QObject *child, children()) { |
|
369 | foreach (QObject *child, children()) { | |
364 | if (qobject_cast<DeclarativeBoxSet *>(child)) { |
|
370 | if (qobject_cast<DeclarativeBoxSet *>(child)) { | |
365 | QBoxPlotSeries::append(qobject_cast<DeclarativeBoxSet *>(child)); |
|
371 | QBoxPlotSeries::append(qobject_cast<DeclarativeBoxSet *>(child)); | |
366 | } else if (qobject_cast<QVBoxPlotModelMapper *>(child)) { |
|
372 | } else if (qobject_cast<QVBoxPlotModelMapper *>(child)) { | |
367 | QVBoxPlotModelMapper *mapper = qobject_cast<QVBoxPlotModelMapper *>(child); |
|
373 | QVBoxPlotModelMapper *mapper = qobject_cast<QVBoxPlotModelMapper *>(child); | |
368 | mapper->setSeries(this); |
|
374 | mapper->setSeries(this); | |
369 | } |
|
375 | } | |
370 | } |
|
376 | } | |
371 | } |
|
377 | } | |
372 |
|
378 | |||
373 | QQmlListProperty<QObject> DeclarativeBoxPlotSeries::seriesChildren() |
|
379 | QQmlListProperty<QObject> DeclarativeBoxPlotSeries::seriesChildren() | |
374 | { |
|
380 | { | |
375 | return QQmlListProperty<QObject>(this, 0, &DeclarativeBoxPlotSeries::appendSeriesChildren ,0,0,0); |
|
381 | return QQmlListProperty<QObject>(this, 0, &DeclarativeBoxPlotSeries::appendSeriesChildren ,0,0,0); | |
376 | } |
|
382 | } | |
377 |
|
383 | |||
378 | void DeclarativeBoxPlotSeries::appendSeriesChildren(QQmlListProperty<QObject> *list, QObject *element) |
|
384 | void DeclarativeBoxPlotSeries::appendSeriesChildren(QQmlListProperty<QObject> *list, QObject *element) | |
379 | { |
|
385 | { | |
380 | // Empty implementation; the children are parsed in componentComplete instead |
|
386 | // Empty implementation; the children are parsed in componentComplete instead | |
381 | Q_UNUSED(list); |
|
387 | Q_UNUSED(list); | |
382 | Q_UNUSED(element); |
|
388 | Q_UNUSED(element); | |
383 | } |
|
389 | } | |
384 |
|
390 | |||
385 | DeclarativeBoxSet *DeclarativeBoxPlotSeries::at(int index) |
|
391 | DeclarativeBoxSet *DeclarativeBoxPlotSeries::at(int index) | |
386 | { |
|
392 | { | |
387 | QList<QBoxSet *> setList = boxSets(); |
|
393 | QList<QBoxSet *> setList = boxSets(); | |
388 | if (index >= 0 && index < setList.count()) |
|
394 | if (index >= 0 && index < setList.count()) | |
389 | return qobject_cast<DeclarativeBoxSet *>(setList[index]); |
|
395 | return qobject_cast<DeclarativeBoxSet *>(setList[index]); | |
390 |
|
396 | |||
391 | return 0; |
|
397 | return 0; | |
392 | } |
|
398 | } | |
393 |
|
399 | |||
394 | DeclarativeBoxSet *DeclarativeBoxPlotSeries::insert(int index, const QString label, QVariantList values) |
|
400 | DeclarativeBoxSet *DeclarativeBoxPlotSeries::insert(int index, const QString label, QVariantList values) | |
395 | { |
|
401 | { | |
396 | DeclarativeBoxSet *barset = new DeclarativeBoxSet(label, this); |
|
402 | DeclarativeBoxSet *barset = new DeclarativeBoxSet(label, this); | |
397 | barset->setValues(values); |
|
403 | barset->setValues(values); | |
398 | if (QBoxPlotSeries::insert(index, barset)) |
|
404 | if (QBoxPlotSeries::insert(index, barset)) | |
399 | return barset; |
|
405 | return barset; | |
400 | delete barset; |
|
406 | delete barset; | |
401 | return 0; |
|
407 | return 0; | |
402 | } |
|
408 | } | |
403 |
|
409 | |||
404 | void DeclarativeBoxPlotSeries::onHovered(bool status, QBoxSet *boxset) |
|
410 | void DeclarativeBoxPlotSeries::onHovered(bool status, QBoxSet *boxset) | |
405 | { |
|
411 | { | |
406 | emit hovered(status, qobject_cast<DeclarativeBoxSet *>(boxset)); |
|
412 | emit hovered(status, qobject_cast<DeclarativeBoxSet *>(boxset)); | |
407 | } |
|
413 | } | |
408 |
|
414 | |||
409 | void DeclarativeBoxPlotSeries::onClicked(QBoxSet *boxset) |
|
415 | void DeclarativeBoxPlotSeries::onClicked(QBoxSet *boxset) | |
410 | { |
|
416 | { | |
411 | emit clicked(qobject_cast<DeclarativeBoxSet *>(boxset)); |
|
417 | emit clicked(qobject_cast<DeclarativeBoxSet *>(boxset)); | |
412 | } |
|
418 | } | |
413 |
|
419 | |||
414 | void DeclarativeBoxPlotSeries::onPressed(QBoxSet *boxset) |
|
420 | void DeclarativeBoxPlotSeries::onPressed(QBoxSet *boxset) | |
415 | { |
|
421 | { | |
416 | emit pressed(qobject_cast<DeclarativeBoxSet *>(boxset)); |
|
422 | emit pressed(qobject_cast<DeclarativeBoxSet *>(boxset)); | |
417 | } |
|
423 | } | |
418 |
|
424 | |||
419 | void DeclarativeBoxPlotSeries::onReleased(QBoxSet *boxset) |
|
425 | void DeclarativeBoxPlotSeries::onReleased(QBoxSet *boxset) | |
420 | { |
|
426 | { | |
421 | emit released(qobject_cast<DeclarativeBoxSet *>(boxset)); |
|
427 | emit released(qobject_cast<DeclarativeBoxSet *>(boxset)); | |
422 | } |
|
428 | } | |
423 |
|
429 | |||
424 | void DeclarativeBoxPlotSeries::onDoubleClicked(QBoxSet *boxset) |
|
430 | void DeclarativeBoxPlotSeries::onDoubleClicked(QBoxSet *boxset) | |
425 | { |
|
431 | { | |
426 | emit doubleClicked(qobject_cast<DeclarativeBoxSet *>(boxset)); |
|
432 | emit doubleClicked(qobject_cast<DeclarativeBoxSet *>(boxset)); | |
427 | } |
|
433 | } | |
428 |
|
434 | |||
429 | QString DeclarativeBoxPlotSeries::brushFilename() const |
|
435 | QString DeclarativeBoxPlotSeries::brushFilename() const | |
430 | { |
|
436 | { | |
431 | return m_brushFilename; |
|
437 | return m_brushFilename; | |
432 | } |
|
438 | } | |
433 |
|
439 | |||
434 | void DeclarativeBoxPlotSeries::setBrushFilename(const QString &brushFilename) |
|
440 | void DeclarativeBoxPlotSeries::setBrushFilename(const QString &brushFilename) | |
435 | { |
|
441 | { | |
436 | QImage brushImage(brushFilename); |
|
442 | QImage brushImage(brushFilename); | |
437 | if (QBoxPlotSeries::brush().textureImage() != brushImage) { |
|
443 | if (QBoxPlotSeries::brush().textureImage() != brushImage) { | |
438 | QBrush brush = QBoxPlotSeries::brush(); |
|
444 | QBrush brush = QBoxPlotSeries::brush(); | |
439 | brush.setTextureImage(brushImage); |
|
445 | brush.setTextureImage(brushImage); | |
440 | QBoxPlotSeries::setBrush(brush); |
|
446 | QBoxPlotSeries::setBrush(brush); | |
441 | m_brushFilename = brushFilename; |
|
447 | m_brushFilename = brushFilename; | |
442 | m_brushImage = brushImage; |
|
448 | m_brushImage = brushImage; | |
443 | emit brushFilenameChanged(brushFilename); |
|
449 | emit brushFilenameChanged(brushFilename); | |
444 | } |
|
450 | } | |
445 | } |
|
451 | } | |
446 |
|
452 | |||
447 | void DeclarativeBoxPlotSeries::handleBrushChanged() |
|
453 | void DeclarativeBoxPlotSeries::handleBrushChanged() | |
448 | { |
|
454 | { | |
449 | // If the texture image of the brush has changed along the brush |
|
455 | // If the texture image of the brush has changed along the brush | |
450 | // the brush file name needs to be cleared. |
|
456 | // the brush file name needs to be cleared. | |
451 | if (!m_brushFilename.isEmpty() && QBoxPlotSeries::brush().textureImage() != m_brushImage) { |
|
457 | if (!m_brushFilename.isEmpty() && QBoxPlotSeries::brush().textureImage() != m_brushImage) { | |
452 | m_brushFilename.clear(); |
|
458 | m_brushFilename.clear(); | |
453 | emit brushFilenameChanged(QString("")); |
|
459 | emit brushFilenameChanged(QString("")); | |
454 | } |
|
460 | } | |
455 | } |
|
461 | } | |
456 |
|
462 | |||
457 | #include "moc_declarativeboxplotseries.cpp" |
|
463 | #include "moc_declarativeboxplotseries.cpp" | |
458 |
|
464 | |||
459 | QT_CHARTS_END_NAMESPACE |
|
465 | QT_CHARTS_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now