QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgssensorregistry.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssensorregistry.h
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#ifndef QGSSENSORREGISTRY_H
17#define QGSSENSORREGISTRY_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgsapplication.h"
22#include "qgsabstractsensor.h"
23
32{
33 public:
34
38 QgsSensorAbstractMetadata( const QString &type, const QString &visibleName )
39 : mType( type )
40 , mVisibleName( visibleName )
41 {}
42
43 virtual ~QgsSensorAbstractMetadata() = default;
44
48 QString type() const { return mType; }
49
53 QString visibleName() const { return mVisibleName; }
54
55 /*
56 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
57 * the case.
58 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
59 *
60 * "
61 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
62 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
63 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
64 * by Python so the /Factory/ on create() would be correct.)
65 *
66 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
67 * "
68 */
69
73 virtual QgsAbstractSensor *createSensor( QObject *parent ) = 0 SIP_TRANSFERBACK;
74
75 private:
76
77 QString mType;
78 QString mVisibleName;
79};
80
82typedef std::function<QgsAbstractSensor *( QObject *parent )> QgsSensorCreateFunc SIP_SKIP;
83
84#ifndef SIP_RUN
85
93{
94 public:
95
99 QgsSensorMetadata( const QString &type, const QString &visibleName,
100 const QgsSensorCreateFunc &pfCreate )
101 : QgsSensorAbstractMetadata( type, visibleName )
102 , mCreateFunc( pfCreate )
103 {}
104
108 QgsSensorCreateFunc createFunction() const { return mCreateFunc; }
109
110 QgsAbstractSensor *createSensor( QObject *parent ) override { return mCreateFunc ? mCreateFunc( parent ) : nullptr; }
111
112 protected:
113 QgsSensorCreateFunc mCreateFunc = nullptr;
114
115};
116
117#endif
118
132class CORE_EXPORT QgsSensorRegistry : public QObject
133{
134 Q_OBJECT
135
136 public:
137
146 QgsSensorRegistry( QObject *parent = nullptr );
147 ~QgsSensorRegistry() override;
148
153 bool populate();
154
159
164 QgsSensorAbstractMetadata *sensorMetadata( const QString &type ) const;
165
166 /*
167 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
168 * the case.
169 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
170 *
171 * "
172 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
173 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
174 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
175 * by Python so the /Factory/ on create() would be correct.)
176 *
177 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
178 * "
179 */
180
185 bool addSensorType( QgsSensorAbstractMetadata *metadata SIP_TRANSFER );
186
190 bool removeSensorType( const QString &type );
191
195 QgsAbstractSensor *createSensor( const QString &type, QObject *parent = nullptr ) const SIP_TRANSFERBACK;
196
200 QMap<QString, QString> sensorTypes() const;
201
202 signals:
203
208 void sensorAdded( const QString &type, const QString &name );
209
210 private:
211
212#ifdef SIP_RUN
214#endif
215
216 QMap<QString, QgsSensorAbstractMetadata *> mMetadata;
217
218};
219
220#endif //QGSSENSORREGISTRY_H
221
222
223
An abstract base class for sensor classes.
Stores metadata about a sensor class.
QString visibleName() const
Returns a translated, user visible name for the sensor class.
QString type() const
Returns the unique type code for the sensor class.
virtual QgsAbstractSensor * createSensor(QObject *parent)=0
Creates a sensor of this class.
QgsSensorAbstractMetadata(const QString &type, const QString &visibleName)
Constructor for QgsSensorAbstractMetadata with the specified class type.
virtual ~QgsSensorAbstractMetadata()=default
Convenience metadata class that uses static functions to create sensors and their configuration widge...
QgsAbstractSensor * createSensor(QObject *parent) override
Creates a sensor of this class.
QgsSensorCreateFunc createFunction() const
Returns the classes' sensor creation function.
QgsSensorMetadata(const QString &type, const QString &visibleName, const QgsSensorCreateFunc &pfCreate)
Constructor for QgsSensorMetadata with the specified class type.
Registry of available sensor types.
QgsSensorRegistry & operator=(const QgsSensorRegistry &rh)=delete
QgsSensorRegistry cannot be copied.
QgsSensorRegistry(const QgsSensorRegistry &rh)=delete
QgsSensorRegistry cannot be copied.
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_TRANSFERBACK
Definition qgis_sip.h:48
std::function< QgsAbstractSensor *(QObject *parent)> QgsSensorCreateFunc
Sensor creation function.