Qt 4.8
qabstractxmlnodemodel.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 #ifndef QABSTRACTXMLNODEMODEL_H
43 #define QABSTRACTXMLNODEMODEL_H
44 
45 #include <QtXmlPatterns/QXmlName>
46 #include <QtCore/QSharedData>
47 #include <QtCore/QScopedPointer>
48 
51 
52 QT_MODULE(XmlPatterns)
53 
54 /* This file contains the classes QXmlNodeModelIndex, QAbstractXmlNodeModel,
55  * QXmlItem and QPatternist::NodeIndexStorage. */
56 
60 class QSourceLocation;
61 class QUrl;
62 class QXmlName;
63 class QXmlNodeModelIndex;
64 template<typename T> class QAbstractXmlForwardIterator;
65 template<typename T> class QVector;
66 
67 /* The members in the namespace QPatternist are internal, not part of the public API, and
68  * unsupported. Using them leads to undefined behavior. */
69 namespace QPatternist
70 {
71  class DynamicContext;
72  class Item;
73  class ItemType;
74  class XsdValidatedXmlNodeModel;
75  template<typename TResult, typename TSource, typename TMapper, typename Context> class ItemMappingIterator;
76  template<typename TResult, typename TSource, typename TMapper> class SequenceMappingIterator;
80 
82  {
83  public:
84  typedef qint64 Data;
85 
90  union
91  {
92  void *ptr; // Do not use ptr directy, use pointer() instead.
93  Data data;
94  };
95  void *pointer() const
96  {
97  /* Constructing to qptrdiff means we avoid the warning "cast to pointer
98  * from integer of different size."
99  */
100  return (void *)qptrdiff(data);
101  }
102 
105 
106  /* Implementation is in qabstractxmlnodemodel.cpp. */
107  inline bool operator!=(const NodeIndexStorage &other) const;
108 
109  void reset()
110  {
111  data = 0;
112  additionalData = 0;
113  model = 0;
114  }
115  };
116 }
117 
119 {
121  {
122  ForwardAxis = 8192,
123  ReverseAxis = 16384
124  };
125 
126 public:
128  {
129  reset();
130  }
131 
132  inline QXmlNodeModelIndex(const QXmlNodeModelIndex &other) : m_storage(other.m_storage)
133  {
134  }
135 
136  bool operator==(const QXmlNodeModelIndex &other) const;
137  bool operator!=(const QXmlNodeModelIndex &other) const;
138 
141 
142  enum NodeKind
143  {
144  Attribute = 1,
145  Comment = 2,
146  Document = 4,
147  Element = 8,
148  Namespace = 16,
149  ProcessingInstruction = 32,
150  Text = 64
151  };
152 
154  {
155  Precedes = -1,
156  Is = 0,
157  Follows = 1
158  };
159 
160  enum Axis
161  {
162  AxisChild = 1 | ForwardAxis,
163  AxisDescendant = 2 | ForwardAxis,
164  AxisAttribute = 4 | ForwardAxis,
165  AxisSelf = 8 | ForwardAxis,
166  AxisDescendantOrSelf = 16 | ForwardAxis,
167  AxisFollowingSibling = 32 | ForwardAxis,
168  AxisNamespace = 64 | ForwardAxis,
169  AxisFollowing = 128 | ReverseAxis,
170  AxisParent = 256 | ReverseAxis,
171  AxisAncestor = 512 | ReverseAxis,
172  AxisPrecedingSibling = 1024 | ReverseAxis,
173  AxisPreceding = 2048 | ReverseAxis,
174  AxisAncestorOrSelf = 4096 | ReverseAxis,
175  /* Note that we cannot clash with the values of ForwardAxis and
176  * ReverseAxis. */
177  AxisChildOrTop = 32768 | ForwardAxis,
178  AxisAttributeOrTop = 65536 | ForwardAxis
179  };
180 
181  inline qint64 data() const
182  {
183  return m_storage.data;
184  }
185 
186  inline void *internalPointer() const
187  {
188  return m_storage.pointer();
189  }
190 
191  inline const QAbstractXmlNodeModel *model() const
192  {
193  return m_storage.model;
194  }
195 
196  inline qint64 additionalData() const
197  {
198  return m_storage.additionalData;
199  }
200 
201  inline bool isNull() const
202  {
203  return !m_storage.model;
204  }
205 
206  /* The members below are internal, not part of the public API, and
207  * unsupported. Using them leads to undefined behavior. */
208 
209  inline QXmlName name() const;
210  inline QXmlNodeModelIndex root() const;
213  inline QUrl documentUri() const;
214  inline QUrl baseUri() const;
215  inline NodeKind kind() const;
216  inline bool isDeepEqual(const QXmlNodeModelIndex &other) const;
217  inline DocumentOrder compareOrder(const QXmlNodeModelIndex &other) const;
218  inline void sendNamespaces(QAbstractXmlReceiver *const receiver) const;
219  inline QVector<QXmlName> namespaceBindings() const;
220  inline QXmlName::NamespaceCode namespaceForPrefix(const QXmlName::PrefixCode prefix) const;
221  inline QString stringValue() const;
222  inline QPatternist::ItemTypePtr type() const;
223  inline bool is(const QXmlNodeModelIndex &other) const;
224 
225  inline void reset()
226  {
227  m_storage.reset();
228  }
229 
230 private:
231  static inline QXmlNodeModelIndex create(const qint64 d,
232  const QAbstractXmlNodeModel *const nm)
233  {
235  n.m_storage.data = d;
236  n.m_storage.model = nm;
238  return n;
239  }
240 
241  static inline QXmlNodeModelIndex create(const qint64 data,
242  const QAbstractXmlNodeModel *const nm,
243  const qint64 addData)
244  {
246  n.m_storage.data = data;
247  n.m_storage.model = nm;
248  n.m_storage.additionalData = addData;
249  return n;
250  }
251 
252  inline QXmlNodeModelIndex(const QPatternist::NodeIndexStorage &storage) : m_storage(storage)
253  {
254  }
255 
256  friend class QAbstractXmlNodeModel;
257  friend class QPatternist::Item;
258  friend class QXmlItem;
259  inline operator int() const; // Disable
260 
262 };
263 
265 
267 {
268  return item.isNull();
269 }
270 
272 {
273 public:
275  {
279  NextSibling
280  };
281 
283  typedef QList<Ptr> List;
284 
286  virtual ~QAbstractXmlNodeModel();
287 
288  virtual QUrl baseUri(const QXmlNodeModelIndex &ni) const = 0;
289  virtual QUrl documentUri(const QXmlNodeModelIndex &ni) const = 0;
290  virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &ni) const = 0;
291  virtual QXmlNodeModelIndex::DocumentOrder compareOrder(const QXmlNodeModelIndex &ni1,
292  const QXmlNodeModelIndex &ni2) const = 0;
293  virtual QXmlNodeModelIndex root(const QXmlNodeModelIndex &n) const = 0;
294  virtual QXmlName name(const QXmlNodeModelIndex &ni) const = 0;
295  virtual QString stringValue(const QXmlNodeModelIndex &n) const = 0;
296  virtual QVariant typedValue(const QXmlNodeModelIndex &n) const = 0;
297 
298  /* The members below are internal, not part of the public API, and
299  * unsupported. Using them leads to undefined behavior. */
301  virtual QPatternist::ItemIteratorPtr sequencedTypedValue(const QXmlNodeModelIndex &ni) const;
302  virtual QPatternist::ItemTypePtr type(const QXmlNodeModelIndex &ni) const;
303  virtual QXmlName::NamespaceCode namespaceForPrefix(const QXmlNodeModelIndex &ni,
304  const QXmlName::PrefixCode prefix) const;
305  virtual bool isDeepEqual(const QXmlNodeModelIndex &ni1,
306  const QXmlNodeModelIndex &ni2) const;
307  virtual void sendNamespaces(const QXmlNodeModelIndex &n,
308  QAbstractXmlReceiver *const receiver) const;
309  virtual QVector<QXmlName> namespaceBindings(const QXmlNodeModelIndex &n) const = 0;
310 
311 
312  virtual QXmlNodeModelIndex elementById(const QXmlName &NCName) const = 0;
313  virtual QVector<QXmlNodeModelIndex> nodesByIdref(const QXmlName &NCName) const = 0;
314 
316  {
317  InheritNamespaces = 0x1,
318  PreserveNamespaces = 0x2
319  };
320 
322  virtual void copyNodeTo(const QXmlNodeModelIndex &node,
323  QAbstractXmlReceiver *const receiver,
324  const NodeCopySettings &) const;
325 
326  QSourceLocation sourceLocation(const QXmlNodeModelIndex &index) const;
327 
328 protected:
329 
330  virtual QXmlNodeModelIndex nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &origin) const = 0;
331  virtual QVector<QXmlNodeModelIndex> attributes(const QXmlNodeModelIndex &element) const = 0;
332 
334 
336  {
337  return QXmlNodeModelIndex::create(data, this);
338  }
339 
341  qint64 additionalData = 0) const
342  {
343  return QXmlNodeModelIndex::create(qptrdiff(pointer), this, additionalData);
344  }
345 
347  qint64 additionalData) const
348  {
349  return QXmlNodeModelIndex::create(data, this, additionalData);
350  }
351 
353 private:
357 
359  const QExplicitlySharedDataPointer<QPatternist::DynamicContext> &) const;
360 
361  static inline bool isIgnorableInDeepEqual(const QXmlNodeModelIndex &n);
363 };
364 
366 
367 template<typename T> class QAbstractXmlForwardIterator;
368 class QVariant;
369 class QXmlItemPrivate;
370 
371 namespace QPatternist
372 {
373  class AtomicValue;
374  class VariableLoader;
375  class IteratorBridge;
376  class ToQXmlItemMapper;
377  class ToItemMapper;
378 }
379 
381 {
382 public:
384 
385  QXmlItem();
386  QXmlItem(const QXmlItem &other);
387  QXmlItem(const QXmlNodeModelIndex &node);
388  QXmlItem(const QVariant &atomicValue);
389  ~QXmlItem();
390  QXmlItem &operator=(const QXmlItem &other);
391 
392  bool isNull() const;
393  bool isNode() const;
394  bool isAtomicValue() const;
395 
396  QVariant toAtomicValue() const;
397  QXmlNodeModelIndex toNodeModelIndex() const;
398 
399 private:
400  friend class QPatternist::IteratorBridge;
402  friend class QPatternist::ToQXmlItemMapper;
403  friend class QPatternist::ToItemMapper;
404  friend class QPatternist::Item;
405 
406  inline bool internalIsAtomicValue() const;
407 
408  inline QXmlItem(const QPatternist::Item &i);
409 
410  union
411  {
413 
414  /* These two sits at the position of NodeIndexStorage::data.
415  * NodeIndexStorage::{additionalData,model} are free. */
417  QXmlItemPrivate * m_ptr; /* Not currently used. */
418  };
419 };
420 
421 inline bool qIsForwardIteratorEnd(const QXmlItem &item)
422 {
423  return item.isNull();
424 }
425 
427 
429 
430 Q_DECLARE_METATYPE(QXmlItem) /* This macro must appear after QT_END_NAMESPACE. */
431 
433 
434 #endif
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QFlags< NodeCopySetting > NodeCopySettings
double d
Definition: qnumeric_p.h:62
static QXmlNodeModelIndex create(const qint64 data, const QAbstractXmlNodeModel *const nm, const qint64 addData)
QXmlNodeModelIndex createIndex(qint64 data, qint64 additionalData) const
Creates a QXmlNodeModelIndex containing data and additionalData.
QXmlNodeModelIndex(const QPatternist::NodeIndexStorage &storage)
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
int type
Definition: qmetatype.cpp:239
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
bool isNull() const
Returns true if this QXmlNodeModelIndex is a default constructed value, otherwise false...
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
void * internalPointer() const
Returns the first data value as a void* pointer.
qint16 NamespaceCode
Definition: qxmlname.h:82
The QXmlItem class contains either an XML node or an atomic value.
QXmlItemPrivate * m_ptr
bool qIsForwardIteratorEnd(const QXmlNodeModelIndex &item)
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
const QPatternist::AtomicValue * m_atomicValue
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
QPatternist::NodeIndexStorage m_node
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
const QAbstractXmlNodeModel * model
QXmlNodeModelIndex createIndex(void *pointer, qint64 additionalData=0) const
Creates a node index with pointer and additionalData as its internal data.
QScopedPointer< QAbstractXmlNodeModelPrivate > d_ptr
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
qint64 data() const
Returns the first data value.
uint qHash(const QPatternist::TargetNode &node)
Base class for all classes representing atomic values.
Definition: qitem_p.h:118
QIntegerForSizeof< void * >::Signed qptrdiff
Definition: qglobal.h:987
The QAbstractXmlNodeModel class is an abstract base class for modeling non-XML data to look like XML ...
DocumentOrder
Identifies the specific node comparison operator that should be used.
const char * name
QPatternist::NodeIndexStorage m_storage
The QAbstractXmlForwardIterator class is a base class for forward iterators.
The namespace for the internal API of QtXmlPatterns.
The QSourceLocation class identifies a location in a resource by URI, line, and column.
unsigned int uint
Definition: qglobal.h:996
QAbstractXmlForwardIterator< QXmlItem > Iterator
A QAbstractXmlForwardIterator over QXmlItem.
__int64 qint64
Definition: qglobal.h:942
The Item is the most basic of all visual items in QML.
const QAbstractXmlNodeModel * model() const
Returns the QAbstractXmlNodeModel that this node index refers to.
#define Q_DECLARE_METATYPE(TYPE)
This macro makes the type Type known to QMetaType as long as it provides a public default constructor...
Definition: qmetatype.h:265
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > ItemIteratorPtr
Proxies another QAbstractXmlForwardIterator, and for each item, returns the Sequence returned from a ...
QList< QXmlNodeModelIndex > List
Typedef for QList<QXmlNodeModelIndex>.
QExplicitlySharedDataPointer< ItemType > ItemTypePtr
QXmlNodeModelIndex(const QXmlNodeModelIndex &other)
Standard copy constructor.
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
The QAbstractXmlReceiver class provides a callback interface for transforming the output of a QXmlQue...
QList< Ptr > List
A list of smart pointers to instances of QAbstractXmlNodeModel.
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
#define Q_XMLPATTERNS_EXPORT
Definition: qglobal.h:1459
A delegate class that wraps around a QAbstractXmlNodeModel and provides additional validation specifi...
The QSharedData class is a base class for shared data objects.
Definition: qshareddata.h:56
NodeKind
Identifies a kind of node.
QXmlNodeModelIndex createIndex(qint64 data) const
Creates a node index with data as its internal data.
QXmlNodeModelIndex()
Default constructor.
static QXmlNodeModelIndex create(const qint64 d, const QAbstractXmlNodeModel *const nm)
SimpleAxis
Four axes that each contain one node only.
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QXmlNodeModelIndex > > mapToSequence(const QXmlNodeModelIndex &ni, const QExplicitlySharedDataPointer< QPatternist::DynamicContext > &) const
quint16 index
Axis
Identify the axes emanating from a node.
static bool isIgnorableInDeepEqual(const QXmlNodeModelIndex &n)
Proxies another QAbstractXmlForwardIterator, and for each item, returns the Item returned from a mapp...
The QFlags class provides a type-safe way of storing OR-combinations of enum values.
Definition: qglobal.h:2313
bool operator!=(const NodeIndexStorage &other) const
qint64 additionalData() const
Returns the second data value.
#define QT_END_HEADER
Definition: qglobal.h:137
Q_DECLARE_TYPEINFO(QXmlNodeModelIndex, Q_MOVABLE_TYPE)
bool operator==(QBool b1, bool b2)
Definition: qglobal.h:2023
QVector< QXmlName > QXmlNameVector
QAbstractXmlForwardIterator< QXmlNodeModelIndex > Iterator
QExplicitlySharedDataPointer< QAbstractXmlNodeModel > Ptr
A QExplicitlySharedDataPointer {smart pointer} to an instance of QAbstractXmlNodeModel.
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300
bool isNull() const
Returns true if this QXmlItem is neither a node nor an atomic value.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
The Text item allows you to add formatted text to a scene.
NamespaceCode PrefixCode
Definition: qxmlname.h:83