summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@theqtcompany.com>2015-09-07 11:19:39 +0300
committerMiikka Heikkinen <miikka.heikkinen@theqtcompany.com>2015-09-07 09:35:50 +0000
commit412d1b6b2a8058f8cfbee275f3dc1f749909cd27 (patch)
treebf83c6ddfd162072cb36ad02535eae3ec1cf893b
parente373ed9f8f653cab2d86b9bab62a6f3ada27d7cf (diff)
Add QXYSeries::replace(QVector<QPointF> points) overload.
Task-number: QTRD-3384 Change-Id: Ic7dcdfeadd3f5c7ba66191f8c427a0d65796895d Reviewed-by: Titta Heikkala <titta.heikkala@theqtcompany.com>
-rw-r--r--examples/charts/qmloscilloscope/datasource.cpp7
-rw-r--r--examples/charts/qmloscilloscope/datasource.h2
-rw-r--r--src/charts/xychart/qxyseries.cpp17
-rw-r--r--src/charts/xychart/qxyseries.h1
4 files changed, 21 insertions, 6 deletions
diff --git a/examples/charts/qmloscilloscope/datasource.cpp b/examples/charts/qmloscilloscope/datasource.cpp
index a82cb08f..07005278 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<QPointF> points = m_data.at(m_index);
+ QVector<QPointF> 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<QPointF> row, m_data)
+ foreach (QVector<QPointF> row, m_data)
row.clear();
m_data.clear();
// Append the new data depending on the type
for (int i(0); i < rowCount; i++) {
- QList<QPointF> points;
+ QVector<QPointF> 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 84548e8b..85740b87 100644
--- a/examples/charts/qmloscilloscope/datasource.h
+++ b/examples/charts/qmloscilloscope/datasource.h
@@ -42,7 +42,7 @@ public slots:
private:
QQuickView *m_appViewer;
- QList<QList<QPointF> > m_data;
+ QList<QVector<QPointF> > m_data;
int m_index;
};
diff --git a/src/charts/xychart/qxyseries.cpp b/src/charts/xychart/qxyseries.cpp
index f7c47887..e97421c2 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<QPointF>} as parameter is slightly faster than using this overload.
\sa QXYSeries::pointsReplaced()
*/
void QXYSeries::replace(QList<QPointF> 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<QPointF> 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 cbb6acc2..dfd5f246 100644
--- a/src/charts/xychart/qxyseries.h
+++ b/src/charts/xychart/qxyseries.h
@@ -93,6 +93,7 @@ public:
QColor pointLabelsColor() const;
void replace(QList<QPointF> points);
+ void replace(QVector<QPointF> points);
Q_SIGNALS:
void clicked(const QPointF &point);