[SailfishDevel] Build a Model with "fixed" items + "dynamic" ones
Lucien Xu
sfietkonstantin at free.fr
Fri Apr 17 10:12:38 UTC 2015
Hi François,
Can't you simply make the hard-coded entries dynamic too. Just add a column in the db saying that these entries are the hardcoded ones ? With this, you got only one query.
And when doing db stuff, don't forget to use transactions. It can help speeding up stuff a lot.
Regards,
Lucien
----- Mail original -----
> De: "François K." <daitheflu at free.fr>
> À: "Sailfish OS Developers" <devel at lists.sailfishos.org>
> Envoyé: Vendredi 17 Avril 2015 12:09:20
> Objet: [SailfishDevel] Build a Model with "fixed" items + "dynamic" ones
>
> 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
> _______________________________________________
> SailfishOS.org Devel mailing list
> To unsubscribe, please send a mail to
> devel-unsubscribe at lists.sailfishos.org
More information about the Devel
mailing list