Set price precision on every security
ClosedPublic

Authored by wojnilowicz on Apr 9 2017, 7:10 PM.

Details

Summary

Lots of code has been changed. In general, this patch intends to replace global price precision with price precision per security. Thanks to this every security is displayed with proper price precision and not highest of all securities.

Things changed:

  1. removed partsPerUnit - no usage anywhere
  2. added pricePrecision - defaults to 4 but can be lowered as low as 2
  3. added edit button to Tools->Currencies - allows setting pricePrecision for currencies
  4. added pricePrecision to investment details dialog
  5. removed "show national currencies" from investment view - it wasn't available without any investment, so it wasn't versatile
  6. replaced tandem of precToDenom and convert to convertPrecision - it's more concise
  7. smallestAccountFraction, smallestCashFraction and pricePrecision are checked for validity before loading from .kmy file
  8. added yLabelsPrecison for graphs - user decides what precision he should get on y axis
  9. removed some warnings from mymoneyreport and mymoneysecurity during compilation

Diff Detail

Repository
R261 KMyMoney
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
wojnilowicz edited the summary of this revision. (Show Details)Apr 10 2017, 5:12 PM
tbaumgart requested changes to this revision.Apr 10 2017, 6:18 PM
tbaumgart added a subscriber: tbaumgart.
tbaumgart added inline comments.
kmymoney/dialogs/kcurrencyeditordlg.cpp
49

Why don't you use MyMoneyMoney and it's formatMoney method here? Using double is what we try to avoid as much as possible.

kmymoney/mymoney/mymoneysecurity.h
62

Either use

const int xxx = 4

or

#define xxx 4

but not both, please.

This revision now requires changes to proceed.Apr 10 2017, 6:18 PM
wojnilowicz added inline comments.Apr 10 2017, 6:27 PM
kmymoney/mymoney/mymoneysecurity.h
62

Yes, but I use DEFAULT_CASH_FRACTION also for MyMoneySecurity() in mymoneysecurity.cpp. I want them to be consistent and defined by single DEFAULT_CASH_FRACTION.
How can it be done otherway?

wojnilowicz edited edge metadata.
wojnilowicz marked an inline comment as done.

Thomas,
I would like to commit this patch. Are you still against #define?

Łukasz

tbaumgart added inline comments.Apr 15 2017, 10:12 AM
kmymoney/mymoney/mymoneysecurity.h
62

I think you can do it as follows:

in the .h file you declare a private member

static const int DEFAULT_ACCOUNT_FRACTION;

in the .cpp file you define this variable as follows (outside any method)

static const int MyMoneySecurity::DEFAULT_ACCOUNT_FRACTION = 4;

and in the ctor you write

smallestAccountFraction = DEFAULT_ACCOUNT_FRACTION;

In case you need the constant outside the scope of MyMoneySecurity, make the member variable public. You can then use MyMoneySecurity::DEFAULT_ACCOUNT_FRACTION in other contexts.

Note: I am not 100% sure that this will work, but have seen and used similar constructions in other code. In case you can't achieve what you want go for the #define way.

wojnilowicz marked 3 inline comments as done.Apr 15 2017, 1:17 PM
wojnilowicz added inline comments.
kmymoney/mymoney/mymoneysecurity.h
62

I did it without #defines but a little bit simpler.
Now it looks like eSECURITYTYPE.

wojnilowicz abandoned this revision.Apr 15 2017, 1:17 PM
wojnilowicz marked an inline comment as done.
This revision was automatically updated to reflect the committed changes.