File indexing completed on 2024-12-29 04:54:51

0001 /*
0002    SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "lineeditvalidator.h"
0008 #include <QRegularExpression>
0009 #include <QRegularExpressionValidator>
0010 
0011 using namespace KSieveUi;
0012 
0013 LineEditValidator::LineEditValidator(QWidget *parent)
0014     : QLineEdit(parent)
0015 {
0016     initialize();
0017 }
0018 
0019 LineEditValidator::~LineEditValidator() = default;
0020 
0021 void LineEditValidator::initialize()
0022 {
0023     QRegularExpression rx(QStringLiteral("^[^\"]*$"));
0024     mValidator = new QRegularExpressionValidator(rx, this);
0025     setValidator(mValidator);
0026 }
0027 
0028 bool LineEditValidator::setRegularExpressionPattern(const QString &pattern)
0029 {
0030     QRegularExpression rx(pattern);
0031     if (rx.isValid()) {
0032         delete mValidator;
0033         mValidator = new QRegularExpressionValidator(rx, this);
0034         setValidator(mValidator);
0035         return true;
0036     }
0037     return false;
0038 }
0039 
0040 #include "moc_lineeditvalidator.cpp"