[Kmymoney-devel] An improvement opportunity in the accounts model?
Alvaro Soliverez
asoliverez at kde.org
Sat Feb 5 19:27:45 CET 2011
Hello all,
I've been working extensively on models in my daily job for the last 4
months. As a result of that, I've learned some tricks regarding Qt MVC
that might be of benefit for KMyMoney.
Currently, the AccountsModel goes through all accounts, and it stores
all the data required by the model in the model itself. Correct me if
I'm wrong, but this is done every time a fileChanged signal is
emitted.
For files with a large amount of accounts, this can prove to be time-consuming.
There's in an alternative to this load-every-time-something-changes algorithm.
Instead, store the list of accounts, the pure objects, and overload
the data() method to call the Account object and get the data
as-needed. A dataChanged signal has to be connected to the fileChanged
signal, so that the model clears its cache.
This way, only the data that needs to be displayed will be loaded by
the model, and not the whole accounts tree and its data has to be
loaded every time.
To summarize, instead of storing the data in roles within the model
(and reload it all every time something changes), we store the
original objects and overload the data() to access the original object
when the data is needed.
Just something that I think could add some performance. Models
resulting of this method are much simpler also, which aids
maintainability.
Regards,
Alvaro
More information about the KMyMoney-devel
mailing list