From a0642b3b00d32bac3697285a4488a87bb02bcd9a Mon Sep 17 00:00:00 2001
From: Lioncash
Date: Tue, 10 Jul 2018 15:10:03 -0400
Subject: [PATCH] Qt/Resources: Convert int parameters of GetCountry(),
GetPlatform() and GetMisc() to enum classes
Makes the parameter strongly-typed and doesn't accept arbitrary int
values.
---
Source/Core/DolphinQt/AboutDialog.cpp | 2 +-
.../Core/DolphinQt/GameList/GameListModel.cpp | 6 ++---
Source/Core/DolphinQt/Resources.cpp | 12 ++++-----
Source/Core/DolphinQt/Resources.h | 26 ++++++++++++-------
4 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/Source/Core/DolphinQt/AboutDialog.cpp b/Source/Core/DolphinQt/AboutDialog.cpp
index 536ef8c265..dccc9add36 100644
--- a/Source/Core/DolphinQt/AboutDialog.cpp
+++ b/Source/Core/DolphinQt/AboutDialog.cpp
@@ -67,7 +67,7 @@ AboutDialog::AboutDialog(QWidget* parent) : QDialog(parent)
QStringLiteral("
"));
QLabel* logo = new QLabel();
- logo->setPixmap(Resources::GetMisc(Resources::LOGO_LARGE));
+ logo->setPixmap(Resources::GetMisc(Resources::MiscID::LogoLarge));
logo->setContentsMargins(30, 0, 30, 0);
QVBoxLayout* main_layout = new QVBoxLayout;
diff --git a/Source/Core/DolphinQt/GameList/GameListModel.cpp b/Source/Core/DolphinQt/GameList/GameListModel.cpp
index e18fdde725..afd8c786b8 100644
--- a/Source/Core/DolphinQt/GameList/GameListModel.cpp
+++ b/Source/Core/DolphinQt/GameList/GameListModel.cpp
@@ -54,13 +54,13 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
{
case COL_PLATFORM:
if (role == Qt::DecorationRole)
- return Resources::GetPlatform(static_cast(game.GetPlatform()));
+ return Resources::GetPlatform(game.GetPlatform());
if (role == Qt::InitialSortOrderRole)
return static_cast(game.GetPlatform());
break;
case COL_COUNTRY:
if (role == Qt::DecorationRole)
- return Resources::GetCountry(static_cast(game.GetCountry()));
+ return Resources::GetCountry(game.GetCountry());
if (role == Qt::InitialSortOrderRole)
return static_cast(game.GetCountry());
break;
@@ -70,7 +70,7 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
// GameCube banners are 96x32, but Wii banners are 192x64.
QPixmap banner = ToQPixmap(game.GetBannerImage());
if (banner.isNull())
- banner = Resources::GetMisc(Resources::BANNER_MISSING);
+ banner = Resources::GetMisc(Resources::MiscID::BannerMissing);
banner.setDevicePixelRatio(
std::max(static_cast(banner.width()) / GAMECUBE_BANNER_SIZE.width(),
diff --git a/Source/Core/DolphinQt/Resources.cpp b/Source/Core/DolphinQt/Resources.cpp
index c631b98d95..feae22cb55 100644
--- a/Source/Core/DolphinQt/Resources.cpp
+++ b/Source/Core/DolphinQt/Resources.cpp
@@ -95,19 +95,19 @@ void Resources::Init()
m_misc.append(GetScaledPixmap("Dolphin"));
}
-QPixmap Resources::GetPlatform(int platform)
+QPixmap Resources::GetPlatform(DiscIO::Platform platform)
{
- return m_platforms[platform];
+ return m_platforms[static_cast(platform)];
}
-QPixmap Resources::GetCountry(int country)
+QPixmap Resources::GetCountry(DiscIO::Country country)
{
- return m_countries[country];
+ return m_countries[static_cast(country)];
}
-QPixmap Resources::GetMisc(int id)
+QPixmap Resources::GetMisc(MiscID id)
{
- return m_misc[id];
+ return m_misc[static_cast(id)];
}
QIcon Resources::GetAppIcon()
diff --git a/Source/Core/DolphinQt/Resources.h b/Source/Core/DolphinQt/Resources.h
index 0d8a6783bb..bb01d7ea5d 100644
--- a/Source/Core/DolphinQt/Resources.h
+++ b/Source/Core/DolphinQt/Resources.h
@@ -7,23 +7,29 @@
#include
#include
+namespace DiscIO
+{
+enum class Country;
+enum class Platform;
+}
+
// Store for various QPixmaps that will be used repeatedly.
class Resources final
{
public:
+ enum class MiscID
+ {
+ BannerMissing,
+ LogoLarge,
+ LogoSmall
+ };
+
static void Init();
- static QPixmap GetPlatform(int platform);
- static QPixmap GetCountry(int country);
+ static QPixmap GetPlatform(DiscIO::Platform platform);
+ static QPixmap GetCountry(DiscIO::Country country);
- static QPixmap GetMisc(int id);
-
- enum
- {
- BANNER_MISSING,
- LOGO_LARGE,
- LOGO_SMALL
- };
+ static QPixmap GetMisc(MiscID id);
static QIcon GetScaledIcon(const std::string& name);
static QIcon GetScaledThemeIcon(const std::string& name);