Qalculate / qalculate-gtk

Qalculate! GTK+ UI
https://qalculate.github.io/
GNU General Public License v2.0
968 stars 71 forks source link

Convert currency by typing in currency codes #206

Closed kidimbwi closed 3 years ago

kidimbwi commented 3 years ago

currently if we want to convert us dollar to albanian lek we have to type out 57, dollar and pick out U.S. Dollar from the list the type in albanian or lek to select Albanian Lek from the popup suggestions.

could you consider adding the ability to recognize currency codes when they are typed in ? so that when we type in usd, U.S. Dollars would be listed as a suggestion and when we type in all we would get the Albanian Lek as a suggestion.

Thank you.

hanna-kn commented 3 years ago

I would type $57 to ALL or 57USD to ALL (if $ conflicts with local currency symbol), or just $57 (if lek is the local currency).

Currency codes are case sensitive.

kidimbwi commented 3 years ago

Thank you for the suggestions, i did not know that currency codes are case sensitive. would you consider making them case insensitive ? this will enable users to skip having to hold down shift or enable caps in order to use currency codes in currency conversion.

hanna-kn commented 3 years ago

I decided not to make the currency codes case insensitive because of the potential conflicts, e.g. CUP (Cuban Pesos) and cup (≈ 0.237 L), and KGS and kilogram second (kgs). I will look into it again.

You also have the option to add keyboard shortcuts for individual units, or add derived units or variables with appropriate names (e.g. variable "usd" with value 1 USD).

kidimbwi commented 3 years ago

good suggestions, i'm continuing to find out that Qalculate! is even more fully featured than i knew.

i've noticed some interesting behaviour in the popup suggestions.

typing in CU

cu1

typing in cu

cu2

typing in GB (interesting to note that the two other units suggested are not shown when gb is typed in)

gb1

typing in gb

gb2

typing in CUP

cup1

typing in cup

cup2

so to summarise

in my view, and from very limited testing, making currency codes case insensitive will do more good than harm. as seen in the last example, making the currency code case insensitive will give a user the same suggestions that we are getting now with case sensitive currency codes.

an alternative method, though maybe more complex, would be to detect the first currency code typed in and restrict the subsequent suggestions to currency codes. so for example, if a user types in "58 CUP to" the suggestions after "to" would only be currencies because it would not make sense to convert Cuban Pesos to Parsecs. this could be part of a larger "smart suggestions" feature where suggestions during unit conversions will be restricted to units that are convertible to the starting unit. so if a user starts by typing in "58 pound_force" then "to" when the user types in "n" the popup suggestions will be restricted to units which pound_force can convert to.

Thank you again for your interest and please have a look at this feature.

hanna-kn commented 3 years ago

The completion list is first updated by comparing the current text string with names of objects (units, etc.). This is always case-sensitive to reduce the number of matches. The resulting matches are shown at the top of the list.

Additional objects are added to the list by comparing words in the title of the object and the countries of currencies. By default this requires a minimum length of two characters (this is also true for names of minor currencies).

To improve currencies matching, I will add case-insensitive name comparison to the latter ("gb" will then show GBP and "cup" will include CUP in the completion list). This change is of little consequence for other types of objects, since names with more than two characters seldom uses capital letters (and the name is often present in the title).

The completion behaviour can be customized in the preferences dialog.

an alternative method, though maybe more complex, would be to detect the first currency code typed in and restrict the subsequent suggestions to currency codes.

This is complicated by the fact that a complete implementation requires that the expression (before "to") is calculated before completion (for all but the simplest expressions the final units of the result might be different from the units present in the expression).

hanna-kn commented 3 years ago

Case insensitive currency codes, case insensitive completion (as title completion), and restricted completion in to-expression has now been implemented.

kidimbwi commented 3 years ago

excellent! Thank you for looking into this and implementing this, your effort is greatly appreciated.