1 /*
2     SPDX-License-Identifier: LGPL-2.1-or-later
3 
4     SPDX-FileCopyrightText: 2013 Ander Pijoan <ander.pijoan@deusto.es>
5     SPDX-FileCopyrightText: 2019 John Zaitseff <J.Zaitseff@zap.org.au>
6 */
7 
8 #ifndef MARBLE_JSONPARSER_H
9 #define MARBLE_JSONPARSER_H
10 
11 class QIODevice;
12 class QJsonObject;
13 
14 #include <QVector>
15 
16 namespace Marble {
17 
18 class GeoDataDocument;
19 class GeoDataGeometry;
20 class GeoDataIconStyle;
21 class GeoDataLineStyle;
22 class GeoDataPolyStyle;
23 class GeoDataLabelStyle;
24 
25 class JsonParser
26 {
27 public:
28     JsonParser();
29     ~JsonParser();
30 
31     /**
32      * @brief parse the GeoJSON file
33      * @return true if parsing of the file was successful
34      */
35     bool read(QIODevice*);
36 
37     /**
38      * @brief retrieve the parsed document and reset the parser
39      * If parsing was successful, retrieve the resulting document
40      * and set the contained m_document pointer to 0.
41      */
42     GeoDataDocument* releaseDocument();
43 
44 private:
45 
46     GeoDataDocument* m_document;
47 
48     GeoDataIconStyle*  m_iconStylePoints;
49     GeoDataIconStyle*  m_iconStyleOther;
50     GeoDataLineStyle*  m_lineStyle;
51     GeoDataPolyStyle*  m_polyStyle;
52     GeoDataLabelStyle* m_labelStyle;
53 
54     /**
55      * @brief parse a top-level GeoJSON object (FeatureCollection or Feature)
56      * @param jsonObject  the object to parse
57      * @return true if parsing of the top-level object was successful
58      */
59     bool parseGeoJsonTopLevel(const QJsonObject&);
60 
61     /**
62       * @brief parse a sub-level GeoJSON object
63       * @param jsonObject    the object to parse
64       * @param geometryList  a list of geometries pass back to the caller
65       * @param hasPoints     a boolean passed back to the caller: true if Points exist in geometry
66       * @return true if parsing of the object was successful
67       */
68     bool parseGeoJsonSubLevel(const QJsonObject&, QVector<GeoDataGeometry*>&, bool&);
69 };
70 
71 }
72 
73 #endif // MARBLE_JSONPARSER_H
74