Added the delete action

Sat, 05 Mar 2022 17:18:44 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 05 Mar 2022 17:18:44 +0200
changeset 169
6da096930534
parent 168
24590af32ad6
child 170
9b655f6fe5a1

Added the delete action

icons/trash-bin-outline.png file | annotate | diff | comparison | revisions
icons_svg/trash-bin-outline.svg file | annotate | diff | comparison | revisions
ldforge.qrc file | annotate | diff | comparison | revisions
src/document.cpp file | annotate | diff | comparison | revisions
src/document.h file | annotate | diff | comparison | revisions
src/mainwindow.cpp file | annotate | diff | comparison | revisions
src/mainwindow.h file | annotate | diff | comparison | revisions
src/mainwindow.ui file | annotate | diff | comparison | revisions
src/ui/canvas.cpp file | annotate | diff | comparison | revisions
src/ui/canvas.h file | annotate | diff | comparison | revisions
Binary file icons/trash-bin-outline.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/icons_svg/trash-bin-outline.svg	Sat Mar 05 17:18:44 2022 +0200
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="512"
+   height="512"
+   viewBox="0 0 512 512"
+   version="1.1"
+   id="svg12"
+   sodipodi:docname="trash-bin-outline.svg"
+   inkscape:version="1.0.2 (e86c870879, 2021-01-15)">
+  <metadata
+     id="metadata18">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <defs
+     id="defs16" />
+  <sodipodi:namedview
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1"
+     objecttolerance="10"
+     gridtolerance="10"
+     guidetolerance="10"
+     inkscape:pageopacity="0"
+     inkscape:pageshadow="2"
+     inkscape:window-width="1920"
+     inkscape:window-height="962"
+     id="namedview14"
+     showgrid="false"
+     inkscape:zoom="0.19726563"
+     inkscape:cx="-369.96706"
+     inkscape:cy="299.55361"
+     inkscape:window-x="0"
+     inkscape:window-y="29"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="svg12" />
+  <title
+     id="title2">ionicons-v5-k</title>
+  <path
+     d="M432,144,403.33,419.74A32,32,0,0,1,371.55,448H140.46a32,32,0,0,1-31.78-28.26L80,144"
+     style="fill:#a0a0a0;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px;fill-opacity:1"
+     id="path4" />
+  <rect
+     x="32"
+     y="64"
+     width="448"
+     height="80"
+     rx="16"
+     ry="16"
+     style="fill:#a0a0a0;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px;fill-opacity:1"
+     id="rect6" />
+  <line
+     x1="312"
+     y1="240"
+     x2="200"
+     y2="352"
+     style="fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"
+     id="line8" />
+  <line
+     x1="312"
+     y1="352"
+     x2="200"
+     y2="240"
+     style="fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"
+     id="line10" />
+</svg>
--- a/ldforge.qrc	Sat Mar 05 16:57:28 2022 +0200
+++ b/ldforge.qrc	Sat Mar 05 17:18:44 2022 +0200
@@ -27,5 +27,6 @@
         <file>icons/linetype-conditionaledge.png</file>
         <file>icons/close-circle-outline.png</file>
         <file>icons/navigate-outline.png</file>
+        <file>icons/trash-bin-outline.png</file>
     </qresource>
 </RCC>
--- a/src/document.cpp	Sat Mar 05 16:57:28 2022 +0200
+++ b/src/document.cpp	Sat Mar 05 17:18:44 2022 +0200
@@ -238,3 +238,8 @@
 {
 	return *this->model;
 }
+
+const QSet<ldraw::id_t> Document::selectedObjects() const
+{
+	return this->renderer->selectedObjects();
+}
--- a/src/document.h	Sat Mar 05 16:57:28 2022 +0200
+++ b/src/document.h	Sat Mar 05 17:18:44 2022 +0200
@@ -49,6 +49,7 @@
 	void handleKeyPress(QKeyEvent* event);
 	void adjustGridToView();
 	const Model& getModel();
+	const QSet<ldraw::id_t> selectedObjects() const;
 Q_SIGNALS:
 	void newStatusText(const QString& newStatusText);
 	void splitterChanged();
