QGIS API Documentation 4.1.0-Master (60fea48833c)
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 <QString>
20#include <QUuid>
21
22#include "moc_qgsabstractsensor.cpp"
23
24using namespace Qt::StringLiterals;
25
27 : QObject( parent )
28 , mId( QUuid::createUuid().toString() )
29{}
30
32{
33 return mName;
34}
35
36void QgsAbstractSensor::setName( const QString &name )
37{
38 if ( mName == name )
39 return;
40
41 mName = name;
42 emit nameChanged();
43}
44
49
51{
52 if ( mStatus == status )
53 return;
54
55 mStatus = status;
56 emit statusChanged();
57}
58
63
69
71{
72 return mErrorString;
73}
74
80
86
87bool QgsAbstractSensor::writePropertiesToElement( QDomElement &, QDomDocument & ) const
88{
89 return true;
90}
91
92bool QgsAbstractSensor::readPropertiesFromElement( const QDomElement &, const QDomDocument & )
93{
94 return true;
95}
96
97bool QgsAbstractSensor::writeXml( QDomElement &parentElement, QDomDocument &document ) const
98{
99 QDomElement element = document.createElement( u"Sensor"_s );
100 element.setAttribute( u"id"_s, id() );
101 element.setAttribute( u"type"_s, type() );
102 element.setAttribute( u"name"_s, name() );
103
104 writePropertiesToElement( element, document );
105 parentElement.appendChild( element );
106
107 return true;
108}
109
110bool QgsAbstractSensor::readXml( const QDomElement &element, const QDomDocument &document )
111{
112 if ( element.nodeName() != "Sensor"_L1 )
113 {
114 return false;
115 }
116
117 mId = element.attribute( u"id"_s, QUuid::createUuid().toString() );
118 mName = element.attribute( u"name"_s );
119 readPropertiesFromElement( element, document );
120
121 return true;
122}
DeviceConnectionStatus
GPS connection status.
Definition qgis.h:1953
@ Connecting
Device is connecting.
Definition qgis.h:1955
@ Disconnected
Device is disconnected.
Definition qgis.h:1954
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.