GameListModel instance ownership transferred back to the GameList instance. The GameListModel instance will be passed as a constructor parameter where needed.

This commit is contained in:
Christian Aguilera
2019-01-17 22:28:07 +00:00
parent 0d02e70d4a
commit 5b757024c4
11 changed files with 69 additions and 71 deletions

View File

@ -10,11 +10,10 @@
#include <QListWidget>
#include <QVBoxLayout>
#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<const UICommon::GameFile> game = game_list_model->GetGameFile(i);
std::shared_ptr<const UICommon::GameFile> 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);
}

View File

@ -6,7 +6,8 @@
#include <QDialog>
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;

View File

@ -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<std::shared_ptr<const UICommon::GameFile>> 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;

View File

@ -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<std::string> 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;

View File

@ -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<const UICommon::GameFile> game = m_game_list_model->GetGameFile(i);
std::shared_ptr<const UICommon::GameFile> 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);
}

View File

@ -6,7 +6,8 @@
#include <QDialog>
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;
};