From 7809dd5f66eb51ad7058048d75e408ade3d7f4d0 2012-07-23 11:18:55 From: Michal Klocek Date: 2012-07-23 11:18:55 Subject: [PATCH] Refactor Visibly methods of axis * adds set*Visiblity * adds hide() * adds disconnect signals to limit changes for object which is deleteLater --- diff --git a/src/axis/categoriesaxis/chartcategoriesaxisx.cpp b/src/axis/categoriesaxis/chartcategoriesaxisx.cpp index d912d28..40bd81d 100644 --- a/src/axis/categoriesaxis/chartcategoriesaxisx.cpp +++ b/src/axis/categoriesaxis/chartcategoriesaxisx.cpp @@ -100,7 +100,7 @@ void ChartCategoriesAxisX::updateGeometry() QList lines = m_grid->childItems(); QList labels = m_labels->childItems(); QList shades = m_shades->childItems(); - QList axis = m_axis->childItems(); + QList axis = m_arrow->childItems(); Q_ASSERT(labels.size() == ticksList.size()); Q_ASSERT(layout.size() == ticksList.size()); diff --git a/src/axis/categoriesaxis/chartcategoriesaxisy.cpp b/src/axis/categoriesaxis/chartcategoriesaxisy.cpp index bd9ff14..4495fe1 100644 --- a/src/axis/categoriesaxis/chartcategoriesaxisy.cpp +++ b/src/axis/categoriesaxis/chartcategoriesaxisy.cpp @@ -97,7 +97,7 @@ void ChartCategoriesAxisY::updateGeometry() QList lines = m_grid->childItems(); QList labels = m_labels->childItems(); QList shades = m_shades->childItems(); - QList axis = m_axis->childItems(); + QList axis = m_arrow->childItems(); Q_ASSERT(labels.size() == ticksList.size()); Q_ASSERT(layout.size() == ticksList.size()); diff --git a/src/axis/chartaxis.cpp b/src/axis/chartaxis.cpp index 005b903..6b7acd6 100644 --- a/src/axis/chartaxis.cpp +++ b/src/axis/chartaxis.cpp @@ -35,7 +35,7 @@ ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(pres m_grid(new QGraphicsItemGroup(presenter->rootItem())), m_shades(new QGraphicsItemGroup(presenter->rootItem())), m_labels(new QGraphicsItemGroup(presenter->rootItem())), - m_axis(new QGraphicsItemGroup(presenter->rootItem())), + m_arrow(new QGraphicsItemGroup(presenter->rootItem())), m_min(0), m_max(0), m_animation(0), @@ -43,8 +43,8 @@ ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(pres m_minHeight(0) { //initial initialization - m_axis->setZValue(ChartPresenter::AxisZValue); - m_axis->setHandlesChildEvents(false); + m_arrow->setZValue(ChartPresenter::AxisZValue); + m_arrow->setHandlesChildEvents(false); m_shades->setZValue(ChartPresenter::ShadesZValue); m_grid->setZValue(ChartPresenter::GridZValue); @@ -71,12 +71,12 @@ void ChartAxis::setLayout(QVector &layout) void ChartAxis::createItems(int count) { - if (m_axis->children().size() == 0) - m_axis->addToGroup(new AxisItem(this)); + if (m_arrow->children().size() == 0) + m_arrow->addToGroup(new AxisItem(this)); for (int i = 0; i < count; ++i) { m_grid->addToGroup(new QGraphicsLineItem()); m_labels->addToGroup(new QGraphicsSimpleTextItem()); - m_axis->addToGroup(new QGraphicsLineItem()); + m_arrow->addToGroup(new QGraphicsLineItem()); if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem()); } } @@ -86,7 +86,7 @@ void ChartAxis::deleteItems(int count) QList lines = m_grid->childItems(); QList labels = m_labels->childItems(); QList shades = m_shades->childItems(); - QList axis = m_axis->childItems(); + QList axis = m_arrow->childItems(); for (int i = 0; i < count; ++i) { if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast()); @@ -140,14 +140,19 @@ void ChartAxis::updateLayout(QVector &layout) } } -void ChartAxis::setAxisOpacity(qreal opacity) +void ChartAxis::setArrowOpacity(qreal opacity) { - m_axis->setOpacity(opacity); + m_arrow->setOpacity(opacity); } -qreal ChartAxis::axisOpacity() const +qreal ChartAxis::arrowOpacity() const { - return m_axis->opacity(); + return m_arrow->opacity(); +} + +void ChartAxis::setArrowVisibility(bool visible) +{ + m_arrow->setOpacity(visible); } void ChartAxis::setGridOpacity(qreal opacity) @@ -160,6 +165,11 @@ qreal ChartAxis::gridOpacity() const return m_grid->opacity(); } +void ChartAxis::setGridVisibility(bool visible) +{ + m_grid->setOpacity(visible); +} + void ChartAxis::setLabelsOpacity(qreal opacity) { m_labels->setOpacity(opacity); @@ -170,6 +180,11 @@ qreal ChartAxis::labelsOpacity() const return m_labels->opacity(); } +void ChartAxis::setLabelsVisibility(bool visible) +{ + m_labels->setOpacity(visible); +} + void ChartAxis::setShadesOpacity(qreal opacity) { m_shades->setOpacity(opacity); @@ -180,6 +195,11 @@ qreal ChartAxis::shadesOpacity() const return m_shades->opacity(); } +void ChartAxis::setShadesVisibility(bool visible) +{ + m_shades->setVisible(visible); +} + void ChartAxis::setLabelsAngle(int angle) { foreach(QGraphicsItem* item , m_labels->childItems()) { @@ -225,9 +245,9 @@ void ChartAxis::setShadesPen(const QPen &pen) } } -void ChartAxis::setAxisPen(const QPen &pen) +void ChartAxis::setArrowPen(const QPen &pen) { - foreach(QGraphicsItem* item , m_axis->childItems()) { + foreach(QGraphicsItem* item , m_arrow->childItems()) { static_cast(item)->setPen(pen); } } @@ -276,45 +296,16 @@ void ChartAxis::handleAxisUpdated() { if(isEmpty()) return; - if (!m_chartAxis->isVisible()) { - setAxisOpacity(0); - setGridOpacity(0); - setLabelsOpacity(0); - setShadesOpacity(0); - } - else { - - if (m_chartAxis->isArrowVisible()) { - setAxisOpacity(100); - } - else { - setAxisOpacity(0); - } - if (m_chartAxis->isGridLineVisible()) { - setGridOpacity(100); - } - else { - setGridOpacity(0); - } - - if (m_chartAxis->labelsVisible()) { - setLabelsOpacity(100); - } - else { - setLabelsOpacity(0); - } + bool visible = m_chartAxis->isVisible(); - if (m_chartAxis->shadesVisible()) { - setShadesOpacity(100); - } - else { - setShadesOpacity(0); - } - } + setArrowVisibility(visible && m_chartAxis->isArrowVisible()); + setGridVisibility(visible && m_chartAxis->isGridLineVisible()); + setLabelsVisibility(visible && m_chartAxis->labelsVisible()); + setShadesVisibility(visible && m_chartAxis->shadesVisible()); setLabelsAngle(m_chartAxis->labelsAngle()); - setAxisPen(m_chartAxis->axisPen()); + setArrowPen(m_chartAxis->axisPen()); setLabelsPen(m_chartAxis->labelsPen()); setLabelsBrush(m_chartAxis->labelsBrush()); setLabelsFont(m_chartAxis->labelsFont()); @@ -324,6 +315,14 @@ void ChartAxis::handleAxisUpdated() } +void ChartAxis::hide() +{ + setArrowVisibility(false); + setGridVisibility(false); + setLabelsVisibility(false); + setShadesVisibility(false); +} + void ChartAxis::handleGeometryChanged(const QRectF &rect) { if(m_rect != rect) diff --git a/src/axis/chartaxis_p.h b/src/axis/chartaxis_p.h index ef92262..2dd63b9 100644 --- a/src/axis/chartaxis_p.h +++ b/src/axis/chartaxis_p.h @@ -52,17 +52,21 @@ public: virtual AxisType axisType() const = 0; - void setAxisOpacity(qreal opacity); - qreal axisOpacity() const; + void setArrowOpacity(qreal opacity); + qreal arrowOpacity() const; + void setArrowVisibility(bool visible); void setGridOpacity(qreal opacity); qreal gridOpacity() const; + void setGridVisibility(bool visible); void setLabelsOpacity(qreal opacity); qreal labelsOpacity() const; + void setLabelsVisibility(bool visible); void setShadesOpacity(qreal opacity); qreal shadesOpacity() const; + void setShadesVisibility(bool visible); void setLabelsAngle(int angle); int labelsAngle()const { return m_labelsAngle; } @@ -70,7 +74,7 @@ public: void setShadesBrush(const QBrush &brush); void setShadesPen(const QPen &pen); - void setAxisPen(const QPen &pen); + void setArrowPen(const QPen &pen); void setGridPen(const QPen &pen); void setLabelsPen(const QPen &pen); @@ -88,6 +92,8 @@ public: qreal minimumWidth(); qreal minimumHeight(); + void hide(); + protected: virtual void updateGeometry() = 0; virtual QVector calculateLayout() const = 0; @@ -112,7 +118,7 @@ protected: QScopedPointer m_grid; QScopedPointer m_shades; QScopedPointer m_labels; - QScopedPointer m_axis; + QScopedPointer m_arrow; QVector m_layoutVector; qreal m_min; qreal m_max; diff --git a/src/axis/datetimeaxis/chartdatetimeaxisx.cpp b/src/axis/datetimeaxis/chartdatetimeaxisx.cpp index 37bec16..95865e5 100644 --- a/src/axis/datetimeaxis/chartdatetimeaxisx.cpp +++ b/src/axis/datetimeaxis/chartdatetimeaxisx.cpp @@ -88,7 +88,7 @@ void ChartDateTimeAxisX::updateGeometry() QList lines = m_grid->childItems(); QList labels = m_labels->childItems(); QList shades = m_shades->childItems(); - QList axis = m_axis->childItems(); + QList axis = m_arrow->childItems(); Q_ASSERT(labels.size() == ticksList.size()); Q_ASSERT(layout.size() == ticksList.size()); diff --git a/src/axis/datetimeaxis/chartdatetimeaxisy.cpp b/src/axis/datetimeaxis/chartdatetimeaxisy.cpp index fadc6a8..439c501 100644 --- a/src/axis/datetimeaxis/chartdatetimeaxisy.cpp +++ b/src/axis/datetimeaxis/chartdatetimeaxisy.cpp @@ -88,7 +88,7 @@ void ChartDateTimeAxisY::updateGeometry() QList lines = m_grid->childItems(); QList labels = m_labels->childItems(); QList shades = m_shades->childItems(); - QList axis = m_axis->childItems(); + QList axis = m_arrow->childItems(); Q_ASSERT(labels.size() == ticksList.size()); Q_ASSERT(layout.size() == ticksList.size()); diff --git a/src/axis/intervalsaxis/chartintervalsaxisx.cpp b/src/axis/intervalsaxis/chartintervalsaxisx.cpp index 2325061..a041ab6 100644 --- a/src/axis/intervalsaxis/chartintervalsaxisx.cpp +++ b/src/axis/intervalsaxis/chartintervalsaxisx.cpp @@ -82,7 +82,7 @@ void ChartIntervalAxisX::updateGeometry() QList lines = m_grid->childItems(); QList labels = m_labels->childItems(); QList shades = m_shades->childItems(); - QList axis = m_axis->childItems(); + QList axis = m_arrow->childItems(); // Q_ASSERT(labels.size() == ticksList.size()); // Q_ASSERT(layout.size() == ticksList.size()); diff --git a/src/axis/intervalsaxis/chartintervalsaxisy.cpp b/src/axis/intervalsaxis/chartintervalsaxisy.cpp index 2c983e4..0a952b8 100644 --- a/src/axis/intervalsaxis/chartintervalsaxisy.cpp +++ b/src/axis/intervalsaxis/chartintervalsaxisy.cpp @@ -79,7 +79,7 @@ void ChartIntervalAxisY::updateGeometry() QList lines = m_grid->childItems(); QList labels = m_labels->childItems(); QList shades = m_shades->childItems(); - QList axis = m_axis->childItems(); + QList axis = m_arrow->childItems(); // Q_ASSERT(labels.size() == ticksList.size()); // Q_ASSERT(layout.size() == ticksList.size()); diff --git a/src/axis/valuesaxis/chartvaluesaxisx.cpp b/src/axis/valuesaxis/chartvaluesaxisx.cpp index 3d41a60..77bc5fa 100644 --- a/src/axis/valuesaxis/chartvaluesaxisx.cpp +++ b/src/axis/valuesaxis/chartvaluesaxisx.cpp @@ -72,7 +72,7 @@ void ChartValuesAxisX::updateGeometry() QList lines = m_grid->childItems(); QList labels = m_labels->childItems(); QList shades = m_shades->childItems(); - QList axis = m_axis->childItems(); + QList axis = m_arrow->childItems(); Q_ASSERT(labels.size() == ticksList.size()); Q_ASSERT(layout.size() == ticksList.size()); diff --git a/src/axis/valuesaxis/chartvaluesaxisy.cpp b/src/axis/valuesaxis/chartvaluesaxisy.cpp index c7d1fed..a3be892 100644 --- a/src/axis/valuesaxis/chartvaluesaxisy.cpp +++ b/src/axis/valuesaxis/chartvaluesaxisy.cpp @@ -72,7 +72,7 @@ void ChartValuesAxisY::updateGeometry() QList lines = m_grid->childItems(); QList labels = m_labels->childItems(); QList shades = m_shades->childItems(); - QList axis = m_axis->childItems(); + QList axis = m_arrow->childItems(); Q_ASSERT(labels.size() == ticksList.size()); Q_ASSERT(layout.size() == ticksList.size()); diff --git a/src/chartdataset.cpp b/src/chartdataset.cpp index a4c924e..403ed10 100644 --- a/src/chartdataset.cpp +++ b/src/chartdataset.cpp @@ -423,10 +423,11 @@ void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Ori QAbstractAxis *oldAxis = seriesAxisMap->take(series); QList axes = seriesAxisMap->values(); - if(oldAxis) { if(axes.indexOf(oldAxis)==-1) { emit axisRemoved(oldAxis); + oldAxis->disconnect(); + QObject::disconnect(domain,0,oldAxis,0); oldAxis->d_ptr->m_dataset=0; oldAxis->deleteLater(); } diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index 54888ce..d231769 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -99,6 +99,9 @@ void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis) Q_ASSERT(item); selectVisibleAxis(); if(m_animator) m_animator->removeAnimation(item); + item->hide(); + item->disconnect(); + QObject::disconnect(this,0,item,0); item->deleteLater(); }