aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/components/navigator/navigatorview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/qmldesigner/components/navigator/navigatorview.cpp')
-rw-r--r--src/plugins/qmldesigner/components/navigator/navigatorview.cpp74
1 files changed, 68 insertions, 6 deletions
diff --git a/src/plugins/qmldesigner/components/navigator/navigatorview.cpp b/src/plugins/qmldesigner/components/navigator/navigatorview.cpp
index ea64f0715a..e9a4930a44 100644
--- a/src/plugins/qmldesigner/components/navigator/navigatorview.cpp
+++ b/src/plugins/qmldesigner/components/navigator/navigatorview.cpp
@@ -117,7 +117,20 @@ void NavigatorView::modelAttached(Model *model)
QTimer::singleShot(0, this, [this, treeView]() {
m_currentModelInterface->setFilter(
DesignerSettings::getValue(DesignerSettingsKey::NAVIGATOR_SHOW_ONLY_VISIBLE_ITEMS).toBool());
+
+ // Expand everything to begin with to ensure model node to index cache is populated
treeView->expandAll();
+
+ if (AbstractView::model() && m_expandMap.contains(AbstractView::model()->fileUrl())) {
+ 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());
+ ++it;
+ }
+ }
});
#ifdef _LOCK_ITEMS_
@@ -127,6 +140,32 @@ void NavigatorView::modelAttached(Model *model)
void NavigatorView::modelAboutToBeDetached(Model *model)
{
+ m_expandMap.remove(model->fileUrl());
+
+ if (currentModel()) {
+ // Store expand state of the navigator tree
+ QHash<QString, bool> localExpandMap;
+ const ModelNode rootNode = rootModelNode();
+ const QModelIndex rootIndex = indexForModelNode(rootNode);
+
+ std::function<void(const QModelIndex &)> gatherExpandedState;
+ gatherExpandedState = [&](const QModelIndex &index) {
+ if (index.isValid()) {
+ const int rowCount = currentModel()->rowCount(index);
+ 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);
+ gatherExpandedState(childIndex);
+ }
+ }
+ };
+ gatherExpandedState(rootIndex);
+ m_expandMap[model->fileUrl()] = localExpandMap;
+ }
+
AbstractView::modelAboutToBeDetached(model);
}
@@ -147,6 +186,17 @@ void NavigatorView::bindingPropertiesChanged(const QList<BindingProperty> & prop
}
}
+void NavigatorView::customNotification(const AbstractView *view, const QString &identifier,
+ const QList<ModelNode> &nodeList, const QList<QVariant> &data)
+{
+ Q_UNUSED(view)
+ Q_UNUSED(nodeList)
+ Q_UNUSED(data)
+
+ if (identifier == "asset_import_update")
+ m_currentModelInterface->notifyIconsChanged();
+}
+
void NavigatorView::handleChangedExport(const ModelNode &modelNode, bool exported)
{
const ModelNode rootNode = rootModelNode();
@@ -155,7 +205,7 @@ void NavigatorView::handleChangedExport(const ModelNode &modelNode, bool exporte
if (rootNode.hasProperty(modelNodeId))
rootNode.removeProperty(modelNodeId);
if (exported) {
- executeInTransaction("NavigatorTreeModel:exportItem", [this, modelNode](){
+ executeInTransaction("NavigatorTreeModel:exportItem", [modelNode](){
QmlObjectNode qmlObjectNode(modelNode);
qmlObjectNode.ensureAliasExport();
});
@@ -416,12 +466,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);
@@ -431,10 +493,10 @@ 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)
- expandRecursively(selectedIndex);
+ expandAncestors(selectedIndex);
}
}
@@ -458,9 +520,9 @@ bool NavigatorView::blockSelectionChangedSignal(bool block)
return oldValue;
}
-void NavigatorView::expandRecursively(const QModelIndex &index)
+void NavigatorView::expandAncestors(const QModelIndex &index)
{
- QModelIndex currentIndex = index;
+ QModelIndex currentIndex = index.parent();
while (currentIndex.isValid()) {
if (!treeWidget()->isExpanded(currentIndex))
treeWidget()->expand(currentIndex);