21#if defined( HAVE_QTSERIALPORT )
23#include <QSerialPortInfo>
35QgsTcpSocketSensorWidget::QgsTcpSocketSensorWidget( QWidget *parent )
48 s->
setPort( mPortSpinBox->value() );
59 s->
setPort( mPortSpinBox->value() );
69 mHostNameLineEdit->setText( ts->
hostName() );
70 mPortSpinBox->setValue( ts->
port() );
77 mHostNameLineEdit->setText( us->
hostName() );
78 mPortSpinBox->setValue( us->
port() );
87QgsUdpSocketSensorWidget::QgsUdpSocketSensorWidget( QWidget *parent )
100 s->
setPort( mPortSpinBox->value() );
111 s->
setPort( mPortSpinBox->value() );
121 mHostNameLineEdit->setText( ts->
hostName() );
122 mPortSpinBox->setValue( ts->
port() );
129 mHostNameLineEdit->setText( us->
hostName() );
130 mPortSpinBox->setValue( us->
port() );
139#if defined( HAVE_QTSERIALPORT )
140QgsSerialPortSensorWidget::QgsSerialPortSensorWidget( QWidget *parent )
145 for (
const QSerialPortInfo &info : QSerialPortInfo::availablePorts() )
147 mSerialPortComboBox->addItem( QStringLiteral(
"%1: %2" ).arg( info.portName(), info.description() ), info.portName() );
150 updateSerialPortDetails();
152 connect( mSerialPortComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [ = ]()
154 updateSerialPortDetails();
161 QgsSerialPortSensor *s =
new QgsSerialPortSensor();
162 s->setPortName( mSerialPortComboBox->currentData().toString() );
168 QgsSerialPortSensor *s =
dynamic_cast<QgsSerialPortSensor *
>( sensor );
172 s->setPortName( mSerialPortComboBox->currentData().toString() );
179 QgsSerialPortSensor *s =
dynamic_cast<QgsSerialPortSensor *
>( sensor );
183 const int index = mSerialPortComboBox->findData( s->portName() );
186 mSerialPortComboBox->setCurrentIndex( index );
190 mSerialPortComboBox->addItem( s->portName(), s->portName() );
191 mSerialPortComboBox->setCurrentIndex( mSerialPortComboBox->count() - 1 );
197void QgsSerialPortSensorWidget::updateSerialPortDetails()
199 if ( mSerialPortComboBox->currentIndex() < 0 )
204 const QString ¤tPortName = mSerialPortComboBox->currentData().toString();
205 bool serialPortFound =
false;
206 for (
const QSerialPortInfo &info : QSerialPortInfo::availablePorts() )
208 serialPortFound = info.portName() == currentPortName;
209 if ( serialPortFound )
211 mSerialPortDetails->setText( QStringLiteral(
"%1:\n- %2: %3\n- %4: %5\n- %6: %7\n- %8: %9\n- %10: %11" ).arg( tr(
"Serial port details" ),
212 tr(
"Port name" ), info.portName(),
213 tr(
"Description" ), info.description(),
214 tr(
"Manufacturer" ), info.manufacturer(),
215 tr(
"Product identifier" ), QString::number( info.productIdentifier() ),
216 tr(
"Serial number" ), info.serialNumber() ) );
220 if ( !serialPortFound )
222 mSerialPortDetails->setText( QStringLiteral(
"%1:\n- %2: %3" ).arg( tr(
"Serial port details" ),
223 tr(
"Port name" ), currentPortName ) );
An abstract base class for sensor classes.
A TCP socket sensor class.
void setHostName(const QString &hostName)
Sets the host name the socket connects to.
int port() const
Returns the port the socket connects to.
void setPort(int port)
Sets the port the socket connects to.
QString hostName() const
Returns the host name the socket connects to.
A UDP socket sensor class.
void setHostName(const QString &hostName)
Sets the host name the socket connects to.
int port() const
Returns the port the socket connects to.
void setPort(int port)
Sets the port the socket connects to.
QString hostName() const
Returns the host name the socket connects to.