mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
Reduce duplication in ResourceFolderModel subclasses
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
e2d503456f
commit
081d2f1e51
5 changed files with 116 additions and 147 deletions
|
|
@ -67,8 +67,6 @@ QVariant ResourcePackFolderModel::data(const QModelIndex& index, int role) const
|
|||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
switch (column) {
|
||||
case NameColumn:
|
||||
return m_resources[row]->name();
|
||||
case PackFormatColumn: {
|
||||
auto& resource = at(row);
|
||||
auto pack_format = resource.packFormat();
|
||||
|
|
@ -82,55 +80,52 @@ QVariant ResourcePackFolderModel::data(const QModelIndex& index, int role) const
|
|||
return QString("%1 (%2 - %3)")
|
||||
.arg(QString::number(pack_format), version_bounds.first.toString(), version_bounds.second.toString());
|
||||
}
|
||||
case DateColumn:
|
||||
return m_resources[row]->dateTimeChanged();
|
||||
case ProviderColumn:
|
||||
return m_resources[row]->provider();
|
||||
case SizeColumn:
|
||||
return m_resources[row]->sizeStr();
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
case Qt::DecorationRole: {
|
||||
if (column == NameColumn && (at(row).isSymLinkUnder(instDirPath()) || at(row).isMoreThanOneHardLink()))
|
||||
return QIcon::fromTheme("status-yellow");
|
||||
if (column == ImageColumn) {
|
||||
return at(row).image({ 32, 32 }, Qt::AspectRatioMode::KeepAspectRatioByExpanding);
|
||||
}
|
||||
return {};
|
||||
break;
|
||||
}
|
||||
case Qt::ToolTipRole: {
|
||||
if (column == PackFormatColumn) {
|
||||
//: The string being explained by this is in the format: ID (Lower version - Upper version)
|
||||
return tr("The resource pack format ID, as well as the Minecraft versions it was designed for.");
|
||||
}
|
||||
if (column == NameColumn) {
|
||||
if (at(row).isSymLinkUnder(instDirPath())) {
|
||||
return m_resources[row]->internal_id() +
|
||||
tr("\nWarning: This resource is symbolically linked from elsewhere. Editing it will also change the original."
|
||||
"\nCanonical Path: %1")
|
||||
.arg(at(row).fileinfo().canonicalFilePath());
|
||||
;
|
||||
}
|
||||
if (at(row).isMoreThanOneHardLink()) {
|
||||
return m_resources[row]->internal_id() +
|
||||
tr("\nWarning: This resource is hard linked elsewhere. Editing it will also change the original.");
|
||||
}
|
||||
}
|
||||
return m_resources[row]->internal_id();
|
||||
break;
|
||||
}
|
||||
case Qt::SizeHintRole:
|
||||
if (column == ImageColumn) {
|
||||
return QSize(32, 32);
|
||||
}
|
||||
return {};
|
||||
case Qt::CheckStateRole:
|
||||
if (column == ActiveColumn)
|
||||
return at(row).enabled() ? Qt::Checked : Qt::Unchecked;
|
||||
return {};
|
||||
default:
|
||||
return {};
|
||||
break;
|
||||
}
|
||||
|
||||
// map the columns to the base equivilents
|
||||
QModelIndex mappedIndex;
|
||||
switch (column) {
|
||||
case ActiveColumn:
|
||||
mappedIndex = index.siblingAtColumn(ResourceFolderModel::ActiveColumn);
|
||||
break;
|
||||
case NameColumn:
|
||||
mappedIndex = index.siblingAtColumn(ResourceFolderModel::NameColumn);
|
||||
break;
|
||||
case DateColumn:
|
||||
mappedIndex = index.siblingAtColumn(ResourceFolderModel::DateColumn);
|
||||
break;
|
||||
case ProviderColumn:
|
||||
mappedIndex = index.siblingAtColumn(ResourceFolderModel::ProviderColumn);
|
||||
break;
|
||||
case SizeColumn:
|
||||
mappedIndex = index.siblingAtColumn(ResourceFolderModel::SizeColumn);
|
||||
break;
|
||||
}
|
||||
|
||||
if (mappedIndex.isValid()) {
|
||||
return ResourceFolderModel::data(mappedIndex, role);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
QVariant ResourcePackFolderModel::headerData(int section, [[maybe_unused]] Qt::Orientation orientation, int role) const
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue