From 7a8f4840205799d837ac32401b4143c716a8bc3d Mon Sep 17 00:00:00 2001 From: fearlessTobi Date: Fri, 3 May 2019 19:21:57 +0200 Subject: [PATCH] Address trivial review comments --- src/yuzu/configuration/config.cpp | 4 +- src/yuzu/game_list.cpp | 71 ++++++++++++++++--------------- src/yuzu/game_list.h | 2 +- src/yuzu/game_list_p.h | 21 +++++---- src/yuzu/game_list_worker.cpp | 6 +-- src/yuzu/main.cpp | 6 +-- src/yuzu/main.h | 2 +- 7 files changed, 59 insertions(+), 53 deletions(-) diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index f2f116a873..b2683faf85 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -521,7 +521,7 @@ void Config::ReadPathValues() { ReadSetting(QStringLiteral("gameListRootDir"), QStringLiteral(".")).toString(); UISettings::values.game_dir_deprecated_deepscan = ReadSetting(QStringLiteral("gameListDeepScan"), false).toBool(); - int gamedirs_size = qt_config->beginReadArray(QStringLiteral("gamedirs")); + const int gamedirs_size = qt_config->beginReadArray(QStringLiteral("gamedirs")); for (int i = 0; i < gamedirs_size; ++i) { qt_config->setArrayIndex(i); UISettings::GameDir game_dir; @@ -927,7 +927,7 @@ void Config::SavePathValues() { qt_config->beginWriteArray(QStringLiteral("gamedirs")); for (int i = 0; i < UISettings::values.game_dirs.size(); ++i) { qt_config->setArrayIndex(i); - const auto& game_dir = UISettings::values.game_dirs.at(i); + const auto& game_dir = UISettings::values.game_dirs[i]; WriteSetting(QStringLiteral("path"), game_dir.path); WriteSetting(QStringLiteral("deep_scan"), game_dir.deep_scan, false); WriteSetting(QStringLiteral("expanded"), game_dir.expanded, true); diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index 65947c59bd..e5627abd4c 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp @@ -87,12 +87,12 @@ QString GameList::getLastFilterResultItem() { QStandardItem* folder; QStandardItem* child; QString file_path; - int folder_count = item_model->rowCount(); + const int folder_count = item_model->rowCount(); for (int i = 0; i < folder_count; ++i) { folder = item_model->item(i, 0); - QModelIndex folder_index = folder->index(); - int childrenCount = folder->rowCount(); - for (int j = 0; j < childrenCount; ++j) { + const QModelIndex folder_index = folder->index(); + const int children_count = folder->rowCount(); + for (int j = 0; j < children_count; ++j) { if (!tree_view->isRowHidden(j, folder_index)) { child = folder->child(j, 0); file_path = child->data(GameListItemPath::FullPathRole).toString(); @@ -160,7 +160,7 @@ static bool ContainsAllWords(const QString& haystack, const QString& userinput) // Syncs the expanded state of Game Directories with settings to persist across sessions void GameList::onItemExpanded(const QModelIndex& item) { - GameListItemType type = item.data(GameListItem::TypeRole).value(); + const auto type = item.data(GameListItem::TypeRole).value(); if (type == GameListItemType::CustomDir || type == GameListItemType::InstalledDir || type == GameListItemType::SystemDir) item.data(GameListDir::GameDirRole).value()->expanded = @@ -169,11 +169,11 @@ void GameList::onItemExpanded(const QModelIndex& item) { // Event in order to filter the gamelist after editing the searchfield void GameList::onTextChanged(const QString& new_text) { - int folder_count = tree_view->model()->rowCount(); + const int folder_count = tree_view->model()->rowCount(); QString edit_filter_text = new_text.toLower(); QStandardItem* folder; QStandardItem* child; - int childrenTotal = 0; + int children_total = 0; QModelIndex root_index = item_model->invisibleRootItem()->index(); // If the searchfield is empty every item is visible @@ -181,22 +181,22 @@ void GameList::onTextChanged(const QString& new_text) { if (edit_filter_text.isEmpty()) { for (int i = 0; i < folder_count; ++i) { folder = item_model->item(i, 0); - QModelIndex folder_index = folder->index(); - int childrenCount = folder->rowCount(); - for (int j = 0; j < childrenCount; ++j) { - ++childrenTotal; + const QModelIndex folder_index = folder->index(); + const int children_count = folder->rowCount(); + for (int j = 0; j < children_count; ++j) { + ++children_total; tree_view->setRowHidden(j, folder_index, false); } } - search_field->setFilterResult(childrenTotal, childrenTotal); + search_field->setFilterResult(children_total, children_total); } else { int result_count = 0; for (int i = 0; i < folder_count; ++i) { folder = item_model->item(i, 0); - QModelIndex folder_index = folder->index(); - int childrenCount = folder->rowCount(); - for (int j = 0; j < childrenCount; ++j) { - ++childrenTotal; + const QModelIndex folder_index = folder->index(); + const int children_count = folder->rowCount(); + for (int j = 0; j < children_count; ++j) { + ++children_total; const QStandardItem* child = folder->child(j, 0); const QString file_path = child->data(GameListItemPath::FullPathRole).toString().toLower(); @@ -220,7 +220,7 @@ void GameList::onTextChanged(const QString& new_text) { } else { tree_view->setRowHidden(j, folder_index, true); } - search_field->setFilterResult(result_count, childrenTotal); + search_field->setFilterResult(result_count, children_total); } } } @@ -230,7 +230,7 @@ void GameList::onUpdateThemedIcons() { for (int i = 0; i < item_model->invisibleRootItem()->rowCount(); i++) { QStandardItem* child = item_model->invisibleRootItem()->child(i); - int icon_size = UISettings::values.icon_size; + const int icon_size = UISettings::values.icon_size; switch (child->data(GameListItem::TypeRole).value()) { case GameListItemType::InstalledDir: child->setData( @@ -249,8 +249,9 @@ void GameList::onUpdateThemedIcons() { case GameListItemType::CustomDir: { const UISettings::GameDir* game_dir = child->data(GameListDir::GameDirRole).value(); - QString icon_name = QFileInfo::exists(game_dir->path) ? QStringLiteral("folder") - : QStringLiteral("bad_folder"); + const QString icon_name = QFileInfo::exists(game_dir->path) + ? QStringLiteral("folder") + : QStringLiteral("bad_folder"); child->setData( QIcon::fromTheme(icon_name).pixmap(icon_size).scaled( icon_size, icon_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), @@ -357,14 +358,14 @@ void GameList::AddEntry(const QList& entry_items, GameListDir* p } void GameList::ValidateEntry(const QModelIndex& item) { - auto selected = item.sibling(item.row(), 0); + const auto selected = item.sibling(item.row(), 0); switch (selected.data(GameListItem::TypeRole).value()) { case GameListItemType::Game: { - QString file_path = selected.data(GameListItemPath::FullPathRole).toString(); + const QString file_path = selected.data(GameListItemPath::FullPathRole).toString(); if (file_path.isEmpty()) return; - QFileInfo file_info(file_path); + const QFileInfo file_info(file_path); if (!file_info.exists()) return; @@ -391,7 +392,7 @@ void GameList::ValidateEntry(const QModelIndex& item) { bool GameList::isEmpty() { for (int i = 0; i < item_model->rowCount(); i++) { const QStandardItem* child = item_model->invisibleRootItem()->child(i); - GameListItemType type = static_cast(child->type()); + const auto type = static_cast(child->type()); if (!child->hasChildren() && (type == GameListItemType::InstalledDir || type == GameListItemType::SystemDir)) { item_model->invisibleRootItem()->removeRow(child->row()); @@ -422,16 +423,16 @@ void GameList::DonePopulating(QStringList watch_list) { QCoreApplication::processEvents(); } tree_view->setEnabled(true); - int folder_count = tree_view->model()->rowCount(); - int childrenTotal = 0; + const int folder_count = tree_view->model()->rowCount(); + int children_total = 0; for (int i = 0; i < folder_count; ++i) { - int childrenCount = item_model->item(i, 0)->rowCount(); - for (int j = 0; j < childrenCount; ++j) { - ++childrenTotal; + int children_count = item_model->item(i, 0)->rowCount(); + for (int j = 0; j < children_count; ++j) { + ++children_total; } } - search_field->setFilterResult(childrenTotal, childrenTotal); - if (childrenTotal > 0) { + search_field->setFilterResult(children_total, children_total); + if (children_total > 0) { search_field->setFocus(); } } @@ -441,7 +442,7 @@ void GameList::PopupContextMenu(const QPoint& menu_location) { if (!item.isValid()) return; - auto selected = item.sibling(item.row(), 0); + const auto selected = item.sibling(item.row(), 0); QMenu context_menu; switch (selected.data(GameListItem::TypeRole).value()) { case GameListItemType::Game: @@ -523,7 +524,7 @@ void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) { QAction* move_down = context_menu.addAction(tr(u8"\U000025bc Move Down ")); QAction* open_directory_location = context_menu.addAction(tr("Open Directory Location")); - int row = selected.row(); + const int row = selected.row(); move_up->setEnabled(row > 0); move_down->setEnabled(row < item_model->rowCount() - 2); @@ -532,7 +533,7 @@ void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) { // find the indices of the items in settings and swap them UISettings::values.game_dirs.swap( UISettings::values.game_dirs.indexOf(game_dir), - UISettings::values.game_dirs.indexOf(*selected.sibling(selected.row() - 1, 0) + UISettings::values.game_dirs.indexOf(*selected.sibling(row - 1, 0) .data(GameListDir::GameDirRole) .value())); // move the treeview items @@ -549,7 +550,7 @@ void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) { .data(GameListDir::GameDirRole) .value())); // move the treeview items - QList item = item_model->takeRow(row); + const QList item = item_model->takeRow(row); item_model->invisibleRootItem()->insertRow(row + 1, item); tree_view->setExpanded(selected, game_dir.expanded); }); diff --git a/src/yuzu/game_list.h b/src/yuzu/game_list.h index a2b58aba56..cf5bd3a39c 100644 --- a/src/yuzu/game_list.h +++ b/src/yuzu/game_list.h @@ -80,7 +80,7 @@ signals: void NavigateToGamedbEntryRequested(u64 program_id, const CompatibilityList& compatibility_list); void OpenPerGameGeneralRequested(const std::string& file); - void OpenDirectory(QString directory); + void OpenDirectory(const QString& directory); void AddDirectory(); void ShowList(bool show); diff --git a/src/yuzu/game_list_p.h b/src/yuzu/game_list_p.h index f5abb759d8..13623f5269 100644 --- a/src/yuzu/game_list_p.h +++ b/src/yuzu/game_list_p.h @@ -220,12 +220,14 @@ public: UISettings::GameDir* game_dir = &directory; setData(QVariant::fromValue(game_dir), GameDirRole); - int icon_size = UISettings::values.icon_size; + const int icon_size = UISettings::values.icon_size; switch (dir_type) { case GameListItemType::InstalledDir: - setData(QIcon::fromTheme("sd_card").pixmap(icon_size).scaled( - icon_size, icon_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), - Qt::DecorationRole); + setData( + QIcon::fromTheme(QStringLiteral("sd_card")) + .pixmap(icon_size) + .scaled(icon_size, icon_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), + Qt::DecorationRole); setData("Installed Titles", Qt::DisplayRole); break; case GameListItemType::SystemDir: @@ -235,7 +237,9 @@ public: setData("System Titles", Qt::DisplayRole); break; case GameListItemType::CustomDir: - QString icon_name = QFileInfo::exists(game_dir->path) ? "folder" : "bad_folder"; + const QString icon_name = QFileInfo::exists(game_dir->path) + ? QStringLiteral("folder") + : QStringLiteral("bad_folder"); setData(QIcon::fromTheme(icon_name).pixmap(icon_size).scaled( icon_size, icon_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), Qt::DecorationRole); @@ -257,9 +261,10 @@ public: explicit GameListAddDir() { setData(type(), TypeRole); - int icon_size = UISettings::values.icon_size; - setData(QIcon::fromTheme("plus").pixmap(icon_size).scaled( - icon_size, icon_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), + const int icon_size = UISettings::values.icon_size; + setData(QIcon::fromTheme(QStringLiteral("plus")) + .pixmap(icon_size) + .scaled(icon_size, icon_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), Qt::DecorationRole); setData("Add New Game Directory", Qt::DisplayRole); } diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index 8c6621c982..e1e69bc1a3 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp @@ -354,16 +354,16 @@ void GameListWorker::run() { for (UISettings::GameDir& game_dir : game_dirs) { if (game_dir.path == "INSTALLED") { - GameListDir* game_list_dir = new GameListDir(game_dir, GameListItemType::InstalledDir); + auto* const game_list_dir = new GameListDir(game_dir, GameListItemType::InstalledDir); emit DirEntryReady({game_list_dir}); AddTitlesToGameList(game_list_dir); } else if (game_dir.path == "SYSTEM") { - GameListDir* game_list_dir = new GameListDir(game_dir, GameListItemType::SystemDir); + auto* const game_list_dir = new GameListDir(game_dir, GameListItemType::SystemDir); emit DirEntryReady({game_list_dir}); AddTitlesToGameList(game_list_dir); } else { watch_list.append(game_dir.path); - GameListDir* game_list_dir = new GameListDir(game_dir); + auto* const game_list_dir = new GameListDir(game_dir); emit DirEntryReady({game_list_dir}); provider->ClearAllEntries(); ScanFileSystem(ScanTarget::FillManualContentProvider, game_dir.path.toStdString(), 2, diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index b2de9545b9..3146e054cf 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -1309,11 +1309,11 @@ void GMainWindow::OnGameListNavigateToGamedbEntry(u64 program_id, QDesktopServices::openUrl(QUrl(QStringLiteral("https://yuzu-emu.org/game/") + directory)); } -void GMainWindow::OnGameListOpenDirectory(QString directory) { +void GMainWindow::OnGameListOpenDirectory(const QString& directory) { QString path; if (directory == QStringLiteral("INSTALLED")) { // TODO: Find a better solution when installing files to the SD card gets implemented - path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir).c_str() + + path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + std::string("user/Contents/registered")); } else if (directory == QStringLiteral("SYSTEM")) { path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir).c_str() + @@ -1329,7 +1329,7 @@ void GMainWindow::OnGameListOpenDirectory(QString directory) { } void GMainWindow::OnGameListAddDirectory() { - QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory")); + const QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory")); if (dir_path.isEmpty()) return; UISettings::GameDir game_dir{dir_path, false, true}; diff --git a/src/yuzu/main.h b/src/yuzu/main.h index b7398b6c78..7d16188cbc 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -187,7 +187,7 @@ private slots: void OnGameListCopyTID(u64 program_id); void OnGameListNavigateToGamedbEntry(u64 program_id, const CompatibilityList& compatibility_list); - void OnGameListOpenDirectory(QString path); + void OnGameListOpenDirectory(const QString& directory); void OnGameListAddDirectory(); void OnGameListShowList(bool show); void OnGameListOpenPerGameProperties(const std::string& file);