20#include "moc_qgssensorguiregistry.cpp"
30 qDeleteAll( mMetadata );
35 if ( !mMetadata.isEmpty() )
39 QObject::tr(
"TCP socket sensor" ),
43 QgsTcpSocketSensorWidget *widget =
new QgsTcpSocketSensorWidget(
nullptr );
44 widget->setSensor( sensor );
48 QObject::tr(
"UDP socket sensor" ),
52 QgsUdpSocketSensorWidget *widget =
new QgsUdpSocketSensorWidget(
nullptr );
53 widget->setSensor( sensor );
56#if defined( HAVE_QTSERIALPORT )
58 QObject::tr(
"Serial port sensor" ),
62 QgsSerialPortSensorWidget *widget =
new QgsSerialPortSensorWidget(
nullptr );
63 widget->setSensor( sensor );
72 return mMetadata.value( type );
77 if ( !metadata || mMetadata.contains( metadata->
type() ) )
80 mMetadata[metadata->
type()] = metadata;
87 if ( !mMetadata.contains( type ) )
90 std::unique_ptr< QgsAbstractSensor > sensor( mMetadata.value( type )->createSensor( parent ) );
92 return sensor.release();
99 if ( !sensor || !mMetadata.contains( sensor->
type() ) )
102 return mMetadata[sensor->
type()]->createSensorWidget( sensor );
107 QMap<QString, QString> types;
108 for (
auto it = mMetadata.constBegin(); it != mMetadata.constEnd(); ++it )
110 types.insert( it.key(), it.value()->visibleName() );
An abstract base class for sensor classes.
virtual QString type() const
Returns the sensor type.
static QgsSensorRegistry * sensorRegistry()
Returns the application's sensor registry, used for sensor types.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
QgsSensorGuiRegistry(QObject *parent=nullptr)
Creates a new empty sensor GUI registry.
~QgsSensorGuiRegistry() override
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.
bool addSensorGuiMetadata(QgsSensorAbstractGuiMetadata *metadata)
Registers the GUI metadata for a new sensor type.
QgsAbstractSensor * createSensor(const QString &type, QObject *parent=nullptr) const
Creates a new instance of a sensor given the type.