| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include <QUrl>
|
|---|
| 43 | #include <QVector>
|
|---|
| 44 | #include <QXmlNamePool>
|
|---|
| 45 |
|
|---|
| 46 | #include "qabstractxmlnodemodel_p.h"
|
|---|
| 47 | #include "qemptyiterator_p.h"
|
|---|
| 48 | #include "qitemmappingiterator_p.h"
|
|---|
| 49 | #include "qsequencemappingiterator_p.h"
|
|---|
| 50 | #include "qsimplexmlnodemodel.h"
|
|---|
| 51 | #include "qsingletoniterator_p.h"
|
|---|
| 52 |
|
|---|
| 53 | QT_BEGIN_NAMESPACE
|
|---|
| 54 |
|
|---|
| 55 | using namespace QPatternist;
|
|---|
| 56 |
|
|---|
| 57 | class QSimpleXmlNodeModelPrivate : public QAbstractXmlNodeModelPrivate
|
|---|
| 58 | {
|
|---|
| 59 | public:
|
|---|
| 60 | QSimpleXmlNodeModelPrivate(const QXmlNamePool &np) : namePool(np)
|
|---|
| 61 | {
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | mutable QXmlNamePool namePool;
|
|---|
| 65 | };
|
|---|
| 66 |
|
|---|
| 67 | /*!
|
|---|
| 68 | \class QSimpleXmlNodeModel
|
|---|
| 69 | \brief The QSimpleXmlNodeModel class is an implementation of QAbstractXmlNodeModel sufficient for many common cases.
|
|---|
| 70 | \reentrant
|
|---|
| 71 | \since 4.4
|
|---|
| 72 | \ingroup xml-tools
|
|---|
| 73 |
|
|---|
| 74 | Subclassing QAbstractXmlNodeModel can be a significant task, because it
|
|---|
| 75 | requires implementing several, complex member functions. QSimpleXmlNodeModel
|
|---|
| 76 | provides default implementations of these member functions that are suitable
|
|---|
| 77 | for a wide range of node models.
|
|---|
| 78 |
|
|---|
| 79 | Subclasses of QSimpleXmlNodeModel must be thread-safe.
|
|---|
| 80 | */
|
|---|
| 81 |
|
|---|
| 82 | /*!
|
|---|
| 83 | Constructs a QSimpleXmlNodeModel for use with with the specified
|
|---|
| 84 | \a namePool.
|
|---|
| 85 | */
|
|---|
| 86 | QSimpleXmlNodeModel::QSimpleXmlNodeModel(const QXmlNamePool &namePool)
|
|---|
| 87 | : QAbstractXmlNodeModel(new QSimpleXmlNodeModelPrivate(namePool))
|
|---|
| 88 | {
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | /*!
|
|---|
| 92 | Destructor.
|
|---|
| 93 | */
|
|---|
| 94 | QSimpleXmlNodeModel::~QSimpleXmlNodeModel()
|
|---|
| 95 | {
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | /*!
|
|---|
| 99 | If \a node is an element or attribute, typedValue() is called, and
|
|---|
| 100 | the return value converted to a string, as per XQuery's rules.
|
|---|
| 101 |
|
|---|
| 102 | If \a node is another type of node, the empty string is returned.
|
|---|
| 103 |
|
|---|
| 104 | If this function is overridden for comments or processing
|
|---|
| 105 | instructions, it is important to remember to call it (for elements
|
|---|
| 106 | and attributes having values not of type \c xs:string) to ensure that
|
|---|
| 107 | the values are formatted according to XQuery.
|
|---|
| 108 |
|
|---|
| 109 | */
|
|---|
| 110 | QString QSimpleXmlNodeModel::stringValue(const QXmlNodeModelIndex &node) const
|
|---|
| 111 | {
|
|---|
| 112 | const QXmlNodeModelIndex::NodeKind k= kind(node);
|
|---|
| 113 | if(k == QXmlNodeModelIndex::Element || k == QXmlNodeModelIndex::Attribute)
|
|---|
| 114 | {
|
|---|
| 115 | const QVariant &candidate = typedValue(node);
|
|---|
| 116 | if(candidate.isNull())
|
|---|
| 117 | return QString();
|
|---|
| 118 | else
|
|---|
| 119 | return AtomicValue::toXDM(candidate).stringValue();
|
|---|
| 120 | }
|
|---|
| 121 | else
|
|---|
| 122 | return QString();
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | /*!
|
|---|
| 126 | Returns the base URI for \a node. This is always the document
|
|---|
| 127 | URI.
|
|---|
| 128 |
|
|---|
| 129 | \sa documentUri()
|
|---|
| 130 | */
|
|---|
| 131 | QUrl QSimpleXmlNodeModel::baseUri(const QXmlNodeModelIndex &node) const
|
|---|
| 132 | {
|
|---|
| 133 | return documentUri(node);
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | /*!
|
|---|
| 137 | Returns the name pool associated with this model. The
|
|---|
| 138 | implementation of name() will use this name pool to create
|
|---|
| 139 | names.
|
|---|
| 140 | */
|
|---|
| 141 | QXmlNamePool &QSimpleXmlNodeModel::namePool() const
|
|---|
| 142 | {
|
|---|
| 143 | Q_D(const QSimpleXmlNodeModel);
|
|---|
| 144 |
|
|---|
| 145 | return d->namePool;
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | /*!
|
|---|
| 149 | Always returns an empty QVector. This signals that no namespace
|
|---|
| 150 | bindings are in scope for \a node.
|
|---|
| 151 | */
|
|---|
| 152 | QVector<QXmlName> QSimpleXmlNodeModel::namespaceBindings(const QXmlNodeModelIndex &node) const
|
|---|
| 153 | {
|
|---|
| 154 | Q_UNUSED(node);
|
|---|
| 155 | return QVector<QXmlName>();
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | /*!
|
|---|
| 159 | Always returns a default constructed QXmlNodeModelIndex instance,
|
|---|
| 160 | regardless of \a id.
|
|---|
| 161 |
|
|---|
| 162 | This effectively means the model has no elements that have an id.
|
|---|
| 163 | */
|
|---|
| 164 | QXmlNodeModelIndex QSimpleXmlNodeModel::elementById(const QXmlName &id) const
|
|---|
| 165 | {
|
|---|
| 166 | Q_UNUSED(id);
|
|---|
| 167 | return QXmlNodeModelIndex();
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | /*!
|
|---|
| 171 | Always returns an empty vector, regardless of \a idref.
|
|---|
| 172 |
|
|---|
| 173 | This effectively means the model has no elements or attributes of
|
|---|
| 174 | type \c IDREF.
|
|---|
| 175 | */
|
|---|
| 176 | QVector<QXmlNodeModelIndex> QSimpleXmlNodeModel::nodesByIdref(const QXmlName &idref) const
|
|---|
| 177 | {
|
|---|
| 178 | Q_UNUSED(idref);
|
|---|
| 179 | return QVector<QXmlNodeModelIndex>();
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | QT_END_NAMESPACE
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|