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