##// END OF EJS Templates
QML BarSet data manipulation
Tero Ahola -
r1513:f9a49067ae3b
parent child
Show More
@@ -1,306 +1,308
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "declarativebarseries.h"
22 22 #include "declarativechart.h"
23 23 #include <QBarSet>
24 24 #include <QVBarModelMapper>
25 25 #include <QHBarModelMapper>
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 DeclarativeBarSet::DeclarativeBarSet(QObject *parent) :
30 30 QBarSet("", parent)
31 31 {
32 32 connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int, int)));
33 33 connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int, int)));
34 34 }
35 35
36 36 void DeclarativeBarSet::handleCountChanged(int index, int count)
37 37 {
38 38 Q_UNUSED(index)
39 39 Q_UNUSED(count)
40 40 emit countChanged(QBarSet::count());
41 41 }
42 42
43 43 QVariantList DeclarativeBarSet::values()
44 44 {
45 45 QVariantList values;
46 46 for (int i(0); i < count(); i++)
47 values.append(QVariant(at(i)));
47 values.append(QVariant(QBarSet::at(i)));
48 48 return values;
49 49 }
50 50
51 51 void DeclarativeBarSet::setValues(QVariantList values)
52 52 {
53 53 while (count())
54 54 remove(count() - 1);
55 55
56 56 for (int i(0); i < values.count(); i++) {
57 57 if (values.at(i).canConvert(QVariant::Double))
58 append(values[i].toDouble());
58 QBarSet::append(values[i].toDouble());
59 else if (values.at(i).canConvert(QVariant::PointF))
60 QBarSet::append(values[i].toPointF());
59 61 }
60 62 }
61 63
62 64 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
63 65 QBarSeries(parent)
64 66 {
65 67 connect(this, SIGNAL(barsetsAdded(QList<QBarSet*>)), this, SLOT(handleAdded(QList<QBarSet*>)));
66 68 connect(this, SIGNAL(barsetsRemoved(QList<QBarSet*>)), this, SLOT(handleRemoved(QList<QBarSet*>)));
67 69 }
68 70
69 71 void DeclarativeBarSeries::handleAdded(QList<QBarSet* > barsets)
70 72 {
71 73 foreach(QBarSet *b, barsets) {
72 74 DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b);
73 75 emit added(barset);
74 76 }
75 77 }
76 78
77 79 void DeclarativeBarSeries::handleRemoved(QList<QBarSet* > barsets)
78 80 {
79 81 foreach(QBarSet *b, barsets) {
80 82 DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b);
81 83 emit removed(barset);
82 84 }
83 85 }
84 86
85 87 void DeclarativeBarSeries::classBegin()
86 88 {
87 89 }
88 90
89 91 void DeclarativeBarSeries::componentComplete()
90 92 {
91 93 foreach(QObject *child, children()) {
92 94 if (qobject_cast<DeclarativeBarSet *>(child)) {
93 95 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
94 96 } else if(qobject_cast<QVBarModelMapper *>(child)) {
95 97 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
96 98 mapper->setSeries(this);
97 99 } else if(qobject_cast<QHBarModelMapper *>(child)) {
98 100 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
99 101 mapper->setSeries(this);
100 102 }
101 103 }
102 104 }
103 105
104 106 QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren()
105 107 {
106 108 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
107 109 }
108 110
109 111 void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
110 112 {
111 113 // Empty implementation; the children are parsed in componentComplete instead
112 114 Q_UNUSED(list);
113 115 Q_UNUSED(element);
114 116 }
115 117
116 118 DeclarativeBarSet *DeclarativeBarSeries::at(int index)
117 119 {
118 120 QList<QBarSet*> setList = barSets();
119 121 if (index >= 0 && index < setList.count())
120 122 return qobject_cast<DeclarativeBarSet *>(setList[index]);
121 123
122 124 return 0;
123 125 }
124 126
125 127 DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values)
126 128 {
127 129 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
128 130 barset->setLabel(label);
129 131 barset->setValues(values);
130 132 if (QBarSeries::insert(index, barset))
131 133 return barset;
132 134 delete barset;
133 135 return 0;
134 136 }
135 137
136 138 DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) :
137 139 QGroupedBarSeries(parent)
138 140 {
139 141 }
140 142
141 143 void DeclarativeGroupedBarSeries::classBegin()
142 144 {
143 145 }
144 146
145 147 void DeclarativeGroupedBarSeries::componentComplete()
146 148 {
147 149 foreach(QObject *child, children()) {
148 150 if (qobject_cast<DeclarativeBarSet *>(child)) {
149 151 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
150 152 } else if(qobject_cast<QVBarModelMapper *>(child)) {
151 153 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
152 154 mapper->setSeries(this);
153 155 } else if(qobject_cast<QHBarModelMapper *>(child)) {
154 156 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
155 157 mapper->setSeries(this);
156 158 }
157 159 }
158 160 }
159 161
160 162 QDeclarativeListProperty<QObject> DeclarativeGroupedBarSeries::seriesChildren()
161 163 {
162 164 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
163 165 }
164 166
165 167 void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
166 168 {
167 169 // Empty implementation; the children are parsed in componentComplete instead
168 170 Q_UNUSED(list);
169 171 Q_UNUSED(element);
170 172 }
171 173
172 174 DeclarativeBarSet *DeclarativeGroupedBarSeries::at(int index)
173 175 {
174 176 QList<QBarSet*> setList = barSets();
175 177 if (index >= 0 && index < setList.count())
176 178 return qobject_cast<DeclarativeBarSet *>(setList[index]);
177 179
178 180 return 0;
179 181 }
180 182
181 183 DeclarativeBarSet *DeclarativeGroupedBarSeries::insert(int index, QString label, QVariantList values)
182 184 {
183 185 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
184 186 barset->setLabel(label);
185 187 barset->setValues(values);
186 188 if (QGroupedBarSeries::insert(index, barset))
187 189 return barset;
188 190 delete barset;
189 191 return 0;
190 192 }
191 193
192 194 DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) :
193 195 QStackedBarSeries(parent)
194 196 {
195 197 }
196 198
197 199 void DeclarativeStackedBarSeries::classBegin()
198 200 {
199 201 }
200 202
201 203 void DeclarativeStackedBarSeries::componentComplete()
202 204 {
203 205 foreach(QObject *child, children()) {
204 206 if (qobject_cast<DeclarativeBarSet *>(child)) {
205 207 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
206 208 } else if(qobject_cast<QVBarModelMapper *>(child)) {
207 209 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
208 210 mapper->setSeries(this);
209 211 } else if(qobject_cast<QHBarModelMapper *>(child)) {
210 212 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
211 213 mapper->setSeries(this);
212 214 }
213 215 }
214 216 }
215 217
216 218 QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren()
217 219 {
218 220 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
219 221 }
220 222
221 223 void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
222 224 {
223 225 // Empty implementation; the children are parsed in componentComplete instead
224 226 Q_UNUSED(list);
225 227 Q_UNUSED(element);
226 228 }
227 229
228 230 DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index)
229 231 {
230 232 QList<QBarSet*> setList = barSets();
231 233 if (index >= 0 && index < setList.count())
232 234 return qobject_cast<DeclarativeBarSet *>(setList[index]);
233 235
234 236 return 0;
235 237 }
236 238
237 239 DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values)
238 240 {
239 241 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
240 242 barset->setLabel(label);
241 243 barset->setValues(values);
242 244 if (QStackedBarSeries::insert(index, barset))
243 245 return barset;
244 246 delete barset;
245 247 return 0;
246 248 }
247 249
248 250 DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) :
249 251 QPercentBarSeries(parent)
250 252 {
251 253 }
252 254
253 255 void DeclarativePercentBarSeries::classBegin()
254 256 {
255 257 }
256 258
257 259 void DeclarativePercentBarSeries::componentComplete()
258 260 {
259 261 foreach(QObject *child, children()) {
260 262 if (qobject_cast<DeclarativeBarSet *>(child)) {
261 263 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
262 264 } else if(qobject_cast<QVBarModelMapper *>(child)) {
263 265 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
264 266 mapper->setSeries(this);
265 267 } else if(qobject_cast<QHBarModelMapper *>(child)) {
266 268 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
267 269 mapper->setSeries(this);
268 270 }
269 271 }
270 272 }
271 273
272 274 QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren()
273 275 {
274 276 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
275 277 }
276 278
277 279 void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
278 280 {
279 281 // Empty implementation; the children are parsed in componentComplete instead
280 282 Q_UNUSED(list);
281 283 Q_UNUSED(element);
282 284 }
283 285
284 286 DeclarativeBarSet *DeclarativePercentBarSeries::at(int index)
285 287 {
286 288 QList<QBarSet*> setList = barSets();
287 289 if (index >= 0 && index < setList.count())
288 290 return qobject_cast<DeclarativeBarSet *>(setList[index]);
289 291
290 292 return 0;
291 293 }
292 294
293 295 DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values)
294 296 {
295 297 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
296 298 barset->setLabel(label);
297 299 barset->setValues(values);
298 300 if (QPercentBarSeries::insert(index, barset))
299 301 return barset;
300 302 delete barset;
301 303 return 0;
302 304 }
303 305
304 306 #include "moc_declarativebarseries.cpp"
305 307
306 308 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,162 +1,166
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef DECLARATIVEBARSERIES_H
22 22 #define DECLARATIVEBARSERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include <QGroupedBarSeries>
26 26 #include <QStackedBarSeries>
27 27 #include <QPercentBarSeries>
28 28 #include <QBarSet>
29 29 #include <QDeclarativeItem>
30 30 #include <QDeclarativeParserStatus>
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 class QChart;
35 35
36 36 class DeclarativeBarSet : public QBarSet
37 37 {
38 38 Q_OBJECT
39 39 Q_PROPERTY(QVariantList values READ values WRITE setValues)
40 40 Q_PROPERTY(int count READ count NOTIFY countChanged)
41 41
42 42 public:
43 43 explicit DeclarativeBarSet(QObject *parent = 0);
44 44 QVariantList values();
45 45 void setValues(QVariantList values);
46 46
47 47 public: // From QBarSet
48 48 Q_INVOKABLE void append(qreal value) { QBarSet::append(value); }
49 49 Q_INVOKABLE void append(qreal x, qreal y) { QBarSet::append(QPointF(x, y)); }
50 Q_INVOKABLE bool remove(const int index, const int count = 1) { return QBarSet::remove(index, count); }
51 Q_INVOKABLE void replace(int index, qreal value) { QBarSet::replace(index, value); }
52 Q_INVOKABLE void replace(int index, qreal x, qreal y) { QBarSet::replace(index, QPointF(x, y)); }
53 Q_INVOKABLE QPointF at(int index) { return QBarSet::at(index); }
50 54
51 55 Q_SIGNALS:
52 56 void countChanged(int count);
53 57
54 58 private Q_SLOTS:
55 59 void handleCountChanged(int index, int count);
56 60 };
57 61
58 62 class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus
59 63 {
60 64 Q_OBJECT
61 65 Q_INTERFACES(QDeclarativeParserStatus)
62 66 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
63 67 Q_CLASSINFO("DefaultProperty", "seriesChildren")
64 68
65 69 public:
66 70 explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0);
67 71 QDeclarativeListProperty<QObject> seriesChildren();
68 72 Q_INVOKABLE DeclarativeBarSet *at(int index);
69 73 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
70 74 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
71 75 Q_INVOKABLE bool remove(QBarSet *barset) { return QBarSeries::remove(barset); }
72 76 Q_INVOKABLE void clear() { return QBarSeries::clear(); }
73 77
74 78 public: // from QDeclarativeParserStatus
75 79 void classBegin();
76 80 void componentComplete();
77 81
78 82 Q_SIGNALS:
79 83 void added(DeclarativeBarSet *barset);
80 84 void removed(DeclarativeBarSet *barset);
81 85
82 86 public Q_SLOTS:
83 87 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
84 88 void handleAdded(QList<QBarSet* > barsets);
85 89 void handleRemoved(QList<QBarSet* > barsets);
86 90 };
87 91
88 92 class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus
89 93 {
90 94 Q_OBJECT
91 95 Q_INTERFACES(QDeclarativeParserStatus)
92 96 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
93 97 Q_CLASSINFO("DefaultProperty", "seriesChildren")
94 98
95 99 public:
96 100 explicit DeclarativeGroupedBarSeries(QDeclarativeItem *parent = 0);
97 101 QDeclarativeListProperty<QObject> seriesChildren();
98 102 Q_INVOKABLE DeclarativeBarSet *at(int index);
99 103 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
100 104 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
101 105 Q_INVOKABLE bool remove(QBarSet *barset) { return QGroupedBarSeries::remove(barset); }
102 106 Q_INVOKABLE void clear() { return QGroupedBarSeries::clear(); }
103 107
104 108 public: // from QDeclarativeParserStatus
105 109 void classBegin();
106 110 void componentComplete();
107 111
108 112 public Q_SLOTS:
109 113 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
110 114 };
111 115
112 116 class DeclarativeStackedBarSeries : public QStackedBarSeries, public QDeclarativeParserStatus
113 117 {
114 118 Q_OBJECT
115 119 Q_INTERFACES(QDeclarativeParserStatus)
116 120 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
117 121 Q_CLASSINFO("DefaultProperty", "seriesChildren")
118 122
119 123 public:
120 124 explicit DeclarativeStackedBarSeries(QDeclarativeItem *parent = 0);
121 125 QDeclarativeListProperty<QObject> seriesChildren();
122 126 Q_INVOKABLE DeclarativeBarSet *at(int index);
123 127 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
124 128 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
125 129 Q_INVOKABLE bool remove(QBarSet *barset) { return QStackedBarSeries::remove(barset); }
126 130 Q_INVOKABLE void clear() { return QStackedBarSeries::clear(); }
127 131
128 132 public: // from QDeclarativeParserStatus
129 133 void classBegin();
130 134 void componentComplete();
131 135
132 136 public Q_SLOTS:
133 137 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
134 138 };
135 139
136 140 class DeclarativePercentBarSeries : public QPercentBarSeries, public QDeclarativeParserStatus
137 141 {
138 142 Q_OBJECT
139 143 Q_INTERFACES(QDeclarativeParserStatus)
140 144 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
141 145 Q_CLASSINFO("DefaultProperty", "seriesChildren")
142 146
143 147 public:
144 148 explicit DeclarativePercentBarSeries(QDeclarativeItem *parent = 0);
145 149 QDeclarativeListProperty<QObject> seriesChildren();
146 150 Q_INVOKABLE DeclarativeBarSet *at(int index);
147 151 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
148 152 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
149 153 Q_INVOKABLE bool remove(QBarSet *barset) { return QPercentBarSeries::remove(barset); }
150 154 Q_INVOKABLE void clear() { return QPercentBarSeries::clear(); }
151 155
152 156 public: // from QDeclarativeParserStatus
153 157 void classBegin();
154 158 void componentComplete();
155 159
156 160 public Q_SLOTS:
157 161 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
158 162 };
159 163
160 164 QTCOMMERCIALCHART_END_NAMESPACE
161 165
162 166 #endif // DECLARATIVEBARSERIES_H
@@ -1,58 +1,66
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23
24 24 ChartView {
25 25 title: "Bar series"
26 26 anchors.fill: parent
27 27 theme: ChartView.ChartThemeLight
28 28 legend.alignment: Qt.AlignBottom
29 29 axisXLabels: ["0", "2007", "1", "2008", "2", "2009", "3", "2010", "4", "2011", "5", "2012"]
30 30
31 31 property variant series: barSeries
32 32
33 33 BarSeries {
34 34 id: barSeries
35 35 name: "bar"
36 36 BarSet { label: "Bob"; values: [4, 7, 3, 10, 5, 6]
37 37 onClicked: console.log("barset.onClicked: " + index);
38 38 onHovered: console.log("barset.onHovered: " + status);
39 onPenChanged: console.log("barset.onPenChanged: " + pen);
40 onBrushChanged: console.log("barset.onBrushChanged: " + brush);
41 onLabelChanged: console.log("barset.onLabelChanged: " + label);
42 onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush);
43 onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont);
39 44 onColorChanged: console.log("barset.onColorChanged: " + color);
40 45 onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color);
41 46 onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color);
42 47 onCountChanged: console.log("barset.onCountChanged: " + count);
48 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
49 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
50 onValueChanged: console.log("barset.onValuesChanged: " + index);
43 51 }
44 52 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 8] }
45 53 BarSet { label: "James"; values: [3, 5, 8, 5, 4, 7] }
46 54
47 55 onNameChanged: console.log("barSeries.onNameChanged: " + series.name);
48 56 onVisibleChanged: console.log("barSeries.onVisibleChanged: " + series.visible);
49 57 onClicked: console.log("barSeries.onClicked: " + barset + " " + index);
50 58 onHovered: console.log("barSeries.onHovered: " + barset + " " + status);
51 59 onLabelsVisibleChanged: console.log("barSeries.onLabelsVisibleChanged: " + series.labelsVisible);
52 60 onCountChanged: console.log("barSeries.onCountChanged: " + count);
53 61 onBarsetsAdded: console.log("barSeries.onBarsetsAdded: " + sets); // There is no point in this signal on QML side
54 62 onAdded: console.log("barSeries.onBarsetAdded: " + barset);
55 63 onBarsetsRemoved: console.log("barSeries.onBarsetsRemoved: " + sets); // There is no point in this signal on QML side
56 64 onRemoved: console.log("barSeries.onBarsetRemoved: " + barset);
57 65 }
58 66 }
@@ -1,88 +1,102
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23
24 24 Flow {
25 25 id: flow
26 26 spacing: 5
27 27 flow: Flow.TopToBottom
28 28 property variant series
29 29
30 30 Button {
31 31 text: "visible"
32 32 onClicked: series.visible = !series.visible;
33 33 }
34 34 Button {
35 35 text: "labels visible"
36 36 onClicked: series.labelsVisible = !series.labelsVisible;
37 37 }
38 38 Button {
39 39 text: "bar width +"
40 40 onClicked: series.barWidth += 0.1;
41 41 }
42 42 Button {
43 43 text: "bar width -"
44 44 onClicked: series.barWidth -= 0.1;
45 45 }
46 46 Button {
47 47 text: "append set"
48 48 onClicked: {
49 49 var count = series.count;
50 50 series.append("set" + count, [0, 0.1 * count, 0.2 * count, 0.3 * count, 0.4 * count, 0.5 * count, 0.6 * count]);
51 51 }
52 52 }
53 53 Button {
54 54 text: "insert set"
55 55 onClicked: {
56 56 var count = series.count;
57 57 series.insert(count - 1, "set" + count, [0, 0.1 * count, 0.2 * count, 0.3 * count, 0.4 * count, 0.5 * count, 0.6 * count]);
58 58 }
59 59 }
60 60 Button {
61 61 text: "remove set"
62 62 onClicked: series.remove(series.at(series.count - 1));
63 63 }
64 64 Button {
65 65 text: "clear sets"
66 66 onClicked: series.clear();
67 67 }
68
69 Button {
70 text: "set 1 append"
71 onClicked: series.at(0).append(series.at(0).count + 1);
72 }
73 Button {
74 text: "set 1 replace"
75 onClicked: series.at(0).replace(series.at(0).count - 1, series.at(0).at(series.at(0).count - 1).y + 0.5);
76 }
77 Button {
78 text: "set 1 remove"
79 onClicked: series.at(0).remove(series.at(0).count - 1);
80 }
81
68 82 Button {
69 83 text: "set 1 color"
70 84 onClicked: series.at(0).color = main.nextColor();
71 85 }
72 86 Button {
73 87 text: "set 1 border color"
74 88 onClicked: series.at(0).borderColor = main.nextColor();
75 89 }
76 90 Button {
77 91 text: "set 1 label color"
78 92 onClicked: series.at(0).labelColor = main.nextColor();
79 93 }
80 94 Button {
81 95 text: "set 1 font size +"
82 96 onClicked: series.at(0).labelFont.pixelSize += 1;
83 97 }
84 98 Button {
85 99 text: "set 1 font size -"
86 100 onClicked: series.at(0).labelFont.pixelSize -= 1;
87 101 }
88 102 }
@@ -1,54 +1,62
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23
24 24 ChartView {
25 25 title: "Grouped bar series"
26 26 anchors.fill: parent
27 27 theme: ChartView.ChartThemeLight
28 28 legend.alignment: Qt.AlignBottom
29 29 axisXLabels: ["0", "2007", "1", "2008", "2", "2009", "3", "2010", "4", "2011", "5", "2012"]
30 30
31 31 property variant series: barSeries
32 32
33 33 GroupedBarSeries {
34 34 id: barSeries
35 35 name: "bar"
36 36 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
37 37 onClicked: console.log("barset.onClicked: " + index);
38 38 onHovered: console.log("barset.onHovered: " + status);
39 onPenChanged: console.log("barset.onPenChanged: " + pen);
40 onBrushChanged: console.log("barset.onBrushChanged: " + brush);
41 onLabelChanged: console.log("barset.onLabelChanged: " + label);
42 onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush);
43 onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont);
39 44 onColorChanged: console.log("barset.onColorChanged: " + color);
40 45 onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color);
41 46 onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color);
42 47 onCountChanged: console.log("barset.onCountChanged: " + count);
48 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
49 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
50 onValueChanged: console.log("barset.onValuesChanged: " + index);
43 51 }
44 52 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
45 53 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
46 54
47 55 onNameChanged: console.log("groupedBarSeries.onNameChanged: " + series.name);
48 56 onVisibleChanged: console.log("groupedBarSeries.onVisibleChanged: " + series.visible);
49 57 onClicked: console.log("groupedBarSeries.onClicked: " + barset + " " + index);
50 58 onHovered: console.log("groupedBarSeries.onHovered: " + barset + " " + status);
51 59 onLabelsVisibleChanged: console.log("groupedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible);
52 60 onCountChanged: console.log("groupedBarSeries.onCountChanged: " + count);
53 61 }
54 62 }
@@ -1,54 +1,62
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23
24 24 ChartView {
25 25 title: "Percent bar series"
26 26 anchors.fill: parent
27 27 theme: ChartView.ChartThemeLight
28 28 legend.alignment: Qt.AlignBottom
29 29 axisXLabels: ["0", "2007", "1", "2008", "2", "2009", "3", "2010", "4", "2011", "5", "2012"]
30 30
31 31 property variant series: barSeries
32 32
33 33 PercentBarSeries {
34 34 id: barSeries
35 35 name: "bar"
36 36 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
37 37 onClicked: console.log("barset.onClicked: " + index);
38 38 onHovered: console.log("barset.onHovered: " + status);
39 onPenChanged: console.log("barset.onPenChanged: " + pen);
40 onBrushChanged: console.log("barset.onBrushChanged: " + brush);
41 onLabelChanged: console.log("barset.onLabelChanged: " + label);
42 onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush);
43 onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont);
39 44 onColorChanged: console.log("barset.onColorChanged: " + color);
40 45 onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color);
41 46 onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color);
42 47 onCountChanged: console.log("barset.onCountChanged: " + count);
48 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
49 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
50 onValueChanged: console.log("barset.onValuesChanged: " + index);
43 51 }
44 52 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
45 53 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
46 54
47 55 onNameChanged: console.log("percentBarSeries.onNameChanged: " + series.name);
48 56 onVisibleChanged: console.log("percentBarSeries.onVisibleChanged: " + series.visible);
49 57 onClicked: console.log("percentBarSeries.onClicked: " + barset + " " + index);
50 58 onHovered: console.log("percentBarSeries.onHovered: " + barset + " " + status);
51 59 onLabelsVisibleChanged: console.log("percentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible);
52 60 onCountChanged: console.log("percentBarSeries.onCountChanged: " + count);
53 61 }
54 62 }
@@ -1,54 +1,62
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23
24 24 ChartView {
25 25 title: "Stacked bar series"
26 26 anchors.fill: parent
27 27 theme: ChartView.ChartThemeLight
28 28 legend.alignment: Qt.AlignBottom
29 29 axisXLabels: ["0", "2007", "1", "2008", "2", "2009", "3", "2010", "4", "2011", "5", "2012"]
30 30
31 31 property variant series: barSeries
32 32
33 33 StackedBarSeries {
34 34 id: barSeries
35 35 name: "bar"
36 36 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
37 37 onClicked: console.log("barset.onClicked: " + index);
38 38 onHovered: console.log("barset.onHovered: " + status);
39 onPenChanged: console.log("barset.onPenChanged: " + pen);
40 onBrushChanged: console.log("barset.onBrushChanged: " + brush);
41 onLabelChanged: console.log("barset.onLabelChanged: " + label);
42 onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush);
43 onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont);
39 44 onColorChanged: console.log("barset.onColorChanged: " + color);
40 45 onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color);
41 46 onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color);
42 47 onCountChanged: console.log("barset.onCountChanged: " + count);
48 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
49 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
50 onValueChanged: console.log("barset.onValuesChanged: " + index);
43 51 }
44 52 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
45 53 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
46 54
47 55 onNameChanged: console.log("stackedBarSeries.onNameChanged: " + series.name);
48 56 onVisibleChanged: console.log("stackedBarSeries.onVisibleChanged: " + series.visible);
49 57 onClicked: console.log("stackedBarSeries.onClicked: " + barset + " " + index);
50 58 onHovered: console.log("stackedBarSeries.onHovered: " + barset + " " + status);
51 59 onLabelsVisibleChanged: console.log("stackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible);
52 60 onCountChanged: console.log("stackedBarSeries.onCountChanged: " + count);
53 61 }
54 62 }
General Comments 0
You need to be logged in to leave comments. Login now