fix layout undo history

This commit is contained in:
garak 2023-02-08 11:48:42 -05:00
parent 72eb8f873f
commit f8c7ada585
6 changed files with 49 additions and 6 deletions

View file

@ -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; }

View file

@ -34,7 +34,7 @@ class Project : public QObject
{
Q_OBJECT
public:
Project(QWidget *parent = nullptr);
Project(QObject *parent = nullptr);
~Project();
Project(const Project &) = delete;

View file

@ -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();
}

View file

@ -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);

View file

@ -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<int>::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()) {

View file

@ -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)