aboutsummaryrefslogtreecommitdiffstats
path: root/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quick3dnodeinstance.cpp
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2019-11-29 17:28:11 +0200
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2019-12-03 08:44:30 +0000
commit73d3df79088a06e8e59b1da0b0eb39d6cd3eba8f (patch)
treef0346ea81124b7946827a114235ee66e1ce4ef35 /share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quick3dnodeinstance.cpp
parentde141661df3caac507eb01da69f8a7b8ede75714 (diff)
QmlDesigner: Make imported models selectable
Import creates an opaque Component, which can contain one or more pickable models. We mark all instanceless models pickable according to the parent instance pickable status and specify the parent instance as the pick target using a dynamic property. Change-Id: I05b96ee48eb8f246c50b2254d620b621e2437aa5 Fixes: QDS-1282 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quick3dnodeinstance.cpp')
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quick3dnodeinstance.cpp47
1 files changed, 34 insertions, 13 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quick3dnodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quick3dnodeinstance.cpp
index f35d165931..4c725749e2 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quick3dnodeinstance.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quick3dnodeinstance.cpp
@@ -37,6 +37,7 @@
#ifdef QUICK3D_MODULE
#include <private/qquick3dnode_p.h>
+#include <private/qquick3dmodel_p.h>
#include <private/qquick3dnode_p_p.h>
#endif
@@ -73,7 +74,7 @@ QQuick3DNode *Quick3DNodeInstance::quick3DNode() const
#endif
}
-void Quick3DNodeInstance::setPickable(bool enable, bool checkParent, bool applyToChildren)
+void Quick3DNodeInstance::setPickable(bool enable, bool checkParent, bool applyToChildInstances)
{
#ifdef QUICK3D_MODULE
auto node = quick3DNode();
@@ -90,22 +91,42 @@ void Quick3DNodeInstance::setPickable(bool enable, bool checkParent, bool applyT
}
if (!parentHidden) {
- if (applyToChildren) {
- auto getQuick3DInstance = [this](QQuick3DObject *obj) -> Quick3DNodeInstance * {
- if (nodeInstanceServer()->hasInstanceForObject(obj)) {
- ServerNodeInstance instance = nodeInstanceServer()->instanceForObject(obj);
- if (instance.isValid() && qobject_cast<QQuick3DNode *>(instance.internalObject()))
- return static_cast<Quick3DNodeInstance *>(instance.internalInstance().data());
- }
- return nullptr;
- };
- const auto childItems = node->childItems();
- for (auto childItem : childItems) {
- if (auto quick3dInstance = getQuick3DInstance(childItem)) {
+ auto getQuick3DInstance = [this](QQuick3DObject *obj) -> Quick3DNodeInstance * {
+ if (nodeInstanceServer()->hasInstanceForObject(obj)) {
+ ServerNodeInstance instance = nodeInstanceServer()->instanceForObject(obj);
+ if (instance.isValid() && qobject_cast<QQuick3DNode *>(instance.internalObject()))
+ return static_cast<Quick3DNodeInstance *>(instance.internalInstance().data());
+ }
+ return nullptr;
+ };
+ const auto childItems = node->childItems();
+ for (auto childItem : childItems) {
+ if (auto quick3dInstance = getQuick3DInstance(childItem)) {
+ if (applyToChildInstances) {
// Don't override explicit block in children
if (!QQuick3DNodePrivate::get(quick3dInstance->quick3DNode())->m_isHiddenInEditor)
quick3dInstance->setPickable(enable, false, true);
}
+ } else {
+ // Children of components do not have instances, but will still need to be
+ // pickable. These need to be set even if applyToChildInstances is false.
+ std::function<void(QQuick3DNode *)> checkChildren;
+ checkChildren = [&](QQuick3DNode *checkNode) {
+ const auto childItems = checkNode->childItems();
+ for (auto child : childItems) {
+ if (auto childNode = qobject_cast<QQuick3DNode *>(child))
+ checkChildren(childNode);
+ }
+ if (auto checkModel = qobject_cast<QQuick3DModel *>(checkNode)) {
+ QVariant value;
+ if (enable)
+ value = QVariant::fromValue(node);
+ // Specify the actual pick target with dynamic property
+ checkModel->setProperty("_pickTarget", value);
+ checkModel->setPickable(enable);
+ }
+ };
+ checkChildren(node);
}
}
if (nodeType == QQuick3DObject::Model)