diff --git a/src/lib/positionsource/positionsource.cpp b/src/lib/positionsource/positionsource.cpp index 4693b2c..a77d425 100644 --- a/src/lib/positionsource/positionsource.cpp +++ b/src/lib/positionsource/positionsource.cpp @@ -1,92 +1,92 @@ #include "positionsource.h" #include "debug.h" #include PositionSource::PositionSource() { QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); createPositionSource(); } void PositionSource::createPositionSource() { // The smartpointer will take care of the pointer, that's why we are using nullptr as parent. m_geoPositionSource.reset(QGeoPositionInfoSource::createDefaultSource(nullptr)); if (m_geoPositionSource.isNull()) { qCWarning(POSITIONSOURCE) << "Position source is not available for this device."; return; } qCDebug(POSITIONSOURCE) << "New position source:" << m_geoPositionSource->sourceName(); - // Set the update interval to 3s + // Set the update interval to 3s. m_geoPositionSource->setUpdateInterval(3000); m_geoPositionSource->setPreferredPositioningMethods(QGeoPositionInfoSource::SatellitePositioningMethods); m_geoPositionSource->startUpdates(); connect(m_geoPositionSource.get(), QOverload::of(&QGeoPositionInfoSource::error), this, &PositionSource::setPositionSourceError); connect(m_geoPositionSource.get(), &QGeoPositionInfoSource::positionUpdated, this, &PositionSource::setPositionInfo); } bool PositionSource::enabled() const { return m_enabled; } void PositionSource::setEnabled(bool enabled) { if (m_enabled == enabled) { return; } m_enabled = enabled; emit enabledChanged(m_enabled); } void PositionSource::setPositionInfo(const QGeoPositionInfo &geoPositionInfo) { if (!geoPositionInfo.isValid()) { qCWarning(POSITIONSOURCE) << "Not valid position info from position source:" << geoPositionInfo; return; } const auto geoCoordinate = geoPositionInfo.coordinate(); if (m_geoCoordinate == geoCoordinate) { return; } m_geoCoordinate = geoCoordinate; emit coordinateChanged(m_geoCoordinate); } QGeoCoordinate PositionSource::coordinate() const { return m_geoCoordinate; } const QGeoPositionInfoSource *PositionSource::positionInfoSource() const { return m_geoPositionSource.get(); } void PositionSource::setPositionSourceError(QGeoPositionInfoSource::Error positioningError) { qWarning(POSITIONSOURCE) << "Position source error:" << positioningError; } QObject *PositionSource::qmlSingletonRegister(QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return &self(); } PositionSource &PositionSource::self() { static PositionSource self; return self; } diff --git a/src/lib/positionsource/positionsource.h b/src/lib/positionsource/positionsource.h index bcf2e9a..0db879e 100644 --- a/src/lib/positionsource/positionsource.h +++ b/src/lib/positionsource/positionsource.h @@ -1,101 +1,101 @@ #pragma once #include #include class QJSEngine; class QQmlEngine; /** - * @brief Manage the position source of the ground control station + * @brief Manage the position source of the ground control station. * */ class PositionSource : public QObject { Q_OBJECT Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) Q_PROPERTY(QGeoCoordinate coordinate READ coordinate NOTIFY coordinateChanged) public: /** - * @brief Return PositionSource status, if it's enabled + * @brief Return PositionSource status, if it's enabled. * - * @return true PositionSource is enable and working - * @return false Positionsource is disabled + * @return true PositionSource is enable and working. + * @return false Positionsource is disabled. */ bool enabled() const; /** - * @brief Turn PositionSource to enable or disable + * @brief Turn PositionSource to enable or disable. * * @param enabled */ void setEnabled(bool enabled); /** - * @brief Set a new position info + * @brief Set a new position info. * * @param geoPositionInfo */ void setPositionInfo(const QGeoPositionInfo &geoPositionInfo); /** - * @brief Return the last valid coordinate + * @brief Return the last valid coordinate. * * @return QGeoCoordinate */ QGeoCoordinate coordinate() const; /** - * @brief Return the position source for this class + * @brief Return the position source for this class. * * @return const QGeoPositionInfoSource* */ const QGeoPositionInfoSource *positionInfoSource() const; /** - * @brief Return PositionSource pointer + * @brief Return PositionSource pointer. * * @return PositionSource* */ static PositionSource &self(); /** - * @brief Return a pointer of this singleton to the qml register function + * @brief Return a pointer of this singleton to the qml register function. * * @param engine * @param scriptEngine * @return QObject* */ static QObject *qmlSingletonRegister(QQmlEngine *engine, QJSEngine *scriptEngine); Q_SIGNALS: void enabledChanged(bool enabled); void coordinateChanged(const QGeoCoordinate &geoCoordinate); private: Q_DISABLE_COPY(PositionSource) /** - * @brief Construct a new Position Source object + * @brief Construct a new Position Source object. * */ PositionSource(); /** - * @brief Create the position source for this class + * @brief Create the position source for this class. * */ void createPositionSource(); /** - * @brief Set position source error type + * @brief Set position source error type. * * @param positioningError */ void setPositionSourceError(QGeoPositionInfoSource::Error positioningError); bool m_enabled; QGeoCoordinate m_geoCoordinate; QSharedPointer m_geoPositionSource; };