QGIS API Documentation 3.41.0-Master (af5edcb665c)
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:
45 QgsSensorAbstractGuiMetadata( const QString &type, const QString &visibleName )
46 : mType( type )
47 , mVisibleName( visibleName )
48 {}
49
50 virtual ~QgsSensorAbstractGuiMetadata() = default;
51
55 QString type() const { return mType; }
56
60 QString visibleName() const { return mVisibleName; }
61
65 virtual QIcon creationIcon() const { return QgsApplication::getThemeIcon( QStringLiteral( "/mSensor.svg" ) ); }
66
67 /*
68 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
69 * the case.
70 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
71 *
72 * "
73 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
74 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
75 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
76 * by Python so the /Factory/ on create() would be correct.)
77 *
78 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
79 * "
80 */
81
86 {
87 Q_UNUSED( sensor )
88 return nullptr;
89 }
90
95 {
96 Q_UNUSED( parent )
97 return nullptr;
98 }
99
100 private:
101 QString mType;
102 QString mVisibleName;
103};
104
107
108#ifndef SIP_RUN
109
116{
117 public:
124 QgsSensorGuiMetadata( const QString &type, const QString &visibleName, const QIcon &creationIcon, const QgsSensorWidgetFunc &pfWidget = nullptr, const QgsSensorCreateFunc &pfCreateFunc = nullptr )
125 : QgsSensorAbstractGuiMetadata( type, visibleName )
126 , mIcon( creationIcon )
127 , mWidgetFunc( pfWidget )
128 , mCreateFunc( pfCreateFunc )
129 {}
130
135 QgsSensorWidgetFunc widgetFunction() const { return mWidgetFunc; }
136
141 void setWidgetFunction( const QgsSensorWidgetFunc &function ) { mWidgetFunc = function; }
142
147 QgsSensorCreateFunc sensorCreationFunction() const { return mCreateFunc; }
148
153 void setSensorCreationFunction( const QgsSensorCreateFunc &function ) { mCreateFunc = function; }
154
155 QIcon creationIcon() const override { return mIcon.isNull() ? QgsSensorAbstractGuiMetadata::creationIcon() : mIcon; }
156 QgsAbstractSensorWidget *createSensorWidget( QgsAbstractSensor *sensor ) override { return mWidgetFunc ? mWidgetFunc( sensor ) : nullptr; }
157 QgsAbstractSensor *createSensor( QObject *parent ) override { return mCreateFunc ? mCreateFunc( parent ) : nullptr; }
158
159 protected:
160 QIcon mIcon;
161 QgsSensorWidgetFunc mWidgetFunc = nullptr;
162 QgsSensorCreateFunc mCreateFunc = nullptr;
163};
164
165#endif
166
180class GUI_EXPORT QgsSensorGuiRegistry : public QObject
181{
182 Q_OBJECT
183
184 public:
191 QgsSensorGuiRegistry( QObject *parent = nullptr );
192 ~QgsSensorGuiRegistry() override;
193
196
201 bool populate();
202
207 QgsSensorAbstractGuiMetadata *sensorMetadata( const QString &type ) const;
208
212 bool addSensorGuiMetadata( QgsSensorAbstractGuiMetadata *metadata SIP_TRANSFER );
213
214 /*
215 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
216 * the case.
217 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
218 *
219 * "
220 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
221 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
222 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
223 * by Python so the /Factory/ on create() would be correct.)
224 *
225 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
226 * "
227 */
228
232 QgsAbstractSensor *createSensor( const QString &type, QObject *parent = nullptr ) const SIP_TRANSFERBACK;
233
240 QgsAbstractSensorWidget *createSensorWidget( QgsAbstractSensor *sensor ) const SIP_TRANSFERBACK;
241
245 QMap<QString, QString> sensorTypes() const;
246
247 signals:
248
253 void sensorAdded( const QString &type, const QString &name );
254
255 private:
256#ifdef SIP_RUN
258#endif
259
260 QMap<QString, QgsSensorAbstractGuiMetadata *> mMetadata;
261};
262
263#endif //QGSSENSORGUIREGISTRY_H
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.