projectpanel: select nodes when items are selected in the project explorer

This commit is contained in:
itsmattkc
2021-05-26 14:22:10 +10:00
parent cac165c62e
commit edd52dd811
6 changed files with 42 additions and 0 deletions
@@ -134,6 +134,7 @@ void ProjectExplorer::AddView(QAbstractItemView *view)
view->setEditTriggers(QAbstractItemView::NoEditTriggers);
connect(view, &QAbstractItemView::clicked, this, &ProjectExplorer::ItemClickedSlot);
connect(view, &QAbstractItemView::doubleClicked, this, &ProjectExplorer::ItemDoubleClickedSlot);
connect(view->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ProjectExplorer::ViewSelectionChanged);
connect(view, SIGNAL(DoubleClickedEmptyArea()), this, SLOT(ViewEmptyAreaDoubleClickedSlot()));
stacked_widget_->addWidget(view);
}
@@ -509,6 +510,28 @@ void ProjectExplorer::ContextMenuStartProxy(QAction *a)
}
}
void ProjectExplorer::ViewSelectionChanged()
{
QItemSelectionModel *model = static_cast<QItemSelectionModel *>(sender());
QModelIndexList selection = model->selectedIndexes();
QVector<Node *> nodes;
foreach (const QModelIndex &index, selection) {
Node *sel = static_cast<Node*>(sort_model_.mapToSource(index).internalPointer());
if (!nodes.contains(sel)) {
nodes.append(sel);
}
}
if (nodes.isEmpty()) {
nodes.append(get_root());
}
emit SelectionChanged(nodes);
}
Project *ProjectExplorer::project() const
{
return model_.project();