@@ -252,7 +252,8 bool QAbstractBarSeries::append(QBarSet *set) | |||||
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | /*! |
|
254 | /*! | |
255 |
Removes |
|
255 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove | |
|
256 | was successful. | |||
256 | Returns true, if set was removed. |
|
257 | Returns true, if set was removed. | |
257 | */ |
|
258 | */ | |
258 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
259 | bool QAbstractBarSeries::remove(QBarSet *set) | |
@@ -265,6 +266,29 bool QAbstractBarSeries::remove(QBarSet *set) | |||||
265 | set->setParent(0); |
|
266 | set->setParent(0); | |
266 | emit barsetsRemoved(sets); |
|
267 | emit barsetsRemoved(sets); | |
267 | emit countChanged(); |
|
268 | emit countChanged(); | |
|
269 | delete set; | |||
|
270 | set = 0; | |||
|
271 | } | |||
|
272 | return success; | |||
|
273 | } | |||
|
274 | ||||
|
275 | /*! | |||
|
276 | Takes a single \a set from the series. Does not delete the barset object. | |||
|
277 | ||||
|
278 | NOTE: The series remains as the barset's parent object. You must set the | |||
|
279 | parent object to take full ownership. | |||
|
280 | ||||
|
281 | Returns true if take was successfull. | |||
|
282 | */ | |||
|
283 | bool QAbstractBarSeries::take(QBarSet *set) | |||
|
284 | { | |||
|
285 | Q_D(QAbstractBarSeries); | |||
|
286 | bool success = d->remove(set); | |||
|
287 | if (success) { | |||
|
288 | QList<QBarSet*> sets; | |||
|
289 | sets.append(set); | |||
|
290 | emit barsetsRemoved(sets); | |||
|
291 | emit countChanged(); | |||
268 | } |
|
292 | } | |
269 | return success; |
|
293 | return success; | |
270 | } |
|
294 | } | |
@@ -305,7 +329,7 bool QAbstractBarSeries::insert(int index, QBarSet *set) | |||||
305 | } |
|
329 | } | |
306 |
|
330 | |||
307 | /*! |
|
331 | /*! | |
308 |
Removes all |
|
332 | Removes all barsets from the series. Deletes removed sets. | |
309 | */ |
|
333 | */ | |
310 | void QAbstractBarSeries::clear() |
|
334 | void QAbstractBarSeries::clear() | |
311 | { |
|
335 | { | |
@@ -315,6 +339,9 void QAbstractBarSeries::clear() | |||||
315 | if (success) { |
|
339 | if (success) { | |
316 | emit barsetsRemoved(sets); |
|
340 | emit barsetsRemoved(sets); | |
317 | emit countChanged(); |
|
341 | emit countChanged(); | |
|
342 | foreach (QBarSet* set, sets) { | |||
|
343 | delete set; | |||
|
344 | } | |||
318 | } |
|
345 | } | |
319 | } |
|
346 | } | |
320 |
|
347 |
@@ -49,6 +49,7 public: | |||||
49 |
|
49 | |||
50 | bool append(QBarSet *set); |
|
50 | bool append(QBarSet *set); | |
51 | bool remove(QBarSet *set); |
|
51 | bool remove(QBarSet *set); | |
|
52 | bool take(QBarSet *set); | |||
52 | bool append(QList<QBarSet* > sets); |
|
53 | bool append(QList<QBarSet* > sets); | |
53 | bool insert(int index, QBarSet *set); |
|
54 | bool insert(int index, QBarSet *set); | |
54 | int count() const; |
|
55 | int count() const; |
@@ -28,6 +28,7 | |||||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | Q_DECLARE_METATYPE(QBarSet*) |
|
30 | Q_DECLARE_METATYPE(QBarSet*) | |
|
31 | Q_DECLARE_METATYPE(QList<QBarSet*>) | |||
31 |
|
32 | |||
32 | class tst_QBarSeries : public QObject |
|
33 | class tst_QBarSeries : public QObject | |
33 | { |
|
34 | { | |
@@ -48,6 +49,8 private slots: | |||||
48 | void append(); |
|
49 | void append(); | |
49 | void remove_data(); |
|
50 | void remove_data(); | |
50 | void remove(); |
|
51 | void remove(); | |
|
52 | void take_data(); | |||
|
53 | void take(); | |||
51 | void appendList_data(); |
|
54 | void appendList_data(); | |
52 | void appendList(); |
|
55 | void appendList(); | |
53 | void count_data(); |
|
56 | void count_data(); | |
@@ -74,6 +77,7 private: | |||||
74 | void tst_QBarSeries::initTestCase() |
|
77 | void tst_QBarSeries::initTestCase() | |
75 | { |
|
78 | { | |
76 | qRegisterMetaType<QBarSet*>("QBarSet*"); |
|
79 | qRegisterMetaType<QBarSet*>("QBarSet*"); | |
|
80 | qRegisterMetaType<QList<QBarSet*>>("QList<QBarSet*>"); | |||
77 | } |
|
81 | } | |
78 |
|
82 | |||
79 | void tst_QBarSeries::cleanupTestCase() |
|
83 | void tst_QBarSeries::cleanupTestCase() | |
@@ -95,7 +99,6 void tst_QBarSeries::cleanup() | |||||
95 | { |
|
99 | { | |
96 | foreach(QBarSet* s, m_testSets) { |
|
100 | foreach(QBarSet* s, m_testSets) { | |
97 | m_barseries_with_sets->remove(s); |
|
101 | m_barseries_with_sets->remove(s); | |
98 | delete s; |
|
|||
99 | } |
|
102 | } | |
100 | m_testSets.clear(); |
|
103 | m_testSets.clear(); | |
101 |
|
104 | |||
@@ -206,6 +209,35 void tst_QBarSeries::remove() | |||||
206 | QVERIFY(m_barseries_with_sets->count() == 0); |
|
209 | QVERIFY(m_barseries_with_sets->count() == 0); | |
207 | } |
|
210 | } | |
208 |
|
211 | |||
|
212 | void tst_QBarSeries::take_data() | |||
|
213 | { | |||
|
214 | ||||
|
215 | } | |||
|
216 | ||||
|
217 | void tst_QBarSeries::take() | |||
|
218 | { | |||
|
219 | int count = m_testSets.count(); | |||
|
220 | QVERIFY(m_barseries_with_sets->count() == count); | |||
|
221 | ||||
|
222 | QSignalSpy countSpy(m_barseries_with_sets,SIGNAL(countChanged())); | |||
|
223 | QSignalSpy removedSpy(m_barseries_with_sets,SIGNAL(barsetsRemoved(QList<QBarSet *>))); | |||
|
224 | ||||
|
225 | for (int i=0; i<m_testSets.count(); i++) { | |||
|
226 | QBarSet* set = m_testSets.at(i); | |||
|
227 | bool success = m_barseries_with_sets->take(set); | |||
|
228 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |||
|
229 | QVERIFY(success); | |||
|
230 | TRY_COMPARE(countSpy.count(),1); | |||
|
231 | TRY_COMPARE(removedSpy.count(),1); | |||
|
232 | ||||
|
233 | QList<QVariant> removedSpyArg = removedSpy.takeFirst(); | |||
|
234 | QList<QBarSet*> removedSets = qvariant_cast<QList<QBarSet*>> (removedSpyArg.at(0)); | |||
|
235 | QCOMPARE(removedSets.at(0), m_testSets.at(i)); | |||
|
236 | countSpy.takeFirst(); | |||
|
237 | } | |||
|
238 | } | |||
|
239 | ||||
|
240 | ||||
209 | void tst_QBarSeries::appendList_data() |
|
241 | void tst_QBarSeries::appendList_data() | |
210 | { |
|
242 | { | |
211 |
|
243 |
General Comments 0
You need to be logged in to leave comments.
Login now