fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / kdeui / util / knumvalidator.h
blobc554b3d7b308ea4ddd0281de32b325b88e904296
1 /**********************************************************************
2 **
3 ** Copyright (C) 1999 Glen Parker <glenebob@nwlink.com>
4 ** Copyright (C) 2002 Marc Mutz <mutz@kde.org>
5 **
6 ** This library is free software; you can redistribute it and/or
7 ** modify it under the terms of the GNU Library General Public
8 ** License as published by the Free Software Foundation; either
9 ** version 2 of the License, or (at your option) any later version.
11 ** This library is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** Library General Public License for more details.
16 ** You should have received a copy of the GNU Library General Public
17 ** License along with this library; if not, write to the Free
18 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 *****************************************************************************/
22 #ifndef KNUMVALIDATOR_H
23 #define KNUMVALIDATOR_H
25 #include <kdeui_export.h>
27 #include <QtGui/QValidator>
29 class QWidget;
30 class QString;
32 /**
33 * QValidator for integers.
35 This can be used by QLineEdit or subclass to provide validated
36 text entry. Can be provided with a base value (default is 10), to allow
37 the proper entry of hexadecimal, octal, or any other base numeric data.
39 @author Glen Parker <glenebob@nwlink.com>
40 @version 0.0.1
42 class KDEUI_EXPORT KIntValidator : public QValidator {
44 public:
45 /**
46 Constuctor. Also sets the base value.
48 explicit KIntValidator ( QWidget * parent, int base = 10 );
49 /**
50 * Constructor. Also sets the minimum, maximum, and numeric base values.
52 KIntValidator ( int bottom, int top, QWidget * parent, int base = 10 );
53 /**
54 * Destructs the validator.
56 virtual ~KIntValidator ();
57 /**
58 * Validates the text, and return the result. Does not modify the parameters.
60 virtual State validate ( QString &, int & ) const;
61 /**
62 * Fixes the text if possible, providing a valid string. The parameter may be modified.
64 virtual void fixup ( QString & ) const;
65 /**
66 * Sets the minimum and maximum values allowed.
67 * If @p top is greater than @p bottom, it is set to the value of @p bottom.
69 virtual void setRange ( int bottom, int top );
70 /**
71 * Sets the numeric base value. @p base must be between 2 and 36.
73 virtual void setBase ( int base );
74 /**
75 * Returns the current minimum value allowed.
77 virtual int bottom () const;
78 /**
79 * Returns the current maximum value allowed.
81 virtual int top () const;
82 /**
83 * Returns the current numeric base.
85 virtual int base () const;
87 private:
88 class KIntValidatorPrivate;
89 KIntValidatorPrivate * const d;
92 /**
93 \brief QValidator for floating point entry (Obsolete)
95 @obsolete Use KDoubleValidator
97 Extends the QValidator class to properly validate double numeric data.
98 This can be used by QLineEdit or subclass to provide validated
99 text entry.
101 @author Glen Parker <glenebob@nwlink.com>
102 @version 0.0.1
104 class KDEUI_EXPORT KFloatValidator : public QValidator {
106 public:
108 * Constructor.
110 explicit KFloatValidator ( QWidget * parent );
112 * Constructor. Also sets the minimum and maximum values.
114 KFloatValidator ( double bottom, double top, QWidget * parent );
116 * Constructor. Sets the validator to be locale aware if @p localeAware is true.
118 KFloatValidator ( double bottom, double top, bool localeAware, QWidget * parent );
120 * Destructs the validator.
122 virtual ~KFloatValidator ();
124 * Validates the text, and return the result. Does not modify the parameters.
126 virtual State validate ( QString &, int & ) const;
128 * Fixes the text if possible, providing a valid string. The parameter may be modified.
130 virtual void fixup ( QString & ) const;
132 * Sets the minimum and maximum value allowed.
134 virtual void setRange ( double bottom, double top );
136 * Returns the current minimum value allowed.
138 virtual double bottom () const;
140 * Returns the current maximum value allowed.
142 virtual double top () const;
144 * Sets the validator to be locale aware if @p is true. In this case, the
145 * character KLocale::decimalSymbol() from the global locale is recognized
146 * as decimal separator.
148 void setAcceptLocalizedNumbers(bool b);
150 * Returns true if the validator is locale aware.
151 * @see setAcceptLocalizedNumbers().
153 bool acceptLocalizedNumbers() const;
155 private:
156 class KFloatValidatorPrivate;
157 KFloatValidatorPrivate * const d;
161 @short A locale-aware QDoubleValidator
163 KDoubleValidator extends QDoubleValidator to be
164 locale-aware. That means that - subject to not being disabled -
165 KLocale::decimalSymbol(), KLocale::thousandsSeparator()
166 and KLocale::positiveSign() and KLocale::negativeSign()
167 are respected.
169 @author Marc Mutz <mutz@kde.org>
170 @see KIntValidator
173 class KDEUI_EXPORT KDoubleValidator : public QDoubleValidator {
174 Q_OBJECT
175 Q_PROPERTY( bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers )
176 public:
177 /** Constuct a locale-aware KDoubleValidator with default range
178 (whatever QDoubleValidator uses for that) and parent @p
179 parent */
180 explicit KDoubleValidator( QObject * parent );
181 /** Constuct a locale-aware KDoubleValidator for range [@p bottom,@p
182 top] and a precision of @p decimals decimals after the decimal
183 point. */
184 KDoubleValidator( double bottom, double top, int decimals,
185 QObject * parent );
186 /** Destructs the validator.
188 virtual ~KDoubleValidator();
190 /** Overloaded for internal reasons. The API is not affected. */
191 virtual QValidator::State validate( QString & input, int & pos ) const;
193 /** @return whether localized numbers are accepted (default: true) */
194 bool acceptLocalizedNumbers() const;
195 /** Sets whether to accept localized numbers (default: true) */
196 void setAcceptLocalizedNumbers( bool accept );
198 private:
199 typedef QDoubleValidator base;
200 class KDoubleValidatorPrivate;
201 KDoubleValidatorPrivate * const d;
204 #endif