Hi Artem, Ok, our analysis of the problem agrees :)
As I said, I'd make a C++ model for this. The reason is that it's just so annoying to manipulate models in QML. You can do it, but the code will feel much simpler in C++. It's also a very common split - to have the backend completely in C++ and the frontend in QML. This is what most end up with as a preferred design for complex QML applications. Bo. Den 20-04-2012 10:42, Artem Marchenko skrev: > Thanks, Bo > > Your UI > obviously mixes concepts in the same area, which is why you have a > problem with the low-end model code. > > Indeed it is so. To be precise, there are two conceptually different, > yet related models. > > 1. One is to have a contact list coming from the messenger API. OK, I > add a couple of custom properties, yet it is still pretty much an > external contact list and it would be good to keep it this way - easier > to verify, easier to sync (I don't trust messenger API much, so it's > good to have isolated point of contact). > > 2. Another one is the model for list shown in the UI. That can have an > extra item (my own contacts) or maybe even hide some item (voice test > contact always provided by a messenger). > > These two models are indeed conceptually different yet one can be > transformed into another one using a couple of clear and simple rules. > > *Options* > So what I am asking for is an advice (or maybe somebody even has similar > experience) on how to do such a transformation. One possibility is to to > make 2nd model in a pure QML (manipulate ListModel whenever c++ model > changes). Another one is to have 2nd model in C++. Another option is to > have just one model on a C++ side, inject and remove items there and/or > maybe have special attribute to tell whether a particular item is hidden. > > Cheers, > Artem. > >> Bo Thorsen <mailto:b...@fioniasoftware.dk> >> 20 квітня 2012 р. 11:20 >> >> Yes, you can do this in QML, coupled with some Javascript and signal >> handlers. But why on earth would you want to, when it's so much easier >> to have it in the model? If you want to, you can add a bool flag on each >> item that says if it's your special item or not. >> >> Let it sit in the model, it's *by far* the easiest for you. >> >> If you are worried about tainting your model with something that doesn't >> match the concept it models, then you're on the wrong track. Your UI >> obviously mixes concepts in the same area, which is why you have a >> problem with the low-end model code. >> >> Fix your UI to not show a special item that is a different concept, or >> accept that you should add it to the model. I would choose one of those >> two options, because the others are worse. >> >> Bo Thorsen, >> Fionia Software. >> >> Artem Marchenko <mailto:artem.marche...@gmail.com> >> 20 квітня 2012 р. 01:53 >> Hi All >> >> I've go a model coming from C++ (Inhertited from >> QAbstractListItemModel) that is basically a list of contact for an >> instant messenger. >> >> App's UI, however, is to include one more special contact representing >> the current user (it makes sense on our devices with extremely >> discouraged chrome elements such as extra headers, scrollbars, etc). >> >> I can certainly, modify the model on C++ side, yet.. this special item >> is really just about the UI representation and therefore it seems very >> logical to me to perform such a modification in QML side. Is there a >> way to somehow inject an item into a model coming from C++? Or maybe >> there is a way to apply some rules to C++ model and make a QML >> ListModel or something like that as a result? >> >> Or how would you do it? >> >> Cheers, >> Artem. >> >> P.S. >> In most of cases there are going to be just a few elements in the >> model so cloning of model if needed shouldn't effect performance and >> memory use much Bo Thorsen, Fionia Software. -- Expert Qt and C++ developer for hire Contact me if you need expert Qt help http://www.fioniasoftware.dk _______________________________________________ Qt-qml mailing list Qt-qml@qt.nokia.com http://lists.qt.nokia.com/mailman/listinfo/qt-qml