[Interest] KDescendantsProxyModel + QSortFilterProxyModel issue
Rodrigo Oliva
Rodrigo.Oliva at king.com
Tue Jun 5 18:22:11 CEST 2018
Hello, I've been using kde's kitemmodels library to make a content explorer.
I have two panels, the left one which is a QTreeView that shows a folder tree structure and the right one which is a QListView that shows a list of files and folders from the current selected folder in the left panel, ignoring folder structure. The list view can then be filtered with a search box.
Example use case:
Left
- Folder1
- Folder2 (selected)
o Folder3
§ File1
Right
- Folder3
- File1
The way I wanted to do this was using the same source model for both panels, using proxy models to show whatever I want in each of the panels. The kitemmodels lib is great for this.
The structure looks like this (mailing list friendly, indentation marks model ancestry):
- Source Model (modeled as a tree).
o Left QSortFilterProxyModel
o KSelectionProxyModel
§ KDescendantsProxyModel - set to SubTreesWithoutRoots
· Right QSortFilterProxyModel
Everything works great, except when I insert rows in the source model while there is an active filter in the right QSortFilterProxyModel, in the filterAcceptsRow. It looks like this
bool RightSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const {
Q_ASSERT(!source_parent.isValid()); // we are filtering a list
QModelIndex sourceIndex = sourceModel()->index(source_row, 0);
if (!sourceIndex.isValid()) {
return false;
}
QString key = sourceModel()->data(sourceIndex).toString();
return filterRegExp().isEmpty() ? true : key.contains(filterRegExp());
}
When sourceModel()->data(sourceIndex) is called, I get an assert in the RightSortFilterProxyModel source model, the KDescendantsProxyModel: "Didn't find target row.", in its mapToSource function. When run in release, the list gets filled with a bunch of empty rows.
The source index is not invalid and sourceModel()->rowCount() returns greater than 0.
Am I doing something wrong in this filterAcceptsRow? The strange thing is that this works perfectly without the filter.
Excuse me if this not the right mailing list for this, I found some questions related to this in qt-interest-old.
Cheers,
Rodrigo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180605/3446393e/attachment.html>
More information about the Interest
mailing list