[Qt-interest] ModelView - how to use proxies to filter this data?
Sean Harmer
sean.harmer at maps-technology.com
Tue Dec 1 16:53:43 CET 2009
Hi,
On Tuesday 01 December 2009 15:36:18 Daniel Price wrote:
> Thanks for the info. I hadn't considered using a proxy filter and just
> accepting/rejecting rows. Does that work with hierarchical data though?
Yes it works absolutely fine with hierarchical data as that is what I am using.
> I actually QAbstractProxyModel and implemented the mapTo/mapFrom functions.
> But sorting doesn't seem to work.
Yeah I thought about doing it that way, but then decided that
QSortFilterProxyModel fitted my needs with a little subclassing.
> BTW it looks like you're storing pointers to your structures in your
> variants as integers and casting them back.
No I am storing them as void* in the QModelIndex's internal pointer so that is
why I am casting them back to my specific types. My model's index function
looks like this:
QModelIndex MapsData1DTreeModel::index( int row, int col, const QModelIndex&
parent ) const
{
MapsData1DTreeModelGroupNode* parentItem;
if ( !parent.isValid() )
parentItem = m_root;
else
parentItem = static_cast<MapsData1DTreeModelGroupNode*>(
parent.internalPointer() );
MapsData1DTreeModelNode* childItem = parentItem->child( row );
if ( childItem )
return createIndex( row, col, childItem );
else
return QModelIndex();
}
Good luck.
Sean
More information about the Qt-interest-old
mailing list