INIshell-ng

Issue 835: The precision of numeric fields should accomodate what the user provides

Reported by Mathias Bavay, Apr 23, 2020

The problem is that by filters, the precision depends on the meteo 
parameter more than the filter itself (ex: a MAX on TA is fine with  
no decimal while on RH it will require 2 decimals at least).

The way to go would be to accept whatever precision the user 
provides in his/her input.

Comment 1 by Michael Reisecker, Apr 24, 2020

It does that though, no?

Comment 2 by Mathias Bavay, Apr 26, 2020

No, if the precision is set to 2, the user can not enter something 
like "1.3452", it will "block" after the second 
decimal. So my first test users complained they could not enter the 
values they (rightly) wanted to.

Something like exposed here would do it: 
https://github.com/Ulm-IQO/qudi/blob/48a6df40713bc66af6e4f4c7dad5c587
6f68f5b9/qtwidgets/scientific_spinbox.py#L803

Or we could simply set a very large precision and let it be...

Comment 3 by Mathias Bavay, Apr 26, 2020

Or maybe (thinking out loud): we could set the default precision to 
something large (8?), remove the precision specification from all 
the filters (since here depending on the parameter it will be used 
on, the precision will change) and only set precision on the few 
places where it is unambiguous (like for the time zone: 2 decimals 
should accommodate all currently existing time zones)...

Comment 4 by Michael Reisecker, Apr 26, 2020

Ah through the GUI you mean, yeah, that can't work of course, cf. 
ticket 825.

It does adapt to INI keys though, so it can be set in the INI file, 
through the preview editor (by loading back), and as an expression.

Maybe something like the following could be expanded to hack 
something together, but probably not too quickly.

if ((key_event->key() >= Qt::Key_0 && 
key_event->key() <= Qt::Key_9) || (key_event->key() == 
Qt::Key_Minus)) {
  if (object->property("empty").toBool()) {
    //(...)
  } else {
    if (auto *spinbox = qobject_cast<QDoubleSpinBox 
*>(object)) {
      spinbox->setDecimals(spinbox->decimals() + 1);
      //more fixing here
    }
  } //endif property
} //endif key_event
Relations: is related to 825

Comment 5 by Michael Reisecker, Apr 26, 2020

Another note: The line from your link is in 
Number::getPrecisionOfNumber(), but to make use of it you'd need to 
set an underlying model for the SpinBox which translates some kind 
of text format to the actual numeric value. I think this is useless 
here because our numbers aren't of a special format and we already 
have that anyway (the text field, which in this case doesn't need 
the ${{..}}). But maybe I'm misremembering how changing the SpinBox 
model works...

Created: 5 months 26 days ago by Mathias Bavay

Updated: 5 months 23 days ago

Status: New

Followed by: 1 person

Labels:
Priority:Critical
Type:Defect

This issue is related to
825 - Bug...dling of decimal numbers