diff --git a/example/scatter/main.cpp b/example/scatter/main.cpp index 6483000..ef2a47d 100644 --- a/example/scatter/main.cpp +++ b/example/scatter/main.cpp @@ -20,13 +20,15 @@ int main(int argc, char *argv[]) // Chart takes ownership chartView->addSeries(scatter); //! [1] +// scatter->replace(0, QPointF(0.75, 5.0)); // And more //! [3] *scatter << QPointF(2.0, 5.5) << QPointF(2.2, 5.4); //! [3] - // Add another scatter series (re-use the previous pointer) + // Add another scatter series (re-use the previous pointer because the code used as snippets + // in the docs) // - more data with random component scatter = new QScatterSeries(); for (qreal i(0.0); i < 20; i += 0.15) { diff --git a/src/scatterseries/qscatterseries.cpp b/src/scatterseries/qscatterseries.cpp index 1487be4..6d354dd 100644 --- a/src/scatterseries/qscatterseries.cpp +++ b/src/scatterseries/qscatterseries.cpp @@ -144,13 +144,27 @@ QList QScatterSeries::data() } /*! - Remove the data point at \a pointIndex. Returns true if a point was removed, false if the point - at \a pointIndex does not exist on the series. + Replaces the point at \a index with \a newPoint. Returns true if \a index is a valid position + in the series data, false otherwise. */ -bool QScatterSeries::removeAt(int pointIndex) +bool QScatterSeries::replace(int index, QPointF newPoint) { - if (pointIndex >=0 && pointIndex < d->m_data.count()) { - d->m_data.removeAt(pointIndex); + if (index >= 0 && index < d->m_data.count()) { + d->m_data.replace(index, newPoint); + emit changed(); + return true; + } + return false; +} + +/*! + Remove the data point at \a index. Returns true if a point was removed, false if the point + at \a index does not exist on the series. +*/ +bool QScatterSeries::removeAt(int index) +{ + if (index >=0 && index < d->m_data.count()) { + d->m_data.removeAt(index); emit changed(); return true; } diff --git a/src/scatterseries/qscatterseries.h b/src/scatterseries/qscatterseries.h index e3dd7b8..2c7ebf6 100644 --- a/src/scatterseries/qscatterseries.h +++ b/src/scatterseries/qscatterseries.h @@ -40,7 +40,8 @@ public: QScatterSeries& operator << (const QPointF &value); QScatterSeries& operator << (QList points); QList data(); - bool removeAt(int pointIndex); + bool replace(int index, QPointF newPoint); + bool removeAt(int index); int removeAll(QPointF point); void clear(); int closestPoint(QPointF coordinate);