Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
sanny32 committed Sep 6, 2023
2 parents cdd43bf + 7f419ed commit 61274ec
Show file tree
Hide file tree
Showing 32 changed files with 1,019 additions and 358 deletions.
21 changes: 21 additions & 0 deletions omodscan/controls/formattedspinbox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "formattedspinbox.h"

///
/// \brief FormattedSpinBox::FormattedSpinBox
/// \param parent
///
FormattedSpinBox::FormattedSpinBox(QWidget* parent)
:QSpinBox(parent)
{
}

///
/// \brief FormattedSpinBox::textFromValue
/// \param val
/// \return
///
QString FormattedSpinBox::textFromValue(int val) const
{
const int nums = qMax(1, QString::number(maximum()).length());
return QStringLiteral("%1").arg(val, nums, 10, QLatin1Char('0'));
}
17 changes: 17 additions & 0 deletions omodscan/controls/formattedspinbox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef FORMATTEDSPINBOX_H
#define FORMATTEDSPINBOX_H

#include <QSpinBox>
#include <QObject>

class FormattedSpinBox : public QSpinBox
{
Q_OBJECT
public:
FormattedSpinBox(QWidget* parent = nullptr);

protected:
QString textFromValue(int val) const override;
};

#endif // FORMATTEDSPINBOX_H
128 changes: 128 additions & 0 deletions omodscan/controls/functioncodecombobox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#include "functioncodecombobox.h"

///
/// \brief FunctionCodeComboBox::FunctionCodeComboBox
/// \param parent
///
FunctionCodeComboBox::FunctionCodeComboBox(QWidget *parent)
:QComboBox(parent)
{
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(on_currentIndexChanged(int)));
}

///
/// \brief FunctionCodeComboBox::currentFunctionCode
/// \return
///
QModbusPdu::FunctionCode FunctionCodeComboBox::currentFunctionCode() const
{
return currentData().value<QModbusPdu::FunctionCode>();
}

///
/// \brief FunctionCodeComboBox::setCurrentFunctionCode
/// \param pointType
///
void FunctionCodeComboBox::setCurrentFunctionCode(QModbusPdu::FunctionCode funcCode)
{
const auto idx = findData(funcCode);
setCurrentIndex(idx);
}

///
/// \brief FunctionCodeComboBox::addItem
/// \param funcCode
///
void FunctionCodeComboBox::addItem(QModbusPdu::FunctionCode funcCode)
{
switch(funcCode)
{
case QModbusPdu::ReadCoils:
QComboBox::addItem("01: READ COILS", QModbusPdu::ReadCoils);
break;

case QModbusPdu::ReadDiscreteInputs:
QComboBox::addItem("02: READ INPUTS", QModbusPdu::ReadDiscreteInputs);
break;

case QModbusPdu::ReadHoldingRegisters:
QComboBox::addItem("03: READ HOLDING REGS", QModbusPdu::ReadHoldingRegisters);
break;

case QModbusPdu::ReadInputRegisters:
QComboBox::addItem("04: READ INPUT REGS", QModbusPdu::ReadInputRegisters);
break;

case QModbusPdu::WriteSingleCoil:
QComboBox::addItem("05: WRITE SINGLE COIL", QModbusPdu::WriteSingleCoil);
break;

case QModbusPdu::WriteSingleRegister:
QComboBox::addItem("06: WRITE SINGLE REG", QModbusPdu::WriteSingleRegister);
break;

case QModbusPdu::ReadExceptionStatus:
QComboBox::addItem("07: READ EXCEPTION STAT", QModbusPdu::ReadExceptionStatus);
break;

case QModbusPdu::Diagnostics:
QComboBox::addItem("08: DIAGNOSTICS", QModbusPdu::Diagnostics);
break;

case QModbusPdu::GetCommEventCounter:
QComboBox::addItem("11: GET COMM EVENT CNT", QModbusPdu::GetCommEventCounter);
break;

case QModbusPdu::GetCommEventLog:
QComboBox::addItem("12: GET COMM EVENT LOG", QModbusPdu::GetCommEventLog);
break;

case QModbusPdu::WriteMultipleCoils:
QComboBox::addItem("15: WRITE MULT COILS", QModbusPdu::WriteMultipleCoils);
break;

case QModbusPdu::WriteMultipleRegisters:
QComboBox::addItem("16: WRITE MULT REGS", QModbusPdu::WriteMultipleRegisters);
break;

case QModbusPdu::ReportServerId:
QComboBox::addItem("17: REPORT SLAVE ID", QModbusPdu::ReportServerId);
break;

case QModbusPdu::ReadFileRecord:
QComboBox::addItem("20: READ FILE RECORD", QModbusPdu::ReadFileRecord);
break;

case QModbusPdu::WriteFileRecord:
QComboBox::addItem("21: WRITE FILE RECORD", QModbusPdu::WriteFileRecord);
break;

case QModbusPdu::MaskWriteRegister:
QComboBox::addItem("22: MASK WRITE REG", QModbusPdu::MaskWriteRegister);
break;

case QModbusPdu::ReadWriteMultipleRegisters:
QComboBox::addItem("23: READ WRITE MULT REGS", QModbusPdu::ReadWriteMultipleRegisters);
break;

case QModbusPdu::ReadFifoQueue:
QComboBox::addItem("24: READ FIFO QUEUE", QModbusPdu::ReadFifoQueue);
break;

case QModbusPdu::EncapsulatedInterfaceTransport:
QComboBox::addItem("43: ENC IFACE TRANSPORT", QModbusPdu::EncapsulatedInterfaceTransport);
break;

default:
break;
}
}

