aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner
diff options
context:
space:
mode:
authorMahmoud Badri <mahmoud.badri@qt.io>2020-04-30 15:13:49 +0300
committerMahmoud Badri <mahmoud.badri@qt.io>2020-04-30 13:52:52 +0000
commit9151e0b58556c376dc2b1c657a4bd052d5081cae (patch)
tree98387e66dbb619d3dc49b067bfbe1c1cd1dbdf17 /src/plugins/qmldesigner
parent04a61fc16bb1b95323c2b1cf37532d12b9aaf1f1 (diff)
QmlDesigner: Fix navigator selection when index is invalid
This fixes the case when the navigator tree is collapsed and nothing is selected, then a 3D object is dragged to the 3D editor. With this fix, the tree is expanded and selection is shown. This also fixes QDS-1892 partially (i.e. it still happens sometimes but less often). Task-number: QDS-2024 Task-number: QDS-1892 Change-Id: If9233497d0f3c0daffafd939476d7bd64b005c79 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'src/plugins/qmldesigner')
-rw-r--r--src/plugins/qmldesigner/components/navigator/navigatorview.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/plugins/qmldesigner/components/navigator/navigatorview.cpp b/src/plugins/qmldesigner/components/navigator/navigatorview.cpp
index 0d0fded729..cd6857d789 100644
--- a/src/plugins/qmldesigner/components/navigator/navigatorview.cpp
+++ b/src/plugins/qmldesigner/components/navigator/navigatorview.cpp
@@ -427,12 +427,24 @@ void NavigatorView::updateItemSelection()
QItemSelection itemSelection;
foreach (const ModelNode &node, selectedModelNodes()) {
const QModelIndex index = indexForModelNode(node);
+
if (index.isValid()) {
const QModelIndex beginIndex(currentModel()->index(index.row(), 0, index.parent()));
const QModelIndex endIndex(currentModel()->index(index.row(), currentModel()->columnCount(index.parent()) - 1, index.parent()));
if (beginIndex.isValid() && endIndex.isValid())
itemSelection.select(beginIndex, endIndex);
- }
+ } else {
+ // if the node index is invalid expand ancestors manually if they are valid.
+ ModelNode parentNode = node;
+ while (parentNode.hasParentProperty()) {
+ parentNode = parentNode.parentProperty().parentQmlObjectNode();
+ QModelIndex parentIndex = indexForModelNode(parentNode);
+ if (parentIndex.isValid())
+ treeWidget()->expand(parentIndex);
+ else
+ break;
+ }
+ }
}
bool blocked = blockSelectionChangedSignal(true);
@@ -442,7 +454,7 @@ void NavigatorView::updateItemSelection()
if (!selectedModelNodes().isEmpty())
treeWidget()->scrollTo(indexForModelNode(selectedModelNodes().constFirst()));
- // make sure selected nodes a visible
+ // make sure selected nodes are visible
foreach (const QModelIndex &selectedIndex, itemSelection.indexes()) {
if (selectedIndex.column() == 0)
expandAncestors(selectedIndex);