diff --git a/sources/editor/elementscene.cpp b/sources/editor/elementscene.cpp index 7bfcc258e..82584ace3 100644 --- a/sources/editor/elementscene.cpp +++ b/sources/editor/elementscene.cpp @@ -1354,24 +1354,28 @@ void ElementScene::managePrimitivesGroups() m_decorator -> hide(); } + if (m_single_selected_item) { + m_single_selected_item->removeHandler(); + m_single_selected_item.clear(); + } + // should we hide the decorator? - QList selected_items = zItems( - ElementScene::Selected - | ElementScene::IncludeTerminals); + const auto selected_items{zItems(ElementScene::Selected | ElementScene::IncludeTerminals)}; if (selected_items.size() <= 1) { - m_decorator -> hide(); + m_decorator->hide(); + + if (!selected_items.isEmpty()) + { + if (CustomElementGraphicPart *item_ = dynamic_cast(selected_items.first())) + { + item_->addHandler(); + m_single_selected_item = item_; + } + } } else { - for(QGraphicsItem *qgi : selected_items) - { - /* We recall set selected, - * then every primitive will remove there handler - * because there are several item selected - */ - qgi->setSelected(true); - } m_decorator -> setZValue(1000000); m_decorator -> setPos(0, 0); m_decorator -> setItems(selected_items); diff --git a/sources/editor/elementscene.h b/sources/editor/elementscene.h index 5f275c344..cde9f07d5 100644 --- a/sources/editor/elementscene.h +++ b/sources/editor/elementscene.h @@ -32,6 +32,7 @@ class ElementPrimitiveDecorator; class QETElementEditor; class ESEventInterface; class QKeyEvent; +class CustomElementGraphicPart; /** @brief The ElementScene class This class is the canvas allowing the visual edition of an electrial element. @@ -87,6 +88,8 @@ class ElementScene : public QGraphicsScene int m_x_grid, m_y_grid; + + QPointer m_single_selected_item; // methods public: diff --git a/sources/editor/graphicspart/customelementgraphicpart.h b/sources/editor/graphicspart/customelementgraphicpart.h index d1a232e67..47e445621 100644 --- a/sources/editor/graphicspart/customelementgraphicpart.h +++ b/sources/editor/graphicspart/customelementgraphicpart.h @@ -298,6 +298,9 @@ class CustomElementGraphicPart : public QGraphicsObject, public CustomElementPar return QObject::property(name);} virtual QPainterPath shadowShape ()const = 0; + + virtual void addHandler() {} + virtual void removeHandler() {} virtual void setHandlerColor(QPointF /*pos*/, const QColor &/*color*/) {} virtual void resetAllHandlerColor() {} diff --git a/sources/editor/graphicspart/partarc.cpp b/sources/editor/graphicspart/partarc.cpp index a5e3e70dd..6bbd6152b 100644 --- a/sources/editor/graphicspart/partarc.cpp +++ b/sources/editor/graphicspart/partarc.cpp @@ -197,32 +197,12 @@ void PartArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) */ QVariant PartArc::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { - if (change == ItemSelectedHasChanged && scene()) - { - if (value.toBool() == true) - { - //When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler, - //according to the number of selected items. - connect(scene(), &QGraphicsScene::selectionChanged, this, &PartArc::sceneSelectionChanged); - - if (scene()->selectedItems().size() == 1) - addHandler(); - } - else - { - disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartArc::sceneSelectionChanged); - removeHandler(); - } - } - else if (change == ItemPositionHasChanged) + if (change == ItemPositionHasChanged) { adjusteHandlerPos(); } else if (change == ItemSceneChange) { - if(scene()) - disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartArc::sceneSelectionChanged); - setSelected(false); //This is item removed from scene, then we deselect this, and so, the handlers is also removed. } @@ -442,18 +422,6 @@ void PartArc::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSc } } -/** - @brief PartArc::sceneSelectionChanged - When the scene selection change, if there are several primitive selected, we remove the handler of this item -*/ -void PartArc::sceneSelectionChanged() -{ - if (this->isSelected() && scene()->selectedItems().size() == 1) - addHandler(); - else - removeHandler(); -} - /** @brief PartArc::addHandler Add handlers for this item diff --git a/sources/editor/graphicspart/partarc.h b/sources/editor/graphicspart/partarc.h index 1186c10c5..fafa37d23 100644 --- a/sources/editor/graphicspart/partarc.h +++ b/sources/editor/graphicspart/partarc.h @@ -61,6 +61,9 @@ class PartArc : public AbstractPartEllipse void setSpanAngle(const int &span_angle) override {AbstractPartEllipse::setSpanAngle(span_angle); adjusteHandlerPos();} QRectF sceneGeometricRect() const override; + void addHandler() override; + void removeHandler() override; + protected: void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; @@ -72,11 +75,7 @@ class PartArc : public AbstractPartEllipse void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event); void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event); void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event); - void sceneSelectionChanged (); - void addHandler(); - void removeHandler(); - private: QPropertyUndoCommand *m_undo_command = nullptr; QPropertyUndoCommand *m_undo_command2 = nullptr; diff --git a/sources/editor/graphicspart/partellipse.cpp b/sources/editor/graphicspart/partellipse.cpp index 6ecdba751..b3523b60a 100644 --- a/sources/editor/graphicspart/partellipse.cpp +++ b/sources/editor/graphicspart/partellipse.cpp @@ -179,32 +179,12 @@ void PartEllipse::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) */ QVariant PartEllipse::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { - if (change == ItemSelectedHasChanged && scene()) - { - if (value.toBool() == true) - { - //When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler, - //according to the number of selected items. - connect(scene(), &QGraphicsScene::selectionChanged, this, &PartEllipse::sceneSelectionChanged); - - if (scene()->selectedItems().size() == 1) - addHandler(); - } - else - { - disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartEllipse::sceneSelectionChanged); - removeHandler(); - } - } - else if (change == ItemPositionHasChanged) + if (change == ItemPositionHasChanged) { adjusteHandlerPos(); } else if (change == ItemSceneChange) { - if(scene()) - disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartEllipse::sceneSelectionChanged); - setSelected(false); //This item is removed from scene, then we deselect this, and so, the handlers is also removed. } @@ -339,18 +319,6 @@ void PartEllipse::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphi m_vector_index = -1; } -/** - @brief PartEllipse::sceneSelectionChanged - When the scene selection change, if there are several primitive selected, we remove the handler of this item -*/ -void PartEllipse::sceneSelectionChanged() -{ - if (this->isSelected() && scene()->selectedItems().size() == 1) - addHandler(); - else - removeHandler(); -} - /** @brief PartEllipse::addHandler Add handlers for this item diff --git a/sources/editor/graphicspart/partellipse.h b/sources/editor/graphicspart/partellipse.h index 0e0bbebae..08f73e7df 100644 --- a/sources/editor/graphicspart/partellipse.h +++ b/sources/editor/graphicspart/partellipse.h @@ -58,6 +58,9 @@ class PartEllipse : public AbstractPartEllipse QPainterPath shadowShape() const override; void setRect(const QRectF &rect) override {AbstractPartEllipse::setRect(rect); adjusteHandlerPos();} + void addHandler() override; + void removeHandler() override; + protected: void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; @@ -69,10 +72,6 @@ class PartEllipse : public AbstractPartEllipse void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event); void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event); void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event); - void sceneSelectionChanged (); - - void addHandler(); - void removeHandler(); private: QPropertyUndoCommand *m_undo_command; diff --git a/sources/editor/graphicspart/partline.cpp b/sources/editor/graphicspart/partline.cpp index f420547b9..f9b5a148d 100644 --- a/sources/editor/graphicspart/partline.cpp +++ b/sources/editor/graphicspart/partline.cpp @@ -155,32 +155,12 @@ void PartLine::fromXml(const QDomElement &qde) { */ QVariant PartLine::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { - if (change == ItemSelectedHasChanged && scene()) - { - if (value.toBool() == true) - { - //When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler, - //according to the number of selected items. - connect(scene(), &QGraphicsScene::selectionChanged, this, &PartLine::sceneSelectionChanged); - - if (scene()->selectedItems().size() == 1) - addHandler(); - } - else - { - disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartLine::sceneSelectionChanged); - removeHandler(); - } - } - else if (change == ItemPositionHasChanged) + if (change == ItemPositionHasChanged) { adjusteHandlerPos(); } else if (change == ItemSceneChange) { - if(scene()) - disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartLine::sceneSelectionChanged); - setSelected(false); //This is item removed from scene, then we deselect this, and so, the handlers is also removed. } @@ -304,18 +284,6 @@ void PartLine::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsS m_vector_index = -1; } -/** - @brief PartLine::sceneSelectionChanged - When the scene selection change, if there are several primitive selected, we remove the handler of this item -*/ -void PartLine::sceneSelectionChanged() -{ - if (this->isSelected() && scene()->selectedItems().size() == 1) - addHandler(); - else - removeHandler(); -} - /** @brief PartLine::addHandler Add handlers for this item diff --git a/sources/editor/graphicspart/partline.h b/sources/editor/graphicspart/partline.h index 0462d3274..04b5b63aa 100644 --- a/sources/editor/graphicspart/partline.h +++ b/sources/editor/graphicspart/partline.h @@ -97,6 +97,9 @@ class PartLine : public CustomElementGraphicPart void setRotation(qreal angle); qreal rotation() const; + void addHandler() override; + void removeHandler() override; + protected: QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override; @@ -106,10 +109,6 @@ class PartLine : public CustomElementGraphicPart void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event); void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event); void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event); - void sceneSelectionChanged (); - - void addHandler(); - void removeHandler(); QPainterPath path() const; QRectF firstEndCircleRect() const; diff --git a/sources/editor/graphicspart/partpolygon.cpp b/sources/editor/graphicspart/partpolygon.cpp index c89103c01..18ed251c6 100644 --- a/sources/editor/graphicspart/partpolygon.cpp +++ b/sources/editor/graphicspart/partpolygon.cpp @@ -316,32 +316,12 @@ qreal PartPolygon::rotation() const { */ QVariant PartPolygon::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { - if (change == ItemSelectedHasChanged && scene()) - { - if (value.toBool() == true) - { - //When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler, - //according to the number of selected items. - connect(scene(), &QGraphicsScene::selectionChanged, this, &PartPolygon::sceneSelectionChanged); - - if (scene()->selectedItems().size() == 1) - addHandler(); - } - else - { - disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartPolygon::sceneSelectionChanged); - removeHandler(); - } - } - else if (change == ItemPositionHasChanged) + if (change == ItemPositionHasChanged) { adjusteHandlerPos(); } else if (change == ItemSceneChange) { - if(scene()) - disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartPolygon::sceneSelectionChanged); - setSelected(false); //This is item removed from scene, then we deselect this, and so, the handlers is also removed. } @@ -484,18 +464,6 @@ void PartPolygon::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphi m_vector_index = -1; } -/** - @brief PartPolygon::sceneSelectionChanged - When the scene selection change, if there are several primitive selected, we remove the handler of this item -*/ -void PartPolygon::sceneSelectionChanged() -{ - if (this->isSelected() && scene()->selectedItems().size() == 1) - addHandler(); - else - removeHandler(); -} - /** @brief PartPolygon::addHandler Add handlers for this item diff --git a/sources/editor/graphicspart/partpolygon.h b/sources/editor/graphicspart/partpolygon.h index a68cbd36a..747c1ef15 100644 --- a/sources/editor/graphicspart/partpolygon.h +++ b/sources/editor/graphicspart/partpolygon.h @@ -90,6 +90,9 @@ class PartPolygon : public CustomElementGraphicPart void setRotation (qreal angle); qreal rotation () const; + void addHandler() override; + void removeHandler() override; + protected: QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override; @@ -100,10 +103,7 @@ class PartPolygon : public CustomElementGraphicPart void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event); void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event); void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event); - void sceneSelectionChanged (); - - void addHandler(); - void removeHandler(); + void insertPoint(); void removePoint(); diff --git a/sources/editor/graphicspart/partrectangle.cpp b/sources/editor/graphicspart/partrectangle.cpp index 148c877c4..108c8224f 100644 --- a/sources/editor/graphicspart/partrectangle.cpp +++ b/sources/editor/graphicspart/partrectangle.cpp @@ -305,32 +305,12 @@ void PartRectangle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) */ QVariant PartRectangle::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { - if (change == ItemSelectedHasChanged && scene()) - { - if (value.toBool() == true) - { - //When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler, - //according to the number of selected items. - connect(scene(), &QGraphicsScene::selectionChanged, this, &PartRectangle::sceneSelectionChanged); - - if (scene()->selectedItems().size() == 1) - addHandler(); - } - else - { - disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartRectangle::sceneSelectionChanged); - removeHandler(); - } - } - else if (change == ItemPositionHasChanged) + if (change == ItemPositionHasChanged) { adjusteHandlerPos(); } else if (change == ItemSceneChange) { - if(scene()) - disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartRectangle::sceneSelectionChanged); - setSelected(false); //This item is removed from scene, then we deselect this, and so, the handlers is also removed. } @@ -521,18 +501,6 @@ void PartRectangle::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGrap m_vector_index = -1; } -/** - @brief PartRectangle::sceneSelectionChanged - When the scene selection change, if there are several primitive selected, we remove the handler of this item -*/ -void PartRectangle::sceneSelectionChanged() -{ - if (this->isSelected() && scene()->selectedItems().size() == 1) - addHandler(); - else - removeHandler(); -} - /** @brief PartRectangle::addHandler Add handlers for this item diff --git a/sources/editor/graphicspart/partrectangle.h b/sources/editor/graphicspart/partrectangle.h index 22b04bdb3..171ef7d90 100644 --- a/sources/editor/graphicspart/partrectangle.h +++ b/sources/editor/graphicspart/partrectangle.h @@ -85,6 +85,9 @@ class PartRectangle : public CustomElementGraphicPart void startUserTransformation(const QRectF &) override; void handleUserTransformation(const QRectF &, const QRectF &) override; + void addHandler() override; + void removeHandler() override; + protected: void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; @@ -96,10 +99,6 @@ class PartRectangle : public CustomElementGraphicPart void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event); void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event); void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event); - void sceneSelectionChanged (); - - void addHandler(); - void removeHandler(); private: QRectF m_rect,