From 54576ab2d36c6736d3720fc4cfbcfc659c279e23 Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Thu, 18 Feb 2010 12:37:52 +0000 Subject: introduce QXmppElementList --- source/QXmppElement.cpp | 27 +++++++++++++++++++++++++-- source/QXmppElement.h | 16 +++++++++++++--- 2 files changed, 38 insertions(+), 5 deletions(-) (limited to 'source') diff --git a/source/QXmppElement.cpp b/source/QXmppElement.cpp index 3820f35e..5bcbeed6 100644 --- a/source/QXmppElement.cpp +++ b/source/QXmppElement.cpp @@ -73,16 +73,24 @@ void QXmppElement::setAttribute(const QString &name, const QString &value) m_attributes.insert(name, value); } -QList QXmppElement::children() const +QXmppElementList QXmppElement::children() const { return m_children; } -void QXmppElement::setChildren(QList &children) +void QXmppElement::setChildren(const QXmppElementList &children) { m_children = children; } +QXmppElement QXmppElement::firstChild(const QString &name) const +{ + foreach (const QXmppElement &child, m_children) + if (child.tagName() == name) + return child; + return QXmppElement(); +} + bool QXmppElement::isNull() const { return m_tagName.isEmpty(); @@ -122,3 +130,18 @@ void QXmppElement::toXml(QXmlStreamWriter *writer) const writer->writeEndElement(); } +QXmppElementList::QXmppElementList() +{ +} + +QXmppElementList::QXmppElementList(const QXmppElement &element) +{ + append(element); +} + + +QXmppElementList::QXmppElementList(const QList &other) + : QList(other) +{ +} + diff --git a/source/QXmppElement.h b/source/QXmppElement.h index d684ddd3..58ec6918 100644 --- a/source/QXmppElement.h +++ b/source/QXmppElement.h @@ -29,6 +29,15 @@ #include class QDomElement; +class QXmppElement; + +class QXmppElementList : public QList +{ +public: + QXmppElementList(); + QXmppElementList(const QXmppElement &element); + QXmppElementList(const QList &other); +}; class QXmppElement { @@ -41,8 +50,9 @@ public: QString attribute(const QString &name) const; void setAttribute(const QString &name, const QString &value); - QList children() const; - void setChildren(QList &children); + QXmppElementList children() const; + QXmppElement firstChild(const QString &name) const; + void setChildren(const QXmppElementList &children); QString tagName() const; void setTagName(const QString &type); @@ -55,7 +65,7 @@ public: private: QMap m_attributes; - QList m_children; + QXmppElementList m_children; QString m_tagName; QString m_value; }; -- cgit v1.2.3