0
|
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 |
|
|
45 |
|
|
46 |
#include <q3header.h>
|
|
47 |
#include <q3listview.h>
|
|
48 |
#include <qapplication.h>
|
|
49 |
#include <qlineedit.h>
|
|
50 |
#include <qpointer.h>
|
|
51 |
#include <qvector.h>
|
|
52 |
|
|
53 |
Q_DECLARE_METATYPE(QPoint)
|
|
54 |
|
|
55 |
QT_BEGIN_NAMESPACE
|
|
56 |
template<> struct QMetaTypeId<Q3ListView::StringComparisonMode>
|
|
57 |
{ enum { Defined = 1 }; static inline int qt_metatype_id() { return QMetaType::Int; } };
|
|
58 |
QT_END_NAMESPACE
|
|
59 |
|
|
60 |
|
|
61 |
//TESTED_CLASS=
|
|
62 |
//TESTED_FILES=
|
|
63 |
|
|
64 |
class tst_Q3ListView : public QObject
|
|
65 |
{
|
|
66 |
Q_OBJECT
|
|
67 |
|
|
68 |
public:
|
|
69 |
tst_Q3ListView();
|
|
70 |
virtual ~tst_Q3ListView();
|
|
71 |
|
|
72 |
|
|
73 |
public slots:
|
|
74 |
void selectionChanged() { changed++; }
|
|
75 |
void selectionChanged( Q3ListViewItem* ) { changedItem++; }
|
|
76 |
void spacePressed( Q3ListViewItem *item ) { pressCount++; pressedItem = item; }
|
|
77 |
void itemRenamed(Q3ListViewItem *item, int column);
|
|
78 |
void itemRenamed(Q3ListViewItem *item, int column, const QString &text);
|
|
79 |
void contextMenu(Q3ListViewItem *item, const QPoint &pos, int col);
|
|
80 |
void doubleClicked(Q3ListViewItem *item) { doubleClickCount++; pressedItem = item; }
|
|
81 |
|
|
82 |
public slots:
|
|
83 |
void initTestCase();
|
|
84 |
void cleanupTestCase();
|
|
85 |
void init();
|
|
86 |
void cleanup();
|
|
87 |
private slots:
|
|
88 |
void getSetCheck();
|
|
89 |
void sortchild();
|
|
90 |
void takeItem_data();
|
|
91 |
void takeItem();
|
|
92 |
void selections_mouseClick_data();
|
|
93 |
void selections_mouseClick();
|
|
94 |
void isVisible();
|
|
95 |
void itemRenaming();
|
|
96 |
void removeColumn();
|
|
97 |
void contextMenuRequested_data();
|
|
98 |
void contextMenuRequested();
|
|
99 |
void itemActivate();
|
|
100 |
void findItem_data();
|
|
101 |
void findItem();
|
|
102 |
void spacePress_data();
|
|
103 |
void spacePress();
|
|
104 |
void adjustColumn();
|
|
105 |
void mouseClickEvents();
|
|
106 |
void mouseClickEvents_data();
|
|
107 |
|
|
108 |
private:
|
|
109 |
QPoint itemCenter( Q3ListView* view, Q3ListViewItem* item, int column = 0);
|
|
110 |
QPoint itemBelow( Q3ListView* view, Q3ListViewItem* item );
|
|
111 |
QString selectionName( int );
|
|
112 |
QString buttonName( int );
|
|
113 |
QString keyName( Qt::KeyboardModifiers );
|
|
114 |
void resetVariables();
|
|
115 |
|
|
116 |
private:
|
|
117 |
Q3ListView*testWidget;
|
|
118 |
int changed, changedItem;
|
|
119 |
|
|
120 |
int pressCount;
|
|
121 |
int doubleClickCount;
|
|
122 |
Q3ListViewItem *pressedItem;
|
|
123 |
|
|
124 |
bool itemRenamedSignalOneReceived, itemRenamedSignalTwoReceived;
|
|
125 |
Q3ListViewItem *itemRenamedOne, *itemRenamedTwo;
|
|
126 |
int columnRenamedOne, columnRenamedTwo;
|
|
127 |
QString textRenamed;
|
|
128 |
|
|
129 |
bool contextMenuRequestedSignalReceived;
|
|
130 |
Q3ListViewItem *contextMenuRequestedItem;
|
|
131 |
QPoint contextMenuRequestedPos;
|
|
132 |
int contextMenuRequestedCol;
|
|
133 |
|
|
134 |
};
|
|
135 |
|
|
136 |
// Testing get/set functions
|
|
137 |
void tst_Q3ListView::getSetCheck()
|
|
138 |
{
|
|
139 |
Q3ListView obj1;
|
|
140 |
// SelectionMode Q3ListView::selectionMode()
|
|
141 |
// void Q3ListView::setSelectionMode(SelectionMode)
|
|
142 |
obj1.setSelectionMode(Q3ListView::SelectionMode(0));
|
|
143 |
QCOMPARE(Q3ListView::SelectionMode(0), obj1.selectionMode());
|
|
144 |
obj1.setSelectionMode(Q3ListView::SelectionMode(1));
|
|
145 |
QCOMPARE(Q3ListView::SelectionMode(1), obj1.selectionMode());
|
|
146 |
|
|
147 |
// int Q3ListView::sortColumn()
|
|
148 |
// void Q3ListView::setSortColumn(int)
|
|
149 |
obj1.setSortColumn(0);
|
|
150 |
QCOMPARE(0, obj1.sortColumn());
|
|
151 |
obj1.setSortColumn(INT_MIN);
|
|
152 |
QCOMPARE(INT_MIN, obj1.sortColumn());
|
|
153 |
obj1.setSortColumn(INT_MAX);
|
|
154 |
QCOMPARE(INT_MAX, obj1.sortColumn());
|
|
155 |
|
|
156 |
Q3CheckListItem obj2(&obj1, "Item1", Q3CheckListItem::CheckBox);
|
|
157 |
obj2.setTristate(true);
|
|
158 |
// ToggleState Q3CheckListItem::state()
|
|
159 |
// void Q3CheckListItem::setState(ToggleState)
|
|
160 |
obj2.setState(Q3CheckListItem::ToggleState(Q3CheckListItem::Off));
|
|
161 |
QCOMPARE(Q3CheckListItem::ToggleState(Q3CheckListItem::Off), obj2.state());
|
|
162 |
obj2.setState(Q3CheckListItem::ToggleState(Q3CheckListItem::NoChange));
|
|
163 |
QCOMPARE(Q3CheckListItem::ToggleState(Q3CheckListItem::NoChange), obj2.state());
|
|
164 |
obj2.setState(Q3CheckListItem::ToggleState(Q3CheckListItem::On));
|
|
165 |
QCOMPARE(Q3CheckListItem::ToggleState(Q3CheckListItem::On), obj2.state());
|
|
166 |
}
|
|
167 |
|
|
168 |
typedef QList<int> IntList;
|
|
169 |
Q_DECLARE_METATYPE(IntList)
|
|
170 |
|
|
171 |
typedef QList<void*> ItemList;
|
|
172 |
Q_DECLARE_METATYPE(ItemList)
|
|
173 |
|
|
174 |
Q_DECLARE_METATYPE(Q3ListView::SelectionMode)
|
|
175 |
|
|
176 |
tst_Q3ListView::tst_Q3ListView()
|
|
177 |
{
|
|
178 |
}
|
|
179 |
|
|
180 |
tst_Q3ListView::~tst_Q3ListView()
|
|
181 |
{
|
|
182 |
|
|
183 |
}
|
|
184 |
|
|
185 |
void tst_Q3ListView::initTestCase()
|
|
186 |
{
|
|
187 |
// Create the test class
|
|
188 |
}
|
|
189 |
|
|
190 |
void tst_Q3ListView::cleanupTestCase()
|
|
191 |
{
|
|
192 |
}
|
|
193 |
|
|
194 |
void tst_Q3ListView::init()
|
|
195 |
{
|
|
196 |
testWidget = new Q3ListView(0,"testObject");
|
|
197 |
testWidget->resize(200,200);
|
|
198 |
testWidget->show();
|
|
199 |
pressCount = 0;
|
|
200 |
pressedItem = 0;
|
|
201 |
connect( testWidget, SIGNAL( spacePressed( Q3ListViewItem* ) ),
|
|
202 |
this, SLOT( spacePressed( Q3ListViewItem* ) ) );
|
|
203 |
itemRenamedSignalOneReceived = FALSE;
|
|
204 |
itemRenamedSignalTwoReceived = FALSE;
|
|
205 |
itemRenamedOne = 0;
|
|
206 |
itemRenamedTwo = 0;
|
|
207 |
columnRenamedOne = -1;
|
|
208 |
columnRenamedTwo = -1;
|
|
209 |
textRenamed = QString();
|
|
210 |
|
|
211 |
contextMenuRequestedSignalReceived = FALSE;
|
|
212 |
contextMenuRequestedItem = 0;
|
|
213 |
contextMenuRequestedPos = QPoint();
|
|
214 |
contextMenuRequestedCol = -1;
|
|
215 |
}
|
|
216 |
|
|
217 |
void tst_Q3ListView::cleanup()
|
|
218 |
{
|
|
219 |
delete testWidget;
|
|
220 |
testWidget = 0;
|
|
221 |
}
|
|
222 |
|
|
223 |
void tst_Q3ListView::sortchild()
|
|
224 |
{
|
|
225 |
Q3ListView* listview = new Q3ListView( 0 );
|
|
226 |
|
|
227 |
listview->addColumn( "" );
|
|
228 |
|
|
229 |
Q3ListViewItem* item1 = new Q3ListViewItem( listview, "zzz" );
|
|
230 |
Q3ListViewItem* item2 = new Q3ListViewItem( listview, "hhh" );
|
|
231 |
Q3ListViewItem* item3 = new Q3ListViewItem( listview, "bbb" );
|
|
232 |
Q3ListViewItem* item4 = new Q3ListViewItem( listview, "jjj" );
|
|
233 |
Q3ListViewItem* item5 = new Q3ListViewItem( listview, "ddd" );
|
|
234 |
Q3ListViewItem* item6 = new Q3ListViewItem( listview, "lll" );
|
|
235 |
|
|
236 |
Q3ListViewItem* item3b = new Q3ListViewItem( item3, "234" );
|
|
237 |
Q3ListViewItem* item3c = new Q3ListViewItem( item3, "345" );
|
|
238 |
Q3ListViewItem* item3a = new Q3ListViewItem( item3, "123" );
|
|
239 |
|
|
240 |
listview->setOpen( item3, TRUE );
|
|
241 |
|
|
242 |
listview->setSorting( 0, TRUE );
|
|
243 |
listview->show();
|
|
244 |
|
|
245 |
Q3ListViewItem *item = listview->firstChild();
|
|
246 |
QVERIFY( item == item3 );
|
|
247 |
item = item->itemBelow();
|
|
248 |
QVERIFY( item == item3a );
|
|
249 |
item = item->itemBelow();
|
|
250 |
QVERIFY( item == item3b );
|
|
251 |
item = item->itemBelow();
|
|
252 |
QVERIFY( item == item3c );
|
|
253 |
item = item->itemBelow();
|
|
254 |
QVERIFY( item == item5 );
|
|
255 |
item = item->itemBelow();
|
|
256 |
QVERIFY( item == item2 );
|
|
257 |
item = item->itemBelow();
|
|
258 |
QVERIFY( item == item4 );
|
|
259 |
item = item->itemBelow();
|
|
260 |
QVERIFY( item == item6 );
|
|
261 |
item = item->itemBelow();
|
|
262 |
QVERIFY( item == item1 );
|
|
263 |
|
|
264 |
listview->setSorting( 0, FALSE );
|
|
265 |
|
|
266 |
item = listview->firstChild();
|
|
267 |
QVERIFY( item == item1 );
|
|
268 |
item = item->itemBelow();
|
|
269 |
QVERIFY( item == item6 );
|
|
270 |
item = item->itemBelow();
|
|
271 |
QVERIFY( item == item4 );
|
|
272 |
item = item->itemBelow();
|
|
273 |
QVERIFY( item == item2 );
|
|
274 |
item = item->itemBelow();
|
|
275 |
QVERIFY( item == item5 );
|
|
276 |
item = item->itemBelow();
|
|
277 |
QVERIFY( item == item3 );
|
|
278 |
item = item->itemBelow();
|
|
279 |
QVERIFY( item == item3c );
|
|
280 |
item = item->itemBelow();
|
|
281 |
QVERIFY( item == item3b );
|
|
282 |
item = item->itemBelow();
|
|
283 |
QVERIFY( item == item3a );
|
|
284 |
|
|
285 |
item = listview->firstChild();
|
|
286 |
item->moveItem( item->itemBelow() );
|
|
287 |
|
|
288 |
listview->setSorting( 0, FALSE );
|
|
289 |
QVERIFY( item == listview->firstChild() );
|
|
290 |
|
|
291 |
delete listview;
|
|
292 |
}
|
|
293 |
|
|
294 |
void tst_Q3ListView::takeItem_data()
|
|
295 |
{
|
|
296 |
QTest::addColumn<Q3ListView::SelectionMode>("selectionMode");
|
|
297 |
QTest::addColumn<int>("selectItem");
|
|
298 |
QTest::addColumn<int>("selectItemAfterTake");
|
|
299 |
|
|
300 |
QTest::newRow( "SelectionMode::Single, item0 selected" ) << Q3ListView::Single
|
|
301 |
<< 0
|
|
302 |
<< -1;
|
|
303 |
QTest::newRow( "SelectionMode::Single, item1 selected" ) << Q3ListView::Single
|
|
304 |
<< 1
|
|
305 |
<< -1;
|
|
306 |
QTest::newRow( "SelectionMode::Single, item2 selected" ) << Q3ListView::Single
|
|
307 |
<< 2
|
|
308 |
<< 2;
|
|
309 |
|
|
310 |
QTest::newRow( "SelectionMode::Multi, item0 selected" ) << Q3ListView::Multi
|
|
311 |
<< 0
|
|
312 |
<< -1;
|
|
313 |
QTest::newRow( "SelectionMode::Multi, item1 selected" ) << Q3ListView::Multi
|
|
314 |
<< 1
|
|
315 |
<< -1;
|
|
316 |
QTest::newRow( "SelectionMode::Multi, item2 selected" ) << Q3ListView::Multi
|
|
317 |
<< 2
|
|
318 |
<< 2;
|
|
319 |
|
|
320 |
QTest::newRow( "SelectionMode::Extended, item0 selected" ) << Q3ListView::Extended
|
|
321 |
<< 0
|
|
322 |
<< -1;
|
|
323 |
QTest::newRow( "SelectionMode::Extended, item1 selected" ) << Q3ListView::Extended
|
|
324 |
<< 1
|
|
325 |
<< -1;
|
|
326 |
QTest::newRow( "SelectionMode::Extended, item2 selected" ) << Q3ListView::Extended
|
|
327 |
<< 2
|
|
328 |
<< 2;
|
|
329 |
}
|
|
330 |
|
|
331 |
void tst_Q3ListView::takeItem()
|
|
332 |
{
|
|
333 |
testWidget->clear();
|
|
334 |
|
|
335 |
QFETCH( Q3ListView::SelectionMode, selectionMode );
|
|
336 |
QFETCH( int, selectItem );
|
|
337 |
QFETCH( int, selectItemAfterTake );
|
|
338 |
|
|
339 |
QVector<Q3ListViewItem*> items(3);
|
|
340 |
|
|
341 |
// tree:
|
|
342 |
// Item0
|
|
343 |
// Item1
|
|
344 |
// Item2
|
|
345 |
for ( int i=0; i<3; i++ ) {
|
|
346 |
if ( i == 1 ) {
|
|
347 |
items.insert( i, new Q3ListViewItem( items.at( 0 ), QString("Item: %1").arg( i ) ) );
|
|
348 |
} else
|
|
349 |
items.insert( i, new Q3ListViewItem( testWidget, QString("Item: %1").arg( i ) ) );
|
|
350 |
}
|
|
351 |
|
|
352 |
testWidget->setSelectionMode( selectionMode );
|
|
353 |
testWidget->setSelected( items.at( selectItem ), TRUE );
|
|
354 |
|
|
355 |
changed = 0;
|
|
356 |
changedItem = 0;
|
|
357 |
connect( testWidget, SIGNAL( selectionChanged() ),
|
|
358 |
this, SLOT( selectionChanged() ) );
|
|
359 |
connect( testWidget, SIGNAL( selectionChanged( Q3ListViewItem* ) ),
|
|
360 |
this, SLOT( selectionChanged( Q3ListViewItem* ) ) );
|
|
361 |
|
|
362 |
testWidget->takeItem( items.at( 0 ) );
|
|
363 |
|
|
364 |
if ( selectionMode == Q3ListView::Single ) {
|
|
365 |
Q3ListViewItem *item = selectItemAfterTake == -1 ? 0 : items.at( selectItemAfterTake );
|
|
366 |
// verify that selectedItem have been properly updated after take
|
|
367 |
QVERIFY( testWidget->selectedItem() == item );
|
|
368 |
if ( selectItemAfterTake == -1 ) {
|
|
369 |
// verify that the selected taken item is unselected as well
|
|
370 |
QVERIFY( items.at( selectItem )->isSelected() == FALSE );
|
|
371 |
// verify that that taking the selectedItem (or parent of it) emits selectionChanged (but not selectionChanged( item )
|
|
372 |
QVERIFY( changed == 1 );
|
|
373 |
QVERIFY( changedItem == 0 );
|
|
374 |
} else {
|
|
375 |
// verify that if we still have selection, no selectionChanged was emitted
|
|
376 |
QVERIFY( changed == 0 );
|
|
377 |
QVERIFY( changedItem == 0 );
|
|
378 |
}
|
|
379 |
} else {
|
|
380 |
// verify for Multi and Extended that no selectionChanged is emitted
|
|
381 |
QVERIFY( changed == 0 );
|
|
382 |
QVERIFY( changedItem == 0 );
|
|
383 |
}
|
|
384 |
|
|
385 |
disconnect( testWidget, 0, this, 0 );
|
|
386 |
|
|
387 |
delete items[0];
|
|
388 |
delete items[2];
|
|
389 |
}
|
|
390 |
|
|
391 |
Qt::KeyboardModifiers intToKey( int stateKey )
|
|
392 |
{
|
|
393 |
switch( stateKey )
|
|
394 |
{
|
|
395 |
case 0: return Qt::NoModifier;
|
|
396 |
case 1: return Qt::ShiftModifier;
|
|
397 |
case 2: return Qt::ControlModifier;
|
|
398 |
case 3: return Qt::AltModifier;
|
|
399 |
}
|
|
400 |
return Qt::NoModifier;
|
|
401 |
}
|
|
402 |
|
|
403 |
void tst_Q3ListView::selections_mouseClick_data()
|
|
404 |
{
|
|
405 |
QTest::addColumn<IntList>("selectedItems");
|
|
406 |
QTest::addColumn<IntList>("clickItems");
|
|
407 |
QTest::addColumn<IntList>("buttonList");
|
|
408 |
QTest::addColumn<IntList>("keyList");
|
|
409 |
QTest::addColumn<Q3ListView::SelectionMode>("selectionMode");
|
|
410 |
|
|
411 |
|
|
412 |
|
|
413 |
for (int mode = Q3ListView::Single; mode <= Q3ListView::NoSelection; mode++ ) {
|
|
414 |
for ( int button = Qt::LeftButton; button <= Qt::RightButton; button++ ) {
|
|
415 |
for ( int s = 0; s < 4; s++ ) {
|
|
416 |
Qt::KeyboardModifiers key = intToKey( s );
|
|
417 |
if ( key != Qt::AltModifier ) {
|
|
418 |
/* tests clicking on item0 with all different selection modes, buttons and statekeys (except Alt) */
|
|
419 |
IntList selectedItems;
|
|
420 |
IntList clickItems;
|
|
421 |
IntList buttonList;
|
|
422 |
IntList keyList;
|
|
423 |
|
|
424 |
if ( mode == Q3ListView::NoSelection ||
|
|
425 |
(button == Qt::RightButton && key == Qt::ControlModifier ) );
|
|
426 |
// don't expect any selections here
|
|
427 |
else
|
|
428 |
selectedItems << 0;
|
|
429 |
clickItems << 0;
|
|
430 |
buttonList << button;
|
|
431 |
keyList << key;
|
|
432 |
QTest::newRow( "Clicking " + buttonName( button ) + " on item0 with "
|
|
433 |
+ keyName( key ) + " in " + selectionName( mode ) )
|
|
434 |
<< selectedItems
|
|
435 |
<< clickItems
|
|
436 |
<< buttonList
|
|
437 |
<< keyList
|
|
438 |
<< (Q3ListView::SelectionMode) mode;
|
|
439 |
}
|
|
440 |
if ( mode != Q3ListView::NoSelection && key == Qt::NoModifier ) {
|
|
441 |
/* tests selecting item0 and item1, then clicking outside the items to clear the selections */
|
|
442 |
IntList selectedItems;
|
|
443 |
IntList clickItems;
|
|
444 |
IntList buttonList;
|
|
445 |
IntList keyList;
|
|
446 |
|
|
447 |
clickItems << 0 << 1 << -1;
|
|
448 |
buttonList << Qt::LeftButton << Qt::LeftButton << button;
|
|
449 |
keyList << Qt::NoModifier << Qt::NoModifier << key;
|
|
450 |
|
|
451 |
QTest::newRow( "Selecting item0 and item1, then clicking "
|
|
452 |
+ buttonName( button ) + " right of item0 with "
|
|
453 |
+ keyName( key ) + " in " + selectionName( mode ) )
|
|
454 |
<< selectedItems
|
|
455 |
<< clickItems
|
|
456 |
<< buttonList
|
|
457 |
<< keyList
|
|
458 |
<< (Q3ListView::SelectionMode) mode;
|
|
459 |
}
|
|
460 |
if ( mode != Q3ListView::NoSelection &&
|
|
461 |
button == Qt::RightButton &&
|
|
462 |
key == Qt::ControlModifier ) {
|
|
463 |
/* tests selecting item0, then selects item1 with RightButton+ControlKey, selection should stay the same */
|
|
464 |
IntList selectedItems;
|
|
465 |
IntList clickItems;
|
|
466 |
IntList buttonList;
|
|
467 |
IntList keyList;
|
|
468 |
|
|
469 |
selectedItems << 0;
|
|
470 |
clickItems << 0 << 1;
|
|
471 |
buttonList << Qt::LeftButton << button;
|
|
472 |
keyList << Qt::NoModifier << key;
|
|
473 |
|
|
474 |
QTest::newRow( "Selecting item0, then clicking "
|
|
475 |
+ buttonName( button ) + " on item1 with "
|
|
476 |
+ keyName( key ) + " in " + selectionName( mode ) )
|
|
477 |
<< selectedItems
|
|
478 |
<< clickItems
|
|
479 |
<< buttonList
|
|
480 |
<< keyList
|
|
481 |
<< (Q3ListView::SelectionMode) mode;
|
|
482 |
}
|
|
483 |
if ( mode != Q3ListView::NoSelection &&
|
|
484 |
button == Qt::RightButton &&
|
|
485 |
key == Qt::ControlModifier ) {
|
|
486 |
/* tests selecting item0, then click right of item0 with RightButton+ControlKey, selection should stay the same */
|
|
487 |
IntList selectedItems;
|
|
488 |
IntList clickItems;
|
|
489 |
IntList buttonList;
|
|
490 |
IntList keyList;
|
|
491 |
|
|
492 |
selectedItems << 0;
|
|
493 |
clickItems << 0 << -1;
|
|
494 |
buttonList << Qt::LeftButton << button;
|
|
495 |
keyList << Qt::NoModifier << key;
|
|
496 |
|
|
497 |
QTest::newRow( "Selecting item0, then clicking "
|
|
498 |
+ buttonName( button ) + " right of item0 with "
|
|
499 |
+ keyName( key ) + " in " + selectionName( mode ) )
|
|
500 |
<< selectedItems
|
|
501 |
<< clickItems
|
|
502 |
<< buttonList
|
|
503 |
<< keyList
|
|
504 |
<< (Q3ListView::SelectionMode) mode;
|
|
505 |
}
|
|
506 |
}
|
|
507 |
}
|
|
508 |
}
|
|
509 |
}
|
|
510 |
|
|
511 |
void tst_Q3ListView::selections_mouseClick()
|
|
512 |
{
|
|
513 |
|
|
514 |
QFETCH( IntList, selectedItems );
|
|
515 |
QFETCH( IntList, clickItems );
|
|
516 |
QFETCH( IntList, buttonList );
|
|
517 |
QFETCH( IntList, keyList );
|
|
518 |
QFETCH( Q3ListView::SelectionMode, selectionMode );
|
|
519 |
|
|
520 |
QVERIFY( clickItems.count() == buttonList.count() &&
|
|
521 |
buttonList.count() == keyList.count() );
|
|
522 |
|
|
523 |
Q3ListView listView( 0 );
|
|
524 |
|
|
525 |
listView.setSelectionMode( selectionMode );
|
|
526 |
listView.addColumn( "First" );
|
|
527 |
listView.addColumn( "Second" );
|
|
528 |
|
|
529 |
// tree:
|
|
530 |
// Item0
|
|
531 |
// Item1
|
|
532 |
// Item2
|
|
533 |
QVector<Q3ListViewItem*> items;
|
|
534 |
int i;
|
|
535 |
for (i = 0; i < 3; ++i) {
|
|
536 |
items.append(new Q3ListViewItem( &listView, QString("Item: %1").arg( i ) ));
|
|
537 |
}
|
|
538 |
listView.setSorting( 0, TRUE );
|
|
539 |
listView.show();
|
|
540 |
|
|
541 |
for ( i=0; i<(int)clickItems.count(); i++ ) {
|
|
542 |
// find point to click, -1 means outside any item
|
|
543 |
QPoint clickPoint = (clickItems[ i ] == -1) ?
|
|
544 |
itemBelow( &listView, items[ 2 ] ) :
|
|
545 |
itemCenter( &listView, items[ clickItems[i] ] );
|
|
546 |
// send the mouse click event
|
|
547 |
QTest::mouseClick( listView.viewport(), (Qt::MouseButton)buttonList.at(i),
|
|
548 |
(Qt::KeyboardModifier) keyList.at(i),
|
|
549 |
clickPoint );
|
|
550 |
}
|
|
551 |
|
|
552 |
// while ( listView.isVisible() )
|
|
553 |
// qApp->processEvents();
|
|
554 |
|
|
555 |
for (i = 0; i < items.count(); ++i) {
|
|
556 |
Q3ListViewItem *item = items.at(i);
|
|
557 |
Q_ASSERT(item);
|
|
558 |
if ( item->isSelected() ) {
|
|
559 |
QVERIFY( selectedItems.contains( i ) );
|
|
560 |
} else {
|
|
561 |
QVERIFY( !selectedItems.contains( i ) );
|
|
562 |
}
|
|
563 |
}
|
|
564 |
}
|
|
565 |
|
|
566 |
QPoint tst_Q3ListView::itemCenter( Q3ListView* view, Q3ListViewItem* item, int )
|
|
567 |
{
|
|
568 |
if ( view && item )
|
|
569 |
return QPoint( view->itemRect( item ).x() + 10, view->itemRect( item ).center().y() );
|
|
570 |
return QPoint();
|
|
571 |
}
|
|
572 |
|
|
573 |
QPoint tst_Q3ListView::itemBelow( Q3ListView* view, Q3ListViewItem* item )
|
|
574 |
{
|
|
575 |
if ( view && item ) {
|
|
576 |
QRect i = view->itemRect( item );
|
|
577 |
return QPoint( i.center().x(), i.bottom()+10 );
|
|
578 |
}
|
|
579 |
return QPoint();
|
|
580 |
}
|
|
581 |
|
|
582 |
|
|
583 |
QString tst_Q3ListView::selectionName( int selectionMode )
|
|
584 |
{
|
|
585 |
switch ( selectionMode ) {
|
|
586 |
case Q3ListView::Single:
|
|
587 |
return "Single";
|
|
588 |
case Q3ListView::Multi:
|
|
589 |
return "Multi";
|
|
590 |
case Q3ListView::Extended:
|
|
591 |
return "Extended";
|
|
592 |
case Q3ListView::NoSelection:
|
|
593 |
return "NoSelection";
|
|
594 |
default:
|
|
595 |
return "Unknown SelectionMode";
|
|
596 |
}
|
|
597 |
}
|
|
598 |
|
|
599 |
QString tst_Q3ListView::buttonName( int mouseButton )
|
|
600 |
{
|
|
601 |
switch ( mouseButton ) {
|
|
602 |
case Qt::LeftButton:
|
|
603 |
return "LeftButton";
|
|
604 |
case Qt::MidButton:
|
|
605 |
return "MidButton";
|
|
606 |
case Qt::RightButton:
|
|
607 |
return "RightButton";
|
|
608 |
default:
|
|
609 |
return "Unknown button";
|
|
610 |
}
|
|
611 |
}
|
|
612 |
|
|
613 |
QString tst_Q3ListView::keyName( Qt::KeyboardModifiers stateKey )
|
|
614 |
{
|
|
615 |
switch ( stateKey ) {
|
|
616 |
case Qt::NoModifier:
|
|
617 |
return "NoKey";
|
|
618 |
case Qt::ShiftModifier:
|
|
619 |
return "ShiftKey";
|
|
620 |
case Qt::ControlModifier:
|
|
621 |
return "ControlKey";
|
|
622 |
case Qt::AltModifier:
|
|
623 |
return "AltKey";
|
|
624 |
default:
|
|
625 |
return "Unknown key";
|
|
626 |
}
|
|
627 |
}
|
|
628 |
|
|
629 |
void tst_Q3ListView::isVisible()
|
|
630 |
{
|
|
631 |
Q3ListView listview( 0 );
|
|
632 |
Q3ListViewItem* tlOne = new Q3ListViewItem( &listview, "Item One" );
|
|
633 |
Q3ListViewItem* tlTwo = new Q3ListViewItem( &listview, "Item Two" );
|
|
634 |
Q3ListViewItem* tlThree = new Q3ListViewItem( &listview, "Item Three" );
|
|
635 |
|
|
636 |
Q3ListViewItem* tlTwoCOne = new Q3ListViewItem( tlTwo, "Child One of Item Two" );
|
|
637 |
Q3ListViewItem* tlTwoCTwo = new Q3ListViewItem( tlTwo, "Child Two of Item Two" );
|
|
638 |
Q3ListViewItem* tlTwoCThree = new Q3ListViewItem( tlTwo, "Child Three of Item Two" );
|
|
639 |
|
|
640 |
Q3ListViewItem* tlTwoCTwoCOne = new Q3ListViewItem( tlTwoCTwo, "Child One of Child Two of Item Two" );
|
|
641 |
Q3ListViewItem* tlTwoCTwoCTwo = new Q3ListViewItem( tlTwoCTwo, "Child Two of Child Two of Item Two" );
|
|
642 |
Q3ListViewItem* tlTwoCTwoCThree = new Q3ListViewItem( tlTwoCTwo, "Child Three of Child Two of Item Two" );
|
|
643 |
Q_UNUSED(tlTwoCTwoCThree);
|
|
644 |
Q_UNUSED(tlTwoCTwoCOne);
|
|
645 |
Q_UNUSED(tlTwoCThree);
|
|
646 |
Q_UNUSED(tlThree);
|
|
647 |
|
|
648 |
listview.show();
|
|
649 |
tlOne->setVisible( FALSE );
|
|
650 |
|
|
651 |
QVERIFY( !tlOne->isVisible() );
|
|
652 |
QVERIFY( tlTwo->isVisible() );
|
|
653 |
QVERIFY( tlTwoCOne->isVisible() );
|
|
654 |
QVERIFY( tlTwoCTwoCTwo->isVisible() );
|
|
655 |
|
|
656 |
tlTwo->setVisible( FALSE );
|
|
657 |
QVERIFY( !tlTwo->isVisible() );
|
|
658 |
QVERIFY( !tlTwoCOne->isVisible() );
|
|
659 |
QVERIFY( !tlTwoCTwoCTwo->isVisible() );
|
|
660 |
|
|
661 |
tlTwoCTwoCTwo->setVisible( TRUE );
|
|
662 |
QVERIFY( !tlTwo->isVisible() );
|
|
663 |
QVERIFY( !tlTwoCOne->isVisible() );
|
|
664 |
QVERIFY( !tlTwoCTwoCTwo->isVisible() );
|
|
665 |
|
|
666 |
tlTwo->setVisible( TRUE );
|
|
667 |
QVERIFY( tlTwo->isVisible() );
|
|
668 |
QVERIFY( tlTwoCOne->isVisible() );
|
|
669 |
QVERIFY( tlTwoCTwoCTwo->isVisible() );
|
|
670 |
}
|
|
671 |
|
|
672 |
void tst_Q3ListView::itemRenamed(Q3ListViewItem *item, int column, const QString &text)
|
|
673 |
{
|
|
674 |
itemRenamedOne = item;
|
|
675 |
columnRenamedOne = column;
|
|
676 |
textRenamed = text;
|
|
677 |
itemRenamedSignalOneReceived = TRUE;
|
|
678 |
}
|
|
679 |
|
|
680 |
void tst_Q3ListView::itemRenamed(Q3ListViewItem *item, int column)
|
|
681 |
{
|
|
682 |
itemRenamedTwo = item;
|
|
683 |
columnRenamedTwo = column;
|
|
684 |
itemRenamedSignalTwoReceived = TRUE;
|
|
685 |
}
|
|
686 |
|
|
687 |
void tst_Q3ListView::resetVariables()
|
|
688 |
{
|
|
689 |
itemRenamedSignalOneReceived = FALSE;
|
|
690 |
itemRenamedSignalTwoReceived = FALSE;
|
|
691 |
itemRenamedOne = 0;
|
|
692 |
itemRenamedTwo = 0;
|
|
693 |
columnRenamedOne = -1;
|
|
694 |
columnRenamedTwo = -1;
|
|
695 |
textRenamed = QString();
|
|
696 |
}
|
|
697 |
|
|
698 |
void tst_Q3ListView::itemRenaming()
|
|
699 |
{
|
|
700 |
int a;
|
|
701 |
|
|
702 |
testWidget->clear();
|
|
703 |
connect(testWidget, SIGNAL(itemRenamed(Q3ListViewItem *, int, const QString &)),
|
|
704 |
this, SLOT(itemRenamed(Q3ListViewItem *, int, const QString &)));
|
|
705 |
connect(testWidget, SIGNAL(itemRenamed(Q3ListViewItem *, int)),
|
|
706 |
this, SLOT(itemRenamed(Q3ListViewItem *, int)));
|
|
707 |
|
|
708 |
Q3ListViewItem *itemOne = new Q3ListViewItem(testWidget, "A - Rename Me One", "Rename Me One Col One");
|
|
709 |
Q3ListViewItem *itemTwo = new Q3ListViewItem(testWidget, "B - Rename Me Two", "Rename Me Two Col One");
|
|
710 |
Q3ListViewItem *itemThree = new Q3ListViewItem(testWidget, "C - Rename Me Three", "Rename Me Three Col One");
|
|
711 |
|
|
712 |
QVERIFY(!itemOne->renameEnabled(0));
|
|
713 |
QVERIFY(!itemOne->renameEnabled(1));
|
|
714 |
for (a = 0;a < 2;a++) {
|
|
715 |
itemOne->setRenameEnabled(a,TRUE);
|
|
716 |
itemTwo->setRenameEnabled(a,TRUE);
|
|
717 |
itemThree->setRenameEnabled(a,TRUE);
|
|
718 |
}
|
|
719 |
QVERIFY(itemOne->renameEnabled(0));
|
|
720 |
QVERIFY(itemOne->renameEnabled(1));
|
|
721 |
|
|
722 |
// Check if programatic renaming works
|
|
723 |
|
|
724 |
itemOne->startRename(0);
|
|
725 |
QLineEdit *renameBox = qFindChild<QLineEdit*>(testWidget->viewport(), "qt_renamebox");
|
|
726 |
QVERIFY(renameBox);
|
|
727 |
QVERIFY(renameBox->isVisible());
|
|
728 |
QTest::keyClick(renameBox, Qt::Key_R);
|
|
729 |
QTest::keyClick(renameBox, Qt::Key_E);
|
|
730 |
QTest::keyClick(renameBox, Qt::Key_N);
|
|
731 |
QTest::keyClick(renameBox, Qt::Key_A);
|
|
732 |
QTest::keyClick(renameBox, Qt::Key_M);
|
|
733 |
QTest::keyClick(renameBox, Qt::Key_E);
|
|
734 |
QTest::keyClick(renameBox, Qt::Key_D);
|
|
735 |
QTest::keyPress(renameBox, Qt::Key_Return);
|
|
736 |
|
|
737 |
QVERIFY(itemRenamedSignalOneReceived);
|
|
738 |
QVERIFY(itemRenamedOne == itemOne );
|
|
739 |
QVERIFY(columnRenamedOne == 0);
|
|
740 |
QVERIFY(textRenamed == "renamed");
|
|
741 |
QVERIFY(itemRenamedSignalTwoReceived);
|
|
742 |
QVERIFY(itemRenamedTwo == itemOne);
|
|
743 |
QVERIFY(columnRenamedTwo == 0);
|
|
744 |
|
|
745 |
QCOMPARE(itemOne->text(0), QString("renamed"));
|
|
746 |
QCOMPARE(itemOne->text(1), QString("Rename Me One Col One"));
|
|
747 |
|
|
748 |
resetVariables();
|
|
749 |
|
|
750 |
itemOne->startRename(1);
|
|
751 |
renameBox = (QLineEdit *)testWidget->viewport()->child("qt_renamebox", "QLineEdit");
|
|
752 |
QVERIFY(renameBox);
|
|
753 |
QVERIFY(renameBox->isVisible());
|
|
754 |
QTest::keyClick(renameBox, Qt::Key_R);
|
|
755 |
QTest::keyClick(renameBox, Qt::Key_E);
|
|
756 |
QTest::keyClick(renameBox, Qt::Key_N);
|
|
757 |
QTest::keyClick(renameBox, Qt::Key_A);
|
|
758 |
QTest::keyClick(renameBox, Qt::Key_M);
|
|
759 |
QTest::keyClick(renameBox, Qt::Key_E);
|
|
760 |
QTest::keyClick(renameBox, Qt::Key_D);
|
|
761 |
QTest::keyClick(renameBox, Qt::Key_Space);
|
|
762 |
QTest::keyClick(renameBox, Qt::Key_C);
|
|
763 |
QTest::keyClick(renameBox, Qt::Key_O);
|
|
764 |
QTest::keyClick(renameBox, Qt::Key_L);
|
|
765 |
QTest::keyClick(renameBox, Qt::Key_1);
|
|
766 |
QTest::keyPress(renameBox, Qt::Key_Return);
|
|
767 |
QCOMPARE(itemOne->text(0), QString("renamed"));
|
|
768 |
QCOMPARE(itemOne->text(1), QString("renamed col1"));
|
|
769 |
|
|
770 |
QVERIFY(itemRenamedSignalOneReceived);
|
|
771 |
QVERIFY(itemRenamedOne == itemOne );
|
|
772 |
QVERIFY(columnRenamedOne == 1);
|
|
773 |
QVERIFY(textRenamed == "renamed col1");
|
|
774 |
QVERIFY(itemRenamedSignalTwoReceived);
|
|
775 |
QVERIFY(itemRenamedTwo == itemOne);
|
|
776 |
QVERIFY(columnRenamedTwo == 1);
|
|
777 |
|
|
778 |
// Check if renaming via keyboard works
|
|
779 |
resetVariables();
|
|
780 |
|
|
781 |
QTest::keyClick(testWidget->viewport(), Qt::Key_Space);
|
|
782 |
QTest::keyClick(testWidget->viewport(), Qt::Key_Down);
|
|
783 |
QVERIFY(testWidget->currentItem() == itemTwo);
|
|
784 |
QTest::keyClick(testWidget->viewport(), Qt::Key_F2);
|
|
785 |
renameBox = (QLineEdit *)testWidget->viewport()->child("qt_renamebox", "QLineEdit");
|
|
786 |
QVERIFY(renameBox);
|
|
787 |
QVERIFY(renameBox->isVisible());
|
|
788 |
QTest::keyClick(renameBox, Qt::Key_R);
|
|
789 |
QTest::keyClick(renameBox, Qt::Key_E);
|
|
790 |
QTest::keyClick(renameBox, Qt::Key_N);
|
|
791 |
QTest::keyClick(renameBox, Qt::Key_A);
|
|
792 |
QTest::keyClick(renameBox, Qt::Key_M);
|
|
793 |
QTest::keyClick(renameBox, Qt::Key_E);
|
|
794 |
QTest::keyClick(renameBox, Qt::Key_D);
|
|
795 |
QTest::keyClick(renameBox, Qt::Key_2);
|
|
796 |
QTest::keyPress(renameBox, Qt::Key_Return);
|
|
797 |
|
|
798 |
QVERIFY(itemRenamedSignalOneReceived);
|
|
799 |
QVERIFY(itemRenamedOne == itemTwo);
|
|
800 |
QVERIFY(columnRenamedOne == 0);
|
|
801 |
QVERIFY(textRenamed == "renamed2");
|
|
802 |
QVERIFY(itemRenamedSignalTwoReceived);
|
|
803 |
QVERIFY(itemRenamedTwo == itemTwo);
|
|
804 |
QVERIFY(columnRenamedTwo == 0);
|
|
805 |
|
|
806 |
QCOMPARE(itemTwo->text(0), QString("renamed2"));
|
|
807 |
QCOMPARE(itemTwo->text(1), QString("Rename Me Two Col One"));
|
|
808 |
|
|
809 |
resetVariables();
|
|
810 |
#if 0
|
|
811 |
// Check if renaming via mouse works
|
|
812 |
QPoint itemPos;
|
|
813 |
itemPos.setX(testWidget->header()->sectionPos(0) + 5);
|
|
814 |
itemPos.setY(itemThree->itemPos() + 5);
|
|
815 |
qDebug("%d-%d",itemPos.x(),itemPos.y());
|
|
816 |
QTest::mousePress(testWidget->viewport(), Qt::LeftButton, Qt::NoModifier, itemPos);
|
|
817 |
|
|
818 |
// Should be enough to wait for a release
|
|
819 |
for (a = 0;a < 100; a++)
|
|
820 |
qApp->processEvents();
|
|
821 |
|
|
822 |
QTest::mouseRelease(testWidget->viewport(), Qt::LeftButton, Qt::NoModifier, itemPos);
|
|
823 |
|
|
824 |
renameBox = (QLineEdit *)testWidget->viewport()->child("qt_renamebox", "QLineEdit");
|
|
825 |
QVERIFY(renameBox);
|
|
826 |
QVERIFY(renameBox->isVisible());
|
|
827 |
QTest::keyClick(renameBox, Qt::Key_R);
|
|
828 |
QTest::keyClick(renameBox, Qt::Key_E);
|
|
829 |
QTest::keyClick(renameBox, Qt::Key_N);
|
|
830 |
QTest::keyClick(renameBox, Qt::Key_A);
|
|
831 |
QTest::keyClick(renameBox, Qt::Key_M);
|
|
832 |
QTest::keyClick(renameBox, Qt::Key_E);
|
|
833 |
QTest::keyClick(renameBox, Qt::Key_D);
|
|
834 |
QTest::keyClick(renameBox, Qt::Key_3);
|
|
835 |
QTest::keyClick(renameBox, Qt::Key_Return);
|
|
836 |
|
|
837 |
QVERIFY(itemRenamedSignalOneReceived);
|
|
838 |
QVERIFY(itemRenamedOne == itemThree);
|
|
839 |
QVERIFY(columnRenamedOne == 0);
|
|
840 |
QVERIFY(textRenamed == "renamed3");
|
|
841 |
QVERIFY(itemRenamedSignalTwoReceived);
|
|
842 |
QVERIFY(itemRenamedTwo == itemThree);
|
|
843 |
QVERIFY(columnRenamedTwo == 0);
|
|
844 |
|
|
845 |
QCOMPARE(itemOne->text(0), QString("renamed3"));
|
|
846 |
QCOMPARE(itemOne->text(1), QString("Rename Me Three Col One"));
|
|
847 |
|
|
848 |
resetVariables();
|
|
849 |
|
|
850 |
itemPos.setX(testWidget->header()->sectionPos(1) + 5);
|
|
851 |
itemPos.setY(itemThree->itemPos() + 5);
|
|
852 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::NoModifier, itemPos);
|
|
853 |
|
|
854 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::NoModifier, itemPos);
|
|
855 |
renameBox = (QLineEdit *)testWidget->viewport()->child("qt_renamebox", "QLineEdit");
|
|
856 |
QVERIFY(renameBox);
|
|
857 |
QVERIFY(renameBox->isVisible());
|
|
858 |
QTest::keyClick(renameBox, Qt::Key_R);
|
|
859 |
QTest::keyClick(renameBox, Qt::Key_E);
|
|
860 |
QTest::keyClick(renameBox, Qt::Key_N);
|
|
861 |
QTest::keyClick(renameBox, Qt::Key_A);
|
|
862 |
QTest::keyClick(renameBox, Qt::Key_M);
|
|
863 |
QTest::keyClick(renameBox, Qt::Key_E);
|
|
864 |
QTest::keyClick(renameBox, Qt::Key_D);
|
|
865 |
QTest::keyClick(renameBox, Qt::Key_3);
|
|
866 |
QTest::keyClick(renameBox, Qt::Key_Space);
|
|
867 |
QTest::keyClick(renameBox, Qt::Key_C);
|
|
868 |
QTest::keyClick(renameBox, Qt::Key_O);
|
|
869 |
QTest::keyClick(renameBox, Qt::Key_L);
|
|
870 |
QTest::keyClick(renameBox, Qt::Key_1);
|
|
871 |
QTest::keyClick(renameBox, Qt::Key_Return);
|
|
872 |
QCOMPARE(itemThree->text(0), QString("renamed3"));
|
|
873 |
QCOMPARE(itemThree->text(1), QString("renamed3 col1"));
|
|
874 |
|
|
875 |
QVERIFY(itemRenamedSignalOneReceived);
|
|
876 |
QVERIFY(itemRenamedOne == itemThree);
|
|
877 |
QVERIFY(columnRenamedOne == 1);
|
|
878 |
QVERIFY(textRenamed == "renamed3 col1");
|
|
879 |
QVERIFY(itemRenamedSignalTwoReceived);
|
|
880 |
QVERIFY(itemRenamedTwo == itemThree);
|
|
881 |
QVERIFY(columnRenamedTwo == 1);
|
|
882 |
#endif
|
|
883 |
}
|
|
884 |
|
|
885 |
void tst_Q3ListView::removeColumn()
|
|
886 |
{
|
|
887 |
// clear all items and columns
|
|
888 |
while ( testWidget->columns() )
|
|
889 |
testWidget->removeColumn( 0 );
|
|
890 |
testWidget->clear();
|
|
891 |
QVERIFY( !testWidget->firstChild() );
|
|
892 |
QVERIFY( !testWidget->columns() );
|
|
893 |
|
|
894 |
// add one column
|
|
895 |
// test columns() and header()->count()
|
|
896 |
testWidget->addColumn( "One" );
|
|
897 |
QCOMPARE( testWidget->columns(), 1 );
|
|
898 |
QCOMPARE( testWidget->header() ? testWidget->header()->count() : -1,
|
|
899 |
testWidget->columns() );
|
|
900 |
// add a second column
|
|
901 |
testWidget->addColumn( "Two" );
|
|
902 |
QCOMPARE( testWidget->columns(), 2 );
|
|
903 |
QCOMPARE( testWidget->header() ? testWidget->header()->count() : -1,
|
|
904 |
testWidget->columns() );
|
|
905 |
// add a third column
|
|
906 |
testWidget->addColumn( "Three" );
|
|
907 |
QCOMPARE( testWidget->columns(), 3 );
|
|
908 |
QCOMPARE( testWidget->header() ? testWidget->header()->count() : -1,
|
|
909 |
testWidget->columns() );
|
|
910 |
|
|
911 |
// actually remove
|
|
912 |
while ( testWidget->columns() ) {
|
|
913 |
testWidget->removeColumn( 0 );
|
|
914 |
// make sure header and q3listview always are in sync
|
|
915 |
QCOMPARE( testWidget->header() ? testWidget->header()->count() : -1,
|
|
916 |
testWidget->columns() );
|
|
917 |
}
|
|
918 |
|
|
919 |
// check that there are no columns
|
|
920 |
QVERIFY( !testWidget->columns() );
|
|
921 |
// check that there are no sections in the header
|
|
922 |
QVERIFY( testWidget->header() ? !testWidget->header()->count() : FALSE );
|
|
923 |
}
|
|
924 |
|
|
925 |
void tst_Q3ListView::contextMenu(Q3ListViewItem *item, const QPoint &pos, int col)
|
|
926 |
{
|
|
927 |
// Slot to gather information from the contextMenuRequested signal
|
|
928 |
contextMenuRequestedItem = item;
|
|
929 |
contextMenuRequestedPos = pos;
|
|
930 |
contextMenuRequestedCol = col;
|
|
931 |
contextMenuRequestedSignalReceived = TRUE;
|
|
932 |
}
|
|
933 |
|
|
934 |
void tst_Q3ListView::contextMenuRequested_data()
|
|
935 |
{
|
|
936 |
QTest::addColumn<bool>("mouse");
|
|
937 |
QTest::addColumn<QPoint>("clickPos");
|
|
938 |
QTest::addColumn<QString>("textOfListViewItem");
|
|
939 |
// QTest::addColumn<QPoint>("menuPos"); -- Need a way to reliably test this
|
|
940 |
QTest::addColumn<int>("column");
|
|
941 |
|
|
942 |
QTest::newRow("mouseClickTopItemFirstColumn") << TRUE << QPoint(22, 5) /* << QPoint()*/ << QString("Item One") << 0;
|
|
943 |
QTest::newRow("keyClickTopItemFirstColumn") << FALSE << QPoint(22, 5) /* << QPoint()*/ << QString("Item One") << -1;
|
|
944 |
QTest::newRow("mouseClick2ndItemSecondColumn") << TRUE << QPoint(40, 20) /* << QPoint()*/ << QString("Item Two") << 0;
|
|
945 |
QTest::newRow("keyClick2ndItemSecondColumn") << FALSE << QPoint(40, 20) /* << QPoint()*/ << QString("Item One") << -1;
|
|
946 |
QTest::newRow("noItemClicked") << TRUE << QPoint(100, 100) /* << QPoint()*/ << QString() << -1;
|
|
947 |
}
|
|
948 |
|
|
949 |
void tst_Q3ListView::contextMenuRequested()
|
|
950 |
{
|
|
951 |
QFETCH(bool, mouse);
|
|
952 |
QFETCH(QPoint, clickPos);
|
|
953 |
QFETCH(QString, textOfListViewItem);
|
|
954 |
//QFETCH(QPoint, menuPos);
|
|
955 |
QFETCH(int, column);
|
|
956 |
|
|
957 |
QSKIP("Does not work with qtestlib's mouse/keyboard handling.", SkipAll);
|
|
958 |
|
|
959 |
testWidget->clear();
|
|
960 |
testWidget->addColumn("Column 1");
|
|
961 |
testWidget->addColumn("Column 2");
|
|
962 |
testWidget->connect(testWidget, SIGNAL(contextMenuRequested(Q3ListViewItem *, const QPoint &, int)),
|
|
963 |
this, SLOT(contextMenu(Q3ListViewItem *, const QPoint &, int)));
|
|
964 |
|
|
965 |
testWidget->setColumnWidth(0, 35);
|
|
966 |
testWidget->setColumnWidth(1, 35);
|
|
967 |
Q3ListViewItem *itemOne = new Q3ListViewItem(testWidget, "Item One", "Item One 2");
|
|
968 |
Q3ListViewItem *itemTwo = new Q3ListViewItem(testWidget, itemOne, "Item Two", "Item Two 2");
|
|
969 |
Q_UNUSED(itemOne);
|
|
970 |
Q_UNUSED(itemTwo);
|
|
971 |
|
|
972 |
|
|
973 |
if (mouse) {
|
|
974 |
QTest::mouseClick(testWidget->viewport(), Qt::RightButton, Qt::NoModifier, clickPos);
|
|
975 |
} else {
|
|
976 |
// Then it's a keypress
|
|
977 |
QTest::mouseMove(testWidget->viewport(), clickPos);
|
|
978 |
QTest::keyClick(testWidget->viewport(), Qt::Key_Menu);
|
|
979 |
}
|
|
980 |
|
|
981 |
QVERIFY(contextMenuRequestedSignalReceived);
|
|
982 |
if (textOfListViewItem.isNull()) {
|
|
983 |
QVERIFY(!contextMenuRequestedItem);
|
|
984 |
} else {
|
|
985 |
QCOMPARE(contextMenuRequestedItem->text(0), textOfListViewItem);
|
|
986 |
}
|
|
987 |
//QCOMPARE(contextMenuRequestedPos, menuPos);
|
|
988 |
QCOMPARE(contextMenuRequestedCol, column);
|
|
989 |
}
|
|
990 |
|
|
991 |
// Exists solely for testing the activate() function
|
|
992 |
class ActivateListViewItem : public Q3ListViewItem
|
|
993 |
{
|
|
994 |
public:
|
|
995 |
ActivateListViewItem(Q3ListView *parent) : Q3ListViewItem(parent),
|
|
996 |
activated(false) {}
|
|
997 |
bool activated;
|
|
998 |
protected:
|
|
999 |
void activate()
|
|
1000 |
{
|
|
1001 |
activated = true;
|
|
1002 |
}
|
|
1003 |
};
|
|
1004 |
|
|
1005 |
void tst_Q3ListView::itemActivate()
|
|
1006 |
{
|
|
1007 |
testWidget->addColumn("Test 1");
|
|
1008 |
ActivateListViewItem *alvi = new ActivateListViewItem(testWidget);
|
|
1009 |
alvi->setText(0, "Test");
|
|
1010 |
new Q3ListViewItem(alvi, "Testing");
|
|
1011 |
testWidget->setCurrentItem(alvi);
|
|
1012 |
QTest::keyPress(testWidget->viewport(), Qt::Key_Space);
|
|
1013 |
QVERIFY(alvi->activated);
|
|
1014 |
QTest::keyRelease(testWidget->viewport(), Qt::Key_Space);
|
|
1015 |
|
|
1016 |
alvi->activated = false;
|
|
1017 |
QTest::mousePress(testWidget->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5,alvi->itemPos()));
|
|
1018 |
QVERIFY(alvi->activated);
|
|
1019 |
QTest::mouseRelease(testWidget->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5,alvi->itemPos()));
|
|
1020 |
QVERIFY(alvi->activated);
|
|
1021 |
}
|
|
1022 |
|
|
1023 |
/*
|
|
1024 |
Qt::CaseSensitive - The strings must match case sensitively.
|
|
1025 |
Q3ListView::ExactMatch - The target and search strings must match exactly.
|
|
1026 |
Q3ListView::BeginsWith - The target string begins with the search string.
|
|
1027 |
Q3ListView::EndsWith - The target string ends with the search string.
|
|
1028 |
Q3ListView::Contains - The target string contains the search string.
|
|
1029 |
|
|
1030 |
the search criteria be applied in the following order: ExactMatch, BeginsWith, EndsWith, Contains
|
|
1031 |
*/
|
|
1032 |
|
|
1033 |
void tst_Q3ListView::findItem_data()
|
|
1034 |
{
|
|
1035 |
QTest::addColumn<int>("indexOfCurrentItem");
|
|
1036 |
QTest::addColumn<QString>("text");
|
|
1037 |
QTest::addColumn<int>("column");
|
|
1038 |
QTest::addColumn<int>("comparisonFlags");
|
|
1039 |
QTest::addColumn<bool>("itemFound");
|
|
1040 |
QTest::addColumn<QString>("textOfItemFound");
|
|
1041 |
|
|
1042 |
QTest::newRow("noCurrentItem") << -1 << "item one" << 0 << 0 << TRUE << "Item One";
|
|
1043 |
QTest::newRow("noCurrentItem-bogusColumn") << -1 << "item one" << 99 << 0 << FALSE << QString();
|
|
1044 |
QTest::newRow("noCurrentItem-invalidItem") << -1 << "blah" << 0 << 0 << FALSE << QString();
|
|
1045 |
QTest::newRow("noCurrentItem-caseSensitive-invalidItem") << -1 << "item one" << 0 << Q3ListView::CaseSensitive << FALSE << QString();
|
|
1046 |
QTest::newRow("noCurrentItem-caseSensitive") << -1 << "Item One" << 0 << Q3ListView::CaseSensitive << TRUE << "Item One";
|
|
1047 |
QTest::newRow("noCurrentItem-exactMatch-invalidItem") << -1 << "blah" << 0 << Q3ListView::ExactMatch << FALSE << QString();
|
|
1048 |
QTest::newRow("noCurrentItem-exactMatch") << -1 << "Item One" << 0 << Q3ListView::ExactMatch << TRUE << "Item One";
|
|
1049 |
QTest::newRow("noCurrentItem-beginsWith-invalidItem") << -1 << "blah" << 0 << Q3ListView::BeginsWith << FALSE << QString();
|
|
1050 |
QTest::newRow("noCurrentItem-beginsWith") << -1 << "Item One" << 0 << Q3ListView::BeginsWith << TRUE << "Item One";
|
|
1051 |
QTest::newRow("noCurrentItem-endsWith-invalidItem") << -1 << "blah" << 0 << Q3ListView::EndsWith << FALSE << QString();
|
|
1052 |
QTest::newRow("noCurrentItem-endsWith") << -1 << "Item One" << 0 << Q3ListView::EndsWith << TRUE << "Item One";
|
|
1053 |
QTest::newRow("noCurrentItem-contains-invalidItem") << -1 << "blah" << 0 << Q3ListView::Contains << FALSE << QString();
|
|
1054 |
QTest::newRow("noCurrentItem-contains") << -1 << "Item One" << 0 << Q3ListView::Contains << TRUE << "Item One";
|
|
1055 |
|
|
1056 |
// Now check that case sensitivity has no effect unless specified
|
|
1057 |
QTest::newRow("noCurrentItem-exactMatch-nocs") << -1 << "ITEM ONE" << 0 << Q3ListView::ExactMatch << TRUE << "Item One";
|
|
1058 |
QTest::newRow("noCurrentItem-beginsWith-nocs") << -1 << "ITEM ONE" << 0 << Q3ListView::BeginsWith << TRUE << "Item One";
|
|
1059 |
QTest::newRow("noCurrentItem-endsWith-nocs") << -1 << "ITEM ONE" << 0 << Q3ListView::EndsWith << TRUE << "Item One";
|
|
1060 |
QTest::newRow("noCurrentItem-contains-nocs") << -1 << "ITEM ONE" << 0 << Q3ListView::Contains << TRUE << "Item One";
|
|
1061 |
QTest::newRow("noCurrentItem-exactMatch-cs") << -1 << "ITEM ONE" << 0 << (Q3ListView::CaseSensitive | Q3ListView::ExactMatch) << FALSE << QString();
|
|
1062 |
QTest::newRow("noCurrentItem-beginsWith-cs") << -1 << "ITEM ONE" << 0 << (Q3ListView::CaseSensitive | Q3ListView::BeginsWith) << FALSE << QString();
|
|
1063 |
QTest::newRow("noCurrentItem-endsWith-cs") << -1 << "ITEM ONE" << 0 << (Q3ListView::CaseSensitive | Q3ListView::EndsWith) << FALSE << QString();
|
|
1064 |
QTest::newRow("noCurrentItem-contains-cs") << -1 << "ITEM ONE" << 0 << (Q3ListView::CaseSensitive | Q3ListView::Contains) << FALSE << QString();
|
|
1065 |
|
|
1066 |
// Now check that the search criteria order is adhered to
|
|
1067 |
QTest::newRow("noCurrentItem-exactMatch-beginswith-nocs") << -1 << "Item One" << 0 << (Q3ListView::ExactMatch | Q3ListView::BeginsWith) << TRUE << "Item One";
|
|
1068 |
QTest::newRow("noCurrentItem-exactMatch-endswith-nocs") << -1 << "Item One" << 0 << (Q3ListView::ExactMatch | Q3ListView::EndsWith) << TRUE << "Item One";
|
|
1069 |
QTest::newRow("noCurrentItem-exactMatch-contains-nocs") << -1 << "Item One" << 0 << (Q3ListView::ExactMatch | Q3ListView::Contains) << TRUE << "Item One";
|
|
1070 |
QTest::newRow("noCurrentItem-beginswith-endswith-nocs") << -1 << "Item One" << 0 << (Q3ListView::BeginsWith | Q3ListView::EndsWith) << TRUE << "Item One";
|
|
1071 |
QTest::newRow("noCurrentItem-beginswith-contains-nocs") << -1 << "Item One" << 0 << (Q3ListView::BeginsWith | Q3ListView::Contains) << TRUE << "Item One";
|
|
1072 |
QTest::newRow("noCurrentItem-endswith-contains-nocs") << -1 << "Item One" << 0 << (Q3ListView::EndsWith | Q3ListView::Contains) << TRUE << "Item One";
|
|
1073 |
|
|
1074 |
// Now check that the current item set has the effect of searching from that item
|
|
1075 |
QTest::newRow("currentItemIsTwo") << 2 << "item one" << 0 << 0 << TRUE << "Item One";
|
|
1076 |
QTest::newRow("currentItemIsTwo-bogusColumn") << 2 << "item one" << 99 << 0 << FALSE << QString();
|
|
1077 |
QTest::newRow("currentItemIsTwo-invalidItem") << 2 << "blah" << 0 << 0 << FALSE << QString();
|
|
1078 |
QTest::newRow("currentItemIsTwo-caseSensitive-invalidItem") << 2 << "item one" << 0 << Q3ListView::CaseSensitive << FALSE << QString();
|
|
1079 |
QTest::newRow("currentItemIsTwo-caseSensitive") << 2 << "Item One" << 0 << Q3ListView::CaseSensitive << TRUE << "Item One";
|
|
1080 |
QTest::newRow("currentItemIsTwo-exactMatch-invalidItem") << 2 << "blah" << 0 << Q3ListView::ExactMatch << FALSE << QString();
|
|
1081 |
QTest::newRow("currentItemIsTwo-exactMatch") << 2 << "Item One" << 0 << Q3ListView::ExactMatch << TRUE << "Item One";
|
|
1082 |
QTest::newRow("currentItemIsTwo-beginsWith-invalidItem") << 2 << "blah" << 0 << Q3ListView::BeginsWith << FALSE << QString();
|
|
1083 |
QTest::newRow("currentItemIsTwo-beginsWith") << 2 << "Item One" << 0 << Q3ListView::BeginsWith << TRUE << "Item One Two Three";
|
|
1084 |
QTest::newRow("currentItemIsTwo-endsWith-invalidItem") << 2 << "blah" << 0 << Q3ListView::EndsWith << FALSE << QString();
|
|
1085 |
QTest::newRow("currentItemIsTwo-endsWith") << 2 << "Item One" << 0 << Q3ListView::EndsWith << TRUE << "Item One Item One";
|
|
1086 |
QTest::newRow("currentItemIsTwo-contains-invalidItem") << 2 << "blah" << 0 << Q3ListView::Contains << FALSE << QString();
|
|
1087 |
QTest::newRow("currentItemIsTwo-contains") << 2 << "Item One" << 0 << Q3ListView::Contains << TRUE << "Item One Two Three";
|
|
1088 |
QTest::newRow("currentItemIsTwo-exactMatch-nocs") << 2 << "ITEM ONE" << 0 << Q3ListView::ExactMatch << TRUE << "Item One";
|
|
1089 |
QTest::newRow("currentItemIsTwo-beginsWith-nocs") << 2 << "ITEM ONE" << 0 << Q3ListView::BeginsWith << TRUE << "Item One Two Three";
|
|
1090 |
QTest::newRow("currentItemIsTwo-endsWith-nocs") << 2 << "ITEM ONE" << 0 << Q3ListView::EndsWith << TRUE << "Item One Item One";
|
|
1091 |
QTest::newRow("currentItemIsTwo-contains-nocs") << 2 << "ITEM ONE" << 0 << Q3ListView::Contains << TRUE << "Item One Two Three";
|
|
1092 |
QTest::newRow("currentItemIsTwo-exactMatch-cs") << 2 << "ITEM ONE" << 0 << (Q3ListView::CaseSensitive | Q3ListView::ExactMatch) << FALSE << QString();
|
|
1093 |
QTest::newRow("currentItemIsTwo-beginsWith-cs") << 2 << "ITEM ONE" << 0 << (Q3ListView::CaseSensitive | Q3ListView::BeginsWith) << FALSE << QString();
|
|
1094 |
QTest::newRow("currentItemIsTwo-endsWith-cs") << 2 << "ITEM ONE" << 0 << (Q3ListView::CaseSensitive | Q3ListView::EndsWith) << FALSE << QString();
|
|
1095 |
QTest::newRow("currentItemIsTwo-contains-cs") << 2 << "ITEM ONE" << 0 << (Q3ListView::CaseSensitive | Q3ListView::Contains) << FALSE << QString();
|
|
1096 |
QTest::newRow("currentItemIsTwo-exactMatch-beginswith-nocs") << 2 << "Item One" << 0 << (Q3ListView::ExactMatch | Q3ListView::BeginsWith) << TRUE << "Item One";
|
|
1097 |
QTest::newRow("currentItemIsTwo-exactMatch-endswith-nocs") << 2 << "Item One" << 0 << (Q3ListView::ExactMatch | Q3ListView::EndsWith) << TRUE << "Item One";
|
|
1098 |
QTest::newRow("currentItemIsTwo-exactMatch-contains-nocs") << 2 << "Item One" << 0 << (Q3ListView::ExactMatch | Q3ListView::Contains) << TRUE << "Item One";
|
|
1099 |
QTest::newRow("currentItemIsTwo-beginswith-endswith-nocs") << 2 << "Item One" << 0 << (Q3ListView::BeginsWith | Q3ListView::EndsWith) << TRUE << "Item One Two Three";
|
|
1100 |
QTest::newRow("currentItemIsTwo-beginswith-contains-nocs") << 2 << "Item One" << 0 << (Q3ListView::BeginsWith | Q3ListView::Contains) << TRUE << "Item One Two Three";
|
|
1101 |
QTest::newRow("currentItemIsTwo-endswith-contains-nocs") << 2 << "Item One" << 0 << (Q3ListView::EndsWith | Q3ListView::Contains) << TRUE << "Item One Item One";
|
|
1102 |
QTest::newRow("itemWithEmptyText") << 2 << "" << 0 << (Q3ListView::ExactMatch | Q3ListView::CaseSensitive) << TRUE << "";
|
|
1103 |
QTest::newRow("itemWithEmptyText-2") << 2 << "" << 0 << (Q3ListView::BeginsWith | Q3ListView::Contains) << FALSE << "";
|
|
1104 |
}
|
|
1105 |
|
|
1106 |
void tst_Q3ListView::findItem()
|
|
1107 |
{
|
|
1108 |
// ### This test is not complete, any results are still valid though
|
|
1109 |
|
|
1110 |
QFETCH(int, indexOfCurrentItem);
|
|
1111 |
QFETCH(QString, text);
|
|
1112 |
QFETCH(int, column);
|
|
1113 |
QFETCH(int, comparisonFlags);
|
|
1114 |
QFETCH(bool, itemFound);
|
|
1115 |
QFETCH(QString, textOfItemFound);
|
|
1116 |
|
|
1117 |
testWidget->addColumn("Test");
|
|
1118 |
testWidget->setSorting(-1);
|
|
1119 |
Q3ListViewItem *itemOne = new Q3ListViewItem(testWidget, "Item One");
|
|
1120 |
Q3ListViewItem *itemTwo = new Q3ListViewItem(testWidget, itemOne, "Item One Two");
|
|
1121 |
Q3ListViewItem *itemThree = new Q3ListViewItem(testWidget, itemTwo, "Item One Two Three");
|
|
1122 |
new Q3ListViewItem(testWidget, itemThree, "Item One Item One");
|
|
1123 |
new Q3ListViewItem(testWidget, ""); // For the empty item test
|
|
1124 |
|
|
1125 |
// We need some way of mapping items to indices
|
|
1126 |
// and also a way to force no current item
|
|
1127 |
// currently we assume item two is the current in the test
|
|
1128 |
if (indexOfCurrentItem != -1)
|
|
1129 |
testWidget->setCurrentItem(itemThree);
|
|
1130 |
|
|
1131 |
Q3ListViewItem *foundItem = testWidget->findItem(text, column, QFlag(comparisonFlags));
|
|
1132 |
if (itemFound) {
|
|
1133 |
QVERIFY(foundItem);
|
|
1134 |
QCOMPARE(textOfItemFound, foundItem->text(column));
|
|
1135 |
} else {
|
|
1136 |
QVERIFY(!foundItem);
|
|
1137 |
}
|
|
1138 |
}
|
|
1139 |
|
|
1140 |
|
|
1141 |
void tst_Q3ListView::spacePress_data()
|
|
1142 |
{
|
|
1143 |
QTest::addColumn<Q3ListView::SelectionMode>("selectionMode");
|
|
1144 |
QTest::addColumn<int>("itemCount");
|
|
1145 |
QTest::addColumn<int>("disabledItem");
|
|
1146 |
QTest::addColumn<QTestEventList>("keys");
|
|
1147 |
QTest::addColumn<int>("expectedCount");
|
|
1148 |
QTest::addColumn<int>("expectedCurrentSelected");
|
|
1149 |
|
|
1150 |
// testing space pressed on enabled/disabled item
|
|
1151 |
for (int mode = Q3ListView::Single; mode <= Q3ListView::NoSelection; mode++ ) {
|
|
1152 |
for (int k=0; k<4; ++k ) {
|
|
1153 |
Qt::KeyboardModifiers key = intToKey( k );
|
|
1154 |
if ( key == Qt::NoModifier || key == Qt::ControlModifier ) {
|
|
1155 |
for ( int enabled=0; enabled<2; ++enabled ) {
|
|
1156 |
QString testName = QString( "Space on %1 item. Selection mode: %2 Button: %3" )
|
|
1157 |
.arg( enabled ? "enabled" : "disabled" )
|
|
1158 |
.arg( selectionName( mode ))
|
|
1159 |
.arg( keyName( key ) );
|
|
1160 |
QTestEventList keys;
|
|
1161 |
// going to first item and pressing space
|
|
1162 |
keys.addKeyClick( Qt::Key_Home );
|
|
1163 |
keys.addKeyClick( Qt::Key_Space, key );
|
|
1164 |
QTest::newRow( testName ) << (Q3ListView::SelectionMode)mode << 9
|
|
1165 |
<< (enabled ? -1 : 0 ) << keys << 1
|
|
1166 |
<< ((mode == Q3ListView::Single) ||
|
|
1167 |
(mode == Q3ListView::Multi && !enabled) ? 1 : -1);
|
|
1168 |
}
|
|
1169 |
}
|
|
1170 |
}
|
|
1171 |
}
|
|
1172 |
|
|
1173 |
{
|
|
1174 |
QTestEventList keys;
|
|
1175 |
keys.addKeyClick( Qt::Key_Home );
|
|
1176 |
keys.addKeyClick( Qt::Key_Down );
|
|
1177 |
keys.addKeyClick( Qt::Key_Up );
|
|
1178 |
keys.addKeyClick( Qt::Key_Space );
|
|
1179 |
keys.addKeyClick( Qt::Key_Space, Qt::ControlModifier );
|
|
1180 |
QTest::newRow( "Space then Ctrl-Space to unselect in Extended" )
|
|
1181 |
<< Q3ListView::Extended << 9 << -1 << keys << 2 << 0;
|
|
1182 |
}
|
|
1183 |
}
|
|
1184 |
|
|
1185 |
void tst_Q3ListView::spacePress()
|
|
1186 |
{
|
|
1187 |
QFETCH( Q3ListView::SelectionMode, selectionMode );
|
|
1188 |
QFETCH( int, itemCount );
|
|
1189 |
QFETCH( int, disabledItem );
|
|
1190 |
QFETCH( QTestEventList, keys );
|
|
1191 |
QFETCH( int, expectedCount );
|
|
1192 |
QFETCH( int, expectedCurrentSelected );
|
|
1193 |
|
|
1194 |
testWidget->setSorting( 0, TRUE );
|
|
1195 |
testWidget->addColumn( "Items" );
|
|
1196 |
testWidget->setSelectionMode( selectionMode );
|
|
1197 |
for ( int i=0; i<itemCount; ++i) {
|
|
1198 |
Q3ListViewItem *item = new Q3ListViewItem( testWidget, QString( "Child %1" ).arg( i ) );
|
|
1199 |
if ( i == disabledItem )
|
|
1200 |
item->setEnabled( FALSE );
|
|
1201 |
if ( i == 0 )
|
|
1202 |
testWidget->setSelected( item, TRUE );
|
|
1203 |
}
|
|
1204 |
|
|
1205 |
// naviagate to keys and press space
|
|
1206 |
pressCount = 0;
|
|
1207 |
keys.simulate( testWidget );
|
|
1208 |
// verify that spacePressed has been called the correct amount of times
|
|
1209 |
QCOMPARE( pressCount, expectedCount );
|
|
1210 |
if ( testWidget->currentItem() && expectedCurrentSelected > -1 )
|
|
1211 |
QCOMPARE( testWidget->currentItem()->isSelected(), (bool)expectedCurrentSelected );
|
|
1212 |
}
|
|
1213 |
|
|
1214 |
void tst_Q3ListView::adjustColumn()
|
|
1215 |
{
|
|
1216 |
testWidget->adjustColumn(-1);
|
|
1217 |
testWidget->adjustColumn(100);
|
|
1218 |
testWidget->adjustColumn(0);
|
|
1219 |
QVERIFY(true); // Just to check it did not crash
|
|
1220 |
}
|
|
1221 |
|
|
1222 |
typedef QPair<QByteArray, QVariant> PropertyItem;
|
|
1223 |
typedef QList<PropertyItem> PropertyItemList;
|
|
1224 |
Q_DECLARE_METATYPE(PropertyItemList)
|
|
1225 |
|
|
1226 |
void tst_Q3ListView::mouseClickEvents_data()
|
|
1227 |
{
|
|
1228 |
QTest::addColumn<QStringList>("itemstrings");
|
|
1229 |
QTest::addColumn<int>("expectedDoubleClickCount");
|
|
1230 |
QTest::addColumn<PropertyItemList>("properties");
|
|
1231 |
|
|
1232 |
QTest::newRow("doubleclick") << (QStringList() << "item 1" << "item 2")
|
|
1233 |
<< 2 << PropertyItemList();
|
|
1234 |
QTest::newRow("doubleclick") << (QStringList() << "item 1" << "item 2")
|
|
1235 |
<< 0 << (PropertyItemList() << PropertyItem("enabled", false));
|
|
1236 |
|
|
1237 |
}
|
|
1238 |
|
|
1239 |
void tst_Q3ListView::mouseClickEvents()
|
|
1240 |
{
|
|
1241 |
QFETCH(QStringList, itemstrings);
|
|
1242 |
QFETCH(int, expectedDoubleClickCount);
|
|
1243 |
QFETCH(PropertyItemList, properties);
|
|
1244 |
|
|
1245 |
int i;
|
|
1246 |
for (i = 0; i < properties.count(); ++i) {
|
|
1247 |
testWidget->setProperty(properties.at(i).first.constData(), properties.at(i).second);
|
|
1248 |
}
|
|
1249 |
|
|
1250 |
doubleClickCount = 0;
|
|
1251 |
pressedItem = 0;
|
|
1252 |
connect( testWidget, SIGNAL( doubleClicked( Q3ListViewItem* ) ),
|
|
1253 |
this, SLOT( doubleClicked( Q3ListViewItem* ) ) );
|
|
1254 |
testWidget->addColumn("Items");
|
|
1255 |
QVector<Q3ListViewItem*> items;
|
|
1256 |
for ( i=0; i<itemstrings.count(); ++i) {
|
|
1257 |
Q3ListViewItem *item = new Q3ListViewItem( testWidget, itemstrings.at(i) );
|
|
1258 |
items.append(item);
|
|
1259 |
}
|
|
1260 |
for ( i = 0; i < items.count(); ++i) {
|
|
1261 |
int prevCount = doubleClickCount;
|
|
1262 |
QTest::mouseDClick(testWidget->viewport(), Qt::LeftButton, 0, itemCenter(testWidget, items.at(i)));
|
|
1263 |
if (doubleClickCount > prevCount) {
|
|
1264 |
QCOMPARE(pressedItem, items.at(i));
|
|
1265 |
} else {
|
|
1266 |
QCOMPARE(pressedItem, (Q3ListViewItem*)0);
|
|
1267 |
}
|
|
1268 |
}
|
|
1269 |
QCOMPARE(doubleClickCount, expectedDoubleClickCount);
|
|
1270 |
disconnect( testWidget, SIGNAL( doubleClicked( Q3ListViewItem* ) ),
|
|
1271 |
this, SLOT( doubleClicked( Q3ListViewItem* ) ) );
|
|
1272 |
}
|
|
1273 |
|
|
1274 |
QTEST_MAIN(tst_Q3ListView)
|
|
1275 |
#include "tst_q3listview.moc"
|
|
1276 |
|