feat: carry selection over when switching views

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2022-10-06 16:36:30 +02:00
parent cf3ccf376b
commit 5815546983
No known key found for this signature in database
GPG Key ID: C10411294912A422

View File

@ -51,12 +51,18 @@ void InstancesView::storeState()
void InstancesView::switchDisplayMode(InstancesView::DisplayMode mode)
{
m_displayMode = mode;
const QModelIndex index = currentView()->currentIndex();
const QModelIndex sourceIndex = mappedIndex(index);
if (mode == DisplayMode::TableMode) {
m_table->selectionModel()->setCurrentIndex(m_tableProxy->mapFromSource(sourceIndex),
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
setCurrentWidget(m_table);
} else {
m_grid->selectionModel()->setCurrentIndex(m_gridProxy->mapFromSource(sourceIndex),
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
setCurrentWidget(m_grid);
}
m_displayMode = mode;
}
void InstancesView::editSelected(InstanceList::Column targetColumn)
@ -171,14 +177,6 @@ void InstancesView::activateInstance(const QModelIndex& index)
void InstancesView::currentRowChanged(const QModelIndex& current, const QModelIndex& previous)
{
// don't fire event, if row changed in inactive model
QSortFilterProxyModel* m = m_tableProxy;
if (m_displayMode == GridMode)
m = m_gridProxy;
if (current.model() != m)
return;
InstancePtr inst1, inst2;
if (current.isValid()) {
int row = mappedIndex(current).row();