From 3d2630a0f36dc664a7dde671ae7f660cad77b317 Mon Sep 17 00:00:00 2001 From: Jari Karppinen Date: Fri, 31 May 2019 11:15:46 +0300 Subject: Add missing error string to SurfaceViewer API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QT3DS-3532 Change-Id: Ia2f9f70daf55ac57e71c0941da8c510f1872cff5 Reviewed-by: Miikka Heikkinen Reviewed-by: Pasi Keränen Reviewed-by: Tomi Korpipää --- .../src/api/studio3d/q3dssurfaceviewer.cpp | 29 +++++++++++++++++++--- .../src/api/studio3d/q3dssurfaceviewer.h | 6 +++-- .../src/api/studio3d/q3dssurfaceviewer_p.h | 2 ++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.cpp b/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.cpp index 23782f2f..401c461d 100644 --- a/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.cpp +++ b/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.cpp @@ -280,6 +280,14 @@ int Q3DSSurfaceViewer::fboId() const return d_ptr->m_fboId; } +/*! + Returns the error string. +*/ +QString Q3DSSurfaceViewer::error() const +{ + return d_ptr->m_error; +} + /*! Returns the surface given in initialization. @@ -442,15 +450,15 @@ bool Q3DSSurfaceViewerPrivate::initialize(QSurface *surface, QOpenGLContext *con Q_ASSERT(surface); if (m_presentation->source().isEmpty()) { - qWarning("Failed to initialize Q3DSSurfaceViewer," - " presentation source must be set before calling initialize()"); + setError(QStringLiteral("Failed to initialize Q3DSSurfaceViewer," + " presentation source must be set before calling initialize()")); return false; } QFileInfo info(Q3DSUtils::urlToLocalFileOrQrc(m_presentation->source())); if (!info.exists()) { - qWarning() << "Failed to initialize Q3DSSurfaceViewer, the presentation doesn't exist:" - << m_presentation->source().toString(); + setError(QStringLiteral("Failed to initialize Q3DSSurfaceViewer, the presentation doesn't exist: %1") + .arg(m_presentation->source().toString())); return false; } @@ -591,6 +599,18 @@ void Q3DSSurfaceViewerPrivate::reset() } } +/*! + * \internal + */ +void Q3DSSurfaceViewerPrivate::setError(const QString &error) +{ + if (m_error != error) { + m_error = error; + qWarning() << error; + Q_EMIT q_ptr->errorChanged(); + } +} + /*! * \internal */ @@ -621,6 +641,7 @@ bool Q3DSSurfaceViewerPrivate::initializeRuntime() m_presentation->variantList(), m_presentation->delayedLoading(), m_presentation->d_ptr->streamProxy())) { + setError(m_viewerApp->error()); releaseRuntime(); qWarning("Failed to initialize runtime"); return false; diff --git a/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.h b/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.h index 5c166af9..42be5c2c 100644 --- a/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.h +++ b/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.h @@ -51,8 +51,7 @@ class Q_STUDIO3D_EXPORT Q3DSSurfaceViewer : public QObject Q_OBJECT Q_DECLARE_PRIVATE(Q3DSSurfaceViewer) - // #TODO: QT3DS-3532 SurfaceViewer API missing error string - //Q_PROPERTY(QString error READ error NOTIFY errorChanged) + Q_PROPERTY(QString error READ error NOTIFY errorChanged) Q_PROPERTY(bool running READ isRunning NOTIFY runningChanged) Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY sizeChanged) Q_PROPERTY(bool autoSize READ autoSize WRITE setAutoSize NOTIFY autoSizeChanged) @@ -91,6 +90,8 @@ public: void setQmlEngine(QQmlEngine *qmlEngine); QString presentationId() const; + QString error() const; + public Q_SLOTS: void update(); void setPresentationId(const QString &id); @@ -99,6 +100,7 @@ Q_SIGNALS: void presentationLoaded(); void presentationReady(); void frameUpdate(); + void errorChanged(); void presentationIdChanged(const QString &id); void sizeChanged(const QSize &size); diff --git a/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer_p.h b/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer_p.h index fc6b4cc8..624a368c 100644 --- a/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer_p.h +++ b/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer_p.h @@ -77,6 +77,7 @@ protected: private: void reset(); + void setError(const QString &error); bool initializeRuntime(); void releaseRuntime(); void resetUpdateTimer(); @@ -98,6 +99,7 @@ private: QString m_id; QElapsedTimer m_startupTimer; QQmlEngine *qmlEngine = nullptr; + QString m_error; }; QT_END_NAMESPACE -- cgit v1.2.3