QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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_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#if defined( HAVE_QTSERIALPORT )
54 else if ( item->type() == QLatin1String( "serial_port" ) && dynamic_cast<QgsSerialPortSensor *>( item ) != NULL )
55 {
56 sipType = sipType_QgsSerialPortSensor;
57 }
58#endif
59 else
60 {
61 sipType = sipType_QgsAbstractSensor;
62 }
63 }
64 else
65 {
66 sipType = NULL;
67 }
69#endif
70
71 Q_OBJECT
72
73 public:
74
78 struct CORE_EXPORT SensorData
79 {
80
85 QVariant lastValue;
86
88 QDateTime lastTimestamp;
89 };
90
94 explicit QgsAbstractSensor( QObject *parent SIP_TRANSFERTHIS = nullptr );
95 virtual ~QgsAbstractSensor() = default;
96
101 QString id() const { return mId; }
102
106 virtual QString type() const { return QString(); }
107
111 QString name() const;
112
116 void setName( const QString &name );
117
121 Qgis::DeviceConnectionStatus status() const;
122
126 void setStatus( Qgis::DeviceConnectionStatus status );
127
131 void connectSensor();
132
136 void disconnectSensor();
137
142
146 void setData( const QgsAbstractSensor::SensorData &data );
147
151 QString errorString() const;
152
158 bool writeXml( QDomElement &parentElement, QDomDocument &document ) const;
159
165 bool readXml( const QDomElement &element, const QDomDocument &document );
166
172 virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document ) const;
173
179 virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document );
180
181 signals:
182
185
188
191
193 void errorOccurred( const QString &errorString );
194
195 protected:
196
201 virtual void handleConnect() = 0;
202
207 virtual void handleDisconnect() = 0;
208
211
212 private:
213
214 QString mId;
215 QString mName;
217
218};
219
221
222#endif //QGSABSTRACTSENSOR_H
DeviceConnectionStatus
GPS connection status.
Definition qgis.h:1721
@ 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:191
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_END
Definition qgis_sip.h:208
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.