From 1bd0ed65055304fff1ce477bf9f38a886eb06a3d Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Wed, 14 Dec 2022 08:33:22 +0100 Subject: Add manual tests to check the use of multiple QQuickWidgets Change-Id: Ib0a9ccaeb543f91da76e479f23bc59e868fbd2c7 Reviewed-by: Mike Krus (cherry picked from commit ff59b0dc9e6a88b08b615d2f8805ffd024b95785) Reviewed-by: Qt Cherry-pick Bot --- tests/manual/CMakeLists.txt | 3 + .../multi-qquickwidgets-scene3d/CMakeLists.txt | 34 +++++++++++ tests/manual/multi-qquickwidgets-scene3d/main.cpp | 60 +++++++++++++++++++ tests/manual/multi-qquickwidgets-scene3d/main.qml | 68 ++++++++++++++++++++++ tests/manual/multi-qquickwidgets-scene3d/main2.qml | 68 ++++++++++++++++++++++ 5 files changed, 233 insertions(+) create mode 100644 tests/manual/multi-qquickwidgets-scene3d/CMakeLists.txt create mode 100644 tests/manual/multi-qquickwidgets-scene3d/main.cpp create mode 100644 tests/manual/multi-qquickwidgets-scene3d/main.qml create mode 100644 tests/manual/multi-qquickwidgets-scene3d/main2.qml diff --git a/tests/manual/CMakeLists.txt b/tests/manual/CMakeLists.txt index 71e4587f0..ee06b5b9b 100644 --- a/tests/manual/CMakeLists.txt +++ b/tests/manual/CMakeLists.txt @@ -97,3 +97,6 @@ endif() if(TARGET Qt::QuickWidgets) add_subdirectory(quickwidget-switch) endif() +if(TARGET Qt::Quick AND TARGET Qt::QuickWidgets) + add_subdirectory(multi-qquickwidgets-scene3d) +endif() diff --git a/tests/manual/multi-qquickwidgets-scene3d/CMakeLists.txt b/tests/manual/multi-qquickwidgets-scene3d/CMakeLists.txt new file mode 100644 index 000000000..0c36c5267 --- /dev/null +++ b/tests/manual/multi-qquickwidgets-scene3d/CMakeLists.txt @@ -0,0 +1,34 @@ +# Copyright (C) 2022 Klaralvdalens Datakonsult AB (KDAB). +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## multi-qquickwidgets-scene3d Binary: +##################################################################### + +qt_internal_add_manual_test(multi-qquickwidgets-scene3d + GUI + SOURCES + main.cpp + LIBRARIES + Qt::3DCore + Qt::3DExtras + Qt::3DInput + Qt::3DRender + Qt::Gui + Qt::Quick + Qt::Widgets + Qt::QuickWidgets +) + +# Resources: +set(multi-qquickwidgets-scene3d_resource_files + "main.qml" + "main2.qml" +) + +qt_internal_add_resource(multi-qquickwidgets-scene3d "multi-qquickwidgets-scene3d" + PREFIX + "/" + FILES + ${multi-qquickwidgets-scene3d_resource_files} +) diff --git a/tests/manual/multi-qquickwidgets-scene3d/main.cpp b/tests/manual/multi-qquickwidgets-scene3d/main.cpp new file mode 100644 index 000000000..f7a5f2ad5 --- /dev/null +++ b/tests/manual/multi-qquickwidgets-scene3d/main.cpp @@ -0,0 +1,60 @@ +// Copyright (C) 2022 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +int main(int argc, char **argv) +{ + qputenv("QT3D_RENDERER", "opengl"); + qputenv("QSG_RHI_BACKEND", "opengl"); + + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); + QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL); + + QSurfaceFormat format(QSurfaceFormat::defaultFormat()); + format.setVersion(3, 3); + format.setProfile(QSurfaceFormat::CoreProfile); + format.setSamples(4); + format.setDepthBufferSize(24); + format.setStencilBufferSize(8); + format.setSwapInterval(0); // 0 = vsync off + QSurfaceFormat::setDefaultFormat(format); + + QApplication app(argc, argv); + + QMainWindow mainWindow; + + QQuickWidget *widget1 = new QQuickWidget(); + widget1->resize(QSize(400, 400)); + widget1->setResizeMode(QQuickWidget::SizeRootObjectToView); + widget1->setSource(QUrl("qrc:/main.qml")); + + QQuickWidget *widget2 = new QQuickWidget(); + widget2->resize(QSize(400, 400)); + widget2->setResizeMode(QQuickWidget::SizeRootObjectToView); + widget2->setSource(QUrl("qrc:/main2.qml")); + + auto centralWidget = new QWidget; + auto layout = new QHBoxLayout; + layout->addWidget(widget1); + layout->addWidget(widget2); + centralWidget->setLayout(layout); + mainWindow.setCentralWidget(centralWidget); + + mainWindow.show(); + + return app.exec(); +} diff --git a/tests/manual/multi-qquickwidgets-scene3d/main.qml b/tests/manual/multi-qquickwidgets-scene3d/main.qml new file mode 100644 index 000000000..850c3aedc --- /dev/null +++ b/tests/manual/multi-qquickwidgets-scene3d/main.qml @@ -0,0 +1,68 @@ +// Copyright (C) 2022 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick 6.0 as QQ2 +import Qt3D.Core 2.15 +import Qt3D.Render 2.15 +import Qt3D.Input 2.15 +import Qt3D.Extras 2.15 +import QtQuick.Scene3D 2.15 + +QQ2.Item { + width: 300 + height: 300 + + Scene3D { + id: scene3d + anchors.fill: parent + aspects: ["render", "input", "logic"] + + Entity { + id: sceneRoot + + Camera { + id: camera + projectionType: CameraLens.PerspectiveProjection + fieldOfView: 45 + aspectRatio: scene3d.width / scene3d.height + nearPlane : 0.1 + farPlane : 1000.0 + position: Qt.vector3d( 0.0, 0.0, -40.0 ) + upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) + viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) + } + + OrbitCameraController { + camera: camera + } + + components: [ + RenderSettings { + activeFrameGraph: ForwardRenderer { + clearColor: Qt.rgba(0.5, 0.0, 1, 1) + camera: camera + showDebugOverlay: true + } + renderPolicy: RenderSettings.OnDemand + }, + InputSettings { } + ] + + Entity { + components: [ + PhongMaterial {}, + TorusMesh { + radius: 5 + minorRadius: 1 + rings: 100 + slices: 20 + }, + Transform { + scale3D: Qt.vector3d(1.5, 1, 0.5) + rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45) + } + ] + } + } + } +} diff --git a/tests/manual/multi-qquickwidgets-scene3d/main2.qml b/tests/manual/multi-qquickwidgets-scene3d/main2.qml new file mode 100644 index 000000000..dd94d1f6e --- /dev/null +++ b/tests/manual/multi-qquickwidgets-scene3d/main2.qml @@ -0,0 +1,68 @@ +// Copyright (C) 2022 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick 6.0 as QQ2 +import Qt3D.Core 2.15 +import Qt3D.Render 2.15 +import Qt3D.Input 2.15 +import Qt3D.Extras 2.15 +import QtQuick.Scene3D 2.15 + +QQ2.Item { + width: 300 + height: 300 + + Scene3D { + id: scene3d + anchors.fill: parent + aspects: ["render", "input", "logic"] + + Entity { + id: sceneRoot + + Camera { + id: camera + projectionType: CameraLens.PerspectiveProjection + fieldOfView: 45 + aspectRatio: scene3d.width / scene3d.height + nearPlane : 0.1 + farPlane : 1000.0 + position: Qt.vector3d( 0.0, 0.0, -40.0 ) + upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) + viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) + } + + OrbitCameraController { + camera: camera + } + + components: [ + RenderSettings { + activeFrameGraph: ForwardRenderer { + clearColor: Qt.rgba(0, 0.5, 1, 1) + camera: camera + showDebugOverlay: true + } + renderPolicy: RenderSettings.OnDemand + }, + InputSettings { } + ] + + Entity { + components: [ + PhongMaterial {}, + TorusMesh { + radius: 5 + minorRadius: 1 + rings: 100 + slices: 20 + }, + Transform { + scale3D: Qt.vector3d(1.5, 1, 0.5) + rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45) + } + ] + } + } + } +} -- cgit v1.2.3