Skip to content

Commit d2b117a

Browse files
committedMar 24, 2023
[sensors] Brand new sensors framework (manager, registry, sensor types)
1 parent 8ea56a8 commit d2b117a

33 files changed

+2734
-26
lines changed
 

‎doc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ if(WITH_APIDOC)
8989
${CMAKE_SOURCE_DIR}/src/core/providers/memory
9090
${CMAKE_SOURCE_DIR}/src/core/raster
9191
${CMAKE_SOURCE_DIR}/src/core/scalebar
92+
${CMAKE_SOURCE_DIR}/src/core/sensor
9293
${CMAKE_SOURCE_DIR}/src/core/settings
9394
${CMAKE_SOURCE_DIR}/src/core/symbology
9495
${CMAKE_SOURCE_DIR}/src/core/textrenderer

‎python/core/auto_additions/qgis.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,13 +1161,20 @@
11611161
Qgis.GpsConnectionType.__doc__ = 'GPS connection types.\n\n.. versionadded:: 3.30\n\n' + '* ``Automatic``: ' + Qgis.GpsConnectionType.Automatic.__doc__ + '\n' + '* ``Internal``: ' + Qgis.GpsConnectionType.Internal.__doc__ + '\n' + '* ``Serial``: ' + Qgis.GpsConnectionType.Serial.__doc__ + '\n' + '* ``Gpsd``: ' + Qgis.GpsConnectionType.Gpsd.__doc__
11621162
# --
11631163
Qgis.GpsConnectionType.baseClass = Qgis
1164-
# monkey patching scoped based enum
1165-
Qgis.GpsConnectionStatus.Disconnected.__doc__ = "Device is disconnected"
1166-
Qgis.GpsConnectionStatus.Connecting.__doc__ = "Device is connecting"
1167-
Qgis.GpsConnectionStatus.Connected.__doc__ = "Device is successfully connected"
1168-
Qgis.GpsConnectionStatus.__doc__ = 'GPS connection status.\n\n.. versionadded:: 3.30\n\n' + '* ``Disconnected``: ' + Qgis.GpsConnectionStatus.Disconnected.__doc__ + '\n' + '* ``Connecting``: ' + Qgis.GpsConnectionStatus.Connecting.__doc__ + '\n' + '* ``Connected``: ' + Qgis.GpsConnectionStatus.Connected.__doc__
1169-
# --
1170-
Qgis.GpsConnectionStatus.baseClass = Qgis
1164+
Qgis.GpsConnectionStatus = Qgis.DeviceConnectionStatus
1165+
# monkey patching scoped based enum
1166+
Qgis.Disconnected = Qgis.DeviceConnectionStatus.Disconnected
1167+
Qgis.Disconnected.is_monkey_patched = True
1168+
Qgis.Disconnected.__doc__ = "Device is disconnected"
1169+
Qgis.Connecting = Qgis.DeviceConnectionStatus.Connecting
1170+
Qgis.Connecting.is_monkey_patched = True
1171+
Qgis.Connecting.__doc__ = "Device is connecting"
1172+
Qgis.Connected = Qgis.DeviceConnectionStatus.Connected
1173+
Qgis.Connected.is_monkey_patched = True
1174+
Qgis.Connected.__doc__ = "Device is successfully connected"
1175+
Qgis.DeviceConnectionStatus.__doc__ = 'GPS connection status.\n\n.. versionadded:: 3.30\n\n' + '* ``Disconnected``: ' + Qgis.DeviceConnectionStatus.Disconnected.__doc__ + '\n' + '* ``Connecting``: ' + Qgis.DeviceConnectionStatus.Connecting.__doc__ + '\n' + '* ``Connected``: ' + Qgis.DeviceConnectionStatus.Connected.__doc__
1176+
# --
1177+
Qgis.DeviceConnectionStatus.baseClass = Qgis
11711178
QgsGpsInformation.FixStatus = Qgis.GpsFixStatus
11721179
# monkey patching scoped based enum
11731180
QgsGpsInformation.NoData = Qgis.GpsFixStatus.NoData

‎python/core/auto_generated/project/qgsproject.sip.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,15 @@ the project.
782782
%End
783783

784784

785+
QgsSensorManager *sensorManager();
786+
%Docstring
787+
Returns the project's sensor manager, which manages sensors within
788+
the project.
789+
790+
.. versionadded:: 3.32
791+
%End
792+
793+
785794
QgsProjectViewSettings *viewSettings();
786795
%Docstring
787796
Returns the project's view settings, which contains settings and properties

‎python/core/auto_generated/qgis.sip.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,8 @@ The development version
687687
Gpsd,
688688
};
689689

