Qt 4.8
Public Types | Public Functions | Private Functions | Properties | Friends | List of all members
QXmlItem Class Reference

The QXmlItem class contains either an XML node or an atomic value. More...

#include <qabstractxmlnodemodel.h>

Public Types

typedef QAbstractXmlForwardIterator< QXmlItemIterator
 A QAbstractXmlForwardIterator over QXmlItem. More...
 

Public Functions

bool isAtomicValue () const
 Returns true if this item is an atomic value. More...
 
bool isNode () const
 Returns true if this item is a Node. More...
 
bool isNull () const
 Returns true if this QXmlItem is neither a node nor an atomic value. More...
 
QXmlItemoperator= (const QXmlItem &other)
 Assigns other to this. More...
 
 QXmlItem ()
 Constructs a null QXmlItem that is neither a node nor an atomic value. More...
 
 QXmlItem (const QXmlItem &other)
 The copy constructor constructs a copy of other. More...
 
 QXmlItem (const QXmlNodeModelIndex &node)
 Constructs a node QXmlItem that is a copy of node. More...
 
 QXmlItem (const QVariant &atomicValue)
 Constructs an atomic value QXmlItem with atomicValue. More...
 
QVariant toAtomicValue () const
 If this QXmlItem represents an atomic value, it is converted to an appropriate QVariant and returned. More...
 
QXmlNodeModelIndex toNodeModelIndex () const
 If this QXmlItem represents a node, it returns the item as a QXmlNodeModelIndex. More...
 
 ~QXmlItem ()
 Destructor. More...
 

Private Functions

bool internalIsAtomicValue () const
 
 QXmlItem (const QPatternist::Item &i)
 

Properties

union {
   const QPatternist::AtomicValue *   m_atomicValue
 
   QPatternist::NodeIndexStorage   m_node
 
   QXmlItemPrivate *   m_ptr
 
}; 
 

Friends

class QPatternist::Item
 
class QPatternist::IteratorBridge
 
class QPatternist::ToItemMapper
 
class QPatternist::ToQXmlItemMapper
 
class QPatternist::VariableLoader
 

Detailed Description

The QXmlItem class contains either an XML node or an atomic value.

Note
This class or function is reentrant.
Since
4.4

In XQuery, all expressions evaluate to a sequence of items, where each item is either an XML node or an atomic value. The query in the following snippet evaluates to sequence of five items.

<aNode/>,
xs:base64Binary("FFFF"),
current-date(),
3e3, (: A floating point value :)
attribute {"name"} {()}

The five items are: An element, an atomic value (binary data encoded in base64), a date, a float, and an attribute.

QXmlItem is the class that represents these XQuery items in the QtXmlPatterns API. A non-null instance of QXmlItem is either a node or an atomic value. Calling isNode() or isAtomicValue() tells you which it is. Atomic values are represented elsewhere in the Qt API as instances of QVariant, and an instance of QXmlItem that represents an atomic value can be converted to a QVariant by calling toAtomicValue(). A QXmlItem that wraps a node is represented elsewhere as an instance of QXmlNodeModelIndex. A node QXmlItem can be converted to a QXmlNodeModelIndex by calling toNodeModelIndex().

A default constructed QXmlItem instance is neither a node nor an atomic value. It is considered null, in which case isNull() returns true.

An instance of QXmlItem will be left dangling if the XML node model it refers to is deleted, if it is a QXmlNodeModelIndex.

Definition at line 380 of file qabstractxmlnodemodel.h.

Typedefs

◆ Iterator

A QAbstractXmlForwardIterator over QXmlItem.

Definition at line 383 of file qabstractxmlnodemodel.h.

Constructors and Destructors

◆ QXmlItem() [1/5]

QXmlItem::QXmlItem ( )

Constructs a null QXmlItem that is neither a node nor an atomic value.

isNull() returns true for a default constructed instance.

Definition at line 1207 of file qabstractxmlnodemodel.cpp.

1208 {
1209  m_node.reset();
1210 }
QPatternist::NodeIndexStorage m_node

◆ QXmlItem() [2/5]

QXmlItem::QXmlItem ( const QXmlItem other)

The copy constructor constructs a copy of other.

Definition at line 1220 of file qabstractxmlnodemodel.cpp.

1220  : m_node(other.m_node)
1221 {
1222  if(internalIsAtomicValue())
1223  m_atomicValue->ref.ref();
1224 }
QAtomicInt ref
Definition: qshareddata.h:59
bool internalIsAtomicValue() const
const QPatternist::AtomicValue * m_atomicValue
bool ref()
Atomically increments the value of this QAtomicInt.
QPatternist::NodeIndexStorage m_node

◆ QXmlItem() [3/5]

