Created
March 21, 2012 09:07
-
-
Save ianunruh/2145726 to your computer and use it in GitHub Desktop.
RecursiveSortFilterProxyModel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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