QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
terminal.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 TERMINAL_H
19#define TERMINAL_H
20#include "../qet.h"
21
22#include <QtWidgets>
23#include <QtXml>
24class Conductor;
25class Diagram;
26class Element;
27class TerminalData;
28
35class Terminal : public QGraphicsObject
36{
37 Q_OBJECT
38
39 signals:
40 void conductorWasAdded(Conductor *conductor);
42
43 // constructors, destructor
44 public:
45 Terminal(TerminalData* data, Element *e = nullptr);
46 ~Terminal() override;
47
48 private:
50
51 // methods
52 public:
59 int type() const override { return Type; }
60
61 void paint(
62 QPainter *painter,
63 const QStyleOptionGraphicsItem *,
64 QWidget *) override;
65 void drawHelpLine (bool draw = true);
66 QLineF HelpLine () const;
67 QRectF boundingRect () const override;
68
69 // methods to manage conductors attached to the terminal
71 bool addConductor (Conductor *conductor);
72 void removeConductor (Conductor *conductor);
73 int conductorsCount () const;
74 Diagram *diagram () const;
75 Element *parentElement () const;
76 QUuid uuid () const;
77 QString name () const;
78
79 QList<Conductor *> conductors() const;
81 QPointF dockConductor() const;
82 void updateConductor();
83 bool isLinkedTo(Terminal *);
84 bool canBeLinkedTo(Terminal *);
85
86 // methods related to XML import/export
87 static bool valideXml(QDomElement &);
88 bool fromXml (QDomElement &);
89 QDomElement toXml (QDomDocument &) const;
90
91 protected:
92 // methods related to events management
93 void hoverEnterEvent (QGraphicsSceneHoverEvent *) override;
94 void hoverMoveEvent (QGraphicsSceneHoverEvent *) override;
95 void hoverLeaveEvent (QGraphicsSceneHoverEvent *) override;
96 void mousePressEvent (QGraphicsSceneMouseEvent *) override;
97 void mouseMoveEvent (QGraphicsSceneMouseEvent *) override;
98 void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
99
100 // attributes
101 public:
102 enum { Type = UserType + 1002 };
103
104 static const qreal terminalSize;
105 static const qreal Z;
106 // Various static colors used for hover effects
108 static QColor neutralColor;
110 static QColor allowedColor;
112 static QColor warningColor;
114 static QColor forbiddenColor;
115
116 private:
117 bool m_draw_help_line{false};
118 QGraphicsLineItem *m_help_line{nullptr};
119 QGraphicsLineItem *m_help_line_a{nullptr};
120
121
123
126 public:
128 QPointF dock_elmt_;
129 private:
131 QList<Conductor *> m_conductors_list;
132 QRectF m_br;
136 bool m_hovered = false;
139
140 private:
141 void init();
142 void init(QPointF pf, Qet::Orientation o);
143};
144
150{
151 return(m_conductors_list.size());
152}
153
154QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal,
155 const bool all_diagram = true);
156
157#endif
Definition conductor.h:43
The Diagram class This class represents an electric diagram. It manages its various child elements,...
Definition diagram.h:56
Definition element.h:43
Orientation
Orientation (used for electrical elements and their terminals)
Definition qet.h:210
The TerminalData class Data of the terminal. Stored in extra class so it can be used by PartTerminal ...
Definition terminaldata.h:37
The Terminal class This class represents a terminal of an electrical element, i.e....
Definition terminal.h:36
int conductorsCount() const
Terminal::conductorsCount.
Definition terminal.h:149
static QColor neutralColor
default color
Definition terminal.h:108
QGraphicsLineItem * m_help_line_a
Definition terminal.h:119
static const qreal terminalSize
Definition terminal.h:104
TerminalData * d
Definition terminal.h:122
bool m_draw_help_line
Definition terminal.h:117
QDomElement toXml(QDomDocument &) const
Terminal::toXml Methode d'export en XML.
Definition terminal.cpp:642
QList< Conductor * > m_conductors_list
List of conductors attached to the terminal.
Definition terminal.h:131
static bool valideXml(QDomElement &)
Terminal::valideXml Permet de savoir si un element XML represente une borne.
Definition terminal.cpp:661
QList< Conductor * > conductors() const
Terminal::conductors.
Definition terminal.cpp:631
void init(QPointF pf, Qet::Orientation o)
void removeConductor(Conductor *conductor)
Terminal::removeConductor Remove a conductor from this terminal.
Definition terminal.cpp:146
QPointF dock_elmt_
docking point for parent element
Definition terminal.h:128
bool addConductor(Conductor *conductor)
Terminal::addConductor Add a conductor to this terminal.
Definition terminal.cpp:119
QString name() const
Definition terminal.cpp:747
static const qreal Z
Definition terminal.h:105
void hoverMoveEvent(QGraphicsSceneHoverEvent *) override
Terminal::hoverMoveEvent Gere les mouvements de la souris sur la zone de la Borne.
Definition terminal.cpp:422
void conductorWasRemoved(Conductor *conductor)
Terminal * alignedWithTerminal() const
Terminal::alignedWithTerminal If this terminal is aligned with an other terminal and is orientation i...
Definition terminal.cpp:353
QColor m_hovered_color
Color used for the hover effect.
Definition terminal.h:138
QRectF m_br
Definition terminal.h:132
Diagram * diagram() const
Terminal::diagram.
Definition terminal.cpp:728
bool isLinkedTo(Terminal *)
Terminal::isLinkedTo.
Definition terminal.cpp:596
Terminal(const Terminal &)
static QColor allowedColor
color for legal actions
Definition terminal.h:110
Qet::Orientation orientation() const
Definition terminal.cpp:97
int type() const override
type Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a Terminal
Definition terminal.h:59
static QColor forbiddenColor
color for forbidden actions
Definition terminal.h:114
QRectF boundingRect() const override
Terminal::boundingRect.
Definition terminal.cpp:342
@ Type
Definition terminal.h:102
Element * parentElement() const
Terminal::parentElement.
Definition terminal.cpp:737
void mousePressEvent(QGraphicsSceneMouseEvent *) override
Terminal::mousePressEvent Gere le fait qu'on enfonce un bouton de la souris sur la Borne.
Definition terminal.cpp:439
void drawHelpLine(bool draw=true)
Terminal::drawHelpLine.
Definition terminal.cpp:283
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
Terminal::mouseReleaseEvent.
Definition terminal.cpp:511
bool fromXml(QDomElement &)
Terminal::fromXml Permet de savoir si un element XML represente cette borne. Attention,...
Definition terminal.cpp:704
void updateConductor()
Terminal::updateConductor Update the path of conductor docked to this terminal.
Definition terminal.cpp:585
QGraphicsLineItem * m_help_line
Definition terminal.h:118
QUuid uuid() const
Definition terminal.cpp:742
QLineF HelpLine() const
Terminal::HelpLine.
Definition terminal.cpp:310
static QColor warningColor
color for allowed but fuzzy or not recommended actions
Definition terminal.h:112
QPointF dockConductor() const
Terminal::dockConductor.
Definition terminal.cpp:718
bool canBeLinkedTo(Terminal *)
Terminal::canBeLinkedTo Checking if the terminal can be linked to other_terminal or not Reasons for n...
Definition terminal.cpp:619
~Terminal() override
Terminal::~Terminal Destruction of the terminal, and also docked conductor.
Definition terminal.cpp:86
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override
Terminal::hoverEnterEvent Gere l'entree de la souris sur la zone de la Borne.
Definition terminal.cpp:412
void init()
Terminal::init Methode privee pour initialiser la borne.
Definition terminal.cpp:44
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
Terminal::hoverLeaveEvent Gere le fait que la souris sorte de la zone de la Borne.
Definition terminal.cpp:428
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
Terminal::paint Fonction de dessin des bornes.
Definition terminal.cpp:160
bool m_hovered
Whether the mouse pointer is hovering the terminal.
Definition terminal.h:136
Element * parent_element_
Parent electrical element.
Definition terminal.h:125
void conductorWasAdded(Conductor *conductor)
void mouseMoveEvent(QGraphicsSceneMouseEvent *) override
Terminal::mouseMoveEvent Gere le fait qu'on bouge la souris sur la Borne.
Definition terminal.cpp:454
Terminal * m_previous_terminal
Last terminal seen through an attached conductor.
Definition terminal.h:134
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:763