##// END OF EJS Templates
QML sample improvement....
Mika Salmela -
r2532:0fd351ebdc9b
parent child
Show More
@@ -1,92 +1,79
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 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 //![1]
22 22 import QtQuick 1.0
23 23 import QtCommercial.Chart 1.1
24 24
25 25 ChartView {
26 26 title: "Box Plot series"
27 27 width: 400
28 28 height: 300
29 29 theme: ChartView.ChartThemeBrownSand
30 30 legend.alignment: Qt.AlignBottom
31 31
32 //![1]
33 //![2]
34 32 BoxPlotSeries {
35 33 id: plotSeries
36 34 name: "Income"
37 //axisX: BarCategoryAxis { categories: ["Jan", "Feb", "Mar", "Apr", "May"] }
38 BoxSet { values: [3, 4, 4.4, 6, 7] }
39 BoxSet { label: "Tok"; values: [5, 6, 7.5, 8, 12] }
40 BoxSet { label: "Kol"; values: [2, 5, 5.7, 8, 9] }
41 BoxSet { id: nelBox
42 label: "Nel"
43 values: [5, 6, 6.8, 7, 8];
44 onColorChanged: {
45 console.log("onColorChanged")
46 }
47 }
48 BoxSet { label: "Vii"; values: [4, 5, 5.2, 6, 7]; color: "#aa0000" }
49 //onClicked: console.log("series onClicked " + boxset.median)
50 //onHovered: console.log("series onHovered " + status + "median = " + boxset.median)
51 onCountChanged: console.log("onCountChanged")
35 BoxSet { label: "Jan"; values: [3, 4, 4.4, 6, 7] }
36 BoxSet { label: "Feb"; values: [5, 6, 7.5, 8, 12] }
37 BoxSet { label: "Mar"; values: [2, 5, 5.7, 8, 9] }
38 BoxSet { label: "Apr"; values: [5, 6, 6.8, 7, 8] }
39 BoxSet { label: "May"; values: [4, 5, 5.2, 6, 7] }
52 40 }
53 //![2]
54 41
55 Rectangle {
56 id: moreButton
57 width: 50
58 height: 50
59 color: "gray"
60 MouseArea {
61 anchors.fill: parent
62 onClicked: {
63 nelBox.color = "#0000aa"
64 var com = Qt.createComponent("box.qml")
65 if (com.status == Component.Ready) {
66 var obj = com.createObject(moreButton)
67 obj.lowerExtreme = 1.2
68 console.log("lowerExtreme = " + obj.lowerExtreme)
69 obj.lowerQuartile = 2.2
70 console.log("lowerQuartile = " + obj.lowerQuartile)
71 obj.median = 3.2
72 console.log("median = " + obj.median)
73 obj.upperQuartile = 4.2
74 console.log("upperQuartile = " + obj.upperQuartile)
75 obj.upperExtreme = 5.2
76 console.log("upperExtreme = " + obj.upperExtreme)
77 obj.label = "mik"
78 console.log("label = " + obj.label)
79 plotSeries.append(obj)
80 obj.color = "#aa0000"
81 console.log("color = " + obj.color)
82 obj.borderColor = "#00aa00"
83 } else {
84 console.log(com.errorString())
85 }
86 }
87 }
88 }
42 // Rectangle {
43 // id: moreButton
44 // width: 50
45 // height: 50
46 // color: "gray"
47 // MouseArea {
48 // anchors.fill: parent
49 // onClicked: {
50 // nelBox.color = "#0000aa"
51 // var com = Qt.createComponent("box.qml")
52 // if (com.status == Component.Ready) {
53 // var obj = com.createObject(moreButton)
54 // obj.lowerExtreme = 1.2
55 // console.log("lowerExtreme = " + obj.lowerExtreme)
56 // obj.lowerQuartile = 2.2
57 // console.log("lowerQuartile = " + obj.lowerQuartile)
58 // obj.median = 3.2
59 // console.log("median = " + obj.median)
60 // obj.upperQuartile = 4.2
61 // console.log("upperQuartile = " + obj.upperQuartile)
62 // obj.upperExtreme = 5.2
63 // console.log("upperExtreme = " + obj.upperExtreme)
64 // obj.label = "mik"
65 // console.log("label = " + obj.label)
66 // plotSeries.append(obj)
67 // obj.color = "#aa0000"
68 // console.log("color = " + obj.color)
69 // obj.borderColor = "#00aa00"
70 // } else {
71 // console.log(com.errorString())
72 // }
73 // }
74 // }
75 // }
89 76
90 77 //![3]
91 78 }
92 79 //![3]
@@ -1,661 +1,683
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 "qboxplotseries.h"
22 22 #include "qboxplotseries_p.h"
23 23 #include "qboxplotlegendmarker.h"
24 24 #include "qbarcategoryaxis.h"
25 25 #include "boxplotchartitem_p.h"
26 26 #include "chartdataset_p.h"
27 27 #include "charttheme_p.h"
28 28 #include "qvalueaxis.h"
29 29 #include "charttheme_p.h"
30 30 #include "boxplotanimation_p.h"
31 31 #include "qchart_p.h"
32 32 #include "qboxset.h"
33 33 #include "qboxset_p.h"
34 34
35 35 #include <QDebug>
36 36
37 37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 38
39 39 /*!
40 40 \class QBoxPlotSeries
41 41 \brief Series for creating box-and-whiskers chart
42 42 \mainclass
43 43
44 44 QBoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this class is to act as
45 45 a container for single box-and-whisker items. Each item is drawn to own slot. If chart includes multiple instances of
46 46 QBoxPlotSeries then box-and-whiskers items with the same index are drawn to same slot.
47 47
48 48 See the \l {Box and Whiskers Example} {box-and-whiskers chart example} to learn how to create a box-and-whiskers chart.
49 49 \image examples_boxplotchart.png
50 50
51 51 \sa QBoxSet
52 52 */
53 53
54 54 /*!
55 55 \qmlclass BoxPlotSeries QBoxPlotSeries
56 56 \inherits QAbstractSeries
57 57
58 58 BoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this class is to act as
59 59 a container for single box-and-whisker items. Each item is drawn to own slot. If chart includes multiple instances of
60 60 BoxPlotSeries then box-and-whiskers items with the same index are drawn to same slot.
61 61
62 62 The following QML shows how to create a simple box-and-whiskers chart:
63 \snippet ../examples/qmlboxplot/qml/qmlboxplot/main.qml 1
63 \code
64 import QtQuick 1.0
65 import QtCommercial.Chart 1.1
66
67 ChartView {
68 title: "Box Plot series"
69 width: 400
70 height: 300
71 theme: ChartView.ChartThemeBrownSand
72 legend.alignment: Qt.AlignBottom
73
74 BoxPlotSeries {
75 id: plotSeries
76 name: "Income"
77 BoxSet { label: "Jan"; values: [3, 4, 4.4, 6, 7] }
78 BoxSet { label: "Feb"; values: [5, 6, 7.5, 8, 12] }
79 BoxSet { label: "Mar"; values: [2, 5, 5.7, 8, 9] }
80 BoxSet { label: "Apr"; values: [5, 6, 6.8, 7, 8] }
81 BoxSet { label: "May"; values: [4, 5, 5.2, 6, 7] }
82 }
83 }
84 \endcode
85
64 86 \beginfloatleft
65 87 \image TODO_CREATE_IMAGE.png
66 88 \endfloat
67 89 \clearfloat
68 90 */
69 91
70 92 /*!
71 93 \fn QBoxPlotSeries::boxsetsAdded(QList<QBoxSet *> sets)
72 94 \brief Signal is emitted when a new \a sets of box-and-whiskers data is added to the series.
73 95 */
74 96
75 97 /*!
76 98 \fn QBoxPlotSeries::boxsetsRemoved(QList<QBoxSet *> sets)
77 99 \brief Signal is emitted when \a sets of box-and-whiskers data is removed from the series.
78 100 */
79 101
80 102 /*!
81 103 \fn QBoxPlotSeries::clicked(QBoxSet *boxset)
82 104 \brief Signal is emitted when the user clicks the \a boxset on the chart.
83 105 */
84 106
85 107 /*!
86 108 \fn QBoxPlotSeries::hovered(bool status, QBoxSet *boxset)
87 109 \brief Signal is emitted when there is change in hover \a status over \a boxset.
88 110 */
89 111
90 112 /*!
91 113 \fn QBoxPlotSeries::countChanged()
92 114 \brief Signal is emitted when there is change in count of box-and-whiskers items in the series.
93 115 */
94 116 /*!
95 117 \qmlmethod BoxPlotSeries::append(const QString label, QVariantList values)
96 118 Appends a new box-and-whiskers set with \a label and \a values to the series.
97 119 */
98 120 /*!
99 121 \qmlmethod BoxPlotSeries::append(BoxSet *box)
100 122 Appends the \a box to the series.
101 123 */
102 124 /*!
103 125 \qmlmethod BoxPlotSeries::insert(int index, const QString label, QVariantList values)
104 126 Inserts a new box-and-whiskers set with \a label and \a values at the \a index position.
105 127 */
106 128 /*!
107 129 \qmlmethod BoxPlotSeries::remove(QBoxSet *boxset)
108 130 Removes the \a boxset from the series.
109 131 */
110 132 /*!
111 133 \qmlmethod BoxPlotSeries::clear()
112 134 Removes all boxsets from the series. Deletes removed sets.
113 135 */
114 136
115 137 /*!
116 138 \qmlsignal BoxPlotSeries::onClicked(BoxSet boxset);
117 139 Signal is emitted when the user clicks the \a boxset on the chart.
118 140 */
119 141 /*!
120 142 \qmlsignal BoxPlotSeries::onHovered(bool status, BoxSet boxset);
121 143 Signal is emitted when there is change in hover \a status over \a boxset.
122 144 */
123 145 /*!
124 146 \qmlsignal BoxPlotSeries::onCountChanged();
125 147 Signal is emitted when there is change in count of box-and-whiskers items in the series.
126 148 */
127 149 /*
128 150 void boxsetsAdded(QList<QBoxSet *> sets);
129 151 */
130 152 /*
131 153 void boxsetsRemoved(QList<QBoxSet *> sets);
132 154 */
133 155
134 156 /*!
135 157 Constructs empty QBoxPlotSeries.
136 158 QBoxPlotSeries is QObject which is a child of a \a parent.
137 159 */
138 160 QBoxPlotSeries::QBoxPlotSeries(QObject *parent)
139 161 : QAbstractSeries(*new QBoxPlotSeriesPrivate(this), parent)
140 162 {
141 163 }
142 164
143 165 /*!
144 166 Destructor. Removes series from chart.
145 167 */
146 168 QBoxPlotSeries::~QBoxPlotSeries()
147 169 {
148 170 qDebug() << "QBoxPlotSeries::~QBoxPlotSeries";
149 171
150 172 Q_D(QBoxPlotSeries);
151 173 if (d->m_chart)
152 174 d->m_chart->removeSeries(this);
153 175 }
154 176
155 177 /*!
156 178 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.
157 179 Returns true, if appending succeeded.
158 180 */
159 181 bool QBoxPlotSeries::append(QBoxSet *set)
160 182 {
161 183 Q_D(QBoxPlotSeries);
162 184
163 185 bool success = d->append(set);
164 186 if (success) {
165 187 QList<QBoxSet *> sets;
166 188 sets.append(set);
167 189 set->setParent(this);
168 190 emit boxsetsAdded(sets);
169 191 emit countChanged();
170 192 }
171 193 return success;
172 194 }
173 195
174 196 /*!
175 197 Removes boxset from the series. Releases ownership of the \a set. Deletes the set, if remove
176 198 was successful.
177 199 Returns true, if the set was removed.
178 200 */
179 201 bool QBoxPlotSeries::remove(QBoxSet *set)
180 202 {
181 203 Q_D(QBoxPlotSeries);
182 204 bool success = d->remove(set);
183 205 if (success) {
184 206 QList<QBoxSet *> sets;
185 207 sets.append(set);
186 208 set->setParent(0);
187 209 emit boxsetsRemoved(sets);
188 210 emit countChanged();
189 211 delete set;
190 212 set = 0;
191 213 }
192 214 return success;
193 215 }
194 216
195 217 /*!
196 218 Takes a single \a set from the series. Does not delete the boxset object.
197 219
198 220 NOTE: The series remains as the boxset's parent object. You must set the
199 221 parent object to take full ownership.
200 222
201 223 Returns true if take was successful.
202 224 */
203 225 bool QBoxPlotSeries::take(QBoxSet *set)
204 226 {
205 227 Q_D(QBoxPlotSeries);
206 228
207 229 bool success = d->remove(set);
208 230 if (success) {
209 231 QList<QBoxSet *> sets;
210 232 sets.append(set);
211 233 emit boxsetsRemoved(sets);
212 234 emit countChanged();
213 235 }
214 236 return success;
215 237 }
216 238
217 239 /*!
218 240 Adds a list of boxsets to series. Takes ownership of the \a sets.
219 241 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
220 242 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
221 243 and function returns false.
222 244 */
223 245 bool QBoxPlotSeries::append(QList<QBoxSet *> sets)
224 246 {
225 247 Q_D(QBoxPlotSeries);
226 248 bool success = d->append(sets);
227 249 if (success) {
228 250 emit boxsetsAdded(sets);
229 251 emit countChanged();
230 252 }
231 253 return success;
232 254 }
233 255
234 256 /*!
235 257 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.
236 258 Returns true, if inserting succeeded.
237 259
238 260 */
239 261 bool QBoxPlotSeries::insert(int index, QBoxSet *set)
240 262 {
241 263 Q_D(QBoxPlotSeries);
242 264 bool success = d->insert(index, set);
243 265 if (success) {
244 266 QList<QBoxSet *> sets;
245 267 sets.append(set);
246 268 emit boxsetsAdded(sets);
247 269 emit countChanged();
248 270 }
249 271 return success;
250 272 }
251 273
252 274 /*!
253 275 Removes all boxsets from the series. Deletes removed sets.
254 276 */
255 277 void QBoxPlotSeries::clear()
256 278 {
257 279 Q_D(QBoxPlotSeries);
258 280 QList<QBoxSet *> sets = boxSets();
259 281 bool success = d->remove(sets);
260 282 if (success) {
261 283 emit boxsetsRemoved(sets);
262 284 emit countChanged();
263 285 foreach (QBoxSet *set, sets)
264 286 delete set;
265 287 }
266 288 }
267 289
268 290 /*!
269 291 Returns number of sets in series.
270 292 */
271 293 int QBoxPlotSeries::count() const
272 294 {
273 295 Q_D(const QBoxPlotSeries);
274 296 return d->m_boxSets.count();
275 297 }
276 298
277 299 /*!
278 300 Returns a list of sets in series. Keeps ownership of sets.
279 301 */
280 302 QList<QBoxSet *> QBoxPlotSeries::boxSets() const
281 303 {
282 304 Q_D(const QBoxPlotSeries);
283 305 return d->m_boxSets;
284 306 }
285 307
286 308 /*!
287 309 Returns QChartSeries::SeriesTypeBoxPlot.
288 310 */
289 311 QAbstractSeries::SeriesType QBoxPlotSeries::type() const
290 312 {
291 313 return QAbstractSeries::SeriesTypeBoxPlot;
292 314 }
293 315
294 316 /*!
295 317 Sets brush for the series. Box-and-whiskers items are drawn using \a brush
296 318 */
297 319 void QBoxPlotSeries::setBrush(const QBrush &brush)
298 320 {
299 321 Q_D(QBoxPlotSeries);
300 322
301 323 if (d->m_brush != brush) {
302 324 d->m_brush = brush;
303 325 emit d->updated();
304 326 }
305 327 }
306 328
307 329 /*!
308 330 Returns brush of the series.
309 331 */
310 332 QBrush QBoxPlotSeries::brush() const
311 333 {
312 334 Q_D(const QBoxPlotSeries);
313 335
314 336 return d->m_brush;
315 337 }
316 338
317 339 /*!
318 340 Sets pen for the series. Box-and-whiskers items are drawn using \a pen
319 341 */
320 342 void QBoxPlotSeries::setPen(const QPen &pen)
321 343 {
322 344 Q_D(QBoxPlotSeries);
323 345
324 346 if (d->m_pen != pen) {
325 347 d->m_pen = pen;
326 348 emit d->updated();
327 349 }
328 350 }
329 351
330 352 /*!
331 353 Returns the pen of this series.
332 354 */
333 355 QPen QBoxPlotSeries::pen() const
334 356 {
335 357 Q_D(const QBoxPlotSeries);
336 358
337 359 return d->m_pen;
338 360 }
339 361
340 362 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
341 363
342 364 QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q)
343 365 : QAbstractSeriesPrivate(q),
344 366 m_pen(QPen(Qt::NoPen)),
345 367 m_brush(QBrush(Qt::NoBrush))
346 368 {
347 369 }
348 370
349 371 QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate()
350 372 {
351 373 qDebug() << "QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate()";
352 374 disconnect(this, 0, 0, 0);
353 375 }
354 376
355 377 void QBoxPlotSeriesPrivate::initializeDomain()
356 378 {
357 379 qreal minX(domain()->minX());
358 380 qreal minY(domain()->minY());
359 381 qreal maxX(domain()->maxX());
360 382 qreal maxY(domain()->maxY());
361 383
362 384 qreal x = m_boxSets.count();
363 385 minX = qMin(minX, - (qreal)0.5);
364 386 minY = qMin(minY, bottom());
365 387 maxX = qMax(maxX, x - (qreal)0.5);
366 388 maxY = qMax(maxY, max());
367 389
368 390 domain()->setRange(minX, maxX, minY, maxY);
369 391 }
370 392
371 393 void QBoxPlotSeriesPrivate::initializeAxes()
372 394 {
373 395 foreach (QAbstractAxis* axis, m_axes) {
374 396 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
375 397 if (axis->orientation() == Qt::Horizontal)
376 398 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
377 399 else
378 400 qDebug() << "ALERT: QBoxPlotSeriesPrivate::initializeAxes implement #1";
379 401 }
380 402 }
381 403 }
382 404
383 405 QAbstractAxis::AxisType QBoxPlotSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
384 406 {
385 407 if (orientation == Qt::Horizontal)
386 408 return QAbstractAxis::AxisTypeBarCategory;
387 409
388 410 return QAbstractAxis::AxisTypeValue;
389 411 }
390 412
391 413 QAbstractAxis* QBoxPlotSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
392 414 {
393 415 Q_UNUSED(orientation);
394 416 // This is not implemented even in barseries, keep in touch if something needs this
395 417 qDebug() << "ALERT: QBoxPlotSeriesPrivate::createDefaultAxis implement";
396 418 return 0;
397 419 }
398 420
399 421 void QBoxPlotSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
400 422 {
401 423 QStringList categories;
402 424 if (axis->categories().isEmpty()) {
403 425 for (int i(1); i < m_boxSets.count() + 1; i++) {
404 426 QBoxSet *set = m_boxSets.at(i - 1);
405 427 if (set->label().isEmpty())
406 428 categories << QString::number(i);
407 429 else
408 430 categories << set->label();
409 431 }
410 432 axis->append(categories);
411 433 }
412 434 }
413 435
414 436 void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
415 437 {
416 438 Q_Q(QBoxPlotSeries);
417 439
418 440 BoxPlotChartItem *boxPlot = new BoxPlotChartItem(q,parent);
419 441 m_item.reset(boxPlot);
420 442 QAbstractSeriesPrivate::initializeGraphics(parent);
421 443
422 444 if (m_chart) {
423 445 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesChange(QAbstractSeries*)) );
424 446 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) );
425 447
426 448 QList<QAbstractSeries *> serieses = m_chart->series();
427 449
428 450 // Tries to find this series from the Chart's list of serieses and deduce the index
429 451 int index = 0;
430 452 foreach (QAbstractSeries *s, serieses) {
431 453 if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) {
432 454 if (q == static_cast<QBoxPlotSeries *>(s)) {
433 455 boxPlot->m_seriesIndex = index;
434 456 m_index = index;
435 457 }
436 458 index++;
437 459 }
438 460 }
439 461 boxPlot->m_seriesCount = index;
440 462 }
441 463
442 464 // Make BoxPlotChartItem to instantiate box & whisker items
443 465 boxPlot->handleDataStructureChanged();
444 466 }
445 467
446 468 void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
447 469 {
448 470 Q_Q(QBoxPlotSeries);
449 471 qDebug() << "QBoxPlotSeriesPrivate::initializeTheme";
450 472
451 473 const QList<QGradient> gradients = theme->seriesGradients();
452 474
453 475 if (forced || m_brush == QBrush(Qt::NoBrush)) {
454 476 QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.5);
455 477 q->setBrush(brushColor);
456 478 }
457 479
458 480 if (forced || m_pen == QPen(Qt::NoPen)) {
459 481 QPen pen = theme->outlinePen();
460 482 pen.setCosmetic(true);
461 483 q->setPen(pen);
462 484 }
463 485 }
464 486
465 487 void QBoxPlotSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
466 488 {
467 489 BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data());
468 490 Q_ASSERT(item);
469 491 if (options.testFlag(QChart::SeriesAnimations)) {
470 492 item->setAnimation(new BoxPlotAnimation(item));
471 493 }else{
472 494 item->setAnimation((BoxPlotAnimation *)0);
473 495 }
474 496 QAbstractSeriesPrivate::initializeAnimations(options);
475 497 }
476 498
477 499 QList<QLegendMarker*> QBoxPlotSeriesPrivate::createLegendMarkers(QLegend *legend)
478 500 {
479 501 Q_Q(QBoxPlotSeries);
480 502 QList<QLegendMarker*> list;
481 503 return list << new QBoxPlotLegendMarker(q, legend);
482 504 }
483 505
484 506 void QBoxPlotSeriesPrivate::handleSeriesRemove(QAbstractSeries *series)
485 507 {
486 508 qDebug() << "QBoxPlotSeriesPrivate::handleSeriesRemove";
487 509 Q_Q(QBoxPlotSeries);
488 510
489 511 QBoxPlotSeries *removedSeries = static_cast<QBoxPlotSeries *>(series);
490 512 QObject::disconnect(m_chart->d_ptr->m_dataset, 0, removedSeries->d_func(), 0);
491 513
492 514 // Test if series removed is me, then don't do anything
493 515 if (q != removedSeries) {
494 516 BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data());
495 517 if (item) {
496 518 item->m_seriesCount = item->m_seriesCount - 1;
497 519 if (removedSeries->d_func()->m_index < m_index) {
498 520 m_index--;
499 521 item->m_seriesIndex = m_index;
500 522 }
501 523
502 524 item->handleDataStructureChanged();
503 525 }
504 526 }
505 527 }
506 528
507 529 void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series)
508 530 {
509 531 Q_UNUSED(series);
510 532
511 533 Q_Q(QBoxPlotSeries);
512 534
513 535 BoxPlotChartItem *boxPlot = static_cast<BoxPlotChartItem *>(m_item.data());
514 536
515 537 if (m_chart) {
516 538 QList<QAbstractSeries *> serieses = m_chart->series();
517 539
518 540 // Tries to find this series from the Chart's list of serieses and deduce the index
519 541 int index = 0;
520 542 foreach (QAbstractSeries *s, serieses) {
521 543 if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) {
522 544 if (q == static_cast<QBoxPlotSeries *>(s)) {
523 545 boxPlot->m_seriesIndex = index;
524 546 m_index = index;
525 547 }
526 548 index++;
527 549 }
528 550 }
529 551 boxPlot->m_seriesCount = index;
530 552 }
531 553
532 554 boxPlot->handleDataStructureChanged();
533 555 }
534 556
535 557 bool QBoxPlotSeriesPrivate::append(QBoxSet *set)
536 558 {
537 559 if ((m_boxSets.contains(set)) || (set == 0))
538 560 return false; // Fail if set is already in list or set is null.
539 561
540 562 m_boxSets.append(set);
541 563 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
542 564 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
543 565 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
544 566
545 567 emit restructuredBoxes(); // this notifies boxplotchartitem
546 568 return true;
547 569 }
548 570
549 571 bool QBoxPlotSeriesPrivate::remove(QBoxSet *set)
550 572 {
551 573 if (!m_boxSets.contains(set))
552 574 return false; // Fail if set is not in list
553 575
554 576 m_boxSets.removeOne(set);
555 577 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
556 578 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
557 579 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
558 580
559 581 emit restructuredBoxes(); // this notifies boxplotchartitem
560 582 return true;
561 583 }
562 584
563 585 bool QBoxPlotSeriesPrivate::append(QList<QBoxSet * > sets)
564 586 {
565 587 foreach (QBoxSet *set, sets) {
566 588 if ((set == 0) || (m_boxSets.contains(set)))
567 589 return false; // Fail if any of the sets is null or is already appended.
568 590 if (sets.count(set) != 1)
569 591 return false; // Also fail if same set is more than once in given list.
570 592 }
571 593
572 594 foreach (QBoxSet *set, sets) {
573 595 m_boxSets.append(set);
574 596 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
575 597 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
576 598 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
577 599 }
578 600
579 601 emit restructuredBoxes(); // this notifies boxplotchartitem
580 602 return true;
581 603 }
582 604
583 605 bool QBoxPlotSeriesPrivate::remove(QList<QBoxSet * > sets)
584 606 {
585 607 if (sets.count() == 0)
586 608 return false;
587 609
588 610 foreach (QBoxSet *set, sets) {
589 611 if ((set == 0) || (!m_boxSets.contains(set)))
590 612 return false; // Fail if any of the sets is null or is not in series
591 613 if (sets.count(set) != 1)
592 614 return false; // Also fail if same set is more than once in given list.
593 615 }
594 616
595 617 foreach (QBoxSet *set, sets) {
596 618 m_boxSets.removeOne(set);
597 619 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
598 620 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
599 621 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
600 622 }
601 623
602 624 emit restructuredBoxes(); // this notifies boxplotchartitem
603 625
604 626 return true;
605 627 }
606 628
607 629 bool QBoxPlotSeriesPrivate::insert(int index, QBoxSet *set)
608 630 {
609 631 if ((m_boxSets.contains(set)) || (set == 0))
610 632 return false; // Fail if set is already in list or set is null.
611 633
612 634 m_boxSets.insert(index, set);
613 635 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
614 636 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
615 637 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
616 638
617 639 emit restructuredBoxes(); // this notifies boxplotchartitem
618 640 return true;
619 641 }
620 642
621 643 QBoxSet *QBoxPlotSeriesPrivate::boxsetAt(int index)
622 644 {
623 645 return m_boxSets.at(index);
624 646 }
625 647
626 648 qreal QBoxPlotSeriesPrivate::bottom()
627 649 {
628 650 // Returns bottom of all boxes
629 651 qreal bottom(0);
630 652 foreach (QBoxSet *set, m_boxSets) {
631 653 for (int i = 0; i < set->count(); i++) {
632 654 if (set->at(i) < bottom)
633 655 bottom = set->at(i);
634 656 }
635 657 }
636 658
637 659 return bottom;
638 660 }
639 661
640 662 qreal QBoxPlotSeriesPrivate::max()
641 663 {
642 664 if (m_boxSets.count() <= 0)
643 665 return 0;
644 666
645 667 qreal max = INT_MIN;
646 668
647 669 foreach (QBoxSet *set, m_boxSets) {
648 670 for (int i = 0; i < set->count(); i++) {
649 671 if (set->at(i) > max)
650 672 max = set->at(i);
651 673 }
652 674 }
653 675
654 676 return max;
655 677 }
656 678
657 679 #include "moc_qboxplotseries.cpp"
658 680 #include "moc_qboxplotseries_p.cpp"
659 681
660 682 QTCOMMERCIALCHART_END_NAMESPACE
661 683
General Comments 0
You need to be logged in to leave comments. Login now