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