1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtPositioning module of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 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 https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General 28 ** Public license version 3 or any later version approved by the KDE Free 29 ** Qt Foundation. The licenses are as published by the Free Software 30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 31 ** included in the packaging of this file. Please review the following 32 ** information to ensure the GNU General Public License requirements will 33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 34 ** https://www.gnu.org/licenses/gpl-3.0.html. 35 ** 36 ** $QT_END_LICENSE$ 37 ** 38 ***************************************************************************/ 39 40 #ifndef QDECLARATIVEPOSITIONSOURCE_H 41 #define QDECLARATIVEPOSITIONSOURCE_H 42 43 // 44 // W A R N I N G 45 // ------------- 46 // 47 // This file is not part of the Qt API. It exists purely as an 48 // implementation detail. This header file may change from version to 49 // version without notice, or even be removed. 50 // 51 // We mean it. 52 // 53 54 #include <QtPositioningQuick/private/qpositioningquickglobal_p.h> 55 #include <QtPositioningQuick/private/qdeclarativeposition_p.h> 56 #include <QtCore/QObject> 57 #include <QtNetwork/QAbstractSocket> 58 #include <QtQml/QQmlParserStatus> 59 #include <QtPositioning/qgeopositioninfosource.h> 60 #include <QtPositioningQuick/private/qdeclarativepluginparameter_p.h> 61 62 QT_BEGIN_NAMESPACE 63 64 class QFile; 65 class QTcpSocket; 66 67 class Q_POSITIONINGQUICK_PRIVATE_EXPORT QDeclarativePositionSource : public QObject, public QQmlParserStatus 68 { 69 Q_OBJECT 70 71 Q_PROPERTY(QDeclarativePosition *position READ position NOTIFY positionChanged) 72 Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) 73 Q_PROPERTY(bool valid READ isValid NOTIFY validityChanged) 74 Q_PROPERTY(QUrl nmeaSource READ nmeaSource WRITE setNmeaSource NOTIFY nmeaSourceChanged) 75 Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval NOTIFY updateIntervalChanged) 76 Q_PROPERTY(PositioningMethods supportedPositioningMethods READ supportedPositioningMethods NOTIFY supportedPositioningMethodsChanged) 77 Q_PROPERTY(PositioningMethods preferredPositioningMethods READ preferredPositioningMethods WRITE setPreferredPositioningMethods NOTIFY preferredPositioningMethodsChanged) 78 Q_PROPERTY(SourceError sourceError READ sourceError NOTIFY sourceErrorChanged) 79 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 80 Q_PROPERTY(QQmlListProperty<QDeclarativePluginParameter> parameters READ parameters REVISION 14) 81 Q_ENUMS(PositioningMethod) 82 83 Q_CLASSINFO("DefaultProperty", "parameters") 84 Q_INTERFACES(QQmlParserStatus) 85 86 public: 87 enum PositioningMethod { 88 NoPositioningMethods = QGeoPositionInfoSource::NoPositioningMethods, 89 SatellitePositioningMethods = QGeoPositionInfoSource::SatellitePositioningMethods, 90 NonSatellitePositioningMethods = QGeoPositionInfoSource::NonSatellitePositioningMethods, 91 AllPositioningMethods = QGeoPositionInfoSource::AllPositioningMethods 92 }; 93 94 Q_DECLARE_FLAGS(PositioningMethods, PositioningMethod) 95 Q_FLAGS(PositioningMethods) 96 97 enum SourceError { 98 AccessError = QGeoPositionInfoSource::AccessError, 99 ClosedError = QGeoPositionInfoSource::ClosedError, 100 UnknownSourceError = QGeoPositionInfoSource::UnknownSourceError, 101 NoError = QGeoPositionInfoSource::NoError, 102 103 //Leave a gap for future error enum values in QGeoPositionInfoSource::Error 104 SocketError = 100 105 }; 106 Q_ENUMS(SourceError) 107 108 QDeclarativePositionSource(); 109 ~QDeclarativePositionSource(); 110 void setNmeaSource(const QUrl &nmeaSource); 111 void setUpdateInterval(int updateInterval); 112 void setActive(bool active); 113 void setPreferredPositioningMethods(PositioningMethods methods); 114 115 QString name() const; 116 void setName(const QString &name); 117 118 QUrl nmeaSource() const; 119 int updateInterval() const; 120 bool isActive() const; 121 bool isValid() const; 122 QDeclarativePosition *position(); 123 PositioningMethods supportedPositioningMethods() const; 124 PositioningMethods preferredPositioningMethods() const; 125 SourceError sourceError() const; 126 QGeoPositionInfoSource *positionSource() const; 127 QQmlListProperty<QDeclarativePluginParameter> parameters(); 128 QVariantMap parameterMap() const; 129 130 // Virtuals from QQmlParserStatus classBegin()131 void classBegin() { } 132 void componentComplete(); 133 134 Q_REVISION(14) Q_INVOKABLE bool setBackendProperty(const QString &name, const QVariant &value); 135 Q_REVISION(14) Q_INVOKABLE QVariant backendProperty(const QString &name) const; 136 137 public Q_SLOTS: 138 void update(); // TODO Qt 6 change to void update(int) 139 void start(); 140 void stop(); 141 142 Q_SIGNALS: 143 void positionChanged(); 144 void activeChanged(); 145 void nmeaSourceChanged(); 146 void updateIntervalChanged(); 147 void supportedPositioningMethodsChanged(); 148 void preferredPositioningMethodsChanged(); 149 void sourceErrorChanged(); 150 void nameChanged(); 151 void validityChanged(); 152 void updateTimeout(); 153 154 private Q_SLOTS: 155 void positionUpdateReceived(const QGeoPositionInfo &update); 156 void sourceErrorReceived(const QGeoPositionInfoSource::Error error); 157 void socketConnected(); 158 void socketError(QAbstractSocket::SocketError error); 159 void updateTimeoutReceived(); 160 void onParameterInitialized(); 161 162 private: 163 void setPosition(const QGeoPositionInfo &pi); 164 void setSource(QGeoPositionInfoSource *source); 165 bool parametersReady(); 166 void tryAttach(const QString &name, bool useFallback = true); 167 168 static void parameter_append(QQmlListProperty<QDeclarativePluginParameter> *prop, QDeclarativePluginParameter *mapObject); 169 static int parameter_count(QQmlListProperty<QDeclarativePluginParameter> *prop); 170 static QDeclarativePluginParameter *parameter_at(QQmlListProperty<QDeclarativePluginParameter> *prop, int index); 171 static void parameter_clear(QQmlListProperty<QDeclarativePluginParameter> *prop); 172 173 QGeoPositionInfoSource *m_positionSource; 174 QDeclarativePosition m_position; 175 PositioningMethods m_preferredPositioningMethods; 176 QFile *m_nmeaFile; 177 QTcpSocket *m_nmeaSocket; 178 QString m_nmeaFileName; 179 QUrl m_nmeaSource; 180 QString m_providerName; 181 bool m_active; 182 bool m_singleUpdate; 183 int m_updateInterval; 184 SourceError m_sourceError; 185 QList<QDeclarativePluginParameter *> m_parameters; 186 bool m_componentComplete = false; 187 bool m_parametersInitialized = false; 188 }; 189 190 QT_END_NAMESPACE 191 192 QML_DECLARE_TYPE(QDeclarativePositionSource) 193 194 #endif 195