##// END OF EJS Templates
Documentation and fix for box specific pen color...
Mika Salmela -
r2531:baa389f1ece6
parent child
Show More
@@ -1,86 +1,86
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 <QBoxSet>
25 #include <QBoxSet>
26 #include <QLegend>
26 #include <QLegend>
27 #include <QBarCategoryAxis>
27 #include <QBarCategoryAxis>
28
28
29 #include "boxdatareader.h"
29 #include "boxdatareader.h"
30
30
31 QTCOMMERCIALCHART_USE_NAMESPACE
31 QTCOMMERCIALCHART_USE_NAMESPACE
32
32
33 int main(int argc, char *argv[])
33 int main(int argc, char *argv[])
34 {
34 {
35 QApplication a(argc, argv);
35 QApplication a(argc, argv);
36 //![1]
36 //![1]
37
37
38 //![2]
38 //![2]
39 QBoxPlotSeries *series = new QBoxPlotSeries();
39 QBoxPlotSeries *series = new QBoxPlotSeries();
40 series->setName("Cargotec");
40 series->setName("Cargotec");
41 //![2]
41 //![2]
42
42
43 QFile stockData(":stock");
43 QFile stockData(":stock");
44 if (!stockData.open(QIODevice::ReadOnly | QIODevice::Text)) {
44 if (!stockData.open(QIODevice::ReadOnly | QIODevice::Text)) {
45 return 1;
45 return 1;
46 }
46 }
47
47
48 BoxDataReader dataReader(&stockData);
48 BoxDataReader dataReader(&stockData);
49 while (!dataReader.atEnd()) {
49 while (!dataReader.atEnd()) {
50 QBoxSet *set = dataReader.readBox();
50 QBoxSet *set = dataReader.readBox();
51 if (set)
51 if (set)
52 series->append(set);
52 series->append(set);
53 }
53 }
54
54
55 //![3]
55 //![3]
56 QChart *chart = new QChart();
56 QChart *chart = new QChart();
57 chart->addSeries(series);
57 chart->addSeries(series);
58 chart->setTitle("Cargotec's share deviation 2012")
58 chart->setTitle("Cargotec's share deviation in 2012");
59 chart->setAnimationOptions(QChart::SeriesAnimations);
59 chart->setAnimationOptions(QChart::SeriesAnimations);
60 //![3]
60 //![3]
61
61
62 //![4]
62 //![4]
63 chart->createDefaultAxes();
63 chart->createDefaultAxes();
64 chart->axisY()->setMin(15.0);
64 chart->axisY()->setMin(15.0);
65 //![4]
65 //![4]
66
66
67 //![5]
67 //![5]
68 chart->legend()->setVisible(true);
68 chart->legend()->setVisible(true);
69 chart->legend()->setAlignment(Qt::AlignBottom);
69 chart->legend()->setAlignment(Qt::AlignBottom);
70 //![5]
70 //![5]
71
71
72 //![6]
72 //![6]
73 QChartView *chartView = new QChartView(chart);
73 QChartView *chartView = new QChartView(chart);
74 chartView->setRenderHint(QPainter::Antialiasing);
74 chartView->setRenderHint(QPainter::Antialiasing);
75 //![6]
75 //![6]
76
76
77 //![7]
77 //![7]
78 QMainWindow window;
78 QMainWindow window;
79 window.setCentralWidget(chartView);
79 window.setCentralWidget(chartView);
80 window.resize(600, 400);
80 window.resize(600, 400);
81 window.show();
81 window.show();
82 //![7]
82 //![7]
83
83
84 return a.exec();
84 return a.exec();
85 }
85 }
86
86
@@ -1,31 +1,37
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 import QtQuick 1.1
21 import QtQuick 1.1
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.1
23
23
24 BoxSet {
24 BoxSet {
25 id: myNewBox
25 id: myNewBox
26 label: "Foo"
26 label: "Foo"
27 values: [5, 6, 7, 8, 9]
27 values: [5, 6, 7, 8, 9]
28 onPenChanged: {
29 console.log("onPenChanged")
30 }
31 onColorChanged: {
32 console.log("onColorChanged")
33 }
28 Component.onCompleted: {
34 Component.onCompleted: {
29 console.log("BoxSet completed")
35 console.log("BoxSet completed")
30 }
36 }
31 }
37 }
@@ -1,79 +1,92
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 //![1]
21 //![1]
22 import QtQuick 1.0
22 import QtQuick 1.0
23 import QtCommercial.Chart 1.1
23 import QtCommercial.Chart 1.1
24
24
25 ChartView {
25 ChartView {
26 title: "Box Plot series"
26 title: "Box Plot series"
27 width: 400
27 width: 400
28 height: 300
28 height: 300
29 theme: ChartView.ChartThemeBrownSand
29 theme: ChartView.ChartThemeBrownSand
30 legend.alignment: Qt.AlignBottom
30 legend.alignment: Qt.AlignBottom
31
31
32 //![1]
32 //![1]
33 //![2]
33 //![2]
34 BoxPlotSeries {
34 BoxPlotSeries {
35 id: plotSeries
35 id: plotSeries
36 name: "Income"
36 name: "Income"
37 //axisX: BarCategoryAxis { categories: ["Jan", "Feb", "Mar", "Apr", "May"] }
37 //axisX: BarCategoryAxis { categories: ["Jan", "Feb", "Mar", "Apr", "May"] }
38 BoxSet { values: [3, 4, 4.4, 6, 7] }
38 BoxSet { values: [3, 4, 4.4, 6, 7] }
39 BoxSet { label: "Tok"; values: [5, 6, 7.5, 8, 12] }
39 BoxSet { label: "Tok"; values: [5, 6, 7.5, 8, 12] }
40 BoxSet { label: "Kol"; values: [2, 5, 5.7, 8, 9] }
40 BoxSet { label: "Kol"; values: [2, 5, 5.7, 8, 9] }
41 BoxSet { label: "Nel"; values: [5, 6, 6.8, 7, 8] }
41 BoxSet { id: nelBox
42 BoxSet { label: "Vii"; values: [4, 5, 5.2, 6, 7] }
42 label: "Nel"
43 values: [5, 6, 6.8, 7, 8];
44 onColorChanged: {
45 console.log("onColorChanged")
46 }
47 }
48 BoxSet { label: "Vii"; values: [4, 5, 5.2, 6, 7]; color: "#aa0000" }
49 //onClicked: console.log("series onClicked " + boxset.median)
50 //onHovered: console.log("series onHovered " + status + "median = " + boxset.median)
51 onCountChanged: console.log("onCountChanged")
43 }
52 }
44 //![2]
53 //![2]
45
54
46 Rectangle {
55 Rectangle {
47 id: moreButton
56 id: moreButton
48 width: 50
57 width: 50
49 height: 50
58 height: 50
50 color: "gray"
59 color: "gray"
51 MouseArea {
60 MouseArea {
52 anchors.fill: parent
61 anchors.fill: parent
53 onClicked: {
62 onClicked: {
63 nelBox.color = "#0000aa"
54 var com = Qt.createComponent("box.qml")
64 var com = Qt.createComponent("box.qml")
55 if (com.status == Component.Ready) {
65 if (com.status == Component.Ready) {
56 var obj = com.createObject(moreButton)
66 var obj = com.createObject(moreButton)
57 obj.lowerExtreme = 1.2
67 obj.lowerExtreme = 1.2
58 console.log("lowerExtreme = " + obj.lowerExtreme)
68 console.log("lowerExtreme = " + obj.lowerExtreme)
59 obj.lowerQuartile = 2.2
69 obj.lowerQuartile = 2.2
60 console.log("lowerQuartile = " + obj.lowerQuartile)
70 console.log("lowerQuartile = " + obj.lowerQuartile)
61 obj.median = 3.2
71 obj.median = 3.2
62 console.log("median = " + obj.median)
72 console.log("median = " + obj.median)
63 obj.upperQuartile = 4.2
73 obj.upperQuartile = 4.2
64 console.log("upperQuartile = " + obj.upperQuartile)
74 console.log("upperQuartile = " + obj.upperQuartile)
65 obj.upperExtreme = 5.2
75 obj.upperExtreme = 5.2
66 console.log("upperExtreme = " + obj.upperExtreme)
76 console.log("upperExtreme = " + obj.upperExtreme)
67 obj.label = "mik"
77 obj.label = "mik"
68 console.log("label = " + obj.label)
78 console.log("label = " + obj.label)
69 plotSeries.append(obj)
79 plotSeries.append(obj)
80 obj.color = "#aa0000"
81 console.log("color = " + obj.color)
82 obj.borderColor = "#00aa00"
70 } else {
83 } else {
71 console.log(com.errorString())
84 console.log(com.errorString())
72 }
85 }
73 }
86 }
74 }
87 }
75 }
88 }
76
89
77 //![3]
90 //![3]
78 }
91 }
79 //![3]
92 //![3]
@@ -1,124 +1,134
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 "declarativebarseries.h"
21 #include "declarativebarseries.h"
22 #include "declarativeboxplotseries.h"
22 #include "declarativeboxplotseries.h"
23 #include "qboxset.h"
23 #include "qboxset.h"
24 #include "qvboxplotmodelmapper.h"
24 #include "qvboxplotmodelmapper.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 DeclarativeBoxSet::DeclarativeBoxSet(const QString label, QObject *parent)
28 DeclarativeBoxSet::DeclarativeBoxSet(const QString label, QObject *parent)
29 : QBoxSet(label, parent)
29 : QBoxSet(label, parent)
30 {
30 {
31 connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int,int)));
31 connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int,int)));
32 //connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int,int)));
32 //connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int,int)));
33 }
33 }
34
34
35 void DeclarativeBoxSet::handleCountChanged(int index, int count)
35 void DeclarativeBoxSet::handleCountChanged(int index, int count)
36 {
36 {
37 Q_UNUSED(index)
37 Q_UNUSED(index)
38 Q_UNUSED(count)
38 Q_UNUSED(count)
39 emit countChanged(QBoxSet::count());
39 emit countChanged(QBoxSet::count());
40 }
40 }
41
41
42 QVariantList DeclarativeBoxSet::values()
42 QVariantList DeclarativeBoxSet::values()
43 {
43 {
44 QVariantList values;
44 QVariantList values;
45 for (int i(0); i < count(); i++)
45 for (int i(0); i < count(); i++)
46 values.append(QVariant(QBoxSet::at(i)));
46 values.append(QVariant(QBoxSet::at(i)));
47 return values;
47 return values;
48 }
48 }
49
49
50 void DeclarativeBoxSet::setValues(QVariantList values)
50 void DeclarativeBoxSet::setValues(QVariantList values)
51 {
51 {
52 for (int i(0); i < values.count(); i++) {
52 for (int i(0); i < values.count(); i++) {
53 if (values.at(i).canConvert(QVariant::Double))
53 if (values.at(i).canConvert(QVariant::Double))
54 QBoxSet::append(values[i].toDouble());
54 QBoxSet::append(values[i].toDouble());
55 }
55 }
56 }
56 }
57
57
58 // Declarative box&whiskers series =====================================================
58 // =====================================================
59
59
60 DeclarativeBoxPlotSeries::DeclarativeBoxPlotSeries(QDeclarativeItem *parent) :
60 DeclarativeBoxPlotSeries::DeclarativeBoxPlotSeries(QDeclarativeItem *parent) :
61 QBoxPlotSeries(parent),
61 QBoxPlotSeries(parent),
62 m_axes(new DeclarativeAxes(this))
62 m_axes(new DeclarativeAxes(this))
63 {
63 {
64 connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*)));
64 connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*)));
65 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
65 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
66 connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
66 connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
67 connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
67 connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
68 connect(this, SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(onHovered(bool, QBoxSet*)));
69 connect(this, SIGNAL(clicked(QBoxSet*)), this, SLOT(onClicked(QBoxSet*)));
68 }
70 }
69
71
70 void DeclarativeBoxPlotSeries::classBegin()
72 void DeclarativeBoxPlotSeries::classBegin()
71 {
73 {
72 }
74 }
73
75
74 void DeclarativeBoxPlotSeries::componentComplete()
76 void DeclarativeBoxPlotSeries::componentComplete()
75 {
77 {
76 foreach (QObject *child, children()) {
78 foreach (QObject *child, children()) {
77 if (qobject_cast<DeclarativeBoxSet *>(child)) {
79 if (qobject_cast<DeclarativeBoxSet *>(child)) {
78 QBoxPlotSeries::append(qobject_cast<DeclarativeBoxSet *>(child));
80 QBoxPlotSeries::append(qobject_cast<DeclarativeBoxSet *>(child));
79 } else if (qobject_cast<QVBoxPlotModelMapper *>(child)) {
81 } else if (qobject_cast<QVBoxPlotModelMapper *>(child)) {
80 QVBoxPlotModelMapper *mapper = qobject_cast<QVBoxPlotModelMapper *>(child);
82 QVBoxPlotModelMapper *mapper = qobject_cast<QVBoxPlotModelMapper *>(child);
81 mapper->setSeries(this);
83 mapper->setSeries(this);
82 }// else if (qobject_cast<QHBarModelMapper *>(child)) { // TODO: Horisontal
84 }// else if (qobject_cast<QHBarModelMapper *>(child)) { // TODO: Horisontal
83 //QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); //TODO
85 //QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); //TODO
84 //mapper->setSeries(this);
86 //mapper->setSeries(this);
85 //}
87 //}
86 }
88 }
87 }
89 }
88
90
89 QDeclarativeListProperty<QObject> DeclarativeBoxPlotSeries::seriesChildren()
91 QDeclarativeListProperty<QObject> DeclarativeBoxPlotSeries::seriesChildren()
90 {
92 {
91 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBoxPlotSeries::appendSeriesChildren);
93 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBoxPlotSeries::appendSeriesChildren);
92 }
94 }
93
95
94 void DeclarativeBoxPlotSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
96 void DeclarativeBoxPlotSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
95 {
97 {
96 // Empty implementation; the children are parsed in componentComplete instead
98 // Empty implementation; the children are parsed in componentComplete instead
97 Q_UNUSED(list);
99 Q_UNUSED(list);
98 Q_UNUSED(element);
100 Q_UNUSED(element);
99 }
101 }
100
102
101 DeclarativeBoxSet *DeclarativeBoxPlotSeries::at(int index)
103 DeclarativeBoxSet *DeclarativeBoxPlotSeries::at(int index)
102 {
104 {
103 qDebug() << "DeclarativeBoxPlotSeries::at";
104 QList<QBoxSet *> setList = boxSets();
105 QList<QBoxSet *> setList = boxSets();
105 if (index >= 0 && index < setList.count())
106 if (index >= 0 && index < setList.count())
106 return qobject_cast<DeclarativeBoxSet *>(setList[index]);
107 return qobject_cast<DeclarativeBoxSet *>(setList[index]);
107
108
108 return 0;
109 return 0;
109 }
110 }
110
111
111 DeclarativeBoxSet *DeclarativeBoxPlotSeries::insert(int index, const QString label, QVariantList values)
112 DeclarativeBoxSet *DeclarativeBoxPlotSeries::insert(int index, const QString label, QVariantList values)
112 {
113 {
113 DeclarativeBoxSet *barset = new DeclarativeBoxSet(label, this);
114 DeclarativeBoxSet *barset = new DeclarativeBoxSet(label, this);
114 barset->setValues(values);
115 barset->setValues(values);
115 if (QBoxPlotSeries::insert(index, barset))
116 if (QBoxPlotSeries::insert(index, barset))
116 return barset;
117 return barset;
117 delete barset;
118 delete barset;
118 return 0;
119 return 0;
119 }
120 }
120
121
122 void DeclarativeBoxPlotSeries::onHovered(bool status, QBoxSet *boxset)
123 {
124 emit hovered(status, qobject_cast<DeclarativeBoxSet *>(boxset));
125 }
126
127 void DeclarativeBoxPlotSeries::onClicked(QBoxSet *boxset)
128 {
129 emit clicked(qobject_cast<DeclarativeBoxSet *>(boxset));
130 }
121
131
122 #include "moc_declarativeboxplotseries.cpp"
132 #include "moc_declarativeboxplotseries.cpp"
123
133
124 QTCOMMERCIALCHART_END_NAMESPACE
134 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,111 +1,115
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 DECLARATIVEBOXPLOT_H
21 #ifndef DECLARATIVEBOXPLOT_H
22 #define DECLARATIVEBOXPLOT_H
22 #define DECLARATIVEBOXPLOT_H
23
23
24 #include "qboxset.h"
24 #include "qboxset.h"
25 #include "declarativeaxes.h"
25 #include "declarativeaxes.h"
26 #include "qboxplotseries.h"
26 #include "qboxplotseries.h"
27 #include <QtDeclarative/QDeclarativeItem>
27 #include <QtDeclarative/QDeclarativeItem>
28 #include <QtDeclarative/QDeclarativeParserStatus>
28 #include <QtDeclarative/QDeclarativeParserStatus>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 class DeclarativeBoxSet : public QBoxSet
32 class DeclarativeBoxSet : public QBoxSet
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35 Q_PROPERTY(QVariantList values READ values WRITE setValues)
35 Q_PROPERTY(QVariantList values READ values WRITE setValues)
36 Q_PROPERTY(QString label READ label WRITE setLabel)
36 Q_PROPERTY(QString label READ label WRITE setLabel)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
38 Q_PROPERTY(qreal lowerExtreme READ lowerExtreme WRITE setLowerExtreme)
38 Q_PROPERTY(qreal lowerExtreme READ lowerExtreme WRITE setLowerExtreme)
39 Q_PROPERTY(qreal lowerQuartile READ lowerQuartile WRITE setLowerQuartile)
39 Q_PROPERTY(qreal lowerQuartile READ lowerQuartile WRITE setLowerQuartile)
40 Q_PROPERTY(qreal median READ median WRITE setMedian)
40 Q_PROPERTY(qreal median READ median WRITE setMedian)
41 Q_PROPERTY(qreal upperQuartile READ upperQuartile WRITE setUpperQuartile)
41 Q_PROPERTY(qreal upperQuartile READ upperQuartile WRITE setUpperQuartile)
42 Q_PROPERTY(qreal upperExtreme READ upperExtreme WRITE setUpperExtreme)
42 Q_PROPERTY(qreal upperExtreme READ upperExtreme WRITE setUpperExtreme)
43
43
44 public:
44 public:
45 explicit DeclarativeBoxSet(const QString label = "", QObject *parent = 0);
45 explicit DeclarativeBoxSet(const QString label = "", QObject *parent = 0);
46 QVariantList values();
46 QVariantList values();
47 void setValues(QVariantList values);
47 void setValues(QVariantList values);
48
48
49 public: // From QBoxSet
49 public: // From QBoxSet
50 Q_INVOKABLE void append(qreal value) { QBoxSet::append(value); }
50 Q_INVOKABLE void append(qreal value) { QBoxSet::append(value); }
51 Q_INVOKABLE void replace(int index, qreal value) { QBoxSet::replace(index, value); }
51 Q_INVOKABLE void replace(int index, qreal value) { QBoxSet::replace(index, value); }
52 Q_INVOKABLE qreal at(int index) { return QBoxSet::at(index); }
52 Q_INVOKABLE qreal at(int index) { return QBoxSet::at(index); }
53
53
54 Q_SIGNALS:
54 Q_SIGNALS:
55 void countChanged(int count);
55 void countChanged(int count);
56
56
57 private Q_SLOTS:
57 private Q_SLOTS:
58 void handleCountChanged(int index, int count);
58 void handleCountChanged(int index, int count);
59 };
59 };
60
60
61 class DeclarativeBoxPlotSeries : public QBoxPlotSeries, public QDeclarativeParserStatus
61 class DeclarativeBoxPlotSeries : public QBoxPlotSeries, public QDeclarativeParserStatus
62 {
62 {
63 Q_OBJECT
63 Q_OBJECT
64 Q_INTERFACES(QDeclarativeParserStatus)
64 Q_INTERFACES(QDeclarativeParserStatus)
65 Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged REVISION 1)
65 Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged REVISION 1)
66 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1)
66 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1)
67 Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2)
67 Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2)
68 Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2)
68 Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2)
69 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
69 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
70 Q_CLASSINFO("DefaultProperty", "seriesChildren")
70 Q_CLASSINFO("DefaultProperty", "seriesChildren")
71
71
72 public:
72 public:
73 explicit DeclarativeBoxPlotSeries(QDeclarativeItem *parent = 0);
73 explicit DeclarativeBoxPlotSeries(QDeclarativeItem *parent = 0);
74 QAbstractAxis *axisX() { return m_axes->axisX(); }
74 QAbstractAxis *axisX() { return m_axes->axisX(); }
75 void setAxisX(QAbstractAxis *axis) { m_axes->setAxisX(axis); }
75 void setAxisX(QAbstractAxis *axis) { m_axes->setAxisX(axis); }
76 QAbstractAxis *axisY() { return m_axes->axisY(); }
76 QAbstractAxis *axisY() { return m_axes->axisY(); }
77 void setAxisY(QAbstractAxis *axis) { m_axes->setAxisY(axis); }
77 void setAxisY(QAbstractAxis *axis) { m_axes->setAxisY(axis); }
78 Q_REVISION(2) QAbstractAxis *axisXTop() { return m_axes->axisXTop(); }
78 Q_REVISION(2) QAbstractAxis *axisXTop() { return m_axes->axisXTop(); }
79 Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); }
79 Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); }
80 Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); }
80 Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); }
81 Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); }
81 Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); }
82 QDeclarativeListProperty<QObject> seriesChildren();
82 QDeclarativeListProperty<QObject> seriesChildren();
83
83
84 public:
84 public:
85 Q_INVOKABLE DeclarativeBoxSet *at(int index);
85 Q_INVOKABLE DeclarativeBoxSet *at(int index);
86 Q_INVOKABLE DeclarativeBoxSet *append(const QString label, QVariantList values) { return insert(count(), label, values); }
86 Q_INVOKABLE DeclarativeBoxSet *append(const QString label, QVariantList values) { return insert(count(), label, values); }
87 Q_INVOKABLE void append(DeclarativeBoxSet *box) { QBoxPlotSeries::append(box); }
87 Q_INVOKABLE void append(DeclarativeBoxSet *box) { QBoxPlotSeries::append(box); }
88 Q_INVOKABLE DeclarativeBoxSet *insert(int index, const QString label, QVariantList values);
88 Q_INVOKABLE DeclarativeBoxSet *insert(int index, const QString label, QVariantList values);
89 Q_INVOKABLE bool remove(QBoxSet *boxset) { return QBoxPlotSeries::remove(boxset); }
89 Q_INVOKABLE bool remove(QBoxSet *boxset) { return QBoxPlotSeries::remove(boxset); }
90 Q_INVOKABLE void clear() { return QBoxPlotSeries::clear(); }
90 Q_INVOKABLE void clear() { return QBoxPlotSeries::clear(); }
91
91
92 public: // from QDeclarativeParserStatus
92 public: // from QDeclarativeParserStatus
93 void classBegin();
93 void classBegin();
94 void componentComplete();
94 void componentComplete();
95
95
96 Q_SIGNALS:
96 Q_SIGNALS:
97 Q_REVISION(1) void axisXChanged(QAbstractAxis *axis);
97 Q_REVISION(1) void axisXChanged(QAbstractAxis *axis);
98 Q_REVISION(1) void axisYChanged(QAbstractAxis *axis);
98 Q_REVISION(1) void axisYChanged(QAbstractAxis *axis);
99 Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis);
99 Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis);
100 Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis);
100 Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis);
101 void clicked(DeclarativeBoxSet *boxset);
102 void hovered(bool status, DeclarativeBoxSet *boxset);
101
103
102 public Q_SLOTS:
104 public Q_SLOTS:
103 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
105 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
106 void onHovered(bool status, QBoxSet *boxset);
107 void onClicked(QBoxSet *boxset);
104
108
105 public:
109 public:
106 DeclarativeAxes *m_axes;
110 DeclarativeAxes *m_axes;
107 };
111 };
108
112
109 QTCOMMERCIALCHART_END_NAMESPACE
113 QTCOMMERCIALCHART_END_NAMESPACE
110
114
111 #endif // DECLARATIVEBOXPLOT_H
115 #endif // DECLARATIVEBOXPLOT_H
@@ -1,235 +1,233
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 "qboxset_p.h"
24 #include "qboxset_p.h"
25 #include "qabstractbarseries_p.h"
25 #include "qabstractbarseries_p.h"
26 #include "qboxset.h"
26 #include "qboxset.h"
27 #include "boxwhiskers_p.h"
27 #include "boxwhiskers_p.h"
28 #include <QPainter>
28 #include <QPainter>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 BoxPlotChartItem::BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item) :
32 BoxPlotChartItem::BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item) :
33 ChartItem(series->d_func(), item),
33 ChartItem(series->d_func(), item),
34 m_series(series),
34 m_series(series),
35 m_animation(0),
35 m_animation(0),
36 m_animate(0),
36 m_animate(0),
37 m_domainMaxY(0.0),
37 m_domainMaxY(0.0),
38 m_domainMinY(0.0)
38 m_domainMinY(0.0)
39 {
39 {
40 connect(series, SIGNAL(boxsetsRemoved(QList<QBoxSet*>)), this, SLOT(handleBoxsetRemove(QList<QBoxSet*>)));
40 connect(series, SIGNAL(boxsetsRemoved(QList<QBoxSet*>)), this, SLOT(handleBoxsetRemove(QList<QBoxSet*>)));
41 connect(series->d_func(), SIGNAL(restructuredBoxes()), this, SLOT(handleDataStructureChanged()));
41 connect(series->d_func(), SIGNAL(restructuredBoxes()), this, SLOT(handleDataStructureChanged()));
42 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
42 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
43 connect(series->d_func(), SIGNAL(updatedBoxes()), this, SLOT(handleUpdatedBars()));
43 connect(series->d_func(), SIGNAL(updatedBoxes()), this, SLOT(handleUpdatedBars()));
44 connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars()));
44 connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars()));
45 // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here
45 // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here
46 setZValue(ChartPresenter::BoxPlotSeriesZValue);
46 setZValue(ChartPresenter::BoxPlotSeriesZValue);
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 QBoxSet *set = m_series->d_func()->boxsetAt(s);
85 QBoxSet *set = m_series->d_func()->boxsetAt(s);
86
86
87 BoxWhiskers *box = m_boxTable.value(set);
87 BoxWhiskers *box = m_boxTable.value(set);
88 if (!box) {
88 if (!box) {
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 box = new BoxWhiskers(set, domain(), this);
90 box = new BoxWhiskers(set, domain(), this);
91 m_boxTable.insert(set, box);
91 m_boxTable.insert(set, box);
92 connect(box, SIGNAL(clicked(QBoxSet *)), m_series, SIGNAL(clicked(QBoxSet*)));
92 connect(box, SIGNAL(clicked(QBoxSet *)), m_series, SIGNAL(clicked(QBoxSet*)));
93 connect(box, SIGNAL(hovered(bool,QBoxSet*)), m_series, SIGNAL(hovered(bool,QBoxSet*)));
93 connect(box, SIGNAL(hovered(bool,QBoxSet*)), m_series, SIGNAL(hovered(bool,QBoxSet*)));
94 connect(box, SIGNAL(clicked(QBoxSet*)), set, SIGNAL(clicked()));
94 connect(box, SIGNAL(clicked(QBoxSet*)), set, SIGNAL(clicked()));
95 connect(box, SIGNAL(hovered(bool,QBoxSet*)), set, SIGNAL(hovered(bool)));
95 connect(box, SIGNAL(hovered(bool,QBoxSet*)), set, SIGNAL(hovered(bool)));
96
96
97 // Set the decorative issues for the newly created box
97 // Set the decorative issues for the newly created box
98 box->setBrush(m_series->brush());
98 box->setBrush(m_series->brush());
99 box->setPen(m_series->pen());
99 box->setPen(m_series->pen());
100 }
100 }
101 updateBoxGeometry(box, s);
101 updateBoxGeometry(box, s);
102
102
103 box->updateGeometry();
103 box->updateGeometry();
104
104
105 if (m_animation)
105 if (m_animation)
106 m_animation->addBox(box);
106 m_animation->addBox(box);
107 }
107 }
108
108
109 //
109 //
110 handleDomainUpdated();
110 handleDomainUpdated();
111 }
111 }
112
112
113 void BoxPlotChartItem::handleUpdatedBars()
113 void BoxPlotChartItem::handleUpdatedBars()
114 {
114 {
115 qDebug() << "BoxPlotChartItem::handleUpdatedBars()";
116
117 foreach (BoxWhiskers *item, m_boxTable.values()) {
115 foreach (BoxWhiskers *item, m_boxTable.values()) {
118 item->setBrush(m_series->brush());
116 item->setBrush(m_series->brush());
119 item->setPen(m_series->pen());
117 item->setPen(m_series->pen());
120 }
118 }
121 // Override with QBoxSet specific settings
119 // Override with QBoxSet specific settings
122 foreach (QBoxSet *set, m_boxTable.keys()) {
120 foreach (QBoxSet *set, m_boxTable.keys()) {
123 if (set->brush().style() != Qt::NoBrush)
121 if (set->brush().style() != Qt::NoBrush)
124 m_boxTable.value(set)->setBrush(set->brush());
122 m_boxTable.value(set)->setBrush(set->brush());
125 if (set->pen().style() != Qt::NoPen)
123 if (set->pen().style() != Qt::NoPen)
126 m_boxTable.value(set)->setPen(set->pen());
124 m_boxTable.value(set)->setPen(set->pen());
127 }
125 }
128 }
126 }
129
127
130 void BoxPlotChartItem::handleBoxsetRemove(QList<QBoxSet*> barSets)
128 void BoxPlotChartItem::handleBoxsetRemove(QList<QBoxSet*> barSets)
131 {
129 {
132 //qDebug() << "BoxPlotChartItem::handleBarsetRemove";
130 //qDebug() << "BoxPlotChartItem::handleBarsetRemove";
133
131
134 foreach (QBoxSet *set, barSets) {
132 foreach (QBoxSet *set, barSets) {
135 BoxWhiskers *boxItem = m_boxTable.value(set);
133 BoxWhiskers *boxItem = m_boxTable.value(set);
136 m_boxTable.remove(set);
134 m_boxTable.remove(set);
137 delete boxItem;
135 delete boxItem;
138 }
136 }
139
137
140 // We trust that series emits the restructuredBars, which handles restructuring
138 // We trust that series emits the restructuredBars, which handles restructuring
141 }
139 }
142
140
143 void BoxPlotChartItem::handleDomainUpdated()
141 void BoxPlotChartItem::handleDomainUpdated()
144 {
142 {
145 //qDebug() << "BoxPlotChartItem::handleDomainUpdated() domain()->size() = " << domain()->size();
143 //qDebug() << "BoxPlotChartItem::handleDomainUpdated() domain()->size() = " << domain()->size();
146
144
147 if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0))
145 if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0))
148 return;
146 return;
149
147
150 // Set my bounding rect to same as domain size
148 // Set my bounding rect to same as domain size
151 m_boundingRect.setRect(0.0, 0.0, domain()->size().width(), domain()->size().height());
149 m_boundingRect.setRect(0.0, 0.0, domain()->size().width(), domain()->size().height());
152
150
153 foreach (BoxWhiskers *item, m_boxTable.values()) {
151 foreach (BoxWhiskers *item, m_boxTable.values()) {
154 // Update the domain size for each BoxWhisker item
152 // Update the domain size for each BoxWhisker item
155 item->setDomainSize(domain()->size());
153 item->setDomainSize(domain()->size());
156 if (domain()->minY() != m_domainMinY || domain()->maxY() != m_domainMaxY) {
154 if (domain()->minY() != m_domainMinY || domain()->maxY() != m_domainMaxY) {
157 item->updateGeometry();
155 item->updateGeometry();
158 m_domainMinY = domain()->minY();
156 m_domainMinY = domain()->minY();
159 m_domainMaxY = domain()->maxY();
157 m_domainMaxY = domain()->maxY();
160 qDebug() << "Updating";
158 qDebug() << "Updating";
161 }
159 }
162
160
163 // If the animation is set, start the animation for each BoxWhisker item
161 // If the animation is set, start the animation for each BoxWhisker item
164 if (m_animation) {
162 if (m_animation) {
165 presenter()->startAnimation(m_animation->boxAnimation(item));
163 presenter()->startAnimation(m_animation->boxAnimation(item));
166 }
164 }
167 }
165 }
168 }
166 }
169
167
170 void BoxPlotChartItem::handleLayoutChanged()
168 void BoxPlotChartItem::handleLayoutChanged()
171 {
169 {
172 qDebug() << "BoxPlotChartItem::handleLayoutChanged";
170 qDebug() << "BoxPlotChartItem::handleLayoutChanged";
173
171
174 foreach (BoxWhiskers *item, m_boxTable.values()) {
172 foreach (BoxWhiskers *item, m_boxTable.values()) {
175 if (m_animation)
173 if (m_animation)
176 m_animation->setAnimationStart(item);
174 m_animation->setAnimationStart(item);
177
175
178 bool dirty = updateBoxGeometry(item, item->m_data.m_index);
176 bool dirty = updateBoxGeometry(item, item->m_data.m_index);
179 if (dirty && m_animation)
177 if (dirty && m_animation)
180 presenter()->startAnimation(m_animation->boxChangeAnimation(item));
178 presenter()->startAnimation(m_animation->boxChangeAnimation(item));
181 else
179 else
182 item->updateGeometry();
180 item->updateGeometry();
183 }
181 }
184 }
182 }
185
183
186 QRectF BoxPlotChartItem::boundingRect() const
184 QRectF BoxPlotChartItem::boundingRect() const
187 {
185 {
188 return m_boundingRect;
186 return m_boundingRect;
189 }
187 }
190
188
191 void BoxPlotChartItem::initializeLayout()
189 void BoxPlotChartItem::initializeLayout()
192 {
190 {
193 qDebug() << "ALERT EMPTY: BoxPlotChartItem::initializeLayout";
191 qDebug() << "ALERT EMPTY: BoxPlotChartItem::initializeLayout";
194 }
192 }
195
193
196 QVector<QRectF> BoxPlotChartItem::calculateLayout()
194 QVector<QRectF> BoxPlotChartItem::calculateLayout()
197 {
195 {
198 qDebug() << "ALERT EMPTY: BoxPlotChartItem::calculateLayout()";
196 qDebug() << "ALERT EMPTY: BoxPlotChartItem::calculateLayout()";
199
197
200 return QVector<QRectF>();
198 return QVector<QRectF>();
201 }
199 }
202
200
203 bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index)
201 bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index)
204 {
202 {
205 bool changed = false;
203 bool changed = false;
206
204
207 QBoxSet *set = m_series->d_func()->boxsetAt(index);
205 QBoxSet *set = m_series->d_func()->boxsetAt(index);
208 BoxWhiskersData &data = box->m_data;
206 BoxWhiskersData &data = box->m_data;
209
207
210 if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) ||
208 if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) ||
211 (data.m_median != set->at(2)) || (data.m_upperQuartile != set->at(3)) || (data.m_upperExtreme != set->at(4)))
209 (data.m_median != set->at(2)) || (data.m_upperQuartile != set->at(3)) || (data.m_upperExtreme != set->at(4)))
212 changed = true;
210 changed = true;
213
211
214 data.m_lowerExtreme = set->at(0);
212 data.m_lowerExtreme = set->at(0);
215 data.m_lowerQuartile = set->at(1);
213 data.m_lowerQuartile = set->at(1);
216 data.m_median = set->at(2);
214 data.m_median = set->at(2);
217 data.m_upperQuartile = set->at(3);
215 data.m_upperQuartile = set->at(3);
218 data.m_upperExtreme = set->at(4);
216 data.m_upperExtreme = set->at(4);
219 data.m_index = index;
217 data.m_index = index;
220 data.m_boxItems = m_series->count();
218 data.m_boxItems = m_series->count();
221
219
222 data.m_maxX = domain()->maxX();
220 data.m_maxX = domain()->maxX();
223 data.m_minX = domain()->minX();
221 data.m_minX = domain()->minX();
224 data.m_maxY = domain()->maxY();
222 data.m_maxY = domain()->maxY();
225 data.m_minY = domain()->minY();
223 data.m_minY = domain()->minY();
226
224
227 data.m_seriesIndex = m_seriesIndex;
225 data.m_seriesIndex = m_seriesIndex;
228 data.m_seriesCount = m_seriesCount;
226 data.m_seriesCount = m_seriesCount;
229
227
230 return changed;
228 return changed;
231 }
229 }
232
230
233 #include "moc_boxplotchartitem_p.cpp"
231 #include "moc_boxplotchartitem_p.cpp"
234
232
235 QTCOMMERCIALCHART_END_NAMESPACE
233 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,618 +1,661
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 "qbarcategoryaxis.h"
24 #include "qbarcategoryaxis.h"
25 #include "boxplotchartitem_p.h"
25 #include "boxplotchartitem_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "charttheme_p.h"
27 #include "charttheme_p.h"
28 #include "qvalueaxis.h"
28 #include "qvalueaxis.h"
29 #include "charttheme_p.h"
29 #include "charttheme_p.h"
30 #include "boxplotanimation_p.h"
30 #include "boxplotanimation_p.h"
31 #include "qchart_p.h"
31 #include "qchart_p.h"
32 #include "qboxset.h"
32 #include "qboxset.h"
33 #include "qboxset_p.h"
33 #include "qboxset_p.h"
34
34
35 #include <QDebug>
35 #include <QDebug>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 /*!
39 /*!
40 \class QBoxPlotSeries
40 \class QBoxPlotSeries
41 \brief Series for creating box-and-whiskers chart
41 \brief Series for creating box-and-whiskers chart
42 \mainclass
42 \mainclass
43
43
44 QBoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this class is to act as
44 QBoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this class is to act as
45 a container for single box-and-whisker items. Each item is drawn to own slot. If chart includes multiple QBoxPlotSeries
45 a container for single box-and-whisker items. Each item is drawn to own slot. If chart includes multiple instances of
46 items with the same index are drawn to same slot.
46 QBoxPlotSeries then box-and-whiskers items with the same index are drawn to same slot.
47
47
48 See the \l {Box and Whiskers Example} {box-and-whiskers chart example} to learn how to create a box-and-whiskers chart.
48 See the \l {Box and Whiskers Example} {box-and-whiskers chart example} to learn how to create a box-and-whiskers chart.
49 \image examples_boxplotchart.png
49 \image examples_boxplotchart.png
50
50
51 \sa QBoxSet
51 \sa QBoxSet
52 */
52 */
53
53
54 /*!
54 /*!
55 \qmlclass BoxPlotSeries QBoxPlotSeries
55 \qmlclass BoxPlotSeries QBoxPlotSeries
56 \inherits AbstractBarSeries
56 \inherits QAbstractSeries
57
58 BoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this class is to act as
59 a container for single box-and-whisker items. Each item is drawn to own slot. If chart includes multiple instances of
60 BoxPlotSeries then box-and-whiskers items with the same index are drawn to same slot.
57
61
58 The following QML shows how to create a simple box-and-whiskers chart:
62 The following QML shows how to create a simple box-and-whiskers chart:
59 \snippet ../examples/qmlboxplot/qml/qmlboxplot/main.qml 1
63 \snippet ../examples/qmlboxplot/qml/qmlboxplot/main.qml 1
60 \beginfloatleft
64 \beginfloatleft
61 \image demos_qmlchart7.png
65 \image TODO_CREATE_IMAGE.png
62 \endfloat
66 \endfloat
63 \clearfloat
67 \clearfloat
64 */
68 */
65
69
66 /*!
70 /*!
67 \fn QBoxPlotSeries::boxsetsAdded(QList<QBoxSet *> sets)
71 \fn QBoxPlotSeries::boxsetsAdded(QList<QBoxSet *> sets)
68 \brief Signal is emitted when a new \a sets of box-and-whiskers data is added to the series.
72 \brief Signal is emitted when a new \a sets of box-and-whiskers data is added to the series.
69 */
73 */
70
74
71 /*!
75 /*!
72 \fn QBoxPlotSeries::boxsetsRemoved(QList<QBoxSet *> sets)
76 \fn QBoxPlotSeries::boxsetsRemoved(QList<QBoxSet *> sets)
73 \brief Signal is emitted when \a sets of box-and-whiskers data is removed from the series.
77 \brief Signal is emitted when \a sets of box-and-whiskers data is removed from the series.
74 */
78 */
75
79
76 /*!
80 /*!
77 \fn QBoxPlotSeries::clicked(QBoxSet *boxset)
81 \fn QBoxPlotSeries::clicked(QBoxSet *boxset)
78 \brief Signal is emitted when the user clicks the \a boxset on the chart.
82 \brief Signal is emitted when the user clicks the \a boxset on the chart.
79 */
83 */
80
84
81 /*!
85 /*!
82 \fn QBoxPlotSeries::hovered(bool status, QBoxSet *boxset)
86 \fn QBoxPlotSeries::hovered(bool status, QBoxSet *boxset)
83 \brief Signal is emitted when there is change in hover \a status over \a boxset.
87 \brief Signal is emitted when there is change in hover \a status over \a boxset.
84 */
88 */
85
89
86 /*!
90 /*!
87 \fn QBoxPlotSeries::countChanged()
91 \fn QBoxPlotSeries::countChanged()
88 \brief Signal is emitted when there is change in count of box-and-whiskers items in the series.
92 \brief Signal is emitted when there is change in count of box-and-whiskers items in the series.
89 */
93 */
94 /*!
95 \qmlmethod BoxPlotSeries::append(const QString label, QVariantList values)
96 Appends a new box-and-whiskers set with \a label and \a values to the series.
97 */
98 /*!
99 \qmlmethod BoxPlotSeries::append(BoxSet *box)
100 Appends the \a box to the series.
101 */
102 /*!
103 \qmlmethod BoxPlotSeries::insert(int index, const QString label, QVariantList values)
104 Inserts a new box-and-whiskers set with \a label and \a values at the \a index position.
105 */
106 /*!
107 \qmlmethod BoxPlotSeries::remove(QBoxSet *boxset)
108 Removes the \a boxset from the series.
109 */
110 /*!
111 \qmlmethod BoxPlotSeries::clear()
112 Removes all boxsets from the series. Deletes removed sets.
113 */
114
115 /*!
116 \qmlsignal BoxPlotSeries::onClicked(BoxSet boxset);
117 Signal is emitted when the user clicks the \a boxset on the chart.
118 */
119 /*!
120 \qmlsignal BoxPlotSeries::onHovered(bool status, BoxSet boxset);
121 Signal is emitted when there is change in hover \a status over \a boxset.
122 */
123 /*!
124 \qmlsignal BoxPlotSeries::onCountChanged();
125 Signal is emitted when there is change in count of box-and-whiskers items in the series.
126 */
127 /*
128 void boxsetsAdded(QList<QBoxSet *> sets);
129 */
130 /*
131 void boxsetsRemoved(QList<QBoxSet *> sets);
132 */
90
133
91 /*!
134 /*!
92 Constructs empty QBoxPlotSeries.
135 Constructs empty QBoxPlotSeries.
93 QBoxPlotSeries is QObject which is a child of a \a parent.
136 QBoxPlotSeries is QObject which is a child of a \a parent.
94 */
137 */
95 QBoxPlotSeries::QBoxPlotSeries(QObject *parent)
138 QBoxPlotSeries::QBoxPlotSeries(QObject *parent)
96 : QAbstractSeries(*new QBoxPlotSeriesPrivate(this), parent)
139 : QAbstractSeries(*new QBoxPlotSeriesPrivate(this), parent)
97 {
140 {
98 }
141 }
99
142
100 /*!
143 /*!
101 Destructor. Removes series from chart.
144 Destructor. Removes series from chart.
102 */
145 */
103 QBoxPlotSeries::~QBoxPlotSeries()
146 QBoxPlotSeries::~QBoxPlotSeries()
104 {
147 {
105 qDebug() << "QBoxPlotSeries::~QBoxPlotSeries";
148 qDebug() << "QBoxPlotSeries::~QBoxPlotSeries";
106
149
107 Q_D(QBoxPlotSeries);
150 Q_D(QBoxPlotSeries);
108 if (d->m_chart)
151 if (d->m_chart)
109 d->m_chart->removeSeries(this);
152 d->m_chart->removeSeries(this);
110 }
153 }
111
154
112 /*!
155 /*!
113 Adds a single box and whiskers set to series. Takes ownership of the \a set. If the set is null or is already in series, it won't be appended.
156 Adds a single box and whiskers set to series. Takes ownership of the \a set. If the set is null or is already in series, it won't be appended.
114 Returns true, if appending succeeded.
157 Returns true, if appending succeeded.
115 */
158 */
116 bool QBoxPlotSeries::append(QBoxSet *set)
159 bool QBoxPlotSeries::append(QBoxSet *set)
117 {
160 {
118 Q_D(QBoxPlotSeries);
161 Q_D(QBoxPlotSeries);
119
162
120 bool success = d->append(set);
163 bool success = d->append(set);
121 if (success) {
164 if (success) {
122 QList<QBoxSet *> sets;
165 QList<QBoxSet *> sets;
123 sets.append(set);
166 sets.append(set);
124 set->setParent(this);
167 set->setParent(this);
125 emit boxsetsAdded(sets);
168 emit boxsetsAdded(sets);
126 emit countChanged();
169 emit countChanged();
127 }
170 }
128 return success;
171 return success;
129 }
172 }
130
173
131 /*!
174 /*!
132 Removes boxset from the series. Releases ownership of the \a set. Deletes the set, if remove
175 Removes boxset from the series. Releases ownership of the \a set. Deletes the set, if remove
133 was successful.
176 was successful.
134 Returns true, if the set was removed.
177 Returns true, if the set was removed.
135 */
178 */
136 bool QBoxPlotSeries::remove(QBoxSet *set)
179 bool QBoxPlotSeries::remove(QBoxSet *set)
137 {
180 {
138 Q_D(QBoxPlotSeries);
181 Q_D(QBoxPlotSeries);
139 bool success = d->remove(set);
182 bool success = d->remove(set);
140 if (success) {
183 if (success) {
141 QList<QBoxSet *> sets;
184 QList<QBoxSet *> sets;
142 sets.append(set);
185 sets.append(set);
143 set->setParent(0);
186 set->setParent(0);
144 emit boxsetsRemoved(sets);
187 emit boxsetsRemoved(sets);
145 emit countChanged();
188 emit countChanged();
146 delete set;
189 delete set;
147 set = 0;
190 set = 0;
148 }
191 }
149 return success;
192 return success;
150 }
193 }
151
194
152 /*!
195 /*!
153 Takes a single \a set from the series. Does not delete the boxset object.
196 Takes a single \a set from the series. Does not delete the boxset object.
154
197
155 NOTE: The series remains as the boxset's parent object. You must set the
198 NOTE: The series remains as the boxset's parent object. You must set the
156 parent object to take full ownership.
199 parent object to take full ownership.
157
200
158 Returns true if take was successful.
201 Returns true if take was successful.
159 */
202 */
160 bool QBoxPlotSeries::take(QBoxSet *set)
203 bool QBoxPlotSeries::take(QBoxSet *set)
161 {
204 {
162 Q_D(QBoxPlotSeries);
205 Q_D(QBoxPlotSeries);
163
206
164 bool success = d->remove(set);
207 bool success = d->remove(set);
165 if (success) {
208 if (success) {
166 QList<QBoxSet *> sets;
209 QList<QBoxSet *> sets;
167 sets.append(set);
210 sets.append(set);
168 emit boxsetsRemoved(sets);
211 emit boxsetsRemoved(sets);
169 emit countChanged();
212 emit countChanged();
170 }
213 }
171 return success;
214 return success;
172 }
215 }
173
216
174 /*!
217 /*!
175 Adds a list of boxsets to series. Takes ownership of the \a sets.
218 Adds a list of boxsets to series. Takes ownership of the \a sets.
176 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
219 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
177 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
220 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
178 and function returns false.
221 and function returns false.
179 */
222 */
180 bool QBoxPlotSeries::append(QList<QBoxSet *> sets)
223 bool QBoxPlotSeries::append(QList<QBoxSet *> sets)
181 {
224 {
182 Q_D(QBoxPlotSeries);
225 Q_D(QBoxPlotSeries);
183 bool success = d->append(sets);
226 bool success = d->append(sets);
184 if (success) {
227 if (success) {
185 emit boxsetsAdded(sets);
228 emit boxsetsAdded(sets);
186 emit countChanged();
229 emit countChanged();
187 }
230 }
188 return success;
231 return success;
189 }
232 }
190
233
191 /*!
234 /*!
192 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
235 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
193 Returns true, if inserting succeeded.
236 Returns true, if inserting succeeded.
194
237
195 */
238 */
196 bool QBoxPlotSeries::insert(int index, QBoxSet *set)
239 bool QBoxPlotSeries::insert(int index, QBoxSet *set)
197 {
240 {
198 Q_D(QBoxPlotSeries);
241 Q_D(QBoxPlotSeries);
199 bool success = d->insert(index, set);
242 bool success = d->insert(index, set);
200 if (success) {
243 if (success) {
201 QList<QBoxSet *> sets;
244 QList<QBoxSet *> sets;
202 sets.append(set);
245 sets.append(set);
203 emit boxsetsAdded(sets);
246 emit boxsetsAdded(sets);
204 emit countChanged();
247 emit countChanged();
205 }
248 }
206 return success;
249 return success;
207 }
250 }
208
251
209 /*!
252 /*!
210 Removes all boxsets from the series. Deletes removed sets.
253 Removes all boxsets from the series. Deletes removed sets.
211 */
254 */
212 void QBoxPlotSeries::clear()
255 void QBoxPlotSeries::clear()
213 {
256 {
214 Q_D(QBoxPlotSeries);
257 Q_D(QBoxPlotSeries);
215 QList<QBoxSet *> sets = boxSets();
258 QList<QBoxSet *> sets = boxSets();
216 bool success = d->remove(sets);
259 bool success = d->remove(sets);
217 if (success) {
260 if (success) {
218 emit boxsetsRemoved(sets);
261 emit boxsetsRemoved(sets);
219 emit countChanged();
262 emit countChanged();
220 foreach (QBoxSet *set, sets)
263 foreach (QBoxSet *set, sets)
221 delete set;
264 delete set;
222 }
265 }
223 }
266 }
224
267
225 /*!
268 /*!
226 Returns number of sets in series.
269 Returns number of sets in series.
227 */
270 */
228 int QBoxPlotSeries::count() const
271 int QBoxPlotSeries::count() const
229 {
272 {
230 Q_D(const QBoxPlotSeries);
273 Q_D(const QBoxPlotSeries);
231 return d->m_boxSets.count();
274 return d->m_boxSets.count();
232 }
275 }
233
276
234 /*!
277 /*!
235 Returns a list of sets in series. Keeps ownership of sets.
278 Returns a list of sets in series. Keeps ownership of sets.
236 */
279 */
237 QList<QBoxSet *> QBoxPlotSeries::boxSets() const
280 QList<QBoxSet *> QBoxPlotSeries::boxSets() const
238 {
281 {
239 Q_D(const QBoxPlotSeries);
282 Q_D(const QBoxPlotSeries);
240 return d->m_boxSets;
283 return d->m_boxSets;
241 }
284 }
242
285
243 /*!
286 /*!
244 Returns QChartSeries::SeriesTypeBoxPlot.
287 Returns QChartSeries::SeriesTypeBoxPlot.
245 */
288 */
246 QAbstractSeries::SeriesType QBoxPlotSeries::type() const
289 QAbstractSeries::SeriesType QBoxPlotSeries::type() const
247 {
290 {
248 return QAbstractSeries::SeriesTypeBoxPlot;
291 return QAbstractSeries::SeriesTypeBoxPlot;
249 }
292 }
250
293
251 /*!
294 /*!
252 Sets brush for the series. Box-and-whiskers items are drawn using \a brush
295 Sets brush for the series. Box-and-whiskers items are drawn using \a brush
253 */
296 */
254 void QBoxPlotSeries::setBrush(const QBrush &brush)
297 void QBoxPlotSeries::setBrush(const QBrush &brush)
255 {
298 {
256 Q_D(QBoxPlotSeries);
299 Q_D(QBoxPlotSeries);
257
300
258 if (d->m_brush != brush) {
301 if (d->m_brush != brush) {
259 d->m_brush = brush;
302 d->m_brush = brush;
260 emit d->updated();
303 emit d->updated();
261 }
304 }
262 }
305 }
263
306
264 /*!
307 /*!
265 Returns brush of the series.
308 Returns brush of the series.
266 */
309 */
267 QBrush QBoxPlotSeries::brush() const
310 QBrush QBoxPlotSeries::brush() const
268 {
311 {
269 Q_D(const QBoxPlotSeries);
312 Q_D(const QBoxPlotSeries);
270
313
271 return d->m_brush;
314 return d->m_brush;
272 }
315 }
273
316
274 /*!
317 /*!
275 Sets pen for the series. Box-and-whiskers items are drawn using \a pen
318 Sets pen for the series. Box-and-whiskers items are drawn using \a pen
276 */
319 */
277 void QBoxPlotSeries::setPen(const QPen &pen)
320 void QBoxPlotSeries::setPen(const QPen &pen)
278 {
321 {
279 Q_D(QBoxPlotSeries);
322 Q_D(QBoxPlotSeries);
280
323
281 if (d->m_pen != pen) {
324 if (d->m_pen != pen) {
282 d->m_pen = pen;
325 d->m_pen = pen;
283 emit d->updated();
326 emit d->updated();
284 }
327 }
285 }
328 }
286
329
287 /*!
330 /*!
288 Returns the pen of this series.
331 Returns the pen of this series.
289 */
332 */
290 QPen QBoxPlotSeries::pen() const
333 QPen QBoxPlotSeries::pen() const
291 {
334 {
292 Q_D(const QBoxPlotSeries);
335 Q_D(const QBoxPlotSeries);
293
336
294 return d->m_pen;
337 return d->m_pen;
295 }
338 }
296
339
297 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
340 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
298
341
299 QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q)
342 QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q)
300 : QAbstractSeriesPrivate(q),
343 : QAbstractSeriesPrivate(q),
301 m_pen(QPen(Qt::NoPen)),
344 m_pen(QPen(Qt::NoPen)),
302 m_brush(QBrush(Qt::NoBrush))
345 m_brush(QBrush(Qt::NoBrush))
303 {
346 {
304 }
347 }
305
348
306 QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate()
349 QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate()
307 {
350 {
308 qDebug() << "QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate()";
351 qDebug() << "QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate()";
309 disconnect(this, 0, 0, 0);
352 disconnect(this, 0, 0, 0);
310 }
353 }
311
354
312 void QBoxPlotSeriesPrivate::initializeDomain()
355 void QBoxPlotSeriesPrivate::initializeDomain()
313 {
356 {
314 qreal minX(domain()->minX());
357 qreal minX(domain()->minX());
315 qreal minY(domain()->minY());
358 qreal minY(domain()->minY());
316 qreal maxX(domain()->maxX());
359 qreal maxX(domain()->maxX());
317 qreal maxY(domain()->maxY());
360 qreal maxY(domain()->maxY());
318
361
319 qreal x = m_boxSets.count();
362 qreal x = m_boxSets.count();
320 minX = qMin(minX, - (qreal)0.5);
363 minX = qMin(minX, - (qreal)0.5);
321 minY = qMin(minY, bottom());
364 minY = qMin(minY, bottom());
322 maxX = qMax(maxX, x - (qreal)0.5);
365 maxX = qMax(maxX, x - (qreal)0.5);
323 maxY = qMax(maxY, max());
366 maxY = qMax(maxY, max());
324
367
325 domain()->setRange(minX, maxX, minY, maxY);
368 domain()->setRange(minX, maxX, minY, maxY);
326 }
369 }
327
370
328 void QBoxPlotSeriesPrivate::initializeAxes()
371 void QBoxPlotSeriesPrivate::initializeAxes()
329 {
372 {
330 foreach (QAbstractAxis* axis, m_axes) {
373 foreach (QAbstractAxis* axis, m_axes) {
331 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
374 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
332 if (axis->orientation() == Qt::Horizontal)
375 if (axis->orientation() == Qt::Horizontal)
333 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
376 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
334 else
377 else
335 qDebug() << "ALERT: QBoxPlotSeriesPrivate::initializeAxes implement #1";
378 qDebug() << "ALERT: QBoxPlotSeriesPrivate::initializeAxes implement #1";
336 }
379 }
337 }
380 }
338 }
381 }
339
382
340 QAbstractAxis::AxisType QBoxPlotSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
383 QAbstractAxis::AxisType QBoxPlotSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
341 {
384 {
342 if (orientation == Qt::Horizontal)
385 if (orientation == Qt::Horizontal)
343 return QAbstractAxis::AxisTypeBarCategory;
386 return QAbstractAxis::AxisTypeBarCategory;
344
387
345 return QAbstractAxis::AxisTypeValue;
388 return QAbstractAxis::AxisTypeValue;
346 }
389 }
347
390
348 QAbstractAxis* QBoxPlotSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
391 QAbstractAxis* QBoxPlotSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
349 {
392 {
350 Q_UNUSED(orientation);
393 Q_UNUSED(orientation);
351 // This is not implemented even in barseries, keep in touch if something needs this
394 // This is not implemented even in barseries, keep in touch if something needs this
352 qDebug() << "ALERT: QBoxPlotSeriesPrivate::createDefaultAxis implement";
395 qDebug() << "ALERT: QBoxPlotSeriesPrivate::createDefaultAxis implement";
353 return 0;
396 return 0;
354 }
397 }
355
398
356 void QBoxPlotSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
399 void QBoxPlotSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
357 {
400 {
358 QStringList categories;
401 QStringList categories;
359 if (axis->categories().isEmpty()) {
402 if (axis->categories().isEmpty()) {
360 for (int i(1); i < m_boxSets.count() + 1; i++) {
403 for (int i(1); i < m_boxSets.count() + 1; i++) {
361 QBoxSet *set = m_boxSets.at(i - 1);
404 QBoxSet *set = m_boxSets.at(i - 1);
362 if (set->label().isEmpty())
405 if (set->label().isEmpty())
363 categories << QString::number(i);
406 categories << QString::number(i);
364 else
407 else
365 categories << set->label();
408 categories << set->label();
366 }
409 }
367 axis->append(categories);
410 axis->append(categories);
368 }
411 }
369 }
412 }
370
413
371 void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
414 void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
372 {
415 {
373 Q_Q(QBoxPlotSeries);
416 Q_Q(QBoxPlotSeries);
374
417
375 BoxPlotChartItem *boxPlot = new BoxPlotChartItem(q,parent);
418 BoxPlotChartItem *boxPlot = new BoxPlotChartItem(q,parent);
376 m_item.reset(boxPlot);
419 m_item.reset(boxPlot);
377 QAbstractSeriesPrivate::initializeGraphics(parent);
420 QAbstractSeriesPrivate::initializeGraphics(parent);
378
421
379 if (m_chart) {
422 if (m_chart) {
380 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesChange(QAbstractSeries*)) );
423 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesChange(QAbstractSeries*)) );
381 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) );
424 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) );
382
425
383 QList<QAbstractSeries *> serieses = m_chart->series();
426 QList<QAbstractSeries *> serieses = m_chart->series();
384
427
385 // Tries to find this series from the Chart's list of serieses and deduce the index
428 // Tries to find this series from the Chart's list of serieses and deduce the index
386 int index = 0;
429 int index = 0;
387 foreach (QAbstractSeries *s, serieses) {
430 foreach (QAbstractSeries *s, serieses) {
388 if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) {
431 if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) {
389 if (q == static_cast<QBoxPlotSeries *>(s)) {
432 if (q == static_cast<QBoxPlotSeries *>(s)) {
390 boxPlot->m_seriesIndex = index;
433 boxPlot->m_seriesIndex = index;
391 m_index = index;
434 m_index = index;
392 }
435 }
393 index++;
436 index++;
394 }
437 }
395 }
438 }
396 boxPlot->m_seriesCount = index;
439 boxPlot->m_seriesCount = index;
397 }
440 }
398
441
399 // Make BoxPlotChartItem to instantiate box & whisker items
442 // Make BoxPlotChartItem to instantiate box & whisker items
400 boxPlot->handleDataStructureChanged();
443 boxPlot->handleDataStructureChanged();
401 }
444 }
402
445
403 void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
446 void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
404 {
447 {
405 Q_Q(QBoxPlotSeries);
448 Q_Q(QBoxPlotSeries);
406 qDebug() << "QBoxPlotSeriesPrivate::initializeTheme";
449 qDebug() << "QBoxPlotSeriesPrivate::initializeTheme";
407
450
408 const QList<QGradient> gradients = theme->seriesGradients();
451 const QList<QGradient> gradients = theme->seriesGradients();
409
452
410 if (forced || m_brush == QBrush(Qt::NoBrush)) {
453 if (forced || m_brush == QBrush(Qt::NoBrush)) {
411 QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.5);
454 QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.5);
412 q->setBrush(brushColor);
455 q->setBrush(brushColor);
413 }
456 }
414
457
415 if (forced || m_pen == QPen(Qt::NoPen)) {
458 if (forced || m_pen == QPen(Qt::NoPen)) {
416 QPen pen = theme->outlinePen();
459 QPen pen = theme->outlinePen();
417 pen.setCosmetic(true);
460 pen.setCosmetic(true);
418 q->setPen(pen);
461 q->setPen(pen);
419 }
462 }
420 }
463 }
421
464
422 void QBoxPlotSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
465 void QBoxPlotSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
423 {
466 {
424 BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data());
467 BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data());
425 Q_ASSERT(item);
468 Q_ASSERT(item);
426 if (options.testFlag(QChart::SeriesAnimations)) {
469 if (options.testFlag(QChart::SeriesAnimations)) {
427 item->setAnimation(new BoxPlotAnimation(item));
470 item->setAnimation(new BoxPlotAnimation(item));
428 }else{
471 }else{
429 item->setAnimation((BoxPlotAnimation *)0);
472 item->setAnimation((BoxPlotAnimation *)0);
430 }
473 }
431 QAbstractSeriesPrivate::initializeAnimations(options);
474 QAbstractSeriesPrivate::initializeAnimations(options);
432 }
475 }
433
476
434 QList<QLegendMarker*> QBoxPlotSeriesPrivate::createLegendMarkers(QLegend *legend)
477 QList<QLegendMarker*> QBoxPlotSeriesPrivate::createLegendMarkers(QLegend *legend)
435 {
478 {
436 Q_Q(QBoxPlotSeries);
479 Q_Q(QBoxPlotSeries);
437 QList<QLegendMarker*> list;
480 QList<QLegendMarker*> list;
438 return list << new QBoxPlotLegendMarker(q, legend);
481 return list << new QBoxPlotLegendMarker(q, legend);
439 }
482 }
440
483
441 void QBoxPlotSeriesPrivate::handleSeriesRemove(QAbstractSeries *series)
484 void QBoxPlotSeriesPrivate::handleSeriesRemove(QAbstractSeries *series)
442 {
485 {
443 qDebug() << "QBoxPlotSeriesPrivate::handleSeriesRemove";
486 qDebug() << "QBoxPlotSeriesPrivate::handleSeriesRemove";
444 Q_Q(QBoxPlotSeries);
487 Q_Q(QBoxPlotSeries);
445
488
446 QBoxPlotSeries *removedSeries = static_cast<QBoxPlotSeries *>(series);
489 QBoxPlotSeries *removedSeries = static_cast<QBoxPlotSeries *>(series);
447 QObject::disconnect(m_chart->d_ptr->m_dataset, 0, removedSeries->d_func(), 0);
490 QObject::disconnect(m_chart->d_ptr->m_dataset, 0, removedSeries->d_func(), 0);
448
491
449 // Test if series removed is me, then don't do anything
492 // Test if series removed is me, then don't do anything
450 if (q != removedSeries) {
493 if (q != removedSeries) {
451 BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data());
494 BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data());
452 if (item) {
495 if (item) {
453 item->m_seriesCount = item->m_seriesCount - 1;
496 item->m_seriesCount = item->m_seriesCount - 1;
454 if (removedSeries->d_func()->m_index < m_index) {
497 if (removedSeries->d_func()->m_index < m_index) {
455 m_index--;
498 m_index--;
456 item->m_seriesIndex = m_index;
499 item->m_seriesIndex = m_index;
457 }
500 }
458
501
459 item->handleDataStructureChanged();
502 item->handleDataStructureChanged();
460 }
503 }
461 }
504 }
462 }
505 }
463
506
464 void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series)
507 void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series)
465 {
508 {
466 Q_UNUSED(series);
509 Q_UNUSED(series);
467
510
468 Q_Q(QBoxPlotSeries);
511 Q_Q(QBoxPlotSeries);
469
512
470 BoxPlotChartItem *boxPlot = static_cast<BoxPlotChartItem *>(m_item.data());
513 BoxPlotChartItem *boxPlot = static_cast<BoxPlotChartItem *>(m_item.data());
471
514
472 if (m_chart) {
515 if (m_chart) {
473 QList<QAbstractSeries *> serieses = m_chart->series();
516 QList<QAbstractSeries *> serieses = m_chart->series();
474
517
475 // Tries to find this series from the Chart's list of serieses and deduce the index
518 // Tries to find this series from the Chart's list of serieses and deduce the index
476 int index = 0;
519 int index = 0;
477 foreach (QAbstractSeries *s, serieses) {
520 foreach (QAbstractSeries *s, serieses) {
478 if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) {
521 if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) {
479 if (q == static_cast<QBoxPlotSeries *>(s)) {
522 if (q == static_cast<QBoxPlotSeries *>(s)) {
480 boxPlot->m_seriesIndex = index;
523 boxPlot->m_seriesIndex = index;
481 m_index = index;
524 m_index = index;
482 }
525 }
483 index++;
526 index++;
484 }
527 }
485 }
528 }
486 boxPlot->m_seriesCount = index;
529 boxPlot->m_seriesCount = index;
487 }
530 }
488
531
489 boxPlot->handleDataStructureChanged();
532 boxPlot->handleDataStructureChanged();
490 }
533 }
491
534
492 bool QBoxPlotSeriesPrivate::append(QBoxSet *set)
535 bool QBoxPlotSeriesPrivate::append(QBoxSet *set)
493 {
536 {
494 if ((m_boxSets.contains(set)) || (set == 0))
537 if ((m_boxSets.contains(set)) || (set == 0))
495 return false; // Fail if set is already in list or set is null.
538 return false; // Fail if set is already in list or set is null.
496
539
497 m_boxSets.append(set);
540 m_boxSets.append(set);
498 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
541 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
499 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
542 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
500 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
543 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
501
544
502 emit restructuredBoxes(); // this notifies boxplotchartitem
545 emit restructuredBoxes(); // this notifies boxplotchartitem
503 return true;
546 return true;
504 }
547 }
505
548
506 bool QBoxPlotSeriesPrivate::remove(QBoxSet *set)
549 bool QBoxPlotSeriesPrivate::remove(QBoxSet *set)
507 {
550 {
508 if (!m_boxSets.contains(set))
551 if (!m_boxSets.contains(set))
509 return false; // Fail if set is not in list
552 return false; // Fail if set is not in list
510
553
511 m_boxSets.removeOne(set);
554 m_boxSets.removeOne(set);
512 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
555 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
513 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
556 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
514 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
557 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
515
558
516 emit restructuredBoxes(); // this notifies boxplotchartitem
559 emit restructuredBoxes(); // this notifies boxplotchartitem
517 return true;
560 return true;
518 }
561 }
519
562
520 bool QBoxPlotSeriesPrivate::append(QList<QBoxSet * > sets)
563 bool QBoxPlotSeriesPrivate::append(QList<QBoxSet * > sets)
521 {
564 {
522 foreach (QBoxSet *set, sets) {
565 foreach (QBoxSet *set, sets) {
523 if ((set == 0) || (m_boxSets.contains(set)))
566 if ((set == 0) || (m_boxSets.contains(set)))
524 return false; // Fail if any of the sets is null or is already appended.
567 return false; // Fail if any of the sets is null or is already appended.
525 if (sets.count(set) != 1)
568 if (sets.count(set) != 1)
526 return false; // Also fail if same set is more than once in given list.
569 return false; // Also fail if same set is more than once in given list.
527 }
570 }
528
571
529 foreach (QBoxSet *set, sets) {
572 foreach (QBoxSet *set, sets) {
530 m_boxSets.append(set);
573 m_boxSets.append(set);
531 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
574 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
532 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
575 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
533 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
576 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
534 }
577 }
535
578
536 emit restructuredBoxes(); // this notifies boxplotchartitem
579 emit restructuredBoxes(); // this notifies boxplotchartitem
537 return true;
580 return true;
538 }
581 }
539
582
540 bool QBoxPlotSeriesPrivate::remove(QList<QBoxSet * > sets)
583 bool QBoxPlotSeriesPrivate::remove(QList<QBoxSet * > sets)
541 {
584 {
542 if (sets.count() == 0)
585 if (sets.count() == 0)
543 return false;
586 return false;
544
587
545 foreach (QBoxSet *set, sets) {
588 foreach (QBoxSet *set, sets) {
546 if ((set == 0) || (!m_boxSets.contains(set)))
589 if ((set == 0) || (!m_boxSets.contains(set)))
547 return false; // Fail if any of the sets is null or is not in series
590 return false; // Fail if any of the sets is null or is not in series
548 if (sets.count(set) != 1)
591 if (sets.count(set) != 1)
549 return false; // Also fail if same set is more than once in given list.
592 return false; // Also fail if same set is more than once in given list.
550 }
593 }
551
594
552 foreach (QBoxSet *set, sets) {
595 foreach (QBoxSet *set, sets) {
553 m_boxSets.removeOne(set);
596 m_boxSets.removeOne(set);
554 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
597 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
555 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
598 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
556 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
599 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
557 }
600 }
558
601
559 emit restructuredBoxes(); // this notifies boxplotchartitem
602 emit restructuredBoxes(); // this notifies boxplotchartitem
560
603
561 return true;
604 return true;
562 }
605 }
563
606
564 bool QBoxPlotSeriesPrivate::insert(int index, QBoxSet *set)
607 bool QBoxPlotSeriesPrivate::insert(int index, QBoxSet *set)
565 {
608 {
566 if ((m_boxSets.contains(set)) || (set == 0))
609 if ((m_boxSets.contains(set)) || (set == 0))
567 return false; // Fail if set is already in list or set is null.
610 return false; // Fail if set is already in list or set is null.
568
611
569 m_boxSets.insert(index, set);
612 m_boxSets.insert(index, set);
570 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
613 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
571 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
614 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
572 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
615 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
573
616
574 emit restructuredBoxes(); // this notifies boxplotchartitem
617 emit restructuredBoxes(); // this notifies boxplotchartitem
575 return true;
618 return true;
576 }
619 }
577
620
578 QBoxSet *QBoxPlotSeriesPrivate::boxsetAt(int index)
621 QBoxSet *QBoxPlotSeriesPrivate::boxsetAt(int index)
579 {
622 {
580 return m_boxSets.at(index);
623 return m_boxSets.at(index);
581 }
624 }
582
625
583 qreal QBoxPlotSeriesPrivate::bottom()
626 qreal QBoxPlotSeriesPrivate::bottom()
584 {
627 {
585 // Returns bottom of all boxes
628 // Returns bottom of all boxes
586 qreal bottom(0);
629 qreal bottom(0);
587 foreach (QBoxSet *set, m_boxSets) {
630 foreach (QBoxSet *set, m_boxSets) {
588 for (int i = 0; i < set->count(); i++) {
631 for (int i = 0; i < set->count(); i++) {
589 if (set->at(i) < bottom)
632 if (set->at(i) < bottom)
590 bottom = set->at(i);
633 bottom = set->at(i);
591 }
634 }
592 }
635 }
593
636
594 return bottom;
637 return bottom;
595 }
638 }
596
639
597 qreal QBoxPlotSeriesPrivate::max()
640 qreal QBoxPlotSeriesPrivate::max()
598 {
641 {
599 if (m_boxSets.count() <= 0)
642 if (m_boxSets.count() <= 0)
600 return 0;
643 return 0;
601
644
602 qreal max = INT_MIN;
645 qreal max = INT_MIN;
603
646
604 foreach (QBoxSet *set, m_boxSets) {
647 foreach (QBoxSet *set, m_boxSets) {
605 for (int i = 0; i < set->count(); i++) {
648 for (int i = 0; i < set->count(); i++) {
606 if (set->at(i) > max)
649 if (set->at(i) > max)
607 max = set->at(i);
650 max = set->at(i);
608 }
651 }
609 }
652 }
610
653
611 return max;
654 return max;
612 }
655 }
613
656
614 #include "moc_qboxplotseries.cpp"
657 #include "moc_qboxplotseries.cpp"
615 #include "moc_qboxplotseries_p.cpp"
658 #include "moc_qboxplotseries_p.cpp"
616
659
617 QTCOMMERCIALCHART_END_NAMESPACE
660 QTCOMMERCIALCHART_END_NAMESPACE
618
661
@@ -1,493 +1,569
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 "qboxset.h"
21 #include "qboxset.h"
22 #include "qboxset_p.h"
22 #include "qboxset_p.h"
23 #include "charthelpers_p.h"
23 #include "charthelpers_p.h"
24
24
25 #include <QDebug> //TODO: remove on release
25 #include <QDebug> //TODO: remove on release
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 /*!
29 /*!
30 \class QBoxSet
30 \class QBoxSet
31 \brief Building block for box-and-whiskers chart
31 \brief Building block for box-and-whiskers chart
32
32
33 QBoxSet represents one box-and-whiskers item. It takes fives values to create a graphical representation
33 QBoxSet represents one box-and-whiskers item. It takes fives values to create a graphical representation
34 of range and three medians. There's two type of methods to give the values. The first one is with constructor
34 of range and three medians. There's two type of methods to give the values. The first one is with constructor
35 or append type of methods (append and operator <<). In these the values have to be given in order lower extreme,
35 or append type of methods (append and operator <<). The values have to be given in order lower extreme,
36 lower quartile, median, upper quartile and upper extre. Second method is to create an empty QBoxSet instance and
36 lower quartile, median, upper quartile and upper extre. Second method is to create an empty QBoxSet instance and
37 give the values using own methods.
37 give the values using value specific methods.
38
38
39 \mainclass
39 \mainclass
40
40
41 \sa QBoxPlotSeries
41 \sa QBoxPlotSeries
42 */
42 */
43 /*!
43 /*!
44 \qmlclass BoxSet QBoxSet
44 \qmlclass BoxSet QBoxSet
45
45
46 BoxSet represents one box-and-whiskers item. It takes fives values to create a graphical representation
46 BoxSet represents one box-and-whiskers item. It takes fives values to create a graphical representation
47 of range and three medians. There's two type of methods to give the values. The first one is with constructor
47 of range and three medians. There's two type of methods to give the values. The first one is with constructor
48 or append type of methods (append and operator <<). In these the values have to be given in order lower extreme,
48 or with append method. In these the values have to be given in order lower extreme, lower quartile, median,
49 lower quartile, median, upper quartile and upper extre. Second method is to create an empty BoxSet instance and
49 upper quartile and upper extre. Second method is to create an empty QBoxSet instance and
50 give the values using own methods.
50 give the values using value specific methods.
51 \sa BoxPlotSeries
51 \sa BoxPlotSeries
52 */
52 */
53 /*!
54 \qmlproperty string BoxSet::label
55 Defines the label of the boxSet.
56 */
57 /*!
58 \qmlproperty int BoxSet::count
59 The count of values on the box-and-whiskers set
60 */
53
61
54 /*!
62 /*!
55 \property QBoxSet::pen
63 \property QBoxSet::pen
56 \brief Defines the pen used by the box-and-whiskers set.
64 \brief Defines the pen used by the box-and-whiskers set.
57 */
65 */
58
66
59 /*!
67 /*!
60 \property QBoxSet::brush
68 \property QBoxSet::brush
61 \brief Defines the brush used by the box-and-whiskers set.
69 \brief Defines the brush used by the box-and-whiskers set.
62 */
70 */
63
71
64 /*!
72 /*!
65 \property QBoxSet::color
73 \property QBoxSet::color
66 The fill (brush) color of the box-and-whiskers set.
74 The fill (brush) color of the box-and-whiskers set.
67 */
75 */
68
76 /*!
77 \qmlproperty color BoxSet::color
78 Defines the fill (brush) color of the box-and-whiskers set.
79 */
69 /*!
80 /*!
70 \property QBoxSet::borderColor
81 \property QBoxSet::borderColor
71 The line (pen) color of the box-and-whiskers set.
82 The line (pen) color of the box-and-whiskers set.
72 */
83 */
84 /*!
85 \qmlproperty color BoxSet::borderColor
86 Defines the outline color of the box-and-whiskers set.
87 */
88
89 /*!
90 \qmlproperty qreal BoxSet::lowerExtreme
91 The lower extreme value of the box-and-whiskers set
92 */
93
94 /*!
95 \qmlproperty qreal BoxSet::lowerQuartile
96 The lower quartile value of the box-and-whiskers set
97 */
98
99 /*!
100 \qmlproperty qreal BoxSet::median
101 The median value of the box-and-whiskers set
102 */
103
104 /*!
105 \qmlproperty qreal BoxSet::upperQuartile
106 The upper quartile value of the box-and-whiskers set
107 */
108
109 /*!
110 \qmlproperty qreal BoxSet::upperExtreme
111 The upper extreme value of the box-and-whiskers set
112 */
73
113
74 /*!
114 /*!
75 \fn void QBoxSet::clicked()
115 \fn void QBoxSet::clicked()
76 The signal is emitted if the user clicks with a mouse on top of box-and-whisker item.
116 The signal is emitted if the user clicks with a mouse on top of box-and-whisker item.
77 */
117 */
118 /*!
119 \qmlsignal BoxSet::onClicked()
120 This signal is emitted when the user clicks with a mouse on top of box-and-whisker item.
121 */
78
122
79 /*!
123 /*!
80 \fn void QBoxSet::hovered(bool status)
124 \fn void QBoxSet::hovered(bool status)
81
125
82 The signal is emitted if mouse is hovered on top of box-and-whisker item.
126 The signal is emitted if mouse is hovered on top of box-and-whisker item.
83 Parameter \a status is true, if mouse entered on top of item, false if mouse left from top of item.
127 Parameter \a status is true, if mouse entered on top of item, false if mouse left from top of item.
84 */
128 */
129 /*!
130 \qmlsignal BoxSet::onHovered(bool status)
131
132 The signal is emitted if mouse is hovered on top of box-and-whisker item.
133 Parameter \a status is true, if mouse entered on top of item, false if mouse left from top of item.
134 */
85
135
86 /*!
136 /*!
87 \fn void QBoxSet::penChanged()
137 \fn void QBoxSet::penChanged()
88 This signal is emitted when the pen of the box-and-whisker item has changed.
138 This signal is emitted when the pen of the box-and-whisker item has changed.
89 \sa pen
139 \sa pen
90 */
140 */
91
141 /*!
142 \qmlsignal BoxSet::onPenChanged()
143 This signal is emitted when the pen of the box-and-whisker item has changed.
144 */
92 /*!
145 /*!
93 \fn void QBoxSet::brushChanged()
146 \fn void QBoxSet::brushChanged()
94 This signal is emitted when the brush of the box-and-whisker item has changed.
147 This signal is emitted when the brush of the box-and-whisker item has changed.
95 \sa brush
148 \sa brush
96 */
149 */
150 /*!
151 \qmlsignal BoxSet::onBrushChanged()
152 This signal is emitted when the brush of the box-and-whisker item has changed.
153 */
97
154
98 /*!
155 /*!
99 \fn void QBoxSet::colorChanged(QColor)
156 \fn void QBoxSet::colorChanged(QColor)
100 This signal is emitted when the fill (brush) color of the box-and-whisker item has changed to \a color.
157 This signal is emitted when the fill (brush) color of the box-and-whisker item has changed to \a color.
101 */
158 */
159 /*!
160 \qmlsignal BoxSet::onColorChanged(QColor color)
161 This signal is emitted when the fill (brush) color of the box-and-whisker item has changed to \a color.
162 */
102
163
103 /*!
164 /*!
104 \fn void QBoxSet::valuesAdded(int index, int count)
165 \fn void QBoxSet::valuesAdded(int index, int count)
105 This signal is emitted when new values have been added to the box-and-whisker item.
166 This signal is emitted when new values have been added to the box-and-whisker item.
106 Parameter \a index indicates the position of the first inserted value.
167 Parameter \a index indicates the position of the first inserted value.
107 Parameter \a count is the number of inserted values.
168 Parameter \a count is the number of inserted values.
108 \sa append(), insert()
169 \sa append(), insert()
109 */
170 */
171 /*!
172 \qmlsignal BoxSet::onValuesAdded(int index, int count)
173 This signal is emitted when new values have been added to the box-and-whisker item.
174 Parameter \a index indicates the position of the first inserted value.
175 Parameter \a count is the number of inserted values.
176 */
110
177
111 /*!
178 /*!
112 \fn void QBoxSet::valueChanged(int index)
179 \fn void QBoxSet::valueChanged(int index)
113 This signal is emitted values the value in the box-and-whisker item has been modified.
180 This signal is emitted values the value in the box-and-whisker item has been modified.
114 Parameter \a index indicates the position of the modified value.
181 Parameter \a index indicates the position of the modified value.
115 \sa at()
182 \sa at()
116 */
183 */
117
184 /*!
185 \qmlsignal BoxSet::onValueChanged(int index)
186 This signal is emitted values the value in the box-and-whisker item has been modified.
187 Parameter \a index indicates the position of the modified value.
188 */
118 /*!
189 /*!
119 \fn void QBoxSet::borderColorChanged(QColor)
190 \fn void QBoxSet::borderColorChanged(QColor)
120 This signal is emitted when the line (pen) color of the box-and-whisker item has changed to \a color.
191 This signal is emitted when the line (pen) color of the box-and-whisker item has changed to \a color.
121 */
192 */
193 /*!
194 \qmlsignal BoxSet::onBorderColorChanged(QColor color)
195 This signal is emitted when the line (pen) color of the box-and-whisker item has changed to \a color.
196 */
122
197
123 /*!
198 /*!
124 Constructs QBoxSet with optional \a label and parent of \a parent
199 Constructs QBoxSet with optional \a label and parent of \a parent
125 */
200 */
126 QBoxSet::QBoxSet(const QString label, QObject *parent)
201 QBoxSet::QBoxSet(const QString label, QObject *parent)
127 : QObject(parent),
202 : QObject(parent),
128 d_ptr(new QBoxSetPrivate(label, this))
203 d_ptr(new QBoxSetPrivate(label, this))
129 {
204 {
130 }
205 }
131
206
132 /*!
207 /*!
133 Constructs QBoxSet with given ordered values. \a le for lower extreme, \a lq for lower quartile, \a m for median,
208 Constructs QBoxSet with given ordered values. \a le for lower extreme, \a lq for lower quartile, \a m for median,
134 \a uq for upper quartile and \a ue for upper quartile. \a label and \a parent are optional.
209 \a uq for upper quartile and \a ue for upper quartile. \a label and \a parent are optional.
135 */
210 */
136 QBoxSet::QBoxSet(const qreal le, const qreal lq, const qreal m, const qreal uq, const qreal ue, const QString label, QObject *parent)
211 QBoxSet::QBoxSet(const qreal le, const qreal lq, const qreal m, const qreal uq, const qreal ue, const QString label, QObject *parent)
137 : QObject(parent),
212 : QObject(parent),
138 d_ptr(new QBoxSetPrivate(label, this))
213 d_ptr(new QBoxSetPrivate(label, this))
139 {
214 {
140 d_ptr->append(le);
215 d_ptr->append(le);
141 d_ptr->append(lq);
216 d_ptr->append(lq);
142 d_ptr->append(m);
217 d_ptr->append(m);
143 d_ptr->append(uq);
218 d_ptr->append(uq);
144 d_ptr->append(ue);
219 d_ptr->append(ue);
145 }
220 }
146
221
147 /*!
222 /*!
148 Destroys the boxset
223 Destroys the boxset
149 */
224 */
150 QBoxSet::~QBoxSet()
225 QBoxSet::~QBoxSet()
151 {
226 {
152 // NOTE: d_ptr destroyed by QObject
227 // NOTE: d_ptr destroyed by QObject
153 }
228 }
154
229
155 /*!
230 /*!
156 Appends new value \a value to the end of set.
231 Appends new value \a value to the end of set.
157 */
232 */
158 void QBoxSet::append(const qreal value)
233 void QBoxSet::append(const qreal value)
159 {
234 {
160 //int index = d_ptr->m_values.count();
235 //int index = d_ptr->m_values.count();
161 d_ptr->append(value);
236 d_ptr->append(value);
162
237
163 emit valuesAdded(d_ptr->m_valuesCount, 1);
238 emit valuesAdded(d_ptr->m_valuesCount, 1);
164 }
239 }
165
240
166 /*!
241 /*!
167 Appends a list of reals to set. Works like append with single real value. The \a values in list
242 Appends a list of reals to set. Works like append with single real value. The \a values in list
168 are appended to end of boxset
243 are appended to end of boxset
169 \sa append()
244 \sa append()
170 */
245 */
171 void QBoxSet::append(const QList<qreal> &values)
246 void QBoxSet::append(const QList<qreal> &values)
172 {
247 {
173 //int index = d_ptr->m_values.count();
248 //int index = d_ptr->m_values.count();
174 d_ptr->append(values);
249 d_ptr->append(values);
175 emit valuesAdded(d_ptr->m_valuesCount, values.count());
250 emit valuesAdded(d_ptr->m_valuesCount, values.count());
176 }
251 }
177
252
178 /*!
253 /*!
179 Sets new value \a value as the lower extreme for the set.
254 Sets new value \a value as the lower extreme for the set.
180 */
255 */
181 void QBoxSet::setLowerExtreme(const qreal value)
256 void QBoxSet::setLowerExtreme(const qreal value)
182 {
257 {
183 d_ptr->replace(QBoxSetPrivate::PosLowerExtreme, value);
258 d_ptr->replace(QBoxSetPrivate::PosLowerExtreme, value);
184 emit d_ptr->restructuredBox();
259 emit d_ptr->restructuredBox();
185 emit valueChanged(QBoxSetPrivate::PosLowerExtreme);
260 emit valueChanged(QBoxSetPrivate::PosLowerExtreme);
186 }
261 }
187
262
188 /*!
263 /*!
189 Returns the lower extreme value of the set.
264 Returns the lower extreme value of the set.
190 */
265 */
191 qreal QBoxSet::lowerExtreme()
266 qreal QBoxSet::lowerExtreme()
192 {
267 {
193 return d_ptr->m_values[QBoxSetPrivate::PosLowerExtreme];
268 return d_ptr->m_values[QBoxSetPrivate::PosLowerExtreme];
194 }
269 }
195
270
196 /*!
271 /*!
197 Sets new value \a value as the lower quartile for the set.
272 Sets new value \a value as the lower quartile for the set.
198 */
273 */
199 void QBoxSet::setLowerQuartile(const qreal value)
274 void QBoxSet::setLowerQuartile(const qreal value)
200 {
275 {
201 d_ptr->replace(QBoxSetPrivate::PosLowerQuartile, value);
276 d_ptr->replace(QBoxSetPrivate::PosLowerQuartile, value);
202 emit d_ptr->restructuredBox();
277 emit d_ptr->restructuredBox();
203 emit valueChanged(QBoxSetPrivate::PosLowerQuartile);
278 emit valueChanged(QBoxSetPrivate::PosLowerQuartile);
204 }
279 }
205
280
206 /*!
281 /*!
207 Returns the lower quartile value of the set.
282 Returns the lower quartile value of the set.
208 */
283 */
209 qreal QBoxSet::lowerQuartile()
284 qreal QBoxSet::lowerQuartile()
210 {
285 {
211 return d_ptr->m_values[QBoxSetPrivate::PosLowerQuartile];
286 return d_ptr->m_values[QBoxSetPrivate::PosLowerQuartile];
212 }
287 }
213
288
214 /*!
289 /*!
215 Sets new value \a value as the median for the set.
290 Sets new value \a value as the median for the set.
216 */
291 */
217 void QBoxSet::setMedian(const qreal value)
292 void QBoxSet::setMedian(const qreal value)
218 {
293 {
219 d_ptr->replace(QBoxSetPrivate::PosMedian, value);
294 d_ptr->replace(QBoxSetPrivate::PosMedian, value);
220 emit d_ptr->restructuredBox();
295 emit d_ptr->restructuredBox();
221 emit valueChanged(QBoxSetPrivate::PosMedian);
296 emit valueChanged(QBoxSetPrivate::PosMedian);
222 }
297 }
223
298
224 /*!
299 /*!
225 Returns the median value of the set.
300 Returns the median value of the set.
226 */
301 */
227 qreal QBoxSet::median()
302 qreal QBoxSet::median()
228 {
303 {
229 return d_ptr->m_values[QBoxSetPrivate::PosMedian];
304 return d_ptr->m_values[QBoxSetPrivate::PosMedian];
230 }
305 }
231
306
232 /*!
307 /*!
233 Sets new value \a value as the upper quartile for the set.
308 Sets new value \a value as the upper quartile for the set.
234 */
309 */
235 void QBoxSet::setUpperQuartile(const qreal value)
310 void QBoxSet::setUpperQuartile(const qreal value)
236 {
311 {
237 d_ptr->replace(QBoxSetPrivate::PosUpperQuartile, value);
312 d_ptr->replace(QBoxSetPrivate::PosUpperQuartile, value);
238 emit d_ptr->restructuredBox();
313 emit d_ptr->restructuredBox();
239 emit valueChanged(QBoxSetPrivate::PosUpperQuartile);
314 emit valueChanged(QBoxSetPrivate::PosUpperQuartile);
240 }
315 }
241
316
242 /*!
317 /*!
243 Returns the upper quartile value of the set.
318 Returns the upper quartile value of the set.
244 */
319 */
245 qreal QBoxSet::upperQuartile()
320 qreal QBoxSet::upperQuartile()
246 {
321 {
247 return d_ptr->m_values[QBoxSetPrivate::PosUpperQuartile];
322 return d_ptr->m_values[QBoxSetPrivate::PosUpperQuartile];
248 }
323 }
249
324
250 /*!
325 /*!
251 Sets new value \a value as the upper extreme for the set.
326 Sets new value \a value as the upper extreme for the set.
252 */
327 */
253 void QBoxSet::setUpperExtreme(const qreal value)
328 void QBoxSet::setUpperExtreme(const qreal value)
254 {
329 {
255 d_ptr->replace(QBoxSetPrivate::PosUpperExtreme, value);
330 d_ptr->replace(QBoxSetPrivate::PosUpperExtreme, value);
256 emit d_ptr->restructuredBox();
331 emit d_ptr->restructuredBox();
257 emit valueChanged(QBoxSetPrivate::PosUpperExtreme);
332 emit valueChanged(QBoxSetPrivate::PosUpperExtreme);
258 }
333 }
259
334
260 /*!
335 /*!
261 Returns the upper extreme value of the set.
336 Returns the upper extreme value of the set.
262 */
337 */
263 qreal QBoxSet::upperExtreme()
338 qreal QBoxSet::upperExtreme()
264 {
339 {
265 return d_ptr->m_values[QBoxSetPrivate::PosUpperExtreme];
340 return d_ptr->m_values[QBoxSetPrivate::PosUpperExtreme];
266 }
341 }
267
342
268 /*!
343 /*!
269 Sets new \a label for set.
344 Sets new \a label for set.
270 */
345 */
271 void QBoxSet::setLabel(const QString label)
346 void QBoxSet::setLabel(const QString label)
272 {
347 {
273 d_ptr->m_label = label;
348 d_ptr->m_label = label;
274 }
349 }
275
350
276 /*!
351 /*!
277 Returns label of the set.
352 Returns label of the set.
278 */
353 */
279 QString QBoxSet::label() const
354 QString QBoxSet::label() const
280 {
355 {
281 return d_ptr->m_label;
356 return d_ptr->m_label;
282 }
357 }
283
358
284 /*!
359 /*!
285 Convenience operator. Same as append, with real \a value.
360 Convenience operator. Same as append, with real \a value.
286 \sa append()
361 \sa append()
287 */
362 */
288 QBoxSet &QBoxSet::operator << (const qreal &value)
363 QBoxSet &QBoxSet::operator << (const qreal &value)
289 {
364 {
290 append(value);
365 append(value);
291 return *this;
366 return *this;
292 }
367 }
293
368
294 /*!
369 /*!
295 Inserts new \a value on the \a index position.
370 Inserts new \a value on the \a index position.
296 The value that is currently at this postion is moved to postion index + 1
371 The value that is currently at this postion is moved to postion index + 1
297 */
372 */
298 void QBoxSet::insert(const int index, const qreal value)
373 void QBoxSet::insert(const int index, const qreal value)
299 {
374 {
300 d_ptr->insert(index, value);
375 d_ptr->insert(index, value);
301 emit valuesAdded(index, 1);
376 emit valuesAdded(index, 1);
302 }
377 }
303
378
304 /*!
379 /*!
305 Sets a new value \a value to set, indexed by \a index
380 Sets a new value \a value to set, indexed by \a index
306 */
381 */
307 void QBoxSet::replace(const int index, const qreal value)
382 void QBoxSet::replace(const int index, const qreal value)
308 {
383 {
309 if (index >= 0 && index < 5) {
384 if (index >= 0 && index < 5) {
310 d_ptr->replace(index, value);
385 d_ptr->replace(index, value);
311 emit valueChanged(index);
386 emit valueChanged(index);
312 }
387 }
313 }
388 }
314
389
315
390
316 /*!
391 /*!
317 Returns value of set indexed by \a index.
392 Returns value of set indexed by \a index.
318 If the index is out of bounds 0.0 is returned.
393 If the index is out of bounds 0.0 is returned.
319 */
394 */
320 qreal QBoxSet::at(const int index) const
395 qreal QBoxSet::at(const int index) const
321 {
396 {
322 if (index < 0 || index >= 5)
397 if (index < 0 || index >= 5)
323 return 0;
398 return 0;
324 return d_ptr->m_values[index];
399 return d_ptr->m_values[index];
325 }
400 }
326
401
327 /*!
402 /*!
328 Returns value of set indexed by \a index.
403 Returns value of set indexed by \a index.
329 If the index is out of bounds 0.0 is returned.
404 If the index is out of bounds 0.0 is returned.
330 */
405 */
331 qreal QBoxSet::operator [](const int index) const
406 qreal QBoxSet::operator [](const int index) const
332 {
407 {
333 return at(index);
408 return at(index);
334 }
409 }
335
410
336 /*!
411 /*!
337 Returns count of values in set.
412 Returns count of values in set.
338 */
413 */
339 int QBoxSet::count() const
414 int QBoxSet::count() const
340 {
415 {
341 return d_ptr->m_valuesCount;
416 return d_ptr->m_valuesCount;
342 }
417 }
343
418
344 /*!
419 /*!
345 Sets pen for set. Boxes of this set are drawn using \a pen
420 Sets pen for set. Boxes of this set are drawn using \a pen
346 */
421 */
347 void QBoxSet::setPen(const QPen &pen)
422 void QBoxSet::setPen(const QPen &pen)
348 {
423 {
349 if (d_ptr->m_pen != pen) {
424 if (d_ptr->m_pen != pen) {
350 d_ptr->m_pen = pen;
425 d_ptr->m_pen = pen;
351 emit d_ptr->updatedBox();
426 emit d_ptr->updatedBox();
352 emit penChanged();
427 emit penChanged();
353 }
428 }
354 }
429 }
355
430
356 /*!
431 /*!
357 Returns pen of the set.
432 Returns pen of the set.
358 */
433 */
359 QPen QBoxSet::pen() const
434 QPen QBoxSet::pen() const
360 {
435 {
361 return d_ptr->m_pen;
436 return d_ptr->m_pen;
362 }
437 }
363
438
364 /*!
439 /*!
365 Sets brush for the set. Boxes of this set are drawn using \a brush
440 Sets brush for the set. Boxes of this set are drawn using \a brush
366 */
441 */
367 void QBoxSet::setBrush(const QBrush &brush)
442 void QBoxSet::setBrush(const QBrush &brush)
368 {
443 {
369 if (d_ptr->m_brush != brush) {
444 if (d_ptr->m_brush != brush) {
370 d_ptr->m_brush = brush;
445 d_ptr->m_brush = brush;
371 emit d_ptr->updatedBox();
446 emit d_ptr->updatedBox();
372 emit brushChanged();
447 emit brushChanged();
373 }
448 }
374 }
449 }
375
450
376 /*!
451 /*!
377 Returns brush of the set.
452 Returns brush of the set.
378 */
453 */
379 QBrush QBoxSet::brush() const
454 QBrush QBoxSet::brush() const
380 {
455 {
381 return d_ptr->m_brush;
456 return d_ptr->m_brush;
382 }
457 }
383
458
384 /*!
459 /*!
385 Returns the color of the brush of boxset.
460 Returns the color of the brush of boxset.
386 */
461 */
387 QColor QBoxSet::color()
462 QColor QBoxSet::color()
388 {
463 {
389 return brush().color();
464 return brush().color();
390 }
465 }
391
466
392 /*!
467 /*!
393 Sets the \a color of brush for this boxset
468 Sets the \a color of brush for this boxset
394 */
469 */
395 void QBoxSet::setColor(QColor color)
470 void QBoxSet::setColor(QColor color)
396 {
471 {
397 QBrush b = brush();
472 QBrush b = brush();
398 if ((b.color() != color) || (b.style() == Qt::NoBrush)) {
473 if ((b.color() != color) || (b.style() == Qt::NoBrush)) {
399 b.setColor(color);
474 b.setColor(color);
400 if (b.style() == Qt::NoBrush) {
475 if (b.style() == Qt::NoBrush) {
401 // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush)
476 // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush)
402 // This prevents theme to override color defined in QML side:
477 // This prevents theme to override color defined in QML side:
403 // BoxSet { label: "Bob"; color:"red"; values: [1,2,3] }
478 // BoxSet { label: "Bob"; color:"red"; values: [1,2,3] }
404 // The color must be obeyed, since user wanted it.
479 // The color must be obeyed, since user wanted it.
405 b.setStyle(Qt::SolidPattern);
480 b.setStyle(Qt::SolidPattern);
406 }
481 }
407 setBrush(b);
482 setBrush(b);
408 emit colorChanged(color);
483 emit colorChanged(color);
409 }
484 }
410 }
485 }
411
486
412 /*!
487 /*!
413 Returns the color of pen of this boxset
488 Returns the color of pen of this boxset
414 */
489 */
415 QColor QBoxSet::borderColor()
490 QColor QBoxSet::borderColor()
416 {
491 {
417 return pen().color();
492 return pen().color();
418 }
493 }
419
494
420 /*!
495 /*!
421 Sets the color of pen for this boxset
496 Sets the color of pen for this boxset
422 */
497 */
423 void QBoxSet::setBorderColor(QColor color)
498 void QBoxSet::setBorderColor(QColor color)
424 {
499 {
425 QPen p = pen();
500 QPen p = pen();
426 if (p.color() != color) {
501 if (p.color() != color) {
427 p.setColor(color);
502 p.setColor(color);
503 p.setStyle(Qt::SolidLine);
428 setPen(p);
504 setPen(p);
429 emit borderColorChanged(color);
505 emit borderColorChanged(color);
430 }
506 }
431 }
507 }
432
508
433 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
509 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
434
510
435 QBoxSetPrivate::QBoxSetPrivate(const QString label, QBoxSet *parent) : QObject(parent),
511 QBoxSetPrivate::QBoxSetPrivate(const QString label, QBoxSet *parent) : QObject(parent),
436 q_ptr(parent),
512 q_ptr(parent),
437 m_label(label),
513 m_label(label),
438 m_valuesCount(5),
514 m_valuesCount(5),
439 m_appendCount(0),
515 m_appendCount(0),
440 m_pen(QPen(Qt::NoPen)),
516 m_pen(QPen(Qt::NoPen)),
441 m_brush(QBrush(Qt::NoBrush))
517 m_brush(QBrush(Qt::NoBrush))
442 {
518 {
443 m_values = new qreal[m_valuesCount];
519 m_values = new qreal[m_valuesCount];
444 }
520 }
445
521
446 QBoxSetPrivate::~QBoxSetPrivate()
522 QBoxSetPrivate::~QBoxSetPrivate()
447 {
523 {
448 }
524 }
449
525
450 void QBoxSetPrivate::append(qreal value)
526 void QBoxSetPrivate::append(qreal value)
451 {
527 {
452 if (isValidValue(value) && m_appendCount < m_valuesCount) {
528 if (isValidValue(value) && m_appendCount < m_valuesCount) {
453 m_values[m_appendCount++] = value;
529 m_values[m_appendCount++] = value;
454 emit restructuredBox();
530 emit restructuredBox();
455 }
531 }
456 }
532 }
457
533
458 void QBoxSetPrivate::append(QList<qreal> values)
534 void QBoxSetPrivate::append(QList<qreal> values)
459 {
535 {
460 for (int i = 0; i < values.count(); i++) {
536 for (int i = 0; i < values.count(); i++) {
461 if (isValidValue(values.at(i)) && m_appendCount < m_valuesCount)
537 if (isValidValue(values.at(i)) && m_appendCount < m_valuesCount)
462 m_values[m_appendCount++] = values.at(i);
538 m_values[m_appendCount++] = values.at(i);
463 }
539 }
464 emit restructuredBox();
540 emit restructuredBox();
465 }
541 }
466
542
467 void QBoxSetPrivate::insert(const int index, const qreal value)
543 void QBoxSetPrivate::insert(const int index, const qreal value)
468 {
544 {
469 if (isValidValue(value)) {
545 if (isValidValue(value)) {
470 for (int i = 4; i > index; i--)
546 for (int i = 4; i > index; i--)
471 m_values[i] = m_values[i - 1];
547 m_values[i] = m_values[i - 1];
472 m_values[index] = value;
548 m_values[index] = value;
473 emit restructuredBox();
549 emit restructuredBox();
474 }
550 }
475 }
551 }
476
552
477 void QBoxSetPrivate::replace(const int index, const qreal value)
553 void QBoxSetPrivate::replace(const int index, const qreal value)
478 {
554 {
479 m_values[index] = value;
555 m_values[index] = value;
480 emit updatedLayout();
556 emit updatedLayout();
481 }
557 }
482
558
483 qreal QBoxSetPrivate::value(const int index)
559 qreal QBoxSetPrivate::value(const int index)
484 {
560 {
485 if (index < 0 || index >= m_valuesCount)
561 if (index < 0 || index >= m_valuesCount)
486 return 0;
562 return 0;
487 return m_values[index];
563 return m_values[index];
488 }
564 }
489
565
490 #include "moc_qboxset.cpp"
566 #include "moc_qboxset.cpp"
491 #include "moc_qboxset_p.cpp"
567 #include "moc_qboxset_p.cpp"
492
568
493 QTCOMMERCIALCHART_END_NAMESPACE
569 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now