some clean-up for "elementInformations" in element-file

- for some time now and for whatever reason, element-editor
  sometimes adds element-information without content –> do not
  save info-lines without any content
- sort element-information alphabetically by name in element-file
- use trimmed strings for element-information to remove leading
  and trailing whitestpace
This commit is contained in:
plc-user 2025-02-05 13:11:37 +01:00
parent b0324bd6e8
commit 408481a023
2 changed files with 7 additions and 3 deletions

View File

@ -151,10 +151,14 @@ bool DiagramContext::operator!=(const DiagramContext &dc) const
void DiagramContext::toXml(QDomElement &e, const QString &tag_name) const
{
foreach (QString key, keys()) {
if (m_content[key].toString().trimmed().isEmpty()) { continue; }
QDomElement property = e.ownerDocument().createElement(tag_name);
// try to sort attributes by removing and re-adding
property.removeAttribute("show");
property.removeAttribute("name");
property.setAttribute("show", m_content_show[key]);
property.setAttribute("name", key);
property.setAttribute("show",m_content_show[key]);
QDomText value = e.ownerDocument().createTextNode(m_content[key].toString());
QDomText value = e.ownerDocument().createTextNode(m_content[key].toString().trimmed());
property.appendChild(value);
e.appendChild(property);
}

View File

@ -99,7 +99,7 @@ class DiagramContext
void add(DiagramContext other);
void remove(const QString &key);
QList<QString> keys(KeyOrder = None) const;
QList<QString> keys(KeyOrder = Alphabetical) const;
bool contains(const QString &) const;
const QVariant operator[](const QString &) const;
bool addValue(const QString &, const QVariant &, bool show = true);