summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSakaria Pouke <[email protected]>2025-05-27 16:30:25 +0300
committerSami Varanka <[email protected]>2025-05-30 16:50:09 +0000
commit65f74386ef747a1ac6c0d223191cc20aa2feb718 (patch)
treead8cfcea0ba39b74aea0126d3f831ca134fe37f4 /tests
parentc1ccb5b83439203dcebe093ebb475d642d5b2973 (diff)
Add scale to scatter itemHEADdev
Also update ItemModelScatterDataProxy and ScatterItemModelHandler. Added manual test for vector fields. Fixes: QTBUG-134242 Task-number: QTBUG-134558 Change-Id: Ie4f128419ea176d1b8e0f8e874f447ce7fb35b39 Reviewed-by: Sami Varanka <[email protected]>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/cpptest/qgscatter-modelproxy/tst_proxy.cpp19
-rw-r--r--tests/auto/qmltest/scatter3d/tst_proxy.qml36
-rw-r--r--tests/manual/CMakeLists.txt1
-rw-r--r--tests/manual/qmlvectorfield/CMakeLists.txt30
-rw-r--r--tests/manual/qmlvectorfield/main.cpp34
-rw-r--r--tests/manual/qmlvectorfield/qml/qmlvectorfield/main.qml113
6 files changed, 232 insertions, 1 deletions
diff --git a/tests/auto/cpptest/qgscatter-modelproxy/tst_proxy.cpp b/tests/auto/cpptest/qgscatter-modelproxy/tst_proxy.cpp
index 811aef55..b9aee104 100644
--- a/tests/auto/cpptest/qgscatter-modelproxy/tst_proxy.cpp
+++ b/tests/auto/cpptest/qgscatter-modelproxy/tst_proxy.cpp
@@ -75,10 +75,11 @@ void tst_proxy::construct()
QCOMPARE(proxy->yPosRole(), QString("y"));
QCOMPARE(proxy->zPosRole(), QString("z"));
QCOMPARE(proxy->rotationRole(), QString(""));
+ QCOMPARE(proxy->scaleRole(), QString(""));
delete proxy;
delete series;
- proxy = new QItemModelScatterDataProxy(table->model(), "x", "y", "z", "rot");
+ proxy = new QItemModelScatterDataProxy(table->model(), "x", "y", "z", "rot", "scale");
series = new QScatter3DSeries(proxy);
QVERIFY(proxy);
QVERIFY(series);
@@ -86,6 +87,7 @@ void tst_proxy::construct()
QCOMPARE(proxy->yPosRole(), QString("y"));
QCOMPARE(proxy->zPosRole(), QString("z"));
QCOMPARE(proxy->rotationRole(), QString("rot"));
+ QCOMPARE(proxy->scaleRole(), QString("scale"));
delete proxy;
delete series;
}
@@ -99,6 +101,9 @@ void tst_proxy::initialProperties()
QCOMPARE(m_proxy->rotationRole(), QString());
QCOMPARE(m_proxy->rotationRolePattern(), QRegularExpression());
QCOMPARE(m_proxy->rotationRoleReplace(), QString());
+ QCOMPARE(m_proxy->scaleRole(), QString());
+ QCOMPARE(m_proxy->scaleRolePattern(), QRegularExpression());
+ QCOMPARE(m_proxy->scaleRoleReplace(), QString());
QCOMPARE(m_proxy->xPosRole(), QString());
QCOMPARE(m_proxy->xPosRolePattern(), QRegularExpression());
QCOMPARE(m_proxy->xPosRoleReplace(), QString());
@@ -124,14 +129,17 @@ void tst_proxy::initializeProperties()
QSignalSpy yPosRoleSpy(m_proxy, &QItemModelScatterDataProxy::yPosRoleChanged);
QSignalSpy zPosRoleSpy(m_proxy, &QItemModelScatterDataProxy::zPosRoleChanged);
QSignalSpy rotationRoleSpy(m_proxy, &QItemModelScatterDataProxy::rotationRoleChanged);
+ QSignalSpy scaleRoleSpy(m_proxy, &QItemModelScatterDataProxy::scaleRoleChanged);
QSignalSpy xPosRolePatternSpy(m_proxy, &QItemModelScatterDataProxy::xPosRolePatternChanged);
QSignalSpy yPosRolePatternSpy(m_proxy, &QItemModelScatterDataProxy::yPosRolePatternChanged);
QSignalSpy zPosRolePatternSpy(m_proxy, &QItemModelScatterDataProxy::zPosRolePatternChanged);
QSignalSpy rotationRolePatternSpy(m_proxy, &QItemModelScatterDataProxy::rotationRolePatternChanged);
+ QSignalSpy scaleRolePatternSpy(m_proxy, &QItemModelScatterDataProxy::scaleRolePatternChanged);
QSignalSpy xPosRoleReplaceSpy(m_proxy, &QItemModelScatterDataProxy::xPosRoleReplaceChanged);
QSignalSpy yPosRoleReplaceSpy(m_proxy, &QItemModelScatterDataProxy::yPosRoleReplaceChanged);
QSignalSpy zPosRoleReplaceSpy(m_proxy, &QItemModelScatterDataProxy::zPosRoleReplaceChanged);
QSignalSpy rotationRoleReplaceSpy(m_proxy, &QItemModelScatterDataProxy::rotationRoleReplaceChanged);
+ QSignalSpy scaleRoleReplaceSpy(m_proxy, &QItemModelScatterDataProxy::scaleRoleReplaceChanged);
QTableWidget table;
@@ -139,6 +147,9 @@ void tst_proxy::initializeProperties()
m_proxy->setRotationRole("rotation");
m_proxy->setRotationRolePattern(QRegularExpression("/-/"));
m_proxy->setRotationRoleReplace("\\\\1");
+ m_proxy->setScaleRole("scale");
+ m_proxy->setScaleRolePattern(QRegularExpression("/-/"));
+ m_proxy->setScaleRoleReplace("\\\\1");
m_proxy->setXPosRole("X");
m_proxy->setXPosRolePattern(QRegularExpression("/-/"));
m_proxy->setXPosRoleReplace("\\\\1");
@@ -153,6 +164,9 @@ void tst_proxy::initializeProperties()
QCOMPARE(m_proxy->rotationRole(), QString("rotation"));
QCOMPARE(m_proxy->rotationRolePattern(), QRegularExpression("/-/"));
QCOMPARE(m_proxy->rotationRoleReplace(), QString("\\\\1"));
+ QCOMPARE(m_proxy->scaleRole(), QString("scale"));
+ QCOMPARE(m_proxy->scaleRolePattern(), QRegularExpression("/-/"));
+ QCOMPARE(m_proxy->scaleRoleReplace(), QString("\\\\1"));
QCOMPARE(m_proxy->xPosRole(), QString("X"));
QCOMPARE(m_proxy->xPosRolePattern(), QRegularExpression("/-/"));
QCOMPARE(m_proxy->xPosRoleReplace(), QString("\\\\1"));
@@ -168,14 +182,17 @@ void tst_proxy::initializeProperties()
QCOMPARE(yPosRoleSpy.size(), 1);
QCOMPARE(zPosRoleSpy.size(), 1);
QCOMPARE(rotationRoleSpy.size(), 1);
+ QCOMPARE(scaleRoleSpy.size(), 1);
QCOMPARE(xPosRolePatternSpy.size(), 1);
QCOMPARE(yPosRolePatternSpy.size(), 1);
QCOMPARE(zPosRolePatternSpy.size(), 1);
QCOMPARE(rotationRolePatternSpy.size(), 1);
+ QCOMPARE(scaleRolePatternSpy.size(), 1);
QCOMPARE(xPosRoleReplaceSpy.size(), 1);
QCOMPARE(yPosRoleReplaceSpy.size(), 1);
QCOMPARE(zPosRoleReplaceSpy.size(), 1);
QCOMPARE(rotationRoleReplaceSpy.size(), 1);
+ QCOMPARE(scaleRoleReplaceSpy.size(), 1);
}
void tst_proxy::addModel()
diff --git a/tests/auto/qmltest/scatter3d/tst_proxy.qml b/tests/auto/qmltest/scatter3d/tst_proxy.qml
index abea0404..9e861187 100644
--- a/tests/auto/qmltest/scatter3d/tst_proxy.qml
+++ b/tests/auto/qmltest/scatter3d/tst_proxy.qml
@@ -24,6 +24,9 @@ Item {
rotationRole: "rot"
rotationRolePattern: /-/
rotationRoleReplace: "\\1"
+ scaleRole: "scale"
+ scaleRolePattern: /-/
+ scaleRoleReplace: "\\1"
xPosRole: "x"
xPosRolePattern: /^.*-(\d\d)$/
xPosRoleReplace: "\\1"
@@ -50,6 +53,9 @@ Item {
compare(initial.rotationRole, "")
verify(initial.rotationRolePattern)
compare(initial.rotationRoleReplace, "")
+ compare(initial.scaleRole, "")
+ verify(initial.scaleRolePattern)
+ compare(initial.scaleRoleReplace, "")
compare(initial.xPosRole, "")
verify(initial.xPosRolePattern)
compare(initial.xPosRoleReplace, "")
@@ -75,6 +81,9 @@ Item {
compare(initialized.rotationRole, "rot")
compare(initialized.rotationRolePattern, /-/)
compare(initialized.rotationRoleReplace, "\\1")
+ compare(initialized.scaleRole, "scale")
+ compare(initialized.scaleRolePattern, /-/)
+ compare(initialized.scaleRoleReplace, "\\1")
compare(initialized.xPosRole, "x")
compare(initialized.xPosRolePattern, /^.*-(\d\d)$/)
compare(initialized.xPosRoleReplace, "\\1")
@@ -97,6 +106,9 @@ Item {
change.rotationRole = "rot"
change.rotationRolePattern = /-/
change.rotationRoleReplace = "\\1"
+ change.scaleRole = "scale"
+ change.scaleRolePattern = /-/
+ change.scaleRoleReplace = "\\1"
change.xPosRole = "x"
change.xPosRolePattern = /^.*-(\d\d)$/
change.xPosRoleReplace = "\\1"
@@ -111,6 +123,9 @@ Item {
compare(change.rotationRole, "rot")
compare(change.rotationRolePattern, /-/)
compare(change.rotationRoleReplace, "\\1")
+ compare(change.scaleRole, "scale")
+ compare(change.scaleRolePattern, /-/)
+ compare(change.scaleRoleReplace, "\\1")
compare(change.xPosRole, "x")
compare(change.xPosRolePattern, /^.*-(\d\d)$/)
compare(change.xPosRoleReplace, "\\1")
@@ -126,6 +141,9 @@ Item {
compare(rotationRoleSpy.count, 1)
compare(rotationPatternSpy.count, 1)
compare(rotationReplaceSpy.count, 1)
+ compare(scaleRoleSpy.count, 1)
+ compare(scalePatternSpy.count, 1)
+ compare(scaleReplaceSpy.count, 1)
compare(xPosRoleSpy.count, 1)
compare(xPosPatternSpy.count, 1)
compare(xPosReplaceSpy.count, 1)
@@ -163,6 +181,24 @@ Item {
}
SignalSpy {
+ id: scaleRoleSpy
+ target: change
+ signalName: "scaleRoleChanged"
+ }
+
+ SignalSpy {
+ id: scalePatternSpy
+ target: change
+ signalName: "scaleRolePatternChanged"
+ }
+
+ SignalSpy {
+ id: scaleReplaceSpy
+ target: change
+ signalName: "scaleRoleReplaceChanged"
+ }
+
+ SignalSpy {
id: xPosRoleSpy
target: change
signalName: "xPosRoleChanged"
diff --git a/tests/manual/CMakeLists.txt b/tests/manual/CMakeLists.txt
index ade4c5ee..d6a0684d 100644
--- a/tests/manual/CMakeLists.txt
+++ b/tests/manual/CMakeLists.txt
@@ -30,6 +30,7 @@ if(QT_FEATURE_graphs_3d)
add_subdirectory(qmlcustominput)
add_subdirectory(qmldynamicdata)
add_subdirectory(qmlspline)
+ add_subdirectory(qmlvectorfield)
endif()
if(QT_FEATURE_graphs_3d_surface3d)
add_subdirectory(qmlgradient)
diff --git a/tests/manual/qmlvectorfield/CMakeLists.txt b/tests/manual/qmlvectorfield/CMakeLists.txt
new file mode 100644
index 00000000..8fa3ec9f
--- /dev/null
+++ b/tests/manual/qmlvectorfield/CMakeLists.txt
@@ -0,0 +1,30 @@
+# Copyright (C) 2025 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+
+if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ project(tst_qmlvectorfield LANGUAGES C CXX)
+ find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST)
+endif()
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+qt_internal_add_manual_test(tst_qmlvectorfield
+ GUI
+ SOURCES
+ main.cpp
+ )
+
+target_link_libraries(tst_qmlvectorfield PUBLIC
+ Qt::Gui
+ Qt::Graphs
+ Qt::GraphsWidgets
+ )
+
+qt_internal_add_resource(tst_qmlvectorfield "qmlvectorfield"
+ PREFIX
+ "/"
+ FILES
+ "qml/qmlvectorfield/main.qml"
+ )
diff --git a/tests/manual/qmlvectorfield/main.cpp b/tests/manual/qmlvectorfield/main.cpp
new file mode 100644
index 00000000..20159ca6
--- /dev/null
+++ b/tests/manual/qmlvectorfield/main.cpp
@@ -0,0 +1,34 @@
+// Copyright (C) 2025 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <QtGui/QGuiApplication>
+#include <QtCore/QDir>
+#include <QtQml/QQmlContext>
+#include <QtQuick/QQuickView>
+#include <QtQml/QQmlEngine>
+
+int main(int argc, char *argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ QQuickView viewer;
+
+ // The following are needed to make examples run without having to install the module
+ // in desktop environments.
+#ifdef Q_OS_WIN
+ QString extraImportPath(QStringLiteral("%1/../../../%2"));
+#else
+ QString extraImportPath(QStringLiteral("%1/../../%2"));
+#endif
+ viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(),
+ QString::fromLatin1("qml")));
+ QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close);
+
+ viewer.setTitle(QStringLiteral("QML Vector Field"));
+ viewer.setSource(QUrl("qrc:/qml/qmlvectorfield/main.qml"));
+ viewer.setResizeMode(QQuickView::SizeRootObjectToView);
+ viewer.show();
+
+ return app.exec();
+}
diff --git a/tests/manual/qmlvectorfield/qml/qmlvectorfield/main.qml b/tests/manual/qmlvectorfield/qml/qmlvectorfield/main.qml
new file mode 100644
index 00000000..598c6e67
--- /dev/null
+++ b/tests/manual/qmlvectorfield/qml/qmlvectorfield/main.qml
@@ -0,0 +1,113 @@
+// Copyright (C) 2025 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+import QtCore
+import QtQuick
+import QtQuick.Layouts
+import QtQuick.Controls
+import QtQuick.Dialogs
+import QtGraphs
+
+Item {
+ id: mainView
+ width: 1280
+ height: 1024
+
+ ListModel {
+ id: data
+
+ property int pointsPerSide: 15
+ onPointsPerSideChanged: initalizeData()
+
+ function initalizeData() {
+ console.log("initalizing data")
+ data.clear()
+ for (let i = 0; i < pointsPerSide; i++) {
+ for (let j = 0; j < pointsPerSide; j++) {
+ data.append({"xPos": i, "yPos":0, "zPos":j, "rotation":"", "scale":""})
+ }
+ }
+ }
+ function updateQuaternions(pos) {
+ for (let i = 0; i < data.count; i++) {
+ let pointPos = Qt.vector3d(data.get(i).xPos,
+ 0,
+ data.get(i).zPos)
+
+
+ var forward = pos.minus(pointPos).normalized()
+ var forwardVector = Qt.vector3d(0,1,0)
+ var dot = forwardVector.dotProduct(forward)
+ var rotAngle = Math.acos(dot) / (2 * Math.PI);
+ var rotAxis = forwardVector.crossProduct(forward).normalized()
+
+ data.setProperty(i, "rotation", generateQuaternion(rotAxis, rotAngle))
+
+ var dist = pos.minus(pointPos).length()
+ data.setProperty(i, "yPos", (Math.sqrt(data.count) -dist))
+ data.setProperty(i, "scale", generateScale(1, dist + 0.1, 1))
+ }
+ }
+
+ function generateQuaternion(axis, angle) {
+ return "@" + angle * 360 + "," + axis.x + ","
+ + axis.y + "," + axis.z;
+ }
+
+ function generateScale(x, y, z) {
+ return x + "," + y + "," + z
+ }
+
+ Component.onCompleted: {
+ initalizeData()
+ updateQuaternions(Qt.vector3d(5,0,5))
+ }
+ }
+
+ Gradient {
+ id: scatterGradient
+ GradientStop { position: 0.0; color: "blue" }
+ GradientStop { id: middleGradient; position: 0.50; color: "green" }
+ GradientStop { position: 1.0; color: "red" }
+ }
+
+ GraphsTheme {
+ id: theme
+ theme: GraphsTheme.Theme.OrangeSeries
+ colorStyle: GraphsTheme.ColorStyle.RangeGradient
+ baseGradients: [scatterGradient]
+ }
+
+ Scatter3D {
+ id: scatterGraph
+ anchors.fill:parent
+ theme: theme
+
+
+ Scatter3DSeries {
+ id: scatterSeries
+
+ itemSize: 0.1
+ mesh: Abstract3DSeries.Mesh.Arrow
+
+ onSelectedItemChanged: {
+ if (selectedItem == -1)
+ return
+ var i = selectedItem
+ let pointPos = Qt.vector3d(data.get(i).xPos,
+ 0,
+ data.get(i).zPos)
+ data.updateQuaternions(pointPos)
+ }
+ ItemModelScatterDataProxy {
+ id: scatterProxy
+ itemModel: data
+ xPosRole: "xPos"
+ yPosRole: "yPos"
+ zPosRole: "zPos"
+ rotationRole: "rotation"
+ scaleRole: "scale"
+ }
+ }
+ }
+}