24#include "moc_qgssensorguiregistry.cpp"
26using namespace Qt::StringLiterals;
34 qDeleteAll( mMetadata );
39 if ( !mMetadata.isEmpty() )
44 QObject::tr(
"TCP socket sensor" ),
47 QgsTcpSocketSensorWidget *widget =
new QgsTcpSocketSensorWidget(
nullptr );
48 widget->setSensor( sensor );
55 QObject::tr(
"UDP socket sensor" ),
58 QgsUdpSocketSensorWidget *widget =
new QgsUdpSocketSensorWidget(
nullptr );
59 widget->setSensor( sensor );
64#if defined( HAVE_QTSERIALPORT )
67 QObject::tr(
"Serial port sensor" ),
70 QgsSerialPortSensorWidget *widget =
new QgsSerialPortSensorWidget(
nullptr );
71 widget->setSensor( sensor );
82 return mMetadata.value( type );
87 if ( !metadata || mMetadata.contains( metadata->
type() ) )
90 mMetadata[metadata->
type()] = metadata;
97 auto it = mMetadata.constFind( type );
98 if ( it == mMetadata.constEnd() )
101 std::unique_ptr<QgsAbstractSensor> sensor( it.value()->createSensor( parent ) );
103 return sensor.release();
113 auto it = mMetadata.constFind( sensor->
type() );
114 if ( it == mMetadata.constEnd() )
117 return it.value()->createSensorWidget( sensor );
122 QMap<QString, QString> types;
123 for (
auto it = mMetadata.constBegin(); it != mMetadata.constEnd(); ++it )
125 types.insert( it.key(), it.value()->visibleName() );
An abstract base class for sensors.
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.