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
This commit is contained in:
Nyall Dawson 2020-08-05 15:20:38 +10:00
parent f7454f65b8
commit 97915e3203
8 changed files with 54 additions and 1 deletions

View File

@ -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:

View File

@ -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 )

View File

@ -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 );

View File

@ -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<QgsMapLayer *> layers )
{
if ( !layers.isEmpty() )

View File

@ -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 );

View File

@ -860,3 +860,8 @@ QgsLayerTreeRegistryBridge::InsertionPoint QgisAppInterface::layerTreeInsertionP
{
return qgis->layerTreeInsertionPoint();
}
void QgisAppInterface::setGpsPanelConnection( QgsGpsConnection *connection )
{
qgis->setGpsPanelConnection( connection );
}

View File

@ -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:

View File

@ -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:
/**