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