Mapper  0.9.0
API documentation
Public Member Functions | List of all members
OpenOrienteering::XmlElementReader Class Reference

The XmlElementReader helps to read a single element in an XML document. More...

#include <xml_stream_util.h>

Public Member Functions

 XmlElementReader (QXmlStreamReader &xml)
 Constructs a new element reader on the given XML reader. More...
 
 XmlElementReader (const XmlElementReader &)=delete
 
 XmlElementReader (XmlElementReader &&)=delete
 
 ~XmlElementReader ()
 Destructor. More...
 
XmlElementReaderoperator= (const XmlElementReader &)=delete
 
XmlElementReaderoperator= (XmlElementReader &&)=delete
 
bool hasAttribute (const QLatin1String &qualifiedName) const
 Tests whether the element has an attribute with the given name. More...
 
bool hasAttribute (const QString &qualifiedName) const
 Tests whether the element has an attribute with the given name. More...
 
template<typename T >
attribute (const QLatin1String &qualifiedName) const
 Returns the value of an attribute of type T. More...
 
void read (QRectF &area)
 Reads attributes named left, top, width, height into the given area object. More...
 
void read (QSizeF &size)
 Reads attributes named width and height into the given size object. More...
 
void read (MapCoordVector &coords)
 Reads the coordinates vector from a simple text format. More...
 
void readForText (MapCoordVector &coords)
 Reads the coordinates vector for a text object. More...
 
void read (QHash< QString, QString > &tags)
 Read tags. More...
 
template<>
QString attribute (const QLatin1String &qualifiedName) const
 
template<>
qint64 attribute (const QLatin1String &qualifiedName) const
 
template<>
int attribute (const QLatin1String &qualifiedName) const
 
template<>
unsigned int attribute (const QLatin1String &qualifiedName) const
 
template<>
long unsigned int attribute (const QLatin1String &qualifiedName) const
 
template<>
double attribute (const QLatin1String &qualifiedName) const
 
template<>
float attribute (const QLatin1String &qualifiedName) const
 
template<>
bool attribute (const QLatin1String &qualifiedName) const
 
template<>
QStringRef attribute (const QLatin1String &qualifiedName) const
 

Detailed Description

The XmlElementReader helps to read a single element in an XML document.

It assumes to be on a QXmlStreamReader::StartElement when constructed, and it reads until the end of the current element, skipping any child nodes, when it is destructed. After construction, it offers convenient functions for reading named attributes of common types.

Typical use:

while (xml_reader.readNextStartElement())
{
// Construction, begins with start tag
XmlElementReader coord(xml_reader);
int x = coord.attribute<int>(QLatin1String("x"));
double y = coord.attribute<double>(QLatin1String("y"));
FlagEnum flags = coord.attribute<FlagEnum>(QLatin1String("flags"));
readChildData(xml_reader);
} // coord goes out of scope here, destructor called, reads until end of element

Constructor & Destructor Documentation

◆ XmlElementReader() [1/3]

OpenOrienteering::XmlElementReader::XmlElementReader ( QXmlStreamReader xml)
inline

Constructs a new element reader on the given XML reader.

It assumes to be on a QXmlStreamReader::StartElement.

◆ XmlElementReader() [2/3]

OpenOrienteering::XmlElementReader::XmlElementReader ( const XmlElementReader )
delete

◆ XmlElementReader() [3/3]

OpenOrienteering::XmlElementReader::XmlElementReader ( XmlElementReader &&  )
delete

◆ ~XmlElementReader()

OpenOrienteering::XmlElementReader::~XmlElementReader ( )
inline

Destructor.

Reads until the end of the current element, skipping any child nodes.

Member Function Documentation

◆ attribute() [1/10]

template<typename T >
T OpenOrienteering::XmlElementReader::attribute ( const QLatin1String qualifiedName) const
inline

Returns the value of an attribute of type T.

Apart from a number of specializations for common types, it has a general implementation which read the attribute as int and does static_cast to the actual type. This is useful for enumerations, but might also be a cause of buildtime or runtime errors.

◆ attribute() [2/10]

template<>
QString OpenOrienteering::XmlElementReader::attribute ( const QLatin1String qualifiedName) const
inline

◆ attribute() [3/10]

template<>
qint64 OpenOrienteering::XmlElementReader::attribute ( const QLatin1String qualifiedName) const
inline

◆ attribute() [4/10]

template<>
int OpenOrienteering::XmlElementReader::attribute ( const QLatin1String qualifiedName) const
inline

◆ attribute() [5/10]

template<>
unsigned int OpenOrienteering::XmlElementReader::attribute ( const QLatin1String qualifiedName) const
inline

◆ attribute() [6/10]

template<>
long unsigned int OpenOrienteering::XmlElementReader::attribute ( const QLatin1String qualifiedName) const
inline

◆ attribute() [7/10]

template<>
double OpenOrienteering::XmlElementReader::attribute ( const QLatin1String qualifiedName) const
inline

◆ attribute() [8/10]

template<>
float OpenOrienteering::XmlElementReader::attribute ( const QLatin1String qualifiedName) const
inline

◆ attribute() [9/10]

template<>
bool OpenOrienteering::XmlElementReader::attribute ( const QLatin1String qualifiedName) const
inline

◆ attribute() [10/10]

template<>
QStringRef OpenOrienteering::XmlElementReader::attribute ( const QLatin1String qualifiedName) const
inline

◆ hasAttribute() [1/2]

bool OpenOrienteering::XmlElementReader::hasAttribute ( const QLatin1String qualifiedName) const
inline

Tests whether the element has an attribute with the given name.

◆ hasAttribute() [2/2]

bool OpenOrienteering::XmlElementReader::hasAttribute ( const QString qualifiedName) const
inline

Tests whether the element has an attribute with the given name.

◆ operator=() [1/2]

XmlElementReader& OpenOrienteering::XmlElementReader::operator= ( const XmlElementReader )
delete

◆ operator=() [2/2]

XmlElementReader& OpenOrienteering::XmlElementReader::operator= ( XmlElementReader &&  )
delete

◆ read() [1/4]

void OpenOrienteering::XmlElementReader::read ( QRectF area)
inline

Reads attributes named left, top, width, height into the given area object.

Counterpart for XmlElementWriter::write(const QRectF&, int).

◆ read() [2/4]

void OpenOrienteering::XmlElementReader::read ( QSizeF size)
inline

Reads attributes named width and height into the given size object.

Counterpart for XmlElementWriter::write(const QSizeF&, int).

◆ read() [3/4]

void OpenOrienteering::XmlElementReader::read ( MapCoordVector coords)

Reads the coordinates vector from a simple text format.

This is much more efficient than loading each coordinate from rich XML.

◆ read() [4/4]

void OpenOrienteering::XmlElementReader::read ( QHash< QString, QString > &  tags)
inline

Read tags.

◆ readForText()

void OpenOrienteering::XmlElementReader::readForText ( MapCoordVector coords)

Reads the coordinates vector for a text object.

This is either a single anchor, or an anchor and a size, packed as a coordinates vector. Regular coordinate bounds checking is not applied to the size.

Todo:
Make box size explicit data.
See also
read(MapCoordVector&)

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