diff --git a/editor/mainwindow.cpp b/editor/mainwindow.cpp index 0f9df6a..06a6774 100644 --- a/editor/mainwindow.cpp +++ b/editor/mainwindow.cpp @@ -83,9 +83,7 @@ MainWindow::MainWindow(QWidget *parent) if (!path) return; std::shared_ptr newModel = DataModel::LoadFromFile(path.value()); dataModel = newModel; - delete ui->explorerView->selectionModel(); - ui->explorerView->reset(); - ui->explorerView->setModel(new ExplorerModel(dataModel)); + ui->explorerView->updateRoot(newModel); }); connect(ui->actionDelete, &QAction::triggered, this, [&]() { diff --git a/editor/panes/explorermodel.cpp b/editor/panes/explorermodel.cpp index 4571e9a..a064fe3 100644 --- a/editor/panes/explorermodel.cpp +++ b/editor/panes/explorermodel.cpp @@ -234,6 +234,12 @@ bool ExplorerModel::dropMimeData(const QMimeData *data, Qt::DropAction action, i return true; } +void ExplorerModel::updateRoot(InstanceRef newRoot) { + beginResetModel(); + rootItem = newRoot; + endResetModel(); +} + QMimeData* ExplorerModel::mimeData(const QModelIndexList& indexes) const { // application/x-openblocks-instance-pointers DragDropSlot* slot = new DragDropSlot(); diff --git a/editor/panes/explorermodel.h b/editor/panes/explorermodel.h index ed78f2a..6ea7037 100644 --- a/editor/panes/explorermodel.h +++ b/editor/panes/explorermodel.h @@ -1,18 +1,12 @@ #pragma once #include "objects/base/instance.h" -#include "objects/part.h" #include "qabstractitemmodel.h" #include "qevent.h" -#include "qmenu.h" #include "qnamespace.h" -#include "qtreeview.h" #include #include -#include -// #ifndef EXPLORERMODEL_H -// #define EXPLORERMODEL_H class ExplorerModel : public QAbstractItemModel { Q_OBJECT @@ -42,6 +36,8 @@ public: Qt::DropActions supportedDropActions() const override; InstanceRef fromIndex(const QModelIndex index) const; QModelIndex ObjectToIndex(InstanceRef item); + + void updateRoot(InstanceRef newRoot); private: InstanceRef rootItem; QModelIndex toIndex(InstanceRef item); diff --git a/editor/panes/explorerview.cpp b/editor/panes/explorerview.cpp index c057c0a..3a63f66 100644 --- a/editor/panes/explorerview.cpp +++ b/editor/panes/explorerview.cpp @@ -73,7 +73,6 @@ void ExplorerView::keyPressEvent(QKeyEvent* event) { } } - void ExplorerView::buildContextMenu() { contextMenu.addAction(M_mainWindow->ui->actionDelete); contextMenu.addSeparator(); @@ -84,4 +83,8 @@ void ExplorerView::buildContextMenu() { contextMenu.addSeparator(); contextMenu.addAction(M_mainWindow->ui->actionSaveModel); contextMenu.addAction(M_mainWindow->ui->actionInsertModel); +} + +void ExplorerView::updateRoot(InstanceRef newRoot) { + model.updateRoot(newRoot); } \ No newline at end of file diff --git a/editor/panes/explorerview.h b/editor/panes/explorerview.h index 54a5eef..607c18d 100644 --- a/editor/panes/explorerview.h +++ b/editor/panes/explorerview.h @@ -22,6 +22,7 @@ public: // void dropEvent(QDropEvent*) override; void buildContextMenu(); + void updateRoot(InstanceRef newRoot); private: ExplorerModel model; QMenu contextMenu;