QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgssensorguiregistry.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssensorguiregistry.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 QGSSENSORGUIREGISTRY_H
17#define QGSSENSORGUIREGISTRY_H
18
19#include "qgis_gui.h"
20#include "qgis_sip.h"
21#include "qgsabstractsensor.h"
22#include "qgssensorregistry.h"
23#include "qgssensorwidget.h"
24
25#include <QIcon>
26
38{
39 public:
40
46 QgsSensorAbstractGuiMetadata( const QString &type, const QString &visibleName )
47 : mType( type )
48 , mVisibleName( visibleName )
49 {}
50
51 virtual ~QgsSensorAbstractGuiMetadata() = default;
52
56 QString type() const { return mType; }
57
61 QString visibleName() const { return mVisibleName; }
62
66 virtual QIcon creationIcon() const { return QgsApplication::getThemeIcon( QStringLiteral( "/mSensor.svg" ) ); }
67
68 /*
69 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
70 * the case.
71 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
72 *
73 * "
74 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
75 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
76 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
77 * by Python so the /Factory/ on create() would be correct.)
78 *
79 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
80 * "
81 */
82
87 {
88 Q_UNUSED( sensor )
89 return nullptr;
90 }
91
96 {
97 Q_UNUSED( parent )
98 return nullptr;
99 }
100
101 private:
102 QString mType;
103 QString mVisibleName;
104};
105
108
109#ifndef SIP_RUN
110
117{
118 public:
119
126 QgsSensorGuiMetadata( const QString &type, const QString &visibleName, const QIcon &creationIcon, const QgsSensorWidgetFunc &pfWidget = nullptr, const QgsSensorCreateFunc &pfCreateFunc = nullptr )
129 , mWidgetFunc( pfWidget )
130 , mCreateFunc( pfCreateFunc )
131 {}
132
138
143 void setWidgetFunction( const QgsSensorWidgetFunc &function ) { mWidgetFunc = function; }
144
150
155 void setSensorCreationFunction( const QgsSensorCreateFunc &function ) { mCreateFunc = function; }
156
157 QIcon creationIcon() const override { return mIcon.isNull() ? QgsSensorAbstractGuiMetadata::creationIcon() : mIcon; }
158 QgsAbstractSensorWidget *createSensorWidget( QgsAbstractSensor *sensor ) override { return mWidgetFunc ? mWidgetFunc( sensor ) : nullptr; }
159 QgsAbstractSensor *createSensor( QObject *parent ) override { return mCreateFunc ? mCreateFunc( parent ) : nullptr; }
160
161 protected:
162 QIcon mIcon;
165};
166
167#endif
168
182class GUI_EXPORT QgsSensorGuiRegistry : public QObject
183{
184 Q_OBJECT
185
186 public:
187
194 QgsSensorGuiRegistry( QObject *parent = nullptr );
195 ~QgsSensorGuiRegistry() override;
196
199
204 bool populate();
205
210 QgsSensorAbstractGuiMetadata *sensorMetadata( const QString &type ) const;
211
216
217 /*
218 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
219 * the case.
220 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
221 *
222 * "
223 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
224 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
225 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
226 * by Python so the /Factory/ on create() would be correct.)
227 *
228 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
229 * "
230 */
231
235 QgsAbstractSensor *createSensor( const QString &type, QObject *parent = nullptr ) const SIP_TRANSFERBACK;
236
244
248 QMap<QString, QString> sensorTypes() const;
249
250 signals:
251
256 void sensorAdded( const QString &type, const QString &name );
257
258 private:
259#ifdef SIP_RUN
261#endif
262
263 QMap<QString, QgsSensorAbstractGuiMetadata *> mMetadata;
264};
265
266#endif //QGSSENSORGUIREGISTRY_H
Base class for widgets which allow control over the properties of sensors.
An abstract base class for sensors.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Stores GUI metadata about one sensor class.
virtual QgsAbstractSensorWidget * createSensorWidget(QgsAbstractSensor *sensor)
Creates a configuration widget for an sensor of this type.
virtual QIcon creationIcon() const
Returns an icon representing creation of the sensor type.
QString type() const
Returns the unique type code for the sensor class.
virtual QgsAbstractSensor * createSensor(QObject *parent)
Creates an instance of the corresponding sensor type.
QgsSensorAbstractGuiMetadata(const QString &type, const QString &visibleName)
Constructor for QgsSensorAbstractGuiMetadata with the specified class type.
virtual ~QgsSensorAbstractGuiMetadata()=default
QString visibleName() const
Returns a translated, user visible name identifying the corresponding sensor.
QgsAbstractSensor * createSensor(QObject *parent) override
Creates an instance of the corresponding sensor type.
QgsSensorWidgetFunc widgetFunction() const
Returns the classes' configuration widget creation function.
QgsSensorCreateFunc sensorCreationFunction() const
Returns the classes' sensor creation function.
void setSensorCreationFunction(const QgsSensorCreateFunc &function)
Sets the classes' sensor creation function.
QgsAbstractSensorWidget * createSensorWidget(QgsAbstractSensor *sensor) override
Creates a configuration widget for an sensor of this type.
void setWidgetFunction(const QgsSensorWidgetFunc &function)
Sets the classes' sensor configuration widget creation function.
QgsSensorWidgetFunc mWidgetFunc
QgsSensorGuiMetadata(const QString &type, const QString &visibleName, const QIcon &creationIcon, const QgsSensorWidgetFunc &pfWidget=nullptr, const QgsSensorCreateFunc &pfCreateFunc=nullptr)
Constructor for QgsSensorGuiMetadata with the specified class type and creationIcon,...
QgsSensorCreateFunc mCreateFunc
QIcon creationIcon() const override
Returns an icon representing creation of the sensor type.
QgsSensorGuiRegistry(QObject *parent=nullptr)
Creates a new empty sensor GUI registry.
QgsSensorGuiRegistry(const QgsSensorGuiRegistry &rh)=delete
QgsSensorAbstractGuiMetadata * 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.
bool populate()
Populates the registry with standard sensor types.
void sensorAdded(const QString &type, const QString &name)
Emitted whenever a new sensor type is added to the registry, with the specified type.
QMap< QString, QString > sensorTypes() const
Returns a list of sensor types handled by the registry.
QgsAbstractSensorWidget * createSensorWidget(QgsAbstractSensor *sensor) const
Creates a new instance of a sensor configuration widget for the specified sensor.
QgsSensorGuiRegistry & operator=(const QgsSensorGuiRegistry &rh)=delete
bool addSensorGuiMetadata(QgsSensorAbstractGuiMetadata *metadata)
Registers the GUI metadata for a new sensor type.
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_TRANSFERBACK
Definition qgis_sip.h:48
std::function< QgsAbstractSensorWidget *(QgsAbstractSensor *sensor)> QgsSensorWidgetFunc
Sensor configuration widget creation function.
std::function< QgsAbstractSensor *(QObject *parent)> QgsSensorCreateFunc
Sensor creation function.