File indexing completed on 2024-07-21 10:50:06

0001 /*
0002     SPDX-FileCopyrightText: 2011 Ilia Kats <ilia-kats@gmx.net>, based on work by 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 SIMPLEIPV6ADDRESSVALIDATOR_H
0008 #define SIMPLEIPV6ADDRESSVALIDATOR_H
0009 
0010 #include <QValidator>
0011 
0012 class Q_DECL_EXPORT SimpleIpV6AddressValidator : public QValidator
0013 {
0014     Q_OBJECT
0015 public:
0016     enum AddressStyle { Base, WithCidr, WithPort };
0017 
0018     explicit SimpleIpV6AddressValidator(AddressStyle style = AddressStyle::Base, QObject *parent = nullptr);
0019     ~SimpleIpV6AddressValidator() 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 &) const;
0030 
0031 private:
0032     const AddressStyle m_addressStyle;
0033     QRegularExpressionValidator m_validator;
0034 };
0035 
0036 #endif // SIMPLEIPV6ADDRESSVALIDATOR_H