From e5d1560a801d85504d4bc956f2b4e20b08763dc9 Mon Sep 17 00:00:00 2001 From: Dmitry Degtyarev Date: Thu, 10 Sep 2020 12:47:37 +0400 Subject: [PATCH] add parent_name field to XmlAttribute --- src/gpgui/gui/xml/xml_attribute.cpp | 29 +++++++++++++++++++++++++++++ src/gpgui/gui/xml/xml_attribute.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/src/gpgui/gui/xml/xml_attribute.cpp b/src/gpgui/gui/xml/xml_attribute.cpp index a8b5611f..500a8d5c 100644 --- a/src/gpgui/gui/xml/xml_attribute.cpp +++ b/src/gpgui/gui/xml/xml_attribute.cpp @@ -34,6 +34,31 @@ XmlAttribute::XmlAttribute(const QDomNode &node) { const QDomNode attribute_use = attributes.namedItem("use"); m_required = (attribute_use.nodeValue() == "required"); + + auto get_parent_name = + [node]() -> QString { + QDomNode current = node.parentNode(); + while (!current.isNull()) { + const bool is_element = (current.nodeName() == "xs:element"); + + if (is_element) { + const QDomNamedNodeMap current_attributes = current.attributes(); + const QDomNode name_node = current_attributes.namedItem("name"); + const QString name = name_node.nodeValue(); + + return name; + } + + current = current.parentNode(); + } + + return QString(); + }; + m_parent_name = get_parent_name(); + + if (m_parent_name.isEmpty()) { + printf("Failed to find parent name for attribute %s!\n", qPrintable(name())); + } } void XmlAttribute::print() const { @@ -69,6 +94,10 @@ bool XmlAttribute::hidden() const { return is_hidden; } +QString XmlAttribute::parent_name() const { + return m_parent_name; +} + const QHash attribute_type_to_string_map = { {XmlAttributeType_String, "string"}, {XmlAttributeType_Boolean, "boolean"}, diff --git a/src/gpgui/gui/xml/xml_attribute.h b/src/gpgui/gui/xml/xml_attribute.h index e32b0787..b5868f04 100644 --- a/src/gpgui/gui/xml/xml_attribute.h +++ b/src/gpgui/gui/xml/xml_attribute.h @@ -43,11 +43,13 @@ public: bool required() const; bool hidden() const; QString display_string() const; + QString parent_name() const; private: QString m_name; XmlAttributeType m_type; bool m_required; + QString m_parent_name; }; QString attribute_type_to_string(const XmlAttributeType type);