diff --git a/doc/src/classes.qdoc b/doc/src/classes.qdoc index d7efe3c..b992ba2 100644 --- a/doc/src/classes.qdoc +++ b/doc/src/classes.qdoc @@ -25,7 +25,7 @@ series->add(0, 6); series->add(2, 4); ... - chartView->addSeries(series); + chart->addSeries(series); \endcode \raw HTML diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index b920512..e79e456 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -88,7 +88,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE This signal is emitted when labels visibility have changed. - \sa labelsVisible(), setLabelsVisible() + \sa isLabelsVisible(), setLabelsVisible() */ /*! @@ -225,6 +225,23 @@ bool QBarSeries::remove(QList sets) } /*! + Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. + Returns true, if inserting succeeded. + +*/ +bool QBarSeries::insert(int index, QBarSet *set) +{ + Q_D(QBarSeries); + bool success = d->insert(index, set); + if (success) { + QList sets; + sets.append(set); + emit barsetsAdded(sets); + } + return success; +} + +/*! Removes all of the bar sets from the series */ void QBarSeries::clear() @@ -266,7 +283,7 @@ void QBarSeries::setLabelsVisible(bool visible) /*! Returns the visibility of labels */ -bool QBarSeries::labelsVisible() const +bool QBarSeries::isLabelsVisible() const { Q_D(const QBarSeries); return d->m_labelsVisible; @@ -610,6 +627,23 @@ bool QBarSeriesPrivate::remove(QList sets) return true; } +bool QBarSeriesPrivate::insert(int index, QBarSet *set) +{ + Q_Q(QBarSeries); + if ((m_barSets.contains(set)) || (set == 0)) { + // Fail if set is already in list or set is null. + return false; + } + m_barSets.insert(index, set); + QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); + QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); + if (m_dataset) { + m_dataset->updateSeries(q); // this notifies legend + } + emit restructuredBars(); // this notifies barchartitem + return true; +} + #include "moc_qbarseries.cpp" #include "moc_qbarseries_p.cpp" diff --git a/src/barchart/qbarseries.h b/src/barchart/qbarseries.h index 2ec17cf..6df40fe 100644 --- a/src/barchart/qbarseries.h +++ b/src/barchart/qbarseries.h @@ -35,7 +35,7 @@ class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries Q_OBJECT Q_PROPERTY(qreal barMargin READ barMargin WRITE setBarMargin) Q_PROPERTY(int count READ barsetCount) - Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible) + Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible) public: explicit QBarSeries(QObject *parent = 0); @@ -50,12 +50,13 @@ public: bool remove(QBarSet *set); bool append(QList sets); bool remove(QList sets); + bool insert(int index, QBarSet *set); int barsetCount() const; QList barSets() const; void clear(); void setLabelsVisible(bool visible = true); - bool labelsVisible() const; + bool isLabelsVisible() const; protected: explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0); diff --git a/src/barchart/qbarseries_p.h b/src/barchart/qbarseries_p.h index a9926a4..9fa2c84 100644 --- a/src/barchart/qbarseries_p.h +++ b/src/barchart/qbarseries_p.h @@ -65,6 +65,7 @@ public: bool remove(QBarSet *set); bool append(QList sets); bool remove(QList sets); + bool insert(int index, QBarSet *set); QBarSet* barsetAt(int index); QString categoryName(int category);