Qt-interest Archive, May 2007
how to use this method
Message 1 in thread
I have problems with QPersistentModelIndex. I found the method
QAbstractItemModel::changePersistentIndexList which might solve some
problems, but I have no idea when I should use that method (before or
after the model was changed), or if I should use it at all (or does the
model handle this for me).
Any hint would be of great value to me.
M
--
[ signature omitted ]
Message 2 in thread
On Tuesday 08 May 2007 13:44:20 QMartin wrote:
> I have problems with QPersistentModelIndex. I found the method
> QAbstractItemModel::changePersistentIndexList which might solve some
> problems, but I have no idea when I should use that method (before or
> after the model was changed), or if I should use it at all (or does the
> model handle this for me).
>
> Any hint would be of great value to me.
>
> M
You want to use that function in conjunction with layoutChanged()
http://doc.trolltech.com/4.2/qabstractitemmodel.html#layoutChanged
If you add/remove rows/columns through the normal means the model will
automatically update the persistant index's,
-Benjamin Meyer
--
[ signature omitted ]
Message 3 in thread
Benjamin Meyer wrote:
> On Tuesday 08 May 2007 13:44:20 QMartin wrote:
>> I have problems with QPersistentModelIndex. I found the method
>> QAbstractItemModel::changePersistentIndexList which might solve some
>> problems, but I have no idea when I should use that method (before or
>> after the model was changed), or if I should use it at all (or does the
>> model handle this for me).
>>
>> Any hint would be of great value to me.
>>
>> M
>
> You want to use that function in conjunction with layoutChanged()
>
> http://doc.trolltech.com/4.2/qabstractitemmodel.html#layoutChanged
>
> If you add/remove rows/columns through the normal means the model will
> automatically update the persistant index's,
Hi Benjamin. Thanks for your answer!
"add/remove rows/columns through the normal means".... meaning
#insertRow etc.? My model wraps a Qt-unaware object model which handles
adding and removing of data. The model just reacts on changes in its
base object model, so I cannot use #insertRow but rather use
#beginInsertRows and #endInsertRows to notify attached views that the
base data was altered. Does that mean that I cannot use persistent model
indices with such a setup?
Thanks!
--
[ signature omitted ]
Message 4 in thread
On Tuesday 08 May 2007 16:04:52 QMartin wrote:
> Benjamin Meyer wrote:
> > On Tuesday 08 May 2007 13:44:20 QMartin wrote:
> >> I have problems with QPersistentModelIndex. I found the method
> >> QAbstractItemModel::changePersistentIndexList which might solve some
> >> problems, but I have no idea when I should use that method (before or
> >> after the model was changed), or if I should use it at all (or does the
> >> model handle this for me).
> >>
> >> Any hint would be of great value to me.
> >>
> >> M
> >
> > You want to use that function in conjunction with layoutChanged()
> >
> > http://doc.trolltech.com/4.2/qabstractitemmodel.html#layoutChanged
> >
> > If you add/remove rows/columns through the normal means the model will
> > automatically update the persistant index's,
>
> Hi Benjamin. Thanks for your answer!
>
> "add/remove rows/columns through the normal means".... meaning
> #insertRow etc.? My model wraps a Qt-unaware object model which handles
> adding and removing of data. The model just reacts on changes in its
> base object model, so I cannot use #insertRow but rather use
> #beginInsertRows and #endInsertRows to notify attached views that the
> base data was altered. Does that mean that I cannot use persistent model
> indices with such a setup?
>
> Thanks!
For most views, insertRows() doesn't do anything. As long as you use
beginInsertRows() and endInsertRows() persistant model indices will be
updated. Usually the persistant model index's are used outside of the model
and not internally.
It sounds like you are learning about models and writing your first one, it
might be worthwhile to check out the model test tool on labs. You can plug
your model into it and it will catch a handful of mistakes and edge cases.
http://labs.trolltech.com/page/Projects/Itemview/Modeltest
-Benjamin Meyer
--
[ signature omitted ]
Message 5 in thread
> It sounds like you are learning about models and writing your first
one,
> it
> might be worthwhile to check out the model test tool on labs. You can
> plug
> your model into it and it will catch a handful of mistakes and edge
cases.
>
> http://labs.trolltech.com/page/Projects/Itemview/Modeltest
This looks promising! I'm wondering about the nice GUI that is depicted
on that page, is it also available somewhere?
Cheers,
Peter
--
[ signature omitted ]
Message 6 in thread
On Tuesday 08 May 2007 17:17:31 Peter Prade wrote:
> > It sounds like you are learning about models and writing your first
>
> one,
>
> > it
> > might be worthwhile to check out the model test tool on labs. You can
> > plug
> > your model into it and it will catch a handful of mistakes and edge
>
> cases.
>
> > http://labs.trolltech.com/page/Projects/Itemview/Modeltest
>
> This looks promising! I'm wondering about the nice GUI that is depicted
> on that page, is it also available somewhere?
>
> Cheers,
> Peter
Haha, no the project image/logo was just me taking a screenshot and then
messing with it for twenty minutes in Gimp.
-Benjamin Meyer
--
[ signature omitted ]
Message 7 in thread
Actually, I'm not writing my first model. I've tried to write models
since Qt 4.0, with not too much success. This is also due to the docs. I
mean, what should I get from the docs on QPersistentModelIndex?! It just
says 'it is safe to store a QPersistentModelIndex since the model will
ensure that references to items will continue to be valid'. Okaaaaaay,
the model... wow, great, but now I write a model, what do I have to do
to make QPersistentModelIndex work? No word about that in the docs. Ok,
let's have a look at an example, or a tutorial.... uh-oh, nothing about
QPersistentModelIndex there either. Let's ask the newsgroup... hm, no
reply. Apparently, nobody uses this stuff. Good for them!
Benjamin Meyer wrote:
> On Tuesday 08 May 2007 16:04:52 QMartin wrote:
>> Benjamin Meyer wrote:
>>> On Tuesday 08 May 2007 13:44:20 QMartin wrote:
>>>> I have problems with QPersistentModelIndex. I found the method
>>>> QAbstractItemModel::changePersistentIndexList which might solve some
>>>> problems, but I have no idea when I should use that method (before or
>>>> after the model was changed), or if I should use it at all (or does the
>>>> model handle this for me).
>>>>
>>>> Any hint would be of great value to me.
>>>>
>>>> M
>>> You want to use that function in conjunction with layoutChanged()
>>>
>>> http://doc.trolltech.com/4.2/qabstractitemmodel.html#layoutChanged
>>>
>>> If you add/remove rows/columns through the normal means the model will
>>> automatically update the persistant index's,
>> Hi Benjamin. Thanks for your answer!
>>
>> "add/remove rows/columns through the normal means".... meaning
>> #insertRow etc.? My model wraps a Qt-unaware object model which handles
>> adding and removing of data. The model just reacts on changes in its
>> base object model, so I cannot use #insertRow but rather use
>> #beginInsertRows and #endInsertRows to notify attached views that the
>> base data was altered. Does that mean that I cannot use persistent model
>> indices with such a setup?
>>
>> Thanks!
>
> For most views, insertRows() doesn't do anything. As long as you use
> beginInsertRows() and endInsertRows() persistant model indices will be
> updated. Usually the persistant model index's are used outside of the model
> and not internally.
>
> It sounds like you are learning about models and writing your first one, it
> might be worthwhile to check out the model test tool on labs. You can plug
> your model into it and it will catch a handful of mistakes and edge cases.
>
> http://labs.trolltech.com/page/Projects/Itemview/Modeltest
>
> -Benjamin Meyer
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]