QHeaderView - minor fix to setDefaultSectionSize
This fixes a situation where we (wrongly) assume that a section with size 0 is hidden. However a hidden section should be one that we have called hideSection (or setSectionHidden) on. Change-Id: Ic14eded2666022f27434dc55927323a74910549c Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
parent
07ff7fe52c
commit
fcc01e6c37
@ -3339,8 +3339,7 @@ void QHeaderViewPrivate::setDefaultSectionSize(int size)
|
||||
defaultSectionSize = size;
|
||||
for (int i = 0; i < sectionSpans.count(); ++i) {
|
||||
QHeaderViewPrivate::SectionSpan &span = sectionSpans[i];
|
||||
if (span.size > 0) {
|
||||
//we resize it if it is not hidden (ie size > 0)
|
||||
if (sectionHidden.isEmpty() || !sectionHidden.testBit(i)) { // resize on not hidden.
|
||||
const int newSize = size;
|
||||
if (newSize != span.size) {
|
||||
length += newSize - span.size; //the whole length is changed
|
||||
|
@ -170,6 +170,7 @@ private slots:
|
||||
void moveSectionAndReset();
|
||||
void moveSectionAndRemove();
|
||||
void saveRestore();
|
||||
void defaultSectionSizeTest();
|
||||
|
||||
void defaultAlignment_data();
|
||||
void defaultAlignment();
|
||||
@ -1625,6 +1626,32 @@ void tst_QHeaderView::saveRestore()
|
||||
QVERIFY(s1 == s2);
|
||||
}
|
||||
|
||||
void tst_QHeaderView::defaultSectionSizeTest()
|
||||
{
|
||||
// Setup
|
||||
QTableView qtv;
|
||||
QStandardItemModel amodel(4, 4);
|
||||
qtv.setModel(&amodel);
|
||||
QHeaderView *hv = qtv.verticalHeader();
|
||||
const int defaultSize = 26;
|
||||
hv->setDefaultSectionSize(defaultSize + 1); // Set it to a value different from defaultSize.
|
||||
|
||||
// no hidden Sections
|
||||
hv->resizeSection(1, 0);
|
||||
hv->setDefaultSectionSize(defaultSize);
|
||||
QVERIFY(hv->sectionSize(1) == defaultSize);
|
||||
|
||||
// with hidden sections
|
||||
hv->resizeSection(1, 0);
|
||||
hv->hideSection(2);
|
||||
hv->setDefaultSectionSize(defaultSize);
|
||||
|
||||
QVERIFY(hv->sectionSize(0) == defaultSize); // trivial case.
|
||||
QVERIFY(hv->sectionSize(1) == defaultSize); // just sized 0. Now it should be 10
|
||||
QVERIFY(hv->sectionSize(2) == 0); // section is hidden. It should not be resized.
|
||||
}
|
||||
|
||||
|
||||
void tst_QHeaderView::defaultAlignment_data()
|
||||
{
|
||||
QTest::addColumn<int>("direction");
|
||||
|
Loading…
Reference in New Issue
Block a user