diff --git a/client/fieldedit.cpp b/client/fieldedit.cpp
index 909a0b6..3d956d1 100644
--- a/client/fieldedit.cpp
+++ b/client/fieldedit.cpp
@@ -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;
+}
diff --git a/client/fieldedit.h b/client/fieldedit.h
index 56eb8f4..f3efe05 100644
--- a/client/fieldedit.h
+++ b/client/fieldedit.h
@@ -42,6 +42,8 @@ public:
void setType(FieldType type);
void setRange(quint64 min, quint64 max);
+ QString text() const;
+
private:
FieldType type_{kUInt64};
diff --git a/client/findreplace.cpp b/client/findreplace.cpp
index 9d580a9..c96c65f 100644
--- a/client/findreplace.cpp
+++ b/client/findreplace.cpp
@@ -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()
diff --git a/common/macaddressvalidator.h b/common/macaddressvalidator.h
index bc04be8..6c5d806 100644
--- a/common/macaddressvalidator.h
+++ b/common/macaddressvalidator.h
@@ -20,18 +20,33 @@ along with this program. If not, see
#ifndef _MAC_ADDRESS_VALIDATOR_H
#define _MAC_ADDRESS_VALIDATOR_H
-#include
+#include
-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