1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
44 #include <QXmlNamePool>
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"
55 using namespace QPatternist;
57 class QSimpleXmlNodeModelPrivate : public QAbstractXmlNodeModelPrivate
60 QSimpleXmlNodeModelPrivate(const QXmlNamePool &np) : namePool(np)
64 mutable QXmlNamePool namePool;
68 \class QSimpleXmlNodeModel
69 \brief The QSimpleXmlNodeModel class is an implementation of QAbstractXmlNodeModel sufficient for many common cases.
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.
79 Subclasses of QSimpleXmlNodeModel must be thread-safe.
83 Constructs a QSimpleXmlNodeModel for use with with the specified
86 QSimpleXmlNodeModel::QSimpleXmlNodeModel(const QXmlNamePool &namePool)
87 : QAbstractXmlNodeModel(new QSimpleXmlNodeModelPrivate(namePool))
94 QSimpleXmlNodeModel::~QSimpleXmlNodeModel()
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.
102 If \a node is another type of node, the empty string is returned.
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.
110 QString QSimpleXmlNodeModel::stringValue(const QXmlNodeModelIndex &node) const
112 const QXmlNodeModelIndex::NodeKind k= kind(node);
113 if(k == QXmlNodeModelIndex::Element || k == QXmlNodeModelIndex::Attribute)
115 const QVariant &candidate = typedValue(node);
116 if(candidate.isNull())
119 return AtomicValue::toXDM(candidate).stringValue();
126 Returns the base URI for \a node. This is always the document
131 QUrl QSimpleXmlNodeModel::baseUri(const QXmlNodeModelIndex &node) const
133 return documentUri(node);
137 Returns the name pool associated with this model. The
138 implementation of name() will use this name pool to create
141 QXmlNamePool &QSimpleXmlNodeModel::namePool() const
143 Q_D(const QSimpleXmlNodeModel);
149 Always returns an empty QVector. This signals that no namespace
150 bindings are in scope for \a node.
152 QVector<QXmlName> QSimpleXmlNodeModel::namespaceBindings(const QXmlNodeModelIndex &node) const
155 return QVector<QXmlName>();
159 Always returns a default constructed QXmlNodeModelIndex instance,
162 This effectively means the model has no elements that have an id.
164 QXmlNodeModelIndex QSimpleXmlNodeModel::elementById(const QXmlName &id) const
167 return QXmlNodeModelIndex();
171 Always returns an empty vector, regardless of \a idref.
173 This effectively means the model has no elements or attributes of
176 QVector<QXmlNodeModelIndex> QSimpleXmlNodeModel::nodesByIdref(const QXmlName &idref) const
179 return QVector<QXmlNodeModelIndex>();