Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 7

Qt-interest Archive, August 2006
QTreeView : how top know when the rootIndex is no more valid ?


Message 1 in thread

Hi all,

I have various QTreeView with various rootIndex(), though built uppon the
same Model.

When the rootIndex() of a given view is no more valid (for example : when it
has been removed from the model), the view apparently reset its rootIndex()
to the root of the model.

Is there an easy way to track the event 
        " the rootIndex of a view is no more valid " ?
I did not find an appropriate signal...

Or should I reimplement
        QTreeView::::rowsAboutToBeRemoved ( const QModelIndex & parent, 
                int start, int end )
and track for the removal of rootIndex() ?

(this would be unlucky, since QTreeView already computes all the necessary
checks).


Best -

Nicolas

--
 [ signature omitted ] 

Message 2 in thread

Hi again,

just to precise the question...

How does the view react when its rootIndex() becomes invalid ?
Which method is responsible for reseting the rootIndex to QModelIndex() ?

I ve tried to follow up the Qt code - no sucess.

Best -

Nicolas Castagne wrote:

> Hi all,
> 
> I have various QTreeView with various rootIndex(), though built uppon the
> same Model.
> 
> When the rootIndex() of a given view is no more valid (for example : when
> it has been removed from the model), the view apparently reset its
> rootIndex() to the root of the model.
> 
> Is there an easy way to track the event
>         " the rootIndex of a view is no more valid " ?
> I did not find an appropriate signal...
> 
> Or should I reimplement
>         QTreeView::::rowsAboutToBeRemoved ( const QModelIndex & parent,
>                 int start, int end )
> and track for the removal of rootIndex() ?
> 
> (this would be unlucky, since QTreeView already computes all the necessary
> checks).
> 
> 
> Best -
> 
> Nicolas

--
 [ signature omitted ] 

Message 3 in thread

Check out the docs for QPersistentModelIndex  The view's keep one for the root 
index.  This way when it is removed the root index in the view will now be 
invalid.

-Benjamin Meyer

On Wednesday 30 August 2006 19:41, Nicolas Castagne wrote:
> Hi all,
>
> I have various QTreeView with various rootIndex(), though built uppon the
> same Model.
>
> When the rootIndex() of a given view is no more valid (for example : when
> it has been removed from the model), the view apparently reset its
> rootIndex() to the root of the model.
>
> Is there an easy way to track the event
>         " the rootIndex of a view is no more valid " ?
> I did not find an appropriate signal...
>
> Or should I reimplement
>         QTreeView::::rowsAboutToBeRemoved ( const QModelIndex & parent,
>                 int start, int end )
> and track for the removal of rootIndex() ?
>
> (this would be unlucky, since QTreeView already computes all the necessary
> checks).
>
>
> Best -
>
> Nicolas
>
> --
> 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 ] 

Message 4 in thread

Thx Benjamin.

> Check out the docs for QPersistentModelIndex  The view's keep one for the
> root
> index.  This way when it is removed the root index in the view will now be
> invalid.

That's what I thought.

My question is rather :
how can I be informed of the fact that 
- the root index has been invalidated
- and hence the view's root is "reset" to the root of the model
?

Indeed, I have various views on the same model inside a QTabWidget.
Each view has its own root.
When a QModelIndex which is a root of a given view is "removed", this view's
root is reset to the model's root.

In that case, I would need to inform the user, especially by closing the
view which is ** no more valid **, instead of reseting it to the model's
root.

To that aim, I would need :
- to get a Signal indicating that the view's old root is no more valid
- or to be able to reimplement a method in my view which is called in that
case, so that I can emit myself a signal

I did not figure this out...

I see only solutions so far :
reimplementing
         QTreeView::::rowsAboutToBeRemoved ( const QModelIndex & parent,
                 int start, int end )
and tracking for the removal of rootIndex() 

However, I don't like it since it corresponds with a job that is already
done within Qt...

Any other advice ?

Best-
Nicolas

BTW, I am currently trying to implement the hack you adviced for row
removal. I may come back to you later. Thanks much.

Benjamin Meyer wrote:

> Check out the docs for QPersistentModelIndex  The view's keep one for the
> root
> index.  This way when it is removed the root index in the view will now be
> invalid.
> 
> -Benjamin Meyer
> 
> On Wednesday 30 August 2006 19:41, Nicolas Castagne wrote:
>> Hi all,
>>
>> I have various QTreeView with various rootIndex(), though built uppon the
>> same Model.
>>
>> When the rootIndex() of a given view is no more valid (for example : when
>> it has been removed from the model), the view apparently reset its
>> rootIndex() to the root of the model.
>>
>> Is there an easy way to track the event
>>         " the rootIndex of a view is no more valid " ?
>> I did not find an appropriate signal...
>>
>> Or should I reimplement
>>         QTreeView::::rowsAboutToBeRemoved ( const QModelIndex & parent,
>>                 int start, int end )
>> and track for the removal of rootIndex() ?
>>
>> (this would be unlucky, since QTreeView already computes all the
>> necessary checks).
>>
>>
>> Best -
>>
>> Nicolas
>>
>> --
>> 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/
> 
> --
> 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 ]