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 mBaudRateComboBox->addItem( QStringLiteral(
"1200 baud" ),
static_cast<int>( QSerialPort::Baud1200 ) );
151 mBaudRateComboBox->addItem( QStringLiteral(
"2400 baud" ),
static_cast<int>( QSerialPort::Baud2400 ) );
152 mBaudRateComboBox->addItem( QStringLiteral(
"4800 baud" ),
static_cast<int>( QSerialPort::Baud4800 ) );
153 mBaudRateComboBox->addItem( QStringLiteral(
"9600 baud" ),
static_cast<int>( QSerialPort::Baud9600 ) );
154 mBaudRateComboBox->addItem( QStringLiteral(
"19200 baud" ),
static_cast<int>( QSerialPort::Baud19200 ) );
155 mBaudRateComboBox->addItem( QStringLiteral(
"38400 baud" ),
static_cast<int>( QSerialPort::Baud38400 ) );
156 mBaudRateComboBox->addItem( QStringLiteral(
"57600 baud" ),
static_cast<int>( QSerialPort::Baud57600 ) );
157 mBaudRateComboBox->addItem( QStringLiteral(
"115200 baud" ),
static_cast<int>( QSerialPort::Baud115200 ) );
158 mBaudRateComboBox->setCurrentIndex( 3 );
160 mDataFrameDelimiterComboBox->addItem( tr(
"No Delimiter" ), QString() );
161 mDataFrameDelimiterComboBox->addItem( tr(
"New Line" ), QString(
"\n" ) );
162 mDataFrameDelimiterComboBox->addItem( tr(
"Custom Character" ), QString() );
164 updateSerialPortDetails();
166 connect( mSerialPortComboBox,
static_cast<void ( QComboBox::* )(
const QString & )
>( &QComboBox::currentTextChanged ),
this, [ = ]()
168 updateSerialPortDetails();
172 connect( mBaudRateComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [ = ]()
174 updateSerialPortDetails();
178 connect( mDataFrameDelimiterComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [ = ](
int index )
180 if ( index == mDataFrameDelimiterComboBox->count() - 1 )
182 mDataFrameDelimiterLineEdit->setEnabled( true );
183 mDataFrameDelimiterLineEdit->setFocus();
187 mDataFrameDelimiterLineEdit->setEnabled( false );
192 connect( mDataFrameDelimiterLineEdit, &QLineEdit::textEdited,
this, [ = ]()
200 QgsSerialPortSensor *s =
new QgsSerialPortSensor();
201 s->setPortName( mSerialPortComboBox->findText( mSerialPortComboBox->currentText() ) != -1 ? mSerialPortComboBox->currentData().toString() : mSerialPortComboBox->currentText() );
202 s->setBaudRate(
static_cast< QSerialPort::BaudRate
>( mBaudRateComboBox->currentData().toInt() ) );
203 const QString delimiter = mDataFrameDelimiterComboBox->currentIndex() == mDataFrameDelimiterComboBox->count() - 1 ? mDataFrameDelimiterLineEdit->text() : mDataFrameDelimiterComboBox->currentData().toString();
204 s->setDelimiter( delimiter.toLocal8Bit() );
210 QgsSerialPortSensor *s =
dynamic_cast<QgsSerialPortSensor *
>( sensor );
214 s->setPortName( mSerialPortComboBox->findText( mSerialPortComboBox->currentText() ) != -1 ? mSerialPortComboBox->currentData().toString() : mSerialPortComboBox->currentText() );
215 s->setBaudRate(
static_cast< QSerialPort::BaudRate
>( mBaudRateComboBox->currentData().toInt() ) );
216 const QString delimiter = mDataFrameDelimiterComboBox->currentIndex() == mDataFrameDelimiterComboBox->count() - 1 ? mDataFrameDelimiterLineEdit->text() : mDataFrameDelimiterComboBox->currentData().toString();
217 s->setDelimiter( delimiter.toLocal8Bit() );
223 QgsSerialPortSensor *s =
dynamic_cast<QgsSerialPortSensor *
>( sensor );
227 const int index = mSerialPortComboBox->findData( s->portName() );
230 mSerialPortComboBox->setCurrentIndex( index );
234 mSerialPortComboBox->addItem( s->portName(), s->portName() );
235 mSerialPortComboBox->setCurrentIndex( mSerialPortComboBox->count() - 1 );
238 const int baudRateIndex = mBaudRateComboBox->findData( s->baudRate() );
241 mBaudRateComboBox->setCurrentIndex( baudRateIndex );
245 mBaudRateComboBox->setCurrentIndex( mBaudRateComboBox->count() - 1 );
248 const QString delimiter = QString( s->delimiter() );
249 if ( !delimiter.isEmpty() )
251 const int delimiterIndex = mDataFrameDelimiterComboBox->findData( delimiter );
252 if ( delimiterIndex > -1 )
254 mDataFrameDelimiterComboBox->setCurrentIndex( delimiterIndex );
258 mDataFrameDelimiterComboBox->setCurrentIndex( mDataFrameDelimiterComboBox->count() - 1 );
259 mDataFrameDelimiterLineEdit->setText( delimiter );
264 mDataFrameDelimiterComboBox->setCurrentIndex( 0 );
265 mDataFrameDelimiterLineEdit->setText( QString() );
271void QgsSerialPortSensorWidget::updateSerialPortDetails()
273 if ( mSerialPortComboBox->currentText().isEmpty() )
278 const QString ¤tPortName = mSerialPortComboBox->findText( mSerialPortComboBox->currentText() ) != -1 ? mSerialPortComboBox->currentData().toString() : mSerialPortComboBox->currentText();
279 bool serialPortFound =
false;
280 for (
const QSerialPortInfo &info : QSerialPortInfo::availablePorts() )
282 serialPortFound = info.portName() == currentPortName;
283 if ( serialPortFound )
285 mSerialPortDetails->setText( QStringLiteral(
"%1:\n- %2: %3\n- %4: %5\n- %6: %7\n- %8: %9\n- %10: %11" ).arg( tr(
"Serial port details" ),
286 tr(
"Port name" ), info.portName(),
287 tr(
"Description" ), info.description(),
288 tr(
"Manufacturer" ), info.manufacturer(),
289 tr(
"Product identifier" ), QString::number( info.productIdentifier() ),
290 tr(
"Serial number" ), info.serialNumber() ) );
294 if ( !serialPortFound )
296 mSerialPortDetails->setText( QStringLiteral(
"%1:\n- %2: %3" ).arg( tr(
"Serial port details" ),
297 tr(
"Port name" ), currentPortName ) );
301 mSerialPortDetails->setText( QString() );
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.