# HG changeset patch # User Teemu Piippo # Date 1646493524 -7200 # Node ID 6da096930534e5e33098b5df5a0f7be2a904aace # Parent 24590af32ad6f32770240d6517295084579f066d Added the delete action diff -r 24590af32ad6 -r 6da096930534 icons/trash-bin-outline.png Binary file icons/trash-bin-outline.png has changed diff -r 24590af32ad6 -r 6da096930534 icons_svg/trash-bin-outline.svg --- /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 @@ + + + + + + image/svg+xml + + + + + + + ionicons-v5-k + + + + + diff -r 24590af32ad6 -r 6da096930534 ldforge.qrc --- 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 @@ icons/linetype-conditionaledge.png icons/close-circle-outline.png icons/navigate-outline.png + icons/trash-bin-outline.png diff -r 24590af32ad6 -r 6da096930534 src/document.cpp --- 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 Document::selectedObjects() const +{ + return this->renderer->selectedObjects(); +} diff -r 24590af32ad6 -r 6da096930534 src/document.h --- 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 selectedObjects() const; Q_SIGNALS: void newStatusText(const QString& newStatusText); void splitterChanged(); diff -r 24590af32ad6 -r 6da096930534 src/mainwindow.cpp --- 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 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 = document->editModel(); + QSet 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 */ diff -r 24590af32ad6 -r 6da096930534 src/mainwindow.h --- 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; diff -r 24590af32ad6 -r 6da096930534 src/mainwindow.ui --- 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 @@ 0 0 800 - 35 + 27 @@ -64,8 +64,15 @@ + + + Edit + + + + @@ -97,6 +104,18 @@ + + + toolBar_2 + + + TopToolBarArea + + + false + + + @@ -227,6 +246,18 @@ Ctrl+W + + + + :/icons/trash-bin-outline.png:/icons/trash-bin-outline.png + + + Delete + + + Del + + diff -r 24590af32ad6 -r 6da096930534 src/ui/canvas.cpp --- 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 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 diff -r 24590af32ad6 -r 6da096930534 src/ui/canvas.h --- 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& points) const; const std::optional& getWorldPosition() const; void adjustGridToView(); + const QSet selectedObjects() const; public Q_SLOTS: void handleSelectionChange(const QSet& selectedIds, const QSet& deselectedIds); void rebuildVertices(Document *document);