[Qt-interest] QSortFilterProxyModel over aQSqlRelationalTableModel

Scott Aron Bloom Scott.Bloom at sabgroup.com
Fri Jan 30 19:10:27 CET 2009


I had a project 2+ years ago (4.1 time frame) which had 1 central model
with about 4 or 5 proxy models (including proxy of proxys..  So I create
a couple of utility functions (for const and non-const) like

const QAbstractItemModel * sourceModel ( const QAbstractItemModel *
inModel )
{
	const QSortFilterProxyModel * proxyModel = dynamic_cast< const
QSortFilterProxyModel * >( inModel );
	if ( proxyModel )
		return sourceModel( proxyModel->sourceModel() );
	return inModel;
}

I also had it for a QModelIndex and a non-const version...

I had put in a request to TT back to add to the base QAbstractItemModel
class a method called sourceModel() as well as a
QModelIndex::sourceModel()

But they said the interface was fixed for the 4.X timeframe and it would
break backward compatibility.. Its been 2+ years maybe I should check to
see if its still open...

Scott

> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of mario
> Sent: 2009-01-30 09:49
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] QSortFilterProxyModel over
> aQSqlRelationalTableModel
> 
> On Fri, Jan 30, 2009 at 5:59 PM, Scott Aron Bloom
> <Scott.Bloom at sabgroup.com> wrote:
> > Looks like a bug in the createEditor...
> >
> > Should check for a source model...
> Something like this...
> (not tested)
> 
> 
> QWidget *createEditor(QWidget *parent,
>                        const QStyleOptionViewItem &option,
>                        const QModelIndex &index) const
> {
>     const QSqlRelationalTableModel *sqlModel = qobject_cast<const>
> QSqlRelationalTableModel *>(index.model());
>     QSqlTableModel *childModel = sqlModel ?
> sqlModel->relationModel(index.column()) : 0;
> 
>     if (!childModel )
>     {
> 		const QSortFilterProxyModel* proxyModel =
qobject_cast<const>
> QSortFilterProxyModel *>(index.model());
> 		if(proxyModel)
> 		{
> 			childModel = proxyModel->sourceModel () ?
proxyModel-
> >sourceModel
> ()->relationModel(index.column()) : 0;
> 		}
>                 //maybe parent recursively...
>     }
> 
>      if (childModel)
>      {
>             return QItemDelegate::createEditor(parent, option, index);
>      }
> 
>      bla.bla...
> 
> 
> 
> > I would file it with trolltech, with the fix.. Then create your own
> > derived delegate with the 2 or 3 lines of code fix.
> 
> done (the second part)
> 
> Tnx
> --
> Mario Signorino | www.sgrunt.net
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list