1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #include <QHeaderView> |
30 | #include <QListView> |
31 | #include <QTableView> |
32 | #include <QTreeView> |
33 | |
34 | /* |
35 | To add a view to be tested add the header file to the includes |
36 | and impliment what is needed in the functions below. |
37 | |
38 | You can add more then one view, several Qt views are included as examples. |
39 | |
40 | In tst_qitemview.cpp a new ViewsToTest object is created for each test. |
41 | |
42 | When you have errors fix the first ones first. Later tests depend upon them working |
43 | */ |
44 | |
45 | class ViewsToTest |
46 | { |
47 | public: |
48 | ViewsToTest(); |
49 | |
50 | QAbstractItemView *createView(const QString &viewType); |
51 | void hideIndexes(QAbstractItemView *view); |
52 | |
53 | enum Display { DisplayNone, DisplayRoot }; |
54 | |
55 | struct test { |
56 | test(const QString &m, Display d) : viewType(m), display(d) {} |
57 | QString viewType; |
58 | Display display; |
59 | }; |
60 | |
61 | QVector<test> tests; |
62 | }; |
63 | |
64 | |
65 | /*! |
66 | Add new tests, they can be the same view, but in a different state. |
67 | */ |
68 | ViewsToTest::ViewsToTest() |
69 | { |
70 | tests.append(t: test("QTreeView_ScrollPerItem" , DisplayRoot)); |
71 | tests.append(t: test("QTreeView_ScrollPerPixel" , DisplayRoot)); |
72 | tests.append(t: test("QListView_ScrollPerItem" , DisplayRoot)); |
73 | tests.append(t: test("QListView_ScrollPerPixel" , DisplayRoot)); |
74 | tests.append(t: test("QHeaderViewHorizontal" , DisplayNone)); |
75 | tests.append(t: test("QHeaderViewVertical" , DisplayNone)); |
76 | tests.append(t: test("QTableView_ScrollPerItem" , DisplayRoot)); |
77 | tests.append(t: test("QTableView_ScrollPerPixel" , DisplayRoot)); |
78 | tests.append(t: test("QTableViewNoGrid" , DisplayRoot)); |
79 | } |
80 | |
81 | /*! |
82 | Return a new viewType. |
83 | */ |
84 | QAbstractItemView *ViewsToTest::createView(const QString &viewType) |
85 | { |
86 | QAbstractItemView *view = nullptr; |
87 | if (viewType == "QListView_ScrollPerItem" ) { |
88 | view = new QListView(); |
89 | view->setObjectName("QListView" ); |
90 | view->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem); |
91 | view->setVerticalScrollMode(QAbstractItemView::ScrollPerItem); |
92 | } else if (viewType == "QListView_ScrollPerPixel" ) { |
93 | view = new QListView(); |
94 | view->setObjectName("QListView" ); |
95 | view->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); |
96 | view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); |
97 | } else if (viewType == "QHeaderViewHorizontal" ) { |
98 | view = new QHeaderView(Qt::Horizontal); |
99 | view->setObjectName("QHeaderView" ); |
100 | } else if (viewType == "QHeaderViewVertical" ) { |
101 | view = new QHeaderView(Qt::Vertical); |
102 | view->setObjectName("QHeaderView" ); |
103 | } else if (viewType == "QTableView_ScrollPerItem" ) { |
104 | view = new QTableView(); |
105 | view->setObjectName("QTableView" ); |
106 | view->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem); |
107 | view->setVerticalScrollMode(QAbstractItemView::ScrollPerItem); |
108 | } else if (viewType == "QTableView_ScrollPerPixel" ) { |
109 | view = new QTableView(); |
110 | view->setObjectName("QTableView" ); |
111 | view->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); |
112 | view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); |
113 | } else if (viewType == "QTableViewNoGrid" ) { |
114 | QTableView *table = new QTableView(); |
115 | table->setObjectName("QTableView" ); |
116 | table->setShowGrid(false); |
117 | view = table; |
118 | } else if (viewType == "QTreeView_ScrollPerItem" ) { |
119 | view = new QTreeView(); |
120 | view->setObjectName("QTreeView" ); |
121 | view->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem); |
122 | view->setVerticalScrollMode(QAbstractItemView::ScrollPerItem); |
123 | view->setSelectionBehavior(QAbstractItemView::SelectItems); |
124 | } else if (viewType == "QTreeView_ScrollPerPixel" ) { |
125 | view = new QTreeView(); |
126 | view->setObjectName("QTreeView" ); |
127 | view->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); |
128 | view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); |
129 | view->setSelectionBehavior(QAbstractItemView::SelectItems); |
130 | } |
131 | return view; |
132 | } |
133 | |
134 | void ViewsToTest::hideIndexes(QAbstractItemView *view) |
135 | { |
136 | if (QTableView *tableView = qobject_cast<QTableView *>(object: view)) { |
137 | tableView->setColumnHidden(column: 1, hide: true); |
138 | tableView->setRowHidden(row: 1, hide: true); |
139 | tableView->setRowHidden(row: tableView->model()->rowCount() - 2, hide: true); |
140 | } |
141 | if (QTreeView *treeView = qobject_cast<QTreeView *>(object: view)) { |
142 | treeView->setColumnHidden(column: 1, hide: true); |
143 | treeView->setRowHidden(row: 1, parent: QModelIndex(), hide: true); |
144 | treeView->setRowHidden(row: treeView->model()->rowCount() - 2, parent: QModelIndex(), hide: true); |
145 | } |
146 | if (QListView *listView = qobject_cast<QListView *>(object: view)) { |
147 | listView->setRowHidden(row: 1, hide: true); |
148 | listView->setRowHidden(row: listView->model()->rowCount() - 2, hide: true); |
149 | } |
150 | } |
151 | |
152 | |