From a14e70ef5339d874ed5fbbeeea2a90c9b97c3faf Mon Sep 17 00:00:00 2001 From: garak Date: Wed, 8 Feb 2023 19:59:45 -0500 Subject: [PATCH] update map lists when new maps and layouts are added --- include/ui/maplistmodels.h | 6 +++++ src/mainwindow.cpp | 4 ++++ src/project.cpp | 1 + src/ui/maplistmodels.cpp | 48 +++++++++++++++++++++++++++++++++++++- 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/include/ui/maplistmodels.h b/include/ui/maplistmodels.h index d730c05e..2465cc29 100644 --- a/include/ui/maplistmodels.h +++ b/include/ui/maplistmodels.h @@ -32,6 +32,8 @@ public: QStandardItem *createGroupItem(QString groupName, int groupIndex); QStandardItem *createMapItem(QString mapName, int groupIndex, int mapIndex); + QStandardItem *insertMapItem(QString mapName, QString groupName); + QStandardItem *getItem(const QModelIndex &index) const; QModelIndex indexOfMap(QString mapName); @@ -68,6 +70,8 @@ public: QStandardItem *createAreaItem(QString areaName, int areaIndex); QStandardItem *createMapItem(QString mapName, int areaIndex, int mapIndex); + QStandardItem *insertMapItem(QString mapName, QString areaName, int groupIndex); + QStandardItem *getItem(const QModelIndex &index) const; QModelIndex indexOfMap(QString mapName); @@ -104,6 +108,8 @@ public: QStandardItem *createLayoutItem(QString layoutId); QStandardItem *createMapItem(QString mapName); + QStandardItem *insertMapItem(QString mapName, QString layoutId); + QStandardItem *getItem(const QModelIndex &index) const; QModelIndex indexOfLayout(QString layoutName); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 47ce878b..18b7d9b9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1248,6 +1248,10 @@ void MainWindow::onNewMapCreated() { // QStandardItem* groupItem = mapGroupItemsList->at(newMapGroup); // int numMapsInGroup = groupItem->rowCount(); + this->mapGroupModel->insertMapItem(newMapName, editor->project->groupNames[newMapGroup]); + this->mapAreaModel->insertMapItem(newMapName, newMap->location, newMapGroup); + this->layoutTreeModel->insertMapItem(newMapName, newMap->layout->id); + // QStandardItem *newMapItem = createMapItem(newMapName, newMapGroup, numMapsInGroup); // groupItem->appendRow(newMapItem); // mapListIndexes.insert(newMapName, newMapItem->index()); diff --git a/src/project.cpp b/src/project.cpp index 15122fac..ba273f17 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1775,6 +1775,7 @@ Map* Project::addNewMapToGroup(QString mapName, int groupNum, Map *newMap, bool if (!existingLayout) { mapLayouts.insert(newMap->layoutId, newMap->layout); mapLayoutsTable.append(newMap->layoutId); + layoutIdsToNames.insert(newMap->layout->id, newMap->layout->name); if (!importedMap) { setNewMapBlockdata(newMap); } diff --git a/src/ui/maplistmodels.cpp b/src/ui/maplistmodels.cpp index bc9ead2f..71c4caf1 100644 --- a/src/ui/maplistmodels.cpp +++ b/src/ui/maplistmodels.cpp @@ -35,7 +35,21 @@ QStandardItem *MapGroupModel::createMapItem(QString mapName, int groupIndex, int return map; } +QStandardItem *MapGroupModel::insertMapItem(QString mapName, QString groupName) { + int groupIndex = this->project->groupNames.indexOf(groupName); + QStandardItem *group = this->groupItems[groupName]; + if (!group) { + return nullptr; + } + int mapIndex = group->rowCount(); + QStandardItem *map = createMapItem(mapName, groupIndex, mapIndex); + group->appendRow(map); + return map; +} + void MapGroupModel::initialize() { + this->groupItems.clear(); + this->mapItems.clear(); for (int i = 0; i < this->project->groupNames.length(); i++) { QString group_name = this->project->groupNames.value(i); QStandardItem *group = createGroupItem(group_name, i); @@ -140,7 +154,21 @@ QStandardItem *MapAreaModel::createMapItem(QString mapName, int groupIndex, int return map; } +QStandardItem *MapAreaModel::insertMapItem(QString mapName, QString areaName, int groupIndex) { + // int areaIndex = this->project->mapSectionNameToValue[areaName]; + QStandardItem *area = this->areaItems[areaName]; + if (!area) { + return nullptr; + } + int mapIndex = area->rowCount(); + QStandardItem *map = createMapItem(mapName, groupIndex, mapIndex); + area->appendRow(map); + return map; +} + void MapAreaModel::initialize() { + this->areaItems.clear(); + this->mapItems.clear(); for (int i = 0; i < this->project->mapSectionNameToValue.size(); i++) { QString mapsecName = project->mapSectionValueToName.value(i); QStandardItem *areaItem = createAreaItem(mapsecName, i); @@ -256,7 +284,26 @@ QStandardItem *LayoutTreeModel::createMapItem(QString mapName) { return map; } +QStandardItem *LayoutTreeModel::insertMapItem(QString mapName, QString layoutId) { + QStandardItem *layout = nullptr; + if (this->layoutItems.contains(layoutId)) { + layout = this->layoutItems[layoutId]; + } + else { + layout = createLayoutItem(layoutId); + this->root->appendRow(layout); + } + if (!layout) { + return nullptr; + } + QStandardItem *map = createMapItem(mapName); + layout->appendRow(map); + return map; +} + void LayoutTreeModel::initialize() { + this->layoutItems.clear(); + this->mapItems.clear(); for (int i = 0; i < this->project->mapLayoutsTable.length(); i++) { QString layoutId = project->mapLayoutsTable.value(i); QStandardItem *layoutItem = createLayoutItem(layoutId); @@ -265,7 +312,6 @@ void LayoutTreeModel::initialize() { for (auto mapList : this->project->groupedMapNames) { for (auto mapName : mapList) { - // QString layoutId = project->readMapLayoutId(mapName); QStandardItem *map = createMapItem(mapName); this->layoutItems[layoutId]->appendRow(map);