QHeaderView - minor bug in visualIndexAt

This fixes a minor bug in VisualIndex triggered when calling
resizeSection with size 0 (but not hideSection).

It is mostly cosmetics - however hopefully there will soon
be a minor refactoring and there is really no need to make
strange code to keep a semantic bug.

However it is also doubtful to make a semantic change
while refactoring.

Change-Id: Ide153e421fd7a634062cb74867f4a49da4bf9cd6
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
bb10
Thorbjørn Lund Martsum 2012-02-03 20:02:46 +01:00 committed by Qt by Nokia
parent 2b42987d0a
commit 73a5bc2aac
2 changed files with 23 additions and 14 deletions

View File

@ -3496,8 +3496,8 @@ int QHeaderViewPrivate::headerVisualIndexAt(int position) const
const QHeaderViewPrivate::SectionSpan &currentSection = sectionSpans.at(i);
int next_span_start_section = span_start_section + currentSection.count;
int next_span_position = span_position + currentSection.size;
if (position == span_position)
return span_start_section; // spans with no size
if (position == span_position && currentSection.size > 0)
return span_start_section;
if (position > span_position && position < next_span_position) {
int position_in_span = position - span_position;
return span_start_section + (position_in_span / currentSection.sectionSize());

View File

@ -204,6 +204,7 @@ private slots:
void QTBUG8650_crashOnInsertSections();
void QTBUG12268_hiddenMovedSectionSorting();
void QTBUG14242_hideSectionAutoSize();
void ensureNoIndexAtLength();
void initialSortOrderRole();
@ -2156,6 +2157,17 @@ void tst_QHeaderView::QTBUG14242_hideSectionAutoSize()
QVERIFY(calced_length == afterlength);
}
void tst_QHeaderView::ensureNoIndexAtLength()
{
QTableView qtv;
QStandardItemModel amodel(4, 4);
qtv.setModel(&amodel);
QHeaderView *hv = qtv.verticalHeader();
QVERIFY(hv->visualIndexAt(hv->length()) == -1);
hv->resizeSection(hv->count() - 1, 0);
QVERIFY(hv->visualIndexAt(hv->length()) == -1);
}
void tst_QHeaderView::initialSortOrderRole()
{
QTableView view; // ### Shadowing member view (of type QHeaderView)
@ -2341,8 +2353,8 @@ void tst_QHeaderView::calculateAndCheck(int cppline, const int precalced_compare
QVERIFY2(chk_logical == x[1], verifytext);
QVERIFY2(chk_sizes == x[2], verifytext);
QVERIFY2(chk_hidden_size == x[3], verifytext);
QVERIFY2(chk_lookup_visual == x[4], verifytext); // Here the semantic can change. See final note (*).
QVERIFY2(chk_lookup_logical == x[5], verifytext); // Here the semantic can change. See final note (*).
QVERIFY2(chk_lookup_visual == x[4], verifytext);
QVERIFY2(chk_lookup_logical == x[5], verifytext);
QVERIFY2(header_lenght == x[6], verifytext);
}
@ -2438,10 +2450,10 @@ void tst_QHeaderView::logicalIndexAtTest()
//qDebug() << "logicalIndexAtTest" << check1 << check2;
const int precalced_check1 = 106327;
const int precalced_check2 = 29856418;
QVERIFY(precalced_check1 == check1); // Here the semantic can change. See final note (*)
QVERIFY(precalced_check2 == check2); // Here the semantic can change. See final note (*)
QVERIFY(precalced_check1 == check1);
QVERIFY(precalced_check2 == check2);
const int precalced_results[] = { 1145298384, -1710423344, -650981936, 372919464, 2139446944, 854793816, 12124 };
const int precalced_results[] = { 1145298384, -1710423344, -650981936, 372919464, -1544372176, -426463328, 12124 };
calculateAndCheck(__LINE__, precalced_results);
}
@ -2466,10 +2478,10 @@ void tst_QHeaderView::visualIndexAtTest()
//qDebug() << "visualIndexAtTest" << check1 << check2;
const int precalced_check1 = 72665;
const int precalced_check2 = 14015890;
QVERIFY(precalced_check1 == check1); // Here the semantic can change. See final note (*)
QVERIFY(precalced_check2 == check2); // Here the semantic can change. See final note (*)
QVERIFY(precalced_check1 == check1);
QVERIFY(precalced_check2 == check2);
const int precalced_results[] = { 1145298384, -1710423344, -1457520212, 169223959, 726651072, -2105938696, 5453 };
const int precalced_results[] = { 1145298384, -1710423344, -1457520212, 169223959, 557466160, -324939600, 5453 };
calculateAndCheck(__LINE__, precalced_results);
}
@ -2598,7 +2610,7 @@ void tst_QHeaderView::mixedTests()
model->setRowCount(model->rowCount() - 10);
if (m_using_reset_model) {
const int precalced_results[] = { 898296472, 337096378, -543340640, 1, 703951756, 250831536, 9250 };
const int precalced_results[] = { 898296472, 337096378, -543340640, 1, -1251526424, -568618976, 9250 };
calculateAndCheck(__LINE__, precalced_results);
} else {
const int precalced_results[] = { 1911338224, 1693514365, -613398968, -1912534953, 1582159424, -1851079000, 9300 };
@ -2633,8 +2645,5 @@ void tst_QHeaderView::resizeToContentTest()
calculateAndCheck(__LINE__, precalced_results);
}
// (*) Currently qheaderview position lookup acts a bit strange. It can return sections with size 0.
// This could be changed in the future.
QTEST_MAIN(tst_QHeaderView)
#include "tst_qheaderview.moc"