diff --git a/examples/charts/qmloscilloscope/datasource.cpp b/examples/charts/qmloscilloscope/datasource.cpp index a82cb08..0700527 100644 --- a/examples/charts/qmloscilloscope/datasource.cpp +++ b/examples/charts/qmloscilloscope/datasource.cpp @@ -48,7 +48,7 @@ void DataSource::update(QAbstractSeries *series) if (m_index > m_data.count() - 1) m_index = 0; - QList points = m_data.at(m_index); + QVector points = m_data.at(m_index); // Use replace instead of clear + append, it's optimized for performance xySeries->replace(points); } @@ -57,13 +57,14 @@ void DataSource::update(QAbstractSeries *series) void DataSource::generateData(int type, int rowCount, int colCount) { // Remove previous data - foreach (QList row, m_data) + foreach (QVector row, m_data) row.clear(); m_data.clear(); // Append the new data depending on the type for (int i(0); i < rowCount; i++) { - QList points; + QVector points; + points.reserve(colCount); for (int j(0); j < colCount; j++) { qreal x(0); qreal y(0); diff --git a/examples/charts/qmloscilloscope/datasource.h b/examples/charts/qmloscilloscope/datasource.h index 84548e8..85740b8 100644 --- a/examples/charts/qmloscilloscope/datasource.h +++ b/examples/charts/qmloscilloscope/datasource.h @@ -42,7 +42,7 @@ public slots: private: QQuickView *m_appViewer; - QList > m_data; + QList > m_data; int m_index; }; diff --git a/src/charts/xychart/qxyseries.cpp b/src/charts/xychart/qxyseries.cpp index f7c4788..e97421c 100644 --- a/src/charts/xychart/qxyseries.cpp +++ b/src/charts/xychart/qxyseries.cpp @@ -494,13 +494,26 @@ void QXYSeries::replace(int index, const QPointF &newPoint) Replaces the current points with \a points. \note This is much faster than replacing data points one by one, or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() - when the points have been replaced. + when the points have been replaced. However, note that using the overload that takes + \c{QVector} as parameter is slightly faster than using this overload. \sa QXYSeries::pointsReplaced() */ void QXYSeries::replace(QList points) { + replace(points.toVector()); +} + +/*! + Replaces the current points with \a points. + \note This is much faster than replacing data points one by one, + or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() + when the points have been replaced. + \sa QXYSeries::pointsReplaced() +*/ +void QXYSeries::replace(QVector points) +{ Q_D(QXYSeries); - d->m_points = points.toVector(); + d->m_points = points; emit pointsReplaced(); } diff --git a/src/charts/xychart/qxyseries.h b/src/charts/xychart/qxyseries.h index cbb6acc..dfd5f24 100644 --- a/src/charts/xychart/qxyseries.h +++ b/src/charts/xychart/qxyseries.h @@ -93,6 +93,7 @@ public: QColor pointLabelsColor() const; void replace(QList points); + void replace(QVector points); Q_SIGNALS: void clicked(const QPointF &point);