From 950c03283754ed00210fcbd1237fc3a2e48b9266 Mon Sep 17 00:00:00 2001 From: Vitor Kiguchi Date: Sat, 9 May 2020 23:36:40 -0300 Subject: [PATCH 1/3] change gameListDir to hold an index instead of a raw pointer --- src/citra_qt/game_list.cpp | 45 +++++++++++++++++--------------------- src/citra_qt/game_list_p.h | 2 +- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp index 8a5df5172..fd140cd60 100644 --- a/src/citra_qt/game_list.cpp +++ b/src/citra_qt/game_list.cpp @@ -178,7 +178,7 @@ void GameList::onItemExpanded(const QModelIndex& item) { const auto type = item.data(GameListItem::TypeRole).value(); if (type == GameListItemType::CustomDir || type == GameListItemType::InstalledDir || type == GameListItemType::SystemDir) - item.data(GameListDir::GameDirRole).value()->expanded = + UISettings::values.game_dirs[item.data(GameListDir::GameDirRole).toInt()].expanded = tree_view->isExpanded(item); } @@ -252,9 +252,9 @@ void GameList::onUpdateThemedIcons() { child->setData(QIcon::fromTheme(QStringLiteral("chip")).pixmap(48), Qt::DecorationRole); break; case GameListItemType::CustomDir: { - const UISettings::GameDir* game_dir = - child->data(GameListDir::GameDirRole).value(); - const QString icon_name = QFileInfo::exists(game_dir->path) + const UISettings::GameDir& game_dir = + UISettings::values.game_dirs[child->data(GameListDir::GameDirRole).toInt()]; + const QString icon_name = QFileInfo::exists(game_dir.path) ? QStringLiteral("folder") : QStringLiteral("bad_folder"); child->setData(QIcon::fromTheme(icon_name).pixmap(48), Qt::DecorationRole); @@ -352,7 +352,7 @@ void GameList::AddDirEntry(GameListDir* entry_items) { item_model->invisibleRootItem()->appendRow(entry_items); tree_view->setExpanded( entry_items->index(), - entry_items->data(GameListDir::GameDirRole).value()->expanded); + UISettings::values.game_dirs[entry_items->data(GameListDir::GameDirRole).toInt()].expanded); } void GameList::AddEntry(const QList& entry_items, GameListDir* parent) { @@ -545,8 +545,7 @@ void GameList::AddGamePopup(QMenu& context_menu, const QString& path, u64 progra }; void GameList::AddCustomDirPopup(QMenu& context_menu, QModelIndex selected) { - UISettings::GameDir& game_dir = - *selected.data(GameListDir::GameDirRole).value(); + UISettings::GameDir& game_dir = UISettings::values.game_dirs[selected.data(GameListDir::GameDirRole).toInt()]; QAction* deep_scan = context_menu.addAction(tr("Scan Subfolders")); QAction* delete_dir = context_menu.addAction(tr("Remove Game Directory")); @@ -565,8 +564,7 @@ void GameList::AddCustomDirPopup(QMenu& context_menu, QModelIndex selected) { } void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) { - UISettings::GameDir& game_dir = - *selected.data(GameListDir::GameDirRole).value(); + int game_dir_index = selected.data(GameListDir::GameDirRole).toInt(); QAction* move_up = context_menu.addAction(tr(u8"\U000025b2 Move Up")); QAction* move_down = context_menu.addAction(tr(u8"\U000025bc Move Down ")); @@ -577,34 +575,31 @@ void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) { move_up->setEnabled(row > 0); move_down->setEnabled(row < item_model->rowCount() - 2); - connect(move_up, &QAction::triggered, [this, selected, row, &game_dir] { + connect(move_up, &QAction::triggered, [this, selected, row, game_dir_index] { // find the indices of the items in settings and swap them - std::swap(UISettings::values.game_dirs[UISettings::values.game_dirs.indexOf(game_dir)], - UISettings::values.game_dirs[UISettings::values.game_dirs.indexOf( - *selected.sibling(row - 1, 0) - .data(GameListDir::GameDirRole) - .value())]); + std::swap(UISettings::values.game_dirs[game_dir_index], + UISettings::values.game_dirs[selected.sibling(row - 1, 0) + .data(GameListDir::GameDirRole).toInt()]); // move the treeview items QList item = item_model->takeRow(row); item_model->invisibleRootItem()->insertRow(row - 1, item); - tree_view->setExpanded(selected, game_dir.expanded); + tree_view->setExpanded(selected, UISettings::values.game_dirs[game_dir_index].expanded); }); - connect(move_down, &QAction::triggered, [this, selected, row, &game_dir] { + connect(move_down, &QAction::triggered, [this, selected, row, game_dir_index] { // find the indices of the items in settings and swap them - std::swap(UISettings::values.game_dirs[UISettings::values.game_dirs.indexOf(game_dir)], - UISettings::values.game_dirs[UISettings::values.game_dirs.indexOf( - *selected.sibling(row + 1, 0) - .data(GameListDir::GameDirRole) - .value())]); + std::swap(UISettings::values.game_dirs[game_dir_index], + UISettings::values.game_dirs[selected.sibling(row + 1, 0) + .data(GameListDir::GameDirRole).toInt()]); // move the treeview items const QList item = item_model->takeRow(row); item_model->invisibleRootItem()->insertRow(row + 1, item); - tree_view->setExpanded(selected, game_dir.expanded); + tree_view->setExpanded(selected, UISettings::values.game_dirs[game_dir_index].expanded); }); - connect(open_directory_location, &QAction::triggered, - [this, game_dir] { emit OpenDirectory(game_dir.path); }); + connect(open_directory_location, &QAction::triggered, [this, game_dir_index] { + emit OpenDirectory(UISettings::values.game_dirs[game_dir_index].path); + }); } void GameList::LoadCompatibilityList() { diff --git a/src/citra_qt/game_list_p.h b/src/citra_qt/game_list_p.h index acb9dbf66..6b4a7667f 100644 --- a/src/citra_qt/game_list_p.h +++ b/src/citra_qt/game_list_p.h @@ -351,7 +351,7 @@ public: setData(type(), TypeRole); UISettings::GameDir* game_dir = &directory; - setData(QVariant::fromValue(game_dir), GameDirRole); + setData(QVariant(UISettings::values.game_dirs.indexOf(directory)), GameDirRole); const int icon_size = IconSizes.at(UISettings::values.game_list_icon_size); switch (dir_type) { From fbf24e3ca40f0f296564239ae672a90ba893926c Mon Sep 17 00:00:00 2001 From: Vitor Kiguchi Date: Sat, 9 May 2020 23:44:41 -0300 Subject: [PATCH 2/3] game_list: fix folder reordering --- src/citra_qt/game_list.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp index fd140cd60..ed2c11e68 100644 --- a/src/citra_qt/game_list.cpp +++ b/src/citra_qt/game_list.cpp @@ -580,6 +580,8 @@ void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) { std::swap(UISettings::values.game_dirs[game_dir_index], UISettings::values.game_dirs[selected.sibling(row - 1, 0) .data(GameListDir::GameDirRole).toInt()]); + GetModel()->setData(selected, QVariant::fromValue(selected.sibling(row-1,0).data(GameListDir::GameDirRole).toInt()), GameListDir::GameDirRole); + GetModel()->setData(selected.sibling(row-1,0), QVariant::fromValue(game_dir_index), GameListDir::GameDirRole); // move the treeview items QList item = item_model->takeRow(row); item_model->invisibleRootItem()->insertRow(row - 1, item); @@ -591,6 +593,8 @@ void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) { std::swap(UISettings::values.game_dirs[game_dir_index], UISettings::values.game_dirs[selected.sibling(row + 1, 0) .data(GameListDir::GameDirRole).toInt()]); + GetModel()->setData(selected, QVariant::fromValue(selected.sibling(row+1,0).data(GameListDir::GameDirRole).toInt()), GameListDir::GameDirRole); + GetModel()->setData(selected.sibling(row+1,0), QVariant::fromValue(game_dir_index), GameListDir::GameDirRole); // move the treeview items const QList item = item_model->takeRow(row); item_model->invisibleRootItem()->insertRow(row + 1, item); From 01b9302a28ec6c6d588078e871a8afb2113f2870 Mon Sep 17 00:00:00 2001 From: Vitor Kiguchi Date: Sun, 10 May 2020 13:45:43 -0300 Subject: [PATCH 3/3] game_list: cleanup and clang format in AddPermDirPopup --- src/citra_qt/game_list.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp index ed2c11e68..e4e0c5788 100644 --- a/src/citra_qt/game_list.cpp +++ b/src/citra_qt/game_list.cpp @@ -545,7 +545,8 @@ void GameList::AddGamePopup(QMenu& context_menu, const QString& path, u64 progra }; void GameList::AddCustomDirPopup(QMenu& context_menu, QModelIndex selected) { - UISettings::GameDir& game_dir = UISettings::values.game_dirs[selected.data(GameListDir::GameDirRole).toInt()]; + UISettings::GameDir& game_dir = + UISettings::values.game_dirs[selected.data(GameListDir::GameDirRole).toInt()]; QAction* deep_scan = context_menu.addAction(tr("Scan Subfolders")); QAction* delete_dir = context_menu.addAction(tr("Remove Game Directory")); @@ -564,7 +565,7 @@ void GameList::AddCustomDirPopup(QMenu& context_menu, QModelIndex selected) { } void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) { - int game_dir_index = selected.data(GameListDir::GameDirRole).toInt(); + const int game_dir_index = selected.data(GameListDir::GameDirRole).toInt(); QAction* move_up = context_menu.addAction(tr(u8"\U000025b2 Move Up")); QAction* move_down = context_menu.addAction(tr(u8"\U000025bc Move Down ")); @@ -576,12 +577,14 @@ void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) { move_down->setEnabled(row < item_model->rowCount() - 2); connect(move_up, &QAction::triggered, [this, selected, row, game_dir_index] { - // find the indices of the items in settings and swap them + const int other_index = selected.sibling(row - 1, 0).data(GameListDir::GameDirRole).toInt(); + // swap the items in the settings std::swap(UISettings::values.game_dirs[game_dir_index], - UISettings::values.game_dirs[selected.sibling(row - 1, 0) - .data(GameListDir::GameDirRole).toInt()]); - GetModel()->setData(selected, QVariant::fromValue(selected.sibling(row-1,0).data(GameListDir::GameDirRole).toInt()), GameListDir::GameDirRole); - GetModel()->setData(selected.sibling(row-1,0), QVariant::fromValue(game_dir_index), GameListDir::GameDirRole); + UISettings::values.game_dirs[other_index]); + // swap the indexes held by the QVariants + GetModel()->setData(selected, QVariant(other_index), GameListDir::GameDirRole); + GetModel()->setData(selected.sibling(row - 1, 0), QVariant(game_dir_index), + GameListDir::GameDirRole); // move the treeview items QList item = item_model->takeRow(row); item_model->invisibleRootItem()->insertRow(row - 1, item); @@ -589,12 +592,14 @@ void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) { }); connect(move_down, &QAction::triggered, [this, selected, row, game_dir_index] { - // find the indices of the items in settings and swap them + const int other_index = selected.sibling(row + 1, 0).data(GameListDir::GameDirRole).toInt(); + // swap the items in the settings std::swap(UISettings::values.game_dirs[game_dir_index], - UISettings::values.game_dirs[selected.sibling(row + 1, 0) - .data(GameListDir::GameDirRole).toInt()]); - GetModel()->setData(selected, QVariant::fromValue(selected.sibling(row+1,0).data(GameListDir::GameDirRole).toInt()), GameListDir::GameDirRole); - GetModel()->setData(selected.sibling(row+1,0), QVariant::fromValue(game_dir_index), GameListDir::GameDirRole); + UISettings::values.game_dirs[other_index]); + // swap the indexes held by the QVariants + GetModel()->setData(selected, QVariant(other_index), GameListDir::GameDirRole); + GetModel()->setData(selected.sibling(row + 1, 0), QVariant(game_dir_index), + GameListDir::GameDirRole); // move the treeview items const QList item = item_model->takeRow(row); item_model->invisibleRootItem()->insertRow(row + 1, item);