From c69e5747a1d27958d22639af7f820857ceea6d5d Mon Sep 17 00:00:00 2001 From: ispyisail Date: Tue, 1 Sep 2026 07:16:32 +1200 Subject: [PATCH] Add position-lock checkbox to element properties (issue #801) Elements already inherited QetGraphicsItem::isMovable()/setMovable() -- the same mechanism images and drawn shapes use for their "lock position" checkbox -- but nothing exposed it in the element properties panel, and Element::toXml()/fromXml() never persisted it. - ElementPropertiesWidget::generalWidget(): add a "Verrouiller la position" checkbox mirroring ShapeGraphicsItemPropertiesWidget's m_lock_pos_cb, toggling the element's inherited setMovable(). - Element::toXml()/fromXml(): persist is_movable, same attribute name and default-true behavior as DiagramImageItem/QetShapeItem. Verified via headless --resave round-trip: is_movable="0" survives load -> save unchanged, existing elements without the attribute default to movable. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01HdWpDp3TrPKbHnv7YUcNJj --- sources/qetgraphicsitem/element.cpp | 2 ++ sources/ui/elementpropertieswidget.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 23c9eda42..6de1df258 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -806,6 +806,7 @@ bool Element::fromXml(QDomElement &e, setZValue(e.attribute(QStringLiteral("z"), QString::number(this->zValue())).toDouble()); setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + is_movable_ = e.attribute(QStringLiteral("is_movable"), QStringLiteral("1")).toInt(); // orientation bool conv_ok; @@ -937,6 +938,7 @@ QDomElement Element::toXml( element.setAttribute(QStringLiteral("y"), QString::number(pos().y())); element.setAttribute(QStringLiteral("z"), QString::number(this->zValue())); element.setAttribute(QStringLiteral("orientation"), QString::number(orientation())); + element.setAttribute(QStringLiteral("is_movable"), bool(is_movable_)); /* get the first id to use for the bounds of this element * recupere le premier id a utiliser pour les bornes de cet element */ diff --git a/sources/ui/elementpropertieswidget.cpp b/sources/ui/elementpropertieswidget.cpp index 47a5b482a..815f954e7 100644 --- a/sources/ui/elementpropertieswidget.cpp +++ b/sources/ui/elementpropertieswidget.cpp @@ -30,6 +30,7 @@ #include "masterpropertieswidget.h" #include "plclinkwidget.h" +#include #include #include #include @@ -396,6 +397,18 @@ QWidget *ElementPropertiesWidget::generalWidget() label->setTextInteractionFlags(Qt::TextEditorInteraction); vlayout_->addWidget(label); + //checkbox to lock the element position on the diagram + //(same mechanism already used by images and drawn shapes) + QCheckBox *lock_pos_cb = new QCheckBox(tr("Verrouiller la position"), general_widget); + lock_pos_cb->setChecked(!m_element->isMovable()); + QPointer element = m_element; + connect(lock_pos_cb, &QCheckBox::clicked, this, [element](bool checked) { + if (element) { + element->setMovable(!checked); + } + }); + vlayout_->addWidget(lock_pos_cb); + //widget for the pixmap QLabel *pix = new QLabel(general_widget); vlayout_->addWidget(pix, 0, Qt::AlignHCenter);