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_P_H 38 #define QDECLARATIVENAVIGATOR_P_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 <QtCore/qlist.h> 52 #include <QtLocation/private/qlocationglobal_p.h> 53 #include <QtCore/qpointer.h> 54 #include <QtLocation/qgeoroute.h> 55 #include <QtLocation/private/qdeclarativenavigator_p.h> 56 #include <QAbstractListModel> 57 #include <QtLocation/private/qdeclarativegeoroute_p.h> 58 #include <QtLocation/private/qdeclarativegeoroutemodel_p.h> 59 60 QT_BEGIN_NAMESPACE 61 62 class QDeclarativeGeoServiceProvider; 63 class QDeclarativeGeoMap; 64 class QNavigationManager; 65 class QDeclarativeGeoRoute; 66 class QDeclarativeGeoRouteLeg; 67 class QDeclarativePositionSource; 68 class QGeoMapParameter; 69 class QDeclarativeGeoRouteSegment; 70 class QParameterizableObject; 71 class QAbstractNavigator; 72 73 template<typename T, int Role> 74 class ReadOnlyListModel : public QAbstractListModel 75 { 76 public: 77 explicit ReadOnlyListModel(const QByteArray &dataRoleName, QObject *parent = nullptr) QAbstractListModel(parent)78 : QAbstractListModel(parent) 79 { 80 m_roleNames.insert(Role, dataRoleName); 81 } 82 rowCount(const QModelIndex &)83 int rowCount(const QModelIndex &) const override 84 { 85 return m_data.size(); 86 } 87 88 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override 89 { 90 const int row = index.row(); 91 if (!index.isValid() || row < 0 || row >= m_data.size() || role != Role) 92 return QVariant(); 93 94 return QVariant::fromValue(m_data.at(row)); 95 } 96 roleNames()97 QHash<int, QByteArray> roleNames() const override 98 { 99 return m_roleNames; 100 } 101 updateData(const QList<T * > & data)102 void updateData(const QList<T*> &data) 103 { 104 beginResetModel(); 105 qDeleteAll(m_data); 106 m_data = data; 107 endResetModel(); 108 } 109 110 protected: 111 QHash<int, QByteArray> m_roleNames; 112 QList<T*> m_data; 113 }; 114 115 class Q_LOCATION_PRIVATE_EXPORT QDeclarativeNavigationBasicDirections : public QObject 116 { 117 Q_OBJECT 118 119 Q_PROPERTY(QVariant nextManeuverIcon READ nextManeuverIcon NOTIFY nextManeuverIconChanged) 120 Q_PROPERTY(qreal distanceToNextManeuver READ distanceToNextManeuver NOTIFY progressInformationChanged) 121 Q_PROPERTY(qreal remainingTravelDistance READ remainingTravelDistance NOTIFY progressInformationChanged) 122 Q_PROPERTY(qreal remainingTravelDistanceToNextWaypoint READ remainingTravelDistanceToNextWaypoint NOTIFY progressInformationChanged) 123 Q_PROPERTY(qreal traveledDistance READ traveledDistance NOTIFY progressInformationChanged) 124 Q_PROPERTY(int timeToNextManeuver READ timeToNextManeuver NOTIFY progressInformationChanged) 125 Q_PROPERTY(int remainingTravelTime READ remainingTravelTime NOTIFY progressInformationChanged) 126 Q_PROPERTY(int remainingTravelTimeToNextWaypoint READ remainingTravelTimeToNextWaypoint NOTIFY progressInformationChanged) 127 Q_PROPERTY(int traveledTime READ traveledTime NOTIFY progressInformationChanged) 128 Q_PROPERTY(QDeclarativeGeoRoute *currentRoute READ currentRoute NOTIFY currentRouteChanged) 129 Q_PROPERTY(QDeclarativeGeoRouteLeg *currentRouteLeg READ currentRouteLeg NOTIFY currentRouteChanged) 130 Q_PROPERTY(int currentSegment READ currentSegment NOTIFY currentSegmentChanged) 131 Q_PROPERTY(QAbstractItemModel *alternativeRoutes READ alternativeRoutes CONSTANT) 132 133 public: 134 explicit QDeclarativeNavigationBasicDirections(QDeclarativeNavigator *parent); 135 136 QVariant nextManeuverIcon() const; 137 qreal distanceToNextManeuver() const; 138 qreal remainingTravelDistance() const; 139 qreal remainingTravelDistanceToNextWaypoint() const; 140 qreal traveledDistance() const; 141 int timeToNextManeuver() const; 142 int remainingTravelTime() const; 143 int remainingTravelTimeToNextWaypoint() const; 144 int traveledTime() const; 145 146 QDeclarativeGeoRoute *currentRoute() const; 147 QDeclarativeGeoRouteLeg *currentRouteLeg() const; 148 int currentSegment() const; 149 QAbstractItemModel *alternativeRoutes(); 150 151 Q_SIGNALS: 152 void progressInformationChanged(); 153 void nextManeuverIconChanged(); 154 void currentRouteChanged(); 155 void currentRouteLegChanged(); 156 void currentSegmentChanged(); 157 void waypointReached(const QDeclarativeGeoWaypoint *pos); 158 void destinationReached(); 159 160 protected slots: 161 void onCurrentRouteChanged(); 162 void onCurrentRouteLegChanged(); 163 void onAlternativeRoutesChanged(); 164 165 protected: 166 QDeclarativeNavigator *m_navigator; 167 QDeclarativeNavigatorPrivate *m_navigatorPrivate; 168 QPointer<QDeclarativeGeoRoute> m_currentRoute; 169 QPointer<QDeclarativeGeoRouteLeg> m_currentRouteLeg; 170 ReadOnlyListModel<QDeclarativeGeoRoute, QDeclarativeGeoRouteModel::RouteRole> m_routes; 171 172 friend class QDeclarativeNavigator; 173 }; 174 175 class Q_LOCATION_PRIVATE_EXPORT QDeclarativeNavigatorParams 176 { 177 public: 178 QPointer<QDeclarativeGeoMap> m_map; 179 QPointer<QDeclarativeGeoRoute> m_route; 180 QGeoRoute m_geoRoute; 181 QPointer<QDeclarativePositionSource> m_positionSource; 182 QList<QPointer<QGeoMapParameter>> m_parameters; 183 bool m_trackPositionSource = true; 184 bool m_autoRerouting = true; 185 }; 186 187 class QDeclarativeNavigatorPrivate 188 { 189 public: 190 QDeclarativeNavigatorPrivate(QParameterizableObject *q_); 191 192 QParameterizableObject *q = nullptr; 193 QSharedPointer<QDeclarativeNavigatorParams> m_params; 194 QScopedPointer<QAbstractNavigator> m_navigator; 195 QDeclarativeGeoServiceProvider *m_plugin = nullptr; 196 QDeclarativeNavigationBasicDirections m_basicDirections; 197 198 bool m_active = false; 199 bool m_completed = false; 200 bool m_ready = false; 201 QDeclarativeNavigator::NavigationError m_error = QDeclarativeNavigator::NoError; 202 QString m_errorString; 203 }; 204 205 QT_END_NAMESPACE 206 207 #endif // QDECLARATIVENAVIGATOR_P_P_H 208