@@ -168,16 +168,36 void ChartDataSet::removeSeries(QChartSeries* series) | |||||
168 | emit seriesRemoved(series); |
|
168 | emit seriesRemoved(series); | |
169 | m_seriesMap.remove(axis,series); |
|
169 | m_seriesMap.remove(axis,series); | |
170 | //remove axis if no longer there |
|
170 | //remove axis if no longer there | |
171 |
if(!m_seriesMap.contains(axis) |
|
171 | if(!m_seriesMap.contains(axis)){ | |
172 | emit axisRemoved(axis); |
|
172 | emit axisRemoved(axis); | |
173 | m_domainMap.remove(axis); |
|
173 | m_domainMap.remove(axis); | |
|
174 | if(axis != m_axisY) | |||
174 | delete axis; |
|
175 | delete axis; | |
175 | } |
|
176 | } | |
|
177 | series->setParent(0); | |||
176 | break; |
|
178 | break; | |
177 | } |
|
179 | } | |
178 | } |
|
180 | } | |
179 | } |
|
181 | } | |
180 |
|
182 | |||
|
183 | void ChartDataSet::removeAllSeries() | |||
|
184 | { | |||
|
185 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |||
|
186 | foreach(QChartAxis* axis , keys) { | |||
|
187 | QList<QChartSeries*> seriesList = m_seriesMap.values(axis); | |||
|
188 | for(int i =0 ; i < seriesList.size();i++ ) | |||
|
189 | { | |||
|
190 | emit seriesRemoved(seriesList.at(i)); | |||
|
191 | delete(seriesList.at(i)); | |||
|
192 | } | |||
|
193 | m_seriesMap.remove(axis); | |||
|
194 | m_domainMap.remove(axis); | |||
|
195 | emit axisRemoved(axis); | |||
|
196 | if(axis != m_axisY) delete axis; | |||
|
197 | } | |||
|
198 | m_domainIndex=0; | |||
|
199 | } | |||
|
200 | ||||
181 | bool ChartDataSet::nextDomain() |
|
201 | bool ChartDataSet::nextDomain() | |
182 | { |
|
202 | { | |
183 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; |
|
203 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; |
@@ -18,6 +18,7 public: | |||||
18 |
|
18 | |||
19 | void addSeries(QChartSeries* series,QChartAxis *axisY = 0); |
|
19 | void addSeries(QChartSeries* series,QChartAxis *axisY = 0); | |
20 | void removeSeries(QChartSeries* series); |
|
20 | void removeSeries(QChartSeries* series); | |
|
21 | void removeAllSeries(); | |||
21 | void addDomain(const QRectF& rect, const QRectF& viewport); |
|
22 | void addDomain(const QRectF& rect, const QRectF& viewport); | |
22 | bool nextDomain(); |
|
23 | bool nextDomain(); | |
23 | bool previousDomain(); |
|
24 | bool previousDomain(); |
@@ -28,6 +28,11 void QChart::removeSeries(QChartSeries* series) | |||||
28 | m_dataset->removeSeries(series); |
|
28 | m_dataset->removeSeries(series); | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
|
31 | void QChart::removeAllSeries() | |||
|
32 | { | |||
|
33 | m_dataset->removeAllSeries(); | |||
|
34 | } | |||
|
35 | ||||
31 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
36 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
32 | { |
|
37 | { | |
33 | createChartBackgroundItem(); |
|
38 | createChartBackgroundItem(); |
@@ -42,8 +42,9 public: | |||||
42 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
42 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
43 | ~QChart(); |
|
43 | ~QChart(); | |
44 |
|
44 | |||
45 |
void addSeries(QChartSeries* series,QChartAxis |
|
45 | void addSeries(QChartSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership | |
46 | void removeSeries(QChartSeries* series); |
|
46 | void removeSeries(QChartSeries* series); //returns ownership , deletes axis if no series attached | |
|
47 | void removeAllSeries(); // deletes series and axis | |||
47 |
|
48 | |||
48 | void setMargin(int margin); |
|
49 | void setMargin(int margin); | |
49 | int margin() const; |
|
50 | int margin() const; |
@@ -51,6 +51,11 void QChartView::removeSeries(QChartSeries* series) | |||||
51 | m_chart->removeSeries(series); |
|
51 | m_chart->removeSeries(series); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
|
54 | void QChartView::removeAllSeries() | |||
|
55 | { | |||
|
56 | m_chart->removeAllSeries(); | |||
|
57 | } | |||
|
58 | ||||
54 | void QChartView::zoomIn() |
|
59 | void QChartView::zoomIn() | |
55 | { |
|
60 | { | |
56 | m_chart->zoomIn(); |
|
61 | m_chart->zoomIn(); |
@@ -24,8 +24,9 public: | |||||
24 | //implement from QWidget |
|
24 | //implement from QWidget | |
25 | void resizeEvent(QResizeEvent *event); |
|
25 | void resizeEvent(QResizeEvent *event); | |
26 |
|
26 | |||
27 | void addSeries(QChartSeries* series,QChartAxis* axisY=0);// takes ownership |
|
27 | void addSeries(QChartSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership | |
28 | void removeSeries(QChartSeries* series); |
|
28 | void removeSeries(QChartSeries* series); //returns ownership , deletes axis if no series attached | |
|
29 | void removeAllSeries(); // deletes series and axis | |||
29 | int margin() const; |
|
30 | int margin() const; | |
30 |
|
31 | |||
31 | void setChartTitle(const QString& title); |
|
32 | void setChartTitle(const QString& title); |
@@ -39,6 +39,8 private slots: | |||||
39 | void nextpreviousDomain(); |
|
39 | void nextpreviousDomain(); | |
40 | void removeSeries_data(); |
|
40 | void removeSeries_data(); | |
41 | void removeSeries(); |
|
41 | void removeSeries(); | |
|
42 | void removeAllSeries_data(); | |||
|
43 | void removeAllSeries(); | |||
42 | }; |
|
44 | }; | |
43 |
|
45 | |||
44 | void tst_ChartDataSet::initTestCase() |
|
46 | void tst_ChartDataSet::initTestCase() | |
@@ -189,8 +191,6 void tst_ChartDataSet::addSeries() | |||||
189 | else |
|
191 | else | |
190 | axisYCount++; |
|
192 | axisYCount++; | |
191 |
|
193 | |||
192 |
|
||||
193 |
|
||||
194 | QCOMPARE(spy0.count(), axisYCount); |
|
194 | QCOMPARE(spy0.count(), axisYCount); | |
195 | QCOMPARE(spy1.count(), seriesCount*2); |
|
195 | QCOMPARE(spy1.count(), seriesCount*2); | |
196 | QCOMPARE(spy2.count(), 0); |
|
196 | QCOMPARE(spy2.count(), 0); | |
@@ -513,6 +513,10 void tst_ChartDataSet::removeSeries() | |||||
513 | dataSet.removeSeries(seriesList.at(i)); |
|
513 | dataSet.removeSeries(seriesList.at(i)); | |
514 | } |
|
514 | } | |
515 |
|
515 | |||
|
516 | //default axis | |||
|
517 | if (axisYCount == 0) | |||
|
518 | axisYCount++; | |||
|
519 | ||||
516 | QCOMPARE(spy0.count(), 0); |
|
520 | QCOMPARE(spy0.count(), 0); | |
517 | QCOMPARE(spy1.count(), 0); |
|
521 | QCOMPARE(spy1.count(), 0); | |
518 | QCOMPARE(spy2.count(), axisYCount); |
|
522 | QCOMPARE(spy2.count(), axisYCount); | |
@@ -521,8 +525,75 void tst_ChartDataSet::removeSeries() | |||||
521 | QCOMPARE(spy5.count(), seriesCount); |
|
525 | QCOMPARE(spy5.count(), seriesCount); | |
522 |
|
526 | |||
523 | QCOMPARE(dataSet.domainIndex(), 0); |
|
527 | QCOMPARE(dataSet.domainIndex(), 0); | |
|
528 | ||||
|
529 | qDeleteAll(seriesList); | |||
524 | } |
|
530 | } | |
525 |
|
531 | |||
|
532 | void tst_ChartDataSet::removeAllSeries_data() | |||
|
533 | { | |||
|
534 | QTest::addColumn<int>("seriesCount"); | |||
|
535 | QTest::addColumn<int>("axisYCount"); | |||
|
536 | QTest::newRow("2 series, default axis") << 2 << 0; | |||
|
537 | QTest::newRow("2 series, 2 new axis") << 2 << 2; | |||
|
538 | QTest::newRow("2 series, 1 new axis") << 2 << 2; | |||
|
539 | QTest::newRow("3 series, 3 new axis") << 3 << 3; | |||
|
540 | QTest::newRow("3 series, 2 new axis") << 3 << 2; | |||
|
541 | QTest::newRow("3 series, 1 new axis") << 3 << 1; | |||
|
542 | } | |||
|
543 | ||||
|
544 | void tst_ChartDataSet::removeAllSeries() | |||
|
545 | { | |||
|
546 | QFETCH(int, seriesCount); | |||
|
547 | QFETCH(int, axisYCount); | |||
|
548 | ||||
|
549 | ChartDataSet dataSet; | |||
|
550 | ||||
|
551 | QList<QChartAxis*> axisList; | |||
|
552 | ||||
|
553 | for (int i = 0; i < axisYCount; i++) { | |||
|
554 | QChartAxis* axis = new QChartAxis(); | |||
|
555 | axisList << axis; | |||
|
556 | } | |||
|
557 | ||||
|
558 | QList<QChartAxis*>::iterator iterator = axisList.begin(); | |||
|
559 | ||||
|
560 | for (int i = 0; i < seriesCount; i++) { | |||
|
561 | QChartAxis* axisY = 0; | |||
|
562 | QLineChartSeries* series = new QLineChartSeries(); | |||
|
563 | if (iterator != axisList.end()) { | |||
|
564 | axisY = *iterator; | |||
|
565 | iterator++; | |||
|
566 | } else if (axisList.count() > 0) { | |||
|
567 | iterator--; | |||
|
568 | axisY = *iterator; | |||
|
569 | iterator++; | |||
|
570 | } | |||
|
571 | dataSet.addSeries(series, axisY); | |||
|
572 | } | |||
|
573 | ||||
|
574 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | |||
|
575 | QSignalSpy spy1(&dataSet, SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); | |||
|
576 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |||
|
577 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*))); | |||
|
578 | QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&))); | |||
|
579 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*))); | |||
|
580 | ||||
|
581 | dataSet.removeAllSeries(); | |||
|
582 | //default axis | |||
|
583 | if (axisYCount == 0) | |||
|
584 | axisYCount++; | |||
|
585 | ||||
|
586 | QCOMPARE(spy0.count(), 0); | |||
|
587 | QCOMPARE(spy1.count(), 0); | |||
|
588 | QCOMPARE(spy2.count(), axisYCount); | |||
|
589 | QCOMPARE(spy3.count(), 0); | |||
|
590 | QCOMPARE(spy4.count(), 0); | |||
|
591 | QCOMPARE(spy5.count(), seriesCount); | |||
|
592 | ||||
|
593 | QCOMPARE(dataSet.domainIndex(), 0); | |||
|
594 | } | |||
|
595 | ||||
|
596 | ||||
526 | QTEST_MAIN(tst_ChartDataSet) |
|
597 | QTEST_MAIN(tst_ChartDataSet) | |
527 | #include "tst_chartdataset.moc" |
|
598 | #include "tst_chartdataset.moc" | |
528 |
|
599 |
General Comments 0
You need to be logged in to leave comments.
Login now