File indexing completed on 2024-05-26 05:54:03
0001 /* 0002 * Copyright 2019 Patrick José Pereira <patrickjp@kde.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) version 3, or any 0008 * later version accepted by the membership of KDE e.V. (or its 0009 * successor approved by the membership of KDE e.V.), which shall 0010 * act as a proxy defined in Section 6 of version 3 of the license. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public 0018 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #pragma once 0022 0023 #include <QGeoPositionInfoSource> 0024 #include <QSharedPointer> 0025 0026 class QJSEngine; 0027 class QQmlEngine; 0028 0029 /** 0030 * @brief Manage the position source of the ground control station. 0031 * 0032 */ 0033 class PositionSource : public QObject 0034 { 0035 Q_OBJECT 0036 0037 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) 0038 Q_PROPERTY(QGeoCoordinate coordinate READ coordinate NOTIFY coordinateChanged) 0039 0040 public: 0041 /** 0042 * @brief Return PositionSource status, if it's enabled. 0043 * 0044 * @return true PositionSource is enable and working. 0045 * @return false Positionsource is disabled. 0046 */ 0047 bool enabled() const; 0048 0049 /** 0050 * @brief Turn PositionSource to enable or disable. 0051 * 0052 * @param enabled 0053 */ 0054 void setEnabled(bool enabled); 0055 0056 /** 0057 * @brief Set a new position info. 0058 * 0059 * @param geoPositionInfo 0060 */ 0061 void setPositionInfo(const QGeoPositionInfo &geoPositionInfo); 0062 0063 /** 0064 * @brief Return the last valid coordinate. 0065 * 0066 * @return QGeoCoordinate 0067 */ 0068 QGeoCoordinate coordinate() const; 0069 0070 /** 0071 * @brief Return the position source for this class. 0072 * 0073 * @return const QGeoPositionInfoSource* 0074 */ 0075 const QGeoPositionInfoSource *positionInfoSource() const; 0076 0077 /** 0078 * @brief Return PositionSource pointer. 0079 * 0080 * @return PositionSource* 0081 */ 0082 static PositionSource &self(); 0083 0084 /** 0085 * @brief Return a pointer of this singleton to the qml register function. 0086 * 0087 * @param engine 0088 * @param scriptEngine 0089 * @return QObject* 0090 */ 0091 static QObject *qmlSingletonRegister(QQmlEngine *engine, QJSEngine *scriptEngine); 0092 0093 Q_SIGNALS: 0094 void enabledChanged(bool enabled); 0095 void coordinateChanged(const QGeoCoordinate &geoCoordinate); 0096 0097 private: 0098 Q_DISABLE_COPY(PositionSource) 0099 /** 0100 * @brief Construct a new Position Source object. 0101 * 0102 */ 0103 PositionSource(); 0104 0105 /** 0106 * @brief Create the position source for this class. 0107 * 0108 */ 0109 void createPositionSource(); 0110 0111 /** 0112 * @brief Set position source error type. 0113 * 0114 * @param positioningError 0115 */ 0116 static void setPositionSourceError(QGeoPositionInfoSource::Error positioningError); 0117 0118 bool m_enabled; 0119 QGeoCoordinate m_geoCoordinate; 0120 QSharedPointer<QGeoPositionInfoSource> m_geoPositionSource; 0121 };