diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-02-18 12:37:52 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-02-18 12:37:52 +0000 |
| commit | 54576ab2d36c6736d3720fc4cfbcfc659c279e23 (patch) | |
| tree | 22b5e62b3e684563d71a3a2d075b464fa37cefc1 /source | |
| parent | 5479c36ba68c9b06300a0b1b4830d21a5415daf7 (diff) | |
| download | qxmpp-54576ab2d36c6736d3720fc4cfbcfc659c279e23.tar.gz | |
introduce QXmppElementList
Diffstat (limited to 'source')
| -rw-r--r-- | source/QXmppElement.cpp | 27 | ||||
| -rw-r--r-- | source/QXmppElement.h | 16 |
2 files changed, 38 insertions, 5 deletions
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> QXmppElement::children() const +QXmppElementList QXmppElement::children() const { return m_children; } -void QXmppElement::setChildren(QList<QXmppElement> &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<QXmppElement> &other) + : QList<QXmppElement>(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 <QXmlStreamWriter> class QDomElement; +class QXmppElement; + +class QXmppElementList : public QList<QXmppElement> +{ +public: + QXmppElementList(); + QXmppElementList(const QXmppElement &element); + QXmppElementList(const QList<QXmppElement> &other); +}; class QXmppElement { @@ -41,8 +50,9 @@ public: QString attribute(const QString &name) const; void setAttribute(const QString &name, const QString &value); - QList<QXmppElement> children() const; - void setChildren(QList<QXmppElement> &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<QString, QString> m_attributes; - QList<QXmppElement> m_children; + QXmppElementList m_children; QString m_tagName; QString m_value; }; |
