Skip to content

Commit

Permalink
Fix script API undo/redo for layouts, final TODO items
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed Nov 8, 2024
1 parent 06ece16 commit e278d48
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions include/ui/maplistmodels.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class MapTree : public QTreeView {
this->setDropIndicatorShown(true);
this->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
this->setFocusPolicy(Qt::StrongFocus);
this->setContextMenuPolicy(Qt::CustomContextMenu);
}

protected:
Expand Down
5 changes: 2 additions & 3 deletions src/core/editcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
Expand Down
4 changes: 0 additions & 4 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 10 additions & 5 deletions src/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e278d48

Please sign in to comment.