mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-30 14:54:13 +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.
167 lines
5.1 KiB
C++
167 lines
5.1 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 CROSSREFITEM_H
|
|
#define CROSSREFITEM_H
|
|
|
|
#include "../properties/xrefproperties.h"
|
|
|
|
#include <QGraphicsObject>
|
|
#include <QMultiMap>
|
|
#include <QStyleOptionGraphicsItem>
|
|
|
|
class Element;
|
|
class DynamicElementTextItem;
|
|
class ElementTextItemGroup;
|
|
|
|
/**
|
|
@brief The CrossRefItem class
|
|
This clas provide an item, for show the cross reference,
|
|
like the contacts linked to a coil.
|
|
The item setpos automatically when parent move.
|
|
All slave displayed in cross ref will be updated
|
|
when folio position change in the project.
|
|
It's the responsibility of the master element
|
|
to inform displayed slave are moved,
|
|
by calling the slot updateLabel
|
|
By default master element is the parent graphics item of this Xref,
|
|
but if the Xref must be snap to the label of master,
|
|
the label become the parent of this Xref.
|
|
This behavior can be changed at anytime by calling setProperties.
|
|
*/
|
|
class CrossRefItem : public QGraphicsObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
//Methods
|
|
public:
|
|
explicit CrossRefItem(Element *elmt);
|
|
explicit CrossRefItem(
|
|
Element *elmt, DynamicElementTextItem *text);
|
|
explicit CrossRefItem(
|
|
Element *elmt, ElementTextItemGroup *group);
|
|
~CrossRefItem() override;
|
|
private:
|
|
void init();
|
|
void setUpConnection();
|
|
|
|
public:
|
|
enum { Type = UserType + 1009 };
|
|
int type() const override { return Type; }
|
|
|
|
/// Returns true when \a xrp asks the contact comb of \a elmt to show
|
|
/// every slave contact the master defines, even the ones no slave is
|
|
/// linked to yet. \a elmt must be a master element.
|
|
static bool showAllConfiguredSlaves(
|
|
const Element *elmt,
|
|
const XRefProperties &xrp);
|
|
|
|
/**
|
|
@brief The CONTACTS enum
|
|
*/
|
|
enum CONTACTS {
|
|
NO = 1,
|
|
NC = 2,
|
|
NOC = 3,
|
|
SW = 4,
|
|
Power = 8,
|
|
DelayOn = 16,
|
|
DelayOff = 32,
|
|
DelayOnOff = 64,
|
|
Delay = 112,
|
|
Other = 128
|
|
};
|
|
|
|
QRectF boundingRect() const override;
|
|
QPainterPath shape() const override;
|
|
QString elementPositionText(
|
|
const Element *elmt,
|
|
const bool &add_prefix = false) const;
|
|
|
|
public slots:
|
|
void updateProperties();
|
|
void updateLabel();
|
|
void autoPos();
|
|
|
|
public:
|
|
/// DXF export: replay this item's paint() on an arbitrary QPainter
|
|
/// (e.g. one targeting DxfPaintDevice). paint() itself stays
|
|
/// protected, as it should for the normal
|
|
/// QGraphicsScene/QGraphicsView paint contract - this is a
|
|
/// deliberate, narrow escape hatch for exporters, not a general
|
|
/// relaxation of that contract.
|
|
void paintForExport(QPainter *painter)
|
|
{
|
|
QStyleOptionGraphicsItem option;
|
|
paint(painter, &option, nullptr);
|
|
}
|
|
|
|
protected:
|
|
bool sceneEvent(QEvent *event) override;
|
|
void paint(QPainter *painter,
|
|
const QStyleOptionGraphicsItem *option,
|
|
QWidget *widget) override;
|
|
void mouseDoubleClickEvent (
|
|
QGraphicsSceneMouseEvent * event ) override;
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
|
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
|
|
|
private:
|
|
void linkedChanged();
|
|
void buildHeaderContact(QPainter &painter, QPointF no_pos, QPointF nc_pos);
|
|
void setUpCrossBoundingRect(QPainter &painter);
|
|
void drawAsCross(QPainter &painter);
|
|
void drawAsContacts(QPainter &painter);
|
|
void drawAsPlcTable(QPainter &painter);
|
|
bool mustDrawAllConfiguredSlaves() const;
|
|
QRectF drawLinkedSlaveContacts(QPainter &painter, Element *elmt);
|
|
QRectF drawContact(QPainter &painter,
|
|
int flags,
|
|
Element *elmt,
|
|
int pole_index = 0,
|
|
const QStringList &master_labels = QStringList());
|
|
void fillCrossRef(QPainter &painter);
|
|
void AddExtraInfo(QPainter &painter, const QString&);
|
|
QList<Element *> NOElements() const;
|
|
QList<Element *> NCElements() const;
|
|
|
|
//Attributes
|
|
private:
|
|
Element *m_element; //element to display the cross reference
|
|
QRectF m_bounding_rect;
|
|
QPainterPath m_shape_path;
|
|
XRefProperties m_properties;
|
|
int m_drawed_contacts;
|
|
bool m_update_map = false;
|
|
QMultiMap <Element *, QRectF> m_hovered_contacts_map;
|
|
Element *m_hovered_contact = nullptr;
|
|
DynamicElementTextItem *m_text = nullptr;
|
|
ElementTextItemGroup *m_group = nullptr;
|
|
QList <QMetaObject::Connection> m_slave_connection;
|
|
QList <QMetaObject::Connection> m_update_connection;
|
|
|
|
public:
|
|
/// Returns the map of linked elements and their clickable rects (local coords).
|
|
/// Used by the PDF export to inject hyperlink annotations.
|
|
const QMultiMap<Element *, QRectF> &hoveredContactsMap() const
|
|
{ return m_hovered_contacts_map; }
|
|
};
|
|
|
|
#endif // CROSSREFITEM_H
|
|
|