##// END OF EJS Templates
Fix box-and-whiskers animations...
Miikka Heikkinen -
r2560:a2f72685ff33
parent child
Show More
@@ -1,78 +1,85
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "boxplotanimation_p.h"
21 #include "boxplotanimation_p.h"
22 #include "boxplotchartitem_p.h"
22 #include "boxplotchartitem_p.h"
23 #include "boxwhiskersdata_p.h"
23 #include "boxwhiskersdata_p.h"
24 #include "boxwhiskersanimation_p.h"
24 #include "boxwhiskersanimation_p.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 BoxPlotAnimation::BoxPlotAnimation(BoxPlotChartItem *item)
28 BoxPlotAnimation::BoxPlotAnimation(BoxPlotChartItem *item)
29 : m_item(item)
29 : QObject(item),
30 m_item(item)
30 {
31 {
31 }
32 }
32
33
33 BoxPlotAnimation::~BoxPlotAnimation()
34 BoxPlotAnimation::~BoxPlotAnimation()
34 {
35 {
35 }
36 }
36
37
37 void BoxPlotAnimation::addBox(BoxWhiskers *box)
38 void BoxPlotAnimation::addBox(BoxWhiskers *box)
38 {
39 {
39 BoxWhiskersAnimation *animation = m_animations.value(box);
40 BoxWhiskersAnimation *animation = m_animations.value(box);
40 if (!animation) {
41 if (!animation) {
41 animation = new BoxWhiskersAnimation(box);
42 animation = new BoxWhiskersAnimation(box);
42 m_animations.insert(box, animation);
43 m_animations.insert(box, animation);
43 BoxWhiskersData start;
44 BoxWhiskersData start;
44 start.m_median = box->m_data.m_median;
45 start.m_median = box->m_data.m_median;
45 animation->setup(start, box->m_data);
46 animation->setup(start, box->m_data);
46 } else {
47 } else {
47 animation->stop();
48 animation->stop();
48 animation->setEndData(box->m_data);
49 animation->setEndData(box->m_data);
49 }
50 }
50 }
51 }
51
52
52 ChartAnimation *BoxPlotAnimation::boxAnimation(BoxWhiskers *box)
53 ChartAnimation *BoxPlotAnimation::boxAnimation(BoxWhiskers *box)
53 {
54 {
54 BoxWhiskersAnimation *animation = m_animations.value(box);
55 BoxWhiskersAnimation *animation = m_animations.value(box);
55 if (animation)
56 if (animation)
56 animation->m_moveMedianLine = false;
57 animation->m_moveMedianLine = false;
57
58
58 return animation;
59 return animation;
59 }
60 }
60
61
61 ChartAnimation *BoxPlotAnimation::boxChangeAnimation(BoxWhiskers *box)
62 ChartAnimation *BoxPlotAnimation::boxChangeAnimation(BoxWhiskers *box)
62 {
63 {
63 BoxWhiskersAnimation *animation = m_animations.value(box);
64 BoxWhiskersAnimation *animation = m_animations.value(box);
64 animation->m_moveMedianLine = true;
65 animation->m_moveMedianLine = true;
65 animation->setEndData(box->m_data);
66 animation->setEndData(box->m_data);
66
67
67 return animation;
68 return animation;
68 }
69 }
69
70
70 void BoxPlotAnimation::setAnimationStart(BoxWhiskers *box)
71 void BoxPlotAnimation::setAnimationStart(BoxWhiskers *box)
71 {
72 {
72 BoxWhiskersAnimation *animation = m_animations.value(box);
73 BoxWhiskersAnimation *animation = m_animations.value(box);
73 animation->setStartData(box->m_data);
74 animation->setStartData(box->m_data);
74 }
75 }
75
76
77 void BoxPlotAnimation::stopAll()
78 {
79 foreach (BoxWhiskersAnimation *animation, m_animations.values())
80 animation->stopAndDestroyLater();
81 }
82
76 //#include "moc_boxplotanimation_p.cpp"
83 //#include "moc_boxplotanimation_p.cpp"
77
84
78 QTCOMMERCIALCHART_END_NAMESPACE
85 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,61 +1,63
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef BOXPLOTANIMATION_P_H
30 #ifndef BOXPLOTANIMATION_P_H
31 #define BOXPLOTANIMATION_P_H
31 #define BOXPLOTANIMATION_P_H
32
32
33 #include "chartanimation_p.h"
33 #include "chartanimation_p.h"
34 #include "boxwhiskers_p.h"
34 #include "boxwhiskers_p.h"
35 #include "boxwhiskersdata_p.h"
35 #include "boxwhiskersdata_p.h"
36 #include "boxwhiskersanimation_p.h"
36 #include "boxwhiskersanimation_p.h"
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class BoxPlotChartItem;
40 class BoxPlotChartItem;
41
41
42 class BoxPlotAnimation
42 class BoxPlotAnimation : public QObject
43 {
43 {
44 Q_OBJECT
44 public:
45 public:
45 BoxPlotAnimation(BoxPlotChartItem *item);
46 BoxPlotAnimation(BoxPlotChartItem *item);
46 ~BoxPlotAnimation();
47 ~BoxPlotAnimation();
47
48
48 void addBox(BoxWhiskers *box);
49 void addBox(BoxWhiskers *box);
49 ChartAnimation *boxAnimation(BoxWhiskers *box);
50 ChartAnimation *boxAnimation(BoxWhiskers *box);
50 ChartAnimation *boxChangeAnimation(BoxWhiskers *box);
51 ChartAnimation *boxChangeAnimation(BoxWhiskers *box);
51
52
52 void setAnimationStart(BoxWhiskers *box);
53 void setAnimationStart(BoxWhiskers *box);
54 void stopAll();
53
55
54 protected:
56 protected:
55 BoxPlotChartItem *m_item;
57 BoxPlotChartItem *m_item;
56 QHash<BoxWhiskers *, BoxWhiskersAnimation *> m_animations;
58 QHash<BoxWhiskers *, BoxWhiskersAnimation *> m_animations;
57 };
59 };
58
60
59 QTCOMMERCIALCHART_END_NAMESPACE
61 QTCOMMERCIALCHART_END_NAMESPACE
60
62
61 #endif // BOXPLOTANIMATION_P_H
63 #endif // BOXPLOTANIMATION_P_H
@@ -1,69 +1,67
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef BOXWHISKERSANIMATION_P_H
30 #ifndef BOXWHISKERSANIMATION_P_H
31 #define BOXWHISKERSANIMATION_P_H
31 #define BOXWHISKERSANIMATION_P_H
32
32
33 #include "chartanimation_p.h"
33 #include "chartanimation_p.h"
34 #include "boxwhiskers_p.h"
34 #include "boxwhiskers_p.h"
35 #include "boxwhiskersdata_p.h"
35 #include "boxwhiskersdata_p.h"
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 class BoxPlotChartItem;
39 class BoxPlotChartItem;
40
40
41 class BoxWhiskersAnimation : public ChartAnimation
41 class BoxWhiskersAnimation : public ChartAnimation
42 {
42 {
43 Q_OBJECT
43 Q_OBJECT
44
44
45 public:
45 public:
46 BoxWhiskersAnimation(BoxWhiskers *box);
46 BoxWhiskersAnimation(BoxWhiskers *box);
47 ~BoxWhiskersAnimation();
47 ~BoxWhiskersAnimation();
48
48
49 public: // from QVariantAnimation
49 public: // from QVariantAnimation
50 virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const;
50 virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const;
51 virtual void updateCurrentValue(const QVariant &value);
51 virtual void updateCurrentValue(const QVariant &value);
52
52
53 void setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData);
53 void setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData);
54 void setEndData(const BoxWhiskersData &endData);
54 void setEndData(const BoxWhiskersData &endData);
55 void setStartData(const BoxWhiskersData &endData);
55 void setStartData(const BoxWhiskersData &endData);
56
56
57 void moveMedianLine(bool move);
57 void moveMedianLine(bool move);
58
58
59 protected:
59 protected:
60 friend class BoxPlotAnimation;
60 friend class BoxPlotAnimation;
61 BoxPlotChartItem *m_item;
62 BoxWhiskers *m_box;
61 BoxWhiskers *m_box;
63 BoxWhiskersData *m_boxData;
64 bool m_moveMedianLine;
62 bool m_moveMedianLine;
65 };
63 };
66
64
67 QTCOMMERCIALCHART_END_NAMESPACE
65 QTCOMMERCIALCHART_END_NAMESPACE
68
66
69 #endif // BOXWHISKERSANIMATION_P_H
67 #endif // BOXWHISKERSANIMATION_P_H
@@ -1,203 +1,202
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "boxplotchartitem_p.h"
21 #include "boxplotchartitem_p.h"
22 #include "qboxplotseries_p.h"
22 #include "qboxplotseries_p.h"
23 #include "bar_p.h"
23 #include "bar_p.h"
24 #include "qboxset_p.h"
24 #include "qboxset_p.h"
25 #include "qabstractbarseries_p.h"
25 #include "qabstractbarseries_p.h"
26 #include "qboxset.h"
26 #include "qboxset.h"
27 #include "boxwhiskers_p.h"
27 #include "boxwhiskers_p.h"
28 #include <QPainter>
28 #include <QPainter>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 BoxPlotChartItem::BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem *item) :
32 BoxPlotChartItem::BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem *item) :
33 ChartItem(series->d_func(), item),
33 ChartItem(series->d_func(), item),
34 m_series(series),
34 m_series(series),
35 m_animation(0),
35 m_animation(0)
36 m_animate(0)
37 {
36 {
38 connect(series, SIGNAL(boxsetsRemoved(QList<QBoxSet *>)), this, SLOT(handleBoxsetRemove(QList<QBoxSet *>)));
37 connect(series, SIGNAL(boxsetsRemoved(QList<QBoxSet *>)), this, SLOT(handleBoxsetRemove(QList<QBoxSet *>)));
39 connect(series->d_func(), SIGNAL(restructuredBoxes()), this, SLOT(handleDataStructureChanged()));
38 connect(series->d_func(), SIGNAL(restructuredBoxes()), this, SLOT(handleDataStructureChanged()));
40 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
39 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
41 connect(series->d_func(), SIGNAL(updatedBoxes()), this, SLOT(handleUpdatedBars()));
40 connect(series->d_func(), SIGNAL(updatedBoxes()), this, SLOT(handleUpdatedBars()));
42 connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars()));
41 connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars()));
43 // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here
42 // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here
44 setZValue(ChartPresenter::BoxPlotSeriesZValue);
43 setZValue(ChartPresenter::BoxPlotSeriesZValue);
45 }
44 }
46
45
47 BoxPlotChartItem::~BoxPlotChartItem()
46 BoxPlotChartItem::~BoxPlotChartItem()
48 {
47 {
49 }
48 }
50
49
51 void BoxPlotChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
50 void BoxPlotChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
52 {
51 {
53 Q_UNUSED(painter);
52 Q_UNUSED(painter);
54 Q_UNUSED(option);
53 Q_UNUSED(option);
55 Q_UNUSED(widget);
54 Q_UNUSED(widget);
56 }
55 }
57
56
58 void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation)
57 void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation)
59 {
58 {
60 m_animation = animation;
59 m_animation = animation;
61 if (m_animation) {
60 if (m_animation) {
62 foreach (BoxWhiskers *item, m_boxTable.values())
61 foreach (BoxWhiskers *item, m_boxTable.values())
63 m_animation->addBox(item);
62 m_animation->addBox(item);
64 handleDomainUpdated();
63 handleDomainUpdated();
65 }
64 }
66 }
65 }
67
66
68 void BoxPlotChartItem::handleDataStructureChanged()
67 void BoxPlotChartItem::handleDataStructureChanged()
69 {
68 {
70 int setCount = m_series->count();
69 int setCount = m_series->count();
71
70
72 for (int s = 0; s < setCount; s++) {
71 for (int s = 0; s < setCount; s++) {
73 QBoxSet *set = m_series->d_func()->boxSetAt(s);
72 QBoxSet *set = m_series->d_func()->boxSetAt(s);
74
73
75 BoxWhiskers *box = m_boxTable.value(set);
74 BoxWhiskers *box = m_boxTable.value(set);
76 if (!box) {
75 if (!box) {
77 // Item is not yet created, make a box and add it to hash table
76 // Item is not yet created, make a box and add it to hash table
78 box = new BoxWhiskers(set, domain(), this);
77 box = new BoxWhiskers(set, domain(), this);
79 m_boxTable.insert(set, box);
78 m_boxTable.insert(set, box);
80 connect(box, SIGNAL(clicked(QBoxSet *)), m_series, SIGNAL(clicked(QBoxSet *)));
79 connect(box, SIGNAL(clicked(QBoxSet *)), m_series, SIGNAL(clicked(QBoxSet *)));
81 connect(box, SIGNAL(hovered(bool, QBoxSet *)), m_series, SIGNAL(hovered(bool, QBoxSet *)));
80 connect(box, SIGNAL(hovered(bool, QBoxSet *)), m_series, SIGNAL(hovered(bool, QBoxSet *)));
82 connect(box, SIGNAL(clicked(QBoxSet *)), set, SIGNAL(clicked()));
81 connect(box, SIGNAL(clicked(QBoxSet *)), set, SIGNAL(clicked()));
83 connect(box, SIGNAL(hovered(bool, QBoxSet *)), set, SIGNAL(hovered(bool)));
82 connect(box, SIGNAL(hovered(bool, QBoxSet *)), set, SIGNAL(hovered(bool)));
84
83
85 // Set the decorative issues for the newly created box
84 // Set the decorative issues for the newly created box
86 box->setBrush(m_series->brush());
85 box->setBrush(m_series->brush());
87 box->setPen(m_series->pen());
86 box->setPen(m_series->pen());
88 }
87 }
89 updateBoxGeometry(box, s);
88 updateBoxGeometry(box, s);
90
89
91 box->updateGeometry(domain());
90 box->updateGeometry(domain());
92
91
93 if (m_animation)
92 if (m_animation)
94 m_animation->addBox(box);
93 m_animation->addBox(box);
95 }
94 }
96
95
97 handleDomainUpdated();
96 handleDomainUpdated();
98 }
97 }
99
98
100 void BoxPlotChartItem::handleUpdatedBars()
99 void BoxPlotChartItem::handleUpdatedBars()
101 {
100 {
102 foreach (BoxWhiskers *item, m_boxTable.values()) {
101 foreach (BoxWhiskers *item, m_boxTable.values()) {
103 item->setBrush(m_series->brush());
102 item->setBrush(m_series->brush());
104 item->setPen(m_series->pen());
103 item->setPen(m_series->pen());
105 }
104 }
106 // Override with QBoxSet specific settings
105 // Override with QBoxSet specific settings
107 foreach (QBoxSet *set, m_boxTable.keys()) {
106 foreach (QBoxSet *set, m_boxTable.keys()) {
108 if (set->brush().style() != Qt::NoBrush)
107 if (set->brush().style() != Qt::NoBrush)
109 m_boxTable.value(set)->setBrush(set->brush());
108 m_boxTable.value(set)->setBrush(set->brush());
110 if (set->pen().style() != Qt::NoPen)
109 if (set->pen().style() != Qt::NoPen)
111 m_boxTable.value(set)->setPen(set->pen());
110 m_boxTable.value(set)->setPen(set->pen());
112 }
111 }
113 }
112 }
114
113
115 void BoxPlotChartItem::handleBoxsetRemove(QList<QBoxSet*> barSets)
114 void BoxPlotChartItem::handleBoxsetRemove(QList<QBoxSet*> barSets)
116 {
115 {
117 foreach (QBoxSet *set, barSets) {
116 foreach (QBoxSet *set, barSets) {
118 BoxWhiskers *boxItem = m_boxTable.value(set);
117 BoxWhiskers *boxItem = m_boxTable.value(set);
119 m_boxTable.remove(set);
118 m_boxTable.remove(set);
120 delete boxItem;
119 delete boxItem;
121 }
120 }
122 }
121 }
123
122
124 void BoxPlotChartItem::handleDomainUpdated()
123 void BoxPlotChartItem::handleDomainUpdated()
125 {
124 {
126 if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0))
125 if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0))
127 return;
126 return;
128
127
129 // Set my bounding rect to same as domain size. Add one pixel at the top (-1.0) and the bottom as 0.0 would
128 // Set my bounding rect to same as domain size. Add one pixel at the top (-1.0) and the bottom as 0.0 would
130 // snip a bit off from the whisker at the grid line
129 // snip a bit off from the whisker at the grid line
131 m_boundingRect.setRect(0.0, -1.0, domain()->size().width(), domain()->size().height() + 1.0);
130 m_boundingRect.setRect(0.0, -1.0, domain()->size().width(), domain()->size().height() + 1.0);
132
131
133 foreach (BoxWhiskers *item, m_boxTable.values()) {
132 foreach (BoxWhiskers *item, m_boxTable.values()) {
134 item->updateGeometry(domain());
133 item->updateGeometry(domain());
135
134
136 // If the animation is set, start the animation for each BoxWhisker item
135 // If the animation is set, start the animation for each BoxWhisker item
137 if (m_animation)
136 if (m_animation)
138 presenter()->startAnimation(m_animation->boxAnimation(item));
137 presenter()->startAnimation(m_animation->boxAnimation(item));
139 }
138 }
140 }
139 }
141
140
142 void BoxPlotChartItem::handleLayoutChanged()
141 void BoxPlotChartItem::handleLayoutChanged()
143 {
142 {
144 foreach (BoxWhiskers *item, m_boxTable.values()) {
143 foreach (BoxWhiskers *item, m_boxTable.values()) {
145 if (m_animation)
144 if (m_animation)
146 m_animation->setAnimationStart(item);
145 m_animation->setAnimationStart(item);
147
146
148 bool dirty = updateBoxGeometry(item, item->m_data.m_index);
147 bool dirty = updateBoxGeometry(item, item->m_data.m_index);
149 if (dirty && m_animation)
148 if (dirty && m_animation)
150 presenter()->startAnimation(m_animation->boxChangeAnimation(item));
149 presenter()->startAnimation(m_animation->boxChangeAnimation(item));
151 else
150 else
152 item->updateGeometry(domain());
151 item->updateGeometry(domain());
153 }
152 }
154 }
153 }
155
154
156 QRectF BoxPlotChartItem::boundingRect() const
155 QRectF BoxPlotChartItem::boundingRect() const
157 {
156 {
158 return m_boundingRect;
157 return m_boundingRect;
159 }
158 }
160
159
161 void BoxPlotChartItem::initializeLayout()
160 void BoxPlotChartItem::initializeLayout()
162 {
161 {
163 }
162 }
164
163
165 QVector<QRectF> BoxPlotChartItem::calculateLayout()
164 QVector<QRectF> BoxPlotChartItem::calculateLayout()
166 {
165 {
167 return QVector<QRectF>();
166 return QVector<QRectF>();
168 }
167 }
169
168
170 bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index)
169 bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index)
171 {
170 {
172 bool changed = false;
171 bool changed = false;
173
172
174 QBoxSet *set = m_series->d_func()->boxSetAt(index);
173 QBoxSet *set = m_series->d_func()->boxSetAt(index);
175 BoxWhiskersData &data = box->m_data;
174 BoxWhiskersData &data = box->m_data;
176
175
177 if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) ||
176 if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) ||
178 (data.m_median != set->at(2)) || (data.m_upperQuartile != set->at(3)) || (data.m_upperExtreme != set->at(4))) {
177 (data.m_median != set->at(2)) || (data.m_upperQuartile != set->at(3)) || (data.m_upperExtreme != set->at(4))) {
179 changed = true;
178 changed = true;
180 }
179 }
181
180
182 data.m_lowerExtreme = set->at(0);
181 data.m_lowerExtreme = set->at(0);
183 data.m_lowerQuartile = set->at(1);
182 data.m_lowerQuartile = set->at(1);
184 data.m_median = set->at(2);
183 data.m_median = set->at(2);
185 data.m_upperQuartile = set->at(3);
184 data.m_upperQuartile = set->at(3);
186 data.m_upperExtreme = set->at(4);
185 data.m_upperExtreme = set->at(4);
187 data.m_index = index;
186 data.m_index = index;
188 data.m_boxItems = m_series->count();
187 data.m_boxItems = m_series->count();
189
188
190 data.m_maxX = domain()->maxX();
189 data.m_maxX = domain()->maxX();
191 data.m_minX = domain()->minX();
190 data.m_minX = domain()->minX();
192 data.m_maxY = domain()->maxY();
191 data.m_maxY = domain()->maxY();
193 data.m_minY = domain()->minY();
192 data.m_minY = domain()->minY();
194
193
195 data.m_seriesIndex = m_seriesIndex;
194 data.m_seriesIndex = m_seriesIndex;
196 data.m_seriesCount = m_seriesCount;
195 data.m_seriesCount = m_seriesCount;
197
196
198 return changed;
197 return changed;
199 }
198 }
200
199
201 #include "moc_boxplotchartitem_p.cpp"
200 #include "moc_boxplotchartitem_p.cpp"
202
201
203 QTCOMMERCIALCHART_END_NAMESPACE
202 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,85 +1,84
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30
30
31 #ifndef BOXPLOTCHARTITEM_H
31 #ifndef BOXPLOTCHARTITEM_H
32 #define BOXPLOTCHARTITEM_H
32 #define BOXPLOTCHARTITEM_H
33
33
34 #include "boxwhiskers_p.h"
34 #include "boxwhiskers_p.h"
35 #include "qboxplotseries.h"
35 #include "qboxplotseries.h"
36 #include "chartitem_p.h"
36 #include "chartitem_p.h"
37 #include "boxplotanimation_p.h"
37 #include "boxplotanimation_p.h"
38 #include "qboxset.h"
38 #include "qboxset.h"
39 #include <QGraphicsItem>
39 #include <QGraphicsItem>
40
40
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
42
42
43 class BoxPlotSeriesPrivate;
43 class BoxPlotSeriesPrivate;
44
44
45 class BoxPlotChartItem : public ChartItem
45 class BoxPlotChartItem : public ChartItem
46 {
46 {
47 Q_OBJECT
47 Q_OBJECT
48 public:
48 public:
49 BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem *item = 0);
49 BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem *item = 0);
50 ~BoxPlotChartItem();
50 ~BoxPlotChartItem();
51
51
52 void setAnimation(BoxPlotAnimation *animation);
52 void setAnimation(BoxPlotAnimation *animation);
53
53
54 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
54 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
55 QRectF boundingRect() const;
55 QRectF boundingRect() const;
56
56
57 public Q_SLOTS:
57 public Q_SLOTS:
58 void handleDataStructureChanged();
58 void handleDataStructureChanged();
59 void handleDomainUpdated();
59 void handleDomainUpdated();
60 void handleLayoutChanged();
60 void handleLayoutChanged();
61 void handleUpdatedBars();
61 void handleUpdatedBars();
62 void handleBoxsetRemove(QList<QBoxSet *> barSets);
62 void handleBoxsetRemove(QList<QBoxSet *> barSets);
63
63
64 private:
64 private:
65 virtual QVector<QRectF> calculateLayout();
65 virtual QVector<QRectF> calculateLayout();
66 void initializeLayout();
66 void initializeLayout();
67 bool updateBoxGeometry(BoxWhiskers *box, int index);
67 bool updateBoxGeometry(BoxWhiskers *box, int index);
68
68
69 protected:
69 protected:
70 friend class QBoxPlotSeriesPrivate;
70 friend class QBoxPlotSeriesPrivate;
71 QBoxPlotSeries *m_series; // Not owned.
71 QBoxPlotSeries *m_series; // Not owned.
72 QList<BoxWhiskers *> m_boxes;
72 QList<BoxWhiskers *> m_boxes;
73 QHash<QBoxSet *, BoxWhiskers *> m_boxTable;
73 QHash<QBoxSet *, BoxWhiskers *> m_boxTable;
74 int m_seriesIndex;
74 int m_seriesIndex;
75 int m_seriesCount;
75 int m_seriesCount;
76
76
77 BoxPlotAnimation *m_animation;
77 BoxPlotAnimation *m_animation;
78 bool m_animate;
79
78
80 QRectF m_boundingRect;
79 QRectF m_boundingRect;
81 };
80 };
82
81
83 QTCOMMERCIALCHART_END_NAMESPACE
82 QTCOMMERCIALCHART_END_NAMESPACE
84
83
85 #endif // BOXPLOTCHARTITEM_H
84 #endif // BOXPLOTCHARTITEM_H
@@ -1,683 +1,689
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qboxplotseries.h"
21 #include "qboxplotseries.h"
22 #include "qboxplotseries_p.h"
22 #include "qboxplotseries_p.h"
23 #include "qboxplotlegendmarker.h"
23 #include "qboxplotlegendmarker.h"
24 #include "qbarcategoryaxis.h"
24 #include "qbarcategoryaxis.h"
25 #include "boxplotchartitem_p.h"
25 #include "boxplotchartitem_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "charttheme_p.h"
27 #include "charttheme_p.h"
28 #include "qvalueaxis.h"
28 #include "qvalueaxis.h"
29 #include "charttheme_p.h"
29 #include "charttheme_p.h"
30 #include "boxplotanimation_p.h"
30 #include "boxplotanimation_p.h"
31 #include "qchart_p.h"
31 #include "qchart_p.h"
32 #include "qboxset.h"
32 #include "qboxset.h"
33 #include "qboxset_p.h"
33 #include "qboxset_p.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 /*!
37 /*!
38 \class QBoxPlotSeries
38 \class QBoxPlotSeries
39 \brief Series for creating box-and-whiskers chart
39 \brief Series for creating box-and-whiskers chart
40 \mainclass
40 \mainclass
41
41
42 QBoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this class is to act as
42 QBoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this class is to act as
43 a container for single box-and-whisker items. Each item is drawn to own slot. If chart includes multiple instances of
43 a container for single box-and-whisker items. Each item is drawn to own slot. If chart includes multiple instances of
44 QBoxPlotSeries then box-and-whiskers items with the same index are drawn to same slot.
44 QBoxPlotSeries then box-and-whiskers items with the same index are drawn to same slot.
45
45
46 See the \l {Box and Whiskers Example} {box-and-whiskers chart example} to learn how to create a box-and-whiskers chart.
46 See the \l {Box and Whiskers Example} {box-and-whiskers chart example} to learn how to create a box-and-whiskers chart.
47 \image examples_boxplotchart.png
47 \image examples_boxplotchart.png
48
48
49 \sa QBoxSet
49 \sa QBoxSet
50 */
50 */
51
51
52 /*!
52 /*!
53 \qmlclass BoxPlotSeries QBoxPlotSeries
53 \qmlclass BoxPlotSeries QBoxPlotSeries
54 \inherits QAbstractSeries
54 \inherits QAbstractSeries
55
55
56 BoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this class is to act as
56 BoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this class is to act as
57 a container for single box-and-whisker items. Each item is drawn to own slot. If chart includes multiple instances of
57 a container for single box-and-whisker items. Each item is drawn to own slot. If chart includes multiple instances of
58 BoxPlotSeries then box-and-whiskers items with the same index are drawn to same slot.
58 BoxPlotSeries then box-and-whiskers items with the same index are drawn to same slot.
59
59
60 The following QML shows how to create a simple box-and-whiskers chart:
60 The following QML shows how to create a simple box-and-whiskers chart:
61 \code
61 \code
62 import QtQuick 1.0
62 import QtQuick 1.0
63 import QtCommercial.Chart 1.1
63 import QtCommercial.Chart 1.1
64
64
65 ChartView {
65 ChartView {
66 title: "Box Plot series"
66 title: "Box Plot series"
67 width: 400
67 width: 400
68 height: 300
68 height: 300
69 theme: ChartView.ChartThemeBrownSand
69 theme: ChartView.ChartThemeBrownSand
70 legend.alignment: Qt.AlignBottom
70 legend.alignment: Qt.AlignBottom
71
71
72 BoxPlotSeries {
72 BoxPlotSeries {
73 id: plotSeries
73 id: plotSeries
74 name: "Income"
74 name: "Income"
75 BoxSet { label: "Jan"; values: [3, 4, 5.1, 6.2, 8.5] }
75 BoxSet { label: "Jan"; values: [3, 4, 5.1, 6.2, 8.5] }
76 BoxSet { label: "Feb"; values: [5, 6, 7.5, 8.6, 11.8] }
76 BoxSet { label: "Feb"; values: [5, 6, 7.5, 8.6, 11.8] }
77 BoxSet { label: "Mar"; values: [3.2, 5, 5.7, 8, 9.2] }
77 BoxSet { label: "Mar"; values: [3.2, 5, 5.7, 8, 9.2] }
78 BoxSet { label: "Apr"; values: [3.8, 5, 6.4, 7, 8] }
78 BoxSet { label: "Apr"; values: [3.8, 5, 6.4, 7, 8] }
79 BoxSet { label: "May"; values: [4, 5, 5.2, 6, 7] }
79 BoxSet { label: "May"; values: [4, 5, 5.2, 6, 7] }
80 }
80 }
81 }
81 }
82 \endcode
82 \endcode
83
83
84 \beginfloatleft
84 \beginfloatleft
85 \image examples_qmlboxplot.png
85 \image examples_qmlboxplot.png
86 \endfloat
86 \endfloat
87 \clearfloat
87 \clearfloat
88 */
88 */
89
89
90 /*!
90 /*!
91 \fn QBoxPlotSeries::boxsetsAdded(QList<QBoxSet *> sets)
91 \fn QBoxPlotSeries::boxsetsAdded(QList<QBoxSet *> sets)
92 \brief Signal is emitted when a new \a sets of box-and-whiskers data is added to the series.
92 \brief Signal is emitted when a new \a sets of box-and-whiskers data is added to the series.
93 */
93 */
94
94
95 /*!
95 /*!
96 \fn QBoxPlotSeries::boxsetsRemoved(QList<QBoxSet *> sets)
96 \fn QBoxPlotSeries::boxsetsRemoved(QList<QBoxSet *> sets)
97 \brief Signal is emitted when \a sets of box-and-whiskers data is removed from the series.
97 \brief Signal is emitted when \a sets of box-and-whiskers data is removed from the series.
98 */
98 */
99
99
100 /*!
100 /*!
101 \fn QBoxPlotSeries::clicked(QBoxSet *boxset)
101 \fn QBoxPlotSeries::clicked(QBoxSet *boxset)
102 \brief Signal is emitted when the user clicks the \a boxset on the chart.
102 \brief Signal is emitted when the user clicks the \a boxset on the chart.
103 */
103 */
104
104
105 /*!
105 /*!
106 \fn QBoxPlotSeries::hovered(bool status, QBoxSet *boxset)
106 \fn QBoxPlotSeries::hovered(bool status, QBoxSet *boxset)
107 \brief Signal is emitted when there is change in hover \a status over \a boxset.
107 \brief Signal is emitted when there is change in hover \a status over \a boxset.
108 */
108 */
109
109
110 /*!
110 /*!
111 \fn QBoxPlotSeries::countChanged()
111 \fn QBoxPlotSeries::countChanged()
112 \brief Signal is emitted when there is change in count of box-and-whiskers items in the series.
112 \brief Signal is emitted when there is change in count of box-and-whiskers items in the series.
113 */
113 */
114 /*!
114 /*!
115 \fn virtual SeriesType QBoxPlotSeries::type() const
115 \fn virtual SeriesType QBoxPlotSeries::type() const
116 \brief Returns type of series.
116 \brief Returns type of series.
117 \sa QAbstractSeries, SeriesType
117 \sa QAbstractSeries, SeriesType
118 */
118 */
119 /*!
119 /*!
120 \qmlmethod BoxPlotSeries::append(const QString label, QVariantList values)
120 \qmlmethod BoxPlotSeries::append(const QString label, QVariantList values)
121 Appends a new box-and-whiskers set with \a label and \a values to the series.
121 Appends a new box-and-whiskers set with \a label and \a values to the series.
122 */
122 */
123 /*!
123 /*!
124 \qmlmethod BoxPlotSeries::append(BoxSet *box)
124 \qmlmethod BoxPlotSeries::append(BoxSet *box)
125 Appends the \a box to the series.
125 Appends the \a box to the series.
126 */
126 */
127 /*!
127 /*!
128 \qmlmethod BoxPlotSeries::insert(int index, const QString label, QVariantList values)
128 \qmlmethod BoxPlotSeries::insert(int index, const QString label, QVariantList values)
129 Inserts a new box-and-whiskers set with \a label and \a values at the \a index position.
129 Inserts a new box-and-whiskers set with \a label and \a values at the \a index position.
130 */
130 */
131 /*!
131 /*!
132 \qmlmethod BoxPlotSeries::remove(QBoxSet *boxset)
132 \qmlmethod BoxPlotSeries::remove(QBoxSet *boxset)
133 Removes the \a boxset from the series.
133 Removes the \a boxset from the series.
134 */
134 */
135 /*!
135 /*!
136 \qmlmethod BoxPlotSeries::clear()
136 \qmlmethod BoxPlotSeries::clear()
137 Removes all boxsets from the series. Deletes removed sets.
137 Removes all boxsets from the series. Deletes removed sets.
138 */
138 */
139
139
140 /*!
140 /*!
141 \qmlsignal BoxPlotSeries::onClicked(BoxSet boxset);
141 \qmlsignal BoxPlotSeries::onClicked(BoxSet boxset);
142 Signal is emitted when the user clicks the \a boxset on the chart.
142 Signal is emitted when the user clicks the \a boxset on the chart.
143 */
143 */
144 /*!
144 /*!
145 \qmlsignal BoxPlotSeries::onHovered(bool status, BoxSet boxset);
145 \qmlsignal BoxPlotSeries::onHovered(bool status, BoxSet boxset);
146 Signal is emitted when there is change in hover \a status over \a boxset.
146 Signal is emitted when there is change in hover \a status over \a boxset.
147 */
147 */
148 /*!
148 /*!
149 \qmlsignal BoxPlotSeries::onCountChanged();
149 \qmlsignal BoxPlotSeries::onCountChanged();
150 Signal is emitted when there is change in count of box-and-whiskers items in the series.
150 Signal is emitted when there is change in count of box-and-whiskers items in the series.
151 */
151 */
152 /*!
152 /*!
153 \qmlsignal BoxPlotSeries::onBoxsetsAdded()
153 \qmlsignal BoxPlotSeries::onBoxsetsAdded()
154 Signal is emitted when new box-and-whiskers sets are added to the series.
154 Signal is emitted when new box-and-whiskers sets are added to the series.
155 */
155 */
156 /*!
156 /*!
157 \qmlsignal BoxPlotSeries::boxsetsRemoved()
157 \qmlsignal BoxPlotSeries::boxsetsRemoved()
158 Signal is emitted when new box-and-whiskers sets are removed from the series.
158 Signal is emitted when new box-and-whiskers sets are removed from the series.
159 */
159 */
160
160
161 /*!
161 /*!
162 Constructs empty QBoxPlotSeries.
162 Constructs empty QBoxPlotSeries.
163 QBoxPlotSeries is QObject which is a child of a \a parent.
163 QBoxPlotSeries is QObject which is a child of a \a parent.
164 */
164 */
165 QBoxPlotSeries::QBoxPlotSeries(QObject *parent)
165 QBoxPlotSeries::QBoxPlotSeries(QObject *parent)
166 : QAbstractSeries(*new QBoxPlotSeriesPrivate(this), parent)
166 : QAbstractSeries(*new QBoxPlotSeriesPrivate(this), parent)
167 {
167 {
168 }
168 }
169
169
170 /*!
170 /*!
171 Destructor. Removes series from chart.
171 Destructor. Removes series from chart.
172 */
172 */
173 QBoxPlotSeries::~QBoxPlotSeries()
173 QBoxPlotSeries::~QBoxPlotSeries()
174 {
174 {
175 Q_D(QBoxPlotSeries);
175 Q_D(QBoxPlotSeries);
176 if (d->m_chart)
176 if (d->m_chart)
177 d->m_chart->removeSeries(this);
177 d->m_chart->removeSeries(this);
178 }
178 }
179
179
180 /*!
180 /*!
181 Adds a single box and whiskers set to series. Takes ownership of the \a set. If the set is null or is already in series, it won't be appended.
181 Adds a single box and whiskers set to series. Takes ownership of the \a set. If the set is null or is already in series, it won't be appended.
182 Returns true, if appending succeeded.
182 Returns true, if appending succeeded.
183 */
183 */
184 bool QBoxPlotSeries::append(QBoxSet *set)
184 bool QBoxPlotSeries::append(QBoxSet *set)
185 {
185 {
186 Q_D(QBoxPlotSeries);
186 Q_D(QBoxPlotSeries);
187
187
188 bool success = d->append(set);
188 bool success = d->append(set);
189 if (success) {
189 if (success) {
190 QList<QBoxSet *> sets;
190 QList<QBoxSet *> sets;
191 sets.append(set);
191 sets.append(set);
192 set->setParent(this);
192 set->setParent(this);
193 emit boxsetsAdded(sets);
193 emit boxsetsAdded(sets);
194 emit countChanged();
194 emit countChanged();
195 }
195 }
196 return success;
196 return success;
197 }
197 }
198
198
199 /*!
199 /*!
200 Removes boxset from the series. Deletes the \a set and returns true if successful.
200 Removes boxset from the series. Deletes the \a set and returns true if successful.
201 */
201 */
202 bool QBoxPlotSeries::remove(QBoxSet *set)
202 bool QBoxPlotSeries::remove(QBoxSet *set)
203 {
203 {
204 Q_D(QBoxPlotSeries);
204 Q_D(QBoxPlotSeries);
205 bool success = d->remove(set);
205 bool success = d->remove(set);
206 if (success) {
206 if (success) {
207 QList<QBoxSet *> sets;
207 QList<QBoxSet *> sets;
208 sets.append(set);
208 sets.append(set);
209 set->setParent(0);
209 set->setParent(0);
210 emit boxsetsRemoved(sets);
210 emit boxsetsRemoved(sets);
211 emit countChanged();
211 emit countChanged();
212 delete set;
212 delete set;
213 set = 0;
213 set = 0;
214 }
214 }
215 return success;
215 return success;
216 }
216 }
217
217
218 /*!
218 /*!
219 Takes a single \a set from the series. Does not delete the boxset object.
219 Takes a single \a set from the series. Does not delete the boxset object.
220
220
221 NOTE: The series remains as the boxset's parent object. You must set the
221 NOTE: The series remains as the boxset's parent object. You must set the
222 parent object to take full ownership.
222 parent object to take full ownership.
223
223
224 Returns true if take was successful.
224 Returns true if take was successful.
225 */
225 */
226 bool QBoxPlotSeries::take(QBoxSet *set)
226 bool QBoxPlotSeries::take(QBoxSet *set)
227 {
227 {
228 Q_D(QBoxPlotSeries);
228 Q_D(QBoxPlotSeries);
229
229
230 bool success = d->remove(set);
230 bool success = d->remove(set);
231 if (success) {
231 if (success) {
232 QList<QBoxSet *> sets;
232 QList<QBoxSet *> sets;
233 sets.append(set);
233 sets.append(set);
234 emit boxsetsRemoved(sets);
234 emit boxsetsRemoved(sets);
235 emit countChanged();
235 emit countChanged();
236 }
236 }
237 return success;
237 return success;
238 }
238 }
239
239
240 /*!
240 /*!
241 Adds a list of boxsets to series. Takes ownership of the \a sets.
241 Adds a list of boxsets to series. Takes ownership of the \a sets.
242 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
242 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
243 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
243 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
244 and function returns false.
244 and function returns false.
245 */
245 */
246 bool QBoxPlotSeries::append(QList<QBoxSet *> sets)
246 bool QBoxPlotSeries::append(QList<QBoxSet *> sets)
247 {
247 {
248 Q_D(QBoxPlotSeries);
248 Q_D(QBoxPlotSeries);
249 bool success = d->append(sets);
249 bool success = d->append(sets);
250 if (success) {
250 if (success) {
251 emit boxsetsAdded(sets);
251 emit boxsetsAdded(sets);
252 emit countChanged();
252 emit countChanged();
253 }
253 }
254 return success;
254 return success;
255 }
255 }
256
256
257 /*!
257 /*!
258 Insert a box-and-whiskers set to the series at \a index postion. Takes ownership of the \a set. If the set is null or
258 Insert a box-and-whiskers set to the series at \a index postion. Takes ownership of the \a set. If the set is null or
259 is already in series, it won't be appended. Returns true, if inserting succeeded.
259 is already in series, it won't be appended. Returns true, if inserting succeeded.
260
260
261 */
261 */
262 bool QBoxPlotSeries::insert(int index, QBoxSet *set)
262 bool QBoxPlotSeries::insert(int index, QBoxSet *set)
263 {
263 {
264 Q_D(QBoxPlotSeries);
264 Q_D(QBoxPlotSeries);
265 bool success = d->insert(index, set);
265 bool success = d->insert(index, set);
266 if (success) {
266 if (success) {
267 QList<QBoxSet *> sets;
267 QList<QBoxSet *> sets;
268 sets.append(set);
268 sets.append(set);
269 emit boxsetsAdded(sets);
269 emit boxsetsAdded(sets);
270 emit countChanged();
270 emit countChanged();
271 }
271 }
272 return success;
272 return success;
273 }
273 }
274
274
275 /*!
275 /*!
276 Removes all boxsets from the series. Deletes removed sets.
276 Removes all boxsets from the series. Deletes removed sets.
277 */
277 */
278 void QBoxPlotSeries::clear()
278 void QBoxPlotSeries::clear()
279 {
279 {
280 Q_D(QBoxPlotSeries);
280 Q_D(QBoxPlotSeries);
281 QList<QBoxSet *> sets = boxSets();
281 QList<QBoxSet *> sets = boxSets();
282 bool success = d->remove(sets);
282 bool success = d->remove(sets);
283 if (success) {
283 if (success) {
284 emit boxsetsRemoved(sets);
284 emit boxsetsRemoved(sets);
285 emit countChanged();
285 emit countChanged();
286 foreach (QBoxSet *set, sets)
286 foreach (QBoxSet *set, sets)
287 delete set;
287 delete set;
288 }
288 }
289 }
289 }
290
290
291 /*!
291 /*!
292 Returns number of sets in series.
292 Returns number of sets in series.
293 */
293 */
294 int QBoxPlotSeries::count() const
294 int QBoxPlotSeries::count() const
295 {
295 {
296 Q_D(const QBoxPlotSeries);
296 Q_D(const QBoxPlotSeries);
297 return d->m_boxSets.count();
297 return d->m_boxSets.count();
298 }
298 }
299
299
300 /*!
300 /*!
301 Returns a list of sets in series. Keeps ownership of sets.
301 Returns a list of sets in series. Keeps ownership of sets.
302 */
302 */
303 QList<QBoxSet *> QBoxPlotSeries::boxSets() const
303 QList<QBoxSet *> QBoxPlotSeries::boxSets() const
304 {
304 {
305 Q_D(const QBoxPlotSeries);
305 Q_D(const QBoxPlotSeries);
306 return d->m_boxSets;
306 return d->m_boxSets;
307 }
307 }
308
308
309 /*
309 /*
310 Returns QAbstractSeries::SeriesTypeBoxPlot.
310 Returns QAbstractSeries::SeriesTypeBoxPlot.
311 */
311 */
312 QAbstractSeries::SeriesType QBoxPlotSeries::type() const
312 QAbstractSeries::SeriesType QBoxPlotSeries::type() const
313 {
313 {
314 return QAbstractSeries::SeriesTypeBoxPlot;
314 return QAbstractSeries::SeriesTypeBoxPlot;
315 }
315 }
316
316
317 /*!
317 /*!
318 Sets brush for the series. Box-and-whiskers items are drawn using \a brush
318 Sets brush for the series. Box-and-whiskers items are drawn using \a brush
319 */
319 */
320 void QBoxPlotSeries::setBrush(const QBrush &brush)
320 void QBoxPlotSeries::setBrush(const QBrush &brush)
321 {
321 {
322 Q_D(QBoxPlotSeries);
322 Q_D(QBoxPlotSeries);
323
323
324 if (d->m_brush != brush) {
324 if (d->m_brush != brush) {
325 d->m_brush = brush;
325 d->m_brush = brush;
326 emit d->updated();
326 emit d->updated();
327 }
327 }
328 }
328 }
329
329
330 /*!
330 /*!
331 Returns brush of the series.
331 Returns brush of the series.
332 */
332 */
333 QBrush QBoxPlotSeries::brush() const
333 QBrush QBoxPlotSeries::brush() const
334 {
334 {
335 Q_D(const QBoxPlotSeries);
335 Q_D(const QBoxPlotSeries);
336
336
337 return d->m_brush;
337 return d->m_brush;
338 }
338 }
339
339
340 /*!
340 /*!
341 Sets pen for the series. Box-and-whiskers items are drawn using \a pen
341 Sets pen for the series. Box-and-whiskers items are drawn using \a pen
342 */
342 */
343 void QBoxPlotSeries::setPen(const QPen &pen)
343 void QBoxPlotSeries::setPen(const QPen &pen)
344 {
344 {
345 Q_D(QBoxPlotSeries);
345 Q_D(QBoxPlotSeries);
346
346
347 if (d->m_pen != pen) {
347 if (d->m_pen != pen) {
348 d->m_pen = pen;
348 d->m_pen = pen;
349 emit d->updated();
349 emit d->updated();
350 }
350 }
351 }
351 }
352
352
353 /*!
353 /*!
354 Returns the pen of this series.
354 Returns the pen of this series.
355 */
355 */
356 QPen QBoxPlotSeries::pen() const
356 QPen QBoxPlotSeries::pen() const
357 {
357 {
358 Q_D(const QBoxPlotSeries);
358 Q_D(const QBoxPlotSeries);
359
359
360 return d->m_pen;
360 return d->m_pen;
361 }
361 }
362
362
363 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
363 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
364
364
365 QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q)
365 QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q)
366 : QAbstractSeriesPrivate(q),
366 : QAbstractSeriesPrivate(q),
367 m_pen(QChartPrivate::defaultPen()),
367 m_pen(QChartPrivate::defaultPen()),
368 m_brush(QChartPrivate::defaultBrush())
368 m_brush(QChartPrivate::defaultBrush())
369 {
369 {
370 }
370 }
371
371
372 QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate()
372 QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate()
373 {
373 {
374 disconnect(this, 0, 0, 0);
374 disconnect(this, 0, 0, 0);
375 }
375 }
376
376
377 void QBoxPlotSeriesPrivate::initializeDomain()
377 void QBoxPlotSeriesPrivate::initializeDomain()
378 {
378 {
379 qreal minX(domain()->minX());
379 qreal minX(domain()->minX());
380 qreal minY(domain()->minY());
380 qreal minY(domain()->minY());
381 qreal maxX(domain()->maxX());
381 qreal maxX(domain()->maxX());
382 qreal maxY(domain()->maxY());
382 qreal maxY(domain()->maxY());
383
383
384 qreal x = m_boxSets.count();
384 qreal x = m_boxSets.count();
385 minX = qMin(minX, qreal(-0.5));
385 minX = qMin(minX, qreal(-0.5));
386 minY = qMin(minY, min());
386 minY = qMin(minY, min());
387 maxX = qMax(maxX, x - qreal(0.5));
387 maxX = qMax(maxX, x - qreal(0.5));
388 maxY = qMax(maxY, max());
388 maxY = qMax(maxY, max());
389
389
390 domain()->setRange(minX, maxX, minY, maxY);
390 domain()->setRange(minX, maxX, minY, maxY);
391 }
391 }
392
392
393 void QBoxPlotSeriesPrivate::initializeAxes()
393 void QBoxPlotSeriesPrivate::initializeAxes()
394 {
394 {
395 foreach (QAbstractAxis* axis, m_axes) {
395 foreach (QAbstractAxis* axis, m_axes) {
396 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
396 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
397 if (axis->orientation() == Qt::Horizontal)
397 if (axis->orientation() == Qt::Horizontal)
398 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
398 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
399 }
399 }
400 }
400 }
401 }
401 }
402
402
403 QAbstractAxis::AxisType QBoxPlotSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
403 QAbstractAxis::AxisType QBoxPlotSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
404 {
404 {
405 if (orientation == Qt::Horizontal)
405 if (orientation == Qt::Horizontal)
406 return QAbstractAxis::AxisTypeBarCategory;
406 return QAbstractAxis::AxisTypeBarCategory;
407
407
408 return QAbstractAxis::AxisTypeValue;
408 return QAbstractAxis::AxisTypeValue;
409 }
409 }
410
410
411 QAbstractAxis* QBoxPlotSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
411 QAbstractAxis* QBoxPlotSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
412 {
412 {
413 Q_UNUSED(orientation);
413 Q_UNUSED(orientation);
414
414
415 return 0;
415 return 0;
416 }
416 }
417
417
418 void QBoxPlotSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
418 void QBoxPlotSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
419 {
419 {
420 QStringList categories;
420 QStringList categories;
421 if (axis->categories().isEmpty()) {
421 if (axis->categories().isEmpty()) {
422 for (int i(1); i < m_boxSets.count() + 1; i++) {
422 for (int i(1); i < m_boxSets.count() + 1; i++) {
423 QBoxSet *set = m_boxSets.at(i - 1);
423 QBoxSet *set = m_boxSets.at(i - 1);
424 if (set->label().isEmpty())
424 if (set->label().isEmpty())
425 categories << QString::number(i);
425 categories << QString::number(i);
426 else
426 else
427 categories << set->label();
427 categories << set->label();
428 }
428 }
429 axis->append(categories);
429 axis->append(categories);
430 }
430 }
431 }
431 }
432
432
433 void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem *parent)
433 void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem *parent)
434 {
434 {
435 Q_Q(QBoxPlotSeries);
435 Q_Q(QBoxPlotSeries);
436
436
437 BoxPlotChartItem *boxPlot = new BoxPlotChartItem(q, parent);
437 BoxPlotChartItem *boxPlot = new BoxPlotChartItem(q, parent);
438 m_item.reset(boxPlot);
438 m_item.reset(boxPlot);
439 QAbstractSeriesPrivate::initializeGraphics(parent);
439 QAbstractSeriesPrivate::initializeGraphics(parent);
440
440
441 if (m_chart) {
441 if (m_chart) {
442 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesChange(QAbstractSeries*)) );
442 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesChange(QAbstractSeries*)) );
443 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) );
443 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) );
444
444
445 QList<QAbstractSeries *> serieses = m_chart->series();
445 QList<QAbstractSeries *> serieses = m_chart->series();
446
446
447 // Tries to find this series from the Chart's list of series and deduce the index
447 // Tries to find this series from the Chart's list of series and deduce the index
448 int index = 0;
448 int index = 0;
449 foreach (QAbstractSeries *s, serieses) {
449 foreach (QAbstractSeries *s, serieses) {
450 if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) {
450 if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) {
451 if (q == static_cast<QBoxPlotSeries *>(s)) {
451 if (q == static_cast<QBoxPlotSeries *>(s)) {
452 boxPlot->m_seriesIndex = index;
452 boxPlot->m_seriesIndex = index;
453 m_index = index;
453 m_index = index;
454 }
454 }
455 index++;
455 index++;
456 }
456 }
457 }
457 }
458 boxPlot->m_seriesCount = index;
458 boxPlot->m_seriesCount = index;
459 }
459 }
460
460
461 // Make BoxPlotChartItem to instantiate box & whisker items
461 // Make BoxPlotChartItem to instantiate box & whisker items
462 boxPlot->handleDataStructureChanged();
462 boxPlot->handleDataStructureChanged();
463 }
463 }
464
464
465 void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
465 void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
466 {
466 {
467 Q_Q(QBoxPlotSeries);
467 Q_Q(QBoxPlotSeries);
468
468
469 const QList<QGradient> gradients = theme->seriesGradients();
469 const QList<QGradient> gradients = theme->seriesGradients();
470
470
471 if (forced || QChartPrivate::defaultBrush() == m_brush) {
471 if (forced || QChartPrivate::defaultBrush() == m_brush) {
472 QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.5);
472 QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.5);
473 q->setBrush(brushColor);
473 q->setBrush(brushColor);
474 }
474 }
475
475
476 if (forced || QChartPrivate::defaultPen() == m_pen) {
476 if (forced || QChartPrivate::defaultPen() == m_pen) {
477 QPen pen = theme->outlinePen();
477 QPen pen = theme->outlinePen();
478 pen.setCosmetic(true);
478 pen.setCosmetic(true);
479 q->setPen(pen);
479 q->setPen(pen);
480 }
480 }
481 }
481 }
482
482
483 void QBoxPlotSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
483 void QBoxPlotSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
484 {
484 {
485 BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data());
485 BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data());
486 Q_ASSERT(item);
486 Q_ASSERT(item);
487 if (item->animation())
487 if (item->animation())
488 item->animation()->stopAndDestroyLater();
488 item->animation()->stopAndDestroyLater();
489
489
490 if (options.testFlag(QChart::SeriesAnimations))
490 if (options.testFlag(QChart::SeriesAnimations))
491 item->setAnimation(new BoxPlotAnimation(item));
491 m_animation = new BoxPlotAnimation(item);
492 else
492 else
493 item->setAnimation(0);
493 m_animation = 0;
494 item->setAnimation(m_animation);
495
494 QAbstractSeriesPrivate::initializeAnimations(options);
496 QAbstractSeriesPrivate::initializeAnimations(options);
495 }
497 }
496
498
497 QList<QLegendMarker*> QBoxPlotSeriesPrivate::createLegendMarkers(QLegend *legend)
499 QList<QLegendMarker*> QBoxPlotSeriesPrivate::createLegendMarkers(QLegend *legend)
498 {
500 {
499 Q_Q(QBoxPlotSeries);
501 Q_Q(QBoxPlotSeries);
500 QList<QLegendMarker *> list;
502 QList<QLegendMarker *> list;
501 return list << new QBoxPlotLegendMarker(q, legend);
503 return list << new QBoxPlotLegendMarker(q, legend);
502 }
504 }
503
505
504 void QBoxPlotSeriesPrivate::handleSeriesRemove(QAbstractSeries *series)
506 void QBoxPlotSeriesPrivate::handleSeriesRemove(QAbstractSeries *series)
505 {
507 {
506 Q_Q(QBoxPlotSeries);
508 Q_Q(QBoxPlotSeries);
507
509
508 QBoxPlotSeries *removedSeries = static_cast<QBoxPlotSeries *>(series);
510 QBoxPlotSeries *removedSeries = static_cast<QBoxPlotSeries *>(series);
509 QObject::disconnect(m_chart->d_ptr->m_dataset, 0, removedSeries->d_func(), 0);
511
512 if (q == removedSeries && m_animation) {
513 m_animation->stopAll();
514 QObject::disconnect(m_chart->d_ptr->m_dataset, 0, removedSeries->d_func(), 0);
515 }
510
516
511 // Test if series removed is me, then don't do anything
517 // Test if series removed is me, then don't do anything
512 if (q != removedSeries) {
518 if (q != removedSeries) {
513 BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data());
519 BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data());
514 if (item) {
520 if (item) {
515 item->m_seriesCount = item->m_seriesCount - 1;
521 item->m_seriesCount = item->m_seriesCount - 1;
516 if (removedSeries->d_func()->m_index < m_index) {
522 if (removedSeries->d_func()->m_index < m_index) {
517 m_index--;
523 m_index--;
518 item->m_seriesIndex = m_index;
524 item->m_seriesIndex = m_index;
519 }
525 }
520
526
521 item->handleDataStructureChanged();
527 item->handleDataStructureChanged();
522 }
528 }
523 }
529 }
524 }
530 }
525
531
526 void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series)
532 void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series)
527 {
533 {
528 Q_UNUSED(series);
534 Q_UNUSED(series);
529
535
530 Q_Q(QBoxPlotSeries);
536 Q_Q(QBoxPlotSeries);
531
537
532 BoxPlotChartItem *boxPlot = static_cast<BoxPlotChartItem *>(m_item.data());
538 BoxPlotChartItem *boxPlot = static_cast<BoxPlotChartItem *>(m_item.data());
533
539
534 if (m_chart) {
540 if (m_chart) {
535 QList<QAbstractSeries *> serieses = m_chart->series();
541 QList<QAbstractSeries *> serieses = m_chart->series();
536
542
537 // Tries to find this series from the Chart's list of series and deduce the index
543 // Tries to find this series from the Chart's list of series and deduce the index
538 int index = 0;
544 int index = 0;
539 foreach (QAbstractSeries *s, serieses) {
545 foreach (QAbstractSeries *s, serieses) {
540 if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) {
546 if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) {
541 if (q == static_cast<QBoxPlotSeries *>(s)) {
547 if (q == static_cast<QBoxPlotSeries *>(s)) {
542 boxPlot->m_seriesIndex = index;
548 boxPlot->m_seriesIndex = index;
543 m_index = index;
549 m_index = index;
544 }
550 }
545 index++;
551 index++;
546 }
552 }
547 }
553 }
548 boxPlot->m_seriesCount = index;
554 boxPlot->m_seriesCount = index;
549 }
555 }
550
556
551 boxPlot->handleDataStructureChanged();
557 boxPlot->handleDataStructureChanged();
552 }
558 }
553
559
554 bool QBoxPlotSeriesPrivate::append(QBoxSet *set)
560 bool QBoxPlotSeriesPrivate::append(QBoxSet *set)
555 {
561 {
556 if ((m_boxSets.contains(set)) || (set == 0))
562 if ((m_boxSets.contains(set)) || (set == 0))
557 return false; // Fail if set is already in list or set is null.
563 return false; // Fail if set is already in list or set is null.
558
564
559 m_boxSets.append(set);
565 m_boxSets.append(set);
560 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
566 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
561 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
567 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
562 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
568 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
563
569
564 emit restructuredBoxes(); // this notifies boxplotchartitem
570 emit restructuredBoxes(); // this notifies boxplotchartitem
565 return true;
571 return true;
566 }
572 }
567
573
568 bool QBoxPlotSeriesPrivate::remove(QBoxSet *set)
574 bool QBoxPlotSeriesPrivate::remove(QBoxSet *set)
569 {
575 {
570 if (!m_boxSets.contains(set))
576 if (!m_boxSets.contains(set))
571 return false; // Fail if set is not in list
577 return false; // Fail if set is not in list
572
578
573 m_boxSets.removeOne(set);
579 m_boxSets.removeOne(set);
574 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
580 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
575 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
581 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
576 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
582 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
577
583
578 emit restructuredBoxes(); // this notifies boxplotchartitem
584 emit restructuredBoxes(); // this notifies boxplotchartitem
579 return true;
585 return true;
580 }
586 }
581
587
582 bool QBoxPlotSeriesPrivate::append(QList<QBoxSet *> sets)
588 bool QBoxPlotSeriesPrivate::append(QList<QBoxSet *> sets)
583 {
589 {
584 foreach (QBoxSet *set, sets) {
590 foreach (QBoxSet *set, sets) {
585 if ((set == 0) || (m_boxSets.contains(set)))
591 if ((set == 0) || (m_boxSets.contains(set)))
586 return false; // Fail if any of the sets is null or is already appended.
592 return false; // Fail if any of the sets is null or is already appended.
587 if (sets.count(set) != 1)
593 if (sets.count(set) != 1)
588 return false; // Also fail if same set is more than once in given list.
594 return false; // Also fail if same set is more than once in given list.
589 }
595 }
590
596
591 foreach (QBoxSet *set, sets) {
597 foreach (QBoxSet *set, sets) {
592 m_boxSets.append(set);
598 m_boxSets.append(set);
593 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
599 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
594 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
600 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
595 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
601 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
596 }
602 }
597
603
598 emit restructuredBoxes(); // this notifies boxplotchartitem
604 emit restructuredBoxes(); // this notifies boxplotchartitem
599 return true;
605 return true;
600 }
606 }
601
607
602 bool QBoxPlotSeriesPrivate::remove(QList<QBoxSet *> sets)
608 bool QBoxPlotSeriesPrivate::remove(QList<QBoxSet *> sets)
603 {
609 {
604 if (sets.count() == 0)
610 if (sets.count() == 0)
605 return false;
611 return false;
606
612
607 foreach (QBoxSet *set, sets) {
613 foreach (QBoxSet *set, sets) {
608 if ((set == 0) || (!m_boxSets.contains(set)))
614 if ((set == 0) || (!m_boxSets.contains(set)))
609 return false; // Fail if any of the sets is null or is not in series
615 return false; // Fail if any of the sets is null or is not in series
610 if (sets.count(set) != 1)
616 if (sets.count(set) != 1)
611 return false; // Also fail if same set is more than once in given list.
617 return false; // Also fail if same set is more than once in given list.
612 }
618 }
613
619
614 foreach (QBoxSet *set, sets) {
620 foreach (QBoxSet *set, sets) {
615 m_boxSets.removeOne(set);
621 m_boxSets.removeOne(set);
616 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
622 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
617 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
623 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
618 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
624 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
619 }
625 }
620
626
621 emit restructuredBoxes(); // this notifies boxplotchartitem
627 emit restructuredBoxes(); // this notifies boxplotchartitem
622
628
623 return true;
629 return true;
624 }
630 }
625
631
626 bool QBoxPlotSeriesPrivate::insert(int index, QBoxSet *set)
632 bool QBoxPlotSeriesPrivate::insert(int index, QBoxSet *set)
627 {
633 {
628 if ((m_boxSets.contains(set)) || (set == 0))
634 if ((m_boxSets.contains(set)) || (set == 0))
629 return false; // Fail if set is already in list or set is null.
635 return false; // Fail if set is already in list or set is null.
630
636
631 m_boxSets.insert(index, set);
637 m_boxSets.insert(index, set);
632 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
638 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
633 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
639 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
634 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
640 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
635
641
636 emit restructuredBoxes(); // this notifies boxplotchartitem
642 emit restructuredBoxes(); // this notifies boxplotchartitem
637 return true;
643 return true;
638 }
644 }
639
645
640 QBoxSet *QBoxPlotSeriesPrivate::boxSetAt(int index)
646 QBoxSet *QBoxPlotSeriesPrivate::boxSetAt(int index)
641 {
647 {
642 return m_boxSets.at(index);
648 return m_boxSets.at(index);
643 }
649 }
644
650
645 qreal QBoxPlotSeriesPrivate::min()
651 qreal QBoxPlotSeriesPrivate::min()
646 {
652 {
647 if (m_boxSets.count() <= 0)
653 if (m_boxSets.count() <= 0)
648 return 0;
654 return 0;
649
655
650 qreal min = m_boxSets.at(0)->at(0);
656 qreal min = m_boxSets.at(0)->at(0);
651
657
652 foreach (QBoxSet *set, m_boxSets) {
658 foreach (QBoxSet *set, m_boxSets) {
653 for (int i = 0; i < 5; i++) {
659 for (int i = 0; i < 5; i++) {
654 if (set->at(i) < min)
660 if (set->at(i) < min)
655 min = set->at(i);
661 min = set->at(i);
656 }
662 }
657 }
663 }
658
664
659 return min;
665 return min;
660 }
666 }
661
667
662 qreal QBoxPlotSeriesPrivate::max()
668 qreal QBoxPlotSeriesPrivate::max()
663 {
669 {
664 if (m_boxSets.count() <= 0)
670 if (m_boxSets.count() <= 0)
665 return 0;
671 return 0;
666
672
667 qreal max = m_boxSets.at(0)->at(0);
673 qreal max = m_boxSets.at(0)->at(0);
668
674
669 foreach (QBoxSet *set, m_boxSets) {
675 foreach (QBoxSet *set, m_boxSets) {
670 for (int i = 0; i < 5; i++) {
676 for (int i = 0; i < 5; i++) {
671 if (set->at(i) > max)
677 if (set->at(i) > max)
672 max = set->at(i);
678 max = set->at(i);
673 }
679 }
674 }
680 }
675
681
676 return max;
682 return max;
677 }
683 }
678
684
679 #include "moc_qboxplotseries.cpp"
685 #include "moc_qboxplotseries.cpp"
680 #include "moc_qboxplotseries_p.cpp"
686 #include "moc_qboxplotseries_p.cpp"
681
687
682 QTCOMMERCIALCHART_END_NAMESPACE
688 QTCOMMERCIALCHART_END_NAMESPACE
683
689
@@ -1,95 +1,98
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QBOXPLOTSERIES_P_H
30 #ifndef QBOXPLOTSERIES_P_H
31 #define QBOXPLOTSERIES_P_H
31 #define QBOXPLOTSERIES_P_H
32
32
33 #include "qboxplotseries.h"
33 #include "qboxplotseries.h"
34 #include "qabstractbarseries_p.h"
34 #include "qabstractbarseries_p.h"
35 #include "abstractdomain_p.h"
35 #include "abstractdomain_p.h"
36 #include "qbarset.h"
36 #include "qbarset.h"
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class BoxPlotAnimation;
41
40 class QBoxPlotSeriesPrivate : public QAbstractSeriesPrivate
42 class QBoxPlotSeriesPrivate : public QAbstractSeriesPrivate
41 {
43 {
42 Q_OBJECT
44 Q_OBJECT
43
45
44 public:
46 public:
45 QBoxPlotSeriesPrivate(QBoxPlotSeries *q);
47 QBoxPlotSeriesPrivate(QBoxPlotSeries *q);
46 ~QBoxPlotSeriesPrivate();
48 ~QBoxPlotSeriesPrivate();
47
49
48 void initializeGraphics(QGraphicsItem *parent);
50 void initializeGraphics(QGraphicsItem *parent);
49 void initializeDomain();
51 void initializeDomain();
50 void initializeAxes();
52 void initializeAxes();
51 void initializeAnimations(QChart::AnimationOptions options);
53 void initializeAnimations(QChart::AnimationOptions options);
52 void initializeTheme(int index, ChartTheme *theme, bool forced = false);
54 void initializeTheme(int index, ChartTheme *theme, bool forced = false);
53
55
54 QList<QLegendMarker*> createLegendMarkers(QLegend *legend);
56 QList<QLegendMarker*> createLegendMarkers(QLegend *legend);
55
57
56 virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
58 virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
57 QAbstractAxis *createDefaultAxis(Qt::Orientation orientation) const;
59 QAbstractAxis *createDefaultAxis(Qt::Orientation orientation) const;
58
60
59 bool append(QBoxSet *set);
61 bool append(QBoxSet *set);
60 bool remove(QBoxSet *set);
62 bool remove(QBoxSet *set);
61 bool append(QList<QBoxSet *> sets);
63 bool append(QList<QBoxSet *> sets);
62 bool remove(QList<QBoxSet *> sets);
64 bool remove(QList<QBoxSet *> sets);
63 bool insert(int index, QBoxSet *set);
65 bool insert(int index, QBoxSet *set);
64 QBoxSet *boxSetAt(int index);
66 QBoxSet *boxSetAt(int index);
65
67
66 qreal max();
68 qreal max();
67 qreal min();
69 qreal min();
68
70
69 private:
71 private:
70 void populateCategories(QBarCategoryAxis *axis);
72 void populateCategories(QBarCategoryAxis *axis);
71
73
72 Q_SIGNALS:
74 Q_SIGNALS:
73 void updated();
75 void updated();
74 void clicked(int index, QBoxSet *barset);
76 void clicked(int index, QBoxSet *barset);
75 void updatedBoxes();
77 void updatedBoxes();
76 void updatedLayout();
78 void updatedLayout();
77 void restructuredBoxes();
79 void restructuredBoxes();
78
80
79 private slots:
81 private slots:
80 void handleSeriesChange(QAbstractSeries *series);
82 void handleSeriesChange(QAbstractSeries *series);
81 void handleSeriesRemove(QAbstractSeries *series);
83 void handleSeriesRemove(QAbstractSeries *series);
82
84
83 protected:
85 protected:
84 QList<QBoxSet *> m_boxSets;
86 QList<QBoxSet *> m_boxSets;
85 QPen m_pen;
87 QPen m_pen;
86 QBrush m_brush;
88 QBrush m_brush;
87 int m_index;
89 int m_index;
90 BoxPlotAnimation *m_animation;
88
91
89 private:
92 private:
90 Q_DECLARE_PUBLIC(QBoxPlotSeries)
93 Q_DECLARE_PUBLIC(QBoxPlotSeries)
91 };
94 };
92
95
93 QTCOMMERCIALCHART_END_NAMESPACE
96 QTCOMMERCIALCHART_END_NAMESPACE
94
97
95 #endif
98 #endif
General Comments 0
You need to be logged in to leave comments. Login now