QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
112{
113 public:
114
121 QgsSensorGuiMetadata( const QString &type, const QString &visibleName, const QIcon &creationIcon,
122 const QgsSensorWidgetFunc &pfWidget = nullptr,
123 const QgsSensorCreateFunc &pfCreateFunc = nullptr )
124 : QgsSensorAbstractGuiMetadata( type, visibleName )
125 , mIcon( creationIcon )
126 , mWidgetFunc( pfWidget )
127 , mCreateFunc( pfCreateFunc )
128 {}
129
134 QgsSensorWidgetFunc widgetFunction() const { return mWidgetFunc; }
135
140 void setWidgetFunction( const QgsSensorWidgetFunc &function ) { mWidgetFunc = function; }
141
146 QgsSensorCreateFunc sensorCreationFunction() const { return mCreateFunc; }
147
152 void setSensorCreationFunction( const QgsSensorCreateFunc &function ) { mCreateFunc = function; }
153
154 QIcon creationIcon() const override { return mIcon.isNull() ? QgsSensorAbstractGuiMetadata::creationIcon() : mIcon; }
155 QgsAbstractSensorWidget *createSensorWidget( QgsAbstractSensor *sensor ) override { return mWidgetFunc ? mWidgetFunc( sensor ) : nullptr; }
156 QgsAbstractSensor *createSensor( QObject *parent ) override { return mCreateFunc ? mCreateFunc( parent ) : nullptr; }
157
158 protected:
159
160 QIcon mIcon;
161 QgsSensorWidgetFunc mWidgetFunc = nullptr;
162 QgsSensorCreateFunc mCreateFunc = nullptr;
163
164};
165
166#endif
167
181class GUI_EXPORT QgsSensorGuiRegistry : public QObject
182{
183 Q_OBJECT
184
185 public:
186
193 QgsSensorGuiRegistry( QObject *parent = nullptr );
194 ~QgsSensorGuiRegistry() override;
195
200
205 bool populate();
206
211 QgsSensorAbstractGuiMetadata *sensorMetadata( const QString &type ) const;
212
216 bool addSensorGuiMetadata( QgsSensorAbstractGuiMetadata *metadata SIP_TRANSFER );
217
218 /*
219 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
220 * the case.
221 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
222 *
223 * "
224 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
225 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
226 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
227 * by Python so the /Factory/ on create() would be correct.)
228 *
229 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
230 * "
231 */
232
236 QgsAbstractSensor *createSensor( const QString &type, QObject *parent = nullptr ) const SIP_TRANSFERBACK;
237
244 QgsAbstractSensorWidget *createSensorWidget( QgsAbstractSensor *sensor ) const SIP_TRANSFERBACK;
245
249 QMap<QString, QString> sensorTypes() const;
250
251 signals:
252
257 void sensorAdded( const QString &type, const QString &name );
258
259 private:
260
261#ifdef SIP_RUN
263#endif
264
265 QMap<QString, QgsSensorAbstractGuiMetadata *> mMetadata;
266
267};
268
269#endif //QGSSENSORGUIREGISTRY_H
270
271
272
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 cannot be copied.
QgsSensorGuiRegistry & operator=(const QgsSensorGuiRegistry &rh)=delete
QgsSensorGuiRegistry 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< QgsAbstractSensorWidget *(QgsAbstractSensor *sensor)> QgsSensorWidgetFunc
Sensor configuration widget creation function.
std::function< QgsAbstractSensor *(QObject *parent)> QgsSensorCreateFunc
Sensor creation function.