Skip to content

Commit

Permalink
+ proper handling of group separator in InputField and QuantitySpinBox
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jul 21, 2014
1 parent 81310c9 commit 2da263a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Gui/Application.cpp
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions src/Gui/InputField.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions src/Gui/QuantitySpinBox.cpp
Expand Up @@ -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());
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Gui/resource.cpp
Expand Up @@ -47,6 +47,7 @@
#include "DlgCustomizeSpaceball.h"
#include "DlgCustomizeSpNavSettings.h"
#include "InputField.h"
#include "QuantitySpinBox.h"

using namespace Gui;
using namespace Gui::Dialog;
Expand Down Expand Up @@ -100,4 +101,5 @@ WidgetFactorySupplier::WidgetFactorySupplier()
new WidgetProducer<Gui::UrlLabel>;
new WidgetProducer<Gui::FileChooser>;
new WidgetProducer<Gui::UIntSpinBox>;
new WidgetProducer<Gui::QuantitySpinBox>;
}

0 comments on commit 2da263a

Please sign in to comment.