Originally Posted by
d_stranz
...does your override of rowCount() ever get called?
Yes, it gets called properly. I modified my override to confirm:
int DecoratorProxyModel
::rowCount(const QModelIndex &parent
) const {
qDebug
() <<
"proxy rowCount() call, sourceModel():" << sourceModel
()->rowCount
(parent
) <<
"base class rowCount():" <<
QSortFilterProxyModel::rowCount(parent
);
qDebug() << "modified rowCount() response:" << sourceModel()->rowCount(parent) + 1;
return sourceModel()->rowCount(parent) + 1;
// return QSortFilterProxyModel::rowCount(parent) + 1;
}
int DecoratorProxyModel::rowCount(const QModelIndex &parent) const
{
qDebug() << "proxy rowCount() call, sourceModel():" << sourceModel()->rowCount(parent) << "base class rowCount():" << QSortFilterProxyModel::rowCount(parent);
qDebug() << "modified rowCount() response:" << sourceModel()->rowCount(parent) + 1;
return sourceModel()->rowCount(parent) + 1;
// return QSortFilterProxyModel::rowCount(parent) + 1;
}
To copy to clipboard, switch view to plain text mode
Both implementations, using the source model rowCount() and using the base class rowCount() report the same number of rows.
Debug output:
> Source model initModel(), rows: 7
proxy rowCount() call, sourceModel()->rowC: 7 base class rowCount(): 7
modified rowCount() response: 8
proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
modified rowCount() response: 8
proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
modified rowCount() response: 8
proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
modified rowCount() response: 8
proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
modified rowCount() response: 8
proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
modified rowCount() response: 8
proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
modified rowCount() response: 8
> Source model initModel(), rows: 7
proxy rowCount() call, sourceModel()->rowC: 7 base class rowCount(): 7
modified rowCount() response: 8
proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
modified rowCount() response: 8
proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
modified rowCount() response: 8
proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
modified rowCount() response: 8
proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
modified rowCount() response: 8
proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
modified rowCount() response: 8
proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
modified rowCount() response: 8
To copy to clipboard, switch view to plain text mode
Originally Posted by
d_stranz
No, I didn't touch the QSortFilterProxyModel::filterAcceptsRow() method. In fact, I've read Qt docs and found out that it is better to use QIdentityProxyModel if I just want to modify the output. So, I tried subclassing identity proxy overriding only rowCount() and data() methods with the same code I did for sortfilter proxy, but it didn't help, the view doesn't call the data() method for that additional virtual rowCount()+1 row.
I also tried fiddling with the QSortFilterProxyModel::flags(), but seems like it doesn't get called for the virtual row either.
Qt
::ItemFlags DecoratorProxyModel
::flags(const QModelIndex &index
) const{
qint32 row = index.row();
qint32 col = index.column();
qDebug() << "flags():" << row << col;
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}
Qt::ItemFlags DecoratorProxyModel::flags(const QModelIndex &index) const
{
qint32 row = index.row();
qint32 col = index.column();
qDebug() << "flags():" << row << col;
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}
To copy to clipboard, switch view to plain text mode
And I thought I understood how Qt's Model View framework works :-)
Bookmarks