Skip to content

Instantly share code, notes, and snippets.

@ianunruh
Created March 21, 2012 09:07
Show Gist options
  • Select an option

  • Save ianunruh/2145726 to your computer and use it in GitHub Desktop.

Select an option

Save ianunruh/2145726 to your computer and use it in GitHub Desktop.

Revisions

  1. ianunruh revised this gist Mar 21, 2012. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions RecursiveSortFilterProxyModel.java
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,10 @@

    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;

    @@ -12,9 +16,7 @@ protected boolean filterAcceptsRow(int row, QModelIndex parent) {
    item = model.itemFromIndex(parent).child(row);
    }

    if(super.filterAcceptsRow(row, parent)) {
    return true;
    } else if(item.hasChildren()) {
    if(item.hasChildren()) {
    QModelIndex index = item.index();
    int rowCount = item.rowCount();
    for(int i = 0; i < rowCount; i++) {
  2. ianunruh created this gist Mar 21, 2012.
    29 changes: 29 additions & 0 deletions RecursiveSortFilterProxyModel.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    import com.trolltech.qt.core.QModelIndex;
    import com.trolltech.qt.gui.*;

    public class RecursiveSortFilterProxyModel extends QSortFilterProxyModel {
    protected boolean filterAcceptsRow(int row, QModelIndex parent) {
    QStandardItemModel model = (QStandardItemModel)sourceModel();
    QStandardItem item;

    if(parent == null) {
    item = model.item(row);
    } else {
    item = model.itemFromIndex(parent).child(row);
    }

    if(super.filterAcceptsRow(row, parent)) {
    return true;
    } else 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;
    }
    }