summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2018-08-24 12:52:48 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2018-08-26 08:59:56 +0000
commitce2e3b3eeaac916521f2a27d17c54bc043ae1492 (patch)
tree088c06ec576b31aa59259d9d86fb6b7041416e61
parentba063c4d626d54dec8da82985f0f59c62346e21a (diff)
Allow non-nodes outside Layer
...both in .uip and when added dynmically. This makes it possible to construct scenes like the following: Scene - DefaultMaterial -- DefaultMaterial -- DefaultMaterial ... - Layer -- Camera -- Light -- Model -- ReferencedMaterial because referencing a material via ReferencedMaterial will work as expected regardless of where the target object lives in the tree. Change-Id: I3cae99403b35f62f5819a96d29c72a87b87470d6 Reviewed-by: Jere Tuliniemi <jere.tuliniemi@qt.io> Reviewed-by: Christian Stromme <christian.stromme@qt.io>
-rw-r--r--src/runtime/q3dsscenemanager.cpp16
-rw-r--r--src/runtime/q3dsscenemanager_p.h1
-rw-r--r--src/runtime/q3dsuipparser.cpp10
3 files changed, 18 insertions, 9 deletions
diff --git a/src/runtime/q3dsscenemanager.cpp b/src/runtime/q3dsscenemanager.cpp
index c350f61..2c8155c 100644
--- a/src/runtime/q3dsscenemanager.cpp
+++ b/src/runtime/q3dsscenemanager.cpp
@@ -8358,10 +8358,13 @@ void Q3DSSceneManager::handleSceneChange(Q3DSScene *, Q3DSGraphObject::DirtyFlag
// of buildLayer().
if (obj->type() != Q3DSGraphObject::Layer) {
- Q_ASSERT(obj->parent() && obj->parent()->attached());
- Q3DSLayerNode *layer3DS = findLayerForObjectInScene(obj);
+ Q3DSLayerNode *layer3DS = nullptr;
+ if (obj->parent() && obj->parent()->attached())
+ layer3DS = findLayerForObjectInScene(obj);
if (layer3DS)
addLayerContent(obj, obj->parent(), layer3DS);
+ else
+ addNonLayerContent(obj);
} else {
addLayer(static_cast<Q3DSLayerNode *>(obj));
}
@@ -8451,6 +8454,15 @@ void Q3DSSceneManager::handleSceneChange(Q3DSScene *, Q3DSGraphObject::DirtyFlag
}
}
+void Q3DSSceneManager::addNonLayerContent(Q3DSGraphObject *obj)
+{
+ initSubTree(obj);
+
+ // and that's it. This is not suitable for nodes as they won't be
+ // functional, but Image, DefaultMaterial, CustomMaterial can live outside
+ // a Layer just fine.
+}
+
void Q3DSSceneManager::addLayerContent(Q3DSGraphObject *obj, Q3DSGraphObject *parent, Q3DSLayerNode *layer3DS)
{
// obj can have children, process the entire subtree recursively
diff --git a/src/runtime/q3dsscenemanager_p.h b/src/runtime/q3dsscenemanager_p.h
index c57e20d..35c1afa 100644
--- a/src/runtime/q3dsscenemanager_p.h
+++ b/src/runtime/q3dsscenemanager_p.h
@@ -890,6 +890,7 @@ private:
void handleNodeGlobalChange(Q3DSNode *node);
void handleSceneChange(Q3DSScene *scene, Q3DSGraphObject::DirtyFlag change, Q3DSGraphObject *obj);
+ void addNonLayerContent(Q3DSGraphObject *obj);
void addLayerContent(Q3DSGraphObject *obj, Q3DSGraphObject *parent, Q3DSLayerNode *layer3DS);
void addLayer(Q3DSLayerNode *layer3DS);
void handleSlideGraphChange(Q3DSSlide *master, Q3DSGraphObject::DirtyFlag change, Q3DSSlide *slide);
diff --git a/src/runtime/q3dsuipparser.cpp b/src/runtime/q3dsuipparser.cpp
index 0aa3607..0528ef8 100644
--- a/src/runtime/q3dsuipparser.cpp
+++ b/src/runtime/q3dsuipparser.cpp
@@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE
</BufferData>
<Graph>
<Scene id="Scene">
- <Layer id="layer"> scene can only have layer children
+ <Layer id="layer">
<Camera id="Camera" />
<Light id="Light" />
...
@@ -307,12 +307,8 @@ void Q3DSUipParser::parseScene()
m_presentation->registerObject(id, scene);
m_presentation->setScene(scene);
- while (r->readNextStartElement()) {
- if (r->name() == QStringLiteral("Layer") || r->name() == QStringLiteral("Behavior"))
- parseObjects(scene);
- else
- r->raiseError(QObject::tr("Scene can only have Layer or Behavior children."));
- }
+ while (r->readNextStartElement())
+ parseObjects(scene);
}
void Q3DSUipParser::parseObjects(Q3DSGraphObject *parent)