From 97915e32033c2f99462abe599f626c794a17bcfb Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 5 Aug 2020 15:20:38 +1000 Subject: [PATCH] Add a iface method to directly set a specific GPS connection to connect to in the GPS Information panel Allows for plugins to create subclasses of QgsGpsConnection and then hook these into the existing GPS panel widget --- python/gui/auto_generated/qgisinterface.sip.in | 10 ++++++++++ src/app/gps/qgsgpsinformationwidget.cpp | 5 +++++ src/app/gps/qgsgpsinformationwidget.h | 8 ++++++++ src/app/qgisapp.cpp | 5 +++++ src/app/qgisapp.h | 9 +++++++++ src/app/qgisappinterface.cpp | 5 +++++ src/app/qgisappinterface.h | 2 +- src/gui/qgisinterface.h | 11 +++++++++++ 8 files changed, 54 insertions(+), 1 deletion(-) diff --git a/python/gui/auto_generated/qgisinterface.sip.in b/python/gui/auto_generated/qgisinterface.sip.in index 1b037892060..fa03eb23571 100644 --- a/python/gui/auto_generated/qgisinterface.sip.in +++ b/python/gui/auto_generated/qgisinterface.sip.in @@ -1395,6 +1395,16 @@ Returns the application browser model. Using this shared model is more efficient creating a new browser model for every use. .. versionadded:: 3.4 +%End + + virtual void setGpsPanelConnection( QgsGpsConnection *connection ) = 0; +%Docstring +Sets a GPS ``connection`` to use within the GPS Panel widget. + +Any existing GPS connection used by the widget will be disconnect and replaced with this connection. The connection +is automatically registered within the :py:func:`QgsApplication.gpsConnectionRegistry()`. + +.. versionadded:: 3.16 %End signals: diff --git a/src/app/gps/qgsgpsinformationwidget.cpp b/src/app/gps/qgsgpsinformationwidget.cpp index ec6d281824d..36a4815aa6e 100644 --- a/src/app/gps/qgsgpsinformationwidget.cpp +++ b/src/app/gps/qgsgpsinformationwidget.cpp @@ -528,6 +528,11 @@ bool QgsGpsInformationWidget::blockCanvasInteraction( QgsMapCanvasInteractionBlo return false; } +void QgsGpsInformationWidget::setConnection( QgsGpsConnection *connection ) +{ + connected( connection ); +} + void QgsGpsInformationWidget::mSpinTrackWidth_valueChanged( int value ) { if ( mRubberBand ) diff --git a/src/app/gps/qgsgpsinformationwidget.h b/src/app/gps/qgsgpsinformationwidget.h index cc668459663..e636d411e34 100644 --- a/src/app/gps/qgsgpsinformationwidget.h +++ b/src/app/gps/qgsgpsinformationwidget.h @@ -58,6 +58,14 @@ class APP_EXPORT QgsGpsInformationWidget: public QgsPanelWidget, public QgsMapCa bool blockCanvasInteraction( Interaction interaction ) const override; + /** + * Sets a GPS \a connection to use within the GPS Panel widget. + * + * Any existing GPS connection used by the widget will be disconnect and replaced with this connection. The connection + * is automatically registered within the QgsApplication::gpsConnectionRegistry(). + */ + void setConnection( QgsGpsConnection *connection ); + public slots: void tapAndHold( const QgsPointXY &mapPoint, QTapAndHoldGesture *gesture ); diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index e9d023dae81..5b799e901e5 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -4813,6 +4813,11 @@ QgsLayerTreeRegistryBridge::InsertionPoint QgisApp::layerTreeInsertionPoint() co return QgsLayerTreeRegistryBridge::InsertionPoint( insertGroup, index ); } +void QgisApp::setGpsPanelConnection( QgsGpsConnection *connection ) +{ + mpGpsWidget->setConnection( connection ); +} + void QgisApp::autoSelectAddedLayer( QList layers ) { if ( !layers.isEmpty() ) diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h index c9b604f0c2e..ed27e75e1e5 100644 --- a/src/app/qgisapp.h +++ b/src/app/qgisapp.h @@ -110,6 +110,7 @@ class QgsUserProfileManagerWidgetFactory; class Qgs3DMapCanvasDockWidget; class QgsHandleBadLayersHandler; class QgsNetworkAccessManager; +class QgsGpsConnection; class QDomDocument; class QNetworkReply; @@ -802,6 +803,14 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow QgsLayerTreeRegistryBridge::InsertionPoint layerTreeInsertionPoint() const; + /** + * Sets a GPS \a connection to use within the GPS Panel widget. + * + * Any existing GPS connection used by the widget will be disconnect and replaced with this connection. The connection + * is automatically registered within the QgsApplication::gpsConnectionRegistry(). + */ + void setGpsPanelConnection( QgsGpsConnection *connection ); + public slots: //! save current vector layer QString saveAsFile( QgsMapLayer *layer = nullptr, bool onlySelected = false, bool defaultToAddToMap = true ); diff --git a/src/app/qgisappinterface.cpp b/src/app/qgisappinterface.cpp index 4e1225fc748..dde798f9fa4 100644 --- a/src/app/qgisappinterface.cpp +++ b/src/app/qgisappinterface.cpp @@ -860,3 +860,8 @@ QgsLayerTreeRegistryBridge::InsertionPoint QgisAppInterface::layerTreeInsertionP { return qgis->layerTreeInsertionPoint(); } + +void QgisAppInterface::setGpsPanelConnection( QgsGpsConnection *connection ) +{ + qgis->setGpsPanelConnection( connection ); +} diff --git a/src/app/qgisappinterface.h b/src/app/qgisappinterface.h index c936a1afcbd..e98f5abab68 100644 --- a/src/app/qgisappinterface.h +++ b/src/app/qgisappinterface.h @@ -309,7 +309,7 @@ class APP_EXPORT QgisAppInterface : public QgisInterface void takeAppScreenShots( const QString &saveDirectory, const int categories = 0 ) override; QgsBrowserGuiModel *browserModel() override; QgsLayerTreeRegistryBridge::InsertionPoint layerTreeInsertionPoint() override; - + void setGpsPanelConnection( QgsGpsConnection *connection ) override; private slots: diff --git a/src/gui/qgisinterface.h b/src/gui/qgisinterface.h index ff13ea174ab..32b4840a458 100644 --- a/src/gui/qgisinterface.h +++ b/src/gui/qgisinterface.h @@ -64,6 +64,7 @@ class QgsStatusBar; class QgsMeshLayer; class QgsBrowserGuiModel; class QgsDevToolWidgetFactory; +class QgsGpsConnection; /** @@ -1157,6 +1158,16 @@ class GUI_EXPORT QgisInterface : public QObject */ virtual QgsBrowserGuiModel *browserModel() = 0; + /** + * Sets a GPS \a connection to use within the GPS Panel widget. + * + * Any existing GPS connection used by the widget will be disconnect and replaced with this connection. The connection + * is automatically registered within the QgsApplication::gpsConnectionRegistry(). + * + * \since QGIS 3.16 + */ + virtual void setGpsPanelConnection( QgsGpsConnection *connection ) = 0; + signals: /**