Change copyrights from Nokia to Digia
[profile/ivi/qtxmlpatterns.git] / src / xmlpatterns / api / qsimplexmlnodemodel.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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   \inmodule QtXmlPatterns
74
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.
79
80   Subclasses of QSimpleXmlNodeModel must be thread-safe.
81  */
82
83 /*!
84   Constructs a QSimpleXmlNodeModel for use with with the specified
85   \a namePool.
86  */
87 QSimpleXmlNodeModel::QSimpleXmlNodeModel(const QXmlNamePool &namePool)
88   : QAbstractXmlNodeModel(new QSimpleXmlNodeModelPrivate(namePool))
89 {
90 }
91
92 /*!
93   Destructor.
94  */
95 QSimpleXmlNodeModel::~QSimpleXmlNodeModel()
96 {
97 }
98
99 /*!
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.
102
103  If \a node is another type of node, the empty string is returned.
104
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.
109
110  */
111 QString QSimpleXmlNodeModel::stringValue(const QXmlNodeModelIndex &node) const
112 {
113     const QXmlNodeModelIndex::NodeKind k= kind(node);
114     if(k == QXmlNodeModelIndex::Element || k == QXmlNodeModelIndex::Attribute)
115     {
116         const QVariant &candidate = typedValue(node);
117         if(candidate.isNull())
118             return QString();
119         else
120             return AtomicValue::toXDM(candidate).stringValue();
121     }
122     else
123         return QString();
124 }
125
126 /*!
127   Returns the base URI for \a node. This is always the document
128   URI.
129
130   \sa documentUri()
131  */
132 QUrl QSimpleXmlNodeModel::baseUri(const QXmlNodeModelIndex &node) const
133 {
134     return documentUri(node);
135 }
136
137 /*!
138   Returns the name pool associated with this model. The
139   implementation of name() will use this name pool to create
140   names.
141  */
142 QXmlNamePool &QSimpleXmlNodeModel::namePool() const
143 {
144     Q_D(const QSimpleXmlNodeModel);
145
146     return d->namePool;
147 }
148
149 /*!
150   Always returns an empty QVector. This signals that no namespace
151   bindings are in scope for \a node.
152  */
153 QVector<QXmlName> QSimpleXmlNodeModel::namespaceBindings(const QXmlNodeModelIndex &node) const
154 {
155     Q_UNUSED(node);
156     return QVector<QXmlName>();
157 }
158
159 /*!
160   Always returns a default constructed QXmlNodeModelIndex instance,
161   regardless of \a id.
162
163   This effectively means the model has no elements that have an id.
164  */
165 QXmlNodeModelIndex QSimpleXmlNodeModel::elementById(const QXmlName &id) const
166 {
167     Q_UNUSED(id);
168     return QXmlNodeModelIndex();
169 }
170
171 /*!
172   Always returns an empty vector, regardless of \a idref.
173
174   This effectively means the model has no elements or attributes of
175   type \c IDREF.
176  */
177 QVector<QXmlNodeModelIndex> QSimpleXmlNodeModel::nodesByIdref(const QXmlName &idref) const
178 {
179     Q_UNUSED(idref);
180     return QVector<QXmlNodeModelIndex>();
181 }
182
183 QT_END_NAMESPACE
184
185