QXmlNodeModelIndex Class

The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeModel . 更多...

头: #include <QXmlNodeModelIndex>
qmake: QT += xmlpatterns
Since: Qt 4.4

该类在 Qt 4.4 引入。

注意: 此类的所有函数 可重入 .

公共类型

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

公共函数

QXmlNodeModelIndex (const QXmlNodeModelIndex & other )
QXmlNodeModelIndex ()
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

详细描述

QXmlNodeModelIndex is an index into an XML node model . It contains:

Because QXmlNodeModelIndex is intentionally a simple class, it doesn't have member functions for accessing the properties of nodes. For example, it doesn't have functions for getting a node's name or its list of attributes or child nodes. If you find that you need to retrieve this kind of information from your query results, there are two ways to proceed.

The second case is explained by example. Suppose you want to populate a list widget with the values of certain attributes from a set of result elements. You could write an XQuery to return the set of elements, and then you would write the code to iterate over the result elements, get their attributes, and extract the desired string values. But the simpler way is to just augment your XQuery to finding the desired attribute values. Then all you have to do is evaluate the XQuery using the version of QXmlQuery::evaluateTo () that populates a QStringList , which you can send directly to your widget.

QXmlNodeModelIndex doesn't impose any restrictions on the data value an QXmlNodeModelIndex should contain. The meaning of the data left to the associated node model . Because QXmlNodeModelIndex depends on a particular subclass of QAbstractXmlNodeModel for its existence, the only way you can create an instance of QXmlNodeModelIndex is by asking the node model to create one for you with QAbstractXmlNodeModel::createIndex (). Since that function is protected, it is usually a good idea to write a public function that creates a QXmlNodeModelIndex from arguments that are appropriate for your particular node model.

A default constructed node index is said to be null, i.e., isNull () returns true.

QXmlNodeModelIndex and QAbstractXmlNodeModel follow the same design pattern used for QModelIndex and QAbstractItemModel .

成员类型文档编制

enum QXmlNodeModelIndex:: DocumentOrder

Identifies the specific node comparison operator that should be used.

常量 描述
QXmlNodeModelIndex::Precedes -1 Signifies the \<\< operator. Test whether the first operand precedes the second in the document.
QXmlNodeModelIndex::Follows 1 Signifies the \>\> operator. Test whether the first operand follows the second in the document.
QXmlNodeModelIndex::Is 0 Signifies the is operator. Test whether two nodes have the same node identity.

typedef QXmlNodeModelIndex:: List

typedef 对于 QList < QXmlNodeModelIndex >.

enum QXmlNodeModelIndex:: NodeKind

Identifies a kind of node.

常量 描述
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.

Note that the optional XML declaration at very beginning of the XML document is not a processing instruction

另请参阅 QAbstractXmlNodeModel::kind ().

成员函数文档编制

QXmlNodeModelIndex:: QXmlNodeModelIndex (const QXmlNodeModelIndex & other )

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

QXmlNodeModelIndex:: QXmlNodeModelIndex ()

Default constructor. Creates an item that is null .

另请参阅 isNull ().

qint64 QXmlNodeModelIndex:: additionalData () const

Returns the second data value. The node index holds two data values. data () returns the first one.

另请参阅 data ().

qint64 QXmlNodeModelIndex:: data () const

Returns the first data value. The node index holds two data values. additionalData () returns the second one.

另请参阅 additionalData ().

void *QXmlNodeModelIndex:: internalPointer () const

Returns the first data value as a void* pointer.

另请参阅 additionalData ().

bool QXmlNodeModelIndex:: isNull () const

返回 true,若此 QXmlNodeModelIndex is a default constructed value, otherwise false.

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

const QAbstractXmlNodeModel *QXmlNodeModelIndex:: model () const

返回 QAbstractXmlNodeModel that this node index refers to. QXmlNodeModelIndex does not own QAbstractXmlNodeModel and does not keep track of its lifetime, so this pointer will dangle if the QAbstractXmlNodeModel is deallocated first.

There is no setter for the node model because instances of QXmlNodeModelIndex instances are only created with QAbstractXmlNodeModel::createIndex ().

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

返回 true 若 other is the same node as this.

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

Returns true if this node is the same as other . This operator does not compare values, children, or names of nodes. It compares node identities, i.e., whether two nodes are from the same document and are found at the exact same place.