QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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 // clang-format off
73 Q_OBJECT
74
75 public:
76 // clang-format on
77
81 struct CORE_EXPORT SensorData
82 {
87 QVariant lastValue;
88
90 QDateTime lastTimestamp;
91 };
92
96 explicit QgsAbstractSensor( QObject *parent SIP_TRANSFERTHIS = nullptr );
97 ~QgsAbstractSensor() override = default;
98
103 QString id() const { return mId; }
104
108 virtual QString type() const { return QString(); }
109
113 QString name() const;
114
118 void setName( const QString &name );
119
123 Qgis::DeviceConnectionStatus status() const;
124
128 void setStatus( Qgis::DeviceConnectionStatus status );
129
133 void connectSensor();
134
138 void disconnectSensor();
139
144
148 void setData( const QgsAbstractSensor::SensorData &data );
149
153 QString errorString() const;
154
160 bool writeXml( QDomElement &parentElement, QDomDocument &document ) const;
161
167 bool readXml( const QDomElement &element, const QDomDocument &document );
168
174 virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document ) const;
175
181 virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document );
182
183 signals:
184
187
190
193
195 void errorOccurred( const QString &errorString );
196
197 protected:
202 virtual void handleConnect() = 0;
203
208 virtual void handleDisconnect() = 0;
209
212
213 private:
214 QString mId;
215 QString mName;
217};
218
220
221#endif //QGSABSTRACTSENSOR_H
DeviceConnectionStatus
GPS connection status.
Definition qgis.h:1953
@ Disconnected
Device is disconnected.
Definition qgis.h:1954
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:198
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_END
Definition qgis_sip.h:215
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.