diff --git a/omodscan/controls/connectioncombobox.cpp b/omodscan/controls/connectioncombobox.cpp index 1ad77cc..50e3d0a 100644 --- a/omodscan/controls/connectioncombobox.cpp +++ b/omodscan/controls/connectioncombobox.cpp @@ -1,5 +1,5 @@ #include -#include +#include "serialportutils.h" #include "connectioncombobox.h" /// @@ -21,11 +21,10 @@ ConnectionComboBox::ConnectionComboBox(QWidget* parent) { addItem(tr("Remote TCP/IP Server"), ConnectionType::Tcp, QString()); - QStringList ports; - for(auto&& port: QSerialPortInfo::availablePorts()) + for(auto&& port: getAvailableSerialPorts()) { - const auto text = QString(tr("Direct Connection to %1")).arg(port.portName()); - addItem(text, ConnectionType::Serial, port.portName()); + const auto text = QString(tr("Direct Connection to %1")).arg(port); + addItem(text, ConnectionType::Serial, port); } } diff --git a/omodscan/controls/numericlineedit.cpp b/omodscan/controls/numericlineedit.cpp index d6b04c3..42737ed 100644 --- a/omodscan/controls/numericlineedit.cpp +++ b/omodscan/controls/numericlineedit.cpp @@ -441,7 +441,7 @@ void NumericLineEdit::on_rangeChanged(const QVariant& bottom, const QVariant& to { const int nums = QString::number(top.toInt()).length(); _paddingZeroWidth = qMax(1, nums); - setMaxLength(qMax(1, nums)); + setMaxLength(qMax(2, nums + 1)); setValidator(new QIntValidator(bottom.toInt(), top.toInt(), this)); } @@ -475,7 +475,7 @@ void NumericLineEdit::on_rangeChanged(const QVariant& bottom, const QVariant& to { const int nums = QString::number(top.toLongLong()).length(); _paddingZeroWidth = qMax(1, nums); - setMaxLength(qMax(1, nums)); + setMaxLength(qMax(2, nums + 1)); setValidator(new QInt64Validator(bottom.toLongLong(), top.toLongLong(), this)); } break; diff --git a/omodscan/dialogs/dialogmodbusscanner.cpp b/omodscan/dialogs/dialogmodbusscanner.cpp index 933e619..e73116e 100644 --- a/omodscan/dialogs/dialogmodbusscanner.cpp +++ b/omodscan/dialogs/dialogmodbusscanner.cpp @@ -5,6 +5,7 @@ #include #include #include "modbuslimits.h" +#include "serialportutils.h" #include "modbusrtuscanner.h" #include "modbustcpscanner.h" #include "dialogmodbusscanner.h" @@ -58,8 +59,7 @@ DialogModbusScanner::DialogModbusScanner(QWidget *parent) ui->pushButtonScan->setIcon(_iconStart); ui->radioButtonTCP->click(); - for(auto&& port: QSerialPortInfo::availablePorts()) - ui->comboBoxSerial->addItem(port.portName()); + ui->comboBoxSerial->addItems(getAvailableSerialPorts()); QHostAddress address, mask; for(auto&& eth : QNetworkInterface::allInterfaces()) { diff --git a/omodscan/omodscan.pro b/omodscan/omodscan.pro index 93f1757..4eb8b7f 100644 --- a/omodscan/omodscan.pro +++ b/omodscan/omodscan.pro @@ -4,7 +4,7 @@ CONFIG += c++17 CONFIG -= debug_and_release CONFIG -= debug_and_release_target -VERSION = 1.8.0 +VERSION = 1.8.1 QMAKE_TARGET_PRODUCT = "Open ModScan" QMAKE_TARGET_DESCRIPTION = "An Open Source Modbus Master (Client) Utility" @@ -176,6 +176,7 @@ HEADERS += \ qrange.h \ quintvalidator.h \ recentfileactionlist.h \ + serialportutils.h \ windowactionlist.h FORMS += \ diff --git a/omodscan/serialportutils.h b/omodscan/serialportutils.h new file mode 100644 index 0000000..96c52b5 --- /dev/null +++ b/omodscan/serialportutils.h @@ -0,0 +1,26 @@ +#ifndef SERIALPORTUTILS_H +#define SERIALPORTUTILS_H + +#include +#include + +/// +/// \brief getAvailableSerialPorts +/// \return +/// +inline QStringList getAvailableSerialPorts() +{ + QStringList ports; + for(auto&& port: QSerialPortInfo::availablePorts()) + ports << port.portName(); + + static QRegularExpression re( "[^\\d]"); + std::sort(ports.begin(), ports.end(), [](QString p1, QString p2) + { + return p1.remove(re).toInt() < p2.remove(re).toInt(); + }); + + return ports; +} + +#endif // SERIALPORTUTILS_H