diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index c2c2e8a0a..61709f5b0 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -32,8 +32,10 @@ set(MM_SRCS ios/iosutils.cpp position/providers/abstractpositionprovider.cpp position/providers/internalpositionprovider.cpp + position/providers/networkpositionprovider.cpp position/providers/positionprovidersmodel.cpp position/providers/simulatedpositionprovider.cpp + position/providers/nmeaparser.cpp position/tracking/abstracttrackingbackend.cpp position/tracking/internaltrackingbackend.cpp position/tracking/positiontrackinghighlight.cpp @@ -126,8 +128,10 @@ set(MM_HDRS ios/iosutils.h position/providers/abstractpositionprovider.h position/providers/internalpositionprovider.h + position/providers/networkpositionprovider.h position/providers/positionprovidersmodel.h position/providers/simulatedpositionprovider.h + position/providers/nmeaparser.h position/tracking/abstracttrackingbackend.h position/tracking/internaltrackingbackend.h position/tracking/positiontrackinghighlight.h diff --git a/app/appsettings.cpp b/app/appsettings.cpp index 3fdb51099..ee139728b 100644 --- a/app/appsettings.cpp +++ b/app/appsettings.cpp @@ -215,6 +215,7 @@ QVariantList AppSettings::savedPositionProviders() const QStringList provider; provider << settings.value( "providerName" ).toString(); provider << settings.value( "providerAddress" ).toString(); + provider << settings.value( "providerType" ).toString(); providers.push_back( provider ); } @@ -238,15 +239,16 @@ void AppSettings::savePositionProviders( const QVariantList &providers ) { QVariantList provider = providers[i].toList(); - if ( provider.length() < 2 ) + if ( provider.length() < 3 ) { CoreUtils::log( QStringLiteral( "AppSettings" ), QStringLiteral( "Tried to save provider without sufficient data" ) ); continue; } settings.setArrayIndex( i ); - settings.setValue( "providerName", providers[i].toList()[0] ); - settings.setValue( "providerAddress", providers[i].toList()[1] ); + settings.setValue( "providerName", provider[0] ); + settings.setValue( "providerAddress", provider[1] ); + settings.setValue( "providerType", provider[2] ); } settings.endArray(); } diff --git a/app/icons/Bluetooth.svg b/app/icons/Bluetooth.svg new file mode 100644 index 000000000..f18e6d485 --- /dev/null +++ b/app/icons/Bluetooth.svg @@ -0,0 +1,3 @@ + + + diff --git a/app/icons/Network.svg b/app/icons/Network.svg new file mode 100644 index 000000000..3ff4e7b3d --- /dev/null +++ b/app/icons/Network.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/app/icons/icons.qrc b/app/icons/icons.qrc index 656d4b479..5345ce912 100644 --- a/app/icons/icons.qrc +++ b/app/icons/icons.qrc @@ -7,6 +7,7 @@ ArrowLinkRight.svg ArrowUp.svg Back.svg + Bluetooth.svg Briefcase.svg Calendar.svg Checkmark.svg @@ -58,6 +59,7 @@ Mouth.svg NaturalResources.svg Next.svg + Network.svg Other.svg Others.svg Personal.svg diff --git a/app/images/ExternalBluetoothProvider.svg b/app/images/ExternalBluetoothProvider.svg new file mode 100644 index 000000000..35f92c7bd --- /dev/null +++ b/app/images/ExternalBluetoothProvider.svg @@ -0,0 +1,274 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/images/ExternalGpsGreen.svg b/app/images/ExternalGpsGreen.svg deleted file mode 100644 index d5a833bd7..000000000 --- a/app/images/ExternalGpsGreen.svg +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/app/images/ExternalGpsRed.svg b/app/images/ExternalGpsRed.svg index 9fd5a52d2..67f981956 100644 --- a/app/images/ExternalGpsRed.svg +++ b/app/images/ExternalGpsRed.svg @@ -1,14 +1,276 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + - + diff --git a/app/images/ExternalNetworkProvider.svg b/app/images/ExternalNetworkProvider.svg new file mode 100644 index 000000000..a2602f99f --- /dev/null +++ b/app/images/ExternalNetworkProvider.svg @@ -0,0 +1,277 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/images/images.qrc b/app/images/images.qrc index b0b772a30..2d2cf69f2 100644 --- a/app/images/images.qrc +++ b/app/images/images.qrc @@ -19,8 +19,9 @@ UploadImage.svg WarnLogoImage.svg NoMapThemesImage.svg + ExternalBluetoothProvider.svg ExternalGpsRed.svg - ExternalGpsGreen.svg + ExternalNetworkProvider.svg NegativeMMSymbol.svg PositiveMMSymbol.svg NeutralMMSymbol.svg diff --git a/app/inpututils.cpp b/app/inpututils.cpp index 855e5b2c2..ff416949a 100644 --- a/app/inpututils.cpp +++ b/app/inpututils.cpp @@ -2105,6 +2105,29 @@ void InputUtils::updateQgisFormats( const QByteArray &output ) #endif } +QString InputUtils::getUniqueString( const QString &newString, const QStringList &existingStrings ) +{ + const QRegularExpression regex( QStringLiteral( R"(^(.*)\((\d+)\)$)" ) ); + QString uniqueString( newString.trimmed() ); + int i = 1; + while ( existingStrings.contains( uniqueString ) ) + { + // if the string ends with "(x)" where x is integer number replace it in place + auto regexMatch = regex.match( uniqueString ); + if ( regexMatch.hasMatch() ) + { + i = regexMatch.captured( 2 ).toInt() + 1; + uniqueString = QStringLiteral( "%1 (%2)" ).arg( regexMatch.captured( 1 ).trimmed(), QString::number( i ) ); + } + else + { + uniqueString = QStringLiteral( "%1 (%2)" ).arg( newString.trimmed(), QString::number( i ) ); + } + i++; + } + return uniqueString; +} + bool InputUtils::rescaleImage( const QString &path, QgsProject *activeProject ) { int quality = activeProject->readNumEntry( QStringLiteral( "Mergin" ), QStringLiteral( "PhotoQuality" ), 0 ); diff --git a/app/inpututils.h b/app/inpututils.h index d94e1803e..adda3cb60 100644 --- a/app/inpututils.h +++ b/app/inpututils.h @@ -662,6 +662,19 @@ class InputUtils: public QObject */ static void updateQgisFormats( const QByteArray &output ); + /** + * From received string checks occurrences in existingStrings and returns first next unique option. Appends " (i)" + * behind received string or replaces it if it exists, where i is the smallest possible number starting from 1 if + * appending and next smallest if replacing. + * "lutra" -> "lutra (1)" + * "lutra (256)" -> "lutra (257)" + * " lutra " -> "lutra (1)" + * \param newString wanted string + * \param existingStrings QStringList of possible similar values + * \return unique variant of wanted string + */ + static QString getUniqueString( const QString &newString, const QStringList &existingStrings ); + public slots: void onQgsLogMessageReceived( const QString &message, const QString &tag, Qgis::MessageLevel level ); diff --git a/app/mmstyle.h b/app/mmstyle.h index aa2207657..e739b4b95 100644 --- a/app/mmstyle.h +++ b/app/mmstyle.h @@ -112,6 +112,7 @@ class MMStyle: public QObject Q_PROPERTY( QUrl arrowDownIcon READ arrowDownIcon CONSTANT ) Q_PROPERTY( QUrl arrowLinkRightIcon READ arrowLinkRightIcon CONSTANT ) Q_PROPERTY( QUrl arrowUpIcon READ arrowUpIcon CONSTANT ) + Q_PROPERTY( QUrl bluetoothIcon READ bluetoothIcon CONSTANT ) Q_PROPERTY( QUrl backIcon READ backIcon CONSTANT ) Q_PROPERTY( QUrl briefcaseIcon READ briefcaseIcon CONSTANT ) Q_PROPERTY( QUrl calendarIcon READ calendarIcon CONSTANT ) @@ -145,6 +146,7 @@ class MMStyle: public QObject Q_PROPERTY( QUrl mouthIcon READ mouthIcon CONSTANT ) Q_PROPERTY( QUrl naturalResourcesIcon READ naturalResourcesIcon CONSTANT ) Q_PROPERTY( QUrl nextIcon READ nextIcon CONSTANT ) + Q_PROPERTY( QUrl networkIcon READ networkIcon CONSTANT ) Q_PROPERTY( QUrl otherIcon READ otherIcon CONSTANT ) Q_PROPERTY( QUrl othersIcon READ othersIcon CONSTANT ) Q_PROPERTY( QUrl plusIcon READ plusIcon CONSTANT ) @@ -228,8 +230,9 @@ class MMStyle: public QObject Q_PROPERTY( QUrl positionTrackingRunningImage READ positionTrackingRunningImage CONSTANT ) Q_PROPERTY( QUrl positionTrackingStartImage READ positionTrackingStartImage CONSTANT ) Q_PROPERTY( QUrl syncImage READ syncImage CONSTANT ) - Q_PROPERTY( QUrl externalGpsGreenImage READ externalGpsGreenImage CONSTANT ) Q_PROPERTY( QUrl externalGpsRedImage READ externalGpsRedImage CONSTANT ) + Q_PROPERTY( QUrl externalBluetoothGreenImage READ externalBluetoothGreenImage CONSTANT ) + Q_PROPERTY( QUrl externalNetworkGreenImage READ externalNetworkGreenImage CONSTANT ) Q_PROPERTY( QUrl negativeMMSymbolImage READ negativeMMSymbolImage CONSTANT ) Q_PROPERTY( QUrl positiveMMSymbolImage READ positiveMMSymbolImage CONSTANT ) Q_PROPERTY( QUrl neutralMMSymbolImage READ neutralMMSymbolImage CONSTANT ) @@ -425,6 +428,7 @@ class MMStyle: public QObject QUrl arrowLinkRightIcon() const {return QUrl( "qrc:/ArrowLinkRight.svg" );} QUrl arrowUpIcon() const {return QUrl( "qrc:/ArrowUp.svg" );} QUrl backIcon() const {return QUrl( "qrc:/Back.svg" );} + QUrl bluetoothIcon() const {return QUrl( "qrc:/Bluetooth.svg" );} QUrl briefcaseIcon() const {return QUrl( "qrc:/Briefcase.svg" );} QUrl calendarIcon() const {return QUrl( "qrc:/Calendar.svg" );} QUrl checkmarkIcon() const {return QUrl( "qrc:/Checkmark.svg" );} @@ -456,6 +460,7 @@ class MMStyle: public QObject QUrl remoteImageLoadErrorIcon() const {return QUrl( "qrc:/RemoteImageLoadError.svg" );} QUrl mouthIcon() const {return QUrl( "qrc:/Mouth.svg" );} QUrl measurementToolIcon() const {return QUrl( "qrc:/Measure.svg" );} + QUrl networkIcon() const {return QUrl( "qrc:/Network.svg" );} QUrl closeShapeIcon() const {return QUrl( "qrc:/CloseShape.svg" );} QUrl naturalResourcesIcon() const {return QUrl( "qrc:/NaturalResources.svg" );} QUrl nextIcon() const {return QUrl( "qrc:/Next.svg" );} @@ -532,8 +537,9 @@ class MMStyle: public QObject QUrl positionTrackingRunningImage() const {return QUrl( "qrc:/images/PositionTrackingRunning.svg" );} QUrl positionTrackingStartImage() const {return QUrl( "qrc:/images/PositionTrackingStart.svg" );} QUrl syncImage() const {return QUrl( "qrc:/images/SyncImage.svg" );} - QUrl externalGpsGreenImage() const {return QUrl( "qrc:/images/ExternalGpsGreen.svg" );} QUrl externalGpsRedImage() const {return QUrl( "qrc:/images/ExternalGpsRed.svg" );} + QUrl externalBluetoothGreenImage() const {return QUrl( "qrc:/images/ExternalBluetoothProvider.svg" );} + QUrl externalNetworkGreenImage() const {return QUrl( "qrc:/images/ExternalNetworkProvider.svg" );} QUrl negativeMMSymbolImage() const {return QUrl( "qrc:/images/NegativeMMSymbol.svg" );} QUrl positiveMMSymbolImage() const {return QUrl( "qrc:/images/PositiveMMSymbol.svg" );} QUrl neutralMMSymbolImage() const {return QUrl( "qrc:/images/NeutralMMSymbol.svg" );} diff --git a/app/position/positionkit.cpp b/app/position/positionkit.cpp index 85c6677a5..8484cdbc0 100644 --- a/app/position/positionkit.cpp +++ b/app/position/positionkit.cpp @@ -7,27 +7,26 @@ * * ***************************************************************************/ -#include "position/positionkit.h" +#include "positionkit.h" + +#include + #include "coreutils.h" #include "mmconfig.h" -#include "qgis.h" +#include "appsettings.h" +#include "inpututils.h" #ifdef HAVE_BLUETOOTH -#include "position/providers/bluetoothpositionprovider.h" +#include "providers/bluetoothpositionprovider.h" #endif - -#include "position/providers/internalpositionprovider.h" -#include "position/providers/simulatedpositionprovider.h" +#include "providers/internalpositionprovider.h" +#include "providers/simulatedpositionprovider.h" +#include "providers/networkpositionprovider.h" #ifdef ANDROID -#include "position/providers/androidpositionprovider.h" +#include "providers/androidpositionprovider.h" #include #endif -#include "appsettings.h" -#include "inpututils.h" - -#include - PositionKit::PositionKit( QObject *parent ) : QObject( parent ) { @@ -126,64 +125,76 @@ QString PositionKit::positionProviderName() const AbstractPositionProvider *PositionKit::constructProvider( const QString &type, const QString &id, const QString &name ) { - QString providerType( type ); - - // currently the only external provider is bluetooth, so manually set internal provider for platforms that - // do not support reading bluetooth serial -#ifndef HAVE_BLUETOOTH - providerType = QStringLiteral( "internal" ); -#endif - if ( providerType == QStringLiteral( "external" ) ) - { #ifdef HAVE_BLUETOOTH + if ( type == QStringLiteral( "external_bt" ) ) + { AbstractPositionProvider *provider = new BluetoothPositionProvider( id, name, *mPositionTransformer ); QQmlEngine::setObjectOwnership( provider, QQmlEngine::CppOwnership ); return provider; -#endif } - else // type == internal +#endif + + if ( type == QStringLiteral( "external_ip" ) ) { - if ( id == QStringLiteral( "simulated" ) ) - { - AbstractPositionProvider *provider = new SimulatedPositionProvider( *mPositionTransformer ); - QQmlEngine::setObjectOwnership( provider, QQmlEngine::CppOwnership ); - return provider; - } -#ifdef ANDROID - if ( id == QStringLiteral( "android_fused" ) || id == QStringLiteral( "android_gps" ) ) + QString providerName( name ); + if ( providerName.isEmpty() ) { - const bool fused = ( id == QStringLiteral( "android_fused" ) ); - if ( fused && !AndroidPositionProvider::isFusedAvailable() ) + QStringList providerNames; + for ( const QVariant &provider : mAppSettings->savedPositionProviders() ) { - // TODO: inform user + use AndroidPositionProvider::fusedErrorString() output? - - // fallback to the default - at this point the Qt Positioning implementation - AbstractPositionProvider *provider = new InternalPositionProvider( *mPositionTransformer ); - QQmlEngine::setObjectOwnership( provider, QQmlEngine::CppOwnership ); - return provider; + providerNames << provider.toStringList().at( 0 ); } - __android_log_print( ANDROID_LOG_INFO, "CPP", "MAKE PROVIDER %d", fused ); - AbstractPositionProvider *provider = new AndroidPositionProvider( fused, *mPositionTransformer ); - QQmlEngine::setObjectOwnership( provider, QQmlEngine::CppOwnership ); - return provider; + providerName = InputUtils::getUniqueString( tr( "Network device" ), providerNames ); } -#endif - else // id == devicegps + AbstractPositionProvider *provider = new NetworkPositionProvider( id, providerName, *mPositionTransformer ); + QQmlEngine::setObjectOwnership( provider, QQmlEngine::CppOwnership ); + return provider; + } + + // from this point type == internal + + if ( id == QStringLiteral( "simulated" ) ) + { + AbstractPositionProvider *provider = new SimulatedPositionProvider( *mPositionTransformer ); + QQmlEngine::setObjectOwnership( provider, QQmlEngine::CppOwnership ); + return provider; + } + +#ifdef ANDROID + if ( id == QStringLiteral( "android_fused" ) || id == QStringLiteral( "android_gps" ) ) + { + const bool fused = ( id == QStringLiteral( "android_fused" ) ); + if ( fused && !AndroidPositionProvider::isFusedAvailable() ) { + // TODO: inform user + use AndroidPositionProvider::fusedErrorString() output? + + // fallback to the default - at this point the Qt Positioning implementation AbstractPositionProvider *provider = new InternalPositionProvider( *mPositionTransformer ); QQmlEngine::setObjectOwnership( provider, QQmlEngine::CppOwnership ); return provider; } + __android_log_print( ANDROID_LOG_INFO, "CPP", "MAKE PROVIDER %d", fused ); + AbstractPositionProvider *provider = new AndroidPositionProvider( fused, *mPositionTransformer ); + QQmlEngine::setObjectOwnership( provider, QQmlEngine::CppOwnership ); + return provider; + } +#endif + + // id == devicegps + { + AbstractPositionProvider *provider = new InternalPositionProvider( *mPositionTransformer ); + QQmlEngine::setObjectOwnership( provider, QQmlEngine::CppOwnership ); + return provider; } } -AbstractPositionProvider *PositionKit::constructActiveProvider( AppSettings *appsettings ) +AbstractPositionProvider *PositionKit::constructActiveProvider( const AppSettings *appsettings ) { if ( !appsettings ) return nullptr; - QString providerId = appsettings->activePositionProviderId(); + const QString &providerId = appsettings->activePositionProviderId(); if ( providerId.isEmpty() ) // nothing has been written to qsettings { @@ -195,39 +206,41 @@ AbstractPositionProvider *PositionKit::constructActiveProvider( AppSettings *app return constructProvider( QStringLiteral( "internal" ), QStringLiteral( "devicegps" ) ); #endif } - else // desktop - { - return constructProvider( QStringLiteral( "internal" ), QStringLiteral( "simulated" ) ); - } + // desktop + return constructProvider( QStringLiteral( "internal" ), QStringLiteral( "simulated" ) ); } - else if ( providerId == QStringLiteral( "devicegps" ) || providerId == QStringLiteral( "simulated" ) || - providerId == QStringLiteral( "android_fused" ) || providerId == QStringLiteral( "android_gps" ) ) + if ( providerId == QStringLiteral( "devicegps" ) || providerId == QStringLiteral( "simulated" ) || + providerId == QStringLiteral( "android_fused" ) || providerId == QStringLiteral( "android_gps" ) ) { return constructProvider( QStringLiteral( "internal" ), providerId ); } - else - { - // find name of the active provider - QString providerName; - QVariantList providers = appsettings->savedPositionProviders(); - for ( const auto &provider : providers ) + // find name & type of the active provider + QString providerName; + // Migration from single external provider to multiple currently, missing type == bluetooth provider + QString providerType = QStringLiteral( "external_bt" ); + QVariantList providers = appsettings->savedPositionProviders(); + + for ( const QVariant &provider : providers ) + { + QVariantList providerData = provider.toList(); + if ( providerData.length() < 2 ) { - QVariantList providerData = provider.toList(); - if ( providerData.length() < 2 ) - { - CoreUtils::log( QStringLiteral( "PositionKit" ), QStringLiteral( "Found provider with insufficient data" ) ); - continue; - } + CoreUtils::log( QStringLiteral( "PositionKit" ), QStringLiteral( "Found provider with insufficient data" ) ); + continue; + } - if ( providerData[1] == providerId ) + if ( providerData[1] == providerId ) + { + providerName = providerData[0].toString(); + if ( !providerData.at( 2 ).isNull() ) { - providerName = providerData[0].toString(); + providerType = providerData[2].toString(); } } - - return constructProvider( QStringLiteral( "external" ), providerId, providerName ); } + + return constructProvider( providerType, providerId, providerName ); } void PositionKit::parsePositionUpdate( const GeoPosition &newPosition ) @@ -407,7 +420,7 @@ void PositionKit::setSkipElevationTransformation( const bool skipElevationTransf mSkipElevationTransformation = skipElevationTransformation; } -void PositionKit::appStateChanged( Qt::ApplicationState state ) +void PositionKit::appStateChanged( const Qt::ApplicationState state ) { if ( state == Qt::ApplicationActive ) { @@ -449,9 +462,9 @@ double PositionKit::geoidSeparation() const QgsPoint PositionKit::positionCoordinate() const { if ( mPosition.hasValidPosition() ) - return QgsPoint( mPosition.longitude, mPosition.latitude, mPosition.elevation ); + return { mPosition.longitude, mPosition.latitude, mPosition.elevation }; - return QgsPoint(); + return {}; } bool PositionKit::hasPosition() const @@ -556,7 +569,7 @@ void PositionKit::setAppSettings( AppSettings *appSettings ) mAppSettings = appSettings; if ( mAppSettings ) { - QObject::connect( mAppSettings, &AppSettings::gpsAntennaHeightChanged, this, &PositionKit::antennaHeightChanged ); + connect( mAppSettings, &AppSettings::gpsAntennaHeightChanged, this, &PositionKit::antennaHeightChanged ); } emit appSettingsChanged(); emit antennaHeightChanged(); @@ -569,8 +582,6 @@ double PositionKit::antennaHeight() const { return mAppSettings->gpsAntennaHeight(); } - else - { - return 0; - } + + return 0; } diff --git a/app/position/positionkit.h b/app/position/positionkit.h index b0ab11de9..6c9bc006f 100644 --- a/app/position/positionkit.h +++ b/app/position/positionkit.h @@ -137,7 +137,7 @@ class PositionKit : public QObject Q_INVOKABLE QString positionCrs3DGeoidModelName(); Q_INVOKABLE AbstractPositionProvider *constructProvider( const QString &type, const QString &id, const QString &name = QString() ); - Q_INVOKABLE AbstractPositionProvider *constructActiveProvider( AppSettings *appsettings ); + Q_INVOKABLE AbstractPositionProvider *constructActiveProvider( const AppSettings *appsettings ); AppSettings *appSettings() const; void setAppSettings( AppSettings *appSettings ); diff --git a/app/position/positiontransformer.cpp b/app/position/positiontransformer.cpp index 3d5dd559c..52071dd16 100644 --- a/app/position/positiontransformer.cpp +++ b/app/position/positiontransformer.cpp @@ -50,6 +50,11 @@ GeoPosition PositionTransformer::processBluetoothPosition( GeoPosition geoPositi return geoPosition; } +GeoPosition PositionTransformer::processNetworkPosition( const GeoPosition &geoPosition ) +{ + return processBluetoothPosition( geoPosition ); +} + GeoPosition PositionTransformer::processAndroidPosition( GeoPosition geoPosition ) { if ( geoPosition.elevation != std::numeric_limits::quiet_NaN() ) diff --git a/app/position/positiontransformer.h b/app/position/positiontransformer.h index 87e4a2c6a..0bac4de0f 100644 --- a/app/position/positiontransformer.h +++ b/app/position/positiontransformer.h @@ -49,6 +49,14 @@ class PositionTransformer : QObject */ GeoPosition processBluetoothPosition( GeoPosition geoPosition ); + /** + * Transform the elevation if the user sets custom vertical CRS. The elevation gets recalculated to ellipsoid elevation + * and then back to orthometric based on specified CRS. + * \note This method should be used only with NetworkPositionProvider to mitigate unnecessary transformations + * \return Copy of passed geoPosition with processed elevation and elevation separation. + */ + GeoPosition processNetworkPosition( const GeoPosition &geoPosition ); + /** * Transform the elevation from EPSG:4979 (WGS84 (EPSG:4326) + ellipsoidal height) to specified geoid model * (by default EPSG:9707 (WGS84 + EGM96)) diff --git a/app/position/providers/bluetoothpositionprovider.cpp b/app/position/providers/bluetoothpositionprovider.cpp index c96a235db..380c595fe 100644 --- a/app/position/providers/bluetoothpositionprovider.cpp +++ b/app/position/providers/bluetoothpositionprovider.cpp @@ -19,19 +19,8 @@ #include #endif -NmeaParser::NmeaParser() : QgsNmeaConnection( new QBluetoothSocket() ) -{ -} - -QgsGpsInformation NmeaParser::parseNmeaString( const QString &nmeaString ) -{ - mStringBuffer = nmeaString; - processStringBuffer(); - return mLastGPSInformation; -} - BluetoothPositionProvider::BluetoothPositionProvider( const QString &addr, const QString &name, PositionTransformer &positionTransformer, QObject *parent ) - : AbstractPositionProvider( addr, QStringLiteral( "external" ), name, positionTransformer, parent ) + : AbstractPositionProvider( addr, QStringLiteral( "external_bt" ), name, positionTransformer, parent ) , mTargetAddress( addr ) { mSocket = std::unique_ptr( new QBluetoothSocket( QBluetoothServiceInfo::RfcommProtocol ) ); diff --git a/app/position/providers/bluetoothpositionprovider.h b/app/position/providers/bluetoothpositionprovider.h index 4670131da..8797c8ec1 100644 --- a/app/position/providers/bluetoothpositionprovider.h +++ b/app/position/providers/bluetoothpositionprovider.h @@ -10,29 +10,12 @@ #ifndef BLUETOOTHPOSITIONPROVIDER_H #define BLUETOOTHPOSITIONPROVIDER_H -#include "abstractpositionprovider.h" - -#include "qgsnmeaconnection.h" - #include #include #include -/** - * NmeaParser is a big hack how to reuse QGIS NmeaConnection function in order to (a) keep ownership of bluetooth - * socket, (b) do not have multiple unique_ptrs holding the same pointer and to avoid some possible crashes. - * - * Note: This way of reusing makes the parser highly dependent on QgsNmeaConnection class and any change inside the class - * can lead to misbehavior's. See implementation of QgsNmeaConnection and QgsGpsConnection for more details. - */ -class NmeaParser : public QgsNmeaConnection -{ - public: - NmeaParser(); - - // Takes nmea string and returns gps position - QgsGpsInformation parseNmeaString( const QString &nmeaString ); -}; +#include "abstractpositionprovider.h" +#include "nmeaparser.h" /** * BluetoothPositionProvider initiates connection to bluetooth device diff --git a/app/position/providers/networkpositionprovider.cpp b/app/position/providers/networkpositionprovider.cpp new file mode 100644 index 000000000..13708470f --- /dev/null +++ b/app/position/providers/networkpositionprovider.cpp @@ -0,0 +1,233 @@ +/*************************************************************************** +* * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "networkpositionprovider.h" + +#include +#include + +constexpr int ONE_SECOND_MS = 1000; + +NetworkPositionProvider::NetworkPositionProvider( const QString &addr, const QString &name, PositionTransformer &positionTransformer, QObject *parent ) + : AbstractPositionProvider( addr, QStringLiteral( "external_ip" ), name, positionTransformer, parent ), + mSecondsLeftToReconnect( ReconnectDelay::ShortDelay / ONE_SECOND_MS ) +{ + const QStringList targetAddress = addr.split( QStringLiteral( ":" ) ); + mTargetAddress = targetAddress.at( 0 ); + mTargetPort = targetAddress.at( 1 ).toInt(); + + mTcpSocket = std::make_unique(); + mUdpSocket = std::make_unique(); + + connect( mTcpSocket.get(), &QTcpSocket::readyRead, this, &NetworkPositionProvider::positionUpdateReceived ); + connect( mUdpSocket.get(), &QUdpSocket::readyRead, this, &NetworkPositionProvider::positionUpdateReceived ); + + connect( mTcpSocket.get(), &QTcpSocket::stateChanged, this, &NetworkPositionProvider::socketStateChanged ); + connect( mUdpSocket.get(), &QUdpSocket::stateChanged, this, &NetworkPositionProvider::socketStateChanged ); + + mReconnectTimer.setSingleShot( false ); + mReconnectTimer.setInterval( ONE_SECOND_MS ); + connect( &mReconnectTimer, &QTimer::timeout, this, &NetworkPositionProvider::reconnectTimeout ); + mUdpReconnectTimer.setSingleShot( true ); + connect( &mUdpReconnectTimer, &QTimer::timeout, this, [this] + { + if ( mTcpSocket->state() != QAbstractSocket::ConnectedState ) + { + setState( tr( "No connection" ), State::NoConnection ); + startReconnectTimer(); + // let's also invalidate current position since we no longer have connection + emit positionChanged( GeoPosition() ); + } + } ); + + NetworkPositionProvider::startUpdates(); +} + +void NetworkPositionProvider::startUpdates() +{ + // TODO: QHostAddress doesn't support hostname lookup (QHostInfo does) + mTcpSocket->connectToHost( mTargetAddress, mTargetPort ); + mUdpSocket->bind( QHostAddress::LocalHost, mTargetPort ); + mUdpReconnectTimer.start( ReconnectDelay::ExtraLongDelay ); +} + +void NetworkPositionProvider::stopUpdates() +{ + if ( mTcpSocket->state() != QAbstractSocket::UnconnectedState && mTcpSocket->state() != QAbstractSocket::ClosingState ) + { + mTcpSocket->disconnectFromHost(); + } + if ( mUdpSocket->state() != QAbstractSocket::UnconnectedState && mUdpSocket->state() != QAbstractSocket::ClosingState ) + { + mUdpSocket->disconnectFromHost(); + } +} + +NetworkPositionProvider::~NetworkPositionProvider() +{ + NetworkPositionProvider::closeProvider(); +} + +void NetworkPositionProvider::closeProvider() +{ + mUdpReconnectTimer.stop(); + mReconnectTimer.stop(); + + if ( mTcpSocket ) + { + mTcpSocket->disconnect(); + mTcpSocket->abort(); + } + if ( mUdpSocket ) + { + mUdpSocket->disconnect(); + mUdpSocket->abort(); + } +} + +void NetworkPositionProvider::positionUpdateReceived() +{ + QAbstractSocket *socket = dynamic_cast( sender() ); + + // if udp is not connected to the host yet, connect + // this approach will let us use QIODevice functions for both sockets + if ( socket->socketType() == QAbstractSocket::UdpSocket && mUdpSocket->state() != QAbstractSocket::ConnectedState ) + { + mUdpReconnectTimer.stop(); + + // if by any chance we showed wrong message in the status like "no connection", fix it here + // we know the connection is working because we just received data from the device + setState( tr( "Connected" ), State::Connected ); + + QHostAddress peerAddress; + int peerPort; + // process the incoming data as it will break the signal emitting if unprocessed + while ( mUdpSocket->hasPendingDatagrams() ) + { + QNetworkDatagram datagram = mUdpSocket->receiveDatagram(); + peerAddress = datagram.senderAddress(); + peerPort = datagram.senderPort(); + const QByteArray rawNmeaData = datagram.data(); + const QString nmeaData( rawNmeaData ); + const QgsGpsInformation gpsInfo = mNmeaParser.parseNmeaString( nmeaData ); + GeoPosition transformedPosition = mPositionTransformer->processNetworkPosition( GeoPosition::fromQgsGpsInformation( gpsInfo ) ); + + emit positionChanged( transformedPosition ); + } + + // "connect" to peer if we are not already connecting + if ( mUdpSocket->state() != QAbstractSocket::ConnectedState && mUdpSocket->state() != QAbstractSocket::ConnectingState ) + { + mUdpSocket->connectToHost( peerAddress.toString(), peerPort ); + } + return; + } + + // stop the UDP silence timer, we just received data + // kills the timer when the app was minimized, and we were able to reconnect in the meantime + if ( socket->socketType() == QAbstractSocket::UdpSocket ) + { + mUdpReconnectTimer.stop(); + } + + const QByteArray rawNmeaData = socket->readAll(); + + if ( rawNmeaData.isEmpty() || !rawNmeaData.contains( '$' ) ) + { + return; + } + + // if by any chance we showed wrong message in the status like "no connection", fix it here + // we know the connection is working because we just received data from the device + setState( tr( "Connected" ), State::Connected ); + + const QString nmeaData( rawNmeaData ); + const QgsGpsInformation gpsInfo = mNmeaParser.parseNmeaString( nmeaData ); + GeoPosition transformedPosition = mPositionTransformer->processNetworkPosition( GeoPosition::fromQgsGpsInformation( gpsInfo ) ); + + emit positionChanged( transformedPosition ); +} + +void NetworkPositionProvider::socketStateChanged( const QAbstractSocket::SocketState state ) +{ + const QAbstractSocket *socket = dynamic_cast( sender() ); + + if ( state == QAbstractSocket::ConnectingState || state == QAbstractSocket::HostLookupState ) + { + setState( tr( "Connecting to %1" ).arg( mProviderName ), State::Connecting ); + } + // Only with TCP we can be sure in ConnectedState that we are connected, with UDP we wait until the first datagram arrives + else if ( state == QAbstractSocket::ConnectedState && socket->socketType() == QAbstractSocket::TcpSocket ) + { + setState( tr( "Connected" ), State::Connected ); + } + else if ( state == QAbstractSocket::UnconnectedState ) + { + const bool isUdpSocketListening = mUdpSocket->state() == QAbstractSocket::ConnectedState || mUdpSocket->state() == QAbstractSocket::BoundState || mUdpReconnectTimer.isActive(); + if ( socket->socketType() == QAbstractSocket::TcpSocket && !isUdpSocketListening && QApplication::applicationState() == Qt::ApplicationActive ) + { + setState( tr( "No connection" ), State::NoConnection ); + startReconnectTimer(); + // let's also invalidate current position since we no longer have connection + emit positionChanged( GeoPosition() ); + } + else if ( socket->socketType() == QAbstractSocket::UdpSocket && QApplication::applicationState() == Qt::ApplicationActive ) + { + setState( tr( "No connection" ), State::NoConnection ); + startReconnectTimer(); + // let's also invalidate current position since we no longer have connection + emit positionChanged( GeoPosition() ); + } + } +} + +void NetworkPositionProvider::reconnectTimeout() +{ + if ( mSecondsLeftToReconnect <= 1 ) + { + reconnect(); + } + else + { + mSecondsLeftToReconnect--; + setState( tr( "No connection, reconnecting in (%1)" ).arg( mSecondsLeftToReconnect ), State::WaitingToReconnect ); + mReconnectTimer.start(); + } +} + +QString NetworkPositionProvider::getIpAddress() const +{ + return QStringLiteral( "%1:%2" ).arg( mTargetAddress, QString::number( mTargetPort ) ); +} + +void NetworkPositionProvider::reconnect() +{ + mReconnectTimer.stop(); + + setState( tr( "Reconnecting" ), State::Connecting ); + + stopUpdates(); + mReconnectTimer.stop(); + + startUpdates(); +} + +void NetworkPositionProvider::startReconnectTimer() +{ + mSecondsLeftToReconnect = mReconnectDelay / ONE_SECOND_MS; + setState( tr( "No connection, reconnecting in (%1)" ).arg( mSecondsLeftToReconnect ), State::WaitingToReconnect ); + + mReconnectTimer.start(); + + // first time do reconnect in short time, then each other in long time + if ( mReconnectDelay == NetworkPositionProvider::ShortDelay ) + { + mReconnectDelay = NetworkPositionProvider::LongDelay; + } +} diff --git a/app/position/providers/networkpositionprovider.h b/app/position/providers/networkpositionprovider.h new file mode 100644 index 000000000..300823e65 --- /dev/null +++ b/app/position/providers/networkpositionprovider.h @@ -0,0 +1,70 @@ +/*************************************************************************** +* * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + + +#ifndef NETWORKPOSITIONPROVIDER_H +#define NETWORKPOSITIONPROVIDER_H + +#include +#include +#include + +#include "abstractpositionprovider.h" +#include "nmeaparser.h" + + +class NetworkPositionProvider : public AbstractPositionProvider +{ + Q_OBJECT + + // signalizes in how many [ms] we will try to reconnect to GPS again + enum ReconnectDelay + { + ShortDelay = 3000, // 3 secs + LongDelay = 5000, // 5 secs + ExtraLongDelay = 10000 // 10 secs + }; + + public: + NetworkPositionProvider( const QString &addr, const QString &name, PositionTransformer &positionTransformer, QObject *parent = nullptr ); + ~NetworkPositionProvider() override; + + void startUpdates() override; + void stopUpdates() override; + void closeProvider() override; + Q_INVOKABLE QString getIpAddress() const; // returns the IP address and the port we try to connect/ are connected to + + public slots: + // processes the received nmea data and emits new position + void positionUpdateReceived(); + // changes the provider state depending on the socket states + void socketStateChanged( QAbstractSocket::SocketState state ); + // checks if enough time passed since last reconnect and triggers it if necessary + void reconnectTimeout(); + + private: + // trigger the reconnection flow for both sockets + void reconnect(); + // start the reconnection timeout + void startReconnectTimer(); + + std::unique_ptr mTcpSocket; + std::unique_ptr mUdpSocket; + + int mReconnectDelay = ReconnectDelay::ShortDelay; // in how many [ms] we will try to reconnect again + int mSecondsLeftToReconnect; // how many seconds are left to reconnect. Reconnects if less than or equal to one + QTimer mReconnectTimer; // timer that times out each second and lowers the mSecondsLeftToReconnect by one + QTimer mUdpReconnectTimer; // timer that times out after ExtraLongDelay and triggers reconnect + + QString mTargetAddress; // IP address or hostname of the receiver + int mTargetPort; // active port of the receiver + + NmeaParser mNmeaParser; // parser to decode received NMEA strings +}; +#endif //NETWORKPOSITIONPROVIDER_H diff --git a/app/position/providers/nmeaparser.cpp b/app/position/providers/nmeaparser.cpp new file mode 100644 index 000000000..69a8f1015 --- /dev/null +++ b/app/position/providers/nmeaparser.cpp @@ -0,0 +1,23 @@ +/*************************************************************************** +* * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "nmeaparser.h" + +#include + +NmeaParser::NmeaParser() : QgsNmeaConnection( new QBuffer() ) +{ +} + +QgsGpsInformation NmeaParser::parseNmeaString( const QString &nmeaString ) +{ + mStringBuffer = nmeaString; + processStringBuffer(); + return mLastGPSInformation; +} \ No newline at end of file diff --git a/app/position/providers/nmeaparser.h b/app/position/providers/nmeaparser.h new file mode 100644 index 000000000..b50f9f3b3 --- /dev/null +++ b/app/position/providers/nmeaparser.h @@ -0,0 +1,32 @@ +/*************************************************************************** +* * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef NMEAPARSER_H +#define NMEAPARSER_H + +#include + +/** + * NmeaParser is a big hack how to reuse QGIS NmeaConnection function in order to (a) keep ownership of bluetooth / TCP/UDP + * socket, (b) do not have multiple unique_ptrs holding the same pointer and to avoid some possible crashes. + * + * Note: This way of reusing makes the parser highly dependent on QgsNmeaConnection class and any change inside the class + * can lead to misbehavior's. See implementation of QgsNmeaConnection and QgsGpsConnection for more details. + */ +class NmeaParser : public QgsNmeaConnection +{ + public: + NmeaParser(); + +// Takes nmea string and returns gps position + QgsGpsInformation parseNmeaString( const QString &nmeaString ); +}; + + +#endif //NMEAPARSER_H \ No newline at end of file diff --git a/app/position/providers/positionprovidersmodel.cpp b/app/position/providers/positionprovidersmodel.cpp index e070e4576..0c6a02f95 100644 --- a/app/position/providers/positionprovidersmodel.cpp +++ b/app/position/providers/positionprovidersmodel.cpp @@ -19,7 +19,7 @@ PositionProvidersModel::PositionProvidersModel( QObject *parent ) : QAbstractLis { if ( !InputUtils::isMobilePlatform() ) { - PositionProvider simulated( "Simulated provider", "Simulated position around point", "internal", "simulated" ); + const PositionProvider simulated( "Simulated provider", "Simulated position around point", "internal", "simulated" ); mProviders.push_front( simulated ); } @@ -74,20 +74,20 @@ QHash PositionProvidersModel::roleNames() const int PositionProvidersModel::rowCount( const QModelIndex & ) const { - return mProviders.count(); + return static_cast( mProviders.count() ); } -QVariant PositionProvidersModel::data( const QModelIndex &index, int role ) const +QVariant PositionProvidersModel::data( const QModelIndex &index, const int role ) const { if ( !index.isValid() ) - return QVariant(); + return {}; - int row = index.row(); + const int row = index.row(); PositionProvider provider = mProviders.at( row ); if ( row < 0 || row > mProviders.count() ) - return QVariant(); + return {}; switch ( role ) { @@ -104,7 +104,7 @@ QVariant PositionProvidersModel::data( const QModelIndex &index, int role ) cons return provider.providerType; default: - return QVariant(); + return {}; } } @@ -119,7 +119,7 @@ void PositionProvidersModel::removeProvider( const QString &providerId ) if ( !mProviders.contains( toRemove ) ) return; - int removeIndex = mProviders.indexOf( toRemove ); + const int removeIndex = static_cast( mProviders.indexOf( toRemove ) ); beginRemoveRows( QModelIndex(), removeIndex, removeIndex ); @@ -134,21 +134,22 @@ void PositionProvidersModel::removeProvider( const QString &providerId ) } } -void PositionProvidersModel::addProvider( const QString &name, const QString &providerId ) +void PositionProvidersModel::addProvider( const QString &name, const QString &providerId, const QString &providerType ) { if ( providerId.isEmpty() ) return; PositionProvider toAdd; + const QString deviceDesc = providerType == QStringLiteral( "external_bt" ) ? tr( " Bluetooth device" ) : tr( " Network device" ); toAdd.name = name; toAdd.providerId = providerId; - toAdd.description = providerId + " " + tr( " Bluetooth device" ); - toAdd.providerType = "external"; + toAdd.description = providerId + " " + deviceDesc; + toAdd.providerType = providerType; if ( mProviders.contains( toAdd ) ) return; - int addIndex = mProviders.count(); + const int addIndex = static_cast( mProviders.count() ); beginInsertRows( QModelIndex(), addIndex, addIndex ); @@ -185,7 +186,7 @@ void PositionProvidersModel::setAppSettings( AppSettings *as ) for ( int i = 0; i < providers.count(); ++i ) { - if ( providers[i].type() == QVariant::List || providers[i].type() == QVariant::StringList ) + if ( providers[i].typeId() == QMetaType::QVariantList || providers[i].typeId() == QMetaType::QStringList ) { QVariantList providerData = providers[i].toList(); @@ -196,10 +197,13 @@ void PositionProvidersModel::setAppSettings( AppSettings *as ) } PositionProvider provider; + // when migrating from older version where type wasn't saved we know it's bluetooth device + const QString providerType = providerData[2].isNull() ? QStringLiteral( "external_bt" ) : providerData[2].toString(); + const QString deviceDesc = providerType == QStringLiteral( "external_bt" ) ? tr( " Bluetooth device" ) : tr( " Network device" ); provider.name = providerData[0].toString(); provider.providerId = providerData[1].toString(); - provider.description = provider.providerId + " " + tr( "Bluetooth device" ); - provider.providerType = "external"; + provider.description = provider.providerId + deviceDesc; + provider.providerType = providerType; mProviders.append( provider ); } @@ -218,8 +222,8 @@ QVariantList PositionProvidersModel::toVariantList() const if ( mProviders[i].providerType == QStringLiteral( "internal" ) ) continue; - QStringList a = { mProviders[i].name, mProviders[i].providerId }; - out.push_back( a ); + QStringList provider = { mProviders[i].name, mProviders[i].providerId, mProviders[i].providerType }; + out.push_back( provider ); } return out; diff --git a/app/position/providers/positionprovidersmodel.h b/app/position/providers/positionprovidersmodel.h index dc24171fe..6499038ed 100644 --- a/app/position/providers/positionprovidersmodel.h +++ b/app/position/providers/positionprovidersmodel.h @@ -10,7 +10,6 @@ #ifndef POSITIONPROVIDERSMODEL_H #define POSITIONPROVIDERSMODEL_H -#include #include #include @@ -21,8 +20,8 @@ struct PositionProvider { QString name; QString description; - QString providerType; // either internal or external - QString providerId; // holds BT address for external provider and simulated/internal for internal provider + QString providerType; // can be internal, external_bt, external_ip + QString providerId; // holds BT address or IP address for external providers and simulated/internal for internal providers bool operator==( const PositionProvider &other ) const { @@ -38,7 +37,7 @@ struct PositionProvider : name( name ), description( desc ), providerType( type ), providerId( id ) {} - PositionProvider() {} + PositionProvider() = default; }; class PositionProvidersModel : public QAbstractListModel @@ -50,14 +49,14 @@ class PositionProvidersModel : public QAbstractListModel public: explicit PositionProvidersModel( QObject *parent = nullptr ); - virtual ~PositionProvidersModel(); + ~PositionProvidersModel() override; enum DataRoles { - ProviderName = Qt::UserRole + 1, //! physical address of BT device - ProviderDescription, - ProviderId, - ProviderType // external (connected) / internal (device) + ProviderName = Qt::UserRole + 1, // name of bluetooth device or custom name for network device + ProviderDescription, // device address (IP/BT) + device type + ProviderId, // device address (IP/BT) + ProviderType // external_ip (connected) / external_bt (connected) / internal (device) / simulated (device) }; Q_ENUM( DataRoles ) @@ -67,7 +66,7 @@ class PositionProvidersModel : public QAbstractListModel QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override; Q_INVOKABLE void removeProvider( const QString &providerId ); - Q_INVOKABLE void addProvider( const QString &providerName, const QString &providerId ); + Q_INVOKABLE void addProvider( const QString &providerName, const QString &providerId, const QString &providerType ); AppSettings *appSettings() const; void setAppSettings( AppSettings * ); diff --git a/app/qml/CMakeLists.txt b/app/qml/CMakeLists.txt index 2413d008d..12b847168 100644 --- a/app/qml/CMakeLists.txt +++ b/app/qml/CMakeLists.txt @@ -1,5 +1,4 @@ set(MM_QML - account/components/MMIconCheckBoxHorizontal.qml account/components/MMIconCheckBoxVertical.qml account/components/MMAccountPageItem.qml account/components/MMWorkspaceDelegate.qml @@ -26,6 +25,7 @@ set(MM_QML components/MMDrawerHeader.qml components/MMHlineText.qml components/MMIcon.qml + components/MMIconCheckBoxHorizontal.qml components/MMInfoBox.qml components/MMLine.qml components/MMListDelegate.qml @@ -132,10 +132,12 @@ set(MM_QML form/editors/MMFormTextMultilineEditor.qml form/editors/MMFormValueMapEditor.qml form/editors/MMFormValueRelationEditor.qml - gps/MMAddPositionProviderDrawer.qml - gps/MMBluetoothConnectionDrawer.qml + gps/MMBluetoothProviderDrawer.qml + gps/MMExternalProviderConnectionDrawer.qml gps/MMGpsDataDrawer.qml + gps/MMNetworkProviderDrawer.qml gps/MMPositionProviderPage.qml + gps/MMProviderTypeDrawer.qml gps/MMStakeoutDrawer.qml gps/MMMeasureDrawer.qml gps/MMSelectionDrawer.qml diff --git a/app/qml/account/MMHowYouFoundUsPage.qml b/app/qml/account/MMHowYouFoundUsPage.qml index 66a84031e..dbc6cfe86 100644 --- a/app/qml/account/MMHowYouFoundUsPage.qml +++ b/app/qml/account/MMHowYouFoundUsPage.qml @@ -112,7 +112,7 @@ MMPage { NumberAnimation { properties: "x,y"; duration: 100 } } - delegate: MMAccountComponents.MMIconCheckBoxHorizontal { + delegate: MMIconCheckBoxHorizontal{ x: model.submenu ? __style.margin20 : 0 width: model.submenu ? ListView.view.width - __style.margin20 : ListView.view.width diff --git a/app/qml/account/components/MMIconCheckBoxHorizontal.qml b/app/qml/account/components/MMIconCheckBoxHorizontal.qml deleted file mode 100644 index cd3a02452..000000000 --- a/app/qml/account/components/MMIconCheckBoxHorizontal.qml +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -import QtQuick -import QtQuick.Controls -import QtQuick.Controls.Basic - -import "../../components" - -CheckBox { - id: control - - property string sourceIcon: "" - property bool small: false - - height: (control.small ? 50 : 80) * __dp - - indicator: Rectangle { - id: iconBgRectangle - width: (control.small ? 24 : 40) * __dp - height: (control.small ? 24 : 40) * __dp - x: 20 * __dp - y: control.height / 2 - height / 2 - radius: width / 2 - color: control.checked ? __style.polarColor : __style.lightGreenColor - - MMIcon { - id: icon - size: control.small ? __style.icon16 : __style.icon24 - anchors.centerIn: parent - source: control.sourceIcon - color: __style.forestColor - } - } - - contentItem: Text { - text: control.text - font: __style.t3 - color: control.checked ? __style.polarColor : __style.nightColor - elide: Text.ElideRight - verticalAlignment: Text.AlignVCenter - leftPadding: control.indicator.width + 30 * __dp - rightPadding: 20 * __dp - } - - background: Rectangle { - radius: __style.radius12 - color: control.checked ? __style.forestColor: __style.polarColor - } -} diff --git a/app/qml/components/MMIconCheckBoxHorizontal.qml b/app/qml/components/MMIconCheckBoxHorizontal.qml new file mode 100644 index 000000000..45dff5de6 --- /dev/null +++ b/app/qml/components/MMIconCheckBoxHorizontal.qml @@ -0,0 +1,79 @@ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +import QtQuick +import QtQuick.Controls +import QtQuick.Controls.Basic + +CheckBox { + id: control + + property alias sourceIcon: icon.source + property alias description: descriptionText.text + property bool showBorder: false + property bool small: false + + readonly property int baseHeight: small ? 50 : 80 + + height: control.baseHeight * __dp + implicitWidth: leftPadding + titleText.implicitWidth + rightPadding + + topPadding: Math.max(0, (height - contentColumn.implicitHeight) / 2) + bottomPadding: topPadding + leftPadding: iconBgRectangle.x + iconBgRectangle.width + 20 * __dp + rightPadding: 20 * __dp + + indicator: Rectangle { + id: iconBgRectangle + implicitWidth: (small ? 24 : 40) * __dp + implicitHeight: (small ? 24 : 40) * __dp + x: 20 * __dp + y: control.height / 2 - height / 2 + radius: width / 2 + color: control.checked ? __style.polarColor : __style.lightGreenColor + + MMIcon { + id: icon + size: small ? __style.icon16 : __style.icon24 + anchors.centerIn: parent + source: control.sourceIcon + color: __style.forestColor + } + } + + contentItem: Column { + id: contentColumn + spacing: 4 * __dp + + Text { + id: titleText + width: parent.width + text: control.text + font: __style.t3 + color: control.checked ? __style.polarColor : __style.nightColor + elide: Text.ElideRight + } + + Text { + id: descriptionText + visible: text !== "" + width: parent.width + font: __style.p6 + color: control.checked ? __style.polarColor : __style.nightColor + wrapMode: Text.Wrap + maximumLineCount: 2 + } + } + + background: Rectangle { + radius: __style.radius12 + color: control.checked ? __style.forestColor : __style.polarColor + border.color: showBorder && !control.checked ? __style.mediumGreenColor : __style.transparentColor + } +} diff --git a/app/qml/components/MMListDelegate.qml b/app/qml/components/MMListDelegate.qml index b7869968c..93c94cca0 100644 --- a/app/qml/components/MMListDelegate.qml +++ b/app/qml/components/MMListDelegate.qml @@ -42,7 +42,7 @@ Item { implicitWidth: ListView?.view?.width ?? 0 // in case ListView is injected as attached property (usually it is) implicitHeight: contentLayout.implicitHeight - height: visible ? implicitHeight : 0.1 // hide invisible items, for some reason setting 0 does not work ¯\_(ツ)_/¯ + height: visible ? contentLayout.implicitHeight : 0.1 // hide invisible items, for some reason setting 0 does not work ¯\_(ツ)_/¯ MouseArea { anchors.fill: contentLayout diff --git a/app/qml/gps/MMBluetoothConnectionDrawer.qml b/app/qml/gps/MMBluetoothConnectionDrawer.qml deleted file mode 100644 index 64d5c9af4..000000000 --- a/app/qml/gps/MMBluetoothConnectionDrawer.qml +++ /dev/null @@ -1,148 +0,0 @@ -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -import QtQuick -import QtQuick.Controls -import QtQuick.Layouts - -import mm 1.0 as MM -import MMInput - -import "../components" as MMComponents - -MMComponents.MMDrawer { - id: root - - property var positionProvider: PositionKit.positionProvider - property string howToConnectGPSLink: __inputHelp.howToConnectGPSLink - - property string titleText: { - if ( rootstate.state === "working" ) - { - if ( !root.positionProvider ) return "" - if ( root.positionProvider.name() ) return qsTr( "Connecting to" ) + " " + root.positionProvider.name() + connectingSuffixAnimation - return qsTr( "Connecting" ) + connectingSuffixAnimation - } - else if ( rootstate.state === "success" ) - { - return qsTr( "Connected" ) - } - else - { - // either NoConnection or WaitingToReconnect - return qsTr( "Failed to connect to" ) + " " + ( root.positionProvider ? root.positionProvider.name() : "" ) - } - } - - property string connectingSuffixAnimation: "" - - property string descriptionText: { - if ( rootstate.state === "working" ) - { - return qsTr( "You might be asked to pair your device during this process." ) - } - else if ( rootstate.state === "success" ) - { - return "" - } - else if ( rootstate.state === "waitingToReconnect" ) - { - return PositionKit.positionProvider.stateMessage + "

