From a2fd9be6e3535656c9838705ffde3c2a0ba1f9e5 Mon Sep 17 00:00:00 2001 From: maelstrom Date: Wed, 26 Feb 2025 22:31:33 +0100 Subject: [PATCH] fix: selecting items in explorer doesn't update the rest of the editor --- editor/panes/explorerview.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/editor/panes/explorerview.cpp b/editor/panes/explorerview.cpp index 699a7b6..77542da 100644 --- a/editor/panes/explorerview.cpp +++ b/editor/panes/explorerview.cpp @@ -6,6 +6,7 @@ #include "qabstractitemmodel.h" #include "qaction.h" #include "qnamespace.h" +#include ExplorerView::ExplorerView(QWidget* parent): QTreeView(parent), @@ -32,7 +33,23 @@ ExplorerView::ExplorerView(QWidget* parent): contextMenu.exec(this->viewport()->mapToGlobal(point)); }); + connect(selectionModel(), &QItemSelectionModel::selectionChanged, this, [&](const QItemSelection &selected, const QItemSelection &deselected) { + std::vector selectedInstances; + selectedInstances.reserve(selected.count()); // This doesn't reserve everything, but should enhance things anyway + + for (auto range : selected) { + for (auto index : range.indexes()) { + selectedInstances.push_back(reinterpret_cast(index.internalPointer())->weak_from_this()); + } + } + + ::setSelection(selectedInstances, true); + }); + addSelectionListener([&](auto oldSelection, auto newSelection, bool fromExplorer) { + // It's from us, ignore it. + if (fromExplorer) return; + this->clearSelection(); for (InstanceRefWeak inst : newSelection) { if (inst.expired()) continue;