fix: selecting items in explorer doesn't update the rest of the editor
This commit is contained in:
parent
e22bb74850
commit
a2fd9be6e3
|
@ -6,6 +6,7 @@
|
||||||
#include "qabstractitemmodel.h"
|
#include "qabstractitemmodel.h"
|
||||||
#include "qaction.h"
|
#include "qaction.h"
|
||||||
#include "qnamespace.h"
|
#include "qnamespace.h"
|
||||||
|
#include <qitemselectionmodel.h>
|
||||||
|
|
||||||
ExplorerView::ExplorerView(QWidget* parent):
|
ExplorerView::ExplorerView(QWidget* parent):
|
||||||
QTreeView(parent),
|
QTreeView(parent),
|
||||||
|
@ -32,7 +33,23 @@ ExplorerView::ExplorerView(QWidget* parent):
|
||||||
contextMenu.exec(this->viewport()->mapToGlobal(point));
|
contextMenu.exec(this->viewport()->mapToGlobal(point));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(selectionModel(), &QItemSelectionModel::selectionChanged, this, [&](const QItemSelection &selected, const QItemSelection &deselected) {
|
||||||
|
std::vector<InstanceRefWeak> 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<Instance*>(index.internalPointer())->weak_from_this());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
::setSelection(selectedInstances, true);
|
||||||
|
});
|
||||||
|
|
||||||
addSelectionListener([&](auto oldSelection, auto newSelection, bool fromExplorer) {
|
addSelectionListener([&](auto oldSelection, auto newSelection, bool fromExplorer) {
|
||||||
|
// It's from us, ignore it.
|
||||||
|
if (fromExplorer) return;
|
||||||
|
|
||||||
this->clearSelection();
|
this->clearSelection();
|
||||||
for (InstanceRefWeak inst : newSelection) {
|
for (InstanceRefWeak inst : newSelection) {
|
||||||
if (inst.expired()) continue;
|
if (inst.expired()) continue;
|
||||||
|
|
Loading…
Reference in a new issue