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

@@ -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);