diff options
| author | 2021-01-19 10:53:18 -0800 | |
|---|---|---|
| committer | 2021-01-19 10:53:18 -0800 | |
| commit | 4cd8b2f1f7837ad3f138148474846b5bdd8c824e (patch) | |
| tree | b1c2c70a1f75924bfff666ef670d4b12f3ddb548 | |
| parent | Merge pull request #5746 from lioncash/sign-compare (diff) | |
| parent | game_list: Fix folder reordering (diff) | |
| download | yuzu-4cd8b2f1f7837ad3f138148474846b5bdd8c824e.tar.gz yuzu-4cd8b2f1f7837ad3f138148474846b5bdd8c824e.tar.xz yuzu-4cd8b2f1f7837ad3f138148474846b5bdd8c824e.zip | |
Merge pull request #5755 from FearlessTobi/port-5344
Port citra-emu/citra#5344: "game_list: Fix folder reordering"
Diffstat (limited to '')
| -rw-r--r-- | src/yuzu/game_list.cpp | 58 | ||||
| -rw-r--r-- | src/yuzu/game_list_p.h | 2 |
2 files changed, 32 insertions, 28 deletions
diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index 37b0d1a0e..9afd5b45f 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp | |||
| @@ -173,8 +173,8 @@ void GameList::OnItemExpanded(const QModelIndex& item) { | |||
| 173 | return; | 173 | return; |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | auto* game_dir = item.data(GameListDir::GameDirRole).value<UISettings::GameDir*>(); | 176 | UISettings::values.game_dirs[item.data(GameListDir::GameDirRole).toInt()].expanded = |
| 177 | game_dir->expanded = tree_view->isExpanded(item); | 177 | tree_view->isExpanded(item); |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | // Event in order to filter the gamelist after editing the searchfield | 180 | // Event in order to filter the gamelist after editing the searchfield |
| @@ -262,9 +262,9 @@ void GameList::OnUpdateThemedIcons() { | |||
| 262 | Qt::DecorationRole); | 262 | Qt::DecorationRole); |
| 263 | break; | 263 | break; |
| 264 | case GameListItemType::CustomDir: { | 264 | case GameListItemType::CustomDir: { |
| 265 | const UISettings::GameDir* game_dir = | 265 | const UISettings::GameDir& game_dir = |
| 266 | child->data(GameListDir::GameDirRole).value<UISettings::GameDir*>(); | 266 | UISettings::values.game_dirs[child->data(GameListDir::GameDirRole).toInt()]; |
| 267 | const QString icon_name = QFileInfo::exists(game_dir->path) | 267 | const QString icon_name = QFileInfo::exists(game_dir.path) |
| 268 | ? QStringLiteral("folder") | 268 | ? QStringLiteral("folder") |
| 269 | : QStringLiteral("bad_folder"); | 269 | : QStringLiteral("bad_folder"); |
| 270 | child->setData( | 270 | child->setData( |
| @@ -366,7 +366,7 @@ void GameList::AddDirEntry(GameListDir* entry_items) { | |||
| 366 | item_model->invisibleRootItem()->appendRow(entry_items); | 366 | item_model->invisibleRootItem()->appendRow(entry_items); |
| 367 | tree_view->setExpanded( | 367 | tree_view->setExpanded( |
| 368 | entry_items->index(), | 368 | entry_items->index(), |
| 369 | entry_items->data(GameListDir::GameDirRole).value<UISettings::GameDir*>()->expanded); | 369 | UISettings::values.game_dirs[entry_items->data(GameListDir::GameDirRole).toInt()].expanded); |
| 370 | } | 370 | } |
| 371 | 371 | ||
| 372 | void GameList::AddEntry(const QList<QStandardItem*>& entry_items, GameListDir* parent) { | 372 | void GameList::AddEntry(const QList<QStandardItem*>& entry_items, GameListDir* parent) { |
| @@ -549,7 +549,7 @@ void GameList::AddGamePopup(QMenu& context_menu, u64 program_id, const std::stri | |||
| 549 | 549 | ||
| 550 | void GameList::AddCustomDirPopup(QMenu& context_menu, QModelIndex selected) { | 550 | void GameList::AddCustomDirPopup(QMenu& context_menu, QModelIndex selected) { |
| 551 | UISettings::GameDir& game_dir = | 551 | UISettings::GameDir& game_dir = |
| 552 | *selected.data(GameListDir::GameDirRole).value<UISettings::GameDir*>(); | 552 | UISettings::values.game_dirs[selected.data(GameListDir::GameDirRole).toInt()]; |
| 553 | 553 | ||
| 554 | QAction* deep_scan = context_menu.addAction(tr("Scan Subfolders")); | 554 | QAction* deep_scan = context_menu.addAction(tr("Scan Subfolders")); |
| 555 | QAction* delete_dir = context_menu.addAction(tr("Remove Game Directory")); | 555 | QAction* delete_dir = context_menu.addAction(tr("Remove Game Directory")); |
| @@ -568,8 +568,7 @@ void GameList::AddCustomDirPopup(QMenu& context_menu, QModelIndex selected) { | |||
| 568 | } | 568 | } |
| 569 | 569 | ||
| 570 | void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) { | 570 | void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) { |
| 571 | UISettings::GameDir& game_dir = | 571 | const int game_dir_index = selected.data(GameListDir::GameDirRole).toInt(); |
| 572 | *selected.data(GameListDir::GameDirRole).value<UISettings::GameDir*>(); | ||
| 573 | 572 | ||
| 574 | QAction* move_up = context_menu.addAction(tr("\u25B2 Move Up")); | 573 | QAction* move_up = context_menu.addAction(tr("\u25B2 Move Up")); |
| 575 | QAction* move_down = context_menu.addAction(tr("\u25bc Move Down")); | 574 | QAction* move_down = context_menu.addAction(tr("\u25bc Move Down")); |
| @@ -580,34 +579,39 @@ void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) { | |||
| 580 | move_up->setEnabled(row > 0); | 579 | move_up->setEnabled(row > 0); |
| 581 | move_down->setEnabled(row < item_model->rowCount() - 2); | 580 | move_down->setEnabled(row < item_model->rowCount() - 2); |
| 582 | 581 | ||
| 583 | connect(move_up, &QAction::triggered, [this, selected, row, &game_dir] { | 582 | connect(move_up, &QAction::triggered, [this, selected, row, game_dir_index] { |
| 584 | // find the indices of the items in settings and swap them | 583 | const int other_index = selected.sibling(row - 1, 0).data(GameListDir::GameDirRole).toInt(); |
| 585 | std::swap(UISettings::values.game_dirs[UISettings::values.game_dirs.indexOf(game_dir)], | 584 | // swap the items in the settings |
| 586 | UISettings::values.game_dirs[UISettings::values.game_dirs.indexOf( | 585 | std::swap(UISettings::values.game_dirs[game_dir_index], |
| 587 | *selected.sibling(row - 1, 0) | 586 | UISettings::values.game_dirs[other_index]); |
| 588 | .data(GameListDir::GameDirRole) | 587 | // swap the indexes held by the QVariants |
| 589 | .value<UISettings::GameDir*>())]); | 588 | item_model->setData(selected, QVariant(other_index), GameListDir::GameDirRole); |
| 589 | item_model->setData(selected.sibling(row - 1, 0), QVariant(game_dir_index), | ||
| 590 | GameListDir::GameDirRole); | ||
| 590 | // move the treeview items | 591 | // move the treeview items |
| 591 | QList<QStandardItem*> item = item_model->takeRow(row); | 592 | QList<QStandardItem*> item = item_model->takeRow(row); |
| 592 | item_model->invisibleRootItem()->insertRow(row - 1, item); | 593 | item_model->invisibleRootItem()->insertRow(row - 1, item); |
| 593 | tree_view->setExpanded(selected, game_dir.expanded); | 594 | tree_view->setExpanded(selected, UISettings::values.game_dirs[game_dir_index].expanded); |
| 594 | }); | 595 | }); |
| 595 | 596 | ||
| 596 | connect(move_down, &QAction::triggered, [this, selected, row, &game_dir] { | 597 | connect(move_down, &QAction::triggered, [this, selected, row, game_dir_index] { |
| 597 | // find the indices of the items in settings and swap them | 598 | const int other_index = selected.sibling(row + 1, 0).data(GameListDir::GameDirRole).toInt(); |
| 598 | std::swap(UISettings::values.game_dirs[UISettings::values.game_dirs.indexOf(game_dir)], | 599 | // swap the items in the settings |
| 599 | UISettings::values.game_dirs[UISettings::values.game_dirs.indexOf( | 600 | std::swap(UISettings::values.game_dirs[game_dir_index], |
| 600 | *selected.sibling(row + 1, 0) | 601 | UISettings::values.game_dirs[other_index]); |
| 601 | .data(GameListDir::GameDirRole) | 602 | // swap the indexes held by the QVariants |
| 602 | .value<UISettings::GameDir*>())]); | 603 | item_model->setData(selected, QVariant(other_index), GameListDir::GameDirRole); |
| 604 | item_model->setData(selected.sibling(row + 1, 0), QVariant(game_dir_index), | ||
| 605 | GameListDir::GameDirRole); | ||
| 603 | // move the treeview items | 606 | // move the treeview items |
| 604 | const QList<QStandardItem*> item = item_model->takeRow(row); | 607 | const QList<QStandardItem*> item = item_model->takeRow(row); |
| 605 | item_model->invisibleRootItem()->insertRow(row + 1, item); | 608 | item_model->invisibleRootItem()->insertRow(row + 1, item); |
| 606 | tree_view->setExpanded(selected, game_dir.expanded); | 609 | tree_view->setExpanded(selected, UISettings::values.game_dirs[game_dir_index].expanded); |
| 607 | }); | 610 | }); |
| 608 | 611 | ||
| 609 | connect(open_directory_location, &QAction::triggered, | 612 | connect(open_directory_location, &QAction::triggered, [this, game_dir_index] { |
| 610 | [this, game_dir] { emit OpenDirectory(game_dir.path); }); | 613 | emit OpenDirectory(UISettings::values.game_dirs[game_dir_index].path); |
| 614 | }); | ||
| 611 | } | 615 | } |
| 612 | 616 | ||
| 613 | void GameList::LoadCompatibilityList() { | 617 | void GameList::LoadCompatibilityList() { |
diff --git a/src/yuzu/game_list_p.h b/src/yuzu/game_list_p.h index df935022d..f25445f18 100644 --- a/src/yuzu/game_list_p.h +++ b/src/yuzu/game_list_p.h | |||
| @@ -230,7 +230,7 @@ public: | |||
| 230 | setData(type(), TypeRole); | 230 | setData(type(), TypeRole); |
| 231 | 231 | ||
| 232 | UISettings::GameDir* game_dir = &directory; | 232 | UISettings::GameDir* game_dir = &directory; |
| 233 | setData(QVariant::fromValue(game_dir), GameDirRole); | 233 | setData(QVariant(UISettings::values.game_dirs.indexOf(directory)), GameDirRole); |
| 234 | 234 | ||
| 235 | const int icon_size = std::min(static_cast<int>(UISettings::values.icon_size), 64); | 235 | const int icon_size = std::min(static_cast<int>(UISettings::values.icon_size), 64); |
| 236 | switch (dir_type) { | 236 | switch (dir_type) { |