Skip to content

Commit

Permalink
[needs-docs][gps] Add explicit setting to allow control over the freq…
Browse files Browse the repository at this point in the history
…uency

of map rotation to match GPS bearing

Otherwise frequent GPS updates can cause a too many map redraws to occur quickly
  • Loading branch information
nyalldawson committed Jan 6, 2020
1 parent e2bb325 commit 3f9b53e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 19 deletions.
10 changes: 9 additions & 1 deletion src/app/gps/qgsgpsinformationwidget.cpp
Expand Up @@ -130,6 +130,8 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsMapCanvas *mapCanvas, QWidg
mpHistogramLayout->addWidget( mPlot ); mpHistogramLayout->addWidget( mPlot );
mpHistogramWidget->setLayout( mpHistogramLayout ); mpHistogramWidget->setLayout( mpHistogramLayout );


mSpinMapRotateInterval->setClearValue( 0 );

// //
// Set up the polar graph for satellite pos // Set up the polar graph for satellite pos
// //
Expand Down Expand Up @@ -276,7 +278,11 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsMapCanvas *mapCanvas, QWidg
{ {
radRecenterWhenNeeded->setChecked( true ); radRecenterWhenNeeded->setChecked( true );
} }

connect( mRotateMapCheckBox, &QCheckBox::toggled, mSpinMapRotateInterval, &QSpinBox::setEnabled );

mRotateMapCheckBox->setChecked( mySettings.value( QStringLiteral( "gps/rotateMap" ), false ).toBool() ); mRotateMapCheckBox->setChecked( mySettings.value( QStringLiteral( "gps/rotateMap" ), false ).toBool() );
mSpinMapRotateInterval->setValue( mySettings.value( QStringLiteral( "gps/rotateMapInterval" ), 0 ).toInt() );
mShowBearingLineCheck->setChecked( mySettings.value( QStringLiteral( "gps/showBearingLine" ), false ).toBool() ); mShowBearingLineCheck->setChecked( mySettings.value( QStringLiteral( "gps/showBearingLine" ), false ).toBool() );


mWgs84CRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( QStringLiteral( "EPSG:4326" ) ); mWgs84CRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( QStringLiteral( "EPSG:4326" ) );
Expand Down Expand Up @@ -445,6 +451,7 @@ QgsGpsInformationWidget::~QgsGpsInformationWidget()
mySettings.setValue( QStringLiteral( "gps/panMode" ), "none" ); mySettings.setValue( QStringLiteral( "gps/panMode" ), "none" );
} }
mySettings.setValue( QStringLiteral( "gps/rotateMap" ), mRotateMapCheckBox->isChecked() ); mySettings.setValue( QStringLiteral( "gps/rotateMap" ), mRotateMapCheckBox->isChecked() );
mySettings.setValue( QStringLiteral( "gps/rotateMapInterval" ), mSpinMapRotateInterval->value() );
mySettings.setValue( QStringLiteral( "gps/showBearingLine" ), mShowBearingLineCheck->isChecked() ); mySettings.setValue( QStringLiteral( "gps/showBearingLine" ), mShowBearingLineCheck->isChecked() );


QDomDocument doc; QDomDocument doc;
Expand Down Expand Up @@ -914,9 +921,10 @@ void QgsGpsInformationWidget::displayGPSInformation( const QgsGpsInformation &in


} }


if ( mRotateMapCheckBox->isChecked() ) if ( mRotateMapCheckBox->isChecked() && ( !mLastRotateTimer.isValid() || mLastRotateTimer.hasExpired( mSpinMapRotateInterval->value() * 1000 ) ) )
{ {
mMapCanvas->setRotation( trueNorth - info.direction ); mMapCanvas->setRotation( trueNorth - info.direction );
mLastRotateTimer.restart();
} }


if ( mShowBearingLineCheck ) if ( mShowBearingLineCheck )
Expand Down
3 changes: 3 additions & 0 deletions src/app/gps/qgsgpsinformationwidget.h
Expand Up @@ -137,6 +137,9 @@ class APP_EXPORT QgsGpsInformationWidget: public QgsPanelWidget, private Ui::Qgs
QMap<QString, QString> mPreferredTimestampFields; QMap<QString, QString> mPreferredTimestampFields;
//! Flag when updating fields //! Flag when updating fields
bool mPopulatingFields = false; bool mPopulatingFields = false;

QElapsedTimer mLastRotateTimer;

friend class TestQgsGpsInformationWidget; friend class TestQgsGpsInformationWidget;
}; };


Expand Down
81 changes: 63 additions & 18 deletions src/ui/qgsgpsinformationwidgetbase.ui
Expand Up @@ -1028,7 +1028,7 @@ gray = no data
<item row="5" column="0"> <item row="5" column="0">
<widget class="QgsCollapsibleGroupBoxBasic" name="groupBox"> <widget class="QgsCollapsibleGroupBoxBasic" name="groupBox">
<property name="title"> <property name="title">
<string>Map Centering</string> <string>Map Centering and Rotation</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_8"> <layout class="QGridLayout" name="gridLayout_8">
<property name="topMargin"> <property name="topMargin">
Expand All @@ -1040,23 +1040,6 @@ gray = no data
<property name="verticalSpacing"> <property name="verticalSpacing">
<number>2</number> <number>2</number>
</property> </property>
<item row="1" column="0">
<widget class="QRadioButton" name="radRecenterWhenNeeded">
<property name="text">
<string>When leaving</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QRadioButton" name="radRecenterMap">
<property name="text">
<string>Always</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0"> <item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin"> <property name="leftMargin">
Expand Down Expand Up @@ -1092,6 +1075,23 @@ gray = no data
</item> </item>
</layout> </layout>
</item> </item>
<item row="0" column="0">
<widget class="QRadioButton" name="radRecenterMap">
<property name="text">
<string>Always</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="radRecenterWhenNeeded">
<property name="text">
<string>When leaving</string>
</property>
</widget>
</item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="QRadioButton" name="radNeverRecenter"> <widget class="QRadioButton" name="radNeverRecenter">
<property name="text"> <property name="text">
Expand All @@ -1106,6 +1106,51 @@ gray = no data
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_5" stretch="0,1">
<property name="leftMargin">
<number>20</number>
</property>
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>Frequency</string>
</property>
</widget>
</item>
<item>
<widget class="QgsSpinBox" name="mSpinMapRotateInterval">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="specialValueText">
<string>On GPS signal</string>
</property>
<property name="suffix">
<string> s</string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1000</number>
</property>
<property name="singleStep">
<number>1</number>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
Expand Down

0 comments on commit 3f9b53e

Please sign in to comment.