diff --git a/NEWS.md b/NEWS.md index 5a83d92a98..f3d3b2917f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/src/tiled/mapobjectmodel.cpp b/src/tiled/mapobjectmodel.cpp index 729de79e76..821d70194a 100644 --- a/src/tiled/mapobjectmodel.cpp +++ b/src/tiled/mapobjectmodel.cpp @@ -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: @@ -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(); @@ -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: @@ -214,6 +235,7 @@ QVariant MapObjectModel::data(const QModelIndex &index, int role) const return QVariant(); } } + return QVariant(); }