refactor: column names as class property, use string names in setting
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
parent
b28f682ad9
commit
4eb9083ddc
@ -57,6 +57,8 @@
|
|||||||
ModFolderModel::ModFolderModel(const QString& dir, BaseInstance* instance, bool is_indexed, bool create_dir)
|
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)
|
: 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_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};
|
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)
|
switch (section)
|
||||||
{
|
{
|
||||||
case ActiveColumn:
|
case ActiveColumn:
|
||||||
return tr("Enable");
|
|
||||||
case NameColumn:
|
case NameColumn:
|
||||||
return tr("Name");
|
|
||||||
case VersionColumn:
|
case VersionColumn:
|
||||||
return tr("Version");
|
|
||||||
case DateColumn:
|
case DateColumn:
|
||||||
return tr("Last changed");
|
|
||||||
case ProviderColumn:
|
case ProviderColumn:
|
||||||
return tr("Provider");
|
|
||||||
case ImageColumn:
|
case ImageColumn:
|
||||||
return tr("Image");
|
return columnNames().at(section);
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
@ -475,11 +475,9 @@ QVariant ResourceFolderModel::headerData(int section, Qt::Orientation orientatio
|
|||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case ACTIVE_COLUMN:
|
case ACTIVE_COLUMN:
|
||||||
return tr("Enable");
|
|
||||||
case NAME_COLUMN:
|
case NAME_COLUMN:
|
||||||
return tr("Name");
|
|
||||||
case DATE_COLUMN:
|
case DATE_COLUMN:
|
||||||
return tr("Last modified");
|
return columnNames().at(section);
|
||||||
default:
|
default:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -509,7 +507,7 @@ void ResourceFolderModel::setupHeaderAction(QAction* act, int column)
|
|||||||
{
|
{
|
||||||
Q_ASSERT(act);
|
Q_ASSERT(act);
|
||||||
|
|
||||||
act->setText(headerData(column, Qt::Orientation::Horizontal).toString());
|
act->setText(columnNames().at(column));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceFolderModel::saveHiddenColumn(int column, bool hidden)
|
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)) ?
|
auto setting = (APPLICATION->settings()->contains(setting_name)) ?
|
||||||
APPLICATION->settings()->getSetting(setting_name) : APPLICATION->settings()->registerSetting(setting_name);
|
APPLICATION->settings()->getSetting(setting_name) : APPLICATION->settings()->registerSetting(setting_name);
|
||||||
|
|
||||||
auto hiddenColumns = QVariantUtils::toList<int>(setting->get());
|
auto hiddenColumns = QVariantUtils::toList<QString>(setting->get());
|
||||||
auto index = hiddenColumns.indexOf(column);
|
auto name = columnNames(false).at(column);
|
||||||
|
auto index = hiddenColumns.indexOf(name);
|
||||||
if (index >= 0 && !hidden) {
|
if (index >= 0 && !hidden) {
|
||||||
hiddenColumns.removeAt(index);
|
hiddenColumns.removeAt(index);
|
||||||
} else if ( index < 0 && hidden) {
|
} else if ( index < 0 && hidden) {
|
||||||
hiddenColumns.append(column);
|
hiddenColumns.append(name);
|
||||||
}
|
}
|
||||||
setting->set(QVariantUtils::fromList(hiddenColumns));
|
setting->set(QVariantUtils::fromList(hiddenColumns));
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,7 @@ class ResourceFolderModel : public QAbstractListModel {
|
|||||||
|
|
||||||
/* Basic columns */
|
/* Basic columns */
|
||||||
enum Columns { ACTIVE_COLUMN = 0, NAME_COLUMN, DATE_COLUMN, NUM_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 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; };
|
[[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.
|
// 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!
|
// As such, the order in with they appear is very important!
|
||||||
QList<SortType> m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::DATE };
|
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 };
|
QList<QHeaderView::ResizeMode> m_column_resize_modes = { QHeaderView::Stretch, QHeaderView::ResizeToContents, QHeaderView::ResizeToContents };
|
||||||
|
|
||||||
bool m_can_interact = true;
|
bool m_can_interact = true;
|
||||||
|
@ -50,6 +50,8 @@
|
|||||||
ResourcePackFolderModel::ResourcePackFolderModel(const QString& dir, BaseInstance* instance)
|
ResourcePackFolderModel::ResourcePackFolderModel(const QString& dir, BaseInstance* instance)
|
||||||
: ResourceFolderModel(QDir(dir), 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_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};
|
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:
|
case Qt::DisplayRole:
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case ActiveColumn:
|
case ActiveColumn:
|
||||||
return tr("Enable");
|
|
||||||
case NameColumn:
|
case NameColumn:
|
||||||
return tr("Name");
|
|
||||||
case PackFormatColumn:
|
case PackFormatColumn:
|
||||||
return tr("Pack Format");
|
|
||||||
case DateColumn:
|
case DateColumn:
|
||||||
return tr("Last changed");
|
|
||||||
case ImageColumn:
|
case ImageColumn:
|
||||||
return tr("Image");
|
return columnNames().at(section);
|
||||||
default:
|
default:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,8 @@
|
|||||||
TexturePackFolderModel::TexturePackFolderModel(const QString& dir, BaseInstance* instance)
|
TexturePackFolderModel::TexturePackFolderModel(const QString& dir, BaseInstance* instance)
|
||||||
: ResourceFolderModel(QDir(dir), 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_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::NAME, SortType::DATE };
|
||||||
m_column_resize_modes = { QHeaderView::ResizeToContents, QHeaderView::ResizeToContents, QHeaderView::Stretch, QHeaderView::ResizeToContents};
|
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:
|
case Qt::DisplayRole:
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case ActiveColumn:
|
case ActiveColumn:
|
||||||
return tr("Enable");
|
|
||||||
case NameColumn:
|
case NameColumn:
|
||||||
return tr("Name");
|
|
||||||
case DateColumn:
|
case DateColumn:
|
||||||
return tr("Last modified");
|
|
||||||
case ImageColumn:
|
case ImageColumn:
|
||||||
return tr("Image");
|
return columnNames().at(section);
|
||||||
default:
|
default:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user