Skip to content

Commit

Permalink
Show location in toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 4, 2022
1 parent b6c865c commit 8ee1781
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/app/gps/qgsappgpsconnection.cpp
Expand Up @@ -58,7 +58,10 @@ void QgsAppGpsConnection::setConnection( QgsGpsConnection *connection )

QgsPoint QgsAppGpsConnection::lastValidLocation() const
{
return mConnection->lastValidLocation();
if ( mConnection )
return mConnection->lastValidLocation();
else
return QgsPoint();
}

void QgsAppGpsConnection::connectGps()
Expand Down Expand Up @@ -180,7 +183,9 @@ void QgsAppGpsConnection::onConnected( QgsGpsConnection *conn )

Qgis::GnssConstellation constellation = Qgis::GnssConstellation::Unknown;
// emit signals so initial fix status is correctly advertised
emit stateChanged( mConnection->currentGPSInformation() );
emit fixStatusChanged( mConnection->currentGPSInformation().bestFixStatus( constellation ) );
emit positionChanged( mConnection->lastValidLocation() );

//insert connection into registry such that it can also be used by other dialogs or plugins
QgsApplication::gpsConnectionRegistry()->registerConnection( mConnection );
Expand Down
27 changes: 27 additions & 0 deletions src/app/gps/qgsgpstoolbar.cpp
Expand Up @@ -19,6 +19,9 @@
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgis.h"
#include "qgscoordinateutils.h"

#include <QLabel>

QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QgsMapCanvas *canvas, QWidget *parent )
: QToolBar( parent )
Expand Down Expand Up @@ -90,4 +93,28 @@ QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QgsMapCanvas *can
}
} );
addAction( mRecenterAction );

mShowInfoAction = new QAction( tr( "Information" ) );
mShowInfoAction->setToolTip( tr( "Show GPS Information Panel" ) );
mShowInfoAction->setCheckable( true );
addAction( mShowInfoAction );

mLocationLabel = new QLabel();
addWidget( mLocationLabel );

connect( mConnection, &QgsAppGpsConnection::positionChanged, this, &QgsGpsToolBar::updateLocationLabel );
updateLocationLabel( mConnection->lastValidLocation() );
}

void QgsGpsToolBar::updateLocationLabel( const QgsPoint &point )
{
if ( point.isEmpty() )
{
mLocationLabel->clear();
}
else
{
const QString pos = QgsCoordinateUtils::formatCoordinateForProject( QgsProject::instance(), point, QgsCoordinateReferenceSystem(), 8 );
mLocationLabel->setText( pos );
}
}
11 changes: 11 additions & 0 deletions src/app/gps/qgsgpstoolbar.h
Expand Up @@ -22,6 +22,7 @@

class QgsAppGpsConnection;
class QgsMapCanvas;
class QLabel;

class QgsGpsToolBar : public QToolBar
{
Expand All @@ -31,12 +32,22 @@ class QgsGpsToolBar : public QToolBar

QgsGpsToolBar( QgsAppGpsConnection *connection, QgsMapCanvas *canvas, QWidget *parent = nullptr );

QAction *showInfoAction() { return mShowInfoAction; }

private slots:

void updateLocationLabel( const QgsPoint &point );

private:

QgsAppGpsConnection *mConnection = nullptr;
QgsMapCanvas *mCanvas = nullptr;
QAction *mConnectAction = nullptr;
QAction *mRecenterAction = nullptr;
QAction *mShowInfoAction = nullptr;

QLabel *mLocationLabel = nullptr;

QgsCoordinateReferenceSystem mWgs84CRS;
};

Expand Down
1 change: 1 addition & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -1416,6 +1416,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers
// add to the Panel submenu
// now add our widget to the dock - ownership of the widget is passed to the dock
mpGpsDock->setWidget( gpsStack );
mpGpsDock->setToggleVisibilityAction( mGpsToolBar->showInfoAction() );
mpGpsDock->hide();

mLastMapToolMessage = nullptr;
Expand Down

0 comments on commit 8ee1781

Please sign in to comment.