From bff78163f6dc83d833b2097a51453523cfa7b00b Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 6 Aug 2013 14:08:47 +0200 Subject: QHeaderView::paintSection(): fix visible index handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sections may be hidden => QStyleOptionHeader::position must reflect the state seen on the screen. Otherwise styles will give wrong visual results. Task-number: QTBUG-32203 Change-Id: I7ef86496be092bf6f52ec45f757b501f38c3a431 Reviewed-by: Thorbjørn Lund Martsum Reviewed-by: Stephen Kelly --- .../itemviews/qheaderview/tst_qheaderview.cpp | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp') diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index fa67e16db9..548b74f914 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -59,6 +60,20 @@ typedef QList IntList; typedef QList BoolList; +class TestStyle : public QProxyStyle +{ +public: + void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const + { + if (element == CE_HeaderSection) { + if (const QStyleOptionHeader *header = qstyleoption_cast(option)) + lastPosition = header->position; + } + QProxyStyle::drawControl(element, option, painter, widget); + } + mutable QStyleOptionHeader::SectionPosition lastPosition; +}; + class protected_QHeaderView : public QHeaderView { Q_OBJECT @@ -229,6 +244,7 @@ private slots: void mixedTests(); void resizeToContentTest(); void testStreamWithHide(); + void testStylePosition(); protected: void setupTestData(bool use_reset_model = false); @@ -2732,5 +2748,54 @@ void tst_QHeaderView::testStreamWithHide() #endif } +void tst_QHeaderView::testStylePosition() +{ + topLevel->show(); + QVERIFY(QTest::qWaitForWindowExposed(topLevel)); + + protected_QHeaderView *header = static_cast(view); + + TestStyle proxy; + header->setStyle(&proxy); + + QImage image(1, 1, QImage::Format_ARGB32); + QPainter p(&image); + + // 0, 1, 2, 3 + header->paintSection(&p, view->rect(), 0); + QCOMPARE(proxy.lastPosition, QStyleOptionHeader::Beginning); + header->paintSection(&p, view->rect(), 1); + QCOMPARE(proxy.lastPosition, QStyleOptionHeader::Middle); + header->paintSection(&p, view->rect(), 2); + QCOMPARE(proxy.lastPosition, QStyleOptionHeader::Middle); + header->paintSection(&p, view->rect(), 3); + QCOMPARE(proxy.lastPosition, QStyleOptionHeader::End); + + // (0),2,1,3 + view->setSectionHidden(0, true); + view->swapSections(1, 2); + header->paintSection(&p, view->rect(), 1); + QCOMPARE(proxy.lastPosition, QStyleOptionHeader::Middle); + header->paintSection(&p, view->rect(), 2); + QCOMPARE(proxy.lastPosition, QStyleOptionHeader::Beginning); + header->paintSection(&p, view->rect(), 3); + QCOMPARE(proxy.lastPosition, QStyleOptionHeader::End); + + // (1),2,0,(3) + view->setSectionHidden(3, true); + view->setSectionHidden(0, false); + view->setSectionHidden(1, true); + view->swapSections(0, 1); + header->paintSection(&p, view->rect(), 0); + QCOMPARE(proxy.lastPosition, QStyleOptionHeader::End); + header->paintSection(&p, view->rect(), 2); + QCOMPARE(proxy.lastPosition, QStyleOptionHeader::Beginning); + + // (1),2,(0),(3) + view->setSectionHidden(0, true); + header->paintSection(&p, view->rect(), 2); + QCOMPARE(proxy.lastPosition, QStyleOptionHeader::OnlyOneSection); +} + QTEST_MAIN(tst_QHeaderView) #include "tst_qheaderview.moc" -- cgit v1.2.3