On 2009-11-07 Linos <i...@linos.es> said:

> ...
> Hi,
>       in the qt examples from qt 4.5 documentation you can see they use this 
> in
>  the model:
> http://doc.trolltech.com/4.5/itemviews-simpletreemodel-treemodel-cpp.html
> 
> QModelIndex TreeModel::index(int row, int column, const QModelIndex
>  &parent) const
>   {
>       if (!hasIndex(row, column, parent))
>           return QModelIndex();
> 
>       TreeItem *parentItem;
> 
>       if (!parent.isValid())
>           parentItem = rootItem;
>       else
>           parentItem = static_cast<TreeItem*>(parent.internalPointer());
> 
>       TreeItem *childItem = parentItem->child(row);
>       if (childItem)
>           return createIndex(row, column, childItem);
>       else
>           return QModelIndex();
>   }
> 

Thanks for this info. I simply didn't check this page because I was interested 
in editable models not in read-only models. Its funny to see that index method 
implementation in the read-only example is more complex than in the editable 
one.

But still, it is nearly the same workaround provided by Baz and doesn't answer 
my question about validity of the passed row argument.

> and this in the item class.
> http://doc.trolltech.com/4.5/itemviews-simpletreemodel-treeitem-cpp.html
> 
> TreeItem *TreeItem::child(int row)
>   {
>       return childItems.value(row);
>   }
> 
> but they can do this because QList .value method dont get an error if it is
>  out of bounds.

Yes but, as you can see in the in the index method provided in that example, 
this is called *after* the row argument has been validated so it has no impact 
in my question.

Vicent
::

        Share what you know, learn what you don't

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to