From 85a14a5f060fc7d34d1d9eca56b6d9eebf36b374 2012-07-31 13:58:17 From: Michal Klocek Date: 2012-07-31 13:58:17 Subject: [PATCH] Add autoscale support to barcategoriesaxis --- diff --git a/src/axis/categoriesaxis/qbarcategoriesaxis.cpp b/src/axis/categoriesaxis/qbarcategoriesaxis.cpp index 5f79496..926144c 100644 --- a/src/axis/categoriesaxis/qbarcategoriesaxis.cpp +++ b/src/axis/categoriesaxis/qbarcategoriesaxis.cpp @@ -423,17 +423,31 @@ ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain) { - Q_UNUSED(domain); - // TODO: this causes crash now. added to known issues. - /* - if (qFuzzyCompare(m_max, m_min)) { - if(m_orientation==Qt::Vertical){ - handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount()); - }else{ - handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount()); + + Q_Q(QBarCategoriesAxis); + if(m_max==m_min) { + int min; + int max; + if(m_orientation==Qt::Vertical) { + min = domain->minY() + 0.5; + max = domain->maxY() - 0.5; + } + else { + min = domain->minX() + 0.5; + max = domain->maxX() - 0.5; + } + + if(min>0 && min0 && maxsetRange(m_categories.at(min),m_categories.at(max)); + } + else { + if(m_orientation==Qt::Vertical) { + domain->setRangeY(m_min, m_max); + } + else { + domain->setRangeX(m_min, m_max); } } - */ } #include "moc_qbarcategoriesaxis.cpp" diff --git a/src/chartdataset.cpp b/src/chartdataset.cpp index 1bc3397..0af53f5 100644 --- a/src/chartdataset.cpp +++ b/src/chartdataset.cpp @@ -203,8 +203,8 @@ void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series) { Domain* domain = m_seriesDomainMap.value(series); axis->d_ptr->m_dataset = this; - axis->d_ptr->intializeDomain(domain); series->d_ptr->initializeAxis(axis); + axis->d_ptr->intializeDomain(domain); if(axis->orientation()==Qt::Horizontal) { QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); diff --git a/tests/auto/qbarcategoriesaxis/tst_qbarcategoriesaxis.cpp b/tests/auto/qbarcategoriesaxis/tst_qbarcategoriesaxis.cpp index b3f947d..efd01ad 100644 --- a/tests/auto/qbarcategoriesaxis/tst_qbarcategoriesaxis.cpp +++ b/tests/auto/qbarcategoriesaxis/tst_qbarcategoriesaxis.cpp @@ -69,6 +69,10 @@ private slots: void range(); void range_animation_data(); void range_animation(); + void noautoscale_data(); + void noautoscale(); + void autoscale_data(); + void autoscale(); private: QBarCategoriesAxis* m_baraxis; @@ -577,6 +581,69 @@ void tst_QBarCategoriesAxis::range_animation() range(); } + +void tst_QBarCategoriesAxis::noautoscale_data() +{ + QTest::addColumn("min"); + QTest::addColumn("max"); + QTest::newRow("Feb - Mar") << "Feb" << "Mar"; + QTest::newRow("Feb - May") << "Feb" << "May"; + QTest::newRow("Apr - May") << "Apr" << "May"; +} + +void tst_QBarCategoriesAxis::noautoscale() +{ + QFETCH(QString, min); + QFETCH(QString, max); + + QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString))); + QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString))); + QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString, QString))); + + m_baraxis->setRange(min, max); + QCOMPARE(m_baraxis->min(),min); + QCOMPARE(m_baraxis->max(),max); + + QCOMPARE(spy0.count(), 1); + QCOMPARE(spy1.count(), 1); + QCOMPARE(spy2.count(), 1); + + m_chart->setAxisX(m_baraxis, m_series); + m_view->show(); + QTest::qWaitForWindowShown(m_view); + QCOMPARE(m_baraxis->min(),min); + QCOMPARE(m_baraxis->max(),max); +} + +void tst_QBarCategoriesAxis::autoscale_data() +{ + +} + +void tst_QBarCategoriesAxis::autoscale() +{ + delete m_baraxis; + m_baraxis = new QBarCategoriesAxis(); + + QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString))); + QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString))); + QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString, QString))); + + QCOMPARE(m_baraxis->min(),QString()); + QCOMPARE(m_baraxis->max(),QString()); + m_chart->setAxisX(m_baraxis, m_series); + + QCOMPARE(spy0.count(), 1); + QCOMPARE(spy1.count(), 1); + QCOMPARE(spy2.count(), 1); + + m_view->show(); + QTest::qWaitForWindowShown(m_view); + QCOMPARE(m_baraxis->min(),QString("1")); + QCOMPARE(m_baraxis->max(),QString("6")); +} + + QTEST_MAIN(tst_QBarCategoriesAxis) #include "tst_qbarcategoriesaxis.moc"