12#include "MarbleDebug.h"
15#include "GeoDocument.h"
16#include "GeoTagHandler.h"
22#define DUMP_PARENT_STACK 0
24GeoParser::GeoParser( GeoDataGenericSourceType source )
26 m_document( nullptr ),
31GeoParser::~GeoParser()
36#if DUMP_PARENT_STACK > 0
37static void dumpParentStack(
const QString& name,
int size,
bool close )
45 for (
int i = 0; i < depth; ++i )
55 fprintf( stderr,
"%s\n", qPrintable( result ));
62 Q_ASSERT( !m_document );
63 m_document = createDocument();
64 Q_ASSERT( m_document );
73 if ( isStartElement() ) {
74 if ( isValidRootElement() ) {
75#if DUMP_PARENT_STACK > 0
76 dumpParentStack(
name().
toString(), m_nodeStack.size(),
false );
81 if ( !m_nodeStack.isEmpty() )
87 QObject::tr(
"Parsing failed line %1. Still %n unclosed tag(s) after document end. ",
"",
88 m_nodeStack.size() ).
arg( lineNumber() ) + errorString());
95 if ( lineNumber() == 1) {
106bool GeoParser::isValidElement(
const QString& tagName )
const
108 return name() == tagName;
111GeoStackItem GeoParser::parentElement(
unsigned int depth )
const
115 if ( it - depth < m_nodeStack.constBegin() )
116 return GeoStackItem();
118 return *(it - depth);
121void GeoParser::parseDocument()
123 if( !isStartElement() ) {
124 raiseError(
QObject::tr(
"Error parsing file at line: %1 and column %2 . ")
125 .arg( lineNumber() ).arg( columnNumber() )
130 bool processChildren =
true;
134 raiseWarning(
QString(
"%1: %2" ).arg(
error() ).arg( errorString() ) );
136 GeoStackItem stackItem( qName,
nullptr );
138 if (
const GeoTagHandler* handler = GeoTagHandler::recognizes( qName )) {
139 stackItem.assignNode( handler->parse( *
this ));
140 processChildren = !isEndElement();
150 if ( processChildren ) {
151 m_nodeStack.push( stackItem );
152#if DUMP_PARENT_STACK > 0
153 dumpParentStack(
name().
toString(), m_nodeStack.size(),
false );
157 if ( isEndElement() ) {
159#if DUMP_PARENT_STACK > 0
160 dumpParentStack(
name().
toString(), m_nodeStack.size(),
true );
165 if ( isStartElement() ) {
170#if DUMP_PARENT_STACK > 0
173 m_nodeStack.push( stackItem );
182void GeoParser::raiseWarning(
const QString& warning )
186 mDebug() <<
"[GeoParser::raiseWarning] -> " << warning;
189QString GeoParser::attribute(
const char* attributeName )
const
191 return attributes().value(
QLatin1String(attributeName)).toString();
194GeoDocument* GeoParser::releaseDocument()
196 GeoDocument* document = m_document;
197 m_document =
nullptr;
char * toString(const EngineQuery &query)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
QString name(StandardShortcut id)
Binds a QML item to a specific geodetic location in screen coordinates.
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(Args &&... args) const const
QString number(double n, char format, int precision)