File indexing completed on 2024-04-21 14:55:57
0001 /********************************************************************** 0002 ** 0003 ** Copyright (C) 1999 Glen Parker <glenebob@nwlink.com> 0004 ** Copyright (C) 2002 Marc Mutz <mutz@kde.org> 0005 ** 0006 ** This library is free software; you can redistribute it and/or 0007 ** modify it under the terms of the GNU Library General Public 0008 ** License as published by the Free Software Foundation; either 0009 ** version 2 of the License, or (at your option) any later version. 0010 ** 0011 ** This library is distributed in the hope that it will be useful, 0012 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 ** Library General Public License for more details. 0015 ** 0016 ** You should have received a copy of the GNU Library General Public 0017 ** License along with this library; if not, write to the Free 0018 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0019 ** 0020 *****************************************************************************/ 0021 0022 #ifndef KNUMVALIDATOR_H 0023 #define KNUMVALIDATOR_H 0024 0025 #include <kdelibs4support_export.h> 0026 0027 #include <QValidator> 0028 0029 class QWidget; 0030 class QString; 0031 0032 /** 0033 * QValidator for integers. 0034 0035 This can be used by QLineEdit or subclass to provide validated 0036 text entry. Can be provided with a base value (default is 10), to allow 0037 the proper entry of hexadecimal, octal, or any other base numeric data. 0038 0039 @author Glen Parker <glenebob@nwlink.com> 0040 @deprecated use QIntValidator (or fix KIntValidator for non-decimal bases) 0041 */ 0042 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KIntValidator : public QValidator 0043 { 0044 0045 public: 0046 /** 0047 * Constructor. Also sets the base value. 0048 */ 0049 KDELIBS4SUPPORT_DEPRECATED explicit KIntValidator(QWidget *parent, int base = 10); 0050 /** 0051 * Constructor. Also sets the minimum, maximum, and numeric base values. 0052 */ 0053 KIntValidator(int bottom, int top, QWidget *parent, int base = 10); 0054 /** 0055 * Destructs the validator. 0056 */ 0057 ~KIntValidator() override; 0058 /** 0059 * Validates the text, and return the result. Does not modify the parameters. 0060 */ 0061 State validate(QString &, int &) const override; 0062 /** 0063 * Fixes the text if possible, providing a valid string. The parameter may be modified. 0064 */ 0065 void fixup(QString &) const override; 0066 /** 0067 * Sets the minimum and maximum values allowed. 0068 * If @p top is greater than @p bottom, it is set to the value of @p bottom. 0069 */ 0070 virtual void setRange(int bottom, int top); 0071 /** 0072 * Sets the numeric base value. @p base must be between 2 and 36. 0073 */ 0074 virtual void setBase(int base); 0075 /** 0076 * Returns the current minimum value allowed. 0077 */ 0078 virtual int bottom() const; 0079 /** 0080 * Returns the current maximum value allowed. 0081 */ 0082 virtual int top() const; 0083 /** 0084 * Returns the current numeric base. 0085 */ 0086 virtual int base() const; 0087 0088 private: 0089 class KIntValidatorPrivate; 0090 KIntValidatorPrivate *const d; 0091 }; 0092 0093 /** 0094 @short A locale-aware QDoubleValidator 0095 0096 KDoubleValidator extends QDoubleValidator to be 0097 locale-aware. That means that - subject to not being disabled - 0098 KLocale::decimalSymbol(), KLocale::thousandsSeparator() 0099 and KLocale::positiveSign() and KLocale::negativeSign() 0100 are respected. 0101 0102 @author Marc Mutz <mutz@kde.org> 0103 @deprecated use QDoubleValidator (and QLocale) 0104 **/ 0105 0106 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KDoubleValidator : public QDoubleValidator 0107 { 0108 Q_OBJECT 0109 Q_PROPERTY(bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers) 0110 public: 0111 /** Constuct a locale-aware KDoubleValidator with default range 0112 (whatever QDoubleValidator uses for that) and parent @p 0113 parent */ 0114 KDELIBS4SUPPORT_DEPRECATED explicit KDoubleValidator(QObject *parent); 0115 /** Constuct a locale-aware KDoubleValidator for range [@p bottom,@p 0116 top] and a precision of @p decimals decimals after the decimal 0117 point. */ 0118 KDoubleValidator(double bottom, double top, int decimals, 0119 QObject *parent); 0120 /** Destructs the validator. 0121 */ 0122 ~KDoubleValidator() override; 0123 0124 /** Overloaded for internal reasons. The API is not affected. */ 0125 QValidator::State validate(QString &input, int &pos) const override; 0126 0127 /** @return whether localized numbers are accepted (default: true) */ 0128 bool acceptLocalizedNumbers() const; 0129 /** Sets whether to accept localized numbers (default: true) */ 0130 void setAcceptLocalizedNumbers(bool accept); 0131 0132 private: 0133 typedef QDoubleValidator base; 0134 class KDoubleValidatorPrivate; 0135 KDoubleValidatorPrivate *const d; 0136 }; 0137 0138 #endif