19#include "moc_qgssensorwidget.cpp"
22#if defined( HAVE_QTSERIALPORT )
24#include <QSerialPortInfo>
36QgsTcpSocketSensorWidget::QgsTcpSocketSensorWidget( QWidget *parent )
49 s->
setPort( mPortSpinBox->value() );
60 s->
setPort( mPortSpinBox->value() );
70 mHostNameLineEdit->setText( ts->
hostName() );
71 mPortSpinBox->setValue( ts->
port() );
78 mHostNameLineEdit->setText( us->
hostName() );
79 mPortSpinBox->setValue( us->
port() );
88QgsUdpSocketSensorWidget::QgsUdpSocketSensorWidget( QWidget *parent )
101 s->
setPort( mPortSpinBox->value() );
112 s->
setPort( mPortSpinBox->value() );
122 mHostNameLineEdit->setText( ts->
hostName() );
123 mPortSpinBox->setValue( ts->
port() );
130 mHostNameLineEdit->setText( us->
hostName() );
131 mPortSpinBox->setValue( us->
port() );
140#if defined( HAVE_QTSERIALPORT )
141QgsSerialPortSensorWidget::QgsSerialPortSensorWidget( QWidget *parent )
146 for (
const QSerialPortInfo &info : QSerialPortInfo::availablePorts() )
148 mSerialPortComboBox->addItem( QStringLiteral(
"%1: %2" ).arg( info.portName(), info.description() ), info.portName() );
151 mBaudRateComboBox->addItem( QStringLiteral(
"1200 baud" ),
static_cast<int>( QSerialPort::Baud1200 ) );
152 mBaudRateComboBox->addItem( QStringLiteral(
"2400 baud" ),
static_cast<int>( QSerialPort::Baud2400 ) );
153 mBaudRateComboBox->addItem( QStringLiteral(
"4800 baud" ),
static_cast<int>( QSerialPort::Baud4800 ) );
154 mBaudRateComboBox->addItem( QStringLiteral(
"9600 baud" ),
static_cast<int>( QSerialPort::Baud9600 ) );
155 mBaudRateComboBox->addItem( QStringLiteral(
"19200 baud" ),
static_cast<int>( QSerialPort::Baud19200 ) );
156 mBaudRateComboBox->addItem( QStringLiteral(
"38400 baud" ),
static_cast<int>( QSerialPort::Baud38400 ) );
157 mBaudRateComboBox->addItem( QStringLiteral(
"57600 baud" ),
static_cast<int>( QSerialPort::Baud57600 ) );
158 mBaudRateComboBox->addItem( QStringLiteral(
"115200 baud" ),
static_cast<int>( QSerialPort::Baud115200 ) );
159 mBaudRateComboBox->setCurrentIndex( 3 );
161 mDataFrameDelimiterComboBox->addItem( tr(
"No Delimiter" ), QString() );
162 mDataFrameDelimiterComboBox->addItem( tr(
"New Line" ), QString(
"\n" ) );
163 mDataFrameDelimiterComboBox->addItem( tr(
"Custom Character" ), QString() );
165 updateSerialPortDetails();
167 connect( mSerialPortComboBox,
static_cast<void ( QComboBox::* )(
const QString & )
>( &QComboBox::currentTextChanged ),
this, [=]() {
168 updateSerialPortDetails();
172 connect( mBaudRateComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [=]() {
173 updateSerialPortDetails();
177 connect( mDataFrameDelimiterComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [=](
int index ) {
178 if ( index == mDataFrameDelimiterComboBox->count() - 1 )
180 mDataFrameDelimiterLineEdit->setEnabled( true );
181 mDataFrameDelimiterLineEdit->setFocus();
185 mDataFrameDelimiterLineEdit->setEnabled( false );
190 connect( mDataFrameDelimiterLineEdit, &QLineEdit::textEdited,
this, [=]() {
197 QgsSerialPortSensor *s =
new QgsSerialPortSensor();
198 s->setPortName( mSerialPortComboBox->findText( mSerialPortComboBox->currentText() ) != -1 ? mSerialPortComboBox->currentData().toString() : mSerialPortComboBox->currentText() );
199 s->setBaudRate(
static_cast<QSerialPort::BaudRate
>( mBaudRateComboBox->currentData().toInt() ) );
200 const QString delimiter = mDataFrameDelimiterComboBox->currentIndex() == mDataFrameDelimiterComboBox->count() - 1 ? mDataFrameDelimiterLineEdit->text() : mDataFrameDelimiterComboBox->currentData().toString();
201 s->setDelimiter( delimiter.toLocal8Bit() );
207 QgsSerialPortSensor *s =
dynamic_cast<QgsSerialPortSensor *
>( sensor );
211 s->setPortName( mSerialPortComboBox->findText( mSerialPortComboBox->currentText() ) != -1 ? mSerialPortComboBox->currentData().toString() : mSerialPortComboBox->currentText() );
212 s->setBaudRate(
static_cast<QSerialPort::BaudRate
>( mBaudRateComboBox->currentData().toInt() ) );
213 const QString delimiter = mDataFrameDelimiterComboBox->currentIndex() == mDataFrameDelimiterComboBox->count() - 1 ? mDataFrameDelimiterLineEdit->text() : mDataFrameDelimiterComboBox->currentData().toString();
214 s->setDelimiter( delimiter.toLocal8Bit() );
220 QgsSerialPortSensor *s =
dynamic_cast<QgsSerialPortSensor *
>( sensor );
224 const int index = mSerialPortComboBox->findData( s->portName() );
227 mSerialPortComboBox->setCurrentIndex( index );
231 mSerialPortComboBox->addItem( s->portName(), s->portName() );
232 mSerialPortComboBox->setCurrentIndex( mSerialPortComboBox->count() - 1 );
235 const int baudRateIndex = mBaudRateComboBox->findData( s->baudRate() );
238 mBaudRateComboBox->setCurrentIndex( baudRateIndex );
242 mBaudRateComboBox->setCurrentIndex( mBaudRateComboBox->count() - 1 );
245 const QString delimiter = QString( s->delimiter() );
246 if ( !delimiter.isEmpty() )
248 const int delimiterIndex = mDataFrameDelimiterComboBox->findData( delimiter );
249 if ( delimiterIndex > -1 )
251 mDataFrameDelimiterComboBox->setCurrentIndex( delimiterIndex );
255 mDataFrameDelimiterComboBox->setCurrentIndex( mDataFrameDelimiterComboBox->count() - 1 );
256 mDataFrameDelimiterLineEdit->setText( delimiter );
261 mDataFrameDelimiterComboBox->setCurrentIndex( 0 );
262 mDataFrameDelimiterLineEdit->setText( QString() );
268void QgsSerialPortSensorWidget::updateSerialPortDetails()
270 if ( mSerialPortComboBox->currentText().isEmpty() )
275 const QString ¤tPortName = mSerialPortComboBox->findText( mSerialPortComboBox->currentText() ) != -1 ? mSerialPortComboBox->currentData().toString() : mSerialPortComboBox->currentText();
276 bool serialPortFound =
false;
277 for (
const QSerialPortInfo &info : QSerialPortInfo::availablePorts() )
279 serialPortFound = info.portName() == currentPortName;
280 if ( serialPortFound )
282 mSerialPortDetails->setText( QStringLiteral(
"%1:\n- %2: %3\n- %4: %5\n- %6: %7\n- %8: %9\n- %10: %11" ).arg( tr(
"Serial port details" ), tr(
"Port name" ), info.portName(), tr(
"Description" ), info.description(), tr(
"Manufacturer" ), info.manufacturer(), tr(
"Product identifier" ), QString::number( info.productIdentifier() ), tr(
"Serial number" ), info.serialNumber() ) );
286 if ( !serialPortFound )
288 mSerialPortDetails->setText( QStringLiteral(
"%1:\n- %2: %3" ).arg( tr(
"Serial port details" ), tr(
"Port name" ), currentPortName ) );
292 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.