From 42870bd3de5c33282a166f3fae21195ccaaf8388 2015-09-11 08:36:18 From: Miikka Heikkinen Date: 2015-09-11 08:36:18 Subject: [PATCH] Add a method to remove more than one point to QXYSeries Task-number: QTRD-3688 Change-Id: Iaea85c5f07740aeaf35ff34a2c5227c5105f2f25 Reviewed-by: Titta Heikkala --- diff --git a/src/charts/xychart/qxymodelmapper.cpp b/src/charts/xychart/qxymodelmapper.cpp index ccd79cc..23ca310 100644 --- a/src/charts/xychart/qxymodelmapper.cpp +++ b/src/charts/xychart/qxymodelmapper.cpp @@ -94,6 +94,7 @@ void QXYModelMapper::setSeries(QXYSeries *series) connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int))); connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int))); connect(d->m_series, SIGNAL(destroyed()), d, SLOT(handleSeriesDestroyed())); + connect(d->m_series, SIGNAL(pointsRemoved(int,int)), d, SLOT(handlePointsRemoved(int,int))); } /*! @@ -309,6 +310,24 @@ void QXYModelMapperPrivate::handlePointRemoved(int pointPos) blockModelSignals(false); } +void QXYModelMapperPrivate::handlePointsRemoved(int pointPos, int count) +{ + if (m_seriesSignalsBlock) + return; + + m_count -= count; + + if (m_count < -1) + m_count = -1; + + blockModelSignals(); + if (m_orientation == Qt::Vertical) + m_model->removeRows(pointPos + m_first, count); + else + m_model->removeColumns(pointPos + m_first, count); + blockModelSignals(false); +} + void QXYModelMapperPrivate::handlePointReplaced(int pointPos) { if (m_seriesSignalsBlock) diff --git a/src/charts/xychart/qxymodelmapper_p.h b/src/charts/xychart/qxymodelmapper_p.h index a9f9913..4b3edbe 100644 --- a/src/charts/xychart/qxymodelmapper_p.h +++ b/src/charts/xychart/qxymodelmapper_p.h @@ -61,6 +61,7 @@ public Q_SLOTS: // for the series void handlePointAdded(int pointPos); void handlePointRemoved(int pointPos); + void handlePointsRemoved(int pointPos, int count); void handlePointReplaced(int pointPos); void handleSeriesDestroyed(); diff --git a/src/charts/xychart/qxyseries.cpp b/src/charts/xychart/qxyseries.cpp index 1ddaf85..c431f8a 100644 --- a/src/charts/xychart/qxyseries.cpp +++ b/src/charts/xychart/qxyseries.cpp @@ -111,7 +111,7 @@ QT_CHARTS_BEGIN_NAMESPACE \property QXYSeries::color The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and fill (brush) color in case of QScatterSeries or QAreaSeries. - \sa QXYSeries::pen(), QXYSeries::brush() + \sa pen(), brush() */ /*! \qmlproperty color XYSeries::color @@ -141,13 +141,13 @@ QT_CHARTS_BEGIN_NAMESPACE area, labels on the edge of the plot area are cut. If the points are close to each other the labels may overlap. - \sa QXYSeries::pointLabelsVisible, QXYSeries::pointLabelsFont, QXYSeries::pointLabelsColor + \sa pointLabelsVisible, pointLabelsFont, pointLabelsColor */ /*! \qmlproperty string XYSeries::pointLabelsFormat The \a format used for showing labels with series points. - \sa QXYSeries::pointLabelsFormat, pointLabelsVisible, pointLabelsFont, pointLabelsColor + \sa pointLabelsFormat, pointLabelsVisible, pointLabelsFont, pointLabelsColor */ /*! \fn void QXYSeries::pointLabelsFormatChanged(const QString &format) @@ -162,7 +162,7 @@ QT_CHARTS_BEGIN_NAMESPACE \property QXYSeries::pointLabelsVisible Defines the visibility for data point labels. False by default. - \sa QXYSeries::pointLabelsFormat + \sa pointLabelsFormat */ /*! \qmlproperty bool XYSeries::pointLabelsVisible @@ -183,7 +183,7 @@ QT_CHARTS_BEGIN_NAMESPACE \property QXYSeries::pointLabelsFont Defines the font used for data point labels. - \sa QXYSeries::pointLabelsFormat + \sa pointLabelsFormat */ /*! \qmlproperty font XYSeries::pointLabelsFont @@ -205,7 +205,7 @@ QT_CHARTS_BEGIN_NAMESPACE Defines the color used for data point labels. By default, the color is the color of the brush defined in theme for labels. - \sa QXYSeries::pointLabelsFormat + \sa pointLabelsFormat */ /*! \qmlproperty font XYSeries::pointLabelsColor @@ -355,6 +355,17 @@ QT_CHARTS_BEGIN_NAMESPACE */ /*! + \fn void QXYSeries::pointsRemoved(int index, int count) + Signal is emitted when a \a count of points has been removed starting at \a index. + \sa removePoints(), clear() +*/ + +/*! + \qmlsignal XYSeries::onPointsRemoved(int index, int count) + Signal is emitted when a \a count of points has been removed starting at \a index. +*/ + +/*! \fn void QXYSeries::colorChanged(QColor color) \brief Signal is emitted when the line (pen) color has changed to \a color. */ @@ -385,6 +396,16 @@ QT_CHARTS_BEGIN_NAMESPACE */ /*! + \qmlmethod XYSeries::remove(int index) + Removes a point from the series at \a index. +*/ + +/*! + \qmlmethod XYSeries::removePoints(int index, int count) + Removes \a count points from the series starting at \a index. +*/ + +/*! \qmlmethod XYSeries::insert(int index, real x, real y) Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of points. If index is the same as or bigger than count, the point is appended to the list of points. @@ -448,7 +469,7 @@ void QXYSeries::append(const QList &points) /*! Replaces data point (\a oldX, \a oldY) with data point (\a newX, \a newY). - \sa QXYSeries::pointReplaced() + \sa pointReplaced() */ void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { @@ -457,7 +478,7 @@ void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY) /*! Replaces \a oldPoint with \a newPoint. - \sa QXYSeries::pointReplaced() + \sa pointReplaced() */ void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint) { @@ -470,7 +491,7 @@ void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint) /*! Replaces the point at \a index with data point (\a newX, \a newY). - \sa QXYSeries::pointReplaced() + \sa pointReplaced() */ void QXYSeries::replace(int index, qreal newX, qreal newY) { @@ -479,7 +500,7 @@ void QXYSeries::replace(int index, qreal newX, qreal newY) /*! Replaces the point at \a index with \a newPoint. - \sa QXYSeries::pointReplaced() + \sa pointReplaced() */ void QXYSeries::replace(int index, const QPointF &newPoint) { @@ -496,7 +517,7 @@ void QXYSeries::replace(int index, const QPointF &newPoint) or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() 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() + \sa pointsReplaced() */ void QXYSeries::replace(QList points) { @@ -508,7 +529,7 @@ void QXYSeries::replace(QList 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() + \sa pointsReplaced() */ void QXYSeries::replace(QVector points) { @@ -519,6 +540,7 @@ void QXYSeries::replace(QVector points) /*! Removes the point (\a x, \a y) from the series. + \sa pointRemoved() */ void QXYSeries::remove(qreal x, qreal y) { @@ -527,6 +549,7 @@ void QXYSeries::remove(qreal x, qreal y) /*! Removes the \a point from the series. + \sa pointRemoved() */ void QXYSeries::remove(const QPointF &point) { @@ -539,6 +562,7 @@ void QXYSeries::remove(const QPointF &point) /*! Removes the point at \a index from the series. + \sa pointRemoved() */ void QXYSeries::remove(int index) { @@ -548,7 +572,23 @@ void QXYSeries::remove(int index) } /*! + Removes \a count number of points from the series starting at \a index. + \sa pointsRemoved() +*/ +void QXYSeries::removePoints(int index, int count) +{ + // This function doesn't overload remove as there is chance for it to get mixed up with + // remove(qreal, qreal) overload in some implicit casting cases. + Q_D(QXYSeries); + if (count > 0) { + d->m_points.remove(index, count); + emit pointsRemoved(index, count); + } +} + +/*! Inserts a \a point in the series at \a index position. + \sa pointAdded() */ void QXYSeries::insert(int index, const QPointF &point) { @@ -561,13 +601,13 @@ void QXYSeries::insert(int index, const QPointF &point) } /*! - Removes all points from the series. + Removes all points from the series. + \sa pointsRemoved() */ void QXYSeries::clear() { Q_D(QXYSeries); - for (int i = d->m_points.size() - 1; i >= 0; i--) - remove(d->m_points.at(i)); + removePoints(0, d->m_points.size()); } /*! diff --git a/src/charts/xychart/qxyseries.h b/src/charts/xychart/qxyseries.h index dfd5f24..ceba5de 100644 --- a/src/charts/xychart/qxyseries.h +++ b/src/charts/xychart/qxyseries.h @@ -58,6 +58,7 @@ public: void remove(qreal x, qreal y); void remove(const QPointF &point); void remove(int index); + void removePoints(int index, int count); void insert(int index, const QPointF &point); void clear(); @@ -110,6 +111,7 @@ Q_SIGNALS: void pointLabelsVisibilityChanged(bool visible); void pointLabelsFontChanged(const QFont &font); void pointLabelsColorChanged(const QColor &color); + void pointsRemoved(int index, int count); private: Q_DECLARE_PRIVATE(QXYSeries) diff --git a/src/charts/xychart/xychart.cpp b/src/charts/xychart/xychart.cpp index f867f0e..16dd707 100644 --- a/src/charts/xychart/xychart.cpp +++ b/src/charts/xychart/xychart.cpp @@ -39,6 +39,7 @@ XYChart::XYChart(QXYSeries *series, QGraphicsItem *item): QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced())); QObject::connect(series, SIGNAL(pointAdded(int)), this, SLOT(handlePointAdded(int))); QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int))); + QObject::connect(series, SIGNAL(pointsRemoved(int, int)), this, SLOT(handlePointsRemoved(int, int))); QObject::connect(this, SIGNAL(clicked(QPointF)), series, SIGNAL(clicked(QPointF))); QObject::connect(this, SIGNAL(hovered(QPointF,bool)), series, SIGNAL(hovered(QPointF,bool))); QObject::connect(this, SIGNAL(pressed(QPointF)), series, SIGNAL(pressed(QPointF))); @@ -145,6 +146,23 @@ void XYChart::handlePointRemoved(int index) updateChart(m_points, points, index); } +void XYChart::handlePointsRemoved(int index, int count) +{ + Q_ASSERT(index <= m_series->count()); + Q_ASSERT(index >= 0); + + QVector points; + + if (m_dirty || m_points.isEmpty()) { + points = domain()->calculateGeometryPoints(m_series->points()); + } else { + points = m_points; + points.remove(index, count); + } + + updateChart(m_points, points, index); +} + void XYChart::handlePointReplaced(int index) { Q_ASSERT(index < m_series->count()); diff --git a/src/charts/xychart/xychart_p.h b/src/charts/xychart/xychart_p.h index addb922..9d35c82 100644 --- a/src/charts/xychart/xychart_p.h +++ b/src/charts/xychart/xychart_p.h @@ -62,6 +62,7 @@ public: public Q_SLOTS: void handlePointAdded(int index); void handlePointRemoved(int index); + void handlePointsRemoved(int index, int count); void handlePointReplaced(int index); void handlePointsReplaced(); void handleDomainUpdated(); diff --git a/src/chartsqml2/chartsqml2_plugin.cpp b/src/chartsqml2/chartsqml2_plugin.cpp index ac36f23..f849d1a 100644 --- a/src/chartsqml2/chartsqml2_plugin.cpp +++ b/src/chartsqml2/chartsqml2_plugin.cpp @@ -306,6 +306,9 @@ public: qmlRegisterUncreatableType(uri, 2, 1, "AbstractAxis", QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead.")); qmlRegisterType(uri, 2, 1, "ChartView"); + qmlRegisterType(uri, 2, 1, "ScatterSeries"); + qmlRegisterType(uri, 2, 1, "LineSeries"); + qmlRegisterType(uri, 2, 1, "SplineSeries"); } }; diff --git a/src/chartsqml2/declarativelineseries.cpp b/src/chartsqml2/declarativelineseries.cpp index af2562d..5a07c12 100644 --- a/src/chartsqml2/declarativelineseries.cpp +++ b/src/chartsqml2/declarativelineseries.cpp @@ -32,6 +32,7 @@ DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) : connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisRadialChanged(QAbstractAxis*))); connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int))); connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int))); + connect(this, SIGNAL(pointsRemoved(int, int)), this, SLOT(handleCountChanged(int))); } void DeclarativeLineSeries::handleCountChanged(int index) diff --git a/src/chartsqml2/declarativelineseries.h b/src/chartsqml2/declarativelineseries.h index 4305d0a..6fb5823 100644 --- a/src/chartsqml2/declarativelineseries.h +++ b/src/chartsqml2/declarativelineseries.h @@ -78,6 +78,7 @@ public: Q_REVISION(3) Q_INVOKABLE void replace(int index, qreal newX, qreal newY) { DeclarativeXySeries::replace(index, newX, newY); } Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); } Q_REVISION(3) Q_INVOKABLE void remove(int index) { DeclarativeXySeries::remove(index); } + Q_REVISION(4) Q_INVOKABLE void removePoints(int index, int count) { DeclarativeXySeries::removePoints(index, count); } Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); } Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); } Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); } diff --git a/src/chartsqml2/declarativescatterseries.cpp b/src/chartsqml2/declarativescatterseries.cpp index e971ecc..468b1ee 100644 --- a/src/chartsqml2/declarativescatterseries.cpp +++ b/src/chartsqml2/declarativescatterseries.cpp @@ -32,6 +32,7 @@ DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) : connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisRadialChanged(QAbstractAxis*))); connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int))); connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int))); + connect(this, SIGNAL(pointsRemoved(int, int)), this, SLOT(handleCountChanged(int))); connect(this, SIGNAL(brushChanged()), this, SLOT(handleBrushChanged())); } diff --git a/src/chartsqml2/declarativescatterseries.h b/src/chartsqml2/declarativescatterseries.h index 7f16c5d..8fe57a8 100644 --- a/src/chartsqml2/declarativescatterseries.h +++ b/src/chartsqml2/declarativescatterseries.h @@ -78,6 +78,7 @@ public: Q_REVISION(3) Q_INVOKABLE void replace(int index, qreal newX, qreal newY) { DeclarativeXySeries::replace(index, newX, newY); } Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); } Q_REVISION(3) Q_INVOKABLE void remove(int index) { DeclarativeXySeries::remove(index); } + Q_REVISION(5) Q_INVOKABLE void removePoints(int index, int count) { DeclarativeXySeries::removePoints(index, count); } Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); } Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); } Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); } diff --git a/src/chartsqml2/declarativesplineseries.cpp b/src/chartsqml2/declarativesplineseries.cpp index dc6c17f..5066abd 100644 --- a/src/chartsqml2/declarativesplineseries.cpp +++ b/src/chartsqml2/declarativesplineseries.cpp @@ -32,6 +32,7 @@ DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) : connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisRadialChanged(QAbstractAxis*))); connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int))); connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int))); + connect(this, SIGNAL(pointsRemoved(int, int)), this, SLOT(handleCountChanged(int))); } void DeclarativeSplineSeries::handleCountChanged(int index) diff --git a/src/chartsqml2/declarativesplineseries.h b/src/chartsqml2/declarativesplineseries.h index 0bf9d00..b4a946b 100644 --- a/src/chartsqml2/declarativesplineseries.h +++ b/src/chartsqml2/declarativesplineseries.h @@ -78,6 +78,7 @@ public: Q_REVISION(3) Q_INVOKABLE void replace(int index, qreal newX, qreal newY) { DeclarativeXySeries::replace(index, newX, newY); } Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); } Q_REVISION(3) Q_INVOKABLE void remove(int index) { DeclarativeXySeries::remove(index); } + Q_REVISION(4) Q_INVOKABLE void removePoints(int index, int count) { DeclarativeXySeries::removePoints(index, count); } Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); } Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); } Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); } diff --git a/src/chartsqml2/declarativexyseries.cpp b/src/chartsqml2/declarativexyseries.cpp index f9088b6..79f096f 100644 --- a/src/chartsqml2/declarativexyseries.cpp +++ b/src/chartsqml2/declarativexyseries.cpp @@ -90,6 +90,13 @@ void DeclarativeXySeries::remove(int index) series->remove(index); } +void DeclarativeXySeries::removePoints(int index, int count) +{ + QXYSeries *series = qobject_cast(xySeries()); + Q_ASSERT(series); + series->removePoints(index, count); +} + void DeclarativeXySeries::insert(int index, qreal x, qreal y) { QXYSeries *series = qobject_cast(xySeries()); diff --git a/src/chartsqml2/declarativexyseries.h b/src/chartsqml2/declarativexyseries.h index c26e3a3..38eee13 100644 --- a/src/chartsqml2/declarativexyseries.h +++ b/src/chartsqml2/declarativexyseries.h @@ -42,6 +42,7 @@ public: void replace(int index, qreal newX, qreal newY); void remove(qreal x, qreal y); void remove(int index); + void removePoints(int index, int count); void insert(int index, qreal x, qreal y); void clear(); QPointF at(int index); diff --git a/tests/auto/qml-qtquicktest/tst_xyseries.qml b/tests/auto/qml-qtquicktest/tst_xyseries.qml index 21729ed..0f70804 100644 --- a/tests/auto/qml-qtquicktest/tst_xyseries.qml +++ b/tests/auto/qml-qtquicktest/tst_xyseries.qml @@ -18,7 +18,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtCharts 2.0 +import QtCharts 2.1 Rectangle { width: 400 @@ -133,6 +133,36 @@ Rectangle { compare(lineSeriesPointRemovedSpy.count, count); compare(splineSeriesPointRemovedSpy.count, count); compare(scatterSeriesPointRemovedSpy.count, count); + + lineSeriesPointRemovedSpy.clear(); + splineSeriesPointRemovedSpy.clear(); + scatterSeriesPointRemovedSpy.clear(); + lineSeriesPointsRemovedSpy.clear(); + splineSeriesPointsRemovedSpy.clear(); + scatterSeriesPointsRemovedSpy.clear(); + + count = append(); + lineSeries.removePoints(2, count - 2); + splineSeries.removePoints(2, count - 2); + scatterSeries.removePoints(2, count - 2); + + compare(lineSeries.count, 2); + compare(splineSeries.count, 2); + compare(scatterSeries.count, 2); + + lineSeries.removePoints(0, 2); + splineSeries.removePoints(0, 2); + scatterSeries.removePoints(0, 2); + + compare(lineSeries.count, 0); + compare(splineSeries.count, 0); + compare(scatterSeries.count, 0); + compare(lineSeriesPointRemovedSpy.count, 0); + compare(splineSeriesPointRemovedSpy.count, 0); + compare(scatterSeriesPointRemovedSpy.count, 0); + compare(lineSeriesPointsRemovedSpy.count, 2); + compare(splineSeriesPointsRemovedSpy.count, 2); + compare(scatterSeriesPointsRemovedSpy.count, 2); } // Not a test function, called from test functions @@ -191,6 +221,12 @@ Rectangle { target: lineSeries signalName: "pointRemoved" } + + SignalSpy { + id: lineSeriesPointsRemovedSpy + target: lineSeries + signalName: "pointsRemoved" + } } AreaSeries { @@ -226,6 +262,12 @@ Rectangle { target: splineSeries signalName: "pointRemoved" } + + SignalSpy { + id: splineSeriesPointsRemovedSpy + target: splineSeries + signalName: "pointsRemoved" + } } ScatterSeries { @@ -255,6 +297,12 @@ Rectangle { target: scatterSeries signalName: "pointRemoved" } + + SignalSpy { + id: scatterSeriesPointsRemovedSpy + target: scatterSeries + signalName: "pointsRemoved" + } } } } diff --git a/tests/auto/qml-qtquicktest/tst_xyseries_2_0.qml b/tests/auto/qml-qtquicktest/tst_xyseries_2_0.qml new file mode 100644 index 0000000..21729ed --- /dev/null +++ b/tests/auto/qml-qtquicktest/tst_xyseries_2_0.qml @@ -0,0 +1,260 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd +** All rights reserved. +** For any questions to The Qt Company, please use contact form at http://qt.io +** +** This file is part of the Qt Charts module. +** +** Licensees holding valid commercial license for Qt may use this file in +** accordance with the Qt License Agreement provided with the Software +** or, alternatively, in accordance with the terms contained in a written +** agreement between you and The Qt Company. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.io +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtCharts 2.0 + +Rectangle { + width: 400 + height: 300 + + TestCase { + id: tc1 + name: "tst_qml-qtquicktest XY Series" + when: windowShown + + function test_properties() { + verify(lineSeries.color != undefined); + compare(lineSeries.pointsVisible, false); + compare(lineSeries.capStyle, Qt.SquareCap); + compare(lineSeries.style, Qt.SolidLine); + compare(lineSeries.width, 2.0); + + verify(splineSeries.color != undefined); + compare(splineSeries.pointsVisible, false); + compare(splineSeries.capStyle, Qt.SquareCap); + compare(splineSeries.style, Qt.SolidLine); + compare(splineSeries.width, 2.0); + + verify(scatterSeries.color != undefined); + verify(scatterSeries.borderColor != undefined); + compare(scatterSeries.borderWidth, 2.0); + compare(scatterSeries.markerShape, ScatterSeries.MarkerShapeCircle); + compare(scatterSeries.markerSize, 15.0); + compare(scatterSeries.brushFilename, ""); + + verify(areaSeries.color != undefined); + verify(areaSeries.borderColor != undefined); + compare(areaSeries.borderWidth, 2.0); + compare(areaSeries.brushFilename, ""); + } + + function test_axes() { + // Axis initialization + compare(chartView.axisX(), lineSeries.axisX); + compare(chartView.axisY(), lineSeries.axisY); + compare(lineSeries.axisX, splineSeries.axisX); + compare(lineSeries.axisY, splineSeries.axisY); + compare(lineSeries.axisX, areaSeries.axisX); + compare(lineSeries.axisY, areaSeries.axisY); + } + + function test_append() { + lineSeriesPointAddedSpy.clear(); + splineSeriesPointAddedSpy.clear(); + scatterSeriesPointAddedSpy.clear(); + var count = append(); + compare(lineSeries.count, count); + compare(splineSeries.count, count); + compare(scatterSeries.count, count); + compare(lineSeriesPointAddedSpy.count, count); + compare(splineSeriesPointAddedSpy.count, count); + compare(scatterSeriesPointAddedSpy.count, count); + clear(); + compare(lineSeries.count, 0); + compare(splineSeries.count, 0); + compare(scatterSeries.count, 0); + } + + function test_replace() { + var count = append(); + for (var i = 0; i < count; i++) { + lineSeries.replace(lineSeries.at(i).x, lineSeries.at(i).y, i, Math.random()); + splineSeries.replace(splineSeries.at(i).x, splineSeries.at(i).y, i, Math.random()); + scatterSeries.replace(scatterSeries.at(i).x, scatterSeries.at(i).y, i, Math.random()); + } + compare(lineSeries.count, count); + compare(splineSeries.count, count); + compare(scatterSeries.count, count); + compare(lineSeriesPointReplacedSpy.count, count); + compare(splineSeriesPointReplacedSpy.count, count); + compare(scatterSeriesPointReplacedSpy.count, count); + clear(); + } + + function test_insert() { + var count = append(); + lineSeriesPointAddedSpy.clear(); + splineSeriesPointAddedSpy.clear(); + scatterSeriesPointAddedSpy.clear(); + for (var i = 0; i < count; i++) { + lineSeries.insert(i * 2, i, Math.random()); + splineSeries.insert(i * 2, i, Math.random()); + scatterSeries.insert(i * 2, i, Math.random()); + } + compare(lineSeries.count, count * 2); + compare(splineSeries.count, count * 2); + compare(scatterSeries.count, count * 2); + compare(lineSeriesPointAddedSpy.count, count); + compare(splineSeriesPointAddedSpy.count, count); + compare(scatterSeriesPointAddedSpy.count, count); + clear(); + } + + function test_remove() { + lineSeriesPointRemovedSpy.clear(); + splineSeriesPointRemovedSpy.clear(); + scatterSeriesPointRemovedSpy.clear(); + var count = append(); + for (var i = 0; i < count; i++) { + lineSeries.remove(lineSeries.at(0).x, lineSeries.at(0).y); + splineSeries.remove(splineSeries.at(0).x, splineSeries.at(0).y); + scatterSeries.remove(scatterSeries.at(0).x, scatterSeries.at(0).y); + } + compare(lineSeries.count, 0); + compare(splineSeries.count, 0); + compare(scatterSeries.count, 0); + compare(lineSeriesPointRemovedSpy.count, count); + compare(splineSeriesPointRemovedSpy.count, count); + compare(scatterSeriesPointRemovedSpy.count, count); + } + + // Not a test function, called from test functions + function append() { + var count = 100; + chartView.axisX().min = 0; + chartView.axisX().max = 100; + chartView.axisY().min = 0; + chartView.axisY().max = 1; + + for (var i = 0; i < count; i++) { + lineSeries.append(i, Math.random()); + splineSeries.append(i, Math.random()); + scatterSeries.append(i, Math.random()); + } + + return count; + } + + // Not a test function, called from test functions + function clear() { + lineSeries.clear(); + splineSeries.clear(); + scatterSeries.clear(); + } + } + + ChartView { + id: chartView + anchors.fill: parent + + LineSeries { + id: lineSeries + name: "line" + + SignalSpy { + id: lineSeriesPointAddedSpy + target: lineSeries + signalName: "pointAdded" + } + + SignalSpy { + id: lineSeriesPointReplacedSpy + target: lineSeries + signalName: "pointReplaced" + } + + SignalSpy { + id: lineSeriesPointsReplacedSpy + target: lineSeries + signalName: "pointsReplaced" + } + + SignalSpy { + id: lineSeriesPointRemovedSpy + target: lineSeries + signalName: "pointRemoved" + } + } + + AreaSeries { + id: areaSeries + name: "area" + upperSeries: lineSeries + } + + SplineSeries { + id: splineSeries + name: "spline" + + SignalSpy { + id: splineSeriesPointAddedSpy + target: splineSeries + signalName: "pointAdded" + } + + SignalSpy { + id: splineSeriesPointReplacedSpy + target: splineSeries + signalName: "pointReplaced" + } + + SignalSpy { + id: splineSeriesPointsReplacedSpy + target: splineSeries + signalName: "pointsReplaced" + } + + SignalSpy { + id: splineSeriesPointRemovedSpy + target: splineSeries + signalName: "pointRemoved" + } + } + + ScatterSeries { + id: scatterSeries + name: "scatter" + + SignalSpy { + id: scatterSeriesPointAddedSpy + target: scatterSeries + signalName: "pointAdded" + } + + SignalSpy { + id: scatterSeriesPointReplacedSpy + target: scatterSeries + signalName: "pointReplaced" + } + + SignalSpy { + id: scatterSeriesPointsReplacedSpy + target: scatterSeries + signalName: "pointsReplaced" + } + + SignalSpy { + id: scatterSeriesPointRemovedSpy + target: scatterSeries + signalName: "pointRemoved" + } + } + } +} diff --git a/tests/auto/qml/tst_qml.cpp b/tests/auto/qml/tst_qml.cpp index 559d80e..cb2da41 100644 --- a/tests/auto/qml/tst_qml.cpp +++ b/tests/auto/qml/tst_qml.cpp @@ -176,7 +176,10 @@ void tst_qml::checkPlugin_data() QTest::newRow("BoxPlotSeries_2_0") << imports_2_0() + "BoxPlotSeries{}"; QTest::newRow("BoxSet_2_0") << imports_2_0() + "BoxSet{}"; - QTest::newRow("CategoryAxis") << imports_2_1() + "CategoryAxis{}"; + QTest::newRow("CategoryAxis_2_1") << imports_2_1() + "CategoryAxis{}"; + QTest::newRow("ScatterSeries_2_1") << imports_2_1() + "ScatterSeries{}"; + QTest::newRow("LineSeries_2_1") << imports_2_1() + "LineSeries{}"; + QTest::newRow("SplineSeries_2_1") << imports_2_1() + "SplineSeries{}"; } void tst_qml::checkPlugin() diff --git a/tests/auto/qxymodelmapper/tst_qxymodelmapper.cpp b/tests/auto/qxymodelmapper/tst_qxymodelmapper.cpp index e23d7a1..33fbeb6 100644 --- a/tests/auto/qxymodelmapper/tst_qxymodelmapper.cpp +++ b/tests/auto/qxymodelmapper/tst_qxymodelmapper.cpp @@ -329,6 +329,10 @@ void tst_qxymodelmapper::seriesUpdated() QCOMPARE(m_series->count(), m_modelRowCount); QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model + m_series->removePoints(1, m_modelRowCount - 4); + QCOMPARE(m_series->count(), 4); + QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model + m_series->replace(m_series->points().first(), QPointF(25.0, 75.0)); QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 25.0); QCOMPARE(m_model->data(m_model->index(0, 1)).toReal(), 75.0); diff --git a/tests/auto/qxyseries/tst_qxyseries.cpp b/tests/auto/qxyseries/tst_qxyseries.cpp index c96424e..337bc4e 100644 --- a/tests/auto/qxyseries/tst_qxyseries.cpp +++ b/tests/auto/qxyseries/tst_qxyseries.cpp @@ -316,6 +316,16 @@ void tst_QXYSeries::remove_raw() QCOMPARE(m_series->points().count(), i); } QCOMPARE(m_series->points().count(), 0); + + // Multiple removal using index + for (int i = 0; i < 10; i++) + bunchOfPoints.append(QPointF(i, (qreal) rand() / (qreal) RAND_MAX)); + m_series->replace(bunchOfPoints); + m_series->removePoints(5, 2); + m_series->removePoints(0, 3); + QCOMPARE(m_series->points().count(), (bunchOfPoints.count() - 5)); + m_series->removePoints(0, (bunchOfPoints.count() - 5)); + QCOMPARE(m_series->points().count(), 0); } void tst_QXYSeries::remove_chart_data() diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml index 1434f37..a6390cb 100644 --- a/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml @@ -111,6 +111,16 @@ Flow { onClicked: series.remove(series.count - 1); } Button { + text: "remove points" + onClicked: { + var count = 3; + if (series.count < 3) + count = series.count + var index = series.count - count; + series.removePoints(index, count); + } + } + Button { text: "insert point" onClicked: series.insert(series.count - 2, series.count - 2, series.count - 2); } diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/ScatterEditor.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ScatterEditor.qml index 19160a2..ce95cf5 100644 --- a/tests/manual/qmlchartproperties/qml/qmlchartproperties/ScatterEditor.qml +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ScatterEditor.qml @@ -106,6 +106,16 @@ Flow { onClicked: series.remove(series.count - 1); } Button { + text: "remove points" + onClicked: { + var count = 3; + if (series.count < 3) + count = series.count + var index = series.count - count; + series.removePoints(index, count); + } + } + Button { text: "insert point" onClicked: series.insert(series.count - 2, series.count - 2, series.count - 2); }