QGIS API Documentation 3.41.0-Master (3440c17df1d)
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#include "moc_qgsabstractsensor.cpp"
19
20#include <QUuid>
21
23 : QObject( parent )
24 , mId( QUuid::createUuid().toString() )
25{
26}
27
29{
30 return mName;
31}
32
33void QgsAbstractSensor::setName( const QString &name )
34{
35 if ( mName == name )
36 return;
37
38 mName = name;
39 emit nameChanged();
40}
41
46
48{
49 if ( mStatus == status )
50 return;
51
52 mStatus = status;
53 emit statusChanged();
54}
55
60
66
68{
69 return mErrorString;
70}
71
77
83
84bool QgsAbstractSensor::writePropertiesToElement( QDomElement &, QDomDocument & ) const
85{
86 return true;
87}
88
89bool QgsAbstractSensor::readPropertiesFromElement( const QDomElement &, const QDomDocument & )
90{
91 return true;
92}
93
94bool QgsAbstractSensor::writeXml( QDomElement &parentElement, QDomDocument &document ) const
95{
96 QDomElement element = document.createElement( QStringLiteral( "Sensor" ) );
97 element.setAttribute( QStringLiteral( "id" ), id() );
98 element.setAttribute( QStringLiteral( "type" ), type() );
99 element.setAttribute( QStringLiteral( "name" ), name() );
100
101 writePropertiesToElement( element, document );
102 parentElement.appendChild( element );
103
104 return true;
105}
106
107bool QgsAbstractSensor::readXml( const QDomElement &element, const QDomDocument &document )
108{
109 if ( element.nodeName() != QLatin1String( "Sensor" ) )
110 {
111 return false;
112 }
113
114 mId = element.attribute( QStringLiteral( "id" ), QUuid::createUuid().toString() );
115 mName = element.attribute( QStringLiteral( "name" ) );
116 readPropertiesFromElement( element, document );
117
118 return true;
119}
DeviceConnectionStatus
GPS connection status.
Definition qgis.h:1721
@ Connecting
Device is connecting.
@ Disconnected
Device is disconnected.
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.