Skip to content

Commit

Permalink
In warning bar which shows when GPS connection fails, add a
Browse files Browse the repository at this point in the history
"Configure Device" button which directly opens the GPS options
dialog

Makes it easier for users to find the correct place to fix
these settings
  • Loading branch information
nyalldawson committed Nov 4, 2022
1 parent 151b1f2 commit 0ba80bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/app/gps/qgsappgpsconnection.cpp
Expand Up @@ -21,6 +21,7 @@
#include "qgisapp.h"
#include "qgsstatusbar.h"
#include "qgsmessagebar.h"
#include "qgsmessagebaritem.h"

QgsAppGpsConnection::QgsAppGpsConnection( QObject *parent )
: QObject( parent )
Expand Down Expand Up @@ -122,7 +123,7 @@ void QgsAppGpsConnection::connectGps()
if ( port.isEmpty() )
{
QgisApp::instance()->statusBarIface()->clearMessage();
QgisApp::instance()->messageBar()->pushCritical( QString(), tr( "No path to the GPS port is specified. Please set a path then try again." ) );
showGpsConnectFailureWarning( tr( "No path to the GPS port is specified. Please set a path then try again." ) );
emit connectionError( tr( "No path to the GPS port is specified. Please set a path then try again." ) );
emit statusChanged( Qgis::GpsConnectionStatus::Disconnected );
return;
Expand Down Expand Up @@ -170,7 +171,7 @@ void QgsAppGpsConnection::onTimeOut()
emit statusChanged( Qgis::GpsConnectionStatus::Disconnected );

QgisApp::instance()->statusBarIface()->clearMessage();
QgisApp::instance()->messageBar()->pushCritical( QString(), tr( "Failed to connect to GPS device." ) );
showGpsConnectFailureWarning( tr( "Failed to connect to GPS device." ) );
}

void QgsAppGpsConnection::onConnected( QgsGpsConnection *conn )
Expand Down Expand Up @@ -199,3 +200,15 @@ void QgsAppGpsConnection::showStatusBarMessage( const QString &msg )
{
QgisApp::instance()->statusBarIface()->showMessage( msg );
}

void QgsAppGpsConnection::showGpsConnectFailureWarning( const QString &message )
{
QgsMessageBarItem *item = QgisApp::instance()->messageBar()->createMessage( QString(), message );
QPushButton *configureButton = new QPushButton( tr( "Configure Device…" ) );
connect( configureButton, &QPushButton::clicked, configureButton, [ = ]
{
QgisApp::instance()->showOptionsDialog( QgisApp::instance(), QStringLiteral( "mGpsOptions" ) );
} );
item->layout()->addWidget( configureButton );
QgisApp::instance()->messageBar()->pushWidget( item, Qgis::MessageLevel::Critical );
}
2 changes: 2 additions & 0 deletions src/app/gps/qgsappgpsconnection.h
Expand Up @@ -140,6 +140,8 @@ class APP_EXPORT QgsAppGpsConnection : public QObject

void showStatusBarMessage( const QString &msg );

void showGpsConnectFailureWarning( const QString &message );

QgsGpsConnection *mConnection = nullptr;
};

Expand Down

0 comments on commit 0ba80bd

Please sign in to comment.