Verify and fix MacAddress type field edit
Use QRegularExpression instead of QRegExp as the latter is deprecated in Qt6
This commit is contained in:
parent
d3400f0897
commit
9385b31bc5
@ -55,3 +55,19 @@ void FieldEdit::setRange(quint64 min, quint64 max)
|
||||
{
|
||||
uint64Validator_.setRange(min, max);
|
||||
}
|
||||
|
||||
QString FieldEdit::text() const
|
||||
{
|
||||
QString str = QLineEdit::text();
|
||||
|
||||
switch (type_) {
|
||||
case kMacAddress:
|
||||
str.remove(QRegularExpression("[:-]"));
|
||||
str.prepend("0x");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
@ -42,6 +42,8 @@ public:
|
||||
void setType(FieldType type);
|
||||
void setRange(quint64 min, quint64 max);
|
||||
|
||||
QString text() const;
|
||||
|
||||
private:
|
||||
FieldType type_{kUInt64};
|
||||
|
||||
|
@ -92,14 +92,21 @@ void FindReplaceDialog::on_field_currentIndexChanged(int index)
|
||||
|
||||
FieldAttrib fieldAttrib = fieldAttrib_.at(index);
|
||||
|
||||
qDebug("XXXXXX %s bitSize %d max %llx", qPrintable(field->currentText()),
|
||||
fieldAttrib.bitSize, fieldAttrib.max);
|
||||
// Use heuristics to determine field type
|
||||
if (fieldAttrib.bitSize == 48) {
|
||||
findValue->setType(FieldEdit::kMacAddress);
|
||||
replaceValue->setType(FieldEdit::kMacAddress);
|
||||
} else {
|
||||
qDebug("XXXXXX %s bitSize %d max %llx",
|
||||
qPrintable(field->currentText()),
|
||||
fieldAttrib.bitSize, fieldAttrib.max);
|
||||
|
||||
findValue->setType(FieldEdit::kUInt64);
|
||||
findValue->setRange(0, fieldAttrib.max);
|
||||
findValue->setType(FieldEdit::kUInt64);
|
||||
findValue->setRange(0, fieldAttrib.max);
|
||||
|
||||
replaceValue->setType(FieldEdit::kUInt64);
|
||||
replaceValue->setRange(0, fieldAttrib.max);
|
||||
replaceValue->setType(FieldEdit::kUInt64);
|
||||
replaceValue->setRange(0, fieldAttrib.max);
|
||||
}
|
||||
}
|
||||
|
||||
void FindReplaceDialog::on_buttonBox_accepted()
|
||||
|
@ -20,18 +20,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#ifndef _MAC_ADDRESS_VALIDATOR_H
|
||||
#define _MAC_ADDRESS_VALIDATOR_H
|
||||
|
||||
#include <QRegExpValidator>
|
||||
#include <QRegularExpressionValidator>
|
||||
|
||||
class MacAddressValidator : public QRegExpValidator
|
||||
// Allow : or - as separator
|
||||
class MacAddressValidator : public QRegularExpressionValidator
|
||||
{
|
||||
public:
|
||||
MacAddressValidator(QObject *parent = 0)
|
||||
: QRegExpValidator(parent)
|
||||
: QRegularExpressionValidator(
|
||||
QRegularExpression(
|
||||
"([0-9,a-f,A-F]{2,2}[:-]){5,5}[0-9,a-f,A-F]{2,2}"),
|
||||
parent)
|
||||
{
|
||||
// Allow : or - as separator
|
||||
setRegExp(QRegExp("([0-9,a-f,A-F]{2,2}[:-]){5,5}[0-9,a-f,A-F]{2,2}"));
|
||||
}
|
||||
~MacAddressValidator() {}
|
||||
|
||||
virtual void fixup(QString &input) const
|
||||
{
|
||||
QStringList bytes = input.split(QRegularExpression("[:-]"),
|
||||
QString::SkipEmptyParts);
|
||||
|
||||
if (!bytes.isEmpty() && bytes.constLast().size() == 1)
|
||||
bytes.last().prepend("0");
|
||||
|
||||
while (bytes.count() < 6)
|
||||
bytes.append("00");
|
||||
|
||||
input = bytes.join(":");
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user