From 38cef2676df31e053f5b94753e9cc5d951471487 2012-05-29 14:22:36 From: sauimone Date: 2012-05-29 14:22:36 Subject: [PATCH] visible property to barseries --- diff --git a/src/barchart/barchartitem.cpp b/src/barchart/barchartitem.cpp index d4a8e45..09bab8e 100644 --- a/src/barchart/barchartitem.cpp +++ b/src/barchart/barchartitem.cpp @@ -103,6 +103,7 @@ QVector BarChartItem::calculateLayout() // Use temporary qreals for accurancy qreal categoryCount = m_series->categoryCount(); qreal setCount = m_series->barsetCount(); + bool barsVisible = m_series->isVisible(); // Domain: qreal width = geometry().width(); @@ -128,6 +129,7 @@ QVector BarChartItem::calculateLayout() layout.append(rect); bar->setPen(barSet->pen()); bar->setBrush(barSet->brush()); + bar->setVisible(barsVisible); QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index 3105078..56ce1c6 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -113,6 +113,12 @@ void QBarSeries::setBarMargin(qreal margin) d->setBarMargin(margin); } +qreal QBarSeries::barMargin() const +{ + Q_D(const QBarSeries); + return d->barMargin(); +} + /*! Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. Returns true, if appending succeeded. @@ -191,6 +197,18 @@ QBarCategories QBarSeries::categories() const return d->categories(); } +void QBarSeries::setVisible(bool visible) +{ + Q_D(QBarSeries); + d->setVisible(visible); +} + +bool QBarSeries::isVisible() const +{ + Q_D(const QBarSeries); + return d->isVisible(); +} + /*! Sets the visibility of labels in series to \a visible */ @@ -214,7 +232,8 @@ bool QBarSeries::isLabelsVisible() const QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractSeriesPrivate(q), m_barMargin(0.05), // Default value is 5% of category width - m_labelsVisible(false) + m_labelsVisible(false), + m_visible(true) { } @@ -280,7 +299,7 @@ void QBarSeriesPrivate::setBarMargin(qreal margin) emit updatedBars(); } -qreal QBarSeriesPrivate::barMargin() +qreal QBarSeriesPrivate::barMargin() const { return m_barMargin; } @@ -290,6 +309,19 @@ QBarSet* QBarSeriesPrivate::barsetAt(int index) return m_barSets.at(index); } +void QBarSeriesPrivate::setVisible(bool visible) +{ + if (m_visible != visible) { + m_visible = visible; + emit updatedBars(); + } +} + +bool QBarSeriesPrivate::isVisible() const +{ + return m_visible; +} + QString QBarSeriesPrivate::categoryName(int category) { if ((category >= 0) && (category < m_categories.count())) { diff --git a/src/barchart/qbarseries.h b/src/barchart/qbarseries.h index 06c247b..98a085c 100644 --- a/src/barchart/qbarseries.h +++ b/src/barchart/qbarseries.h @@ -44,6 +44,7 @@ public: void setCategories(QBarCategories categories); void setBarMargin(qreal margin); + qreal barMargin() const; bool append(QBarSet *set); bool remove(QBarSet *set); @@ -54,6 +55,8 @@ public: QList barSets() const; QBarCategories categories() const; + void setVisible(bool visible = true); + bool isVisible() const; void setLabelsVisible(bool visible = true); bool isLabelsVisible() const; diff --git a/src/barchart/qbarseries_p.h b/src/barchart/qbarseries_p.h index 4d260c3..1f59508 100644 --- a/src/barchart/qbarseries_p.h +++ b/src/barchart/qbarseries_p.h @@ -51,7 +51,10 @@ public: QBarCategories categories() const; void setBarMargin(qreal margin); - qreal barMargin(); + qreal barMargin() const; + + void setVisible(bool visible); + bool isVisible() const; void scaleDomain(Domain& domain); Chart* createGraphics(ChartPresenter* presenter); @@ -87,6 +90,7 @@ protected: QBarCategories m_categories; qreal m_barMargin; bool m_labelsVisible; + bool m_visible; private: Q_DECLARE_PUBLIC(QBarSeries)