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

2019-08-16 Thread Matthew Woehlke
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
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


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

2019-08-16 Thread Jérôme Godbout
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  On Behalf Of Matthew Woehlke
Sent: August 15, 2019 5:42 PM
To: qt qt 
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@qt-project.org
https://lists.qt-project.org/listinfo/interest
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


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

2019-08-16 Thread Giuseppe D'Angelo via Interest

Il 15/08/19 23:42, Matthew Woehlke ha scritto:

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


There isn't such an API. Maybe you can fake it via a drop?

My 2 c,

--
Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts



smime.p7s
Description: Firma crittografica S/MIME
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


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

2019-08-15 Thread Matthew Woehlke
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@qt-project.org
https://lists.qt-project.org/listinfo/interest