diff options
author | Alexander Volkov <a.volkov@rusbitech.ru> | 2014-09-10 18:09:55 +0400 |
---|---|---|
committer | Alexander Volkov <a.volkov@rusbitech.ru> | 2014-09-15 10:05:25 +0200 |
commit | 256df2484c62aebb9062dd2559399a136678a430 (patch) | |
tree | 4cce109a6ac65a53b9b981a2339ffd0b8bf5d1d4 /tests/auto/widgets | |
parent | 0c748fb7b109244c03eebbceb400db53af95974c (diff) |
Make the default value of QTreeView::indentation() be style dependent
Add a new PM_TreeViewIndentaion enum value to QStyle and get
the corresponding pixel metric in QTreeView.
[ChangeLog][QtWidgets][QTreeView] Indentation is now style-dependent by default.
[ChangeLog][QtWidgets][QTreeView] Added resetIndentation().
Change-Id: Ifad7987b8f3c6cd32987b89d95390f33043d8f19
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Adam Majer <adamm@zombino.com>
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r-- | tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp index 34cfbf8c99..653f158fc9 100644 --- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp @@ -212,6 +212,7 @@ private slots: void rowSizeHint(); void setSortingEnabled(); void headerHidden(); + void indentation(); void selection(); void removeAndInsertExpandedCol0(); @@ -439,7 +440,8 @@ void tst_QTreeView::getSetCheck() // int QTreeView::indentation() // void QTreeView::setIndentation(int) - QCOMPARE(obj1.indentation(), 20); + const int styledIndentation = obj1.style()->pixelMetric(QStyle::PM_TreeViewIndentation, 0, &obj1); + QCOMPARE(obj1.indentation(), styledIndentation); obj1.setIndentation(0); QCOMPARE(obj1.indentation(), 0); obj1.setIndentation(INT_MIN); @@ -554,7 +556,8 @@ void tst_QTreeView::construction() QCOMPARE(view.columnWidth(0), 0); QCOMPARE(view.columnWidth(1), 0); QVERIFY(view.header()); - QCOMPARE(view.indentation(), 20); + const int styledIndentation = view.style()->pixelMetric(QStyle::PM_TreeViewIndentation, 0, &view); + QCOMPARE(view.indentation(), styledIndentation); QCOMPARE(view.indexAbove(QModelIndex()), QModelIndex()); QCOMPARE(view.indexBelow(QModelIndex()), QModelIndex()); QVERIFY(!view.isAnimated()); @@ -2576,6 +2579,42 @@ void tst_QTreeView::headerHidden() QCOMPARE(view.header()->isHidden(), true); } +class TestTreeViewStyle : public QProxyStyle +{ +public: + TestTreeViewStyle() : indentation(20) {} + int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const Q_DECL_OVERRIDE + { + if (metric == QStyle::PM_TreeViewIndentation) + return indentation; + else + return QProxyStyle::pixelMetric(metric, option, widget); + } + int indentation; +}; + +void tst_QTreeView::indentation() +{ + TestTreeViewStyle style1; + TestTreeViewStyle style2; + style1.indentation = 20; + style2.indentation = 30; + + QTreeView view; + view.setStyle(&style1); + QCOMPARE(view.indentation(), style1.indentation); + view.setStyle(&style2); + QCOMPARE(view.indentation(), style2.indentation); + view.setIndentation(70); + QCOMPARE(view.indentation(), 70); + view.setStyle(&style1); + QCOMPARE(view.indentation(), 70); + view.resetIndentation(); + QCOMPARE(view.indentation(), style1.indentation); + view.setStyle(&style2); + QCOMPARE(view.indentation(), style2.indentation); +} + // From Task 145199 (crash when column 0 having at least one expanded item is removed and then // inserted). The test passes simply if it doesn't crash, hence there are no calls // to QCOMPARE() or QVERIFY(). |