+ proper handling of group separator in InputField and QuantitySpinBox
This commit is contained in:
parent
81310c906b
commit
2da263ae95
|
@ -350,12 +350,14 @@ Application::Application(bool GUIenabled)
|
||||||
throw Base::Exception("Invalid system settings");
|
throw Base::Exception("Invalid system settings");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#if 0 // QuantitySpinBox and InputField try to handle the group separator now
|
||||||
// http://forum.freecadweb.org/viewtopic.php?f=10&t=6910
|
// 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.
|
// A workaround is to disable the group separator for double-to-string conversion, i.e.
|
||||||
// setting the flag 'OmitGroupSeparator'.
|
// setting the flag 'OmitGroupSeparator'.
|
||||||
QLocale loc = QLocale::system();
|
QLocale loc = QLocale::system();
|
||||||
loc.setNumberOptions(QLocale::OmitGroupSeparator);
|
loc.setNumberOptions(QLocale::OmitGroupSeparator);
|
||||||
QLocale::setDefault(loc);
|
QLocale::setDefault(loc);
|
||||||
|
#endif
|
||||||
|
|
||||||
// setting up Python binding
|
// setting up Python binding
|
||||||
Base::PyGILStateLocker lock;
|
Base::PyGILStateLocker lock;
|
||||||
|
|
|
@ -180,7 +180,9 @@ void InputField::newInput(const QString & text)
|
||||||
{
|
{
|
||||||
Quantity res;
|
Quantity res;
|
||||||
try {
|
try {
|
||||||
res = Quantity::parse(text);
|
QString input = text;
|
||||||
|
input.remove(locale().groupSeparator());
|
||||||
|
res = Quantity::parse(input);
|
||||||
}
|
}
|
||||||
catch(Base::Exception &e){
|
catch(Base::Exception &e){
|
||||||
ErrorText = e.what();
|
ErrorText = e.what();
|
||||||
|
@ -524,13 +526,16 @@ void InputField::wheelEvent (QWheelEvent * event)
|
||||||
|
|
||||||
void InputField::fixup(QString& input) const
|
void InputField::fixup(QString& input) const
|
||||||
{
|
{
|
||||||
|
input.remove(locale().groupSeparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
QValidator::State InputField::validate(QString& input, int& pos) const
|
QValidator::State InputField::validate(QString& input, int& pos) const
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Quantity res;
|
Quantity res;
|
||||||
res = Quantity::parse(input);
|
QString text = input;
|
||||||
|
text.remove(locale().groupSeparator());
|
||||||
|
res = Quantity::parse(text);
|
||||||
|
|
||||||
double factor;
|
double factor;
|
||||||
QString unitStr;
|
QString unitStr;
|
||||||
|
|
|
@ -145,7 +145,9 @@ void QuantitySpinBox::userInput(const QString & text)
|
||||||
Q_D(QuantitySpinBox);
|
Q_D(QuantitySpinBox);
|
||||||
Base::Quantity res;
|
Base::Quantity res;
|
||||||
try {
|
try {
|
||||||
res = Base::Quantity::parse(text);
|
QString input = text;
|
||||||
|
input.remove(locale().groupSeparator());
|
||||||
|
res = Base::Quantity::parse(input);
|
||||||
}
|
}
|
||||||
catch (Base::Exception &e) {
|
catch (Base::Exception &e) {
|
||||||
d->errorText = QString::fromAscii(e.what());
|
d->errorText = QString::fromAscii(e.what());
|
||||||
|
@ -287,7 +289,7 @@ void QuantitySpinBox::stepBy(int steps)
|
||||||
else if (val < d->minimum)
|
else if (val < d->minimum)
|
||||||
val = d->minimum;
|
val = d->minimum;
|
||||||
|
|
||||||
setValue(val);
|
lineEdit()->setText(QString::fromUtf8("%L1 %2").arg(val).arg(d->unitStr));
|
||||||
update();
|
update();
|
||||||
selectNumber();
|
selectNumber();
|
||||||
}
|
}
|
||||||
|
@ -354,6 +356,7 @@ Base::Quantity QuantitySpinBox::valueFromText(const QString &text) const
|
||||||
Q_D(const QuantitySpinBox);
|
Q_D(const QuantitySpinBox);
|
||||||
|
|
||||||
QString copy = text;
|
QString copy = text;
|
||||||
|
copy.remove(locale().groupSeparator());
|
||||||
int pos = lineEdit()->cursorPosition();
|
int pos = lineEdit()->cursorPosition();
|
||||||
QValidator::State state = QValidator::Acceptable;
|
QValidator::State state = QValidator::Acceptable;
|
||||||
return d->validateAndInterpret(copy, pos, state);
|
return d->validateAndInterpret(copy, pos, state);
|
||||||
|
@ -364,7 +367,9 @@ QValidator::State QuantitySpinBox::validate(QString &text, int &pos) const
|
||||||
Q_D(const QuantitySpinBox);
|
Q_D(const QuantitySpinBox);
|
||||||
|
|
||||||
QValidator::State state;
|
QValidator::State state;
|
||||||
d->validateAndInterpret(text, pos, state);
|
QString copy = text;
|
||||||
|
copy.remove(locale().groupSeparator());
|
||||||
|
d->validateAndInterpret(copy, pos, state);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
#include "DlgCustomizeSpaceball.h"
|
#include "DlgCustomizeSpaceball.h"
|
||||||
#include "DlgCustomizeSpNavSettings.h"
|
#include "DlgCustomizeSpNavSettings.h"
|
||||||
#include "InputField.h"
|
#include "InputField.h"
|
||||||
|
#include "QuantitySpinBox.h"
|
||||||
|
|
||||||
using namespace Gui;
|
using namespace Gui;
|
||||||
using namespace Gui::Dialog;
|
using namespace Gui::Dialog;
|
||||||
|
@ -100,4 +101,5 @@ WidgetFactorySupplier::WidgetFactorySupplier()
|
||||||
new WidgetProducer<Gui::UrlLabel>;
|
new WidgetProducer<Gui::UrlLabel>;
|
||||||
new WidgetProducer<Gui::FileChooser>;
|
new WidgetProducer<Gui::FileChooser>;
|
||||||
new WidgetProducer<Gui::UIntSpinBox>;
|
new WidgetProducer<Gui::UIntSpinBox>;
|
||||||
|
new WidgetProducer<Gui::QuantitySpinBox>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user