1
0
mirror of https://github.com/altlinux/admc.git synced 2025-03-20 02:50:07 +03:00

add parent_name field to XmlAttribute

This commit is contained in:
Dmitry Degtyarev 2020-09-10 12:47:37 +04:00
parent 2296b8104e
commit e5d1560a80
2 changed files with 31 additions and 0 deletions

View File

@ -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<XmlAttributeType, QString> attribute_type_to_string_map = {
{XmlAttributeType_String, "string"},
{XmlAttributeType_Boolean, "boolean"},

View File

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