@@ -1,244 +1,262 | |||||
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 "declarativebarseries.h" |
|
21 | #include "declarativebarseries.h" | |
22 | #include "declarativechart.h" |
|
22 | #include "declarativechart.h" | |
23 | #include <QBarSet> |
|
23 | #include <QBarSet> | |
24 | #include <QVBarModelMapper> |
|
24 | #include <QVBarModelMapper> | |
25 | #include <QHBarModelMapper> |
|
25 | #include <QHBarModelMapper> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) : |
|
29 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) : | |
30 | QBarSet("", parent) |
|
30 | QBarSet("", parent) | |
31 | { |
|
31 | { | |
32 | connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int, int))); |
|
32 | connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int, int))); | |
33 | connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int, int))); |
|
33 | connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int, int))); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | void DeclarativeBarSet::handleCountChanged(int index, int count) |
|
36 | void DeclarativeBarSet::handleCountChanged(int index, int count) | |
37 | { |
|
37 | { | |
38 | Q_UNUSED(index) |
|
38 | Q_UNUSED(index) | |
39 | Q_UNUSED(count) |
|
39 | Q_UNUSED(count) | |
40 | emit countChanged(QBarSet::count()); |
|
40 | emit countChanged(QBarSet::count()); | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | QVariantList DeclarativeBarSet::values() |
|
43 | QVariantList DeclarativeBarSet::values() | |
44 | { |
|
44 | { | |
45 | QVariantList values; |
|
45 | QVariantList values; | |
46 | for (int i(0); i < count(); i++) |
|
46 | for (int i(0); i < count(); i++) | |
47 | values.append(QVariant(at(i))); |
|
47 | values.append(QVariant(at(i))); | |
48 | return values; |
|
48 | return values; | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void DeclarativeBarSet::setValues(QVariantList values) |
|
51 | void DeclarativeBarSet::setValues(QVariantList values) | |
52 | { |
|
52 | { | |
53 | while (count()) |
|
53 | while (count()) | |
54 | remove(count() - 1); |
|
54 | remove(count() - 1); | |
55 |
|
55 | |||
56 | for (int i(0); i < values.count(); i++) { |
|
56 | for (int i(0); i < values.count(); i++) { | |
57 | if (values.at(i).canConvert(QVariant::Double)) |
|
57 | if (values.at(i).canConvert(QVariant::Double)) | |
58 | append(values[i].toDouble()); |
|
58 | append(values[i].toDouble()); | |
59 | } |
|
59 | } | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : |
|
62 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : | |
63 | QBarSeries(parent) |
|
63 | QBarSeries(parent) | |
64 | { |
|
64 | { | |
|
65 | connect(this, SIGNAL(barsetsAdded(QList<QBarSet*>)), this, SLOT(handleAdded(QList<QBarSet*>))); | |||
|
66 | connect(this, SIGNAL(barsetsRemoved(QList<QBarSet*>)), this, SLOT(handleRemoved(QList<QBarSet*>))); | |||
|
67 | } | |||
|
68 | ||||
|
69 | void DeclarativeBarSeries::handleAdded(QList<QBarSet* > barsets) | |||
|
70 | { | |||
|
71 | foreach(QBarSet *b, barsets) { | |||
|
72 | DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b); | |||
|
73 | emit added(barset); | |||
|
74 | } | |||
|
75 | } | |||
|
76 | ||||
|
77 | void DeclarativeBarSeries::handleRemoved(QList<QBarSet* > barsets) | |||
|
78 | { | |||
|
79 | foreach(QBarSet *b, barsets) { | |||
|
80 | DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b); | |||
|
81 | emit removed(barset); | |||
|
82 | } | |||
65 | } |
|
83 | } | |
66 |
|
84 | |||
67 | void DeclarativeBarSeries::classBegin() |
|
85 | void DeclarativeBarSeries::classBegin() | |
68 | { |
|
86 | { | |
69 | } |
|
87 | } | |
70 |
|
88 | |||
71 | void DeclarativeBarSeries::componentComplete() |
|
89 | void DeclarativeBarSeries::componentComplete() | |
72 | { |
|
90 | { | |
73 | foreach(QObject *child, children()) { |
|
91 | foreach(QObject *child, children()) { | |
74 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
92 | if (qobject_cast<DeclarativeBarSet *>(child)) { | |
75 | QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
93 | QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | |
76 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
94 | } else if(qobject_cast<QVBarModelMapper *>(child)) { | |
77 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
95 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
78 | mapper->setSeries(this); |
|
96 | mapper->setSeries(this); | |
79 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
97 | } else if(qobject_cast<QHBarModelMapper *>(child)) { | |
80 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
98 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
81 | mapper->setSeries(this); |
|
99 | mapper->setSeries(this); | |
82 | } |
|
100 | } | |
83 | } |
|
101 | } | |
84 | } |
|
102 | } | |
85 |
|
103 | |||
86 | QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren() |
|
104 | QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren() | |
87 | { |
|
105 | { | |
88 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); |
|
106 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); | |
89 | } |
|
107 | } | |
90 |
|
108 | |||
91 | void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
109 | void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
92 | { |
|
110 | { | |
93 | // Empty implementation; the children are parsed in componentComplete instead |
|
111 | // Empty implementation; the children are parsed in componentComplete instead | |
94 | Q_UNUSED(list); |
|
112 | Q_UNUSED(list); | |
95 | Q_UNUSED(element); |
|
113 | Q_UNUSED(element); | |
96 | } |
|
114 | } | |
97 |
|
115 | |||
98 | DeclarativeBarSet *DeclarativeBarSeries::at(int index) |
|
116 | DeclarativeBarSet *DeclarativeBarSeries::at(int index) | |
99 | { |
|
117 | { | |
100 | QList<QBarSet*> setList = barSets(); |
|
118 | QList<QBarSet*> setList = barSets(); | |
101 | if (index < setList.count()) |
|
119 | if (index < setList.count()) | |
102 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
120 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | |
103 |
|
121 | |||
104 | return 0; |
|
122 | return 0; | |
105 | } |
|
123 | } | |
106 |
|
124 | |||
107 | DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) : |
|
125 | DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) : | |
108 | QGroupedBarSeries(parent) |
|
126 | QGroupedBarSeries(parent) | |
109 | { |
|
127 | { | |
110 | } |
|
128 | } | |
111 |
|
129 | |||
112 | void DeclarativeGroupedBarSeries::classBegin() |
|
130 | void DeclarativeGroupedBarSeries::classBegin() | |
113 | { |
|
131 | { | |
114 | } |
|
132 | } | |
115 |
|
133 | |||
116 | void DeclarativeGroupedBarSeries::componentComplete() |
|
134 | void DeclarativeGroupedBarSeries::componentComplete() | |
117 | { |
|
135 | { | |
118 | foreach(QObject *child, children()) { |
|
136 | foreach(QObject *child, children()) { | |
119 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
137 | if (qobject_cast<DeclarativeBarSet *>(child)) { | |
120 | QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
138 | QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | |
121 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
139 | } else if(qobject_cast<QVBarModelMapper *>(child)) { | |
122 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
140 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
123 | mapper->setSeries(this); |
|
141 | mapper->setSeries(this); | |
124 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
142 | } else if(qobject_cast<QHBarModelMapper *>(child)) { | |
125 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
143 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
126 | mapper->setSeries(this); |
|
144 | mapper->setSeries(this); | |
127 | } |
|
145 | } | |
128 | } |
|
146 | } | |
129 | } |
|
147 | } | |
130 |
|
148 | |||
131 | QDeclarativeListProperty<QObject> DeclarativeGroupedBarSeries::seriesChildren() |
|
149 | QDeclarativeListProperty<QObject> DeclarativeGroupedBarSeries::seriesChildren() | |
132 | { |
|
150 | { | |
133 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); |
|
151 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); | |
134 | } |
|
152 | } | |
135 |
|
153 | |||
136 | void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
154 | void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
137 | { |
|
155 | { | |
138 | // Empty implementation; the children are parsed in componentComplete instead |
|
156 | // Empty implementation; the children are parsed in componentComplete instead | |
139 | Q_UNUSED(list); |
|
157 | Q_UNUSED(list); | |
140 | Q_UNUSED(element); |
|
158 | Q_UNUSED(element); | |
141 | } |
|
159 | } | |
142 |
|
160 | |||
143 | DeclarativeBarSet *DeclarativeGroupedBarSeries::at(int index) |
|
161 | DeclarativeBarSet *DeclarativeGroupedBarSeries::at(int index) | |
144 | { |
|
162 | { | |
145 | QList<QBarSet*> setList = barSets(); |
|
163 | QList<QBarSet*> setList = barSets(); | |
146 | if (index < setList.count()) |
|
164 | if (index < setList.count()) | |
147 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
165 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | |
148 |
|
166 | |||
149 | return 0; |
|
167 | return 0; | |
150 | } |
|
168 | } | |
151 |
|
169 | |||
152 | DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) : |
|
170 | DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) : | |
153 | QStackedBarSeries(parent) |
|
171 | QStackedBarSeries(parent) | |
154 | { |
|
172 | { | |
155 | } |
|
173 | } | |
156 |
|
174 | |||
157 | void DeclarativeStackedBarSeries::classBegin() |
|
175 | void DeclarativeStackedBarSeries::classBegin() | |
158 | { |
|
176 | { | |
159 | } |
|
177 | } | |
160 |
|
178 | |||
161 | void DeclarativeStackedBarSeries::componentComplete() |
|
179 | void DeclarativeStackedBarSeries::componentComplete() | |
162 | { |
|
180 | { | |
163 | foreach(QObject *child, children()) { |
|
181 | foreach(QObject *child, children()) { | |
164 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
182 | if (qobject_cast<DeclarativeBarSet *>(child)) { | |
165 | QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
183 | QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | |
166 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
184 | } else if(qobject_cast<QVBarModelMapper *>(child)) { | |
167 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
185 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
168 | mapper->setSeries(this); |
|
186 | mapper->setSeries(this); | |
169 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
187 | } else if(qobject_cast<QHBarModelMapper *>(child)) { | |
170 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
188 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
171 | mapper->setSeries(this); |
|
189 | mapper->setSeries(this); | |
172 | } |
|
190 | } | |
173 | } |
|
191 | } | |
174 | } |
|
192 | } | |
175 |
|
193 | |||
176 | QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren() |
|
194 | QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren() | |
177 | { |
|
195 | { | |
178 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); |
|
196 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); | |
179 | } |
|
197 | } | |
180 |
|
198 | |||
181 | void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
199 | void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
182 | { |
|
200 | { | |
183 | // Empty implementation; the children are parsed in componentComplete instead |
|
201 | // Empty implementation; the children are parsed in componentComplete instead | |
184 | Q_UNUSED(list); |
|
202 | Q_UNUSED(list); | |
185 | Q_UNUSED(element); |
|
203 | Q_UNUSED(element); | |
186 | } |
|
204 | } | |
187 |
|
205 | |||
188 | DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index) |
|
206 | DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index) | |
189 | { |
|
207 | { | |
190 | QList<QBarSet*> setList = barSets(); |
|
208 | QList<QBarSet*> setList = barSets(); | |
191 | if (index < setList.count()) |
|
209 | if (index < setList.count()) | |
192 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
210 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | |
193 |
|
211 | |||
194 | return 0; |
|
212 | return 0; | |
195 | } |
|
213 | } | |
196 |
|
214 | |||
197 | DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) : |
|
215 | DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) : | |
198 | QPercentBarSeries(parent) |
|
216 | QPercentBarSeries(parent) | |
199 | { |
|
217 | { | |
200 | } |
|
218 | } | |
201 |
|
219 | |||
202 | void DeclarativePercentBarSeries::classBegin() |
|
220 | void DeclarativePercentBarSeries::classBegin() | |
203 | { |
|
221 | { | |
204 | } |
|
222 | } | |
205 |
|
223 | |||
206 | void DeclarativePercentBarSeries::componentComplete() |
|
224 | void DeclarativePercentBarSeries::componentComplete() | |
207 | { |
|
225 | { | |
208 | foreach(QObject *child, children()) { |
|
226 | foreach(QObject *child, children()) { | |
209 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
227 | if (qobject_cast<DeclarativeBarSet *>(child)) { | |
210 | QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
228 | QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | |
211 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
229 | } else if(qobject_cast<QVBarModelMapper *>(child)) { | |
212 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
230 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
213 | mapper->setSeries(this); |
|
231 | mapper->setSeries(this); | |
214 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
232 | } else if(qobject_cast<QHBarModelMapper *>(child)) { | |
215 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
233 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
216 | mapper->setSeries(this); |
|
234 | mapper->setSeries(this); | |
217 | } |
|
235 | } | |
218 | } |
|
236 | } | |
219 | } |
|
237 | } | |
220 |
|
238 | |||
221 | QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren() |
|
239 | QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren() | |
222 | { |
|
240 | { | |
223 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); |
|
241 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); | |
224 | } |
|
242 | } | |
225 |
|
243 | |||
226 | void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
244 | void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
227 | { |
|
245 | { | |
228 | // Empty implementation; the children are parsed in componentComplete instead |
|
246 | // Empty implementation; the children are parsed in componentComplete instead | |
229 | Q_UNUSED(list); |
|
247 | Q_UNUSED(list); | |
230 | Q_UNUSED(element); |
|
248 | Q_UNUSED(element); | |
231 | } |
|
249 | } | |
232 |
|
250 | |||
233 | DeclarativeBarSet *DeclarativePercentBarSeries::at(int index) |
|
251 | DeclarativeBarSet *DeclarativePercentBarSeries::at(int index) | |
234 | { |
|
252 | { | |
235 | QList<QBarSet*> setList = barSets(); |
|
253 | QList<QBarSet*> setList = barSets(); | |
236 | if (index < setList.count()) |
|
254 | if (index < setList.count()) | |
237 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
255 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | |
238 |
|
256 | |||
239 | return 0; |
|
257 | return 0; | |
240 | } |
|
258 | } | |
241 |
|
259 | |||
242 | #include "moc_declarativebarseries.cpp" |
|
260 | #include "moc_declarativebarseries.cpp" | |
243 |
|
261 | |||
244 | QTCOMMERCIALCHART_END_NAMESPACE |
|
262 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,140 +1,146 | |||||
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 | #ifndef DECLARATIVEBARSERIES_H |
|
21 | #ifndef DECLARATIVEBARSERIES_H | |
22 | #define DECLARATIVEBARSERIES_H |
|
22 | #define DECLARATIVEBARSERIES_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include <QGroupedBarSeries> |
|
25 | #include <QGroupedBarSeries> | |
26 | #include <QStackedBarSeries> |
|
26 | #include <QStackedBarSeries> | |
27 | #include <QPercentBarSeries> |
|
27 | #include <QPercentBarSeries> | |
28 | #include <QBarSet> |
|
28 | #include <QBarSet> | |
29 | #include <QDeclarativeItem> |
|
29 | #include <QDeclarativeItem> | |
30 | #include <QDeclarativeParserStatus> |
|
30 | #include <QDeclarativeParserStatus> | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | class QChart; |
|
34 | class QChart; | |
35 |
|
35 | |||
36 | class DeclarativeBarSet : public QBarSet |
|
36 | class DeclarativeBarSet : public QBarSet | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 | Q_PROPERTY(QVariantList values READ values WRITE setValues) |
|
39 | Q_PROPERTY(QVariantList values READ values WRITE setValues) | |
40 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
40 | Q_PROPERTY(int count READ count NOTIFY countChanged) | |
41 |
|
41 | |||
42 | public: |
|
42 | public: | |
43 | explicit DeclarativeBarSet(QObject *parent = 0); |
|
43 | explicit DeclarativeBarSet(QObject *parent = 0); | |
44 | QVariantList values(); |
|
44 | QVariantList values(); | |
45 | void setValues(QVariantList values); |
|
45 | void setValues(QVariantList values); | |
46 |
|
46 | |||
47 | public: // From QBarSet |
|
47 | public: // From QBarSet | |
48 | Q_INVOKABLE void append(qreal value) { QBarSet::append(value); } |
|
48 | Q_INVOKABLE void append(qreal value) { QBarSet::append(value); } | |
49 | Q_INVOKABLE void append(qreal x, qreal y) { QBarSet::append(QPointF(x, y)); } |
|
49 | Q_INVOKABLE void append(qreal x, qreal y) { QBarSet::append(QPointF(x, y)); } | |
50 |
|
50 | |||
51 | Q_SIGNALS: |
|
51 | Q_SIGNALS: | |
52 | void countChanged(int count); |
|
52 | void countChanged(int count); | |
53 |
|
53 | |||
54 | private Q_SLOTS: |
|
54 | private Q_SLOTS: | |
55 | void handleCountChanged(int index, int count); |
|
55 | void handleCountChanged(int index, int count); | |
56 | }; |
|
56 | }; | |
57 |
|
57 | |||
58 | class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus |
|
58 | class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus | |
59 | { |
|
59 | { | |
60 | Q_OBJECT |
|
60 | Q_OBJECT | |
61 | Q_INTERFACES(QDeclarativeParserStatus) |
|
61 | Q_INTERFACES(QDeclarativeParserStatus) | |
62 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
62 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) | |
63 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
63 | Q_CLASSINFO("DefaultProperty", "seriesChildren") | |
64 |
|
64 | |||
65 | public: |
|
65 | public: | |
66 | explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0); |
|
66 | explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0); | |
67 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
67 | QDeclarativeListProperty<QObject> seriesChildren(); | |
68 | Q_INVOKABLE DeclarativeBarSet *at(int index); |
|
68 | Q_INVOKABLE DeclarativeBarSet *at(int index); | |
69 |
|
69 | |||
70 | public: // from QDeclarativeParserStatus |
|
70 | public: // from QDeclarativeParserStatus | |
71 | void classBegin(); |
|
71 | void classBegin(); | |
72 | void componentComplete(); |
|
72 | void componentComplete(); | |
73 |
|
73 | |||
|
74 | Q_SIGNALS: | |||
|
75 | void added(DeclarativeBarSet *barset); | |||
|
76 | void removed(DeclarativeBarSet *barset); | |||
|
77 | ||||
74 | public Q_SLOTS: |
|
78 | public Q_SLOTS: | |
75 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
79 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); | |
|
80 | void handleAdded(QList<QBarSet* > barsets); | |||
|
81 | void handleRemoved(QList<QBarSet* > barsets); | |||
76 | }; |
|
82 | }; | |
77 |
|
83 | |||
78 | class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus |
|
84 | class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus | |
79 | { |
|
85 | { | |
80 | Q_OBJECT |
|
86 | Q_OBJECT | |
81 | Q_INTERFACES(QDeclarativeParserStatus) |
|
87 | Q_INTERFACES(QDeclarativeParserStatus) | |
82 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
88 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) | |
83 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
89 | Q_CLASSINFO("DefaultProperty", "seriesChildren") | |
84 |
|
90 | |||
85 | public: |
|
91 | public: | |
86 | explicit DeclarativeGroupedBarSeries(QDeclarativeItem *parent = 0); |
|
92 | explicit DeclarativeGroupedBarSeries(QDeclarativeItem *parent = 0); | |
87 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
93 | QDeclarativeListProperty<QObject> seriesChildren(); | |
88 | Q_INVOKABLE DeclarativeBarSet *at(int index); |
|
94 | Q_INVOKABLE DeclarativeBarSet *at(int index); | |
89 |
|
95 | |||
90 | public: // from QDeclarativeParserStatus |
|
96 | public: // from QDeclarativeParserStatus | |
91 | void classBegin(); |
|
97 | void classBegin(); | |
92 | void componentComplete(); |
|
98 | void componentComplete(); | |
93 |
|
99 | |||
94 | public Q_SLOTS: |
|
100 | public Q_SLOTS: | |
95 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
101 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); | |
96 | }; |
|
102 | }; | |
97 |
|
103 | |||
98 | class DeclarativeStackedBarSeries : public QStackedBarSeries, public QDeclarativeParserStatus |
|
104 | class DeclarativeStackedBarSeries : public QStackedBarSeries, public QDeclarativeParserStatus | |
99 | { |
|
105 | { | |
100 | Q_OBJECT |
|
106 | Q_OBJECT | |
101 | Q_INTERFACES(QDeclarativeParserStatus) |
|
107 | Q_INTERFACES(QDeclarativeParserStatus) | |
102 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
108 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) | |
103 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
109 | Q_CLASSINFO("DefaultProperty", "seriesChildren") | |
104 |
|
110 | |||
105 | public: |
|
111 | public: | |
106 | explicit DeclarativeStackedBarSeries(QDeclarativeItem *parent = 0); |
|
112 | explicit DeclarativeStackedBarSeries(QDeclarativeItem *parent = 0); | |
107 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
113 | QDeclarativeListProperty<QObject> seriesChildren(); | |
108 | Q_INVOKABLE DeclarativeBarSet *at(int index); |
|
114 | Q_INVOKABLE DeclarativeBarSet *at(int index); | |
109 |
|
115 | |||
110 | public: // from QDeclarativeParserStatus |
|
116 | public: // from QDeclarativeParserStatus | |
111 | void classBegin(); |
|
117 | void classBegin(); | |
112 | void componentComplete(); |
|
118 | void componentComplete(); | |
113 |
|
119 | |||
114 | public Q_SLOTS: |
|
120 | public Q_SLOTS: | |
115 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
121 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); | |
116 | }; |
|
122 | }; | |
117 |
|
123 | |||
118 | class DeclarativePercentBarSeries : public QPercentBarSeries, public QDeclarativeParserStatus |
|
124 | class DeclarativePercentBarSeries : public QPercentBarSeries, public QDeclarativeParserStatus | |
119 | { |
|
125 | { | |
120 | Q_OBJECT |
|
126 | Q_OBJECT | |
121 | Q_INTERFACES(QDeclarativeParserStatus) |
|
127 | Q_INTERFACES(QDeclarativeParserStatus) | |
122 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
128 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) | |
123 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
129 | Q_CLASSINFO("DefaultProperty", "seriesChildren") | |
124 |
|
130 | |||
125 | public: |
|
131 | public: | |
126 | explicit DeclarativePercentBarSeries(QDeclarativeItem *parent = 0); |
|
132 | explicit DeclarativePercentBarSeries(QDeclarativeItem *parent = 0); | |
127 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
133 | QDeclarativeListProperty<QObject> seriesChildren(); | |
128 | Q_INVOKABLE DeclarativeBarSet *at(int index); |
|
134 | Q_INVOKABLE DeclarativeBarSet *at(int index); | |
129 |
|
135 | |||
130 | public: // from QDeclarativeParserStatus |
|
136 | public: // from QDeclarativeParserStatus | |
131 | void classBegin(); |
|
137 | void classBegin(); | |
132 | void componentComplete(); |
|
138 | void componentComplete(); | |
133 |
|
139 | |||
134 | public Q_SLOTS: |
|
140 | public Q_SLOTS: | |
135 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
141 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); | |
136 | }; |
|
142 | }; | |
137 |
|
143 | |||
138 | QTCOMMERCIALCHART_END_NAMESPACE |
|
144 | QTCOMMERCIALCHART_END_NAMESPACE | |
139 |
|
145 | |||
140 | #endif // DECLARATIVEBARSERIES_H |
|
146 | #endif // DECLARATIVEBARSERIES_H |
@@ -1,680 +1,688 | |||||
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 "qbarseries.h" |
|
21 | #include "qbarseries.h" | |
22 | #include "qbarseries_p.h" |
|
22 | #include "qbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "legendmarker_p.h" |
|
26 | #include "legendmarker_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \class QBarSeries |
|
34 | \class QBarSeries | |
35 | \brief Series for creating a bar chart |
|
35 | \brief Series for creating a bar chart | |
36 | \mainclass |
|
36 | \mainclass | |
37 |
|
37 | |||
38 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
38 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
39 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
39 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
40 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
40 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
41 | shows the x-values. |
|
41 | shows the x-values. | |
42 |
|
42 | |||
43 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
43 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
44 | \image examples_barchart.png |
|
44 | \image examples_barchart.png | |
45 |
|
45 | |||
46 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
46 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
47 | */ |
|
47 | */ | |
48 | /*! |
|
48 | /*! | |
49 | \qmlclass BarSeries QBarSeries |
|
49 | \qmlclass BarSeries QBarSeries | |
50 |
|
50 | |||
51 | \beginfloatleft |
|
51 | \beginfloatleft | |
52 | \image demos_qmlchart6.png |
|
52 | \image demos_qmlchart6.png | |
53 | \endfloat |
|
53 | \endfloat | |
54 | \clearfloat |
|
54 | \clearfloat | |
55 |
|
55 | |||
56 | The following QML shows how to create a simple bar chart: |
|
56 | The following QML shows how to create a simple bar chart: | |
57 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
57 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \property QBarSeries::barWidth |
|
61 | \property QBarSeries::barWidth | |
62 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
62 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
63 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
63 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
64 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
64 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
65 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
65 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. | |
66 | \sa QGroupedBarSeries |
|
66 | \sa QGroupedBarSeries | |
67 | */ |
|
67 | */ | |
68 | /*! |
|
68 | /*! | |
69 | \qmlproperty real BarSeries::barWidth |
|
69 | \qmlproperty real BarSeries::barWidth | |
70 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
70 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars | |
71 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
71 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
72 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
72 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
73 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
73 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \property QBarSeries::count |
|
77 | \property QBarSeries::count | |
78 | Holds the number of sets in series. |
|
78 | Holds the number of sets in series. | |
79 | */ |
|
79 | */ | |
80 | /*! |
|
80 | /*! | |
81 | \qmlproperty int BarSeries::count |
|
81 | \qmlproperty int BarSeries::count | |
82 | Holds the number of sets in series. |
|
82 | Holds the number of sets in series. | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \property QBarSeries::labelsVisible |
|
86 | \property QBarSeries::labelsVisible | |
87 | Defines the visibility of the labels in series |
|
87 | Defines the visibility of the labels in series | |
88 | */ |
|
88 | */ | |
89 | /*! |
|
89 | /*! | |
90 | \qmlproperty bool BarSeries::labelsVisible |
|
90 | \qmlproperty bool BarSeries::labelsVisible | |
91 | Defines the visibility of the labels in series |
|
91 | Defines the visibility of the labels in series | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \fn void QBarSeries::clicked(QBarSet *barset, int index) |
|
95 | \fn void QBarSeries::clicked(QBarSet *barset, int index) | |
96 |
|
96 | |||
97 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
97 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
98 | Clicked bar inside set is indexed by \a index |
|
98 | Clicked bar inside set is indexed by \a index | |
99 | */ |
|
99 | */ | |
100 | /*! |
|
100 | /*! | |
101 | \qmlsignal BarSeries::onClicked(BarSet barset, int index) |
|
101 | \qmlsignal BarSeries::onClicked(BarSet barset, int index) | |
102 |
|
102 | |||
103 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
103 | The signal is emitted if the user clicks with a mouse on top of BarSet. | |
104 | Clicked bar inside set is indexed by \a index |
|
104 | Clicked bar inside set is indexed by \a index | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) |
|
108 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) | |
109 |
|
109 | |||
110 | The signal is emitted if mouse is hovered on top of series. |
|
110 | The signal is emitted if mouse is hovered on top of series. | |
111 | Parameter \a barset is the pointer of barset, where hover happened. |
|
111 | Parameter \a barset is the pointer of barset, where hover happened. | |
112 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
112 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
113 | */ |
|
113 | */ | |
114 | /*! |
|
114 | /*! | |
115 | \qmlsignal BarSeries::onHovered(BarSet barset, bool status) |
|
115 | \qmlsignal BarSeries::onHovered(BarSet barset, bool status) | |
116 |
|
116 | |||
117 | The signal is emitted if mouse is hovered on top of series. |
|
117 | The signal is emitted if mouse is hovered on top of series. | |
118 | Parameter \a barset is the pointer of barset, where hover happened. |
|
118 | Parameter \a barset is the pointer of barset, where hover happened. | |
119 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
119 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | \fn void QBarSeries::countChanged() |
|
123 | \fn void QBarSeries::countChanged() | |
124 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
124 | This signal is emitted when barset count has been changed, for example by append or remove. | |
125 | */ |
|
125 | */ | |
126 | /*! |
|
126 | /*! | |
127 | \qmlsignal BarSeries::countChanged() |
|
127 | \qmlsignal BarSeries::countChanged() | |
128 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
128 | This signal is emitted when barset count has been changed, for example by append or remove. | |
129 | */ |
|
129 | */ | |
130 |
|
130 | |||
131 | /*! |
|
131 | /*! | |
132 | \fn void QBarSeries::labelsVisibleChanged() |
|
132 | \fn void QBarSeries::labelsVisibleChanged() | |
133 | This signal is emitted when labels visibility have changed. |
|
133 | This signal is emitted when labels visibility have changed. | |
134 | \sa isLabelsVisible(), setLabelsVisible() |
|
134 | \sa isLabelsVisible(), setLabelsVisible() | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
138 | \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets) | |
139 | This signal is emitted when \a sets have been added to the series. |
|
139 | This signal is emitted when \a sets have been added to the series. | |
140 | \sa append(), insert() |
|
140 | \sa append(), insert() | |
141 | */ |
|
141 | */ | |
|
142 | /*! | |||
|
143 | \qmlsignal BarSeries::added(BarSet barset) | |||
|
144 | Emitted when \a barset has been added to the series. | |||
|
145 | */ | |||
142 |
|
146 | |||
143 | /*! |
|
147 | /*! | |
144 | \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
148 | \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets) | |
145 | This signal is emitted when \a sets have been removed from the series. |
|
149 | This signal is emitted when \a sets have been removed from the series. | |
146 | \sa remove() |
|
150 | \sa remove() | |
147 | */ |
|
151 | */ | |
|
152 | /*! | |||
|
153 | \qmlsignal BarSeries::removed(BarSet barset) | |||
|
154 | Emitted when \a barset has been removed from the series. | |||
|
155 | */ | |||
148 |
|
156 | |||
149 | /*! |
|
157 | /*! | |
150 | Constructs empty QBarSeries. |
|
158 | Constructs empty QBarSeries. | |
151 | QBarSeries is QObject which is a child of a \a parent. |
|
159 | QBarSeries is QObject which is a child of a \a parent. | |
152 | */ |
|
160 | */ | |
153 | QBarSeries::QBarSeries(QObject *parent) : |
|
161 | QBarSeries::QBarSeries(QObject *parent) : | |
154 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) |
|
162 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) | |
155 | { |
|
163 | { | |
156 | } |
|
164 | } | |
157 |
|
165 | |||
158 | /*! |
|
166 | /*! | |
159 | Destructs barseries and owned barsets. |
|
167 | Destructs barseries and owned barsets. | |
160 | */ |
|
168 | */ | |
161 | QBarSeries::~QBarSeries() |
|
169 | QBarSeries::~QBarSeries() | |
162 | { |
|
170 | { | |
163 | Q_D(QBarSeries); |
|
171 | Q_D(QBarSeries); | |
164 | if(d->m_dataset){ |
|
172 | if(d->m_dataset){ | |
165 | d->m_dataset->removeSeries(this); |
|
173 | d->m_dataset->removeSeries(this); | |
166 | } |
|
174 | } | |
167 | } |
|
175 | } | |
168 |
|
176 | |||
169 | /*! |
|
177 | /*! | |
170 | \internal |
|
178 | \internal | |
171 | */ |
|
179 | */ | |
172 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
180 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : | |
173 | QAbstractSeries(d,parent) |
|
181 | QAbstractSeries(d,parent) | |
174 | { |
|
182 | { | |
175 | } |
|
183 | } | |
176 |
|
184 | |||
177 | /*! |
|
185 | /*! | |
178 | Returns the type of series. Derived classes override this. |
|
186 | Returns the type of series. Derived classes override this. | |
179 | */ |
|
187 | */ | |
180 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
188 | QAbstractSeries::SeriesType QBarSeries::type() const | |
181 | { |
|
189 | { | |
182 | return QAbstractSeries::SeriesTypeBar; |
|
190 | return QAbstractSeries::SeriesTypeBar; | |
183 | } |
|
191 | } | |
184 |
|
192 | |||
185 | /*! |
|
193 | /*! | |
186 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
194 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
187 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
195 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
188 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
196 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
189 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
197 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
190 | */ |
|
198 | */ | |
191 | void QBarSeries::setBarWidth(qreal width) |
|
199 | void QBarSeries::setBarWidth(qreal width) | |
192 | { |
|
200 | { | |
193 | Q_D(QBarSeries); |
|
201 | Q_D(QBarSeries); | |
194 | d->setBarWidth(width); |
|
202 | d->setBarWidth(width); | |
195 | } |
|
203 | } | |
196 |
|
204 | |||
197 | /*! |
|
205 | /*! | |
198 | Returns the width of the bars of the series. |
|
206 | Returns the width of the bars of the series. | |
199 | \sa setBarWidth() |
|
207 | \sa setBarWidth() | |
200 | */ |
|
208 | */ | |
201 | qreal QBarSeries::barWidth() const |
|
209 | qreal QBarSeries::barWidth() const | |
202 | { |
|
210 | { | |
203 | Q_D(const QBarSeries); |
|
211 | Q_D(const QBarSeries); | |
204 | return d->barWidth(); |
|
212 | return d->barWidth(); | |
205 | } |
|
213 | } | |
206 |
|
214 | |||
207 | /*! |
|
215 | /*! | |
208 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
216 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
209 | Returns true, if appending succeeded. |
|
217 | Returns true, if appending succeeded. | |
210 | */ |
|
218 | */ | |
211 | bool QBarSeries::append(QBarSet *set) |
|
219 | bool QBarSeries::append(QBarSet *set) | |
212 | { |
|
220 | { | |
213 | Q_D(QBarSeries); |
|
221 | Q_D(QBarSeries); | |
214 | bool success = d->append(set); |
|
222 | bool success = d->append(set); | |
215 | if (success) { |
|
223 | if (success) { | |
216 | QList<QBarSet*> sets; |
|
224 | QList<QBarSet*> sets; | |
217 | sets.append(set); |
|
225 | sets.append(set); | |
218 | emit barsetsAdded(sets); |
|
226 | emit barsetsAdded(sets); | |
219 | emit countChanged(); |
|
227 | emit countChanged(); | |
220 | } |
|
228 | } | |
221 | return success; |
|
229 | return success; | |
222 | } |
|
230 | } | |
223 |
|
231 | |||
224 | /*! |
|
232 | /*! | |
225 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
233 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
226 | Returns true, if set was removed. |
|
234 | Returns true, if set was removed. | |
227 | */ |
|
235 | */ | |
228 | bool QBarSeries::remove(QBarSet *set) |
|
236 | bool QBarSeries::remove(QBarSet *set) | |
229 | { |
|
237 | { | |
230 | Q_D(QBarSeries); |
|
238 | Q_D(QBarSeries); | |
231 | bool success = d->remove(set); |
|
239 | bool success = d->remove(set); | |
232 | if (success) { |
|
240 | if (success) { | |
233 | QList<QBarSet*> sets; |
|
241 | QList<QBarSet*> sets; | |
234 | sets.append(set); |
|
242 | sets.append(set); | |
235 | emit barsetsRemoved(sets); |
|
243 | emit barsetsRemoved(sets); | |
236 | emit countChanged(); |
|
244 | emit countChanged(); | |
237 | } |
|
245 | } | |
238 | return success; |
|
246 | return success; | |
239 | } |
|
247 | } | |
240 |
|
248 | |||
241 | /*! |
|
249 | /*! | |
242 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
250 | Adds a list of barsets to series. Takes ownership of \a sets. | |
243 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
251 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
244 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
252 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
245 | and function returns false. |
|
253 | and function returns false. | |
246 | */ |
|
254 | */ | |
247 | bool QBarSeries::append(QList<QBarSet* > sets) |
|
255 | bool QBarSeries::append(QList<QBarSet* > sets) | |
248 | { |
|
256 | { | |
249 | Q_D(QBarSeries); |
|
257 | Q_D(QBarSeries); | |
250 | bool success = d->append(sets); |
|
258 | bool success = d->append(sets); | |
251 | if (success) { |
|
259 | if (success) { | |
252 | emit barsetsAdded(sets); |
|
260 | emit barsetsAdded(sets); | |
253 | emit countChanged(); |
|
261 | emit countChanged(); | |
254 | } |
|
262 | } | |
255 | return success; |
|
263 | return success; | |
256 | } |
|
264 | } | |
257 |
|
265 | |||
258 | /*! |
|
266 | /*! | |
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. |
|
267 | 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. | |
260 | Returns true, if inserting succeeded. |
|
268 | Returns true, if inserting succeeded. | |
261 |
|
269 | |||
262 | */ |
|
270 | */ | |
263 | bool QBarSeries::insert(int index, QBarSet *set) |
|
271 | bool QBarSeries::insert(int index, QBarSet *set) | |
264 | { |
|
272 | { | |
265 | Q_D(QBarSeries); |
|
273 | Q_D(QBarSeries); | |
266 | bool success = d->insert(index, set); |
|
274 | bool success = d->insert(index, set); | |
267 | if (success) { |
|
275 | if (success) { | |
268 | QList<QBarSet*> sets; |
|
276 | QList<QBarSet*> sets; | |
269 | sets.append(set); |
|
277 | sets.append(set); | |
270 | emit barsetsAdded(sets); |
|
278 | emit barsetsAdded(sets); | |
271 | emit countChanged(); |
|
279 | emit countChanged(); | |
272 | } |
|
280 | } | |
273 | return success; |
|
281 | return success; | |
274 | } |
|
282 | } | |
275 |
|
283 | |||
276 | /*! |
|
284 | /*! | |
277 | Removes all of the bar sets from the series |
|
285 | Removes all of the bar sets from the series | |
278 | */ |
|
286 | */ | |
279 | void QBarSeries::clear() |
|
287 | void QBarSeries::clear() | |
280 | { |
|
288 | { | |
281 | Q_D(QBarSeries); |
|
289 | Q_D(QBarSeries); | |
282 | QList<QBarSet *> sets = barSets(); |
|
290 | QList<QBarSet *> sets = barSets(); | |
283 | bool success = d->remove(sets); |
|
291 | bool success = d->remove(sets); | |
284 | if (success) { |
|
292 | if (success) { | |
285 | emit barsetsRemoved(sets); |
|
293 | emit barsetsRemoved(sets); | |
286 | emit countChanged(); |
|
294 | emit countChanged(); | |
287 | } |
|
295 | } | |
288 | } |
|
296 | } | |
289 |
|
297 | |||
290 | /*! |
|
298 | /*! | |
291 | Returns number of sets in series. |
|
299 | Returns number of sets in series. | |
292 | */ |
|
300 | */ | |
293 | int QBarSeries::count() const |
|
301 | int QBarSeries::count() const | |
294 | { |
|
302 | { | |
295 | Q_D(const QBarSeries); |
|
303 | Q_D(const QBarSeries); | |
296 | return d->m_barSets.count(); |
|
304 | return d->m_barSets.count(); | |
297 | } |
|
305 | } | |
298 |
|
306 | |||
299 | /*! |
|
307 | /*! | |
300 | Returns a list of sets in series. Keeps ownership of sets. |
|
308 | Returns a list of sets in series. Keeps ownership of sets. | |
301 | */ |
|
309 | */ | |
302 | QList<QBarSet*> QBarSeries::barSets() const |
|
310 | QList<QBarSet*> QBarSeries::barSets() const | |
303 | { |
|
311 | { | |
304 | Q_D(const QBarSeries); |
|
312 | Q_D(const QBarSeries); | |
305 | return d->m_barSets; |
|
313 | return d->m_barSets; | |
306 | } |
|
314 | } | |
307 |
|
315 | |||
308 | /*! |
|
316 | /*! | |
309 | Sets the visibility of labels in series to \a visible |
|
317 | Sets the visibility of labels in series to \a visible | |
310 | */ |
|
318 | */ | |
311 | void QBarSeries::setLabelsVisible(bool visible) |
|
319 | void QBarSeries::setLabelsVisible(bool visible) | |
312 | { |
|
320 | { | |
313 | Q_D(QBarSeries); |
|
321 | Q_D(QBarSeries); | |
314 | if (d->m_labelsVisible != visible) { |
|
322 | if (d->m_labelsVisible != visible) { | |
315 | d->setLabelsVisible(visible); |
|
323 | d->setLabelsVisible(visible); | |
316 | emit labelsVisibleChanged(); |
|
324 | emit labelsVisibleChanged(); | |
317 | } |
|
325 | } | |
318 | } |
|
326 | } | |
319 |
|
327 | |||
320 | /*! |
|
328 | /*! | |
321 | Returns the visibility of labels |
|
329 | Returns the visibility of labels | |
322 | */ |
|
330 | */ | |
323 | bool QBarSeries::isLabelsVisible() const |
|
331 | bool QBarSeries::isLabelsVisible() const | |
324 | { |
|
332 | { | |
325 | Q_D(const QBarSeries); |
|
333 | Q_D(const QBarSeries); | |
326 | return d->m_labelsVisible; |
|
334 | return d->m_labelsVisible; | |
327 | } |
|
335 | } | |
328 |
|
336 | |||
329 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
337 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
330 |
|
338 | |||
331 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : |
|
339 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : | |
332 | QAbstractSeriesPrivate(q), |
|
340 | QAbstractSeriesPrivate(q), | |
333 | m_barWidth(0.5), // Default value is 50% of category width |
|
341 | m_barWidth(0.5), // Default value is 50% of category width | |
334 | m_labelsVisible(false), |
|
342 | m_labelsVisible(false), | |
335 | m_visible(true) |
|
343 | m_visible(true) | |
336 | { |
|
344 | { | |
337 | } |
|
345 | } | |
338 |
|
346 | |||
339 | int QBarSeriesPrivate::categoryCount() const |
|
347 | int QBarSeriesPrivate::categoryCount() const | |
340 | { |
|
348 | { | |
341 | // No categories defined. return count of longest set. |
|
349 | // No categories defined. return count of longest set. | |
342 | int count = 0; |
|
350 | int count = 0; | |
343 | for (int i=0; i<m_barSets.count(); i++) { |
|
351 | for (int i=0; i<m_barSets.count(); i++) { | |
344 | if (m_barSets.at(i)->count() > count) { |
|
352 | if (m_barSets.at(i)->count() > count) { | |
345 | count = m_barSets.at(i)->count(); |
|
353 | count = m_barSets.at(i)->count(); | |
346 | } |
|
354 | } | |
347 | } |
|
355 | } | |
348 |
|
356 | |||
349 | return count; |
|
357 | return count; | |
350 | } |
|
358 | } | |
351 |
|
359 | |||
352 | void QBarSeriesPrivate::setBarWidth(qreal width) |
|
360 | void QBarSeriesPrivate::setBarWidth(qreal width) | |
353 | { |
|
361 | { | |
354 | if (width < 0.0) { |
|
362 | if (width < 0.0) { | |
355 | width = 0.0; |
|
363 | width = 0.0; | |
356 | } |
|
364 | } | |
357 | m_barWidth = width; |
|
365 | m_barWidth = width; | |
358 | emit updatedBars(); |
|
366 | emit updatedBars(); | |
359 | } |
|
367 | } | |
360 |
|
368 | |||
361 | qreal QBarSeriesPrivate::barWidth() const |
|
369 | qreal QBarSeriesPrivate::barWidth() const | |
362 | { |
|
370 | { | |
363 | return m_barWidth; |
|
371 | return m_barWidth; | |
364 | } |
|
372 | } | |
365 |
|
373 | |||
366 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
374 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
367 | { |
|
375 | { | |
368 | return m_barSets.at(index); |
|
376 | return m_barSets.at(index); | |
369 | } |
|
377 | } | |
370 |
|
378 | |||
371 | void QBarSeriesPrivate::setVisible(bool visible) |
|
379 | void QBarSeriesPrivate::setVisible(bool visible) | |
372 | { |
|
380 | { | |
373 | m_visible = visible; |
|
381 | m_visible = visible; | |
374 | emit updatedBars(); |
|
382 | emit updatedBars(); | |
375 | } |
|
383 | } | |
376 |
|
384 | |||
377 | void QBarSeriesPrivate::setLabelsVisible(bool visible) |
|
385 | void QBarSeriesPrivate::setLabelsVisible(bool visible) | |
378 | { |
|
386 | { | |
379 | m_labelsVisible = visible; |
|
387 | m_labelsVisible = visible; | |
380 | emit labelsVisibleChanged(visible); |
|
388 | emit labelsVisibleChanged(visible); | |
381 | } |
|
389 | } | |
382 |
|
390 | |||
383 | qreal QBarSeriesPrivate::min() |
|
391 | qreal QBarSeriesPrivate::min() | |
384 | { |
|
392 | { | |
385 | if (m_barSets.count() <= 0) { |
|
393 | if (m_barSets.count() <= 0) { | |
386 | return 0; |
|
394 | return 0; | |
387 | } |
|
395 | } | |
388 | qreal min = INT_MAX; |
|
396 | qreal min = INT_MAX; | |
389 |
|
397 | |||
390 | for (int i = 0; i < m_barSets.count(); i++) { |
|
398 | for (int i = 0; i < m_barSets.count(); i++) { | |
391 | int categoryCount = m_barSets.at(i)->count(); |
|
399 | int categoryCount = m_barSets.at(i)->count(); | |
392 | for (int j = 0; j < categoryCount; j++) { |
|
400 | for (int j = 0; j < categoryCount; j++) { | |
393 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
401 | qreal temp = m_barSets.at(i)->at(j).y(); | |
394 | if (temp < min) |
|
402 | if (temp < min) | |
395 | min = temp; |
|
403 | min = temp; | |
396 | } |
|
404 | } | |
397 | } |
|
405 | } | |
398 | return min; |
|
406 | return min; | |
399 | } |
|
407 | } | |
400 |
|
408 | |||
401 | qreal QBarSeriesPrivate::max() |
|
409 | qreal QBarSeriesPrivate::max() | |
402 | { |
|
410 | { | |
403 | if (m_barSets.count() <= 0) { |
|
411 | if (m_barSets.count() <= 0) { | |
404 | return 0; |
|
412 | return 0; | |
405 | } |
|
413 | } | |
406 | qreal max = INT_MIN; |
|
414 | qreal max = INT_MIN; | |
407 |
|
415 | |||
408 | for (int i = 0; i < m_barSets.count(); i++) { |
|
416 | for (int i = 0; i < m_barSets.count(); i++) { | |
409 | int categoryCount = m_barSets.at(i)->count(); |
|
417 | int categoryCount = m_barSets.at(i)->count(); | |
410 | for (int j = 0; j < categoryCount; j++) { |
|
418 | for (int j = 0; j < categoryCount; j++) { | |
411 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
419 | qreal temp = m_barSets.at(i)->at(j).y(); | |
412 | if (temp > max) |
|
420 | if (temp > max) | |
413 | max = temp; |
|
421 | max = temp; | |
414 | } |
|
422 | } | |
415 | } |
|
423 | } | |
416 |
|
424 | |||
417 | return max; |
|
425 | return max; | |
418 | } |
|
426 | } | |
419 |
|
427 | |||
420 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
428 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
421 | { |
|
429 | { | |
422 | if ((set < 0) || (set >= m_barSets.count())) { |
|
430 | if ((set < 0) || (set >= m_barSets.count())) { | |
423 | // No set, no value. |
|
431 | // No set, no value. | |
424 | return 0; |
|
432 | return 0; | |
425 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
433 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
426 | // No category, no value. |
|
434 | // No category, no value. | |
427 | return 0; |
|
435 | return 0; | |
428 | } |
|
436 | } | |
429 |
|
437 | |||
430 | return m_barSets.at(set)->at(category).y(); |
|
438 | return m_barSets.at(set)->at(category).y(); | |
431 | } |
|
439 | } | |
432 |
|
440 | |||
433 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
441 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
434 | { |
|
442 | { | |
435 | if ((set < 0) || (set >= m_barSets.count())) { |
|
443 | if ((set < 0) || (set >= m_barSets.count())) { | |
436 | // No set, no value. |
|
444 | // No set, no value. | |
437 | return 0; |
|
445 | return 0; | |
438 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
446 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
439 | // No category, no value. |
|
447 | // No category, no value. | |
440 | return 0; |
|
448 | return 0; | |
441 | } |
|
449 | } | |
442 |
|
450 | |||
443 | qreal value = m_barSets.at(set)->at(category).y(); |
|
451 | qreal value = m_barSets.at(set)->at(category).y(); | |
444 | qreal sum = categorySum(category); |
|
452 | qreal sum = categorySum(category); | |
445 | if ( qFuzzyIsNull(sum) ) { |
|
453 | if ( qFuzzyIsNull(sum) ) { | |
446 | return 0; |
|
454 | return 0; | |
447 | } |
|
455 | } | |
448 |
|
456 | |||
449 | return value / sum; |
|
457 | return value / sum; | |
450 | } |
|
458 | } | |
451 |
|
459 | |||
452 | qreal QBarSeriesPrivate::categorySum(int category) |
|
460 | qreal QBarSeriesPrivate::categorySum(int category) | |
453 | { |
|
461 | { | |
454 | qreal sum(0); |
|
462 | qreal sum(0); | |
455 | int count = m_barSets.count(); // Count sets |
|
463 | int count = m_barSets.count(); // Count sets | |
456 | for (int set = 0; set < count; set++) { |
|
464 | for (int set = 0; set < count; set++) { | |
457 | if (category < m_barSets.at(set)->count()) |
|
465 | if (category < m_barSets.at(set)->count()) | |
458 | sum += m_barSets.at(set)->at(category).y(); |
|
466 | sum += m_barSets.at(set)->at(category).y(); | |
459 | } |
|
467 | } | |
460 | return sum; |
|
468 | return sum; | |
461 | } |
|
469 | } | |
462 |
|
470 | |||
463 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
471 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
464 | { |
|
472 | { | |
465 | qreal sum(0); |
|
473 | qreal sum(0); | |
466 | int count = m_barSets.count(); // Count sets |
|
474 | int count = m_barSets.count(); // Count sets | |
467 | for (int set = 0; set < count; set++) { |
|
475 | for (int set = 0; set < count; set++) { | |
468 | if (category < m_barSets.at(set)->count()) |
|
476 | if (category < m_barSets.at(set)->count()) | |
469 | sum += qAbs(m_barSets.at(set)->at(category).y()); |
|
477 | sum += qAbs(m_barSets.at(set)->at(category).y()); | |
470 | } |
|
478 | } | |
471 | return sum; |
|
479 | return sum; | |
472 | } |
|
480 | } | |
473 |
|
481 | |||
474 | qreal QBarSeriesPrivate::maxCategorySum() |
|
482 | qreal QBarSeriesPrivate::maxCategorySum() | |
475 | { |
|
483 | { | |
476 | qreal max = INT_MIN; |
|
484 | qreal max = INT_MIN; | |
477 | int count = categoryCount(); |
|
485 | int count = categoryCount(); | |
478 | for (int i = 0; i < count; i++) { |
|
486 | for (int i = 0; i < count; i++) { | |
479 | qreal sum = categorySum(i); |
|
487 | qreal sum = categorySum(i); | |
480 | if (sum > max) |
|
488 | if (sum > max) | |
481 | max = sum; |
|
489 | max = sum; | |
482 | } |
|
490 | } | |
483 | return max; |
|
491 | return max; | |
484 | } |
|
492 | } | |
485 |
|
493 | |||
486 | qreal QBarSeriesPrivate::minX() |
|
494 | qreal QBarSeriesPrivate::minX() | |
487 | { |
|
495 | { | |
488 | if (m_barSets.count() <= 0) { |
|
496 | if (m_barSets.count() <= 0) { | |
489 | return 0; |
|
497 | return 0; | |
490 | } |
|
498 | } | |
491 | qreal min = INT_MAX; |
|
499 | qreal min = INT_MAX; | |
492 |
|
500 | |||
493 | for (int i = 0; i < m_barSets.count(); i++) { |
|
501 | for (int i = 0; i < m_barSets.count(); i++) { | |
494 | int categoryCount = m_barSets.at(i)->count(); |
|
502 | int categoryCount = m_barSets.at(i)->count(); | |
495 | for (int j = 0; j < categoryCount; j++) { |
|
503 | for (int j = 0; j < categoryCount; j++) { | |
496 | qreal temp = m_barSets.at(i)->at(j).x(); |
|
504 | qreal temp = m_barSets.at(i)->at(j).x(); | |
497 | if (temp < min) |
|
505 | if (temp < min) | |
498 | min = temp; |
|
506 | min = temp; | |
499 | } |
|
507 | } | |
500 | } |
|
508 | } | |
501 | return min; |
|
509 | return min; | |
502 | } |
|
510 | } | |
503 |
|
511 | |||
504 | qreal QBarSeriesPrivate::maxX() |
|
512 | qreal QBarSeriesPrivate::maxX() | |
505 | { |
|
513 | { | |
506 | if (m_barSets.count() <= 0) { |
|
514 | if (m_barSets.count() <= 0) { | |
507 | return 0; |
|
515 | return 0; | |
508 | } |
|
516 | } | |
509 | qreal max = INT_MIN; |
|
517 | qreal max = INT_MIN; | |
510 |
|
518 | |||
511 | for (int i = 0; i < m_barSets.count(); i++) { |
|
519 | for (int i = 0; i < m_barSets.count(); i++) { | |
512 | int categoryCount = m_barSets.at(i)->count(); |
|
520 | int categoryCount = m_barSets.at(i)->count(); | |
513 | for (int j = 0; j < categoryCount; j++) { |
|
521 | for (int j = 0; j < categoryCount; j++) { | |
514 | qreal temp = m_barSets.at(i)->at(j).x(); |
|
522 | qreal temp = m_barSets.at(i)->at(j).x(); | |
515 | if (temp > max) |
|
523 | if (temp > max) | |
516 | max = temp; |
|
524 | max = temp; | |
517 | } |
|
525 | } | |
518 | } |
|
526 | } | |
519 |
|
527 | |||
520 | return max; |
|
528 | return max; | |
521 | } |
|
529 | } | |
522 |
|
530 | |||
523 |
|
531 | |||
524 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
532 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
525 | { |
|
533 | { | |
526 | qreal minX(domain.minX()); |
|
534 | qreal minX(domain.minX()); | |
527 | qreal minY(domain.minY()); |
|
535 | qreal minY(domain.minY()); | |
528 | qreal maxX(domain.maxX()); |
|
536 | qreal maxX(domain.maxX()); | |
529 | qreal maxY(domain.maxY()); |
|
537 | qreal maxY(domain.maxY()); | |
530 | int tickXCount(domain.tickXCount()); |
|
538 | int tickXCount(domain.tickXCount()); | |
531 | int tickYCount(domain.tickYCount()); |
|
539 | int tickYCount(domain.tickYCount()); | |
532 |
|
540 | |||
533 | qreal seriesMinX = this->minX(); |
|
541 | qreal seriesMinX = this->minX(); | |
534 | qreal seriesMaxX = this->maxX(); |
|
542 | qreal seriesMaxX = this->maxX(); | |
535 | qreal y = max(); |
|
543 | qreal y = max(); | |
536 | minX = qMin(minX, seriesMinX - 0.5); |
|
544 | minX = qMin(minX, seriesMinX - 0.5); | |
537 | minY = qMin(minY, y); |
|
545 | minY = qMin(minY, y); | |
538 | maxX = qMax(maxX, seriesMaxX + 0.5); |
|
546 | maxX = qMax(maxX, seriesMaxX + 0.5); | |
539 | maxY = qMax(maxY, y); |
|
547 | maxY = qMax(maxY, y); | |
540 | tickXCount = categoryCount()+1; |
|
548 | tickXCount = categoryCount()+1; | |
541 |
|
549 | |||
542 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
550 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
543 | } |
|
551 | } | |
544 |
|
552 | |||
545 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
553 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
546 | { |
|
554 | { | |
547 | Q_Q(QBarSeries); |
|
555 | Q_Q(QBarSeries); | |
548 |
|
556 | |||
549 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
557 | BarChartItem* bar = new BarChartItem(q,presenter); | |
550 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
558 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
551 | presenter->animator()->addAnimation(bar); |
|
559 | presenter->animator()->addAnimation(bar); | |
552 | } |
|
560 | } | |
553 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
561 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
554 | return bar; |
|
562 | return bar; | |
555 |
|
563 | |||
556 | } |
|
564 | } | |
557 |
|
565 | |||
558 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
566 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
559 | { |
|
567 | { | |
560 | Q_Q(QBarSeries); |
|
568 | Q_Q(QBarSeries); | |
561 | QList<LegendMarker*> markers; |
|
569 | QList<LegendMarker*> markers; | |
562 | foreach(QBarSet* set, q->barSets()) { |
|
570 | foreach(QBarSet* set, q->barSets()) { | |
563 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
571 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
564 | markers << marker; |
|
572 | markers << marker; | |
565 | } |
|
573 | } | |
566 |
|
574 | |||
567 | return markers; |
|
575 | return markers; | |
568 | } |
|
576 | } | |
569 |
|
577 | |||
570 | bool QBarSeriesPrivate::append(QBarSet *set) |
|
578 | bool QBarSeriesPrivate::append(QBarSet *set) | |
571 | { |
|
579 | { | |
572 | Q_Q(QBarSeries); |
|
580 | Q_Q(QBarSeries); | |
573 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
581 | if ((m_barSets.contains(set)) || (set == 0)) { | |
574 | // Fail if set is already in list or set is null. |
|
582 | // Fail if set is already in list or set is null. | |
575 | return false; |
|
583 | return false; | |
576 | } |
|
584 | } | |
577 | m_barSets.append(set); |
|
585 | m_barSets.append(set); | |
578 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
586 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
579 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
587 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
580 | emit restructuredBars(); // this notifies barchartitem |
|
588 | emit restructuredBars(); // this notifies barchartitem | |
581 | if (m_dataset) { |
|
589 | if (m_dataset) { | |
582 | m_dataset->updateSeries(q); // this notifies legend |
|
590 | m_dataset->updateSeries(q); // this notifies legend | |
583 | } |
|
591 | } | |
584 | return true; |
|
592 | return true; | |
585 | } |
|
593 | } | |
586 |
|
594 | |||
587 | bool QBarSeriesPrivate::remove(QBarSet *set) |
|
595 | bool QBarSeriesPrivate::remove(QBarSet *set) | |
588 | { |
|
596 | { | |
589 | Q_Q(QBarSeries); |
|
597 | Q_Q(QBarSeries); | |
590 | if (!m_barSets.contains(set)) { |
|
598 | if (!m_barSets.contains(set)) { | |
591 | // Fail if set is not in list |
|
599 | // Fail if set is not in list | |
592 | return false; |
|
600 | return false; | |
593 | } |
|
601 | } | |
594 | m_barSets.removeOne(set); |
|
602 | m_barSets.removeOne(set); | |
595 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
603 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
596 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
604 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
597 | emit restructuredBars(); // this notifies barchartitem |
|
605 | emit restructuredBars(); // this notifies barchartitem | |
598 | if (m_dataset) { |
|
606 | if (m_dataset) { | |
599 | m_dataset->updateSeries(q); // this notifies legend |
|
607 | m_dataset->updateSeries(q); // this notifies legend | |
600 | } |
|
608 | } | |
601 | return true; |
|
609 | return true; | |
602 | } |
|
610 | } | |
603 |
|
611 | |||
604 | bool QBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
612 | bool QBarSeriesPrivate::append(QList<QBarSet* > sets) | |
605 | { |
|
613 | { | |
606 | Q_Q(QBarSeries); |
|
614 | Q_Q(QBarSeries); | |
607 | foreach (QBarSet* set, sets) { |
|
615 | foreach (QBarSet* set, sets) { | |
608 | if ((set == 0) || (m_barSets.contains(set))) { |
|
616 | if ((set == 0) || (m_barSets.contains(set))) { | |
609 | // Fail if any of the sets is null or is already appended. |
|
617 | // Fail if any of the sets is null or is already appended. | |
610 | return false; |
|
618 | return false; | |
611 | } |
|
619 | } | |
612 | if (sets.count(set) != 1) { |
|
620 | if (sets.count(set) != 1) { | |
613 | // Also fail if same set is more than once in given list. |
|
621 | // Also fail if same set is more than once in given list. | |
614 | return false; |
|
622 | return false; | |
615 | } |
|
623 | } | |
616 | } |
|
624 | } | |
617 |
|
625 | |||
618 | foreach (QBarSet* set, sets) { |
|
626 | foreach (QBarSet* set, sets) { | |
619 | m_barSets.append(set); |
|
627 | m_barSets.append(set); | |
620 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
628 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
621 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
629 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
622 | } |
|
630 | } | |
623 | emit restructuredBars(); // this notifies barchartitem |
|
631 | emit restructuredBars(); // this notifies barchartitem | |
624 | if (m_dataset) { |
|
632 | if (m_dataset) { | |
625 | m_dataset->updateSeries(q); // this notifies legend |
|
633 | m_dataset->updateSeries(q); // this notifies legend | |
626 | } |
|
634 | } | |
627 | return true; |
|
635 | return true; | |
628 | } |
|
636 | } | |
629 |
|
637 | |||
630 | bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
638 | bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
631 | { |
|
639 | { | |
632 | Q_Q(QBarSeries); |
|
640 | Q_Q(QBarSeries); | |
633 | if (sets.count() == 0) { |
|
641 | if (sets.count() == 0) { | |
634 | return false; |
|
642 | return false; | |
635 | } |
|
643 | } | |
636 | foreach (QBarSet* set, sets) { |
|
644 | foreach (QBarSet* set, sets) { | |
637 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
645 | if ((set == 0) || (!m_barSets.contains(set))) { | |
638 | // Fail if any of the sets is null or is not in series |
|
646 | // Fail if any of the sets is null or is not in series | |
639 | return false; |
|
647 | return false; | |
640 | } |
|
648 | } | |
641 | if (sets.count(set) != 1) { |
|
649 | if (sets.count(set) != 1) { | |
642 | // Also fail if same set is more than once in given list. |
|
650 | // Also fail if same set is more than once in given list. | |
643 | return false; |
|
651 | return false; | |
644 | } |
|
652 | } | |
645 | } |
|
653 | } | |
646 |
|
654 | |||
647 | foreach (QBarSet* set, sets) { |
|
655 | foreach (QBarSet* set, sets) { | |
648 | m_barSets.removeOne(set); |
|
656 | m_barSets.removeOne(set); | |
649 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
657 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
650 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
658 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
651 | } |
|
659 | } | |
652 |
|
660 | |||
653 | emit restructuredBars(); // this notifies barchartitem |
|
661 | emit restructuredBars(); // this notifies barchartitem | |
654 | if (m_dataset) { |
|
662 | if (m_dataset) { | |
655 | m_dataset->updateSeries(q); // this notifies legend |
|
663 | m_dataset->updateSeries(q); // this notifies legend | |
656 | } |
|
664 | } | |
657 | return true; |
|
665 | return true; | |
658 | } |
|
666 | } | |
659 |
|
667 | |||
660 | bool QBarSeriesPrivate::insert(int index, QBarSet *set) |
|
668 | bool QBarSeriesPrivate::insert(int index, QBarSet *set) | |
661 | { |
|
669 | { | |
662 | Q_Q(QBarSeries); |
|
670 | Q_Q(QBarSeries); | |
663 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
671 | if ((m_barSets.contains(set)) || (set == 0)) { | |
664 | // Fail if set is already in list or set is null. |
|
672 | // Fail if set is already in list or set is null. | |
665 | return false; |
|
673 | return false; | |
666 | } |
|
674 | } | |
667 | m_barSets.insert(index, set); |
|
675 | m_barSets.insert(index, set); | |
668 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
676 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
669 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
677 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
670 | emit restructuredBars(); // this notifies barchartitem |
|
678 | emit restructuredBars(); // this notifies barchartitem | |
671 | if (m_dataset) { |
|
679 | if (m_dataset) { | |
672 | m_dataset->updateSeries(q); // this notifies legend |
|
680 | m_dataset->updateSeries(q); // this notifies legend | |
673 | } |
|
681 | } | |
674 | return true; |
|
682 | return true; | |
675 | } |
|
683 | } | |
676 |
|
684 | |||
677 | #include "moc_qbarseries.cpp" |
|
685 | #include "moc_qbarseries.cpp" | |
678 | #include "moc_qbarseries_p.cpp" |
|
686 | #include "moc_qbarseries_p.cpp" | |
679 |
|
687 | |||
680 | QTCOMMERCIALCHART_END_NAMESPACE |
|
688 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,54 +1,58 | |||||
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 | import QtQuick 1.0 |
|
21 | import QtQuick 1.0 | |
22 | import QtCommercial.Chart 1.0 |
|
22 | import QtCommercial.Chart 1.0 | |
23 |
|
23 | |||
24 | ChartView { |
|
24 | ChartView { | |
25 | title: "Bar series" |
|
25 | title: "Bar series" | |
26 | anchors.fill: parent |
|
26 | anchors.fill: parent | |
27 | theme: ChartView.ChartThemeLight |
|
27 | theme: ChartView.ChartThemeLight | |
28 | legend.alignment: Qt.AlignBottom |
|
28 | legend.alignment: Qt.AlignBottom | |
29 | axisXLabels: ["0", "2007", "1", "2008", "2", "2009", "3", "2010", "4", "2011", "5", "2012"] |
|
29 | axisXLabels: ["0", "2007", "1", "2008", "2", "2009", "3", "2010", "4", "2011", "5", "2012"] | |
30 |
|
30 | |||
31 | property variant series: barSeries |
|
31 | property variant series: barSeries | |
32 |
|
32 | |||
33 | BarSeries { |
|
33 | BarSeries { | |
34 | id: barSeries |
|
34 | id: barSeries | |
35 | name: "bar" |
|
35 | name: "bar" | |
36 | BarSet { label: "Bob"; values: [4, 7, 3, 10, 5, 6] |
|
36 | BarSet { label: "Bob"; values: [4, 7, 3, 10, 5, 6] | |
37 | onClicked: console.log("barset.onClicked: " + index); |
|
37 | onClicked: console.log("barset.onClicked: " + index); | |
38 | onHovered: console.log("barset.onHovered: " + status); |
|
38 | onHovered: console.log("barset.onHovered: " + status); | |
39 | onColorChanged: console.log("barset.onColorChanged: " + color); |
|
39 | onColorChanged: console.log("barset.onColorChanged: " + color); | |
40 | onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); |
|
40 | onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); | |
41 | onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); |
|
41 | onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); | |
42 | onCountChanged: console.log("barset.onCountChanged: " + count); |
|
42 | onCountChanged: console.log("barset.onCountChanged: " + count); | |
43 | } |
|
43 | } | |
44 | BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 8] } |
|
44 | BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 8] } | |
45 | BarSet { label: "James"; values: [3, 5, 8, 5, 4, 7] } |
|
45 | BarSet { label: "James"; values: [3, 5, 8, 5, 4, 7] } | |
46 |
|
46 | |||
47 | onNameChanged: console.log("barSeries.onNameChanged: " + series.name); |
|
47 | onNameChanged: console.log("barSeries.onNameChanged: " + series.name); | |
48 | onVisibleChanged: console.log("barSeries.onVisibleChanged: " + series.visible); |
|
48 | onVisibleChanged: console.log("barSeries.onVisibleChanged: " + series.visible); | |
49 | onClicked: console.log("barSeries.onClicked: " + barset + " " + index); |
|
49 | onClicked: console.log("barSeries.onClicked: " + barset + " " + index); | |
50 | onHovered: console.log("barSeries.onHovered: " + barset + " " + status); |
|
50 | onHovered: console.log("barSeries.onHovered: " + barset + " " + status); | |
51 | onLabelsVisibleChanged: console.log("barSeries.onLabelsVisibleChanged: " + series.labelsVisible); |
|
51 | onLabelsVisibleChanged: console.log("barSeries.onLabelsVisibleChanged: " + series.labelsVisible); | |
52 | onCountChanged: console.log("barSeries.onCountChanged: " + count); |
|
52 | onCountChanged: console.log("barSeries.onCountChanged: " + count); | |
|
53 | onBarsetsAdded: console.log("barSeries.onBarsetsAdded: " + sets); // There is no point in this signal on QML side | |||
|
54 | onAdded: console.log("barSeries.onBarsetAdded: " + barset); | |||
|
55 | onBarsetsRemoved: console.log("barSeries.onBarsetsRemoved: " + sets); // There is no point in this signal on QML side | |||
|
56 | onRemoved: console.log("barSeries.onBarsetRemoved: " + barset); | |||
53 | } |
|
57 | } | |
54 | } |
|
58 | } |
@@ -1,66 +1,70 | |||||
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 | import QtQuick 1.0 |
|
21 | import QtQuick 1.0 | |
22 | import QtCommercial.Chart 1.0 |
|
22 | import QtCommercial.Chart 1.0 | |
23 |
|
23 | |||
24 | Flow { |
|
24 | Flow { | |
25 | id: flow |
|
25 | id: flow | |
26 | spacing: 5 |
|
26 | spacing: 5 | |
27 | flow: Flow.TopToBottom |
|
27 | flow: Flow.TopToBottom | |
28 | property variant series |
|
28 | property variant series | |
29 |
|
29 | |||
30 | Button { |
|
30 | Button { | |
31 | text: "visible" |
|
31 | text: "visible" | |
32 | onClicked: series.visible = !series.visible; |
|
32 | onClicked: series.visible = !series.visible; | |
33 | } |
|
33 | } | |
34 | Button { |
|
34 | Button { | |
35 | text: "labels visible" |
|
35 | text: "labels visible" | |
36 | onClicked: series.labelsVisible = !series.labelsVisible; |
|
36 | onClicked: series.labelsVisible = !series.labelsVisible; | |
37 | } |
|
37 | } | |
38 | Button { |
|
38 | Button { | |
39 | text: "bar width +" |
|
39 | text: "bar width +" | |
40 | onClicked: series.barWidth += 0.1; |
|
40 | onClicked: series.barWidth += 0.1; | |
41 | } |
|
41 | } | |
42 | Button { |
|
42 | Button { | |
43 | text: "bar width -" |
|
43 | text: "bar width -" | |
44 | onClicked: series.barWidth -= 0.1; |
|
44 | onClicked: series.barWidth -= 0.1; | |
45 | } |
|
45 | } | |
46 | Button { |
|
46 | Button { | |
|
47 | text: "remove set" | |||
|
48 | onClicked: series.remove(series.count - 1); | |||
|
49 | } | |||
|
50 | Button { | |||
47 | text: "set 1 color" |
|
51 | text: "set 1 color" | |
48 | onClicked: series.at(0).color = main.nextColor(); |
|
52 | onClicked: series.at(0).color = main.nextColor(); | |
49 | } |
|
53 | } | |
50 | Button { |
|
54 | Button { | |
51 | text: "set 1 border color" |
|
55 | text: "set 1 border color" | |
52 | onClicked: series.at(0).borderColor = main.nextColor(); |
|
56 | onClicked: series.at(0).borderColor = main.nextColor(); | |
53 | } |
|
57 | } | |
54 | Button { |
|
58 | Button { | |
55 | text: "set 1 label color" |
|
59 | text: "set 1 label color" | |
56 | onClicked: series.at(0).labelColor = main.nextColor(); |
|
60 | onClicked: series.at(0).labelColor = main.nextColor(); | |
57 | } |
|
61 | } | |
58 | Button { |
|
62 | Button { | |
59 | text: "set 1 font size +" |
|
63 | text: "set 1 font size +" | |
60 | onClicked: series.at(0).labelFont.pixelSize += 1; |
|
64 | onClicked: series.at(0).labelFont.pixelSize += 1; | |
61 | } |
|
65 | } | |
62 | Button { |
|
66 | Button { | |
63 | text: "set 1 font size -" |
|
67 | text: "set 1 font size -" | |
64 | onClicked: series.at(0).labelFont.pixelSize -= 1; |
|
68 | onClicked: series.at(0).labelFont.pixelSize -= 1; | |
65 | } |
|
69 | } | |
66 | } |
|
70 | } |
General Comments 0
You need to be logged in to leave comments.
Login now