TEST a Merge branch 'XMLProperties'

it gets built let's test it for bugs

 Conflicts:
	sources/ElementsCollection/fileelementcollectionitem.cpp
	sources/QetGraphicsItemModeler/qetgraphicshandleritem.h
	sources/borderproperties.cpp
	sources/conductorproperties.cpp
	sources/conductorproperties.h
	sources/diagram.cpp
	sources/diagram.h
	sources/diagramprintdialog.cpp
	sources/diagramprintdialog.h
	sources/editor/graphicspart/customelementgraphicpart.cpp
	sources/editor/graphicspart/partarc.cpp
	sources/editor/graphicspart/partdynamictextfield.cpp
	sources/editor/graphicspart/partdynamictextfield.h
	sources/editor/graphicspart/partellipse.cpp
	sources/editor/graphicspart/partline.cpp
	sources/editor/graphicspart/partpolygon.cpp
	sources/editor/graphicspart/partrectangle.cpp
	sources/editor/graphicspart/partterminal.cpp
	sources/editor/graphicspart/partterminal.h
	sources/editor/graphicspart/parttext.cpp
	sources/properties/propertiesinterface.cpp
	sources/properties/propertiesinterface.h
	sources/properties/terminaldata.cpp
	sources/properties/terminaldata.h
	sources/properties/xrefproperties.cpp
	sources/properties/xrefproperties.h
	sources/qetgraphicsitem/conductor.cpp
	sources/qetgraphicsitem/conductor.h
	sources/qetgraphicsitem/conductortextitem.h
	sources/qetgraphicsitem/dynamicelementtextitem.h
	sources/qetgraphicsitem/element.cpp
	sources/qetgraphicsitem/element.h
	sources/qetgraphicsitem/elementtextitemgroup.h
	sources/qetgraphicsitem/slaveelement.cpp
	sources/qetgraphicsitem/slaveelement.h
	sources/qetgraphicsitem/terminal.cpp
	sources/qetgraphicsitem/terminal.h
	sources/qetproject.cpp
	sources/titleblockproperties.cpp
This commit is contained in:
Simon De Backer
2020-10-13 21:51:34 +02:00
67 changed files with 2095 additions and 1486 deletions

View File

