Problem with negative values in InputField

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
User avatar
DevJohan
Posts: 41
Joined: Sun Jul 13, 2014 2:36 pm
Location: Stockholm, Sweden

Re: Problem with negative values in InputField

Postby DevJohan » Thu Jul 31, 2014 11:18 am

I don't know if extending the parser to include more unicode characters is the the right way to go. This increases the complexity of the parser without much gain. What I propose is to complement InputField::fixup(...) and QuantitySpinBox::fixup(...) to read something like

Code: Select all

void CLASS_NAME::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('+'));
}
and call this function before sending the code to the parser. Another similar replacement would be the decimal point character which at the moment both '.' and ',' is accepted by the parser. From what I've read german locale uses '.' for group separation and ',' as the decimal point. For me the most intuitive would be to either make the parser locale aware or removing locale specific constructs prior to parsing.
User avatar
jriegel
Site Admin
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Problem with negative values in InputField

Postby jriegel » Thu Jul 31, 2014 12:12 pm

Its no problem, since the Lex/Yacc style parsers are always seperated in scanner and parser. I can make the scanner read any kind of UTF8 sequence as minus token.

I think I will tackle also the number group thing in the parser. That will allow any kind of number grouping working....
* 1.3434.334,44234mm
* 1,2323,234.345345in

It will be a tricky regex, but should be be doable....

I will not allow
* 123,232in as grouping
you have to write at least:
* 123,232.0in
Stop whining - start coding!
wmayer
Site Admin
Posts: 15756
Joined: Thu Feb 19, 2009 10:32 am

Re: Problem with negative values in InputField

Postby wmayer » Thu Jul 31, 2014 1:26 pm

And what about ?
* 1,3434,334.44234mm
* 1.2323.234,345345in
i.e. German group separator combined with imperial units. The point is group and decimal separator are system settings while the unit system is a user setting.
User avatar
jriegel
Site Admin
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Problem with negative values in InputField

Postby jriegel » Thu Jul 31, 2014 5:28 pm

Since the number and unit interpretation are separate, both will work.

My aim is to keep the unit parser locale agnostic since it is in the base system. If FreeCAD runs headless or by scripts, no locale is set...
Stop whining - start coding!
User avatar
jriegel
Site Admin
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Problem with negative values in InputField

Postby jriegel » Thu Jul 31, 2014 7:54 pm

I can use the minus, but the other group seperators are to strange.

I will only support dot and comma....
Stop whining - start coding!
wmayer
Site Admin
Posts: 15756
Joined: Thu Feb 19, 2009 10:32 am

Re: Problem with negative values in InputField

Postby wmayer » Thu Jul 31, 2014 9:33 pm

I think that's fine.
User avatar
jriegel
Site Admin
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Problem with negative values in InputField

Postby jriegel » Sun Aug 03, 2014 5:01 pm

Ok I added the special minus. Please test someone with Swedish keyboard :)

I did not get the locale agnostic groups managed. So I would fall back to the DevJohans solution and replace critical chars in front of the parser.

@DevJohan
You have a working branch? Then I can pull and test....
Stop whining - start coding!
obbe
Posts: 2
Joined: Wed Jul 30, 2014 12:17 pm

Re: Problem with negative values in InputField

Postby obbe » Mon Aug 04, 2014 3:52 pm

I tried to download and compile it, but the dependencies are huge, so I don't have the space on my hard drive.

But isn't it enough with pasting the offending character (− I believe)? Without being an expert, the fix seemed global.
User avatar
ralvejd
Posts: 58
Joined: Wed Feb 20, 2013 10:31 pm
Location: Sweden

Re: Problem with negative values in InputField

Postby ralvejd » Tue Aug 05, 2014 8:51 pm

jriegel wrote:Ok I added the special minus. Please test someone with Swedish keyboard :)
The Swede has tested, the minus sign works fine now. :)
I even tried to use the . or , for decimal numbers, they worked both.
The . was nicely replaced with a , automatically.
The test is carried out with the Placement dialogue in Part Design.

On behalf of all 9 million Swedes , I thank you!

OS: Debian GNU/Linux 7.6 (wheezy)
Word size: 64-bit
Version: 0.15.3829 (Git)
Branch: master
Hash: 234af5b27f997ee3e5dfa86e76ffe5521b31d532
Python version: 2.7.3
Qt version: 4.8.2
Coin version: 3.1.3
SoQt version: 1.5.0
OCC version: 6.7.0
sorry for my outrageous English, but I have a bad excuse
User avatar
jriegel
Site Admin
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Problem with negative values in InputField

Postby jriegel » Wed Aug 06, 2014 8:10 am

:D
ralvejd wrote:
jriegel wrote: On behalf of all 9 million Swedes , I thank you!
Your welcome!
Stop whining - start coding!