QXmlItem::QXmlItem ( const QXmlNodeModelIndex node)

Constructs a node QXmlItem that is a copy of node.

See also
isNode()

Definition at line 1263 of file qabstractxmlnodemodel.cpp.

1263  : m_node(node.m_storage)
1264 {
1265 }
QPatternist::NodeIndexStorage m_node
QPatternist::NodeIndexStorage m_storage

◆ QXmlItem() [4/5]

QXmlItem::QXmlItem ( const QVariant atomicValue)

Constructs an atomic value QXmlItem with atomicValue.

See also
isAtomicValue()

Definition at line 1231 of file qabstractxmlnodemodel.cpp.

1232 {
1233  m_node.reset();
1234  if(atomicValue.isNull())
1235  {
1236  /* Then we behave just like the default constructor. */
1237  return;
1238  }
1239 
1240  /*
1241  We can't assign directly to m_atomicValue, because the
1242  temporary will self-destruct before we've ref'd it.
1243  */
1244  const QPatternist::Item temp(QPatternist::AtomicValue::toXDM(atomicValue));
1245 
1246  if(temp)
1247  {
1248  temp.asAtomicValue()->ref.ref();
1249  m_node.model = reinterpret_cast<const QAbstractXmlNodeModel *>(~0);
1250  m_atomicValue = temp.asAtomicValue();
1251  }
1252  else
1253  {
1254  m_atomicValue = 0;
1255  }
1256 }
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
const QPatternist::AtomicValue * m_atomicValue
QPatternist::NodeIndexStorage m_node
const QAbstractXmlNodeModel * model
The QAbstractXmlNodeModel class is an abstract base class for modeling non-XML data to look like XML ...
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
static Item toXDM(const QVariant &value)

◆ ~QXmlItem()

QXmlItem::~QXmlItem ( )

Destructor.

Definition at line 1271 of file qabstractxmlnodemodel.cpp.

1272 {
1274  delete m_atomicValue;
1275 }
QAtomicInt ref
Definition: qshareddata.h:59
bool internalIsAtomicValue() const
const QPatternist::AtomicValue * m_atomicValue
bool deref()
Atomically decrements the value of this QAtomicInt.

◆ QXmlItem() [5/5]

QXmlItem::QXmlItem ( const QPatternist::Item i)
inlineprivate

Definition at line 524 of file qitem_p.h.

524  : m_node(i.node)
525  {
526  if(isAtomicValue())
527  m_atomicValue->ref.ref();
528  }
QAtomicInt ref
Definition: qshareddata.h:59
NodeIndexStorage node
Definition: qitem_p.h:425
const QPatternist::AtomicValue * m_atomicValue
bool ref()
Atomically increments the value of this QAtomicInt.
QPatternist::NodeIndexStorage m_node
bool isAtomicValue() const
Returns true if this item is an atomic value.

Functions

◆ internalIsAtomicValue()

bool QXmlItem::internalIsAtomicValue ( ) const
inlineprivate

Definition at line 1212 of file qabstractxmlnodemodel.cpp.

Referenced by isAtomicValue(), operator=(), QXmlItem(), and ~QXmlItem().

1213 {
1214  return m_node.model == reinterpret_cast<QAbstractXmlNodeModel *>(~0);
1215 }
QPatternist::NodeIndexStorage m_node
const QAbstractXmlNodeModel * model
The QAbstractXmlNodeModel class is an abstract base class for modeling non-XML data to look like XML ...

◆ isAtomicValue()

bool QXmlItem::isAtomicValue ( ) const

Returns true if this item is an atomic value.

Returns false if it is a node or null.

See also
isNull(), isNode()

Definition at line 1320 of file qabstractxmlnodemodel.cpp.

Referenced by QPatternist::VariableLoader::isSameType(), QPatternist::AtomicValue::qtToXDMType(), QXmlItem(), and toAtomicValue().

1321 {
1322  return internalIsAtomicValue();
1323 }
bool internalIsAtomicValue() const

◆ isNode()

bool QXmlItem::isNode ( ) const

Returns true if this item is a Node.

Returns false if it is an atomic value or null.

See also
isNull(), isAtomicValue()

Definition at line 1309 of file qabstractxmlnodemodel.cpp.

Referenced by QPatternist::VariableLoader::isSameType(), QPatternist::AtomicValue::qtToXDMType(), and toNodeModelIndex().

1310 {
1311  return QPatternist::Item::fromPublic(*this).isNode();
1312 }
bool isNode() const
Determines whether this item is an atomic value, or a node.
Definition: qitem_p.h:349
static Item fromPublic(const QXmlItem &i)
Definition: qitem_p.h:408

◆ isNull()

