Reduce duplication in ResourceFolderModel subclasses

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad 2026-02-12 17:47:10 +00:00
parent e2d503456f
commit 081d2f1e51
No known key found for this signature in database
GPG key ID: 5E39D70B4C93C38E
5 changed files with 116 additions and 147 deletions

View file

@ -90,24 +90,15 @@ QVariant ModFolderModel::data(const QModelIndex& index, int role) const
switch (role) {
case Qt::DisplayRole:
switch (column) {
case NameColumn:
return m_resources[row]->name();
case VersionColumn: {
switch (at(row).type()) {
case ResourceType::FOLDER:
return tr("Folder");
case ResourceType::SINGLEFILE:
return tr("File");
default:
break;
}
return at(row).version();
}
case DateColumn:
return at(row).dateTimeChanged();
case ProviderColumn: {
return at(row).provider();
}
case SideColumn: {
return at(row).side();
}
@ -120,53 +111,54 @@ QVariant ModFolderModel::data(const QModelIndex& index, int role) const
case ReleaseTypeColumn: {
return at(row).releaseType();
}
case SizeColumn: {
return at(row).sizeStr();
}
case RequiredByColumn: {
return at(row).requiredByCount();
}
case RequiresColumn: {
return at(row).requiresCount();
}
default:
return QVariant();
}
case Qt::ToolTipRole:
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::DecorationRole: {
if (column == NameColumn && (at(row).isSymLinkUnder(instDirPath()) || at(row).isMoreThanOneHardLink()))
return QIcon::fromTheme("status-yellow");
if (column == ImageColumn) {
return at(row).icon({ 32, 32 }, Qt::AspectRatioMode::KeepAspectRatioByExpanding);
}
return {};
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 QVariant();
break;
default:
return QVariant();
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 ModFolderModel::headerData(int section, [[maybe_unused]] Qt::Orientation orientation, int role) const