summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Varanka <sami.varanka@qt.io>2021-09-23 08:52:53 +0300
committerSami Varanka <sami.varanka@qt.io>2021-09-24 12:47:37 +0300
commit333cf897359eab1eb37e1f60dd681b00e6a5d135 (patch)
tree919e7e4233b57d2d3932e7b9a1e08d2aeab8f62f
parent5502d8116ff10e755ac562aebcf00d292f9a11a4 (diff)
Add hasSeries method to Abstract3D graphHEADdev
Added a hasSeries method to Abstract3Dgraph. The method can be used to check whether a series has already been added to the graph. In addition, modified cpp and qml autotests to test the added method. Fixes: QTBUG-96683 Change-Id: I91f70ca15b6c5fbaa7691cd17bbfc2ef460c3d37 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r--src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc6
-rw-r--r--src/datavisualization/doc/src/qtdatavisualization-qml-bars3d.qdoc3
-rw-r--r--src/datavisualization/doc/src/qtdatavisualization-qml-scatter3d.qdoc2
-rw-r--r--src/datavisualization/doc/src/qtdatavisualization-qml-surface3d.qdoc2
-rw-r--r--src/datavisualization/engine/abstract3dcontroller.cpp5
-rw-r--r--src/datavisualization/engine/abstract3dcontroller_p.h1
-rw-r--r--src/datavisualization/engine/q3dbars.cpp8
-rw-r--r--src/datavisualization/engine/q3dscatter.cpp6
-rw-r--r--src/datavisualization/engine/q3dsurface.cpp6
-rw-r--r--src/datavisualization/engine/qabstract3dgraph.cpp10
-rw-r--r--src/datavisualization/engine/qabstract3dgraph.h3
-rw-r--r--src/datavisualizationqml/abstractdeclarative.cpp5
-rw-r--r--src/datavisualizationqml/abstractdeclarative_p.h2
-rw-r--r--tests/auto/cpptest/q3dbars/tst_bars.cpp10
-rw-r--r--tests/auto/cpptest/q3dscatter/tst_scatter.cpp10
-rw-r--r--tests/auto/cpptest/q3dsurface/tst_surface.cpp10
-rw-r--r--tests/auto/qmltest/bars3d/tst_bars.qml8
-rw-r--r--tests/auto/qmltest/scatter3d/tst_scatter.qml8
-rw-r--r--tests/auto/qmltest/surface3d/tst_surface.qml8
19 files changed, 109 insertions, 4 deletions
diff --git a/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc b/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc
index df2143a3..9f9dd6e1 100644
--- a/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc
+++ b/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc
@@ -190,6 +190,12 @@
*/
/*!
+ * \qmlmethod bool AbstractGraph3D::hasSeries(Abstract3DSeries series)
+ * \since 6.3
+ * Returns whether the \a series has already been added to the graph.
+ */
+
+/*!
* \qmlmethod int AbstractGraph3D::addCustomItem(Custom3DItem item)
*
* Adds a Custom3DItem \a item to the graph. Graph takes ownership of the added item.
diff --git a/src/datavisualization/doc/src/qtdatavisualization-qml-bars3d.qdoc b/src/datavisualization/doc/src/qtdatavisualization-qml-bars3d.qdoc
index 0a18a912..437f2f6f 100644
--- a/src/datavisualization/doc/src/qtdatavisualization-qml-bars3d.qdoc
+++ b/src/datavisualization/doc/src/qtdatavisualization-qml-bars3d.qdoc
@@ -164,11 +164,13 @@
* generate the row or column labels on the axes in cases where the labels are not explicitly set
* to the axes. If the newly added series has specified a selected bar, it will be highlighted and
* any existing selection will be cleared. Only one added series can have an active selection.
+ * \sa AbstractGraph3D::hasSeries()
*/
/*!
* \qmlmethod void Bars3D::removeSeries(Bar3DSeries series)
* Remove the \a series from the graph.
+ * \sa AbstractGraph3D::hasSeries()
*/
/*!
@@ -179,4 +181,5 @@
* \note When moving a series to a new \a index that is after its old index,
* the new position in list is calculated as if the series was still in its old
* index, so the final index is actually the \a index decremented by one.
+ * \sa AbstractGraph3D::hasSeries()
*/
diff --git a/src/datavisualization/doc/src/qtdatavisualization-qml-scatter3d.qdoc b/src/datavisualization/doc/src/qtdatavisualization-qml-scatter3d.qdoc
index 78350c78..8a5ce9d8 100644
--- a/src/datavisualization/doc/src/qtdatavisualization-qml-scatter3d.qdoc
+++ b/src/datavisualization/doc/src/qtdatavisualization-qml-scatter3d.qdoc
@@ -97,9 +97,11 @@
* Adds the \a series to the graph. A graph can contain multiple series, but has only one set of
* axes. If the newly added series has specified a selected item, it will be highlighted and
* any existing selection will be cleared. Only one added series can have an active selection.
+ * \sa AbstractGraph3D::hasSeries()
*/
/*!
* \qmlmethod void Scatter3D::removeSeries(Scatter3DSeries series)
* Remove the \a series from the graph.
+ * \sa AbstractGraph3D::hasSeries()
*/
diff --git a/src/datavisualization/doc/src/qtdatavisualization-qml-surface3d.qdoc b/src/datavisualization/doc/src/qtdatavisualization-qml-surface3d.qdoc
index f494edba..c3daca2a 100644
--- a/src/datavisualization/doc/src/qtdatavisualization-qml-surface3d.qdoc
+++ b/src/datavisualization/doc/src/qtdatavisualization-qml-surface3d.qdoc
@@ -108,9 +108,11 @@
/*!
* \qmlmethod void Surface3D::addSeries(Surface3DSeries series)
* Adds the \a series to the graph.
+ * \sa AbstractGraph3D::hasSeries()
*/
/*!
* \qmlmethod void Surface3D::removeSeries(Surface3DSeries series)
* Removes the \a series from the graph.
+ * \sa AbstractGraph3D::hasSeries()
*/
diff --git a/src/datavisualization/engine/abstract3dcontroller.cpp b/src/datavisualization/engine/abstract3dcontroller.cpp
index 5ed62ca9..22d39e4a 100644
--- a/src/datavisualization/engine/abstract3dcontroller.cpp
+++ b/src/datavisualization/engine/abstract3dcontroller.cpp
@@ -179,6 +179,11 @@ void Abstract3DController::removeSeries(QAbstract3DSeries *series)
}
}
+bool Abstract3DController::hasSeries(QAbstract3DSeries *series)
+{
+ return m_seriesList.contains(series);
+}
+
QList<QAbstract3DSeries *> Abstract3DController::seriesList()
{
return m_seriesList;
diff --git a/src/datavisualization/engine/abstract3dcontroller_p.h b/src/datavisualization/engine/abstract3dcontroller_p.h
index 2aee01ef..a2efbd17 100644
--- a/src/datavisualization/engine/abstract3dcontroller_p.h
+++ b/src/datavisualization/engine/abstract3dcontroller_p.h
@@ -243,6 +243,7 @@ public:
virtual void addSeries(QAbstract3DSeries *series);
virtual void insertSeries(int index, QAbstract3DSeries *series);
virtual void removeSeries(QAbstract3DSeries *series);
+ virtual bool hasSeries(QAbstract3DSeries *series);
QList<QAbstract3DSeries *> seriesList();
virtual void setAxisX(QAbstract3DAxis *axis);
diff --git a/src/datavisualization/engine/q3dbars.cpp b/src/datavisualization/engine/q3dbars.cpp
index ccc8edd5..0d0597dc 100644
--- a/src/datavisualization/engine/q3dbars.cpp
+++ b/src/datavisualization/engine/q3dbars.cpp
@@ -157,7 +157,7 @@ QBar3DSeries *Q3DBars::primarySeries() const
* to the axes. If the newly added series has specified a selected bar, it will be highlighted and
* any existing selection will be cleared. Only one added series can have an active selection.
*
- * \sa seriesList(), primarySeries
+ * \sa seriesList(), primarySeries, QAbstract3DGraph::hasSeries()
*/
void Q3DBars::addSeries(QBar3DSeries *series)
{
@@ -166,6 +166,8 @@ void Q3DBars::addSeries(QBar3DSeries *series)
/*!
* Removes the \a series from the graph.
+ *
+ * \sa QAbstract3DGraph::hasSeries()
*/
void Q3DBars::removeSeries(QBar3DSeries *series)
{
@@ -180,7 +182,7 @@ void Q3DBars::removeSeries(QBar3DSeries *series)
* the new position in list is calculated as if the series was still in its old
* index, so the final index is actually the \a index decremented by one.
*
- * \sa addSeries(), seriesList()
+ * \sa addSeries(), seriesList(), QAbstract3DGraph::hasSeries()
*/
void Q3DBars::insertSeries(int index, QBar3DSeries *series)
{
@@ -189,6 +191,8 @@ void Q3DBars::insertSeries(int index, QBar3DSeries *series)
/*!
* Returns the list of series added to this graph.
+ *
+ * \sa QAbstract3DGraph::hasSeries()
*/
QList<QBar3DSeries *> Q3DBars::seriesList() const
{
diff --git a/src/datavisualization/engine/q3dscatter.cpp b/src/datavisualization/engine/q3dscatter.cpp
index 37834322..7774c5d5 100644
--- a/src/datavisualization/engine/q3dscatter.cpp
+++ b/src/datavisualization/engine/q3dscatter.cpp
@@ -110,6 +110,8 @@ Q3DScatter::~Q3DScatter()
* Adds the \a series to the graph. A graph can contain multiple series, but has only one set of
* axes. If the newly added series has specified a selected item, it will be highlighted and
* any existing selection will be cleared. Only one added series can have an active selection.
+ *
+ * \sa QAbstract3DGraph::hasSeries()
*/
void Q3DScatter::addSeries(QScatter3DSeries *series)
{
@@ -118,6 +120,8 @@ void Q3DScatter::addSeries(QScatter3DSeries *series)
/*!
* Removes the \a series from the graph.
+ *
+ * \sa QAbstract3DGraph::hasSeries()
*/
void Q3DScatter::removeSeries(QScatter3DSeries *series)
{
@@ -126,6 +130,8 @@ void Q3DScatter::removeSeries(QScatter3DSeries *series)
/*!
* Returns the list of series added to this graph.
+ *
+ * \sa QAbstract3DGraph::hasSeries()
*/
QList<QScatter3DSeries *> Q3DScatter::seriesList() const
{
diff --git a/src/datavisualization/engine/q3dsurface.cpp b/src/datavisualization/engine/q3dsurface.cpp
index 0c3e401d..b22ff446 100644
--- a/src/datavisualization/engine/q3dsurface.cpp
+++ b/src/datavisualization/engine/q3dsurface.cpp
@@ -127,6 +127,8 @@ Q3DSurface::~Q3DSurface()
* Adds the \a series to the graph. A graph can contain multiple series, but has only one set of
* axes. If the newly added series has specified a selected item, it will be highlighted and
* any existing selection will be cleared. Only one added series can have an active selection.
+ *
+ * \sa QAbstract3DGraph::hasSeries()
*/
void Q3DSurface::addSeries(QSurface3DSeries *series)
{
@@ -135,6 +137,8 @@ void Q3DSurface::addSeries(QSurface3DSeries *series)
/*!
* Removes the \a series from the graph.
+ *
+ * \sa QAbstract3DGraph::hasSeries()
*/
void Q3DSurface::removeSeries(QSurface3DSeries *series)
{
@@ -143,6 +147,8 @@ void Q3DSurface::removeSeries(QSurface3DSeries *series)
/*!
* Returns the list of series added to this graph.
+ *
+ * \sa QAbstract3DGraph::hasSeries()
*/
QList<QSurface3DSeries *> Q3DSurface::seriesList() const
{
diff --git a/src/datavisualization/engine/qabstract3dgraph.cpp b/src/datavisualization/engine/qabstract3dgraph.cpp
index 957004f4..3110ec92 100644
--- a/src/datavisualization/engine/qabstract3dgraph.cpp
+++ b/src/datavisualization/engine/qabstract3dgraph.cpp
@@ -436,6 +436,16 @@ void QAbstract3DGraph::clearSelection()
}
/*!
+ * Returns whether the \a series has already been added to the graph.
+ *
+ * \since 6.3
+ */
+bool QAbstract3DGraph::hasSeries(QAbstract3DSeries *series)
+{
+ return d_ptr->m_visualController->hasSeries(series);
+}
+
+/*!
* Adds a QCustom3DItem \a item to the graph. Graph takes ownership of the added item.
*
* Returns the index to the added item if the add operation was successful, -1
diff --git a/src/datavisualization/engine/qabstract3dgraph.h b/src/datavisualization/engine/qabstract3dgraph.h
index fd8610fa..86e754de 100644
--- a/src/datavisualization/engine/qabstract3dgraph.h
+++ b/src/datavisualization/engine/qabstract3dgraph.h
@@ -43,6 +43,7 @@ QT_BEGIN_NAMESPACE
class QAbstract3DGraphPrivate;
class QCustom3DItem;
class QAbstract3DAxis;
+class QAbstract3DSeries;
class QT_DATAVISUALIZATION_EXPORT QAbstract3DGraph : public QWindow, protected QOpenGLFunctions
{
@@ -141,6 +142,8 @@ public:
void clearSelection();
+ virtual bool hasSeries(QAbstract3DSeries *series);
+
int addCustomItem(QCustom3DItem *item);
void removeCustomItems();
void removeCustomItem(QCustom3DItem *item);
diff --git a/src/datavisualizationqml/abstractdeclarative.cpp b/src/datavisualizationqml/abstractdeclarative.cpp
index 890ea324..e449c7d5 100644
--- a/src/datavisualizationqml/abstractdeclarative.cpp
+++ b/src/datavisualizationqml/abstractdeclarative.cpp
@@ -185,6 +185,11 @@ void AbstractDeclarative::clearSelection()
m_controller->clearSelection();
}
+bool AbstractDeclarative::hasSeries(QAbstract3DSeries *series)
+{
+ return m_controller->hasSeries(series);
+}
+
void AbstractDeclarative::setSelectionMode(SelectionFlags mode)
{
int intmode = int(mode);
diff --git a/src/datavisualizationqml/abstractdeclarative_p.h b/src/datavisualizationqml/abstractdeclarative_p.h
index 3b9d4d96..ce98c8e7 100644
--- a/src/datavisualizationqml/abstractdeclarative_p.h
+++ b/src/datavisualizationqml/abstractdeclarative_p.h
@@ -168,6 +168,8 @@ public:
Q_INVOKABLE virtual void clearSelection();
+ Q_REVISION(6, 3) Q_INVOKABLE virtual bool hasSeries(QAbstract3DSeries *series);
+
Q_REVISION(1, 1) Q_INVOKABLE virtual int addCustomItem(QCustom3DItem *item);
Q_REVISION(1, 1) Q_INVOKABLE virtual void removeCustomItems();
Q_REVISION(1, 1) Q_INVOKABLE virtual void removeCustomItem(QCustom3DItem *item);
diff --git a/tests/auto/cpptest/q3dbars/tst_bars.cpp b/tests/auto/cpptest/q3dbars/tst_bars.cpp
index 47529285..9c92cc84 100644
--- a/tests/auto/cpptest/q3dbars/tst_bars.cpp
+++ b/tests/auto/cpptest/q3dbars/tst_bars.cpp
@@ -57,6 +57,7 @@ private slots:
void selectSeries();
void removeSeries();
void removeMultipleSeries();
+ void hasSeries();
// The following tests are not required for scatter or surface, as they are handled identically
void addInputHandler();
@@ -300,6 +301,15 @@ void tst_bars::removeMultipleSeries()
delete series3;
}
+void tst_bars::hasSeries()
+{
+ QBar3DSeries *series1 = newSeries();
+ m_graph->addSeries(series1);
+ QCOMPARE(m_graph->hasSeries(series1), true);
+ QBar3DSeries *series2 = newSeries();
+ QCOMPARE(m_graph->hasSeries(series2), false);
+}
+
// The following tests are not required for scatter or surface, as they are handled identically
void tst_bars::addInputHandler()
{
diff --git a/tests/auto/cpptest/q3dscatter/tst_scatter.cpp b/tests/auto/cpptest/q3dscatter/tst_scatter.cpp
index 502c2923..cd39ab8d 100644
--- a/tests/auto/cpptest/q3dscatter/tst_scatter.cpp
+++ b/tests/auto/cpptest/q3dscatter/tst_scatter.cpp
@@ -54,6 +54,7 @@ private slots:
void selectSeries();
void removeSeries();
void removeMultipleSeries();
+ void hasSeries();
private:
Q3DScatter *m_graph;
@@ -253,5 +254,14 @@ void tst_scatter::removeMultipleSeries()
delete series3;
}
+void tst_scatter::hasSeries()
+{
+ QScatter3DSeries *series1 = newSeries();
+ m_graph->addSeries(series1);
+ QCOMPARE(m_graph->hasSeries(series1), true);
+ QScatter3DSeries *series2 = newSeries();
+ QCOMPARE(m_graph->hasSeries(series2), false);
+}
+
QTEST_MAIN(tst_scatter)
#include "tst_scatter.moc"
diff --git a/tests/auto/cpptest/q3dsurface/tst_surface.cpp b/tests/auto/cpptest/q3dsurface/tst_surface.cpp
index e0add57c..fc1068e3 100644
--- a/tests/auto/cpptest/q3dsurface/tst_surface.cpp
+++ b/tests/auto/cpptest/q3dsurface/tst_surface.cpp
@@ -54,6 +54,7 @@ private slots:
void selectSeries();
void removeSeries();
void removeMultipleSeries();
+ void hasSeries();
private:
Q3DSurface *m_graph;
@@ -263,5 +264,14 @@ void tst_surface::removeMultipleSeries()
delete series3;
}
+void tst_surface::hasSeries()
+{
+ QSurface3DSeries *series1 = newSeries();
+ m_graph->addSeries(series1);
+ QCOMPARE(m_graph->hasSeries(series1), true);
+ QSurface3DSeries *series2 = newSeries();
+ QCOMPARE(m_graph->hasSeries(series2), false);
+}
+
QTEST_MAIN(tst_surface)
#include "tst_surface.moc"
diff --git a/tests/auto/qmltest/bars3d/tst_bars.qml b/tests/auto/qmltest/bars3d/tst_bars.qml
index 349e28b2..80c1d9e4 100644
--- a/tests/auto/qmltest/bars3d/tst_bars.qml
+++ b/tests/auto/qmltest/bars3d/tst_bars.qml
@@ -89,6 +89,14 @@ Item {
compare(bars3d.selectedSeries, series1)
waitForRendering(top)
+ }
+
+ function test_6_has_series() {
+ bars3d.seriesList = [series1]
+ compare(bars3d.hasSeries(series1), true)
+ compare(bars3d.hasSeries(series2), false)
+
+ waitForRendering(top)
bars3d.destroy()
waitForRendering(top)
}
diff --git a/tests/auto/qmltest/scatter3d/tst_scatter.qml b/tests/auto/qmltest/scatter3d/tst_scatter.qml
index 9805b2e9..d871f891 100644
--- a/tests/auto/qmltest/scatter3d/tst_scatter.qml
+++ b/tests/auto/qmltest/scatter3d/tst_scatter.qml
@@ -28,7 +28,7 @@
****************************************************************************/
import QtQuick 2.0
-import QtDataVisualization 1.2
+import QtDataVisualization
import QtTest 1.0
Item {
@@ -67,5 +67,11 @@ Item {
series.seriesList[0].selectedItem = 0
compare(series.selectedSeries, series1)
}
+
+ function test_5_has_series() {
+ series.seriesList = [series1]
+ compare(series.hasSeries(series1), true)
+ compare(series.hasSeries(series2), false)
+ }
}
}
diff --git a/tests/auto/qmltest/surface3d/tst_surface.qml b/tests/auto/qmltest/surface3d/tst_surface.qml
index 2ec96007..e112295f 100644
--- a/tests/auto/qmltest/surface3d/tst_surface.qml
+++ b/tests/auto/qmltest/surface3d/tst_surface.qml
@@ -28,7 +28,7 @@
****************************************************************************/
import QtQuick 2.0
-import QtDataVisualization 1.2
+import QtDataVisualization
import QtTest 1.0
Item {
@@ -67,5 +67,11 @@ Item {
series.seriesList[0].selectedPoint = Qt.point(0, 0)
compare(series.selectedSeries, series1)
}
+
+ function test_5_has_series() {
+ series.seriesList = [series1]
+ compare(series.hasSeries(series1), true)
+ compare(series.hasSeries(series2), false)
+ }
}
}