File indexing completed on 2024-11-03 11:15:19

0001 /*
0002     SPDX-FileCopyrightText: 2009 Paul Marchouk <pmarchouk@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #ifndef SIMPLEIPV4ADDRESSVALIDATOR_H
0008 #define SIMPLEIPV4ADDRESSVALIDATOR_H
0009 
0010 #include <QValidator>
0011 
0012 class Q_DECL_EXPORT SimpleIpV4AddressValidator : public QValidator
0013 {
0014     Q_OBJECT
0015 public:
0016     enum AddressStyle { Base, WithCidr, WithPort };
0017 
0018     explicit SimpleIpV4AddressValidator(AddressStyle style = AddressStyle::Base, QObject *parent = nullptr);
0019     ~SimpleIpV4AddressValidator() override;
0020 
0021     State validate(QString &, int &) const override;
0022 
0023     /** Check input value with a regular expression describing simple input mask.
0024      */
0025     QValidator::State checkWithInputMask(QString &, int &) const;
0026     /** Function split input string into tetrads and check them for valid values.
0027      *  In the tetrads are placed into QList. Input string may be changed.
0028      */
0029     QValidator::State checkTetradsRanges(QString &, QList<int> &) const;
0030 
0031 private:
0032     AddressStyle m_addressStyle;
0033     QRegularExpressionValidator m_validator;
0034 };
0035 
0036 #endif // SIMPLEIPV4ADDRESSVALIDATOR_H