--- 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
  */
--- a/src/mainwindow.h	Sat Mar 05 16:57:28 2022 +0200
+++ b/src/mainwindow.h	Sat Mar 05 17:18:44 2022 +0200
@@ -47,6 +47,7 @@
 	void actionSave();
 	void actionSaveAs();
 	void actionClose();
+	void actionDelete();
 	void handleTabCloseButton(int tabIndex);
 protected:
 	void changeEvent(QEvent* event) override;
--- a/src/mainwindow.ui	Sat Mar 05 16:57:28 2022 +0200
+++ b/src/mainwindow.ui	Sat Mar 05 17:18:44 2022 +0200
@@ -30,7 +30,7 @@
      <x>0</x>
      <y>0</y>
      <width>800</width>
-     <height>35</height>
+     <height>27</height>
     </rect>
    </property>
    <widget class="QMenu" name="menuFile">
@@ -64,8 +64,15 @@
     <addaction name="separator"/>
     <addaction name="actionAdjustGridToView"/>
    </widget>
+   <widget class="QMenu" name="menuEdit">
+    <property name="title">
+     <string>Edit</string>
+    </property>
+    <addaction name="actionDelete"/>
+   </widget>
    <addaction name="menuFile"/>
    <addaction name="menuView"/>
+   <addaction name="menuEdit"/>
   </widget>
   <widget class="QStatusBar" name="statusbar"/>
   <widget class="QToolBar" name="fileToolBar">
@@ -97,6 +104,18 @@
    <addaction name="actionRenderStyleBfc"/>
    <addaction name="actionRenderStyleRandom"/>
   </widget>
+  <widget class="QToolBar" name="editToolBar">
+   <property name="windowTitle">
+    <string>toolBar_2</string>
+   </property>
+   <attribute name="toolBarArea">
+    <enum>TopToolBarArea</enum>
+   </attribute>
+   <attribute name="toolBarBreak">
+    <bool>false</bool>
+   </attribute>
+   <addaction name="actionDelete"/>
+  </widget>
   <action name="actionQuit">
    <property name="icon">
     <iconset resource="../ldforge.qrc">
@@ -227,6 +246,18 @@
     <string>Ctrl+W</string>
    </property>
   </action>
+  <action name="actionDelete">
+   <property name="icon">
+    <iconset resource="../ldforge.qrc">
+     <normaloff>:/icons/trash-bin-outline.png</normaloff>:/icons/trash-bin-outline.png</iconset>
+   </property>
+   <property name="text">
+    <string>Delete</string>
+   </property>
+   <property name="shortcut">
+    <string>Del</string>
+   </property>
+  </action>
  </widget>
  <resources>
   <include location="../ldforge.qrc"/>
--- a/src/ui/canvas.cpp	Sat Mar 05 16:57:28 2022 +0200
+++ b/src/ui/canvas.cpp	Sat Mar 05 17:18:44 2022 +0200
@@ -276,6 +276,14 @@
 }
 
 /**
+ * @returns the ids of the currently selected objects 
+ */
+const QSet<ldraw::id_t> Canvas::selectedObjects() const
+{
+	return this->selection;
+}
+
+/**
  * @brief Paints a circle at where @c worldPoint is located on the screen.
  * @param painter Painter to use to render
  * @param worldPoint Point to render
--- a/src/ui/canvas.h	Sat Mar 05 16:57:28 2022 +0200
+++ b/src/ui/canvas.h	Sat Mar 05 17:18:44 2022 +0200
@@ -26,6 +26,7 @@
 	Winding worldPolygonWinding(const std::vector<glm::vec3>& points) const;
 	const std::optional<glm::vec3>& getWorldPosition() const;
 	void adjustGridToView();
+	const QSet<ldraw::id_t> selectedObjects() const;
 public Q_SLOTS:
 	void handleSelectionChange(const QSet<ldraw::id_t>& selectedIds, const QSet<ldraw::id_t>& deselectedIds);
 	void rebuildVertices(Document *document);

mercurial