Skip to content

Commit 90df8ba

Browse files
committed
Qt: Fix game list multi-selection after Refresh
1 parent 1eb0b22 commit 90df8ba

8 files changed

Lines changed: 31 additions & 29 deletions

rpcs3/rpcs3qt/game_list_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class game_list_base
1515
[[maybe_unused]] const std::vector<game_info>& game_data,
1616
[[maybe_unused]] const std::map<QString, QString>& notes_map,
1717
[[maybe_unused]] const std::map<QString, QString>& title_map,
18-
[[maybe_unused]] const std::string& selected_item_id,
18+
[[maybe_unused]] const std::set<std::string>& selected_item_ids,
1919
[[maybe_unused]] bool play_hover_movies){};
2020

2121
void set_icon_size(QSize size) { m_icon_size = std::move(size); }

rpcs3/rpcs3qt/game_list_context_menu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ void game_list_context_menu::show_single_selection_context_menu(const game_info&
581581
Q_EMIT m_game_list_frame->RequestBoot(gameinfo, cfg_mode::global);
582582
});
583583

584-
const auto configure_l = [this, current_game, gameinfo](bool create_cfg_from_global_cfg)
584+
auto configure_l = [this, current_game, gameinfo](bool create_cfg_from_global_cfg)
585585
{
586586
settings_dialog dlg(m_gui_settings, m_emu_settings, 0, m_game_list_frame, &current_game, create_cfg_from_global_cfg);
587587

rpcs3/rpcs3qt/game_list_frame.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ void game_list_frame::Refresh(const bool from_drive, const std::vector<std::stri
446446

447447
// Fill Game List / Game Grid
448448

449-
const std::string selected_item = CurrentSelectionPath();
449+
const std::set<std::string> selected_items = CurrentSelectionPaths();
450450

451451
// Release old data
452452
for (const auto& game : m_game_data)
@@ -481,7 +481,7 @@ void game_list_frame::Refresh(const bool from_drive, const std::vector<std::stri
481481
{
482482
m_game_grid->clear_list();
483483
const int scroll_position = m_game_list->verticalScrollBar()->value();
484-
m_game_list->populate(matching_apps, m_notes, m_titles, selected_item, m_play_hover_movies);
484+
m_game_list->populate(matching_apps, m_notes, m_titles, selected_items, m_play_hover_movies);
485485
m_game_list->sort(m_game_data.size(), m_sort_column, m_col_sort_order);
486486
RepaintIcons();
487487

@@ -497,7 +497,7 @@ void game_list_frame::Refresh(const bool from_drive, const std::vector<std::stri
497497
else
498498
{
499499
m_game_list->clear_list();
500-
m_game_grid->populate(matching_apps, m_notes, m_titles, selected_item, m_play_hover_movies);
500+
m_game_grid->populate(matching_apps, m_notes, m_titles, selected_items, m_play_hover_movies);
501501
RepaintIcons();
502502
}
503503
}
@@ -1257,38 +1257,37 @@ bool game_list_frame::SearchMatchesApp(const QString& name, const QString& seria
12571257
return true;
12581258
}
12591259

1260-
std::string game_list_frame::CurrentSelectionPath()
1260+
std::set<std::string> game_list_frame::CurrentSelectionPaths()
12611261
{
1262-
std::string selection;
1263-
1264-
game_info game{};
1262+
std::set<std::string> selection;
12651263

12661264
if (m_old_layout_is_list)
12671265
{
1268-
if (!m_game_list->selectedItems().isEmpty())
1266+
for (const QTableWidgetItem* selected_item : m_game_list->selectedItems())
12691267
{
1270-
if (QTableWidgetItem* item = m_game_list->item(m_game_list->currentRow(), 0))
1268+
if (const QTableWidgetItem* item = m_game_list->item(selected_item->row(), 0))
12711269
{
12721270
if (const QVariant var = item->data(gui::game_role); var.canConvert<game_info>())
12731271
{
1274-
game = var.value<game_info>();
1272+
if (const game_info game = var.value<game_info>())
1273+
{
1274+
selection.insert(game->info.path + game->info.icon_path);
1275+
}
12751276
}
12761277
}
12771278
}
12781279
}
12791280
else if (m_game_grid)
12801281
{
1281-
if (game_list_grid_item* item = static_cast<game_list_grid_item*>(m_game_grid->selected_item()))
1282+
if (const game_list_grid_item* item = static_cast<game_list_grid_item*>(m_game_grid->selected_item()))
12821283
{
1283-
game = item->game();
1284+
if (const game_info& game = item->game())
1285+
{
1286+
selection.insert(game->info.path + game->info.icon_path);
1287+
}
12841288
}
12851289
}
12861290

1287-
if (game)
1288-
{
1289-
selection = game->info.path + game->info.icon_path;
1290-
}
1291-
12921291
m_old_layout_is_list = m_is_list_layout;
12931292

12941293
return selection;

rpcs3/rpcs3qt/game_list_frame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private Q_SLOTS:
130130

131131
bool SearchMatchesApp(const QString& name, const QString& serial, bool fallback = false) const;
132132

133-
std::string CurrentSelectionPath();
133+
std::set<std::string> CurrentSelectionPaths();
134134

135135
game_info GetGameInfoByMode(const QTableWidgetItem* item) const;
136136
static game_info GetGameInfoFromItem(const QTableWidgetItem* item);

rpcs3/rpcs3qt/game_list_grid.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void game_list_grid::populate(
4040
const std::vector<game_info>& game_data,
4141
const std::map<QString, QString>& notes_map,
4242
const std::map<QString, QString>& title_map,
43-
const std::string& selected_item_id,
43+
const std::set<std::string>& selected_item_ids,
4444
bool play_hover_movies)
4545
{
4646
clear_list();
@@ -110,7 +110,7 @@ void game_list_grid::populate(
110110
item->set_video_path(game->info.movie_path);
111111
}
112112

113-
if (selected_item_id == game->info.path + game->info.icon_path)
113+
if (selected_item_ids.contains(game->info.path + game->info.icon_path))
114114
{
115115
selected_item = item;
116116
}

rpcs3/rpcs3qt/game_list_grid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class game_list_grid : public flow_widget, public game_list_base
1818
const std::vector<game_info>& game_data,
1919
const std::map<QString, QString>& notes_map,
2020
const std::map<QString, QString>& title_map,
21-
const std::string& selected_item_id,
21+
const std::set<std::string>& selected_item_ids,
2222
bool play_hover_movies) override;
2323

2424
void repaint_icons(std::vector<game_info>& game_data, const QColor& icon_color, const QSize& icon_size, qreal device_pixel_ratio) override;

rpcs3/rpcs3qt/game_list_table.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void game_list_table::populate(
204204
const std::vector<game_info>& game_data,
205205
const std::map<QString, QString>& notes_map,
206206
const std::map<QString, QString>& title_map,
207-
const std::string& selected_item_id,
207+
const std::set<std::string>& selected_item_ids,
208208
bool play_hover_movies)
209209
{
210210
clear_list();
@@ -219,7 +219,7 @@ void game_list_table::populate(
219219

220220
int row = 0;
221221
int index = -1;
222-
int selected_row = -1;
222+
std::set<int> selected_rows;
223223

224224
const auto get_title = [&title_map](const QString& serial, const std::string& name) -> QString
225225
{
@@ -378,15 +378,18 @@ void game_list_table::populate(
378378
setItem(row, static_cast<int>(gui::game_list_columns::compat), compat_item);
379379
setItem(row, static_cast<int>(gui::game_list_columns::dir_size), new custom_table_widget_item(game_size != umax ? gui::utils::format_byte_size(game_size) : tr("Unknown"), Qt::UserRole, QVariant::fromValue<qulonglong>(game_size)));
380380

381-
if (selected_item_id == game->info.path + game->info.icon_path)
381+
if (selected_item_ids.contains(game->info.path + game->info.icon_path))
382382
{
383-
selected_row = row;
383+
selected_rows.insert(row);
384384
}
385385

386386
row++;
387387
}
388388

389-
selectRow(selected_row);
389+
for (int selected_row : selected_rows)
390+
{
391+
selectionModel()->select(model()->index(selected_row, 0), QItemSelectionModel::Select | QItemSelectionModel::Rows);
392+
}
390393
}
391394

392395
void game_list_table::repaint_icons(std::vector<game_info>& game_data, const QColor& icon_color, const QSize& icon_size, qreal device_pixel_ratio)

rpcs3/rpcs3qt/game_list_table.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class game_list_table : public game_list
2828
const std::vector<game_info>& game_data,
2929
const std::map<QString, QString>& notes_map,
3030
const std::map<QString, QString>& title_map,
31-
const std::string& selected_item_id,
31+
const std::set<std::string>& selected_item_ids,
3232
bool play_hover_movies) override;
3333

3434
void repaint_icons(std::vector<game_info>& game_data, const QColor& icon_color, const QSize& icon_size, qreal device_pixel_ratio) override;

0 commit comments

Comments
 (0)