QGIS API Documentation 3.41.0-Master (3440c17df1d)
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
156
161 QgsSensorAbstractMetadata *sensorMetadata( const QString &type ) const;
162
163 /*
164 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
165 * the case.
166 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
167 *
168 * "
169 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
170 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
171 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
172 * by Python so the /Factory/ on create() would be correct.)
173 *
174 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
175 * "
176 */
177
182 bool addSensorType( QgsSensorAbstractMetadata *metadata SIP_TRANSFER );
183
187 bool removeSensorType( const QString &type );
188
192 QgsAbstractSensor *createSensor( const QString &type, QObject *parent = nullptr ) const SIP_TRANSFERBACK;
193
197 QMap<QString, QString> sensorTypes() const;
198
199 signals:
200
205 void sensorAdded( const QString &type, const QString &name );
206
207 private:
208
209#ifdef SIP_RUN
211#endif
212
213 QMap<QString, QgsSensorAbstractMetadata *> mMetadata;
214
215};
216
217#endif //QGSSENSORREGISTRY_H
218
219
220
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(const QgsSensorRegistry &rh)=delete
#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.