From f8c7ada585c2cbeea2850a0be637a624b41a73b3 Mon Sep 17 00:00:00 2001 From: garak Date: Wed, 8 Feb 2023 11:48:42 -0500 Subject: [PATCH] fix layout undo history --- include/core/maplayout.h | 2 ++ include/project.h | 2 +- src/core/maplayout.cpp | 4 ++++ src/editor.cpp | 18 ++++++++++++++++++ src/mainwindow.cpp | 27 +++++++++++++++++++++++---- src/project.cpp | 2 +- 6 files changed, 49 insertions(+), 6 deletions(-) diff --git a/include/core/maplayout.h b/include/core/maplayout.h index 1e809c13..968b8960 100644 --- a/include/core/maplayout.h +++ b/include/core/maplayout.h @@ -109,6 +109,8 @@ public: // QPixmap renderConnection(MapConnection, Layout *); QPixmap renderBorder(bool ignoreCache = false); + QPixmap getLayoutItemPixmap(); + void setLayoutItem(LayoutPixmapItem *item) { layoutItem = item; } void setCollisionItem(CollisionPixmapItem *item) { collisionItem = item; } void setBorderItem(BorderMetatilesPixmapItem *item) { borderItem = item; } diff --git a/include/project.h b/include/project.h index 9a58905f..24f14611 100644 --- a/include/project.h +++ b/include/project.h @@ -34,7 +34,7 @@ class Project : public QObject { Q_OBJECT public: - Project(QWidget *parent = nullptr); + Project(QObject *parent = nullptr); ~Project(); Project(const Project &) = delete; diff --git a/src/core/maplayout.cpp b/src/core/maplayout.cpp index 1923cf3d..4fd05b4f 100644 --- a/src/core/maplayout.cpp +++ b/src/core/maplayout.cpp @@ -438,6 +438,10 @@ QPixmap Layout::renderBorder(bool ignoreCache) { return this->border_pixmap; } +QPixmap Layout::getLayoutItemPixmap() { + return this->layoutItem ? this->layoutItem->pixmap() : QPixmap(); +} + bool Layout::hasUnsavedChanges() { return !this->editHistory.isClean(); } diff --git a/src/editor.cpp b/src/editor.cpp index 8703aa24..7d6d2780 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -100,6 +100,10 @@ void Editor::setEditingMap() { this->cursorMapTileRect->stopSingleTileMode(); this->cursorMapTileRect->setActive(true); + if (this->layout) { + this->editGroup.setActiveStack(&this->layout->editHistory); + } + setMapEditingButtonsEnabled(true); } @@ -128,6 +132,10 @@ void Editor::setEditingCollision() { this->cursorMapTileRect->setSingleTileMode(); this->cursorMapTileRect->setActive(true); + if (this->layout) { + this->editGroup.setActiveStack(&this->layout->editHistory); + } + setMapEditingButtonsEnabled(true); } @@ -152,6 +160,10 @@ void Editor::setEditingObjects() { this->cursorMapTileRect->setSingleTileMode(); this->cursorMapTileRect->setActive(false); + if (this->map) { + this->editGroup.setActiveStack(&this->map->editHistory); + } + setMapEditingButtonsEnabled(false); } @@ -184,6 +196,10 @@ void Editor::setEditingConnections() { setConnectionsEditable(true); this->cursorMapTileRect->setSingleTileMode(); this->cursorMapTileRect->setActive(false); + + if (this->map) { + this->editGroup.setActiveStack(&this->map->editHistory); + } } void Editor::setEditingEncounters() { @@ -1153,6 +1169,8 @@ bool Editor::setLayout(QString layoutId) { // !TODO: editGroup addStack + editGroup.addStack(&layout->editHistory); + map_ruler->setMapDimensions(QSize(this->layout->getWidth(), this->layout->getHeight())); connect(this->layout, &Layout::layoutDimensionsChanged, map_ruler, &MapRuler::setMapDimensions); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 25e73e73..b62aa339 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -221,6 +221,14 @@ void MainWindow::initExtraSignals() { connect(ui->mapList, &QTreeView::customContextMenuRequested, this, &MainWindow::onOpenMapListContextMenu); + ui->areaList->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->areaList, &QTreeView::customContextMenuRequested, + this, &MainWindow::onOpenMapListContextMenu); + + ui->layoutList->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->layoutList, &QTreeView::customContextMenuRequested, + this, &MainWindow::onOpenMapListContextMenu); + // other signals connect(ui->newEventToolButton, &NewEventToolButton::newEventAdded, this, &MainWindow::addNewEvent); connect(ui->tabWidget_EventType, &QTabWidget::currentChanged, this, &MainWindow::eventTabChanged); @@ -296,7 +304,7 @@ void MainWindow::initEditor() { ui->menuEdit->addAction(showHistory); // Toggle an asterisk in the window title when the undo state is changed - connect(&editor->editGroup, &QUndoGroup::cleanChanged, this, &MainWindow::showWindowTitle); + connect(&editor->editGroup, &QUndoGroup::indexChanged, this, &MainWindow::showWindowTitle); // selecting objects from the spinners connect(this->ui->spinner_ObjectID, QOverload::of(&QSpinBox::valueChanged), [this](int value) { @@ -378,8 +386,8 @@ void MainWindow::showWindowTitle() { ); } if (editor && editor->layout) { - // // QPixmap pixmap = editor->layout ? editor->layout->render(true) : QPixmap(); - QPixmap pixmap = editor->layout ? editor->layout->render(false) : QPixmap(); + //QPixmap pixmap = editor->layout ? editor->layout->render(false) : QPixmap(); + QPixmap pixmap = editor->layout->pixmap;//getLayoutItemPixmap(); if (!pixmap.isNull()) { ui->mainTabBar->setTabIcon(0, QIcon(pixmap.scaled(16, 16))); } else { @@ -549,7 +557,7 @@ bool MainWindow::openProject(QString dir) { bool already_open = isProjectOpen() && (editor->project->root == dir); if (!already_open) { editor->closeProject(); - editor->project = new Project(this); + editor->project = new Project(editor); QObject::connect(editor->project, &Project::reloadProject, this, &MainWindow::on_action_Reload_Project_triggered); QObject::connect(editor->project, &Project::disableWildEncountersUI, [this]() { this->setWildEncountersUIEnabled(false); }); QObject::connect(editor->project, &Project::uncheckMonitorFilesAction, [this]() { @@ -931,6 +939,7 @@ void MainWindow::on_comboBox_LayoutSelector_currentTextChanged(const QString &te // !TODO: method to setMapLayout instead of having to do whole setMap thing, // also edit history and bug fixes setMap(editor->map->name); + markMapEdited(); } } } @@ -1150,6 +1159,16 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point) { // return; // } + switch (ui->mapListContainer->currentIndex()) { + // + case MapListTab::Groups: + break; + case MapListTab::Areas: + break; + case MapListTab::Layouts: + break; + } + // QStandardItem *selectedItem = mapListModel->itemFromIndex(index); // QVariant itemType = selectedItem->data(MapListUserRoles::TypeRole); // if (!itemType.isValid()) { diff --git a/src/project.cpp b/src/project.cpp index f4672fab..15122fac 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -35,7 +35,7 @@ int Project::max_map_data_size = 10240; // 0x2800 int Project::default_map_size = 20; int Project::max_object_events = 64; -Project::Project(QWidget *parent) : +Project::Project(QObject *parent) : QObject(parent), eventScriptLabelModel(this), eventScriptLabelCompleter(this)