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

@ -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<const UICommon::GameFile> 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<std::shared_ptr<const UICommon::GameFile>> 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<const UICommon::GameFile> GameList::FindGame(const std::string& path) const
{
return m_model->FindGame(path);
return m_model.FindGame(path);
}
std::shared_ptr<const UICommon::GameFile>
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);
}

View File

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