QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
22 : QObject( parent )
23 , mId( QUuid::createUuid().toString() )
24{
25}
26
28{
29 return mName;
30}
31
32void QgsAbstractSensor::setName( const QString &name )
33{
34 if ( mName == name )
35 return;
36
37 mName = name;
38 emit nameChanged();
39}
40
45
47{
48 if ( mStatus == status )
49 return;
50
51 mStatus = status;
52 emit statusChanged();
53}
54
59
65
67{
68 return mErrorString;
69}
70
76
82
83bool QgsAbstractSensor::writePropertiesToElement( QDomElement &, QDomDocument & ) const
84{
85 return true;
86}
87
88bool QgsAbstractSensor::readPropertiesFromElement( const QDomElement &, const QDomDocument & )
89{
90 return true;
91}
92
93bool QgsAbstractSensor::writeXml( QDomElement &parentElement, QDomDocument &document ) const
94{
95 QDomElement element = document.createElement( QStringLiteral( "Sensor" ) );
96 element.setAttribute( QStringLiteral( "id" ), id() );
97 element.setAttribute( QStringLiteral( "type" ), type() );
98 element.setAttribute( QStringLiteral( "name" ), name() );
99
100 writePropertiesToElement( element, document );
101 parentElement.appendChild( element );
102
103 return true;
104}
105
106bool QgsAbstractSensor::readXml( const QDomElement &element, const QDomDocument &document )
107{
108 if ( element.nodeName() != QLatin1String( "Sensor" ) )
109 {
110 return false;
111 }
112
113 mId = element.attribute( QStringLiteral( "id" ), QUuid::createUuid().toString() );
114 mName = element.attribute( QStringLiteral( "name" ) );
115 readPropertiesFromElement( element, document );
116
117 return true;
118}
DeviceConnectionStatus
GPS connection status.
Definition qgis.h:1366
@ 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.