QElectroTech  0.70
element.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 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 "qet.h"
22 #include "qetgraphicsitem.h"
23 #include "diagramcontext.h"
24 #include "assignvariables.h"
25 #include "elementslocation.h"
26 #include "nameslist.h"
27 
28 #include <algorithm>
29 #include <QPicture>
30 
31 class QETProject;
32 class Terminal;
33 class Conductor;
36 
40 class Element : public QetGraphicsItem
41 {
42  friend class DiagramEventAddElement;
43 
44  Q_OBJECT
45  public:
50  enum kind {Simple = 1,
53  AllReport = 6,
54  Master = 8,
55  Slave = 16,
56  Terminale = 32};
57 
58  Element(const ElementsLocation &location, QGraphicsItem * = nullptr, int *state = nullptr, Element::kind link_type = Element::Simple);
59  ~Element() override;
60  private:
61  Element(const Element &);
62 
63  // attributes
64  public:
69  enum { Type = UserType + 1000 };
70  int type() const override { return Type; }
71 
72  signals:
73  void linkedElementChanged(); //This signal is emited when the linked elements with this element change
74  void elementInfoChange(DiagramContext old_info, DiagramContext new_info);
81 
82 
83  public:
84  QList<Terminal *> terminals() const;
85  QList<Conductor *> conductors() const;
86  QList <QPair <Terminal *, Terminal *> > AlignedFreeTerminals () const;
87 
88  //METHODS related to information
90  virtual void setElementInformations (DiagramContext dc);
91  DiagramContext kindInformations () const {return m_kind_informations;} //@kind_information_ is used to store more information
92  //about the herited class like contactelement for know
93  // kind of contact (simple tempo) or number of contact show by the element.
94 
97  void setUpFormula(bool code_letter = true);
98  void setPrefix(QString);
99  QString getPrefix() const;
100  void freezeLabel(bool freeze);
101  bool isFreezeLabel() const {return m_freeze_label;}
102  void freezeNewAddedElement();
103 
104  QString name() const override;
105  ElementsLocation location() const;
106  virtual void setHighlighted(bool);
107  void displayHelpLine(bool b = true);
108  QSize size() const;
109  QPixmap pixmap();
110  QPoint setHotspot(QPoint);
111  QPoint hotspot() const;
112  void editProperty() override;
113  static bool valideXml(QDomElement &);
114  virtual bool fromXml(QDomElement &, QHash<int, Terminal *> &, bool = false);
115  virtual QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
116  QUuid uuid() const;
117  int orientation() const;
118 
119  //METHODS related to texts
120  void addDynamicTextItem(DynamicElementTextItem *deti = nullptr);
122  QList<DynamicElementTextItem *> dynamicTextItems() const;
123  ElementTextItemGroup *addTextGroup(const QString &name);
124  void addTextGroup(ElementTextItemGroup *group);
126  ElementTextItemGroup *textGroup(const QString &name) const;
127  QList<ElementTextItemGroup *> textGroups() const;
130 
131  //METHODS related to linked element
132  bool isFree () const;
133  virtual void linkToElement (Element *) {}
134  virtual void unlinkAllElements () {}
135  virtual void unlinkElement (Element *) {}
136  virtual void initLink (QETProject *);
137  QList<Element *> linkedElements ();
138  virtual kind linkType() const {return m_link_type;} // @return the linkable type
139  void newUuid() {m_uuid = QUuid::createUuid();} //create new uuid for this element
140 
141  protected:
142  void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
143  void setSize(int, int);
144 
145  private:
146  void drawSelection(QPainter *, const QStyleOptionGraphicsItem *);
147  void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *);
148  bool buildFromXml(const QDomElement &, int * = nullptr);
149  bool parseElement(const QDomElement &dom);
150  bool parseInput(const QDomElement &dom_element);
151  DynamicElementTextItem *parseDynamicText(const QDomElement &dom_element);
152  Terminal *parseTerminal(const QDomElement &dom_element);
153 
154  //Reimplemented from QGraphicsItem
155  public:
156  void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
157  QRectF boundingRect() const override;
158  protected:
159  void mouseMoveEvent ( QGraphicsSceneMouseEvent *event ) override;
160  void mouseReleaseEvent ( QGraphicsSceneMouseEvent *event ) override;
161  void hoverEnterEvent ( QGraphicsSceneHoverEvent * ) override;
162  void hoverLeaveEvent ( QGraphicsSceneHoverEvent * ) override;
163 
164  protected:
165  // @m_converted_text_from_description, when a element is created from his description, the old element text item (tagged as 'input' in the xml)
166  // are converted to dynamic text field, the QPointF is the original position of the text item, because the origin transformation point of text item
167  // and dynamic text item are not the same, so we must to keep a track of this value, to be use in the function element::fromXml
168  QHash <DynamicElementTextItem *, QPointF> m_converted_text_from_xml_description;
169 
170  //ATTRIBUTES related to linked element
171  QList <Element *> connected_elements;
172  QList <QUuid> tmp_uuids_link;
173  QUuid m_uuid;
175 
176  //ATTRIBUTES related to informations
179  bool m_freeze_label = false;
180  QString m_F_str;
181 
184  QList <Terminal *> m_terminals;
185  const QPicture m_picture;
186  const QPicture m_low_zoom_picture;
187 
188  private:
189  bool m_must_highlight = false;
190  QSize dimensions;
192  bool m_mouse_over = false;
193  QString m_prefix;
194  QList <DynamicElementTextItem *> m_dynamic_text_list;
195  QList <ElementTextItemGroup *> m_texts_group;
196 
197 };
198 
199 bool comparPos(const Element * elmt1, const Element * elmt2);
200 
201 inline bool Element::isFree() const {
202  return (connected_elements.isEmpty());
203 }
204 
213 inline int Element::orientation() const {
214  return(QET::correctAngle(rotation())/90);
215 }
216 
221 inline QUuid Element::uuid() const {
222  return m_uuid;
223 }
224 
229 inline QList <Element *> Element::linkedElements() {
230  std::sort(connected_elements.begin(), connected_elements.end(), comparPos);
231  return connected_elements;
232 }
233 
234 #endif
QUuid m_uuid
Definition: element.h:173
void removeTextGroup(ElementTextItemGroup *group)
Element::removeTextGroup Remove the text group from this element, and set the parent of group to 0...
Definition: element.cpp:1257
QList< QPair< Terminal *, Terminal * > > AlignedFreeTerminals() const
Element::AlignedFreeTerminals.
Definition: element.cpp:1355
virtual void linkToElement(Element *)
Definition: element.h:133
QSize size() const
Definition: element.cpp:229
virtual kind linkType() const
Definition: element.h:138
ElementsLocation location() const
Definition: element.cpp:1569
void freezeNewAddedElement()
Element::freezeNewAddedElement Freeze this label if needed.
Definition: element.cpp:1554
QList< Element * > linkedElements()
Element::linkedElements.
Definition: element.h:229
QList< Element * > connected_elements
Definition: element.h:171
Element(const ElementsLocation &location, QGraphicsItem *=nullptr, int *state=nullptr, Element::kind link_type=Element::Simple)
Element::Element.
Definition: element.cpp:71
bool isFree() const
Definition: element.h:201
virtual void unlinkElement(Element *)
Definition: element.h:135
The DynamicElementTextItem class This class provide a simple text field of element who can be added o...
bool m_must_highlight
Definition: element.h:189
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override
Definition: element.cpp:1461
kind
The kind enum Used to know the kind of this element (master, slave, report ect...) ...
Definition: element.h:50
autonum::sequentialNumbers m_autoNum_seq
Definition: element.h:178
void textsGroupAdded(ElementTextItemGroup *group)
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:500
QRectF boundingRect() const override
Definition: element.cpp:205
NamesList m_names
Definition: element.h:183
~Element() override
Element::~Element.
Definition: element.cpp:114
DiagramContext elementInformations() const
Definition: element.h:89
QUuid uuid() const
Element::uuid.
Definition: element.h:221
QPoint setHotspot(QPoint)
Definition: element.cpp:238
autonum::sequentialNumbers & rSequenceStruct()
Definition: element.h:96
bool m_mouse_over
Definition: element.h:192
void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *)
Definition: element.cpp:315
autonum::sequentialNumbers sequenceStruct() const
Definition: element.h:95
int type() const override
Definition: element.h:70
virtual void setHighlighted(bool)
Definition: element.cpp:162
QSize dimensions
Definition: element.h:190
void setUpFormula(bool code_letter=true)
Element::setUpFormula Set up the formula used to create the label of this element.
Definition: element.cpp:1494
const QPicture m_low_zoom_picture
Definition: element.h:186
Terminal * parseTerminal(const QDomElement &dom_element)
Definition: element.cpp:565
QString name() const override
Element::name.
Definition: element.cpp:1565
void linkedElementChanged()
const QPicture m_picture
Definition: element.h:185
bool buildFromXml(const QDomElement &, int *=nullptr)
Element::buildFromXml Build this element from an xml description.
Definition: element.cpp:350
QList< Conductor * > conductors() const
Element::conductors.
Definition: element.cpp:134
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
Element::paint.
Definition: element.cpp:184
void newUuid()
Definition: element.h:139
ElementTextItemGroup * textGroup(const QString &name) const
Definition: element.cpp:1285
DiagramContext m_element_informations
Definition: element.h:177
void setSize(int, int)
Element::setSize Define the size of the element. The size must be a multiple of 10. If not, the dimensions indicated will be arrrondies to higher tens.
Definition: element.cpp:217
virtual QDomElement toXml(QDomDocument &, QHash< Terminal *, int > &) const
Definition: element.cpp:1021
QList< Terminal * > terminals() const
Element::terminals.
Definition: element.cpp:124
void textsGroupAboutToBeRemoved(ElementTextItemGroup *group)
void textAddedToGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
QET::GraphicsItemState state() const
QetGraphicsItem::state.
void addDynamicTextItem(DynamicElementTextItem *deti=nullptr)
Element::addDynamiqueTextItem Add as a dynamic text item of this element, is reparented to this If ...
Definition: element.cpp:1146
void removeDynamicTextItem(DynamicElementTextItem *deti)
Element::removeDynamicTextItem Remove , no matter if is a child of this element or a child of a group...
Definition: element.cpp:1168
qreal correctAngle(const qreal &)
Definition: qet.cpp:505
QList< ElementTextItemGroup * > m_texts_group
Definition: element.h:195
bool parseElement(const QDomElement &dom)
Element::parseElement Parse the element of the xml description of this element.
Definition: element.cpp:484
QList< QUuid > tmp_uuids_link
Definition: element.h:172
virtual void initLink(QETProject *)
Element::initLink Initialise the link between this element and other elements. This method can be cal...
Definition: element.cpp:1381
virtual bool fromXml(QDomElement &, QHash< int, Terminal *> &, bool=false)
Element::fromXml Import the parameters of this element from a xml document. When call this function e...
Definition: element.cpp:647
DynamicElementTextItem * parseDynamicText(const QDomElement &dom_element)
Element::parseDynamicText Create the dynamic text field describ in .
Definition: element.cpp:550
QPixmap pixmap()
Element::pixmap.
Definition: element.cpp:262
virtual void unlinkAllElements()
Definition: element.h:134
bool removeTextFromGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
Element::removeTextFromGroup Remove the text from the group , en reparent to this element...
Definition: element.cpp:1331
void editProperty() override
Definition: element.cpp:145
bool isFreezeLabel() const
Definition: element.h:101
QPoint hotspot() const
Definition: element.cpp:254
virtual void setElementInformations(DiagramContext dc)
Element::setElementInformations Set new information for this element. If new information is different...
Definition: element.cpp:1399
QList< Terminal * > m_terminals
Definition: element.h:184
ElementTextItemGroup * addTextGroup(const QString &name)
Definition: element.cpp:1209
void textRemovedFromGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
kind m_link_type
Definition: element.h:174
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Element::mouseMoveEvent.
Definition: element.cpp:1433
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
Definition: element.cpp:1478
The ElementTextItemGroup class This class represent a group of element text Texts in the group can be...
bool m_freeze_label
Definition: element.h:179
QString m_prefix
Definition: element.h:193
void elementInfoChange(DiagramContext old_info, DiagramContext new_info)
DiagramContext m_kind_informations
Definition: element.h:177
void drawSelection(QPainter *, const QStyleOptionGraphicsItem *)
Definition: element.cpp:292
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:1414
QPoint hotspot_coord
Definition: element.h:191
int orientation() const
Definition: element.h:213
void setPrefix(QString)
Element::setPrefix set Element Prefix.
Definition: element.cpp:1537
static bool valideXml(QDomElement &)
Definition: element.cpp:614
The DiagramEventAddElement class This diagram event add a new element, for each left click button at ...
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *)
Definition: element.cpp:273
ElementsLocation m_location
Definition: element.h:182
QList< DynamicElementTextItem * > m_dynamic_text_list
Definition: element.h:194
void textAdded(DynamicElementTextItem *deti)
QString m_F_str
Definition: element.h:180
void textRemoved(DynamicElementTextItem *deti)
DiagramContext kindInformations() const
Definition: element.h:91
QString getPrefix() const
Element::getPrefix get Element Prefix.
Definition: element.cpp:1529
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Element::mouseReleaseEvent.
Definition: element.cpp:1446
void freezeLabel(bool freeze)
Element::freezeLabel Freeze this element label.
Definition: element.cpp:1545
QHash< DynamicElementTextItem *, QPointF > m_converted_text_from_xml_description
Definition: element.h:168
bool addTextToGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
Element::addTextToGroup Add the text to the group ; If isn&#39;t owned by this element return false...
Definition: element.cpp:1310
QList< DynamicElementTextItem * > dynamicTextItems() const
Element::dynamicTextItems.
Definition: element.cpp:1197
void displayHelpLine(bool b=true)
Element::displayHelpLine Display the help line of each terminal if b is true.
Definition: element.cpp:172
QList< ElementTextItemGroup * > textGroups() const
Element::textGroups.
Definition: element.cpp:1298