Merge branch 'refs/heads/negative_sign_problem-2'

This commit is contained in:
jriegel 2014-08-10 19:12:39 +02:00
commit 1b4190b047
3 changed files with 22 additions and 10 deletions

View File

@ -55,7 +55,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){
@ -450,7 +450,9 @@ void InputField::setHistorySize(int i)
void InputField::selectNumber(void)
{
QByteArray str = text().toLatin1();
QString input = text();
fixup(input);
QByteArray str = input.toLatin1();
unsigned int i = 0;
for (QByteArray::iterator it = str.begin(); it != str.end(); ++it) {
@ -458,7 +460,7 @@ void InputField::selectNumber(void)
i++;
else if (*it == ',' || *it == '.')
i++;
else if (*it == '-')
else if (*it == '-' )
i++;
else // any non-number character
break;
@ -529,6 +531,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 +542,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) {
@ -326,7 +326,9 @@ void QuantitySpinBox::clear()
void QuantitySpinBox::selectNumber()
{
QByteArray str = lineEdit()->text().toLatin1();
QString input = lineEdit()->text();
fixup(input);
QByteArray str = input.toLatin1();
unsigned int i = 0;
for (QByteArray::iterator it = str.begin(); it != str.end(); ++it) {
@ -334,7 +336,7 @@ void QuantitySpinBox::selectNumber()
i++;
else if (*it == ',' || *it == '.')
i++;
else if (*it == '-')
else if (*it == '-' )
i++;
else // any non-number character
break;
@ -359,7 +361,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 +373,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 +381,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('+'));
}