summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2021-11-23 14:15:15 +0200
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2021-11-25 11:19:43 +0000
commitcfaf169ea1e967b02a023cd38799ae7381f673d3 (patch)
tree132323a2de234826fcdaa22ba334b6a121ab372b
parent10d6bab932a2a8449e00e79ddc35bcbb66423bd9 (diff)
downloadqt-creator-cfaf169ea1e967b02a023cd38799ae7381f673d3.tar.gz
QmlDesigner: Fix node expand state caching for subcomponent edit case
When detaching subcomponent edit model, we just update node expand state cache for the file instead of recreating it from scratch. Also, never collapse the current root node when attaching the model. Fixes: QDS-5557 Change-Id: Id107940daccd9663ec4216de7dc8ae6a5bee8974 Reviewed-by: Samuel Ghinet <samuel.ghinet@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Henning Gründl <henning.gruendl@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r--src/plugins/qmldesigner/components/navigator/navigatorview.cpp34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/plugins/qmldesigner/components/navigator/navigatorview.cpp b/src/plugins/qmldesigner/components/navigator/navigatorview.cpp
index 2606ea83a4..514bf2c75b 100644
--- a/src/plugins/qmldesigner/components/navigator/navigatorview.cpp
+++ b/src/plugins/qmldesigner/components/navigator/navigatorview.cpp
@@ -28,6 +28,7 @@
#include "navigatorwidget.h"
#include "qmldesignerconstants.h"
#include "qmldesignericons.h"
+#include "qmldesignerplugin.h"
#include "nameitemdelegate.h"
#include "iconcheckboxitemdelegate.h"
@@ -166,9 +167,14 @@ void NavigatorView::modelAttached(Model *model)
const QHash<QString, bool> localExpandMap = m_expandMap[AbstractView::model()->fileUrl()];
auto it = localExpandMap.constBegin();
while (it != localExpandMap.constEnd()) {
- const QModelIndex index = indexForModelNode(modelNodeForId(it.key()));
- if (index.isValid())
- treeWidget()->setExpanded(index, it.value());
+ const ModelNode node = modelNodeForId(it.key());
+ // When editing subcomponent, the current root node may be marked collapsed in the
+ // full file view, but we never want to actually collapse it, so skip it.
+ if (!node.isRootNode()) {
+ const QModelIndex index = indexForModelNode(node);
+ if (index.isValid())
+ treeWidget()->setExpanded(index, it.value());
+ }
++it;
}
}
@@ -200,11 +206,18 @@ void NavigatorView::addNodeAndSubModelNodesToList(const ModelNode &node, QList<M
void NavigatorView::modelAboutToBeDetached(Model *model)
{
- m_expandMap.remove(model->fileUrl());
+ QHash<QString, bool> &localExpandMap = m_expandMap[model->fileUrl()];
+
+ // If detaching full document model, recreate expand map from scratch to remove stale entries.
+ // Otherwise just update it (subcomponent edit case).
+ bool fullUpdate = true;
+ if (DesignDocument *document = QmlDesignerPlugin::instance()->currentDesignDocument())
+ fullUpdate = !document->inFileComponentModelActive();
+ if (fullUpdate)
+ localExpandMap.clear();
if (currentModel()) {
// Store expand state of the navigator tree
- QHash<QString, bool> localExpandMap;
const ModelNode rootNode = rootModelNode();
const QModelIndex rootIndex = indexForModelNode(rootNode);
@@ -215,15 +228,18 @@ void NavigatorView::modelAboutToBeDetached(Model *model)
for (int i = 0; i < rowCount; ++i) {
const QModelIndex childIndex = currentModel()->index(i, 0, index);
const ModelNode node = modelNodeForIndex(childIndex);
- // Just store collapsed states as everything is expanded by default
- if (node.isValid() && !treeWidget()->isExpanded(childIndex))
- localExpandMap.insert(node.id(), false);
+ if (node.isValid()) {
+ // Just store collapsed states as everything is expanded by default
+ if (!treeWidget()->isExpanded(childIndex))
+ localExpandMap.insert(node.id(), false);
+ else if (!fullUpdate)
+ localExpandMap.remove(node.id());
+ }
gatherExpandedState(childIndex);
}
}
};
gatherExpandedState(rootIndex);
- m_expandMap[model->fileUrl()] = localExpandMap;
}
AbstractView::modelAboutToBeDetached(model);