summaryrefslogtreecommitdiffstats
path: root/src/runtime/q3dsconsolecommands.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2018-07-09 15:43:40 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2018-07-10 08:03:39 +0000
commitdc04968027163c9698b872498f7856a0e56088cc (patch)
tree6d02cead24ec47764092a37654a86b15ebdab39f /src/runtime/q3dsconsolecommands.cpp
parent280abea92d6174f8082e6825d06abd982f12b9cc (diff)
Do not leak attached objects when removing and readding
The attached object should go away when an object gets disconnected from a scene (or master slide). It is recreated when the object gets added into a scene (or master slide) hierarchy again. To exercise this, the console's setparent() now works as expected, supporting both unparenting (with a 'null' parent) and reparenting. Change-Id: I70d69300d7fbab6a48b33d7082b2fb9fa9fe1e7e Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/runtime/q3dsconsolecommands.cpp')
-rw-r--r--src/runtime/q3dsconsolecommands.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/runtime/q3dsconsolecommands.cpp b/src/runtime/q3dsconsolecommands.cpp
index 2da5a8a..bfe9e1b 100644
--- a/src/runtime/q3dsconsolecommands.cpp
+++ b/src/runtime/q3dsconsolecommands.cpp
@@ -148,7 +148,7 @@ void Q3DSConsoleCommands::setupConsole(Q3DSConsole *console)
"\n"
"object(id, name, type, parentObj, slide) - Creates a new object. (type == Model, DefaultMaterial, ...; parent and slide may be null) [R]\n"
"primitive(id, name, source, parentObj, slide) - Shortcut to add a model with a default material. (source == #Cube, #Cone, etc.) [R]\n"
- "setparent(obj, parentObj) - Sets the parent (only valid when object()/primitive() was called with parentObj == null) [R]\n"
+ "setparent(obj, parentObj) - Sets the parent (may be null). [R]\n"
"kill(obj) - Removes a node from the scene graph (and from the slides' object list). [R]\n"
"objslideadd(obj, slide) - Associates the object with the given slide. [R]\n"
"objslideremove(obj, slide) - Removes the object from the slide's objject list. [R]\n"
@@ -438,9 +438,20 @@ void Q3DSConsoleCommands::setupConsole(Q3DSConsole *console)
if (splitArgs.count() >= 2) {
Q3DSGraphObject *obj = resolveObj(splitArgs[0]);
Q3DSGraphObject *parent = resolveObj(splitArgs[1]);
- if (obj && parent) {
- parent->appendChildNode(obj);
- m_console->addMessageFmt(responseColor, "Appended as child node");
+ if (obj) {
+ if (parent) {
+ if (obj->parent() != parent) {
+ if (obj->parent())
+ obj->parent()->removeChildNode(obj);
+ parent->appendChildNode(obj);
+ m_console->addMessageFmt(responseColor, "Reparented");
+ }
+ } else {
+ if (obj->parent()) {
+ obj->parent()->removeChildNode(obj);
+ m_console->addMessageFmt(responseColor, "Unparented");
+ }
+ }
}
}
}, Q3DSConsole::CmdRecordable));