690-
enum class GpsConnectionStatus
691-
{
690+
enum class DeviceConnectionStatus
691+
{
692692
Disconnected,
693693
Connecting,
694694
Connected,

‎python/core/auto_generated/qgsapplication.sip.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,13 @@ Using this shared model instead of creating a new :py:class:`QgsStyleModel` impr
895895
Returns the application font manager, which manages available fonts and font installation for the QGIS instance.
896896

897897
.. versionadded:: 3.28
898+
%End
899+
900+
static QgsSensorRegistry *sensorRegistry() /KeepReference/;
901+
%Docstring
902+
Returns the application's sensor registry, used for sensor types.
903+
904+
.. versionadded:: 3.32
898905
%End
899906

900907
static QgsMessageLog *messageLog();
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/sensor/qgsabstractsensor.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
class QgsAbstractSensor : QObject
12+
{
13+
%Docstring(signature="appended")
14+
An abstract base class for sensor classes
15+
16+
.. versionadded:: 3.32
17+
%End
18+
19+
%TypeHeaderCode
20+
#include "qgsabstractsensor.h"
21+
#include "qgsiodevicesensor.h"
22+
#include "qgssensorregistry.h"
23+
%End
24+
%ConvertToSubClassCode
25+
if ( QgsAbstractSensor *item = qobject_cast< QgsAbstractSensor * >( sipCpp ) )
26+
{
27+
if ( item->type() == QLatin1String( "tcp_socket" ) && dynamic_cast<QgsTcpSocketSensor *>( item ) != NULL )
28+
{
29+
sipType = sipType_QgsTcpSocketSensor;
30+
}
31+
else if ( item->type() == QLatin1String( "udp_socket" ) && dynamic_cast<QgsUdpSocketSensor *>( item ) != NULL )
32+
{
33+
sipType = sipType_QgsUdpSocketSensor;
34+
}
35+
else if ( item->type() == QLatin1String( "serial_port" ) && dynamic_cast<QgsSerialPortSensor *>( item ) != NULL )
36+
{
37+
sipType = sipType_QgsSerialPortSensor;
38+
}
39+
else
40+
{
41+
sipType = sipType_QgsAbstractSensor;
42+
}
43+
}
44+
else
45+
{
46+
sipType = NULL;
47+
}
48+
%End
49+
public:
50+
51+
struct SensorData
52+
{
53+
54+
QVariant lastValue;
55+
56+
QDateTime lastTimestamp;
57+
};
58+
59+
explicit QgsAbstractSensor( QObject *parent /TransferThis/ = 0 );
60+
%Docstring
61+
Constructor for an abstract sensor, bound to the specified ``parent``.
62+
%End
63+
virtual ~QgsAbstractSensor();
64+
65+
QString id() const;
66+
%Docstring
67+
Returns the sensor ID.
68+
69+
.. note::
70+
71+
This is a autogenerated unique string identifying an individual sensor.
72+
%End
73+
74+
virtual QString type() const;
75+
%Docstring
76+
Returns the sensor type. This will match the type string of the sensor class, as used by :py:class:`QgsSensorRegistry`.
77+
%End
78+
79+
QString name() const;
80+
%Docstring
81+
Returns the user-friendly name identifying the sensor.
82+
%End
83+
84+
void setName( const QString &name );
85+
%Docstring
86+
Sets the user-friendly name identfying the sensor.
87+
%End
88+
89+
Qgis::DeviceConnectionStatus status() const;
90+
%Docstring
91+
Returns the current sensor status.
92+
%End
93+
94+
void setStatus( Qgis::DeviceConnectionStatus status );
95+
%Docstring
96+
Sets the current sensor ``status``.
97+
%End
98+
99+
void connectSensor();
100+
%Docstring
101+
Connects the sensor to its source.
102+
%End
103+
104+
void disconnectSensor();
105+
%Docstring
106+
Disconnects the sensor from its source.
107+
%End
108+
109+
QgsAbstractSensor::SensorData data() const;
110+
%Docstring
111+
Returns the latest captured data from the sensor.
112+
%End
113+
114+
void setData( const QgsAbstractSensor::SensorData &data );
115+
%Docstring
116+
Sets the latest captured data from the sensor.
117+
%End
118+
119+
bool writeXml( QDomElement &parentElement, QDomDocument &document ) const;
120+
%Docstring
121+
Write generic sensor properties into a DOM element.
122+
123+
:param parentElement: parent DOM element (e.g 'Sensors' element)
124+
:param document: DOM document
125+
%End
126+
127+
bool readXml( const QDomElement &element, const QDomDocument &document );
128+
%Docstring
129+
Restores generic sensor details from a DOM element.
130+
131+
:param element: DOM node corresponding to item (e.g. 'Sensor' element)
132+
:param document: DOM document
133+
%End
134+
135+
virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document ) const;
136+
%Docstring
137+
Write specific sensor type properties into a DOM element.
138+
139+
:param element: DOM node corresponding to item (e.g. 'Sensor' element)
140+
:param document: DOM document
141+
%End
142+
143+
virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document );
144+
%Docstring
145+
Restores specific sensor type properties from a DOM element.
146+
147+
:param element: DOM node corresponding to item (e.g. 'Sensor' element)
148+
:param document: DOM document
149+
%End
150+
151+
signals:
152+
153+
void nameChanged();
154+
%Docstring
155+
Emitted when the sensor name has changed.
156+
%End
157+
158+
void statusChanged();
159+
%Docstring
160+
Emitted when the sensor status has changed.
161+
%End
162+
163+
void dataChanged();
164+
%Docstring
165+
Emitted when the captured sensor data has changed.
166+
%End
167+
168+
protected:
169+
170+
virtual void handleConnect() = 0;
171+
%Docstring
172+
Handles the connection to the sensor.
173+
174+
.. note::
175+
176+
Triggered by calling :py:func:`~QgsAbstractSensor.connectSensor`
177+
%End
178+
179+
virtual void handleDisconnect() = 0;
180+
%Docstring
181+
Handles the disconnection from the sensor.
182+
183+
.. note::
184+
185+
Triggered by calling :py:func:`~QgsAbstractSensor.disconnectSensor`
186+
%End
187+
188+
189+
};
190+
191+
192+
/************************************************************************
193+
* This file has been generated automatically from *
194+
* *
195+
* src/core/sensor/qgsabstractsensor.h *
196+
* *
197+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
198+
************************************************************************/

0 commit comments

Comments
 (0)
Please sign in to comment.