Merge pull request #5786 from grimpunch/qt_viewoptions

Qt: Implement Show Platforms / Show Regions
This commit is contained in:
Leo Lam
2017-07-26 12:02:14 +08:00
committed by GitHub
13 changed files with 181 additions and 2 deletions

View File

@ -26,6 +26,7 @@
#include "DolphinQt2/Config/PropertiesDialog.h"
#include "DolphinQt2/GameList/GameList.h"
#include "DolphinQt2/GameList/ListProxyModel.h"
#include "DolphinQt2/GameList/TableProxyModel.h"
#include "DolphinQt2/QtUtils/DoubleClickEventFilter.h"
#include "DolphinQt2/Settings.h"
@ -34,7 +35,7 @@ static bool CompressCB(const std::string&, float, void*);
GameList::GameList(QWidget* parent) : QStackedWidget(parent)
{
m_model = new GameListModel(this);
m_table_proxy = new QSortFilterProxyModel(this);
m_table_proxy = new TableProxyModel(this);
m_table_proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
m_table_proxy->setSortRole(Qt::InitialSortOrderRole);
m_table_proxy->setSourceModel(m_model);
@ -446,6 +447,12 @@ void GameList::OnColumnVisibilityToggled(const QString& row, bool visible)
m_table->setColumnHidden(rowname_to_col_index[row], !visible);
}
void GameList::OnGameListVisibilityChanged()
{
m_table_proxy->invalidate();
m_list_proxy->invalidate();
}
static bool CompressCB(const std::string& text, float percent, void* ptr)
{
if (ptr == nullptr)

View File

@ -25,6 +25,7 @@ public:
void SetListView() { SetPreferredView(false); }
void SetViewColumn(int col, bool view) { m_table->setColumnHidden(col, !view); }
void OnColumnVisibilityToggled(const QString& row, bool visible);
void OnGameListVisibilityChanged();
signals:
void GameSelected();

View File

@ -3,7 +3,7 @@
// Refer to the license.txt file included.
#include "DolphinQt2/GameList/GameListModel.h"
#include "Core/ConfigManager.h"
#include "DiscIO/Enums.h"
#include "DolphinQt2/Resources.h"
#include "DolphinQt2/Settings.h"
@ -138,6 +138,63 @@ int GameListModel::columnCount(const QModelIndex& parent) const
return NUM_COLS;
}
bool GameListModel::ShouldDisplayGameListItem(int index) const
{
QSharedPointer<GameFile> game = m_games[index];
const bool show_platform = [&game] {
switch (game->GetPlatformID())
{
case DiscIO::Platform::GAMECUBE_DISC:
return SConfig::GetInstance().m_ListGC;
case DiscIO::Platform::WII_DISC:
return SConfig::GetInstance().m_ListWii;
case DiscIO::Platform::WII_WAD:
return SConfig::GetInstance().m_ListWad;
case DiscIO::Platform::ELF_DOL:
return SConfig::GetInstance().m_ListElfDol;
default:
return false;
}
}();
if (!show_platform)
return false;
switch (game->GetCountryID())
{
case DiscIO::Country::COUNTRY_AUSTRALIA:
return SConfig::GetInstance().m_ListAustralia;
case DiscIO::Country::COUNTRY_EUROPE:
return SConfig::GetInstance().m_ListPal;
case DiscIO::Country::COUNTRY_FRANCE:
return SConfig::GetInstance().m_ListFrance;
case DiscIO::Country::COUNTRY_GERMANY:
return SConfig::GetInstance().m_ListGermany;
case DiscIO::Country::COUNTRY_ITALY:
return SConfig::GetInstance().m_ListItaly;
case DiscIO::Country::COUNTRY_JAPAN:
return SConfig::GetInstance().m_ListJap;
case DiscIO::Country::COUNTRY_KOREA:
return SConfig::GetInstance().m_ListKorea;
case DiscIO::Country::COUNTRY_NETHERLANDS:
return SConfig::GetInstance().m_ListNetherlands;
case DiscIO::Country::COUNTRY_RUSSIA:
return SConfig::GetInstance().m_ListRussia;
case DiscIO::Country::COUNTRY_SPAIN:
return SConfig::GetInstance().m_ListSpain;
case DiscIO::Country::COUNTRY_TAIWAN:
return SConfig::GetInstance().m_ListTaiwan;
case DiscIO::Country::COUNTRY_USA:
return SConfig::GetInstance().m_ListUsa;
case DiscIO::Country::COUNTRY_WORLD:
return SConfig::GetInstance().m_ListWorld;
case DiscIO::Country::COUNTRY_UNKNOWN:
default:
return SConfig::GetInstance().m_ListUnknown;
}
}
void GameListModel::UpdateGame(QSharedPointer<GameFile> game)
{
QString path = game->GetFilePath();

View File

@ -27,6 +27,7 @@ public:
// Path of the Game at the specified index.
QString GetPath(int index) const { return m_games[index]->GetFilePath(); }
bool ShouldDisplayGameListItem(int index) const;
enum
{
COL_PLATFORM = 0,

View File

@ -34,3 +34,9 @@ QVariant ListProxyModel::data(const QModelIndex& i, int role) const
}
return QVariant();
}
bool ListProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{
GameListModel* glm = qobject_cast<GameListModel*>(sourceModel());
return glm->ShouldDisplayGameListItem(source_row);
}

View File

@ -15,4 +15,5 @@ class ListProxyModel final : public QSortFilterProxyModel
public:
explicit ListProxyModel(QObject* parent = nullptr);
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
};

View File

@ -0,0 +1,16 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "DolphinQt2/GameList/TableProxyModel.h"
#include "DolphinQt2/GameList/GameListModel.h"
TableProxyModel::TableProxyModel(QObject* parent) : QSortFilterProxyModel(parent)
{
}
bool TableProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{
GameListModel* glm = qobject_cast<GameListModel*>(sourceModel());
return glm->ShouldDisplayGameListItem(source_row);
}

View File

@ -0,0 +1,15 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <QSortFilterProxyModel>
// This subclass of QSortFilterProxyModel allows the data to be filtered by the view.
class TableProxyModel final : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit TableProxyModel(QObject* parent = nullptr);
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
};