diff --git a/src/core/positioning/positioning.cpp b/src/core/positioning/positioning.cpp index 4f333c40c7..69f13add08 100644 --- a/src/core/positioning/positioning.cpp +++ b/src/core/positioning/positioning.cpp @@ -198,7 +198,27 @@ GnssPositionInformation Positioning::positionInformation() const double Positioning::orientation() const { - return mPositioningSourceReplica->property( "orientation" ).toDouble(); + return adjustOrientation( mPositioningSourceReplica->property( "orientation" ).toDouble() ); +} + +double Positioning::adjustOrientation( double orientation ) const +{ + // Take into account the orientation of the device + QScreen *screen = QgsApplication::instance()->primaryScreen(); + switch ( screen->orientation() ) + { + case Qt::LandscapeOrientation: + orientation += 90; + break; + case Qt::InvertedLandscapeOrientation: + orientation += 270; + break; + case Qt::PortraitOrientation: + default: + break; + } + + return std::fmod( orientation, 360 ); } void Positioning::setCoordinateTransformer( QgsQuickCoordinateTransformer *coordinateTransformer ) @@ -250,6 +270,11 @@ void Positioning::processGnssPositionInformation() mCoordinateTransformer->setSourcePosition( mSourcePosition ); } + if ( mPositionInformation.orientationValid() ) + { + mPositionInformation.setOrientation( adjustOrientation( mPositionInformation.orientation() ) ); + } + emit positionInformationChanged(); } diff --git a/src/core/positioning/positioningsource.cpp b/src/core/positioning/positioningsource.cpp index 96071e40df..b6ceff1c21 100644 --- a/src/core/positioning/positioningsource.cpp +++ b/src/core/positioning/positioningsource.cpp @@ -34,10 +34,8 @@ PositioningSource::PositioningSource( QObject *parent ) // Setup internal gnss receiver by default setupDevice(); - // Setup the compass to respect screen orientation - mCompass.setAxesOrientationMode( QSensor::AxesOrientationMode::AutomaticOrientation ); - - // Use a timer instead of the compass's readingChanged signal to avoid handling too many signals + // Setup the compass, use a timer instead of the compass's readingChanged signal to avoid handling + // too many signals mCompassTimer.setInterval( 200 ); connect( &mCompassTimer, &QTimer::timeout, this, &PositioningSource::processCompassReading ); }