Skip to content

Commit

Permalink
[ui][sensors] Sensors GUI registry implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Mar 30, 2023
1 parent 97d68a3 commit 95c57b1
Show file tree
Hide file tree
Showing 25 changed files with 1,611 additions and 10 deletions.
1 change: 1 addition & 0 deletions doc/CMakeLists.txt
Expand Up @@ -122,6 +122,7 @@ if(WITH_APIDOC)
${CMAKE_SOURCE_DIR}/src/gui/processing
${CMAKE_SOURCE_DIR}/src/gui/processing/models
${CMAKE_SOURCE_DIR}/src/gui/raster
${CMAKE_SOURCE_DIR}/src/gui/sensor
${CMAKE_SOURCE_DIR}/src/gui/settings
${CMAKE_SOURCE_DIR}/src/gui/symbology
${CMAKE_SOURCE_DIR}/src/gui/tableeditor
Expand Down
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -797,6 +797,7 @@
<file>themes/default/mActionRegularPolygonCenterPoint.svg</file>
<file>themes/default/3d.svg</file>
<file>themes/default/mActionResizeSquare.svg</file>
<file>themes/default/mSensor.svg</file>
<file>themes/default/mSourceFields.svg</file>
<file>themes/default/cursors/mCapturePoint.svg</file>
<file>themes/default/cursors/mCrossHair.svg</file>
Expand Down
2 changes: 2 additions & 0 deletions images/themes/default/mSensor.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions python/gui/auto_generated/qgsgui.sip.in
Expand Up @@ -10,6 +10,7 @@




