From 95c21a4572824d7e9900467f16ab071557a0204e Mon Sep 17 00:00:00 2001 From: garak Date: Thu, 28 Sep 2023 19:56:54 -0400 Subject: [PATCH] do not show nonexistent map sections --- src/ui/maplistmodels.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ui/maplistmodels.cpp b/src/ui/maplistmodels.cpp index e3dfba14..277147e0 100644 --- a/src/ui/maplistmodels.cpp +++ b/src/ui/maplistmodels.cpp @@ -268,7 +268,6 @@ QVariant MapGroupModel::data(const QModelIndex &index, int role) const { } } else if (role == Qt::DisplayRole) { - // QStandardItem *item = this->getItem(index)->child(row, col); QString type = item->data(MapListRoles::TypeRole).toString(); @@ -342,7 +341,9 @@ QStandardItem *MapAreaModel::insertMapItem(QString mapName, QString areaName, in void MapAreaModel::initialize() { this->areaItems.clear(); this->mapItems.clear(); - for (int i = 0; i < this->project->mapSectionNameToValue.size(); i++) { + this->setSortRole(MapListRoles::GroupRole); + + for (int i : this->project->mapSectionNameToValue) { QString mapsecName = project->mapSectionValueToName.value(i); QStandardItem *areaItem = createAreaItem(mapsecName, i); this->root->appendRow(areaItem); @@ -359,6 +360,7 @@ void MapAreaModel::initialize() { } } } + this->sort(0, Qt::AscendingOrder); } QStandardItem *MapAreaModel::getItem(const QModelIndex &index) const { @@ -422,6 +424,16 @@ QVariant MapAreaModel::data(const QModelIndex &index, int role) const { return mapGrayIcon; } } + else if (role == Qt::DisplayRole) { + QStandardItem *item = this->getItem(index)->child(row, col); + QString type = item->data(MapListRoles::TypeRole).toString(); + + if (type == "map_section") { + return QString("[0x%1] %2") + .arg(QString("%1").arg(item->data(MapListRoles::GroupRole).toInt(), 2, 16, QLatin1Char('0')).toUpper()) + .arg(item->data(Qt::UserRole).toString()); + } + } return QStandardItemModel::data(index, role); }