feat: Basic context menu for explorer
This commit is contained in:
parent
6931aa5b7e
commit
497b24c03f
BIN
assets/icons/editor/delete.png
Normal file
BIN
assets/icons/editor/delete.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 715 B |
|
@ -22,6 +22,7 @@
|
||||||
#include "qevent.h"
|
#include "qevent.h"
|
||||||
#include "qnamespace.h"
|
#include "qnamespace.h"
|
||||||
#include "qobject.h"
|
#include "qobject.h"
|
||||||
|
#include "qtreeview.h"
|
||||||
|
|
||||||
class ExplorerEventFilter : public QObject {
|
class ExplorerEventFilter : public QObject {
|
||||||
|
|
||||||
|
@ -68,6 +69,21 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
ui->explorerView->setAcceptDrops(true);
|
ui->explorerView->setAcceptDrops(true);
|
||||||
ui->explorerView->setDropIndicatorShown(true);
|
ui->explorerView->setDropIndicatorShown(true);
|
||||||
ui->explorerView->installEventFilter(new ExplorerEventFilter(ui->explorerView, &explorerModel));
|
ui->explorerView->installEventFilter(new ExplorerEventFilter(ui->explorerView, &explorerModel));
|
||||||
|
ui->explorerView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
|
||||||
|
explorerMenu.addAction(ui->actionDelete);
|
||||||
|
|
||||||
|
connect(ui->explorerView, &QTreeView::customContextMenuRequested, this, [&](const QPoint& point) {
|
||||||
|
QModelIndex index = ui->explorerView->indexAt(point);
|
||||||
|
explorerMenu.exec(ui->explorerView->viewport()->mapToGlobal(point));
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(ui->actionDelete, &QAction::triggered, this, [&]() {
|
||||||
|
QModelIndexList selectedIndexes = ui->explorerView->selectionModel()->selectedIndexes();
|
||||||
|
for (QModelIndex index : selectedIndexes) {
|
||||||
|
explorerModel.fromIndex(index)->SetParent(std::nullopt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
simulationInit();
|
simulationInit();
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "explorermodel.h"
|
#include "explorermodel.h"
|
||||||
#include "qbasictimer.h"
|
#include "qbasictimer.h"
|
||||||
#include "qcoreevent.h"
|
#include "qcoreevent.h"
|
||||||
|
#include "qmenu.h"
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ExplorerModel explorerModel;
|
ExplorerModel explorerModel;
|
||||||
|
QMenu explorerMenu;
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
QBasicTimer timer;
|
QBasicTimer timer;
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,21 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
<action name="actionDelete">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset>
|
||||||
|
<normaloff>assets/icons/editor/delete.png</normaloff>assets/icons/editor/delete.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Delete</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string><html><head/><body><p>Deletes a selected object</p></body></html></string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Del</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
|
Loading…
Reference in a new issue