" + - qsTr( "You can close this message, we will try to repeatedly connect to your device." ) - } - - else - { - return qsTr( "We were not able to connect to the specified device. Please make sure your device is powered on and can be connected to." ) - } - } - - property var imageSource: { - if ( rootstate.state === "fail" ) - { - return __style.externalGpsRedImage - } - else { - return __style.externalGpsGreenImage - } - } - - signal success() - signal failure() - - StateGroup { - id: rootstate - - states: [ - State { - name: "working" - when: root.positionProvider && root.positionProvider.state === MM.PositionProvider.Connecting - }, - State { - name: "success" - when: root.positionProvider && root.positionProvider.state === MM.PositionProvider.Connected - }, - State { - name: "fail" - when: !root.positionProvider || root.positionProvider.state === MM.PositionProvider.NoConnection - }, - State { - name: "waitingToReconnect" - when: !root.positionProvider || root.positionProvider.state === MM.PositionProvider.WaitingToReconnect - } - ] - - state: "working" - } - - drawerBottomMargin: __style.margin20 - drawerContent: MMComponents.MMScrollView { - - width: parent.width - height: root.maxHeightHit ? root.drawerContentAvailableHeight : contentHeight - - MMComponents.MMMessage { - width: parent.width - - image: root.imageSource - title: root.titleText - description: root.descriptionText - link: root.howToConnectGPSLink - linkText: ( rootstate.state === "working" || rootstate.state === "success" ) ? "" : qsTr( "Learn more" ) - } - } - - Timer { - id: closeTimer - - interval: 1500 - repeat: false - running: rootstate.state === "success" - onTriggered: { - root.close() - } - } - - Timer { - // connecting animator - interval: 400 - - repeat: true - running: rootstate.state === "working" - - onTriggered: { - if ( root.connectingSuffixAnimation.length > 2 ) { - root.connectingSuffixAnimation = "" - } - else { - root.connectingSuffixAnimation += "." - } - } - } -} diff --git a/app/qml/gps/MMAddPositionProviderDrawer.qml b/app/qml/gps/MMBluetoothProviderDrawer.qml similarity index 74% rename from app/qml/gps/MMAddPositionProviderDrawer.qml rename to app/qml/gps/MMBluetoothProviderDrawer.qml index ab4771bcf..1263b203b 100644 --- a/app/qml/gps/MMAddPositionProviderDrawer.qml +++ b/app/qml/gps/MMBluetoothProviderDrawer.qml @@ -10,7 +10,6 @@ import QtCore import QtQuick import QtQuick.Controls - import mm 1.0 as MM import "../components" as MMComponents @@ -21,7 +20,9 @@ MMComponents.MMListDrawer { signal initiatedConnectionTo( string deviceAddress, string deviceName ) showFullScreen: true - drawerHeader.title: qsTr( "Connect to bluetooth device" ) + drawerHeader.title: qsTr( "Bluetooth Connection" ) + + list.height: root.drawerContentAvailableHeight list.model: MM.BluetoothDiscoveryModel { id: btModel @@ -97,22 +98,47 @@ MMComponents.MMListDrawer { } } + // footer Component { id: discoveringMessageComponent - Column { + Item { width: ListView.view.width + height: Math.max( contentColumn.implicitHeight, + ListView.view.height - ( ListView.view.contentHeight - height ) ) - spacing: 0 + Column { + id: contentColumn - MMComponents.MMListSpacer { height: __style.margin40 } + anchors.bottom: parent.bottom + anchors.horizontalCenter: parent.horizontalCenter - MMComponents.MMText { width: parent.width - text: qsTr( "Looking for devices" ) + "..." + Image { + anchors.horizontalCenter: parent.horizontalCenter + + source: __style.mmSymbolImage + + width: __style.icon32 * __dp + height: __style.icon32 * __dp + + fillMode: Image.PreserveAspectFit + } - font: __style.t3 + MMComponents.MMListSpacer { height: __style.margin16 } + + MMComponents.MMText { + width: parent.width + + text: qsTr( "Scanning for devices" ) + "..." + + font: __style.t3 + color: __style.forestColor + + horizontalAlignment: Text.AlignHCenter + } + MMComponents.MMListSpacer { height: __style.margin16 } } } } diff --git a/app/qml/gps/MMExternalProviderConnectionDrawer.qml b/app/qml/gps/MMExternalProviderConnectionDrawer.qml new file mode 100644 index 000000000..928aba748 --- /dev/null +++ b/app/qml/gps/MMExternalProviderConnectionDrawer.qml @@ -0,0 +1,135 @@ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts +import mm 1.0 as MM +import MMInput + +import "../components" as MMComponents + +MMComponents.MMDrawer { + id: root + + property string providerType: "" + property var positionProvider: PositionKit.positionProvider + + property string connectingSuffixAnimation: "" + + signal success() + signal failure() + + StateGroup { + id: rootstate + + states: [ + State { + name: "working" + when: root.positionProvider && root.positionProvider.state === MM.PositionProvider.Connecting + PropertyChanges { + target: message + image: root.providerType === "bluetooth" ? __style.externalBluetoothGreenImage : __style.externalNetworkGreenImage + title: root.providerType === "network" + ? qsTr( "Connecting to external receiver" ) + : ( root.positionProvider.name() + ? qsTr( "Connecting to" ) + " " + root.positionProvider.name() + : qsTr( "Connecting" ) + root.connectingSuffixAnimation ) + description: root.providerType === "bluetooth" + ? qsTr( "You might be asked to pair your device during this process." ) + : ( root.positionProvider.getIpAddress() + ? qsTr( "Connecting to" ) + " " + root.positionProvider.getIpAddress() + qsTr( ". You can close this panel, the app will continue in the background." ) + : qsTr( "Connecting" ) + root.connectingSuffixAnimation ) + linkText: "" + } + }, + State { + name: "success" + when: root.positionProvider && root.positionProvider.state === MM.PositionProvider.Connected + PropertyChanges { + target: message + image: root.providerType === "bluetooth" ? __style.externalBluetoothGreenImage : __style.externalNetworkGreenImage + title: qsTr( "Connected" ) + description: "" + linkText: "" + } + }, + State { + name: "fail" + when: !root.positionProvider || root.positionProvider.state === MM.PositionProvider.NoConnection + PropertyChanges { + target: message + image: __style.externalGpsRedImage + title: qsTr( "Failed to connect to" ) + " " + ( root.positionProvider + ? ( root.providerType === "network" ? root.positionProvider.getIpAddress() : root.positionProvider.name() ) + : "" ) + description: root.providerType === "bluetooth" + ? qsTr( "We were not able to connect to the specified device. Please make sure your device is powered on and can be connected to." ) + : qsTr( "We were not able to connect to the specified IP address. Please try again later." ) + linkText: qsTr( "Learn more" ) + } + }, + State { + name: "waitingToReconnect" + when: root.positionProvider && root.positionProvider.state === MM.PositionProvider.WaitingToReconnect + PropertyChanges { + target: message + image: root.providerType === "bluetooth" ? __style.externalBluetoothGreenImage : __style.externalNetworkGreenImage + title: root.providerType === "bluetooth" + ? qsTr( "We were not able to connect to the specified device. Please make sure your device is powered on and can be connected to." ) + : qsTr( "We were not able to connect to the specified IP address. Please try again later." ) + description: root.positionProvider.stateMessage + "

