mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-29 05:44:14 +02:00
c1cc9a5b98
Add a new cross reference setting per xref type (coil, protection, commutator, PLC), labelled "Afficher tous les esclaves definis par le maitre" and persisted as showallconfiguredslaves. When it is enabled, the contacts display is selected and the master declares contact groups, the contact comb draws every contact group of the master in the master's own order, even when no slave is linked to it yet. Masters without declared contact groups and the option turned off keep the previous behaviour exactly: linked slaves only, sorted by position. - XRefProperties: new property stored in the settings and in the project XML (attribute showallconfiguredslaves, absent means false so old files are unaffected), included in operator==. - XRefPropertiesWidget: new checkbox placed after the terminal names one, enabled only while "Afficher en contacts" is selected; its enabled state is now also set explicitly when a type is loaded (a radio button that does not change emits no toggled()). - For the PLC type the contacts/cross radios, the two display checkboxes and the cross options group are hidden: a PLC master is always drawn as its IO table, those settings have no effect there. Positioning and label settings, which the table really uses, stay. - CrossRefItem: free slots draw the symbol of the group plus the terminal names the master defines (pairs swapped for a single pole NO/NC contact, labels of a changeover contact rotated one step counter-clockwise), without position text and without hover/click. Linked slaves keep drawing from their own data at their assigned group position; links without a group are appended at the end in position order. - Xref lifecycle: the item is created and kept without linked slaves for snap-to-bottom (MasterElement::mustShowXrefWithoutSlave) and for snap-to-label (DynamicElementTextItem::updateXref and ElementTextItemGroup::updateXref, which now also run when the element lands on the scene and re-establish their project connection), so a freshly placed master shows its comb immediately instead of only after the next settings change. updateLabel() resets its geometry when the option is turned off again, so no stale ghost stays.
131 lines
4.6 KiB
C++
131 lines
4.6 KiB
C++
/*
|
|
Copyright 2006-2026 The QElectroTech Team
|
|
This file is part of QElectroTech.
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#ifndef ELEMENTTEXTITEMGROUP_H
|
|
#define ELEMENTTEXTITEMGROUP_H
|
|
|
|
#include <QGraphicsItemGroup>
|
|
#include <QObject>
|
|
#include <QDomElement>
|
|
|
|
class Element;
|
|
class DynamicElementTextItem;
|
|
class Diagram;
|
|
class CrossRefItem;
|
|
|
|
/**
|
|
@brief The ElementTextItemGroup class
|
|
This class represent a group of element text
|
|
Texts in the group can be aligned left / center /right
|
|
*/
|
|
class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
|
|
{
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
|
|
Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
|
|
Q_PROPERTY(int verticalAdjustment READ verticalAdjustment WRITE setVerticalAdjustment NOTIFY verticalAdjustmentChanged)
|
|
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
|
|
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
|
Q_PROPERTY(bool holdToBottomPage READ holdToBottomPage WRITE setHoldToBottomPage NOTIFY holdToBottomPageChanged)
|
|
Q_PROPERTY(bool frame READ frame WRITE setFrame NOTIFY frameChanged)
|
|
|
|
public:
|
|
signals:
|
|
void rotationChanged(qreal);
|
|
void verticalAdjustmentChanged(int);
|
|
void alignmentChanged(Qt::Alignment);
|
|
void nameChanged(QString);
|
|
void holdToBottomPageChanged(bool);
|
|
void xChanged();
|
|
void yChanged();
|
|
void frameChanged(bool frame);
|
|
|
|
public:
|
|
ElementTextItemGroup(const QString &name, Element *parent);
|
|
~ElementTextItemGroup() override;
|
|
void addToGroup(QGraphicsItem *item);
|
|
void removeFromGroup(QGraphicsItem *item);
|
|
void blockAlignmentUpdate(bool block);
|
|
|
|
void setAlignment(Qt::Alignment alignement);
|
|
Qt::Alignment alignment() const;
|
|
void updateAlignment();
|
|
int verticalAdjustment() const {return m_vertical_adjustment;}
|
|
void setVerticalAdjustment(int v);
|
|
void setName(QString name);
|
|
QString name() const {return m_name;}
|
|
void setHoldToBottomPage(bool hold);
|
|
bool holdToBottomPage() const {return m_hold_to_bottom_of_page;}
|
|
void setFrame(const bool frame);
|
|
bool frame() const;
|
|
QList<DynamicElementTextItem *> texts() const;
|
|
Diagram *diagram() const;
|
|
Element *parentElement() const;
|
|
/// PDF export: slave cross-reference text item of the group, if any.
|
|
QGraphicsTextItem *slaveXrefItem() const { return m_slave_Xref_item; }
|
|
|
|
QDomElement toXml(QDomDocument &dom_document) const;
|
|
void fromXml(QDomElement &dom_element);
|
|
static QString xmlTaggName() {return QString("texts_group");}
|
|
|
|
void paint(QPainter *painter,
|
|
const QStyleOptionGraphicsItem *option,
|
|
QWidget *widget) override;
|
|
QRectF boundingRect() const override;
|
|
void setRotation(qreal angle);
|
|
void setPos(const QPointF &pos);
|
|
void setPos(qreal x, qreal y);
|
|
|
|
protected:
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
|
void mouseReleaseEvent(
|
|
QGraphicsSceneMouseEvent *event) override;
|
|
void mouseDoubleClickEvent(
|
|
QGraphicsSceneMouseEvent *event) override;
|
|
void keyPressEvent(QKeyEvent *event) override;
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
|
QVariant itemChange(GraphicsItemChange change,
|
|
const QVariant &value) override;
|
|
|
|
private:
|
|
void updateXref();
|
|
void adjustSlaveXrefPos(int slave_offset = 0);
|
|
void autoPos();
|
|
|
|
private:
|
|
Qt::Alignment m_alignment = Qt::AlignJustify;
|
|
QString m_name;
|
|
bool m_first_move = true,
|
|
m_hold_to_bottom_of_page = false,
|
|
m_block_alignment_update = false,
|
|
m_frame = false;
|
|
QPointF m_initial_position;
|
|
int m_vertical_adjustment = 0;
|
|
CrossRefItem *m_Xref_item = nullptr;
|
|
Element *m_parent_element = nullptr;
|
|
QList<QMetaObject::Connection> m_update_slave_Xref_connection;
|
|
QGraphicsTextItem *m_slave_Xref_item = nullptr;
|
|
QMetaObject::Connection m_project_xref_connection;
|
|
QMetaObject::Connection m_XrefChanged_timer,
|
|
m_linked_changed_timer;
|
|
};
|
|
|
|
#endif // ELEMENTTEXTITEMGROUP_H
|