File indexing completed on 2024-07-14 10:58:39

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2011 Thibaut Gridel <tgridel@free.fr>
0004 
0005 #include "GpxRunner.h"
0006 
0007 #include "GeoDataDocument.h"
0008 #include "GpxParser.h"
0009 #include "MarbleDebug.h"
0010 
0011 #include <QFile>
0012 
0013 namespace Marble
0014 {
0015 
0016 GpxRunner::GpxRunner(QObject *parent) :
0017     ParsingRunner(parent)
0018 {
0019 }
0020 
0021 GpxRunner::~GpxRunner()
0022 {
0023 }
0024 
0025 GeoDataDocument *GpxRunner::parseFile(const QString &fileName, DocumentRole role, QString &error)
0026 {
0027     QFile file( fileName );
0028     if ( !file.exists() ) {
0029         error = QStringLiteral("File %1 does not exist").arg(fileName);
0030         mDebug() << error;
0031         return nullptr;
0032     }
0033 
0034     // Open file in right mode
0035     file.open( QIODevice::ReadOnly );
0036 
0037     GpxParser parser;
0038 
0039     if ( !parser.read( &file ) ) {
0040         error = parser.errorString();
0041         mDebug() << error;
0042         return nullptr;
0043     }
0044     GeoDocument* document = parser.releaseDocument();
0045     Q_ASSERT( document );
0046     GeoDataDocument* doc = static_cast<GeoDataDocument*>( document );
0047     doc->setDocumentRole( role );
0048     doc->setFileName( fileName );
0049 
0050     file.close();
0051     return doc;
0052 }
0053 
0054 }
0055 
0056 #include "moc_GpxRunner.cpp"