File indexing completed on 2025-01-05 03:59:27
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 <QFile> 0008 0009 #include "GeoDataDocument.h" 0010 #include "GpxParser.h" 0011 0012 #include "digikam_debug.h" 0013 0014 namespace Marble 0015 { 0016 0017 GpxRunner::GpxRunner(QObject *parent) : 0018 ParsingRunner(parent) 0019 { 0020 } 0021 0022 GpxRunner::~GpxRunner() 0023 { 0024 } 0025 0026 GeoDataDocument *GpxRunner::parseFile(const QString &fileName, DocumentRole role, QString &error) 0027 { 0028 QFile file( fileName ); 0029 if ( !file.exists() ) { 0030 error = QStringLiteral("File %1 does not exist").arg(fileName); 0031 qCDebug(DIGIKAM_MARBLE_LOG) << error; 0032 return nullptr; 0033 } 0034 0035 // Open file in right mode 0036 file.open( QIODevice::ReadOnly ); 0037 0038 GpxParser parser; 0039 0040 if ( !parser.read( &file ) ) { 0041 error = parser.errorString(); 0042 qCDebug(DIGIKAM_MARBLE_LOG) << error; 0043 return nullptr; 0044 } 0045 GeoDocument* document = parser.releaseDocument(); 0046 Q_ASSERT( document ); 0047 GeoDataDocument* doc = static_cast<GeoDataDocument*>( document ); 0048 doc->setDocumentRole( role ); 0049 doc->setFileName( fileName ); 0050 0051 file.close(); 0052 return doc; 0053 } 0054 0055 } 0056 0057 #include "moc_GpxRunner.cpp"