[SailfishDevel] Build a Model with "fixed" items + "dynamic" ones

François K. daitheflu at free.fr
Fri Apr 17 10:09:20 UTC 2015


Hi !

Today, my issue is probably more about Qt than SailfishOS, but I'd like to try my luck with you first :)

I want to build a list where the first 6 items are "fixed" (they have to always be here) and the following ones are retrieved from a database.
For each of these items, I'd like to also have the numbers of contained items (i.e. "My Project : 6 remaining tasks").

I came with 2 ideas to achieve this :

1/ The first one is to build a Model that would inherit from QAbstractListModel.
In the constructor, I would add the first 6 items (hard-code them).
Then I would add a QSqlQueryModel instance and try to keep things up-to-date, thanks to the signals/slots mechanism.
When updating the model, I would have to query the database 7 times (6 times for the hard-coded items, and 1 time for the following ones).
I would also have to be careful when updating the "dynamic" items, and do this smartly (remove items that don't exist anymore, add the new ones or modifiy the existing ones to avoid too much visual glitches, ...)
It seems a bit convoluted to me, but yeah...

2/ The second idea I have is to slightly modify my database scheme and build a view with UNION statements. Basically, I would have 7 SELECT statements UNIONed.
My Model would then consist in a basic QSqlQueryModel.
When updating the model, I would have to query the database just one time, and everything should update accordingly (magically).


I don't really know what is the best solution, mostly when it comes to performance. What do you guys think ? Any hint, tip or advice to achieve my goal ?

Thanks a lot :)

-- 
François


More information about the Devel mailing list