Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/runner/json/JsonRunner.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | This file is part of the Marble Virtual Globe. | 2 | This file is part of the Marble Virtual Globe. | ||
3 | 3 | | |||
4 | This program is free software licensed under the GNU LGPL. You can | 4 | This program is free software licensed under the GNU LGPL. You can | ||
5 | find a copy of this license in LICENSE.txt in the top directory of | 5 | find a copy of this license in LICENSE.txt in the top directory of | ||
6 | the source code. | 6 | the source code. | ||
7 | 7 | | |||
8 | Copyright 2013 Ander Pijoan <ander.pijoan@deusto.es> | 8 | Copyright 2013 Ander Pijoan <ander.pijoan@deusto.es> | ||
9 | Copyright 2019 John Zaitseff <J.Zaitseff@zap.org.au> | ||||
9 | */ | 10 | */ | ||
10 | 11 | | |||
11 | #include "JsonRunner.h" | 12 | #include "JsonRunner.h" | ||
12 | #include "JsonParser.h" | 13 | #include "JsonParser.h" | ||
13 | 14 | | |||
14 | #include "GeoDataDocument.h" | 15 | #include "GeoDataDocument.h" | ||
15 | #include "MarbleDebug.h" | 16 | #include "MarbleDebug.h" | ||
16 | 17 | | |||
17 | #include <QFile> | 18 | #include <QFile> | ||
18 | 19 | | |||
19 | namespace Marble | 20 | namespace Marble | ||
20 | { | 21 | { | ||
21 | 22 | | |||
22 | JsonRunner::JsonRunner(QObject *parent) : | 23 | JsonRunner::JsonRunner(QObject *parent) : | ||
23 | ParsingRunner(parent) | 24 | ParsingRunner(parent) | ||
24 | { | 25 | { | ||
25 | } | 26 | } | ||
26 | 27 | | |||
27 | JsonRunner::~JsonRunner() | 28 | JsonRunner::~JsonRunner() | ||
28 | { | 29 | { | ||
29 | } | 30 | } | ||
30 | 31 | | |||
31 | GeoDataDocument *JsonRunner::parseFile(const QString &fileName, DocumentRole role, QString &error) | 32 | GeoDataDocument *JsonRunner::parseFile(const QString &fileName, DocumentRole role, QString &error) | ||
32 | { | 33 | { | ||
33 | // Check file exists | 34 | // Check that the file exists | ||
34 | QFile file( fileName ); | 35 | QFile file(fileName); | ||
35 | if ( !file.exists() ) { | 36 | if (! file.exists()) { | ||
36 | error = QStringLiteral("File %1 does not exist").arg(fileName); | 37 | error = QStringLiteral("File %1 does not exist").arg(fileName); | ||
37 | mDebug() << error; | 38 | mDebug() << error; | ||
38 | return nullptr; | 39 | return nullptr; | ||
39 | } | 40 | } | ||
40 | 41 | | |||
41 | // Open file in right mode | 42 | // Open file in the correct mode | ||
42 | file.open( QIODevice::ReadOnly ); | 43 | file.open(QIODevice::ReadOnly); | ||
43 | 44 | | |||
44 | // Create parser | 45 | // Create parser | ||
45 | JsonParser parser; | 46 | JsonParser parser; | ||
46 | 47 | | |||
47 | // Start parsing | 48 | // Start parsing | ||
48 | if ( !parser.read( &file ) ) { | 49 | if (! parser.read(&file)) { | ||
49 | error = QStringLiteral("Could not parse GeoJSON from %1").arg(fileName); | 50 | error = QStringLiteral("Could not parse GeoJSON from %1").arg(fileName); | ||
50 | mDebug() << error; | 51 | mDebug() << error; | ||
51 | return nullptr; | 52 | return nullptr; | ||
52 | } | 53 | } | ||
53 | 54 | | |||
54 | GeoDataDocument* document = parser.releaseDocument(); | 55 | GeoDataDocument* document = parser.releaseDocument(); | ||
55 | file.close(); | 56 | file.close(); | ||
57 | | ||||
56 | document->setDocumentRole( role ); | 58 | document->setDocumentRole( role ); | ||
57 | document->setFileName( fileName ); | 59 | document->setFileName( fileName ); | ||
58 | 60 | | |||
59 | return document; | 61 | return document; | ||
60 | } | 62 | } | ||
61 | 63 | | |||
62 | } | 64 | } | ||
63 | 65 | | |||
64 | #include "moc_JsonRunner.cpp" | 66 | #include "moc_JsonRunner.cpp" |