From e278d48380c198d0589164e7b12edd4c7d9c3a0c Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 8 Nov 2024 14:59:41 -0500 Subject: [PATCH] Fix script API undo/redo for layouts, final TODO items --- include/ui/maplistmodels.h | 1 + src/core/editcommands.cpp | 5 ++--- src/mainwindow.cpp | 4 ---- src/project.cpp | 15 ++++++++++----- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/ui/maplistmodels.h b/include/ui/maplistmodels.h index 80a5423b..17810c7e 100644 --- a/include/ui/maplistmodels.h +++ b/include/ui/maplistmodels.h @@ -27,6 +27,7 @@ public: this->setDropIndicatorShown(true); this->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); this->setFocusPolicy(Qt::StrongFocus); + this->setContextMenuPolicy(Qt::CustomContextMenu); } protected: diff --git a/src/core/editcommands.cpp b/src/core/editcommands.cpp index 0843b2c0..c500c8c0 100644 --- a/src/core/editcommands.cpp +++ b/src/core/editcommands.cpp @@ -486,7 +486,6 @@ int EventPaste::id() const { ************************************************************************ ******************************************************************************/ -// TODO: Undo/redo for script edits to layout dimensions doesn't render correctly. ScriptEditLayout::ScriptEditLayout(Layout *layout, QSize oldLayoutDimensions, QSize newLayoutDimensions, const Blockdata &oldMetatiles, const Blockdata &newMetatiles, @@ -538,7 +537,7 @@ void ScriptEditLayout::redo() { layout->lastCommitBlocks.border = newBorder; layout->lastCommitBlocks.borderDimensions = QSize(newBorderWidth, newBorderHeight); - renderBlocks(layout); + renderBlocks(layout, true); layout->borderItem->draw(); } @@ -564,7 +563,7 @@ void ScriptEditLayout::undo() { layout->lastCommitBlocks.border = oldBorder; layout->lastCommitBlocks.borderDimensions = QSize(oldBorderWidth, oldBorderHeight); - renderBlocks(layout); + renderBlocks(layout, true); layout->borderItem->draw(); QUndoCommand::undo(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9cb9d130..2b83e0b0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -406,9 +406,6 @@ void MainWindow::initMapList() { connect(ui->layoutList, &QAbstractItemView::activated, this, &MainWindow::openMapListItem); // Right-clicking on items in the map list brings up a context menu. - ui->mapList->setContextMenuPolicy(Qt::CustomContextMenu); - ui->areaList->setContextMenuPolicy(Qt::CustomContextMenu); - ui->layoutList->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->mapList, &QTreeView::customContextMenuRequested, this, &MainWindow::onOpenMapListContextMenu); connect(ui->areaList, &QTreeView::customContextMenuRequested, this, &MainWindow::onOpenMapListContextMenu); connect(ui->layoutList, &QTreeView::customContextMenuRequested, this, &MainWindow::onOpenMapListContextMenu); @@ -1316,7 +1313,6 @@ void MainWindow::scrollMapListToCurrentMap(MapTree *list) { } } -// TODO: Initial scrolling doesn't center the layout on launch if it's not the current tab. void MainWindow::scrollMapListToCurrentLayout(MapTree *list) { if (this->editor->layout) { scrollMapList(list, this->editor->layout->id); diff --git a/src/project.cpp b/src/project.cpp index 9c9fcf14..88e3d9d1 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -2266,11 +2266,16 @@ bool Project::readRegionMapSections() { fileWatcher.addPath(filepath); QJsonArray mapSections = doc.object()["map_sections"].toArray(); - for (const auto &mapSection : mapSections) { - // For each map section, "id" is the only required field. This is the field we use - // to display the location names in various drop-downs. - QJsonObject mapSectionObj = mapSection.toObject(); - const QString idName = ParseUtil::jsonToQString(mapSectionObj["id"]); + for (int i = 0; i < mapSections.size(); i++) { + QJsonObject mapSectionObj = mapSections.at(i).toObject(); + + // For each map section, "id" is the only required field. This is the field we use to display the location names in various drop-downs. + const QString idField = "id"; + if (!mapSectionObj.contains(idField)) { + logWarn(QString("Ignoring data for map section %1. Missing required field \"%2\"").arg(i).arg(idField)); + continue; + } + const QString idName = ParseUtil::jsonToQString(mapSectionObj[idField]); if (!idName.startsWith(requiredPrefix)) { logWarn(QString("Ignoring data for map section '%1'. IDs must start with the prefix '%2'").arg(idName).arg(requiredPrefix)); continue;