src/mainwindow.cpp

changeset 169
6da096930534
parent 160
536efae7137e
child 170
9b655f6fe5a1
--- a/src/mainwindow.cpp	Sat Mar 05 16:57:28 2022 +0200
+++ b/src/mainwindow.cpp	Sat Mar 05 17:18:44 2022 +0200
@@ -28,6 +28,7 @@
 #include "document.h"
 #include "uiutilities.h"
 #include "widgets/colorselectdialog.h"
+#include "modeleditor.h"
 
 template<typename BaseType, typename MemberType, typename DataType>
 struct MemberData
@@ -77,6 +78,7 @@
 	connect(this->ui->actionSaveAs, &QAction::triggered,
 		this, &MainWindow::actionSaveAs);
 	connect(this->ui->actionClose, &QAction::triggered, this, &MainWindow::actionClose);
+	connect(this->ui->actionDelete, &QAction::triggered, this, &MainWindow::actionDelete);
 	connect(this->ui->tabs, &QTabWidget::tabCloseRequested, this, &MainWindow::handleTabCloseButton);
 	for (auto data : ::renderStyleButtons)
 	{
@@ -332,6 +334,27 @@
 }
 
 /**
+ * @brief Handles the "Delete" (Del) action
+ */
+void MainWindow::actionDelete()
+{
+	Document* document = this->currentDocument();
+	if (document != nullptr)
+	{
+		std::unique_ptr<ModelEditor> modelEditor = document->editModel();
+		QSet<ldraw::id_t> ids = document->selectedObjects(); // copy
+		for (const ldraw::id_t id : ids)
+		{
+			const QModelIndex index = modelEditor->model().find(id);
+			if (index.isValid())
+			{
+				modelEditor->remove(index.row());
+			}
+		}
+	}
+}
+
+/**
  * @brief Removes the document at the specified tab index
  * @param index
  */

mercurial