Sat, 24 Jul 2021 01:50:38 +0300
Move selection logic into select tool
src/gl/partrenderer.cpp | file | annotate | diff | comparison | revisions | |
src/gl/partrenderer.h | file | annotate | diff | comparison | revisions | |
src/main.h | file | annotate | diff | comparison | revisions | |
src/tools/selecttool.cpp | file | annotate | diff | comparison | revisions | |
src/tools/selecttool.h | file | annotate | diff | comparison | revisions | |
src/ui/canvas.cpp | file | annotate | diff | comparison | revisions | |
src/ui/canvas.h | file | annotate | diff | comparison | revisions |
--- a/src/gl/partrenderer.cpp Tue Jul 20 01:22:01 2021 +0300 +++ b/src/gl/partrenderer.cpp Sat Jul 24 01:50:38 2021 +0300 @@ -382,3 +382,11 @@ emit this->renderPreferencesChanged(); this->update(); } + +/** + * @return the currently highlighted object + */ +ldraw::id_t PartRenderer::getHighlightedObject() const +{ + return this->highlighted; +}
--- a/src/gl/partrenderer.h Tue Jul 20 01:22:01 2021 +0300 +++ b/src/gl/partrenderer.h Sat Jul 24 01:50:38 2021 +0300 @@ -22,6 +22,7 @@ QWidget* parent = nullptr); ~PartRenderer() override; void setRenderPreferences(const gl::RenderPreferences& newPreferences); + ldraw::id_t getHighlightedObject() const; protected: ldraw::id_t pick(const QPoint& where); void initializeGL() override;
--- a/src/main.h Tue Jul 20 01:22:01 2021 +0300 +++ b/src/main.h Sat Jul 24 01:50:38 2021 +0300 @@ -92,6 +92,12 @@ } template<typename T> + inline bool operator!=(Id<T> one, decltype(NULL_ID)) + { + return one.value != 0; + } + + template<typename T> inline bool operator<(Id<T> one, decltype(NULL_ID)) { return one.value < 0;
--- a/src/tools/selecttool.cpp Tue Jul 20 01:22:01 2021 +0300 +++ b/src/tools/selecttool.cpp Sat Jul 24 01:50:38 2021 +0300 @@ -14,3 +14,14 @@ static const QString result = tr("Select elements from the model."); return result; } + +bool SelectTool::mouseClick(const Canvas::MouseClickInfo& info) +{ + const ldraw::id_t highlighted = info.invoker->getHighlightedObject(); + info.invoker->clearSelection(); + if (highlighted != ldraw::NULL_ID) + { + info.invoker->addToSelection(highlighted); + } + return true; +}
--- a/src/tools/selecttool.h Tue Jul 20 01:22:01 2021 +0300 +++ b/src/tools/selecttool.h Sat Jul 24 01:50:38 2021 +0300 @@ -8,6 +8,7 @@ public: Q_INVOKABLE SelectTool(QObject* parent = nullptr); - QString name() const; - QString toolTip() const; + QString name() const override; + QString toolTip() const override; + bool mouseClick(const Canvas::MouseClickInfo &info) override; };
--- a/src/ui/canvas.cpp Tue Jul 20 01:22:01 2021 +0300 +++ b/src/ui/canvas.cpp Sat Jul 24 01:50:38 2021 +0300 @@ -91,17 +91,6 @@ { if (this->totalMouseMove < (2.0 / sqrt(2)) * 5.0) { - if (this->highlighted == ldraw::NULL_ID) - { - this->selection = {}; - } - else - { - this->selection = {this->highlighted}; - } - this->compiler->setSelectedObjects(this->selection); - emit selectionChanged(this->selection); - this->update(); MouseClickInfo info; info.worldPosition = this->worldPosition; info.invoker = this; @@ -297,3 +286,19 @@ { return previewLayers[static_cast<unsigned int>(name)]; } + +void Canvas::clearSelection() +{ + this->selection.clear(); + this->compiler->setSelectedObjects(this->selection); + emit selectionChanged(this->selection); + this->update(); +} + +void Canvas::addToSelection(ldraw::id_t id) +{ + this->selection.insert(id); + this->compiler->setSelectedObjects(this->selection); + emit selectionChanged(this->selection); + this->update(); +}
--- a/src/ui/canvas.h Tue Jul 20 01:22:01 2021 +0300 +++ b/src/ui/canvas.h Sat Jul 24 01:50:38 2021 +0300 @@ -26,6 +26,8 @@ QWidget* parent = nullptr); const PreviewLayer& getPreviewLayer(PreviewLayerName name) const; PreviewLayer& modifyPreviewLayer(PreviewLayerName name); + void clearSelection(); + void addToSelection(ldraw::id_t id); public slots: void handleSelectionChange(const QSet<ldraw::id_t>& selectedIds, const QSet<ldraw::id_t>& deselectedIds); protected: