QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgsabstractsensor.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsabstractsensor.cpp
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
17#include "qgsabstractsensor.h"
18
19#include <QUuid>
20
21#include "moc_qgsabstractsensor.cpp"
22
24 : QObject( parent )
25 , mId( QUuid::createUuid().toString() )
26{
27}
28
30{
31 return mName;
32}
33
34void QgsAbstractSensor::setName( const QString &name )
35{
36 if ( mName == name )
37 return;
38
39 mName = name;
40 emit nameChanged();
41}
42
47
49{
50 if ( mStatus == status )
51 return;
52
53 mStatus = status;
54 emit statusChanged();
55}
56
61
67
69{
70 return mErrorString;
71}
72
78
84
85bool QgsAbstractSensor::writePropertiesToElement( QDomElement &, QDomDocument & ) const
86{
87 return true;
88}
89
90bool QgsAbstractSensor::readPropertiesFromElement( const QDomElement &, const QDomDocument & )
91{
92 return true;
93}
94
95bool QgsAbstractSensor::writeXml( QDomElement &parentElement, QDomDocument &document ) const
96{
97 QDomElement element = document.createElement( QStringLiteral( "Sensor" ) );
98 element.setAttribute( QStringLiteral( "id" ), id() );
99 element.setAttribute( QStringLiteral( "type" ), type() );
100 element.setAttribute( QStringLiteral( "name" ), name() );
101
102 writePropertiesToElement( element, document );
103 parentElement.appendChild( element );
104
105 return true;
106}
107
108bool QgsAbstractSensor::readXml( const QDomElement &element, const QDomDocument &document )
109{
110 if ( element.nodeName() != QLatin1String( "Sensor" ) )
111 {
112 return false;
113 }
114
115 mId = element.attribute( QStringLiteral( "id" ), QUuid::createUuid().toString() );
116 mName = element.attribute( QStringLiteral( "name" ) );
117 readPropertiesFromElement( element, document );
118
119 return true;
120}
DeviceConnectionStatus
GPS connection status.
Definition qgis.h:1874
@ Connecting
Device is connecting.
Definition qgis.h:1876
@ Disconnected
Device is disconnected.
Definition qgis.h:1875
QgsAbstractSensor(QObject *parent=nullptr)
Constructor for an abstract sensor, bound to the specified parent.
Qgis::DeviceConnectionStatus status() const
Returns the current sensor status.
void connectSensor()
Connects the sensor to its source.
QgsAbstractSensor::SensorData data() const
Returns the latest captured data from the sensor.
virtual void handleDisconnect()=0
Handles the disconnection from the sensor.
void statusChanged()
Emitted when the sensor status has changed.
void setStatus(Qgis::DeviceConnectionStatus status)
Sets the current sensor status.
void disconnectSensor()
Disconnects the sensor from its source.
QString name() const
Returns the user-friendly name identifying the sensor.
virtual QString type() const
Returns the sensor type.
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document) const
Write specific sensor type properties into a DOM element.
void nameChanged()
Emitted when the sensor name has changed.
bool readXml(const QDomElement &element, const QDomDocument &document)
Restores generic sensor details from a DOM element.
void setData(const QgsAbstractSensor::SensorData &data)
Sets the latest captured data from the sensor.
QgsAbstractSensor::SensorData mData
QString errorString() const
Returns the last error message.
virtual void handleConnect()=0
Handles the connection to the sensor.
virtual bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document)
Restores specific sensor type properties from a DOM element.
void dataChanged()
Emitted when the captured sensor data has changed.
void setName(const QString &name)
Sets the user-friendly name identfying the sensor.
bool writeXml(QDomElement &parentElement, QDomDocument &document) const
Write generic sensor properties into a DOM element.
Contains details of a sensor data capture.