fix(editor): undo state for moving objects in the explorer
This commit is contained in:
parent
fc105400e3
commit
0991f31e57
2 changed files with 9 additions and 1 deletions
|
@ -1,11 +1,15 @@
|
|||
#include "explorermodel.h"
|
||||
#include "common.h"
|
||||
#include "mainwindow.h"
|
||||
#include "objects/base/instance.h"
|
||||
#include "objects/base/member.h"
|
||||
#include "undohistory.h"
|
||||
#include <qicon.h>
|
||||
#include <qmimedata.h>
|
||||
#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
|
||||
|
||||
std::map<std::string, QIcon> instanceIconCache;
|
||||
|
@ -216,11 +220,15 @@ bool ExplorerModel::dropMimeData(const QMimeData *data, Qt::DropAction action, i
|
|||
return true;
|
||||
}
|
||||
|
||||
UndoState historyState;
|
||||
std::shared_ptr<Instance> parentInst = fromIndex(parent);
|
||||
for (std::shared_ptr<Instance> instance : slot->instances) {
|
||||
historyState.push_back(UndoStateInstanceReparented { instance, instance->GetParent().value_or(nullptr), parentInst });
|
||||
instance->SetParent(parentInst);
|
||||
}
|
||||
|
||||
M_mainWindow->undoManager.PushState(historyState);
|
||||
|
||||
delete slot;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
ExplorerView::ExplorerView(QWidget* parent):
|
||||
QTreeView(parent),
|
||||
model(ExplorerModel(std::dynamic_pointer_cast<Instance>(gDataModel))),
|
||||
model(ExplorerModel(std::dynamic_pointer_cast<Instance>(gDataModel), this)),
|
||||
contextMenu(this) {
|
||||
|
||||
this->setModel(&model);
|
||||
|
|
Loading…
Add table
Reference in a new issue