Merge pull request #5344 from vitor-k/fix-folder-order

game_list: Fix folder reordering
This commit is contained in:
Marshall Mohror 2020-06-20 13:23:44 -05:00 committed by GitHub
commit 8a080146c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 27 deletions

View File

@ -178,7 +178,7 @@ void GameList::onItemExpanded(const QModelIndex& item) {
const auto type = item.data(GameListItem::TypeRole).value<GameListItemType>(); const auto type = item.data(GameListItem::TypeRole).value<GameListItemType>();
if (type == GameListItemType::CustomDir || type == GameListItemType::InstalledDir || if (type == GameListItemType::CustomDir || type == GameListItemType::InstalledDir ||
type == GameListItemType::SystemDir) type == GameListItemType::SystemDir)
item.data(GameListDir::GameDirRole).value<UISettings::GameDir*>()->expanded = UISettings::values.game_dirs[item.data(GameListDir::GameDirRole).toInt()].expanded =
tree_view->isExpanded(item); tree_view->isExpanded(item);
} }
@ -252,9 +252,9 @@ void GameList::onUpdateThemedIcons() {
child->setData(QIcon::fromTheme(QStringLiteral("chip")).pixmap(48), Qt::DecorationRole); child->setData(QIcon::fromTheme(QStringLiteral("chip")).pixmap(48), Qt::DecorationRole);
break; break;
case GameListItemType::CustomDir: { case GameListItemType::CustomDir: {
const UISettings::GameDir* game_dir = const UISettings::GameDir& game_dir =
child->data(GameListDir::GameDirRole).value<UISettings::GameDir*>(); UISettings::values.game_dirs[child->data(GameListDir::GameDirRole).toInt()];
const QString icon_name = QFileInfo::exists(game_dir->path) const QString icon_name = QFileInfo::exists(game_dir.path)
? QStringLiteral("folder") ? QStringLiteral("folder")
: QStringLiteral("bad_folder"); : QStringLiteral("bad_folder");
child->setData(QIcon::fromTheme(icon_name).pixmap(48), Qt::DecorationRole); 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); item_model->invisibleRootItem()->appendRow(entry_items);
tree_view->setExpanded( tree_view->setExpanded(
entry_items->index(), entry_items->index(),
entry_items->data(GameListDir::GameDirRole).value<UISettings::GameDir*>()->expanded); UISettings::values.game_dirs[entry_items->data(GameListDir::GameDirRole).toInt()].expanded);
} }
void GameList::AddEntry(const QList<QStandardItem*>& entry_items, GameListDir* parent) { void GameList::AddEntry(const QList<QStandardItem*>& entry_items, GameListDir* parent) {
@ -546,7 +546,7 @@ void GameList::AddGamePopup(QMenu& context_menu, const QString& path, u64 progra
void GameList::AddCustomDirPopup(QMenu& context_menu, QModelIndex selected) { void GameList::AddCustomDirPopup(QMenu& context_menu, QModelIndex selected) {
UISettings::GameDir& game_dir = UISettings::GameDir& game_dir =
*selected.data(GameListDir::GameDirRole).value<UISettings::GameDir*>(); UISettings::values.game_dirs[selected.data(GameListDir::GameDirRole).toInt()];
QAction* deep_scan = context_menu.addAction(tr("Scan Subfolders")); QAction* deep_scan = context_menu.addAction(tr("Scan Subfolders"));
QAction* delete_dir = context_menu.addAction(tr("Remove Game Directory")); QAction* delete_dir = context_menu.addAction(tr("Remove Game Directory"));
@ -565,8 +565,7 @@ void GameList::AddCustomDirPopup(QMenu& context_menu, QModelIndex selected) {
} }
void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) { void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) {
UISettings::GameDir& game_dir = const int game_dir_index = selected.data(GameListDir::GameDirRole).toInt();
*selected.data(GameListDir::GameDirRole).value<UISettings::GameDir*>();
QAction* move_up = context_menu.addAction(tr(u8"\U000025b2 Move Up")); QAction* move_up = context_menu.addAction(tr(u8"\U000025b2 Move Up"));
QAction* move_down = context_menu.addAction(tr(u8"\U000025bc Move Down ")); QAction* move_down = context_menu.addAction(tr(u8"\U000025bc Move Down "));
@ -577,34 +576,39 @@ void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) {
move_up->setEnabled(row > 0); move_up->setEnabled(row > 0);
move_down->setEnabled(row < item_model->rowCount() - 2); 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 const int other_index = selected.sibling(row - 1, 0).data(GameListDir::GameDirRole).toInt();
std::swap(UISettings::values.game_dirs[UISettings::values.game_dirs.indexOf(game_dir)], // swap the items in the settings
UISettings::values.game_dirs[UISettings::values.game_dirs.indexOf( std::swap(UISettings::values.game_dirs[game_dir_index],
*selected.sibling(row - 1, 0) UISettings::values.game_dirs[other_index]);
.data(GameListDir::GameDirRole) // swap the indexes held by the QVariants
.value<UISettings::GameDir*>())]); 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 // move the treeview items
QList<QStandardItem*> item = item_model->takeRow(row); QList<QStandardItem*> item = item_model->takeRow(row);
item_model->invisibleRootItem()->insertRow(row - 1, item); 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 const int other_index = selected.sibling(row + 1, 0).data(GameListDir::GameDirRole).toInt();
std::swap(UISettings::values.game_dirs[UISettings::values.game_dirs.indexOf(game_dir)], // swap the items in the settings
UISettings::values.game_dirs[UISettings::values.game_dirs.indexOf( std::swap(UISettings::values.game_dirs[game_dir_index],
*selected.sibling(row + 1, 0) UISettings::values.game_dirs[other_index]);
.data(GameListDir::GameDirRole) // swap the indexes held by the QVariants
.value<UISettings::GameDir*>())]); 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 // move the treeview items
const QList<QStandardItem*> item = item_model->takeRow(row); const QList<QStandardItem*> item = item_model->takeRow(row);
item_model->invisibleRootItem()->insertRow(row + 1, item); 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, connect(open_directory_location, &QAction::triggered, [this, game_dir_index] {
[this, game_dir] { emit OpenDirectory(game_dir.path); }); emit OpenDirectory(UISettings::values.game_dirs[game_dir_index].path);
});
} }
void GameList::LoadCompatibilityList() { void GameList::LoadCompatibilityList() {

View File

@ -351,7 +351,7 @@ public:
setData(type(), TypeRole); setData(type(), TypeRole);
UISettings::GameDir* game_dir = &directory; 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); const int icon_size = IconSizes.at(UISettings::values.game_list_icon_size);
switch (dir_type) { switch (dir_type) {