diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2019-06-04 17:50:00 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2019-06-05 11:55:33 +0300 |
commit | 059007c11ca4ed8ed60ab6f9d203e9d81f3e3379 (patch) | |
tree | c7b40b8028af4aaf7917fcc13a9e9dda4f72c577 | |
parent | 8b8ad9d1245e6ce1f97effa82ee44bd5fca416a0 (diff) |
Add accessors for lists of created elements/materials/meshes
Task-number: QT3DS-3618
Change-Id: I3b58ac2d2099836f142ef1a3b25a333a1023582b
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Reviewed-by: Jari Karppinen <jari.karppinen@qt.io>
Reviewed-by: Antti Määttä <antti.maatta@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Pasi Keränen <pasi.keranen@qt.io>
5 files changed, 172 insertions, 25 deletions
diff --git a/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.cpp b/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.cpp index 2f63efda..611daef1 100644 --- a/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.cpp +++ b/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.cpp @@ -147,7 +147,7 @@ void Q3DSPresentation::setSource(const QUrl &source) } /*! - \qmlproperty variant Presentation::variantList + \qmlproperty list<string> Presentation::variantList Holds a list of (variant group):(variant) tags that are loaded when the \c{source} property is set. If this list is left empty (default), no variant @@ -839,6 +839,36 @@ void Q3DSPresentation::deleteElements(const QStringList &elementPaths) QStringList *theElementPaths = new QStringList(elementPaths); d_ptr->m_commandQueue->queueCommand(CommandType_DeleteElements, theElementPaths); } + for (const auto &elementPath : elementPaths) + d_ptr->m_createdElements.removeAll(elementPath); +} + +/*! + \qmlproperty list<string> Presentation::createdElements + + This property contains a list of all dynamically created elements on this presentation. + + This property is read-only. + + \note Elements can only be dynamically created via C++ API. + + \sa createElement + \sa createElements +*/ + +/*! + \property Q3DSPresentation::createdElements + + This property contains a list of all dynamically created elements on this presentation. + + This property is read-only. + + \sa createElement + \sa createElements +*/ +QStringList Q3DSPresentation::createdElements() const +{ + return d_ptr->m_createdElements; } /*! @@ -939,6 +969,36 @@ void Q3DSPresentation::deleteMaterials(const QStringList &materialNames) QStringList *theMaterialNames = new QStringList(materialNames); d_ptr->m_commandQueue->queueCommand(CommandType_DeleteMaterials, theMaterialNames); } + for (const auto &name : materialNames) + d_ptr->m_createdMaterials.removeAll(name); +} + +/*! + \qmlproperty list<string> Presentation::createdMaterials + + This property contains a list of all dynamically created materials on this presentation. + + This property is read-only. + + \note Materials can only be dynamically created via C++ API. + + \sa createMaterial + \sa createMaterials +*/ + +/*! + \property Q3DSPresentation::createdMaterials + + This property contains a list of all dynamically created materials on this presentation. + + This property is read-only. + + \sa createMaterial + \sa createMaterials +*/ +QStringList Q3DSPresentation::createdMaterials() const +{ + return d_ptr->m_createdMaterials; } /*! @@ -1017,6 +1077,36 @@ void Q3DSPresentation::deleteMeshes(const QStringList &meshNames) QStringList *theMeshNames = new QStringList(meshNames); d_ptr->m_commandQueue->queueCommand(CommandType_DeleteMeshes, theMeshNames); } + for (const auto &name : meshNames) + d_ptr->m_createdMeshes.removeAll(name); +} + +/*! + \qmlproperty list<string> Presentation::createdMeshes + + This property contains a list of all dynamically created meshes on this presentation. + + This property is read-only. + + \note Meshes can only be dynamically created via C++ API. + + \sa createMesh + \sa createMeshes +*/ + +/*! + \property Q3DSPresentation::createdMeshes + + This property contains a list of all dynamically created meshes on this presentation. + + This property is read-only. + + \sa createMesh + \sa createMeshes +*/ +QStringList Q3DSPresentation::createdMeshes() const +{ + return d_ptr->m_createdMeshes; } /*! @@ -1309,11 +1399,11 @@ void Q3DSPresentationPrivate::setViewerApp(Q3DSViewer::Q3DSViewerApp *app, bool connect(app, &Q3DSViewer::Q3DSViewerApp::SigDataOutputValueUpdated, this, &Q3DSPresentationPrivate::handleDataOutputValueUpdate); connect(app, &Q3DSViewer::Q3DSViewerApp::SigElementsCreated, - q_ptr, &Q3DSPresentation::elementsCreated); + this, &Q3DSPresentationPrivate::handleElementsCreated); connect(app, &Q3DSViewer::Q3DSViewerApp::SigMaterialsCreated, - q_ptr, &Q3DSPresentation::materialsCreated); + this, &Q3DSPresentationPrivate::handleMaterialsCreated); connect(app, &Q3DSViewer::Q3DSViewerApp::SigMeshesCreated, - q_ptr, &Q3DSPresentation::meshesCreated); + this, &Q3DSPresentationPrivate::handleMeshesCreated); } if (oldApp) { disconnect(oldApp, &Q3DSViewer::Q3DSViewerApp::SigSlideEntered, @@ -1325,11 +1415,11 @@ void Q3DSPresentationPrivate::setViewerApp(Q3DSViewer::Q3DSViewerApp *app, bool disconnect(oldApp, &Q3DSViewer::Q3DSViewerApp::SigDataOutputValueUpdated, this, &Q3DSPresentationPrivate::handleDataOutputValueUpdate); disconnect(oldApp, &Q3DSViewer::Q3DSViewerApp::SigElementsCreated, - q_ptr, &Q3DSPresentation::elementsCreated); + this, &Q3DSPresentationPrivate::handleElementsCreated); disconnect(oldApp, &Q3DSViewer::Q3DSViewerApp::SigMaterialsCreated, - q_ptr, &Q3DSPresentation::materialsCreated); + this, &Q3DSPresentationPrivate::handleMaterialsCreated); disconnect(oldApp, &Q3DSViewer::Q3DSViewerApp::SigMeshesCreated, - q_ptr, &Q3DSPresentation::meshesCreated); + this, &Q3DSPresentationPrivate::handleMeshesCreated); } } } @@ -1973,4 +2063,31 @@ void Q3DSPresentationPrivate::handleDataOutputValueUpdate(const QString &name, node->setValue(newValue); } +void Q3DSPresentationPrivate::handleElementsCreated(const QStringList &elementPaths, + const QString &error) +{ + if (error.isEmpty()) + m_createdElements << elementPaths; + + Q_EMIT q_ptr->elementsCreated(elementPaths, error); +} + +void Q3DSPresentationPrivate::handleMaterialsCreated(const QStringList &materialNames, + const QString &error) +{ + if (error.isEmpty()) + m_createdMaterials << materialNames; + + Q_EMIT q_ptr->materialsCreated(materialNames, error); +} + +void Q3DSPresentationPrivate::handleMeshesCreated(const QStringList &meshNames, + const QString &error) +{ + if (error.isEmpty()) + m_createdMeshes << meshNames; + + Q_EMIT q_ptr->meshesCreated(meshNames, error); +} + QT_END_NAMESPACE diff --git a/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.h b/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.h index 03283a9e..04faf0d0 100644 --- a/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.h +++ b/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.h @@ -55,6 +55,9 @@ class Q_STUDIO3D_EXPORT Q3DSPresentation : public QObject Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) Q_PROPERTY(QStringList variantList READ variantList WRITE setVariantList NOTIFY variantListChanged) Q_PROPERTY(bool delayedLoading READ delayedLoading WRITE setDelayedLoading NOTIFY delayedLoadingChanged) + Q_PROPERTY(QStringList createdElements READ createdElements NOTIFY elementsCreated) + Q_PROPERTY(QStringList createdMaterials READ createdMaterials NOTIFY materialsCreated) + Q_PROPERTY(QStringList createdMeshes READ createdMeshes NOTIFY meshesCreated) public: explicit Q3DSPresentation(QObject *parent = nullptr); @@ -101,14 +104,19 @@ public: const QVector<QHash<QString, QVariant>> &properties); void deleteElement(const QString &elementPath); void deleteElements(const QStringList &elementPaths); + QStringList createdElements() const; + void createMaterial(const QString &materialDefinition, const QString &subPresId = {}); void createMaterials(const QStringList &materialDefinitions, const QString &subPresId = {}); void deleteMaterial(const QString &materialName); void deleteMaterials(const QStringList &materialNames); + QStringList createdMaterials() const; + void createMesh(const QString &meshName, const Q3DSGeometry &geometry); void createMeshes(const QHash<QString, const Q3DSGeometry *> &meshData); void deleteMesh(const QString &meshName); void deleteMeshes(const QStringList &meshNames); + QStringList createdMeshes() const; public Q_SLOTS: void setSource(const QUrl &source); diff --git a/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation_p.h b/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation_p.h index c30eb82d..59b9f383 100644 --- a/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation_p.h +++ b/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation_p.h @@ -98,6 +98,9 @@ public: public Q_SLOTS: void handleSlideEntered(const QString &elementPath, unsigned int index, const QString &name); void handleDataOutputValueUpdate(const QString &name, const QVariant &newValue); + void handleElementsCreated(const QStringList &elementPaths, const QString &error); + void handleMaterialsCreated(const QStringList &materialNames, const QString &error); + void handleMeshesCreated(const QStringList &meshNames, const QString &error); public: Q3DSPresentation *q_ptr; @@ -112,6 +115,9 @@ private: QStringList m_variantList; ViewerQmlStreamProxy *m_streamProxy; bool m_delayedLoading; + QStringList m_createdElements; + QStringList m_createdMaterials; + QStringList m_createdMeshes; friend class Q3DSStudio3D; }; diff --git a/src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsstudio3d.cpp b/src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsstudio3d.cpp index 3d48babc..5a460895 100644 --- a/src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsstudio3d.cpp +++ b/src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsstudio3d.cpp @@ -372,16 +372,16 @@ QQuickFramebufferObject::Renderer *Q3DSStudio3D::createRenderer() const m_presentation->d_ptr, &Q3DSPresentationPrivate::handleSlideEntered); connect(renderer, &Q3DSRenderer::dataOutputValueUpdated, m_presentation->d_ptr, &Q3DSPresentationPrivate::handleDataOutputValueUpdate); + connect(renderer, &Q3DSRenderer::elementsCreated, + m_presentation->d_ptr, &Q3DSPresentationPrivate::handleElementsCreated); + connect(renderer, &Q3DSRenderer::materialsCreated, + m_presentation->d_ptr, &Q3DSPresentationPrivate::handleMaterialsCreated); + connect(renderer, &Q3DSRenderer::meshesCreated, + m_presentation->d_ptr, &Q3DSPresentationPrivate::handleMeshesCreated); connect(renderer, &Q3DSRenderer::exitSlide, m_presentation, &Q3DSPresentation::slideExited); connect(renderer, &Q3DSRenderer::customSignalEmitted, m_presentation, &Q3DSPresentation::customSignalEmitted); - connect(renderer, &Q3DSRenderer::elementsCreated, - m_presentation, &Q3DSPresentation::elementsCreated); - connect(renderer, &Q3DSRenderer::materialsCreated, - m_presentation, &Q3DSPresentation::materialsCreated); - connect(renderer, &Q3DSRenderer::meshesCreated, - m_presentation, &Q3DSPresentation::meshesCreated); connect(renderer, &Q3DSRenderer::requestResponse, this, &Q3DSStudio3D::requestResponseHandler); connect(renderer, &Q3DSRenderer::presentationLoaded, diff --git a/tests/auto/viewer/tst_qt3dsviewer.cpp b/tests/auto/viewer/tst_qt3dsviewer.cpp index 6f8be09c..d38e0207 100644 --- a/tests/auto/viewer/tst_qt3dsviewer.cpp +++ b/tests/auto/viewer/tst_qt3dsviewer.cpp @@ -192,10 +192,8 @@ void tst_qt3dsviewer::testCreateElement() QObject::connect(m_presentation, &Q3DSPresentation::elementsCreated, [this](const QStringList &elementNames, const QString &error) { QCOMPARE(error, QString()); - for (auto &elementName : elementNames) { - if (!m_createdElements.contains(elementName)) - QVERIFY(false); - } + for (const auto &elementName : elementNames) + QVERIFY(m_createdElements.contains(elementName)); }); auto loadMatDefFile = [&](const QString &fileName) -> QString { @@ -212,9 +210,12 @@ void tst_qt3dsviewer::testCreateElement() QString md = loadMatDefFile(QStringLiteral( ":/scenes/simple_cube_animation/materials/Basic Red.materialdef")); m_presentation->createMaterial(md); + m_createdMaterials << QStringLiteral("materials/Basic Red"); md = loadMatDefFile(QStringLiteral( ":/scenes/simple_cube_animation/materials/Basic Green.materialdef")); m_presentation->createMaterial(md); + m_createdMaterials << QStringLiteral("materials/Basic Green"); + QHash<QString, QVariant> data; data.insert(QStringLiteral("name"), QStringLiteral("New Cylinder")); @@ -331,8 +332,7 @@ void tst_qt3dsviewer::testCreateElement() // Remove dynamically added object QTimer::singleShot(3000, [&]() { m_presentation->deleteElement(QStringLiteral("Scene.Layer.Sphere To Delete")); - // Don't remove the deleted element from createdElements to test removing already deleted - // element later when everything is cleaned up. + m_createdElements.removeOne(QStringLiteral("Scene.Layer.Sphere To Delete")); }); // Create objects to slides 1 and 2 while slide 2 is executing @@ -388,6 +388,10 @@ void tst_qt3dsviewer::testCreateElement() QTest::qWait(500); QCOMPARE(spyElemCreated.count(), 9); + const QStringList createdElements = m_presentation->createdElements(); + QCOMPARE(createdElements.size(), m_createdElements.size()); + for (const auto &elementName : createdElements) + QVERIFY(m_createdElements.contains(elementName)); deleteCreated(); // Switch to slide 1 @@ -436,8 +440,9 @@ void tst_qt3dsviewer::testCreateMaterial() QObject::connect(m_presentation, &Q3DSPresentation::materialsCreated, [this](const QStringList &materialNames, const QString &error) { - QVERIFY(error.isEmpty()); + QCOMPARE(error, QString()); for (auto &name : materialNames) { + QVERIFY(m_createdMaterials.contains(name)); QHash<QString, QVariant> data; if (name == QLatin1String("materials/Basic Blue")) { data.insert(QStringLiteral("name"), QStringLiteral("Blue Cylinder")); @@ -488,10 +493,9 @@ void tst_qt3dsviewer::testCreateMaterial() // Delete material QTimer::singleShot(2500, [&]() { - // Material not removed from m_createdMaterials purposefully to ensure deleting already - // deleted material is handled properly later m_presentation->deleteElement(QStringLiteral("Scene.Layer.Textured Cone")); m_presentation->deleteMaterial("materials/Basic Texture"); + m_createdMaterials.removeOne(QStringLiteral("materials/Basic Texture")); // Try to use the deleted material - should find a fallback material QHash<QString, QVariant> data; @@ -506,6 +510,10 @@ void tst_qt3dsviewer::testCreateMaterial() QVERIFY(spyExited.wait(20000)); QCOMPARE(spyMatCreated.count(), 2); QCOMPARE(spyElemCreated.count(), 5); + const QStringList createdMaterials = m_presentation->createdMaterials(); + QCOMPARE(createdMaterials.size(), m_createdMaterials.size()); + for (const auto &name : createdMaterials) + QVERIFY(m_createdMaterials.contains(name)); deleteCreated(); QTest::qWait(200); // Extra wait to verify slide change visually } @@ -543,13 +551,15 @@ void tst_qt3dsviewer::testCreateMesh() m_presentation->createMaterial( QStringLiteral(":/scenes/simple_cube_animation/materials/Basic Texture.materialdef")); + m_createdMaterials << QStringLiteral("materials/Basic Texture"); m_presentation->createMesh(QStringLiteral("Pyramid"), pyramid); m_createdMeshes << QStringLiteral("Pyramid"); QObject::connect(m_presentation, &Q3DSPresentation::meshesCreated, [&](const QStringList &meshNames, const QString &error) { - QVERIFY(error.isEmpty()); + QCOMPARE(error, QString()); for (auto &name : meshNames) { + QVERIFY(m_createdMeshes.contains(name)); QHash<QString, QVariant> data; if (name == QLatin1String("Pyramid")) { data.insert(QStringLiteral("name"), QStringLiteral("Pyramid")); @@ -581,13 +591,16 @@ void tst_qt3dsviewer::testCreateMesh() QTimer::singleShot(3000, [&]() { m_presentation->deleteElement(QStringLiteral("Scene.Layer.Star")); m_presentation->deleteMesh(QStringLiteral("Star")); - // Mesh nor removed from m_createdMeshes purposefully to ensure deleting already deleted - // mesh is handled properly later + m_createdMeshes.removeOne(QStringLiteral("Star")); }); QVERIFY(spyExited.wait(20000)); QCOMPARE(spyMeshCreated.count(), 2); QCOMPARE(spyElemCreated.count(), 2); + const QStringList createdMeshes = m_presentation->createdMeshes(); + QCOMPARE(createdMeshes.size(), m_createdMeshes.size()); + for (const auto &name : createdMeshes) + QVERIFY(m_createdMeshes.contains(name)); deleteCreated(); QTest::qWait(200); // Extra wait to verify slide change visually } @@ -630,6 +643,9 @@ void tst_qt3dsviewer::deleteCreated() m_createdElements.clear(); m_createdMaterials.clear(); m_createdMeshes.clear(); + QVERIFY(m_presentation->createdElements().size() == 0); + QVERIFY(m_presentation->createdMaterials().size() == 0); + QVERIFY(m_presentation->createdMeshes().size() == 0); } void tst_qt3dsviewer::createElement(const QString &parentElementPath, const QString &slideName, |