From da0240b3bff089175b9cbe49ce94d379db8c61b3 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 17 May 2025 11:17:20 -0400 Subject: [PATCH] Separate map layers into their own tree items --- apps/mapeditor/include/objectlistmodel.h | 2 ++ apps/mapeditor/src/objectlistmodel.cpp | 23 ++++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/apps/mapeditor/include/objectlistmodel.h b/apps/mapeditor/include/objectlistmodel.h index bd68d21..568c2f2 100644 --- a/apps/mapeditor/include/objectlistmodel.h +++ b/apps/mapeditor/include/objectlistmodel.h @@ -12,6 +12,8 @@ enum class TreeType { Root, /// LGB file File, + /// A layer. + Layer, /// A single object Object, }; diff --git a/apps/mapeditor/src/objectlistmodel.cpp b/apps/mapeditor/src/objectlistmodel.cpp index fbecff1..ea394b7 100644 --- a/apps/mapeditor/src/objectlistmodel.cpp +++ b/apps/mapeditor/src/objectlistmodel.cpp @@ -74,15 +74,8 @@ QVariant ObjectListModel::data(const QModelIndex &index, int role) const return {}; auto item = static_cast(index.internalPointer()); - - if (item->type == TreeType::File) { - if (role == Qt::DisplayRole) { - return item->name; - } - } else if (item->type == TreeType::Object) { - if (role == Qt::DisplayRole) { - return item->name; - } + if (role == Qt::DisplayRole) { + return item->name; } return {}; @@ -117,15 +110,23 @@ void ObjectListModel::refresh() const auto chunk = lgb.chunks[i]; for (int j = 0; j < chunk.num_layers; j++) { const auto layer = chunk.layers[j]; + + auto layerItem = new TreeInformation(); + layerItem->type = TreeType::Layer; + layerItem->parent = fileItem; + layerItem->name = i18n("Layer %1", j); // TODO: do display names if we have them + layerItem->row = j; + fileItem->children.push_back(layerItem); + for (int z = 0; z < layer.num_objects; z++) { const auto object = layer.objects[z]; auto objectItem = new TreeInformation(); objectItem->type = TreeType::Object; - objectItem->parent = fileItem; + objectItem->parent = layerItem; objectItem->name = i18n("Unknown (%1)", object.instance_id); // TODO: do display names if we have them objectItem->row = z; - fileItem->children.push_back(objectItem); + layerItem->children.push_back(objectItem); } } }