" + qsTr( "You can close this message, we will try to repeatedly connect to your device." ) + linkText: qsTr( "Learn more" ) + } + } + ] + + state: "working" + } + + drawerBottomMargin: __style.margin40 + drawerContent: MMComponents.MMScrollView { + + width: parent.width + height: root.maxHeightHit ? root.drawerContentAvailableHeight : contentHeight + + MMComponents.MMMessage { + id: message + + width: parent.width + link: __inputHelp.howToConnectGPSLink + } + } + + Timer { + id: closeTimer + + interval: 1500 + repeat: false + running: rootstate.state === "success" + onTriggered: root.close() + } + + Timer { + // connecting animator + interval: 400 + + repeat: true + running: rootstate.state === "working" + + onTriggered: { + if ( root.connectingSuffixAnimation.length > 2 ) { + root.connectingSuffixAnimation = "" + } + else { + root.connectingSuffixAnimation += "." + } + } + } +} diff --git a/app/qml/gps/MMGpsDataDrawer.qml b/app/qml/gps/MMGpsDataDrawer.qml index 1b018bbe3..b375b29cd 100644 --- a/app/qml/gps/MMGpsDataDrawer.qml +++ b/app/qml/gps/MMGpsDataDrawer.qml @@ -9,7 +9,6 @@ import QtQuick import QtQuick.Layouts - import mm 1.0 as MM import MMInput @@ -27,322 +26,336 @@ MMComponents.MMDrawer { drawerHeader.title: qsTr( "GPS info" ) - - drawerContent: MMComponents.MMScrollView { + drawerContent: Item { width: parent.width - height: root.maxHeightHit ? root.drawerContentAvailableHeight : contentHeight + height: root.maxHeightHit ? root.drawerContentAvailableHeight + : ( scrollView.contentHeight + internal.reservedButtonSpace ) - Column { - width: parent.width + MMComponents.MMScrollView { + id: scrollView - spacing: __style.spacing40 + width: parent.width + height: root.maxHeightHit ? ( parent.height - internal.reservedButtonSpace) + : contentHeight - Item { + Column { width: parent.width - height: datagrid.implicitHeight - Rectangle { - // horizontal line after each row in the grid - anchors { - fill: datagrid - bottomMargin: datagrid.children[0].height + Item { + width: parent.width + height: datagrid.implicitHeight + + Rectangle { + // horizontal line after each row in the grid + anchors { + fill: datagrid + bottomMargin: datagrid.children[0].height + } + color: __style.greyColor } - color: __style.greyColor - } - Grid { - id: datagrid + Grid { + id: datagrid - width: parent.width - columns: 2 + width: parent.width + columns: 2 - rowSpacing: __style.margin1 + rowSpacing: __style.margin1 - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - title: qsTr( "Source" ) - value: PositionKit.positionProvider ? PositionKit.positionProviderName : qsTr( "No receiver" ) + title: qsTr( "Source" ) + value: PositionKit.positionProvider ? PositionKit.positionProviderName : qsTr( "No receiver" ) - alignmentRight: Positioner.index % 2 === 1 - } + alignmentRight: Positioner.index % 2 === 1 + } - MMGpsComponents.MMGpsDataText { - id: statusCell + MMGpsComponents.MMGpsDataText { + id: statusCell - width: parent.width / 2 + width: parent.width / 2 - visible: PositionKit.positionProvider && PositionKit.positionProvider.type() === "external" + visible: PositionKit.positionProvider && PositionKit.positionProvider.type().includes("external") - title: qsTr( "Status" ) - value: PositionKit.positionProvider ? PositionKit.positionProvider.stateMessage : "" + title: qsTr( "Status" ) + value: PositionKit.positionProvider ? PositionKit.positionProvider.stateMessage : "" - alignmentRight: Positioner.index % 2 === 1 - } + alignmentRight: Positioner.index % 2 === 1 + } - Rectangle { // placeholder cell to keep long/lat in one line - width: parent.width - height: statusCell.height + Rectangle { // placeholder cell to keep long/lat in one line + width: parent.width + height: statusCell.height - color: __style.polarColor - visible: !statusCell.visible - } + color: __style.polarColor + visible: !statusCell.visible + } + + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + title: qsTr( "Longitude") + value: { + if ( !PositionKit.hasPosition || Number.isNaN( PositionKit.longitude ) ) { + return qsTr( "N/A" ) + } + + let coordParts = internal.coordinatesInDegrees.split(", ") + if ( coordParts.length > 1 ) + return coordParts[1] - title: qsTr( "Longitude") - value: { - if ( !PositionKit.hasPosition || Number.isNaN( PositionKit.longitude ) ) { return qsTr( "N/A" ) } - let coordParts = internal.coordinatesInDegrees.split(", ") - if ( coordParts.length > 1 ) - return coordParts[1] - - return qsTr( "N/A" ) + alignmentRight: Positioner.index % 2 === 1 } - alignmentRight: Positioner.index % 2 === 1 - } + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + title: qsTr( "Latitude" ) + value: { + if ( !PositionKit.hasPosition || Number.isNaN( PositionKit.latitude ) ) { + return qsTr( "N/A" ) + } + + let coordParts = internal.coordinatesInDegrees.split(", ") + if ( coordParts.length > 1 ) + return coordParts[0] - title: qsTr( "Latitude" ) - value: { - if ( !PositionKit.hasPosition || Number.isNaN( PositionKit.latitude ) ) { return qsTr( "N/A" ) } - let coordParts = internal.coordinatesInDegrees.split(", ") - if ( coordParts.length > 1 ) - return coordParts[0] - - return qsTr( "N/A" ) + alignmentRight: Positioner.index % 2 === 1 } - alignmentRight: Positioner.index % 2 === 1 - } + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + title: qsTr( "X" ) + value: { + if ( !PositionKit.hasPosition || Number.isNaN( mapPositioning.mapPosition.x ) ) { + return qsTr( "N/A" ) + } - title: qsTr( "X" ) - value: { - if ( !PositionKit.hasPosition || Number.isNaN( mapPositioning.mapPosition.x ) ) { - return qsTr( "N/A" ) + __inputUtils.formatNumber( mapPositioning.mapPosition.x, 2 ) } - __inputUtils.formatNumber( mapPositioning.mapPosition.x, 2 ) + alignmentRight: Positioner.index % 2 === 1 } - alignmentRight: Positioner.index % 2 === 1 - } + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + title: qsTr( "Y" ) + value: { + if ( !PositionKit.hasPosition || Number.isNaN( mapPositioning.mapPosition.y ) ) { + return qsTr( "N/A" ) + } - title: qsTr( "Y" ) - value: { - if ( !PositionKit.hasPosition || Number.isNaN( mapPositioning.mapPosition.y ) ) { - return qsTr( "N/A" ) + __inputUtils.formatNumber( mapPositioning.mapPosition.y, 2 ) } - __inputUtils.formatNumber( mapPositioning.mapPosition.y, 2 ) + alignmentRight: Positioner.index % 2 === 1 } - alignmentRight: Positioner.index % 2 === 1 - } + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + title: qsTr( "Horizontal accuracy" ) + value: { + if ( !PositionKit.hasPosition || PositionKit.horizontalAccuracy < 0 ) { + return qsTr( "N/A" ) + } - title: qsTr( "Horizontal accuracy" ) - value: { - if ( !PositionKit.hasPosition || PositionKit.horizontalAccuracy < 0 ) { - return qsTr( "N/A" ) + __inputUtils.formatNumber( PositionKit.horizontalAccuracy, 2 ) + " m" } - __inputUtils.formatNumber( PositionKit.horizontalAccuracy, 2 ) + " m" + alignmentRight: Positioner.index % 2 === 1 } - alignmentRight: Positioner.index % 2 === 1 - } + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + title: qsTr( "Vertical accuracy" ) + value: { + if ( !PositionKit.hasPosition || PositionKit.verticalAccuracy < 0 ) { + return qsTr( "N/A" ) + } - title: qsTr( "Vertical accuracy" ) - value: { - if ( !PositionKit.hasPosition || PositionKit.verticalAccuracy < 0 ) { - return qsTr( "N/A" ) + __inputUtils.formatNumber( PositionKit.verticalAccuracy, 2 ) + " m" } - __inputUtils.formatNumber( PositionKit.verticalAccuracy, 2 ) + " m" + alignmentRight: Positioner.index % 2 === 1 } - alignmentRight: Positioner.index % 2 === 1 - } - - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - title: qsTr( "Altitude" ) - value: { - if ( !PositionKit.hasPosition || Number.isNaN( PositionKit.altitude ) ) { - return qsTr( "N/A" ) + title: qsTr( "Altitude" ) + value: { + if ( !PositionKit.hasPosition || Number.isNaN( PositionKit.altitude ) ) { + return qsTr( "N/A" ) + } + __inputUtils.formatNumber( PositionKit.altitude, 2 ) + " m" } - __inputUtils.formatNumber( PositionKit.altitude, 2 ) + " m" + + alignmentRight: Positioner.index % 2 === 1 + desc: PositionKit.positionCrs3DGeoidModelName().length > 0 ? qsTr("Orthometric height, using %1 geoid").arg(PositionKit.positionCrs3DGeoidModelName()) : qsTr("Elevation using unspecified grid") } - alignmentRight: Positioner.index % 2 === 1 - desc: PositionKit.positionCrs3DGeoidModelName().length > 0 ? qsTr("Orthometric height, using %1 geoid").arg(PositionKit.positionCrs3DGeoidModelName()) : qsTr("Elevation using unspecified grid") - } + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + title: qsTr( "Fix quality" ) + value: { + if ( !PositionKit.hasPosition ) { + return qsTr( "N/A" ) + } - title: qsTr( "Fix quality" ) - value: { - if ( !PositionKit.hasPosition ) { - return qsTr( "N/A" ) + PositionKit.fix } - PositionKit.fix - } + visible: PositionKit.positionProvider && PositionKit.positionProvider.type().includes("external") - visible: PositionKit.positionProvider && PositionKit.positionProvider.type() === "external" + alignmentRight: Positioner.index % 2 === 1 + } - alignmentRight: Positioner.index % 2 === 1 - } + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + title: qsTr( "Satellites (in use/view)" ) + value: { + if ( PositionKit.satellitesUsed < 0 || PositionKit.satellitesVisible < 0 ) + { + return qsTr( "N/A" ) + } - title: qsTr( "Satellites (in use/view)" ) - value: { - if ( PositionKit.satellitesUsed < 0 || PositionKit.satellitesVisible < 0 ) - { - return qsTr( "N/A" ) + PositionKit.satellitesUsed + "/" + PositionKit.satellitesVisible } - PositionKit.satellitesUsed + "/" + PositionKit.satellitesVisible + alignmentRight: Positioner.index % 2 === 1 } - alignmentRight: Positioner.index % 2 === 1 - } + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + title: qsTr( "HDOP" ) + value: { + if ( !PositionKit.hasPosition || PositionKit.hdop < 0 ) { + return qsTr( "N/A" ) + } - title: qsTr( "HDOP" ) - value: { - if ( !PositionKit.hasPosition || PositionKit.hdop < 0 ) { - return qsTr( "N/A" ) + __inputUtils.formatNumber( PositionKit.hdop, 2 ) } - __inputUtils.formatNumber( PositionKit.hdop, 2 ) - } + visible: PositionKit.positionProvider && PositionKit.positionProvider.type().includes("external") - visible: PositionKit.positionProvider && PositionKit.positionProvider.type() === "external" + alignmentRight: Positioner.index % 2 === 1 + } - alignmentRight: Positioner.index % 2 === 1 - } + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + title: qsTr( "VDOP" ) + value: { + if ( !PositionKit.hasPosition || PositionKit.vdop < 0 ) { + return qsTr( "N/A" ) + } - title: qsTr( "VDOP" ) - value: { - if ( !PositionKit.hasPosition || PositionKit.vdop < 0 ) { - return qsTr( "N/A" ) + __inputUtils.formatNumber( PositionKit.vdop, 2 ) } - __inputUtils.formatNumber( PositionKit.vdop, 2 ) - } + visible: PositionKit.positionProvider && PositionKit.positionProvider.type().includes("external") - visible: PositionKit.positionProvider && PositionKit.positionProvider.type() === "external" + alignmentRight: Positioner.index % 2 === 1 + } - alignmentRight: Positioner.index % 2 === 1 - } + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + title: qsTr( "PDOP" ) + value: { + if ( !PositionKit.hasPosition || PositionKit.pdop < 0 ) { + return qsTr( "N/A" ) + } - title: qsTr( "PDOP" ) - value: { - if ( !PositionKit.hasPosition || PositionKit.pdop < 0 ) { - return qsTr( "N/A" ) + __inputUtils.formatNumber( PositionKit.pdop, 2 ) } - __inputUtils.formatNumber( PositionKit.pdop, 2 ) - } + visible: PositionKit.positionProvider && PositionKit.positionProvider.type().includes("external") - visible: PositionKit.positionProvider && PositionKit.positionProvider.type() === "external" + alignmentRight: Positioner.index % 2 === 1 + } - alignmentRight: Positioner.index % 2 === 1 - } + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + title: qsTr( "Speed" ) + value: { + if ( !PositionKit.hasPosition || PositionKit.speed < 0 ) { + return qsTr( "N/A" ) + } - title: qsTr( "Speed" ) - value: { - if ( !PositionKit.hasPosition || PositionKit.speed < 0 ) { - return qsTr( "N/A" ) + __inputUtils.formatNumber( PositionKit.speed, 2 ) + " km/h" } - __inputUtils.formatNumber( PositionKit.speed, 2 ) + " km/h" + alignmentRight: Positioner.index % 2 === 1 } - alignmentRight: Positioner.index % 2 === 1 - } - - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - title: qsTr( "Last Fix" ) - value: PositionKit.lastRead.toLocaleTimeString( Qt.locale() ) || qsTr( "N/A" ) + title: qsTr( "Last Fix" ) + value: PositionKit.lastRead.toLocaleTimeString( Qt.locale() ) || qsTr( "N/A" ) - alignmentRight: Positioner.index % 2 === 1 - } + alignmentRight: Positioner.index % 2 === 1 + } - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - title: qsTr( "GPS antenna height" ) - value: AppSettings.gpsAntennaHeight > 0 ? __inputUtils.formatNumber(AppSettings.gpsAntennaHeight, 3) + " m" : qsTr( "Not set" ) + title: qsTr( "GPS antenna height" ) + value: AppSettings.gpsAntennaHeight > 0 ? __inputUtils.formatNumber(AppSettings.gpsAntennaHeight, 3) + " m" : qsTr( "Not set" ) - alignmentRight: Positioner.index % 2 === 1 - } + alignmentRight: Positioner.index % 2 === 1 + } - MMGpsComponents.MMGpsDataText { - width: parent.width / 2 + MMGpsComponents.MMGpsDataText { + width: parent.width / 2 - title: qsTr( "Geoid separation" ) - value: { - if ( !PositionKit.hasPosition || Number.isNaN( PositionKit.geoidSeparation ) ) { - return qsTr( "N/A" ) + title: qsTr( "Geoid separation" ) + value: { + if ( !PositionKit.hasPosition || Number.isNaN( PositionKit.geoidSeparation ) ) { + return qsTr( "N/A" ) + } + __inputUtils.formatNumber( PositionKit.geoidSeparation, 2 ) + " m" } - __inputUtils.formatNumber( PositionKit.geoidSeparation, 2 ) + " m" - } + visible: PositionKit.positionProvider && PositionKit.positionProvider.type().includes("external") - alignmentRight: Positioner.index % 2 === 1 + alignmentRight: Positioner.index % 2 === 1 + } } } } + } - MMComponents.MMButton { - width: parent.width + MMComponents.MMButton { + id: manageButton + + width: parent.width - visible: root.showReceiversButton + visible: root.showReceiversButton - text: qsTr( "Manage GPS receivers" ) - onClicked: root.manageReceiversClicked() + anchors { + bottom: parent.bottom + bottomMargin: 0 } + + text: qsTr( "Manage GPS receivers" ) + onClicked: root.manageReceiversClicked() } } @@ -357,5 +370,6 @@ MMComponents.MMDrawer { id: internal property string coordinatesInDegrees: __inputUtils.degreesString( PositionKit.positionCoordinate ) + readonly property real reservedButtonSpace: __style.spacing20 + manageButton.implicitHeight + __style.margin8 } } diff --git a/app/qml/gps/MMNetworkProviderDrawer.qml b/app/qml/gps/MMNetworkProviderDrawer.qml new file mode 100644 index 000000000..058766f7d --- /dev/null +++ b/app/qml/gps/MMNetworkProviderDrawer.qml @@ -0,0 +1,126 @@ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +import QtQuick + +import "../components" as MMComponents +import "../inputs" as MMInputs + +MMComponents.MMDrawer { + id: root + + signal confirmed( string alias, string deviceAddress ) + + drawerHeader.title: qsTr( "Network connection" ) + drawerHeader.titleFont: __style.t2 + + drawerContent: Column { + width: parent.width + spacing: __style.spacing20 + + MMComponents.MMText { + width: parent.width + text: qsTr( "Enter the IP address and port for your receiver. You can find these in your manufacturer's app. TCP and UDP connections are supported. Optionally, add a nickname to tell your receivers apart." ) + font: __style.p5 + color: __style.nightColor + + wrapMode: Text.Wrap + horizontalAlignment: Text.AlignJustify + } + + MMInputs.MMTextInput { + id: ipAddressInput + + width: parent.width + textFieldBackground.color: __style.lightGreenColor + + title: qsTr( "IP Address" ) + placeholderText: qsTr( "localhost" ) + + onTextEdited: errorMsg = "" + } + + MMInputs.MMTextInput { + id: portInput + + width: parent.width + textFieldBackground.color: __style.lightGreenColor + + title: "Port" + placeholderText: "1234" + + textField.inputMethodHints: Qt.ImhDigitsOnly + + onTextEdited: errorMsg = "" + } + + MMInputs.MMTextInput { + id: aliasInput + + width: parent.width + textFieldBackground.color: __style.lightGreenColor + + title: qsTr( "Receiver nickname (optional)" ) + placeholderText: qsTr( "External receiver" ) + } + + MMComponents.MMButton { + width: parent.width + + text: qsTr( "Confirm" ) + + onClicked: { + const ip = ipAddressInput.text.trim() + const port = portInput.text.trim() + + const ipv4Regex = /^((25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/ + const hostnameRegex = /^[a-zA-Z0-9]([a-zA-Z0-9\-\.]*[a-zA-Z0-9])?$/ + + if ( !ip ) { + ipAddressInput.errorMsg = qsTr( "IP address is required" ) + } + else if ( !ipv4Regex.test( ip ) && !hostnameRegex.test( ip ) ) { + ipAddressInput.errorMsg = qsTr( "Enter a valid IP address or hostname" ) + } + else { + ipAddressInput.errorMsg = "" + } + + const portNum = parseInt( port ) + if ( !port ) { + portInput.errorMsg = qsTr( "Port is required" ) + } + else if ( portNum < 1 || portNum > 65535 ) { + portInput.errorMsg = qsTr( "Enter a valid port (1–65535)" ) + } + else { + portInput.errorMsg = "" + } + + if ( ipAddressInput.errorMsg || portInput.errorMsg ) { + return + } + + const deviceAddress = ip + ":" + port + + root.confirmed( aliasInput.text.trim(), deviceAddress ) + root.close() + ipAddressInput.textField.clear() + portInput.textField.clear() + aliasInput.textField.clear() + } + } + } + + onClosed: { + ipAddressInput.textField.clear() + portInput.textField.clear() + aliasInput.textField.clear() + } +} diff --git a/app/qml/gps/MMPositionProviderPage.qml b/app/qml/gps/MMPositionProviderPage.qml index c98d9a0c8..bcc801e7f 100644 --- a/app/qml/gps/MMPositionProviderPage.qml +++ b/app/qml/gps/MMPositionProviderPage.qml @@ -8,8 +8,6 @@ ***************************************************************************/ import QtQuick -import QtQuick.Controls -import QtQuick.Dialogs import mm 1.0 as MM import MMInput @@ -20,7 +18,7 @@ import "../dialogs" as MMDialogs MMComponents.MMPage { id: root - pageHeader.title: listview.showTopTitle ? internal.pageTitle : "" + pageHeader.title: internal.pageTitle pageBottomMarginPolicy: MMComponents.MMPage.PaintBehindSystemBar @@ -31,10 +29,6 @@ MMComponents.MMPage { MMComponents.MMListView { id: listview - property bool showTopTitle: visibleArea.yPosition * height > ( headerItem.contentHeight / 2 ) - - visible: __haveBluetooth - width: parent.width height: parent.height @@ -46,26 +40,13 @@ MMComponents.MMPage { appSettings: AppSettings } - header: MMComponents.MMText { - id: headerText - - width: ListView.view.width - - text: internal.pageTitle - - font: __style.h3 - color: __style.forestColor - - wrapMode: Text.Wrap - maximumLineCount: 2 - - bottomPadding: __style.margin40 - } - delegate: MMComponents.MMListDelegate { id: listdelegate - property bool isActive: AppSettings.activePositionProviderId === model.ProviderId + required property var model + required property int index + + property bool isActive: AppSettings.activePositionProviderId === listdelegate.model.ProviderId leftContent: MMComponents.MMRadioButton { checked: listdelegate.isActive @@ -75,32 +56,42 @@ MMComponents.MMPage { anchors.fill: parent onClicked: function( mouse ) { mouse.accepted = true - root.constructProvider( model.ProviderType, model.ProviderId, model.ProviderName ) + root.activateProvider( listdelegate.model.ProviderType, listdelegate.model.ProviderId, listdelegate.model.ProviderName ) } } } - text: model.ProviderName ? model.ProviderName : qsTr( "Unknown device" ) - secondaryText: listdelegate.isActive ? PositionKit.positionProvider.stateMessage : model.ProviderDescription + text: { + if ( listdelegate.model.ProviderName ) return listdelegate.model.ProviderName + return qsTr( "Unknown device" ) + } + secondaryText: { + if ( listdelegate.isActive ) { + if ( listdelegate.model.ProviderType === "external_ip" && typeof PositionKit.positionProvider.getIpAddress === "function" ) + return PositionKit.positionProvider.stateMessage + " - " + PositionKit.positionProvider.getIpAddress() + return PositionKit.positionProvider.stateMessage + } + return listdelegate.model.ProviderDescription + } rightContent: MMComponents.MMRoundButton { - visible: model.ProviderType !== "internal" + visible: listdelegate.model.ProviderType !== "internal" iconSource: __style.deleteIcon - onClicked: removeDialog.openDialog( model.ProviderId ) + onClicked: removeDialog.openDialog( listdelegate.model.ProviderId ) } hasLine: { - if ( index === ListView.view.count - 1 ) return false + if ( listdelegate.index === ListView.view.count - 1 ) return false if ( ListView.section === "internal" ) { - let ix = providersModel.index( index + 1, 0 ) + let ix = providersModel.index( listdelegate.index + 1, 0 ) let type = providersModel.data( ix, MM.PositionProvidersModel.ProviderType ) - if ( type === "external" ) return false + if ( type.includes( "external" ) ) return false } return true } - onClicked: root.constructProvider( model.ProviderType, model.ProviderId, model.ProviderName ) + onClicked: root.activateProvider( listdelegate.model.ProviderType, listdelegate.model.ProviderId, listdelegate.model.ProviderName ) } section { @@ -135,7 +126,31 @@ MMComponents.MMPage { text: qsTr( "Connect new receiver" ) - onClicked: bluetoothDiscoveryLoader.active = true + onClicked: { + if ( __haveBluetooth ) { + providerTypeDrawer.open() + } + else { + networkProviderDrawer.open() + } + } + } + + MMProviderTypeDrawer { + id: providerTypeDrawer + + onProviderSelected: function( providerType ) { + if ( providerType === "bluetooth" ) bluetoothDiscoveryLoader.active = true + else if ( providerType === "network" ) networkProviderDrawer.open() + } + } + + MMNetworkProviderDrawer { + id: networkProviderDrawer + + onConfirmed: function( alias, deviceAddress ) { + root.activateProvider( "external_ip", deviceAddress, alias ) + } } MMComponents.MMMessage { @@ -146,10 +161,10 @@ MMComponents.MMPage { image: __style.externalGpsRedImage title: qsTr( "Connecting to external receivers via bluetooth is not supported" ) description: qsTr( "This function is not available on iOS. " + - "Your hardware vendor may provide a custom " + - "app that connects to the receiver and sets position. " + - "The app will still think it is the internal GPS of " + - "your phone/tablet." ) + "Your hardware vendor may provide a custom " + + "app that connects to the receiver and sets position. " + + "The app will still think it is the internal GPS of " + + "your phone/tablet." ) link: __inputHelp.howToConnectGPSLink } @@ -162,7 +177,7 @@ MMComponents.MMPage { } onRemoveProvider: { - if (removeDialog.providerId === "") { + if ( !removeDialog.providerId ) { close() return } @@ -170,7 +185,7 @@ MMComponents.MMPage { if ( AppSettings.activePositionProviderId === removeDialog.providerId ) { // we are removing an active provider, replace it with internal provider - root.constructProvider( "internal", "devicegps", qsTr( "Internal" ) ) + root.activateProvider( "internal", "devicegps", qsTr( "Internal" ) ) } providersModel.removeProvider( removeDialog.providerId ) @@ -183,52 +198,49 @@ MMComponents.MMPage { id: bluetoothDiscoveryLoader active: false - sourceComponent: bluetoothDiscoveryDrawerComponent + sourceComponent: Component { MMBluetoothProviderDrawer {} } + + onLoaded: item.open() } - Loader { - id: connectingDialogLoader + Connections { + target: bluetoothDiscoveryLoader.item - active: false - asynchronous: true - sourceComponent: connectionToSavedProviderDialogComponent - - function open() { - active = true - focus = true + function onInitiatedConnectionTo( deviceAddress, deviceName ) { + bluetoothDiscoveryLoader.item.list.model.discovering = false + bluetoothDiscoveryLoader.item.close() + root.activateProvider( "external_bt", deviceAddress, deviceName ) } + + function onClosed() { bluetoothDiscoveryLoader.active = false } } - } - Component { - id: bluetoothDiscoveryDrawerComponent + Loader { + id: connectingDialogLoader - MMAddPositionProviderDrawer { - onInitiatedConnectionTo: function ( deviceAddress, deviceName ) { - PositionKit.positionProvider = PositionKit.constructProvider( "external", deviceAddress, deviceName ) + property string providerType: "" - providersModel.addProvider( deviceName, deviceAddress ) - list.model.discovering = false - close() + active: false + asynchronous: true + sourceComponent: Component { MMExternalProviderConnectionDrawer{} } - connectingDialogLoader.open() + onLoaded: { + item.providerType = connectingDialogLoader.providerType + item.open() } - onClosed: bluetoothDiscoveryLoader.active = false - Component.onCompleted: open() + function open( type ) { + providerType = type + active = true + focus = true + } } - } - - Component { - id: connectionToSavedProviderDialogComponent - MMBluetoothConnectionDrawer { - onClosed: connectingDialogLoader.active = false + Connections { + target: connectingDialogLoader.item - // revert position provider back to internal provider - onFailure: PositionKit.positionProvider = PositionKit.constructProvider( "internal", "devicegps", "" ) - - Component.onCompleted: open() + function onClosed() { connectingDialogLoader.active = false } + function onFailure() { root.activateProvider( "internal", "devicegps", "" ) } } } @@ -238,8 +250,8 @@ MMComponents.MMPage { property string pageTitle: qsTr( "Manage GPS receivers" ) } - function constructProvider( type, id, name ) { - if ( type === "external" ) { + function activateProvider( type, id, name ) { + if ( type === "external_bt" ) { // Is bluetooth turned on? if ( !__inputUtils.isBluetoothTurnedOn() ) { __inputUtils.turnBluetoothOn() @@ -251,10 +263,14 @@ MMComponents.MMPage { return // do not construct the same provider again } + providersModel.addProvider( name, id, type ) PositionKit.positionProvider = PositionKit.constructProvider( type, id, name ) - if ( type === "external" ) { - connectingDialogLoader.open() + if ( type === "external_bt" ) { + connectingDialogLoader.open( "bluetooth" ) + } + else if ( type === "external_ip" ) { + connectingDialogLoader.open( "network" ) } } } diff --git a/app/qml/gps/MMProviderTypeDrawer.qml b/app/qml/gps/MMProviderTypeDrawer.qml new file mode 100644 index 000000000..d08181e1b --- /dev/null +++ b/app/qml/gps/MMProviderTypeDrawer.qml @@ -0,0 +1,107 @@ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +pragma ComponentBehavior: Bound +import QtQuick +import QtQml.Models +import "../components" as MMComponents + +MMComponents.MMListDrawer { + id: root + + signal providerSelected( string providerType ) + + drawerHeader.title: qsTr( "Connect new receiver" ) + drawerHeader.titleFont: __style.t2 + + onOpened: root.list.currentIndex = -1 + + list.model: ListModel { + id: providerTypeModel + + Component.onCompleted: { + providerTypeModel.append( [ + { name: qsTr( "Bluetooth" ), description: qsTr( "Bad Elf, Emlid, Juniper, marXact and more" ), type: "bluetooth", icon: __style.bluetoothIcon }, + { name: qsTr( "Network (TCP, UDP)" ), description: qsTr( "Emlid RS, EOS and more" ), type: "network", icon: __style.networkIcon } + ] ) + } + } + + list.header: MMComponents.MMText { + width: ListView.view.width + text: __inputUtils.htmlLink( + qsTr( "External receivers use different connection methods depending on the manufacturer. Select a connection type below, or %1check our documentation%2 for supported devices and setup instructions." ), + __style.nightColor, + __inputHelp.howToConnectGPSLink, + "", + true, + false + ) + font: __style.p5 + color: __style.nightColor + textFormat: Text.RichText + + wrapMode: Text.Wrap + horizontalAlignment: Text.AlignJustify + bottomPadding: __style.margin16 + + onLinkActivated: function( link ) { + Qt.openUrlExternally( link ) + } + } + + list.delegate: Item { + required property string name + required property string description + required property string type + required property url icon + required property int index + + width: ListView.view.width + height: checkbox.height + __style.margin12 + + MMComponents.MMIconCheckBoxHorizontal { + id: checkbox + + width: parent.width + showBorder: true + sourceIcon: parent.icon + text: parent.name + description: parent.description + checked: parent.ListView.isCurrentItem + + onClicked: { + if ( parent.ListView.isCurrentItem ) { + parent.ListView.view.currentIndex = -1 + } + else { + parent.ListView.view.currentIndex = parent.index + } + } + } + } + + list.footer: MMComponents.MMButton { + width: parent.width + + text: qsTr( "Continue" ) + enabled: root.list.currentIndex !== -1 + + onClicked: { + const providerType = providerTypeModel.get( root.list.currentIndex ).type + root.close() + + if ( providerType === "bluetooth" ) { + root.providerSelected("bluetooth") + } + else if ( providerType === "network" ) { + root.providerSelected("network") + } + } + } +} diff --git a/app/qml/map/MMMapController.qml b/app/qml/map/MMMapController.qml index f3b3601ee..31b1ee106 100644 --- a/app/qml/map/MMMapController.qml +++ b/app/qml/map/MMMapController.qml @@ -680,7 +680,7 @@ Item { visible: { if ( root.mapExtentOffset > 0 && root.state !== "stakeout" ) return false - if ( PositionKit.positionProvider && PositionKit.positionProvider.type() === "external" ) { + if ( PositionKit.positionProvider && PositionKit.positionProvider.type().includes("external") ) { // for external receivers we want to show gps panel and accuracy button // even when the GPS receiver is not sending position data return true @@ -700,7 +700,7 @@ Item { { return "" } - else if ( PositionKit.positionProvider.type() === "external" ) + else if ( PositionKit.positionProvider.type().includes("external") ) { if ( PositionKit.positionProvider.state === MM.PositionProvider.Connecting ) { diff --git a/app/test/testposition.cpp b/app/test/testposition.cpp index 6c0bdba26..846c4c227 100644 --- a/app/test/testposition.cpp +++ b/app/test/testposition.cpp @@ -106,8 +106,8 @@ void TestPosition::testBluetoothProviderConnection() QCOMPARE( "testBluetoothProvider", pkProvider->name() ); QCOMPARE( "AA:AA:AA:AA:00:00", btProvider->id() ); QCOMPARE( "AA:AA:AA:AA:00:00", pkProvider->id() ); - QCOMPARE( "external", btProvider->type() ); - QCOMPARE( "external", pkProvider->type() ); + QCOMPARE( "external_bt", btProvider->type() ); + QCOMPARE( "external_bt", pkProvider->type() ); // // let's continue with BT instance, @@ -257,11 +257,11 @@ void TestPosition::testPositionProviderKeysInSettings() rawSettings.remove( AppSettings::POSITION_PROVIDERS_GROUP ); // make sure nothing is there from previous tests #ifdef HAVE_BLUETOOTH - positionKit->setPositionProvider( positionKit->constructProvider( "external", "AA:BB:CC:DD:EE:FF", "testProviderA" ) ); + positionKit->setPositionProvider( positionKit->constructProvider( "external_bt", "AA:BB:CC:DD:EE:FF", "testProviderA" ) ); QCOMPARE( positionKit->positionProvider()->id(), "AA:BB:CC:DD:EE:FF" ); QCOMPARE( positionKit->positionProvider()->name(), "testProviderA" ); - QCOMPARE( positionKit->positionProvider()->type(), "external" ); + QCOMPARE( positionKit->positionProvider()->type(), "external_bt" ); QCOMPARE( rawSettings.value( CoreUtils::QSETTINGS_APP_GROUP_NAME + "/activePositionProviderId" ).toString(), "AA:BB:CC:DD:EE:FF" ); #endif @@ -279,20 +279,28 @@ void TestPosition::testPositionProviderKeysInSettings() QCOMPARE( providersModel.data( providersModel.index( 1 ), PositionProvidersModel::ProviderId ), "simulated" ); providersModel.setAppSettings( &appSettings ); - providersModel.addProvider( "testProviderB", "AA:00:11:22:23:44" ); + providersModel.addProvider( "testProviderB", "AA:00:11:22:23:44", "external_bt" ); + providersModel.addProvider( "testProviderC", "localhost:9000", "external_ip" ); - // app settings should have one saved provider - testProviderB + // app settings should have two saved providers - testProviderB & testProviderC QVariantList providers = appSettings.savedPositionProviders(); - QCOMPARE( providers.count(), 1 ); // we have one (external) provider - QCOMPARE( providers.at( 0 ).toList().count(), 2 ); // the provider has two properties + QCOMPARE( providers.count(), 2 ); // we have two (external) providers + QCOMPARE( providers.at( 0 ).toList().count(), 3 ); // the provider has two properties QVariantList providerData = providers.at( 0 ).toList(); QCOMPARE( providerData.at( 0 ).toString(), "testProviderB" ); QCOMPARE( providerData.at( 1 ).toString(), "AA:00:11:22:23:44" ); + QCOMPARE( providerData.at( 2 ).toString(), "external_bt" ); + + providerData = providers.at( 1 ).toList(); + QCOMPARE( providerData.at( 0 ).toString(), "testProviderC" ); + QCOMPARE( providerData.at( 1 ).toString(), "localhost:9000" ); + QCOMPARE( providerData.at( 2 ).toString(), "external_ip" ); // remove that provider providersModel.removeProvider( "AA:00:11:22:23:44" ); + providersModel.removeProvider( "localhost:9000" ); providers = appSettings.savedPositionProviders(); @@ -762,6 +770,73 @@ void TestPosition::testPositionTransformerInternalDesktopPosition() QVERIFY( qgsDoubleNear( newPosition.elevation, 171.3 ) ); } +void TestPosition::testPositionTransformerNetworkPosition() +{ +// prepare position transformers + // WGS84 + ellipsoid + QgsCoordinateReferenceSystem ellipsoidHeightCrs = QgsCoordinateReferenceSystem::fromEpsgId( 4979 ); + // WGS84 + EGM96 + QgsCoordinateReferenceSystem geoidHeightCrs = QgsCoordinateReferenceSystem::fromEpsgId( 9707 ); + PositionTransformer passThroughTransformer( ellipsoidHeightCrs, geoidHeightCrs, true, QgsCoordinateTransformContext() ); + PositionTransformer positionTransformer( ellipsoidHeightCrs, geoidHeightCrs, false, QgsCoordinateTransformContext() ); + +#ifdef HAVE_BLUETOOTH + // mini file contains only minimal info like position and date + QString miniNmeaPositionFilePath = TestUtils::testDataDir() + "/position/nmea_petrzalka_mini.txt"; + QFile miniNmeaFile( miniNmeaPositionFilePath ); + miniNmeaFile.open( QFile::ReadOnly ); + + QVERIFY( miniNmeaFile.isOpen() ); + + NmeaParser parser; + QgsGpsInformation position = parser.parseNmeaString( miniNmeaFile.readAll() ); + GeoPosition geoPosition = GeoPosition::fromQgsGpsInformation( position ); + + QVERIFY( qgsDoubleNear( geoPosition.latitude, 48.10305 ) ); + QVERIFY( qgsDoubleNear( geoPosition.longitude, 17.1064 ) ); + QCOMPARE( geoPosition.elevation, 171.3 ); + QCOMPARE( geoPosition.elevation_diff, std::numeric_limits::quiet_NaN() ); +#else + GeoPosition geoPosition; + geoPosition.latitude = 48.10305; + geoPosition.longitude = 17.1064; + geoPosition.elevation = 171.3; +#endif + + // transform with pass through disabled and missing elevation separation + GeoPosition newPosition = positionTransformer.processNetworkPosition( geoPosition ); + + QVERIFY( qgsDoubleNear( newPosition.latitude, 48.10305 ) ); + QVERIFY( qgsDoubleNear( newPosition.longitude, 17.1064 ) ); + QCOMPARE( newPosition.elevation, 171.3 ); + QCOMPARE( newPosition.elevation_diff, std::numeric_limits::quiet_NaN() ); + + // transform with pass through enabled and missing elevation separation + newPosition = passThroughTransformer.processNetworkPosition( geoPosition ); + + QVERIFY( qgsDoubleNear( newPosition.latitude, 48.10305 ) ); + QVERIFY( qgsDoubleNear( newPosition.longitude, 17.1064 ) ); + QCOMPARE( newPosition.elevation, 171.3 ); + QCOMPARE( newPosition.elevation_diff, std::numeric_limits::quiet_NaN() ); + + // transform with pass through enabled and elevation separation + geoPosition.elevation_diff = 40; + newPosition = passThroughTransformer.processNetworkPosition( geoPosition ); + + QVERIFY( qgsDoubleNear( newPosition.latitude, 48.10305 ) ); + QVERIFY( qgsDoubleNear( newPosition.longitude, 17.1064 ) ); + QCOMPARE( newPosition.elevation, 171.3 ); + QCOMPARE( newPosition.elevation_diff, 40 ); + + // transform with pass through disabled and elevation separation + newPosition = positionTransformer.processNetworkPosition( geoPosition ); + + QVERIFY( qgsDoubleNear( newPosition.latitude, 48.10305 ) ); + QVERIFY( qgsDoubleNear( newPosition.longitude, 17.1064 ) ); + QVERIFY( qgsDoubleNear( newPosition.elevation, 167.53574931171875 ) ); + QVERIFY( qgsDoubleNear( newPosition.elevation_diff, 43.764250688281265 ) ); +} + void TestPosition::testPositionTransformerSimulatedPosition() { // prepare position transformers diff --git a/app/test/testposition.h b/app/test/testposition.h index 3636b89c3..40ffd45c6 100644 --- a/app/test/testposition.h +++ b/app/test/testposition.h @@ -44,6 +44,7 @@ class TestPosition: public QObject void testPositionTransformerInternalAndroidPosition(); void testPositionTransformerInternalIosPosition(); void testPositionTransformerInternalDesktopPosition(); + void testPositionTransformerNetworkPosition(); void testPositionTransformerSimulatedPosition(); private: diff --git a/app/test/testutilsfunctions.cpp b/app/test/testutilsfunctions.cpp index 556f0d3ac..2a55d201b 100644 --- a/app/test/testutilsfunctions.cpp +++ b/app/test/testutilsfunctions.cpp @@ -1047,3 +1047,32 @@ void TestUtilsFunctions::testSanitizePath() InputUtils::sanitizePath( str ); QCOMPARE( str, QStringLiteral( "C:/project name/project.qgz" ) ); } + +void TestUtilsFunctions::testUniqueString() +{ + const QStringList similarStrings( {QStringLiteral( "lutra" ), QStringLiteral( "lutra (1)" ), QStringLiteral( "lutra (256)" ), QStringLiteral( "lutra (257)" )} ); + + const QString testString1( QStringLiteral( "lutra" ) ); + QString result = InputUtils::getUniqueString( testString1, similarStrings ); + QCOMPARE( result, QStringLiteral( "lutra (2)" ) ); + + const QString testString2( QStringLiteral( "lutra " ) ); + result = InputUtils::getUniqueString( testString2, similarStrings ); + QCOMPARE( result, QStringLiteral( "lutra (2)" ) ); + + const QString testString3( QStringLiteral( " lutra" ) ); + result = InputUtils::getUniqueString( testString3, similarStrings ); + QCOMPARE( result, QStringLiteral( "lutra (2)" ) ); + + const QString testString4( QStringLiteral( "lutra (1)" ) ); + result = InputUtils::getUniqueString( testString4, similarStrings ); + QCOMPARE( result, QStringLiteral( "lutra (2)" ) ); + + const QString testString5( QStringLiteral( "lutra (256)" ) ); + result = InputUtils::getUniqueString( testString5, similarStrings ); + QCOMPARE( result, QStringLiteral( "lutra (258)" ) ); + + const QString testString6( QStringLiteral( "mulutram" ) ); + result = InputUtils::getUniqueString( testString6, similarStrings ); + QCOMPARE( result, QStringLiteral( "mulutram" ) ); +} diff --git a/app/test/testutilsfunctions.h b/app/test/testutilsfunctions.h index affe9437d..09839fecb 100644 --- a/app/test/testutilsfunctions.h +++ b/app/test/testutilsfunctions.h @@ -52,6 +52,7 @@ class TestUtilsFunctions: public QObject void testRelevantGeometryCenterToScreenCoordinates(); void testIsValidEmail(); void testSanitizePath(); + void testUniqueString(); private: void testFormatDuration( const QDateTime &t0, qint64 diffSecs, const QString &expectedResult ); diff --git a/app/test/testvariablesmanager.cpp b/app/test/testvariablesmanager.cpp index e7bda0498..cd191c431 100644 --- a/app/test/testvariablesmanager.cpp +++ b/app/test/testvariablesmanager.cpp @@ -84,7 +84,7 @@ void TestVariablesManager::testPositionVariables() evaluateExpression( QStringLiteral( "@position_gps_antenna_height" ), QStringLiteral( "0.000" ), &context ); evaluateExpression( QStringLiteral( "@position_provider_address" ), QStringLiteral( "AA:AA:FF:AA:00:10" ), &context ); evaluateExpression( QStringLiteral( "@position_provider_name" ), QStringLiteral( "testBluetoothProvider" ), &context ); - evaluateExpression( QStringLiteral( "@position_provider_type" ), QStringLiteral( "external" ), &context ); + evaluateExpression( QStringLiteral( "@position_provider_type" ), QStringLiteral( "external_bt" ), &context ); mAppSettings->setGpsAntennaHeight( 1.6784 ); pos.verticalSpeed = 1.345; diff --git a/gallery/positionkit.h b/gallery/positionkit.h index 059a3e737..bab5f6dfc 100644 --- a/gallery/positionkit.h +++ b/gallery/positionkit.h @@ -61,7 +61,7 @@ class PositionKit : public QObject private: QString pProviderName = "Gps Source is ok!"; - QString pProviderType = "external"; + QString pProviderType = "external_bt"; QString pProviderMessage = "Connected"; QString pStateMessage = "Message"; QString pLastRead = "17:19:08 CEST"; diff --git a/gallery/qml.qrc b/gallery/qml.qrc index d709e4bc5..ece26deed 100644 --- a/gallery/qml.qrc +++ b/gallery/qml.qrc @@ -40,6 +40,7 @@ ../app/qml/components/MMPageHeader.qml ../app/qml/components/MMDrawerHeader.qml ../app/qml/components/MMLine.qml + ../app/qml/components/MMIconCheckBoxHorizontal.qml ../app/qml/components/MMIcon.qml ../app/qml/components/MMLine.qml ../app/qml/components/MMText.qml @@ -79,7 +80,6 @@ ../app/qml/components/MMSingleClickMouseArea.qml ../app/qml/components/MMNotificationBox.qml ../app/qml/account/components/MMAccountPageItem.qml - ../app/qml/account/components/MMIconCheckBoxHorizontal.qml ../app/qml/account/components/MMIconCheckBoxVertical.qml ../app/qml/account/components/MMWorkspaceDelegate.qml ../app/qml/account/components/MMWorkspaceInvitationDelegate.qml @@ -142,7 +142,7 @@ ../app/qml/settings/components/MMSettingsInput.qml ../app/qml/settings/components/MMSettingsDropdown.qml ../app/qml/settings/components/MMSettingsSwitch.qml - ../app/qml/gps/MMBluetoothConnectionDrawer.qml + ../app/qml/gps/MMExternalProviderConnectionDrawer.qml ../app/qml/gps/MMGpsDataDrawer.qml ../app/qml/gps/components/MMGpsDataText.qml ../app/qml/dialogs/MMSyncFailedDialog.qml diff --git a/gallery/qml/pages/ChecksPage.qml b/gallery/qml/pages/ChecksPage.qml index 8c2b5129d..7d14690c8 100644 --- a/gallery/qml/pages/ChecksPage.qml +++ b/gallery/qml/pages/ChecksPage.qml @@ -73,30 +73,43 @@ ScrollView { spacing: 10 anchors.fill: parent - MMAccountComponents.MMIconCheckBoxHorizontal { + MMComponents.MMIconCheckBoxHorizontal{ checked: false sourceIcon: __style.qgisIcon text: "QGIS website" } - MMAccountComponents.MMIconCheckBoxHorizontal { + MMComponents.MMIconCheckBoxHorizontal{ checked: true sourceIcon: __style.qgisIcon text: "QGIS website" } - MMAccountComponents.MMIconCheckBoxHorizontal { + MMComponents.MMIconCheckBoxHorizontal{ checked: false sourceIcon: __style.redditIcon text: "Reddit" small: true } - MMAccountComponents.MMIconCheckBoxHorizontal { + MMComponents.MMIconCheckBoxHorizontal{ checked: true + width: 300 * __dp sourceIcon: __style.redditIcon text: "Reddit" - small: true + description: "This is a small description to check the functionality of this component" + small: false + } + + + MMComponents.MMIconCheckBoxHorizontal{ + checked: false + width: 300 * __dp + sourceIcon: __style.redditIcon + text: "Internet provider mock" + description: "This is a small description to check the functionality of this component" + small: false + showBorder: true } } } diff --git a/gallery/qml/pages/DrawerPage.qml b/gallery/qml/pages/DrawerPage.qml index e3400a423..47a0aab1f 100644 --- a/gallery/qml/pages/DrawerPage.qml +++ b/gallery/qml/pages/DrawerPage.qml @@ -59,7 +59,7 @@ Page { } Button { - text: "MMBluetoothConnectionDrawer" + text: "MMExternalProviderConnectionDrawer" onClicked: { bluetoothConnectionDrawer.positionProvider.state = PositionProvider.Connecting bluetoothConnectionTimer.start() @@ -197,8 +197,9 @@ Page { } } - MMBluetoothConnectionDrawer { + MMExternalProviderConnectionDrawer { id: bluetoothConnectionDrawer + providerType: "bluetooth" howToConnectGPSLink: "www.merginmaps.com" positionProvider: QtObject { diff --git a/gallery/qml/pages/ImagesPage.qml b/gallery/qml/pages/ImagesPage.qml index ed931d11b..59bd68133 100644 --- a/gallery/qml/pages/ImagesPage.qml +++ b/gallery/qml/pages/ImagesPage.qml @@ -38,7 +38,8 @@ ScrollView { Column { Image { source: __style.positionTrackingRunningImage } Text { text: "positionTrackingRunningImage" } } Column { Image { source: __style.noMapThemesImage } Text { text: "noMapThemesImage" } } Column { Image { source: __style.syncImage } Text { text: "syncImage" } } - Column { Image { source: __style.externalGpsGreenImage } Text { text: "externalGpsGreenImage" } } + Column { Image { source: __style.externalBluetoothGreenImage } Text { text: "externalBluetoothGreenImage" } } + Column { Image { source: __style.externalNetworkGreenImage } Text { text: "externalNetworkGreenImage" } } Column { Image { source: __style.externalGpsRedImage } Text { text: "externalGpsRedImage" } } Column { Image { source: __style.reachedDataLimitImage } Text { text: "reachedDataLimitImage" } } Column { Image { source: __style.positiveMMSymbolImage } Text { text: "positiveMMSymbolImage" } }