From 7d4c8a7722397da35034c669849b415ea4e2cba3 2012-07-04 08:13:05 From: Michal Klocek Date: 2012-07-04 08:13:05 Subject: [PATCH] Adds logic to fix overlaping axes --- diff --git a/src/axis/qabstractaxis.cpp b/src/axis/qabstractaxis.cpp index 42093f5..8947a71 100644 --- a/src/axis/qabstractaxis.cpp +++ b/src/axis/qabstractaxis.cpp @@ -516,8 +516,11 @@ bool QAbstractAxis::isVisible() const */ void QAbstractAxis::setVisible(bool visible) { - d_ptr->m_visible=visible; - emit d_ptr->updated(); + if(d_ptr->m_visible!=visible){ + d_ptr->m_visible=visible; + emit visibleChanged(visible); + emit d_ptr->updated(); + } } @@ -555,7 +558,7 @@ void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): q_ptr(q), - m_visible(true), + m_visible(false), m_axisVisible(true), m_gridLineVisible(true), m_labelsVisible(true), diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index 0cc8da9..2951a34 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -93,9 +93,14 @@ void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain) } QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); + QObject::connect(axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleAxisVisibleChanged(bool))); //initialize if(m_rect.isValid()) item->handleGeometryChanged(m_rect); + //reload visiblity m_axisItems.insert(axis, item); + if(axis->isVisible()) axis->hide(); + axis->show(); + } void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis) @@ -138,6 +143,27 @@ void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series) item->deleteLater(); } + +void ChartPresenter::handleAxisVisibleChanged(bool visible) +{ + QAbstractAxis* axis = static_cast (sender()); + Q_ASSERT(axis); + if(visible){ + + QMapIterator i(m_axisItems); + + while (i.hasNext()) { + i.next(); + if(i.key()==axis) { + continue; + } + if(i.key()->d_ptr->m_orientation==axis->d_ptr->m_orientation) { + i.key()->setVisible(false); + } + } + } +} + void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) { if(m_chartTheme && m_chartTheme->id() == theme) return; diff --git a/src/chartpresenter_p.h b/src/chartpresenter_p.h index 178586d..98ce8d1 100644 --- a/src/chartpresenter_p.h +++ b/src/chartpresenter_p.h @@ -143,6 +143,7 @@ public Q_SLOTS: void handleSeriesRemoved(QAbstractSeries* series); void handleAxisAdded(QAbstractAxis* axis,Domain* domain); void handleAxisRemoved(QAbstractAxis* axis); + void handleAxisVisibleChanged(bool visible); private Q_SLOTS: void handleAnimationFinished();