@@ -76,14 +76,7 @@ class ConductorXmlRetroCompatibility
*/
Conductor::Conductor(Terminal *p1, Terminal* p2) :
terminal1(p1),
terminal2(p2),
m_mouse_over(false),
m_text_item(nullptr),
segments(nullptr),
m_moving_segment(false),
modified_path(false),
has_to_save_profile(false),
must_highlight_(Conductor::None)
terminal2(p2)
{
//set Zvalue at 11 to be upper than the DiagramImageItem and element
setZValue(11);
@@ -580,41 +573,13 @@ ConductorTextItem *Conductor::textItem() const
}
/**
Methode de validation d'element XML
@param e Un element XML sense represente un Conducteur
@return true si l'element XML represente bien un Conducteur ; false sinon
@brief Conductor::valideXml
@param e
@return true
*/
bool Conductor::valideXml(QDomElement &e){
// verifie le nom du tag
if (e.tagName() != "conductor") return(false);
// verifie la presence des attributs minimaux
if (!e.hasAttribute("terminal1")) return(false);
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'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);
}
return(true);
bool Conductor::valideXml(QDomElement &e)
{
return true;
}
/**
@@ -984,13 +949,16 @@ void Conductor::pointsToSegments(const QList<QPointF>& points_list) {
/**
@brief Conductor::fromXml
Load the conductor and her information from xml element
@param dom_element
@param e
@return true is loading success else return false
*/
bool Conductor::fromXml(QDomElement &dom_element)
bool Conductor::fromXml(const QDomElement &dom_element)
{
setPos(dom_element.attribute("x", nullptr).toDouble(),
dom_element.attribute("y", nullptr).toDouble());
// TODO: seems to short!
double x=0, y=0;
propertyDouble(dom_element, "x", &x);
propertyDouble(dom_element, "y", &y);
setPos(x, y);
bool return_ = pathFromXml(dom_element);
@@ -1004,49 +972,48 @@ bool Conductor::fromXml(QDomElement &dom_element)
else
m_autoNum_seq.fromXml(dom_element.firstChildElement("sequentialNumbers"));
m_freeze_label = dom_element.attribute("freezeLabel") == "true"? true : false;
propertyBool(dom_element, "freezeLabel", &m_freeze_label);
setProperties(pr);
return return_;
}
/**
@brief Conductor::toXml
Exporte les caracteristiques du conducteur sous forme d'une element XML.
@param dom_document :
Le document XML a utiliser pour creer l'element XML
@param table_adr_id :
Hash stockant les correspondances entre les ids des
bornes dans le document XML et leur adresse en memoire
@return Un element XML representant le conducteur
*/
QDomElement Conductor::toXml(QDomDocument &dom_document,
QHash<Terminal *,
int> &table_adr_id) const
{
QDomElement dom_element = dom_document.createElement("conductor");
dom_element.setAttribute("x", QString::number(pos().x()));
dom_element.setAttribute("y", QString::number(pos().y()));
// does not support legacy method
// dom_element.setAttribute("terminal1", table_adr_id.value(terminal1));
QDomElement Conductor::toXml(QDomDocument & doc) const
{
QDomElement dom_element = doc.createElement("conductor");
dom_element.appendChild(createXmlProperty(doc, "x", pos().x()));
dom_element.appendChild(createXmlProperty(doc, "y", 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
QUuid terminal = terminal1->uuid();
QUuid terminalParent = terminal1->parentElement()->uuid();
if (terminalParent.isNull() || terminal.isNull()) {
// legacy when the terminal does not have a valid uuid
// do not store element1 information, because this is used to determine in the fromXml
// process that legacy file format
dom_element.appendChild(createXmlProperty(doc, "terminal1", terminal1->ID()));
} else {
dom_element.setAttribute("element1", terminal1->parentElement()->uuid().toString());
dom_element.setAttribute("terminal1", terminal1->uuid().toString());
dom_element.appendChild(createXmlProperty(doc, "element1", terminalParent));
dom_element.appendChild(createXmlProperty(doc, "terminal1", terminal));
}
if (terminal2->uuid().isNull()) {
// legacy method to identify the terminal
dom_element.setAttribute("terminal2", table_adr_id.value(terminal2)); // for backward compability
terminal = terminal2->uuid();
terminalParent = terminal2->parentElement()->uuid();
if (terminalParent.isNull() || terminal.isNull()) {
// legacy when the terminal does not have a valid uuid
// do not store element1 information, because this is used to determine in the fromXml
// process that legacy file format
dom_element.appendChild(createXmlProperty(doc, "terminal2", terminal2->ID()));
} else {
dom_element.setAttribute("element2", terminal2->parentElement()->uuid().toString());
dom_element.setAttribute("terminal2", terminal2->uuid().toString());
dom_element.appendChild(createXmlProperty(doc, "element2", terminal2->parentElement()->uuid()));
dom_element.appendChild(createXmlProperty(doc, "terminal2", terminal2->uuid()));
}
dom_element.setAttribute("freezeLabel", m_freeze_label? "true" : "false");
dom_element.appendChild(createXmlProperty(doc, "freezeLabel", m_freeze_label));
// on n'exporte les segments du conducteur que si ceux-ci ont
// ete modifies par l'utilisateur
@@ -1056,33 +1023,32 @@ QDomElement Conductor::toXml(QDomDocument &dom_document,
QDomElement current_segment;
foreach(ConductorSegment *segment, segmentsList())
{
current_segment = dom_document.createElement("segment");
current_segment.setAttribute("orientation", segment -> isHorizontal() ? "horizontal" : "vertical");
current_segment.setAttribute("length", QString("%1").arg(segment -> length()));
current_segment = doc.createElement("segment");
current_segment.appendChild(createXmlProperty(doc, "orientation", segment->isHorizontal() ? "horizontal": "vertical"));
current_segment.appendChild(createXmlProperty(doc, "length", segment -> length()));
dom_element.appendChild(current_segment);
}
}
QDomElement dom_seq = m_autoNum_seq.toXml(dom_document);
QDomElement dom_seq = m_autoNum_seq.toXml(doc); // swquentialNumbers tag
dom_element.appendChild(dom_seq);
// Export the properties and text
m_properties. toXml(dom_element);
if(m_text_item->wasMovedByUser())
{
dom_element.setAttribute("userx", QString::number(m_text_item->pos().x()));
dom_element.setAttribute("usery", QString::number(m_text_item->pos().y()));
QDomElement conductorProperties = m_properties.toXml(doc);
for (int i=0; i < conductorProperties.childNodes().count(); i++) {
QDomNode node = conductorProperties.childNodes().at(i).cloneNode(); // cloneNode() is important!
dom_element.appendChild(node);
}
if(m_text_item->wasRotateByUser())
dom_element.setAttribute("rotation", QString::number(m_text_item->rotation()));
m_text_item->toXml(doc, dom_element);
return(dom_element);
}
/**
@brief Conductor::pathFromXml
Generate the path (of the line) from xml file by checking the segments in the xml
file
Generate the path (of the line) from xml file by checking
the segments in the xml file
@param e
@return true if generate path success else return false
*/
@@ -1096,14 +1062,21 @@ bool Conductor::pathFromXml(const QDomElement &e) {
if (current_segment.isNull() || current_segment.tagName() != "segment") continue;
// le segment doit avoir une longueur
if (!current_segment.hasAttribute("length")) continue;
qreal segment_length;
if (propertyDouble(current_segment, "length", & segment_length))
continue;
// cette longueur doit etre un reel
bool ok;
qreal segment_length = current_segment.attribute("length").toDouble(&ok);
if (!ok) continue;
bool isHorizontal = false;
QString orientation;
if (propertyString(current_segment, "orientation", &orientation) == PropertyFlags::Success) {
if (orientation == "horizontal")
isHorizontal = true;
} else {
qDebug() << "PathFromXML failed";
return false;
}
if (current_segment.attribute("orientation") == "horizontal") {
if (isHorizontal) {
segments_x << segment_length;
segments_y << 0.0;
} else {

View File

@@ -1,17 +1,17 @@
/*
Copyright 2006-2020 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -19,6 +19,7 @@
#define CONDUCTOR_H
#include "conductorproperties.h"
#include "propertiesinterface.h"
#include <QGraphicsPathItem>
#include "assignvariables.h"
@@ -39,7 +40,7 @@ typedef QHash<Qt::Corner, ConductorProfile> ConductorProfilesGroup;
This class represents a conductor, i.e. a wire between two element
terminals.
*/
class Conductor : public QGraphicsObject
class Conductor : public QGraphicsObject, public PropertiesInterface
{
Q_OBJECT
@@ -50,13 +51,13 @@ class Conductor : public QGraphicsObject
signals:
void propertiesChange();
public:
Conductor(Terminal *, Terminal *);
~Conductor() override;
bool isValid() const;
private:
Conductor(const Conductor &);
@@ -66,7 +67,7 @@ class Conductor : public QGraphicsObject
Terminal *terminal1;
Terminal *terminal2;
public:
/**
@brief type
@@ -100,11 +101,9 @@ class Conductor : public QGraphicsObject
public:
static bool valideXml (QDomElement &);
bool fromXml (QDomElement &);
QDomElement toXml (
QDomDocument &,
QHash<Terminal *,
int> &) const;
bool fromXml (const QDomElement &) override;
//QDomElement toXml (QDomDocument &, QHash<Terminal *, int> &) const;
QDomElement toXml (QDomDocument &doc) const override;
private:
bool pathFromXml(const QDomElement &);
@@ -137,7 +136,7 @@ class Conductor : public QGraphicsObject
{return m_autoNum_seq;}
void setSequenceNum(const autonum::sequentialNumbers& sn);
QList<QPointF> junctions() const;
QList<QPointF> junctions() const;
private:
void setUpConnectionForFormula(
@@ -146,10 +145,10 @@ class Conductor : public QGraphicsObject
public:
void setFreezeLabel(bool freeze);
public slots:
void displayedTextChanged();
protected:
void mouseDoubleClickEvent(
QGraphicsSceneMouseEvent *event) override;
@@ -165,7 +164,7 @@ class Conductor : public QGraphicsObject
private:
void adjusteHandlerPos();
void handlerMousePressEvent(
QetGraphicsHandlerItem *qghi,
QGraphicsSceneMouseEvent *event);
@@ -177,32 +176,32 @@ class Conductor : public QGraphicsObject
QGraphicsSceneMouseEvent *event);
void addHandler();
void removeHandler();
QVector<QetGraphicsHandlerItem *> m_handler_vector;
int m_vector_index = -1;
bool m_mouse_over;
bool m_mouse_over{false};
/// Functional properties
ConductorProperties m_properties;
/// Text input for non simple, non-singleline conductors
ConductorTextItem *m_text_item;
ConductorTextItem *m_text_item{nullptr};
/// Segments composing the conductor
ConductorSegment *segments;
ConductorSegment *segments{nullptr};
/// Attributs related to mouse interaction
bool m_moving_segment;
bool m_moving_segment{false};
int moved_point;
qreal m_previous_z_value;
ConductorSegment *m_moved_segment;
QPointF before_mov_text_pos_;
/// Whether the conductor was manually modified by users
bool modified_path;
bool modified_path{false};
/// Whether the current profile should be saved as soon as possible
bool has_to_save_profile;
bool has_to_save_profile{false};
/// conductor profile: "photography" of what the conductor is supposed to look
/// like - there is one profile per kind of traject
ConductorProfilesGroup conductor_profiles;
/// Define whether and how the conductor should be highlighted
Highlight must_highlight_;
Highlight must_highlight_{Conductor::None};
bool m_valid;
bool m_freeze_label = false;
@@ -211,7 +210,7 @@ class Conductor : public QGraphicsObject
static QBrush conductor_brush;
static bool pen_and_brush_initialized;
QPainterPath m_path;
private:
void segmentsToPath();
void saveProfile(bool = true);

View File

@@ -26,9 +26,7 @@
*/
ConductorTextItem::ConductorTextItem(Conductor *parent_conductor) :
DiagramTextItem(parent_conductor),
parent_conductor_(parent_conductor),
moved_by_user_(false),
rotate_by_user_(false)
parent_conductor_(parent_conductor)
{
setAcceptHoverEvents(true);
}
@@ -62,21 +60,36 @@ Conductor *ConductorTextItem::parentConductor() const
return(parent_conductor_);
}
void ConductorTextItem::toXml(QDomDocument& doc, QDomElement& e) {
if(moved_by_user_)
{
e.appendChild(PropertiesInterface::createXmlProperty(doc, "userx", pos().x()));
e.appendChild(PropertiesInterface::createXmlProperty(doc, "usery", pos().y()));
}
if(rotate_by_user_)
e.appendChild(PropertiesInterface::createXmlProperty(doc, "rotation", rotation()));
}
/**
@brief ConductorTextItem::fromXml
Read the properties stored in the xml element given in parameter
@param e
*/
void ConductorTextItem::fromXml(const QDomElement &e) {
if (e.hasAttribute("userx")) {
setPos(e.attribute("userx").toDouble(),
e.attribute("usery").toDouble());
moved_by_user_ = true;
}
if (e.hasAttribute("rotation")) {
setRotation(e.attribute("rotation").toDouble());
rotate_by_user_ = true;
}
double userx=0, usery=0;
if (PropertiesInterface::propertyDouble(e, "userx", &userx) == PropertiesInterface::PropertyFlags::Success &&
PropertiesInterface::propertyDouble(e, "usery", &usery) == PropertiesInterface::PropertyFlags::Success) {
setPos(userx, usery);
moved_by_user_ = true;
}
double rotation;
if (PropertiesInterface::propertyDouble(e, "rotation", &rotation) == PropertiesInterface::PropertyFlags::Success) {
setRotation(rotation);
rotate_by_user_ = true;
}
}
/**

View File

@@ -1,17 +1,17 @@
/*
Copyright 2006-2020 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -42,6 +42,7 @@ class ConductorTextItem : public DiagramTextItem
enum { Type = UserType + 1006 };
Conductor *parentConductor() const;
void fromXml(const QDomElement &) override;
void toXml(QDomDocument& doc, QDomElement& e);
int type() const override { return Type; }
virtual bool wasMovedByUser() const;
virtual bool wasRotateByUser() const;
@@ -61,8 +62,8 @@ class ConductorTextItem : public DiagramTextItem
// attributes
private:
Conductor *parent_conductor_;
bool moved_by_user_;
bool rotate_by_user_;
bool moved_by_user_{false};
bool rotate_by_user_{false};
QPointF before_mov_pos_;
};
#endif

View File

@@ -20,6 +20,8 @@
#include "qetapp.h"
#include "richtext/richtexteditor_p.h"
#include "diagram.h"
#include "dynamicelementtextitem.h"
/**
@brief DiagramTextItem::DiagramTextItem
@@ -218,12 +220,24 @@ QRectF DiagramTextItem::frameRect() const
void DiagramTextItem::setHtml(const QString &text)
{
DynamicElementTextItem* abc = dynamic_cast<DynamicElementTextItem*>(this);
if (abc) {
if (abc->searchedElement) {
int stop = 1;
}
}
QGraphicsTextItem::setHtml(text);
m_is_html = true;
}
void DiagramTextItem::setPlainText(const QString &text)
{
DynamicElementTextItem* abc = dynamic_cast<DynamicElementTextItem*>(this);
if (abc) {
if (abc->searchedElement) {
int stop = 1;
}
}
QGraphicsTextItem::setPlainText(text);
m_is_html = false;
}
@@ -243,6 +257,16 @@ bool DiagramTextItem::isHtml() const
*/
void DiagramTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
DynamicElementTextItem* abc = dynamic_cast<DynamicElementTextItem*>(this);
if (abc) {
if (abc->searchedElement) {
int stop = 1;
QString text = toPlainText();
qDebug() << text;
}
}
painter -> setRenderHint(QPainter::Antialiasing, false);
QGraphicsTextItem::paint(painter, option, widget);

View File

@@ -1,17 +1,17 @@
/*
Copyright 2006-2020 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -54,7 +54,7 @@ DynamicElementTextItem::DynamicElementTextItem(Element *parent_element) :
this->m_parent_element->diagram()->undoStack().push(undo);
}
});
//Option when text is displayed in multiple line
QTextOption option = document()->defaultTextOption();
option.setAlignment(Qt::AlignHCenter);
@@ -87,7 +87,7 @@ DynamicElementTextItem::DynamicElementTextItem()
QDomElement DynamicElementTextItem::toXml(QDomDocument &dom_doc) const
{
QDomElement root_element = dom_doc.createElement(xmlTagName());
root_element.setAttribute("x", QString::number(pos().x()));
root_element.setAttribute("y", QString::number(pos().y()));
root_element.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
@@ -95,10 +95,10 @@ QDomElement DynamicElementTextItem::toXml(QDomDocument &dom_doc) const
root_element.setAttribute("frame", m_frame? "true" : "false");
root_element.setAttribute("text_width", QString::number(m_text_width));
root_element.setAttribute("font", font().toString());
QMetaEnum me = textFromMetaEnum();
root_element.setAttribute("text_from", me.valueToKey(m_text_from));
me = QMetaEnum::fromType<Qt::Alignment>();
if(this->alignment() &Qt::AlignRight)
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignRight));
@@ -106,19 +106,19 @@ QDomElement DynamicElementTextItem::toXml(QDomDocument &dom_doc) const
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignLeft));
else if(this->alignment() &Qt::AlignHCenter)
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignHCenter));
if(this->alignment() &Qt::AlignBottom)
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignBottom));
else if(this->alignment() & Qt::AlignTop)
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignTop));
else if(this->alignment() &Qt::AlignVCenter)
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignVCenter));
QDomElement dom_text = dom_doc.createElement("text");
dom_text.appendChild(dom_doc.createTextNode(toPlainText()));
root_element.appendChild(dom_text);
//Info name
if(!m_info_name.isEmpty())
{
@@ -126,7 +126,7 @@ QDomElement DynamicElementTextItem::toXml(QDomDocument &dom_doc) const
dom_info_name.appendChild(dom_doc.createTextNode(m_info_name));
root_element.appendChild(dom_info_name);
}
//Composite text
if(!m_composite_text.isEmpty())
{
@@ -134,7 +134,7 @@ QDomElement DynamicElementTextItem::toXml(QDomDocument &dom_doc) const
dom_comp_text.appendChild(dom_doc.createTextNode(m_composite_text));
root_element.appendChild(dom_comp_text);
}
//Color
if(color() != QColor(Qt::black))
{
@@ -142,7 +142,7 @@ QDomElement DynamicElementTextItem::toXml(QDomDocument &dom_doc) const
dom_color.appendChild(dom_doc.createTextNode(color().name()));
root_element.appendChild(dom_color);
}
return root_element;
}
@@ -157,7 +157,7 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt)
qDebug() << "DynamicElementTextItem::fromXml : Wrong tagg name";
return;
}
QGraphicsTextItem::setRotation(dom_elmt.attribute("rotation", QString::number(0)).toDouble());
if (dom_elmt.hasAttribute("font"))
@@ -177,11 +177,11 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt)
m_uuid = QUuid(dom_elmt.attribute("uuid", QUuid::createUuid().toString()));
setFrame(dom_elmt.attribute("frame", "false") == "true"? true : false);
setTextWidth(dom_elmt.attribute("text_width", QString::number(-1)).toDouble());
//Text from
QMetaEnum me = textFromMetaEnum();
setTextFrom(DynamicElementTextItem::TextFrom(me.keyToValue(dom_elmt.attribute("text_from").toStdString().data())));
me = QMetaEnum::fromType<Qt::Alignment>();
if(dom_elmt.hasAttribute("Halignment"))
setAlignment(Qt::Alignment(me.keyToValue(dom_elmt.attribute("Halignment").toStdString().data())));
@@ -200,7 +200,7 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt)
QDomElement dom_info_name = dom_elmt.firstChildElement("info_name");
if(!dom_info_name.isNull())
setInfoName(dom_info_name.text());
//Composite text
QDomElement dom_comp_text = dom_elmt.firstChildElement("composite_text");
if(!dom_comp_text.isNull())
@@ -210,10 +210,10 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt)
QDomElement dom_color = dom_elmt.firstChildElement("color");
if(!dom_color.isNull())
setColor(QColor(dom_color.text()));
//Force the update of the displayed text
setTextFrom(m_text_from);
setTextFrom(m_text_from); // TODO: does not update because there is a retrun inside if the textfrom argument is the same as m_text_from
QGraphicsTextItem::setPos(dom_elmt.attribute("x", QString::number(0)).toDouble(),
dom_elmt.attribute("y", QString::number(0)).toDouble());
}
@@ -241,7 +241,7 @@ ElementTextItemGroup *DynamicElementTextItem::parentGroup() const
if(ElementTextItemGroup *grp = dynamic_cast<ElementTextItemGroup *>(parentItem()))
return grp;
}
return nullptr;
}
@@ -261,7 +261,7 @@ Element *DynamicElementTextItem::elementUseForInfo() const
Element *elmt = parentElement();
if(!elmt)
return nullptr;
switch (elmt->linkType())
{
case Element::Simple:
@@ -325,15 +325,18 @@ DynamicElementTextItem::TextFrom DynamicElementTextItem::textFrom() const
*/
void DynamicElementTextItem::setTextFrom(DynamicElementTextItem::TextFrom text_from)
{
if (searchedElement)
int stop = true;
if(m_text_from == text_from)
return;
setNoEditable(text_from == UserText? false : true);
clearFormulaConnection();
TextFrom old_text_from = m_text_from;
m_text_from = text_from;
if(m_text_from == UserText)
{
setPlainText(m_text);
@@ -348,7 +351,7 @@ void DynamicElementTextItem::setTextFrom(DynamicElementTextItem::TextFrom text_f
}
else
setPlainText(elementUseForInfo()->elementInformations().value(m_info_name).toString());
if(old_text_from == UserText)
connect(elementUseForInfo(), &Element::elementInfoChange, this, &DynamicElementTextItem::elementInfoChanged);
}
@@ -361,15 +364,15 @@ void DynamicElementTextItem::setTextFrom(DynamicElementTextItem::TextFrom text_f
}
else
setPlainText(autonum::AssignVariables::replaceVariable(m_composite_text, elementUseForInfo()->elementInformations()));
if(old_text_from == UserText)
connect(elementUseForInfo(), &Element::elementInfoChange, this, &DynamicElementTextItem::elementInfoChanged);
}
if(m_parent_element.data()->linkType() == Element::Master ||
m_parent_element.data()->linkType() == Element::Slave)
updateXref();
emit textFromChanged(m_text_from);
}
@@ -389,6 +392,9 @@ QString DynamicElementTextItem::text() const
*/
void DynamicElementTextItem::setText(const QString &text)
{
if (m_text == "14" && text == "")
int a = 54;
m_text_old = m_text;
m_text = text;
if(m_text_from == DynamicElementTextItem::UserText)
setPlainText(m_text);
@@ -405,7 +411,10 @@ void DynamicElementTextItem::setInfoName(const QString &info_name)
QString old_info_name = m_info_name;
m_info_name = info_name;
if (searchedElement)
int stop = true;
if(old_info_name == "label")
{
clearFormulaConnection();
@@ -429,7 +438,7 @@ void DynamicElementTextItem::setInfoName(const QString &info_name)
}
}
else if (m_info_name == "label" && elementUseForInfo())
{
{
setupFormulaConnection();
updateLabel();
updateXref();
@@ -437,7 +446,7 @@ void DynamicElementTextItem::setInfoName(const QString &info_name)
else if(elementUseForInfo() && m_text_from == DynamicElementTextItem::ElementInfo) {
setPlainText(elementUseForInfo()->elementInformations().value(info_name).toString());
}
emit infoNameChanged(info_name);
}
@@ -459,7 +468,7 @@ void DynamicElementTextItem::setCompositeText(const QString &text)
{
QString old_composite_text = m_composite_text;
m_composite_text = text;
if(old_composite_text.contains("%{label}"))
{
clearFormulaConnection();
@@ -478,7 +487,7 @@ void DynamicElementTextItem::setCompositeText(const QString &text)
removeConnectionForReportFormula(m_report_formula);
if(m_composite_text.contains("%{label}"))
setConnectionForReportFormula(m_report_formula);
updateReportText();
}
else if (m_composite_text.contains("%{label}") && elementUseForInfo())
@@ -494,7 +503,7 @@ void DynamicElementTextItem::setCompositeText(const QString &text)
dc = elementUseForInfo()->elementInformations();
setPlainText(autonum::AssignVariables::replaceVariable(m_composite_text, dc));
}
emit compositeTextChanged(m_composite_text);
}
@@ -539,7 +548,7 @@ void DynamicElementTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
if(m_slave_Xref_item)
m_slave_Xref_item->setDefaultTextColor(Qt::black);
}
DiagramTextItem::mousePressEvent(event);
}
@@ -548,33 +557,33 @@ void DynamicElementTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
@param event
*/
void DynamicElementTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
{
if((event->buttons() & Qt::LeftButton) && (flags() & ItemIsMovable))
{
if(diagram() && m_first_move)
diagram()->elementTextsMover().beginMovement(diagram(), this);
if(m_first_move)
{
m_initial_position = pos();
if(parentElement())
parentElement()->setHighlighted(true);
}
QPointF current_parent_pos;
QPointF button_down_parent_pos;
current_parent_pos = mapToParent(mapFromScene(event->scenePos()));
button_down_parent_pos = mapToParent(mapFromScene(event->buttonDownScenePos(Qt::LeftButton)));
QPointF new_pos = m_initial_position + current_parent_pos - button_down_parent_pos;
event->modifiers() == Qt::ControlModifier ? setPos(new_pos) : setPos(Diagram::snapToGrid(new_pos));
if(diagram())
diagram()->elementTextsMover().continueMovement(event);
} else {
event->ignore();
}
if(m_first_move)
m_first_move = false;
}
@@ -587,10 +596,10 @@ void DynamicElementTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (m_parent_element)
m_parent_element->setHighlighted(false);
if(m_parent_element && m_parent_element->diagram())
m_parent_element.data()->diagram()->elementTextsMover().endMovement();
if(!(event->modifiers() & Qt::ControlModifier))
QGraphicsTextItem::mouseReleaseEvent(event);
}
@@ -618,12 +627,12 @@ void DynamicElementTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *eve
void DynamicElementTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
DiagramTextItem::hoverEnterEvent(event);
//If the text is selected we set the real color, otherwise the editor will display the color of text as blue,
//but this is not the color set by the user.
if(isSelected())
return;
if ((parentElement()->linkType() & Element::AllReport) && m_other_report)
{
if( (m_text_from == ElementInfo && m_info_name == "label") ||
@@ -642,25 +651,25 @@ void DynamicElementTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
void DynamicElementTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
DiagramTextItem::hoverLeaveEvent(event);
if(m_user_color.isValid())
{
setDefaultTextColor(m_user_color);
m_user_color = QColor(); //m_user_color is now invalid
}
}
void DynamicElementTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
DiagramTextItem::paint(painter, option, widget);
if (m_frame)
{
painter->save();
painter->setFont(QETApp::dynamicTextsItemFont(font().pointSize()));
//Adjust the thickness according to the font size,
//Adjust the thickness according to the font size,
qreal w=0.3;
if(font().pointSize() >= 5)
{
@@ -668,7 +677,7 @@ void DynamicElementTextItem::paint(QPainter *painter, const QStyleOptionGraphics
if(w > 2.5)
w = 2.5;
}
QPen pen;
pen.setColor(color());
pen.setWidthF(w);
@@ -678,7 +687,7 @@ void DynamicElementTextItem::paint(QPainter *painter, const QStyleOptionGraphics
//Adjust the rounding of the rectangle according to the size of the font
qreal ro = font().pointSizeF()/3;
painter->drawRoundedRect(frameRect(), ro, ro);
painter->restore();
}
}
@@ -691,7 +700,7 @@ QVariant DynamicElementTextItem::itemChange(QGraphicsItem::GraphicsItemChange ch
{
if(m_parent_element.isNull())
return QGraphicsObject::itemChange(change, value);
//If the parent is slave, we keep aware about the changement of master.
if(m_parent_element.data()->linkType() == Element::Slave)
{
@@ -708,13 +717,13 @@ QVariant DynamicElementTextItem::itemChange(QGraphicsItem::GraphicsItemChange ch
m_report_formula = m_parent_element.data()->diagram()->project()->defaultReportProperties();
m_report_formula_con = connect(m_parent_element.data()->diagram()->project(), &QETProject::reportPropertiesChanged, this, &DynamicElementTextItem::reportFormulaChanged);
}
//Add connection to keep up to date the status of the element linked to the parent folio report of this text.
connect(m_parent_element.data(), &Element::linkedElementChanged, this, &DynamicElementTextItem::reportChanged);
//The parent is already linked, we call reportChanged for init the connection
if(!m_parent_element.data()->linkedElements().isEmpty())
reportChanged();
if(m_parent_element.data()->terminals().size())
{
//Add connection to keep up date the conductors added or removed to the parent folio report element
@@ -732,7 +741,7 @@ QVariant DynamicElementTextItem::itemChange(QGraphicsItem::GraphicsItemChange ch
if(!m_parent_element.data()->linkedElements().isEmpty())
updateXref();
}
m_first_scene_change = false;
return QGraphicsObject::itemChange(change, value);
}
@@ -741,7 +750,7 @@ QVariant DynamicElementTextItem::itemChange(QGraphicsItem::GraphicsItemChange ch
updateXref();
updateXref();
}
return QGraphicsObject::itemChange(change, value);
}
@@ -749,7 +758,7 @@ bool DynamicElementTextItem::sceneEventFilter(QGraphicsItem *watched, QEvent *ev
{
if(watched != m_slave_Xref_item)
return false;
if(event->type() == QEvent::GraphicsSceneHoverEnter) {
m_slave_Xref_item->setDefaultTextColor(Qt::blue);
return true;
@@ -762,7 +771,7 @@ bool DynamicElementTextItem::sceneEventFilter(QGraphicsItem *watched, QEvent *ev
zoomToLinkedElement();
return true;
}
return false;
}
@@ -773,7 +782,7 @@ void DynamicElementTextItem::elementInfoChanged()
if(element) {
dc = element->elementInformations();
}
QString final_text;
@@ -799,12 +808,12 @@ void DynamicElementTextItem::elementInfoChanged()
//connection if the label is created from a formula
if (m_composite_text.contains("%{label}"))
setupFormulaConnection();
final_text = autonum::AssignVariables::replaceVariable(m_composite_text, dc);
}
else if (m_text_from == UserText)
final_text = m_text;
setPlainText(final_text);
emit plainTextChanged();
}
@@ -823,16 +832,16 @@ void DynamicElementTextItem::masterChanged()
m_master_element.clear();
updateXref();
}
if(elementUseForInfo())
{
m_master_element = elementUseForInfo();
if(m_text_from == ElementInfo || m_text_from == CompositeText)
connect(m_master_element.data(), &Element::elementInfoChange, this, &DynamicElementTextItem::elementInfoChanged);
updateXref();
}
//Because master changed we update this text
elementInfoChanged();
}
@@ -859,23 +868,23 @@ void DynamicElementTextItem::reportChanged()
m_report_formula_con = connect(parentElement()->diagram()->project(), &QETProject::reportPropertiesChanged, this, &DynamicElementTextItem::reportFormulaChanged);
}
}
bool text_have_label = false;
if((textFrom() == ElementInfo && m_info_name == "label") ||
(textFrom() == CompositeText && m_composite_text.contains("%{label}")))
text_have_label = true;
if(text_have_label)
removeConnectionForReportFormula(m_report_formula);
m_other_report.clear();
if(!m_parent_element.data()->linkedElements().isEmpty())
m_other_report = m_parent_element.data()->linkedElements().first();
//Because linked report was changed, we ensure there is a conductor watched
setPotentialConductor();
if(text_have_label)
{
setConnectionForReportFormula(m_report_formula);
@@ -890,7 +899,7 @@ void DynamicElementTextItem::reportChanged()
void DynamicElementTextItem::reportFormulaChanged()
{
m_report_formula = parentElement()->diagram()->project()->defaultReportProperties();
if(m_text_from == ElementInfo && m_info_name == "label")
updateReportText();
}
@@ -899,11 +908,11 @@ void DynamicElementTextItem::setConnectionForReportFormula(const QString &formul
{
if(m_other_report.isNull() || formula.isEmpty())
return;
Element *other_elmt = m_other_report.data();
QString string = formula;
Diagram *other_diagram = m_other_report.data()->diagram();
//Because the variable %F is a reference to another text which can contain variables,
//we must to replace %F by the real text, to check if the real text contain the variable %id
if (other_diagram && string.contains("%F"))
@@ -912,7 +921,7 @@ void DynamicElementTextItem::setConnectionForReportFormula(const QString &formul
string.replace("%F", other_diagram->border_and_titleblock.folio());
connect(&other_diagram->border_and_titleblock, &BorderTitleBlock::titleBlockFolioChanged, this, &DynamicElementTextItem::updateReportFormulaConnection);
}
if (other_diagram && (string.contains("%f") || string.contains("%id")))
{
connect(other_diagram->project(), &QETProject::projectDiagramsOrderChanged, this, &DynamicElementTextItem::updateReportText);
@@ -928,11 +937,11 @@ void DynamicElementTextItem::removeConnectionForReportFormula(const QString &for
{
if(m_other_report.isNull() || formula.isEmpty())
return;
Element *other_element = m_other_report.data();
QString string = formula;
Diagram *other_diagram = m_other_report.data()->diagram();
//Because the variable %F is a reference to another text which can contain variables,
//we must to replace %F by the real text, to check if the real text contain the variable %id
if (other_diagram && string.contains("%F"))
@@ -940,14 +949,14 @@ void DynamicElementTextItem::removeConnectionForReportFormula(const QString &for
string.replace("%F", m_F_str);
disconnect(&other_diagram->border_and_titleblock, &BorderTitleBlock::titleBlockFolioChanged, this, &DynamicElementTextItem::updateReportFormulaConnection);
}
if (other_diagram && (string.contains("%f") || string.contains("%id")))
disconnect(other_diagram->project(), &QETProject::projectDiagramsOrderChanged, this, &DynamicElementTextItem::updateReportText);
if (string.contains("%l"))
disconnect(other_element, &Element::yChanged, this, &DynamicElementTextItem::updateReportText);
if (string.contains("%c"))
disconnect(other_element, &Element::xChanged, this, &DynamicElementTextItem::updateReportText);
}
/**
@@ -960,25 +969,25 @@ void DynamicElementTextItem::setupFormulaConnection()
(m_text_from == CompositeText && m_composite_text.contains("%{label}")))
{
clearFormulaConnection();
Element *element = elementUseForInfo();
if (!element)
return;
Diagram *diagram = element->diagram();
QString formula = element->elementInformations().value("formula").toString();
//Label is frozen, so we don't update it.
if (element->isFreezeLabel())
return;
if (diagram && formula.contains("%F"))
{
m_F_str = diagram->border_and_titleblock.folio();
formula.replace("%F", m_F_str);
m_formula_connection << connect(&diagram->border_and_titleblock, &BorderTitleBlock::titleBlockFolioChanged, this, &DynamicElementTextItem::updateLabel);
}
if (diagram && (formula.contains("%f") || formula.contains("%id")))
{
m_formula_connection << connect(diagram->project(), &QETProject::projectDiagramsOrderChanged, this, &DynamicElementTextItem::updateLabel);
@@ -988,7 +997,7 @@ void DynamicElementTextItem::setupFormulaConnection()
m_formula_connection << connect(element, &Element::yChanged, this, &DynamicElementTextItem::updateLabel);
if (formula.contains("%c"))
m_formula_connection << connect(element, &Element::xChanged, this, &DynamicElementTextItem::updateLabel);
}
}
@@ -1003,7 +1012,7 @@ void DynamicElementTextItem::updateReportFormulaConnection()
{
if(!(m_parent_element.data()->linkType() & Element::AllReport))
return;
removeConnectionForReportFormula(m_report_formula);
setConnectionForReportFormula(m_report_formula);
updateReportText();
@@ -1017,7 +1026,7 @@ void DynamicElementTextItem::updateReportText()
{
if(!(m_parent_element.data()->linkType() & Element::AllReport))
return;
if (m_text_from == ElementInfo && m_info_name == "label")
{
if(m_other_report)
@@ -1053,7 +1062,7 @@ void DynamicElementTextItem::updateLabel()
if(element) {
dc = element->elementInformations();
}
if(m_text_from == ElementInfo && element) {
setPlainText(element->actualLabel());
@@ -1101,7 +1110,7 @@ void DynamicElementTextItem::setPotentialConductor()
{
if(parentElement()->terminals().isEmpty())
return;
/*
* #First case, if m_watched_conductor is a conductor of the parent report, everything is ok
* #Second case, if the conductors list of parent report element is not empty,
@@ -1111,14 +1120,14 @@ void DynamicElementTextItem::setPotentialConductor()
* #third case, if m_watched_conductor is null, we set a conductor of the linked report, if any.
*/
QList<Conductor *> c_list = parentElement()->terminals().first()->conductors();
if(!c_list.isEmpty() && c_list.contains(m_watched_conductor.data()))
return;
else if(!c_list.isEmpty())
{
if(!m_watched_conductor.isNull())
disconnect(m_watched_conductor.data(), &Conductor::propertiesChange, this, &DynamicElementTextItem::conductorPropertiesChanged);
m_watched_conductor = c_list.first();
connect(m_watched_conductor.data(), &Conductor::propertiesChange, this, &DynamicElementTextItem::conductorPropertiesChanged);
}
@@ -1135,7 +1144,7 @@ void DynamicElementTextItem::setPotentialConductor()
{
if(!m_watched_conductor.isNull())
disconnect(m_watched_conductor.data(), &Conductor::propertiesChange, this, &DynamicElementTextItem::conductorPropertiesChanged);
m_watched_conductor.clear();
}
}
@@ -1174,11 +1183,11 @@ void DynamicElementTextItem::conductorPropertiesChanged()
QString DynamicElementTextItem::reportReplacedCompositeText() const
{
QString string;
if(m_parent_element.data()->linkType() & Element::AllReport)
{
string = m_composite_text;
if (string.contains("%{label}") && m_other_report)
{
Element *elmt = m_other_report.data();
@@ -1198,7 +1207,7 @@ QString DynamicElementTextItem::reportReplacedCompositeText() const
string.replace("%{conductor_section}", m_watched_conductor.data()->properties().m_wire_section);
}
}
return string;
}
@@ -1211,9 +1220,9 @@ void DynamicElementTextItem::zoomToLinkedElement()
{
if(!parentElement())
return;
Element *zoomed_element = nullptr;
if(parentElement()->linkType() == Element::Slave && m_master_element)
{
if ((m_text_from == ElementInfo && m_info_name == "label") ||
@@ -1226,18 +1235,18 @@ void DynamicElementTextItem::zoomToLinkedElement()
(m_text_from == CompositeText && m_composite_text.contains("%{label}")))
zoomed_element = m_other_report.data();
}
if(zoomed_element)
{
//Unselect and ungrab mouse to prevent unwanted
//move when linked element is in the same scene of this.
setSelected(false);
ungrabMouse();
if(scene() != zoomed_element->scene())
zoomed_element->diagram()->showMe();
zoomed_element->setSelected(true);
//Zoom to the element
for(QGraphicsView *view : zoomed_element->scene()->views())
{
@@ -1259,7 +1268,7 @@ void DynamicElementTextItem::updateXref()
if(m_parent_element.data()->linkType() == Element::Master)
{
XRefProperties xrp = diagram()->project()->defaultXRefProperties(m_parent_element.data()->kindInformations()["type"].toString());
if(m_text_from == DynamicElementTextItem::ElementInfo &&
m_info_name == "label" &&
!m_parent_element.data()->linkedElements().isEmpty() &&
@@ -1286,13 +1295,13 @@ void DynamicElementTextItem::updateXref()
XRefProperties xrp = diagram()->project()->defaultXRefProperties(m_master_element.data()->kindInformations()["type"].toString());
QString xref_label = xrp.slaveLabel();
xref_label = autonum::AssignVariables::formulaToLabel(xref_label, m_master_element.data()->rSequenceStruct(), m_master_element.data()->diagram(), m_master_element.data());
if(!m_slave_Xref_item)
{
m_slave_Xref_item = new QGraphicsTextItem(xref_label, this);
m_slave_Xref_item->setFont(QETApp::diagramTextsFont(5));
m_slave_Xref_item->installSceneEventFilter(this);
m_update_slave_Xref_connection << connect(m_master_element.data(), &Element::xChanged, this, &DynamicElementTextItem::updateXref);
m_update_slave_Xref_connection << connect(m_master_element.data(), &Element::yChanged, this, &DynamicElementTextItem::updateXref);
m_update_slave_Xref_connection << connect(m_master_element.data(), &Element::elementInfoChange, this, &DynamicElementTextItem::updateXref);
@@ -1314,7 +1323,7 @@ void DynamicElementTextItem::updateXref()
delete m_Xref_item;
m_Xref_item = nullptr;
}
if(m_slave_Xref_item)
{
delete m_slave_Xref_item;
@@ -1325,6 +1334,8 @@ void DynamicElementTextItem::updateXref()
void DynamicElementTextItem::setPlainText(const QString &text)
{
if (text == "14")
searchedElement = true;
if (toPlainText() == text)
return;
@@ -1335,13 +1346,13 @@ void DynamicElementTextItem::setPlainText(const QString &text)
if (m_parent_element.data()->state() == QET::GIBuildingFromXml ||
m_parent_element.data()->state() == QET::GILoadingFromXml)
update_alignment = false;
if (update_alignment) {
prepareAlignment();
}
DiagramTextItem::setPlainText(text);
//User define a text width
if (m_text_width > 0)
{
@@ -1354,11 +1365,11 @@ void DynamicElementTextItem::setPlainText(const QString &text)
}
}
}
if (update_alignment) {
finishAlignment();
}
if (m_Xref_item) {
m_Xref_item->autoPos();
}

View File

@@ -1,17 +1,17 @@
/*
Copyright 2006-2020 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -33,7 +33,7 @@ class CrossRefItem;
@brief The DynamicElementTextItem class
This class provide a simple text field of element who can be added or removed directly from the diagram editor.
This text is created to compensate a big lack of the ElementTextItem : ElementTextItem can't be added or removed directly in the diagram editor
*/
class DynamicElementTextItem : public DiagramTextItem
{
@@ -77,7 +77,7 @@ class DynamicElementTextItem : public DiagramTextItem
private:
DynamicElementTextItem ();
DynamicElementTextItem(const DynamicElementTextItem &);
public:
QDomElement toXml(QDomDocument &dom_doc) const override;
void fromXml(const QDomElement &dom_elmt) override;
@@ -104,6 +104,7 @@ class DynamicElementTextItem : public DiagramTextItem
void setTextWidth(qreal width);
void setXref_item(Qt::AlignmentFlag m_exHrefPos);
bool searchedElement{false};
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
@@ -140,22 +141,20 @@ class DynamicElementTextItem : public DiagramTextItem
m_master_element,
m_other_report;
QPointer <Conductor> m_watched_conductor;
QString
m_text,
m_info_name,
m_composite_text,
m_report_formula,
m_F_str;
QString m_text,
m_text_old,
m_info_name,
m_composite_text,
m_report_formula,
m_F_str;
DynamicElementTextItem::TextFrom m_text_from = UserText;
QUuid m_uuid;
QMetaObject::Connection m_report_formula_con;
QList<QMetaObject::Connection>
m_formula_connection,
m_update_slave_Xref_connection;
QColor m_user_color;
bool
m_frame = false,
m_first_scene_change = true;
QList<QMetaObject::Connection> m_formula_connection,
m_update_slave_Xref_connection;
QColor m_user_color{QColor()};
bool m_frame = false,
m_first_scene_change = true;
CrossRefItem *m_Xref_item = nullptr;
QGraphicsTextItem *m_slave_Xref_item = nullptr;
qreal m_text_width = -1;

View File

@@ -73,16 +73,15 @@ class ElementXmlRetroCompatibility
/**
@brief Element::Element
@param location : location of this element
@param parent : parent graphics item
@param state : state of the instanciation
@param link_type
New element from xml
@param location, location of this element
@param parent, parent graphics item
@param state, state of the instanciation
*/
Element::Element(
const ElementsLocation &location,
QGraphicsItem *parent,
int *state,
kind link_type) :
int *state, kind link_type) :
QetGraphicsItem(parent),
m_link_type (link_type),
m_location (location)
@@ -96,7 +95,8 @@ Element::Element(
}
}
int elmt_state;
buildFromXml(location.xml(), &elmt_state);
qDebug() << "\tCollection Path: " << location.collectionPath();
buildFromXml(location.xml(), &elmt_state); // build from the collection definition
if (state) {
*state = elmt_state;
}
@@ -387,7 +387,7 @@ void Element::drawHighlight(
/**
@brief Element::buildFromXml
Build this element from an xml description
Build this element from an xml description (from the collection)
@param xml_def_elmt
@param state
Optional pointer which define the status of build
@@ -476,7 +476,8 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
if (elmts.tagName() == "description")
{
//Minor workaround to find if there is a "input" tagg as label.
//If not, we set the tagg "label" to the first "input.
//If not, we set the tagg "label" to the first "input. Why one must have a tagg label?
// is label a required field?
QList <QDomElement> input_field;
bool have_label = false;
for (QDomElement input_node = node.firstChildElement("input") ;
@@ -504,11 +505,15 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
if (qde.isNull())
continue;
if (parseElement(qde)) {
qDebug() << "\t\tElement.cpp:buildFromXml;parseElement: " << qde.tagName();
if (parseElement(qde)) { // TODO: why lines are not parsed here?
qDebug() << "\t\t\tParsing Element success";
++ parsed_elements_count;
}
else
{
qDebug() << "\t\t\tParsing Element no success";
if (state)
*state = 7;
m_state = QET::GIOK;
@@ -534,13 +539,11 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
m_state = QET::GIOK;
return(false);
}
else
{
if (state)
*state = 0;
m_state = QET::GIOK;
return(true);
}
if (state)
*state = 0;
m_state = QET::GIOK;
return(true);
}
/**
@@ -650,7 +653,11 @@ Terminal *Element::parseTerminal(const QDomElement &dom_element)
return nullptr;
}
Terminal *new_terminal = new Terminal(data, this);
if (!Terminal::valideXml(dom_element))
return nullptr;
Terminal *new_terminal = new Terminal(0, 0, Qet::Orientation::North, this); // does not matter which values are typed in here, because they get overwritten by the fromXML() function
new_terminal->fromXml(dom_element);
m_terminals << new_terminal;
//Sort from top to bottom and left to rigth
@@ -664,8 +671,7 @@ Terminal *Element::parseTerminal(const QDomElement &dom_element)
else
return (a->dockConductor().y() < b->dockConductor().y());
});
return(new_terminal);
return(new_terminal); // TODO: makes not sense
}
/**
@@ -715,23 +721,37 @@ bool Element::fromXml(
les bornes vont maintenant etre recensees pour associer leurs id a leur adresse reelle
ce recensement servira lors de la mise en place des fils
*/
QList<QDomElement> liste_terminals;
foreach(QDomElement qde,
QET::findInDomElement(e, "terminals", "terminal")) {
QList<QDomElement> liste_terminals; // terminals in the element in the diagram
foreach(QDomElement qde, QET::findInDomElement(e, "terminals", "terminal")) {
if (Terminal::valideXml(qde)) liste_terminals << qde;
}
QHash<int, Terminal *> priv_id_adr;
int terminals_non_trouvees = 0;
foreach(QGraphicsItem *qgi, childItems()) {
// The added childs from the collection now must match with the terminals from the diagram. Iterate through
// all Terminals in the collection and in the diagram to link them together
for(QGraphicsItem *qgi: childItems()) { // TODO: Where the Terminals are added as childs?
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
bool terminal_trouvee = false;
foreach(QDomElement qde, liste_terminals) {
if (p -> fromXml(qde)) {
priv_id_adr.insert(
qde.attribute(
"id").toInt(),
p);
for(QDomElement qde: liste_terminals)
{
// The position in the collection element definition is the origin position (originPos).
// The position in the diagram element definition is the position where the conductor is connected (dock position)
// Therefore a simple operator overloading is not possible.
Terminal diagramTerminal(0,0, Qet::Orientation::East);
diagramTerminal.fromXml(qde);
QPointF dockPos1 = diagramTerminal.originPos(); // position here is directly the dock_elmt_ position (stored in the diagram)
QPointF dockPos2 = p->dockPos();
if (qFuzzyCompare(dockPos1.x(), dockPos2.x()) &&
qFuzzyCompare(dockPos1.y(), dockPos2.y()) &&
p->orientation() == diagramTerminal.orientation()) { // check if the part in the collection is the same as in the diagram stored
qDebug() << "Matching Terminal found.";
// store id for legacy purpose, because when opening a old project in the collection the terminal does not have an uuid. Therefore the id must be used
if (p->uuid().isNull()) {
p->setID(qde.attribute("id").toInt());
}
priv_id_adr.insert(qde.attribute("id").toInt(), p);
terminal_trouvee = true;
// We used to break here, because we did not expect
// several terminals to share the same position.
@@ -744,6 +764,7 @@ bool Element::fromXml(
if (terminals_non_trouvees > 0)
{
qDebug() << "element.cpp: Element::fromXML; Elements not found: " << terminals_non_trouvees;
m_state = QET::GIOK;
return(false);
}
@@ -788,6 +809,8 @@ bool Element::fromXml(
QString fl = e.attribute("freezeLabel", "false");
m_freeze_label = fl == "false"? false : true;
// TODO: why element information is not read?
//Load Sequential Values
if (e.hasAttribute("sequ_1")
|| e.hasAttribute("sequf_1")
@@ -824,10 +847,9 @@ bool Element::fromXml(
//************************//
//***Dynamic texts item***//
//************************//
for (const QDomElement& qde : QET::findInDomElement(
e,
"dynamic_texts",
DynamicElementTextItem::xmlTagName()))
// read from the diagram section
// this is not done in the older versions, because there only inputs are available.
for (const QDomElement& qde : QET::findInDomElement(e, "dynamic_texts", DynamicElementTextItem::xmlTagName()))
{
DynamicElementTextItem *deti = new DynamicElementTextItem(this);
addDynamicTextItem(deti);
@@ -837,27 +859,27 @@ bool Element::fromXml(
//************************//
//***Element texts item***//
//************************//
QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input");
QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input"); // inputs in diagram section
//First case, we check for the text item converted to dynamic text item
const QList <DynamicElementTextItem *> conv_deti_list =
m_converted_text_from_xml_description.keys();
QList <DynamicElementTextItem *> successfully_converted;
const QList <QDomElement> dom_inputs = inputs;
for (DynamicElementTextItem *deti : conv_deti_list)
// TODO: Legacy (0.7 and prior)
for (DynamicElementTextItem *deti : conv_deti_list) // elements read from the element collection definition
{
for(const QDomElement& dom_input : dom_inputs)
for(const QDomElement& dom_input : dom_inputs) // elements in the diagram section
{
//we use the same method used in ElementTextItem::fromXml
//to compar and know if the input dom element is for one of the text stored.
//The comparaison is made from the text position :
//if the position of the text is the same as the position stored in 'input' dom element
//that mean this is the good text
if (qFuzzyCompare(qreal(dom_input.attribute("x").toDouble()),
m_converted_text_from_xml_description.value(deti).x()) &&
qFuzzyCompare(qreal(dom_input.attribute("y").toDouble()),
m_converted_text_from_xml_description.value(deti).y()))
//we use the same method used in ElementTextItem::fromXml to compar and know if the input dom element is for one of the text stored.
//The comparaison is made from the text position : if the position of the text is the same as the position stored in 'input' dom element
//that mean this is the good text
// This is only used when in the diagram description the text elements are stored in the "inputs" section. In 0.8 and higher,
// texts are stored in directly in the "dynamic_elmt_text" section
if (qFuzzyCompare(qreal(dom_input.attribute("x").toDouble()), m_converted_text_from_xml_description.value(deti).x()) &&
qFuzzyCompare(qreal(dom_input.attribute("y").toDouble()), m_converted_text_from_xml_description.value(deti).y()))
{
//Once again this 'if', is only for retrocompatibility with old old old project
//when element text with tagg "label" is not null, but the element information "label" is.
@@ -1164,10 +1186,8 @@ bool Element::fromXml(
\~ @return The XML element representing this electrical element
\~French L'element XML representant cet element electrique
*/
QDomElement Element::toXml(
QDomDocument &document,
QHash<Terminal *,
int> &table_adr_id) const
QDomElement Element::toXml(QDomDocument &document) const
{
QDomElement element = document.createElement("element");
@@ -1194,19 +1214,6 @@ QDomElement Element::toXml(
element.setAttribute("z", QString::number(this->zValue()));
element.setAttribute("orientation", QString::number(orientation()));
/* get the first id to use for the bounds of this element
* recupere le premier id a utiliser pour les bornes de cet element */
int id_terminal = 0;
if (!table_adr_id.isEmpty()) {
// trouve le plus grand id
int max_id_t = -1;
foreach (int id_t, table_adr_id.values()) {
if (id_t > max_id_t) max_id_t = id_t;
}
id_terminal = max_id_t + 1;
}
// registration of device terminals
// enregistrement des bornes de l'appareil
QDomElement xml_terminals = document.createElement("terminals");
// for each child of the element
@@ -1214,8 +1221,10 @@ QDomElement Element::toXml(
foreach(Terminal *t, terminals()) {
// alors on enregistre la borne
QDomElement terminal = t -> toXml(document);
terminal.setAttribute("id", id_terminal); // for backward compatibility
table_adr_id.insert(t, id_terminal ++);
if (t->ID() > 0) {
// for backward compatibility
terminal.setAttribute("id", t->ID()); // for backward compatibility
}
xml_terminals.appendChild(terminal);
}
element.appendChild(xml_terminals);

View File

@@ -38,7 +38,7 @@ class ElementTextItemGroup;
/**
This is the base class for electrical elements.
*/
class Element : public QetGraphicsItem
class Element : public QetGraphicsItem // TODO: derive from propertiesInterface!
{
friend class DiagramEventAddElement;
@@ -46,22 +46,20 @@ class Element : public QetGraphicsItem
public:
/**
@brief The kind enum
Used to know the kind of this element
(master, slave, report ect...)
Used to know the kind of this element (master, slave, report ect...)
*/
enum kind {
Simple = 1,
NextReport = 2,
PreviousReport = 4,
AllReport = 6,
Master = 8,
Slave = 16,
Terminale = 32};
enum kind {Simple = 1,
NextReport = 2,
PreviousReport = 4,
AllReport = 6,
Master = 8,
Slave = 16,
Terminale = 32};
Element(const ElementsLocation &location,
QGraphicsItem * = nullptr,
int *state = nullptr,
Element::kind link_type = Element::Simple);
Element(
const ElementsLocation &location,
QGraphicsItem * parent= nullptr, int *state = nullptr,
Element::kind link_type = Element::Simple);
~Element() override;
private:
Element(const Element &);
@@ -130,17 +128,10 @@ class Element : public QetGraphicsItem
QPoint hotspot() const;
void editProperty() override;
static bool valideXml(QDomElement &);
virtual bool fromXml(
QDomElement &,
QHash<int,
Terminal *> &);
virtual QDomElement toXml(
QDomDocument &,
QHash<Terminal *,
int> &) const;
virtual bool fromXml(QDomElement &, QHash<int, Terminal *> &);
virtual QDomElement toXml(QDomDocument &) const;
QUuid uuid() const;
int orientation() const;
//METHODS related to texts
void addDynamicTextItem(DynamicElementTextItem *deti = nullptr);
void removeDynamicTextItem(DynamicElementTextItem *deti);

View File

@@ -437,6 +437,7 @@ QDomElement ElementTextItemGroup::toXml(QDomDocument &dom_document) const
return dom_element;
}
// TOOD: inherit from propertiesinterface
/**
@brief ElementTextItemGroup::fromXml
Import data of this group from xml

View File

@@ -32,10 +32,10 @@ class CrossRefItem;
This class represent a group of element text
Texts in the group can be aligned left / center /right
*/
class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
class ElementTextItemGroup : public QObject, public QGraphicsItemGroup // TODO: derive from PropertiesInterface
{
Q_OBJECT
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
Q_PROPERTY(int verticalAdjustment READ verticalAdjustment WRITE setVerticalAdjustment NOTIFY verticalAdjustmentChanged)
@@ -43,7 +43,7 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(bool holdToBottomPage READ holdToBottomPage WRITE setHoldToBottomPage NOTIFY holdToBottomPageChanged)
Q_PROPERTY(bool frame READ frame WRITE setFrame NOTIFY frameChanged)
public:
signals:
void rotationChanged(qreal);
@@ -54,14 +54,14 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
void xChanged();
void yChanged();
void frameChanged(bool frame);
public:
ElementTextItemGroup(const QString &name, Element *parent);
~ElementTextItemGroup() override;
void addToGroup(QGraphicsItem *item);
void removeFromGroup(QGraphicsItem *item);
void blockAlignmentUpdate(bool block);
void setAlignment(Qt::Alignment alignement);
Qt::Alignment alignment() const;
void updateAlignment();
@@ -76,11 +76,11 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
QList<DynamicElementTextItem *> texts() const;
Diagram *diagram() const;
Element *parentElement() const;
QDomElement toXml(QDomDocument &dom_document) const;
void fromXml(QDomElement &dom_element);
static QString xmlTaggName() {return QString("texts_group");}
void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget) override;
@@ -88,7 +88,7 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
void setRotation(qreal angle);
void setPos(const QPointF &pos);
void setPos(qreal x, qreal y);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
@@ -99,7 +99,7 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
void keyPressEvent(QKeyEvent *event) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
private:
void updateXref();
void adjustSlaveXrefPos();
@@ -108,11 +108,12 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
private:
Qt::Alignment m_alignment = Qt::AlignJustify;
QString m_name;
bool m_first_move = true,
bool
m_first_move = true,
m_hold_to_bottom_of_page = false,
m_block_alignment_update = false,
m_frame = false;
QPointF m_initial_position;
QPointF m_initial_position{QPointF(0,0)};
int m_vertical_adjustment = 0;
CrossRefItem *m_Xref_item = nullptr;
Element *m_parent_element = nullptr;

View File

@@ -50,6 +50,7 @@ IndependentTextItem::~IndependentTextItem()
{
}
// TODO: inherit from PropertiesInterface
/**
Permet de lire le texte a mettre dans le champ a partir d'un element XML.
Cette methode se base sur la position du champ pour assigner ou non la

View File

@@ -24,10 +24,7 @@
@param parent : Parent Item
*/
QetGraphicsItem::QetGraphicsItem(QGraphicsItem *parent):
QGraphicsObject(parent),
is_movable_(true),
m_first_move(true),
snap_to_grid_(true)
QGraphicsObject(parent)
{}
QetGraphicsItem::~QetGraphicsItem()

View File

@@ -55,10 +55,10 @@ class QetGraphicsItem : public QGraphicsObject
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
protected:
bool is_movable_;
bool m_first_move;
bool snap_to_grid_;
QPointF m_mouse_to_origin_movement;
bool is_movable_{true};
bool m_first_move{true};
bool snap_to_grid_{true};
QPointF m_mouse_to_origin_movement{QPointF(0,0)};
QET::GraphicsItemState m_state = QET:: GIOK;
};

View File

@@ -835,6 +835,7 @@ void QetShapeItem::handlerMouseReleaseEvent()
}
}
// TODO: inherit from Propertiesinterface!
/**
@brief QetShapeItem::fromXml
Build this item from the xml description

View File

@@ -26,14 +26,13 @@
Default constructor
@param location location of xml definition
@param qgi parent QGraphicItem
@param s parent diagram
@param state int used to know if the creation of element have error
*/
SlaveElement::SlaveElement(const ElementsLocation &location,
QGraphicsItem *qgi,
int *state) :
Element(location, qgi, state, Element::Slave)
SlaveElement::SlaveElement(
const ElementsLocation &location, QGraphicsItem *parent, int *state) :
Element(location, parent, state, Element::Slave)
{
m_xref_item = nullptr;
}
/**

View File

@@ -25,17 +25,17 @@ class SlaveElement : public Element
{
Q_OBJECT
public:
explicit SlaveElement (
explicit SlaveElement (
const ElementsLocation &,
QGraphicsItem * = nullptr,
QGraphicsItem * parent= nullptr,
int * = nullptr);
~SlaveElement() override;
void linkToElement(Element *elmt) override;
void unlinkAllElements() override;
void unlinkElement(Element *elmt) override;
private:
QGraphicsTextItem *m_xref_item;
QGraphicsTextItem *m_xref_item{nullptr};
};
#endif // SLAVEELEMENT_H

View File

@@ -30,7 +30,7 @@ QColor Terminal::neutralColor = QColor(Qt::blue);
QColor Terminal::allowedColor = QColor(Qt::darkGreen);
QColor Terminal::warningColor = QColor("#ff8000");
QColor Terminal::forbiddenColor = QColor(Qt::red);
const qreal Terminal::terminalSize = 4.0;
const qreal Terminal::terminalSize = 4.0; // TODO: store terminalSize in terminaldata, because in PartTerminal there is the same parameter. So only one is needed
const qreal Terminal::Z = 1000;
/**
@@ -40,11 +40,8 @@ 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) {
@@ -57,17 +54,15 @@ void Terminal::init(
// Number of terminal
number_terminal_ = std::move(number);
// Name of terminal
name_terminal_ = std::move(name);
d->m_name = std::move(name);
name_terminal_hidden = hiddenName;
// par defaut : pas de conducteur
// QRectF null
br_ = new QRectF();
previous_terminal_ = nullptr;
// divers
setAcceptHoverEvents(true);
setAcceptedMouseButtons(Qt::LeftButton);
hovered_ = false;
setToolTip(QObject::tr("Borne", "tooltip"));
setZValue(Z);
}
@@ -214,10 +209,18 @@ void Terminal::setNumber(QString number)
*/
void Terminal::setName(QString name, bool hiddenName)
{
name_terminal_ = std::move(name);
d->m_name = std::move(name);
name_terminal_hidden = hiddenName;
}
/**
@brief Terminal::name
@return the name of terminal.
*/
inline QString Terminal::name() const {
return(d->m_name);
}
/**
@brief Terminal::addConductor
Add a conductor to this terminal
@@ -745,6 +748,10 @@ bool Terminal::canBeLinkedTo(Terminal *other_terminal)
return true;
}
void Terminal::setID(int id) {
m_id = id;
}
/**
@brief Terminal::conductors
@return La liste des conducteurs lies a cette borne
@@ -764,15 +771,24 @@ QDomElement Terminal::toXml(QDomDocument &doc) const
{
QDomElement qdo = doc.createElement("terminal");
// for backward compatibility
qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x()));
qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y()));
// end for backward compatibility
qdo.appendChild(createXmlProperty(doc, "number", number_terminal_));
qdo.appendChild(createXmlProperty(doc, "nameHidden", name_terminal_hidden));
// store terminal data too!
// Do not store terminal data in its own child
// Bad hack. The problem is that in the diagrams the terminal is described by the position and in the Collection by the dock.
QPointF tempPos = d->m_pos;
d->m_pos = dock_elmt_;
QDomElement terminalDataElement = d->toXml(doc);
d->m_pos = tempPos;
int childsCount = terminalDataElement.childNodes().count();
for (int i=0; i < childsCount; i++) {
QDomNode node = terminalDataElement.childNodes().at(i).cloneNode(); // cloneNode() is important, otherwise no deep clone is made
qdo.appendChild(node);
}
qdo.setAttribute("orientation", d->m_orientation);
qdo.setAttribute("number", number_terminal_);
qdo.setAttribute("name", name_terminal_);
qdo.setAttribute("nameHidden", name_terminal_hidden);
return(qdo);
}
@@ -782,42 +798,24 @@ 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)
{
// verifie le nom du tag
bool Terminal::valideXml(const QDomElement &terminal) {
if (terminal.tagName() != "terminal") return(false);
// verifie la presence des attributs minimaux
if (!terminal.hasAttribute("x")) return(false);
if (!terminal.hasAttribute("y")) return(false);
if (!terminal.hasAttribute("orientation")) return(false);
// affuteuse_250h.qet contains in line 8398 terminals which do not have this
// if (propertyString(terminal, "number"))
// return false;
// affuteuse_250h.qet contains in line 8398 terminals which do not have this
// if (propertyBool(terminal, "nameHidden"))
// return false;
bool conv_ok;
// parse l'abscisse
terminal.attribute("x").toDouble(&conv_ok);
if (!conv_ok) return(false);
// parse l'ordonnee
terminal.attribute("y").toDouble(&conv_ok);
if (!conv_ok) return(false);
// parse l'id
terminal.attribute("id").toInt(&conv_ok);
if (!conv_ok) return(false);
// parse l'orientation
int terminal_or = terminal.attribute("orientation").toInt(&conv_ok);
if (!conv_ok) return(false);
if (terminal_or != Qet::North
&& terminal_or != Qet::South
&& terminal_or != Qet::East
&& terminal_or != Qet::West) return(false);
if (!TerminalData::valideXml(terminal))
return false;
// a ce stade, la borne est syntaxiquement correcte
return(true);
return true;
}
/**
/** RETURNS True
@brief Terminal::fromXml
Permet de savoir si un element XML represente cette borne. Attention,
l'element XML n'est pas verifie
@@ -825,17 +823,17 @@ 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(const QDomElement &terminal)
{
number_terminal_ = terminal.attribute("number");
name_terminal_ = terminal.attribute("name");
name_terminal_hidden = terminal.attribute("nameHidden").toInt();
propertyString(terminal, "number", &number_terminal_);
return (
qFuzzyCompare(terminal.attribute("x").toDouble(), dock_elmt_.x()) &&
qFuzzyCompare(terminal.attribute("y").toDouble(), dock_elmt_.y()) &&
(terminal.attribute("orientation").toInt() == d->m_orientation)
);
propertyBool(terminal, "nameHidden", &name_terminal_hidden);
if(!d->fromXml(terminal))
return false;
init(number_terminal_, d->m_name, name_terminal_hidden); // initialize dock_elmt_. This must be done after Terminal data is initialized
return true;
}
/**
@@ -872,6 +870,18 @@ QUuid Terminal::uuid() const
return d->m_uuid;
}
int Terminal::ID() const {
return m_id;
}
QPointF Terminal::dockPos() {
return dock_elmt_;
}
QPointF Terminal::originPos() {
return d->m_pos;
}
/**
@brief Conductor::relatedPotentialTerminal
Return terminal at the same potential from the same

View File

@@ -20,6 +20,8 @@
#include <QtWidgets>
#include <QtXml>
#include "qet.h"
#include "propertiesinterface.h"
class Conductor;
class Diagram;
class Element;
@@ -31,7 +33,7 @@ class TerminalData;
plug point for conductors.
This class handles all mouse events for connecting conductors
*/
class Terminal : public QGraphicsObject
class Terminal : public QGraphicsObject, public PropertiesInterface
{
Q_OBJECT
@@ -78,6 +80,10 @@ class Terminal : public QGraphicsObject
Element *parentElement () const;
QUuid uuid () const;
int ID() const;
QPointF dockPos();
QPointF originPos();
QList<Conductor *> conductors() const;
Qet::Orientation orientation() const;
QPointF dockConductor() const;
@@ -89,10 +95,12 @@ class Terminal : public QGraphicsObject
bool isLinkedTo(Terminal *);
bool canBeLinkedTo(Terminal *);
void setID(int id);
// methods related to XML import/export
static bool valideXml(QDomElement &);
bool fromXml (QDomElement &);
QDomElement toXml (QDomDocument &) const;
static bool valideXml(const QDomElement &);
bool fromXml (const QDomElement &) override;
QDomElement toXml (QDomDocument &) const override;
protected:
// methods related to events management
@@ -109,7 +117,8 @@ class Terminal : public QGraphicsObject
static const qreal terminalSize;
static const qreal Z;
// Various static colors used for hover effects
// Various static colors used for hover effects.
// The assignement is in the cpp file
/// default color
static QColor neutralColor;
/// color for legal actions
@@ -142,16 +151,18 @@ class Terminal : public QGraphicsObject
*/
QRectF *br_{nullptr};
/// Last terminal seen through an attached conductor
Terminal *previous_terminal_;
Terminal *previous_terminal_{nullptr};
/// Whether the mouse pointer is hovering the terminal
bool hovered_;
bool hovered_{false};
/// Color used for the hover effect
QColor hovered_color_;
QColor hovered_color_{Terminal::hovered_color_};
/// Number of Terminal
QString number_terminal_;
/// Name of Terminal
QString name_terminal_;
bool name_terminal_hidden;
bool name_terminal_hidden{true};
/// legacy id used by the conductor to find the terminal. From 0.8x on the uuid is used instead.
int m_id{-1};
private:
void init(QString number, QString name, bool hiddenName);
@@ -176,16 +187,6 @@ inline QString Terminal::number() const
{
return(number_terminal_);
}
/**
@brief Terminal::name
@return the name of terminal.
*/
inline QString Terminal::name() const
{
return(name_terminal_);
}
QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal,
const bool all_diagram = true);