1 | /**************************************************************************** |
---|---|
2 | ** |
3 | ** Copyright (C) 2015 The Qt Company Ltd. |
4 | ** Contact: http://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtLocation module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at http://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or later as published by the Free |
28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
29 | ** the packaging of this file. Please review the following information to |
30 | ** ensure the GNU General Public License version 2.0 requirements will be |
31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
32 | ** |
33 | ** $QT_END_LICENSE$ |
34 | ** |
35 | ****************************************************************************/ |
36 | |
37 | #ifndef QROUTEXMLPARSER_H |
38 | #define QROUTEXMLPARSER_H |
39 | |
40 | #include <QtCore/QObject> |
41 | #include <QtCore/QRunnable> |
42 | #include <QtCore/QString> |
43 | #include <QtCore/QList> |
44 | |
45 | #include <QtLocation/QGeoRouteRequest> |
46 | #include <QtLocation/QGeoRouteSegment> |
47 | #include <QtLocation/QGeoManeuver> |
48 | #include <QtLocation/qgeoroute.h> |
49 | |
50 | QT_BEGIN_NAMESPACE |
51 | |
52 | class QXmlStreamReader; |
53 | class QGeoRoute; |
54 | class QGeoCoordinate; |
55 | class QGeoRectangle; |
56 | |
57 | class QGeoManeuverContainer |
58 | { |
59 | public: |
60 | QGeoManeuver maneuver; |
61 | QString id; |
62 | QString toLink; // Id of the link this maneuver brings into |
63 | int legIndex = 0; |
64 | int index = 0; |
65 | QList<QGeoCoordinate> path; |
66 | bool first = false; |
67 | bool last = false; |
68 | }; |
69 | |
70 | class QGeoRouteSegmentContainer |
71 | { |
72 | public: |
73 | QGeoRouteSegment segment; |
74 | QString id; |
75 | QString maneuverId; |
76 | |
77 | bool operator ==(const QGeoRouteSegmentContainer &other) const |
78 | { |
79 | return ( segment == other.segment && id == other.id && maneuverId == other.maneuverId ); |
80 | } |
81 | }; |
82 | |
83 | class QGeoDynamicSpeedInfoContainer |
84 | { |
85 | public: |
86 | QGeoDynamicSpeedInfoContainer(); |
87 | |
88 | public: |
89 | double trafficSpeed; |
90 | double baseSpeed; |
91 | int trafficTime; |
92 | int baseTime; |
93 | }; |
94 | |
95 | class QGeoRouteXmlParser : public QObject, public QRunnable |
96 | { |
97 | Q_OBJECT |
98 | |
99 | public: |
100 | QGeoRouteXmlParser(const QGeoRouteRequest &request); |
101 | ~QGeoRouteXmlParser(); |
102 | |
103 | void parse(const QByteArray &data); |
104 | void run(); |
105 | |
106 | signals: |
107 | void results(const QList<QGeoRoute> &routes); |
108 | void error(const QString &errorString); |
109 | |
110 | private: |
111 | bool parseRootElement(); |
112 | bool parseRoute(QGeoRoute *route); |
113 | //bool parseWaypoint(QGeoRoute *route); |
114 | bool parseCoordinates(QGeoCoordinate &coord); |
115 | bool parseMode(QGeoRoute *route); |
116 | bool parseSummary(QGeoRoute *route); |
117 | bool parseGeoPoints(const QString &strPoints, QList<QGeoCoordinate> *geoPoints, const QString &elementName); |
118 | bool parseLeg(int legIndex); |
119 | bool parseManeuver(QList<QGeoManeuverContainer> &maneuvers); |
120 | bool parseLink(QList<QGeoRouteSegmentContainer> &links); |
121 | bool postProcessRoute(QGeoRoute *route); |
122 | |
123 | bool parseBoundingBox(QGeoRectangle &bounds); |
124 | bool parseDynamicSpeedInfo(QGeoDynamicSpeedInfoContainer &speedInfo); |
125 | |
126 | QGeoRouteRequest m_request; |
127 | QByteArray m_data; |
128 | QXmlStreamReader *m_reader; |
129 | |
130 | QList<QGeoRoute> m_results; |
131 | QList<QGeoRouteLeg> m_legs; |
132 | QList<QList<QGeoManeuverContainer>> m_maneuvers; |
133 | //QList<QList<QGeoRouteSegmentContainer>> m_segments; |
134 | }; |
135 | |
136 | QT_END_NAMESPACE |
137 | |
138 | #endif |
139 |