QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
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.h"
20#include "qgis_core.h"
21#include "qgis_sip.h"
22
23#include <QDateTime>
24#include <QDomElement>
25#include <QString>
26#include <QVariant>
27
28using namespace Qt::StringLiterals;
29
36class CORE_EXPORT QgsAbstractSensor : public QObject
37{
38 //SIP_TYPEHEADER_INCLUDE( "qgsiodevicesensor.h" );
39 //SIP_TYPEHEADER_INCLUDE( "qgssensorregistry.h" );
40
41
42#ifdef SIP_RUN
44 if ( QgsAbstractSensor *item = qobject_cast< QgsAbstractSensor * >( sipCpp ) )
45 {
46 if ( item->type() == "tcp_socket"_L1 && dynamic_cast<QgsTcpSocketSensor *>( item ) != NULL )
47 {
48 sipType = sipType_QgsTcpSocketSensor;
49 }
50 else if ( item->type() == "udp_socket"_L1 && dynamic_cast<QgsUdpSocketSensor *>( item ) != NULL )
51 {
52 sipType = sipType_QgsUdpSocketSensor;
53 }
54#if defined( HAVE_QTSERIALPORT )
55 else if ( item->type() == "serial_port"_L1 && dynamic_cast<QgsSerialPortSensor *>( item ) != NULL )
56 {
57 sipType = sipType_QgsSerialPortSensor;
58 }
59#endif
60 else
61 {
62 sipType = sipType_QgsAbstractSensor;
63 }
64 }
65 else
66 {
67 sipType = NULL;
68 }
70#endif
71
72 Q_OBJECT
73
74 public:
75
79 struct CORE_EXPORT SensorData
80 {
81
86 QVariant lastValue;
87
89 QDateTime lastTimestamp;
90 };
91
95 explicit QgsAbstractSensor( QObject *parent SIP_TRANSFERTHIS = nullptr );
96 ~QgsAbstractSensor() override = default;
97
102 QString id() const { return mId; }
103
107 virtual QString type() const { return QString(); }
108
112 QString name() const;
113
117 void setName( const QString &name );
118
122 Qgis::DeviceConnectionStatus status() const;
123
127 void setStatus( Qgis::DeviceConnectionStatus status );
128
132 void connectSensor();
133
137 void disconnectSensor();
138
143
147 void setData( const QgsAbstractSensor::SensorData &data );
148
152 QString errorString() const;
153
159 bool writeXml( QDomElement &parentElement, QDomDocument &document ) const;
160
166 bool readXml( const QDomElement &element, const QDomDocument &document );
167
173 virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document ) const;
174
180 virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document );
181
182 signals:
183
186
189
192
194 void errorOccurred( const QString &errorString );
195
196 protected:
197
202 virtual void handleConnect() = 0;
203
208 virtual void handleDisconnect() = 0;
209
212
213 private:
214
215 QString mId;
216 QString mName;
218
219};
220
222
223#endif //QGSABSTRACTSENSOR_H
DeviceConnectionStatus
GPS connection status.
Definition qgis.h:1932
@ Disconnected
Device is disconnected.
Definition qgis.h:1933
An abstract base class for sensors.
QString id() const
Returns the sensor ID.
QgsAbstractSensor(QObject *parent=nullptr)
Constructor for an abstract sensor, bound to the specified parent.
~QgsAbstractSensor() override=default
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
QString errorString() const
Returns the last error message.
virtual void handleConnect()=0
Handles the connection to the sensor.
void dataChanged()
Emitted when the captured sensor data has changed.
A TCP socket sensor class.
A UDP socket sensor class.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_END
Definition qgis_sip.h:216
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.