|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 |
|
43 #include <QtTest/QtTest> |
|
44 #include <QtCore/QtCore> |
|
45 #include <QtGui/QtGui> |
|
46 |
|
47 /* |
|
48 To add a view to be tested add the header file to the includes |
|
49 and impliment what is needed in the functions below. |
|
50 |
|
51 You can add more then one view, several Qt views are included as examples. |
|
52 |
|
53 In tst_qitemview.cpp a new ViewsToTest object is created for each test. |
|
54 |
|
55 When you have errors fix the first ones first. Later tests depend upon them working |
|
56 */ |
|
57 |
|
58 class ViewsToTest |
|
59 { |
|
60 public: |
|
61 ViewsToTest(); |
|
62 |
|
63 QAbstractItemView *createView(const QString &viewType); |
|
64 void hideIndexes(QAbstractItemView *view); |
|
65 |
|
66 enum Display { DisplayNone, DisplayRoot }; |
|
67 |
|
68 struct test { |
|
69 test(QString m, Display d) : viewType(m), display(d){}; |
|
70 QString viewType; |
|
71 Display display; |
|
72 }; |
|
73 |
|
74 QList<test> tests; |
|
75 }; |
|
76 |
|
77 |
|
78 /*! |
|
79 Add new tests, they can be the same view, but in a different state. |
|
80 */ |
|
81 ViewsToTest::ViewsToTest() |
|
82 { |
|
83 tests.append(test("QTreeView_ScrollPerItem", DisplayRoot)); |
|
84 tests.append(test("QTreeView_ScrollPerPixel", DisplayRoot)); |
|
85 tests.append(test("QListView_ScrollPerItem", DisplayRoot)); |
|
86 tests.append(test("QListView_ScrollPerPixel", DisplayRoot)); |
|
87 tests.append(test("QHeaderViewHorizontal", DisplayNone)); |
|
88 tests.append(test("QHeaderViewVertical", DisplayNone)); |
|
89 tests.append(test("QTableView_ScrollPerItem", DisplayRoot)); |
|
90 tests.append(test("QTableView_ScrollPerPixel", DisplayRoot)); |
|
91 tests.append(test("QTableViewNoGrid", DisplayRoot)); |
|
92 } |
|
93 |
|
94 /*! |
|
95 Return a new viewType. |
|
96 */ |
|
97 QAbstractItemView *ViewsToTest::createView(const QString &viewType) |
|
98 { |
|
99 QAbstractItemView *view = 0; |
|
100 if (viewType == "QListView_ScrollPerItem") { |
|
101 view = new QListView(); |
|
102 view->setObjectName("QListView"); |
|
103 view->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem); |
|
104 view->setVerticalScrollMode(QAbstractItemView::ScrollPerItem); |
|
105 } else if (viewType == "QListView_ScrollPerPixel") { |
|
106 view = new QListView(); |
|
107 view->setObjectName("QListView"); |
|
108 view->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); |
|
109 view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); |
|
110 } else if (viewType == "QHeaderViewHorizontal") { |
|
111 view = new QHeaderView(Qt::Horizontal); |
|
112 view->setObjectName("QHeaderView"); |
|
113 } else if (viewType == "QHeaderViewVertical") { |
|
114 view = new QHeaderView(Qt::Vertical); |
|
115 view->setObjectName("QHeaderView"); |
|
116 } else if (viewType == "QTableView_ScrollPerItem") { |
|
117 view = new QTableView(); |
|
118 view->setObjectName("QTableView"); |
|
119 view->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem); |
|
120 view->setVerticalScrollMode(QAbstractItemView::ScrollPerItem); |
|
121 } else if (viewType == "QTableView_ScrollPerPixel") { |
|
122 view = new QTableView(); |
|
123 view->setObjectName("QTableView"); |
|
124 view->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); |
|
125 view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); |
|
126 } else if (viewType == "QTableViewNoGrid") { |
|
127 QTableView *table = new QTableView(); |
|
128 table->setObjectName("QTableView"); |
|
129 table->setShowGrid(false); |
|
130 view = table; |
|
131 } else if (viewType == "QTreeView_ScrollPerItem") { |
|
132 view = new QTreeView(); |
|
133 view->setObjectName("QTreeView"); |
|
134 view->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem); |
|
135 view->setVerticalScrollMode(QAbstractItemView::ScrollPerItem); |
|
136 view->setSelectionBehavior(QAbstractItemView::SelectItems); |
|
137 } else if (viewType == "QTreeView_ScrollPerPixel") { |
|
138 view = new QTreeView(); |
|
139 view->setObjectName("QTreeView"); |
|
140 view->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); |
|
141 view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); |
|
142 view->setSelectionBehavior(QAbstractItemView::SelectItems); |
|
143 } |
|
144 Q_ASSERT(view); |
|
145 return view; |
|
146 } |
|
147 |
|
148 void ViewsToTest::hideIndexes(QAbstractItemView *view) |
|
149 { |
|
150 if (QTableView *tableView = qobject_cast<QTableView *>(view)) { |
|
151 tableView->setColumnHidden(1, true); |
|
152 tableView->setRowHidden(1, true); |
|
153 tableView->setRowHidden(tableView->model()->rowCount()-2, true); |
|
154 } |
|
155 if (QTreeView *treeView = qobject_cast<QTreeView *>(view)) { |
|
156 treeView->setColumnHidden(1, true); |
|
157 treeView->setRowHidden(1, QModelIndex(), true); |
|
158 treeView->setRowHidden(treeView->model()->rowCount()-2, QModelIndex(), true); |
|
159 } |
|
160 if (QListView *listView = qobject_cast<QListView *>(view)) { |
|
161 listView->setRowHidden(1, true); |
|
162 listView->setRowHidden(listView->model()->rowCount()-2, true); |
|
163 } |
|
164 } |
|
165 |