1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 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 QDECLARATIVENAVIGATOR_P_H
38 #define QDECLARATIVENAVIGATOR_P_H
39 
40 //
41 //  W A R N I N G
42 //  -------------
43 //
44 // This file is not part of the Qt API.  It exists purely as an
45 // implementation detail.  This header file may change from version to
46 // version without notice, or even be removed.
47 //
48 // We mean it.
49 //
50 
51 #include <QtLocation/private/qlocationglobal_p.h>
52 #include <QtQml/qqml.h>
53 #include <QSharedPointer>
54 #include <QtLocation/private/qparameterizableobject_p.h>
55 #include <QtLocation/qgeoserviceprovider.h>
56 
57 QT_BEGIN_NAMESPACE
58 
59 class QDeclarativeGeoServiceProvider;
60 class QDeclarativeGeoMap;
61 class QNavigationManager;
62 class QDeclarativeGeoRoute;
63 class QDeclarativeGeoRouteLeg;
64 class QDeclarativePositionSource;
65 class QDeclarativeGeoWaypoint;
66 class QGeoRoute;
67 class QGeoRouteLeg;
68 class QGeoRouteSegment;
69 class QDeclarativeNavigatorPrivate;
70 class QDeclarativeGeoRouteSegment;
71 class QDeclarativeNavigationBasicDirections;
72 class QAbstractNavigator;
73 
74 class Q_LOCATION_PRIVATE_EXPORT QDeclarativeNavigator : public QParameterizableObject, public QQmlParserStatus
75 {
76     Q_OBJECT
77     Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
78     Q_PROPERTY(QDeclarativeGeoMap *map READ map WRITE setMap NOTIFY mapChanged)
79     Q_PROPERTY(QDeclarativeGeoRoute *route READ route WRITE setRoute NOTIFY routeChanged)
80     Q_PROPERTY(QDeclarativePositionSource *positionSource READ positionSource WRITE setPositionSource NOTIFY positionSourceChanged)
81     Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
82     Q_PROPERTY(bool navigatorReady READ navigatorReady NOTIFY navigatorReadyChanged)
83     Q_PROPERTY(bool trackPositionSource READ trackPositionSource WRITE setTrackPositionSource NOTIFY trackPositionSourceChanged)
84     Q_PROPERTY(bool automaticReroutingEnabled READ automaticReroutingEnabled WRITE setAutomaticReroutingEnabled NOTIFY automaticReroutingEnabledChanged)
85     Q_PROPERTY(bool isOnRoute READ isOnRoute NOTIFY isOnRouteChanged)
86     Q_PROPERTY(QDeclarativeNavigationBasicDirections *directions READ directions CONSTANT)
87     Q_PROPERTY(NavigationError error READ error NOTIFY errorChanged)
88     Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
89     Q_PROPERTY(QAbstractNavigator *engineHandle READ abstractNavigator CONSTANT)
90 
91     Q_INTERFACES(QQmlParserStatus)
92 
93 public:
94     enum NavigationError {
95         //QGeoServiceProvider related errors start here
96         NoError = QGeoServiceProvider::NoError,
97         NotSupportedError = QGeoServiceProvider::NotSupportedError, //TODO Qt6 consider merge with NotSupportedError
98         ConnectionError = QGeoServiceProvider::ConnectionError, //TODO Qt6 merge with Map's ConnectionError
99         LoaderError = QGeoServiceProvider::LoaderError,
100         UnknownParameterError = QGeoServiceProvider::UnknownParameterError, //TODO Qt6 consider rename UnsupportedOperationError
101         MissingRequiredParameterError = QGeoServiceProvider::MissingRequiredParameterError,
102         //we leave gap for future QGeoCodeReply errors
103 
104         // Navigation-specific error should start at 100
105         UnknownError = 100
106     };
107 
108     explicit QDeclarativeNavigator(QObject *parent = nullptr);
109     ~QDeclarativeNavigator();
110 
111     // QQmlParserStatus interface
112     void classBegin() override;
113     void componentComplete() override;
114 
115     // QDeclarativeNavigator
116     void start();
117     void stop();
118 
119     void setActive(bool active);
120     bool active() const;
121 
122     void setPlugin(QDeclarativeGeoServiceProvider * plugin);
123     QDeclarativeGeoServiceProvider *plugin() const;
124 
125     void setMap(QDeclarativeGeoMap *map);
126     QDeclarativeGeoMap * map() const;
127 
128     void setRoute(QDeclarativeGeoRoute *route);
129     QDeclarativeGeoRoute *route() const;
130 
131     void setPositionSource(QDeclarativePositionSource *positionSource);
132     QDeclarativePositionSource *positionSource() const;
133 
134     // To enable/disable automatic route recalculation in the engines
135     bool automaticReroutingEnabled() const;
136     void setAutomaticReroutingEnabled(bool autoRerouting);
137 
138     bool navigatorReady() const;
139 
140     void setTrackPositionSource(bool trackPositionSource);
141     bool trackPositionSource() const;
142 
143     // To discover/notify when the tracked position goes off the active navigation route
144     bool isOnRoute() const;
145 
146     QDeclarativeNavigationBasicDirections *directions() const;
147     QAbstractNavigator *abstractNavigator() const;
148 
149     NavigationError error() const;
150     QString errorString() const;
151 
152     Q_INVOKABLE void recalculateRoutes();
153 
154 signals:
155     void navigatorReadyChanged(bool ready);
156     void trackPositionSourceChanged(bool trackPositionSource);
157     void activeChanged(bool active);
158 
159     void pluginChanged();
160     void mapChanged();
161     void routeChanged();
162     void positionSourceChanged();
163     void errorChanged();
164     void automaticReroutingEnabledChanged();
165     void isOnRouteChanged();
166 
167 protected:
168     void pluginReady();
169     bool ensureEngine();
170     void updateReadyState();
171     void setError(NavigationError error, const QString &errorString);
172 
173 private:
174     QScopedPointer<QDeclarativeNavigatorPrivate> d_ptr;
175 
176     friend class QDeclarativeNavigatorPrivate;
177     friend class QDeclarativeNavigationBasicDirections;
178 };
179 
180 QT_END_NAMESPACE
181 
182 QML_DECLARE_TYPE(QDeclarativeNavigator)
183 
184 
185 #endif // QDECLARATIVENAVIGATOR_P_H
186