Skip to content

Commit

Permalink
In Qt we cannot trust, revert "In Qt we shall trust, let it deal with…
Browse files Browse the repository at this point in the history
… screen orientation"

This reverts commit 3e5e8c0.
  • Loading branch information
nirvn committed Dec 20, 2024
1 parent 3e5e8c0 commit 99187e2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
27 changes: 26 additions & 1 deletion src/core/positioning/positioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -250,6 +270,11 @@ void Positioning::processGnssPositionInformation()
mCoordinateTransformer->setSourcePosition( mSourcePosition );
}

if ( mPositionInformation.orientationValid() )
{
mPositionInformation.setOrientation( adjustOrientation( mPositionInformation.orientation() ) );
}

emit positionInformationChanged();
}

Expand Down
6 changes: 2 additions & 4 deletions src/core/positioning/positioningsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down

0 comments on commit 99187e2

Please sign in to comment.