QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
qgsabstractsensor.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsabstractsensor.h
3 ---------------------------
4 begin : March 2023
5 copyright : (C) 2023 by Mathieu Pellerin
6 email : mathieu at opengis dot ch
7 ***************************************************************************/
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#ifndef QGSABSTRACTSENSOR_H
17#define QGSABSTRACTSENSOR_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgis.h"
22
23#include <QDateTime>
24#include <QDomElement>
25#include <QVariant>
26
33class CORE_EXPORT QgsAbstractSensor : public QObject
34{
35#ifdef SIP_RUN
36#include "qgsiodevicesensor.h"
37#include "qgssensorregistry.h"
38#endif
39
40
41#ifdef SIP_RUN
43 if ( QgsAbstractSensor *item = qobject_cast< QgsAbstractSensor * >( sipCpp ) )
44 {
45 if ( item->type() == QLatin1String( "tcp_socket" ) && dynamic_cast<QgsTcpSocketSensor *>( item ) != NULL )
46 {
47 sipType = sipType_QgsTcpSocketSensor;
48 }
49 else if ( item->type() == QLatin1String( "udp_socket" ) && dynamic_cast<QgsUdpSocketSensor *>( item ) != NULL )
50 {
51 sipType = sipType_QgsUdpSocketSensor;
52 }
53 else if ( item->type() == QLatin1String( "serial_port" ) && dynamic_cast<QgsSerialPortSensor *>( item ) != NULL )
54 {
55 sipType = sipType_QgsSerialPortSensor;
56 }
57 else
58 {
59 sipType = sipType_QgsAbstractSensor;
60 }
61 }
62 else
63 {
64 sipType = NULL;
65 }
67#endif
68
69 Q_OBJECT
70
71 public:
72
76 struct CORE_EXPORT SensorData
77 {
78
83 QVariant lastValue;
84
86 QDateTime lastTimestamp;
87 };
88
92 explicit QgsAbstractSensor( QObject *parent SIP_TRANSFERTHIS = nullptr );
93 virtual ~QgsAbstractSensor() = default;
94
99 QString id() const { return mId; }
100
104 virtual QString type() const { return QString(); }
105
109 QString name() const;
110
114 void setName( const QString &name );
115
119 Qgis::DeviceConnectionStatus status() const;
120
124 void setStatus( Qgis::DeviceConnectionStatus status );
125
129 void connectSensor();
130
134 void disconnectSensor();
135
140
144 void setData( const QgsAbstractSensor::SensorData &data );
145
149 QString errorString() const;
150
156 bool writeXml( QDomElement &parentElement, QDomDocument &document ) const;
157
163 bool readXml( const QDomElement &element, const QDomDocument &document );
164
170 virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document ) const;
171
177 virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document );
178
179 signals:
180
183
186
189
191 void errorOccurred( const QString &errorString );
192
193 protected:
194
199 virtual void handleConnect() = 0;
200
205 virtual void handleDisconnect() = 0;
206
209
210 private:
211
212 QString mId;
213 QString mName;
215
216};
217
219
220#endif //QGSABSTRACTSENSOR_H
DeviceConnectionStatus
GPS connection status.
Definition: qgis.h:1270
@ Disconnected
Device is disconnected.
An abstract base class for sensor classes.
QString id() const
Returns the sensor ID.
virtual void handleDisconnect()=0
Handles the disconnection from the sensor.
void statusChanged()
Emitted when the sensor status has changed.
virtual QString type() const
Returns the sensor type.
void errorOccurred(const QString &errorString)
Emitted when an error has occurred. The errorString describes the error.
void nameChanged()
Emitted when the sensor name has changed.
QgsAbstractSensor::SensorData mData
virtual void handleConnect()=0
Handles the connection to the sensor.
void dataChanged()
Emitted when the captured sensor data has changed.
virtual ~QgsAbstractSensor()=default
A TCP socket sensor class.
A UDP socket sensor class.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_END
Definition: qgis_sip.h:203
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
Contains details of a sensor data capture.
QVariant lastValue
Last captured sensor value stored as a QVariant.
QDateTime lastTimestamp
Timestamp of last captured sensor value.