From 5815546983112176ebb2114258650b901027b440 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Thu, 6 Oct 2022 16:36:30 +0200 Subject: [PATCH] feat: carry selection over when switching views Signed-off-by: Sefa Eyeoglu --- launcher/ui/instanceview/InstancesView.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/launcher/ui/instanceview/InstancesView.cpp b/launcher/ui/instanceview/InstancesView.cpp index 21bd2fd8f..7db8ee792 100644 --- a/launcher/ui/instanceview/InstancesView.cpp +++ b/launcher/ui/instanceview/InstancesView.cpp @@ -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();