
Originally Posted by
d_stranz
The Qt documentation for QAbstractProxyModel is wrong - it implies that to derive a custom proxy, you need only implement the mapTo/FromSource methods. There's a bunch more pure virtual methods in QAbstractItemModel that also need to be implemented.
Technically speaking it's not wrong. As classes are inheriting other classes, you'd have to understand the sentence from the docs as "to subclass QAbstractProxyModel you have to implement x and y apart from things you have to implement from QAbstractItemModel".
I've probably done some of that wrong, because I don't know whether mapping needs to be done (in the index() method, for example) or not, because I don't know who is calling them and in what direction the information is flowing.
The proxy has to return all data (apart from mapToSource()) based on itself. So index() has to return index in the proxy space. A crude implementation of index() for flat models would be:
if(parent.isValid() || row<0 || column <0 || row>=rowCount() || column>=columnCount())
return createIndex(row, column, 0);
}
QModelIndex MyProxy::index(int row, int column, const QModelIndex &parent = QModelIndex()) const {
if(parent.isValid() || row<0 || column <0 || row>=rowCount() || column>=columnCount())
return QModelIndex();
return createIndex(row, column, 0);
}
To copy to clipboard, switch view to plain text mode
A less crude implementation would probably have something more useful than "0" as the last parameter to createIndex().
Bookmarks