Render incompatibility highlight and warning

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad 2026-02-12 18:51:27 +00:00
parent 081d2f1e51
commit 9cb33b519f
No known key found for this signature in database
GPG key ID: 5E39D70B4C93C38E
6 changed files with 48 additions and 13 deletions

View file

@ -64,6 +64,8 @@ QVariant DataPackFolderModel::data(const QModelIndex& index, int role) const
int column = index.column();
switch (role) {
case Qt::BackgroundRole:
return rowBackground(row);
case Qt::DisplayRole:
switch (column) {
case PackFormatColumn: {

View file

@ -88,6 +88,8 @@ QVariant ModFolderModel::data(const QModelIndex& index, int role) const
int column = index.column();
switch (role) {
case Qt::BackgroundRole:
return rowBackground(row);
case Qt::DisplayRole:
switch (column) {
case VersionColumn: {
@ -96,8 +98,9 @@ QVariant ModFolderModel::data(const QModelIndex& index, int role) const
return tr("Folder");
case ResourceType::SINGLEFILE:
return tr("File");
default:
return at(row).version();
}
return at(row).version();
}
case SideColumn: {
return at(row).side();

View file

@ -499,6 +499,17 @@ bool ResourceFolderModel::validateIndex(const QModelIndex& index) const
return true;
}
// HACK: all subclasses need to call this to have the whole row painted
// and they only delegate to the superclass for compatible columns
QBrush ResourceFolderModel::rowBackground(int row) const
{
if (!m_resources[row]->isCompatible()) {
return { QColor(255, 0, 0, 40) };
} else {
return {};
}
}
QVariant ResourceFolderModel::data(const QModelIndex& index, int role) const
{
if (!validateIndex(index))
@ -508,6 +519,8 @@ QVariant ResourceFolderModel::data(const QModelIndex& index, int role) const
int column = index.column();
switch (role) {
case Qt::BackgroundRole:
return rowBackground(row);
case Qt::DisplayRole:
switch (column) {
case NameColumn:
@ -521,25 +534,37 @@ QVariant ResourceFolderModel::data(const QModelIndex& index, int role) const
default:
return {};
}
case Qt::ToolTipRole:
case Qt::ToolTipRole: {
QString tooltip = m_resources[row]->internal_id();
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).isCompatible()) {
tooltip += tr("\nResource is not marked as compatible with the instance.");
}
if (at(row).isSymLinkUnder(instDirPath())) {
tooltip +=
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.");
tooltip += tr("\nWarning: This resource is hard linked elsewhere. Editing it will also change the original.");
}
}
return m_resources[row]->internal_id();
return tooltip;
}
case Qt::DecorationRole: {
if (column == NameColumn && (at(row).isSymLinkUnder(instDirPath()) || at(row).isMoreThanOneHardLink()))
return QIcon::fromTheme("status-yellow");
if (column == NameColumn) {
if (!at(row).isCompatible()) {
return QIcon::fromTheme("status-bad");
} else if (at(row).isSymLinkUnder(instDirPath()) || at(row).isMoreThanOneHardLink()) {
return QIcon::fromTheme("status-yellow");
}
}
return {};
}

View file

@ -153,6 +153,7 @@ class ResourceFolderModel : public QAbstractListModel {
[[nodiscard]] bool validateIndex(const QModelIndex& index) const;
QBrush rowBackground(int row) const;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;

View file

@ -65,6 +65,8 @@ QVariant ResourcePackFolderModel::data(const QModelIndex& index, int role) const
int column = index.column();
switch (role) {
case Qt::BackgroundRole:
return rowBackground(row);
case Qt::DisplayRole:
switch (column) {
case PackFormatColumn: {

View file

@ -63,6 +63,8 @@ QVariant TexturePackFolderModel::data(const QModelIndex& index, int role) const
int column = index.column();
switch (role) {
case Qt::BackgroundRole:
return rowBackground(row);
case Qt::DecorationRole: {
if (column == ImageColumn) {
return at(row).image({ 32, 32 }, Qt::AspectRatioMode::KeepAspectRatioByExpanding);