QGIS API Documentation 3.99.0-Master (d270888f95f)
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}
31
33{
34 return mName;
35}
36
37void QgsAbstractSensor::setName( const QString &name )
38{
39 if ( mName == name )
40 return;
41
42 mName = name;
43 emit nameChanged();
44}
45
50
52{
53 if ( mStatus == status )
54 return;
55
56 mStatus = status;
57 emit statusChanged();
58}
59
64
70
72{
73 return mErrorString;
74}
75
81
87
88bool QgsAbstractSensor::writePropertiesToElement( QDomElement &, QDomDocument & ) const
89{
90 return true;
91}
92
93bool QgsAbstractSensor::readPropertiesFromElement( const QDomElement &, const QDomDocument & )
94{
95 return true;
96}
97
98bool QgsAbstractSensor::writeXml( QDomElement &parentElement, QDomDocument &document ) const
99{
100 QDomElement element = document.createElement( u"Sensor"_s );
101 element.setAttribute( u"id"_s, id() );
102 element.setAttribute( u"type"_s, type() );
103 element.setAttribute( u"name"_s, name() );
104
105 writePropertiesToElement( element, document );
106 parentElement.appendChild( element );
107
108 return true;
109}
110
111bool QgsAbstractSensor::readXml( const QDomElement &element, const QDomDocument &document )
112{
113 if ( element.nodeName() != "Sensor"_L1 )
114 {
115 return false;
116 }
117
118 mId = element.attribute( u"id"_s, QUuid::createUuid().toString() );
119 mName = element.attribute( u"name"_s );
120 readPropertiesFromElement( element, document );
121
122 return true;
123}
DeviceConnectionStatus
GPS connection status.
Definition qgis.h:1932
@ Connecting
Device is connecting.
Definition qgis.h:1934
@ Disconnected
Device is disconnected.
Definition qgis.h:1933
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.