diff --git a/Source/Core/DolphinQt/CheatsManager.cpp b/Source/Core/DolphinQt/CheatsManager.cpp index edb9537c86..3c0dc72e76 100644 --- a/Source/Core/DolphinQt/CheatsManager.cpp +++ b/Source/Core/DolphinQt/CheatsManager.cpp @@ -33,7 +33,6 @@ #include "DolphinQt/Config/ARCodeWidget.h" #include "DolphinQt/Config/GeckoCodeWidget.h" -#include "DolphinQt/GameList/GameListModel.h" #include "DolphinQt/Settings.h" constexpr u32 MAX_RESULTS = 50; @@ -152,7 +151,8 @@ static bool Compare(T mem_value, T value, CompareType op) } } -CheatsManager::CheatsManager(QWidget* parent) : QDialog(parent) +CheatsManager::CheatsManager(const GameListModel& game_list_model, QWidget* parent) + : QDialog(parent), m_game_list_model(game_list_model) { setWindowTitle(tr("Cheats Manager")); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); @@ -175,11 +175,9 @@ void CheatsManager::OnStateChanged(Core::State state) if (state != Core::State::Running && state != Core::State::Paused) return; - auto* model = Settings::Instance().GetGameListModel(); - - for (int i = 0; i < model->rowCount(QModelIndex()); i++) + for (int i = 0; i < m_game_list_model.rowCount(QModelIndex()); i++) { - auto file = model->GetGameFile(i); + auto file = m_game_list_model.GetGameFile(i); if (file->GetGameID() == SConfig::GetInstance().GetGameID()) { diff --git a/Source/Core/DolphinQt/CheatsManager.h b/Source/Core/DolphinQt/CheatsManager.h index 7d0d1297f6..f1e0c1ec86 100644 --- a/Source/Core/DolphinQt/CheatsManager.h +++ b/Source/Core/DolphinQt/CheatsManager.h @@ -11,6 +11,7 @@ #include #include "Common/CommonTypes.h" +#include "DolphinQt/GameList/GameListModel.h" class ARCodeWidget; class QComboBox; @@ -39,7 +40,7 @@ class CheatsManager : public QDialog { Q_OBJECT public: - explicit CheatsManager(QWidget* parent = nullptr); + explicit CheatsManager(const GameListModel& game_list_model, QWidget* parent = nullptr); ~CheatsManager(); private: @@ -61,6 +62,7 @@ private: void OnMatchContextMenu(); void OnWatchItemChanged(QTableWidgetItem* item); + const GameListModel& m_game_list_model; std::vector m_results; std::vector m_watch; std::shared_ptr m_game_file; diff --git a/Source/Core/DolphinQt/GameList/GameList.cpp b/Source/Core/DolphinQt/GameList/GameList.cpp index 11cbadb2d3..c8412b4902 100644 --- a/Source/Core/DolphinQt/GameList/GameList.cpp +++ b/Source/Core/DolphinQt/GameList/GameList.cpp @@ -41,7 +41,6 @@ #include "DolphinQt/Config/PropertiesDialog.h" #include "DolphinQt/ConvertDialog.h" -#include "DolphinQt/GameList/GameListModel.h" #include "DolphinQt/GameList/GridProxyModel.h" #include "DolphinQt/GameList/ListProxyModel.h" #include "DolphinQt/MenuBar.h" @@ -54,27 +53,26 @@ #include "UICommon/GameFile.h" -GameList::GameList(QWidget* parent) : QStackedWidget(parent) +GameList::GameList(QWidget* parent) : QStackedWidget(parent), m_model(this) { - m_model = Settings::Instance().GetGameListModel(); m_list_proxy = new ListProxyModel(this); m_list_proxy->setSortCaseSensitivity(Qt::CaseInsensitive); m_list_proxy->setSortRole(GameListModel::SORT_ROLE); - m_list_proxy->setSourceModel(m_model); + m_list_proxy->setSourceModel(&m_model); m_grid_proxy = new GridProxyModel(this); - m_grid_proxy->setSourceModel(m_model); + m_grid_proxy->setSourceModel(&m_model); MakeListView(); MakeGridView(); MakeEmptyView(); if (Settings::GetQSettings().contains(QStringLiteral("gridview/scale"))) - m_model->SetScale(Settings::GetQSettings().value(QStringLiteral("gridview/scale")).toFloat()); + m_model.SetScale(Settings::GetQSettings().value(QStringLiteral("gridview/scale")).toFloat()); connect(m_list, &QTableView::doubleClicked, this, &GameList::GameSelected); connect(m_grid, &QListView::doubleClicked, this, &GameList::GameSelected); - connect(m_model, &QAbstractItemModel::rowsInserted, this, &GameList::ConsiderViewChange); - connect(m_model, &QAbstractItemModel::rowsRemoved, this, &GameList::ConsiderViewChange); + connect(&m_model, &QAbstractItemModel::rowsInserted, this, &GameList::ConsiderViewChange); + connect(&m_model, &QAbstractItemModel::rowsRemoved, this, &GameList::ConsiderViewChange); addWidget(m_list); addWidget(m_grid); @@ -94,7 +92,7 @@ GameList::GameList(QWidget* parent) : QStackedWidget(parent) void GameList::PurgeCache() { - m_model->PurgeCache(); + m_model.PurgeCache(); } void GameList::MakeListView() @@ -176,7 +174,7 @@ GameList::~GameList() { Settings::GetQSettings().setValue(QStringLiteral("tableheader/state"), m_list->horizontalHeader()->saveState()); - Settings::GetQSettings().setValue(QStringLiteral("gridview/scale"), m_model->GetScale()); + Settings::GetQSettings().setValue(QStringLiteral("gridview/scale"), m_model.GetScale()); } void GameList::UpdateColumnVisibility() @@ -368,21 +366,19 @@ void GameList::ShowContextMenu(const QPoint&) menu->addSeparator(); - auto* model = Settings::Instance().GetGameListModel(); - auto* tags_menu = menu->addMenu(tr("Tags")); auto path = game->GetFilePath(); - auto game_tags = model->GetGameTags(path); + auto game_tags = m_model.GetGameTags(path); - for (const auto& tag : model->GetAllTags()) + for (const auto& tag : m_model.GetAllTags()) { auto* tag_action = tags_menu->addAction(tag); tag_action->setCheckable(true); tag_action->setChecked(game_tags.contains(tag)); - connect(tag_action, &QAction::toggled, [path, tag, model](bool checked) { + connect(tag_action, &QAction::toggled, [path, tag, model = &m_model](bool checked) { if (!checked) model->RemoveGameTag(path, tag); else @@ -635,7 +631,7 @@ void GameList::DeleteFile() if (deletion_successful) { - m_model->RemoveGame(game->GetFilePath()); + m_model.RemoveGame(game->GetFilePath()); } else { @@ -686,7 +682,7 @@ std::shared_ptr GameList::GetSelectedGame() const if (sel_model->hasSelection()) { QModelIndex model_index = proxy->mapToSource(sel_model->selectedIndexes()[0]); - return m_model->GetGameFile(model_index.row()); + return m_model.GetGameFile(model_index.row()); } return {}; } @@ -714,7 +710,7 @@ QList> GameList::GetSelectedGames() co for (const auto& index : index_list) { QModelIndex model_index = proxy->mapToSource(index); - selected_list.push_back(m_model->GetGameFile(model_index.row())); + selected_list.push_back(m_model.GetGameFile(model_index.row())); } } return selected_list; @@ -728,18 +724,18 @@ bool GameList::HasMultipleSelected() const std::shared_ptr GameList::FindGame(const std::string& path) const { - return m_model->FindGame(path); + return m_model.FindGame(path); } std::shared_ptr GameList::FindSecondDisc(const UICommon::GameFile& game) const { - return m_model->FindSecondDisc(game); + return m_model.FindSecondDisc(game); } std::string GameList::GetNetPlayName(const UICommon::GameFile& game) const { - return m_model->GetNetPlayName(game); + return m_model.GetNetPlayName(game); } void GameList::SetViewColumn(int col, bool view) @@ -756,7 +752,7 @@ void GameList::SetPreferredView(bool list) void GameList::ConsiderViewChange() { - if (m_model->rowCount(QModelIndex()) > 0) + if (m_model.rowCount(QModelIndex()) > 0) { if (m_prefer_list) setCurrentWidget(m_list); @@ -905,7 +901,7 @@ void GameList::NewTag() if (tag.isEmpty()) return; - Settings::Instance().GetGameListModel()->NewTag(tag); + m_model.NewTag(tag); } void GameList::DeleteTag() @@ -915,12 +911,12 @@ void GameList::DeleteTag() if (tag.isEmpty()) return; - Settings::Instance().GetGameListModel()->DeleteTag(tag); + m_model.DeleteTag(tag); } void GameList::SetSearchTerm(const QString& term) { - m_model->SetSearchTerm(term); + m_model.SetSearchTerm(term); m_list_proxy->invalidate(); m_grid_proxy->invalidate(); @@ -930,7 +926,7 @@ void GameList::SetSearchTerm(const QString& term) void GameList::ZoomIn() { - m_model->SetScale(m_model->GetScale() + 0.1); + m_model.SetScale(m_model.GetScale() + 0.1); m_list_proxy->invalidate(); m_grid_proxy->invalidate(); @@ -940,10 +936,10 @@ void GameList::ZoomIn() void GameList::ZoomOut() { - if (m_model->GetScale() <= 0.1) + if (m_model.GetScale() <= 0.1) return; - m_model->SetScale(m_model->GetScale() - 0.1); + m_model.SetScale(m_model.GetScale() - 0.1); m_list_proxy->invalidate(); m_grid_proxy->invalidate(); @@ -955,7 +951,7 @@ void GameList::UpdateFont() { QFont f; - f.setPointSizeF(m_model->GetScale() * f.pointSize()); + f.setPointSizeF(m_model.GetScale() * f.pointSize()); m_grid->setFont(f); } diff --git a/Source/Core/DolphinQt/GameList/GameList.h b/Source/Core/DolphinQt/GameList/GameList.h index ec92ea08e0..8ed4c87ec8 100644 --- a/Source/Core/DolphinQt/GameList/GameList.h +++ b/Source/Core/DolphinQt/GameList/GameList.h @@ -8,7 +8,8 @@ #include -class GameListModel; +#include "DolphinQt/GameList/GameListModel.h" + class QLabel; class QListView; class QSortFilterProxyModel; @@ -46,6 +47,8 @@ public: void PurgeCache(); + const GameListModel& GetGameListModel() const { return m_model; } + signals: void GameSelected(); void NetPlayHost(const UICommon::GameFile& game); @@ -85,7 +88,7 @@ private: void ConsiderViewChange(); void UpdateFont(); - GameListModel* m_model; + GameListModel m_model; QSortFilterProxyModel* m_list_proxy; QSortFilterProxyModel* m_grid_proxy; diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index 4e654c8b64..7119e9e414 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -399,7 +399,7 @@ void MainWindow::CreateComponents() m_watch_widget = new WatchWidget(this); m_breakpoint_widget = new BreakpointWidget(this); m_code_widget = new CodeWidget(this); - m_cheats_manager = new CheatsManager(this); + m_cheats_manager = new CheatsManager(m_game_list->GetGameListModel(), this); const auto request_watch = [this](QString name, u32 addr) { m_watch_widget->AddWatch(name, addr); @@ -1286,8 +1286,9 @@ void MainWindow::BootWiiSystemMenu() void MainWindow::NetPlayInit() { - m_netplay_setup_dialog = new NetPlaySetupDialog(this); - m_netplay_dialog = new NetPlayDialog; + const auto& game_list_model = m_game_list->GetGameListModel(); + m_netplay_setup_dialog = new NetPlaySetupDialog(game_list_model, this); + m_netplay_dialog = new NetPlayDialog(game_list_model); #ifdef USE_DISCORD_PRESENCE m_netplay_discord = new DiscordHandler(this); #endif diff --git a/Source/Core/DolphinQt/NetPlay/GameListDialog.cpp b/Source/Core/DolphinQt/NetPlay/GameListDialog.cpp index d0723d3766..1117cbe4c6 100644 --- a/Source/Core/DolphinQt/NetPlay/GameListDialog.cpp +++ b/Source/Core/DolphinQt/NetPlay/GameListDialog.cpp @@ -10,11 +10,10 @@ #include #include -#include "DolphinQt/GameList/GameListModel.h" -#include "DolphinQt/Settings.h" #include "UICommon/GameFile.h" -GameListDialog::GameListDialog(QWidget* parent) : QDialog(parent) +GameListDialog::GameListDialog(const GameListModel& game_list_model, QWidget* parent) + : QDialog(parent), m_game_list_model(game_list_model) { setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setWindowTitle(tr("Select a game")); @@ -47,16 +46,14 @@ void GameListDialog::ConnectWidgets() void GameListDialog::PopulateGameList() { - auto* game_list_model = Settings::Instance().GetGameListModel(); - m_game_list->clear(); - for (int i = 0; i < game_list_model->rowCount(QModelIndex()); i++) + for (int i = 0; i < m_game_list_model.rowCount(QModelIndex()); i++) { - std::shared_ptr game = game_list_model->GetGameFile(i); + std::shared_ptr game = m_game_list_model.GetGameFile(i); auto* item = - new QListWidgetItem(QString::fromStdString(game_list_model->GetNetPlayName(*game))); + new QListWidgetItem(QString::fromStdString(m_game_list_model.GetNetPlayName(*game))); item->setData(Qt::UserRole, QVariant::fromValue(std::move(game))); m_game_list->addItem(item); } diff --git a/Source/Core/DolphinQt/NetPlay/GameListDialog.h b/Source/Core/DolphinQt/NetPlay/GameListDialog.h index 78e5f90ff3..11e50e05aa 100644 --- a/Source/Core/DolphinQt/NetPlay/GameListDialog.h +++ b/Source/Core/DolphinQt/NetPlay/GameListDialog.h @@ -6,7 +6,8 @@ #include -class GameListModel; +#include "DolphinQt/GameList/GameListModel.h" + class QVBoxLayout; class QListWidget; class QDialogButtonBox; @@ -20,7 +21,7 @@ class GameListDialog : public QDialog { Q_OBJECT public: - explicit GameListDialog(QWidget* parent); + explicit GameListDialog(const GameListModel& game_list_model, QWidget* parent); int exec() override; const UICommon::GameFile& GetSelectedGame() const; @@ -30,6 +31,7 @@ private: void ConnectWidgets(); void PopulateGameList(); + const GameListModel& m_game_list_model; QVBoxLayout* m_main_layout; QListWidget* m_game_list; QDialogButtonBox* m_button_box; diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp index dd3be6cc65..39b989d141 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp +++ b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp @@ -40,7 +40,6 @@ #include "Core/NetPlayServer.h" #include "Core/SyncIdentifier.h" -#include "DolphinQt/GameList/GameListModel.h" #include "DolphinQt/NetPlay/ChunkedProgressDialog.h" #include "DolphinQt/NetPlay/GameListDialog.h" #include "DolphinQt/NetPlay/MD5Dialog.h" @@ -60,8 +59,8 @@ #include "VideoCommon/RenderBase.h" #include "VideoCommon/VideoConfig.h" -NetPlayDialog::NetPlayDialog(QWidget* parent) - : QDialog(parent), m_game_list_model(Settings::Instance().GetGameListModel()) +NetPlayDialog::NetPlayDialog(const GameListModel& game_list_model, QWidget* parent) + : QDialog(parent), m_game_list_model(game_list_model) { setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); @@ -158,7 +157,7 @@ void NetPlayDialog::CreateMainLayout() Settings::Instance().GetNetPlayServer()->ComputeMD5(m_current_game_identifier); }); m_md5_menu->addAction(tr("Other game..."), this, [this] { - GameListDialog gld(this); + GameListDialog gld(m_game_list_model, this); if (gld.exec() != QDialog::Accepted) return; @@ -322,13 +321,13 @@ void NetPlayDialog::ConnectWidgets() connect(m_quit_button, &QPushButton::clicked, this, &NetPlayDialog::reject); connect(m_game_button, &QPushButton::clicked, [this] { - GameListDialog gld(this); + GameListDialog gld(m_game_list_model, this); if (gld.exec() == QDialog::Accepted) { Settings& settings = Settings::Instance(); const UICommon::GameFile& game = gld.GetSelectedGame(); - const std::string netplay_name = settings.GetGameListModel()->GetNetPlayName(game); + const std::string netplay_name = m_game_list_model.GetNetPlayName(game); settings.GetNetPlayServer()->ChangeGame(game.GetSyncIdentifier(), netplay_name); Settings::GetQSettings().setValue(QStringLiteral("netplay/hostgame"), @@ -1048,9 +1047,9 @@ NetPlayDialog::FindGameFile(const NetPlay::SyncIdentifier& sync_identifier, std::optional> game_file = RunOnObject(this, [this, &sync_identifier, found] { - for (int i = 0; i < m_game_list_model->rowCount(QModelIndex()); i++) + for (int i = 0; i < m_game_list_model.rowCount(QModelIndex()); i++) { - auto game_file = m_game_list_model->GetGameFile(i); + auto game_file = m_game_list_model.GetGameFile(i); *found = std::min(*found, game_file->CompareSyncIdentifier(sync_identifier)); if (*found == NetPlay::SyncIdentifierComparison::SameGame) return game_file; diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.h b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.h index 7459be4f16..bd32dd61f4 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.h +++ b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.h @@ -9,11 +9,11 @@ #include "Common/Lazy.h" #include "Core/NetPlayClient.h" +#include "DolphinQt/GameList/GameListModel.h" #include "VideoCommon/OnScreenDisplay.h" class ChunkedProgressDialog; class MD5Dialog; -class GameListModel; class PadMappingDialog; class QCheckBox; class QComboBox; @@ -31,7 +31,7 @@ class NetPlayDialog : public QDialog, public NetPlay::NetPlayUI { Q_OBJECT public: - explicit NetPlayDialog(QWidget* parent = nullptr); + explicit NetPlayDialog(const GameListModel& game_list_model, QWidget* parent = nullptr); ~NetPlayDialog(); void show(std::string nickname, bool use_traversal); @@ -151,7 +151,7 @@ private: std::string m_current_game_name; Common::Lazy m_external_ip_address; std::string m_nickname; - GameListModel* m_game_list_model = nullptr; + const GameListModel& m_game_list_model; bool m_use_traversal = false; bool m_is_copy_button_retry = false; bool m_got_stop_request = true; diff --git a/Source/Core/DolphinQt/NetPlay/NetPlaySetupDialog.cpp b/Source/Core/DolphinQt/NetPlay/NetPlaySetupDialog.cpp index adcfa3faf3..521ec48745 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlaySetupDialog.cpp +++ b/Source/Core/DolphinQt/NetPlay/NetPlaySetupDialog.cpp @@ -21,7 +21,6 @@ #include "Core/Config/NetplaySettings.h" #include "Core/NetPlayProto.h" -#include "DolphinQt/GameList/GameListModel.h" #include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/UTF8CodePointCountValidator.h" #include "DolphinQt/Settings.h" @@ -29,8 +28,8 @@ #include "UICommon/GameFile.h" #include "UICommon/NetPlayIndex.h" -NetPlaySetupDialog::NetPlaySetupDialog(QWidget* parent) - : QDialog(parent), m_game_list_model(Settings::Instance().GetGameListModel()) +NetPlaySetupDialog::NetPlaySetupDialog(const GameListModel& game_list_model, QWidget* parent) + : QDialog(parent), m_game_list_model(game_list_model) { setWindowTitle(tr("NetPlay Setup")); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); @@ -359,12 +358,12 @@ void NetPlaySetupDialog::PopulateGameList() QSignalBlocker blocker(m_host_games); m_host_games->clear(); - for (int i = 0; i < m_game_list_model->rowCount(QModelIndex()); i++) + for (int i = 0; i < m_game_list_model.rowCount(QModelIndex()); i++) { - std::shared_ptr game = m_game_list_model->GetGameFile(i); + std::shared_ptr game = m_game_list_model.GetGameFile(i); auto* item = - new QListWidgetItem(QString::fromStdString(m_game_list_model->GetNetPlayName(*game))); + new QListWidgetItem(QString::fromStdString(m_game_list_model.GetNetPlayName(*game))); item->setData(Qt::UserRole, QVariant::fromValue(std::move(game))); m_host_games->addItem(item); } diff --git a/Source/Core/DolphinQt/NetPlay/NetPlaySetupDialog.h b/Source/Core/DolphinQt/NetPlay/NetPlaySetupDialog.h index a2ff67264d..b3247df03b 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlaySetupDialog.h +++ b/Source/Core/DolphinQt/NetPlay/NetPlaySetupDialog.h @@ -6,7 +6,8 @@ #include -class GameListModel; +#include "DolphinQt/GameList/GameListModel.h" + class QCheckBox; class QComboBox; class QDialogButtonBox; @@ -27,7 +28,7 @@ class NetPlaySetupDialog : public QDialog { Q_OBJECT public: - explicit NetPlaySetupDialog(QWidget* parent); + explicit NetPlaySetupDialog(const GameListModel& game_list_model, QWidget* parent); void accept() override; void show(); @@ -79,5 +80,5 @@ private: QCheckBox* m_host_upnp; #endif - GameListModel* m_game_list_model; + const GameListModel& m_game_list_model; };