Revert pull request #48

This commit is contained in:
Laurent Trinques
2020-06-14 07:35:52 +02:00
parent c9a7c836c5
commit 22e619d6b9
13 changed files with 171 additions and 428 deletions

View File

@@ -581,27 +581,13 @@ bool Conductor::valideXml(QDomElement &e){
if (!e.hasAttribute("terminal2")) return(false);
bool conv_ok;
// parse l'abscisse
if (e.hasAttribute("element1")) {
if (QUuid(e.attribute("element1")).isNull())
return false;
if (QUuid(e.attribute("terminal1")).isNull())
return false;
} else {
e.attribute("terminal1").toInt(&conv_ok);
if (!conv_ok) return(false);
}
// parse l'abscisse
e.attribute("terminal1").toInt(&conv_ok);
if (!conv_ok) return(false);
// parse l'ordonnee
if (e.hasAttribute("element2")) {
if (QUuid(e.attribute("element2")).isNull())
return false;
if (QUuid(e.attribute("terminal2")).isNull())
return false;
} else {
e.attribute("terminal2").toInt(&conv_ok);
if (!conv_ok) return(false);
}
e.attribute("terminal2").toInt(&conv_ok);
if (!conv_ok) return(false);
return(true);
}
@@ -1010,23 +996,8 @@ QDomElement Conductor::toXml(QDomDocument &dom_document, QHash<Terminal *, int>
dom_element.setAttribute("x", QString::number(pos().x()));
dom_element.setAttribute("y", QString::number(pos().y()));
// Terminal is uniquely identified by the uuid of the terminal and the element
if (terminal1->uuid().isNull()) {
// legacy method to identify the terminal
dom_element.setAttribute("terminal1", table_adr_id.value(terminal1)); // for backward compability
} else {
dom_element.setAttribute("element1", terminal1->parentElement()->uuid().toString());
dom_element.setAttribute("terminal1", terminal1->uuid().toString());
}
if (terminal2->uuid().isNull()) {
// legacy method to identify the terminal
dom_element.setAttribute("terminal2", table_adr_id.value(terminal2)); // for backward compability
} else {
dom_element.setAttribute("element2", terminal2->parentElement()->uuid().toString());
dom_element.setAttribute("terminal2", terminal2->uuid().toString());
}
dom_element.setAttribute("terminal1", table_adr_id.value(terminal1));
dom_element.setAttribute("terminal2", table_adr_id.value(terminal2));
dom_element.setAttribute("freezeLabel", m_freeze_label? "true" : "false");
// on n'exporte les segments du conducteur que si ceux-ci ont
@@ -1062,8 +1033,7 @@ QDomElement Conductor::toXml(QDomDocument &dom_document, QHash<Terminal *, int>
/**
* @brief Conductor::pathFromXml
* Generate the path (of the line) from xml file by checking the segments in the xml
* file
* Generate the path from xml file
* @param e
* @return true if generate path success else return false
*/

View File

@@ -23,7 +23,6 @@
#include "elementprovider.h"
#include "diagramposition.h"
#include "terminal.h"
#include "terminaldata.h"
#include "PropertiesEditor/propertieseditordialog.h"
#include "elementpropertieswidget.h"
#include "numerotationcontextcommands.h"
@@ -561,22 +560,36 @@ DynamicElementTextItem *Element::parseDynamicText(const QDomElement &dom_element
return deti;
}
/*!
* \brief Element::parseTerminal
* Parse partTerminal from xml structure
* \param dom_element
* \return
*/
Terminal *Element::parseTerminal(const QDomElement &dom_element)
{
TerminalData* data = new TerminalData();
if (!data->fromXml(dom_element)) {
delete data;
return nullptr;
}
qreal terminalx, terminaly;
Qet::Orientation terminalo;
if (!QET::attributeIsAReal(dom_element, QString("x"), &terminalx)) {
return(nullptr);
}
if (!QET::attributeIsAReal(dom_element, QString("y"), &terminaly)) {
return(nullptr);
}
if (!dom_element.hasAttribute("orientation")) {
return(nullptr);
}
if (dom_element.attribute("orientation") == "n") {
terminalo = Qet::North;
}
else if (dom_element.attribute("orientation") == "s") {
terminalo = Qet::South;
}
else if (dom_element.attribute("orientation") == "e") {
terminalo = Qet::East;
}
else if (dom_element.attribute("orientation") == "w") {
terminalo = Qet::West;
}
else {
return(nullptr);
}
Terminal *new_terminal = new Terminal(data, this);
Terminal *new_terminal = new Terminal(terminalx, terminaly, terminalo, this);
m_terminals << new_terminal;
//Sort from top to bottom and left to rigth
@@ -1047,7 +1060,7 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
foreach(Terminal *t, terminals()) {
// alors on enregistre la borne
QDomElement terminal = t -> toXml(document);
terminal.setAttribute("id", id_terminal); // for backward compatibility
terminal.setAttribute("id", id_terminal);
table_adr_id.insert(t, id_terminal ++);
xml_terminals.appendChild(terminal);
}

View File

@@ -24,7 +24,6 @@
#include "diagramcommands.h"
#include "conductorautonumerotation.h"
#include "conductortextitem.h"
#include "terminaldata.h"
QColor Terminal::neutralColor = QColor(Qt::blue);
QColor Terminal::allowedColor = QColor(Qt::darkGreen);
@@ -40,13 +39,17 @@ const qreal Terminal::Z = 1000;
@param number of terminal
@param name of terminal
*/
void Terminal::init(QString number, QString name, bool hiddenName) {
hovered_color_ = Terminal::neutralColor;
void Terminal::init(QPointF pf, Qet::Orientation o, QString number, QString name, bool hiddenName) {
// definition du pount d'amarrage pour un conducteur
dock_conductor_ = pf;
// definition de l'orientation de la borne (par defaut : sud)
if (o < Qet::North || o > Qet::West) ori_ = Qet::South;
else ori_ = o;
// calcul de la position du point d'amarrage a l'element
dock_elmt_ = d->m_pos;
switch(d->m_orientation) {
dock_elmt_ = dock_conductor_;
switch(ori_) {
case Qet::North: dock_elmt_ += QPointF(0, Terminal::terminalSize); break;
case Qet::East : dock_elmt_ += QPointF(-Terminal::terminalSize, 0); break;
case Qet::West : dock_elmt_ += QPointF(Terminal::terminalSize, 0); break;
@@ -71,27 +74,6 @@ void Terminal::init(QString number, QString name, bool hiddenName) {
setZValue(Z);
}
/*!
* \brief Terminal::init
* Additionaly to the init above, this method stores position and orientation into the data class
* \param pf
* \param o
* \param number
* \param name
* \param 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;
// definition de l'orientation de la borne (par defaut : sud)
if (o < Qet::North || o > Qet::West) d->m_orientation = Qet::South;
else d->m_orientation = o;
init(number, name, hiddenName);
}
/**
initialise une borne
@param pf position du point d'amarrage pour un conducteur
@@ -101,8 +83,11 @@ void Terminal::init(QPointF pf, Qet::Orientation o, QString number, QString name
*/
Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) :
QGraphicsObject(e),
d(new TerminalData(this)),
parent_element_ (e)
m_draw_help_line(false),
m_help_line (nullptr),
m_help_line_a (nullptr),
parent_element_ (e),
hovered_color_ (Terminal::neutralColor)
{
init(pf, o, "_", "_", false);
}
@@ -117,10 +102,13 @@ Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) :
*/
Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
QGraphicsObject(e),
d(new TerminalData(this)),
parent_element_ (e)
m_draw_help_line (false),
m_help_line (nullptr),
m_help_line_a (nullptr),
parent_element_ (e),
hovered_color_ (Terminal::neutralColor)
{
init(QPointF(pf_x, pf_y), o, "_", "_", false);
init(QPointF(pf_x, pf_y), o, "_", "_", false);
}
/**
@@ -135,22 +123,15 @@ Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, 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)
m_draw_help_line (false),
m_help_line (nullptr),
m_help_line_a (nullptr),
parent_element_ (e),
hovered_color_ (Terminal::neutralColor)
{
init(pf, o, std::move(num), std::move(name), hiddenName);
}
Terminal::Terminal(TerminalData* data, Element* e) :
QGraphicsObject(e),
d(data),
parent_element_(e)
{
// TODO: what is when multiple parents exist. So the other relation is lost.
d->setParent(this);
init("_", "_", false);
}
/**
Destructeur
La destruction de la borne entraine la destruction des conducteurs
@@ -172,15 +153,15 @@ 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();
if (ori_cur == 0) return(d->m_orientation);
if (ori_cur == 0) return(ori_);
else {
// calcul l'angle de rotation implique par l'orientation de l'element parent
// angle de rotation de la borne sur la scene, divise par 90
int angle = ori_cur + d->m_orientation;
int angle = ori_cur + ori_;
while (angle >= 4) angle -= 4;
return((Qet::Orientation)angle);
}
} else return(d->m_orientation);
} else return(ori_);
}
@@ -257,7 +238,7 @@ void Terminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, QWidg
p -> setRenderHint(QPainter::SmoothPixmapTransform, false);
// on travaille avec les coordonnees de l'element parent
QPointF c = mapFromParent(d->m_pos);
QPointF c = mapFromParent(dock_conductor_);
QPointF e = mapFromParent(dock_elmt_);
QPen t;
@@ -409,11 +390,11 @@ QLineF Terminal::HelpLine() const
*/
QRectF Terminal::boundingRect() const {
if (br_ -> isNull()) {
qreal dcx = d->m_pos.x();
qreal dcy = d->m_pos.y();
qreal dcx = dock_conductor_.x();
qreal dcy = dock_conductor_.y();
qreal dex = dock_elmt_.x();
qreal dey = dock_elmt_.y();
QPointF origin = (dcx <= dex && dcy <= dey ? d->m_pos : dock_elmt_);
QPointF origin = (dcx <= dex && dcy <= dey ? dock_conductor_ : dock_elmt_);
origin += QPointF(-3.0, -3.0);
qreal w = qAbs((int)(dcx - dex)) + 7;
qreal h = qAbs((int)(dcy - dey)) + 7;
@@ -511,10 +492,10 @@ void Terminal::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
@param e L'evenement souris correspondant
*/
void Terminal::mousePressEvent(QGraphicsSceneMouseEvent *e) {
if (Diagram *diag = diagram()) {
diag -> setConductorStart(mapToScene(QPointF(d->m_pos)));
diag -> setConductorStop(e -> scenePos());
diag -> setConductor(true);
if (Diagram *d = diagram()) {
d -> setConductorStart(mapToScene(QPointF(dock_conductor_)));
d -> setConductorStop(e -> scenePos());
d -> setConductor(true);
//setCursor(Qt::CrossCursor);
}
}
@@ -536,13 +517,13 @@ void Terminal::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
}
Diagram *diag = diagram();
if (!diag) return;
Diagram *d = diagram();
if (!d) return;
// si la scene est un Diagram, on actualise le poseur de conducteur
diag -> setConductorStop(e -> scenePos());
d -> setConductorStop(e -> scenePos());
// on recupere la liste des qgi sous le pointeur
QList<QGraphicsItem *> qgis = diag -> items(e -> scenePos());
QList<QGraphicsItem *> qgis = d -> items(e -> scenePos());
/* le qgi le plus haut
= le poseur de conductor
@@ -678,10 +659,6 @@ bool Terminal::isLinkedTo(Terminal *other_terminal) {
/**
* @brief Terminal::canBeLinkedTo
* Checking if the terminal can be linked to \p other_terminal or not
* Reasons for not linable:
* - \p other_terminal is this terminal
* - this terminal is already connected to \p other_terminal
* @param other_terminal
* @return true if this terminal can be linked to @other_terminal,
* otherwise false
@@ -708,9 +685,9 @@ QList<Conductor *> Terminal::conductors() const {
*/
QDomElement Terminal::toXml(QDomDocument &doc) const {
QDomElement qdo = doc.createElement("terminal");
qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x())); // for backward compatibility
qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y()));// for backward compatibility
qdo.setAttribute("orientation", d->m_orientation);
qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x()));
qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y()));
qdo.setAttribute("orientation", ori_);
qdo.setAttribute("number", number_terminal_);
qdo.setAttribute("name", name_terminal_);
qdo.setAttribute("nameHidden", name_terminal_hidden);
@@ -762,22 +739,13 @@ bool Terminal::fromXml(QDomElement &terminal) {
number_terminal_ = terminal.attribute("number");
name_terminal_ = terminal.attribute("name");
name_terminal_hidden = terminal.attribute("nameHidden").toInt();
return (
qFuzzyCompare(terminal.attribute("x").toDouble(), dock_elmt_.x()) &&
qFuzzyCompare(terminal.attribute("y").toDouble(), dock_elmt_.y()) &&
(terminal.attribute("orientation").toInt() == d->m_orientation)
(terminal.attribute("orientation").toInt() == ori_)
);
}
/**
@return the position, relative to the scene, of the docking point for
conductors.
*/
inline QPointF Terminal::dockConductor() const {
return(mapToScene(d->m_pos));
}
/**
@return le Diagram auquel cette borne appartient, ou 0 si cette borne est independant
*/
@@ -792,10 +760,6 @@ Element *Terminal::parentElement() const {
return(parent_element_);
}
QUuid Terminal::uuid() const {
return d->m_uuid;
}
/**
* @brief Conductor::relatedPotentialTerminal
* Return terminal at the same potential from the same

View File

@@ -23,12 +23,9 @@
class Conductor;
class Diagram;
class Element;
class TerminalData;
/**
This class represents a terminal of an electrical element, i.e. a possible
plug point for conductors.
This class handles all mouse events for connecting conductors
*/
class Terminal : public QGraphicsObject
{
@@ -42,7 +39,6 @@ class Terminal : public QGraphicsObject
public:
Terminal(QPointF, Qet::Orientation, Element * = nullptr);
Terminal(qreal, qreal, Qet::Orientation, Element * = nullptr);
Terminal(TerminalData* data, Element *e = nullptr);
Terminal(QPointF, Qet::Orientation, QString number, QString name, bool hiddenName, Element * = nullptr);
~Terminal() override;
@@ -67,7 +63,6 @@ class Terminal : public QGraphicsObject
int conductorsCount () const;
Diagram *diagram () const;
Element *parentElement () const;
QUuid uuid () const;
QList<Conductor *> conductors() const;
Qet::Orientation orientation() const;
@@ -111,23 +106,24 @@ class Terminal : public QGraphicsObject
static QColor forbiddenColor;
private:
bool m_draw_help_line{false};
QGraphicsLineItem *m_help_line{nullptr};
QGraphicsLineItem *m_help_line_a{nullptr};
TerminalData* d;
bool m_draw_help_line;
QGraphicsLineItem *m_help_line;
QGraphicsLineItem *m_help_line_a;
/// Parent electrical element
Element *parent_element_{nullptr};
Element *parent_element_;
/// docking point for conductors
QPointF dock_conductor_;
/// docking point for parent element
QPointF dock_elmt_;
/// terminal orientation
Qet::Orientation ori_;
/// List of conductors attached to the terminal
QList<Conductor *> conductors_;
/// Pointer to a rectangle representing the terminal bounding rect;
/// used to calculate the bounding rect once only;
/// used a pointer because boundingRect() is supposed to be const.
QRectF *br_{nullptr};
QRectF *br_;
/// Last terminal seen through an attached conductor
Terminal *previous_terminal_;
/// Whether the mouse pointer is hovering the terminal
@@ -141,8 +137,7 @@ class Terminal : public QGraphicsObject
bool name_terminal_hidden;
private:
void init(QString number, QString name, bool hiddenName);
void init(QPointF pf, Qet::Orientation o, QString number, QString name, bool hiddenName);
void init(QPointF, Qet::Orientation, QString number, QString name, bool hiddenName);
};
/**
@@ -152,6 +147,14 @@ inline int Terminal::conductorsCount() const {
return(conductors_.size());
}
/**
@return the position, relative to the scene, of the docking point for
conductors.
*/
inline QPointF Terminal::dockConductor() const {
return(mapToScene(dock_conductor_));
}
/**
@return the number of terminal.
*/