Compare commits

...

10 Commits

Author SHA1 Message Date
Martin Marmsoler
f2b911da14 do not save conductorproperties in own child, but as part of conductor 2021-03-14 13:37:08 +01:00
Martin Marmsoler
539de96455 Fix problem when really old elements are added to a new project. These elements do not have an uuid for each terminal. So when exporting, save an unique ID into the terminal. So the conductors know to which terminal they must be connected 2021-03-14 11:49:01 +01:00
Martin Marmsoler
2a4416469a set tagname for PartText 2021-03-14 10:48:28 +01:00
Martin Marmsoler
0fbadc727d store terminalData in the terminal tag. Fixes the drag problem from the collection into the diagram. The problem was that some tags missed and therefore the creation of the element for dragging was unsuccessful 2021-03-14 08:29:26 +01:00
Martin Marmsoler
d805fb9ced read terminal uuid in Terminal and do not write terminal uuid from TerminalData, because Terminal just reads it, only PartTerminal writes the uuid 2021-03-13 18:57:01 +01:00
Martin Marmsoler
ba0faa7122 uuid gets already stored in the terminalData, so no need to store it again in the terminal it self 2021-03-13 18:25:12 +01:00
Martin Marmsoler
87d810744f use failed instead of no success, so the traces can be filtered more easily 2021-03-13 18:10:40 +01:00
Martin Marmsoler
1dabe930f2 fix terminal data problems 2021-03-13 18:10:06 +01:00
Martin Marmsoler
c3c13d5102 store also terminal data when storing terminal. Was accidentaly removed in 5d3710c4b2 2021-03-13 18:09:52 +01:00
Martin Marmsoler
f6c1a47d62 do not store invalid uuid, better to not store and use legacy approach 2021-03-13 17:27:12 +01:00
9 changed files with 93 additions and 22 deletions

View File

@@ -1864,6 +1864,28 @@ void Diagram::changeZValue(QET::DepthOption option)
delete undo;
}
int Diagram::uniqueTerminalID() const
{
for (int i=1; i < 10000; i++) {
bool found = false;
for (auto element: elements()) {
for (auto terminal: element->terminals()) {
if (terminal->ID() == i) {
found = true;
break;
}
}
if (found) {
break;
}
}
if (!found)
return i;
}
return -1;
}
/**
@brief Diagram::loadElmtFolioSeq
This class loads all folio sequential variables related

View File

@@ -257,6 +257,13 @@ class Diagram : public QGraphicsScene
NumerotationContext *nc);
void changeZValue(QET::DepthOption option);
/*!
* \brief uniqueTerminalID
* Determines a new unique Terminal ID
* This is used only for legacy purpose
*/
int uniqueTerminalID() const;
public slots:
void adjustSceneRect ();
void titleChanged(const QString &);

View File

