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

# QXmlNodeModelIndex Class Reference
[QtXmlPatterns module]

The QXmlNodeModelIndex class is used to represent a node in a node model. More...

     #include <QXmlNodeModelIndex>

Note: All the functions in this class are reentrant.

This class was introduced in Qt 4.4.

- List of all members, including inherited members

### Public Types

- enum DocumentOrder { Precedes, Follows, Is }
- typedef List
- enum NodeKind { Attribute, Text, Comment, Document, ..., ProcessingInstruction }

### Public Functions

- QXmlNodeModelIndex ()
- QXmlNodeModelIndex ( const QXmlNodeModelIndex & other )
- qint64 additionalData () const
- qint64 data () const
- void * internalPointer () const
- bool isNull () const
- const QAbstractXmlNodeModel * model () const
- bool operator!= ( const QXmlNodeModelIndex & other ) const
- bool operator== ( const QXmlNodeModelIndex & other ) const

### Related Non-Members

- uint qHash ( const QXmlNodeModelIndex & index )

## Detailed Description

The QXmlNodeModelIndex class is used to represent a node in a node model.

QXmlNodeModelIndex is used as an index into QAbstractXmlNodeModel. It contains two things:

- A pointer to a QAbstractXmlNodeModel, retrievable via model()
- Data, retrievable via data(), internalPointer() and additionalData().

QXmlNodeModelIndex is intentionally a simple class. For instance it doesn't have a function for getting a node's name or the list of its attributes. Therefore, QXmlNodeModelIndex is primarily useful if you are using your own node model, but falls short if you to some degree want to spectate the nodes as ordinary XML nodes. Typically the best way to achieve the latter is to either send the result out to a QAbstractXmlReceiver or to put more of the logic inside the query.

For instance, let's say you want to populate a list widget with the values of a set of attributes. Instead of letting the query return a set of elements and then iterate over the their attributes and extract the string values, let the query do all this directly and then evaluate it using QXmlQuery::evaluateTo() and pass a pointer to QStringList.

QXmlNodeModelIndex does not impose restrictions on what data QXmlNodeModelIndex should contain, that is entirely up to the associated QAbstractXmlNodeModel.

Conceptually, QXmlNodeModelIndex can be seen as being one of the two types of items in XQuery: namely nodes. When the XQuery engine handles nodes, it uses QXmlNodeModelIndex in order to delegate the actual functionality to the associated QAbstractXmlNodeModel.

Since QXmlNodeModelIndex is dependent on a particular QAbstractXmlNodeModel subclass, there is no way to create instances, except for via QAbstractXmlNodeModel::createIndex(). Since that function is protected, it can probably be good to create a function that creates node indexes from arguments that fits the particular node model.

A default constructed node index `null`, and isNull() will return `true`.

QXmlNodeModelIndex and QAbstractXmlNodeModel follows the same design pattern that QModelIndex QAbstractItemModel do.

## Member Type Documentation

### enum QXmlNodeModelIndex::DocumentOrder

Identifies what specific node comparison operator that should be used.

Constant | Value | Description
--- | --- | ---
`QXmlNodeModelIndex::Precedes` | `-1` | Signifies the `\<\<` operator. Whether the first operand precedes the second operand in document order.
`QXmlNodeModelIndex::Follows` | `1` | Signifies the `\>\>` operator. Whether the first operand follows the second operand in document order.
`QXmlNodeModelIndex::Is` | `0` | Signifies the `is` operator. Whether two nodes have the same node identity.

### typedef QXmlNodeModelIndex::List

Typedef for QList<QXmlNodeModelIndex>.

### enum QXmlNodeModelIndex::NodeKind

Identifies the kind of a node.

Constant | Value | Description
--- | --- | ---
`QXmlNodeModelIndex::Attribute` | `1` | Identifies an attribute node
`QXmlNodeModelIndex::Text` | `64` | Identifies a text node
`QXmlNodeModelIndex::Comment` | `2` | Identifies a comment node
`QXmlNodeModelIndex::Document` | `4` | Identifies a document node
`QXmlNodeModelIndex::Element` | `8` | Identifies an element node
`QXmlNodeModelIndex::Namespace` | `16` | Identifies a namespace node
`QXmlNodeModelIndex::ProcessingInstruction` | `32` | Identifies a processing instruction. Not that the optional XML declaration at very beginning of the XML document is not a processing instruction

See also QAbstractXmlNodeModel::kind().

## Member Function Documentation

### QXmlNodeModelIndex::QXmlNodeModelIndex ()

Default constructor. Creates an item that is `null`.

See also isNull().

### QXmlNodeModelIndex::QXmlNodeModelIndex ( const QXmlNodeModelIndex & other )

Standard copy constructor. Creates a QXmlNodeModelIndex instance that is a copy of other.

### qint64 QXmlNodeModelIndex::additionalData () const

Returns the second data section that this node index carries.

See also data().

### qint64 QXmlNodeModelIndex::data () const

Returns the first data section that this node index carries.

See also additionalData().

### void * QXmlNodeModelIndex::internalPointer () const

Returns the first data section typed as a void * pointer.

See also additionalData().

### bool QXmlNodeModelIndex::isNull () const

Returns `true` if this QXmlNodeModelIndex is a default constructed value, otherwise `false`.

A `null` QXmlNodeModelIndex instance doesn't represent any node and cannot be used in conjunction with QAbstractXmlNodeModel.

### const QAbstractXmlNodeModel * QXmlNodeModelIndex::model () const

Returns the QAbstractXmlNodeModel that this node index belongs to. QXmlNodeModelIndex does not own QAbstractXmlNodeModel nor keep track of its lifetime, so this pointer will dangle whenthe QAbstractXmlNodeModel is deallocated.

There is no setter for this, QXmlNodeModelIndex instances are created with QAbstractXmlNodeModel::createIndex().

### bool QXmlNodeModelIndex::operator!= ( const QXmlNodeModelIndex & other ) const

Returns true if other is the same node as this.

### bool QXmlNodeModelIndex::operator== ( const QXmlNodeModelIndex & other ) const

Returns true if this node is the same as other.

In other words, this operator does not compare values, children or names of nodes, it tells whether two nodes have the same node identity. That is, whether they are from the same document and can be found at the exact same place.

## Related Non-Members

### uint qHash ( const QXmlNodeModelIndex & index )

This is an overloaded member function, provided for convenience.

Computes a hash key from the QXmlNodeModelIndex index, and returns it.

The hash is computed on QXmlNodeModelIndex::data(), QXmlNodeModelIndex::additionalData(), and QXmlNodeModelIndex::model(). This means the hash key can be used for node indexes from different node models.