Fix indexAbove and indexBelow to return indexes in the correct column.
They used to always return indexes in column 0. Change-Id: I2cf4239e0a975b37548de00a1deb916fcd88b4c7 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
parent
2b57a8ebfe
commit
0c955b4976
@ -1991,7 +1991,8 @@ QModelIndex QTreeView::indexAbove(const QModelIndex &index) const
|
||||
int i = d->viewIndex(index);
|
||||
if (--i < 0)
|
||||
return QModelIndex();
|
||||
return d->viewItems.at(i).index;
|
||||
const QModelIndex firstColumnIndex = d->viewItems.at(i).index;
|
||||
return firstColumnIndex.sibling(firstColumnIndex.row(), index.column());
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -2006,7 +2007,8 @@ QModelIndex QTreeView::indexBelow(const QModelIndex &index) const
|
||||
int i = d->viewIndex(index);
|
||||
if (++i >= d->viewItems.count())
|
||||
return QModelIndex();
|
||||
return d->viewItems.at(i).index;
|
||||
const QModelIndex firstColumnIndex = d->viewItems.at(i).index;
|
||||
return firstColumnIndex.sibling(firstColumnIndex.row(), index.column());
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -1870,17 +1870,21 @@ void tst_QTreeView::indexAbove()
|
||||
model.fetchMore(p);
|
||||
int rows = model.rowCount(p);
|
||||
for (int r = rows - 1; r > 0; --r) {
|
||||
QModelIndex idx = model.index(r, 0, p);
|
||||
QModelIndex expected = model.index(r - 1, 0, p);
|
||||
QCOMPARE(view.indexAbove(idx), expected);
|
||||
for (int column = 0; column < 3; ++column) {
|
||||
QModelIndex idx = model.index(r, column, p);
|
||||
QModelIndex expected = model.index(r - 1, column, p);
|
||||
QCOMPARE(view.indexAbove(idx), expected);
|
||||
}
|
||||
}
|
||||
// hide even rows
|
||||
for (int r = 0; r < rows; r+=2)
|
||||
view.setRowHidden(r, p, true);
|
||||
for (int r = rows - 1; r > 0; r-=2) {
|
||||
QModelIndex idx = model.index(r, 0, p);
|
||||
QModelIndex expected = model.index(r - 2, 0, p);
|
||||
QCOMPARE(view.indexAbove(idx), expected);
|
||||
for (int column = 0; column < 3; ++column) {
|
||||
QModelIndex idx = model.index(r, column, p);
|
||||
QModelIndex expected = model.index(r - 2, column, p);
|
||||
QCOMPARE(view.indexAbove(idx), expected);
|
||||
}
|
||||
}
|
||||
// for (int r = 0; r < rows; ++r)
|
||||
// parents.push(model.index(r, 0, p));
|
||||
@ -1889,21 +1893,39 @@ void tst_QTreeView::indexAbove()
|
||||
|
||||
void tst_QTreeView::indexBelow()
|
||||
{
|
||||
QtTestModel model(2, 1);
|
||||
QtTestModel model(2, 2);
|
||||
|
||||
QTreeView view;
|
||||
view.setModel(&model);
|
||||
view.show();
|
||||
|
||||
QModelIndex i = model.index(0, 0, view.rootIndex());
|
||||
QVERIFY(i.isValid());
|
||||
QCOMPARE(i.row(), 0);
|
||||
{
|
||||
QModelIndex i = model.index(0, 0, view.rootIndex());
|
||||
QVERIFY(i.isValid());
|
||||
QCOMPARE(i.row(), 0);
|
||||
QCOMPARE(i.column(), 0);
|
||||
|
||||
i = view.indexBelow(i);
|
||||
QVERIFY(i.isValid());
|
||||
QCOMPARE(i.row(), 1);
|
||||
i = view.indexBelow(i);
|
||||
QVERIFY(!i.isValid());
|
||||
i = view.indexBelow(i);
|
||||
QVERIFY(i.isValid());
|
||||
QCOMPARE(i.row(), 1);
|
||||
QCOMPARE(i.column(), 0);
|
||||
i = view.indexBelow(i);
|
||||
QVERIFY(!i.isValid());
|
||||
}
|
||||
|
||||
{
|
||||
QModelIndex i = model.index(0, 1, view.rootIndex());
|
||||
QVERIFY(i.isValid());
|
||||
QCOMPARE(i.row(), 0);
|
||||
QCOMPARE(i.column(), 1);
|
||||
|
||||
i = view.indexBelow(i);
|
||||
QVERIFY(i.isValid());
|
||||
QCOMPARE(i.row(), 1);
|
||||
QCOMPARE(i.column(), 1);
|
||||
i = view.indexBelow(i);
|
||||
QVERIFY(!i.isValid());
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QTreeView::clicked()
|
||||
|
Loading…
Reference in New Issue
Block a user