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);
|
int i = d->viewIndex(index);
|
||||||
if (--i < 0)
|
if (--i < 0)
|
||||||
return QModelIndex();
|
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);
|
int i = d->viewIndex(index);
|
||||||
if (++i >= d->viewItems.count())
|
if (++i >= d->viewItems.count())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
return d->viewItems.at(i).index;
|
const QModelIndex firstColumnIndex = d->viewItems.at(i).index;
|
||||||
|
return firstColumnIndex.sibling(firstColumnIndex.row(), index.column());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -1870,18 +1870,22 @@ void tst_QTreeView::indexAbove()
|
|||||||
model.fetchMore(p);
|
model.fetchMore(p);
|
||||||
int rows = model.rowCount(p);
|
int rows = model.rowCount(p);
|
||||||
for (int r = rows - 1; r > 0; --r) {
|
for (int r = rows - 1; r > 0; --r) {
|
||||||
QModelIndex idx = model.index(r, 0, p);
|
for (int column = 0; column < 3; ++column) {
|
||||||
QModelIndex expected = model.index(r - 1, 0, p);
|
QModelIndex idx = model.index(r, column, p);
|
||||||
|
QModelIndex expected = model.index(r - 1, column, p);
|
||||||
QCOMPARE(view.indexAbove(idx), expected);
|
QCOMPARE(view.indexAbove(idx), expected);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// hide even rows
|
// hide even rows
|
||||||
for (int r = 0; r < rows; r+=2)
|
for (int r = 0; r < rows; r+=2)
|
||||||
view.setRowHidden(r, p, true);
|
view.setRowHidden(r, p, true);
|
||||||
for (int r = rows - 1; r > 0; r-=2) {
|
for (int r = rows - 1; r > 0; r-=2) {
|
||||||
QModelIndex idx = model.index(r, 0, p);
|
for (int column = 0; column < 3; ++column) {
|
||||||
QModelIndex expected = model.index(r - 2, 0, p);
|
QModelIndex idx = model.index(r, column, p);
|
||||||
|
QModelIndex expected = model.index(r - 2, column, p);
|
||||||
QCOMPARE(view.indexAbove(idx), expected);
|
QCOMPARE(view.indexAbove(idx), expected);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// for (int r = 0; r < rows; ++r)
|
// for (int r = 0; r < rows; ++r)
|
||||||
// parents.push(model.index(r, 0, p));
|
// parents.push(model.index(r, 0, p));
|
||||||
}
|
}
|
||||||
@ -1889,21 +1893,39 @@ void tst_QTreeView::indexAbove()
|
|||||||
|
|
||||||
void tst_QTreeView::indexBelow()
|
void tst_QTreeView::indexBelow()
|
||||||
{
|
{
|
||||||
QtTestModel model(2, 1);
|
QtTestModel model(2, 2);
|
||||||
|
|
||||||
QTreeView view;
|
QTreeView view;
|
||||||
view.setModel(&model);
|
view.setModel(&model);
|
||||||
view.show();
|
view.show();
|
||||||
|
|
||||||
|
{
|
||||||
QModelIndex i = model.index(0, 0, view.rootIndex());
|
QModelIndex i = model.index(0, 0, view.rootIndex());
|
||||||
QVERIFY(i.isValid());
|
QVERIFY(i.isValid());
|
||||||
QCOMPARE(i.row(), 0);
|
QCOMPARE(i.row(), 0);
|
||||||
|
QCOMPARE(i.column(), 0);
|
||||||
|
|
||||||
i = view.indexBelow(i);
|
i = view.indexBelow(i);
|
||||||
QVERIFY(i.isValid());
|
QVERIFY(i.isValid());
|
||||||
QCOMPARE(i.row(), 1);
|
QCOMPARE(i.row(), 1);
|
||||||
|
QCOMPARE(i.column(), 0);
|
||||||
i = view.indexBelow(i);
|
i = view.indexBelow(i);
|
||||||
QVERIFY(!i.isValid());
|
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()
|
void tst_QTreeView::clicked()
|
||||||
|
Loading…
Reference in New Issue
Block a user