--- a/src/document.cpp Fri Feb 07 02:02:16 2020 +0200 +++ b/src/document.cpp Fri Feb 07 23:59:06 2020 +0200 @@ -41,6 +41,35 @@ this->setMouseTracking(true); connect(this->ui.splitter, &QSplitter::splitterMoved, this, &Document::splitterChanged); connect(this->renderer, &Canvas::newStatusText, this, &Document::newStatusText); + connect(this->renderer, &Canvas::selectionChanged, [&](const QSet<ldraw::Id>& newSelection) + { + QItemSelectionModel* selectionModel = this->ui.listView->selectionModel(); + QItemSelection selection; + for (ldraw::Id id : newSelection) + { + QModelIndex index = this->model->lookup(id); + if (index != QModelIndex{}) + { + selection.select(index, index); + } + } + selectionModel->select(selection, QItemSelectionModel::ClearAndSelect); + }); + connect(this->ui.listView->selectionModel(), &QItemSelectionModel::selectionChanged, + [&](const QItemSelection& selected, const QItemSelection& deselected) + { + QSet<ldraw::Id> selectedIds; + QSet<ldraw::Id> deselectedIds; + for (const QModelIndex& index : selected.indexes()) + { + selectedIds.insert(this->model->resolve(index)); + } + for (const QModelIndex& index : deselected.indexes()) + { + deselectedIds.insert(this->model->resolve(index)); + } + this->renderer->handleSelectionChange(selectedIds, deselectedIds); + }); } Document::~Document()