File indexing completed on 2025-01-05 03:59:27

0001 /*
0002     SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004     SPDX-FileCopyrightText: 2013 Ander Pijoan <ander.pijoan@deusto.es>
0005     SPDX-FileCopyrightText: 2019 John Zaitseff <J.Zaitseff@zap.org.au>
0006 */
0007 
0008 #include "JsonRunner.h"
0009 
0010 #include <QFile>
0011 
0012 #include "JsonParser.h"
0013 #include "GeoDataDocument.h"
0014 
0015 #include "digikam_debug.h"
0016 
0017 namespace Marble
0018 {
0019 
0020 JsonRunner::JsonRunner(QObject *parent) :
0021     ParsingRunner(parent)
0022 {
0023 }
0024 
0025 JsonRunner::~JsonRunner()
0026 {
0027 }
0028 
0029 GeoDataDocument *JsonRunner::parseFile(const QString &fileName, DocumentRole role, QString &error)
0030 {
0031     // Check that the file exists
0032     QFile file(fileName);
0033     if (! file.exists()) {
0034         error = QStringLiteral("File %1 does not exist").arg(fileName);
0035         qCDebug(DIGIKAM_MARBLE_LOG) << error;
0036         return nullptr;
0037     }
0038 
0039     // Open file in the correct mode
0040     file.open(QIODevice::ReadOnly);
0041 
0042     // Create parser
0043     JsonParser parser;
0044 
0045     // Start parsing
0046     if (! parser.read(&file)) {
0047         error = QStringLiteral("Could not parse GeoJSON from %1").arg(fileName);
0048         qCDebug(DIGIKAM_MARBLE_LOG) << error;
0049         return nullptr;
0050     }
0051 
0052     GeoDataDocument* document = parser.releaseDocument();
0053     file.close();
0054 
0055     document->setDocumentRole( role );
0056     document->setFileName( fileName );
0057 
0058     return document;
0059 }
0060 
0061 }
0062 
0063 #include "moc_JsonRunner.cpp"