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

Matthew Woehlke mwoehlke.floss at gmail.com
Fri Aug 16 17:03:16 CEST 2019


On 16/08/2019 09.27, Jérôme Godbout wrote:
> 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.

I honestly didn't follow any of that.

Right now, my work-around is to make all of my models subclass some
intermediate interface type (which itself subclasses QAbstractItemModel)
that provides an 'addRowWithData' method. This version doesn't take an
index; instead it *returns* the index where insertion happened. (Anyway,
the design of my models is that they present data in an arbitrary order,
with the expectation that a QSortFilterProxyModel will be used to
present them.)

> 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.

I don't see how this relates?

My model isn't using QVariantList. The actual model data is backed by a
custom container type that has specific ordering requirements. As a
result, users of the model cannot control the order in which rows are
inserted. Instead, they must ask to insert a row *with data*, and the
underlying container will determine *where* that rowdata *must* be inserted.

I don't need sorting. I need for users to be able to ask to insert a row
without specifying  *where* to insert the row.

-- 
Matthew



More information about the Interest mailing list