Skip to content

Commit

Permalink
Display the image base name for unnamed tile objects
Browse files Browse the repository at this point in the history
When an unnamed tile object refers to single images (from an image
collection tileset), the image base name will now be displayed in the
Objects view.
  • Loading branch information
bjorn committed Jul 28, 2023
1 parent a1de722 commit c6006d6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Added support for setting custom properties on the project (#2903)
* Removed Space and Ctrl+Space shortcuts from Layers view to avoid conflict with panning (#3672)
* Display the image base name for unnamed tile objects referring to single images
* Scripting: Added API for editing tile layers using terrain sets (with a-morphous, #3758)
* Scripting: Support erasing tiles in Tool.preview and TileMap.merge
* Scripting: Added WangSet.effectiveTypeForColor
Expand Down
36 changes: 29 additions & 7 deletions src/tiled/mapobjectmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,17 @@ QVariant MapObjectModel::data(const QModelIndex &index, int role) const
case Qt::DisplayRole:
case Qt::EditRole:
switch (index.column()) {
case Name:
return mapObject->name();
case Name: {
QString name = mapObject->name();

// Display the tile image file name as a fallback
if (name.isEmpty())
if (Tile *tile = mapObject->cell().tile())
if (!tile->imageSource().isEmpty())
name = QFileInfo(tile->imageSource().fileName()).completeBaseName();

return name;
}
case Class:
return mapObject->effectiveClassName();
case Id:
Expand All @@ -173,14 +182,25 @@ QVariant MapObjectModel::data(const QModelIndex &index, int role) const
if (index.column() == Name)
return ObjectIconManager::instance().iconForObject(*mapObject);
break;
case Qt::ForegroundRole:
if (index.column() == 1) {
case Qt::ForegroundRole: {
bool disabled = false;

switch (index.column()) {
case Name:
disabled = mapObject->name().isEmpty();
break;
case Class:
disabled = mapObject->className().isEmpty();
break;
}

if (disabled) {
const QPalette palette = QApplication::palette();
const auto classColorGroup = mapObject->className().isEmpty() ? QPalette::Disabled
: QPalette::Active;
return palette.brush(classColorGroup, QPalette::WindowText);
return palette.brush(QPalette::Disabled, QPalette::WindowText);
}

return QVariant();
}
case Qt::CheckStateRole:
if (index.column() > 0)
return QVariant();
Expand All @@ -191,6 +211,7 @@ QVariant MapObjectModel::data(const QModelIndex &index, int role) const
return QVariant();
}
}

if (Layer *layer = toLayer(index)) {
switch (role) {
case Qt::DisplayRole:
Expand All @@ -214,6 +235,7 @@ QVariant MapObjectModel::data(const QModelIndex &index, int role) const
return QVariant();
}
}

return QVariant();
}

Expand Down

0 comments on commit c6006d6

Please sign in to comment.