Adding changes

This commit is contained in:
Johan K 2014-08-03 19:38:34 +02:00
parent b32b227733
commit 5cfdabb45a
3 changed files with 17 additions and 8 deletions

View File

@ -58,7 +58,7 @@
| SINH '(' num ')' { $$ = sinh($3.getValue()); }
| TAN '(' num ')' { $$ = tan($3.getValue()); }
| TANH '(' num ')' { $$ = tanh($3.getValue()); }
| SQRT '(' num ')' { $$ = tanh($3.getValue()); }
| SQRT '(' num ')' { $$ = sqrt($3.getValue()); }
| COS '(' num ')' { $$ = cos($3.getValue()); }
;

View File

@ -181,7 +181,7 @@ void InputField::newInput(const QString & text)
Quantity res;
try {
QString input = text;
input.remove(locale().groupSeparator());
fixup(input);
res = Quantity::parse(input);
}
catch(Base::Exception &e){
@ -452,13 +452,14 @@ void InputField::selectNumber(void)
{
QByteArray str = text().toLatin1();
unsigned int i = 0;
Base::Console().Message("%i", locale().negativeSign().toAscii());
for (QByteArray::iterator it = str.begin(); it != str.end(); ++it) {
if (*it >= '0' && *it <= '9')
i++;
else if (*it == ',' || *it == '.')
i++;
else if (*it == '-')
else if (*it == '-' || *it == locale().negativeSign().toAscii())
i++;
else // any non-number character
break;
@ -529,6 +530,10 @@ void InputField::wheelEvent (QWheelEvent * event)
void InputField::fixup(QString& input) const
{
input.remove(locale().groupSeparator());
if(locale().negativeSign() != QChar::fromAscii('-'))
input.replace(locale().negativeSign(), QChar::fromAscii('-'));
if(locale().positiveSign() != QChar::fromAscii('+'))
input.replace(locale().positiveSign(), QChar::fromAscii('+'));
}
QValidator::State InputField::validate(QString& input, int& pos) const
@ -536,7 +541,7 @@ QValidator::State InputField::validate(QString& input, int& pos) const
try {
Quantity res;
QString text = input;
text.remove(locale().groupSeparator());
fixup(text);
res = Quantity::parse(text);
double factor;

View File

@ -146,7 +146,7 @@ void QuantitySpinBox::userInput(const QString & text)
Base::Quantity res;
try {
QString input = text;
input.remove(locale().groupSeparator());
fixup(input);
res = Base::Quantity::parse(input);
}
catch (Base::Exception &e) {
@ -334,7 +334,7 @@ void QuantitySpinBox::selectNumber()
i++;
else if (*it == ',' || *it == '.')
i++;
else if (*it == '-')
else if (*it == '-' || *it == locale().negativeSign().toAscii())
i++;
else // any non-number character
break;
@ -359,7 +359,7 @@ Base::Quantity QuantitySpinBox::valueFromText(const QString &text) const
Q_D(const QuantitySpinBox);
QString copy = text;
copy.remove(locale().groupSeparator());
fixup( copy );
int pos = lineEdit()->cursorPosition();
QValidator::State state = QValidator::Acceptable;
return d->validateAndInterpret(copy, pos, state);
@ -371,7 +371,7 @@ QValidator::State QuantitySpinBox::validate(QString &text, int &pos) const
QValidator::State state;
QString copy = text;
copy.remove(locale().groupSeparator());
fixup(copy);
d->validateAndInterpret(copy, pos, state);
return state;
}
@ -379,6 +379,10 @@ QValidator::State QuantitySpinBox::validate(QString &text, int &pos) const
void QuantitySpinBox::fixup(QString &input) const
{
input.remove(locale().groupSeparator());
if(locale().negativeSign() != QChar::fromAscii('-'))
input.replace(locale().negativeSign(), QChar::fromAscii('-'));
if(locale().positiveSign() != QChar::fromAscii('+'))
input.replace(locale().positiveSign(), QChar::fromAscii('+'));
}