///
/// \brief FunctionCodeComboBox::on_currentIndexChanged
/// \param index
///
void FunctionCodeComboBox::on_currentIndexChanged(int index)
{
emit functionCodeChanged(itemData(index).value<QModbusPdu::FunctionCode>());
}
26 changes: 26 additions & 0 deletions omodscan/controls/functioncodecombobox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef FUNCTIONCODECOMBOBOX_H
#define FUNCTIONCODECOMBOBOX_H

#include <QComboBox>
#include <QModbusPdu>

class FunctionCodeComboBox : public QComboBox
{
Q_OBJECT

public:
FunctionCodeComboBox(QWidget *parent = nullptr);

QModbusPdu::FunctionCode currentFunctionCode() const;
void setCurrentFunctionCode(QModbusPdu::FunctionCode funcCode);

void addItem(QModbusPdu::FunctionCode funcCode);

signals:
void functionCodeChanged(QModbusPdu::FunctionCode funcCode);

private slots:
void on_currentIndexChanged(int);
};

#endif // FUNCTIONCODECOMBOBOX_H
45 changes: 45 additions & 0 deletions omodscan/controls/numericlineedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ void NumericLineEdit::setInputMode(InputMode mode)
_maxValue = INT_MAX;
break;

case UnsignedMode:
_minValue = 0U;
_maxValue = UINT_MAX;
break;

case FloatMode:
_minValue = -FLT_MAX;
_maxValue = FLT_MAX;
Expand Down Expand Up @@ -129,6 +134,20 @@ void NumericLineEdit::internalSetValue(QVariant value)
}
break;

case UnsignedMode:
value = qBound(_minValue.toUInt(), value.toUInt(), _maxValue.toUInt());
if(_paddingZeroes)
{
const auto text = QStringLiteral("%1").arg(value.toUInt(), _paddingZeroWidth, 10, QLatin1Char('0'));
QLineEdit::setText(text);
}
else
{
const auto text = QString::number(value.toUInt());
QLineEdit::setText(text);
}
break;

case HexMode:
value = qBound(_minValue.toInt() > 0 ? _minValue.toUInt() : 0, value.toUInt(), _maxValue.toUInt());
if(_paddingZeroes)
Expand Down Expand Up @@ -177,6 +196,15 @@ void NumericLineEdit::updateValue()
}
break;

case UnsignedMode:
{
bool ok;
const auto value = text().toUInt(&ok);
if(ok) internalSetValue(value);
else internalSetValue(_value);
}
break;

case HexMode:
{
bool ok;
Expand Down Expand Up @@ -240,6 +268,14 @@ void NumericLineEdit::on_textChanged(const QString& text)
}
break;

case UnsignedMode:
{
bool ok;
const auto valueInt = text.toUInt(&ok);
if(ok) value = qBound(_minValue.toUInt(), valueInt, _maxValue.toUInt());
}
break;

case HexMode:
{
bool ok;
Expand Down Expand Up @@ -293,6 +329,15 @@ void NumericLineEdit::on_rangeChanged(const QVariant& bottom, const QVariant& to
}
break;

case UnsignedMode:
{
const int nums = QString::number(top.toUInt()).length();
_paddingZeroWidth = qMax(1, nums);
setMaxLength(qMax(1, nums));
setValidator(new QIntValidator(bottom.toUInt(), top.toUInt(), this));
}
break;

case HexMode:
{
const int nums = QString::number(top.toUInt(), 16).length();
Expand Down
1 change: 1 addition & 0 deletions omodscan/controls/numericlineedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class NumericLineEdit : public QLineEdit
enum InputMode
{
DecMode = 0,
UnsignedMode,
HexMode,
FloatMode,
DoubleMode
Expand Down
Loading

0 comments on commit 61274ec

Please sign in to comment.