mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-24 03:10:52 +01:00
Wrap code for better readability
This commit is contained in:
@@ -40,12 +40,11 @@ const qreal Terminal::Z = 1000;
|
||||
@param name of terminal
|
||||
@param hiddenName
|
||||
*/
|
||||
void Terminal::init(QString number,
|
||||
QString name,
|
||||
bool hiddenName) {
|
||||
|
||||
void Terminal::init(
|
||||
QString number, QString name, bool hiddenName)
|
||||
{
|
||||
hovered_color_ = Terminal::neutralColor;
|
||||
|
||||
|
||||
// calcul de la position du point d'amarrage a l'element
|
||||
dock_elmt_ = d->m_pos;
|
||||
switch(d->m_orientation) {
|
||||
@@ -61,7 +60,7 @@ void Terminal::init(QString number,
|
||||
name_terminal_ = std::move(name);
|
||||
name_terminal_hidden = hiddenName;
|
||||
// par defaut : pas de conducteur
|
||||
|
||||
|
||||
// QRectF null
|
||||
br_ = new QRectF();
|
||||
previous_terminal_ = nullptr;
|
||||
@@ -82,7 +81,12 @@ void Terminal::init(QString number,
|
||||
\param name
|
||||
\param hiddenName
|
||||
*/
|
||||
void Terminal::init(QPointF pf, Qet::Orientation o, QString number, QString name, bool hiddenName)
|
||||
void Terminal::init(
|
||||
QPointF pf,
|
||||
Qet::Orientation o,
|
||||
QString number,
|
||||
QString name,
|
||||
bool hiddenName)
|
||||
{
|
||||
// definition du pount d'amarrage pour un conducteur
|
||||
d->m_pos = pf;
|
||||
@@ -132,12 +136,13 @@ Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
|
||||
@param hiddenName hide or show the name
|
||||
@param e Element auquel cette borne appartient
|
||||
*/
|
||||
Terminal::Terminal(QPointF pf,
|
||||
Qet::Orientation o,
|
||||
QString num,
|
||||
QString name,
|
||||
bool hiddenName,
|
||||
Element *e) :
|
||||
Terminal::Terminal(
|
||||
QPointF pf,
|
||||
Qet::Orientation o,
|
||||
QString num,
|
||||
QString name,
|
||||
bool hiddenName,
|
||||
Element *e) :
|
||||
QGraphicsObject (e),
|
||||
d(new TerminalData(this)),
|
||||
parent_element_ (e)
|
||||
@@ -160,7 +165,8 @@ Terminal::Terminal(TerminalData* data, Element* e) :
|
||||
La destruction de la borne entraine la destruction des conducteurs
|
||||
associes.
|
||||
*/
|
||||
Terminal::~Terminal() {
|
||||
Terminal::~Terminal()
|
||||
{
|
||||
foreach(Conductor *c, conductors_) delete c;
|
||||
delete br_;
|
||||
}
|
||||
@@ -172,7 +178,8 @@ Terminal::~Terminal() {
|
||||
pivote. Sinon elle renvoie son sens normal.
|
||||
@return L'orientation actuelle de la Terminal.
|
||||
*/
|
||||
Qet::Orientation Terminal::orientation() const {
|
||||
Qet::Orientation Terminal::orientation() const
|
||||
{
|
||||
if (Element *elt = qgraphicsitem_cast<Element *>(parentItem())) {
|
||||
// orientations actuelle et par defaut de l'element
|
||||
int ori_cur = elt -> orientation();
|
||||
@@ -192,7 +199,8 @@ Qet::Orientation Terminal::orientation() const {
|
||||
@brief Terminal::setNumber
|
||||
@param number
|
||||
*/
|
||||
void Terminal::setNumber(QString number) {
|
||||
void Terminal::setNumber(QString number)
|
||||
{
|
||||
number_terminal_ = std::move(number);
|
||||
}
|
||||
|
||||
@@ -201,7 +209,8 @@ void Terminal::setNumber(QString number) {
|
||||
@param name : QString
|
||||
@param hiddenName : bool
|
||||
*/
|
||||
void Terminal::setName(QString name, bool hiddenName) {
|
||||
void Terminal::setName(QString name, bool hiddenName)
|
||||
{
|
||||
name_terminal_ = std::move(name);
|
||||
name_terminal_hidden = hiddenName;
|
||||
}
|
||||
@@ -215,13 +224,16 @@ void Terminal::setName(QString name, bool hiddenName) {
|
||||
bool Terminal::addConductor(Conductor *conductor)
|
||||
{
|
||||
if (!conductor) return(false);
|
||||
|
||||
Q_ASSERT_X(((conductor -> terminal1 == this) ^ (conductor -> terminal2 == this)),
|
||||
"Terminal::addConductor",
|
||||
"The conductor must be linked exactly once to this terminal");
|
||||
|
||||
//Get the other terminal where the conductor must be linked
|
||||
Terminal *other_terminal = (conductor -> terminal1 == this)
|
||||
? conductor->terminal2 : conductor->terminal1;
|
||||
|
||||
Q_ASSERT_X(((conductor -> terminal1 == this) ^ (conductor -> terminal2 == this)), "Terminal::addConductor", "The conductor must be linked exactly once to this terminal");
|
||||
|
||||
//Get the other terminal where the conductor must be linked
|
||||
Terminal *other_terminal = (conductor -> terminal1 == this) ? conductor->terminal2 : conductor->terminal1;
|
||||
|
||||
//Check if this terminal isn't already linked with other_terminal
|
||||
//Check if this terminal isn't already linked with other_terminal
|
||||
foreach (Conductor* cond, conductors_)
|
||||
if (cond -> terminal1 == other_terminal || cond -> terminal2 == other_terminal)
|
||||
return false; //They already a conductor linked to this and other_terminal
|
||||
@@ -250,35 +262,37 @@ void Terminal::removeConductor(Conductor *conductor)
|
||||
@param p Le QPainter a utiliser
|
||||
@param options Les options de dessin
|
||||
*/
|
||||
void Terminal::paint(QPainter *p,
|
||||
const QStyleOptionGraphicsItem *options,
|
||||
QWidget *) {
|
||||
void Terminal::paint(
|
||||
QPainter *p,
|
||||
const QStyleOptionGraphicsItem *options,
|
||||
QWidget *)
|
||||
{
|
||||
// en dessous d'un certain zoom, les bornes ne sont plus dessinees
|
||||
if (options && options -> levelOfDetail < 0.5) return;
|
||||
|
||||
|
||||
p -> save();
|
||||
|
||||
//annulation des renderhints
|
||||
p -> setRenderHint(QPainter::Antialiasing, false);
|
||||
p -> setRenderHint(QPainter::TextAntialiasing, false);
|
||||
p -> setRenderHint(QPainter::SmoothPixmapTransform, false);
|
||||
|
||||
|
||||
// on travaille avec les coordonnees de l'element parent
|
||||
QPointF c = mapFromParent(d->m_pos);
|
||||
QPointF e = mapFromParent(dock_elmt_);
|
||||
|
||||
|
||||
QPen t;
|
||||
t.setWidthF(1.0);
|
||||
|
||||
|
||||
if (options && options -> levelOfDetail < 1.0) {
|
||||
t.setCosmetic(true);
|
||||
}
|
||||
|
||||
|
||||
// dessin de la borne en rouge
|
||||
t.setColor(Qt::red);
|
||||
p -> setPen(t);
|
||||
p -> drawLine(c, e);
|
||||
|
||||
|
||||
// dessin du point d'amarrage au conducteur en bleu
|
||||
t.setColor(hovered_color_);
|
||||
p -> setPen(t);
|
||||
@@ -288,11 +302,11 @@ void Terminal::paint(QPainter *p,
|
||||
p -> drawEllipse(QRectF(c.x() - 2.5, c.y() - 2.5, 5.0, 5.0));
|
||||
} else p -> drawPoint(c);
|
||||
|
||||
//Draw help line if needed,
|
||||
//Draw help line if needed,
|
||||
if (diagram() && m_draw_help_line)
|
||||
{
|
||||
//Draw the help line with same orientation of terminal
|
||||
//Only if there isn't docked conductor
|
||||
//Draw the help line with same orientation of terminal
|
||||
//Only if there isn't docked conductor
|
||||
if (conductors().isEmpty())
|
||||
{
|
||||
if (!m_help_line)
|
||||
@@ -312,14 +326,14 @@ void Terminal::paint(QPainter *p,
|
||||
}
|
||||
}
|
||||
|
||||
//Map the line (in scene coordinate) to m_help_line coordinate
|
||||
//Map the line (in scene coordinate) to m_help_line coordinate
|
||||
line.setP1(m_help_line -> mapFromScene(line.p1()));
|
||||
line.setP2(m_help_line -> mapFromScene(line.p2()));
|
||||
m_help_line -> setPen(pen);
|
||||
m_help_line -> setLine(line);
|
||||
}
|
||||
|
||||
//Draw the help line perpendicular to the terminal
|
||||
//Draw the help line perpendicular to the terminal
|
||||
if (!m_help_line_a)
|
||||
{
|
||||
m_help_line_a = new QGraphicsLineItem(this);
|
||||
@@ -415,7 +429,8 @@ QLineF Terminal::HelpLine() const
|
||||
@brief Terminal::boundingRect
|
||||
@return Le rectangle (en precision flottante) delimitant la borne et ses alentours.
|
||||
*/
|
||||
QRectF Terminal::boundingRect() const {
|
||||
QRectF Terminal::boundingRect() const
|
||||
{
|
||||
if (br_ -> isNull())
|
||||
{
|
||||
qreal dcx = d->m_pos.x();
|
||||
@@ -497,7 +512,8 @@ Terminal* Terminal::alignedWithTerminal() const
|
||||
@brief Terminal::hoverEnterEvent
|
||||
Gere l'entree de la souris sur la zone de la Borne.
|
||||
*/
|
||||
void Terminal::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
|
||||
void Terminal::hoverEnterEvent(QGraphicsSceneHoverEvent *)
|
||||
{
|
||||
hovered_ = true;
|
||||
update();
|
||||
}
|
||||
@@ -506,14 +522,14 @@ void Terminal::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
|
||||
@brief Terminal::hoverMoveEvent
|
||||
Gere les mouvements de la souris sur la zone de la Borne.
|
||||
*/
|
||||
void Terminal::hoverMoveEvent(QGraphicsSceneHoverEvent *) {
|
||||
}
|
||||
void Terminal::hoverMoveEvent(QGraphicsSceneHoverEvent *) {}
|
||||
|
||||
/**
|
||||
@brief Terminal::hoverLeaveEvent
|
||||
Gere le fait que la souris sorte de la zone de la Borne.
|
||||
*/
|
||||
void Terminal::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
||||
void Terminal::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
|
||||
{
|
||||
hovered_ = false;
|
||||
update();
|
||||
}
|
||||
@@ -523,7 +539,8 @@ void Terminal::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
||||
Gere le fait qu'on enfonce un bouton de la souris sur la Borne.
|
||||
@param e L'evenement souris correspondant
|
||||
*/
|
||||
void Terminal::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||
void Terminal::mousePressEvent(QGraphicsSceneMouseEvent *e)
|
||||
{
|
||||
if (Diagram *diag = diagram()) {
|
||||
diag -> setConductorStart(mapToScene(QPointF(d->m_pos)));
|
||||
diag -> setConductorStop(e -> scenePos());
|
||||
@@ -537,10 +554,11 @@ void Terminal::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||
Gere le fait qu'on bouge la souris sur la Borne.
|
||||
@param e L'evenement souris correspondant
|
||||
*/
|
||||
void Terminal::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
void Terminal::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
|
||||
{
|
||||
// pendant la pose d'un conducteur, on adopte un autre curseur
|
||||
//setCursor(Qt::CrossCursor);
|
||||
|
||||
|
||||
// d'un mouvement a l'autre, il faut retirer l'effet hover de la borne precedente
|
||||
if (previous_terminal_) {
|
||||
if (previous_terminal_ == this) hovered_ = true;
|
||||
@@ -583,7 +601,7 @@ void Terminal::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
} else {
|
||||
other_terminal -> hovered_color_ = allowedColor;
|
||||
}
|
||||
|
||||
|
||||
other_terminal -> hovered_ = true;
|
||||
other_terminal -> update();
|
||||
}
|
||||
@@ -667,7 +685,8 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
|
||||
@brief Terminal::updateConductor
|
||||
Update the path of conductor docked to this terminal
|
||||
*/
|
||||
void Terminal::updateConductor() {
|
||||
void Terminal::updateConductor()
|
||||
{
|
||||
foreach (Conductor *conductor, conductors_)
|
||||
conductor->updatePath();
|
||||
}
|
||||
@@ -712,7 +731,8 @@ bool Terminal::canBeLinkedTo(Terminal *other_terminal)
|
||||
@brief Terminal::conductors
|
||||
@return La liste des conducteurs lies a cette borne
|
||||
*/
|
||||
QList<Conductor *> Terminal::conductors() const {
|
||||
QList<Conductor *> Terminal::conductors() const
|
||||
{
|
||||
return(conductors_);
|
||||
}
|
||||
|
||||
@@ -722,7 +742,8 @@ QList<Conductor *> Terminal::conductors() const {
|
||||
@param doc Le Document XML a utiliser pour creer l'element XML
|
||||
@return un QDomElement representant cette borne
|
||||
*/
|
||||
QDomElement Terminal::toXml(QDomDocument &doc) const {
|
||||
QDomElement Terminal::toXml(QDomDocument &doc) const
|
||||
{
|
||||
QDomElement qdo = doc.createElement("terminal");
|
||||
|
||||
// for backward compatibility
|
||||
@@ -743,7 +764,8 @@ QDomElement Terminal::toXml(QDomDocument &doc) const {
|
||||
@param terminal Le QDomElement a analyser
|
||||
@return true si le QDomElement passe en parametre est une borne, false sinon
|
||||
*/
|
||||
bool Terminal::valideXml(QDomElement &terminal) {
|
||||
bool Terminal::valideXml(QDomElement &terminal)
|
||||
{
|
||||
// verifie le nom du tag
|
||||
if (terminal.tagName() != "terminal") return(false);
|
||||
|
||||
@@ -785,7 +807,8 @@ bool Terminal::valideXml(QDomElement &terminal) {
|
||||
@return true si la borne "se reconnait"
|
||||
(memes coordonnes, meme orientation), false sinon
|
||||
*/
|
||||
bool Terminal::fromXml(QDomElement &terminal) {
|
||||
bool Terminal::fromXml(QDomElement &terminal)
|
||||
{
|
||||
number_terminal_ = terminal.attribute("number");
|
||||
name_terminal_ = terminal.attribute("name");
|
||||
name_terminal_hidden = terminal.attribute("nameHidden").toInt();
|
||||
@@ -802,7 +825,8 @@ bool Terminal::fromXml(QDomElement &terminal) {
|
||||
@return the position, relative to the scene, of the docking point for
|
||||
conductors.
|
||||
*/
|
||||
QPointF Terminal::dockConductor() const {
|
||||
QPointF Terminal::dockConductor() const
|
||||
{
|
||||
return(mapToScene(d->m_pos));
|
||||
}
|
||||
|
||||
@@ -811,7 +835,8 @@ QPointF Terminal::dockConductor() const {
|
||||
@return le Diagram auquel cette borne appartient,
|
||||
ou 0 si cette borne est independant
|
||||
*/
|
||||
Diagram *Terminal::diagram() const {
|
||||
Diagram *Terminal::diagram() const
|
||||
{
|
||||
return(qobject_cast<Diagram *>(scene()));
|
||||
}
|
||||
|
||||
@@ -819,11 +844,13 @@ Diagram *Terminal::diagram() const {
|
||||
@brief Terminal::parentElement
|
||||
@return L'element auquel cette borne est rattachee
|
||||
*/
|
||||
Element *Terminal::parentElement() const {
|
||||
Element *Terminal::parentElement() const
|
||||
{
|
||||
return(parent_element_);
|
||||
}
|
||||
|
||||
QUuid Terminal::uuid() const {
|
||||
QUuid Terminal::uuid() const
|
||||
{
|
||||
return d->m_uuid;
|
||||
}
|
||||
|
||||
@@ -838,9 +865,10 @@ QUuid Terminal::uuid() const {
|
||||
false return only terminal in the same diagram of t
|
||||
@return the list of terminal at the same potential
|
||||
*/
|
||||
QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal, const bool all_diagram)
|
||||
QList<Terminal *> relatedPotentialTerminal (
|
||||
const Terminal *terminal, const bool all_diagram)
|
||||
{
|
||||
// If terminal parent element is a folio report.
|
||||
// If terminal parent element is a folio report.
|
||||
if (all_diagram && terminal -> parentElement() -> linkType() & Element::AllReport)
|
||||
{
|
||||
QList <Element *> elmt_list = terminal -> parentElement() -> linkedElements();
|
||||
@@ -849,7 +877,7 @@ QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal, const bool
|
||||
return (elmt_list.first()->terminals());
|
||||
}
|
||||
}
|
||||
// If terminal parent element is a Terminal element.
|
||||
// If terminal parent element is a Terminal element.
|
||||
else if (terminal -> parentElement() -> linkType() & Element::Terminale)
|
||||
{
|
||||
QList <Terminal *> terminals = terminal->parentElement()->terminals();
|
||||
|
||||
Reference in New Issue
Block a user