Home · All Classes · Main Classes · Grouped Classes · Modules · Functions

QSimpleXmlNodeModel Class Reference
[
QtXmlPatterns module]

The QSimpleXmlNodeModel class provides a simple yet powerful way of implementing QAbstractXmlNodeModel. More...

 #include <QSimpleXmlNodeModel>

Inherits QAbstractXmlNodeModel.

Note: All the functions in this class are reentrant.

This class was introduced in Qt 4.4.

Public Types

Public Functions

Protected Functions


Detailed Description

The QSimpleXmlNodeModel class provides a simple yet powerful way of implementing QAbstractXmlNodeModel.

Since QAbstractXmlNodeModel::iterate() requires a sub-class of QAbstractXmlForwardIterator to be returned for each axis, it can be a bit time consuming to implement. For that reason QSimpleXmlNodeModel exists which has nextFromSimpleAxis(), that that is a quick but often sufficient way of providing the node navigation. Behind the scenes QSimpleXmlNodeModel::iterate() "emulates" the full XPath axes using nextFromSimpleAxis().

Apart from nextFromSimpleAxis(), QSimpleXmlNodeModel provides default implementations for many of the members in QAbstractXmlNodeModel that are suitable for a wide range of scenarios.


Member Type Documentation

enum QSimpleXmlNodeModel::SimpleAxis

Four axes that only contain one node each.

ConstantValueDescription
QSimpleXmlNodeModel::Parent0The parent of the context node
QSimpleXmlNodeModel::FirstChild1The first child of the context node
QSimpleXmlNodeModel::PreviousSibling2The previous sibling of the context node
QSimpleXmlNodeModel::NextSibling3The next sibling of the context node


Member Function Documentation

QSimpleXmlNodeModel::QSimpleXmlNodeModel ( const QXmlNamePool & namePool )

Constructs a QSimpleXmlNodeModel instance that can be used with the name pool namePool. It can subsequently be accessed with namePool().

QSimpleXmlNodeModel::~QSimpleXmlNodeModel ()   [virtual]

Destructor.

QVector<QXmlNodeModelIndex> QSimpleXmlNodeModel::attributes ( const QXmlNodeModelIndex & element ) const   [virtual]

Returns the attributes that element element has.

The caller guarantees that element is always an element.

QUrl QSimpleXmlNodeModel::baseUri ( const QXmlNodeModelIndex & node ) const   [virtual]

Returns the base URI for node. This is always the document URI. This is safe, works and is often ok.

Reimplemented from QAbstractXmlNodeModel.

See also documentUri().

QXmlNodeModelIndex QSimpleXmlNodeModel::id ( const QString & id ) const   [virtual]

Always returns a default constructed QXmlNodeModelIndex instance, regardless of id.

This effectively means the model has no elements that has an id.

Reimplemented from QAbstractXmlNodeModel.

QXmlNodeModelIndex QSimpleXmlNodeModel::idref ( const QString & idref ) const   [virtual]

Always returns a default constructed QXmlNodeModelIndex instance, regardless of idref.

This effectively means the model has no elements or attributes are of type IDREF.

Reimplemented from QAbstractXmlNodeModel.

QXmlNamePool QSimpleXmlNodeModel::namePool () const

Returns the name pool that is associated with this model. The implementation of name() would use this to create names.

QVector<QXmlName> QSimpleXmlNodeModel::namespaceBindings ( const QXmlNodeModelIndex & node ) const   [virtual]

Returns always an empty QVector. This signals that no namespace bindings are in scope for node.

Reimplemented from QAbstractXmlNodeModel.

QXmlNodeModelIndex QSimpleXmlNodeModel::nextFromSimpleAxis ( SimpleAxis axis, const QXmlNodeModelIndex & origin ) const   [pure virtual protected]

When Patternist calls iterate(), QSimpleXmlNodeModel create iterators that calls nextFromSimpleAxis() and "emulates" real XPath axes using QSimpleXmlNodeModel::SimpleAxis. Therefore, the implementation of this function should return the node, if any, that appear on axis axis, from origin.

If no such node is available, a default constructed QXmlNodeModelIndex is returned.

QSimpleXmlNodeModel removes the need to handle redundant corner cases by guaranteeing that it will never ask for:

A typical implementation does a switch over axis:

 QXmlItemIteratorPointer MyTreeModel::nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &origin) const
 {
   // Convert the QXmlNodeModelIndex to a value that is specific to what we represent.
   const MyValue value = toMyValue(ni);

   switch(axis)
   {
       case Parent:
           return toNodeIndex(value.parent());
       case FirstChild:
       case PreviousSibling:
       case NextSibling:
           // and so on
   }
 }

QString QSimpleXmlNodeModel::stringValue ( const QXmlNodeModelIndex & node ) const   [virtual]

If node is an element or attribute, typedValue() is called, and the return value converted to a string, as per XQuery's rules.

If node is another type of node, the empty string is returned.

If this function is overriden for for instance comments or processing instructions, it is important to remember to call this function for elements and attribute, if they have atomic values that are not of type xs:string, such that they get formatted according to XQuery.

Reimplemented from QAbstractXmlNodeModel.


Copyright © 2007 Trolltech Trademarks
Qt 4.4.0-tp1