Qt: Construct QRegExp only once

In Interface Toolbar lineedit the QRegExp only needs to be
constructed once, not for every validity check.

Change-Id: I39e9ab9c57b4ac64a0b9b601fa72646d8c420274
Reviewed-on: https://code.wireshark.org/review/23425
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
This commit is contained in:
Stig Bjørlykke 2017-09-07 13:27:41 +02:00
parent b57010039b
commit d38197bb67
2 changed files with 4 additions and 5 deletions

View File

@ -33,7 +33,7 @@
InterfaceToolbarLineEdit::InterfaceToolbarLineEdit(QWidget *parent, QString validation_regex, bool is_required) :
QLineEdit(parent),
validation_regex_(validation_regex),
regex_expr_(validation_regex),
is_required_(is_required),
text_edited_(false)
{
@ -95,10 +95,9 @@ bool InterfaceToolbarLineEdit::isValid()
valid = false;
}
if (!validation_regex_.isEmpty() && text().length() > 0)
if (!regex_expr_.isEmpty() && text().length() > 0)
{
QRegExp expr(validation_regex_);
if (!expr.isValid() || expr.indexIn(text(), 0) == -1)
if (!regex_expr_.isValid() || regex_expr_.indexIn(text(), 0) == -1)
{
valid = false;
}

View File

@ -50,7 +50,7 @@ private:
void updateStyleSheet(bool is_valid);
StockIconToolButton *apply_button_;
QString validation_regex_;
QRegExp regex_expr_;
bool is_required_;
bool text_edited_;
};