QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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
86 virtual QgsAbstractSensorWidget *createSensorWidget( QgsAbstractSensor *sensor ) SIP_TRANSFERBACK { Q_UNUSED( sensor ) return nullptr; }
87
91 virtual QgsAbstractSensor *createSensor( QObject *parent ) SIP_TRANSFERBACK { Q_UNUSED( parent ) return nullptr; }
92
93 private:
94
95 QString mType;
96 QString mVisibleName;
97
98};
99
102
103#ifndef SIP_RUN
104
111{
112 public:
113
120 QgsSensorGuiMetadata( const QString &type, const QString &visibleName, const QIcon &creationIcon,
121 const QgsSensorWidgetFunc &pfWidget = nullptr,
122 const QgsSensorCreateFunc &pfCreateFunc = nullptr )
123 : QgsSensorAbstractGuiMetadata( type, visibleName )
124 , mIcon( creationIcon )
125 , mWidgetFunc( pfWidget )
126 , mCreateFunc( pfCreateFunc )
127 {}
128
133 QgsSensorWidgetFunc widgetFunction() const { return mWidgetFunc; }
134
139 void setWidgetFunction( const QgsSensorWidgetFunc &function ) { mWidgetFunc = function; }
140
145 QgsSensorCreateFunc sensorCreationFunction() const { return mCreateFunc; }
146
151 void setSensorCreationFunction( const QgsSensorCreateFunc &function ) { mCreateFunc = function; }
152
153 QIcon creationIcon() const override { return mIcon.isNull() ? QgsSensorAbstractGuiMetadata::creationIcon() : mIcon; }
154 QgsAbstractSensorWidget *createSensorWidget( QgsAbstractSensor *sensor ) override { return mWidgetFunc ? mWidgetFunc( sensor ) : nullptr; }
155 QgsAbstractSensor *createSensor( QObject *parent ) override { return mCreateFunc ? mCreateFunc( parent ) : nullptr; }
156
157 protected:
158
159 QIcon mIcon;
160 QgsSensorWidgetFunc mWidgetFunc = nullptr;
161 QgsSensorCreateFunc mCreateFunc = nullptr;
162
163};
164
165#endif
166
180class GUI_EXPORT QgsSensorGuiRegistry : public QObject
181{
182 Q_OBJECT
183
184 public:
185
192 QgsSensorGuiRegistry( QObject *parent = nullptr );
193 ~QgsSensorGuiRegistry() override;
194
197
202 bool populate();
203
208 QgsSensorAbstractGuiMetadata *sensorMetadata( const QString &type ) const;
209
213 bool addSensorGuiMetadata( QgsSensorAbstractGuiMetadata *metadata SIP_TRANSFER );
214
215 /*
216 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
217 * the case.
218 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
219 *
220 * "
221 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
222 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
223 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
224 * by Python so the /Factory/ on create() would be correct.)
225 *
226 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
227 * "
228 */
229
233 QgsAbstractSensor *createSensor( const QString &type, QObject *parent = nullptr ) const SIP_TRANSFERBACK;
234
241 QgsAbstractSensorWidget *createSensorWidget( QgsAbstractSensor *sensor ) const SIP_TRANSFERBACK;
242
246 QMap<QString, QString> sensorTypes() const;
247
248 signals:
249
254 void sensorAdded( const QString &type, const QString &name );
255
256 private:
257
258#ifdef SIP_RUN
260#endif
261
262 QMap<QString, QgsSensorAbstractGuiMetadata *> mMetadata;
263
264};
265
266#endif //QGSSENSORGUIREGISTRY_H
267
268
269
Base class for widgets which allow control over the properties of sensors.
An abstract base class for sensor classes.
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.
Convenience metadata class that uses static functions to handle sensor GUI behavior.
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.
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,...
QIcon creationIcon() const override
Returns an icon representing creation of the sensor type.
Registry of available sensor GUI behavior.
QgsSensorGuiRegistry(const QgsSensorGuiRegistry &rh)=delete
QgsSensorGuiRegistry & operator=(const QgsSensorGuiRegistry &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< QgsAbstractSensorWidget *(QgsAbstractSensor *sensor)> QgsSensorWidgetFunc
Sensor configuration widget creation function.
std::function< QgsAbstractSensor *(QObject *parent)> QgsSensorCreateFunc
Sensor creation function.