From b176a61d26a05c3b43edb8c4d168231ccc744867 Mon Sep 17 00:00:00 2001 From: David Antunes Date: Mon, 16 Jun 2025 19:45:58 +0100 Subject: [PATCH] keep row selection when adding favorites --- src/qt_gui/game_list_frame.cpp | 11 +++++++++-- src/qt_gui/game_list_frame.h | 1 + src/qt_gui/gui_context_menus.h | 1 - 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/qt_gui/game_list_frame.cpp b/src/qt_gui/game_list_frame.cpp index b64717aec..301685971 100644 --- a/src/qt_gui/game_list_frame.cpp +++ b/src/qt_gui/game_list_frame.cpp @@ -16,6 +16,7 @@ GameListFrame::GameListFrame(std::shared_ptr gui_settings, : QTableWidget(parent), m_gui_settings(std::move(gui_settings)), m_game_info(game_info_get), m_compat_info(compat_info_get) { icon_size = m_gui_settings->GetValue(gui::gl_icon_size).toInt(); + last_favorite = ""; this->setShowGrid(false); this->setEditTriggers(QAbstractItemView::NoEditTriggers); this->setSelectionBehavior(QAbstractItemView::SelectRows); @@ -82,8 +83,10 @@ GameListFrame::GameListFrame(std::shared_ptr gui_settings, connect(this, &QTableWidget::customContextMenuRequested, this, [=, this](const QPoint& pos) { int changedFavorite = m_gui_context_menus.RequestGameMenu( pos, m_game_info->m_games, m_compat_info, m_gui_settings, this, true); - if (changedFavorite) + if (changedFavorite) { + last_favorite = m_game_info->m_games[this->currentRow()].serial; PopulateGameList(false); + } }); connect(this, &QTableWidget::cellClicked, this, [=, this](int row, int column) { @@ -92,10 +95,10 @@ GameListFrame::GameListFrame(std::shared_ptr gui_settings, QDesktopServices::openUrl( QUrl(url_issues + m_game_info->m_games[row].compatibility.issue_number)); } else if (column == 10) { + last_favorite = m_game_info->m_games[row].serial; QString serialStr = QString::fromStdString(m_game_info->m_games[row].serial); bool isFavorite = m_gui_settings->GetValue(gui::favorites, serialStr, false).toBool(); m_gui_settings->SetValue(gui::favorites, serialStr, !isFavorite, true); - this->setCurrentCell(-1, -1); PopulateGameList(false); } }); @@ -142,6 +145,10 @@ void GameListFrame::PopulateGameList(bool isInitialPopulation) { SetTableItem(i, 7, QString::fromStdString(m_game_info->m_games[i].version)); SetFavoriteIcon(i, 10); + if (m_game_info->m_games[i].serial == last_favorite && !isInitialPopulation) { + this->setCurrentCell(i, 10); + } + m_game_info->m_games[i].compatibility = m_compat_info->GetCompatibilityInfo(m_game_info->m_games[i].serial); SetCompatibilityItem(i, 2, m_game_info->m_games[i].compatibility); diff --git a/src/qt_gui/game_list_frame.h b/src/qt_gui/game_list_frame.h index 69ca76e7d..d1e065864 100644 --- a/src/qt_gui/game_list_frame.h +++ b/src/qt_gui/game_list_frame.h @@ -66,6 +66,7 @@ public: std::shared_ptr m_compat_info; int icon_size; + std::string last_favorite; static float parseAsFloat(const std::string& str, const int& offset) { return std::stof(str.substr(0, str.size() - offset)); diff --git a/src/qt_gui/gui_context_menus.h b/src/qt_gui/gui_context_menus.h index 7fa4654da..b33dd611a 100644 --- a/src/qt_gui/gui_context_menus.h +++ b/src/qt_gui/gui_context_menus.h @@ -317,7 +317,6 @@ public: if (selected == toggleFavorite) { m_gui_settings->SetValue(gui::favorites, serialStr, !isFavorite, true); - widget->setCurrentCell(-1, -1); changedFavorite = 1; }