fix(editor): undo state for moving objects in the explorer

This commit is contained in:
maelstrom 2025-07-08 00:50:46 +02:00
parent fc105400e3
commit 0991f31e57
2 changed files with 9 additions and 1 deletions

View file

@ -1,11 +1,15 @@
#include "explorermodel.h" #include "explorermodel.h"
#include "common.h" #include "common.h"
#include "mainwindow.h"
#include "objects/base/instance.h" #include "objects/base/instance.h"
#include "objects/base/member.h" #include "objects/base/member.h"
#include "undohistory.h"
#include <qicon.h> #include <qicon.h>
#include <qmimedata.h> #include <qmimedata.h>
#include <QWidget> #include <QWidget>
#define M_mainWindow dynamic_cast<MainWindow*>(dynamic_cast<QWidget*>(dynamic_cast<QObject*>(this)->parent())->window())
// https://doc.qt.io/qt-6/qtwidgets-itemviews-simpletreemodel-example.html#testing-the-model // https://doc.qt.io/qt-6/qtwidgets-itemviews-simpletreemodel-example.html#testing-the-model
std::map<std::string, QIcon> instanceIconCache; std::map<std::string, QIcon> instanceIconCache;
@ -216,11 +220,15 @@ bool ExplorerModel::dropMimeData(const QMimeData *data, Qt::DropAction action, i
return true; return true;
} }
UndoState historyState;
std::shared_ptr<Instance> parentInst = fromIndex(parent); std::shared_ptr<Instance> parentInst = fromIndex(parent);
for (std::shared_ptr<Instance> instance : slot->instances) { for (std::shared_ptr<Instance> instance : slot->instances) {
historyState.push_back(UndoStateInstanceReparented { instance, instance->GetParent().value_or(nullptr), parentInst });
instance->SetParent(parentInst); instance->SetParent(parentInst);
} }
M_mainWindow->undoManager.PushState(historyState);
delete slot; delete slot;
return true; return true;
} }

View file

@ -15,7 +15,7 @@
ExplorerView::ExplorerView(QWidget* parent): ExplorerView::ExplorerView(QWidget* parent):
QTreeView(parent), QTreeView(parent),
model(ExplorerModel(std::dynamic_pointer_cast<Instance>(gDataModel))), model(ExplorerModel(std::dynamic_pointer_cast<Instance>(gDataModel), this)),
contextMenu(this) { contextMenu(this) {
this->setModel(&model); this->setModel(&model);