From c871e96450b9b14ef2b60abf3f91425f3c0eb488 2012-12-12 12:40:02 From: Tero Ahola Date: 2012-12-12 12:40:02 Subject: [PATCH] Fixed a bug with QChart::axis getters with no series defined --- diff --git a/src/qchart.cpp b/src/qchart.cpp index ba62cc9..f0dd9d3 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -313,25 +313,10 @@ void QChart::zoom(qreal factor) */ QAbstractAxis *QChart::axisX(QAbstractSeries *series) const { - if(!series && d_ptr->m_dataset->series().size()>0){ - series = d_ptr->m_dataset->series().first(); - } - - QList axes = series->attachedAxes(); - QAbstractAxis* bottom=0; - QAbstractAxis* top=0; - - foreach(QAbstractAxis* axis, axes){ - - if(axis->alignment()==Qt::AlignTop){ - top=axis; - } - - if(axis->alignment()==Qt::AlignBottom){ - bottom=axis; - } - } - return bottom?bottom:top; + QList axisList = axes(Qt::Horizontal, series); + if (axisList.count()) + return axisList[0]; + return 0; } /*! @@ -340,31 +325,15 @@ QAbstractAxis *QChart::axisX(QAbstractSeries *series) const */ QAbstractAxis *QChart::axisY(QAbstractSeries *series) const { - if(!series && d_ptr->m_dataset->series().size()>0) { - series = d_ptr->m_dataset->series().first(); - } - - QList axes = series->attachedAxes(); - - QAbstractAxis* left=0; - QAbstractAxis* right=0; - - foreach(QAbstractAxis* axis, axes){ - - if(axis->alignment()==Qt::AlignLeft){ - left=axis; - } - - if(axis->alignment()==Qt::AlignRight){ - right=axis; - } - } - - return left?left:right; + QList axisList = axes(Qt::Vertical, series); + if (axisList.count()) + return axisList[0]; + return 0; } /*! - Returns the axes added for the \a series with \a orientation + Returns the axes added for the \a series with \a orientation. If no series is provided, then all axes with the + specified orientation are returned. \sa addAxis(), createDefaultAxes() */ QList QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const @@ -377,11 +346,9 @@ QList QChart::axes(Qt::Orientations orientation, QAbstractSerie result << axis; } } else { - foreach (QAbstractSeries *s, QChart::series()) { - foreach (QAbstractAxis *axis, s->attachedAxes()){ - if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) - result << axis; - } + foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ + if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) + result << axis; } } diff --git a/tests/auto/chartdataset/tst_chartdataset.cpp b/tests/auto/chartdataset/tst_chartdataset.cpp index f19be8d..38af86d 100644 --- a/tests/auto/chartdataset/tst_chartdataset.cpp +++ b/tests/auto/chartdataset/tst_chartdataset.cpp @@ -264,6 +264,7 @@ void tst_ChartDataSet::removeAxis() m_dataset->removeAxis(axis); + QCOMPARE(m_dataset->axes().count(),0); QCOMPARE(m_dataset->series().count(),0); TRY_COMPARE(spy0.count(), 0); TRY_COMPARE(spy1.count(), 1); diff --git a/tests/auto/qchart/tst_qchart.cpp b/tests/auto/qchart/tst_qchart.cpp index 4c6f5bc..5fa266f 100644 --- a/tests/auto/qchart/tst_qchart.cpp +++ b/tests/auto/qchart/tst_qchart.cpp @@ -431,14 +431,15 @@ void tst_QChart::removeAllSeries() m_view->show(); QTest::qWaitForWindowShown(m_view); m_chart->createDefaultAxes(); + QCOMPARE(m_chart->axes().count(), 2); QVERIFY(m_chart->axisY(series0)!=0); QVERIFY(m_chart->axisY(series1)!=0); QVERIFY(m_chart->axisY(series2)!=0); m_chart->removeAllSeries(); - QVERIFY(m_chart->axisY(series0)==0); - QVERIFY(m_chart->axisY(series1)==0); - QVERIFY(m_chart->axisY(series2)==0); + QCOMPARE(m_chart->axes().count(), 2); + QVERIFY(m_chart->axisX() != 0); + QVERIFY(m_chart->axisY() != 0); QCOMPARE(deleteSpy1.count(), 1); QCOMPARE(deleteSpy2.count(), 1); QCOMPARE(deleteSpy3.count(), 1); @@ -461,6 +462,8 @@ void tst_QChart::removeSeries() m_chart->setAxisY(axis,series); QCOMPARE(m_chart->axisY(series),axis); m_chart->removeSeries(series); + QCOMPARE(m_chart->axes().count(), 1); + QVERIFY(m_chart->axisY() != 0); QVERIFY(m_chart->axisY(series)==0); QCOMPARE(deleteSpy.count(), 0); }