@@ -1,735 +1,735 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qabstractbarseries.h" |
|
22 | 22 | #include "qabstractbarseries_p.h" |
|
23 | 23 | #include "qbarset.h" |
|
24 | 24 | #include "qbarset_p.h" |
|
25 | 25 | #include "domain_p.h" |
|
26 | 26 | #include "legendmarker_p.h" |
|
27 | 27 | #include "chartdataset_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartanimator_p.h" |
|
30 | 30 | #include "qvaluesaxis.h" |
|
31 | 31 | #include "qcategoriesaxis.h" |
|
32 | 32 | |
|
33 | 33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | 34 | |
|
35 | 35 | /*! |
|
36 | 36 | \class QAbstractBarSeries |
|
37 | 37 | \brief Series for creating a bar chart |
|
38 | 38 | \mainclass |
|
39 | 39 | |
|
40 | 40 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
41 | 41 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
42 | 42 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
43 | 43 | shows the x-values. |
|
44 | 44 | |
|
45 | 45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
46 | 46 | \image examples_barchart.png |
|
47 | 47 | |
|
48 | 48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
49 | 49 | */ |
|
50 | 50 | /*! |
|
51 | \qmlclass BarSeries QAbstractBarSeries | |
|
51 | \qmlclass AbstractBarSeries QAbstractBarSeries | |
|
52 | 52 | \inherits QAbstractSeries |
|
53 | 53 | |
|
54 | 54 | The following QML shows how to create a simple bar chart: |
|
55 | 55 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
56 | 56 | |
|
57 | 57 | \beginfloatleft |
|
58 | 58 | \image demos_qmlchart6.png |
|
59 | 59 | \endfloat |
|
60 | 60 | \clearfloat |
|
61 | 61 | */ |
|
62 | 62 | |
|
63 | 63 | /*! |
|
64 | 64 | \property QAbstractBarSeries::barWidth |
|
65 | 65 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
66 | 66 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
67 | 67 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
68 | 68 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
69 | 69 | \sa QGroupedBarSeries |
|
70 | 70 | */ |
|
71 | 71 | /*! |
|
72 | \qmlproperty real BarSeries::barWidth | |
|
72 | \qmlproperty real AbstractBarSeries::barWidth | |
|
73 | 73 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
74 | 74 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
75 | 75 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
76 | 76 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
77 | 77 | */ |
|
78 | 78 | |
|
79 | 79 | /*! |
|
80 | 80 | \property QAbstractBarSeries::count |
|
81 | 81 | Holds the number of sets in series. |
|
82 | 82 | */ |
|
83 | 83 | /*! |
|
84 | \qmlproperty int BarSeries::count | |
|
84 | \qmlproperty int AbstractBarSeries::count | |
|
85 | 85 | Holds the number of sets in series. |
|
86 | 86 | */ |
|
87 | 87 | |
|
88 | 88 | /*! |
|
89 | 89 | \property QAbstractBarSeries::labelsVisible |
|
90 | 90 | Defines the visibility of the labels in series |
|
91 | 91 | */ |
|
92 | 92 | /*! |
|
93 | \qmlproperty bool BarSeries::labelsVisible | |
|
93 | \qmlproperty bool AbstractBarSeries::labelsVisible | |
|
94 | 94 | Defines the visibility of the labels in series |
|
95 | 95 | */ |
|
96 | 96 | |
|
97 | 97 | /*! |
|
98 | 98 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
99 | 99 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
100 | 100 | Clicked bar inside set is indexed by \a index |
|
101 | 101 | */ |
|
102 | 102 | /*! |
|
103 | \qmlsignal BarSeries::onClicked(int index, BarSet barset) | |
|
103 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) | |
|
104 | 104 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
105 | 105 | Clicked bar inside set is indexed by \a index |
|
106 | 106 | */ |
|
107 | 107 | |
|
108 | 108 | /*! |
|
109 | 109 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
110 | 110 | |
|
111 | 111 | The signal is emitted if mouse is hovered on top of series. |
|
112 | 112 | Parameter \a barset is the pointer of barset, where hover happened. |
|
113 | 113 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
114 | 114 | */ |
|
115 | 115 | /*! |
|
116 | \qmlsignal BarSeries::onHovered(bool status, BarSet barset) | |
|
116 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) | |
|
117 | 117 | |
|
118 | 118 | The signal is emitted if mouse is hovered on top of series. |
|
119 | 119 | Parameter \a barset is the pointer of barset, where hover happened. |
|
120 | 120 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
121 | 121 | */ |
|
122 | 122 | |
|
123 | 123 | /*! |
|
124 | 124 | \fn void QAbstractBarSeries::countChanged() |
|
125 | 125 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
126 | 126 | */ |
|
127 | 127 | /*! |
|
128 | \qmlsignal BarSeries::onCountChanged() | |
|
128 | \qmlsignal AbstractBarSeries::onCountChanged() | |
|
129 | 129 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
134 | 134 | This signal is emitted when labels visibility have changed. |
|
135 | 135 | \sa isLabelsVisible(), setLabelsVisible() |
|
136 | 136 | */ |
|
137 | 137 | |
|
138 | 138 | /*! |
|
139 | 139 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
140 | 140 | This signal is emitted when \a sets have been added to the series. |
|
141 | 141 | \sa append(), insert() |
|
142 | 142 | */ |
|
143 | 143 | /*! |
|
144 | \qmlsignal BarSeries::onAdded(BarSet barset) | |
|
144 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) | |
|
145 | 145 | Emitted when \a barset has been added to the series. |
|
146 | 146 | */ |
|
147 | 147 | |
|
148 | 148 | /*! |
|
149 | 149 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
150 | 150 | This signal is emitted when \a sets have been removed from the series. |
|
151 | 151 | \sa remove() |
|
152 | 152 | */ |
|
153 | 153 | /*! |
|
154 | \qmlsignal BarSeries::onRemoved(BarSet barset) | |
|
154 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) | |
|
155 | 155 | Emitted when \a barset has been removed from the series. |
|
156 | 156 | */ |
|
157 | 157 | |
|
158 | 158 | /*! |
|
159 | \qmlmethod BarSet BarSeries::at(int index) | |
|
159 | \qmlmethod BarSet AbstractBarSeries::at(int index) | |
|
160 | 160 | Returns bar set at \a index. Returns null if the index is not valid. |
|
161 | 161 | */ |
|
162 | 162 | |
|
163 | 163 | /*! |
|
164 | \qmlmethod BarSet BarSeries::append(string label, VariantList values) | |
|
164 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) | |
|
165 | 165 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
166 | 166 | For example: |
|
167 | 167 | \code |
|
168 | 168 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
169 | 169 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); |
|
170 | 170 | \endcode |
|
171 | 171 | */ |
|
172 | 172 | |
|
173 | 173 | /*! |
|
174 | \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values) | |
|
174 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) | |
|
175 | 175 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
176 | 176 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
177 | 177 | appended. |
|
178 | \sa BarSeries::append() | |
|
178 | \sa AbstractBarSeries::append() | |
|
179 | 179 | */ |
|
180 | 180 | |
|
181 | 181 | /*! |
|
182 | \qmlmethod bool BarSeries::remove(BarSet barset) | |
|
182 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) | |
|
183 | 183 | Removes the barset from the series. Returns true if successfull, false otherwise. |
|
184 | 184 | */ |
|
185 | 185 | |
|
186 | 186 | /*! |
|
187 | \qmlmethod BarSeries::clear() | |
|
187 | \qmlmethod AbstractBarSeries::clear() | |
|
188 | 188 | Removes all barsets from the series. |
|
189 | 189 | */ |
|
190 | 190 | |
|
191 | 191 | /*! |
|
192 | 192 | Constructs empty QAbstractBarSeries. |
|
193 | 193 | QAbstractBarSeries is QObject which is a child of a \a parent. |
|
194 | 194 | */ |
|
195 | 195 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : |
|
196 | 196 | QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent) |
|
197 | 197 | { |
|
198 | 198 | } |
|
199 | 199 | |
|
200 | 200 | /*! |
|
201 | Destructs barseries and owned barsets. | |
|
201 | Destructs abstractbarseries and owned barsets. | |
|
202 | 202 | */ |
|
203 | 203 | QAbstractBarSeries::~QAbstractBarSeries() |
|
204 | 204 | { |
|
205 | 205 | Q_D(QAbstractBarSeries); |
|
206 | 206 | if(d->m_dataset){ |
|
207 | 207 | d->m_dataset->removeSeries(this); |
|
208 | 208 | } |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | /*! |
|
212 | 212 | \internal |
|
213 | 213 | */ |
|
214 | 214 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : |
|
215 | 215 | QAbstractSeries(d,parent) |
|
216 | 216 | { |
|
217 | 217 | } |
|
218 | 218 | |
|
219 | 219 | /*! |
|
220 | 220 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
221 | 221 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
222 | 222 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
223 | 223 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
224 | 224 | */ |
|
225 | 225 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
226 | 226 | { |
|
227 | 227 | Q_D(QAbstractBarSeries); |
|
228 | 228 | d->setBarWidth(width); |
|
229 | 229 | } |
|
230 | 230 | |
|
231 | 231 | /*! |
|
232 | 232 | Returns the width of the bars of the series. |
|
233 | 233 | \sa setBarWidth() |
|
234 | 234 | */ |
|
235 | 235 | qreal QAbstractBarSeries::barWidth() const |
|
236 | 236 | { |
|
237 | 237 | Q_D(const QAbstractBarSeries); |
|
238 | 238 | return d->barWidth(); |
|
239 | 239 | } |
|
240 | 240 | |
|
241 | 241 | /*! |
|
242 | 242 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
243 | 243 | Returns true, if appending succeeded. |
|
244 | 244 | */ |
|
245 | 245 | bool QAbstractBarSeries::append(QBarSet *set) |
|
246 | 246 | { |
|
247 | 247 | Q_D(QAbstractBarSeries); |
|
248 | 248 | bool success = d->append(set); |
|
249 | 249 | if (success) { |
|
250 | 250 | QList<QBarSet*> sets; |
|
251 | 251 | sets.append(set); |
|
252 | 252 | emit barsetsAdded(sets); |
|
253 | 253 | emit countChanged(); |
|
254 | 254 | } |
|
255 | 255 | return success; |
|
256 | 256 | } |
|
257 | 257 | |
|
258 | 258 | /*! |
|
259 | 259 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
260 | 260 | Returns true, if set was removed. |
|
261 | 261 | */ |
|
262 | 262 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
263 | 263 | { |
|
264 | 264 | Q_D(QAbstractBarSeries); |
|
265 | 265 | bool success = d->remove(set); |
|
266 | 266 | if (success) { |
|
267 | 267 | QList<QBarSet*> sets; |
|
268 | 268 | sets.append(set); |
|
269 | 269 | emit barsetsRemoved(sets); |
|
270 | 270 | emit countChanged(); |
|
271 | 271 | } |
|
272 | 272 | return success; |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | /*! |
|
276 | 276 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
277 | 277 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
278 | 278 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
279 | 279 | and function returns false. |
|
280 | 280 | */ |
|
281 | 281 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) |
|
282 | 282 | { |
|
283 | 283 | Q_D(QAbstractBarSeries); |
|
284 | 284 | bool success = d->append(sets); |
|
285 | 285 | if (success) { |
|
286 | 286 | emit barsetsAdded(sets); |
|
287 | 287 | emit countChanged(); |
|
288 | 288 | } |
|
289 | 289 | return success; |
|
290 | 290 | } |
|
291 | 291 | |
|
292 | 292 | /*! |
|
293 | 293 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
294 | 294 | Returns true, if inserting succeeded. |
|
295 | 295 | |
|
296 | 296 | */ |
|
297 | 297 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
298 | 298 | { |
|
299 | 299 | Q_D(QAbstractBarSeries); |
|
300 | 300 | bool success = d->insert(index, set); |
|
301 | 301 | if (success) { |
|
302 | 302 | QList<QBarSet*> sets; |
|
303 | 303 | sets.append(set); |
|
304 | 304 | emit barsetsAdded(sets); |
|
305 | 305 | emit countChanged(); |
|
306 | 306 | } |
|
307 | 307 | return success; |
|
308 | 308 | } |
|
309 | 309 | |
|
310 | 310 | /*! |
|
311 | 311 | Removes all of the bar sets from the series |
|
312 | 312 | */ |
|
313 | 313 | void QAbstractBarSeries::clear() |
|
314 | 314 | { |
|
315 | 315 | Q_D(QAbstractBarSeries); |
|
316 | 316 | QList<QBarSet *> sets = barSets(); |
|
317 | 317 | bool success = d->remove(sets); |
|
318 | 318 | if (success) { |
|
319 | 319 | emit barsetsRemoved(sets); |
|
320 | 320 | emit countChanged(); |
|
321 | 321 | } |
|
322 | 322 | } |
|
323 | 323 | |
|
324 | 324 | /*! |
|
325 | 325 | Returns number of sets in series. |
|
326 | 326 | */ |
|
327 | 327 | int QAbstractBarSeries::count() const |
|
328 | 328 | { |
|
329 | 329 | Q_D(const QAbstractBarSeries); |
|
330 | 330 | return d->m_barSets.count(); |
|
331 | 331 | } |
|
332 | 332 | |
|
333 | 333 | /*! |
|
334 | 334 | Returns a list of sets in series. Keeps ownership of sets. |
|
335 | 335 | */ |
|
336 | 336 | QList<QBarSet*> QAbstractBarSeries::barSets() const |
|
337 | 337 | { |
|
338 | 338 | Q_D(const QAbstractBarSeries); |
|
339 | 339 | return d->m_barSets; |
|
340 | 340 | } |
|
341 | 341 | |
|
342 | 342 | /*! |
|
343 | 343 | Sets the visibility of labels in series to \a visible |
|
344 | 344 | */ |
|
345 | 345 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
346 | 346 | { |
|
347 | 347 | Q_D(QAbstractBarSeries); |
|
348 | 348 | if (d->m_labelsVisible != visible) { |
|
349 | 349 | d->setLabelsVisible(visible); |
|
350 | 350 | emit labelsVisibleChanged(); |
|
351 | 351 | } |
|
352 | 352 | } |
|
353 | 353 | |
|
354 | 354 | /*! |
|
355 | 355 | Returns the visibility of labels |
|
356 | 356 | */ |
|
357 | 357 | bool QAbstractBarSeries::isLabelsVisible() const |
|
358 | 358 | { |
|
359 | 359 | Q_D(const QAbstractBarSeries); |
|
360 | 360 | return d->m_labelsVisible; |
|
361 | 361 | } |
|
362 | 362 | |
|
363 | 363 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
364 | 364 | |
|
365 | 365 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
366 | 366 | QAbstractSeriesPrivate(q), |
|
367 | 367 | m_barWidth(0.5), // Default value is 50% of category width |
|
368 | 368 | m_labelsVisible(false), |
|
369 | 369 | m_visible(true) |
|
370 | 370 | { |
|
371 | 371 | } |
|
372 | 372 | |
|
373 | 373 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
374 | 374 | { |
|
375 | 375 | // No categories defined. return count of longest set. |
|
376 | 376 | int count = 0; |
|
377 | 377 | for (int i=0; i<m_barSets.count(); i++) { |
|
378 | 378 | if (m_barSets.at(i)->count() > count) { |
|
379 | 379 | count = m_barSets.at(i)->count(); |
|
380 | 380 | } |
|
381 | 381 | } |
|
382 | 382 | |
|
383 | 383 | return count; |
|
384 | 384 | } |
|
385 | 385 | |
|
386 | 386 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
387 | 387 | { |
|
388 | 388 | if (width < 0.0) { |
|
389 | 389 | width = 0.0; |
|
390 | 390 | } |
|
391 | 391 | m_barWidth = width; |
|
392 | 392 | emit updatedBars(); |
|
393 | 393 | } |
|
394 | 394 | |
|
395 | 395 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
396 | 396 | { |
|
397 | 397 | return m_barWidth; |
|
398 | 398 | } |
|
399 | 399 | |
|
400 | 400 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) |
|
401 | 401 | { |
|
402 | 402 | return m_barSets.at(index); |
|
403 | 403 | } |
|
404 | 404 | |
|
405 | 405 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
406 | 406 | { |
|
407 | 407 | m_visible = visible; |
|
408 | 408 | emit updatedBars(); |
|
409 | 409 | } |
|
410 | 410 | |
|
411 | 411 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
412 | 412 | { |
|
413 | 413 | m_labelsVisible = visible; |
|
414 | 414 | emit labelsVisibleChanged(visible); |
|
415 | 415 | } |
|
416 | 416 | |
|
417 | 417 | qreal QAbstractBarSeriesPrivate::min() |
|
418 | 418 | { |
|
419 | 419 | if (m_barSets.count() <= 0) { |
|
420 | 420 | return 0; |
|
421 | 421 | } |
|
422 | 422 | qreal min = INT_MAX; |
|
423 | 423 | |
|
424 | 424 | for (int i = 0; i < m_barSets.count(); i++) { |
|
425 | 425 | int categoryCount = m_barSets.at(i)->count(); |
|
426 | 426 | for (int j = 0; j < categoryCount; j++) { |
|
427 | 427 | qreal temp = m_barSets.at(i)->at(j); |
|
428 | 428 | if (temp < min) |
|
429 | 429 | min = temp; |
|
430 | 430 | } |
|
431 | 431 | } |
|
432 | 432 | return min; |
|
433 | 433 | } |
|
434 | 434 | |
|
435 | 435 | qreal QAbstractBarSeriesPrivate::max() |
|
436 | 436 | { |
|
437 | 437 | if (m_barSets.count() <= 0) { |
|
438 | 438 | return 0; |
|
439 | 439 | } |
|
440 | 440 | qreal max = INT_MIN; |
|
441 | 441 | |
|
442 | 442 | for (int i = 0; i < m_barSets.count(); i++) { |
|
443 | 443 | int categoryCount = m_barSets.at(i)->count(); |
|
444 | 444 | for (int j = 0; j < categoryCount; j++) { |
|
445 | 445 | qreal temp = m_barSets.at(i)->at(j); |
|
446 | 446 | if (temp > max) |
|
447 | 447 | max = temp; |
|
448 | 448 | } |
|
449 | 449 | } |
|
450 | 450 | |
|
451 | 451 | return max; |
|
452 | 452 | } |
|
453 | 453 | |
|
454 | 454 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
455 | 455 | { |
|
456 | 456 | if ((set < 0) || (set >= m_barSets.count())) { |
|
457 | 457 | // No set, no value. |
|
458 | 458 | return 0; |
|
459 | 459 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
460 | 460 | // No category, no value. |
|
461 | 461 | return 0; |
|
462 | 462 | } |
|
463 | 463 | |
|
464 | 464 | return m_barSets.at(set)->at(category); |
|
465 | 465 | } |
|
466 | 466 | |
|
467 | 467 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
468 | 468 | { |
|
469 | 469 | if ((set < 0) || (set >= m_barSets.count())) { |
|
470 | 470 | // No set, no value. |
|
471 | 471 | return 0; |
|
472 | 472 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
473 | 473 | // No category, no value. |
|
474 | 474 | return 0; |
|
475 | 475 | } |
|
476 | 476 | |
|
477 | 477 | qreal value = m_barSets.at(set)->at(category); |
|
478 | 478 | qreal sum = categorySum(category); |
|
479 | 479 | if ( qFuzzyIsNull(sum) ) { |
|
480 | 480 | return 0; |
|
481 | 481 | } |
|
482 | 482 | |
|
483 | 483 | return value / sum; |
|
484 | 484 | } |
|
485 | 485 | |
|
486 | 486 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
487 | 487 | { |
|
488 | 488 | qreal sum(0); |
|
489 | 489 | int count = m_barSets.count(); // Count sets |
|
490 | 490 | for (int set = 0; set < count; set++) { |
|
491 | 491 | if (category < m_barSets.at(set)->count()) |
|
492 | 492 | sum += m_barSets.at(set)->at(category); |
|
493 | 493 | } |
|
494 | 494 | return sum; |
|
495 | 495 | } |
|
496 | 496 | |
|
497 | 497 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
498 | 498 | { |
|
499 | 499 | qreal sum(0); |
|
500 | 500 | int count = m_barSets.count(); // Count sets |
|
501 | 501 | for (int set = 0; set < count; set++) { |
|
502 | 502 | if (category < m_barSets.at(set)->count()) |
|
503 | 503 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
504 | 504 | } |
|
505 | 505 | return sum; |
|
506 | 506 | } |
|
507 | 507 | |
|
508 | 508 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
509 | 509 | { |
|
510 | 510 | qreal max = INT_MIN; |
|
511 | 511 | int count = categoryCount(); |
|
512 | 512 | for (int i = 0; i < count; i++) { |
|
513 | 513 | qreal sum = categorySum(i); |
|
514 | 514 | if (sum > max) |
|
515 | 515 | max = sum; |
|
516 | 516 | } |
|
517 | 517 | return max; |
|
518 | 518 | } |
|
519 | 519 | |
|
520 | 520 | qreal QAbstractBarSeriesPrivate::minX() |
|
521 | 521 | { |
|
522 | 522 | if (m_barSets.count() <= 0) { |
|
523 | 523 | return 0; |
|
524 | 524 | } |
|
525 | 525 | qreal min = INT_MAX; |
|
526 | 526 | |
|
527 | 527 | for (int i = 0; i < m_barSets.count(); i++) { |
|
528 | 528 | int categoryCount = m_barSets.at(i)->count(); |
|
529 | 529 | for (int j = 0; j < categoryCount; j++) { |
|
530 | 530 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
531 | 531 | if (temp < min) |
|
532 | 532 | min = temp; |
|
533 | 533 | } |
|
534 | 534 | } |
|
535 | 535 | return min; |
|
536 | 536 | } |
|
537 | 537 | |
|
538 | 538 | qreal QAbstractBarSeriesPrivate::maxX() |
|
539 | 539 | { |
|
540 | 540 | if (m_barSets.count() <= 0) { |
|
541 | 541 | return 0; |
|
542 | 542 | } |
|
543 | 543 | qreal max = INT_MIN; |
|
544 | 544 | |
|
545 | 545 | for (int i = 0; i < m_barSets.count(); i++) { |
|
546 | 546 | int categoryCount = m_barSets.at(i)->count(); |
|
547 | 547 | for (int j = 0; j < categoryCount; j++) { |
|
548 | 548 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
549 | 549 | if (temp > max) |
|
550 | 550 | max = temp; |
|
551 | 551 | } |
|
552 | 552 | } |
|
553 | 553 | |
|
554 | 554 | return max; |
|
555 | 555 | } |
|
556 | 556 | |
|
557 | 557 | |
|
558 | 558 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) |
|
559 | 559 | { |
|
560 | 560 | qreal minX(domain.minX()); |
|
561 | 561 | qreal minY(domain.minY()); |
|
562 | 562 | qreal maxX(domain.maxX()); |
|
563 | 563 | qreal maxY(domain.maxY()); |
|
564 | 564 | int tickXCount(domain.tickXCount()); |
|
565 | 565 | int tickYCount(domain.tickYCount()); |
|
566 | 566 | |
|
567 | 567 | qreal seriesMinX = this->minX(); |
|
568 | 568 | qreal seriesMaxX = this->maxX(); |
|
569 | 569 | qreal y = max(); |
|
570 | 570 | minX = qMin(minX, seriesMinX - 0.5); |
|
571 | 571 | minY = qMin(minY, y); |
|
572 | 572 | maxX = qMax(maxX, seriesMaxX + 0.5); |
|
573 | 573 | maxY = qMax(maxY, y); |
|
574 | 574 | tickXCount = categoryCount()+1; |
|
575 | 575 | |
|
576 | 576 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
577 | 577 | } |
|
578 | 578 | |
|
579 | 579 | Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
580 | 580 | { |
|
581 | 581 | Q_Q(QAbstractBarSeries); |
|
582 | 582 | |
|
583 | 583 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
584 | 584 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
585 | 585 | presenter->animator()->addAnimation(bar); |
|
586 | 586 | } |
|
587 | 587 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
588 | 588 | return bar; |
|
589 | 589 | |
|
590 | 590 | } |
|
591 | 591 | |
|
592 | 592 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
593 | 593 | { |
|
594 | 594 | Q_Q(QAbstractBarSeries); |
|
595 | 595 | QList<LegendMarker*> markers; |
|
596 | 596 | foreach(QBarSet* set, q->barSets()) { |
|
597 | 597 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
598 | 598 | markers << marker; |
|
599 | 599 | } |
|
600 | 600 | |
|
601 | 601 | return markers; |
|
602 | 602 | } |
|
603 | 603 | |
|
604 | 604 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
605 | 605 | { |
|
606 | 606 | Q_Q(QAbstractBarSeries); |
|
607 | 607 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
608 | 608 | // Fail if set is already in list or set is null. |
|
609 | 609 | return false; |
|
610 | 610 | } |
|
611 | 611 | m_barSets.append(set); |
|
612 | 612 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
613 | 613 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
614 | 614 | emit restructuredBars(); // this notifies barchartitem |
|
615 | 615 | if (m_dataset) { |
|
616 | 616 | m_dataset->updateSeries(q); // this notifies legend |
|
617 | 617 | } |
|
618 | 618 | return true; |
|
619 | 619 | } |
|
620 | 620 | |
|
621 | 621 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
622 | 622 | { |
|
623 | 623 | Q_Q(QAbstractBarSeries); |
|
624 | 624 | if (!m_barSets.contains(set)) { |
|
625 | 625 | // Fail if set is not in list |
|
626 | 626 | return false; |
|
627 | 627 | } |
|
628 | 628 | m_barSets.removeOne(set); |
|
629 | 629 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
630 | 630 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
631 | 631 | emit restructuredBars(); // this notifies barchartitem |
|
632 | 632 | if (m_dataset) { |
|
633 | 633 | m_dataset->updateSeries(q); // this notifies legend |
|
634 | 634 | } |
|
635 | 635 | return true; |
|
636 | 636 | } |
|
637 | 637 | |
|
638 | 638 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
639 | 639 | { |
|
640 | 640 | Q_Q(QAbstractBarSeries); |
|
641 | 641 | foreach (QBarSet* set, sets) { |
|
642 | 642 | if ((set == 0) || (m_barSets.contains(set))) { |
|
643 | 643 | // Fail if any of the sets is null or is already appended. |
|
644 | 644 | return false; |
|
645 | 645 | } |
|
646 | 646 | if (sets.count(set) != 1) { |
|
647 | 647 | // Also fail if same set is more than once in given list. |
|
648 | 648 | return false; |
|
649 | 649 | } |
|
650 | 650 | } |
|
651 | 651 | |
|
652 | 652 | foreach (QBarSet* set, sets) { |
|
653 | 653 | m_barSets.append(set); |
|
654 | 654 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
655 | 655 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
656 | 656 | } |
|
657 | 657 | emit restructuredBars(); // this notifies barchartitem |
|
658 | 658 | if (m_dataset) { |
|
659 | 659 | m_dataset->updateSeries(q); // this notifies legend |
|
660 | 660 | } |
|
661 | 661 | return true; |
|
662 | 662 | } |
|
663 | 663 | |
|
664 | 664 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
665 | 665 | { |
|
666 | 666 | Q_Q(QAbstractBarSeries); |
|
667 | 667 | if (sets.count() == 0) { |
|
668 | 668 | return false; |
|
669 | 669 | } |
|
670 | 670 | foreach (QBarSet* set, sets) { |
|
671 | 671 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
672 | 672 | // Fail if any of the sets is null or is not in series |
|
673 | 673 | return false; |
|
674 | 674 | } |
|
675 | 675 | if (sets.count(set) != 1) { |
|
676 | 676 | // Also fail if same set is more than once in given list. |
|
677 | 677 | return false; |
|
678 | 678 | } |
|
679 | 679 | } |
|
680 | 680 | |
|
681 | 681 | foreach (QBarSet* set, sets) { |
|
682 | 682 | m_barSets.removeOne(set); |
|
683 | 683 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
684 | 684 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
685 | 685 | } |
|
686 | 686 | |
|
687 | 687 | emit restructuredBars(); // this notifies barchartitem |
|
688 | 688 | if (m_dataset) { |
|
689 | 689 | m_dataset->updateSeries(q); // this notifies legend |
|
690 | 690 | } |
|
691 | 691 | return true; |
|
692 | 692 | } |
|
693 | 693 | |
|
694 | 694 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
695 | 695 | { |
|
696 | 696 | Q_Q(QAbstractBarSeries); |
|
697 | 697 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
698 | 698 | // Fail if set is already in list or set is null. |
|
699 | 699 | return false; |
|
700 | 700 | } |
|
701 | 701 | m_barSets.insert(index, set); |
|
702 | 702 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
703 | 703 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
704 | 704 | emit restructuredBars(); // this notifies barchartitem |
|
705 | 705 | if (m_dataset) { |
|
706 | 706 | m_dataset->updateSeries(q); // this notifies legend |
|
707 | 707 | } |
|
708 | 708 | return true; |
|
709 | 709 | } |
|
710 | 710 | |
|
711 | 711 | void QAbstractBarSeriesPrivate::initializeAxisX(QAbstractAxis* axis) |
|
712 | 712 | { |
|
713 | 713 | Q_UNUSED(axis); |
|
714 | 714 | } |
|
715 | 715 | |
|
716 | 716 | void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis) |
|
717 | 717 | { |
|
718 | 718 | Q_UNUSED(axis) |
|
719 | 719 | } |
|
720 | 720 | |
|
721 | 721 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const |
|
722 | 722 | { |
|
723 | 723 | return QAbstractAxis::AxisTypeCategories; |
|
724 | 724 | } |
|
725 | 725 | |
|
726 | 726 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const |
|
727 | 727 | { |
|
728 | 728 | return QAbstractAxis::AxisTypeValues; |
|
729 | 729 | } |
|
730 | 730 | |
|
731 | 731 | #include "moc_qabstractbarseries.cpp" |
|
732 | 732 | #include "moc_qabstractbarseries_p.cpp" |
|
733 | 733 | |
|
734 | 734 | |
|
735 | 735 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,84 +1,84 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | #ifndef BARSERIES_H | |
|
22 | #define BARSERIES_H | |
|
21 | #ifndef ABSTRACTBARSERIES_H | |
|
22 | #define ABSTRACTBARSERIES_H | |
|
23 | 23 | |
|
24 | 24 | #include <qabstractseries.h> |
|
25 | 25 | #include <QStringList> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | class QBarSet; |
|
30 | 30 | class QAbstractBarSeriesPrivate; |
|
31 | 31 | |
|
32 | 32 | // Container for series |
|
33 | 33 | class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | 36 | Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth) |
|
37 | 37 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
38 | 38 | Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
39 | 39 | |
|
40 | 40 | protected: |
|
41 | 41 | explicit QAbstractBarSeries(QObject *parent = 0); |
|
42 | 42 | |
|
43 | 43 | public: |
|
44 | 44 | virtual ~QAbstractBarSeries(); |
|
45 | 45 | |
|
46 | 46 | virtual QAbstractSeries::SeriesType type() const = 0; |
|
47 | 47 | |
|
48 | 48 | void setBarWidth(qreal width); |
|
49 | 49 | qreal barWidth() const; |
|
50 | 50 | |
|
51 | 51 | bool append(QBarSet *set); |
|
52 | 52 | bool remove(QBarSet *set); |
|
53 | 53 | bool append(QList<QBarSet* > sets); |
|
54 | 54 | bool insert(int index, QBarSet *set); |
|
55 | 55 | int count() const; |
|
56 | 56 | QList<QBarSet*> barSets() const; |
|
57 | 57 | void clear(); |
|
58 | 58 | |
|
59 | 59 | void setLabelsVisible(bool visible = true); |
|
60 | 60 | bool isLabelsVisible() const; |
|
61 | 61 | |
|
62 | 62 | protected: |
|
63 | 63 | explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d,QObject *parent = 0); |
|
64 | 64 | |
|
65 | 65 | Q_SIGNALS: |
|
66 | 66 | void clicked(int index, QBarSet *barset); |
|
67 | 67 | void hovered(bool status, QBarSet *barset); |
|
68 | 68 | void countChanged(); |
|
69 | 69 | void labelsVisibleChanged(); |
|
70 | 70 | |
|
71 | 71 | void barsetsAdded(QList<QBarSet*> sets); |
|
72 | 72 | void barsetsRemoved(QList<QBarSet*> sets); |
|
73 | 73 | |
|
74 | 74 | protected: |
|
75 | 75 | Q_DECLARE_PRIVATE(QAbstractBarSeries) |
|
76 | 76 | friend class BarChartItem; |
|
77 | 77 | friend class PercentBarChartItem; |
|
78 | 78 | friend class StackedBarChartItem; |
|
79 | 79 | friend class GroupedBarChartItem; |
|
80 | 80 | }; |
|
81 | 81 | |
|
82 | 82 | QTCOMMERCIALCHART_END_NAMESPACE |
|
83 | 83 | |
|
84 | #endif // BARSERIES_H | |
|
84 | #endif // ABSTRACTBARSERIES_H |
@@ -1,616 +1,616 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qbarset.h" |
|
22 | 22 | #include "qbarset_p.h" |
|
23 | 23 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
|
26 | 26 | /*! |
|
27 | 27 | \class QBarSet |
|
28 | 28 | \brief Building block for different bar charts |
|
29 | 29 | |
|
30 | 30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
31 | 31 | First value of set is assumed to belong to first category, second to second category and so on. |
|
32 | 32 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
33 | 33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
34 | 34 | |
|
35 | 35 | \mainclass |
|
36 | 36 | |
|
37 | 37 | \sa QAbstractBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries |
|
38 | 38 | */ |
|
39 | 39 | /*! |
|
40 | 40 | \qmlclass BarSet QBarSet |
|
41 | 41 | |
|
42 | 42 | BarSet represents one set of bars. Set of bars contains one data value for each category. |
|
43 | 43 | First value of set is assumed to belong to first category, second to second category and so on. |
|
44 | 44 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
45 | 45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
46 | \sa BarSeries, GroupedBarSeries, StackedBarSeries, PercentBarSeries | |
|
46 | \sa AbstractBarSeries, GroupedBarSeries, StackedBarSeries, PercentBarSeries | |
|
47 | 47 | */ |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | 50 | \property QBarSet::label |
|
51 | 51 | Defines the label of the barSet. |
|
52 | 52 | */ |
|
53 | 53 | /*! |
|
54 | 54 | \qmlproperty string BarSet::label |
|
55 | 55 | Defines the label of the barSet. |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \property QBarSet::pen |
|
60 | 60 | \brief Defines the pen used by the barSet. |
|
61 | 61 | */ |
|
62 | 62 | |
|
63 | 63 | /*! |
|
64 | 64 | \property QBarSet::brush |
|
65 | 65 | \brief Defines the brush used by the barSet. |
|
66 | 66 | */ |
|
67 | 67 | |
|
68 | 68 | /*! |
|
69 | 69 | \property QBarSet::labelBrush |
|
70 | 70 | \brief Defines the brush used by the barSet's label. |
|
71 | 71 | */ |
|
72 | 72 | |
|
73 | 73 | /*! |
|
74 | 74 | \property QBarSet::labelFont |
|
75 | 75 | \brief Defines the font used by the barSet's label. |
|
76 | 76 | */ |
|
77 | 77 | |
|
78 | 78 | /*! |
|
79 | 79 | \qmlproperty Font BarSet::labelFont |
|
80 | 80 | Defines the font used by the barSet's label. |
|
81 | 81 | |
|
82 | 82 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | 85 | /*! |
|
86 | 86 | \property QBarSet::color |
|
87 | 87 | The fill (brush) color of the bar set. |
|
88 | 88 | */ |
|
89 | 89 | /*! |
|
90 | 90 | \qmlproperty color BarSet::color |
|
91 | 91 | The fill (brush) color of the bar set. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \property QBarSet::borderColor |
|
96 | 96 | The line (pen) color of the bar set. |
|
97 | 97 | */ |
|
98 | 98 | /*! |
|
99 | 99 | \qmlproperty color BarSet::borderColor |
|
100 | 100 | The line (pen) color of the bar set. |
|
101 | 101 | */ |
|
102 | 102 | |
|
103 | 103 | /*! |
|
104 | 104 | \property QBarSet::labelColor |
|
105 | 105 | The text (label) color of the bar set. |
|
106 | 106 | */ |
|
107 | 107 | /*! |
|
108 | 108 | \qmlproperty color BarSet::labelColor |
|
109 | 109 | The text (label) color of the bar set. |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \fn void QBarSet::clicked(int index) |
|
114 | 114 | |
|
115 | 115 | The signal is emitted if the user clicks with a mouse on top of barset. |
|
116 | 116 | Clicked bar inside set is indexed by \a index |
|
117 | 117 | */ |
|
118 | 118 | |
|
119 | 119 | /*! |
|
120 | 120 | \fn void QBarSet::hovered(bool status) |
|
121 | 121 | |
|
122 | 122 | The signal is emitted if mouse is hovered on top of barset. |
|
123 | 123 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. |
|
124 | 124 | */ |
|
125 | 125 | |
|
126 | 126 | |
|
127 | 127 | /*! |
|
128 | 128 | \fn void QBarSet::labelChanged() |
|
129 | 129 | This signal is emitted when the label of the barSet has changed. |
|
130 | 130 | \sa label |
|
131 | 131 | */ |
|
132 | 132 | /*! |
|
133 | 133 | \qmlsignal BarSet::onLabelChanged() |
|
134 | 134 | This signal is emitted when the label of the barSet has changed. |
|
135 | 135 | */ |
|
136 | 136 | |
|
137 | 137 | /*! |
|
138 | 138 | \fn void QBarSet::penChanged() |
|
139 | 139 | This signal is emitted when the pen of the barSet has changed. |
|
140 | 140 | \sa pen |
|
141 | 141 | */ |
|
142 | 142 | |
|
143 | 143 | /*! |
|
144 | 144 | \fn void QBarSet::brushChanged() |
|
145 | 145 | This signal is emitted when the brush of the barSet has changed. |
|
146 | 146 | \sa brush |
|
147 | 147 | */ |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | \fn void QBarSet::labelBrushChanged() |
|
151 | 151 | This signal is emitted when the brush of the barSet's label has changed. |
|
152 | 152 | \sa labelBrush |
|
153 | 153 | */ |
|
154 | 154 | |
|
155 | 155 | /*! |
|
156 | 156 | \fn void QBarSet::labelFontChanged() |
|
157 | 157 | This signal is emitted when the font of the barSet's label has changed. |
|
158 | 158 | \sa labelBrush |
|
159 | 159 | */ |
|
160 | 160 | |
|
161 | 161 | /*! |
|
162 | 162 | \fn void QBarSet::colorChanged(QColor) |
|
163 | 163 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
164 | 164 | */ |
|
165 | 165 | /*! |
|
166 | 166 | \qmlsignal BarSet::onColorChanged(color color) |
|
167 | 167 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
168 | 168 | */ |
|
169 | 169 | |
|
170 | 170 | /*! |
|
171 | 171 | \fn void QBarSet::borderColorChanged(QColor) |
|
172 | 172 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
173 | 173 | */ |
|
174 | 174 | /*! |
|
175 | 175 | \qmlsignal BarSet::onBorderColorChanged(color color) |
|
176 | 176 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
177 | 177 | */ |
|
178 | 178 | |
|
179 | 179 | /*! |
|
180 | 180 | \fn void QBarSet::labelColorChanged(QColor) |
|
181 | 181 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
182 | 182 | */ |
|
183 | 183 | /*! |
|
184 | 184 | \qmlsignal BarSet::onLabelColorChanged(color color) |
|
185 | 185 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
186 | 186 | */ |
|
187 | 187 | |
|
188 | 188 | /*! |
|
189 | 189 | \fn void QBarSet::valuesAdded(int index, int count) |
|
190 | 190 | This signal is emitted when new values have been added to the set. |
|
191 | 191 | Parameter \a index indicates the position of the first inserted value. |
|
192 | 192 | Parameter \a count is the number of iserted values. |
|
193 | 193 | \sa append(), insert() |
|
194 | 194 | */ |
|
195 | 195 | /*! |
|
196 | 196 | \qmlsignal BarSet::onValuesAdded(int index, int count) |
|
197 | 197 | This signal is emitted when new values have been added to the set. |
|
198 | 198 | Parameter \a index indicates the position of the first inserted value. |
|
199 | 199 | Parameter \a count is the number of iserted values. |
|
200 | 200 | */ |
|
201 | 201 | |
|
202 | 202 | /*! |
|
203 | 203 | \fn void QBarSet::valuesRemoved(int index, int count) |
|
204 | 204 | This signal is emitted values have been removed from the set. |
|
205 | 205 | Parameter \a index indicates the position of the first removed value. |
|
206 | 206 | Parameter \a count is the number of removed values. |
|
207 | 207 | \sa remove() |
|
208 | 208 | */ |
|
209 | 209 | /*! |
|
210 | 210 | \qmlsignal BarSet::onValuesRemoved(int index, int count) |
|
211 | 211 | This signal is emitted values have been removed from the set. |
|
212 | 212 | Parameter \a index indicates the position of the first removed value. |
|
213 | 213 | Parameter \a count is the number of removed values. |
|
214 | 214 | */ |
|
215 | 215 | |
|
216 | 216 | /*! |
|
217 | 217 | \fn void QBarSet::valueChanged(int index) |
|
218 | 218 | This signal is emitted values the value in the set has been modified. |
|
219 | 219 | Parameter \a index indicates the position of the modified value. |
|
220 | 220 | \sa at() |
|
221 | 221 | */ |
|
222 | 222 | /*! |
|
223 | 223 | \qmlsignal BarSet::onValueChanged(int index) |
|
224 | 224 | This signal is emitted values the value in the set has been modified. |
|
225 | 225 | Parameter \a index indicates the position of the modified value. |
|
226 | 226 | */ |
|
227 | 227 | |
|
228 | 228 | /*! |
|
229 | 229 | \qmlproperty int BarSet::count |
|
230 | 230 | The count of values on the barset |
|
231 | 231 | */ |
|
232 | 232 | |
|
233 | 233 | /*! |
|
234 | 234 | \qmlproperty QVariantList BarSet::values |
|
235 | 235 | The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of |
|
236 | 236 | reals as values, the values are automatically completed to points by using the index of a value as it's |
|
237 | 237 | x-coordinate. For example: |
|
238 | 238 | \code |
|
239 | 239 | myBarSet1.values = [0, 5, 1, 5]; |
|
240 | 240 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; |
|
241 | 241 | \endcode |
|
242 | 242 | */ |
|
243 | 243 | |
|
244 | 244 | /*! |
|
245 | 245 | Constructs QBarSet with a label of \a label and with parent of \a parent |
|
246 | 246 | */ |
|
247 | 247 | QBarSet::QBarSet(const QString label, QObject *parent) |
|
248 | 248 | : QObject(parent) |
|
249 | 249 | ,d_ptr(new QBarSetPrivate(label,this)) |
|
250 | 250 | { |
|
251 | 251 | } |
|
252 | 252 | |
|
253 | 253 | /*! |
|
254 | 254 | Destroys the barset |
|
255 | 255 | */ |
|
256 | 256 | QBarSet::~QBarSet() |
|
257 | 257 | { |
|
258 | 258 | // NOTE: d_ptr destroyed by QObject |
|
259 | 259 | } |
|
260 | 260 | |
|
261 | 261 | /*! |
|
262 | 262 | Sets new \a label for set. |
|
263 | 263 | */ |
|
264 | 264 | void QBarSet::setLabel(const QString label) |
|
265 | 265 | { |
|
266 | 266 | d_ptr->m_label = label; |
|
267 | 267 | emit labelChanged(); |
|
268 | 268 | } |
|
269 | 269 | |
|
270 | 270 | /*! |
|
271 | 271 | Returns label of the set. |
|
272 | 272 | */ |
|
273 | 273 | QString QBarSet::label() const |
|
274 | 274 | { |
|
275 | 275 | return d_ptr->m_label; |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | /*! |
|
279 | 279 | Appends new value \a value to the end of set. |
|
280 | 280 | */ |
|
281 | 281 | void QBarSet::append(const qreal value) |
|
282 | 282 | { |
|
283 | 283 | // Convert to QPointF |
|
284 | 284 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
285 | 285 | } |
|
286 | 286 | |
|
287 | 287 | /*! |
|
288 | 288 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
289 | 289 | are appended to end of barset |
|
290 | 290 | \sa append() |
|
291 | 291 | */ |
|
292 | 292 | void QBarSet::append(const QList<qreal> &values) |
|
293 | 293 | { |
|
294 | 294 | int index = d_ptr->m_values.count(); |
|
295 | 295 | d_ptr->append(values); |
|
296 | 296 | emit valuesAdded(index, values.count()); |
|
297 | 297 | } |
|
298 | 298 | |
|
299 | 299 | /*! |
|
300 | 300 | Convinience operator. Same as append, with real \a value. |
|
301 | 301 | \sa append() |
|
302 | 302 | */ |
|
303 | 303 | QBarSet& QBarSet::operator << (const qreal &value) |
|
304 | 304 | { |
|
305 | 305 | // append(value); |
|
306 | 306 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
307 | 307 | return *this; |
|
308 | 308 | } |
|
309 | 309 | |
|
310 | 310 | /*! |
|
311 | 311 | Inserts new \a value on the \a index position. |
|
312 | 312 | The value that is currently at this postion is moved to postion index + 1 |
|
313 | 313 | \sa remove() |
|
314 | 314 | */ |
|
315 | 315 | void QBarSet::insert(const int index, const qreal value) |
|
316 | 316 | { |
|
317 | 317 | d_ptr->insert(index, value); |
|
318 | 318 | emit valuesAdded(index,1); |
|
319 | 319 | } |
|
320 | 320 | |
|
321 | 321 | /*! |
|
322 | 322 | Removes \a count number of values from the set starting at \a index. |
|
323 | 323 | \sa insert() |
|
324 | 324 | */ |
|
325 | 325 | void QBarSet::remove(const int index, const int count) |
|
326 | 326 | { |
|
327 | 327 | int removedCount = d_ptr->remove(index,count); |
|
328 | 328 | if (removedCount > 0) { |
|
329 | 329 | emit valuesRemoved(index,removedCount); |
|
330 | 330 | } |
|
331 | 331 | return; |
|
332 | 332 | } |
|
333 | 333 | |
|
334 | 334 | /*! |
|
335 | 335 | Sets a new value \a value to set, indexed by \a index |
|
336 | 336 | */ |
|
337 | 337 | void QBarSet::replace(const int index, const qreal value) |
|
338 | 338 | { |
|
339 | 339 | if (index >= 0 && index < d_ptr->m_values.count()) { |
|
340 | 340 | d_ptr->replace(index,value); |
|
341 | 341 | emit valueChanged(index); |
|
342 | 342 | } |
|
343 | 343 | } |
|
344 | 344 | |
|
345 | 345 | |
|
346 | 346 | /*! |
|
347 | 347 | Returns value of set indexed by \a index. |
|
348 | 348 | If the index is out of bounds 0.0 is returned. |
|
349 | 349 | */ |
|
350 | 350 | qreal QBarSet::at(const int index) const |
|
351 | 351 | { |
|
352 | 352 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
353 | 353 | return 0; |
|
354 | 354 | } |
|
355 | 355 | |
|
356 | 356 | return d_ptr->m_values.at(index).y(); |
|
357 | 357 | } |
|
358 | 358 | |
|
359 | 359 | /*! |
|
360 | 360 | Returns value of set indexed by \a index. |
|
361 | 361 | If the index is out of bounds 0.0 is returned. |
|
362 | 362 | */ |
|
363 | 363 | qreal QBarSet::operator [](const int index) const |
|
364 | 364 | { |
|
365 | 365 | return at(index); |
|
366 | 366 | } |
|
367 | 367 | |
|
368 | 368 | /*! |
|
369 | 369 | Returns count of values in set. |
|
370 | 370 | */ |
|
371 | 371 | int QBarSet::count() const |
|
372 | 372 | { |
|
373 | 373 | return d_ptr->m_values.count(); |
|
374 | 374 | } |
|
375 | 375 | |
|
376 | 376 | /*! |
|
377 | 377 | Returns sum of all values in barset. |
|
378 | 378 | */ |
|
379 | 379 | qreal QBarSet::sum() const |
|
380 | 380 | { |
|
381 | 381 | qreal total(0); |
|
382 | 382 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
383 | 383 | total += d_ptr->m_values.at(i).y(); |
|
384 | 384 | } |
|
385 | 385 | return total; |
|
386 | 386 | } |
|
387 | 387 | |
|
388 | 388 | /*! |
|
389 | 389 | Sets pen for set. Bars of this set are drawn using \a pen |
|
390 | 390 | */ |
|
391 | 391 | void QBarSet::setPen(const QPen &pen) |
|
392 | 392 | { |
|
393 | 393 | if(d_ptr->m_pen!=pen){ |
|
394 | 394 | d_ptr->m_pen = pen; |
|
395 | 395 | emit d_ptr->updatedBars(); |
|
396 | 396 | emit penChanged(); |
|
397 | 397 | } |
|
398 | 398 | } |
|
399 | 399 | |
|
400 | 400 | /*! |
|
401 | 401 | Returns pen of the set. |
|
402 | 402 | */ |
|
403 | 403 | QPen QBarSet::pen() const |
|
404 | 404 | { |
|
405 | 405 | return d_ptr->m_pen; |
|
406 | 406 | } |
|
407 | 407 | |
|
408 | 408 | /*! |
|
409 | 409 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
410 | 410 | */ |
|
411 | 411 | void QBarSet::setBrush(const QBrush &brush) |
|
412 | 412 | { |
|
413 | 413 | if(d_ptr->m_brush!=brush){ |
|
414 | 414 | d_ptr->m_brush = brush; |
|
415 | 415 | emit d_ptr->updatedBars(); |
|
416 | 416 | emit brushChanged(); |
|
417 | 417 | } |
|
418 | 418 | } |
|
419 | 419 | |
|
420 | 420 | /*! |
|
421 | 421 | Returns brush of the set. |
|
422 | 422 | */ |
|
423 | 423 | QBrush QBarSet::brush() const |
|
424 | 424 | { |
|
425 | 425 | return d_ptr->m_brush; |
|
426 | 426 | } |
|
427 | 427 | |
|
428 | 428 | /*! |
|
429 | 429 | Sets \a brush of the values that are drawn on top of this barset |
|
430 | 430 | */ |
|
431 | 431 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
432 | 432 | { |
|
433 | 433 | if(d_ptr->m_labelBrush!=brush){ |
|
434 | 434 | d_ptr->m_labelBrush = brush; |
|
435 | 435 | emit d_ptr->updatedBars(); |
|
436 | 436 | emit labelBrushChanged(); |
|
437 | 437 | } |
|
438 | 438 | } |
|
439 | 439 | |
|
440 | 440 | /*! |
|
441 | 441 | Returns brush of the values that are drawn on top of this barset |
|
442 | 442 | */ |
|
443 | 443 | QBrush QBarSet::labelBrush() const |
|
444 | 444 | { |
|
445 | 445 | return d_ptr->m_labelBrush; |
|
446 | 446 | } |
|
447 | 447 | |
|
448 | 448 | /*! |
|
449 | 449 | Sets the \a font for values that are drawn on top of this barset |
|
450 | 450 | */ |
|
451 | 451 | void QBarSet::setLabelFont(const QFont &font) |
|
452 | 452 | { |
|
453 | 453 | if(d_ptr->m_labelFont!=font) { |
|
454 | 454 | d_ptr->m_labelFont = font; |
|
455 | 455 | emit d_ptr->updatedBars(); |
|
456 | 456 | emit labelFontChanged(); |
|
457 | 457 | } |
|
458 | 458 | |
|
459 | 459 | } |
|
460 | 460 | |
|
461 | 461 | /*! |
|
462 | 462 | Returns the pen for values that are drawn on top of this barset |
|
463 | 463 | */ |
|
464 | 464 | QFont QBarSet::labelFont() const |
|
465 | 465 | { |
|
466 | 466 | return d_ptr->m_labelFont; |
|
467 | 467 | } |
|
468 | 468 | |
|
469 | 469 | /*! |
|
470 | 470 | Returns the color of the brush of barset. |
|
471 | 471 | */ |
|
472 | 472 | QColor QBarSet::color() |
|
473 | 473 | { |
|
474 | 474 | return brush().color(); |
|
475 | 475 | } |
|
476 | 476 | |
|
477 | 477 | /*! |
|
478 | 478 | Sets the \a color of brush for this barset |
|
479 | 479 | */ |
|
480 | 480 | void QBarSet::setColor(QColor color) |
|
481 | 481 | { |
|
482 | 482 | QBrush b = brush(); |
|
483 | 483 | if (b.color() != color) { |
|
484 | 484 | b.setColor(color); |
|
485 | 485 | setBrush(b); |
|
486 | 486 | emit colorChanged(color); |
|
487 | 487 | } |
|
488 | 488 | } |
|
489 | 489 | |
|
490 | 490 | /*! |
|
491 | 491 | Returns the color of pen of this barset |
|
492 | 492 | */ |
|
493 | 493 | QColor QBarSet::borderColor() |
|
494 | 494 | { |
|
495 | 495 | return pen().color(); |
|
496 | 496 | } |
|
497 | 497 | |
|
498 | 498 | /*! |
|
499 | 499 | Sets the color of pen for this barset |
|
500 | 500 | */ |
|
501 | 501 | void QBarSet::setBorderColor(QColor color) |
|
502 | 502 | { |
|
503 | 503 | QPen p = pen(); |
|
504 | 504 | if (p.color() != color) { |
|
505 | 505 | p.setColor(color); |
|
506 | 506 | setPen(p); |
|
507 | 507 | emit borderColorChanged(color); |
|
508 | 508 | } |
|
509 | 509 | } |
|
510 | 510 | |
|
511 | 511 | /*! |
|
512 | 512 | Returns the color of labels of this barset |
|
513 | 513 | */ |
|
514 | 514 | QColor QBarSet::labelColor() |
|
515 | 515 | { |
|
516 | 516 | return labelBrush().color(); |
|
517 | 517 | } |
|
518 | 518 | |
|
519 | 519 | /*! |
|
520 | 520 | Sets the color of labels for this barset |
|
521 | 521 | */ |
|
522 | 522 | void QBarSet::setLabelColor(QColor color) |
|
523 | 523 | { |
|
524 | 524 | QBrush b = labelBrush(); |
|
525 | 525 | if (b.color() != color) { |
|
526 | 526 | b.setColor(color); |
|
527 | 527 | setLabelBrush(b); |
|
528 | 528 | emit labelColorChanged(color); |
|
529 | 529 | } |
|
530 | 530 | } |
|
531 | 531 | |
|
532 | 532 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
533 | 533 | |
|
534 | 534 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
535 | 535 | q_ptr(parent), |
|
536 | 536 | m_label(label) |
|
537 | 537 | { |
|
538 | 538 | } |
|
539 | 539 | |
|
540 | 540 | QBarSetPrivate::~QBarSetPrivate() |
|
541 | 541 | { |
|
542 | 542 | } |
|
543 | 543 | |
|
544 | 544 | void QBarSetPrivate::append(QPointF value) |
|
545 | 545 | { |
|
546 | 546 | m_values.append(value); |
|
547 | 547 | emit restructuredBars(); |
|
548 | 548 | } |
|
549 | 549 | |
|
550 | 550 | void QBarSetPrivate::append(QList<QPointF> values) |
|
551 | 551 | { |
|
552 | 552 | for (int i=0; i<values.count(); i++) { |
|
553 | 553 | m_values.append(values.at(i)); |
|
554 | 554 | } |
|
555 | 555 | emit restructuredBars(); |
|
556 | 556 | } |
|
557 | 557 | |
|
558 | 558 | void QBarSetPrivate::append(QList<qreal> values) |
|
559 | 559 | { |
|
560 | 560 | int index = m_values.count(); |
|
561 | 561 | for (int i=0; i<values.count(); i++) { |
|
562 | 562 | m_values.append(QPointF(index,values.at(i))); |
|
563 | 563 | index++; |
|
564 | 564 | } |
|
565 | 565 | emit restructuredBars(); |
|
566 | 566 | } |
|
567 | 567 | |
|
568 | 568 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
569 | 569 | { |
|
570 | 570 | m_values.insert(index, QPointF(index, value)); |
|
571 | 571 | emit restructuredBars(); |
|
572 | 572 | } |
|
573 | 573 | |
|
574 | 574 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
575 | 575 | { |
|
576 | 576 | m_values.insert(index, value); |
|
577 | 577 | emit restructuredBars(); |
|
578 | 578 | } |
|
579 | 579 | |
|
580 | 580 | int QBarSetPrivate::remove(const int index, const int count) |
|
581 | 581 | { |
|
582 | 582 | int removeCount = count; |
|
583 | 583 | |
|
584 | 584 | if ((index <0) || (m_values.count() == 0)) { |
|
585 | 585 | // Invalid index or not values in list, remove nothing. |
|
586 | 586 | return 0; |
|
587 | 587 | } else if ((index + count) > m_values.count()) { |
|
588 | 588 | // Trying to remove more items than list has. Limit amount to be removed. |
|
589 | 589 | removeCount = m_values.count() - index; |
|
590 | 590 | } |
|
591 | 591 | |
|
592 | 592 | int c = 0; |
|
593 | 593 | while (c < removeCount) { |
|
594 | 594 | m_values.removeAt(index); |
|
595 | 595 | c++; |
|
596 | 596 | } |
|
597 | 597 | emit restructuredBars(); |
|
598 | 598 | return removeCount; |
|
599 | 599 | } |
|
600 | 600 | |
|
601 | 601 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
602 | 602 | { |
|
603 | 603 | m_values.replace(index,QPointF(index,value)); |
|
604 | 604 | emit updatedBars(); |
|
605 | 605 | } |
|
606 | 606 | |
|
607 | 607 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
608 | 608 | { |
|
609 | 609 | m_values.replace(index,value); |
|
610 | 610 | emit updatedBars(); |
|
611 | 611 | } |
|
612 | 612 | |
|
613 | 613 | #include "moc_qbarset.cpp" |
|
614 | 614 | #include "moc_qbarset_p.cpp" |
|
615 | 615 | |
|
616 | 616 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,119 +1,119 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qgroupedbarseries.h" |
|
22 | 22 | #include "qgroupedbarseries_p.h" |
|
23 | 23 | #include "groupedbarchartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "chartanimator_p.h" |
|
27 | 27 | #include "qcategoriesaxis.h" |
|
28 | 28 | #include "qvaluesaxis.h" |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | /*! |
|
33 | 33 | \class QGroupedBarSeries |
|
34 | 34 | \brief Series for creating grouped bar chart |
|
35 | 35 | \mainclass |
|
36 | 36 | |
|
37 | 37 | QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
38 | 38 | as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data |
|
39 | 39 | from sets to categories, which are defined by a QStringList. |
|
40 | 40 | |
|
41 | 41 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. |
|
42 | 42 | \image examples_groupedbarchart.png |
|
43 | 43 | |
|
44 | 44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries |
|
45 | 45 | */ |
|
46 | 46 | /*! |
|
47 | 47 | \qmlclass GroupedBarSeries QGroupedBarSeries |
|
48 | \inherits BarSeries | |
|
48 | \inherits AbstractBarSeries | |
|
49 | 49 | |
|
50 | 50 | The following QML shows how to create a simple grouped bar chart: |
|
51 | 51 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 |
|
52 | 52 | \beginfloatleft |
|
53 | 53 | \image demos_qmlchart7.png |
|
54 | 54 | \endfloat |
|
55 | 55 | \clearfloat |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | Constructs empty QGroupedBarSeries. |
|
60 | 60 | QGroupedBarSeries is QObject which is a child of a \a parent. |
|
61 | 61 | */ |
|
62 | 62 | QGroupedBarSeries::QGroupedBarSeries(QObject *parent) |
|
63 | 63 | : QAbstractBarSeries(*new QGroupedBarSeriesPrivate(this), parent) |
|
64 | 64 | { |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | /*! |
|
68 | 68 | Returns QChartSeries::SeriesTypeGroupedBar. |
|
69 | 69 | */ |
|
70 | 70 | QAbstractSeries::SeriesType QGroupedBarSeries::type() const |
|
71 | 71 | { |
|
72 | 72 | return QAbstractSeries::SeriesTypeGroupedBar; |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 | 76 | |
|
77 | 77 | QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
78 | 78 | { |
|
79 | 79 | |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
83 | 83 | { |
|
84 | 84 | qreal minX(domain.minX()); |
|
85 | 85 | qreal minY(domain.minY()); |
|
86 | 86 | qreal maxX(domain.maxX()); |
|
87 | 87 | qreal maxY(domain.maxY()); |
|
88 | 88 | int tickXCount(domain.tickXCount()); |
|
89 | 89 | int tickYCount(domain.tickYCount()); |
|
90 | 90 | |
|
91 | 91 | qreal x = categoryCount(); |
|
92 | 92 | qreal y = max(); |
|
93 | 93 | minX = qMin(minX, -0.5); |
|
94 | 94 | minY = qMin(minY, y); |
|
95 | 95 | maxX = qMax(maxX, x - 0.5); |
|
96 | 96 | maxY = qMax(maxY, y); |
|
97 | 97 | tickXCount = x+1; |
|
98 | 98 | |
|
99 | 99 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
100 | 100 | } |
|
101 | 101 | |
|
102 | 102 | |
|
103 | 103 | Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
104 | 104 | { |
|
105 | 105 | Q_Q(QGroupedBarSeries); |
|
106 | 106 | |
|
107 | 107 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); |
|
108 | 108 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
109 | 109 | presenter->animator()->addAnimation(bar); |
|
110 | 110 | } |
|
111 | 111 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
112 | 112 | return bar; |
|
113 | 113 | } |
|
114 | 114 | |
|
115 | 115 | |
|
116 | 116 | #include "moc_qgroupedbarseries.cpp" |
|
117 | 117 | |
|
118 | 118 | QTCOMMERCIALCHART_END_NAMESPACE |
|
119 | 119 |
@@ -1,249 +1,249 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qhbarmodelmapper.h" |
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | /*! |
|
26 | 26 | \class QHBarModelMapper |
|
27 | 27 | \brief Horizontal model mapper for bar series |
|
28 | 28 | \mainclass |
|
29 | 29 | |
|
30 | 30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
31 | 31 | Horizontal model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. |
|
32 | 32 | Model mapper maintains equal size of all the BarSets. |
|
33 | 33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
34 | 34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
35 | 35 | */ |
|
36 | 36 | /*! |
|
37 | 37 | \qmlclass HBarModelMapper QHBarModelMapper |
|
38 | 38 | |
|
39 | 39 | HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source |
|
40 | 40 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. |
|
41 | 41 | HBarModelMapper keeps the series and the model in sync. |
|
42 | 42 | |
|
43 | 43 | The following QML example would create a bar series with three bar sets (assuming the model has |
|
44 | 44 | at least four rows). Each bar set would contain data starting from column 1. The name of a set would be defined by |
|
45 | 45 | the vertical header (of the row). |
|
46 | 46 | \code |
|
47 | 47 | BarSeries { |
|
48 | 48 | HBarModelMapper { |
|
49 | 49 | model: myCustomModel // QAbstractItemModel derived implementation |
|
50 | 50 | firstBarSetRow: 1 |
|
51 | 51 | lastBarSetRow: 3 |
|
52 | 52 | firstColumn: 1 |
|
53 | 53 | } |
|
54 | 54 | } |
|
55 | 55 | \endcode |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \property QHBarModelMapper::series |
|
60 | 60 | \brief Defines the QPieSeries object that is used by the mapper. |
|
61 | 61 | |
|
62 | 62 | All the data in the series is discarded when it is set to the mapper. |
|
63 | 63 | When new series is specified the old series is disconnected (it preserves its data) |
|
64 | 64 | */ |
|
65 | 65 | /*! |
|
66 | \qmlproperty BarSeries HBarModelMapper::series | |
|
67 | Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is | |
|
66 | \qmlproperty AbstractBarSeries HBarModelMapper::series | |
|
67 | Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is | |
|
68 | 68 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
69 | 69 | */ |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | \property QHBarModelMapper::model |
|
73 | 73 | \brief Defines the model that is used by the mapper. |
|
74 | 74 | */ |
|
75 | 75 | /*! |
|
76 | 76 | \qmlproperty SomeModel HBarModelMapper::model |
|
77 | 77 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
78 | 78 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns |
|
79 | 79 | and modifying the data of the cells. |
|
80 | 80 | */ |
|
81 | 81 | |
|
82 | 82 | /*! |
|
83 | 83 | \property QHBarModelMapper::firstBarSetRow |
|
84 | 84 | \brief Defines which column of the model is used as the data source for the first bar set |
|
85 | 85 | Default value is: -1 (invalid mapping) |
|
86 | 86 | */ |
|
87 | 87 | /*! |
|
88 | 88 | \qmlproperty int HBarModelMapper::firstBarSetRow |
|
89 | 89 | Defines which column of the model is used as the data source for the first bar set. The default value is -1 |
|
90 | 90 | (invalid mapping). |
|
91 | 91 | */ |
|
92 | 92 | |
|
93 | 93 | /*! |
|
94 | 94 | \property QHBarModelMapper::lastBarSetRow |
|
95 | 95 | \brief Defines which column of the model is used as the data source for the last bar set |
|
96 | 96 | Default value is: -1 (invalid mapping) |
|
97 | 97 | */ |
|
98 | 98 | /*! |
|
99 | 99 | \qmlproperty int HBarModelMapper::lastBarSetRow |
|
100 | 100 | Defines which column of the model is used as the data source for the last bar set. The default value is -1 |
|
101 | 101 | (invalid mapping). |
|
102 | 102 | */ |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | \property QHBarModelMapper::firstColumn |
|
106 | 106 | \brief Defines which column of the model contains the first values of the QBarSets in the series. |
|
107 | 107 | Minimal and default value is: 0 |
|
108 | 108 | */ |
|
109 | 109 | /*! |
|
110 | 110 | \qmlproperty int HBarModelMapper::firstColumn |
|
111 | 111 | Defines which column of the model contains the first values of the QBarSets in the series. |
|
112 | 112 | The default value is 0. |
|
113 | 113 | */ |
|
114 | 114 | |
|
115 | 115 | /*! |
|
116 | 116 | \property QHBarModelMapper::columnCount |
|
117 | 117 | \brief Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries |
|
118 | 118 | Minimal and default value is: -1 (count limited by the number of columns in the model) |
|
119 | 119 | */ |
|
120 | 120 | /*! |
|
121 | 121 | \qmlproperty int HBarModelMapper::columnCount |
|
122 | 122 | Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries. The default value is |
|
123 | 123 | -1 (count limited by the number of columns in the model) |
|
124 | 124 | */ |
|
125 | 125 | |
|
126 | 126 | /*! |
|
127 | 127 | \fn void QHBarModelMapper::seriesReplaced() |
|
128 | 128 | |
|
129 | 129 | Emitted when the series to which mapper is connected to has changed. |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | \fn void QHBarModelMapper::modelReplaced() |
|
134 | 134 | |
|
135 | 135 | Emitted when the model to which mapper is connected to has changed. |
|
136 | 136 | */ |
|
137 | 137 | |
|
138 | 138 | /*! |
|
139 | 139 | \fn void QHBarModelMapper::firstBarSetRowChanged() |
|
140 | 140 | |
|
141 | 141 | Emitted when the firstBarSetRow has changed. |
|
142 | 142 | */ |
|
143 | 143 | |
|
144 | 144 | /*! |
|
145 | 145 | \fn void QHBarModelMapper::lastBarSetRowChanged() |
|
146 | 146 | |
|
147 | 147 | Emitted when the lastBarSetRow has changed. |
|
148 | 148 | */ |
|
149 | 149 | |
|
150 | 150 | /*! |
|
151 | 151 | \fn void QHBarModelMapper::firstColumnChanged() |
|
152 | 152 | Emitted when the firstColumn has changed. |
|
153 | 153 | */ |
|
154 | 154 | |
|
155 | 155 | /*! |
|
156 | 156 | \fn void QHBarModelMapper::columnCountChanged() |
|
157 | 157 | Emitted when the columnCount has changed. |
|
158 | 158 | */ |
|
159 | 159 | |
|
160 | 160 | /*! |
|
161 | 161 | Constructs a mapper object which is a child of \a parent. |
|
162 | 162 | */ |
|
163 | 163 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : |
|
164 | 164 | QBarModelMapper(parent) |
|
165 | 165 | { |
|
166 | 166 | QBarModelMapper::setOrientation(Qt::Horizontal); |
|
167 | 167 | } |
|
168 | 168 | |
|
169 | 169 | QAbstractItemModel* QHBarModelMapper::model() const |
|
170 | 170 | { |
|
171 | 171 | return QBarModelMapper::model(); |
|
172 | 172 | } |
|
173 | 173 | |
|
174 | 174 | void QHBarModelMapper::setModel(QAbstractItemModel *model) |
|
175 | 175 | { |
|
176 | 176 | if (model != QBarModelMapper::model()) { |
|
177 | 177 | QBarModelMapper::setModel(model); |
|
178 | 178 | emit modelReplaced(); |
|
179 | 179 | } |
|
180 | 180 | } |
|
181 | 181 | |
|
182 | 182 | QAbstractBarSeries* QHBarModelMapper::series() const |
|
183 | 183 | { |
|
184 | 184 | return QBarModelMapper::series(); |
|
185 | 185 | } |
|
186 | 186 | |
|
187 | 187 | void QHBarModelMapper::setSeries(QAbstractBarSeries *series) |
|
188 | 188 | { |
|
189 | 189 | if (series != QBarModelMapper::series()) { |
|
190 | 190 | QBarModelMapper::setSeries(series); |
|
191 | 191 | emit seriesReplaced(); |
|
192 | 192 | } |
|
193 | 193 | } |
|
194 | 194 | |
|
195 | 195 | int QHBarModelMapper::firstBarSetRow() const |
|
196 | 196 | { |
|
197 | 197 | return QBarModelMapper::firstBarSetSection(); |
|
198 | 198 | } |
|
199 | 199 | |
|
200 | 200 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) |
|
201 | 201 | { |
|
202 | 202 | if (firstBarSetRow != firstBarSetSection()) { |
|
203 | 203 | QBarModelMapper::setFirstBarSetSection(firstBarSetRow); |
|
204 | 204 | emit firstBarSetRowChanged(); |
|
205 | 205 | } |
|
206 | 206 | } |
|
207 | 207 | |
|
208 | 208 | int QHBarModelMapper::lastBarSetRow() const |
|
209 | 209 | { |
|
210 | 210 | return QBarModelMapper::lastBarSetSection(); |
|
211 | 211 | } |
|
212 | 212 | |
|
213 | 213 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) |
|
214 | 214 | { |
|
215 | 215 | if (lastBarSetRow != lastBarSetSection()) { |
|
216 | 216 | QBarModelMapper::setLastBarSetSection(lastBarSetRow); |
|
217 | 217 | emit lastBarSetRowChanged(); |
|
218 | 218 | } |
|
219 | 219 | } |
|
220 | 220 | |
|
221 | 221 | int QHBarModelMapper::firstColumn() const |
|
222 | 222 | { |
|
223 | 223 | return QBarModelMapper::first(); |
|
224 | 224 | } |
|
225 | 225 | |
|
226 | 226 | void QHBarModelMapper::setFirstColumn(int firstColumn) |
|
227 | 227 | { |
|
228 | 228 | if (firstColumn != first()) { |
|
229 | 229 | QBarModelMapper::setFirst(firstColumn); |
|
230 | 230 | emit firstColumnChanged(); |
|
231 | 231 | } |
|
232 | 232 | } |
|
233 | 233 | |
|
234 | 234 | int QHBarModelMapper::columnCount() const |
|
235 | 235 | { |
|
236 | 236 | return QBarModelMapper::count(); |
|
237 | 237 | } |
|
238 | 238 | |
|
239 | 239 | void QHBarModelMapper::setColumnCount(int columnCount) |
|
240 | 240 | { |
|
241 | 241 | if (columnCount != count()) { |
|
242 | 242 | QBarModelMapper::setCount(columnCount); |
|
243 | 243 | emit firstColumnChanged(); |
|
244 | 244 | } |
|
245 | 245 | } |
|
246 | 246 | |
|
247 | 247 | #include "moc_qhbarmodelmapper.cpp" |
|
248 | 248 | |
|
249 | 249 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,120 +1,120 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qstackedbarseries.h" |
|
22 | 22 | #include "qstackedbarseries_p.h" |
|
23 | 23 | #include "stackedbarchartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "chartanimator_p.h" |
|
27 | 27 | #include "qcategoriesaxis.h" |
|
28 | 28 | #include "qvaluesaxis.h" |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | /*! |
|
33 | 33 | \class QStackedBarSeries |
|
34 | 34 | \brief Series for creating stacked bar chart |
|
35 | 35 | \mainclass |
|
36 | 36 | |
|
37 | 37 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
38 | 38 | as stacks, where bars in same category are stacked on top of each other. |
|
39 | 39 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
40 | 40 | |
|
41 | 41 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
|
42 | 42 | \image examples_stackedbarchart.png |
|
43 | 43 | |
|
44 | 44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries |
|
45 | 45 | */ |
|
46 | 46 | |
|
47 | 47 | /*! |
|
48 | 48 | \qmlclass StackedBarSeries QStackedBarSeries |
|
49 | \inherits BarSeries | |
|
49 | \inherits AbstractBarSeries | |
|
50 | 50 | |
|
51 | 51 | The following QML shows how to create a simple stacked bar chart: |
|
52 | 52 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 |
|
53 | 53 | \beginfloatleft |
|
54 | 54 | \image demos_qmlchart8.png |
|
55 | 55 | \endfloat |
|
56 | 56 | \clearfloat |
|
57 | 57 | */ |
|
58 | 58 | |
|
59 | 59 | /*! |
|
60 | 60 | Constructs empty QStackedBarSeries. |
|
61 | 61 | QStackedBarSeries is QObject which is a child of a \a parent. |
|
62 | 62 | */ |
|
63 | 63 | QStackedBarSeries::QStackedBarSeries(QObject *parent) |
|
64 | 64 | : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent) |
|
65 | 65 | { |
|
66 | 66 | } |
|
67 | 67 | |
|
68 | 68 | /*! |
|
69 | 69 | Returns QChartSeries::SeriesTypeStackedBar. |
|
70 | 70 | */ |
|
71 | 71 | QAbstractSeries::SeriesType QStackedBarSeries::type() const |
|
72 | 72 | { |
|
73 | 73 | return QAbstractSeries::SeriesTypeStackedBar; |
|
74 | 74 | } |
|
75 | 75 | |
|
76 | 76 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
77 | 77 | |
|
78 | 78 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
79 | 79 | { |
|
80 | 80 | |
|
81 | 81 | } |
|
82 | 82 | |
|
83 | 83 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
84 | 84 | { |
|
85 | 85 | qreal minX(domain.minX()); |
|
86 | 86 | qreal minY(domain.minY()); |
|
87 | 87 | qreal maxX(domain.maxX()); |
|
88 | 88 | qreal maxY(domain.maxY()); |
|
89 | 89 | int tickXCount(domain.tickXCount()); |
|
90 | 90 | int tickYCount(domain.tickYCount()); |
|
91 | 91 | |
|
92 | 92 | qreal x = categoryCount(); |
|
93 | 93 | qreal y = maxCategorySum(); |
|
94 | 94 | minX = qMin(minX, -0.5); |
|
95 | 95 | minY = qMin(minY, y); |
|
96 | 96 | maxX = qMax(maxX, x - 0.5); |
|
97 | 97 | maxY = qMax(maxY, y); |
|
98 | 98 | tickXCount = x+1; |
|
99 | 99 | |
|
100 | 100 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
101 | 101 | } |
|
102 | 102 | |
|
103 | 103 | |
|
104 | 104 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
105 | 105 | { |
|
106 | 106 | Q_Q(QStackedBarSeries); |
|
107 | 107 | |
|
108 | 108 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); |
|
109 | 109 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
110 | 110 | presenter->animator()->addAnimation(bar); |
|
111 | 111 | } |
|
112 | 112 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
113 | 113 | return bar; |
|
114 | 114 | } |
|
115 | 115 | |
|
116 | 116 | |
|
117 | 117 | #include "moc_qstackedbarseries.cpp" |
|
118 | 118 | |
|
119 | 119 | QTCOMMERCIALCHART_END_NAMESPACE |
|
120 | 120 |
@@ -1,248 +1,248 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qvbarmodelmapper.h" |
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | /*! |
|
26 | 26 | \class QVBarModelMapper |
|
27 | 27 | \brief Vertical model mapper for bar series |
|
28 | 28 | \mainclass |
|
29 | 29 | |
|
30 | 30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
31 | 31 | Vertical model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. |
|
32 | 32 | Model mapper maintains equal size of all the BarSets. |
|
33 | 33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
34 | 34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
35 | 35 | */ |
|
36 | 36 | /*! |
|
37 | 37 | \qmlclass VBarModelMapper |
|
38 | 38 | \mainclass |
|
39 | 39 | |
|
40 | 40 | VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source |
|
41 | 41 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. |
|
42 | 42 | VBarModelMapper keeps the series and the model in sync. |
|
43 | 43 | |
|
44 | 44 | The following QML example would create a bar series with three bar sets (assuming the |
|
45 | 45 | model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be |
|
46 | 46 | defined by the horizontal header (of the column). |
|
47 | 47 | \code |
|
48 | 48 | GroupedBarSeries { |
|
49 | 49 | VBarModelMapper { |
|
50 | 50 | model: myCustomModel // QAbstractItemModel derived implementation |
|
51 | 51 | firstBarSetColumn: 1 |
|
52 | 52 | lastBarSetColumn: 3 |
|
53 | 53 | firstRow: 1 |
|
54 | 54 | } |
|
55 | 55 | } |
|
56 | 56 | \endcode |
|
57 | 57 | */ |
|
58 | 58 | |
|
59 | 59 | /*! |
|
60 | 60 | \property QVBarModelMapper::series |
|
61 | 61 | \brief Defines the QPieSeries object that is used by the mapper. |
|
62 | 62 | |
|
63 | 63 | All the data in the series is discarded when it is set to the mapper. |
|
64 | 64 | When new series is specified the old series is disconnected (it preserves its data) |
|
65 | 65 | */ |
|
66 | 66 | /*! |
|
67 | \qmlproperty BarSeries VBarModelMapper::series | |
|
68 | Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is | |
|
67 | \qmlproperty AbstractBarSeries VBarModelMapper::series | |
|
68 | Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is | |
|
69 | 69 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
70 | 70 | */ |
|
71 | 71 | |
|
72 | 72 | /*! |
|
73 | 73 | \property QVBarModelMapper::model |
|
74 | 74 | \brief Defines the model that is used by the mapper. |
|
75 | 75 | */ |
|
76 | 76 | /*! |
|
77 | 77 | \qmlproperty SomeModel VBarModelMapper::model |
|
78 | 78 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
79 | 79 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns |
|
80 | 80 | and modifying the data of the cells. |
|
81 | 81 | */ |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | \property QVBarModelMapper::firstBarSetColumn |
|
85 | 85 | \brief Defines which column of the model is used as the data source for the first bar set |
|
86 | 86 | Default value is: -1 (invalid mapping) |
|
87 | 87 | */ |
|
88 | 88 | /*! |
|
89 | 89 | \qmlproperty int VBarModelMapper::firstBarSetColumn |
|
90 | 90 | Defines which column of the model is used as the data source for the first bar set. Default value |
|
91 | 91 | is: -1 (invalid mapping). |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \property QVBarModelMapper::lastBarSetColumn |
|
96 | 96 | \brief Defines which column of the model is used as the data source for the last bar set |
|
97 | 97 | Default value is: -1 (invalid mapping) |
|
98 | 98 | */ |
|
99 | 99 | /*! |
|
100 | 100 | \qmlproperty int VBarModelMapper::lastBarSetColumn |
|
101 | 101 | Defines which column of the model is used as the data source for the last bar set. Default |
|
102 | 102 | value is: -1 (invalid mapping). |
|
103 | 103 | */ |
|
104 | 104 | |
|
105 | 105 | /*! |
|
106 | 106 | \property QVBarModelMapper::firstRow |
|
107 | 107 | \brief Defines which row of the model contains the first values of the QBarSets in the series. |
|
108 | 108 | Minimal and default value is: 0 |
|
109 | 109 | */ |
|
110 | 110 | /*! |
|
111 | 111 | \qmlproperty int VBarModelMapper::firstRow |
|
112 | 112 | Defines which row of the model contains the first values of the QBarSets in the series. |
|
113 | 113 | The default value is 0. |
|
114 | 114 | */ |
|
115 | 115 | |
|
116 | 116 | /*! |
|
117 | 117 | \property QVBarModelMapper::rowCount |
|
118 | 118 | \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries |
|
119 | 119 | Minimal and default value is: -1 (count limited by the number of rows in the model) |
|
120 | 120 | */ |
|
121 | 121 | /*! |
|
122 | 122 | \qmlproperty int VBarModelMapper::rowCount |
|
123 | 123 | Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is |
|
124 | 124 | -1 (count limited by the number of rows in the model) |
|
125 | 125 | */ |
|
126 | 126 | |
|
127 | 127 | /*! |
|
128 | 128 | \fn void QVBarModelMapper::seriesReplaced() |
|
129 | 129 | |
|
130 | 130 | Emitted when the series to which mapper is connected to has changed. |
|
131 | 131 | */ |
|
132 | 132 | |
|
133 | 133 | /*! |
|
134 | 134 | \fn void QVBarModelMapper::modelReplaced() |
|
135 | 135 | |
|
136 | 136 | Emitted when the model to which mapper is connected to has changed. |
|
137 | 137 | */ |
|
138 | 138 | |
|
139 | 139 | /*! |
|
140 | 140 | \fn void QVBarModelMapper::firstBarSetColumnChanged() |
|
141 | 141 | Emitted when the firstBarSetColumn has changed. |
|
142 | 142 | */ |
|
143 | 143 | |
|
144 | 144 | /*! |
|
145 | 145 | \fn void QVBarModelMapper::lastBarSetColumnChanged() |
|
146 | 146 | Emitted when the lastBarSetColumn has changed. |
|
147 | 147 | */ |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | \fn void QVBarModelMapper::firstRowChanged() |
|
151 | 151 | Emitted when the firstRow has changed. |
|
152 | 152 | */ |
|
153 | 153 | |
|
154 | 154 | /*! |
|
155 | 155 | \fn void QVBarModelMapper::rowCountChanged() |
|
156 | 156 | Emitted when the rowCount has changed. |
|
157 | 157 | */ |
|
158 | 158 | |
|
159 | 159 | /*! |
|
160 | 160 | Constructs a mapper object which is a child of \a parent. |
|
161 | 161 | */ |
|
162 | 162 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : |
|
163 | 163 | QBarModelMapper(parent) |
|
164 | 164 | { |
|
165 | 165 | QBarModelMapper::setOrientation(Qt::Vertical); |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | QAbstractItemModel* QVBarModelMapper::model() const |
|
169 | 169 | { |
|
170 | 170 | return QBarModelMapper::model(); |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | void QVBarModelMapper::setModel(QAbstractItemModel *model) |
|
174 | 174 | { |
|
175 | 175 | if (model != QBarModelMapper::model()) { |
|
176 | 176 | QBarModelMapper::setModel(model); |
|
177 | 177 | emit modelReplaced(); |
|
178 | 178 | } |
|
179 | 179 | } |
|
180 | 180 | |
|
181 | 181 | QAbstractBarSeries* QVBarModelMapper::series() const |
|
182 | 182 | { |
|
183 | 183 | return QBarModelMapper::series(); |
|
184 | 184 | } |
|
185 | 185 | |
|
186 | 186 | void QVBarModelMapper::setSeries(QAbstractBarSeries *series) |
|
187 | 187 | { |
|
188 | 188 | if (series != QBarModelMapper::series()) { |
|
189 | 189 | QBarModelMapper::setSeries(series); |
|
190 | 190 | emit seriesReplaced(); |
|
191 | 191 | } |
|
192 | 192 | } |
|
193 | 193 | |
|
194 | 194 | int QVBarModelMapper::firstBarSetColumn() const |
|
195 | 195 | { |
|
196 | 196 | return QBarModelMapper::firstBarSetSection(); |
|
197 | 197 | } |
|
198 | 198 | |
|
199 | 199 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) |
|
200 | 200 | { |
|
201 | 201 | if (firstBarSetColumn != firstBarSetSection()) { |
|
202 | 202 | QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); |
|
203 | 203 | emit firstBarSetColumnChanged(); |
|
204 | 204 | } |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | int QVBarModelMapper::lastBarSetColumn() const |
|
208 | 208 | { |
|
209 | 209 | return QBarModelMapper::lastBarSetSection(); |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | 212 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) |
|
213 | 213 | { |
|
214 | 214 | if (lastBarSetColumn != lastBarSetSection()) { |
|
215 | 215 | QBarModelMapper::setLastBarSetSection(lastBarSetColumn); |
|
216 | 216 | emit lastBarSetColumnChanged(); |
|
217 | 217 | } |
|
218 | 218 | } |
|
219 | 219 | |
|
220 | 220 | int QVBarModelMapper::firstRow() const |
|
221 | 221 | { |
|
222 | 222 | return QBarModelMapper::first(); |
|
223 | 223 | } |
|
224 | 224 | |
|
225 | 225 | void QVBarModelMapper::setFirstRow(int firstRow) |
|
226 | 226 | { |
|
227 | 227 | if (firstRow != first()) { |
|
228 | 228 | QBarModelMapper::setFirst(firstRow); |
|
229 | 229 | emit firstRowChanged(); |
|
230 | 230 | } |
|
231 | 231 | } |
|
232 | 232 | |
|
233 | 233 | int QVBarModelMapper::rowCount() const |
|
234 | 234 | { |
|
235 | 235 | return QBarModelMapper::count(); |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | void QVBarModelMapper::setRowCount(int rowCount) |
|
239 | 239 | { |
|
240 | 240 | if (rowCount != count()) { |
|
241 | 241 | QBarModelMapper::setCount(rowCount); |
|
242 | 242 | emit firstRowChanged(); |
|
243 | 243 | } |
|
244 | 244 | } |
|
245 | 245 | |
|
246 | 246 | #include "moc_qvbarmodelmapper.cpp" |
|
247 | 247 | |
|
248 | 248 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now