QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
element.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2024 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
21#include "../ElementsCollection/elementslocation.h"
22#include "../NameList/nameslist.h"
23#include "../autoNum/assignvariables.h"
24#include "../diagramcontext.h"
25#include "../qet.h"
26#include "qetgraphicsitem.h"
27#include "../properties/elementdata.h"
28
29#include <QHash>
30#include <QPicture>
31#include <algorithm>
32
33class QETProject;
34class Terminal;
35class Conductor;
38
43{
45
46 Q_OBJECT
47 public:
62
64 QGraphicsItem * = nullptr,
65 int *state = nullptr,
66 Element::kind link_type = Element::Simple);
67 ~Element() override;
68 private:
69 Element(const Element &);
70
71 // attributes
72 public:
78 enum { Type = UserType + 1000 };
79 int type() const override { return Type; }
80
81 signals:
82 void linkedElementChanged(); //This signal is emitted when the linked elements with this element change
84 DiagramContext old_info,
85 DiagramContext new_info);
96
97
98 public:
99 QList<Terminal *> terminals() const;
100 QList<Conductor *> conductors() const;
101 QList<QPair<Terminal *,Terminal *>> AlignedFreeTerminals() const;
102
103 //METHODS related to information
106 virtual void setElementInformations(DiagramContext dc);
107
108 ElementData elementData() const;
109 void setElementData (ElementData data);
110
119 //@kind_information_ is used to store more information
120 //about the herited class like contactelement for know
121 // kind of contact (simple tempo) or number of contact show by the element.
122
127 void setUpFormula(bool code_letter = true);
128 void setPrefix(QString);
129 QString getPrefix() const;
130 void freezeLabel(bool freeze);
131 bool isFreezeLabel() const {return m_freeze_label;}
133 QString actualLabel();
134
135 QString name() const override;
137 virtual void setHighlighted(bool);
138 void displayHelpLine(bool b = true);
139 QSize size() const;
140 QPixmap pixmap();
141 QPoint setHotspot(QPoint);
142 QPoint hotspot() const;
143 void editProperty() override;
144 static bool valideXml(QDomElement &);
145 virtual bool fromXml(
146 QDomElement &,
147 QHash<int,
148 Terminal *> &);
149 virtual QDomElement toXml(
150 QDomDocument &,
151 QHash<Terminal *,
152 int> &) const;
153 QUuid uuid() const;
154 int orientation() const;
155
156 //METHODS related to texts
157 void addDynamicTextItem(DynamicElementTextItem *deti = nullptr);
159 QList<DynamicElementTextItem *> dynamicTextItems() const;
160 ElementTextItemGroup *addTextGroup(const QString &name);
163 ElementTextItemGroup *textGroup(const QString &name) const;
164 QList<ElementTextItemGroup *> textGroups() const;
165 bool addTextToGroup(
167 ElementTextItemGroup *group);
170 ElementTextItemGroup *group);
171
172 //METHODS related to linked element
173 bool isFree() const;
174 virtual void linkToElement(Element *) {}
175 virtual void unlinkAllElements() {}
176 virtual void unlinkElement(Element *) {}
177 virtual void initLink(QETProject *);
178 QList<Element *> linkedElements ();
179
185 virtual kind linkType() const {return m_link_type;} // return the linkable type
191 QString linkTypeToString() const;
192
193 void newUuid() {m_uuid = QUuid::createUuid();} //create new uuid for this element
194
195 protected:
196 void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
197 void setSize(int, int);
198
199 private:
200 void drawSelection(
201 QPainter *,
202 const QStyleOptionGraphicsItem *);
203 void drawHighlight(
204 QPainter *,
205 const QStyleOptionGraphicsItem *);
206 bool buildFromXml(const QDomElement &, int * = nullptr);
207 bool parseElement(const QDomElement &dom);
208 bool parseInput(const QDomElement &dom_element);
210 const QDomElement &dom_element);
211 Terminal *parseTerminal(const QDomElement &dom_element);
212
213 //Reimplemented from QGraphicsItem
214 public:
215 void paint(
216 QPainter *,
217 const QStyleOptionGraphicsItem *,
218 QWidget *) override;
219 QRectF boundingRect() const override;
220 protected:
221 void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
223 QGraphicsSceneMouseEvent *event) override;
224 void hoverEnterEvent(QGraphicsSceneHoverEvent *) override;
225 void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override;
226
227 protected:
228 //ATTRIBUTES related to linked element
229 QList <Element *> connected_elements;
230 QList <QUuid> tmp_uuids_link;
231 QUuid m_uuid;
233
234 //ATTRIBUTES related to informations
237 bool m_freeze_label = false;
238 QString m_F_str;
239
241 QList <Terminal *> m_terminals;
242 const QPicture m_picture;
243 const QPicture m_low_zoom_picture;
245
246 private:
247 bool m_must_highlight = false;
250 bool m_mouse_over = false;
251 QString m_prefix;
252 QList <DynamicElementTextItem *> m_dynamic_text_list;
253 QList <ElementTextItemGroup *> m_texts_group;
254
255};
256
257bool comparPos(const Element * elmt1, const Element * elmt2);
258
259inline bool Element::isFree() const
260{
261 return (connected_elements.isEmpty());
262}
263
272inline int Element::orientation() const
273{
274 return(QET::correctAngle(rotation())/90);
275}
276
281inline QUuid Element::uuid() const
282{return m_uuid;}
283
288inline QList <Element *> Element::linkedElements()
289{
290 std::sort(
291 connected_elements.begin(),
292 connected_elements.end(),
293 comparPos);
294 return connected_elements;
295}
296
297#endif
Definition conductor.h:43
Definition diagramcontext.h:57
The DiagramEventAddElement class This diagram event add a new element, for each left click button at ...
Definition diagrameventaddelement.h:33
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:32
DiagramContext m_informations
Definition elementdata.h:145
Definition element.h:43
QList< QUuid > tmp_uuids_link
Definition element.h:230
ElementsLocation location() const
Definition element.cpp:1593
void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *)
Definition element.cpp:377
QRectF boundingRect() const override
Definition element.cpp:253
void textRemoved(DynamicElementTextItem *deti)
QString linkTypeToString() const
linkTypeToString use elementData function instead
Definition element.cpp:1312
~Element() override
Element::~Element.
Definition element.cpp:134
void newUuid()
Definition element.h:193
Terminal * parseTerminal(const QDomElement &dom_element)
Element::parseTerminal Parse partTerminal from xml structure.
Definition element.cpp:653
bool buildFromXml(const QDomElement &, int *=nullptr)
Element::buildFromXml Build this element from an xml description.
Definition element.cpp:418
autonum::sequentialNumbers & rSequenceStruct()
Definition element.h:125
void linkedElementChanged()
DynamicElementTextItem * parseDynamicText(const QDomElement &dom_element)
Element::parseDynamicText Create the dynamic text field described in dom_element.
Definition element.cpp:631
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override
Definition element.cpp:1447
QList< Conductor * > conductors() const
Element::conductors.
Definition element.cpp:155
QUuid m_uuid
Definition element.h:231
QList< QPair< Terminal *, Terminal * > > AlignedFreeTerminals() const
Element::AlignedFreeTerminals.
Definition element.cpp:1266
void textRemovedFromGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
QString m_prefix
Definition element.h:251
virtual void unlinkElement(Element *)
Definition element.h:176
bool isFree() const
Definition element.h:259
kind m_link_type
Definition element.h:232
bool m_mouse_over
Definition element.h:250
QList< DynamicElementTextItem * > dynamicTextItems() const
Element::dynamicTextItems.
Definition element.cpp:1101
QPoint setHotspot(QPoint)
Definition element.cpp:289
const QPicture m_picture
Definition element.h:242
virtual void initLink(QETProject *)
Element::initLink Initialise the link between this element and other elements. This method can be cal...
Definition element.cpp:1294
QSize size() const
Definition element.cpp:279
@ Type
Definition element.h:78
DiagramContext kindInformations() const
kindInformations
Definition element.h:117
ElementData m_data
Definition element.h:244
const QPicture m_low_zoom_picture
Definition element.h:243
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Element::mouseMoveEvent.
Definition element.cpp:1419
QList< Element * > linkedElements()
Element::linkedElements.
Definition element.h:288
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:1072
int type() const override
Definition element.h:79
kind
The kind enum Used to know the kind of this element (master, slave, report ect...)
Definition element.h:53
@ Simple
Definition element.h:54
@ NextReport
Definition element.h:55
@ Thumbnail
Definition element.h:61
@ AllReport
Definition element.h:57
@ Master
Definition element.h:58
@ Slave
Definition element.h:59
@ Terminale
Definition element.h:60
@ PreviousReport
Definition element.h:56
void textAdded(DynamicElementTextItem *deti)
void elementInfoChange(DiagramContext old_info, DiagramContext new_info)
QList< ElementTextItemGroup * > m_texts_group
Definition element.h:253
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
Definition element.cpp:1465
QString m_F_str
Definition element.h:238
bool m_freeze_label
Definition element.h:237
virtual kind linkType() const
linkType use elementData function instead
Definition element.h:185
QUuid uuid() const
Element::uuid.
Definition element.h:281
QString name() const override
Element::name.
Definition element.cpp:1589
autonum::sequentialNumbers m_autoNum_seq
Definition element.h:236
bool parseElement(const QDomElement &dom)
Element::parseElement Parse the element of the xml description of this element.
Definition element.cpp:562
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Element::mouseReleaseEvent.
Definition element.cpp:1432
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *)
Definition element.cpp:327
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:578
autonum::sequentialNumbers sequenceStruct() const
Definition element.h:123
virtual void unlinkAllElements()
Definition element.h:175
void textAddedToGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
void setPrefix(QString)
Element::setPrefix set Element Prefix.
Definition element.cpp:1538
void displayHelpLine(bool b=true)
Element::displayHelpLine Display the help line of each terminal if b is true.
Definition element.cpp:198
void setSize(int, int)
Element::setSize Define the size of the element. The size must be a multiple of 10....
Definition element.cpp:267
void addDynamicTextItem(DynamicElementTextItem *deti=nullptr)
Element::addDynamiqueTextItem Add deti as a dynamic text item of this element, deti is reparented to ...
Definition element.cpp:1049
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:715
QPoint hotspot_coord
Definition element.h:249
Element(const Element &)
QList< Terminal * > terminals() const
Element::terminals.
Definition element.cpp:144
void removeTextGroup(ElementTextItemGroup *group)
Element::removeTextGroup Remove the text group group from this element, and set the parent of group t...
Definition element.cpp:1164
QList< ElementTextItemGroup * > textGroups() const
Element::textGroups.
Definition element.cpp:1206
void drawSelection(QPainter *, const QStyleOptionGraphicsItem *)
Definition element.cpp:349
QList< Terminal * > m_terminals
Definition element.h:241
QString getPrefix() const
Element::getPrefix get Element Prefix.
Definition element.cpp:1529
void setUpFormula(bool code_letter=true)
Element::setUpFormula Set up the formula used to create the label of this element.
Definition element.cpp:1484
QList< DynamicElementTextItem * > m_dynamic_text_list
Definition element.h:252
QPixmap pixmap()
Element::pixmap.
Definition element.cpp:315
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:1571
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:1218
DiagramContext m_kind_informations
Definition element.h:235
void freezeLabel(bool freeze)
Element::freezeLabel Freeze this element label.
Definition element.cpp:1547
QList< Element * > connected_elements
Definition element.h:229
void freezeNewAddedElement()
Element::freezeNewAddedElement Freeze this label if needed.
Definition element.cpp:1556
bool m_must_highlight
Definition element.h:247
void textsGroupAboutToBeRemoved(ElementTextItemGroup *group)
ElementData elementData() const
Element::elementData.
Definition element.cpp:1361
void setElementData(ElementData data)
Element::setElementData Set new data for this element. If m_information of data is changed,...
Definition element.cpp:1372
ElementsLocation m_location
Definition element.h:240
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:1114
QSize dimensions
Definition element.h:248
void editProperty() override
Definition element.cpp:166
virtual QDomElement toXml(QDomDocument &, QHash< Terminal *, int > &) const
Element::toXml Allows to export the element in XML.
Definition element.cpp:897
DiagramContext elementInformations() const
Definition element.h:104
static bool valideXml(QDomElement &)
Definition element.cpp:684
virtual void setHighlighted(bool)
Definition element.cpp:187
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
Element::paint.
Definition element.cpp:209
bool isFreezeLabel() const
Definition element.h:131
QPoint hotspot() const
Definition element.cpp:306
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:1241
int orientation() const
Definition element.h:272
ElementTextItemGroup * textGroup(const QString &name) const
Element::textGroup.
Definition element.cpp:1193
virtual void setElementInformations(DiagramContext dc)
Element::setElementInformations Set new information for this element. If new information is different...
Definition element.cpp:1341
virtual void linkToElement(Element *)
Definition element.h:174
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:62
Definition qetgraphicsitem.h:28
QET::GraphicsItemState state() const
QetGraphicsItem::state.
Definition qetgraphicsitem.cpp:75
The Terminal class This class represents a terminal of an electrical element, i.e....
Definition terminal.h:36
Definition assignvariables.h:34
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:1393
qreal correctAngle(const qreal &, const bool &positive=false)
Definition qet.cpp:582