From ae9ab27188c98cbf7fef1d0fab145961164c7f5b 2012-07-04 08:29:49 From: Michal Klocek Date: 2012-07-04 08:29:49 Subject: [PATCH] Add defualt show axis * adds selectViebileAxis to presenter * fix qmlcustommodel example to use the new logic --- diff --git a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml index 5e8607c..b18d31b 100644 --- a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml +++ b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml @@ -164,20 +164,10 @@ Rectangle { //![3] Component.onCompleted: { - setAxisX(categoryAxis,myBarSeries) - setAxisX(categoryAxis,lineSeries1) - setAxisX(categoryAxis,lineSeries2) - setAxisX(categoryAxis,lineSeries3) - setAxisX(categoryAxis,lineSeries4) - setAxisX(categoryAxis,lineSeries5) - setAxisY(yAxis,myBarSeries) - setAxisY(yAxis,lineSeries1) - setAxisY(yAxis,lineSeries2) - setAxisY(yAxis,lineSeries3) - setAxisY(yAxis,lineSeries4) - setAxisY(yAxis,lineSeries5) - categoryAxis.min = "2007" - categoryAxis.max = "2014" + createDefaultAxes(); + setAxisX(categoryAxis,myBarSeries) + categoryAxis.min = "2007" + categoryAxis.max = "2014" } } } diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index 2951a34..7546087 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -98,8 +98,7 @@ void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain) if(m_rect.isValid()) item->handleGeometryChanged(m_rect); //reload visiblity m_axisItems.insert(axis, item); - if(axis->isVisible()) axis->hide(); - axis->show(); + selectVisibleAxis(); } @@ -107,6 +106,7 @@ void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis) { ChartAxis* item = m_axisItems.take(axis); Q_ASSERT(item); + selectVisibleAxis(); if(m_animator) m_animator->removeAnimation(item); item->deleteLater(); } @@ -143,6 +143,34 @@ void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series) item->deleteLater(); } +void ChartPresenter::selectVisibleAxis() +{ + QMapIterator i(m_axisItems); + + while (i.hasNext()) { + i.next(); + i.key()->hide(); + } + + i.toFront(); + + bool axisX=false; + bool axisY=false; + + while (i.hasNext()) { + i.next(); + if(i.key()->d_ptr->m_orientation==Qt::Vertical && !axisY) { + axisY=true; + i.key()->show(); + } + if(i.key()->d_ptr->m_orientation==Qt::Horizontal && !axisX) { + axisX=true; + i.key()->show(); + } + + } +} + void ChartPresenter::handleAxisVisibleChanged(bool visible) { diff --git a/src/chartpresenter_p.h b/src/chartpresenter_p.h index 98ce8d1..283f7a0 100644 --- a/src/chartpresenter_p.h +++ b/src/chartpresenter_p.h @@ -137,6 +137,7 @@ public: private: void createBackgroundItem(); void createTitleItem(); + void selectVisibleAxis(); public Q_SLOTS: void handleSeriesAdded(QAbstractSeries* series,Domain* domain);