##// END OF EJS Templates
Implemented QPieSeries::take()
Jani Honkonen -
r1798:4447e4e83da1
parent child
Show More
@@ -511,6 +511,31 bool QPieSeries::remove(QPieSlice* slice)
511 }
511 }
512
512
513 /*!
513 /*!
514 Takes a single \a slice from the series. Does not destroy the slice object.
515
516 NOTE: The series remains as the slice's parent object. You must set the
517 parent object to take full ownership.
518
519 Returns true if take was successfull.
520 */
521 bool QPieSeries::take(QPieSlice* slice)
522 {
523 Q_D(QPieSeries);
524
525 if (!d->m_slices.removeOne(slice))
526 return false;
527
528 QPieSlicePrivate::fromSlice(slice)->m_series = 0;
529
530 d->updateDerivativeData();
531
532 emit removed(QList<QPieSlice*>() << slice);
533 emit countChanged();
534
535 return true;
536 }
537
538 /*!
514 Clears all slices from the series.
539 Clears all slices from the series.
515 */
540 */
516 void QPieSeries::clear()
541 void QPieSeries::clear()
@@ -55,6 +55,7 public:
55 bool insert(int index, QPieSlice* slice);
55 bool insert(int index, QPieSlice* slice);
56
56
57 bool remove(QPieSlice* slice);
57 bool remove(QPieSlice* slice);
58 bool take(QPieSlice* slice);
58 void clear();
59 void clear();
59
60
60 QList<QPieSlice*> slices() const;
61 QList<QPieSlice*> slices() const;
@@ -50,6 +50,8 private slots:
50 void insertAnimated();
50 void insertAnimated();
51 void remove();
51 void remove();
52 void removeAnimated();
52 void removeAnimated();
53 void take();
54 void takeAnimated();
53 void calculatedValues();
55 void calculatedValues();
54 void clickedSignal();
56 void clickedSignal();
55 void hoverSignal();
57 void hoverSignal();
@@ -348,6 +350,40 void tst_qpieseries::removeAnimated()
348 remove();
350 remove();
349 }
351 }
350
352
353 void tst_qpieseries::take()
354 {
355 m_view->chart()->addSeries(m_series);
356 QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>)));
357
358 // add some slices
359 QPieSlice *slice1 = m_series->append("slice 1", 1);
360 QPieSlice *slice2 = m_series->append("slice 2", 2);
361 m_series->append("slice 3", 3);
362 QSignalSpy spy1(slice1, SIGNAL(destroyed()));
363 QCOMPARE(m_series->count(), 3);
364
365 // null pointer remove
366 QVERIFY(!m_series->take(0));
367
368 // take first
369 QVERIFY(m_series->take(slice1));
370 TRY_COMPARE(spy1.count(), 0);
371 QVERIFY(slice1->parent() == m_series); // series is still the parent object
372 QVERIFY(!m_series->take(slice1));
373 QCOMPARE(m_series->count(), 2);
374 QCOMPARE(m_series->slices().at(0)->label(), slice2->label());
375 QCOMPARE(removedSpy.count(), 1);
376 QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0));
377 QCOMPARE(removed.count(), 1);
378 QCOMPARE(removed.first(), slice1);
379 }
380
381 void tst_qpieseries::takeAnimated()
382 {
383 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
384 take();
385 }
386
351 void tst_qpieseries::calculatedValues()
387 void tst_qpieseries::calculatedValues()
352 {
388 {
353 m_view->chart()->addSeries(m_series);
389 m_view->chart()->addSeries(m_series);
@@ -573,6 +609,9 void tst_qpieseries::sliceSeries()
573 slice = new QPieSlice();
609 slice = new QPieSlice();
574 m_series->insert(0, slice);
610 m_series->insert(0, slice);
575 QCOMPARE(slice->series(), m_series);
611 QCOMPARE(slice->series(), m_series);
612
613 m_series->take(slice);
614 QCOMPARE(slice->series(), (QPieSeries*) 0);
576 }
615 }
577
616
578 void tst_qpieseries::destruction()
617 void tst_qpieseries::destruction()
General Comments 0
You need to be logged in to leave comments. Login now