I don't want change orginal files. I try this:
{
public:
MyDoubleValidator
( double bottom,
double top,
int decimals,
QObject* parent
= 0) {}
{
if (input.contains(' '))
return Invalid;
return Invalid;
if (empty.exactMatch(input))
return Intermediate;
bool ok = true;
double entered = input.toDouble(&ok);
int nume = input.count('e', Qt::CaseInsensitive);
if (!ok) {
// explicit exponent regexp
int eePos = expexpexp.indexIn(input);
if (eePos > 0 && nume == 1) {
QString mantissa
= input.
left(eePos
);
entered = mantissa.toDouble(&ok);
if (!ok)
return Invalid;
if (expexpexp.cap(1).isEmpty())
return Intermediate;
} else if (eePos == 0) {
return Intermediate;
} else {
return Invalid;
}
}
int i = input.indexOf('.');
if (i >= 0 && nume == 0) {
// has decimal point (but no E), now count digits after that
i++;
int j = i;
while(input[j].isDigit())
j++;
if (j - i > d)
return Intermediate;
}
if (entered < b || entered > t)
return Intermediate;
return Acceptable;
}
};
class MyDoubleValidator : public QDoubleValidator
{
public:
MyDoubleValidator( double bottom, double top, int decimals, QObject* parent = 0)
: QDoubleValidator( bottom, top, decimals, parent)
{}
QValidator::State QDoubleValidator::validate(QString & input, int &) const
{
QRegExp empty(QString::fromLatin1("-?\\.?"));
if (input.contains(' '))
return Invalid;
if (b >= 0 && input.startsWith(QLatin1Char('-')))
return Invalid;
if (empty.exactMatch(input))
return Intermediate;
bool ok = true;
double entered = input.toDouble(&ok);
int nume = input.count('e', Qt::CaseInsensitive);
if (!ok) {
// explicit exponent regexp
QRegExp expexpexp(QString::fromLatin1("[Ee][+-]?(\\d*)$"));
int eePos = expexpexp.indexIn(input);
if (eePos > 0 && nume == 1) {
QString mantissa = input.left(eePos);
entered = mantissa.toDouble(&ok);
if (!ok)
return Invalid;
if (expexpexp.cap(1).isEmpty())
return Intermediate;
} else if (eePos == 0) {
return Intermediate;
} else {
return Invalid;
}
}
int i = input.indexOf('.');
if (i >= 0 && nume == 0) {
// has decimal point (but no E), now count digits after that
i++;
int j = i;
while(input[j].isDigit())
j++;
if (j - i > d)
return Intermediate;
}
if (entered < b || entered > t)
return Intermediate;
return Acceptable;
}
};
To copy to clipboard, switch view to plain text mode
but i can't compile!
Bookmarks