Marble
12 #include "MarbleDebug.h"
15 #include "GeoDocument.h"
16 #include "GeoTagHandler.h"
22 #define DUMP_PARENT_STACK 0
24 GeoParser::GeoParser( GeoDataGenericSourceType source )
26 m_document( nullptr ),
31 GeoParser::~GeoParser()
36 #if DUMP_PARENT_STACK > 0
37 static 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) {
106 bool GeoParser::isValidElement(
const QString& tagName )
const
108 return name() == tagName;
111 GeoStackItem GeoParser::parentElement(
unsigned int depth )
const
115 if ( it - depth < m_nodeStack.constBegin() )
116 return GeoStackItem();
118 return *(it - depth);
121 void 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 );
182 void GeoParser::raiseWarning(
const QString& warning )
186 mDebug() <<
"[GeoParser::raiseWarning] -> " << warning;
189 QString GeoParser::attribute(
const char* attributeName )
const
191 return attributes().value(
QLatin1String(attributeName)).toString();
194 GeoDocument* GeoParser::releaseDocument()
196 GeoDocument* document = m_document;
197 m_document =
nullptr;
QString number(int n, int base)
QVector::const_iterator constEnd() const const
Binds a QML item to a specific geodetic location in screen coordinates.
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
const char * name(StandardAction id)
QString tr(const char *sourceText, const char *disambiguation, int n)
QDebug mDebug()
a function to replace qDebug() in Marble library code
char * toString(const EngineQuery &query)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 21 2023 04:12:26 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.