KExtraColumnsProxyModel: fix bug in sibling() which broke e.g. selections

wilder
David Faure 11 years ago
parent b6ca1f1c84
commit 06a48c672a
  1. 16
      autotests/kextracolumnsproxymodeltest.cpp
  2. 8
      src/kextracolumnsproxymodel.cpp

@ -170,6 +170,9 @@ private Q_SLOTS:
QVERIFY(indexToText(pm.index(0, 5)).startsWith("0,5,")); QVERIFY(indexToText(pm.index(0, 5)).startsWith("0,5,"));
QCOMPARE(indexToText(pm.index(0, 5, secondParent).parent()), indexToText(secondParent)); QCOMPARE(indexToText(pm.index(0, 5, secondParent).parent()), indexToText(secondParent));
QCOMPARE(pm.index(0, 0).sibling(0, 4).column(), 4);
QCOMPARE(pm.index(0, 4).sibling(0, 1).column(), 1);
QVERIFY(!pm.canFetchMore(QModelIndex())); QVERIFY(!pm.canFetchMore(QModelIndex()));
} }
@ -304,15 +307,28 @@ private Q_SLOTS:
// And a QSFPM underneath // And a QSFPM underneath
QSortFilterProxyModel proxy; QSortFilterProxyModel proxy;
proxy.setSourceModel(&mod); proxy.setSourceModel(&mod);
QCOMPARE(proxy.columnCount(), 4);
pm.setSourceModel(&proxy); pm.setSourceModel(&proxy);
QCOMPARE(pm.columnCount(), 6);
QCOMPARE(extractRowTexts(&pm, 0), QString("ABCDZ0"));
// And a selection // And a selection
QItemSelectionModel selection(&pm); QItemSelectionModel selection(&pm);
selection.select(pm.index(0, 0), QItemSelectionModel::Select | QItemSelectionModel::Rows); selection.select(pm.index(0, 0), QItemSelectionModel::Select | QItemSelectionModel::Rows);
const QModelIndexList lst = selection.selectedIndexes();
QCOMPARE(lst.count(), 6);
for (int col = 0; col < lst.count(); ++col) {
QCOMPARE(lst.at(col).row(), 0);
QCOMPARE(lst.at(col).column(), col);
}
// When sorting // When sorting
pm.sort(0, Qt::DescendingOrder); pm.sort(0, Qt::DescendingOrder);
// Then the proxy should be sorted
QCOMPARE(extractRowTexts(&pm, 0), QString("EFGHZ0")); QCOMPARE(extractRowTexts(&pm, 0), QString("EFGHZ0"));
QCOMPARE(extractRowTexts(&pm, 1), QString("ABCDZ1")); QCOMPARE(extractRowTexts(&pm, 1), QString("ABCDZ1"));
// And the selection should be updated accordingly
QCOMPARE(selection.selectedIndexes().first().row(), 1);
} }
private: private:

@ -39,7 +39,7 @@ public:
// Configuration (doesn't change once source model is plugged in) // Configuration (doesn't change once source model is plugged in)
QVector<QString> m_extraHeaders; QVector<QString> m_extraHeaders;
// for layoutAboutToChanged/layoutChanged // for layoutAboutToBeChanged/layoutChanged
QVector<QPersistentModelIndex> layoutChangePersistentIndexes; QVector<QPersistentModelIndex> layoutChangePersistentIndexes;
QVector<int> layoutChangeProxyColumns; QVector<int> layoutChangeProxyColumns;
QModelIndexList proxyIndexes; QModelIndexList proxyIndexes;
@ -117,10 +117,10 @@ QModelIndex KExtraColumnsProxyModel::mapToSource(const QModelIndex &proxyIndex)
QModelIndex KExtraColumnsProxyModel::sibling(int row, int column, const QModelIndex &idx) const QModelIndex KExtraColumnsProxyModel::sibling(int row, int column, const QModelIndex &idx) const
{ {
if (idx.column() >= sourceModel()->columnCount()) { if (row == idx.row() && column == idx.column()) {
return index(row, column, parent(idx)); return idx;
} }
return mapFromSource(sourceModel()->sibling(row, column, mapToSource(idx))); return index(row, column, parent(idx));
} }
QItemSelection KExtraColumnsProxyModel::mapSelectionToSource(const QItemSelection &selection) const QItemSelection KExtraColumnsProxyModel::mapSelectionToSource(const QItemSelection &selection) const

Loading…
Cancel
Save