##// END OF EJS Templates
Implemented BarSeries::append, insert, remove and clear to QML API
Tero Ahola -
r1511:ed36c132b8e6
parent child
Show More
@@ -116,12 +116,23 void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject
116 116 DeclarativeBarSet *DeclarativeBarSeries::at(int index)
117 117 {
118 118 QList<QBarSet*> setList = barSets();
119 if (index < setList.count())
119 if (index >= 0 && index < setList.count())
120 120 return qobject_cast<DeclarativeBarSet *>(setList[index]);
121 121
122 122 return 0;
123 123 }
124 124
125 DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values)
126 {
127 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
128 barset->setLabel(label);
129 barset->setValues(values);
130 if (QBarSeries::insert(index, barset))
131 return barset;
132 delete barset;
133 return 0;
134 }
135
125 136 DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) :
126 137 QGroupedBarSeries(parent)
127 138 {
@@ -161,12 +172,23 void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty<
161 172 DeclarativeBarSet *DeclarativeGroupedBarSeries::at(int index)
162 173 {
163 174 QList<QBarSet*> setList = barSets();
164 if (index < setList.count())
175 if (index >= 0 && index < setList.count())
165 176 return qobject_cast<DeclarativeBarSet *>(setList[index]);
166 177
167 178 return 0;
168 179 }
169 180
181 DeclarativeBarSet *DeclarativeGroupedBarSeries::insert(int index, QString label, QVariantList values)
182 {
183 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
184 barset->setLabel(label);
185 barset->setValues(values);
186 if (QGroupedBarSeries::insert(index, barset))
187 return barset;
188 delete barset;
189 return 0;
190 }
191
170 192 DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) :
171 193 QStackedBarSeries(parent)
172 194 {
@@ -206,12 +228,23 void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<
206 228 DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index)
207 229 {
208 230 QList<QBarSet*> setList = barSets();
209 if (index < setList.count())
231 if (index >= 0 && index < setList.count())
210 232 return qobject_cast<DeclarativeBarSet *>(setList[index]);
211 233
212 234 return 0;
213 235 }
214 236
237 DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values)
238 {
239 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
240 barset->setLabel(label);
241 barset->setValues(values);
242 if (QStackedBarSeries::insert(index, barset))
243 return barset;
244 delete barset;
245 return 0;
246 }
247
215 248 DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) :
216 249 QPercentBarSeries(parent)
217 250 {
@@ -251,12 +284,23 void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<
251 284 DeclarativeBarSet *DeclarativePercentBarSeries::at(int index)
252 285 {
253 286 QList<QBarSet*> setList = barSets();
254 if (index < setList.count())
287 if (index >= 0 && index < setList.count())
255 288 return qobject_cast<DeclarativeBarSet *>(setList[index]);
256 289
257 290 return 0;
258 291 }
259 292
293 DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values)
294 {
295 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
296 barset->setLabel(label);
297 barset->setValues(values);
298 if (QPercentBarSeries::insert(index, barset))
299 return barset;
300 delete barset;
301 return 0;
302 }
303
260 304 #include "moc_declarativebarseries.cpp"
261 305
262 306 QTCOMMERCIALCHART_END_NAMESPACE
@@ -66,6 +66,10 public:
66 66 explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0);
67 67 QDeclarativeListProperty<QObject> seriesChildren();
68 68 Q_INVOKABLE DeclarativeBarSet *at(int index);
69 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
70 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
71 Q_INVOKABLE bool remove(QBarSet *barset) { return QBarSeries::remove(barset); }
72 Q_INVOKABLE void clear() { return QBarSeries::clear(); }
69 73
70 74 public: // from QDeclarativeParserStatus
71 75 void classBegin();
@@ -92,6 +96,10 public:
92 96 explicit DeclarativeGroupedBarSeries(QDeclarativeItem *parent = 0);
93 97 QDeclarativeListProperty<QObject> seriesChildren();
94 98 Q_INVOKABLE DeclarativeBarSet *at(int index);
99 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
100 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
101 Q_INVOKABLE bool remove(QBarSet *barset) { return QGroupedBarSeries::remove(barset); }
102 Q_INVOKABLE void clear() { return QGroupedBarSeries::clear(); }
95 103
96 104 public: // from QDeclarativeParserStatus
97 105 void classBegin();
@@ -112,6 +120,10 public:
112 120 explicit DeclarativeStackedBarSeries(QDeclarativeItem *parent = 0);
113 121 QDeclarativeListProperty<QObject> seriesChildren();
114 122 Q_INVOKABLE DeclarativeBarSet *at(int index);
123 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
124 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
125 Q_INVOKABLE bool remove(QBarSet *barset) { return QStackedBarSeries::remove(barset); }
126 Q_INVOKABLE void clear() { return QStackedBarSeries::clear(); }
115 127
116 128 public: // from QDeclarativeParserStatus
117 129 void classBegin();
@@ -132,6 +144,10 public:
132 144 explicit DeclarativePercentBarSeries(QDeclarativeItem *parent = 0);
133 145 QDeclarativeListProperty<QObject> seriesChildren();
134 146 Q_INVOKABLE DeclarativeBarSet *at(int index);
147 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
148 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
149 Q_INVOKABLE bool remove(QBarSet *barset) { return QPercentBarSeries::remove(barset); }
150 Q_INVOKABLE void clear() { return QPercentBarSeries::clear(); }
135 151
136 152 public: // from QDeclarativeParserStatus
137 153 void classBegin();
@@ -93,12 +93,9 QPieSlice* DeclarativePieSeries::append(QString label, qreal value)
93 93 return slice;
94 94 }
95 95
96 bool DeclarativePieSeries::remove(int index)
96 bool DeclarativePieSeries::remove(QPieSlice *slice)
97 97 {
98 QPieSlice *slice = at(index);
99 if (slice)
100 return QPieSeries::remove(slice);
101 return false;
98 return QPieSeries::remove(slice);
102 99 }
103 100
104 101 void DeclarativePieSeries::clear()
@@ -45,7 +45,7 public:
45 45 Q_INVOKABLE QPieSlice *at(int index);
46 46 Q_INVOKABLE QPieSlice *find(QString label);
47 47 Q_INVOKABLE QPieSlice *append(QString label, qreal value);
48 Q_INVOKABLE bool remove(int index);
48 Q_INVOKABLE bool remove(QPieSlice *slice);
49 49 Q_INVOKABLE void clear();
50 50
51 51 public:
@@ -44,8 +44,26 Flow {
44 44 onClicked: series.barWidth -= 0.1;
45 45 }
46 46 Button {
47 text: "append set"
48 onClicked: {
49 var count = series.count;
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 }
52 }
53 Button {
54 text: "insert set"
55 onClicked: {
56 var count = series.count;
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 }
59 }
60 Button {
47 61 text: "remove set"
48 onClicked: series.remove(series.count - 1);
62 onClicked: series.remove(series.at(series.count - 1));
63 }
64 Button {
65 text: "clear sets"
66 onClicked: series.clear();
49 67 }
50 68 Button {
51 69 text: "set 1 color"
@@ -73,7 +73,7 Flow {
73 73 }
74 74 Button {
75 75 text: "remove slice"
76 onClicked: series.remove(series.count - 1);
76 onClicked: series.remove(series.at(series.count - 1));
77 77 }
78 78 Button {
79 79 text: "slice color"
General Comments 0
You need to be logged in to leave comments. Login now