bool QXmlItem::isNull ( ) const

Returns true if this QXmlItem is neither a node nor an atomic value.

Default constructed instances of QXmlItem are null.

Definition at line 1363 of file qabstractxmlnodemodel.cpp.

Referenced by QXmlQuery::bindVariable(), QXmlQueryPrivate::dynamicContext(), QPatternist::FieldNode::isEmpty(), qIsForwardIteratorEnd(), QPatternist::AtomicValue::qtToXDMType(), QPatternist::XsdValidatingInstanceReader::selectNodeSets(), and QXmlQueryPrivate::staticContext().

1364 {
1365  return !m_node.model;
1366 }
QPatternist::NodeIndexStorage m_node
const QAbstractXmlNodeModel * model

◆ operator=()

QXmlItem & QXmlItem::operator= ( const QXmlItem other)

Assigns other to this.

Definition at line 1287 of file qabstractxmlnodemodel.cpp.

1288 {
1289  if(m_node != other.m_node)
1290  {
1292  delete m_atomicValue;
1293 
1294  m_node = other.m_node;
1295 
1296  if(internalIsAtomicValue())
1297  m_atomicValue->ref.ref();
1298  }
1299 
1300  return *this;
1301 }
QAtomicInt ref
Definition: qshareddata.h:59
bool internalIsAtomicValue() const
const QPatternist::AtomicValue * m_atomicValue
bool ref()
Atomically increments the value of this QAtomicInt.
QPatternist::NodeIndexStorage m_node
bool deref()
Atomically decrements the value of this QAtomicInt.

◆ toAtomicValue()

QVariant QXmlItem::toAtomicValue ( ) const

If this QXmlItem represents an atomic value, it is converted to an appropriate QVariant and returned.

If this QXmlItem is not an atomic value, the return value is a default constructed QVariant. You can call isAtomicValue() to test whether the item is an atomic value.

See also
isAtomicValue()

Definition at line 1334 of file qabstractxmlnodemodel.cpp.

Referenced by QDeclarativeXmlQueryEngine::doQueryJob(), QPatternist::VariableLoader::isSameType(), and QPatternist::AtomicValue::qtToXDMType().

1335 {
1336  if(isAtomicValue())
1338  else
1339  return QVariant();
1340 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QVariant toQt(const AtomicValue *const value)
const QPatternist::AtomicValue * m_atomicValue
bool isAtomicValue() const
Returns true if this item is an atomic value.

◆ toNodeModelIndex()

QXmlNodeModelIndex QXmlItem::toNodeModelIndex ( ) const

If this QXmlItem represents a node, it returns the item as a QXmlNodeModelIndex.

If this QXmlItem is not a node, the return value is undefined. You can call isNode() to test whether the item is a node.

See also
isNode()

Definition at line 1350 of file qabstractxmlnodemodel.cpp.

Referenced by QPatternist::XsdInstanceReader::convertToQName(), QPatternist::TargetNode::operator==(), QPatternist::qHash(), QPatternist::XsdValidatingInstanceReader::read(), and QPatternist::XsdValidatingInstanceReader::validateKeyIdentityConstraint().

1351 {
1352  if(isNode())
1353  return reinterpret_cast<const QXmlNodeModelIndex &>(m_node);
1354  else
1355  return QXmlNodeModelIndex();
1356 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
QPatternist::NodeIndexStorage m_node
bool isNode() const
Returns true if this item is a Node.

Friends and Related Functions

◆ QPatternist::Item

friend class QPatternist::Item
friend

Definition at line 404 of file qabstractxmlnodemodel.h.

◆ QPatternist::IteratorBridge

friend class QPatternist::IteratorBridge
friend

Definition at line 400 of file qabstractxmlnodemodel.h.

◆ QPatternist::ToItemMapper

friend class QPatternist::ToItemMapper
friend

Definition at line 403 of file qabstractxmlnodemodel.h.

◆ QPatternist::ToQXmlItemMapper

friend class QPatternist::ToQXmlItemMapper
friend

Definition at line 402 of file qabstractxmlnodemodel.h.

◆ QPatternist::VariableLoader

Definition at line 401 of file qabstractxmlnodemodel.h.

Properties

◆ @371

union { ... }

◆ m_atomicValue

const QPatternist::AtomicValue* QXmlItem::m_atomicValue

Definition at line 416 of file qabstractxmlnodemodel.h.

Referenced by operator=(), QXmlItem(), toAtomicValue(), and ~QXmlItem().

◆ m_node

◆ m_ptr

QXmlItemPrivate* QXmlItem::m_ptr

Definition at line 417 of file qabstractxmlnodemodel.h.


The documentation for this class was generated from the following files: