# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2015-10-07 15:35:43 # Node ID 18a2603b6b9b76655b8d93411257ac6bcbbf5a50 # Parent e7af61f7cb69bad19cf41935b88e481b3dbd1c86 improved hex validator to not put space at the end of hex command diff --git a/commandwidget.cpp b/commandwidget.cpp --- a/commandwidget.cpp +++ b/commandwidget.cpp @@ -33,7 +33,7 @@ public: HexCommandValidator::HexCommandValidator(QObject* parent) : QRegExpValidator(parent) { - QRegExp regExp("([0-9A-F]{2}[ ])*"); + QRegExp regExp("^(?:(?:[0-9A-F]{2}[ ])+(?:[0-9A-F]{2}))|(?:[0-9A-F]{2})$"); setRegExp(regExp); } @@ -47,10 +47,10 @@ QValidator::State HexCommandValidator::v pos = orgPos; // try fixing up spaces - if (r == QValidator::Invalid) + if (r != QValidator::Acceptable) { input = input.replace(" ", ""); - input.replace(QRegExp("([0-9A-F]{2})"), "\\1 "); + input.replace(QRegExp("([0-9A-F]{2}(?!$))"), "\\1 "); if (pos == input.size()-1) pos = input.size(); r = QRegExpValidator::validate(input, pos); }