Skip to content

Instantly share code, notes, and snippets.

@ianunruh
Created March 21, 2012 09:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianunruh/2145726 to your computer and use it in GitHub Desktop.
Save ianunruh/2145726 to your computer and use it in GitHub Desktop.
RecursiveSortFilterProxyModel
import com.trolltech.qt.core.QModelIndex;
import com.trolltech.qt.gui.*;
public class RecursiveSortFilterProxyModel extends QSortFilterProxyModel {
protected boolean filterAcceptsRow(int row, QModelIndex parent) {
if(super.filterAcceptsRow(row, parent)) {
return true;
}
QStandardItemModel model = (QStandardItemModel)sourceModel();
QStandardItem item;
if(parent == null) {
item = model.item(row);
} else {
item = model.itemFromIndex(parent).child(row);
}
if(item.hasChildren()) {
QModelIndex index = item.index();
int rowCount = item.rowCount();
for(int i = 0; i < rowCount; i++) {
if(filterAcceptsRow(i, index)) {
return true;
}
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment