diff --git a/CMakeLists.txt b/CMakeLists.txt index 022f6e8..4251595 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ set(HEADER_FILES enterpassworddialog/enterpassworddialog.h misc/dialogutils.h misc/desktoputils.h + misc/xmlparsermacros.h models/checklistmodel.h resources/qtconfigarguments.h resources/resources.h diff --git a/misc/xmlparsermacros.h b/misc/xmlparsermacros.h new file mode 100644 index 0000000..c8f9ad6 --- /dev/null +++ b/misc/xmlparsermacros.h @@ -0,0 +1,41 @@ +#include + +/*! + * \file xmlparsermacros.h + * \brief Macros to utilize XML parsing using QXmlStreamReader. + * \sa For an example, see dbquery.cpp of the tageditor project. + */ + +#ifndef xmlReader +# error "xmlReader must be defined to use these macros." +#endif + +#ifdef iftag +# undef iftag +#endif +#define iftag(tagName) if(xmlReader.name() == QLatin1String(tagName)) + +#ifdef eliftag +# undef eliftag +#endif +#define eliftag(tagName) else if(xmlReader.name() == QLatin1String(tagName)) + +#ifdef else_skip +# undef else_skip +#endif +#define else_skip else { xmlReader.skipCurrentElement(); } + +#ifdef children +# undef children +#endif +#define children while(xmlReader.readNextStartElement()) + +#ifdef text +# undef text +#endif +#define text xmlReader.readElementText(QXmlStreamReader::ErrorOnUnexpectedElement) + +#ifdef attribute +# undef attribute +#endif +#define attribute(attributeName) xmlReader.attributes().value(QLatin1String(attributeName)) diff --git a/qtutilities.pro b/qtutilities.pro index bfaed88..d059c4e 100644 --- a/qtutilities.pro +++ b/qtutilities.pro @@ -30,7 +30,8 @@ HEADERS += \ models/checklistmodel.h \ resources/qtconfigarguments.h \ misc/dialogutils.h \ - misc/desktoputils.h + misc/desktoputils.h \ + misc/xmlparsermacros.h SOURCES += resources/resources.cpp \ models/checklistmodel.cpp \