diff --git a/src/axis/qvaluesaxis.cpp b/src/axis/qvaluesaxis.cpp index 54eabc4..00c091e 100644 --- a/src/axis/qvaluesaxis.cpp +++ b/src/axis/qvaluesaxis.cpp @@ -165,10 +165,11 @@ void QValuesAxis::setRange(qreal min, qreal max) } if (changed) { - emit rangeChanged(d->m_min,d->m_max); - emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); + emit rangeChanged(d->m_min,d->m_max); + if(!signalsBlocked()){ + emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); + } } -// d->setRange(min,max); } /*! diff --git a/src/chartdataset.cpp b/src/chartdataset.cpp index b472f53..cf01296 100644 --- a/src/chartdataset.cpp +++ b/src/chartdataset.cpp @@ -258,20 +258,48 @@ void ChartDataSet::removeAllSeries() void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) { + //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates + + blockAxisSignals(true); + QMapIterator i(m_seriesDomainMap); + while (i.hasNext()) { i.next(); i.value()->zoomIn(rect,size); } + + blockAxisSignals(false); + } void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) { + //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates + + blockAxisSignals(true); + QMapIterator i(m_seriesDomainMap); + while (i.hasNext()) { i.next(); i.value()->zoomOut(rect,size); } + + blockAxisSignals(false); +} + +void ChartDataSet::blockAxisSignals(bool enabled) +{ + QMapIterator i(m_seriesDomainMap); + + while (i.hasNext()) { + i.next(); + QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); + QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); + if(axisX) axisX->blockSignals(enabled); + if(axisY) axisY->blockSignals(enabled); + } } int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) @@ -395,11 +423,13 @@ Domain* ChartDataSet::domain(QAbstractSeries *series) const void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) { + blockAxisSignals(true); QMapIterator i(m_seriesDomainMap); while (i.hasNext()) { i.next(); i.value()->move(dx,dy,size); } + blockAxisSignals(false); } QList ChartDataSet::series() const diff --git a/src/chartdataset_p.h b/src/chartdataset_p.h index 9cd3ded..d8064fd 100644 --- a/src/chartdataset_p.h +++ b/src/chartdataset_p.h @@ -82,6 +82,7 @@ private: void addAxisX(QAbstractAxis* axis,QAbstractSeries* series); void addAxisY(QAbstractAxis* axis,QAbstractSeries* series); void removeAxes(QAbstractSeries* series); + void blockAxisSignals(bool enabled); private: QMap m_seriesAxisXMap; diff --git a/tests/auto/chartdataset/tst_chartdataset.cpp b/tests/auto/chartdataset/tst_chartdataset.cpp index 66eebe9..7cae06b 100644 --- a/tests/auto/chartdataset/tst_chartdataset.cpp +++ b/tests/auto/chartdataset/tst_chartdataset.cpp @@ -74,12 +74,11 @@ private Q_SLOTS: void domain(); void zoomInDomain_data(); void zoomInDomain(); - /* void zoomOutDomain_data(); void zoomOutDomain(); void scrollDomain_data(); void scrollDomain(); - */ + private: ChartDataSet* m_dataset; }; @@ -520,28 +519,22 @@ void tst_ChartDataSet::domain() void tst_ChartDataSet::zoomInDomain_data() { + QTest::addColumn("sameAxis"); QTest::addColumn >("seriesList"); - QTest::newRow("line,line, line, spline") << (QList() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); + QTest::newRow("sameAxis: line,line, line, spline") << true << (QList() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); + QTest::newRow("separeateAxis: line,line, line, spline") << false << (QList() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); } void tst_ChartDataSet::zoomInDomain() { + QFETCH(bool, sameAxis); QFETCH(QList, seriesList); foreach(QAbstractSeries* series, seriesList) { m_dataset->addSeries(series); } - /* - QValuesAxis* axis = new QValuesAxis(); - - for (int i = 0; i < seriesList.count(); i++) { - m_dataset->setAxisX(seriesList.at(i), axis); - } -*/ - m_dataset->createDefaultAxes(); - - + if(sameAxis) m_dataset->createDefaultAxes(); QList spyList; @@ -558,79 +551,74 @@ void tst_ChartDataSet::zoomInDomain() qDeleteAll(spyList); } -/* + + void tst_ChartDataSet::zoomOutDomain_data() { - addSeries_data(); + zoomInDomain_data(); } void tst_ChartDataSet::zoomOutDomain() { - QFETCH(QLineSeries*, series0); - QFETCH(QAxis*, axis0); - QFETCH(QLineSeries*, series1); - QFETCH(QAxis*, axis1); - QFETCH(QLineSeries*, series2); - QFETCH(QAxis*, axis2); - QFETCH(int, axisCount); + QFETCH(bool, sameAxis); + QFETCH(QList, seriesList); - Q_UNUSED(axisCount); + foreach(QAbstractSeries* series, seriesList) { + m_dataset->addSeries(series); + } - m_dataset->addSeries(series0, axis0); - m_dataset->addSeries(series1, axis1); - m_dataset->addSeries(series2, axis2); + if (sameAxis) + m_dataset->createDefaultAxes(); - Domain* domain0 = m_dataset->domain(series0); - Domain* domain1 = m_dataset->domain(series1); - Domain* domain2 = m_dataset->domain(series2); + QList spyList; - QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); + foreach(QAbstractSeries* series, seriesList) { + spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); + } - m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); + m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); - TRY_COMPARE(spy0.count(), 1); - TRY_COMPARE(spy1.count(), 1); - TRY_COMPARE(spy2.count(), 1); + foreach(QSignalSpy* spy, spyList) { + TRY_COMPARE(spy->count(), 1); + } + + qDeleteAll (spyList); } void tst_ChartDataSet::scrollDomain_data() { - addSeries_data(); + zoomInDomain_data(); } void tst_ChartDataSet::scrollDomain() { - QFETCH(QLineSeries*, series0); - QFETCH(QAxis*, axis0); - QFETCH(QLineSeries*, series1); - QFETCH(QAxis*, axis1); - QFETCH(QLineSeries*, series2); - QFETCH(QAxis*, axis2); - QFETCH(int, axisCount); + QFETCH(bool, sameAxis); + QFETCH(QList, seriesList); + + foreach(QAbstractSeries* series, seriesList) { + m_dataset->addSeries(series); + } - Q_UNUSED(axisCount); + if (sameAxis) + m_dataset->createDefaultAxes(); - m_dataset->addSeries(series0, axis0); - m_dataset->addSeries(series1, axis1); - m_dataset->addSeries(series2, axis2); + QList spyList; - Domain* domain0 = m_dataset->domain(series0); - Domain* domain1 = m_dataset->domain(series1); - Domain* domain2 = m_dataset->domain(series2); + foreach(QAbstractSeries* series, seriesList) { + spyList + << new QSignalSpy(m_dataset->domain(series), + SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); + } - QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); - QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); + m_dataset->scrollDomain(10, 10, QSize(1000, 1000)); - m_dataset->scrollDomain(10,10,QSize(1000,1000)); + foreach(QSignalSpy* spy, spyList) { + TRY_COMPARE(spy->count(), 1); + } - TRY_COMPARE(spy0.count(), 1); - TRY_COMPARE(spy1.count(), 1); - TRY_COMPARE(spy2.count(), 1); + qDeleteAll(spyList); } -*/ + QTEST_MAIN(tst_ChartDataSet) #include "tst_chartdataset.moc"