28 #include "knumvalidator.h" 30 #include <tdeglobal.h> 38 : TQValidator(TQT_TQOBJECT(parent), name)
41 if (_base < 2) _base = 2;
42 if (_base > 36) _base = 36;
48 : TQValidator(TQT_TQOBJECT(parent), name)
51 if (_base > 36) _base = 36;
66 newStr = str.stripWhiteSpace();
68 newStr = newStr.upper();
70 if (newStr == TQString::fromLatin1(
"-"))
71 if ((_min || _max) && _min >= 0)
74 return TQValidator::Acceptable;
75 else if (newStr.length())
76 val = newStr.toInt(&ok, _base);
83 return TQValidator::Invalid;
85 if ((! _min && ! _max) || (val >= _min && val <= _max))
86 return TQValidator::Acceptable;
88 if (_max && _min >= 0 && val < 0)
89 return TQValidator::Invalid;
91 return TQValidator::Valid;
98 TQValidator::State state;
102 if (state == TQValidator::Invalid || state == TQValidator::Acceptable)
105 if (! _min && ! _max)
108 val = str.toInt(0, _base);
110 if (val < _min) val = _min;
111 if (val > _max) val = _max;
113 str.setNum(val, _base);
128 if (_base < 2) _base = 2;
151 class KFloatValidatorPrivate
154 KFloatValidatorPrivate()
157 ~KFloatValidatorPrivate()
160 bool acceptLocalizedNumbers;
165 : TQValidator(TQT_TQOBJECT(parent), name)
167 d =
new KFloatValidatorPrivate;
168 d->acceptLocalizedNumbers=
false;
173 : TQValidator(TQT_TQOBJECT(parent), name)
175 d =
new KFloatValidatorPrivate;
176 d->acceptLocalizedNumbers=
false;
182 : TQValidator(TQT_TQOBJECT(parent), name)
184 d =
new KFloatValidatorPrivate;
185 d->acceptLocalizedNumbers = localeAware;
197 d->acceptLocalizedNumbers=_b;
202 return d->acceptLocalizedNumbers;
210 newStr = str.stripWhiteSpace();
212 if (newStr == TQString::fromLatin1(
"-"))
213 if ((_min || _max) && _min >= 0)
216 return TQValidator::Acceptable;
218 return TQValidator::Acceptable;
219 else if (newStr.length())
221 val = newStr.toDouble(&ok);
222 if(!ok && d->acceptLocalizedNumbers)
231 return TQValidator::Invalid;
233 if (( !_min && !_max) || (val >= _min && val <= _max))
234 return TQValidator::Acceptable;
236 if (_max && _min >= 0 && val < 0)
237 return TQValidator::Invalid;
239 if ( (_min || _max) && (val < _min || val > _max))
240 return TQValidator::Invalid;
242 return TQValidator::Valid;
249 TQValidator::State state;
253 if (state == TQValidator::Invalid || state == TQValidator::Acceptable)
256 if (! _min && ! _max)
259 val = str.toDouble();
261 if (val < _min) val = _min;
262 if (val > _max) val = _max;
293 class KDoubleValidator::Private {
301 : TQDoubleValidator( parent, name ), d( 0 )
307 TQObject * parent,
const char * name )
308 : TQDoubleValidator( bottom, top, decimals, parent, name ), d( 0 )
319 return d->acceptLocalizedNumbers;
323 d->acceptLocalizedNumbers = accept;
342 for (
int idx = s.find( p ) ; idx >= 0 ; idx = s.find( p, idx ) )
343 s.remove( idx, p.length() );
347 for (
int idx = s.find( t ) ; idx >= 0 ; idx = s.find( t, idx ) )
348 s.remove( idx, t.length() );
351 if ( ( !n.isEmpty() && n.find(
'.') != -1 ) ||
352 ( !d.isEmpty() && d.find(
'-') != -1 ) ) {
354 kdWarning() <<
"KDoubleValidator: decimal symbol contains '-' or " 355 "negative sign contains '.' -> improve algorithm" <<
endl;
359 if ( !d.isEmpty() && d !=
"." )
360 for (
int idx = s.find( d ) ; idx >= 0 ; idx = s.find( d, idx + 1 ) )
361 s.replace( idx, d.length(),
'.');
363 if ( !n.isEmpty() && n !=
"-" )
364 for (
int idx = s.find( n ) ; idx >= 0 ; idx = s.find( n, idx + 1 ) )
365 s.replace( idx, n.length(),
'-' );
368 return base::validate( s, p );
371 #include "knumvalidator.moc" virtual void fixup(TQString &) const
Fixes the text if possible, providing a valid string.
virtual ~KFloatValidator()
Destructs the validator.
bool acceptLocalizedNumbers() const
Returns true if the validator is locale aware.
virtual int top() const
Returns the current maximum value allowed.
void setAcceptLocalizedNumbers(bool b)
Sets the validator to be locale aware if is true.
virtual int bottom() const
Returns the current minimum value allowed.
virtual State validate(TQString &, int &) const
Validates the text, and return the result.
TQString negativeSign() const
virtual int base() const
Returns the current numeric base.
TQString decimalSymbol() const
KIntValidator(TQWidget *parent, int base=10, const char *name=0)
Constuctor.
virtual void fixup(TQString &) const
Fixes the text if possible, providing a valid string.
virtual void setRange(int bottom, int top)
Sets the minimum and maximum values allowed.
virtual ~KIntValidator()
Destructs the validator.
virtual ~KDoubleValidator()
Destructs the validator.
virtual double bottom() const
Returns the current minimum value allowed.
virtual void setRange(double bottom, double top)
Sets the minimum and maximum value allowed.
kdbgstream kdWarning(int area=0)
virtual void setBase(int base)
Sets the numeric base value.
double readNumber(const TQString &numStr, bool *ok=0) const
TQString thousandsSeparator() const
KFloatValidator(TQWidget *parent, const char *name=0)
Constructor.
void setAcceptLocalizedNumbers(bool accept)
Sets whether to accept localized numbers (default: true)
virtual TQValidator::State validate(TQString &input, int &pos) const
Overloaded for internal reasons.
static TDELocale * locale()
virtual State validate(TQString &, int &) const
Validates the text, and return the result.
TQString positiveSign() const
kndbgstream & endl(kndbgstream &s)
KDoubleValidator(TQObject *parent, const char *name=0)
Constuct a locale-aware KDoubleValidator with default range (whatever TQDoubleValidator uses for that...
bool acceptLocalizedNumbers() const
virtual double top() const
Returns the current maximum value allowed.