##// END OF EJS Templates
Added remove single box...
Mika Salmela -
r2482:63ca3532f831
parent child
Show More
@@ -1,198 +1,215
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 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 "qbarset_p.h"
24 #include "qbarset_p.h"
25 #include "qabstractbarseries_p.h"
25 #include "qabstractbarseries_p.h"
26 #include "qbarset.h"
26 #include "qbarset.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)
36 m_animate(0)
37 {
37 {
38 connect(series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), this, SLOT(handleBarsetRemove(QList<QBarSet*>)));
38 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
39 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
39 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
40 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
40 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars()));
41 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars()));
41 connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars()));
42 connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars()));
42 // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here
43 // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here
43 setZValue(ChartPresenter::BoxPlotSeriesZValue);
44 setZValue(ChartPresenter::BoxPlotSeriesZValue);
44
45
45 m_barSets = m_series->barSets();
46 m_barSets = m_series->barSets();
46 }
47 }
47
48
48 BoxPlotChartItem::~BoxPlotChartItem()
49 BoxPlotChartItem::~BoxPlotChartItem()
49 {
50 {
50 qDebug() << "BoxPlotChartItem::~BoxPlotChartItem() " << m_seriesIndex;
51 qDebug() << "BoxPlotChartItem::~BoxPlotChartItem() " << m_seriesIndex;
51 }
52 }
52
53
53 void BoxPlotChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
54 void BoxPlotChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
54 {
55 {
55 Q_UNUSED(painter);
56 Q_UNUSED(painter);
56 Q_UNUSED(option);
57 Q_UNUSED(option);
57 Q_UNUSED(widget);
58 Q_UNUSED(widget);
58
59
59 //painter->setClipRect(QRectF(QPointF(0,0),domain()->size()));
60 //painter->setClipRect(QRectF(QPointF(0,0),domain()->size()));
60
61
61 //qDebug() << "ALERT EMPTY: BoxPlotChartItem::paint";
62 //qDebug() << "ALERT EMPTY: BoxPlotChartItem::paint";
62 }
63 }
63
64
64 void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation)
65 void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation)
65 {
66 {
66 //qDebug() << "BoxPlotChartItem::setAnimation :" << animation;
67 //qDebug() << "BoxPlotChartItem::setAnimation :" << animation;
67
68
68 m_animation = animation;
69 m_animation = animation;
69 if (m_animation) {
70 if (m_animation) {
70 foreach (BoxWhiskers *item, m_boxTable.values()) {
71 foreach (BoxWhiskers *item, m_boxTable.values()) {
71 m_animation->addBox(item);
72 m_animation->addBox(item);
72 }
73 }
73 handleDomainUpdated();
74 handleDomainUpdated();
74 }
75 }
75 }
76 }
76
77
77 void BoxPlotChartItem::handleDataStructureChanged()
78 void BoxPlotChartItem::handleDataStructureChanged()
78 {
79 {
79 //qDebug() << "BoxPlotChartItem::handleDataStructureChanged()";
80 qDebug() << "BoxPlotChartItem::handleDataStructureChanged()";
81
80 int setCount = m_series->count();
82 int setCount = m_series->count();
81
83
82 for (int s = 0; s < setCount; s++) {
84 for (int s = 0; s < setCount; s++) {
83 QBarSet *set = m_series->d_func()->barsetAt(s);
85 QBarSet *set = m_series->d_func()->barsetAt(s);
84
86
85 BoxWhiskers *boxWhiskersItem = m_boxTable.value(set);
87 BoxWhiskers *boxWhiskersItem = m_boxTable.value(set);
86 if (boxWhiskersItem == 0) {
88 if (boxWhiskersItem == 0) {
87 // Item is not yet created, make a box and add it to hash table
89 // Item is not yet created, make a box and add it to hash table
88 boxWhiskersItem = new BoxWhiskers(domain(), this);
90 boxWhiskersItem = new BoxWhiskers(domain(), this);
89 m_boxTable.insert(set, boxWhiskersItem);
91 m_boxTable.insert(set, boxWhiskersItem);
90
92
91 boxWhiskersItem->setBrush(m_series->brush());
93 boxWhiskersItem->setBrush(m_series->brush());
92 boxWhiskersItem->setPen(m_series->pen());
94 boxWhiskersItem->setPen(m_series->pen());
93 }
95 }
94 updateBoxGeometry(boxWhiskersItem, s);
96 updateBoxGeometry(boxWhiskersItem, s);
95
97
96 boxWhiskersItem->updateGeometry();
98 boxWhiskersItem->updateGeometry();
97
99
98 if (m_animation)
100 if (m_animation)
99 m_animation->addBox(boxWhiskersItem);
101 m_animation->addBox(boxWhiskersItem);
100 }
102 }
101
103
102 //
104 //
103 handleDomainUpdated();
105 handleDomainUpdated();
104 }
106 }
105
107
106 void BoxPlotChartItem::handleUpdatedBars()
108 void BoxPlotChartItem::handleUpdatedBars()
107 {
109 {
108 //qDebug() << "BoxPlotChartItem::handleUpdatedBars()";
110 qDebug() << "BoxPlotChartItem::handleUpdatedBars()";
109
111
110 foreach (BoxWhiskers *item, m_boxTable.values()) {
112 foreach (BoxWhiskers *item, m_boxTable.values()) {
111 item->setBrush(m_series->brush());
113 item->setBrush(m_series->brush());
112 item->setPen(m_series->pen());
114 item->setPen(m_series->pen());
113 }
115 }
114 }
116 }
115
117
118 void BoxPlotChartItem::handleBarsetRemove(QList<QBarSet*> barSets)
119 {
120 //qDebug() << "BoxPlotChartItem::handleBarsetRemove";
121
122 foreach (QBarSet *set, barSets) {
123 BoxWhiskers *boxItem = m_boxTable.value(set);
124 m_boxTable.remove(set);
125 delete boxItem;
126 }
127
128 // We trust that series emits the restructuredBars, which handles restructuring
129 }
130
116 void BoxPlotChartItem::handleDomainUpdated()
131 void BoxPlotChartItem::handleDomainUpdated()
117 {
132 {
118 //qDebug() << "BoxPlotChartItem::handleDomainUpdated() domain()->size() = " << domain()->size();
133 //qDebug() << "BoxPlotChartItem::handleDomainUpdated() domain()->size() = " << domain()->size();
119
134
120 if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0))
135 if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0))
121 return;
136 return;
122
137
123 // Set my bounding rect to same as domain size
138 // Set my bounding rect to same as domain size
124 m_boundingRect.setRect(0.0, 0.0, domain()->size().width(), domain()->size().height());
139 m_boundingRect.setRect(0.0, 0.0, domain()->size().width(), domain()->size().height());
125
140
126 foreach (BoxWhiskers *item, m_boxTable.values()) {
141 foreach (BoxWhiskers *item, m_boxTable.values()) {
127 // Update the domain size for each BoxWhisker item
142 // Update the domain size for each BoxWhisker item
128 item->setDomainSize(domain()->size());
143 item->setDomainSize(domain()->size());
129
144
130 // If the animation is set, start the animation for each BoxWhisker item
145 // If the animation is set, start the animation for each BoxWhisker item
131 if (m_animation) {
146 if (m_animation) {
132 presenter()->startAnimation(m_animation->boxAnimation(item));
147 presenter()->startAnimation(m_animation->boxAnimation(item));
133 }
148 }
134 }
149 }
135 }
150 }
136
151
137 void BoxPlotChartItem::handleLayoutChanged()
152 void BoxPlotChartItem::handleLayoutChanged()
138 {
153 {
154 qDebug() << "BoxPlotChartItem::handleLayoutChanged";
155
139 foreach (BoxWhiskers *item, m_boxTable.values()) {
156 foreach (BoxWhiskers *item, m_boxTable.values()) {
140 if (m_animation)
157 if (m_animation)
141 m_animation->setAnimationStart(item);
158 m_animation->setAnimationStart(item);
142
159
143 bool dirty = updateBoxGeometry(item, item->m_data.m_index);
160 bool dirty = updateBoxGeometry(item, item->m_data.m_index);
144 if (dirty && m_animation)
161 if (dirty && m_animation)
145 presenter()->startAnimation(m_animation->boxChangeAnimation(item));
162 presenter()->startAnimation(m_animation->boxChangeAnimation(item));
146 else
163 else
147 item->updateGeometry();
164 item->updateGeometry();
148 }
165 }
149 }
166 }
150
167
151 QRectF BoxPlotChartItem::boundingRect() const
168 QRectF BoxPlotChartItem::boundingRect() const
152 {
169 {
153 return m_boundingRect;
170 return m_boundingRect;
154 }
171 }
155
172
156 void BoxPlotChartItem::initializeLayout()
173 void BoxPlotChartItem::initializeLayout()
157 {
174 {
158 qDebug() << "ALERT EMPTY: BoxPlotChartItem::initializeLayout";
175 qDebug() << "ALERT EMPTY: BoxPlotChartItem::initializeLayout";
159 }
176 }
160
177
161 QVector<QRectF> BoxPlotChartItem::calculateLayout()
178 QVector<QRectF> BoxPlotChartItem::calculateLayout()
162 {
179 {
163 return QVector<QRectF>();
180 return QVector<QRectF>();
164 }
181 }
165
182
166 bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index)
183 bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index)
167 {
184 {
168 bool changed = false;
185 bool changed = false;
169
186
170 QBarSet *set = m_series->d_func()->barsetAt(index);
187 QBarSet *set = m_series->d_func()->barsetAt(index);
171 BoxWhiskersData &data = box->m_data;
188 BoxWhiskersData &data = box->m_data;
172
189
173 if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) ||
190 if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) ||
174 (data.m_median != set->at(2)) || (data.m_upperQuartile != set->at(3)) || (data.m_upperExtreme != set->at(4)))
191 (data.m_median != set->at(2)) || (data.m_upperQuartile != set->at(3)) || (data.m_upperExtreme != set->at(4)))
175 changed = true;
192 changed = true;
176
193
177 data.m_lowerExtreme = set->at(0);
194 data.m_lowerExtreme = set->at(0);
178 data.m_lowerQuartile = set->at(1);
195 data.m_lowerQuartile = set->at(1);
179 data.m_median = set->at(2);
196 data.m_median = set->at(2);
180 data.m_upperQuartile = set->at(3);
197 data.m_upperQuartile = set->at(3);
181 data.m_upperExtreme = set->at(4);
198 data.m_upperExtreme = set->at(4);
182 data.m_index = index;
199 data.m_index = index;
183 data.m_boxItems = m_series->count();
200 data.m_boxItems = m_series->count();
184
201
185 data.m_maxX = domain()->maxX();
202 data.m_maxX = domain()->maxX();
186 data.m_minX = domain()->minX();
203 data.m_minX = domain()->minX();
187 data.m_maxY = domain()->maxY();
204 data.m_maxY = domain()->maxY();
188 data.m_minY = domain()->minY();
205 data.m_minY = domain()->minY();
189
206
190 data.m_seriesIndex = m_seriesIndex;
207 data.m_seriesIndex = m_seriesIndex;
191 data.m_seriesCount = m_seriesCount;
208 data.m_seriesCount = m_seriesCount;
192
209
193 return changed;
210 return changed;
194 }
211 }
195
212
196 #include "moc_boxplotchartitem_p.cpp"
213 #include "moc_boxplotchartitem_p.cpp"
197
214
198 QTCOMMERCIALCHART_END_NAMESPACE
215 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,86 +1,88
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 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 "qbarset.h"
38 #include <QGraphicsItem>
39 #include <QGraphicsItem>
39
40
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41
42
42 class BoxPlotSeriesPrivate;
43 class BoxPlotSeriesPrivate;
43
44
44 class BoxPlotChartItem : public ChartItem
45 class BoxPlotChartItem : public ChartItem
45 {
46 {
46 Q_OBJECT
47 Q_OBJECT
47 public:
48 public:
48 BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item =0);
49 BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item =0);
49 ~BoxPlotChartItem();
50 ~BoxPlotChartItem();
50
51
51 void setAnimation(BoxPlotAnimation *animation);
52 void setAnimation(BoxPlotAnimation *animation);
52
53
53 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
54 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
54 QRectF boundingRect() const;
55 QRectF boundingRect() const;
55
56
56 public Q_SLOTS:
57 public Q_SLOTS:
57 void handleDataStructureChanged();
58 void handleDataStructureChanged();
58 void handleDomainUpdated();
59 void handleDomainUpdated();
59 void handleLayoutChanged();
60 void handleLayoutChanged();
60 void handleUpdatedBars();
61 void handleUpdatedBars();
62 void handleBarsetRemove(QList<QBarSet*> barSets);
61
63
62 private:
64 private:
63 virtual QVector<QRectF> calculateLayout();
65 virtual QVector<QRectF> calculateLayout();
64 void initializeLayout();
66 void initializeLayout();
65 bool updateBoxGeometry(BoxWhiskers *box, int index);
67 bool updateBoxGeometry(BoxWhiskers *box, int index);
66
68
67 protected:
69 protected:
68 friend class QBoxPlotSeriesPrivate;
70 friend class QBoxPlotSeriesPrivate;
69 QBoxPlotSeries *m_series; // Not owned.
71 QBoxPlotSeries *m_series; // Not owned.
70 QList<BoxWhiskers *> m_boxes;
72 QList<BoxWhiskers *> m_boxes;
71 QHash<QBarSet *, BoxWhiskers *> m_boxTable;
73 QHash<QBarSet *, BoxWhiskers *> m_boxTable;
72 QList<QBarSet *> m_barSets;
74 QList<QBarSet *> m_barSets;
73 int m_seriesIndex;
75 int m_seriesIndex;
74 int m_seriesCount;
76 int m_seriesCount;
75
77
76 BoxPlotAnimation *m_animation;
78 BoxPlotAnimation *m_animation;
77 bool m_animate;
79 bool m_animate;
78
80
79 QRectF m_boundingRect;
81 QRectF m_boundingRect;
80
82
81 //QList<BoxPlotAnimation *> m_animations;
83 //QList<BoxPlotAnimation *> m_animations;
82 };
84 };
83
85
84 QTCOMMERCIALCHART_END_NAMESPACE
86 QTCOMMERCIALCHART_END_NAMESPACE
85
87
86 #endif // BOXPLOTCHARTITEM_H
88 #endif // BOXPLOTCHARTITEM_H
@@ -1,189 +1,190
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "boxwhiskers_p.h"
21 #include "boxwhiskers_p.h"
22 #include <QPainter>
22 #include <QPainter>
23 #include <QDebug>
23 #include <QDebug>
24 #include <QWidget>
24 #include <QWidget>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 BoxWhiskers::BoxWhiskers(AbstractDomain *domain, QGraphicsObject *parent) :
28 BoxWhiskers::BoxWhiskers(AbstractDomain *domain, QGraphicsObject *parent) :
29 QGraphicsObject(parent),
29 QGraphicsObject(parent),
30 m_domain(domain)
30 m_domain(domain)
31 {
31 {
32 //qDebug() << "BoxWhiskers::BoxWhiskers()";
32 }
33 }
33
34
34 BoxWhiskers::~BoxWhiskers()
35 BoxWhiskers::~BoxWhiskers()
35 {
36 {
36 //qDebug() << "BoxWhiskers::~BoxWhiskers()";
37 //qDebug() << "BoxWhiskers::~BoxWhiskers()";
37 }
38 }
38
39
39 void BoxWhiskers::mousePressEvent(QGraphicsSceneMouseEvent *event)
40 void BoxWhiskers::mousePressEvent(QGraphicsSceneMouseEvent *event)
40 {
41 {
41 Q_UNUSED(event)
42 Q_UNUSED(event)
42
43
43 qDebug() << "BoxWhiskers::mousePressEvent";
44 qDebug() << "BoxWhiskers::mousePressEvent";
44 }
45 }
45
46
46 void BoxWhiskers::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
47 void BoxWhiskers::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
47 {
48 {
48 Q_UNUSED(event)
49 Q_UNUSED(event)
49
50
50 qDebug() << "BoxWhiskers::hoverEnterEvent";
51 qDebug() << "BoxWhiskers::hoverEnterEvent";
51 }
52 }
52
53
53 void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
54 void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
54 {
55 {
55 Q_UNUSED(event)
56 Q_UNUSED(event)
56
57
57 qDebug() << "BoxWhiskers::hoverLeaveEvent";
58 qDebug() << "BoxWhiskers::hoverLeaveEvent";
58 }
59 }
59
60
60 void BoxWhiskers::setBrush(const QBrush &brush)
61 void BoxWhiskers::setBrush(const QBrush &brush)
61 {
62 {
62 m_brush = brush;
63 m_brush = brush;
63 }
64 }
64
65
65 void BoxWhiskers::setPen(const QPen &pen)
66 void BoxWhiskers::setPen(const QPen &pen)
66 {
67 {
67 m_pen = pen;
68 m_pen = pen;
68 }
69 }
69
70
70 void BoxWhiskers::setLayout(const BoxWhiskersData &data)
71 void BoxWhiskers::setLayout(const BoxWhiskersData &data)
71 {
72 {
72 m_data = data;
73 m_data = data;
73 // if (m_data.m_index == 1)
74 // if (m_data.m_index == 1)
74 // qDebug() << "BoxWhiskers::setLayout";
75 // qDebug() << "BoxWhiskers::setLayout";
75 updateGeometry();
76 updateGeometry();
76 update();
77 update();
77 }
78 }
78
79
79
80
80 QSizeF BoxWhiskers::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
81 QSizeF BoxWhiskers::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
81 {
82 {
82 //Q_UNUSED(which)
83 //Q_UNUSED(which)
83 Q_UNUSED(constraint)
84 Q_UNUSED(constraint)
84
85
85 qDebug() << "BoxWhiskers::sizeHint, which = " << which;
86 qDebug() << "BoxWhiskers::sizeHint, which = " << which;
86
87
87 return QSizeF();
88 return QSizeF();
88 }
89 }
89
90
90 void BoxWhiskers::setGeometry(const QRectF &rect) // TODO: Unused?
91 void BoxWhiskers::setGeometry(const QRectF &rect) // TODO: Unused?
91 {
92 {
92 Q_UNUSED(rect)
93 Q_UNUSED(rect)
93
94
94 qDebug() << "BoxWhiskers::setGeometry";
95 qDebug() << "BoxWhiskers::setGeometry";
95 }
96 }
96
97
97 void BoxWhiskers::setDomainSize(const QSizeF &size)
98 void BoxWhiskers::setDomainSize(const QSizeF &size)
98 {
99 {
99 m_domainSize = size;
100 m_domainSize = size;
100
101
101 updateBoundingRect();
102 updateBoundingRect();
102 }
103 }
103
104
104 QRectF BoxWhiskers::boundingRect() const
105 QRectF BoxWhiskers::boundingRect() const
105 {
106 {
106 return m_boundingRect;
107 return m_boundingRect;
107 }
108 }
108
109
109 void BoxWhiskers::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
110 void BoxWhiskers::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
110 {
111 {
111 Q_UNUSED(option)
112 Q_UNUSED(option)
112 Q_UNUSED(widget)
113 Q_UNUSED(widget)
113 //Q_UNUSED(painter)
114 //Q_UNUSED(painter)
114
115
115 //painter->save();
116 //painter->save();
116 //painter->setClipRect(parentItem()->boundingRect());
117 //painter->setClipRect(parentItem()->boundingRect());
117 painter->setPen(m_pen);
118 painter->setPen(m_pen);
118 painter->setBrush(m_brush);
119 painter->setBrush(m_brush);
119 qreal spanY = m_data.m_maxY - m_data.m_minY;
120 qreal spanY = m_data.m_maxY - m_data.m_minY;
120 //painter->setClipRect(parentItem()->boundingRect());
121 //painter->setClipRect(parentItem()->boundingRect());
121 painter->scale(m_domainSize.width() / m_data.m_boxItems, m_domainSize.height() / spanY);
122 painter->scale(m_domainSize.width() / m_data.m_boxItems, m_domainSize.height() / spanY);
122 painter->drawPath(m_boxPath);
123 painter->drawPath(m_boxPath);
123 //painter->restore();
124 //painter->restore();
124 }
125 }
125
126
126 void BoxWhiskers::updateGeometry()
127 void BoxWhiskers::updateGeometry()
127 {
128 {
128 prepareGeometryChange();
129 prepareGeometryChange();
129
130
130 QPainterPath path;
131 QPainterPath path;
131
132
132 qreal columnWidth = 1.0 / m_data.m_seriesCount;
133 qreal columnWidth = 1.0 / m_data.m_seriesCount;
133 qreal left = 0.25 * columnWidth + columnWidth * m_data.m_seriesIndex;
134 qreal left = 0.25 * columnWidth + columnWidth * m_data.m_seriesIndex;
134 qreal right = 0.75 * columnWidth + columnWidth * m_data.m_seriesIndex;
135 qreal right = 0.75 * columnWidth + columnWidth * m_data.m_seriesIndex;
135 qreal middle = 0.5 * columnWidth + columnWidth * m_data.m_seriesIndex;
136 qreal middle = 0.5 * columnWidth + columnWidth * m_data.m_seriesIndex;
136
137
137 //whisker = 0.35 0.75
138 //whisker = 0.35 0.75
138
139
139 // Upper whisker
140 // Upper whisker
140 path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme);
141 path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme);
141 path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme);
142 path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme);
142 path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme);
143 path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme);
143 path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile);
144 path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile);
144 path.closeSubpath();
145 path.closeSubpath();
145
146
146 // Middle Box
147 // Middle Box
147 path.addRect(left + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile,
148 path.addRect(left + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile,
148 0.5 * columnWidth, m_data.m_upperQuartile - m_data.m_lowerQuartile);
149 0.5 * columnWidth, m_data.m_upperQuartile - m_data.m_lowerQuartile);
149
150
150 // Median/mean line
151 // Median/mean line
151 path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_median);
152 path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_median);
152 path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_median);
153 path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_median);
153
154
154 // Lower whisker
155 // Lower whisker
155 path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme);
156 path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme);
156 path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme);
157 path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme);
157 path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme);
158 path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme);
158 path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerQuartile);
159 path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerQuartile);
159 path.closeSubpath();
160 path.closeSubpath();
160
161
161 m_boxPath = path;
162 m_boxPath = path;
162
163
163 updateBoundingRect();
164 updateBoundingRect();
164
165
165 // qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY);
166 // qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY);
166 // qreal scaleX = m_domainSize.width() / m_data.m_boxItems;
167 // qreal scaleX = m_domainSize.width() / m_data.m_boxItems;
167 // QRectF br = path.boundingRect();
168 // QRectF br = path.boundingRect();
168 // m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY);
169 // m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY);
169
170
170 if (m_data.m_index == 5) {
171 if (m_data.m_index == 5) {
171 //qDebug() << "myValue = " << myValue;
172 //qDebug() << "myValue = " << myValue;
172 //qDebug() << "m_data.m_upperExtreme" << m_data.m_upperExtreme;
173 //qDebug() << "m_data.m_upperExtreme" << m_data.m_upperExtreme;
173 //qDebug() << "m_boundingRect = " << m_boundingRect;
174 //qDebug() << "m_boundingRect = " << m_boundingRect;
174 // qDebug() << "x = " << m_boundingRect.x() << ", y = " << m_boundingRect.y() << ", width = "
175 // qDebug() << "x = " << m_boundingRect.x() << ", y = " << m_boundingRect.y() << ", width = "
175 // << m_boundingRect.width() << ", height = " << m_boundingRect.height();
176 // << m_boundingRect.width() << ", height = " << m_boundingRect.height();
176 }
177 }
177 }
178 }
178
179
179 void BoxWhiskers::updateBoundingRect()
180 void BoxWhiskers::updateBoundingRect()
180 {
181 {
181 qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY);
182 qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY);
182 qreal scaleX = m_domainSize.width() / m_data.m_boxItems;
183 qreal scaleX = m_domainSize.width() / m_data.m_boxItems;
183 QRectF br = m_boxPath.boundingRect();
184 QRectF br = m_boxPath.boundingRect();
184 m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY);
185 m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY);
185 }
186 }
186
187
187 #include "moc_boxwhiskers_p.cpp"
188 #include "moc_boxwhiskers_p.cpp"
188
189
189 QTCOMMERCIALCHART_END_NAMESPACE
190 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,283 +1,303
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "mainwidget.h"
21 #include "mainwidget.h"
22 #include "customtablemodel.h"
22 #include "customtablemodel.h"
23 #include <QVBarModelMapper>
23 #include <QVBarModelMapper>
24 #include <QTableView>
24 #include <QTableView>
25 #include <QHeaderView>
25 #include <QHeaderView>
26 #include <QChartView>
26 #include <QChartView>
27 #include <QBoxPlotSeries>
27 #include <QBoxPlotSeries>
28 #include <QBarSet>
28 #include <QBarSet>
29 #include <QLegend>
29 #include <QLegend>
30 #include <QBarCategoryAxis>
30 #include <QBarCategoryAxis>
31 #include <QBrush>
31 #include <QBrush>
32 #include <QColor>
32 #include <QColor>
33 #include <QPushButton>
33 #include <QPushButton>
34 #include <QComboBox>
34 #include <QComboBox>
35 #include <QSpinBox>
35 #include <QSpinBox>
36 #include <QCheckBox>
36 #include <QCheckBox>
37 #include <QGridLayout>
37 #include <QGridLayout>
38 #include <QHBoxLayout>
38 #include <QHBoxLayout>
39 #include <QLabel>
39 #include <QLabel>
40 #include <QSpacerItem>
40 #include <QSpacerItem>
41 #include <QMessageBox>
41 #include <QMessageBox>
42 #include <cmath>
42 #include <cmath>
43 #include <QDebug>
43 #include <QDebug>
44 #include <QStandardItemModel>
44 #include <QStandardItemModel>
45 #include <QBarCategoryAxis>
45 #include <QBarCategoryAxis>
46
46
47
47
48 QTCOMMERCIALCHART_USE_NAMESPACE
48 QTCOMMERCIALCHART_USE_NAMESPACE
49
49
50 QString addCategories[] = {"Jul", "Aug", "Sep", "Nov", "Dec"};
50 QString addCategories[] = {"Jul", "Aug", "Sep", "Nov", "Dec"};
51
51
52 MainWidget::MainWidget(QWidget *parent) :
52 MainWidget::MainWidget(QWidget *parent) :
53 QWidget(parent),
53 QWidget(parent),
54 m_chart(0),
54 m_chart(0),
55 rowPos(0),
55 rowPos(0),
56 nSeries(0),
56 nSeries(0),
57 nNewBoxes(0)
57 nNewBoxes(0)
58 {
58 {
59 m_chart = new QChart();
59 m_chart = new QChart();
60
60
61 // Grid layout for the controls for configuring the chart widget
61 // Grid layout for the controls for configuring the chart widget
62 QGridLayout *grid = new QGridLayout();
62 QGridLayout *grid = new QGridLayout();
63
63
64 // Create add a series button
64 // Create add a series button
65 QPushButton *addSeriesButton = new QPushButton("Add a series");
65 QPushButton *addSeriesButton = new QPushButton("Add a series");
66 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
66 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
67 grid->addWidget(addSeriesButton, rowPos++, 1);
67 grid->addWidget(addSeriesButton, rowPos++, 1);
68
68
69 // Create remove a series button
69 // Create remove a series button
70 QPushButton *removeSeriesButton = new QPushButton("Remove a series");
70 QPushButton *removeSeriesButton = new QPushButton("Remove a series");
71 connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries()));
71 connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries()));
72 grid->addWidget(removeSeriesButton, rowPos++, 1);
72 grid->addWidget(removeSeriesButton, rowPos++, 1);
73
73
74
75 // Create add a single box button
74 // Create add a single box button
76 QPushButton *addBoxButton = new QPushButton("Add a box");
75 QPushButton *addBoxButton = new QPushButton("Add a box");
77 connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox()));
76 connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox()));
78 grid->addWidget(addBoxButton, rowPos++, 1);
77 grid->addWidget(addBoxButton, rowPos++, 1);
79
78
79 // Create add a single box button
80 QPushButton *removeBoxButton = new QPushButton("Remove a box");
81 connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox()));
82 grid->addWidget(removeBoxButton, rowPos++, 1);
83
80 initThemeCombo(grid);
84 initThemeCombo(grid);
81 initCheckboxes(grid);
85 initCheckboxes(grid);
82
86
83 m_model = new CustomTableModel;
87 m_model = new CustomTableModel;
84 QTableView *tableView = new QTableView;
88 QTableView *tableView = new QTableView;
85 tableView->setModel(m_model);
89 tableView->setModel(m_model);
86 tableView->setMaximumWidth(200);
90 tableView->setMaximumWidth(200);
87 grid->addWidget(tableView, rowPos++, 0, 3, 2, Qt::AlignLeft);
91 grid->addWidget(tableView, rowPos++, 0, 3, 2, Qt::AlignLeft);
88 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
92 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
89 tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
93 tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
90 tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
94 tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
91 #else
95 #else
92 tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
96 tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
93 tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
97 tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
94 #endif
98 #endif
95
99
96 // add row with empty label to make all the other rows static
100 // add row with empty label to make all the other rows static
97 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
101 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
98 grid->setRowStretch(grid->rowCount() - 1, 1);
102 grid->setRowStretch(grid->rowCount() - 1, 1);
99
103
100 // Create chart view with the chart
104 // Create chart view with the chart
101 m_chartView = new QChartView(m_chart, this);
105 m_chartView = new QChartView(m_chart, this);
102 //m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
106 //m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
103
107
104 // Another grid layout as a main layout
108 // Another grid layout as a main layout
105 QGridLayout *mainLayout = new QGridLayout();
109 QGridLayout *mainLayout = new QGridLayout();
106 mainLayout->addLayout(grid, 0, 0);
110 mainLayout->addLayout(grid, 0, 0);
107 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
111 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
108 setLayout(mainLayout);
112 setLayout(mainLayout);
109
113
110 legendToggled(false);
114 legendToggled(false);
111 animationToggled(false);
115 animationToggled(false);
112 }
116 }
113
117
114 // Combo box for selecting theme
118 // Combo box for selecting theme
115 void MainWidget::initThemeCombo(QGridLayout *grid)
119 void MainWidget::initThemeCombo(QGridLayout *grid)
116 {
120 {
117 QComboBox *chartTheme = new QComboBox();
121 QComboBox *chartTheme = new QComboBox();
118 chartTheme->addItem("Default");
122 chartTheme->addItem("Default");
119 chartTheme->addItem("Light");
123 chartTheme->addItem("Light");
120 chartTheme->addItem("Blue Cerulean");
124 chartTheme->addItem("Blue Cerulean");
121 chartTheme->addItem("Dark");
125 chartTheme->addItem("Dark");
122 chartTheme->addItem("Brown Sand");
126 chartTheme->addItem("Brown Sand");
123 chartTheme->addItem("Blue NCS");
127 chartTheme->addItem("Blue NCS");
124 chartTheme->addItem("High Contrast");
128 chartTheme->addItem("High Contrast");
125 chartTheme->addItem("Blue Icy");
129 chartTheme->addItem("Blue Icy");
126 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
130 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
127 this, SLOT(changeChartTheme(int)));
131 this, SLOT(changeChartTheme(int)));
128 grid->addWidget(new QLabel("Chart theme:"), rowPos, 0);
132 grid->addWidget(new QLabel("Chart theme:"), rowPos, 0);
129 grid->addWidget(chartTheme, rowPos++, 1);
133 grid->addWidget(chartTheme, rowPos++, 1);
130 }
134 }
131
135
132 // Different check boxes for customizing chart
136 // Different check boxes for customizing chart
133 void MainWidget::initCheckboxes(QGridLayout *grid)
137 void MainWidget::initCheckboxes(QGridLayout *grid)
134 {
138 {
135 QCheckBox *animationCheckBox = new QCheckBox("Animation");
139 QCheckBox *animationCheckBox = new QCheckBox("Animation");
136 connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool)));
140 connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool)));
137 animationCheckBox->setChecked(false);
141 animationCheckBox->setChecked(false);
138 grid->addWidget(animationCheckBox, rowPos++, 0);
142 grid->addWidget(animationCheckBox, rowPos++, 0);
139
143
140 QCheckBox *legendCheckBox = new QCheckBox("Legend");
144 QCheckBox *legendCheckBox = new QCheckBox("Legend");
141 connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool)));
145 connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool)));
142 legendCheckBox->setChecked(false);
146 legendCheckBox->setChecked(false);
143 grid->addWidget(legendCheckBox, rowPos++, 0);
147 grid->addWidget(legendCheckBox, rowPos++, 0);
144
148
145 QCheckBox *titleCheckBox = new QCheckBox("Title");
149 QCheckBox *titleCheckBox = new QCheckBox("Title");
146 connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool)));
150 connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool)));
147 titleCheckBox->setChecked(false);
151 titleCheckBox->setChecked(false);
148 grid->addWidget(titleCheckBox, rowPos++, 0);
152 grid->addWidget(titleCheckBox, rowPos++, 0);
149
153
150 QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper");
154 QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper");
151 connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool)));
155 connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool)));
152 modelMapperCheckBox->setChecked(false);
156 modelMapperCheckBox->setChecked(false);
153 grid->addWidget(modelMapperCheckBox, rowPos++, 0);
157 grid->addWidget(modelMapperCheckBox, rowPos++, 0);
154
158
155 }
159 }
156
160
157 void MainWidget::addSeries()
161 void MainWidget::addSeries()
158 {
162 {
159 qDebug() << "BoxPlotTester::MainWidget::addSeries()";
163 qDebug() << "BoxPlotTester::MainWidget::addSeries()";
160
164
161 if (nSeries > 9)
165 if (nSeries > 9)
162 return;
166 return;
163
167
164 // Initial data
168 // Initial data
165 //![1]
169 //![1]
166 QBarSet *set0 = new QBarSet("Jan");
170 QBarSet *set0 = new QBarSet("Jan");
167 QBarSet *set1 = new QBarSet("Feb");
171 QBarSet *set1 = new QBarSet("Feb");
168 QBarSet *set2 = new QBarSet("Mar");
172 QBarSet *set2 = new QBarSet("Mar");
169 QBarSet *set3 = new QBarSet("Apr");
173 QBarSet *set3 = new QBarSet("Apr");
170 QBarSet *set4 = new QBarSet("May");
174 QBarSet *set4 = new QBarSet("May");
171 QBarSet *set5 = new QBarSet("Jun");
175 QBarSet *set5 = new QBarSet("Jun");
172
176
173 // low bot med top upp
177 // low bot med top upp
174 *set0 << 3 << 4 << 4.4 << 6 << 7;
178 *set0 << 3 << 4 << 4.4 << 6 << 7;
175 *set1 << 5 << 6 << 7.5 << 8 << 12;
179 *set1 << 5 << 6 << 7.5 << 8 << 12;
176 *set2 << 3 << 5 << 5.7 << 8 << 9;
180 *set2 << 3 << 5 << 5.7 << 8 << 9;
177 *set3 << 5 << 6 << 6.8 << 7 << 8;
181 *set3 << 5 << 6 << 6.8 << 7 << 8;
178 *set4 << 4 << 5 << 5.2 << 6 << 7;
182 *set4 << 4 << 5 << 5.2 << 6 << 7;
179 *set5 << 4 << 7 << 8.2 << 9 << 10;
183 *set5 << 4 << 7 << 8.2 << 9 << 10;
180
184
181 m_series[nSeries] = new QBoxPlotSeries();
185 m_series[nSeries] = new QBoxPlotSeries();
182 m_series[nSeries]->append(set0);
186 m_series[nSeries]->append(set0);
183 m_series[nSeries]->append(set1);
187 m_series[nSeries]->append(set1);
184 m_series[nSeries]->append(set2);
188 m_series[nSeries]->append(set2);
185 m_series[nSeries]->append(set3);
189 m_series[nSeries]->append(set3);
186 m_series[nSeries]->append(set4);
190 m_series[nSeries]->append(set4);
187 m_series[nSeries]->append(set5);
191 m_series[nSeries]->append(set5);
188 m_series[nSeries]->type();
192 m_series[nSeries]->type();
189 m_series[nSeries]->setName("Box & Whiskers");
193 m_series[nSeries]->setName("Box & Whiskers");
190
194
191 m_chart->addSeries(m_series[nSeries]);
195 m_chart->addSeries(m_series[nSeries]);
192
196
193 if (nSeries == 0) {
197 if (nSeries == 0) {
194 QStringList categories;
198 QStringList categories;
195 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
199 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
196 m_axis = new QBarCategoryAxis();
200 m_axis = new QBarCategoryAxis();
197 m_axis->append(categories);
201 m_axis->append(categories);
198 m_chart->createDefaultAxes();
202 m_chart->createDefaultAxes();
199 m_chart->setAxisX(m_axis, m_series[nSeries]);
203 m_chart->setAxisX(m_axis, m_series[nSeries]);
200 }
204 }
201
205
202 nSeries++;
206 nSeries++;
203 }
207 }
204
208
205 void MainWidget::removeSeries()
209 void MainWidget::removeSeries()
206 {
210 {
207 if (nSeries > 0) {
211 if (nSeries > 0) {
208 nSeries--;
212 nSeries--;
209 m_chart->removeSeries(m_series[nSeries]);
213 m_chart->removeSeries(m_series[nSeries]);
210 delete m_series[nSeries];
214 delete m_series[nSeries];
215 } else {
216 qDebug() << "Create a series first";
211 }
217 }
212 }
218 }
213
219
214 void MainWidget::addBox()
220 void MainWidget::addBox()
215 {
221 {
216 qDebug() << "BoxPlotTester::MainWidget::addBox()";
222 qDebug() << "BoxPlotTester::MainWidget::addBox()";
217
223
218 QBarSet *newSet = new QBarSet("New");
224 if (nSeries > 0) {
219 *newSet << 5 << 6 << 6.8 << 7 << 8;
225 QBarSet *newSet = new QBarSet("New");
226 *newSet << 5 << 6 << 6.8 << 7 << 8;
220
227
221 m_series[0]->append(newSet);
228 m_series[0]->append(newSet);
222
229
223 m_axis->append(addCategories[nNewBoxes]);
230 m_axis->append(addCategories[nNewBoxes]);
224
231
225 nNewBoxes++;
232 nNewBoxes++;
233 }
234 }
235
236 void MainWidget::removeBox()
237 {
238 qDebug() << "MainWidget::removeBox";
239
240 if (nSeries > 0) {
241 QList<QBarSet *> sets = m_series[0]->barSets();
242 m_series[0]->remove(sets.at(m_series[0]->count() - 3));
243 } else {
244 qDebug() << "Create a series first";
245 }
226 }
246 }
227
247
228 void MainWidget::animationToggled(bool enabled)
248 void MainWidget::animationToggled(bool enabled)
229 {
249 {
230 qDebug() << "BoxPlotTester::Animation toggled to " << enabled;
250 qDebug() << "BoxPlotTester::Animation toggled to " << enabled;
231 if (enabled)
251 if (enabled)
232 m_chart->setAnimationOptions(QChart::SeriesAnimations);
252 m_chart->setAnimationOptions(QChart::SeriesAnimations);
233 else
253 else
234 m_chart->setAnimationOptions(QChart::NoAnimation);
254 m_chart->setAnimationOptions(QChart::NoAnimation);
235 }
255 }
236
256
237 void MainWidget::legendToggled(bool enabled)
257 void MainWidget::legendToggled(bool enabled)
238 {
258 {
239 qDebug() << "BoxPlotTester::Legend toggled to " << enabled;
259 qDebug() << "BoxPlotTester::Legend toggled to " << enabled;
240 m_chart->legend()->setVisible(enabled);
260 m_chart->legend()->setVisible(enabled);
241 if (enabled)
261 if (enabled)
242 m_chart->legend()->setAlignment(Qt::AlignBottom);
262 m_chart->legend()->setAlignment(Qt::AlignBottom);
243 }
263 }
244
264
245 void MainWidget::titleToggled(bool enabled)
265 void MainWidget::titleToggled(bool enabled)
246 {
266 {
247 qDebug() << "BoxPlotTester::Title toggled to " << enabled;
267 qDebug() << "BoxPlotTester::Title toggled to " << enabled;
248 if (enabled)
268 if (enabled)
249 m_chart->setTitle("Simple boxplotchart example");
269 m_chart->setTitle("Simple boxplotchart example");
250 else
270 else
251 m_chart->setTitle("");
271 m_chart->setTitle("");
252 }
272 }
253
273
254 void MainWidget::modelMapperToggled(bool enabled)
274 void MainWidget::modelMapperToggled(bool enabled)
255 {
275 {
256 if (enabled) {
276 if (enabled) {
257 m_series[nSeries] = new QBoxPlotSeries();
277 m_series[nSeries] = new QBoxPlotSeries();
258
278
259 int first = 0;
279 int first = 0;
260 int count = 5;
280 int count = 5;
261 QVBarModelMapper *mapper = new QVBarModelMapper(this);
281 QVBarModelMapper *mapper = new QVBarModelMapper(this);
262 mapper->setFirstBarSetColumn(0);
282 mapper->setFirstBarSetColumn(0);
263 mapper->setLastBarSetColumn(5);
283 mapper->setLastBarSetColumn(5);
264 mapper->setFirstRow(first);
284 mapper->setFirstRow(first);
265 mapper->setRowCount(count);
285 mapper->setRowCount(count);
266 mapper->setSeries(m_series[nSeries]);
286 mapper->setSeries(m_series[nSeries]);
267 mapper->setModel(m_model);
287 mapper->setModel(m_model);
268 m_chart->addSeries(m_series[nSeries]);
288 m_chart->addSeries(m_series[nSeries]);
269
289
270 nSeries++;
290 nSeries++;
271 } else {
291 } else {
272 removeSeries();
292 removeSeries();
273 }
293 }
274 }
294 }
275
295
276 void MainWidget::changeChartTheme(int themeIndex)
296 void MainWidget::changeChartTheme(int themeIndex)
277 {
297 {
278 qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex;
298 qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex;
279 if (themeIndex == 0)
299 if (themeIndex == 0)
280 m_chart->setTheme(QChart::ChartThemeLight);
300 m_chart->setTheme(QChart::ChartThemeLight);
281 else
301 else
282 m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1));
302 m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1));
283 }
303 }
@@ -1,70 +1,71
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef MAINWIDGET_H
21 #ifndef MAINWIDGET_H
22 #define MAINWIDGET_H
22 #define MAINWIDGET_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qchart.h"
25 #include "qchart.h"
26 #include "qchartview.h"
26 #include "qchartview.h"
27 #include "customtablemodel.h"
27 #include "customtablemodel.h"
28 #include <QWidget>
28 #include <QWidget>
29 #include <QBoxPlotSeries>
29 #include <QBoxPlotSeries>
30 #include <QBarCategoryAxis>
30 #include <QBarCategoryAxis>
31
31
32 class QGridLayout;
32 class QGridLayout;
33
33
34 QTCOMMERCIALCHART_USE_NAMESPACE
34 QTCOMMERCIALCHART_USE_NAMESPACE
35
35
36 class MainWidget : public QWidget
36 class MainWidget : public QWidget
37 {
37 {
38 Q_OBJECT
38 Q_OBJECT
39 public:
39 public:
40 explicit MainWidget(QWidget *parent = 0);
40 explicit MainWidget(QWidget *parent = 0);
41
41
42 signals:
42 signals:
43
43
44 private:
44 private:
45 void initThemeCombo(QGridLayout *grid);
45 void initThemeCombo(QGridLayout *grid);
46 void initCheckboxes(QGridLayout *grid);
46 void initCheckboxes(QGridLayout *grid);
47
47
48 private slots:
48 private slots:
49 void addSeries();
49 void addSeries();
50 void removeSeries();
50 void removeSeries();
51 void addBox();
51 void addBox();
52 void removeBox();
52 void animationToggled(bool enabled);
53 void animationToggled(bool enabled);
53 void legendToggled(bool enabled);
54 void legendToggled(bool enabled);
54 void titleToggled(bool enabled);
55 void titleToggled(bool enabled);
55 void modelMapperToggled(bool enabled);
56 void modelMapperToggled(bool enabled);
56 void changeChartTheme(int themeIndex);
57 void changeChartTheme(int themeIndex);
57
58
58 private:
59 private:
59 QChart *m_chart;
60 QChart *m_chart;
60 QChartView *m_chartView;
61 QChartView *m_chartView;
61 QGridLayout *m_scatterLayout;
62 QGridLayout *m_scatterLayout;
62 QBarCategoryAxis *m_axis;
63 QBarCategoryAxis *m_axis;
63 CustomTableModel *m_model;
64 CustomTableModel *m_model;
64 int rowPos;
65 int rowPos;
65 int nSeries;
66 int nSeries;
66 int nNewBoxes;
67 int nNewBoxes;
67 QBoxPlotSeries *m_series[10];
68 QBoxPlotSeries *m_series[10];
68 };
69 };
69
70
70 #endif // MAINWIDGET_H
71 #endif // MAINWIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now