@@ -1,107 +1,137 | |||||
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 <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QBoxPlotSeries> |
|
24 | #include <QBoxPlotSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 | #include <QBarCategoryAxis> |
|
27 | #include <QBarCategoryAxis> | |
|
28 | #include <QLineSeries> | |||
28 |
|
29 | |||
29 | #include <QBrush> |
|
30 | #include <QBrush> | |
30 | #include <QColor> |
|
31 | #include <QColor> | |
31 |
|
32 | |||
32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
33 | QTCOMMERCIALCHART_USE_NAMESPACE | |
33 |
|
34 | |||
34 | int main(int argc, char *argv[]) |
|
35 | int main(int argc, char *argv[]) | |
35 | { |
|
36 | { | |
36 | QApplication a(argc, argv); |
|
37 | QApplication a(argc, argv); | |
37 |
|
38 | |||
38 | //![1] |
|
39 | //![1] | |
39 | QBarSet *set0 = new QBarSet("Jan"); |
|
40 | QBarSet *set0 = new QBarSet("Jan"); | |
40 | QBarSet *set1 = new QBarSet("Feb"); |
|
41 | QBarSet *set1 = new QBarSet("Feb"); | |
41 | QBarSet *set2 = new QBarSet("Mar"); |
|
42 | QBarSet *set2 = new QBarSet("Mar"); | |
42 | QBarSet *set3 = new QBarSet("Apr"); |
|
43 | QBarSet *set3 = new QBarSet("Apr"); | |
43 | QBarSet *set4 = new QBarSet("May"); |
|
44 | QBarSet *set4 = new QBarSet("May"); | |
44 | QBarSet *set5 = new QBarSet("Jun"); |
|
45 | QBarSet *set5 = new QBarSet("Jun"); | |
|
46 | QBarSet *set6 = new QBarSet("Jul"); | |||
|
47 | QBarSet *set7 = new QBarSet("Aug"); | |||
|
48 | QBarSet *set8 = new QBarSet("Sep"); | |||
|
49 | QBarSet *set9 = new QBarSet("Oct"); | |||
|
50 | QBarSet *set10 = new QBarSet("Nov"); | |||
|
51 | QBarSet *set11 = new QBarSet("Dec"); | |||
45 |
|
52 | |||
46 | // low bot med top upp |
|
53 | // low bot med top upp | |
47 | *set0 << 3 << 4 << 4.4 << 6 << 7; |
|
54 | *set0 << 3 << 4 << 4.4 << 6 << 7; | |
48 | *set1 << 5 << 6 << 7.5 << 8 << 12; |
|
55 | *set1 << 5 << 6 << 7.5 << 8 << 12; | |
49 | *set2 << 3 << 5 << 5.7 << 8 << 9; |
|
56 | *set2 << 3 << 5 << 5.7 << 8 << 9; | |
50 | *set3 << 5 << 6 << 6.8 << 7 << 8; |
|
57 | *set3 << 5 << 6 << 6.8 << 7 << 8; | |
51 | *set4 << 4 << 5 << 5.2 << 6 << 7; |
|
58 | *set4 << 4 << 5 << 5.2 << 6 << 7; | |
52 | *set5 << 4 << 7 << 8.2 << 9 << 10; |
|
59 | *set5 << 4 << 7 << 8.2 << 9 << 10; | |
|
60 | *set6 << 2.5 << 5 << 5.4 << 6 << 7; | |||
|
61 | *set7 << 5 << 6.3 << 7.5 << 8 << 12; | |||
|
62 | *set8 << 2.6 << 5.1 << 5.7 << 8 << 9; | |||
|
63 | *set9 << 3.1 << 5.8 << 6.8 << 7 << 8; | |||
|
64 | *set10 << 4.2 << 5 << 5.8 << 6 << 7; | |||
|
65 | *set11 << 4.7 << 7 << 8.2 << 9 << 10; | |||
53 |
|
66 | |||
54 | set0->setBrush(QBrush(QColor(Qt::yellow))); |
|
|||
55 |
|
||||
56 | //set0->setColor(QColor(Qt::darkRed)); |
|
|||
57 | //![1] |
|
67 | //![1] | |
58 |
|
68 | |||
59 | //![2] |
|
69 | //![2] | |
60 | QBoxPlotSeries *series = new QBoxPlotSeries(); |
|
70 | QBoxPlotSeries *series = new QBoxPlotSeries(); | |
61 | series->append(set0); |
|
71 | series->append(set0); | |
62 | series->append(set1); |
|
72 | series->append(set1); | |
63 | series->append(set2); |
|
73 | series->append(set2); | |
64 | series->append(set3); |
|
74 | series->append(set3); | |
65 | series->append(set4); |
|
75 | series->append(set4); | |
66 | series->append(set5); |
|
76 | series->append(set5); | |
67 |
series-> |
|
77 | series->append(set6); | |
|
78 | series->append(set7); | |||
|
79 | series->append(set8); | |||
|
80 | series->append(set9); | |||
|
81 | series->append(set10); | |||
|
82 | series->append(set11); | |||
68 | series->setName("Box & Whiskers"); |
|
83 | series->setName("Box & Whiskers"); | |
69 | //series->setBrush(QBrush(QColor(Qt::yellow))); |
|
|||
70 | //![2] |
|
84 | //![2] | |
71 |
|
85 | |||
|
86 | QLineSeries *lineSeries = new QLineSeries(); | |||
|
87 | lineSeries->append(0, 4.4); | |||
|
88 | lineSeries->append(1, 7.5); | |||
|
89 | lineSeries->append(2, 5.7); | |||
|
90 | lineSeries->append(3, 6.8); | |||
|
91 | lineSeries->append(4, 5.2); | |||
|
92 | lineSeries->append(5, 8.2); | |||
|
93 | lineSeries->append(6, 5.4); | |||
|
94 | lineSeries->append(7, 7.5); | |||
|
95 | lineSeries->append(8, 5.7); | |||
|
96 | lineSeries->append(9, 6.8); | |||
|
97 | lineSeries->append(10, 5.2); | |||
|
98 | lineSeries->append(11, 8.2); | |||
|
99 | lineSeries->setName("Medians"); | |||
|
100 | ||||
72 | //![3] |
|
101 | //![3] | |
73 | QChart *chart = new QChart(); |
|
102 | QChart *chart = new QChart(); | |
74 | chart->addSeries(series); |
|
103 | chart->addSeries(series); | |
|
104 | chart->addSeries(lineSeries); | |||
75 | chart->setTitle("Simple boxplotchart example"); |
|
105 | chart->setTitle("Simple boxplotchart example"); | |
76 | chart->setAnimationOptions(QChart::SeriesAnimations); |
|
106 | chart->setAnimationOptions(QChart::SeriesAnimations); | |
77 | //![3] |
|
107 | //![3] | |
78 |
|
108 | |||
79 | //![4] |
|
109 | //![4] | |
80 | QStringList categories; |
|
110 | QStringList categories; | |
81 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
111 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
82 | QBarCategoryAxis *axis = new QBarCategoryAxis(); |
|
112 | QBarCategoryAxis *axis = new QBarCategoryAxis(); | |
83 | axis->append(categories); |
|
113 | axis->append(categories); | |
84 | chart->createDefaultAxes(); |
|
114 | chart->createDefaultAxes(); | |
85 | chart->setAxisX(axis, series); |
|
115 | chart->setAxisX(axis, series); | |
86 | //![4] |
|
116 | //![4] | |
87 |
|
117 | |||
88 | //![5] |
|
118 | //![5] | |
89 | chart->legend()->setVisible(true); |
|
119 | chart->legend()->setVisible(true); | |
90 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
120 | chart->legend()->setAlignment(Qt::AlignBottom); | |
91 | //![5] |
|
121 | //![5] | |
92 |
|
122 | |||
93 | //![6] |
|
123 | //![6] | |
94 | QChartView *chartView = new QChartView(chart); |
|
124 | QChartView *chartView = new QChartView(chart); | |
95 | chartView->setRenderHint(QPainter::Antialiasing); |
|
125 | chartView->setRenderHint(QPainter::Antialiasing); | |
96 | //![6] |
|
126 | //![6] | |
97 |
|
127 | |||
98 | //![7] |
|
128 | //![7] | |
99 | QMainWindow window; |
|
129 | QMainWindow window; | |
100 | window.setCentralWidget(chartView); |
|
130 | window.setCentralWidget(chartView); | |
101 | window.resize(400, 300); |
|
131 | window.resize(400, 300); | |
102 | window.show(); |
|
132 | window.show(); | |
103 | //![7] |
|
133 | //![7] | |
104 |
|
134 | |||
105 | return a.exec(); |
|
135 | return a.exec(); | |
106 | } |
|
136 | } | |
107 |
|
137 |
@@ -1,215 +1,224 | |||||
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, SIGNAL(barsetsRemoved(QList<QBarSet*>)), this, SLOT(handleBarsetRemove(QList<QBarSet*>))); | |
39 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); |
|
39 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); | |
40 | connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); |
|
40 | connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); | |
41 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars())); |
|
41 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars())); | |
42 | connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars())); |
|
42 | connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars())); | |
43 | // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here |
|
43 | // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here | |
44 | setZValue(ChartPresenter::BoxPlotSeriesZValue); |
|
44 | setZValue(ChartPresenter::BoxPlotSeriesZValue); | |
45 |
|
45 | |||
46 | m_barSets = m_series->barSets(); |
|
46 | m_barSets = m_series->barSets(); | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | BoxPlotChartItem::~BoxPlotChartItem() |
|
49 | BoxPlotChartItem::~BoxPlotChartItem() | |
50 | { |
|
50 | { | |
51 | qDebug() << "BoxPlotChartItem::~BoxPlotChartItem() " << m_seriesIndex; |
|
51 | qDebug() << "BoxPlotChartItem::~BoxPlotChartItem() " << m_seriesIndex; | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void BoxPlotChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
54 | void BoxPlotChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
55 | { |
|
55 | { | |
56 | Q_UNUSED(painter); |
|
56 | Q_UNUSED(painter); | |
57 | Q_UNUSED(option); |
|
57 | Q_UNUSED(option); | |
58 | Q_UNUSED(widget); |
|
58 | Q_UNUSED(widget); | |
59 |
|
59 | |||
60 | //painter->setClipRect(QRectF(QPointF(0,0),domain()->size())); |
|
60 | //painter->setClipRect(QRectF(QPointF(0,0),domain()->size())); | |
61 |
|
61 | |||
62 | //qDebug() << "ALERT EMPTY: BoxPlotChartItem::paint"; |
|
62 | //qDebug() << "ALERT EMPTY: BoxPlotChartItem::paint"; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation) |
|
65 | void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation) | |
66 | { |
|
66 | { | |
67 | //qDebug() << "BoxPlotChartItem::setAnimation :" << animation; |
|
67 | //qDebug() << "BoxPlotChartItem::setAnimation :" << animation; | |
68 |
|
68 | |||
69 | m_animation = animation; |
|
69 | m_animation = animation; | |
70 | if (m_animation) { |
|
70 | if (m_animation) { | |
71 | foreach (BoxWhiskers *item, m_boxTable.values()) { |
|
71 | foreach (BoxWhiskers *item, m_boxTable.values()) { | |
72 | m_animation->addBox(item); |
|
72 | m_animation->addBox(item); | |
73 | } |
|
73 | } | |
74 | handleDomainUpdated(); |
|
74 | handleDomainUpdated(); | |
75 | } |
|
75 | } | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void BoxPlotChartItem::handleDataStructureChanged() |
|
78 | void BoxPlotChartItem::handleDataStructureChanged() | |
79 | { |
|
79 | { | |
80 | qDebug() << "BoxPlotChartItem::handleDataStructureChanged()"; |
|
80 | qDebug() << "BoxPlotChartItem::handleDataStructureChanged()"; | |
81 |
|
81 | |||
82 | int setCount = m_series->count(); |
|
82 | int setCount = m_series->count(); | |
83 |
|
83 | |||
84 | for (int s = 0; s < setCount; s++) { |
|
84 | for (int s = 0; s < setCount; s++) { | |
85 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
85 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
86 |
|
86 | |||
87 | BoxWhiskers *boxWhiskersItem = m_boxTable.value(set); |
|
87 | BoxWhiskers *boxWhiskersItem = m_boxTable.value(set); | |
88 | if (boxWhiskersItem == 0) { |
|
88 | if (boxWhiskersItem == 0) { | |
89 | // 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 | |
90 | boxWhiskersItem = new BoxWhiskers(domain(), this); |
|
90 | boxWhiskersItem = new BoxWhiskers(domain(), this); | |
91 | m_boxTable.insert(set, boxWhiskersItem); |
|
91 | m_boxTable.insert(set, boxWhiskersItem); | |
92 |
|
92 | |||
93 | boxWhiskersItem->setBrush(m_series->brush()); |
|
93 | boxWhiskersItem->setBrush(m_series->brush()); | |
94 | boxWhiskersItem->setPen(m_series->pen()); |
|
94 | boxWhiskersItem->setPen(m_series->pen()); | |
95 | } |
|
95 | } | |
96 | updateBoxGeometry(boxWhiskersItem, s); |
|
96 | updateBoxGeometry(boxWhiskersItem, s); | |
97 |
|
97 | |||
98 | boxWhiskersItem->updateGeometry(); |
|
98 | boxWhiskersItem->updateGeometry(); | |
99 |
|
99 | |||
100 | if (m_animation) |
|
100 | if (m_animation) | |
101 | m_animation->addBox(boxWhiskersItem); |
|
101 | m_animation->addBox(boxWhiskersItem); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | // |
|
104 | // | |
105 | handleDomainUpdated(); |
|
105 | handleDomainUpdated(); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | void BoxPlotChartItem::handleUpdatedBars() |
|
108 | void BoxPlotChartItem::handleUpdatedBars() | |
109 | { |
|
109 | { | |
110 | qDebug() << "BoxPlotChartItem::handleUpdatedBars()"; |
|
110 | qDebug() << "BoxPlotChartItem::handleUpdatedBars()"; | |
111 |
|
111 | |||
112 | foreach (BoxWhiskers *item, m_boxTable.values()) { |
|
112 | foreach (BoxWhiskers *item, m_boxTable.values()) { | |
113 | item->setBrush(m_series->brush()); |
|
113 | item->setBrush(m_series->brush()); | |
114 | item->setPen(m_series->pen()); |
|
114 | item->setPen(m_series->pen()); | |
115 | } |
|
115 | } | |
|
116 | // Override with QBarSet specific settings | |||
|
117 | foreach (QBarSet *set, m_boxTable.keys()) { | |||
|
118 | if (set->brush().style() != Qt::NoBrush) | |||
|
119 | m_boxTable.value(set)->setBrush(set->brush()); | |||
|
120 | if (set->pen().style() != Qt::NoPen) | |||
|
121 | m_boxTable.value(set)->setPen(set->pen()); | |||
|
122 | } | |||
116 | } |
|
123 | } | |
117 |
|
124 | |||
118 | void BoxPlotChartItem::handleBarsetRemove(QList<QBarSet*> barSets) |
|
125 | void BoxPlotChartItem::handleBarsetRemove(QList<QBarSet*> barSets) | |
119 | { |
|
126 | { | |
120 | //qDebug() << "BoxPlotChartItem::handleBarsetRemove"; |
|
127 | //qDebug() << "BoxPlotChartItem::handleBarsetRemove"; | |
121 |
|
128 | |||
122 | foreach (QBarSet *set, barSets) { |
|
129 | foreach (QBarSet *set, barSets) { | |
123 | BoxWhiskers *boxItem = m_boxTable.value(set); |
|
130 | BoxWhiskers *boxItem = m_boxTable.value(set); | |
124 | m_boxTable.remove(set); |
|
131 | m_boxTable.remove(set); | |
125 | delete boxItem; |
|
132 | delete boxItem; | |
126 | } |
|
133 | } | |
127 |
|
134 | |||
128 | // We trust that series emits the restructuredBars, which handles restructuring |
|
135 | // We trust that series emits the restructuredBars, which handles restructuring | |
129 | } |
|
136 | } | |
130 |
|
137 | |||
131 | void BoxPlotChartItem::handleDomainUpdated() |
|
138 | void BoxPlotChartItem::handleDomainUpdated() | |
132 | { |
|
139 | { | |
133 | //qDebug() << "BoxPlotChartItem::handleDomainUpdated() domain()->size() = " << domain()->size(); |
|
140 | //qDebug() << "BoxPlotChartItem::handleDomainUpdated() domain()->size() = " << domain()->size(); | |
134 |
|
141 | |||
135 | if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0)) |
|
142 | if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0)) | |
136 | return; |
|
143 | return; | |
137 |
|
144 | |||
138 | // Set my bounding rect to same as domain size |
|
145 | // Set my bounding rect to same as domain size | |
139 | m_boundingRect.setRect(0.0, 0.0, domain()->size().width(), domain()->size().height()); |
|
146 | m_boundingRect.setRect(0.0, 0.0, domain()->size().width(), domain()->size().height()); | |
140 |
|
147 | |||
141 | foreach (BoxWhiskers *item, m_boxTable.values()) { |
|
148 | foreach (BoxWhiskers *item, m_boxTable.values()) { | |
142 | // Update the domain size for each BoxWhisker item |
|
149 | // Update the domain size for each BoxWhisker item | |
143 | item->setDomainSize(domain()->size()); |
|
150 | item->setDomainSize(domain()->size()); | |
144 |
|
151 | |||
145 | // If the animation is set, start the animation for each BoxWhisker item |
|
152 | // If the animation is set, start the animation for each BoxWhisker item | |
146 | if (m_animation) { |
|
153 | if (m_animation) { | |
147 | presenter()->startAnimation(m_animation->boxAnimation(item)); |
|
154 | presenter()->startAnimation(m_animation->boxAnimation(item)); | |
148 | } |
|
155 | } | |
149 | } |
|
156 | } | |
150 | } |
|
157 | } | |
151 |
|
158 | |||
152 | void BoxPlotChartItem::handleLayoutChanged() |
|
159 | void BoxPlotChartItem::handleLayoutChanged() | |
153 | { |
|
160 | { | |
154 | qDebug() << "BoxPlotChartItem::handleLayoutChanged"; |
|
161 | qDebug() << "BoxPlotChartItem::handleLayoutChanged"; | |
155 |
|
162 | |||
156 | foreach (BoxWhiskers *item, m_boxTable.values()) { |
|
163 | foreach (BoxWhiskers *item, m_boxTable.values()) { | |
157 | if (m_animation) |
|
164 | if (m_animation) | |
158 | m_animation->setAnimationStart(item); |
|
165 | m_animation->setAnimationStart(item); | |
159 |
|
166 | |||
160 | bool dirty = updateBoxGeometry(item, item->m_data.m_index); |
|
167 | bool dirty = updateBoxGeometry(item, item->m_data.m_index); | |
161 | if (dirty && m_animation) |
|
168 | if (dirty && m_animation) | |
162 | presenter()->startAnimation(m_animation->boxChangeAnimation(item)); |
|
169 | presenter()->startAnimation(m_animation->boxChangeAnimation(item)); | |
163 | else |
|
170 | else | |
164 | item->updateGeometry(); |
|
171 | item->updateGeometry(); | |
165 | } |
|
172 | } | |
166 | } |
|
173 | } | |
167 |
|
174 | |||
168 | QRectF BoxPlotChartItem::boundingRect() const |
|
175 | QRectF BoxPlotChartItem::boundingRect() const | |
169 | { |
|
176 | { | |
170 | return m_boundingRect; |
|
177 | return m_boundingRect; | |
171 | } |
|
178 | } | |
172 |
|
179 | |||
173 | void BoxPlotChartItem::initializeLayout() |
|
180 | void BoxPlotChartItem::initializeLayout() | |
174 | { |
|
181 | { | |
175 | qDebug() << "ALERT EMPTY: BoxPlotChartItem::initializeLayout"; |
|
182 | qDebug() << "ALERT EMPTY: BoxPlotChartItem::initializeLayout"; | |
176 | } |
|
183 | } | |
177 |
|
184 | |||
178 | QVector<QRectF> BoxPlotChartItem::calculateLayout() |
|
185 | QVector<QRectF> BoxPlotChartItem::calculateLayout() | |
179 | { |
|
186 | { | |
|
187 | qDebug() << "ALERT EMPTY: BoxPlotChartItem::calculateLayout()"; | |||
|
188 | ||||
180 | return QVector<QRectF>(); |
|
189 | return QVector<QRectF>(); | |
181 | } |
|
190 | } | |
182 |
|
191 | |||
183 | bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index) |
|
192 | bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index) | |
184 | { |
|
193 | { | |
185 | bool changed = false; |
|
194 | bool changed = false; | |
186 |
|
195 | |||
187 | QBarSet *set = m_series->d_func()->barsetAt(index); |
|
196 | QBarSet *set = m_series->d_func()->barsetAt(index); | |
188 | BoxWhiskersData &data = box->m_data; |
|
197 | BoxWhiskersData &data = box->m_data; | |
189 |
|
198 | |||
190 | if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) || |
|
199 | if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) || | |
191 | (data.m_median != set->at(2)) || (data.m_upperQuartile != set->at(3)) || (data.m_upperExtreme != set->at(4))) |
|
200 | (data.m_median != set->at(2)) || (data.m_upperQuartile != set->at(3)) || (data.m_upperExtreme != set->at(4))) | |
192 | changed = true; |
|
201 | changed = true; | |
193 |
|
202 | |||
194 | data.m_lowerExtreme = set->at(0); |
|
203 | data.m_lowerExtreme = set->at(0); | |
195 | data.m_lowerQuartile = set->at(1); |
|
204 | data.m_lowerQuartile = set->at(1); | |
196 | data.m_median = set->at(2); |
|
205 | data.m_median = set->at(2); | |
197 | data.m_upperQuartile = set->at(3); |
|
206 | data.m_upperQuartile = set->at(3); | |
198 | data.m_upperExtreme = set->at(4); |
|
207 | data.m_upperExtreme = set->at(4); | |
199 | data.m_index = index; |
|
208 | data.m_index = index; | |
200 | data.m_boxItems = m_series->count(); |
|
209 | data.m_boxItems = m_series->count(); | |
201 |
|
210 | |||
202 | data.m_maxX = domain()->maxX(); |
|
211 | data.m_maxX = domain()->maxX(); | |
203 | data.m_minX = domain()->minX(); |
|
212 | data.m_minX = domain()->minX(); | |
204 | data.m_maxY = domain()->maxY(); |
|
213 | data.m_maxY = domain()->maxY(); | |
205 | data.m_minY = domain()->minY(); |
|
214 | data.m_minY = domain()->minY(); | |
206 |
|
215 | |||
207 | data.m_seriesIndex = m_seriesIndex; |
|
216 | data.m_seriesIndex = m_seriesIndex; | |
208 | data.m_seriesCount = m_seriesCount; |
|
217 | data.m_seriesCount = m_seriesCount; | |
209 |
|
218 | |||
210 | return changed; |
|
219 | return changed; | |
211 | } |
|
220 | } | |
212 |
|
221 | |||
213 | #include "moc_boxplotchartitem_p.cpp" |
|
222 | #include "moc_boxplotchartitem_p.cpp" | |
214 |
|
223 | |||
215 | QTCOMMERCIALCHART_END_NAMESPACE |
|
224 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,190 +1,192 | |||||
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 | //qDebug() << "BoxWhiskers::BoxWhiskers()"; | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | BoxWhiskers::~BoxWhiskers() |
|
35 | BoxWhiskers::~BoxWhiskers() | |
36 | { |
|
36 | { | |
37 | //qDebug() << "BoxWhiskers::~BoxWhiskers()"; |
|
37 | //qDebug() << "BoxWhiskers::~BoxWhiskers()"; | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | void BoxWhiskers::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
40 | void BoxWhiskers::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
41 | { |
|
41 | { | |
42 | Q_UNUSED(event) |
|
42 | Q_UNUSED(event) | |
43 |
|
43 | |||
44 | qDebug() << "BoxWhiskers::mousePressEvent"; |
|
44 | qDebug() << "BoxWhiskers::mousePressEvent"; | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void BoxWhiskers::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
47 | void BoxWhiskers::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
48 | { |
|
48 | { | |
49 | Q_UNUSED(event) |
|
49 | Q_UNUSED(event) | |
50 |
|
50 | |||
51 | qDebug() << "BoxWhiskers::hoverEnterEvent"; |
|
51 | qDebug() << "BoxWhiskers::hoverEnterEvent"; | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
54 | void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
55 | { |
|
55 | { | |
56 | Q_UNUSED(event) |
|
56 | Q_UNUSED(event) | |
57 |
|
57 | |||
58 | qDebug() << "BoxWhiskers::hoverLeaveEvent"; |
|
58 | qDebug() << "BoxWhiskers::hoverLeaveEvent"; | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | void BoxWhiskers::setBrush(const QBrush &brush) |
|
61 | void BoxWhiskers::setBrush(const QBrush &brush) | |
62 | { |
|
62 | { | |
63 | m_brush = brush; |
|
63 | m_brush = brush; | |
|
64 | update(); | |||
64 | } |
|
65 | } | |
65 |
|
66 | |||
66 | void BoxWhiskers::setPen(const QPen &pen) |
|
67 | void BoxWhiskers::setPen(const QPen &pen) | |
67 | { |
|
68 | { | |
68 | m_pen = pen; |
|
69 | m_pen = pen; | |
|
70 | update(); | |||
69 | } |
|
71 | } | |
70 |
|
72 | |||
71 | void BoxWhiskers::setLayout(const BoxWhiskersData &data) |
|
73 | void BoxWhiskers::setLayout(const BoxWhiskersData &data) | |
72 | { |
|
74 | { | |
73 | m_data = data; |
|
75 | m_data = data; | |
74 | // if (m_data.m_index == 1) |
|
76 | // if (m_data.m_index == 1) | |
75 | // qDebug() << "BoxWhiskers::setLayout"; |
|
77 | // qDebug() << "BoxWhiskers::setLayout"; | |
76 | updateGeometry(); |
|
78 | updateGeometry(); | |
77 | update(); |
|
79 | update(); | |
78 | } |
|
80 | } | |
79 |
|
81 | |||
80 |
|
82 | |||
81 | QSizeF BoxWhiskers::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
83 | QSizeF BoxWhiskers::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
82 | { |
|
84 | { | |
83 | //Q_UNUSED(which) |
|
85 | //Q_UNUSED(which) | |
84 | Q_UNUSED(constraint) |
|
86 | Q_UNUSED(constraint) | |
85 |
|
87 | |||
86 | qDebug() << "BoxWhiskers::sizeHint, which = " << which; |
|
88 | qDebug() << "BoxWhiskers::sizeHint, which = " << which; | |
87 |
|
89 | |||
88 | return QSizeF(); |
|
90 | return QSizeF(); | |
89 | } |
|
91 | } | |
90 |
|
92 | |||
91 | void BoxWhiskers::setGeometry(const QRectF &rect) // TODO: Unused? |
|
93 | void BoxWhiskers::setGeometry(const QRectF &rect) // TODO: Unused? | |
92 | { |
|
94 | { | |
93 | Q_UNUSED(rect) |
|
95 | Q_UNUSED(rect) | |
94 |
|
96 | |||
95 | qDebug() << "BoxWhiskers::setGeometry"; |
|
97 | qDebug() << "BoxWhiskers::setGeometry"; | |
96 | } |
|
98 | } | |
97 |
|
99 | |||
98 | void BoxWhiskers::setDomainSize(const QSizeF &size) |
|
100 | void BoxWhiskers::setDomainSize(const QSizeF &size) | |
99 | { |
|
101 | { | |
100 | m_domainSize = size; |
|
102 | m_domainSize = size; | |
101 |
|
103 | |||
102 | updateBoundingRect(); |
|
104 | updateBoundingRect(); | |
103 | } |
|
105 | } | |
104 |
|
106 | |||
105 | QRectF BoxWhiskers::boundingRect() const |
|
107 | QRectF BoxWhiskers::boundingRect() const | |
106 | { |
|
108 | { | |
107 | return m_boundingRect; |
|
109 | return m_boundingRect; | |
108 | } |
|
110 | } | |
109 |
|
111 | |||
110 | void BoxWhiskers::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
112 | void BoxWhiskers::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
111 | { |
|
113 | { | |
112 | Q_UNUSED(option) |
|
114 | Q_UNUSED(option) | |
113 | Q_UNUSED(widget) |
|
115 | Q_UNUSED(widget) | |
114 | //Q_UNUSED(painter) |
|
116 | //Q_UNUSED(painter) | |
115 |
|
117 | |||
116 | //painter->save(); |
|
118 | //painter->save(); | |
117 | //painter->setClipRect(parentItem()->boundingRect()); |
|
119 | //painter->setClipRect(parentItem()->boundingRect()); | |
118 | painter->setPen(m_pen); |
|
120 | painter->setPen(m_pen); | |
119 | painter->setBrush(m_brush); |
|
121 | painter->setBrush(m_brush); | |
120 | qreal spanY = m_data.m_maxY - m_data.m_minY; |
|
122 | qreal spanY = m_data.m_maxY - m_data.m_minY; | |
121 | //painter->setClipRect(parentItem()->boundingRect()); |
|
123 | //painter->setClipRect(parentItem()->boundingRect()); | |
122 | painter->scale(m_domainSize.width() / m_data.m_boxItems, m_domainSize.height() / spanY); |
|
124 | painter->scale(m_domainSize.width() / m_data.m_boxItems, m_domainSize.height() / spanY); | |
123 | painter->drawPath(m_boxPath); |
|
125 | painter->drawPath(m_boxPath); | |
124 | //painter->restore(); |
|
126 | //painter->restore(); | |
125 | } |
|
127 | } | |
126 |
|
128 | |||
127 | void BoxWhiskers::updateGeometry() |
|
129 | void BoxWhiskers::updateGeometry() | |
128 | { |
|
130 | { | |
129 | prepareGeometryChange(); |
|
131 | prepareGeometryChange(); | |
130 |
|
132 | |||
131 | QPainterPath path; |
|
133 | QPainterPath path; | |
132 |
|
134 | |||
133 | qreal columnWidth = 1.0 / m_data.m_seriesCount; |
|
135 | qreal columnWidth = 1.0 / m_data.m_seriesCount; | |
134 | qreal left = 0.25 * columnWidth + columnWidth * m_data.m_seriesIndex; |
|
136 | qreal left = 0.25 * columnWidth + columnWidth * m_data.m_seriesIndex; | |
135 | qreal right = 0.75 * columnWidth + columnWidth * m_data.m_seriesIndex; |
|
137 | qreal right = 0.75 * columnWidth + columnWidth * m_data.m_seriesIndex; | |
136 | qreal middle = 0.5 * columnWidth + columnWidth * m_data.m_seriesIndex; |
|
138 | qreal middle = 0.5 * columnWidth + columnWidth * m_data.m_seriesIndex; | |
137 |
|
139 | |||
138 | //whisker = 0.35 0.75 |
|
140 | //whisker = 0.35 0.75 | |
139 |
|
141 | |||
140 | // Upper whisker |
|
142 | // Upper whisker | |
141 | path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme); |
|
143 | path.moveTo(left + 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); |
|
144 | path.lineTo(right + 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); |
|
145 | path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme); | |
144 | path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile); |
|
146 | path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile); | |
145 | path.closeSubpath(); |
|
147 | path.closeSubpath(); | |
146 |
|
148 | |||
147 | // Middle Box |
|
149 | // Middle Box | |
148 | path.addRect(left + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile, |
|
150 | path.addRect(left + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile, | |
149 | 0.5 * columnWidth, m_data.m_upperQuartile - m_data.m_lowerQuartile); |
|
151 | 0.5 * columnWidth, m_data.m_upperQuartile - m_data.m_lowerQuartile); | |
150 |
|
152 | |||
151 | // Median/mean line |
|
153 | // Median/mean line | |
152 | path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_median); |
|
154 | path.moveTo(left + 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); |
|
155 | path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_median); | |
154 |
|
156 | |||
155 | // Lower whisker |
|
157 | // Lower whisker | |
156 | path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme); |
|
158 | path.moveTo(left + 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); |
|
159 | path.lineTo(right + 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); |
|
160 | path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme); | |
159 | path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerQuartile); |
|
161 | path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerQuartile); | |
160 | path.closeSubpath(); |
|
162 | path.closeSubpath(); | |
161 |
|
163 | |||
162 | m_boxPath = path; |
|
164 | m_boxPath = path; | |
163 |
|
165 | |||
164 | updateBoundingRect(); |
|
166 | updateBoundingRect(); | |
165 |
|
167 | |||
166 | // qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY); |
|
168 | // qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY); | |
167 | // qreal scaleX = m_domainSize.width() / m_data.m_boxItems; |
|
169 | // qreal scaleX = m_domainSize.width() / m_data.m_boxItems; | |
168 | // QRectF br = path.boundingRect(); |
|
170 | // QRectF br = path.boundingRect(); | |
169 | // m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY); |
|
171 | // m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY); | |
170 |
|
172 | |||
171 | if (m_data.m_index == 5) { |
|
173 | if (m_data.m_index == 5) { | |
172 | //qDebug() << "myValue = " << myValue; |
|
174 | //qDebug() << "myValue = " << myValue; | |
173 | //qDebug() << "m_data.m_upperExtreme" << m_data.m_upperExtreme; |
|
175 | //qDebug() << "m_data.m_upperExtreme" << m_data.m_upperExtreme; | |
174 | //qDebug() << "m_boundingRect = " << m_boundingRect; |
|
176 | //qDebug() << "m_boundingRect = " << m_boundingRect; | |
175 | // qDebug() << "x = " << m_boundingRect.x() << ", y = " << m_boundingRect.y() << ", width = " |
|
177 | // qDebug() << "x = " << m_boundingRect.x() << ", y = " << m_boundingRect.y() << ", width = " | |
176 | // << m_boundingRect.width() << ", height = " << m_boundingRect.height(); |
|
178 | // << m_boundingRect.width() << ", height = " << m_boundingRect.height(); | |
177 | } |
|
179 | } | |
178 | } |
|
180 | } | |
179 |
|
181 | |||
180 | void BoxWhiskers::updateBoundingRect() |
|
182 | void BoxWhiskers::updateBoundingRect() | |
181 | { |
|
183 | { | |
182 | qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY); |
|
184 | qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY); | |
183 | qreal scaleX = m_domainSize.width() / m_data.m_boxItems; |
|
185 | qreal scaleX = m_domainSize.width() / m_data.m_boxItems; | |
184 | QRectF br = m_boxPath.boundingRect(); |
|
186 | QRectF br = m_boxPath.boundingRect(); | |
185 | m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY); |
|
187 | m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY); | |
186 | } |
|
188 | } | |
187 |
|
189 | |||
188 | #include "moc_boxwhiskers_p.cpp" |
|
190 | #include "moc_boxwhiskers_p.cpp" | |
189 |
|
191 | |||
190 | QTCOMMERCIALCHART_END_NAMESPACE |
|
192 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,285 +1,283 | |||||
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 "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 "boxplotchartitem_p.h" |
|
24 | #include "boxplotchartitem_p.h" | |
25 | #include "chartdataset_p.h" |
|
25 | #include "chartdataset_p.h" | |
26 | #include "charttheme_p.h" |
|
26 | #include "charttheme_p.h" | |
27 | #include "qvalueaxis.h" |
|
27 | #include "qvalueaxis.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "boxplotanimation_p.h" |
|
29 | #include "boxplotanimation_p.h" | |
30 | #include "qchart_p.h" |
|
30 | #include "qchart_p.h" | |
31 |
|
31 | |||
32 | #include <QDebug> |
|
32 | #include <QDebug> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \class QBoxPlotSeries |
|
37 | \class QBoxPlotSeries | |
38 | \brief Series for creating stacked bar chart |
|
38 | \brief Series for creating stacked bar chart | |
39 | \mainclass |
|
39 | \mainclass | |
40 |
|
40 | |||
41 | QBoxPlotSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
41 | QBoxPlotSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
42 | as stacks, where bars in same category are stacked on top of each other. |
|
42 | as stacks, where bars in same category are stacked on top of each other. | |
43 | QBoxPlotSeries groups the data from sets to categories, which are defined by QStringList. |
|
43 | QBoxPlotSeries groups the data from sets to categories, which are defined by QStringList. | |
44 |
|
44 | |||
45 | See the \l {BoxPlotChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
|
45 | See the \l {BoxPlotChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. | |
46 | \image examples_boxplotchart.png |
|
46 | \image examples_boxplotchart.png | |
47 |
|
47 | |||
48 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries |
|
48 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | \qmlclass BoxPlotSeries QBoxPlotSeries |
|
52 | \qmlclass BoxPlotSeries QBoxPlotSeries | |
53 | \inherits AbstractBarSeries |
|
53 | \inherits AbstractBarSeries | |
54 |
|
54 | |||
55 | The following QML shows how to create a simple stacked bar chart: |
|
55 | The following QML shows how to create a simple stacked bar chart: | |
56 | \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1 |
|
56 | \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1 | |
57 | \beginfloatleft |
|
57 | \beginfloatleft | |
58 | \image demos_qmlchart7.png |
|
58 | \image demos_qmlchart7.png | |
59 | \endfloat |
|
59 | \endfloat | |
60 | \clearfloat |
|
60 | \clearfloat | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | Constructs empty QBoxPlotSeries. |
|
64 | Constructs empty QBoxPlotSeries. | |
65 | QBoxPlotSeries is QObject which is a child of a \a parent. |
|
65 | QBoxPlotSeries is QObject which is a child of a \a parent. | |
66 | */ |
|
66 | */ | |
67 | QBoxPlotSeries::QBoxPlotSeries(QObject *parent) |
|
67 | QBoxPlotSeries::QBoxPlotSeries(QObject *parent) | |
68 | : QAbstractBarSeries(*new QBoxPlotSeriesPrivate(this), parent) |
|
68 | : QAbstractBarSeries(*new QBoxPlotSeriesPrivate(this), parent) | |
69 | { |
|
69 | { | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | Destructor. Removes series from chart. |
|
73 | Destructor. Removes series from chart. | |
74 | */ |
|
74 | */ | |
75 | QBoxPlotSeries::~QBoxPlotSeries() |
|
75 | QBoxPlotSeries::~QBoxPlotSeries() | |
76 | { |
|
76 | { | |
77 | qDebug() << "QBoxPlotSeries::~QBoxPlotSeries"; |
|
77 | qDebug() << "QBoxPlotSeries::~QBoxPlotSeries"; | |
78 |
|
78 | |||
79 | Q_D(QBoxPlotSeries); |
|
79 | Q_D(QBoxPlotSeries); | |
80 | if (d->m_chart) |
|
80 | if (d->m_chart) | |
81 | d->m_chart->removeSeries(this); |
|
81 | d->m_chart->removeSeries(this); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | Returns QChartSeries::SeriesTypeBoxPlot. |
|
85 | Returns QChartSeries::SeriesTypeBoxPlot. | |
86 | */ |
|
86 | */ | |
87 | QAbstractSeries::SeriesType QBoxPlotSeries::type() const |
|
87 | QAbstractSeries::SeriesType QBoxPlotSeries::type() const | |
88 | { |
|
88 | { | |
89 | return QAbstractSeries::SeriesTypeBoxPlot; |
|
89 | return QAbstractSeries::SeriesTypeBoxPlot; | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | void QBoxPlotSeries::setBrush(const QBrush &brush) |
|
92 | void QBoxPlotSeries::setBrush(const QBrush &brush) | |
93 | { |
|
93 | { | |
94 | Q_D(QBoxPlotSeries); |
|
94 | Q_D(QBoxPlotSeries); | |
95 |
|
95 | |||
96 | if (d->m_brush != brush) { |
|
96 | if (d->m_brush != brush) { | |
97 | d->m_brush = brush; |
|
97 | d->m_brush = brush; | |
98 | emit d->updated(); |
|
98 | emit d->updated(); | |
99 | } |
|
99 | } | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | QBrush QBoxPlotSeries::brush() const |
|
102 | QBrush QBoxPlotSeries::brush() const | |
103 | { |
|
103 | { | |
104 | Q_D(const QBoxPlotSeries); |
|
104 | Q_D(const QBoxPlotSeries); | |
105 |
|
105 | |||
106 | return d->m_brush; |
|
106 | return d->m_brush; | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void QBoxPlotSeries::setPen(const QPen &pen) |
|
109 | void QBoxPlotSeries::setPen(const QPen &pen) | |
110 | { |
|
110 | { | |
111 | Q_D(QBoxPlotSeries); |
|
111 | Q_D(QBoxPlotSeries); | |
112 |
|
112 | |||
113 | if (d->m_pen != pen) { |
|
113 | if (d->m_pen != pen) { | |
114 | d->m_pen = pen; |
|
114 | d->m_pen = pen; | |
115 | emit d->updated(); |
|
115 | emit d->updated(); | |
116 | } |
|
116 | } | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | QPen QBoxPlotSeries::pen() const |
|
119 | QPen QBoxPlotSeries::pen() const | |
120 | { |
|
120 | { | |
121 | Q_D(const QBoxPlotSeries); |
|
121 | Q_D(const QBoxPlotSeries); | |
122 |
|
122 | |||
123 | return d->m_pen; |
|
123 | return d->m_pen; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
126 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
127 |
|
127 | |||
128 | QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q) |
|
128 | QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q) | |
129 | : QAbstractBarSeriesPrivate(q), |
|
129 | : QAbstractBarSeriesPrivate(q), | |
130 | m_pen(QPen(Qt::NoPen)), |
|
130 | m_pen(QPen(Qt::NoPen)), | |
131 | m_brush(QBrush(Qt::NoBrush)) |
|
131 | m_brush(QBrush(Qt::NoBrush)) | |
132 | { |
|
132 | { | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate() |
|
135 | QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate() | |
136 | { |
|
136 | { | |
137 | qDebug() << "QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate()"; |
|
137 | qDebug() << "QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate()"; | |
138 | disconnect(this, 0, 0, 0); |
|
138 | disconnect(this, 0, 0, 0); | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | void QBoxPlotSeriesPrivate::initializeDomain() |
|
141 | void QBoxPlotSeriesPrivate::initializeDomain() | |
142 | { |
|
142 | { | |
143 | qreal minX(domain()->minX()); |
|
143 | qreal minX(domain()->minX()); | |
144 | qreal minY(domain()->minY()); |
|
144 | qreal minY(domain()->minY()); | |
145 | qreal maxX(domain()->maxX()); |
|
145 | qreal maxX(domain()->maxX()); | |
146 | qreal maxY(domain()->maxY()); |
|
146 | qreal maxY(domain()->maxY()); | |
147 |
|
147 | |||
148 | qreal x = categoryCount(); |
|
148 | qreal x = categoryCount(); | |
149 | minX = qMin(minX, - (qreal)0.5); |
|
149 | minX = qMin(minX, - (qreal)0.5); | |
150 | minY = qMin(minY, bottom()); |
|
150 | minY = qMin(minY, bottom()); | |
151 | maxX = qMax(maxX, x - (qreal)0.5); |
|
151 | maxX = qMax(maxX, x - (qreal)0.5); | |
152 | //maxY = qMax(maxY, top()); |
|
152 | //maxY = qMax(maxY, top()); | |
153 | maxY = qMax(maxY, max()); |
|
153 | maxY = qMax(maxY, max()); | |
154 |
|
154 | |||
155 | domain()->setRange(minX, maxX, minY, maxY); |
|
155 | domain()->setRange(minX, maxX, minY, maxY); | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
158 | void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
159 | { |
|
159 | { | |
160 | Q_Q(QBoxPlotSeries); |
|
160 | Q_Q(QBoxPlotSeries); | |
161 |
|
161 | |||
162 | BoxPlotChartItem *boxPlot = new BoxPlotChartItem(q,parent); |
|
162 | BoxPlotChartItem *boxPlot = new BoxPlotChartItem(q,parent); | |
163 | m_item.reset(boxPlot); |
|
163 | m_item.reset(boxPlot); | |
164 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
164 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
165 |
|
165 | |||
166 | if (m_chart) { |
|
166 | if (m_chart) { | |
167 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesChange(QAbstractSeries*)) ); |
|
167 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesChange(QAbstractSeries*)) ); | |
168 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) ); |
|
168 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) ); | |
169 |
|
169 | |||
170 | QList<QAbstractSeries *> serieses = m_chart->series(); |
|
170 | QList<QAbstractSeries *> serieses = m_chart->series(); | |
171 | boxPlot->m_seriesCount = serieses.count(); |
|
|||
172 |
|
171 | |||
173 | // Tries to find this series from the Chart's list of serieses and deduce the index |
|
172 | // Tries to find this series from the Chart's list of serieses and deduce the index | |
174 | int index = 0; |
|
173 | int index = 0; | |
175 | foreach (QAbstractSeries *s, serieses) { |
|
174 | foreach (QAbstractSeries *s, serieses) { | |
176 | if (q == static_cast<QBoxPlotSeries *>(s)) { |
|
175 | if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) { | |
177 | boxPlot->m_seriesIndex = index; |
|
176 | if (q == static_cast<QBoxPlotSeries *>(s)) { | |
178 | m_index = index; |
|
177 | boxPlot->m_seriesIndex = index; | |
|
178 | m_index = index; | |||
|
179 | } | |||
|
180 | index++; | |||
179 | } |
|
181 | } | |
180 | index++; |
|
|||
181 | } |
|
182 | } | |
|
183 | boxPlot->m_seriesCount = index; | |||
182 | } |
|
184 | } | |
183 |
|
185 | |||
184 | // Make BoxPlotChartItem to instantiate box & whisker items |
|
186 | // Make BoxPlotChartItem to instantiate box & whisker items | |
185 | boxPlot->handleDataStructureChanged(); |
|
187 | boxPlot->handleDataStructureChanged(); | |
186 | } |
|
188 | } | |
187 |
|
189 | |||
188 | void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
190 | void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |
189 | { |
|
191 | { | |
190 | Q_Q(QBoxPlotSeries); |
|
192 | Q_Q(QBoxPlotSeries); | |
191 | qDebug() << "QBoxPlotSeriesPrivate::initializeTheme"; |
|
193 | qDebug() << "QBoxPlotSeriesPrivate::initializeTheme"; | |
192 |
|
194 | |||
193 | const QList<QGradient> gradients = theme->seriesGradients(); |
|
195 | const QList<QGradient> gradients = theme->seriesGradients(); | |
194 |
|
196 | |||
195 | if (forced || m_brush == QBrush(Qt::NoBrush)) { |
|
197 | if (forced || m_brush == QBrush(Qt::NoBrush)) { | |
196 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.5); |
|
198 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.5); | |
197 | q->setBrush(brushColor); |
|
199 | q->setBrush(brushColor); | |
198 | } |
|
200 | } | |
199 |
|
201 | |||
200 | if (forced || m_pen == QPen(Qt::NoPen)) { |
|
202 | if (forced || m_pen == QPen(Qt::NoPen)) { | |
201 | QPen pen = theme->outlinePen(); |
|
203 | QPen pen = theme->outlinePen(); | |
202 | pen.setCosmetic(true); |
|
204 | pen.setCosmetic(true); | |
203 |
|
||||
204 | // QPen pen; |
|
|||
205 | // pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 1.0)); |
|
|||
206 | // pen.setWidthF(2.0); |
|
|||
207 | // pen.setCosmetic(true); |
|
|||
208 |
|
||||
209 | q->setPen(pen); |
|
205 | q->setPen(pen); | |
210 | } |
|
206 | } | |
211 | } |
|
207 | } | |
212 |
|
208 | |||
213 | void QBoxPlotSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) |
|
209 | void QBoxPlotSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |
214 | { |
|
210 | { | |
215 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); |
|
211 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); | |
216 | Q_ASSERT(item); |
|
212 | Q_ASSERT(item); | |
217 | if (options.testFlag(QChart::SeriesAnimations)) { |
|
213 | if (options.testFlag(QChart::SeriesAnimations)) { | |
218 | item->setAnimation(new BoxPlotAnimation(item)); |
|
214 | item->setAnimation(new BoxPlotAnimation(item)); | |
219 | }else{ |
|
215 | }else{ | |
220 | item->setAnimation((BoxPlotAnimation *)0); |
|
216 | item->setAnimation((BoxPlotAnimation *)0); | |
221 | } |
|
217 | } | |
222 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
218 | QAbstractSeriesPrivate::initializeAnimations(options); | |
223 | } |
|
219 | } | |
224 |
|
220 | |||
225 | QList<QLegendMarker*> QBoxPlotSeriesPrivate::createLegendMarkers(QLegend *legend) |
|
221 | QList<QLegendMarker*> QBoxPlotSeriesPrivate::createLegendMarkers(QLegend *legend) | |
226 | { |
|
222 | { | |
227 | Q_Q(QBoxPlotSeries); |
|
223 | Q_Q(QBoxPlotSeries); | |
228 | QList<QLegendMarker*> list; |
|
224 | QList<QLegendMarker*> list; | |
229 | return list << new QBoxPlotLegendMarker(q, legend); |
|
225 | return list << new QBoxPlotLegendMarker(q, legend); | |
230 | } |
|
226 | } | |
231 |
|
227 | |||
232 | void QBoxPlotSeriesPrivate::handleSeriesRemove(QAbstractSeries *series) |
|
228 | void QBoxPlotSeriesPrivate::handleSeriesRemove(QAbstractSeries *series) | |
233 | { |
|
229 | { | |
234 | qDebug() << "QBoxPlotSeriesPrivate::handleSeriesRemove"; |
|
230 | qDebug() << "QBoxPlotSeriesPrivate::handleSeriesRemove"; | |
235 | Q_Q(QBoxPlotSeries); |
|
231 | Q_Q(QBoxPlotSeries); | |
236 |
|
232 | |||
237 | QBoxPlotSeries *removedSeries = static_cast<QBoxPlotSeries *>(series); |
|
233 | QBoxPlotSeries *removedSeries = static_cast<QBoxPlotSeries *>(series); | |
238 | QObject::disconnect(m_chart->d_ptr->m_dataset, 0, removedSeries->d_func(), 0); |
|
234 | QObject::disconnect(m_chart->d_ptr->m_dataset, 0, removedSeries->d_func(), 0); | |
239 |
|
235 | |||
240 | // Test if series removed is me, then don't do anything |
|
236 | // Test if series removed is me, then don't do anything | |
241 | if (q != removedSeries) { |
|
237 | if (q != removedSeries) { | |
242 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); |
|
238 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); | |
243 | if (item) { |
|
239 | if (item) { | |
244 | item->m_seriesCount = item->m_seriesCount - 1; |
|
240 | item->m_seriesCount = item->m_seriesCount - 1; | |
245 | if (removedSeries->d_func()->m_index < m_index) { |
|
241 | if (removedSeries->d_func()->m_index < m_index) { | |
246 | m_index--; |
|
242 | m_index--; | |
247 | item->m_seriesIndex = m_index; |
|
243 | item->m_seriesIndex = m_index; | |
248 | } |
|
244 | } | |
249 |
|
245 | |||
250 | item->handleDataStructureChanged(); |
|
246 | item->handleDataStructureChanged(); | |
251 | } |
|
247 | } | |
252 | } |
|
248 | } | |
253 | } |
|
249 | } | |
254 |
|
250 | |||
255 | void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series) |
|
251 | void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series) | |
256 | { |
|
252 | { | |
257 | Q_UNUSED(series); |
|
253 | Q_UNUSED(series); | |
258 |
|
254 | |||
259 | Q_Q(QBoxPlotSeries); |
|
255 | Q_Q(QBoxPlotSeries); | |
260 |
|
256 | |||
261 | BoxPlotChartItem *boxPlot = static_cast<BoxPlotChartItem *>(m_item.data()); |
|
257 | BoxPlotChartItem *boxPlot = static_cast<BoxPlotChartItem *>(m_item.data()); | |
262 |
|
258 | |||
263 | if (m_chart) { |
|
259 | if (m_chart) { | |
264 | QList<QAbstractSeries *> serieses = m_chart->series(); |
|
260 | QList<QAbstractSeries *> serieses = m_chart->series(); | |
265 | boxPlot->m_seriesCount = serieses.count(); |
|
|||
266 |
|
261 | |||
267 | // Tries to find this series from the Chart's list of serieses and deduce the index |
|
262 | // Tries to find this series from the Chart's list of serieses and deduce the index | |
268 | int index = 0; |
|
263 | int index = 0; | |
269 | foreach (QAbstractSeries *s, serieses) { |
|
264 | foreach (QAbstractSeries *s, serieses) { | |
270 | if (q == static_cast<QBoxPlotSeries *>(s)) { |
|
265 | if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) { | |
271 | boxPlot->m_seriesIndex = index; |
|
266 | if (q == static_cast<QBoxPlotSeries *>(s)) { | |
272 | m_index = index; |
|
267 | boxPlot->m_seriesIndex = index; | |
|
268 | m_index = index; | |||
|
269 | } | |||
|
270 | index++; | |||
273 | } |
|
271 | } | |
274 | index++; |
|
|||
275 | } |
|
272 | } | |
|
273 | boxPlot->m_seriesCount = index; | |||
276 | } |
|
274 | } | |
277 |
|
275 | |||
278 | boxPlot->handleDataStructureChanged(); |
|
276 | boxPlot->handleDataStructureChanged(); | |
279 | } |
|
277 | } | |
280 |
|
278 | |||
281 | #include "moc_qboxplotseries.cpp" |
|
279 | #include "moc_qboxplotseries.cpp" | |
282 | #include "moc_qboxplotseries_p.cpp" |
|
280 | #include "moc_qboxplotseries_p.cpp" | |
283 |
|
281 | |||
284 | QTCOMMERCIALCHART_END_NAMESPACE |
|
282 | QTCOMMERCIALCHART_END_NAMESPACE | |
285 |
|
283 |
@@ -1,303 +1,359 | |||||
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 | // Create add a single box button |
|
74 | // Create add a single box button | |
75 | QPushButton *addBoxButton = new QPushButton("Add a box"); |
|
75 | QPushButton *addBoxButton = new QPushButton("Add a box"); | |
76 | connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox())); |
|
76 | connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox())); | |
77 | grid->addWidget(addBoxButton, rowPos++, 1); |
|
77 | grid->addWidget(addBoxButton, rowPos++, 1); | |
78 |
|
78 | |||
|
79 | // Create insert a box button | |||
|
80 | QPushButton *insertBoxButton = new QPushButton("Insert a box"); | |||
|
81 | connect(insertBoxButton, SIGNAL(clicked()), this, SLOT(insertBox())); | |||
|
82 | grid->addWidget(insertBoxButton, rowPos++, 1); | |||
|
83 | ||||
79 | // Create add a single box button |
|
84 | // Create add a single box button | |
80 | QPushButton *removeBoxButton = new QPushButton("Remove a box"); |
|
85 | QPushButton *removeBoxButton = new QPushButton("Remove a box"); | |
81 | connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox())); |
|
86 | connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox())); | |
82 | grid->addWidget(removeBoxButton, rowPos++, 1); |
|
87 | grid->addWidget(removeBoxButton, rowPos++, 1); | |
83 |
|
88 | |||
|
89 | // Create clear button | |||
|
90 | QPushButton *clearButton = new QPushButton("Clear"); | |||
|
91 | connect(clearButton, SIGNAL(clicked()), this, SLOT(clear())); | |||
|
92 | grid->addWidget(clearButton, rowPos++, 1); | |||
|
93 | ||||
|
94 | // Create set brush button | |||
|
95 | QPushButton *setBrushButton = new QPushButton("Set brush"); | |||
|
96 | connect(setBrushButton, SIGNAL(clicked()), this, SLOT(setBrush())); | |||
|
97 | grid->addWidget(setBrushButton, rowPos++, 1); | |||
|
98 | ||||
84 | initThemeCombo(grid); |
|
99 | initThemeCombo(grid); | |
85 | initCheckboxes(grid); |
|
100 | initCheckboxes(grid); | |
86 |
|
101 | |||
87 | m_model = new CustomTableModel; |
|
102 | m_model = new CustomTableModel; | |
88 | QTableView *tableView = new QTableView; |
|
103 | QTableView *tableView = new QTableView; | |
89 | tableView->setModel(m_model); |
|
104 | tableView->setModel(m_model); | |
90 | tableView->setMaximumWidth(200); |
|
105 | tableView->setMaximumWidth(200); | |
91 | grid->addWidget(tableView, rowPos++, 0, 3, 2, Qt::AlignLeft); |
|
106 | grid->addWidget(tableView, rowPos++, 0, 3, 2, Qt::AlignLeft); | |
92 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
|
107 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | |
93 | tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
|
108 | tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); | |
94 | tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
|
109 | tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); | |
95 | #else |
|
110 | #else | |
96 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
111 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); | |
97 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
112 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); | |
98 | #endif |
|
113 | #endif | |
99 |
|
114 | |||
100 | // add row with empty label to make all the other rows static |
|
115 | // add row with empty label to make all the other rows static | |
101 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
116 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
102 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
117 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
103 |
|
118 | |||
104 | // Create chart view with the chart |
|
119 | // Create chart view with the chart | |
105 | m_chartView = new QChartView(m_chart, this); |
|
120 | m_chartView = new QChartView(m_chart, this); | |
106 | //m_chartView->setRubberBand(QChartView::HorizonalRubberBand); |
|
121 | //m_chartView->setRubberBand(QChartView::HorizonalRubberBand); | |
107 |
|
122 | |||
108 | // Another grid layout as a main layout |
|
123 | // Another grid layout as a main layout | |
109 | QGridLayout *mainLayout = new QGridLayout(); |
|
124 | QGridLayout *mainLayout = new QGridLayout(); | |
110 | mainLayout->addLayout(grid, 0, 0); |
|
125 | mainLayout->addLayout(grid, 0, 0); | |
111 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
126 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
112 | setLayout(mainLayout); |
|
127 | setLayout(mainLayout); | |
113 |
|
128 | |||
114 | legendToggled(false); |
|
129 | legendToggled(false); | |
115 | animationToggled(false); |
|
130 | animationToggled(false); | |
116 | } |
|
131 | } | |
117 |
|
132 | |||
118 | // Combo box for selecting theme |
|
133 | // Combo box for selecting theme | |
119 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
134 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
120 | { |
|
135 | { | |
121 | QComboBox *chartTheme = new QComboBox(); |
|
136 | QComboBox *chartTheme = new QComboBox(); | |
122 | chartTheme->addItem("Default"); |
|
137 | chartTheme->addItem("Default"); | |
123 | chartTheme->addItem("Light"); |
|
138 | chartTheme->addItem("Light"); | |
124 | chartTheme->addItem("Blue Cerulean"); |
|
139 | chartTheme->addItem("Blue Cerulean"); | |
125 | chartTheme->addItem("Dark"); |
|
140 | chartTheme->addItem("Dark"); | |
126 | chartTheme->addItem("Brown Sand"); |
|
141 | chartTheme->addItem("Brown Sand"); | |
127 | chartTheme->addItem("Blue NCS"); |
|
142 | chartTheme->addItem("Blue NCS"); | |
128 | chartTheme->addItem("High Contrast"); |
|
143 | chartTheme->addItem("High Contrast"); | |
129 | chartTheme->addItem("Blue Icy"); |
|
144 | chartTheme->addItem("Blue Icy"); | |
130 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
145 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
131 | this, SLOT(changeChartTheme(int))); |
|
146 | this, SLOT(changeChartTheme(int))); | |
132 | grid->addWidget(new QLabel("Chart theme:"), rowPos, 0); |
|
147 | grid->addWidget(new QLabel("Chart theme:"), rowPos, 0); | |
133 | grid->addWidget(chartTheme, rowPos++, 1); |
|
148 | grid->addWidget(chartTheme, rowPos++, 1); | |
134 | } |
|
149 | } | |
135 |
|
150 | |||
136 | // Different check boxes for customizing chart |
|
151 | // Different check boxes for customizing chart | |
137 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
152 | void MainWidget::initCheckboxes(QGridLayout *grid) | |
138 | { |
|
153 | { | |
139 | QCheckBox *animationCheckBox = new QCheckBox("Animation"); |
|
154 | QCheckBox *animationCheckBox = new QCheckBox("Animation"); | |
140 | connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool))); |
|
155 | connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool))); | |
141 | animationCheckBox->setChecked(false); |
|
156 | animationCheckBox->setChecked(false); | |
142 | grid->addWidget(animationCheckBox, rowPos++, 0); |
|
157 | grid->addWidget(animationCheckBox, rowPos++, 0); | |
143 |
|
158 | |||
144 | QCheckBox *legendCheckBox = new QCheckBox("Legend"); |
|
159 | QCheckBox *legendCheckBox = new QCheckBox("Legend"); | |
145 | connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool))); |
|
160 | connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool))); | |
146 | legendCheckBox->setChecked(false); |
|
161 | legendCheckBox->setChecked(false); | |
147 | grid->addWidget(legendCheckBox, rowPos++, 0); |
|
162 | grid->addWidget(legendCheckBox, rowPos++, 0); | |
148 |
|
163 | |||
149 | QCheckBox *titleCheckBox = new QCheckBox("Title"); |
|
164 | QCheckBox *titleCheckBox = new QCheckBox("Title"); | |
150 | connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool))); |
|
165 | connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool))); | |
151 | titleCheckBox->setChecked(false); |
|
166 | titleCheckBox->setChecked(false); | |
152 | grid->addWidget(titleCheckBox, rowPos++, 0); |
|
167 | grid->addWidget(titleCheckBox, rowPos++, 0); | |
153 |
|
168 | |||
154 | QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper"); |
|
169 | QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper"); | |
155 | connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool))); |
|
170 | connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool))); | |
156 | modelMapperCheckBox->setChecked(false); |
|
171 | modelMapperCheckBox->setChecked(false); | |
157 | grid->addWidget(modelMapperCheckBox, rowPos++, 0); |
|
172 | grid->addWidget(modelMapperCheckBox, rowPos++, 0); | |
158 |
|
173 | |||
159 | } |
|
174 | } | |
160 |
|
175 | |||
161 | void MainWidget::addSeries() |
|
176 | void MainWidget::addSeries() | |
162 | { |
|
177 | { | |
163 | qDebug() << "BoxPlotTester::MainWidget::addSeries()"; |
|
178 | qDebug() << "BoxPlotTester::MainWidget::addSeries()"; | |
164 |
|
179 | |||
165 | if (nSeries > 9) |
|
180 | if (nSeries > 9) | |
166 | return; |
|
181 | return; | |
167 |
|
182 | |||
168 | // Initial data |
|
183 | // Initial data | |
169 | //![1] |
|
184 | //![1] | |
170 | QBarSet *set0 = new QBarSet("Jan"); |
|
185 | QBarSet *set0 = new QBarSet("Jan"); | |
171 | QBarSet *set1 = new QBarSet("Feb"); |
|
186 | QBarSet *set1 = new QBarSet("Feb"); | |
172 | QBarSet *set2 = new QBarSet("Mar"); |
|
187 | QBarSet *set2 = new QBarSet("Mar"); | |
173 | QBarSet *set3 = new QBarSet("Apr"); |
|
188 | QBarSet *set3 = new QBarSet("Apr"); | |
174 | QBarSet *set4 = new QBarSet("May"); |
|
189 | QBarSet *set4 = new QBarSet("May"); | |
175 | QBarSet *set5 = new QBarSet("Jun"); |
|
190 | QBarSet *set5 = new QBarSet("Jun"); | |
176 |
|
191 | |||
177 | // low bot med top upp |
|
192 | // low bot med top upp | |
178 | *set0 << 3 << 4 << 4.4 << 6 << 7; |
|
193 | *set0 << 3 << 4 << 4.4 << 6 << 7; | |
179 | *set1 << 5 << 6 << 7.5 << 8 << 12; |
|
194 | *set1 << 5 << 6 << 7.5 << 8 << 12; | |
180 | *set2 << 3 << 5 << 5.7 << 8 << 9; |
|
195 | *set2 << 3 << 5 << 5.7 << 8 << 9; | |
181 | *set3 << 5 << 6 << 6.8 << 7 << 8; |
|
196 | *set3 << 5 << 6 << 6.8 << 7 << 8; | |
182 | *set4 << 4 << 5 << 5.2 << 6 << 7; |
|
197 | *set4 << 4 << 5 << 5.2 << 6 << 7; | |
183 | *set5 << 4 << 7 << 8.2 << 9 << 10; |
|
198 | *set5 << 4 << 7 << 8.2 << 9 << 10; | |
184 |
|
199 | |||
185 | m_series[nSeries] = new QBoxPlotSeries(); |
|
200 | m_series[nSeries] = new QBoxPlotSeries(); | |
186 | m_series[nSeries]->append(set0); |
|
201 | m_series[nSeries]->append(set0); | |
187 | m_series[nSeries]->append(set1); |
|
202 | m_series[nSeries]->append(set1); | |
188 | m_series[nSeries]->append(set2); |
|
203 | m_series[nSeries]->append(set2); | |
189 | m_series[nSeries]->append(set3); |
|
204 | m_series[nSeries]->append(set3); | |
190 | m_series[nSeries]->append(set4); |
|
205 | m_series[nSeries]->append(set4); | |
191 | m_series[nSeries]->append(set5); |
|
206 | m_series[nSeries]->append(set5); | |
192 | m_series[nSeries]->type(); |
|
207 | m_series[nSeries]->type(); | |
193 | m_series[nSeries]->setName("Box & Whiskers"); |
|
208 | m_series[nSeries]->setName("Box & Whiskers"); | |
194 |
|
209 | |||
195 | m_chart->addSeries(m_series[nSeries]); |
|
210 | m_chart->addSeries(m_series[nSeries]); | |
196 |
|
211 | |||
197 | if (nSeries == 0) { |
|
212 | if (nSeries == 0) { | |
198 | QStringList categories; |
|
213 | QStringList categories; | |
199 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
214 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
200 | m_axis = new QBarCategoryAxis(); |
|
215 | m_axis = new QBarCategoryAxis(); | |
201 | m_axis->append(categories); |
|
216 | m_axis->append(categories); | |
202 | m_chart->createDefaultAxes(); |
|
217 | m_chart->createDefaultAxes(); | |
203 | m_chart->setAxisX(m_axis, m_series[nSeries]); |
|
218 | m_chart->setAxisX(m_axis, m_series[nSeries]); | |
204 | } |
|
219 | } | |
205 |
|
220 | |||
206 | nSeries++; |
|
221 | nSeries++; | |
207 | } |
|
222 | } | |
208 |
|
223 | |||
209 | void MainWidget::removeSeries() |
|
224 | void MainWidget::removeSeries() | |
210 | { |
|
225 | { | |
|
226 | qDebug() << "BoxPlotTester::MainWidget::removeSeries()"; | |||
|
227 | ||||
211 | if (nSeries > 0) { |
|
228 | if (nSeries > 0) { | |
212 | nSeries--; |
|
229 | nSeries--; | |
213 | m_chart->removeSeries(m_series[nSeries]); |
|
230 | m_chart->removeSeries(m_series[nSeries]); | |
214 | delete m_series[nSeries]; |
|
231 | delete m_series[nSeries]; | |
215 | } else { |
|
232 | } else { | |
216 | qDebug() << "Create a series first"; |
|
233 | qDebug() << "Create a series first"; | |
217 | } |
|
234 | } | |
218 | } |
|
235 | } | |
219 |
|
236 | |||
220 | void MainWidget::addBox() |
|
237 | void MainWidget::addBox() | |
221 | { |
|
238 | { | |
222 | qDebug() << "BoxPlotTester::MainWidget::addBox()"; |
|
239 | qDebug() << "BoxPlotTester::MainWidget::addBox()"; | |
223 |
|
240 | |||
224 | if (nSeries > 0) { |
|
241 | if (nSeries > 0) { | |
225 | QBarSet *newSet = new QBarSet("New"); |
|
242 | QBarSet *newSet = new QBarSet("New"); | |
226 | *newSet << 5 << 6 << 6.8 << 7 << 8; |
|
243 | *newSet << 5 << 6 << 6.8 << 7 << 8; | |
227 |
|
244 | |||
228 | m_series[0]->append(newSet); |
|
245 | m_series[0]->append(newSet); | |
229 |
|
246 | |||
230 | m_axis->append(addCategories[nNewBoxes]); |
|
247 | m_axis->append(addCategories[nNewBoxes]); | |
231 |
|
248 | |||
232 | nNewBoxes++; |
|
249 | nNewBoxes++; | |
233 | } |
|
250 | } | |
234 | } |
|
251 | } | |
235 |
|
252 | |||
|
253 | void MainWidget::insertBox() | |||
|
254 | { | |||
|
255 | qDebug() << "BoxPlotTester::MainWidget::insertBox()"; | |||
|
256 | ||||
|
257 | if (nSeries > 0) { | |||
|
258 | QBarSet *newSet = new QBarSet("New"); | |||
|
259 | *newSet << 2 << 6 << 6.8 << 7 << 10; | |||
|
260 | ||||
|
261 | m_series[0]->insert(1, newSet); | |||
|
262 | ||||
|
263 | m_axis->append(addCategories[nNewBoxes]); | |||
|
264 | ||||
|
265 | nNewBoxes++; | |||
|
266 | } | |||
|
267 | } | |||
|
268 | ||||
236 | void MainWidget::removeBox() |
|
269 | void MainWidget::removeBox() | |
237 | { |
|
270 | { | |
238 | qDebug() << "MainWidget::removeBox"; |
|
271 | qDebug() << "BoxPlotTester::MainWidget::removeBox"; | |
239 |
|
272 | |||
240 | if (nSeries > 0) { |
|
273 | if (nSeries > 0) { | |
241 | QList<QBarSet *> sets = m_series[0]->barSets(); |
|
274 | QList<QBarSet *> sets = m_series[0]->barSets(); | |
242 | m_series[0]->remove(sets.at(m_series[0]->count() - 3)); |
|
275 | m_series[0]->remove(sets.at(m_series[0]->count() - 3)); | |
243 | } else { |
|
276 | } else { | |
244 | qDebug() << "Create a series first"; |
|
277 | qDebug() << "Create a series first"; | |
245 | } |
|
278 | } | |
246 | } |
|
279 | } | |
247 |
|
280 | |||
|
281 | void MainWidget::clear() | |||
|
282 | { | |||
|
283 | qDebug() << "BoxPlotTester::MainWidget::clear"; | |||
|
284 | ||||
|
285 | if (nSeries > 0) { | |||
|
286 | m_series[0]->clear(); | |||
|
287 | } else { | |||
|
288 | qDebug() << "Create a series first"; | |||
|
289 | } | |||
|
290 | } | |||
|
291 | ||||
|
292 | void MainWidget::setBrush() | |||
|
293 | { | |||
|
294 | qDebug() << "BoxPlotTester::MainWidget::setBrush"; | |||
|
295 | ||||
|
296 | if (nSeries > 0) { | |||
|
297 | QList<QBarSet *> sets = m_series[0]->barSets(); | |||
|
298 | sets.at(1)->setBrush(QBrush(QColor(Qt::yellow))); | |||
|
299 | } else { | |||
|
300 | qDebug() << "Create a series first"; | |||
|
301 | } | |||
|
302 | } | |||
|
303 | ||||
248 | void MainWidget::animationToggled(bool enabled) |
|
304 | void MainWidget::animationToggled(bool enabled) | |
249 | { |
|
305 | { | |
250 | qDebug() << "BoxPlotTester::Animation toggled to " << enabled; |
|
306 | qDebug() << "BoxPlotTester::Animation toggled to " << enabled; | |
251 | if (enabled) |
|
307 | if (enabled) | |
252 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
308 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
253 | else |
|
309 | else | |
254 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
310 | m_chart->setAnimationOptions(QChart::NoAnimation); | |
255 | } |
|
311 | } | |
256 |
|
312 | |||
257 | void MainWidget::legendToggled(bool enabled) |
|
313 | void MainWidget::legendToggled(bool enabled) | |
258 | { |
|
314 | { | |
259 | qDebug() << "BoxPlotTester::Legend toggled to " << enabled; |
|
315 | qDebug() << "BoxPlotTester::Legend toggled to " << enabled; | |
260 | m_chart->legend()->setVisible(enabled); |
|
316 | m_chart->legend()->setVisible(enabled); | |
261 | if (enabled) |
|
317 | if (enabled) | |
262 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
318 | m_chart->legend()->setAlignment(Qt::AlignBottom); | |
263 | } |
|
319 | } | |
264 |
|
320 | |||
265 | void MainWidget::titleToggled(bool enabled) |
|
321 | void MainWidget::titleToggled(bool enabled) | |
266 | { |
|
322 | { | |
267 | qDebug() << "BoxPlotTester::Title toggled to " << enabled; |
|
323 | qDebug() << "BoxPlotTester::Title toggled to " << enabled; | |
268 | if (enabled) |
|
324 | if (enabled) | |
269 | m_chart->setTitle("Simple boxplotchart example"); |
|
325 | m_chart->setTitle("Simple boxplotchart example"); | |
270 | else |
|
326 | else | |
271 | m_chart->setTitle(""); |
|
327 | m_chart->setTitle(""); | |
272 | } |
|
328 | } | |
273 |
|
329 | |||
274 | void MainWidget::modelMapperToggled(bool enabled) |
|
330 | void MainWidget::modelMapperToggled(bool enabled) | |
275 | { |
|
331 | { | |
276 | if (enabled) { |
|
332 | if (enabled) { | |
277 | m_series[nSeries] = new QBoxPlotSeries(); |
|
333 | m_series[nSeries] = new QBoxPlotSeries(); | |
278 |
|
334 | |||
279 | int first = 0; |
|
335 | int first = 0; | |
280 | int count = 5; |
|
336 | int count = 5; | |
281 | QVBarModelMapper *mapper = new QVBarModelMapper(this); |
|
337 | QVBarModelMapper *mapper = new QVBarModelMapper(this); | |
282 | mapper->setFirstBarSetColumn(0); |
|
338 | mapper->setFirstBarSetColumn(0); | |
283 | mapper->setLastBarSetColumn(5); |
|
339 | mapper->setLastBarSetColumn(5); | |
284 | mapper->setFirstRow(first); |
|
340 | mapper->setFirstRow(first); | |
285 | mapper->setRowCount(count); |
|
341 | mapper->setRowCount(count); | |
286 | mapper->setSeries(m_series[nSeries]); |
|
342 | mapper->setSeries(m_series[nSeries]); | |
287 | mapper->setModel(m_model); |
|
343 | mapper->setModel(m_model); | |
288 | m_chart->addSeries(m_series[nSeries]); |
|
344 | m_chart->addSeries(m_series[nSeries]); | |
289 |
|
345 | |||
290 | nSeries++; |
|
346 | nSeries++; | |
291 | } else { |
|
347 | } else { | |
292 | removeSeries(); |
|
348 | removeSeries(); | |
293 | } |
|
349 | } | |
294 | } |
|
350 | } | |
295 |
|
351 | |||
296 | void MainWidget::changeChartTheme(int themeIndex) |
|
352 | void MainWidget::changeChartTheme(int themeIndex) | |
297 | { |
|
353 | { | |
298 | qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex; |
|
354 | qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex; | |
299 | if (themeIndex == 0) |
|
355 | if (themeIndex == 0) | |
300 | m_chart->setTheme(QChart::ChartThemeLight); |
|
356 | m_chart->setTheme(QChart::ChartThemeLight); | |
301 | else |
|
357 | else | |
302 | m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1)); |
|
358 | m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1)); | |
303 | } |
|
359 | } |
@@ -1,71 +1,74 | |||||
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 insertBox(); | |||
52 | void removeBox(); |
|
53 | void removeBox(); | |
|
54 | void clear(); | |||
|
55 | void setBrush(); | |||
53 | void animationToggled(bool enabled); |
|
56 | void animationToggled(bool enabled); | |
54 | void legendToggled(bool enabled); |
|
57 | void legendToggled(bool enabled); | |
55 | void titleToggled(bool enabled); |
|
58 | void titleToggled(bool enabled); | |
56 | void modelMapperToggled(bool enabled); |
|
59 | void modelMapperToggled(bool enabled); | |
57 | void changeChartTheme(int themeIndex); |
|
60 | void changeChartTheme(int themeIndex); | |
58 |
|
61 | |||
59 | private: |
|
62 | private: | |
60 | QChart *m_chart; |
|
63 | QChart *m_chart; | |
61 | QChartView *m_chartView; |
|
64 | QChartView *m_chartView; | |
62 | QGridLayout *m_scatterLayout; |
|
65 | QGridLayout *m_scatterLayout; | |
63 | QBarCategoryAxis *m_axis; |
|
66 | QBarCategoryAxis *m_axis; | |
64 | CustomTableModel *m_model; |
|
67 | CustomTableModel *m_model; | |
65 | int rowPos; |
|
68 | int rowPos; | |
66 | int nSeries; |
|
69 | int nSeries; | |
67 | int nNewBoxes; |
|
70 | int nNewBoxes; | |
68 | QBoxPlotSeries *m_series[10]; |
|
71 | QBoxPlotSeries *m_series[10]; | |
69 | }; |
|
72 | }; | |
70 |
|
73 | |||
71 | #endif // MAINWIDGET_H |
|
74 | #endif // MAINWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now