Skip to content
Permalink
Browse files

[needs-docs] Add a recenter button to the GPS information panel

There's NO way to recenter the map on the GPS location, which is a
HUGE ux limitation in QGIS' GPS handling. This commit adds a new
"Recenter" button to the panel to allow users to jump right to
the current GPS position.
  • Loading branch information
nyalldawson committed Feb 5, 2020
1 parent 9e540f0 commit 51f4f032f68391236a4adf67b17312e25f761271
@@ -81,6 +81,8 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsMapCanvas *mapCanvas, QWidg
Q_ASSERT( mMapCanvas ); // precondition
setupUi( this );
connect( mConnectButton, &QPushButton::toggled, this, &QgsGpsInformationWidget::mConnectButton_toggled );
connect( mRecenterButton, &QPushButton::clicked, this, &QgsGpsInformationWidget::recenter );
connect( mConnectButton, &QAbstractButton::toggled, mRecenterButton, &QWidget::setEnabled );
connect( mBtnTrackColor, &QgsColorButton::colorChanged, this, &QgsGpsInformationWidget::trackColorChanged );
connect( mSpinTrackWidth, qgis::overload< int >::of( &QSpinBox::valueChanged ), this, &QgsGpsInformationWidget::mSpinTrackWidth_valueChanged );
connect( mBtnPosition, &QToolButton::clicked, this, &QgsGpsInformationWidget::mBtnPosition_clicked );
@@ -96,6 +98,8 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsMapCanvas *mapCanvas, QWidg
connect( mMapCanvas, &QgsMapCanvas::xyCoordinates, this, &QgsGpsInformationWidget::cursorCoordinateChanged );
connect( mMapCanvas, &QgsMapCanvas::tapAndHoldGestureOccurred, this, &QgsGpsInformationWidget::tapAndHold );

mRecenterButton->setEnabled( false );

mWgs84CRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( QStringLiteral( "EPSG:4326" ) );

mBearingNumericFormat.reset( QgsLocalDefaultSettings::bearingFormat() );
@@ -552,6 +556,20 @@ void QgsGpsInformationWidget::mConnectButton_toggled( bool flag )
}
}

void QgsGpsInformationWidget::recenter()
{
try
{
const QgsPointXY center = mCanvasToWgs84Transform.transform( mLastGpsPosition, QgsCoordinateTransform::ReverseTransform );
mMapCanvas->setCenter( center );
mMapCanvas->refresh();
}
catch ( QgsCsException & )
{

}
}

void QgsGpsInformationWidget::connectGps()
{
// clear position page fields to give better indication that something happened (or didn't happen)
@@ -61,6 +61,7 @@ class APP_EXPORT QgsGpsInformationWidget: public QgsPanelWidget, private Ui::Qgs

private slots:
void mConnectButton_toggled( bool flag );
void recenter();
void displayGPSInformation( const QgsGpsInformation &info );
void logNmeaSentence( const QString &nmeaString ); // added to handle 'raw' data
void updateCloseFeatureButton( QgsMapLayer *lyr );
@@ -1414,6 +1414,22 @@ gray = no data
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="mRecenterButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Recenter</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mConnectButton">
<property name="sizePolicy">

0 comments on commit 51f4f03

Please sign in to comment.
You can’t perform that action at this time.