QElectroTech 0.200.1-dev
Loading...
Searching...
No Matches
element.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2026 The QElectroTech Team
3 This file is part of QElectroTech.
4
5 QElectroTech is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
9
10 QElectroTech is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef ELEMENT_H
19#define ELEMENT_H
20
24#include "../diagramcontext.h"
25#include "../qet.h"
26#include "qetgraphicsitem.h"
28
29#include <QHash>
30#include <QPicture>
31#include <algorithm>
32
33class QETProject;
34class Terminal;
35class Conductor;
38class QUndoCommand;
39
44{
47
48 Q_OBJECT
49 public:
65
72 struct LinkInfo {
73 QUuid uuid;
74 int group_index = -1;
75
76 LinkInfo() = default;
77 LinkInfo(const QUuid &u, int gi = -1) : uuid(u), group_index(gi) {}
78 };
79
81 QGraphicsItem * = nullptr,
82 int *state = nullptr,
83 Element::kind link_type = Element::Simple);
84 ~Element() override;
85 private:
86 Element(const Element &);
87
88 // attributes
89 public:
95 enum { Type = UserType + 1000 };
96 int type() const override { return Type; }
97
98 signals:
99 void linkedElementChanged(); //This signal is emitted when the linked elements with this element change
101 DiagramContext old_info,
102 DiagramContext new_info);
109 ElementTextItemGroup *group);
112 ElementTextItemGroup *group);
113
114 public slots:
116
117 public:
118 QList<Terminal *> terminals() const;
119 QList<Conductor *> conductors() const;
120 QList<QPair<Terminal *,Terminal *>> AlignedFreeTerminals() const;
121
122 //METHODS related to information
124 {return m_data.m_informations;}
125 virtual void setElementInformations(DiagramContext dc);
126
127 ElementData elementData() const;
128 void setElementData (ElementData data);
129
138 //@kind_information_ is used to store more information
139 //about the herited class like contactelement for know
140 // kind of contact (simple tempo) or number of contact show by the element.
141
146 void setUpFormula(bool code_letter = true, QUndoCommand *parent_undo = nullptr);
147 void setPrefix(QString);
148 QString getPrefix() const;
149 void freezeLabel(bool freeze);
150 bool isFreezeLabel() const {return m_freeze_label;}
152 QString actualLabel();
153
154 QString name() const override;
156 virtual void setHighlighted(bool);
157 void displayHelpLine(bool b = true);
158 QSize size() const;
159 QPixmap pixmap();
160 QPoint setHotspot(QPoint);
161 QPoint hotspot() const;
162 void editProperty() override;
163 static bool valideXml(QDomElement &);
164 virtual bool fromXml(
165 QDomElement &,
166 QHash<int,
167 Terminal *> &);
168 virtual QDomElement toXml(
169 QDomDocument &,
170 QHash<Terminal *,
171 int> &) const;
172 QUuid uuid() const;
173 int orientation() const;
174
175 //METHODS related to texts
176 void addDynamicTextItem(DynamicElementTextItem *deti = nullptr);
178 QList<DynamicElementTextItem *> dynamicTextItems() const;
179 ElementTextItemGroup *addTextGroup(const QString &name);
182 ElementTextItemGroup *textGroup(const QString &name) const;
183 QList<ElementTextItemGroup *> textGroups() const;
184 bool addTextToGroup(
186 ElementTextItemGroup *group);
189 ElementTextItemGroup *group);
190
191 //METHODS related to linked element
192 bool isFree() const;
193 virtual void linkToElement(Element *) {}
194 virtual void unlinkAllElements() {}
195 virtual void unlinkElement(Element *) {}
196 virtual void initLink(QETProject *);
197 QList<Element *> linkedElements ();
198
199 int groupIndexForElement(Element *elmt) const;
200 void setGroupIndexForElement(Element *elmt, int index);
201
207 virtual kind linkType() const {return m_link_type;} // return the linkable type
213 QString linkTypeToString() const;
214
215 void newUuid() {m_uuid = QUuid::createUuid();} //create new uuid for this element
216
217 protected:
218 void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
219 void setSize(int, int);
220
221 private:
222 void drawHighlight(
223 QPainter *,
224 const QStyleOptionGraphicsItem *);
225 bool buildFromXml(const QDomElement &, int * = nullptr);
226 bool parseElement(const QDomElement &dom);
227 bool parseInput(const QDomElement &dom_element);
229 const QDomElement &dom_element);
230 Terminal *parseTerminal(const QDomElement &dom_element);
231
232 //Reimplemented from QGraphicsItem
233 public:
234 void paint(
235 QPainter *,
236 const QStyleOptionGraphicsItem *,
237 QWidget *) override;
238 QRectF boundingRect() const override;
239 protected:
240 void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
242 QGraphicsSceneMouseEvent *event) override;
243 void hoverEnterEvent(QGraphicsSceneHoverEvent *) override;
244 void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override;
245
246 protected:
247 //ATTRIBUTES related to linked element
248 QList <Element *> connected_elements;
249 QList <LinkInfo> tmp_uuids_link;
250 QHash <Element *, int> m_group_index_map;
251 QUuid m_uuid;
253
254 //ATTRIBUTES related to informations
257 bool m_freeze_label = false;
258 QString m_F_str;
259
261 QList <Terminal *> m_terminals;
262 QPicture m_picture;
265 QList<QPointF> m_plc_table_positions; // Positions of plc_table parts in the element definition
266
267 void drawPlcTable(QPainter *painter);
268
269 public:
271 QList<QPointF> plcTablePositions() const { return m_plc_table_positions; }
272
273 private:
274 bool m_must_highlight = false;
277 bool m_mouse_over = false;
278 QString m_prefix;
279 QList <DynamicElementTextItem *> m_dynamic_text_list;
280 QList <ElementTextItemGroup *> m_texts_group;
281
282};
283
284bool comparPos(const Element * elmt1, const Element * elmt2);
285
286inline bool Element::isFree() const
287{
288 return (connected_elements.isEmpty());
289}
290
299inline int Element::orientation() const
300{
301 return(QET::correctAngle(rotation())/90);
302}
303
308inline QUuid Element::uuid() const
309{return m_uuid;}
310
315inline QList <Element *> Element::linkedElements()
316{
317 std::sort(
318 connected_elements.begin(),
319 connected_elements.end(),
320 comparPos);
321 return connected_elements;
322}
323
324#endif
Definition conductor.h:44
Definition diagramcontext.h:92
The DynamicElementTextItem class This class provide a simple text field of element who can be added o...
Definition dynamicelementtextitem.h:40
The ElementData class WARNING This class inherit from PropertiesInterface but only fromXml is actuall...
Definition elementdata.h:36
Definition element.h:44
ElementsLocation location() const
Definition element.cpp:1776
void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *)
Definition element.cpp:370
QRectF boundingRect() const override
Definition element.cpp:274
void textRemoved(DynamicElementTextItem *deti)
QString linkTypeToString() const
linkTypeToString use elementData function instead
Definition element.cpp:1357
~Element() override
Element::~Element.
Definition element.cpp:150
QPicture m_low_zoom_picture
Definition element.h:263
void updateConductorTexts()
Element::updateConductorTexts Slot that is triggered when a cable is * connected to or disconnected f...
Definition element.cpp:1789
void newUuid()
Definition element.h:215
Terminal * parseTerminal(const QDomElement &dom_element)
Element::parseTerminal Parse partTerminal from xml structure.
Definition element.cpp:658
bool buildFromXml(const QDomElement &, int *=nullptr)
Element::buildFromXml Build this element from an xml description.
Definition element.cpp:411
autonum::sequentialNumbers & rSequenceStruct()
Definition element.h:144
int groupIndexForElement(Element *elmt) const
Element::groupIndexForElement Returns the group index assigned to the given linked element....
Definition element.cpp:1390
void linkedElementChanged()
void setUpFormula(bool code_letter=true, QUndoCommand *parent_undo=nullptr)
Element::setUpFormula Set up the formula used to create the label of this element.
Definition element.cpp:1654
DynamicElementTextItem * parseDynamicText(const QDomElement &dom_element)
Element::parseDynamicText Create the dynamic text field described in dom_element.
Definition element.cpp:636
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override
Definition element.cpp:1617
QList< Conductor * > conductors() const
Element::conductors.
Definition element.cpp:171
QUuid m_uuid
Definition element.h:251
@ Type
Definition element.h:95
QList< QPair< Terminal *, Terminal * > > AlignedFreeTerminals() const
Element::AlignedFreeTerminals.
Definition element.cpp:1298
void textRemovedFromGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
QList< QPointF > plcTablePositions() const
Positions where the PLC IO table is drawn (from the .elmt file).
Definition element.h:271
QString m_prefix
Definition element.h:278
virtual void unlinkElement(Element *)
Definition element.h:195
bool isFree() const
Definition element.h:286
void drawPlcTable(QPainter *painter)
Element::drawPlcTable Draw the PLC table directly from in-memory ElementData. This overlays the stale...
Definition element.cpp:1808
kind m_link_type
Definition element.h:252
bool m_mouse_over
Definition element.h:277
QList< DynamicElementTextItem * > dynamicTextItems() const
Element::dynamicTextItems.
Definition element.cpp:1133
QPoint setHotspot(QPoint)
Definition element.cpp:310
virtual void initLink(QETProject *)
Element::initLink Initialise the link between this element and other elements. This method can be cal...
Definition element.cpp:1326
QSize size() const
Definition element.cpp:300
DiagramContext kindInformations() const
kindInformations
Definition element.h:136
Element(const ElementsLocation &location, QGraphicsItem *=nullptr, int *state=nullptr, Element::kind link_type=Element::Simple)
Element::Element.
Definition element.cpp:101
ElementData m_data
Definition element.h:264
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Element::mouseMoveEvent.
Definition element.cpp:1589
QList< QPointF > m_plc_table_positions
Definition element.h:265
QList< Element * > linkedElements()
Element::linkedElements.
Definition element.h:315
void removeDynamicTextItem(DynamicElementTextItem *deti)
Element::removeDynamicTextItem Remove deti, no matter if is a child of this element or a child of a g...
Definition element.cpp:1104
int type() const override
Definition element.h:96
kind
The kind enum Used to know the kind of this element (master, slave, report ect...).
Definition element.h:55
@ Simple
Definition element.h:56
@ NextReport
Definition element.h:57
@ Thumbnail
Definition element.h:63
@ AllReport
Definition element.h:59
@ ConductorDefinition
Definition element.h:64
@ Master
Definition element.h:60
@ Slave
Definition element.h:61
@ Terminale
Definition element.h:62
@ PreviousReport
Definition element.h:58
void textAdded(DynamicElementTextItem *deti)
void elementInfoChange(DiagramContext old_info, DiagramContext new_info)
QList< ElementTextItemGroup * > m_texts_group
Definition element.h:280
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
Definition element.cpp:1635
QString m_F_str
Definition element.h:258
bool m_freeze_label
Definition element.h:257
QPicture m_picture
Definition element.h:262
virtual kind linkType() const
linkType use elementData function instead
Definition element.h:207
QUuid uuid() const
Element::uuid.
Definition element.h:308
QString name() const override
Element::name.
Definition element.cpp:1772
autonum::sequentialNumbers m_autoNum_seq
Definition element.h:256
bool parseElement(const QDomElement &dom)
Element::parseElement Parse the element of the xml description of this element.
Definition element.cpp:567
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Element::mouseReleaseEvent.
Definition element.cpp:1602
QHash< Element *, int > m_group_index_map
Maps linked elements to their group index (for slave->master links).
Definition element.h:250
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *)
Definition element.cpp:348
void setGroupIndexForElement(Element *elmt, int index)
Element::setGroupIndexForElement Sets the group index for a linked element.
Definition element.cpp:1401
bool parseInput(const QDomElement &dom_element)
Element::parseInput Parse the input (old text field) the parsed input are converted to dynamic text f...
Definition element.cpp:583
autonum::sequentialNumbers sequenceStruct() const
Definition element.h:142
virtual void unlinkAllElements()
Definition element.h:194
void textAddedToGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
void setPrefix(QString)
Element::setPrefix set Element Prefix.
Definition element.cpp:1721
void displayHelpLine(bool b=true)
Element::displayHelpLine Display the help line of each terminal if b is true.
Definition element.cpp:214
void setSize(int, int)
Element::setSize Define the size of the element. The size must be a multiple of 10....
Definition element.cpp:288
void addDynamicTextItem(DynamicElementTextItem *deti=nullptr)
Element::addDynamiqueTextItem Add deti as a dynamic text item of this element, deti is reparented to ...
Definition element.cpp:1081
virtual bool fromXml(QDomElement &, QHash< int, Terminal * > &)
Element::fromXml Import the parameters of this element from a xml document. When call this function e...
Definition element.cpp:723
QPoint hotspot_coord
Definition element.h:276
Element(const Element &)
QList< Terminal * > terminals() const
Element::terminals.
Definition element.cpp:160
void removeTextGroup(ElementTextItemGroup *group)
Element::removeTextGroup Remove the text group group from this element, and set the parent of group t...
Definition element.cpp:1196
QList< ElementTextItemGroup * > textGroups() const
Element::textGroups.
Definition element.cpp:1238
QList< Terminal * > m_terminals
Definition element.h:261
QString getPrefix() const
Element::getPrefix get Element Prefix.
Definition element.cpp:1712
QList< DynamicElementTextItem * > m_dynamic_text_list
Definition element.h:279
QPixmap pixmap()
Element::pixmap.
Definition element.cpp:336
friend class DynamicElementTextItem
Definition element.h:46
friend class DiagramEventAddElement
Definition element.h:45
void textsGroupAdded(ElementTextItemGroup *group)
QString actualLabel()
Element::actualLabel Always return the current label to be displayed. This function is useful when la...
Definition element.cpp:1754
bool addTextToGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
Element::addTextToGroup Add the text text to the group group; If group isn't owned by this element re...
Definition element.cpp:1250
DiagramContext m_kind_informations
Definition element.h:255
void freezeLabel(bool freeze)
Element::freezeLabel Freeze this element label.
Definition element.cpp:1730
QList< Element * > connected_elements
Definition element.h:248
void freezeNewAddedElement()
Element::freezeNewAddedElement Freeze this label if needed.
Definition element.cpp:1739
bool m_must_highlight
Definition element.h:274
void textsGroupAboutToBeRemoved(ElementTextItemGroup *group)
ElementData elementData() const
Element::elementData.
Definition element.cpp:1457
void setElementData(ElementData data)
Element::setElementData Set new data for this element. If m_information of data is changed,...
Definition element.cpp:1468
ElementsLocation m_location
Definition element.h:260
ElementTextItemGroup * addTextGroup(const QString &name)
Element::addTextGroup Create and add an element text item group to this element. If this element alre...
Definition element.cpp:1146
QSize dimensions
Definition element.h:275
void editProperty() override
Definition element.cpp:182
virtual QDomElement toXml(QDomDocument &, QHash< Terminal *, int > &) const
Element::toXml Allows to export the element in XML.
Definition element.cpp:912
DiagramContext elementInformations() const
Definition element.h:123
static bool valideXml(QDomElement &)
Definition element.cpp:692
virtual void setHighlighted(bool)
Definition element.cpp:203
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
Element::paint.
Definition element.cpp:225
QList< LinkInfo > tmp_uuids_link
Definition element.h:249
bool isFreezeLabel() const
Definition element.h:150
QPoint hotspot() const
Definition element.cpp:327
bool removeTextFromGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
Element::removeTextFromGroup Remove the text text from the group group, en reparent text to this elem...
Definition element.cpp:1273
int orientation() const
Definition element.h:299
ElementTextItemGroup * textGroup(const QString &name) const
Element::textGroup.
Definition element.cpp:1225
virtual void setElementInformations(DiagramContext dc)
Element::setElementInformations Set new information for this element. If new information is different...
Definition element.cpp:1416
virtual void linkToElement(Element *)
Definition element.h:193
The ElementTextItemGroup class This class represent a group of element text Texts in the group can be...
Definition elementtextitemgroup.h:36
The ElementsLocation class This class represents the location, the location of an element or of a cat...
Definition elementslocation.h:47
Definition qetproject.h:77
QetGraphicsItem(QGraphicsItem *parent=nullptr)
Definition qetgraphicsitem.cpp:44
QET::GraphicsItemState state() const
QetGraphicsItem::state.
Definition qetgraphicsitem.cpp:99
The Terminal class This class represents a terminal of an electrical element, i.e....
Definition terminal.h:37
Definition assignvariables.h:35
bool comparPos(const Element *elmt1, const Element *elmt2)
comparPos Compare position of the two elements. Compare 3 points: 1 folio - 2 row - 3 line returns a ...
Definition element.cpp:1563
qreal correctAngle(const qreal &, const bool &positive=false)
Definition qet.cpp:622