Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 4, 2022
1 parent 06ef6e1 commit 8dfd167
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 44 deletions.
22 changes: 0 additions & 22 deletions src/app/gps/qgsgpsinformationwidget.cpp
Expand Up @@ -80,7 +80,6 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsAppGpsConnection *connectio
Q_ASSERT( mMapCanvas ); // precondition
setupUi( this );
connect( mConnectButton, &QPushButton::toggled, this, &QgsGpsInformationWidget::mConnectButton_toggled );
connect( mRecenterButton, &QPushButton::clicked, this, &QgsGpsInformationWidget::recenter );
connect( mBtnPosition, &QToolButton::clicked, this, &QgsGpsInformationWidget::mBtnPosition_clicked );
connect( mBtnSignal, &QToolButton::clicked, this, &QgsGpsInformationWidget::mBtnSignal_clicked );
connect( mBtnSatellites, &QToolButton::clicked, this, &QgsGpsInformationWidget::mBtnSatellites_clicked );
Expand All @@ -103,9 +102,6 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsAppGpsConnection *connectio
settingLastLogFolder.setValue( QFileInfo( mLogFilename->filePath() ).absolutePath() );
} );


mRecenterButton->setEnabled( false );

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

mBearingNumericFormat.reset( QgsLocalDefaultSettings::bearingFormat() );
Expand Down Expand Up @@ -368,19 +364,16 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsAppGpsConnection *connectio
whileBlocking( mConnectButton )->setChecked( false );
mConnectButton->setText( tr( "Connect" ) );
mConnectButton->setEnabled( true );
mRecenterButton->setEnabled( false );
break;
case Qgis::GpsConnectionStatus::Connecting:
whileBlocking( mConnectButton )->setChecked( true );
mConnectButton->setText( tr( "Connecting" ) );
mConnectButton->setEnabled( false );
mRecenterButton->setEnabled( false );
break;
case Qgis::GpsConnectionStatus::Connected:
whileBlocking( mConnectButton )->setChecked( true );
mConnectButton->setText( tr( "Disconnect" ) );
mConnectButton->setEnabled( true );
mRecenterButton->setEnabled( true );
break;
}
} );
Expand Down Expand Up @@ -570,20 +563,6 @@ void QgsGpsInformationWidget::mConnectButton_toggled( bool flag )
}
}

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

}
}

void QgsGpsInformationWidget::gpsConnecting()
{
// clear position page fields to give better indication that something happened (or didn't happen)
Expand All @@ -602,7 +581,6 @@ void QgsGpsInformationWidget::gpsConnecting()
mTxtSatellitesUsed->clear();
mTxtStatus->clear();

mLastGpsPosition = QgsPointXY();
mSecondLastGpsPosition = QgsPointXY();

mGPSPlainTextEdit->appendPlainText( tr( "Connecting…" ) );
Expand Down
1 change: 0 additions & 1 deletion src/app/gps/qgsgpsinformationwidget.h
Expand Up @@ -76,7 +76,6 @@ class APP_EXPORT QgsGpsInformationWidget: public QgsPanelWidget, public QgsMapCa

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 );
Expand Down
33 changes: 32 additions & 1 deletion src/app/gps/qgsgpstoolbar.cpp
Expand Up @@ -15,16 +15,22 @@

#include "qgsgpstoolbar.h"
#include "qgsappgpsconnection.h"
#include "qgscoordinatetransform.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgis.h"

QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QWidget *parent )
QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QgsMapCanvas *canvas, QWidget *parent )
: QToolBar( parent )
, mConnection( connection )
, mCanvas( canvas )
{
setObjectName( QStringLiteral( "mGpsToolBar" ) );
setWindowTitle( tr( "GPS Toolbar" ) );
setToolTip( tr( "GPS Toolbar" ) );

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

mConnectAction = new QAction( tr( "Connect" ), this );
mConnectAction->setCheckable( true );
addAction( mConnectAction );
Expand All @@ -37,16 +43,19 @@ QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QWidget *parent )
whileBlocking( mConnectAction )->setChecked( false );
mConnectAction->setText( tr( "Connect" ) );
mConnectAction->setEnabled( true );
mRecenterAction->setEnabled( false );
break;
case Qgis::GpsConnectionStatus::Connecting:
whileBlocking( mConnectAction )->setChecked( true );
mConnectAction->setText( tr( "Connecting" ) );
mConnectAction->setEnabled( false );
mRecenterAction->setEnabled( false );
break;
case Qgis::GpsConnectionStatus::Connected:
whileBlocking( mConnectAction )->setChecked( true );
mConnectAction->setText( tr( "Disconnect" ) );
mConnectAction->setEnabled( true );
mRecenterAction->setEnabled( true );
break;
}
} );
Expand All @@ -59,4 +68,26 @@ QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QWidget *parent )
mConnection->disconnectGps();
} );

mRecenterAction = new QAction( tr( "Recenter" ) );
mRecenterAction->setToolTip( tr( "Recenter map on GPS location" ) );
mRecenterAction->setEnabled( false );

connect( mRecenterAction, &QAction::triggered, this, [ = ]
{
if ( mConnection->lastPosition().isEmpty() )
return;

const QgsCoordinateTransform canvasToWgs84Transform = QgsCoordinateTransform( mCanvas->mapSettings().destinationCrs(), mWgs84CRS, QgsProject::instance() );
try
{
const QgsPointXY center = canvasToWgs84Transform.transform( mConnection->lastPosition(), Qgis::TransformDirection::Reverse );
mCanvas->setCenter( center );
mCanvas->refresh();
}
catch ( QgsCsException & )
{

}
} );
addAction( mRecenterAction );
}
9 changes: 7 additions & 2 deletions src/app/gps/qgsgpstoolbar.h
Expand Up @@ -18,21 +18,26 @@

#include <QToolBar>

#include "qgscoordinatereferencesystem.h"

class QgsAppGpsConnection;
class QgsMapCanvas;

class QgsGpsToolBar : public QToolBar
{
Q_OBJECT

public:

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

private:

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

QAction *mRecenterAction = nullptr;
QgsCoordinateReferenceSystem mWgs84CRS;
};

#endif // QGSGPSTOOLBAR_H
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -1395,7 +1395,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers
// create the GPS tool on starting QGIS - this is like the browser
mGpsConnection = new QgsAppGpsConnection( this );

mGpsToolBar = new QgsGpsToolBar( mGpsConnection, this );
mGpsToolBar = new QgsGpsToolBar( mGpsConnection, mMapCanvas, this );
addToolBar( mGpsToolBar );

mpGpsWidget = new QgsGpsInformationWidget( mGpsConnection, mMapCanvas );
Expand Down
17 changes: 0 additions & 17 deletions src/ui/qgsgpsinformationwidgetbase.ui
Expand Up @@ -967,22 +967,6 @@ 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">
Expand Down Expand Up @@ -1053,7 +1037,6 @@ gray = no data
<tabstop>mBtnSatellites</tabstop>
<tabstop>mBtnOptions</tabstop>
<tabstop>mBtnDebug</tabstop>
<tabstop>mRecenterButton</tabstop>
<tabstop>mConnectButton</tabstop>
<tabstop>scrollArea</tabstop>
<tabstop>mCbxAutoCommit</tabstop>
Expand Down

0 comments on commit 8dfd167

Please sign in to comment.