1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
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.
73 \inmodule QtXmlPatterns
75 Subclassing QAbstractXmlNodeModel can be a significant task, because it
76 requires implementing several, complex member functions. QSimpleXmlNodeModel
77 provides default implementations of these member functions that are suitable
78 for a wide range of node models.
80 Subclasses of QSimpleXmlNodeModel must be thread-safe.
84 Constructs a QSimpleXmlNodeModel for use with with the specified
87 QSimpleXmlNodeModel::QSimpleXmlNodeModel(const QXmlNamePool &namePool)
88 : QAbstractXmlNodeModel(new QSimpleXmlNodeModelPrivate(namePool))
95 QSimpleXmlNodeModel::~QSimpleXmlNodeModel()
100 If \a node is an element or attribute, typedValue() is called, and
101 the return value converted to a string, as per XQuery's rules.
103 If \a node is another type of node, the empty string is returned.
105 If this function is overridden for comments or processing
106 instructions, it is important to remember to call it (for elements
107 and attributes having values not of type \c xs:string) to ensure that
108 the values are formatted according to XQuery.
111 QString QSimpleXmlNodeModel::stringValue(const QXmlNodeModelIndex &node) const
113 const QXmlNodeModelIndex::NodeKind k= kind(node);
114 if(k == QXmlNodeModelIndex::Element || k == QXmlNodeModelIndex::Attribute)
116 const QVariant &candidate = typedValue(node);
117 if(candidate.isNull())
120 return AtomicValue::toXDM(candidate).stringValue();
127 Returns the base URI for \a node. This is always the document
132 QUrl QSimpleXmlNodeModel::baseUri(const QXmlNodeModelIndex &node) const
134 return documentUri(node);
138 Returns the name pool associated with this model. The
139 implementation of name() will use this name pool to create
142 QXmlNamePool &QSimpleXmlNodeModel::namePool() const
144 Q_D(const QSimpleXmlNodeModel);
150 Always returns an empty QVector. This signals that no namespace
151 bindings are in scope for \a node.
153 QVector<QXmlName> QSimpleXmlNodeModel::namespaceBindings(const QXmlNodeModelIndex &node) const
156 return QVector<QXmlName>();
160 Always returns a default constructed QXmlNodeModelIndex instance,
163 This effectively means the model has no elements that have an id.
165 QXmlNodeModelIndex QSimpleXmlNodeModel::elementById(const QXmlName &id) const
168 return QXmlNodeModelIndex();
172 Always returns an empty vector, regardless of \a idref.
174 This effectively means the model has no elements or attributes of
177 QVector<QXmlNodeModelIndex> QSimpleXmlNodeModel::nodesByIdref(const QXmlName &idref) const
180 return QVector<QXmlNodeModelIndex>();