[Interest] Add row to model *with data*?

Jérôme Godbout godboutj at amotus.ca
Fri Aug 16 15:27:43 CEST 2019


Maybe you can add a type to your model and make a map of type to Component, when initalizing the view element, use a Loader that will create the proper Item view based on your type. Not sure this is what you are looking for.

As for sorting, if you use a QVariantList, you can call javascript sort() on the array if you have a small list or you could make your own method in C++ that will sort the element. Note, if you use the QQmlListProperty binding on content might not be notified of changed for the method to be revaluate properly (since the list doesn't emit changed when content changes).

-----Original Message-----
From: Interest <interest-bounces at qt-project.org> On Behalf Of Matthew Woehlke
Sent: August 15, 2019 5:42 PM
To: qt qt <interest at qt-project.org>
Subject: [Interest] Add row to model *with data*?

So... I have a (subclass of) QAbstractItemModel. This class internally represents data using some other container, which has specific requirements on both the item, and on the order of items. Thus, I can't just add rows anywhere and with no data, to be filled in later.

My users are intended to work with *just* the QAbstractItemModel API. (I eventually expect to have multiple model implementations.)

Is there any way, with the existing QAbstractItemModel API, to specify the data that the row should contain in the same call that adds the row?
Even better, is there any way to ask the model to add a row, with data, but *not* specify where the row is to be added? (The model would then return the new row index, or -1 if it could not complete the operation as requested.)

If not, is this something that would make sense to add?

--
Matthew
_______________________________________________
Interest mailing list
Interest at qt-project.org
https://lists.qt-project.org/listinfo/interest


More information about the Interest mailing list