mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 14:50:53 +01:00
Element editor : Improve responsiveness when several shapes are selected.
This commit is contained in:
@@ -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<QGraphicsItem *> 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<CustomElementGraphicPart *>(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);
|
||||
|
||||
@@ -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.
|
||||
@@ -88,6 +89,8 @@ class ElementScene : public QGraphicsScene
|
||||
int m_x_grid,
|
||||
m_y_grid;
|
||||
|
||||
QPointer<CustomElementGraphicPart> m_single_selected_item;
|
||||
|
||||
// methods
|
||||
public:
|
||||
ElementData elementData();
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,10 +75,6 @@ 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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user