class QgsGui : QObject
{
%Docstring(signature="appended")
Expand Down Expand Up @@ -130,6 +131,13 @@ Returns the global GUI-related project storage registry
Returns the registry of GUI-related components of data providers

.. versionadded:: 3.10
%End

static QgsSensorGuiRegistry *sensorGuiRegistry() /KeepReference/;
%Docstring
Returns the registry of GUI-related components for sensors

.. versionadded:: 3.32
%End

static QgsSubsetStringEditorProviderRegistry *subsetStringEditorProviderRegistry() /KeepReference/;
Expand Down
156 changes: 156 additions & 0 deletions python/gui/auto_generated/sensor/qgssensorguiregistry.sip.in
@@ -0,0 +1,156 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/sensor/qgssensorguiregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsSensorAbstractGuiMetadata
{
%Docstring(signature="appended")
Stores GUI metadata about one sensor class.

This is a companion to :py:class:`QgsSensorAbstractMetadata`, storing only
the components related to the GUI behavior of sensor.

.. note::

In C++ you can use :py:class:`QgsSensorGuiMetadata` convenience class.

.. versionadded:: 3.32
%End

%TypeHeaderCode
#include "qgssensorguiregistry.h"
%End
public:

QgsSensorAbstractGuiMetadata( const QString &type, const QString &visibleName );
%Docstring
Constructor for QgsSensorAbstractGuiMetadata with the specified class ``type``.

``visibleName`` should be set to a translated, user visible name identifying the corresponding sensor type.
%End

virtual ~QgsSensorAbstractGuiMetadata();

QString type() const;
%Docstring
Returns the unique type code for the sensor class.
%End

QString visibleName() const;
%Docstring
Returns a translated, user visible name identifying the corresponding sensor.
%End

virtual QIcon creationIcon() const;
%Docstring
Returns an icon representing creation of the sensor type.
%End


virtual QgsAbstractSensorWidget *createSensorWidget( QgsAbstractSensor *sensor ) /TransferBack/;
%Docstring
Creates a configuration widget for an ``sensor`` of this type. Can return ``None`` if no configuration GUI is required.
%End

virtual QgsAbstractSensor *createSensor( QObject *parent ) /TransferBack/;
%Docstring
Creates an instance of the corresponding sensor type.
%End

};



class QgsSensorGuiRegistry : QObject
{
%Docstring(signature="appended")
Registry of available sensor GUI behavior.

:py:class:`QgsSensorGuiRegistry` is not usually directly created, but rather accessed through
:py:func:`QgsGui.sensorGuiRegistry()`.

This acts as a companion to :py:class:`QgsSensorRegistry`, handling only
the components related to the GUI behavior of sensors.

.. versionadded:: 3.32
%End

%TypeHeaderCode
#include "qgssensorguiregistry.h"
%End
public:

QgsSensorGuiRegistry( QObject *parent = 0 );
%Docstring
Creates a new empty sensor GUI registry.

QgsSensorGuiRegistry is not usually directly created, but rather accessed through
:py:func:`QgsGui.sensorGuiRegistry()`.
%End
~QgsSensorGuiRegistry();


bool populate();
%Docstring
Populates the registry with standard sensor types. If called on a non-empty registry
then this will have no effect and will return ``False``.
%End

QgsSensorAbstractGuiMetadata *sensorMetadata( const QString &type ) const;
%Docstring
Returns the metadata for the specified sensor ``type``. Returns ``None`` if
a corresponding sensor type was not found in the registry.
%End

bool addSensorGuiMetadata( QgsSensorAbstractGuiMetadata *metadata /Transfer/ );
%Docstring
Registers the GUI metadata for a new sensor type. Takes ownership of the metadata instance.
%End


QgsAbstractSensor *createSensor( const QString &type, QObject *parent = 0 ) const /TransferBack/;
%Docstring
Creates a new instance of a sensor given the ``type``.
%End

QgsAbstractSensorWidget *createSensorWidget( QgsAbstractSensor *sensor ) const /TransferBack/;
%Docstring
Creates a new instance of a sensor configuration widget for the specified ``sensor``. The
``sensor`` doesn't need to live for the duration of the widget, it is only used when creating
the configuration widget to match a sensor type and initiate the widget to match the
``sensor`` settings.
%End

QMap<QString, QString> sensorTypes() const;
%Docstring
Returns a list of sensor types handled by the registry.
%End

signals:

void sensorAdded( const QString &type, const QString &name );
%Docstring
Emitted whenever a new sensor type is added to the registry, with the specified
``type``.
%End

private:
QgsSensorGuiRegistry( const QgsSensorGuiRegistry &rh );
};




/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/sensor/qgssensorguiregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
72 changes: 72 additions & 0 deletions python/gui/auto_generated/sensor/qgssensorwidget.sip.in
@@ -0,0 +1,72 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/sensor/qgssensorwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsAbstractSensorWidget : QWidget
{
%Docstring(signature="appended")
Base class for widgets which allow control over the properties of sensors.

.. versionadded:: 3.32
%End

%TypeHeaderCode
#include "qgssensorwidget.h"
%End
public:

QgsAbstractSensorWidget( QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsAbstractSensorWidget.

:param parent: parent widget
%End

virtual QgsAbstractSensor *createSensor() = 0 /Factory/;
%Docstring
Creates a new sensor matching the settings defined in the widget.
%End

virtual bool updateSensor( QgsAbstractSensor *sensor ) = 0;
%Docstring
Updates an existing ``sensor`` to match the settings defined in the widget. If
``True`` is returned, the ``sensor`` was successfully updated.

If ``False`` is returned, then the widget could not successfully update
the ``sensor``.
%End

virtual bool setSensor( QgsAbstractSensor *sensor ) = 0;
%Docstring
Sets the widget settings to match a given ``sensor``. If ``True`` is returned, ``sensor``
was an acceptable type and the widget has been updated to match
the ``sensor``'s properties.

If ``False`` is returned, then the widget could not be successfully updated
to show the properties of ``sensor``.
%End

signals:

void changed();
%Docstring
Emitted whenever configuration changes happened on this sensor configuration.
%End
};


/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/sensor/qgssensorwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
2 changes: 2 additions & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -476,6 +476,8 @@
%Include auto_generated/symbology/qgssymbolslistwidget.sip
%Include auto_generated/symbology/qgssymbolwidgetcontext.sip
%Include auto_generated/symbology/qgsvectorfieldsymbollayerwidget.sip
%Include auto_generated/sensor/qgssensorguiregistry.sip
%Include auto_generated/sensor/qgssensorwidget.sip
%Include auto_generated/settings/qgssettingsregistrygui.sip
%Include auto_generated/tableeditor/qgstableeditordialog.sip
%Include auto_generated/tableeditor/qgstableeditorwidget.sip
Expand Down
18 changes: 18 additions & 0 deletions src/app/sensor/qgsprojectsensorsettingswidget.cpp
Expand Up @@ -20,12 +20,16 @@
#include "qgsapplication.h"
#include "qgsproject.h"
#include "qgssensormanager.h"
#include "qgssensortablewidget.h"

QgsProjectSensorSettingsWidget::QgsProjectSensorSettingsWidget( QWidget *parent )
: QgsOptionsPageWidget( parent )
{
setupUi( this );

QgsSensorTableWidget *widget = new QgsSensorTableWidget( this );
mPanelStack->setMainPanel( widget );

QDomElement sensorElem = QgsProject::instance()->sensorManager()->writeXml( mPreviousSensors );
mPreviousSensors.appendChild( sensorElem );

Expand Down Expand Up @@ -67,6 +71,20 @@ void QgsProjectSensorSettingsWidget::cancel()

void QgsProjectSensorSettingsWidget::apply()
{
mPreviousSensors = QDomDocument();
QDomElement sensorElem = QgsProject::instance()->sensorManager()->writeXml( mPreviousSensors );
mPreviousSensors.appendChild( sensorElem );

mConnectedSensors.clear();
const QList<QgsAbstractSensor *> sensors = QgsProject::instance()->sensorManager()->sensors();
for ( QgsAbstractSensor *sensor : sensors )
{
if ( sensor->status() == Qgis::DeviceConnectionStatus::Connected )
{
mConnectedSensors << sensor->id();
}
}

return;
}

Expand Down

0 comments on commit 95c57b1

Please sign in to comment.