KRearrangeColumnsProxyModel: fix assert in index(0, 0) on empty model

REVIEW: 128578
wilder
David Faure 10 years ago
parent 73c005a031
commit 2380ac105d
  1. 17
      autotests/krearrangecolumnsproxymodeltest.cpp
  2. 4
      src/krearrangecolumnsproxymodel.cpp

@ -78,6 +78,23 @@ private Q_SLOTS:
QCOMPARE(pm.columnCount(), 0);
}
void shouldShowNothingIfNoRows()
{
// Given a rearrange-columns proxy
KRearrangeColumnsProxyModel pm;
pm.setSourceColumns(QVector<int>() << 2 << 3 << 1 << 0);
// When using that proxy on top of an empty source model
QStandardItemModel sourceModel;
sourceModel.setColumnCount(4);
pm.setSourceModel(&sourceModel);
// Then the proxy should show nothing
QCOMPARE(pm.rowCount(), 0);
QCOMPARE(pm.columnCount(), 4);
QCOMPARE(pm.index(0, 0), pm.index(0, 0)); // like QAbstractItemView::setModel does in a Q_ASSERT_X
}
void shouldRearrangeColumns()
{
// Given a rearrange-columns proxy

@ -69,7 +69,9 @@ QModelIndex KRearrangeColumnsProxyModel::index(int row, int column, const QModel
// Find the child in the source model, we need its internal pointer
const QModelIndex sourceIndex = sourceModel()->index(row, sourceColumnForProxyColumn(column), sourceParent);
Q_ASSERT(sourceIndex.isValid());
if (!sourceIndex.isValid()) {
return QModelIndex();
}
return createIndex(row, column, sourceIndex.internalPointer());
}

Loading…
Cancel
Save