@@ -72,12 +72,23 @@ bool PartTerminal::fromXmlPriv(const QDomElement &xml_elmt) {
*/
void PartTerminal::toXmlPriv(QDomElement& e) const {
if (!d->m_uuid.isNull())
e.setAttribute("uuid", d->m_uuid.toString());
d->m_pos = pos();
QDomDocument doc = e.ownerDocument();
e.appendChild(d -> toXml(doc));
QDomElement terminalData = d -> toXml(doc);
// Copy everything from terminalData to terminal
for (int i=0; i < terminalData.attributes().count(); i++) {
QDomAttr attr = terminalData.attributes().item(i).toAttr();
e.setAttribute(attr.name(), attr.value());
}
// for (int i=0; i < terminalData.childNodes().count(); i++) {
// e.appendChild(terminalData.childNodes().at(i));
// }
}

View File

@@ -35,6 +35,7 @@ PartText::PartText(QETElementEditor *editor, QGraphicsItem *parent) :
CustomElementPart(editor),
previous_text()
{
setTagName("text");
document() -> setDocumentMargin(1.0);
setDefaultTextColor(Qt::black);
setFont(QETApp::diagramTextsFont());

View File

@@ -95,10 +95,9 @@ void TerminalData::fromSettings(QSettings &settings, const QString& prefix)
*/
void TerminalData::toXmlPriv(QDomElement& xml_element) const
{
xml_element.setAttribute("x", QString("%1").arg(q->scenePos().x()));
xml_element.setAttribute("y", QString("%1").arg(q->scenePos().y()));
xml_element.setAttribute("x", m_pos.x());
xml_element.setAttribute("y", m_pos.y());
xml_element.setAttribute("uuid", m_uuid.toString());
xml_element.setAttribute("name", m_name);
xml_element.setAttribute("orientation",
@@ -163,6 +162,9 @@ bool TerminalData::valideXml(const QDomElement& xml_element) {
if (QETXML::propertyDouble(xml_element, "x"))
return false;
if (QETXML::propertyDouble(xml_element, "y"))
return false;
// Old projects do not have this property.
// if (QETXML::propertyString(xml_element, "type"))
// return false;

View File

@@ -56,14 +56,16 @@ class TerminalData : public PropertiesInterface
const QString& prefix = QString()) const override;
void fromSettings(QSettings &settings,
const QString& = QString()) override;
void toXmlPriv(QDomElement &xml_element) const override;
bool fromXmlPriv(const QDomElement &xml_element) override;
static bool valideXml(const QDomElement &xml_element);
static QString typeToString(TerminalData::Type type);
static TerminalData::Type typeFromString(const QString &string);
private:
void toXmlPriv(QDomElement &xml_element) const override;
bool fromXmlPriv(const QDomElement &xml_element) override;
// must be public, because this class is a private member
// of PartTerminal/Terminal and they must access this data
public:

View File

@@ -976,15 +976,8 @@ bool Conductor::fromXmlPriv(const QDomElement &dom_element)
m_text_item -> fromXml(dom_element);
auto prs = QETXML::findInDomElement(dom_element, ConductorProperties::xmlTagName());
ConductorProperties pr;
if (!prs.isEmpty()) {
pr.fromXml(prs.first());
} else {
// legacy
// added in 0.9 remove in later version!
pr.fromXml(dom_element);
}
//Load Sequential Values
if (dom_element.hasAttribute("sequ_1") || dom_element.hasAttribute("sequf_1") || dom_element.hasAttribute("seqt_1") || dom_element.hasAttribute("seqtf_1") || dom_element.hasAttribute("seqh_1") || dom_element.hasAttribute("sequf_1"))
@@ -1051,7 +1044,16 @@ void Conductor::toXmlPriv(QDomElement& dom_element) const {
dom_element.appendChild(dom_seq);
// Export the properties and text
dom_element.appendChild(m_properties. toXml(doc));
// Do not add properties as own child, but add the properties to the conductor it self
//dom_element.appendChild(m_properties. toXml(doc));
// Copy everything from comductorProperties to Conductor
auto ConductorProperties = m_properties. toXml(doc);
for (int i=0; i < ConductorProperties.attributes().count(); i++) {
QDomAttr attr = ConductorProperties.attributes().item(i).toAttr();
dom_element.setAttribute(attr.name(), attr.value());
}
if(m_text_item->wasMovedByUser())
{
dom_element.setAttribute("userx", QString::number(m_text_item->pos().x()));

View File

@@ -527,7 +527,7 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
}
else
{
qDebug() << "\t\t\tParsing Element no success";
qDebug() << "\t\t\tParsing Element failed";
if (state)
*state = 7;
m_state = QET::GIOK;
@@ -944,7 +944,14 @@ QDomElement Element::toXml(
QDomElement terminal = t -> toXml(document);
if (t->ID() > 0) {
// for backward compatibility
// Terminal was loaded during loading an old project. So the terminal has a valid id
terminal.setAttribute("id", t->ID()); // for backward compatibility
} else if (t->uuid().isNull()) {
// for backward compatibility
// An old element with no uuid on the terminals was added to the project.
// give it an id
t->setID(t->diagram()->uniqueTerminalID());
terminal.setAttribute("id", t->ID());
}
xml_terminals.appendChild(terminal);
}

View File

@@ -761,11 +761,28 @@ QList<Conductor *> Terminal::conductors() const
void Terminal::toXmlPriv(QDomElement &qdo) const
{
// for backward compatibility
qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x()));
qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y()));
qdo.setAttribute("number", number_terminal_);
qdo.setAttribute("nameHidden", name_terminal_hidden);
// end for backward compatibility
qdo.setAttribute("orientation", d->m_orientation);
// 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_;
QDomDocument doc = qdo.ownerDocument();
QDomElement terminalData = d->toXml(doc); // TerminalData
d->m_pos = tempPos;
// Copy everything from terminalData to terminal
for (int i=0; i < terminalData.attributes().count(); i++) {
QDomAttr attr = terminalData.attributes().item(i).toAttr();
qdo.setAttribute(attr.name(), attr.value());
}
// for (int i=0; i < terminalData.childNodes().count(); i++) {
// qdo.appendChild(terminalData.childNodes().at(i));
// }
}
/**
@@ -802,8 +819,8 @@ bool Terminal::valideXml(const QDomElement &terminal)
*/
bool Terminal::fromXmlPriv(const QDomElement &terminal) {
QETXML::propertyString(terminal, "number", &number_terminal_);
QETXML::propertyBool(terminal, "nameHidden", &name_terminal_hidden);
QETXML::propertyUuid(terminal, "uuid", &d->m_uuid);
if(!d->fromXml(terminal))
return false;