QGIS API Documentation 3.39.0-Master (be2050b798e)
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
92{
93 public:
94
98 QgsSensorMetadata( const QString &type, const QString &visibleName,
99 const QgsSensorCreateFunc &pfCreate )
100 : QgsSensorAbstractMetadata( type, visibleName )
101 , mCreateFunc( pfCreate )
102 {}
103
107 QgsSensorCreateFunc createFunction() const { return mCreateFunc; }
108
109 QgsAbstractSensor *createSensor( QObject *parent ) override { return mCreateFunc ? mCreateFunc( parent ) : nullptr; }
110
111 protected:
112 QgsSensorCreateFunc mCreateFunc = nullptr;
113
114};
115
116#endif
117
131class CORE_EXPORT QgsSensorRegistry : public QObject
132{
133 Q_OBJECT
134
135 public:
136
145 QgsSensorRegistry( QObject *parent = nullptr );
146 ~QgsSensorRegistry() override;
147
152 bool populate();
153
158
163 QgsSensorAbstractMetadata *sensorMetadata( const QString &type ) const;
164
165 /*
166 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
167 * the case.
168 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
169 *
170 * "
171 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
172 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
173 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
174 * by Python so the /Factory/ on create() would be correct.)
175 *
176 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
177 * "
178 */
179
184 bool addSensorType( QgsSensorAbstractMetadata *metadata SIP_TRANSFER );
185
189 bool removeSensorType( const QString &type );
190
194 QgsAbstractSensor *createSensor( const QString &type, QObject *parent = nullptr ) const SIP_TRANSFERBACK;
195
199 QMap<QString, QString> sensorTypes() const;
200
201 signals:
202
207 void sensorAdded( const QString &type, const QString &name );
208
209 private:
210
211#ifdef SIP_RUN
213#endif
214
215 QMap<QString, QgsSensorAbstractMetadata *> mMetadata;
216
217};
218
219#endif //QGSSENSORREGISTRY_H
220
221
222
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.