File indexing completed on 2024-07-14 05:24:11

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 "plasmanm_editor_export.h"
0011 
0012 #include <QValidator>
0013 
0014 class PLASMANM_EDITOR_EXPORT SimpleIpV4AddressValidator : public QValidator
0015 {
0016     Q_OBJECT
0017 public:
0018     enum AddressStyle { Base, WithCidr, WithPort };
0019 
0020     explicit SimpleIpV4AddressValidator(AddressStyle style = AddressStyle::Base, QObject *parent = nullptr);
0021     ~SimpleIpV4AddressValidator() override;
0022 
0023     State validate(QString &, int &) const override;
0024 
0025     /** Check input value with a regular expression describing simple input mask.
0026      */
0027     QValidator::State checkWithInputMask(QString &, int &) const;
0028     /** Function split input string into tetrads and check them for valid values.
0029      *  In the tetrads are placed into QList. Input string may be changed.
0030      */
0031     QValidator::State checkTetradsRanges(QString &, QList<int> &) const;
0032 
0033 private:
0034     AddressStyle m_addressStyle;
0035     QRegularExpressionValidator m_validator;
0036 };
0037 
0038 #endif // SIMPLEIPV4ADDRESSVALIDATOR_H