Bug 492100

Summary: [Feature] Update input when changing bases
Product: [Applications] kcalc Reporter: David Harty <kde>
Component: generalAssignee: Gabriel Barrantes <gabriel.barrantes.dev>
Status: CONFIRMED ---    
Severity: normal CC: benny, ekigwana, gabriel.barrantes.dev, net147, xypron.glpk
Priority: NOR    
Version First Reported In: 24.05.2   
Target Milestone: ---   
Platform: Manjaro   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Conversion from Hex to Decimal

Description David Harty 2024-08-23 19:34:08 UTC
Created attachment 172890 [details]
Conversion from Hex to Decimal

***
If you're not sure this is actually a bug, instead post about it at https://discuss.kde.org

If you're reporting a crash, attach a backtrace with debug symbols; see https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports
***

SUMMARY
KCalc doesn't switch between 

STEPS TO REPRODUCE
1. Go into numeric system mode.
2. Enter a number in Decimal mode.
3. Hit Enter (this didn't used to be required)
3. Switch to Hex mode.

OBSERVED RESULT
Upon hitting enter the equivalent notation for the entered value appears in Hex, Dec, Oct and Binary.
However when switching to any of those notations, the value in the readout/enter area remains Decimal.
This occurs also when switching from any mode to any other.

EXPECTED RESULT
The numeric system values used to be automatically updated in the numeric system representations as it was typed.
More importantly, in prior versions, kcalc would switch the value in the calculation area to the selected notation. 
This is important to users if they want to add 145 decimal to 0xFE hex.
There is also not an easy way to copy a numeric system value. EG I entered FA into Hex, it shows 250 in Decimal, but I can't copy it or otherwise use that value.

SOFTWARE/OS VERSIONS
Linux: 6.9.12-3-MANJARO
KDE Plasma: 
KDE Plasma Version: 6.0.5
KDE Frameworks Version: 6.5.0
Qt Version: 6.7.2
6.0.5


ADDITIONAL INFORMATION
In the attached screenshot. I started in hex and entered FA. Then I switched to decimal and attempted to add 120 to FA, however the calculation fails because FA was not converted to Decimal when switching.
Comment 1 Gabriel Barrantes 2024-08-24 01:11:14 UTC
Try the latest version (24.08), the new numeral system view allows copying the values.

This is something that might get fix at some point (not even Qalculate does it) but changing bases is not currently updating the input display, you can just type 0xfa+120 (in decimal mode).
Comment 2 Gabriel Barrantes 2024-09-12 18:26:32 UTC
*** Bug 493019 has been marked as a duplicate of this bug. ***
Comment 3 Edward Kigwana 2024-11-19 20:38:25 UTC
This has been working my nerves for a bit now. I imagine this simply needs an input state tracker.
E.g.

When one enters DEC 16 the tracker stores DEC.
When one changes base to HEX, the input is updated by converting DEC 16 to HEX 10 and the state tracker then gets changed to HEX.

At the moment the action above converts DEC 16 to HEX 16 which does not make any sense since DEC 16 != HEX 16. HEX 9 to OCT waits for a request for results before complaining about a syntax error.

It seems we need an input regex for each mode as well so that invalid input is also not possible.
Comment 4 Gabriel Barrantes 2024-11-20 00:35:14 UTC
(In reply to Edward Kigwana from comment #3)
> This has been working my nerves for a bit now. I imagine this simply needs
> an input state tracker.
> E.g.
> 
> When one enters DEC 16 the tracker stores DEC.
> When one changes base to HEX, the input is updated by converting DEC 16 to
> HEX 10 and the state tracker then gets changed to HEX.
> 
> At the moment the action above converts DEC 16 to HEX 16 which does not make
> any sense since DEC 16 != HEX 16. HEX 9 to OCT waits for a request for
> results before complaining about a syntax error.
> 
> It seems we need an input regex for each mode as well so that invalid input
> is also not possible.

is not that simple because inputs can be many things now, not a single number that can be easily converted.
To convert 10+20+30 for example all the numbers will need to be found and then converted and replaced in the string. Not even Qalculate is doing it...
Comment 5 Edward Kigwana 2024-11-20 15:23:04 UTC
(In reply to Gabriel Barrantes from comment #4)
> (In reply to Edward Kigwana from comment #3)
> > This has been working my nerves for a bit now. I imagine this simply needs
> > an input state tracker.
> > E.g.
> > 
> > When one enters DEC 16 the tracker stores DEC.
> > When one changes base to HEX, the input is updated by converting DEC 16 to
> > HEX 10 and the state tracker then gets changed to HEX.
> > 
> > At the moment the action above converts DEC 16 to HEX 16 which does not make
> > any sense since DEC 16 != HEX 16. HEX 9 to OCT waits for a request for
> > results before complaining about a syntax error.
> > 
> > It seems we need an input regex for each mode as well so that invalid input
> > is also not possible.
> 
> is not that simple because inputs can be many things now, not a single
> number that can be easily converted.
> To convert 10+20+30 for example all the numbers will need to be found and
> then converted and replaced in the string. Not even Qalculate is doing it...

I agree it is not simple and only discussed the simple case as an illustrative case. If the input is restricted to one base then it is a matter of using a regex to capture the values and tokens. For the case of the current input it should then be straight forward to do the conversion and leave history alone especially since the history results indicate base.
Comment 6 Gabriel Barrantes 2024-11-20 19:18:43 UTC
(In reply to Edward Kigwana from comment #5)
> (In reply to Gabriel Barrantes from comment #4)
> > (In reply to Edward Kigwana from comment #3)
> > > This has been working my nerves for a bit now. I imagine this simply needs
> > > an input state tracker.
> > > E.g.
> > > 
> > > When one enters DEC 16 the tracker stores DEC.
> > > When one changes base to HEX, the input is updated by converting DEC 16 to
> > > HEX 10 and the state tracker then gets changed to HEX.
> > > 
> > > At the moment the action above converts DEC 16 to HEX 16 which does not make
> > > any sense since DEC 16 != HEX 16. HEX 9 to OCT waits for a request for
> > > results before complaining about a syntax error.
> > > 
> > > It seems we need an input regex for each mode as well so that invalid input
> > > is also not possible.
> > 
> > is not that simple because inputs can be many things now, not a single
> > number that can be easily converted.
> > To convert 10+20+30 for example all the numbers will need to be found and
> > then converted and replaced in the string. Not even Qalculate is doing it...
> 
> I agree it is not simple and only discussed the simple case as an
> illustrative case. If the input is restricted to one base then it is a
> matter of using a regex to capture the values and tokens. For the case of
> the current input it should then be straight forward to do the conversion
> and leave history alone especially since the history results indicate base.

I might do it at some point, but you can enter prefixes 0x, 0o and 0b, and the numeral system view shows the result for all the other bases.
Comment 7 Gabriel Barrantes 2024-12-06 18:00:11 UTC
*** Bug 497112 has been marked as a duplicate of this bug. ***
Comment 8 Heinrich Schuchardt 2025-01-03 22:31:50 UTC
(In reply to Gabriel Barrantes from comment #6)

>> numeral system view shows the result for all the other bases

This is of limited value as these values cannot be copied.
Comment 9 Gabriel Barrantes 2025-01-04 17:32:49 UTC
(In reply to Heinrich Schuchardt from comment #8)
> (In reply to Gabriel Barrantes from comment #6)
> 
> >> numeral system view shows the result for all the other bases
> 
> This is of limited value as these values cannot be copied.

They can, right click on them