--- ./src/gui/itemviews/qsortfilterproxymodel.cpp.orig 2010-11-20 17:54:23.000000000 -0600 +++ ./src/gui/itemviews/qsortfilterproxymodel.cpp 2011-01-07 00:40:04.000000000 -0600 @@ -782,14 +782,14 @@ if (orthogonal_source_to_proxy.isEmpty()) { const int ortho_end = (orient == Qt::Horizontal) ? model->rowCount(source_parent) : model->columnCount(source_parent); + orthogonal_source_to_proxy.resize(ortho_end); + for (int ortho_item = 0; ortho_item < ortho_end; ++ortho_item) { if ((orient == Qt::Horizontal) ? q->filterAcceptsRow(ortho_item, source_parent) : q->filterAcceptsColumn(ortho_item, source_parent)) { orthogonal_proxy_to_source.append(ortho_item); } } - orthogonal_source_to_proxy.resize(orthogonal_proxy_to_source.size()); - if (orient == Qt::Horizontal) { // We're reacting to columnsInserted, but we've just inserted new rows. Sort them. sort_source_rows(orthogonal_proxy_to_source, source_parent); --- ./tests/auto/qsortfilterproxymodel/qsortfilterproxymodel.pro.orig 2010-11-20 17:54:28.000000000 -0600 +++ ./tests/auto/qsortfilterproxymodel/qsortfilterproxymodel.pro 2011-01-07 00:40:04.000000000 -0600 @@ -1,6 +1,7 @@ load(qttest_p4) -SOURCES += tst_qsortfilterproxymodel.cpp - +INCLUDEPATH += $$PWD/../modeltest +SOURCES += tst_qsortfilterproxymodel.cpp ../modeltest/dynamictreemodel.cpp ../modeltest/modeltest.cpp +HEADERS += ../modeltest/dynamictreemodel.h ../modeltest/modeltest.h --- ./tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp.orig 2010-11-20 17:54:28.000000000 -0600 +++ ./tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp 2011-01-07 00:41:02.000000000 -0600 @@ -43,6 +43,9 @@ #include #include "../../shared/util.h" +#include "dynamictreemodel.h" +#include "modeltest.h" + #include #include @@ -143,6 +146,7 @@ void taskQTBUG_10287_unnecessaryMapCreation(); void testMultipleProxiesWithSelection(); + void filteredColumns(); protected: void buildHierarchy(const QStringList &data, QAbstractItemModel *model); @@ -3135,5 +3139,40 @@ // No assert failure, it passes. } +class FilteredColumnProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT +public: + FilteredColumnProxyModel(QObject *parent = 0) + : QSortFilterProxyModel(parent) + { + + } + +protected: + bool filterAcceptsColumn(int column, const QModelIndex &source_parent) const + { + return column % 2 != 0; + } +}; + +void tst_QSortFilterProxyModel::filteredColumns() +{ + DynamicTreeModel *model = new DynamicTreeModel(this); + + FilteredColumnProxyModel *proxy = new FilteredColumnProxyModel(this); + proxy->setSourceModel(model); + + new ModelTest(proxy, this); + + ModelInsertCommand *insertCommand = new ModelInsertCommand(model, this); + insertCommand->setNumCols(2); + insertCommand->setStartRow(0); + insertCommand->setEndRow(0); + // Parent is QModelIndex() + insertCommand->doCommand(); + +} + QTEST_MAIN(tst_QSortFilterProxyModel) #include "tst_qsortfilterproxymodel.moc"