QElectroTech  0.70
terminal.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 TERMINAL_H
19 #define TERMINAL_H
20 #include <QtWidgets>
21 #include <QtXml>
22 #include "qet.h"
23 class Conductor;
24 class Diagram;
25 class Element;
30 class Terminal : public QGraphicsObject
31 {
32  Q_OBJECT
33 
34  signals:
35  void conductorWasAdded(Conductor *conductor);
36  void conductorWasRemoved(Conductor *conductor);
37 
38  // constructors, destructor
39  public:
40  Terminal(QPointF, Qet::Orientation, Element * = nullptr);
41  Terminal(qreal, qreal, Qet::Orientation, Element * = nullptr);
42  Terminal(QPointF, Qet::Orientation, QString number, QString name, bool hiddenName, Element * = nullptr);
43  ~Terminal() override;
44 
45  private:
46  Terminal(const Terminal &);
47 
48  // methods
49  public:
50  //Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a Terminal
51  //@return the QGraphicsItem type
52  int type() const override { return Type; }
53 
54  void paint (QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
55  void drawHelpLine (bool draw = true);
56  QLineF HelpLine () const;
57  QRectF boundingRect () const override;
58 
59  // methods to manage conductors attached to the terminal
60  Terminal* alignedWithTerminal () const;
61  bool addConductor (Conductor *conductor);
62  void removeConductor (Conductor *conductor);
63  int conductorsCount () const;
64  Diagram *diagram () const;
65  Element *parentElement () const;
66 
67  QList<Conductor *> conductors() const;
69  QPointF dockConductor() const;
70  QString number() const;
71  QString name() const;
72  void setNumber(QString number);
73  void setName(QString name, bool hiddenName);
74  void updateConductor();
75  bool isLinkedTo(Terminal *);
76  bool canBeLinkedTo(Terminal *);
77 
78  // methods related to XML import/export
79  static bool valideXml(QDomElement &);
80  bool fromXml (QDomElement &);
81  QDomElement toXml (QDomDocument &) const;
82 
83  protected:
84  // methods related to events management
85  void hoverEnterEvent (QGraphicsSceneHoverEvent *) override;
86  void hoverMoveEvent (QGraphicsSceneHoverEvent *) override;
87  void hoverLeaveEvent (QGraphicsSceneHoverEvent *) override;
88  void mousePressEvent (QGraphicsSceneMouseEvent *) override;
89  void mouseMoveEvent (QGraphicsSceneMouseEvent *) override;
90  void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
91 
92  // attributes
93  public:
94  enum { Type = UserType + 1002 };
95 
96  static const qreal terminalSize;
97  static const qreal Z;
98  // Various static colors used for hover effects
100  static QColor neutralColor;
102  static QColor allowedColor;
104  static QColor warningColor;
106  static QColor forbiddenColor;
107 
108  private:
110  QGraphicsLineItem *m_help_line;
111  QGraphicsLineItem *m_help_line_a;
112 
118  QPointF dock_elmt_;
122  QList<Conductor *> conductors_;
126  QRectF *br_;
130  bool hovered_;
136  QString name_terminal_;
138 
139  private:
140  void init(QPointF, Qet::Orientation, QString number, QString name, bool hiddenName);
141 };
142 
146 inline int Terminal::conductorsCount() const {
147  return(conductors_.size());
148 }
149 
154 inline QPointF Terminal::dockConductor() const {
155  return(mapToScene(dock_conductor_));
156 }
157 
161 inline QString Terminal::number() const {
162  return(number_terminal_);
163 }
164 
168 inline QString Terminal::name() const {
169  return(name_terminal_);
170 }
171 
172 QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal, const bool all_diagram = true);
173 
174 #endif
bool m_draw_help_line
Definition: terminal.h:109
int type() const override
Definition: terminal.h:52
static QColor forbiddenColor
color for forbidden actions
Definition: terminal.h:106
QList< Conductor * > conductors() const
Definition: terminal.cpp:677
static QColor allowedColor
color for legal actions
Definition: terminal.h:102
QPointF dock_elmt_
docking point for parent element
Definition: terminal.h:118
bool addConductor(Conductor *conductor)
Terminal::addConductor Add a conductor to this terminal.
Definition: terminal.cpp:191
bool isLinkedTo(Terminal *)
Definition: terminal.cpp:647
QColor hovered_color_
Color used for the hover effect.
Definition: terminal.h:132
int conductorsCount() const
Definition: terminal.h:146
Terminal(QPointF, Qet::Orientation, Element *=nullptr)
Definition: terminal.cpp:84
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
Terminal::mouseReleaseEvent.
Definition: terminal.cpp:564
void mousePressEvent(QGraphicsSceneMouseEvent *) override
Definition: terminal.cpp:494
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override
Definition: terminal.cpp:471
static const qreal terminalSize
Definition: terminal.h:96
Terminal * alignedWithTerminal() const
Terminal::alignedWithTerminal If this terminal is aligned with an other terminal and is orientation i...
Definition: terminal.cpp:413
void init(QPointF, Qet::Orientation, QString number, QString name, bool hiddenName)
Definition: terminal.cpp:42
static const qreal Z
Definition: terminal.h:97
void conductorWasAdded(Conductor *conductor)
QDomElement toXml(QDomDocument &) const
Definition: terminal.cpp:686
QString number_terminal_
Number of Terminal.
Definition: terminal.h:134
static bool valideXml(QDomElement &)
Definition: terminal.cpp:702
Element * parentElement() const
Definition: terminal.cpp:759
QString number() const
Definition: terminal.h:161
bool hovered_
Whether the mouse pointer is hovering the terminal.
Definition: terminal.h:130
QRectF boundingRect() const override
Definition: terminal.cpp:391
void setNumber(QString number)
Terminal::setNumber.
Definition: terminal.cpp:172
QList< Terminal * > relatedPotentialTerminal(const Terminal *terminal, const bool all_diagram=true)
Conductor::relatedPotentialTerminal Return terminal at the same potential from the same parent elemen...
Definition: terminal.cpp:774
QLineF HelpLine() const
Terminal::HelpLine.
Definition: terminal.cpp:360
Terminal * previous_terminal_
Last terminal seen through an attached conductor.
Definition: terminal.h:128
QRectF * br_
Definition: terminal.h:126
QPointF dockConductor() const
Definition: terminal.h:154
Qet::Orientation ori_
terminal orientation
Definition: terminal.h:120
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
Definition: terminal.cpp:229
bool canBeLinkedTo(Terminal *)
Terminal::canBeLinkedTo.
Definition: terminal.cpp:666
bool name_terminal_hidden
Definition: terminal.h:137
QGraphicsLineItem * m_help_line_a
Definition: terminal.h:111
static QColor neutralColor
default color
Definition: terminal.h:100
QGraphicsLineItem * m_help_line
Definition: terminal.h:110
QString name() const
Definition: terminal.h:168
QList< Conductor * > conductors_
List of conductors attached to the terminal.
Definition: terminal.h:122
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
Definition: terminal.cpp:485
~Terminal() override
Definition: terminal.cpp:140
void updateConductor()
Terminal::updateConductor Update the path of conductor docked to this terminal.
Definition: terminal.cpp:638
bool fromXml(QDomElement &)
Definition: terminal.cpp:738
void removeConductor(Conductor *conductor)
Terminal::removeConductor Remove a conductor from this terminal.
Definition: terminal.cpp:215
Element * parent_element_
Parent electrical element.
Definition: terminal.h:114
void conductorWasRemoved(Conductor *conductor)
QPointF dock_conductor_
docking point for conductors
Definition: terminal.h:116
QString name_terminal_
Name of Terminal.
Definition: terminal.h:136
Qet::Orientation orientation() const
Definition: terminal.cpp:152
static QColor warningColor
color for allowed but fuzzy or not recommended actions
Definition: terminal.h:104
void mouseMoveEvent(QGraphicsSceneMouseEvent *) override
Definition: terminal.cpp:507
void setName(QString name, bool hiddenName)
Terminal::setName.
Definition: terminal.cpp:180
Diagram * diagram() const
Definition: terminal.cpp:752
void drawHelpLine(bool draw=true)
Terminal::drawHelpLine.
Definition: terminal.cpp:333
void hoverMoveEvent(QGraphicsSceneHoverEvent *) override
Definition: terminal.cpp:479
Orientation
Orientation (used for electrical elements and their terminals)
Definition: qet.h:204