##// END OF EJS Templates
Add autoscale support to barcategoriesaxis
Michal Klocek -
r1764:85a14a5f060f
parent child
Show More
@@ -423,17 +423,31 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
423
423
424 void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain)
424 void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain)
425 {
425 {
426 Q_UNUSED(domain);
426
427 // TODO: this causes crash now. added to known issues.
427 Q_Q(QBarCategoriesAxis);
428 /*
428 if(m_max==m_min) {
429 if (qFuzzyCompare(m_max, m_min)) {
429 int min;
430 if(m_orientation==Qt::Vertical){
430 int max;
431 handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount());
431 if(m_orientation==Qt::Vertical) {
432 }else{
432 min = domain->minY() + 0.5;
433 handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount());
433 max = domain->maxY() - 0.5;
434 }
435 else {
436 min = domain->minX() + 0.5;
437 max = domain->maxX() - 0.5;
438 }
439
440 if(min>0 && min<m_categories.count() && max>0 && max<m_categories.count())
441 q->setRange(m_categories.at(min),m_categories.at(max));
442 }
443 else {
444 if(m_orientation==Qt::Vertical) {
445 domain->setRangeY(m_min, m_max);
446 }
447 else {
448 domain->setRangeX(m_min, m_max);
434 }
449 }
435 }
450 }
436 */
437 }
451 }
438
452
439 #include "moc_qbarcategoriesaxis.cpp"
453 #include "moc_qbarcategoriesaxis.cpp"
@@ -203,8 +203,8 void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series)
203 {
203 {
204 Domain* domain = m_seriesDomainMap.value(series);
204 Domain* domain = m_seriesDomainMap.value(series);
205 axis->d_ptr->m_dataset = this;
205 axis->d_ptr->m_dataset = this;
206 axis->d_ptr->intializeDomain(domain);
207 series->d_ptr->initializeAxis(axis);
206 series->d_ptr->initializeAxis(axis);
207 axis->d_ptr->intializeDomain(domain);
208 if(axis->orientation()==Qt::Horizontal) {
208 if(axis->orientation()==Qt::Horizontal) {
209 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
209 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
210 QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
210 QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
@@ -69,6 +69,10 private slots:
69 void range();
69 void range();
70 void range_animation_data();
70 void range_animation_data();
71 void range_animation();
71 void range_animation();
72 void noautoscale_data();
73 void noautoscale();
74 void autoscale_data();
75 void autoscale();
72
76
73 private:
77 private:
74 QBarCategoriesAxis* m_baraxis;
78 QBarCategoriesAxis* m_baraxis;
@@ -577,6 +581,69 void tst_QBarCategoriesAxis::range_animation()
577 range();
581 range();
578 }
582 }
579
583
584
585 void tst_QBarCategoriesAxis::noautoscale_data()
586 {
587 QTest::addColumn<QString>("min");
588 QTest::addColumn<QString>("max");
589 QTest::newRow("Feb - Mar") << "Feb" << "Mar";
590 QTest::newRow("Feb - May") << "Feb" << "May";
591 QTest::newRow("Apr - May") << "Apr" << "May";
592 }
593
594 void tst_QBarCategoriesAxis::noautoscale()
595 {
596 QFETCH(QString, min);
597 QFETCH(QString, max);
598
599 QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString)));
600 QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString)));
601 QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString, QString)));
602
603 m_baraxis->setRange(min, max);
604 QCOMPARE(m_baraxis->min(),min);
605 QCOMPARE(m_baraxis->max(),max);
606
607 QCOMPARE(spy0.count(), 1);
608 QCOMPARE(spy1.count(), 1);
609 QCOMPARE(spy2.count(), 1);
610
611 m_chart->setAxisX(m_baraxis, m_series);
612 m_view->show();
613 QTest::qWaitForWindowShown(m_view);
614 QCOMPARE(m_baraxis->min(),min);
615 QCOMPARE(m_baraxis->max(),max);
616 }
617
618 void tst_QBarCategoriesAxis::autoscale_data()
619 {
620
621 }
622
623 void tst_QBarCategoriesAxis::autoscale()
624 {
625 delete m_baraxis;
626 m_baraxis = new QBarCategoriesAxis();
627
628 QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString)));
629 QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString)));
630 QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString, QString)));
631
632 QCOMPARE(m_baraxis->min(),QString());
633 QCOMPARE(m_baraxis->max(),QString());
634 m_chart->setAxisX(m_baraxis, m_series);
635
636 QCOMPARE(spy0.count(), 1);
637 QCOMPARE(spy1.count(), 1);
638 QCOMPARE(spy2.count(), 1);
639
640 m_view->show();
641 QTest::qWaitForWindowShown(m_view);
642 QCOMPARE(m_baraxis->min(),QString("1"));
643 QCOMPARE(m_baraxis->max(),QString("6"));
644 }
645
646
580 QTEST_MAIN(tst_QBarCategoriesAxis)
647 QTEST_MAIN(tst_QBarCategoriesAxis)
581 #include "tst_qbarcategoriesaxis.moc"
648 #include "tst_qbarcategoriesaxis.moc"
582
649
General Comments 0
You need to be logged in to leave comments. Login now