summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaj Grönholm <kaj.gronholm@qt.io>2019-05-28 09:04:18 +0300
committerKaj Grönholm <kaj.gronholm@qt.io>2019-05-28 09:09:40 +0300
commit3685a8f5b9cfce588d6589c9e1afdb04ec9b5133 (patch)
treef5e14e314f6cb986447df1f94761e0b57ab0787a
parentb59b9b9e1fbd6aa1ae8edfc0d5248ab37d266e82 (diff)
Remove Q3DSWidget from OpenGL runtime
This QWidget based Q3DSWidget hasn't been tested or used in any examples, so remove it from OpenGL runtime API. Qt 3D based runtime contains still Q3DSWidget which can be used. Task-number: QT3DS-3577 Change-Id: If022e18b1285f9be78048cef3821e9f063c3c721 Reviewed-by: Pasi Keränen <pasi.keranen@qt.io> Reviewed-by: Antti Määttä <antti.maatta@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r--src/Runtime/api/studio3d/q3dspresentation.h1
-rw-r--r--src/Runtime/api/studio3d/q3dsviewersettings.h1
-rw-r--r--src/Runtime/api/studio3d/q3dswidget.cpp332
-rw-r--r--src/Runtime/api/studio3d/q3dswidget.h92
-rw-r--r--src/Runtime/api/studio3d/q3dswidget_p.h93
-rw-r--r--src/Runtime/api/studio3d/studio3d.pro5
-rw-r--r--tests/auto/studio3d/q3dswidget/q3dswidget.pro10
-rw-r--r--tests/auto/studio3d/q3dswidget/tst_q3dswidget.cpp1040
-rw-r--r--tests/auto/studio3d/studio3d.pro3
9 files changed, 2 insertions, 1575 deletions
diff --git a/src/Runtime/api/studio3d/q3dspresentation.h b/src/Runtime/api/studio3d/q3dspresentation.h
index 60191be2..6a2a8926 100644
--- a/src/Runtime/api/studio3d/q3dspresentation.h
+++ b/src/Runtime/api/studio3d/q3dspresentation.h
@@ -145,7 +145,6 @@ private:
friend class Q3DSPresentationItem;
friend class Q3DSSurfaceViewerPrivate;
- friend class Q3DSWidgetPrivate;
friend class Q3DSRenderer;
friend class Q3DSStudio3D;
friend class Q3DSDataInput;
diff --git a/src/Runtime/api/studio3d/q3dsviewersettings.h b/src/Runtime/api/studio3d/q3dsviewersettings.h
index 82d7d62e..80d5edb2 100644
--- a/src/Runtime/api/studio3d/q3dsviewersettings.h
+++ b/src/Runtime/api/studio3d/q3dsviewersettings.h
@@ -91,7 +91,6 @@ private:
Q3DSViewerSettingsPrivate *d_ptr;
friend class Q3DSSurfaceViewerPrivate;
- friend class Q3DSWidgetPrivate;
friend class Q3DSRenderer;
friend class Q3DSStudio3D;
};
diff --git a/src/Runtime/api/studio3d/q3dswidget.cpp b/src/Runtime/api/studio3d/q3dswidget.cpp
deleted file mode 100644
index 23334b5b..00000000
--- a/src/Runtime/api/studio3d/q3dswidget.cpp
+++ /dev/null
@@ -1,332 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 - 2016 NVIDIA Corporation.
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt 3D Studio.
-**
-** $QT_BEGIN_LICENSE:GPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 or (at your option) any later version
-** approved by the KDE Free Qt Foundation. The licenses are as published by
-** the Free Software Foundation and appearing in the file LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "q3dswidget_p.h"
-#include "Qt3DSAudioPlayerImpl.h"
-#include "viewerqmlstreamproxy_p.h"
-#include "q3dsviewersettings_p.h"
-#include "q3dspresentation_p.h"
-#include "studioutils_p.h"
-#include "q3dsvariantconfig_p.h"
-
-#include <QtGui/qevent.h>
-#include <QtGui/qopenglcontext.h>
-#include <QtGui/QWindow>
-#include <QtCore/qfileinfo.h>
-#include <QtCore/qdebug.h>
-
-using namespace Q3DSViewer;
-
-QT_BEGIN_NAMESPACE
-
-typedef void (QWidget::*QWidgetVoidSlot)();
-
-Q3DSWidget::Q3DSWidget(QWidget *parent)
- : QOpenGLWidget(parent)
- , d_ptr(new Q3DSWidgetPrivate(this))
-{
- // Get keyboard handling
- setFocusPolicy(Qt::StrongFocus);
- setMouseTracking(true);
-}
-
-Q3DSWidget::~Q3DSWidget()
-{
- delete d_ptr;
-}
-
-bool Q3DSWidget::initialize()
-{
- return d_ptr->initialize();
-}
-
-int Q3DSWidget::updateInterval() const
-{
- return d_ptr->m_updateInterval;
-}
-
-bool Q3DSWidget::isRunning() const
-{
- return d_ptr->m_viewerApp != nullptr;
-}
-
-Q3DSViewerSettings *Q3DSWidget::settings() const
-{
- return d_ptr->settings();
-}
-
-Q3DSPresentation *Q3DSWidget::presentation() const
-{
- return d_ptr->presentation();
-}
-
-void Q3DSWidget::initializeGL()
-{
- // Find the native window to determine pixel ratio
- QWidget *widget = this;
- QWindow *window = windowHandle();
- while (widget && window == nullptr) {
- widget = qobject_cast<QWidget *>(widget->parent());
- window = widget->windowHandle();
- }
- if (window)
- d_ptr->m_pixelRatio = window->devicePixelRatio();
-}
-
-void Q3DSWidget::resizeGL(int w, int h)
-{
- if (d_ptr->m_viewerApp)
- d_ptr->m_viewerApp->Resize(int(w * d_ptr->m_pixelRatio), int(h * d_ptr->m_pixelRatio));
-}
-
-void Q3DSWidget::paintGL()
-{
- if (d_ptr->m_viewerApp && d_ptr->m_viewerApp->IsInitialised())
- d_ptr->m_viewerApp->Render();
-}
-
-void Q3DSWidget::setUpdateInterval(int interval)
-{
- d_ptr->setUpdateInterval(interval);
-}
-
-void Q3DSWidget::shutdown()
-{
- d_ptr->shutdown();
-}
-
-void Q3DSWidget::reset()
-{
- d_ptr->reset();
-}
-
-void Q3DSWidget::mousePressEvent(QMouseEvent *event)
-{
- if (d_ptr->m_pixelRatio != 1.0) {
- QMouseEvent scaledEvent(event->type(), event->pos() * d_ptr->m_pixelRatio,
- event->button(), event->buttons(), event->modifiers());
- d_ptr->m_presentation->mousePressEvent(&scaledEvent);
- } else {
- d_ptr->m_presentation->mousePressEvent(event);
- }
-}
-
-void Q3DSWidget::mouseReleaseEvent(QMouseEvent *event)
-{
- if (d_ptr->m_pixelRatio != 1.0) {
- QMouseEvent scaledEvent(event->type(), event->pos() * d_ptr->m_pixelRatio,
- event->button(), event->buttons(), event->modifiers());
- d_ptr->m_presentation->mouseReleaseEvent(&scaledEvent);
- } else {
- d_ptr->m_presentation->mouseReleaseEvent(event);
- }
-}
-
-void Q3DSWidget::mouseMoveEvent(QMouseEvent *event)
-{
- if (d_ptr->m_pixelRatio != 1.0) {
- QMouseEvent scaledEvent(event->type(), event->pos() * d_ptr->m_pixelRatio,
- event->button(), event->buttons(), event->modifiers());
- d_ptr->m_presentation->mouseMoveEvent(&scaledEvent);
- } else {
- d_ptr->m_presentation->mouseMoveEvent(event);
- }
-}
-
-void Q3DSWidget::wheelEvent(QWheelEvent *event)
-{
- d_ptr->m_presentation->wheelEvent(event);
-}
-
-void Q3DSWidget::keyPressEvent(QKeyEvent *event)
-{
- d_ptr->m_presentation->keyPressEvent(event);
-}
-
-void Q3DSWidget::keyReleaseEvent(QKeyEvent *event)
-{
- d_ptr->m_presentation->keyReleaseEvent(event);
-}
-
-Q3DSWidgetPrivate::Q3DSWidgetPrivate(Q3DSWidget *q)
- : QObject(q)
- , q_ptr(q)
- , m_viewerApp(nullptr)
- , m_timer(nullptr)
- , m_updateInterval(-1)
- , m_pixelRatio(1.0)
- , m_settings(new Q3DSViewerSettings(this))
- , m_presentation(new Q3DSPresentation(this))
-{
- m_startupTimer.start();
- connect(m_presentation, &Q3DSPresentation::sourceChanged, this, &Q3DSWidgetPrivate::reset);
-}
-
-Q3DSWidgetPrivate::~Q3DSWidgetPrivate()
-{
- releaseRuntime();
-
- delete m_timer;
-}
-
-void Q3DSWidgetPrivate::reset()
-{
- if (m_viewerApp) {
- releaseRuntime();
- initializeRuntime();
- }
-}
-
-void Q3DSWidgetPrivate::setUpdateInterval(int interval)
-{
- if (m_updateInterval != interval) {
- m_updateInterval = interval;
- resetUpdateTimer();
- Q_EMIT q_ptr->updateIntervalChanged(m_updateInterval);
- }
-}
-
-bool Q3DSWidgetPrivate::initialize()
-{
- Q_ASSERT(q_ptr->context());
-
- if (m_presentation->source().isEmpty()) {
- qWarning("Failed to initialize Q3DSWidget,"
- " presentation source must be set before calling initialize()");
- return false;
- }
-
- QFileInfo info(Q3DSUtils::urlToLocalFileOrQrc(m_presentation->source()));
- if (!info.exists()) {
- qWarning() << "Failed to initialize Q3DSWidget, the presentation doesn't exist:"
- << m_presentation->source().toString();
- return false;
- }
-
- shutdown();
-
- connect(q_ptr->context(), &QOpenGLContext::aboutToBeDestroyed,
- this, &Q3DSWidgetPrivate::shutdown);
-
- bool success = initializeRuntime();
-
- if (success)
- Q_EMIT q_ptr->runningChanged(true);
-
- return success;
-}
-
-Q3DSViewerSettings *Q3DSWidgetPrivate::settings()
-{
- return m_settings;
-}
-
-Q3DSPresentation *Q3DSWidgetPrivate::presentation()
-{
- return m_presentation;
-}
-
-void Q3DSWidgetPrivate::shutdown()
-{
- bool oldInitialized = (m_viewerApp != nullptr);
-
- if (q_ptr->context()) {
- disconnect(q_ptr->context(), &QOpenGLContext::aboutToBeDestroyed,
- this, &Q3DSWidgetPrivate::shutdown);
- }
-
- releaseRuntime();
-
- if (oldInitialized)
- Q_EMIT q_ptr->runningChanged(false);
-}
-
-bool Q3DSWidgetPrivate::initializeRuntime()
-{
- Q_ASSERT(!m_viewerApp);
-
- q_ptr->makeCurrent();
-
- m_viewerApp = &Q3DSViewerApp::Create(q_ptr->context(), new Qt3DSAudioPlayerImpl(),
- &m_startupTimer);
-
- Q_ASSERT(m_viewerApp);
-
- const QString localSource = Q3DSUtils::urlToLocalFileOrQrc(m_presentation->source());
-
- if (!m_viewerApp->InitializeApp(int(q_ptr->width() * m_pixelRatio),
- int(q_ptr->height() * m_pixelRatio),
- q_ptr->context()->format(),
- q_ptr->defaultFramebufferObject(), localSource,
- m_presentation->variantList(),
- m_presentation->delayedLoading(),
- m_presentation->d_ptr->streamProxy())) {
- releaseRuntime();
- qWarning("Failed to initialize runtime");
- return false;
- }
-
- m_settings->d_ptr->setViewerApp(m_viewerApp);
- m_presentation->d_ptr->setViewerApp(m_viewerApp);
-
- resetUpdateTimer();
-
- return true;
-}
-
-void Q3DSWidgetPrivate::releaseRuntime()
-{
- m_settings->d_ptr->setViewerApp(nullptr);
- m_presentation->d_ptr->setViewerApp(nullptr);
-
- if (m_viewerApp) {
- q_ptr->makeCurrent();
- m_viewerApp->Release();
- m_viewerApp = nullptr;
- }
-
- resetUpdateTimer();
-}
-
-void Q3DSWidgetPrivate::resetUpdateTimer()
-{
- if (m_viewerApp && m_updateInterval >= 0) {
- if (!m_timer) {
- m_timer = new QTimer();
- connect(m_timer, &QTimer::timeout,
- q_ptr, static_cast<QWidgetVoidSlot>(&QWidget::update));
- }
- m_timer->start(m_updateInterval);
- } else if (m_timer) {
- m_timer->stop();
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/Runtime/api/studio3d/q3dswidget.h b/src/Runtime/api/studio3d/q3dswidget.h
deleted file mode 100644
index ad5d823d..00000000
--- a/src/Runtime/api/studio3d/q3dswidget.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 - 2016 NVIDIA Corporation.
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt 3D Studio.
-**
-** $QT_BEGIN_LICENSE:GPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 or (at your option) any later version
-** approved by the KDE Free Qt Foundation. The licenses are as published by
-** the Free Software Foundation and appearing in the file LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef Q3DSWIDGET_H
-#define Q3DSWIDGET_H
-
-#include <QtStudio3D/qstudio3dglobal.h>
-#include <QtWidgets/QOpenGLWidget>
-#include <QtCore/QUrl>
-
-QT_BEGIN_NAMESPACE
-
-class Q3DSWidgetPrivate;
-class Q3DSViewerSettings;
-class Q3DSPresentation;
-
-class Q_STUDIO3D_EXPORT Q3DSWidget : public QOpenGLWidget
-{
- Q_OBJECT
- Q_DECLARE_PRIVATE(Q3DSWidget)
- Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval NOTIFY updateIntervalChanged)
- Q_PROPERTY(bool running READ isRunning NOTIFY runningChanged)
-
-public:
- explicit Q3DSWidget(QWidget *parent = nullptr);
- virtual ~Q3DSWidget();
-
- bool initialize();
-
- // Property accessors
- int updateInterval() const;
- bool isRunning() const;
-
- Q3DSViewerSettings *settings() const;
- Q3DSPresentation *presentation() const;
-
-public Q_SLOTS:
- void setUpdateInterval(int interval);
- void shutdown();
- void reset();
-
-Q_SIGNALS:
- void updateIntervalChanged(bool autoUpdate);
- void runningChanged(bool initialized);
-
-protected:
- // Qt event handling
- void mousePressEvent(QMouseEvent *event) override;
- void mouseReleaseEvent(QMouseEvent *event) override;
- void mouseMoveEvent(QMouseEvent *event) override;
- void wheelEvent(QWheelEvent *event) override;
- void keyPressEvent(QKeyEvent *event) override;
- void keyReleaseEvent(QKeyEvent *e) override;
-
- // Qt overrides
- void initializeGL() override;
- void resizeGL(int w, int h) override;
- void paintGL() override;
-
-private:
- Q_DISABLE_COPY(Q3DSWidget)
- Q3DSWidgetPrivate *d_ptr;
-};
-QT_END_NAMESPACE
-#endif // Q3DSWIDGET_H
diff --git a/src/Runtime/api/studio3d/q3dswidget_p.h b/src/Runtime/api/studio3d/q3dswidget_p.h
deleted file mode 100644
index 03ca6aac..00000000
--- a/src/Runtime/api/studio3d/q3dswidget_p.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 - 2016 NVIDIA Corporation.
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt 3D Studio.
-**
-** $QT_BEGIN_LICENSE:GPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 or (at your option) any later version
-** approved by the KDE Free Qt Foundation. The licenses are as published by
-** the Free Software Foundation and appearing in the file LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the QtStudio3D API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-
-#ifndef Q3DSWIDGET_P_H
-#define Q3DSWIDGET_P_H
-
-#include "q3dswidget.h"
-#include "Qt3DSViewerApp.h"
-
-#include <QtCore/qtimer.h>
-
-QT_BEGIN_NAMESPACE
-
-class Q3DSViewerSettings;
-class Q3DSPresentation;
-
-class Q_STUDIO3D_EXPORT Q3DSWidgetPrivate : public QObject
-{
-public:
- Q_OBJECT
- Q_DECLARE_PUBLIC(Q3DSWidget)
-
-public:
- explicit Q3DSWidgetPrivate(Q3DSWidget *q);
- virtual ~Q3DSWidgetPrivate();
-
- void reset();
- void setUpdateInterval(int interval);
- bool initialize();
-
- Q3DSViewerSettings *settings();
- Q3DSPresentation *presentation();
-
-private Q_SLOTS:
- void shutdown();
-
-private:
- bool initializeRuntime();
- void releaseRuntime();
- void resetUpdateTimer();
-
- Q3DSWidget *q_ptr;
-
- Q3DSViewer::Q3DSViewerApp *m_viewerApp;
- QTimer *m_timer;
- int m_updateInterval;
- qreal m_pixelRatio;
- QElapsedTimer m_startupTimer;
-
- Q3DSViewerSettings *m_settings;
- Q3DSPresentation *m_presentation;
-};
-
-QT_END_NAMESPACE
-
-#endif // Q3DSWIDGET_P_H
diff --git a/src/Runtime/api/studio3d/studio3d.pro b/src/Runtime/api/studio3d/studio3d.pro
index e2592426..62d0613f 100644
--- a/src/Runtime/api/studio3d/studio3d.pro
+++ b/src/Runtime/api/studio3d/studio3d.pro
@@ -16,8 +16,6 @@ LIBS += \
HEADERS += \
q3dsdataoutput.h \
q3dsdataoutput_p.h \
- q3dswidget.h \
- q3dswidget_p.h \
q3dssurfaceviewer.h \
q3dssurfaceviewer_p.h \
qstudio3dglobal.h \
@@ -39,8 +37,7 @@ HEADERS += \
q3dsgeometry.h \
q3dsgeometry_p.h
-SOURCES += q3dswidget.cpp \
- q3dsdataoutput.cpp \
+SOURCES += q3dsdataoutput.cpp \
q3dssurfaceviewer.cpp \
viewerqmlstreamproxy.cpp \
q3dsviewersettings.cpp \
diff --git a/tests/auto/studio3d/q3dswidget/q3dswidget.pro b/tests/auto/studio3d/q3dswidget/q3dswidget.pro
deleted file mode 100644
index 82339b2b..00000000
--- a/tests/auto/studio3d/q3dswidget/q3dswidget.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-TEMPLATE = app
-CONFIG += testcase
-
-TARGET = tst_q3dswidget
-
-QT += testlib studio3d
-
-SOURCES += tst_q3dswidget.cpp
-
-RESOURCES += ../shared/shared_presentations.qrc
diff --git a/tests/auto/studio3d/q3dswidget/tst_q3dswidget.cpp b/tests/auto/studio3d/q3dswidget/tst_q3dswidget.cpp
deleted file mode 100644
index c92a9159..00000000
--- a/tests/auto/studio3d/q3dswidget/tst_q3dswidget.cpp
+++ /dev/null
@@ -1,1040 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of Qt 3D Studio.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
-#include <QtStudio3D/q3dswidget.h>
-#include <QtStudio3D/q3dsviewersettings.h>
-#include <QtStudio3D/q3dspresentation.h>
-#include <QtStudio3D/q3dssceneelement.h>
-#include <QtGui/qwindow.h>
-#include <QtGui/qopenglcontext.h>
-#include <QtGui/qpixmap.h>
-#include <QtGui/qimage.h>
-#include <QtGui/qscreen.h>
-#include <QtGui/qopenglframebufferobject.h>
-#include <QtGui/qevent.h>
-#include <QtWidgets/qmainwindow.h>
-#include <QtCore/qurl.h>
-#include <QtCore/qfile.h>
-#include "../shared/shared_presentations.h"
-
-class tst_Q3DSWidget : public QObject
-{
- Q_OBJECT
-public:
- tst_Q3DSWidget();
- ~tst_Q3DSWidget() {}
-
-private slots:
- void initTestCase();
- void init();
- void cleanup();
-
- void testBasics();
- void testSourceChange();
- void testUpdateInterval();
- void testMultiple();
- void testReset();
- void testSettings();
- void testPresentation();
- void testPresentationActivation();
- void testScene();
- void testMouseInput();
-
-private:
- QMainWindow *createWindow(const QSize &size);
-
- // Created viewers are returned via *&viewer parameter rather than return value, so that we can
- // use QCOMPARE and QVERIFY inside these functions (they require void return value).
- void createViewer(Q3DSWidget *&viewer, QMainWindow *window, const QUrl &url,
- int updateInterval);
- void createWindowAndViewer(Q3DSWidget *&viewer, const QUrl &url,
- const QSize &size = QSize(), int updateInterval = 0);
- void checkPixel(Q3DSWidget *viewer, const QColor &color,
- const QPoint &pixel = QPoint(50, 50));
-
- QMainWindow *m_window;
- Q3DSWidget *m_viewer;
-};
-
-tst_Q3DSWidget::tst_Q3DSWidget()
- : m_window(nullptr)
- , m_viewer(nullptr)
-{
-}
-
-//#define DUMP_LOGFILE // Uncomment log Qt 3D Studio internal messages to log.txt file
-void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
-{
- Q_UNUSED(context);
- switch (type) {
- // case QtDebugMsg:
- case QtInfoMsg:
- case QtWarningMsg:
- case QtCriticalMsg: {
-#ifdef DUMP_LOGFILE
- QFile file("log.txt");
- if (file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) {
- QTextStream stream(&file);
- stream << msg << "\n";
- }
- file.close();
-#endif
- } break; // swallow
- case QtFatalMsg:
- QFAIL(msg.toLocal8Bit().constData());
- }
-}
-
-void tst_Q3DSWidget::initTestCase()
-{
- qInstallMessageHandler(messageOutput);
-#ifdef DUMP_LOGFILE
- QFile file("log.txt");
- if (file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
- QTextStream stream(&file);
- stream << "Log file: " << QTime::currentTime().toString() << "\n";
- }
- file.close();
-#endif
-}
-
-void tst_Q3DSWidget::init()
-{
-}
-
-void tst_Q3DSWidget::cleanup()
-{
- if (m_window)
- m_window->close();
-
- delete m_viewer;
- m_viewer = nullptr;
-
- delete m_window;
- m_window = nullptr;
-}
-
-QMainWindow *tst_Q3DSWidget::createWindow(const QSize &size)
-{
- QMainWindow *window = new QMainWindow();
-
- window->resize(size);
-
- return window;
-}
-
-void tst_Q3DSWidget::createViewer(Q3DSWidget *&viewer, QMainWindow *window, const QUrl &url,
- int updateInterval)
-{
- viewer = new Q3DSWidget();
- QSignalSpy spy(viewer, &Q3DSWidget::runningChanged);
-
- window->setCentralWidget(viewer);
-
- viewer->presentation()->setSource(url);
- QCOMPARE(viewer->presentation()->source(), url);
-
- QVERIFY(spy.isValid());
- QCOMPARE(spy.count(), 0);
-
- viewer->setUpdateInterval(updateInterval);
-
- QVERIFY(viewer->initialize());
-
- QCOMPARE(spy.count(), 1);
- QVERIFY(viewer->isRunning());
-}
-
-void tst_Q3DSWidget::createWindowAndViewer(Q3DSWidget *&viewer, const QUrl &url,
- const QSize &size, int updateInterval)
-{
- QSize actualSize = size;
- if (actualSize.isEmpty())
- actualSize = QSize(300, 200);
-
- m_window = createWindow(actualSize);
- m_window->show();
-
- createViewer(viewer, m_window, url, updateInterval);
-
- QGuiApplication::processEvents();
-}
-
-void tst_Q3DSWidget::checkPixel(Q3DSWidget *viewer, const QColor &color,
- const QPoint &pixel)
-{
- // Grab operation is potentially costly, so retry only every second instead of using
- // QTRY_COMPARE which would try it every 50ms. We also want to wait first as it takes some time
- // for the presentation to be displayed.
- QColor grabColor;
- for (int i = 0; i < 20; i++) {
- QTest::qWait(1000);
- QImage image = viewer->grabFramebuffer();
- grabColor = QColor(image.pixel(pixel));
- if (grabColor == color)
- break;
- }
- QCOMPARE(grabColor, color);
-}
-
-void tst_Q3DSWidget::testBasics()
-{
- createWindowAndViewer(m_viewer, RED);
-
- QSignalSpy spy(m_viewer, &Q3DSWidget::runningChanged);
- QVERIFY(spy.isValid());
-
- checkPixel(m_viewer, Qt::red);
-
- m_viewer->shutdown();
-
- QCOMPARE(spy.count(), 1);
- QVERIFY(!m_viewer->isRunning());
-}
-
-void tst_Q3DSWidget::testSourceChange()
-{
- createWindowAndViewer(m_viewer, RED);
-
- QSignalSpy spy(m_viewer->presentation(), &Q3DSPresentation::sourceChanged);
- QVERIFY(spy.isValid());
- QVERIFY(m_viewer->presentation()->source() == RED);
-
- checkPixel(m_viewer, Qt::red);
-
- // Different source
- m_viewer->presentation()->setSource(BLUE);
- QCOMPARE(spy.count(), 1);
- QVERIFY(m_viewer->presentation()->source() == BLUE);
-
- checkPixel(m_viewer, Qt::blue);
-
- // Reset same source
- m_viewer->presentation()->setSource(BLUE);
- QCOMPARE(spy.count(), 1);
- QVERIFY(m_viewer->presentation()->source() == BLUE);
-
- checkPixel(m_viewer, Qt::blue);
-
- // Different source again
- m_viewer->presentation()->setSource(RED);
- QCOMPARE(spy.count(), 2);
- QVERIFY(m_viewer->presentation()->source() == RED);
-
- checkPixel(m_viewer, Qt::red);
-}
-
-void tst_Q3DSWidget::testUpdateInterval()
-{
- createWindowAndViewer(m_viewer, ANIMATION);
-
- m_viewer->settings()->setScaleMode(Q3DSViewerSettings::ScaleModeFill);
-
- QSignalSpy spy(m_viewer, &Q3DSWidget::updateIntervalChanged);
- QVERIFY(spy.isValid());
- QVERIFY(m_viewer->updateInterval() == 0);
-
- checkPixel(m_viewer, Qt::black);
- {
- // Grab two images two seconds apart to verify animation is happening
- QImage image1 = m_viewer->grabFramebuffer();
- QTest::qWait(2000);
- QImage image2 = m_viewer->grabFramebuffer();
- QVERIFY(image1 != image2);
-
- }
- {
- m_viewer->setUpdateInterval(100000);
- QVERIFY(m_viewer->updateInterval() == 100000);
- QCOMPARE(spy.count(), 1);
- // Can't test if animation actually stopped, as grabbing the viewer forces update on it
- }
- {
- m_viewer->setUpdateInterval(20);
- QCOMPARE(spy.count(), 2);
- QVERIFY(m_viewer->updateInterval() == 20);
-
- // Non-zero interval short enough to see animation
- QImage image1 = m_viewer->grabFramebuffer();
- QTest::qWait(2000);
- QImage image2 = m_viewer->grabFramebuffer();
- QVERIFY(image1 != image2);
- }
- {
- m_viewer->setUpdateInterval(-1);
- QCOMPARE(spy.count(), 3);
- QVERIFY(m_viewer->updateInterval() == -1);
- // Can't test if animation actually stopped, as grabbing the viewer forces update on it
- }
-}
-
-void tst_Q3DSWidget::testMultiple()
-{
- int viewerCount = 3;
-
- QVector<QMainWindow *> windows;
- QVector<Q3DSWidget *> viewers;
-
- windows.resize(viewerCount);
- viewers.resize(viewerCount);
-
- QSize size(200, 150);
- QUrl url;
- for (int i = 0; i < viewerCount; i++) {
- windows[i] = createWindow(size);
- if (i % 2)
- url = RED;
- else
- url = BLUE;
- windows[i]->move(10 + i * 50, 10 + i * 50);
- windows[i]->show();
- createViewer(viewers[i], windows[i], url, 0);
- QGuiApplication::processEvents();
- }
-
- for (int i = 0; i < viewerCount; i++) {
- if (i % 2)
- checkPixel(viewers[i], Qt::red);
- else
- checkPixel(viewers[i], Qt::blue);
- }
-
- for (QMainWindow *w : windows) {
- w->close();
- delete w;
- }
- windows.clear();
-}
-
-void tst_Q3DSWidget::testReset()
-{
- createWindowAndViewer(m_viewer, RED);
-
- checkPixel(m_viewer, Qt::red);
-
- // TODO: change color of the cube to blue (not currently possible, API missing)
- // checkPixel(m_viewer, Qt::blue);
-
- m_viewer->reset();
-
- checkPixel(m_viewer, Qt::red);
-}
-
-void tst_Q3DSWidget::testSettings()
-{
- int width = 500;
- int height = 500;
-
- createWindowAndViewer(m_viewer, SETTINGS, QSize(width, height));
-
- Q3DSViewerSettings *s = m_viewer->settings();
-
- QSignalSpy spy1(s, &Q3DSViewerSettings::matteColorChanged);
- QSignalSpy spy2(s, &Q3DSViewerSettings::showRenderStatsChanged);
- QSignalSpy spy3(s, &Q3DSViewerSettings::shadeModeChanged);
- QSignalSpy spy4(s, &Q3DSViewerSettings::scaleModeChanged);
- QVERIFY(spy1.isValid());
- QVERIFY(spy2.isValid());
- QVERIFY(spy3.isValid());
- QVERIFY(spy4.isValid());
-
- // Check defaults
- QCOMPARE(s->matteColor(), QColor(Qt::black));
- QCOMPARE(s->isShowRenderStats(), false);
- QCOMPARE(s->shadeMode(), Q3DSViewerSettings::ShadeModeShaded);
- QCOMPARE(s->scaleMode(), Q3DSViewerSettings::ScaleModeCenter);
-
- // Matte
- checkPixel(m_viewer, Qt::black);
-
- s->setMatteColor(Qt::cyan);
- QCOMPARE(s->matteColor(), QColor(Qt::cyan));
-
- QCOMPARE(spy1.count(), 1);
- QCOMPARE(spy2.count(), 0);
- QCOMPARE(spy3.count(), 0);
- QCOMPARE(spy4.count(), 0);
-
- checkPixel(m_viewer, Qt::cyan);
-
- // Render stats
- QImage image1 = m_viewer->grabFramebuffer();
-
- s->setShowRenderStats(true);
- QCOMPARE(s->isShowRenderStats(), true);
-
- QCOMPARE(spy1.count(), 1);
- QCOMPARE(spy2.count(), 1);
- QCOMPARE(spy3.count(), 0);
- QCOMPARE(spy4.count(), 0);
-
- QImage image2 = m_viewer->grabFramebuffer();
- QVERIFY(image1 != image2);
-
- // ShadeMode
- image1 = m_viewer->grabFramebuffer();
-
- s->setShadeMode(Q3DSViewerSettings::ShadeModeShadedWireframe);
- QCOMPARE(s->shadeMode(), Q3DSViewerSettings::ShadeModeShadedWireframe);
-
- QCOMPARE(spy1.count(), 1);
- QCOMPARE(spy2.count(), 1);
- QCOMPARE(spy3.count(), 1);
- QCOMPARE(spy4.count(), 0);
-
- image2 = m_viewer->grabFramebuffer();
- QVERIFY(image1 != image2);
-
- // Restore shade mode so following tests are not affected by wireframes
- s->setShadeMode(Q3DSViewerSettings::ShadeModeShaded);
-
- // ScaleMode
- checkPixel(m_viewer, Qt::cyan);
- checkPixel(m_viewer, Qt::cyan, QPoint(50, height / 2));
- s->setScaleMode(Q3DSViewerSettings::ScaleModeFit);
- QCOMPARE(s->scaleMode(), Q3DSViewerSettings::ScaleModeFit);
-
- QCOMPARE(spy1.count(), 1);
- QCOMPARE(spy2.count(), 1);
- QCOMPARE(spy3.count(), 2);
- QCOMPARE(spy4.count(), 1);
-
- checkPixel(m_viewer, Qt::cyan);
- checkPixel(m_viewer, Qt::red, QPoint(50, height / 2));
-
- s->setScaleMode(Q3DSViewerSettings::ScaleModeFill);
- QCOMPARE(s->scaleMode(), Q3DSViewerSettings::ScaleModeFill);
-
- QCOMPARE(spy1.count(), 1);
- QCOMPARE(spy2.count(), 1);
- QCOMPARE(spy3.count(), 2);
- QCOMPARE(spy4.count(), 2);
-
- checkPixel(m_viewer, Qt::blue);
- checkPixel(m_viewer, Qt::red, QPoint(50, height / 2));
-
- // Saving & loading settings
- s->save(QStringLiteral("testViewer"), QStringLiteral("The Qt Company"),
- QStringLiteral("tst_q3dsurfaceviewer"));
-
- image1 = m_viewer->grabFramebuffer();
-
- s->setMatteColor(Qt::yellow);
- s->setShowRenderStats(false);
- s->setShadeMode(Q3DSViewerSettings::ShadeModeShadedWireframe);
- s->setScaleMode(Q3DSViewerSettings::ScaleModeFit);
-
- QCOMPARE(s->matteColor(), QColor(Qt::yellow));
- QCOMPARE(s->isShowRenderStats(), false);
- QCOMPARE(s->shadeMode(), Q3DSViewerSettings::ShadeModeShadedWireframe);
- QCOMPARE(s->scaleMode(), Q3DSViewerSettings::ScaleModeFit);
-
- QCOMPARE(spy1.count(), 2);
- QCOMPARE(spy2.count(), 2);
- QCOMPARE(spy3.count(), 3);
- QCOMPARE(spy4.count(), 3);
-
- image2 = m_viewer->grabFramebuffer();
-
- s->load(QStringLiteral("testViewer"), QStringLiteral("The Qt Company"),
- QStringLiteral("tst_q3dsurfaceviewer"));
-
- QCOMPARE(s->matteColor(), QColor(Qt::cyan));
- QCOMPARE(s->isShowRenderStats(), true);
- QCOMPARE(s->shadeMode(), Q3DSViewerSettings::ShadeModeShaded);
- QCOMPARE(s->scaleMode(), Q3DSViewerSettings::ScaleModeFill);
-
- QCOMPARE(spy1.count(), 3);
- QCOMPARE(spy2.count(), 3);
- QCOMPARE(spy3.count(), 4);
- QCOMPARE(spy4.count(), 4);
-
- QImage image3 = m_viewer->grabFramebuffer();
- QVERIFY(image1 != image2);
- QVERIFY(image3 != image2);
- QVERIFY(image1 == image3);
-
- // Clean up the settings so they don't pollute the system (and we have clean slate next time)
- QSettings(QStringLiteral("The Qt Company"), QStringLiteral("tst_q3dwidget")).clear();
-}
-
-void tst_Q3DSWidget::testPresentation()
-{
- createWindowAndViewer(m_viewer, MULTISLIDE);
-
- m_viewer->setUpdateBehavior(QOpenGLWidget::PartialUpdate);
-
- m_viewer->settings()->setScaleMode(Q3DSViewerSettings::ScaleModeFill);
-
- QList<QVariant> args;
- Q3DSPresentation *p = m_viewer->presentation();
- QSignalSpy spy1(p, &Q3DSPresentation::slideEntered);
- QSignalSpy spy2(p, &Q3DSPresentation::slideExited);
- QVERIFY(spy1.isValid());
- QVERIFY(spy2.isValid());
-
- // There are three different "scenes":
- // The main Scene, three slides: S1, S2, S3
- // Two components on Scene.Layer:
- // Scene.Layer.Component1, two slides: C1S1, C1S2
- // Scene.Layer.Component2, two slides: C2S1, C2S2
- // The component slides also get enter when parent slide is entered, but they do not get
- // the corresponding exit if parent slide is exited.
- QString path = QStringLiteral("Scene");
- QString pathC1 = QStringLiteral("Scene.Layer.Component1");
- QString pathC2 = QStringLiteral("Scene.Layer.Component2");
- QPoint mainPoint(m_viewer->size().width() * 2 / 8, m_viewer->size().height() / 2);
- QPoint bgPoint(m_viewer->size().width() * 2 / 8, m_viewer->size().height() / 32);
- QPoint c1Point(m_viewer->size().width() * 5 / 8, m_viewer->size().height() / 2);
- QPoint c2Point(m_viewer->size().width() * 7 / 8, m_viewer->size().height() / 2);
-
- checkPixel(m_viewer, Qt::red, mainPoint);
- checkPixel(m_viewer, Qt::green, c1Point);
- checkPixel(m_viewer, Qt::yellow, c2Point);
-
- QCOMPARE(spy1.count(), 3);
- QCOMPARE(spy2.count(), 0);
-
- // String Attribute
- QImage image1 = m_viewer->grabFramebuffer();
- p->setAttribute(QStringLiteral("Scene.Layer.Text"),
- QStringLiteral("textstring"), QStringLiteral("Test!"));
- QImage image2 = m_viewer->grabFramebuffer();
- QTRY_VERIFY(image1 != image2);
-
- // Float Attribute
- p->setAttribute(QStringLiteral("Scene.Layer.Rect.Material"),
- QStringLiteral("diffuse.r"), 0.0);
- p->setAttribute(QStringLiteral("Scene.Layer.Rect.Material"),
- QStringLiteral("diffuse.g"), 1.0);
- p->setAttribute(QStringLiteral("Scene.Layer.Rect.Material"),
- QStringLiteral("diffuse.b"), 1.0);
-
- checkPixel(m_viewer, Qt::cyan, mainPoint);
- checkPixel(m_viewer, Qt::green, c1Point);
- checkPixel(m_viewer, Qt::yellow, c2Point);
-
- p->setAttribute(QStringLiteral("Scene.Layer.Rect.Material"),
- QStringLiteral("diffuse.r"), 1.0);
- p->setAttribute(QStringLiteral("Scene.Layer.Rect.Material"),
- QStringLiteral("diffuse.g"), 0.0);
- p->setAttribute(QStringLiteral("Scene.Layer.Rect.Material"),
- QStringLiteral("diffuse.b"), 0.0);
-
- checkPixel(m_viewer, Qt::red, mainPoint);
- checkPixel(m_viewer, Qt::green, c1Point);
- checkPixel(m_viewer, Qt::yellow, c2Point);
-
- // Bool Attribute
- checkPixel(m_viewer, Qt::yellow, bgPoint);
- p->setAttribute(QStringLiteral("Scene"), QStringLiteral("bgcolorenable"), false);
- checkPixel(m_viewer, Qt::black, bgPoint);
-
- // Slide changes
- p->goToSlide(path, 2);
- checkPixel(m_viewer, Qt::blue, mainPoint);
- checkPixel(m_viewer, Qt::blue, c1Point);
- checkPixel(m_viewer, Qt::blue, c2Point);
-
- QCOMPARE(spy1.count(), 4);
- QCOMPARE(spy2.count(), 1);
- args = spy1.last();
- QCOMPARE(args.at(0).toString(), path);
- QCOMPARE(args.at(1).toInt(), 2);
- QCOMPARE(args.at(2).toString(), QStringLiteral("S2"));
- args = spy2.last();
- QCOMPARE(args.at(0).toString(), path);
- QCOMPARE(args.at(1).toInt(), 1);
- QCOMPARE(args.at(2).toString(), QStringLiteral("S1"));
-
- // Time change
- p->goToTime(path, 7);
- checkPixel(m_viewer, Qt::black, mainPoint);
- QCOMPARE(spy1.count(), 4);
- QCOMPARE(spy2.count(), 1);
-
- // More complex slide changes
- // Changing slide that is not visible should not trigger enter signals
- // The slides should still change, though, and become visible later when we switch back to S1
- p->goToSlide(pathC1, QStringLiteral("C1S2"));
- p->goToSlide(pathC2, QStringLiteral("C2S2"));
- QCOMPARE(spy1.count(), 4);
- QCOMPARE(spy2.count(), 1);
-
- p->goToSlide(path, QStringLiteral("S1"));
- checkPixel(m_viewer, Qt::red, mainPoint);
- checkPixel(m_viewer, Qt::cyan, c1Point);
- checkPixel(m_viewer, Qt::magenta, c2Point);
- QCOMPARE(spy1.count(), 7);
- QCOMPARE(spy2.count(), 2);
-
- p->goToSlide(pathC1, QStringLiteral("C1S1"));
- checkPixel(m_viewer, Qt::red, mainPoint);
- checkPixel(m_viewer, Qt::green, c1Point);
- checkPixel(m_viewer, Qt::magenta, c2Point);
- QCOMPARE(spy1.count(), 8);
- QCOMPARE(spy2.count(), 3);
-
- args = spy1.last();
- QCOMPARE(args.at(0).toString(), pathC1);
- QCOMPARE(args.at(1).toInt(), 1);
- QCOMPARE(args.at(2).toString(), QStringLiteral("C1S1"));
- args = spy2.last();
- QCOMPARE(args.at(0).toString(), pathC1);
- QCOMPARE(args.at(1).toInt(), 2);
- QCOMPARE(args.at(2).toString(), QStringLiteral("C1S2"));
-
- p->goToSlide(pathC2, QStringLiteral("C2S1"));
- checkPixel(m_viewer, Qt::red, mainPoint);
- checkPixel(m_viewer, Qt::green, c1Point);
- checkPixel(m_viewer, Qt::yellow, c2Point);
- QCOMPARE(spy1.count(), 9);
- QCOMPARE(spy2.count(), 4);
-
- args = spy1.last();
- QCOMPARE(args.at(0).toString(), pathC2);
- QCOMPARE(args.at(1).toInt(), 1);
- QCOMPARE(args.at(2).toString(), QStringLiteral("C2S1"));
- args = spy2.last();
- QCOMPARE(args.at(0).toString(), pathC2);
- QCOMPARE(args.at(1).toInt(), 2);
- QCOMPARE(args.at(2).toString(), QStringLiteral("C2S2"));
-
- p->goToSlide(path, true, true);
- checkPixel(m_viewer, Qt::blue, mainPoint);
- checkPixel(m_viewer, Qt::blue, c1Point);
- checkPixel(m_viewer, Qt::blue, c2Point);
- QCOMPARE(spy1.count(), 10);
- QCOMPARE(spy2.count(), 5);
-
- args = spy1.last();
- QCOMPARE(args.at(0).toString(), path);
- QCOMPARE(args.at(1).toInt(), 2);
- QCOMPARE(args.at(2).toString(), QStringLiteral("S2"));
- args = spy2.last();
- QCOMPARE(args.at(0).toString(), path);
- QCOMPARE(args.at(1).toInt(), 1);
- QCOMPARE(args.at(2).toString(), QStringLiteral("S1"));
-
- p->goToSlide(path, false, true);
- checkPixel(m_viewer, Qt::red, mainPoint);
- checkPixel(m_viewer, Qt::green, c1Point);
- checkPixel(m_viewer, Qt::yellow, c2Point);
- QCOMPARE(spy1.count(), 13);
- QCOMPARE(spy2.count(), 6);
-
- // No wrap, should not change
- p->goToSlide(path, false, false);
- checkPixel(m_viewer, Qt::red, mainPoint);
- checkPixel(m_viewer, Qt::green, c1Point);
- checkPixel(m_viewer, Qt::yellow, c2Point);
- QCOMPARE(spy1.count(), 13);
- QCOMPARE(spy2.count(), 6);
-
- // Should wrap
- p->goToSlide(path, false, true);
- checkPixel(m_viewer, Qt::green, mainPoint);
- checkPixel(m_viewer, Qt::green, c1Point);
- checkPixel(m_viewer, Qt::green, c2Point);
- QCOMPARE(spy1.count(), 14);
- QCOMPARE(spy2.count(), 7);
-
- // No wrap, should not change
- p->goToSlide(path, true, false);
- checkPixel(m_viewer, Qt::green, mainPoint);
- checkPixel(m_viewer, Qt::green, c1Point);
- checkPixel(m_viewer, Qt::green, c2Point);
- QCOMPARE(spy1.count(), 14);
- QCOMPARE(spy2.count(), 7);
-
- // Should wrap
- p->goToSlide(path, true, true);
- checkPixel(m_viewer, Qt::red, mainPoint);
- checkPixel(m_viewer, Qt::green, c1Point);
- checkPixel(m_viewer, Qt::yellow, c2Point);
- QCOMPARE(spy1.count(), 17);
- QCOMPARE(spy2.count(), 8);
-}
-
-void tst_Q3DSWidget::testPresentationActivation()
-{
- createWindowAndViewer(m_viewer, ANIMATION);
-
- m_viewer->settings()->setScaleMode(Q3DSViewerSettings::ScaleModeFill);
-
- {
- // Grab two images two seconds apart to verify animation is happening
- QImage image1 = m_viewer->grabFramebuffer();
- QTest::qWait(2000);
- QImage image2 = m_viewer->grabFramebuffer();
- QVERIFY(image1 != image2);
- }
-
- m_viewer->presentation()->setPresentationActive(QStringLiteral("animation"), false);
-
- {
- // Grab two images two seconds apart to verify animation has stopped
- QImage image1 = m_viewer->grabFramebuffer();
- QTest::qWait(2000);
- QImage image2 = m_viewer->grabFramebuffer();
- QVERIFY(image1 == image2);
- }
-
- m_viewer->presentation()->setPresentationActive(QStringLiteral("animation"), true);
-
- {
- // Grab two images two seconds apart to verify animation is happening
- QImage image1 = m_viewer->grabFramebuffer();
- QTest::qWait(2000);
- QImage image2 = m_viewer->grabFramebuffer();
- QVERIFY(image1 != image2);
- }
-}
-
-void tst_Q3DSWidget::testScene()
-{
- createWindowAndViewer(m_viewer, MULTISLIDE);
-
- m_viewer->settings()->setScaleMode(Q3DSViewerSettings::ScaleModeFill);
-
- QString path = QStringLiteral("Scene");
- QString pathC1 = QStringLiteral("Scene.Layer.Component1");
- QString pathC2 = QStringLiteral("Scene.Layer.Component2");
-
- Q3DSPresentation *p = m_viewer->presentation();
- Q3DSSceneElement *scene = new Q3DSSceneElement(path);
- Q3DSSceneElement *sceneC1 = new Q3DSSceneElement(pathC1);
- Q3DSSceneElement *sceneC2 = new Q3DSSceneElement(pathC2);
- QSignalSpy spy1(scene, &Q3DSSceneElement::currentSlideIndexChanged);
- QSignalSpy spy2(scene, &Q3DSSceneElement::previousSlideIndexChanged);
- QSignalSpy spy3(scene, &Q3DSSceneElement::currentSlideNameChanged);
- QSignalSpy spy4(scene, &Q3DSSceneElement::previousSlideNameChanged);
- QSignalSpy spy5(scene, &Q3DSSceneElement::elementPathChanged);
- QSignalSpy spy6(sceneC1, &Q3DSSceneElement::currentSlideIndexChanged);
- QSignalSpy spy7(sceneC1, &Q3DSSceneElement::previousSlideIndexChanged);
- QSignalSpy spy8(sceneC1, &Q3DSSceneElement::currentSlideNameChanged);
- QSignalSpy spy9(sceneC1, &Q3DSSceneElement::previousSlideNameChanged);
- QSignalSpy spy10(sceneC1, &Q3DSSceneElement::elementPathChanged);
- QSignalSpy spy11(sceneC2, &Q3DSSceneElement::currentSlideIndexChanged);
- QSignalSpy spy12(sceneC2, &Q3DSSceneElement::previousSlideIndexChanged);
- QSignalSpy spy13(sceneC2, &Q3DSSceneElement::currentSlideNameChanged);
- QSignalSpy spy14(sceneC2, &Q3DSSceneElement::previousSlideNameChanged);
- QSignalSpy spy15(sceneC2, &Q3DSSceneElement::elementPathChanged);
- QVERIFY(spy1.isValid());
- QVERIFY(spy2.isValid());
- QVERIFY(spy3.isValid());
- QVERIFY(spy4.isValid());
- QVERIFY(spy5.isValid());
- QVERIFY(spy6.isValid());
- QVERIFY(spy7.isValid());
- QVERIFY(spy8.isValid());
- QVERIFY(spy9.isValid());
- QVERIFY(spy10.isValid());
- QVERIFY(spy11.isValid());
- QVERIFY(spy12.isValid());
- QVERIFY(spy13.isValid());
- QVERIFY(spy14.isValid());
- QVERIFY(spy15.isValid());
-
- // Defaults
- QCOMPARE(scene->currentSlideIndex(), 0);
- QCOMPARE(scene->previousSlideIndex(), 0);
- QCOMPARE(scene->currentSlideName(), QStringLiteral(""));
- QCOMPARE(scene->previousSlideName(), QStringLiteral(""));
- QCOMPARE(scene->elementPath(), path);
-
- checkPixel(m_viewer, Qt::red);
-
- // Ensure the first slide enter events come before we register so they don't muddle the waters
- QGuiApplication::processEvents();
-
- p->registerElement(scene);
- p->registerElement(sceneC1);
- p->registerElement(sceneC2);
-
- QCOMPARE(scene->currentSlideIndex(), 1);
- QCOMPARE(scene->previousSlideIndex(), 0);
- QCOMPARE(scene->currentSlideName(), QStringLiteral("S1"));
- QCOMPARE(scene->previousSlideName(), QStringLiteral(""));
- QCOMPARE(scene->elementPath(), path);
-
- p->goToSlide(path, QStringLiteral("S2"));
- checkPixel(m_viewer, Qt::blue);
- QGuiApplication::processEvents();
-
- QCOMPARE(spy1.count(), 1);
- QCOMPARE(spy2.count(), 1);
- QCOMPARE(spy3.count(), 1);
- QCOMPARE(spy4.count(), 1);
- QCOMPARE(spy5.count(), 0);
- QCOMPARE(spy6.count(), 0);
- QCOMPARE(spy7.count(), 0);
- QCOMPARE(spy8.count(), 0);
- QCOMPARE(spy9.count(), 0);
- QCOMPARE(spy10.count(), 0);
- QCOMPARE(spy11.count(), 0);
- QCOMPARE(spy12.count(), 0);
- QCOMPARE(spy13.count(), 0);
- QCOMPARE(spy14.count(), 0);
- QCOMPARE(spy15.count(), 0);
-
- p->goToSlide(path, QStringLiteral("S1"));
- checkPixel(m_viewer, Qt::red);
- QGuiApplication::processEvents();
-
- QCOMPARE(spy1.count(), 2);
- QCOMPARE(spy2.count(), 2);
- QCOMPARE(spy3.count(), 2);
- QCOMPARE(spy4.count(), 2);
- QCOMPARE(spy5.count(), 0);
- QCOMPARE(spy6.count(), 0);
- // Getting previous slide change without getting current slide change seems illogical here,
- // but that's how the internal viewer logic for previous slide works. It makes sense when
- // you consider the fact that we always get enter events for child slides when parent slide
- // is entered.
- QCOMPARE(spy7.count(), 1);
- QCOMPARE(spy8.count(), 0);
- QCOMPARE(spy9.count(), 1);
- QCOMPARE(spy10.count(), 0);
- QCOMPARE(spy11.count(), 0);
- QCOMPARE(spy12.count(), 1);
- QCOMPARE(spy13.count(), 0);
- QCOMPARE(spy14.count(), 1);
- QCOMPARE(spy15.count(), 0);
-
- p->goToSlide(pathC1, QStringLiteral("C1S2"));
- checkPixel(m_viewer, Qt::red);
- QGuiApplication::processEvents();
-
- QCOMPARE(spy1.count(), 2);
- QCOMPARE(spy2.count(), 2);
- QCOMPARE(spy3.count(), 2);
- QCOMPARE(spy4.count(), 2);
- QCOMPARE(spy5.count(), 0);
- QCOMPARE(spy6.count(), 1);
- QCOMPARE(spy7.count(), 1);
- QCOMPARE(spy8.count(), 1);
- QCOMPARE(spy9.count(), 1);
- QCOMPARE(spy10.count(), 0);
- QCOMPARE(spy11.count(), 0);
- QCOMPARE(spy12.count(), 1);
- QCOMPARE(spy13.count(), 0);
- QCOMPARE(spy14.count(), 1);
- QCOMPARE(spy15.count(), 0);
-
- p->goToSlide(pathC2, QStringLiteral("C2S2"));
- checkPixel(m_viewer, Qt::red);
- QGuiApplication::processEvents();
-
- QCOMPARE(spy1.count(), 2);
- QCOMPARE(spy2.count(), 2);
- QCOMPARE(spy3.count(), 2);
- QCOMPARE(spy4.count(), 2);
- QCOMPARE(spy5.count(), 0);
- QCOMPARE(spy6.count(), 1);
- QCOMPARE(spy7.count(), 1);
- QCOMPARE(spy8.count(), 1);
- QCOMPARE(spy9.count(), 1);
- QCOMPARE(spy10.count(), 0);
- QCOMPARE(spy11.count(), 1);
- QCOMPARE(spy12.count(), 1);
- QCOMPARE(spy13.count(), 1);
- QCOMPARE(spy14.count(), 1);
- QCOMPARE(spy15.count(), 0);
-
- // Subscenes revert to original slides when parent is re-entered
- p->goToSlide(path, QStringLiteral("S2"));
- checkPixel(m_viewer, Qt::blue);
- QGuiApplication::processEvents();
-
- QCOMPARE(spy1.count(), 3);
- QCOMPARE(spy2.count(), 3);
- QCOMPARE(spy3.count(), 3);
- QCOMPARE(spy4.count(), 3);
- QCOMPARE(spy5.count(), 0);
- QCOMPARE(spy6.count(), 1);
- QCOMPARE(spy7.count(), 1);
- QCOMPARE(spy8.count(), 1);
- QCOMPARE(spy9.count(), 1);
- QCOMPARE(spy10.count(), 0);
- QCOMPARE(spy11.count(), 1);
- QCOMPARE(spy12.count(), 1);
- QCOMPARE(spy13.count(), 1);
- QCOMPARE(spy14.count(), 1);
- QCOMPARE(spy15.count(), 0);
-
- p->goToSlide(path, QStringLiteral("S1"));
- checkPixel(m_viewer, Qt::red);
- QGuiApplication::processEvents();
-
- QCOMPARE(spy1.count(), 4);
- QCOMPARE(spy2.count(), 4);
- QCOMPARE(spy3.count(), 4);
- QCOMPARE(spy4.count(), 4);
- QCOMPARE(spy5.count(), 0);
- QCOMPARE(spy6.count(), 2);
- QCOMPARE(spy7.count(), 2);
- QCOMPARE(spy8.count(), 2);
- QCOMPARE(spy9.count(), 2);
- QCOMPARE(spy10.count(), 0);
- QCOMPARE(spy11.count(), 2);
- QCOMPARE(spy12.count(), 2);
- QCOMPARE(spy13.count(), 2);
- QCOMPARE(spy14.count(), 2);
- QCOMPARE(spy15.count(), 0);
-
- p->unregisterElement(scene);
- p->unregisterElement(sceneC1);
- p->unregisterElement(sceneC2);
-
- // No more signals after unregistering
- p->goToSlide(path, QStringLiteral("S2"));
- checkPixel(m_viewer, Qt::blue);
- QGuiApplication::processEvents();
-
- QCOMPARE(spy1.count(), 4);
- QCOMPARE(spy2.count(), 4);
- QCOMPARE(spy3.count(), 4);
- QCOMPARE(spy4.count(), 4);
- QCOMPARE(spy5.count(), 0);
- QCOMPARE(spy6.count(), 2);
- QCOMPARE(spy7.count(), 2);
- QCOMPARE(spy8.count(), 2);
- QCOMPARE(spy9.count(), 2);
- QCOMPARE(spy10.count(), 0);
- QCOMPARE(spy11.count(), 2);
- QCOMPARE(spy12.count(), 2);
- QCOMPARE(spy13.count(), 2);
- QCOMPARE(spy14.count(), 2);
- QCOMPARE(spy15.count(), 0);
-
- // Reregister
- p->registerElement(scene);
- p->goToSlide(path, QStringLiteral("S1"));
- checkPixel(m_viewer, Qt::red);
- QGuiApplication::processEvents();
-
- QCOMPARE(spy1.count(), 5);
- QCOMPARE(spy2.count(), 5);
- QCOMPARE(spy3.count(), 5);
- QCOMPARE(spy4.count(), 5);
- QCOMPARE(spy5.count(), 0);
-
- QCOMPARE(scene->currentSlideIndex(), 1);
- QCOMPARE(scene->previousSlideIndex(), 2);
- QCOMPARE(scene->currentSlideName(), QStringLiteral("S1"));
- QCOMPARE(scene->previousSlideName(), QStringLiteral("S2"));
- QCOMPARE(scene->elementPath(), path);
-
- // Change elementpath
- scene->setElementPath(pathC1);
- checkPixel(m_viewer, Qt::red);
- QGuiApplication::processEvents();
-
- QCOMPARE(spy1.count(), 5);
- QCOMPARE(spy2.count(), 5);
- QCOMPARE(spy3.count(), 5);
- QCOMPARE(spy4.count(), 5);
- QCOMPARE(spy5.count(), 1);
-
- QCOMPARE(scene->currentSlideIndex(), 1);
- QCOMPARE(scene->previousSlideIndex(), 1);
- // Having current and previous slides the same seems weird, but that's how the slide
- // logic works internally.
- QCOMPARE(scene->currentSlideName(), QStringLiteral("C1S1"));
- QCOMPARE(scene->previousSlideName(), QStringLiteral("C1S1"));
- QCOMPARE(scene->elementPath(), pathC1);
-
- p->goToSlide(pathC1, QStringLiteral("C1S2"));
- checkPixel(m_viewer, Qt::red);
- QGuiApplication::processEvents();
-
- QCOMPARE(spy1.count(), 6);
- QCOMPARE(spy2.count(), 5);
- QCOMPARE(spy3.count(), 6);
- QCOMPARE(spy4.count(), 5);
- QCOMPARE(spy5.count(), 1);
-
- p->goToSlide(path, QStringLiteral("S2"));
- checkPixel(m_viewer, Qt::blue);
- QGuiApplication::processEvents();
-
- QCOMPARE(spy1.count(), 6);
- QCOMPARE(spy2.count(), 5);
- QCOMPARE(spy3.count(), 6);
- QCOMPARE(spy4.count(), 5);
- QCOMPARE(spy5.count(), 1);
-}
-
-void tst_Q3DSWidget::testMouseInput()
-{
- createWindowAndViewer(m_viewer, MOUSE);
-
- m_viewer->settings()->setScaleMode(Q3DSViewerSettings::ScaleModeFill);
-
- QPoint point1(m_viewer->size().width() * 1 / 4, m_viewer->size().height() / 2);
- QPoint point2(m_viewer->size().width() * 3 / 4, m_viewer->size().height() / 2);
-
- checkPixel(m_viewer, Qt::blue, point1);
- checkPixel(m_viewer, Qt::red, point2);
-
- QMouseEvent e1(QEvent::MouseButtonPress, point1, Qt::LeftButton, Qt::LeftButton,
- Qt::NoModifier);
- m_viewer->presentation()->mousePressEvent(&e1);
-
- checkPixel(m_viewer, Qt::green, point1);
- checkPixel(m_viewer, Qt::red, point2);
-
- QMouseEvent e2(QEvent::MouseButtonRelease, point1, Qt::LeftButton, Qt::LeftButton,
- Qt::NoModifier);
- m_viewer->presentation()->mouseReleaseEvent(&e2);
-
- checkPixel(m_viewer, Qt::blue, point1);
- checkPixel(m_viewer, Qt::red, point2);
-
- QMouseEvent e3(QEvent::MouseButtonPress, point2, Qt::LeftButton, Qt::LeftButton,
- Qt::NoModifier);
- m_viewer->presentation()->mousePressEvent(&e3);
-
- checkPixel(m_viewer, Qt::blue, point1);
- checkPixel(m_viewer, Qt::blue, point2);
-
- QMouseEvent e4(QEvent::MouseButtonRelease, point2, Qt::LeftButton, Qt::LeftButton,
- Qt::NoModifier);
- m_viewer->presentation()->mouseReleaseEvent(&e4);
-
- checkPixel(m_viewer, Qt::blue, point1);
- checkPixel(m_viewer, Qt::red, point2);
-
- // Note: No way yet to hook mouse move into anything in the presentation
-}
-
-QTEST_MAIN(tst_Q3DSWidget)
-
-#include "tst_q3dswidget.moc"
diff --git a/tests/auto/studio3d/studio3d.pro b/tests/auto/studio3d/studio3d.pro
index bc866821..e92019f0 100644
--- a/tests/auto/studio3d/studio3d.pro
+++ b/tests/auto/studio3d/studio3d.pro
@@ -1,5 +1,4 @@
TEMPLATE = subdirs
SUBDIRS += \
- q3dssurfaceviewer \
- q3dswidget
+ q3dssurfaceviewer