diff --git a/src/axis/chartaxis.cpp b/src/axis/chartaxis.cpp index c282085..5cd7576 100644 --- a/src/axis/chartaxis.cpp +++ b/src/axis/chartaxis.cpp @@ -82,6 +82,7 @@ void ChartAxis::connectSlots() QObject::connect(m_axis,SIGNAL(titleFontChanged(const QFont&)),this,SLOT(handleTitleFontChanged(const QFont&))); QObject::connect(m_axis,SIGNAL(titlePenChanged(const QPen&)),this,SLOT(handleTitlePenChanged(const QPen&))); QObject::connect(m_axis,SIGNAL(titleBrushChanged(const QBrush&)),this,SLOT(handleTitleBrushChanged(const QBrush&))); + QObject::connect(m_axis,SIGNAL(titleVisibleChanged(bool)),this,SLOT(handleTitleVisibleChanged(bool))); QObject::connect(m_axis->d_ptr.data(),SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(handleRangeChanged(qreal,qreal))); } @@ -289,6 +290,12 @@ void ChartAxis::handleShadesVisibleChanged(bool visible) m_shades->setVisible(visible); } +void ChartAxis::handleTitleVisibleChanged(bool visible) +{ + m_title->setVisible(visible); + presenter()->layout()->invalidate(); +} + void ChartAxis::handleLabelsAngleChanged(int angle) { foreach (QGraphicsItem *item, m_labels->childItems()) @@ -371,6 +378,21 @@ void ChartAxis::handleTitleFontChanged(const QFont &font) void ChartAxis::handleVisibleChanged(bool visible) { setVisible(visible); + if(!visible) { + m_grid->setVisible(visible); + m_arrow->setVisible(visible); + m_shades->setVisible(visible); + m_labels->setVisible(visible); + m_title->setVisible(visible); + }else { + m_grid->setVisible(m_axis->isGridLineVisible()); + m_arrow->setVisible(m_axis->isLineVisible()); + m_shades->setVisible(m_axis->shadesVisible()); + m_labels->setVisible(m_axis->labelsVisible()); + m_title->setVisible(m_axis->isTitleVisible()); + } + + presenter()->layout()->invalidate(); } void ChartAxis::handleRangeChanged(qreal min, qreal max) diff --git a/src/axis/chartaxis_p.h b/src/axis/chartaxis_p.h index ee54d85..37e94be 100644 --- a/src/axis/chartaxis_p.h +++ b/src/axis/chartaxis_p.h @@ -129,6 +129,7 @@ public Q_SLOTS: void handleTitleBrushChanged(const QBrush &brush); void handleTitleFontChanged(const QFont &font); void handleTitleTextChanged(const QString &title); + void handleTitleVisibleChanged(bool visible); void handleRangeChanged(qreal min , qreal max); Q_SIGNALS: diff --git a/src/axis/horizontalaxis.cpp b/src/axis/horizontalaxis.cpp index 302f11b..dc4c36c 100644 --- a/src/axis/horizontalaxis.cpp +++ b/src/axis/horizontalaxis.cpp @@ -189,7 +189,7 @@ QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) co QFontMetrics fn(titleFont()); QSizeF sh; - if (titleText().isNull()) + if (titleText().isNull() || !titleItem()->isVisible()) return sh; switch (which) { diff --git a/src/axis/qabstractaxis.cpp b/src/axis/qabstractaxis.cpp index f40e4c5..65d54aa 100644 --- a/src/axis/qabstractaxis.cpp +++ b/src/axis/qabstractaxis.cpp @@ -499,11 +499,11 @@ void QAbstractAxis::setTitleVisible(bool visible) { if (d_ptr->m_titleVisible != visible) { d_ptr->m_titleVisible = visible; - emit labelsVisibleChanged(visible); + emit titleVisibleChanged(visible); } } -bool QAbstractAxis::titleVisible() const +bool QAbstractAxis::isTitleVisible() const { return d_ptr->m_titleVisible; } diff --git a/src/axis/qabstractaxis.h b/src/axis/qabstractaxis.h index de612f8..343724c 100644 --- a/src/axis/qabstractaxis.h +++ b/src/axis/qabstractaxis.h @@ -64,8 +64,8 @@ class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged) Q_PROPERTY(QPen titlePen READ titlePen WRITE setTitlePen NOTIFY titlePenChanged) Q_PROPERTY(QBrush titleBrush READ titleBrush WRITE setTitleBrush NOTIFY titleBrushChanged) - Q_PROPERTY(bool titleVisible READ titleVisible WRITE setTitleVisible) - Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) + Q_PROPERTY(bool titleVisible READ isTitleVisible WRITE setTitleVisible NOTIFY titleVisibleChanged) + Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont NOTIFY titleFontChanged) //orientation Q_PROPERTY(Qt::Orientation orinetation READ orientation) //aligment @@ -127,7 +127,7 @@ public: QColor labelsColor() const; //title handling - bool titleVisible() const; + bool isTitleVisible() const; void setTitleVisible(bool visible = true); void setTitlePen(const QPen &pen); QPen titlePen() const; diff --git a/src/axis/verticalaxis.cpp b/src/axis/verticalaxis.cpp index 448f8f9..826e257 100644 --- a/src/axis/verticalaxis.cpp +++ b/src/axis/verticalaxis.cpp @@ -191,7 +191,7 @@ QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons QFontMetrics fn(titleFont()); QSizeF sh; - if (titleText().isNull()) + if (titleText().isNull() || !titleItem()->isVisible()) return sh; switch (which) {