mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Compare commits
10 Commits
master
...
XMLPropert
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2b911da14 | ||
|
|
539de96455 | ||
|
|
2a4416469a | ||
|
|
0fbadc727d | ||
|
|
d805fb9ced | ||
|
|
ba0faa7122 | ||
|
|
87d810744f | ||
|
|
1dabe930f2 | ||
|
|
c3c13d5102 | ||
|
|
f6c1a47d62 |
@@ -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
|
||||
|
||||
@@ -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 &);
|
||||
|
||||
@@ -72,12 +72,23 @@ bool PartTerminal::fromXmlPriv(const QDomElement &xml_elmt) {
|
||||
*/
|
||||
void PartTerminal::toXmlPriv(QDomElement& e) const {
|
||||
|
||||
e.setAttribute("uuid", d->m_uuid.toString());
|
||||
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));
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
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"))
|
||||
@@ -1050,8 +1043,17 @@ void Conductor::toXmlPriv(QDomElement& dom_element) const {
|
||||
QDomElement dom_seq = m_autoNum_seq.toXml(doc);
|
||||
dom_element.appendChild(dom_seq);
|
||||
|
||||
// Export the properties and text
|
||||
dom_element.appendChild(m_properties. toXml(doc));
|
||||
// Export the properties and text
|
||||
// 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()));
|
||||
|
||||
@@ -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,8 +944,15 @@ 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);
|
||||
}
|
||||
element.appendChild(xml_terminals);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user