QGIS API Documentation 4.1.0-Master (60fea48833c)
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 "qgsabstractsensor.h"
22#include "qgsapplication.h"
23
32{
33 public:
37 QgsSensorAbstractMetadata( const QString &type, const QString &visibleName )
38 : mType( type )
39 , mVisibleName( visibleName )
40 {}
41
42 virtual ~QgsSensorAbstractMetadata() = default;
43
47 QString type() const { return mType; }
48
52 QString visibleName() const { return mVisibleName; }
53
54 /*
55 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
56 * the case.
57 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
58 *
59 * "
60 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
61 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
62 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
63 * by Python so the /Factory/ on create() would be correct.)
64 *
65 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
66 * "
67 */
68
72 virtual QgsAbstractSensor *createSensor( QObject *parent ) = 0 SIP_TRANSFERBACK;
73
74 private:
75 QString mType;
76 QString mVisibleName;
77};
78
80typedef std::function<QgsAbstractSensor *( QObject *parent )> QgsSensorCreateFunc SIP_SKIP;
81
82#ifndef SIP_RUN
83
90{
91 public:
95 QgsSensorMetadata( const QString &type, const QString &visibleName, const QgsSensorCreateFunc &pfCreate )
97 , mCreateFunc( pfCreate )
98 {}
99
104
105 QgsAbstractSensor *createSensor( QObject *parent ) override { return mCreateFunc ? mCreateFunc( parent ) : nullptr; }
106
107 protected:
109};
110
111#endif
112
126class CORE_EXPORT QgsSensorRegistry : public QObject
127{
128 Q_OBJECT
129
130 public:
139 QgsSensorRegistry( QObject *parent = nullptr );
140 ~QgsSensorRegistry() override;
141
146 bool populate();
147
150
155 QgsSensorAbstractMetadata *sensorMetadata( const QString &type ) const;
156
157 /*
158 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
159 * the case.
160 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
161 *
162 * "
163 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
164 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
165 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
166 * by Python so the /Factory/ on create() would be correct.)
167 *
168 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
169 * "
170 */
171
177
181 bool removeSensorType( const QString &type );
182
186 QgsAbstractSensor *createSensor( const QString &type, QObject *parent = nullptr ) const SIP_TRANSFERBACK;
187
191 QMap<QString, QString> sensorTypes() const;
192
193 signals:
194
199 void sensorAdded( const QString &type, const QString &name );
200
201 private:
202#ifdef SIP_RUN
204#endif
205
206 QMap<QString, QgsSensorAbstractMetadata *> mMetadata;
207};
208
209#endif //QGSSENSORREGISTRY_H
An abstract base class for sensors.
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
QgsAbstractSensor * createSensor(QObject *parent) override
Creates a sensor of this class.
QgsSensorCreateFunc createFunction() const
Returns the classes' sensor creation function.
QgsSensorCreateFunc mCreateFunc
QgsSensorMetadata(const QString &type, const QString &visibleName, const QgsSensorCreateFunc &pfCreate)
Constructor for QgsSensorMetadata with the specified class type.
QgsSensorRegistry & operator=(const QgsSensorRegistry &rh)=delete
QgsSensorRegistry(const QgsSensorRegistry &rh)=delete
bool addSensorType(QgsSensorAbstractMetadata *metadata)
Registers a new sensor type.
bool populate()
Populates the registry with standard sensor types.
QgsSensorRegistry(QObject *parent=nullptr)
Creates a new empty item registry.
void sensorAdded(const QString &type, const QString &name)
Emitted whenever a new sensor type is added to the registry, with the specified type and visible name...
bool removeSensorType(const QString &type)
Removes a new a sensor type from the registry.
QgsSensorAbstractMetadata * sensorMetadata(const QString &type) const
Returns the metadata for the specified sensor type.
QgsAbstractSensor * createSensor(const QString &type, QObject *parent=nullptr) const
Creates a new instance of a sensor given the type.
QMap< QString, QString > sensorTypes() const
Returns a map of available sensor types to translated name.
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_TRANSFERBACK
Definition qgis_sip.h:47
std::function< QgsAbstractSensor *(QObject *parent)> QgsSensorCreateFunc
Sensor creation function.