+ proper handling of group separator in InputField and QuantitySpinBox

This commit is contained in:
wmayer 2014-07-21 15:03:45 +02:00
parent 81310c906b
commit 2da263ae95
4 changed files with 19 additions and 5 deletions

View File

@ -350,12 +350,14 @@ Application::Application(bool GUIenabled)
throw Base::Exception("Invalid system settings");
}
#endif
#if 0 // QuantitySpinBox and InputField try to handle the group separator now
// http://forum.freecadweb.org/viewtopic.php?f=10&t=6910
// A workaround is to disable the group separator for double-to-string conversion, i.e.
// setting the flag 'OmitGroupSeparator'.
QLocale loc = QLocale::system();
loc.setNumberOptions(QLocale::OmitGroupSeparator);
QLocale::setDefault(loc);
#endif
// setting up Python binding
Base::PyGILStateLocker lock;

View File

@ -180,7 +180,9 @@ void InputField::newInput(const QString & text)
{
Quantity res;
try {
res = Quantity::parse(text);
QString input = text;
input.remove(locale().groupSeparator());
res = Quantity::parse(input);
}
catch(Base::Exception &e){
ErrorText = e.what();
@ -524,13 +526,16 @@ void InputField::wheelEvent (QWheelEvent * event)
void InputField::fixup(QString& input) const
{
input.remove(locale().groupSeparator());
}
QValidator::State InputField::validate(QString& input, int& pos) const
{
try {
Quantity res;
res = Quantity::parse(input);
QString text = input;
text.remove(locale().groupSeparator());
res = Quantity::parse(text);
double factor;
QString unitStr;

View File

@ -145,7 +145,9 @@ void QuantitySpinBox::userInput(const QString & text)
Q_D(QuantitySpinBox);
Base::Quantity res;
try {
res = Base::Quantity::parse(text);
QString input = text;
input.remove(locale().groupSeparator());
res = Base::Quantity::parse(input);
}
catch (Base::Exception &e) {
d->errorText = QString::fromAscii(e.what());
@ -287,7 +289,7 @@ void QuantitySpinBox::stepBy(int steps)
else if (val < d->minimum)
val = d->minimum;
setValue(val);
lineEdit()->setText(QString::fromUtf8("%L1 %2").arg(val).arg(d->unitStr));
update();
selectNumber();
}
@ -354,6 +356,7 @@ Base::Quantity QuantitySpinBox::valueFromText(const QString &text) const
Q_D(const QuantitySpinBox);
QString copy = text;
copy.remove(locale().groupSeparator());
int pos = lineEdit()->cursorPosition();
QValidator::State state = QValidator::Acceptable;
return d->validateAndInterpret(copy, pos, state);
@ -364,7 +367,9 @@ QValidator::State QuantitySpinBox::validate(QString &text, int &pos) const
Q_D(const QuantitySpinBox);
QValidator::State state;
d->validateAndInterpret(text, pos, state);
QString copy = text;
copy.remove(locale().groupSeparator());
d->validateAndInterpret(copy, pos, state);
return state;
}

View File

@ -47,6 +47,7 @@
#include "DlgCustomizeSpaceball.h"
#include "DlgCustomizeSpNavSettings.h"
#include "InputField.h"
#include "QuantitySpinBox.h"
using namespace Gui;
using namespace Gui::Dialog;
@ -100,4 +101,5 @@ WidgetFactorySupplier::WidgetFactorySupplier()
new WidgetProducer<Gui::UrlLabel>;
new WidgetProducer<Gui::FileChooser>;
new WidgetProducer<Gui::UIntSpinBox>;
new WidgetProducer<Gui::QuantitySpinBox>;
}