aboutsummaryrefslogtreecommitdiff
path: root/launcher/minecraft
diff options
context:
space:
mode:
authorRachel Powers <508861+Ryex@users.noreply.github.com>2023-05-28 13:00:08 -0700
committerRachel Powers <508861+Ryex@users.noreply.github.com>2023-05-28 13:00:08 -0700
commit4eb9083ddc3c57f45d252ceae18d3e9dbf4ee4a3 (patch)
tree3afed793299f611462a316a0ac7861a178f7bf04 /launcher/minecraft
parentb28f682ad9726c536f49579a3bd810cacc6e45ef (diff)
downloadPrismLauncher-4eb9083ddc3c57f45d252ceae18d3e9dbf4ee4a3.tar.gz
PrismLauncher-4eb9083ddc3c57f45d252ceae18d3e9dbf4ee4a3.tar.bz2
PrismLauncher-4eb9083ddc3c57f45d252ceae18d3e9dbf4ee4a3.zip
refactor: column names as class property, use string names in setting
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
Diffstat (limited to 'launcher/minecraft')
-rw-r--r--launcher/minecraft/mod/ModFolderModel.cpp9
-rw-r--r--launcher/minecraft/mod/ResourceFolderModel.cpp13
-rw-r--r--launcher/minecraft/mod/ResourceFolderModel.h3
-rw-r--r--launcher/minecraft/mod/ResourcePackFolderModel.cpp8
-rw-r--r--launcher/minecraft/mod/TexturePackFolderModel.cpp7
5 files changed, 18 insertions, 22 deletions
diff --git a/launcher/minecraft/mod/ModFolderModel.cpp b/launcher/minecraft/mod/ModFolderModel.cpp
index 02e77b30..b49aac18 100644
--- a/launcher/minecraft/mod/ModFolderModel.cpp
+++ b/launcher/minecraft/mod/ModFolderModel.cpp
@@ -57,6 +57,8 @@
ModFolderModel::ModFolderModel(const QString& dir, BaseInstance* instance, bool is_indexed, bool create_dir)
: ResourceFolderModel(QDir(dir), instance, nullptr, create_dir), m_is_indexed(is_indexed)
{
+ m_column_names = QStringList({ "Enable", "Image", "Name", "Version", "Last Modified", "Provider" });
+ m_column_names_translated = QStringList({ tr("Enable"), tr("Image"), tr("Name"), tr("Version"), tr("Last Modified"), tr("Provider") });
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::NAME , SortType::VERSION, SortType::DATE, SortType::PROVIDER};
m_column_resize_modes = { QHeaderView::ResizeToContents, QHeaderView::ResizeToContents, QHeaderView::Stretch, QHeaderView::ResizeToContents, QHeaderView::ResizeToContents};
}
@@ -145,17 +147,12 @@ QVariant ModFolderModel::headerData(int section, Qt::Orientation orientation, in
switch (section)
{
case ActiveColumn:
- return tr("Enable");
case NameColumn:
- return tr("Name");
case VersionColumn:
- return tr("Version");
case DateColumn:
- return tr("Last changed");
case ProviderColumn:
- return tr("Provider");
case ImageColumn:
- return tr("Image");
+ return columnNames().at(section);
default:
return QVariant();
}
diff --git a/launcher/minecraft/mod/ResourceFolderModel.cpp b/launcher/minecraft/mod/ResourceFolderModel.cpp
index 838fca53..2997a43d 100644
--- a/launcher/minecraft/mod/ResourceFolderModel.cpp
+++ b/launcher/minecraft/mod/ResourceFolderModel.cpp
@@ -475,11 +475,9 @@ QVariant ResourceFolderModel::headerData(int section, Qt::Orientation orientatio
case Qt::DisplayRole:
switch (section) {
case ACTIVE_COLUMN:
- return tr("Enable");
case NAME_COLUMN:
- return tr("Name");
case DATE_COLUMN:
- return tr("Last modified");
+ return columnNames().at(section);
default:
return {};
}
@@ -509,7 +507,7 @@ void ResourceFolderModel::setupHeaderAction(QAction* act, int column)
{
Q_ASSERT(act);
- act->setText(headerData(column, Qt::Orientation::Horizontal).toString());
+ act->setText(columnNames().at(column));
}
void ResourceFolderModel::saveHiddenColumn(int column, bool hidden)
@@ -518,12 +516,13 @@ void ResourceFolderModel::saveHiddenColumn(int column, bool hidden)
auto setting = (APPLICATION->settings()->contains(setting_name)) ?
APPLICATION->settings()->getSetting(setting_name) : APPLICATION->settings()->registerSetting(setting_name);
- auto hiddenColumns = QVariantUtils::toList<int>(setting->get());
- auto index = hiddenColumns.indexOf(column);
+ auto hiddenColumns = QVariantUtils::toList<QString>(setting->get());
+ auto name = columnNames(false).at(column);
+ auto index = hiddenColumns.indexOf(name);
if (index >= 0 && !hidden) {
hiddenColumns.removeAt(index);
} else if ( index < 0 && hidden) {
- hiddenColumns.append(column);
+ hiddenColumns.append(name);
}
setting->set(QVariantUtils::fromList(hiddenColumns));
}
diff --git a/launcher/minecraft/mod/ResourceFolderModel.h b/launcher/minecraft/mod/ResourceFolderModel.h
index e1dc685b..138815cf 100644
--- a/launcher/minecraft/mod/ResourceFolderModel.h
+++ b/launcher/minecraft/mod/ResourceFolderModel.h
@@ -97,6 +97,7 @@ class ResourceFolderModel : public QAbstractListModel {
/* Basic columns */
enum Columns { ACTIVE_COLUMN = 0, NAME_COLUMN, DATE_COLUMN, NUM_COLUMNS };
+ QStringList columnNames(bool translated = true) const { return translated ? m_column_names_translated : m_column_names; };
[[nodiscard]] int rowCount(const QModelIndex& parent = {}) const override { return parent.isValid() ? 0 : static_cast<int>(size()); }
[[nodiscard]] int columnCount(const QModelIndex& parent = {}) const override { return parent.isValid() ? 0 : NUM_COLUMNS; };
@@ -198,6 +199,8 @@ class ResourceFolderModel : public QAbstractListModel {
// Represents the relationship between a column's index (represented by the list index), and it's sorting key.
// As such, the order in with they appear is very important!
QList<SortType> m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::DATE };
+ QStringList m_column_names = {"Enable", "Name", "Last Modified"};
+ QStringList m_column_names_translated = {tr("Enable"), tr("Name"), tr("Last Modified")};
QList<QHeaderView::ResizeMode> m_column_resize_modes = { QHeaderView::Stretch, QHeaderView::ResizeToContents, QHeaderView::ResizeToContents };
bool m_can_interact = true;
diff --git a/launcher/minecraft/mod/ResourcePackFolderModel.cpp b/launcher/minecraft/mod/ResourcePackFolderModel.cpp
index 8a7b1049..989554de 100644
--- a/launcher/minecraft/mod/ResourcePackFolderModel.cpp
+++ b/launcher/minecraft/mod/ResourcePackFolderModel.cpp
@@ -50,6 +50,8 @@
ResourcePackFolderModel::ResourcePackFolderModel(const QString& dir, BaseInstance* instance)
: ResourceFolderModel(QDir(dir), instance)
{
+ m_column_names = QStringList({ "Enable", "Image", "Name", "Pack Format", "Last Modified" });
+ m_column_names_translated = QStringList({ tr("Enable"), tr("Image"), tr("Name"), tr("Pack Format"), tr("Last Modified") });
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::NAME, SortType::PACK_FORMAT, SortType::DATE};
m_column_resize_modes = { QHeaderView::ResizeToContents, QHeaderView::ResizeToContents, QHeaderView::Stretch, QHeaderView::ResizeToContents};
@@ -132,15 +134,11 @@ QVariant ResourcePackFolderModel::headerData(int section, Qt::Orientation orient
case Qt::DisplayRole:
switch (section) {
case ActiveColumn:
- return tr("Enable");
case NameColumn:
- return tr("Name");
case PackFormatColumn:
- return tr("Pack Format");
case DateColumn:
- return tr("Last changed");
case ImageColumn:
- return tr("Image");
+ return columnNames().at(section);
default:
return {};
}
diff --git a/launcher/minecraft/mod/TexturePackFolderModel.cpp b/launcher/minecraft/mod/TexturePackFolderModel.cpp
index 76145b3b..898d128f 100644
--- a/launcher/minecraft/mod/TexturePackFolderModel.cpp
+++ b/launcher/minecraft/mod/TexturePackFolderModel.cpp
@@ -45,6 +45,8 @@
TexturePackFolderModel::TexturePackFolderModel(const QString& dir, BaseInstance* instance)
: ResourceFolderModel(QDir(dir), instance)
{
+ m_column_names = QStringList({ "Enable", "Image", "Name", "Last Modified" });
+ m_column_names_translated = QStringList({ tr("Enable"), tr("Image"), tr("Name"), tr("Last Modified") });
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::NAME, SortType::DATE };
m_column_resize_modes = { QHeaderView::ResizeToContents, QHeaderView::ResizeToContents, QHeaderView::Stretch, QHeaderView::ResizeToContents};
@@ -118,13 +120,10 @@ QVariant TexturePackFolderModel::headerData(int section, Qt::Orientation orienta
case Qt::DisplayRole:
switch (section) {
case ActiveColumn:
- return tr("Enable");
case NameColumn:
- return tr("Name");
case DateColumn:
- return tr("Last modified");
case ImageColumn:
- return tr("Image");
+ return columnNames().at(section);
default:
return {};
}