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 |
#include <qabstractitemview.h>
|
|
46 |
#include <qstandarditemmodel.h>
|
|
47 |
#include <qapplication.h>
|
|
48 |
#include <qlistview.h>
|
|
49 |
#include <qtableview.h>
|
|
50 |
#include <qtreeview.h>
|
|
51 |
#include <qtreewidget.h>
|
|
52 |
#include <qheaderview.h>
|
|
53 |
#include <qspinbox.h>
|
|
54 |
#include <qitemdelegate.h>
|
|
55 |
#include <qpushbutton.h>
|
|
56 |
#include <qscrollbar.h>
|
|
57 |
#include <qboxlayout.h>
|
|
58 |
#include <qlineedit.h>
|
|
59 |
#include "../../shared/util.h"
|
|
60 |
|
|
61 |
//TESTED_CLASS=
|
|
62 |
//TESTED_FILES=
|
|
63 |
|
|
64 |
// Will try to wait for the condition while allowing event processing
|
|
65 |
// for a maximum of 5 seconds.
|
|
66 |
#define TRY_COMPARE(expr, expected) \
|
|
67 |
do { \
|
|
68 |
const int step = 50; \
|
|
69 |
for (int q = 0; q < 5000 && ((expr) != (expected)); q+=step) { \
|
|
70 |
QTest::qWait(step); \
|
|
71 |
} \
|
|
72 |
QCOMPARE(expr, expected); \
|
|
73 |
} while(0)
|
|
74 |
|
|
75 |
class TestView : public QAbstractItemView
|
|
76 |
{
|
|
77 |
Q_OBJECT
|
|
78 |
public:
|
|
79 |
inline void tst_dataChanged(const QModelIndex &tl, const QModelIndex &br)
|
|
80 |
{ dataChanged(tl, br); }
|
|
81 |
inline void tst_setHorizontalStepsPerItem(int steps)
|
|
82 |
{ setHorizontalStepsPerItem(steps); }
|
|
83 |
inline int tst_horizontalStepsPerItem() const
|
|
84 |
{ return horizontalStepsPerItem(); }
|
|
85 |
inline void tst_setVerticalStepsPerItem(int steps)
|
|
86 |
{ setVerticalStepsPerItem(steps); }
|
|
87 |
inline int tst_verticalStepsPerItem() const
|
|
88 |
{ return verticalStepsPerItem(); }
|
|
89 |
|
|
90 |
inline void tst_rowsInserted(const QModelIndex &parent, int start, int end)
|
|
91 |
{ rowsInserted(parent, start, end); }
|
|
92 |
inline void tst_rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
|
|
93 |
{ rowsAboutToBeRemoved(parent, start, end); }
|
|
94 |
inline void tst_selectionChanged(const QItemSelection &selected,
|
|
95 |
const QItemSelection &deselected)
|
|
96 |
{ selectionChanged(selected, deselected); }
|
|
97 |
inline void tst_currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
|
98 |
{ currentChanged(current, previous); }
|
|
99 |
inline void tst_updateEditorData()
|
|
100 |
{ updateEditorData(); }
|
|
101 |
inline void tst_updateEditorGeometries()
|
|
102 |
{ updateEditorGeometries(); }
|
|
103 |
inline void tst_updateGeometries()
|
|
104 |
{ updateGeometries(); }
|
|
105 |
inline void tst_verticalScrollbarAction(int action)
|
|
106 |
{ verticalScrollbarAction(action); }
|
|
107 |
inline void tst_horizontalScrollbarAction(int action)
|
|
108 |
{ horizontalScrollbarAction(action); }
|
|
109 |
inline void tst_verticalScrollbarValueChanged(int value)
|
|
110 |
{ verticalScrollbarValueChanged(value); }
|
|
111 |
inline void tst_horizontalScrollbarValueChanged(int value)
|
|
112 |
{ horizontalScrollbarValueChanged(value); }
|
|
113 |
inline void tst_closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint)
|
|
114 |
{ closeEditor(editor, hint); }
|
|
115 |
inline void tst_commitData(QWidget *editor)
|
|
116 |
{ commitData(editor); }
|
|
117 |
inline void tst_editorDestroyed(QObject *editor)
|
|
118 |
{ editorDestroyed(editor); }
|
|
119 |
enum tst_CursorAction {
|
|
120 |
MoveUp = QAbstractItemView::MoveUp,
|
|
121 |
MoveDown = QAbstractItemView::MoveDown,
|
|
122 |
MoveLeft = QAbstractItemView::MoveLeft,
|
|
123 |
MoveRight = QAbstractItemView::MoveRight,
|
|
124 |
MoveHome = QAbstractItemView::MoveHome,
|
|
125 |
MoveEnd = QAbstractItemView::MoveEnd,
|
|
126 |
MovePageUp = QAbstractItemView::MovePageUp,
|
|
127 |
MovePageDown = QAbstractItemView::MovePageDown,
|
|
128 |
MoveNext = QAbstractItemView::MoveNext,
|
|
129 |
MovePrevious = QAbstractItemView::MovePrevious
|
|
130 |
};
|
|
131 |
inline QModelIndex tst_moveCursor(tst_CursorAction cursorAction,
|
|
132 |
Qt::KeyboardModifiers modifiers)
|
|
133 |
{ return moveCursor(QAbstractItemView::CursorAction(cursorAction), modifiers); }
|
|
134 |
inline int tst_horizontalOffset() const
|
|
135 |
{ return horizontalOffset(); }
|
|
136 |
inline int tst_verticalOffset() const
|
|
137 |
{ return verticalOffset(); }
|
|
138 |
inline bool tst_isIndexHidden(const QModelIndex &index) const
|
|
139 |
{ return isIndexHidden(index); }
|
|
140 |
inline void tst_setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
|
|
141 |
{ setSelection(rect, command); }
|
|
142 |
inline QRegion tst_visualRegionForSelection(const QItemSelection &selection) const
|
|
143 |
{ return visualRegionForSelection(selection); }
|
|
144 |
inline QModelIndexList tst_selectedIndexes() const
|
|
145 |
{ return selectedIndexes(); }
|
|
146 |
inline bool tst_edit(const QModelIndex &index, EditTrigger trigger, QEvent *event)
|
|
147 |
{ return edit(index, trigger, event); }
|
|
148 |
inline QItemSelectionModel::SelectionFlags tst_selectionCommand(const QModelIndex &index,
|
|
149 |
const QEvent *event = 0) const
|
|
150 |
{ return selectionCommand(index, event); }
|
|
151 |
#ifndef QT_NO_DRAGANDDROP
|
|
152 |
inline void tst_startDrag(Qt::DropActions supportedActions)
|
|
153 |
{ startDrag(supportedActions); }
|
|
154 |
#endif
|
|
155 |
inline QStyleOptionViewItem tst_viewOptions() const
|
|
156 |
{ return viewOptions(); }
|
|
157 |
enum tst_State {
|
|
158 |
NoState = QAbstractItemView::NoState,
|
|
159 |
DraggingState = QAbstractItemView::DraggingState,
|
|
160 |
DragSelectingState = QAbstractItemView::DragSelectingState,
|
|
161 |
EditingState = QAbstractItemView::EditingState,
|
|
162 |
ExpandingState = QAbstractItemView::ExpandingState,
|
|
163 |
CollapsingState = QAbstractItemView::CollapsingState
|
|
164 |
};
|
|
165 |
inline tst_State tst_state() const
|
|
166 |
{ return (tst_State)state(); }
|
|
167 |
inline void tst_setState(tst_State state)
|
|
168 |
{ setState(QAbstractItemView::State(state)); }
|
|
169 |
inline void tst_startAutoScroll()
|
|
170 |
{ startAutoScroll(); }
|
|
171 |
inline void tst_stopAutoScroll()
|
|
172 |
{ stopAutoScroll(); }
|
|
173 |
inline void tst_doAutoScroll()
|
|
174 |
{ doAutoScroll(); }
|
|
175 |
};
|
|
176 |
|
|
177 |
class tst_QAbstractItemView : public QObject
|
|
178 |
{
|
|
179 |
Q_OBJECT
|
|
180 |
|
|
181 |
public:
|
|
182 |
|
|
183 |
tst_QAbstractItemView();
|
|
184 |
virtual ~tst_QAbstractItemView();
|
|
185 |
void basic_tests(TestView *view);
|
|
186 |
|
|
187 |
public slots:
|
|
188 |
void initTestCase();
|
|
189 |
void cleanupTestCase();
|
|
190 |
|
|
191 |
private slots:
|
|
192 |
void getSetCheck();
|
|
193 |
void emptyModels_data();
|
|
194 |
void emptyModels();
|
|
195 |
void setModel_data();
|
|
196 |
void setModel();
|
|
197 |
void noModel();
|
|
198 |
void dragSelect();
|
|
199 |
void rowDelegate();
|
|
200 |
void columnDelegate();
|
|
201 |
void selectAll();
|
|
202 |
void ctrlA();
|
|
203 |
void persistentEditorFocus();
|
|
204 |
void setItemDelegate();
|
|
205 |
void setItemDelegate_data();
|
|
206 |
// The dragAndDrop() test doesn't work, and is thus disabled on Mac and Windows
|
|
207 |
// for the following reasons:
|
|
208 |
// Mac: use of GetCurrentEventButtonState() in QDragManager::drag()
|
|
209 |
// Win: unknown reason
|
|
210 |
#if !defined(Q_OS_MAC) && !defined(Q_OS_WIN)
|
|
211 |
#if 0
|
|
212 |
void dragAndDrop();
|
|
213 |
void dragAndDropOnChild();
|
|
214 |
#endif
|
|
215 |
#endif
|
|
216 |
void noFallbackToRoot();
|
|
217 |
void setCurrentIndex_data();
|
|
218 |
void setCurrentIndex();
|
|
219 |
|
|
220 |
void task221955_selectedEditor();
|
|
221 |
void task250754_fontChange();
|
|
222 |
void task200665_itemEntered();
|
|
223 |
void task257481_emptyEditor();
|
|
224 |
void shiftArrowSelectionAfterScrolling();
|
|
225 |
void shiftSelectionAfterRubberbandSelection();
|
|
226 |
void ctrlRubberbandSelection();
|
|
227 |
};
|
|
228 |
|
|
229 |
class MyAbstractItemDelegate : public QAbstractItemDelegate
|
|
230 |
{
|
|
231 |
public:
|
|
232 |
MyAbstractItemDelegate() : QAbstractItemDelegate() {};
|
|
233 |
void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const {}
|
|
234 |
QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const { return QSize(); }
|
|
235 |
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
|
|
236 |
const QModelIndex &) const { return new QWidget(parent); }
|
|
237 |
};
|
|
238 |
|
|
239 |
// Testing get/set functions
|
|
240 |
void tst_QAbstractItemView::getSetCheck()
|
|
241 |
{
|
|
242 |
QListView view;
|
|
243 |
TestView *obj1 = reinterpret_cast<TestView*>(&view);
|
|
244 |
// QAbstractItemDelegate * QAbstractItemView::itemDelegate()
|
|
245 |
// void QAbstractItemView::setItemDelegate(QAbstractItemDelegate *)
|
|
246 |
MyAbstractItemDelegate *var1 = new MyAbstractItemDelegate;
|
|
247 |
obj1->setItemDelegate(var1);
|
|
248 |
QCOMPARE((QAbstractItemDelegate*)var1, obj1->itemDelegate());
|
|
249 |
obj1->setItemDelegate((QAbstractItemDelegate *)0);
|
|
250 |
QCOMPARE((QAbstractItemDelegate *)0, obj1->itemDelegate());
|
|
251 |
delete var1;
|
|
252 |
|
|
253 |
// EditTriggers QAbstractItemView::editTriggers()
|
|
254 |
// void QAbstractItemView::setEditTriggers(EditTriggers)
|
|
255 |
obj1->setEditTriggers(QAbstractItemView::EditTriggers(QAbstractItemView::NoEditTriggers));
|
|
256 |
QCOMPARE(QAbstractItemView::EditTriggers(QAbstractItemView::NoEditTriggers), obj1->editTriggers());
|
|
257 |
obj1->setEditTriggers(QAbstractItemView::EditTriggers(QAbstractItemView::CurrentChanged));
|
|
258 |
QCOMPARE(QAbstractItemView::EditTriggers(QAbstractItemView::CurrentChanged), obj1->editTriggers());
|
|
259 |
obj1->setEditTriggers(QAbstractItemView::EditTriggers(QAbstractItemView::DoubleClicked));
|
|
260 |
QCOMPARE(QAbstractItemView::EditTriggers(QAbstractItemView::DoubleClicked), obj1->editTriggers());
|
|
261 |
obj1->setEditTriggers(QAbstractItemView::EditTriggers(QAbstractItemView::SelectedClicked));
|
|
262 |
QCOMPARE(QAbstractItemView::EditTriggers(QAbstractItemView::SelectedClicked), obj1->editTriggers());
|
|
263 |
obj1->setEditTriggers(QAbstractItemView::EditTriggers(QAbstractItemView::EditKeyPressed));
|
|
264 |
QCOMPARE(QAbstractItemView::EditTriggers(QAbstractItemView::EditKeyPressed), obj1->editTriggers());
|
|
265 |
obj1->setEditTriggers(QAbstractItemView::EditTriggers(QAbstractItemView::AnyKeyPressed));
|
|
266 |
QCOMPARE(QAbstractItemView::EditTriggers(QAbstractItemView::AnyKeyPressed), obj1->editTriggers());
|
|
267 |
obj1->setEditTriggers(QAbstractItemView::EditTriggers(QAbstractItemView::AllEditTriggers));
|
|
268 |
QCOMPARE(QAbstractItemView::EditTriggers(QAbstractItemView::AllEditTriggers), obj1->editTriggers());
|
|
269 |
|
|
270 |
// bool QAbstractItemView::tabKeyNavigation()
|
|
271 |
// void QAbstractItemView::setTabKeyNavigation(bool)
|
|
272 |
obj1->setTabKeyNavigation(false);
|
|
273 |
QCOMPARE(false, obj1->tabKeyNavigation());
|
|
274 |
obj1->setTabKeyNavigation(true);
|
|
275 |
QCOMPARE(true, obj1->tabKeyNavigation());
|
|
276 |
|
|
277 |
// bool QAbstractItemView::dragEnabled()
|
|
278 |
// void QAbstractItemView::setDragEnabled(bool)
|
|
279 |
#ifndef QT_NO_DRAGANDDROP
|
|
280 |
obj1->setDragEnabled(false);
|
|
281 |
QCOMPARE(false, obj1->dragEnabled());
|
|
282 |
obj1->setDragEnabled(true);
|
|
283 |
QCOMPARE(true, obj1->dragEnabled());
|
|
284 |
#endif
|
|
285 |
// bool QAbstractItemView::alternatingRowColors()
|
|
286 |
// void QAbstractItemView::setAlternatingRowColors(bool)
|
|
287 |
obj1->setAlternatingRowColors(false);
|
|
288 |
QCOMPARE(false, obj1->alternatingRowColors());
|
|
289 |
obj1->setAlternatingRowColors(true);
|
|
290 |
QCOMPARE(true, obj1->alternatingRowColors());
|
|
291 |
|
|
292 |
// State QAbstractItemView::state()
|
|
293 |
// void QAbstractItemView::setState(State)
|
|
294 |
obj1->tst_setState(TestView::tst_State(TestView::NoState));
|
|
295 |
QCOMPARE(TestView::tst_State(TestView::NoState), obj1->tst_state());
|
|
296 |
obj1->tst_setState(TestView::tst_State(TestView::DraggingState));
|
|
297 |
QCOMPARE(TestView::tst_State(TestView::DraggingState), obj1->tst_state());
|
|
298 |
obj1->tst_setState(TestView::tst_State(TestView::DragSelectingState));
|
|
299 |
QCOMPARE(TestView::tst_State(TestView::DragSelectingState), obj1->tst_state());
|
|
300 |
obj1->tst_setState(TestView::tst_State(TestView::EditingState));
|
|
301 |
QCOMPARE(TestView::tst_State(TestView::EditingState), obj1->tst_state());
|
|
302 |
obj1->tst_setState(TestView::tst_State(TestView::ExpandingState));
|
|
303 |
QCOMPARE(TestView::tst_State(TestView::ExpandingState), obj1->tst_state());
|
|
304 |
obj1->tst_setState(TestView::tst_State(TestView::CollapsingState));
|
|
305 |
QCOMPARE(TestView::tst_State(TestView::CollapsingState), obj1->tst_state());
|
|
306 |
|
|
307 |
// QWidget QAbstractScrollArea::viewport()
|
|
308 |
// void setViewport(QWidget*)
|
|
309 |
QWidget *vp = new QWidget;
|
|
310 |
obj1->setViewport(vp);
|
|
311 |
QCOMPARE(vp, obj1->viewport());
|
|
312 |
|
|
313 |
QCOMPARE(16, obj1->autoScrollMargin());
|
|
314 |
obj1->setAutoScrollMargin(20);
|
|
315 |
QCOMPARE(20, obj1->autoScrollMargin());
|
|
316 |
obj1->setAutoScrollMargin(16);
|
|
317 |
QCOMPARE(16, obj1->autoScrollMargin());
|
|
318 |
}
|
|
319 |
|
|
320 |
tst_QAbstractItemView::tst_QAbstractItemView()
|
|
321 |
{
|
|
322 |
}
|
|
323 |
|
|
324 |
tst_QAbstractItemView::~tst_QAbstractItemView()
|
|
325 |
{
|
|
326 |
}
|
|
327 |
|
|
328 |
void tst_QAbstractItemView::initTestCase()
|
|
329 |
{
|
|
330 |
#ifdef Q_OS_WINCE_WM
|
|
331 |
qApp->setAutoMaximizeThreshold(-1);
|
|
332 |
#endif
|
|
333 |
}
|
|
334 |
|
|
335 |
void tst_QAbstractItemView::cleanupTestCase()
|
|
336 |
{
|
|
337 |
}
|
|
338 |
|
|
339 |
void tst_QAbstractItemView::emptyModels_data()
|
|
340 |
{
|
|
341 |
QTest::addColumn<QString>("viewType");
|
|
342 |
|
|
343 |
QTest::newRow("QListView") << "QListView";
|
|
344 |
QTest::newRow("QTableView") << "QTableView";
|
|
345 |
QTest::newRow("QTreeView") << "QTreeView";
|
|
346 |
QTest::newRow("QHeaderView") << "QHeaderView";
|
|
347 |
}
|
|
348 |
|
|
349 |
void tst_QAbstractItemView::emptyModels()
|
|
350 |
{
|
|
351 |
QFETCH(QString, viewType);
|
|
352 |
|
|
353 |
TestView *view = 0;
|
|
354 |
if (viewType == "QListView")
|
|
355 |
view = reinterpret_cast<TestView*>(new QListView());
|
|
356 |
else if (viewType == "QTableView")
|
|
357 |
view = reinterpret_cast<TestView*>(new QTableView());
|
|
358 |
else if (viewType == "QTreeView")
|
|
359 |
view = reinterpret_cast<TestView*>(new QTreeView());
|
|
360 |
else if (viewType == "QHeaderView")
|
|
361 |
view = reinterpret_cast<TestView*>(new QHeaderView(Qt::Vertical));
|
|
362 |
else
|
|
363 |
QVERIFY(0);
|
|
364 |
view->show();
|
|
365 |
|
|
366 |
QVERIFY(!view->model());
|
|
367 |
QVERIFY(!view->selectionModel());
|
|
368 |
//QVERIFY(view->itemDelegate() != 0);
|
|
369 |
|
|
370 |
basic_tests(view);
|
|
371 |
delete view;
|
|
372 |
}
|
|
373 |
|
|
374 |
void tst_QAbstractItemView::setModel_data()
|
|
375 |
{
|
|
376 |
QTest::addColumn<QString>("viewType");
|
|
377 |
|
|
378 |
QTest::newRow("QListView") << "QListView";
|
|
379 |
QTest::newRow("QTableView") << "QTableView";
|
|
380 |
QTest::newRow("QTreeView") << "QTreeView";
|
|
381 |
QTest::newRow("QHeaderView") << "QHeaderView";
|
|
382 |
}
|
|
383 |
|
|
384 |
void tst_QAbstractItemView::setModel()
|
|
385 |
{
|
|
386 |
QFETCH(QString, viewType);
|
|
387 |
TestView *view = 0;
|
|
388 |
if (viewType == "QListView")
|
|
389 |
view = reinterpret_cast<TestView*>(new QListView());
|
|
390 |
else if (viewType == "QTableView")
|
|
391 |
view = reinterpret_cast<TestView*>(new QTableView());
|
|
392 |
else if (viewType == "QTreeView")
|
|
393 |
view = reinterpret_cast<TestView*>(new QTreeView());
|
|
394 |
else if (viewType == "QHeaderView")
|
|
395 |
view = reinterpret_cast<TestView*>(new QHeaderView(Qt::Vertical));
|
|
396 |
else
|
|
397 |
QVERIFY(0);
|
|
398 |
view->show();
|
|
399 |
|
|
400 |
QStandardItemModel model(20,20);
|
|
401 |
view->setModel(0);
|
|
402 |
view->setModel(&model);
|
|
403 |
basic_tests(view);
|
|
404 |
delete view;
|
|
405 |
}
|
|
406 |
|
|
407 |
void tst_QAbstractItemView::basic_tests(TestView *view)
|
|
408 |
{
|
|
409 |
// setSelectionModel
|
|
410 |
// Will assert as it should
|
|
411 |
//view->setSelectionModel(0);
|
|
412 |
// setItemDelegate
|
|
413 |
//view->setItemDelegate(0);
|
|
414 |
// Will asswert as it should
|
|
415 |
|
|
416 |
// setSelectionMode
|
|
417 |
view->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
418 |
QCOMPARE(view->selectionMode(), QAbstractItemView::SingleSelection);
|
|
419 |
view->setSelectionMode(QAbstractItemView::ContiguousSelection);
|
|
420 |
QCOMPARE(view->selectionMode(), QAbstractItemView::ContiguousSelection);
|
|
421 |
view->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
422 |
QCOMPARE(view->selectionMode(), QAbstractItemView::ExtendedSelection);
|
|
423 |
view->setSelectionMode(QAbstractItemView::MultiSelection);
|
|
424 |
QCOMPARE(view->selectionMode(), QAbstractItemView::MultiSelection);
|
|
425 |
view->setSelectionMode(QAbstractItemView::NoSelection);
|
|
426 |
QCOMPARE(view->selectionMode(), QAbstractItemView::NoSelection);
|
|
427 |
|
|
428 |
// setSelectionBehavior
|
|
429 |
view->setSelectionBehavior(QAbstractItemView::SelectItems);
|
|
430 |
QCOMPARE(view->selectionBehavior(), QAbstractItemView::SelectItems);
|
|
431 |
view->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
432 |
QCOMPARE(view->selectionBehavior(), QAbstractItemView::SelectRows);
|
|
433 |
view->setSelectionBehavior(QAbstractItemView::SelectColumns);
|
|
434 |
QCOMPARE(view->selectionBehavior(), QAbstractItemView::SelectColumns);
|
|
435 |
|
|
436 |
// setEditTriggers
|
|
437 |
view->setEditTriggers(QAbstractItemView::EditKeyPressed);
|
|
438 |
QCOMPARE(view->editTriggers(), QAbstractItemView::EditKeyPressed);
|
|
439 |
view->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
440 |
QCOMPARE(view->editTriggers(), QAbstractItemView::NoEditTriggers);
|
|
441 |
view->setEditTriggers(QAbstractItemView::CurrentChanged);
|
|
442 |
QCOMPARE(view->editTriggers(), QAbstractItemView::CurrentChanged);
|
|
443 |
view->setEditTriggers(QAbstractItemView::DoubleClicked);
|
|
444 |
QCOMPARE(view->editTriggers(), QAbstractItemView::DoubleClicked);
|
|
445 |
view->setEditTriggers(QAbstractItemView::SelectedClicked);
|
|
446 |
QCOMPARE(view->editTriggers(), QAbstractItemView::SelectedClicked);
|
|
447 |
view->setEditTriggers(QAbstractItemView::AnyKeyPressed);
|
|
448 |
QCOMPARE(view->editTriggers(), QAbstractItemView::AnyKeyPressed);
|
|
449 |
view->setEditTriggers(QAbstractItemView::AllEditTriggers);
|
|
450 |
QCOMPARE(view->editTriggers(), QAbstractItemView::AllEditTriggers);
|
|
451 |
|
|
452 |
// setAutoScroll
|
|
453 |
view->setAutoScroll(false);
|
|
454 |
QCOMPARE(view->hasAutoScroll(), false);
|
|
455 |
view->setAutoScroll(true);
|
|
456 |
QCOMPARE(view->hasAutoScroll(), true);
|
|
457 |
|
|
458 |
// setTabKeyNavigation
|
|
459 |
view->setTabKeyNavigation(false);
|
|
460 |
QCOMPARE(view->tabKeyNavigation(), false);
|
|
461 |
view->setTabKeyNavigation(true);
|
|
462 |
QCOMPARE(view->tabKeyNavigation(), true);
|
|
463 |
|
|
464 |
#ifndef QT_NO_DRAGANDDROP
|
|
465 |
// setDropIndicatorShown
|
|
466 |
view->setDropIndicatorShown(false);
|
|
467 |
QCOMPARE(view->showDropIndicator(), false);
|
|
468 |
view->setDropIndicatorShown(true);
|
|
469 |
QCOMPARE(view->showDropIndicator(), true);
|
|
470 |
|
|
471 |
// setDragEnabled
|
|
472 |
view->setDragEnabled(false);
|
|
473 |
QCOMPARE(view->dragEnabled(), false);
|
|
474 |
view->setDragEnabled(true);
|
|
475 |
QCOMPARE(view->dragEnabled(), true);
|
|
476 |
#endif
|
|
477 |
|
|
478 |
// setAlternatingRowColors
|
|
479 |
view->setAlternatingRowColors(false);
|
|
480 |
QCOMPARE(view->alternatingRowColors(), false);
|
|
481 |
view->setAlternatingRowColors(true);
|
|
482 |
QCOMPARE(view->alternatingRowColors(), true);
|
|
483 |
|
|
484 |
// setIconSize
|
|
485 |
view->setIconSize(QSize(16, 16));
|
|
486 |
QCOMPARE(view->iconSize(), QSize(16, 16));
|
|
487 |
view->setIconSize(QSize(32, 32));
|
|
488 |
QCOMPARE(view->iconSize(), QSize(32, 32));
|
|
489 |
// Should this happen?
|
|
490 |
view->setIconSize(QSize(-1, -1));
|
|
491 |
QCOMPARE(view->iconSize(), QSize(-1, -1));
|
|
492 |
|
|
493 |
QCOMPARE(view->currentIndex(), QModelIndex());
|
|
494 |
QCOMPARE(view->rootIndex(), QModelIndex());
|
|
495 |
|
|
496 |
view->keyboardSearch("");
|
|
497 |
view->keyboardSearch("foo");
|
|
498 |
view->keyboardSearch("1");
|
|
499 |
|
|
500 |
QCOMPARE(view->visualRect(QModelIndex()), QRect());
|
|
501 |
|
|
502 |
view->scrollTo(QModelIndex());
|
|
503 |
|
|
504 |
QCOMPARE(view->sizeHintForIndex(QModelIndex()), QSize());
|
|
505 |
QCOMPARE(view->indexAt(QPoint(-1, -1)), QModelIndex());
|
|
506 |
|
|
507 |
if (!view->model()){
|
|
508 |
QCOMPARE(view->indexAt(QPoint(10, 10)), QModelIndex());
|
|
509 |
QCOMPARE(view->sizeHintForRow(0), -1);
|
|
510 |
QCOMPARE(view->sizeHintForColumn(0), -1);
|
|
511 |
}else if (view->itemDelegate()){
|
|
512 |
view->sizeHintForRow(0);
|
|
513 |
view->sizeHintForColumn(0);
|
|
514 |
}
|
|
515 |
view->openPersistentEditor(QModelIndex());
|
|
516 |
view->closePersistentEditor(QModelIndex());
|
|
517 |
|
|
518 |
view->reset();
|
|
519 |
view->setRootIndex(QModelIndex());
|
|
520 |
view->doItemsLayout();
|
|
521 |
view->selectAll();
|
|
522 |
view->edit(QModelIndex());
|
|
523 |
view->clearSelection();
|
|
524 |
view->setCurrentIndex(QModelIndex());
|
|
525 |
|
|
526 |
// protected methods
|
|
527 |
view->tst_dataChanged(QModelIndex(), QModelIndex());
|
|
528 |
view->tst_rowsInserted(QModelIndex(), -1, -1);
|
|
529 |
view->tst_rowsAboutToBeRemoved(QModelIndex(), -1, -1);
|
|
530 |
view->tst_selectionChanged(QItemSelection(), QItemSelection());
|
|
531 |
if (view->model()){
|
|
532 |
view->tst_currentChanged(QModelIndex(), QModelIndex());
|
|
533 |
view->tst_currentChanged(QModelIndex(), view->model()->index(0,0));
|
|
534 |
}
|
|
535 |
view->tst_updateEditorData();
|
|
536 |
view->tst_updateEditorGeometries();
|
|
537 |
view->tst_updateGeometries();
|
|
538 |
view->tst_verticalScrollbarAction(QAbstractSlider::SliderSingleStepAdd);
|
|
539 |
view->tst_horizontalScrollbarAction(QAbstractSlider::SliderSingleStepAdd);
|
|
540 |
view->tst_verticalScrollbarValueChanged(10);
|
|
541 |
view->tst_horizontalScrollbarValueChanged(10);
|
|
542 |
view->tst_closeEditor(0, QAbstractItemDelegate::NoHint);
|
|
543 |
view->tst_commitData(0);
|
|
544 |
view->tst_editorDestroyed(0);
|
|
545 |
|
|
546 |
view->tst_setHorizontalStepsPerItem(2);
|
|
547 |
view->tst_horizontalStepsPerItem();
|
|
548 |
view->tst_setVerticalStepsPerItem(2);
|
|
549 |
view->tst_verticalStepsPerItem();
|
|
550 |
|
|
551 |
// Will assert as it should
|
|
552 |
// view->setIndexWidget(QModelIndex(), 0);
|
|
553 |
|
|
554 |
view->tst_moveCursor(TestView::MoveUp, Qt::NoModifier);
|
|
555 |
view->tst_horizontalOffset();
|
|
556 |
view->tst_verticalOffset();
|
|
557 |
|
|
558 |
// view->tst_isIndexHidden(QModelIndex()); // will (correctly) assert
|
|
559 |
if(view->model())
|
|
560 |
view->tst_isIndexHidden(view->model()->index(0,0));
|
|
561 |
|
|
562 |
view->tst_setSelection(QRect(0, 0, 10, 10), QItemSelectionModel::ClearAndSelect);
|
|
563 |
view->tst_setSelection(QRect(-1, -1, -1, -1), QItemSelectionModel::ClearAndSelect);
|
|
564 |
view->tst_visualRegionForSelection(QItemSelection());
|
|
565 |
view->tst_selectedIndexes();
|
|
566 |
|
|
567 |
view->tst_edit(QModelIndex(), QAbstractItemView::NoEditTriggers, 0);
|
|
568 |
|
|
569 |
view->tst_selectionCommand(QModelIndex(), 0);
|
|
570 |
|
|
571 |
#ifndef QT_NO_DRAGANDDROP
|
|
572 |
if (!view->model())
|
|
573 |
view->tst_startDrag(Qt::CopyAction);
|
|
574 |
|
|
575 |
view->tst_viewOptions();
|
|
576 |
|
|
577 |
view->tst_setState(TestView::NoState);
|
|
578 |
QVERIFY(view->tst_state()==TestView::NoState);
|
|
579 |
view->tst_setState(TestView::DraggingState);
|
|
580 |
QVERIFY(view->tst_state()==TestView::DraggingState);
|
|
581 |
view->tst_setState(TestView::DragSelectingState);
|
|
582 |
QVERIFY(view->tst_state()==TestView::DragSelectingState);
|
|
583 |
view->tst_setState(TestView::EditingState);
|
|
584 |
QVERIFY(view->tst_state()==TestView::EditingState);
|
|
585 |
view->tst_setState(TestView::ExpandingState);
|
|
586 |
QVERIFY(view->tst_state()==TestView::ExpandingState);
|
|
587 |
view->tst_setState(TestView::CollapsingState);
|
|
588 |
QVERIFY(view->tst_state()==TestView::CollapsingState);
|
|
589 |
#endif
|
|
590 |
|
|
591 |
view->tst_startAutoScroll();
|
|
592 |
view->tst_stopAutoScroll();
|
|
593 |
view->tst_doAutoScroll();
|
|
594 |
|
|
595 |
// testing mouseFoo and key functions
|
|
596 |
// QTest::mousePress(view, Qt::LeftButton, Qt::NoModifier, QPoint(0,0));
|
|
597 |
// mouseMove(view, Qt::LeftButton, Qt::NoModifier, QPoint(10,10));
|
|
598 |
// QTest::mouseRelease(view, Qt::LeftButton, Qt::NoModifier, QPoint(10,10));
|
|
599 |
// QTest::mouseClick(view, Qt::LeftButton, Qt::NoModifier, QPoint(10,10));
|
|
600 |
// mouseDClick(view, Qt::LeftButton, Qt::NoModifier, QPoint(10,10));
|
|
601 |
// QTest::keyClick(view, Qt::Key_A);
|
|
602 |
}
|
|
603 |
|
|
604 |
void tst_QAbstractItemView::noModel()
|
|
605 |
{
|
|
606 |
// From task #85415
|
|
607 |
|
|
608 |
QStandardItemModel model(20,20);
|
|
609 |
QTreeView view;
|
|
610 |
|
|
611 |
view.setModel(&model);
|
|
612 |
// Make the viewport smaller than the contents, so that we can scroll
|
|
613 |
view.resize(100,100);
|
|
614 |
view.show();
|
|
615 |
|
|
616 |
// make sure that the scrollbars are not at value 0
|
|
617 |
view.scrollTo(view.model()->index(10,10));
|
|
618 |
QApplication::processEvents();
|
|
619 |
|
|
620 |
view.setModel(0);
|
|
621 |
// Due to the model is removed, this will generate a valueChanged signal on both scrollbars. (value to 0)
|
|
622 |
QApplication::processEvents();
|
|
623 |
QCOMPARE(view.model(), (QAbstractItemModel*)0);
|
|
624 |
}
|
|
625 |
|
|
626 |
void tst_QAbstractItemView::dragSelect()
|
|
627 |
{
|
|
628 |
// From task #86108
|
|
629 |
|
|
630 |
QStandardItemModel model(64,64);
|
|
631 |
|
|
632 |
QTableView view;
|
|
633 |
view.setModel(&model);
|
|
634 |
view.setVisible(true);
|
|
635 |
|
|
636 |
const int delay = 2;
|
|
637 |
for (int i = 0; i < 2; ++i) {
|
|
638 |
bool tracking = (i == 1);
|
|
639 |
view.setMouseTracking(false);
|
|
640 |
QTest::mouseMove(&view, QPoint(0, 0), delay);
|
|
641 |
view.setMouseTracking(tracking);
|
|
642 |
QTest::mouseMove(&view, QPoint(50, 50), delay);
|
|
643 |
QVERIFY(view.selectionModel()->selectedIndexes().isEmpty());
|
|
644 |
}
|
|
645 |
}
|
|
646 |
|
|
647 |
void tst_QAbstractItemView::rowDelegate()
|
|
648 |
{
|
|
649 |
QStandardItemModel model(4,4);
|
|
650 |
MyAbstractItemDelegate delegate;
|
|
651 |
|
|
652 |
QTableView view;
|
|
653 |
view.setModel(&model);
|
|
654 |
view.setItemDelegateForRow(3, &delegate);
|
|
655 |
view.show();
|
|
656 |
|
|
657 |
QModelIndex index = model.index(3, 0);
|
|
658 |
view.openPersistentEditor(index);
|
|
659 |
QWidget *w = view.indexWidget(index);
|
|
660 |
QVERIFY(w);
|
|
661 |
QCOMPARE(w->metaObject()->className(), "QWidget");
|
|
662 |
}
|
|
663 |
|
|
664 |
void tst_QAbstractItemView::columnDelegate()
|
|
665 |
{
|
|
666 |
QStandardItemModel model(4,4);
|
|
667 |
MyAbstractItemDelegate delegate;
|
|
668 |
|
|
669 |
QTableView view;
|
|
670 |
view.setModel(&model);
|
|
671 |
view.setItemDelegateForColumn(3, &delegate);
|
|
672 |
view.show();
|
|
673 |
|
|
674 |
QModelIndex index = model.index(0, 3);
|
|
675 |
view.openPersistentEditor(index);
|
|
676 |
QWidget *w = view.indexWidget(index);
|
|
677 |
QVERIFY(w);
|
|
678 |
QCOMPARE(w->metaObject()->className(), "QWidget");
|
|
679 |
}
|
|
680 |
|
|
681 |
void tst_QAbstractItemView::selectAll()
|
|
682 |
{
|
|
683 |
QStandardItemModel model(4,4);
|
|
684 |
QTableView view;
|
|
685 |
view.setModel(&model);
|
|
686 |
|
|
687 |
TestView *tst_view = (TestView*)&view;
|
|
688 |
|
|
689 |
QCOMPARE(tst_view->tst_selectedIndexes().count(), 0);
|
|
690 |
view.selectAll();
|
|
691 |
QCOMPARE(tst_view->tst_selectedIndexes().count(), 4*4);
|
|
692 |
}
|
|
693 |
|
|
694 |
void tst_QAbstractItemView::ctrlA()
|
|
695 |
{
|
|
696 |
QStandardItemModel model(4,4);
|
|
697 |
QTableView view;
|
|
698 |
view.setModel(&model);
|
|
699 |
|
|
700 |
TestView *tst_view = (TestView*)&view;
|
|
701 |
|
|
702 |
QCOMPARE(tst_view->tst_selectedIndexes().count(), 0);
|
|
703 |
QTest::keyClick(&view, Qt::Key_A, Qt::ControlModifier);
|
|
704 |
QCOMPARE(tst_view->tst_selectedIndexes().count(), 4*4);
|
|
705 |
}
|
|
706 |
|
|
707 |
void tst_QAbstractItemView::persistentEditorFocus()
|
|
708 |
{
|
|
709 |
// one row, three columns
|
|
710 |
QStandardItemModel model(1, 3);
|
|
711 |
for(int i = 0; i < model.columnCount(); ++i)
|
|
712 |
model.setData(model.index(0, i), i);
|
|
713 |
QTableView view;
|
|
714 |
view.setModel(&model);
|
|
715 |
|
|
716 |
view.openPersistentEditor(model.index(0, 1));
|
|
717 |
view.openPersistentEditor(model.index(0, 2));
|
|
718 |
|
|
719 |
//these are spinboxes because we put numbers inside
|
|
720 |
QList<QSpinBox*> list = qFindChildren<QSpinBox*>(view.viewport());
|
|
721 |
QCOMPARE(list.count(), 2); //these should be the 2 editors
|
|
722 |
|
|
723 |
view.setCurrentIndex(model.index(0, 0));
|
|
724 |
QCOMPARE(view.currentIndex(), model.index(0, 0));
|
|
725 |
view.show();
|
|
726 |
QTRY_VERIFY(view.isVisible());
|
|
727 |
|
|
728 |
for (int i = 0; i < list.count(); ++i) {
|
|
729 |
TRY_COMPARE(list.at(i)->isVisible(), true);
|
|
730 |
QPoint p = QPoint(5, 5);
|
|
731 |
QMouseEvent mouseEvent(QEvent::MouseButtonPress, p, Qt::LeftButton,
|
|
732 |
Qt::LeftButton, Qt::NoModifier);
|
|
733 |
qApp->sendEvent(list.at(i), &mouseEvent);
|
|
734 |
if (!qApp->focusWidget())
|
|
735 |
QSKIP("Some window managers don't handle focus that well", SkipAll);
|
|
736 |
QTRY_COMPARE(qApp->focusWidget(), static_cast<QWidget *>(list.at(i)));
|
|
737 |
}
|
|
738 |
}
|
|
739 |
|
|
740 |
|
|
741 |
#if !defined(Q_OS_MAC) && !defined(Q_OS_WIN)
|
|
742 |
|
|
743 |
#if 0
|
|
744 |
|
|
745 |
static void sendMouseMove(QWidget *widget, QPoint pos = QPoint())
|
|
746 |
{
|
|
747 |
if (pos.isNull())
|
|
748 |
pos = widget->rect().center();
|
|
749 |
QMouseEvent event(QEvent::MouseMove, pos, widget->mapToGlobal(pos), Qt::NoButton, 0, 0);
|
|
750 |
QCursor::setPos(widget->mapToGlobal(pos));
|
|
751 |
qApp->processEvents();
|
|
752 |
#if defined(Q_WS_X11)
|
|
753 |
qt_x11_wait_for_window_manager(widget);
|
|
754 |
#endif
|
|
755 |
QApplication::sendEvent(widget, &event);
|
|
756 |
}
|
|
757 |
|
|
758 |
static void sendMousePress(
|
|
759 |
QWidget *widget, QPoint pos = QPoint(), Qt::MouseButton button = Qt::LeftButton)
|
|
760 |
{
|
|
761 |
if (pos.isNull())
|
|
762 |
pos = widget->rect().center();
|
|
763 |
QMouseEvent event(QEvent::MouseButtonPress, pos, widget->mapToGlobal(pos), button, 0, 0);
|
|
764 |
QApplication::sendEvent(widget, &event);
|
|
765 |
}
|
|
766 |
|
|
767 |
static void sendMouseRelease(
|
|
768 |
QWidget *widget, QPoint pos = QPoint(), Qt::MouseButton button = Qt::LeftButton)
|
|
769 |
{
|
|
770 |
if (pos.isNull())
|
|
771 |
pos = widget->rect().center();
|
|
772 |
QMouseEvent event(QEvent::MouseButtonRelease, pos, widget->mapToGlobal(pos), button, 0, 0);
|
|
773 |
QApplication::sendEvent(widget, &event);
|
|
774 |
}
|
|
775 |
|
|
776 |
class DnDTestModel : public QStandardItemModel
|
|
777 |
{
|
|
778 |
Q_OBJECT
|
|
779 |
bool dropMimeData(const QMimeData *md, Qt::DropAction action, int r, int c, const QModelIndex &p)
|
|
780 |
{
|
|
781 |
dropAction_result = action;
|
|
782 |
QStandardItemModel::dropMimeData(md, action, r, c, p);
|
|
783 |
return true;
|
|
784 |
}
|
|
785 |
Qt::DropActions supportedDropActions() const { return Qt::CopyAction | Qt::MoveAction; }
|
|
786 |
|
|
787 |
Qt::DropAction dropAction_result;
|
|
788 |
public:
|
|
789 |
DnDTestModel() : QStandardItemModel(20, 20), dropAction_result(Qt::IgnoreAction) {
|
|
790 |
for (int i = 0; i < rowCount(); ++i)
|
|
791 |
setData(index(i, 0), QString("%1").arg(i));
|
|
792 |
}
|
|
793 |
Qt::DropAction dropAction() const { return dropAction_result; }
|
|
794 |
};
|
|
795 |
|
|
796 |
class DnDTestView : public QTreeView
|
|
797 |
{
|
|
798 |
Q_OBJECT
|
|
799 |
|
|
800 |
QPoint dropPoint;
|
|
801 |
Qt::DropAction dropAction;
|
|
802 |
|
|
803 |
void dragEnterEvent(QDragEnterEvent *event)
|
|
804 |
{
|
|
805 |
QAbstractItemView::dragEnterEvent(event);
|
|
806 |
}
|
|
807 |
|
|
808 |
void dropEvent(QDropEvent *event)
|
|
809 |
{
|
|
810 |
event->setDropAction(dropAction);
|
|
811 |
QTreeView::dropEvent(event);
|
|
812 |
}
|
|
813 |
|
|
814 |
void timerEvent(QTimerEvent *event)
|
|
815 |
{
|
|
816 |
killTimer(event->timerId());
|
|
817 |
sendMouseMove(this, dropPoint);
|
|
818 |
sendMouseRelease(this);
|
|
819 |
}
|
|
820 |
|
|
821 |
void mousePressEvent(QMouseEvent *e)
|
|
822 |
{
|
|
823 |
QTreeView::mousePressEvent(e);
|
|
824 |
|
|
825 |
startTimer(0);
|
|
826 |
setState(DraggingState);
|
|
827 |
startDrag(dropAction);
|
|
828 |
}
|
|
829 |
|
|
830 |
public:
|
|
831 |
DnDTestView(Qt::DropAction dropAction, QAbstractItemModel *model)
|
|
832 |
: dropAction(dropAction)
|
|
833 |
{
|
|
834 |
header()->hide();
|
|
835 |
setModel(model);
|
|
836 |
setDragDropMode(QAbstractItemView::DragDrop);
|
|
837 |
setAcceptDrops(true);
|
|
838 |
setDragEnabled(true);
|
|
839 |
}
|
|
840 |
|
|
841 |
void dragAndDrop(QPoint drag, QPoint drop)
|
|
842 |
{
|
|
843 |
dropPoint = drop;
|
|
844 |
setCurrentIndex(indexAt(drag));
|
|
845 |
sendMousePress(viewport(), drag);
|
|
846 |
}
|
|
847 |
};
|
|
848 |
|
|
849 |
class DnDTestWidget : public QWidget
|
|
850 |
{
|
|
851 |
Q_OBJECT
|
|
852 |
|
|
853 |
Qt::DropAction dropAction_request;
|
|
854 |
Qt::DropAction dropAction_result;
|
|
855 |
QWidget *dropTarget;
|
|
856 |
|
|
857 |
void timerEvent(QTimerEvent *event)
|
|
858 |
{
|
|
859 |
killTimer(event->timerId());
|
|
860 |
sendMouseMove(dropTarget);
|
|
861 |
sendMouseRelease(dropTarget);
|
|
862 |
}
|
|
863 |
|
|
864 |
void mousePressEvent(QMouseEvent *)
|
|
865 |
{
|
|
866 |
QDrag *drag = new QDrag(this);
|
|
867 |
QMimeData *mimeData = new QMimeData;
|
|
868 |
mimeData->setData("application/x-qabstractitemmodeldatalist", QByteArray(""));
|
|
869 |
drag->setMimeData(mimeData);
|
|
870 |
startTimer(0);
|
|
871 |
dropAction_result = drag->start(dropAction_request);
|
|
872 |
}
|
|
873 |
|
|
874 |
public:
|
|
875 |
Qt::DropAction dropAction() const { return dropAction_result; }
|
|
876 |
|
|
877 |
void dragAndDrop(QWidget *dropTarget, Qt::DropAction dropAction)
|
|
878 |
{
|
|
879 |
this->dropTarget = dropTarget;
|
|
880 |
dropAction_request = dropAction;
|
|
881 |
sendMousePress(this);
|
|
882 |
}
|
|
883 |
};
|
|
884 |
|
|
885 |
void tst_QAbstractItemView::dragAndDrop()
|
|
886 |
{
|
|
887 |
// From Task 137729
|
|
888 |
|
|
889 |
#ifdef Q_WS_QWS
|
|
890 |
QSKIP("Embedded drag-and-drop not good enough yet...", SkipAll);
|
|
891 |
#endif
|
|
892 |
|
|
893 |
const int attempts = 10;
|
|
894 |
int successes = 0;
|
|
895 |
for (int i = 0; i < attempts; ++i) {
|
|
896 |
Qt::DropAction dropAction = Qt::MoveAction;
|
|
897 |
|
|
898 |
DnDTestModel model;
|
|
899 |
DnDTestView view(dropAction, &model);
|
|
900 |
DnDTestWidget widget;
|
|
901 |
|
|
902 |
const int size = 200;
|
|
903 |
widget.setFixedSize(size, size);
|
|
904 |
view.setFixedSize(size, size);
|
|
905 |
|
|
906 |
widget.move(0, 0);
|
|
907 |
view.move(int(size * 1.5), int(size * 1.5));
|
|
908 |
|
|
909 |
widget.show();
|
|
910 |
view.show();
|
|
911 |
#if defined(Q_WS_X11)
|
|
912 |
qt_x11_wait_for_window_manager(&widget);
|
|
913 |
qt_x11_wait_for_window_manager(&view);
|
|
914 |
#endif
|
|
915 |
|
|
916 |
widget.dragAndDrop(&view, dropAction);
|
|
917 |
if (model.dropAction() == dropAction
|
|
918 |
&& widget.dropAction() == dropAction)
|
|
919 |
++successes;
|
|
920 |
}
|
|
921 |
|
|
922 |
if (successes < attempts) {
|
|
923 |
QString msg = QString("# successes (%1) < # attempts (%2)").arg(successes).arg(attempts);
|
|
924 |
QWARN(msg.toLatin1());
|
|
925 |
}
|
|
926 |
QVERIFY(successes > 0); // allow for some "event unstability" (i.e. unless
|
|
927 |
// successes == 0, QAbstractItemView is probably ok!)
|
|
928 |
}
|
|
929 |
|
|
930 |
void tst_QAbstractItemView::dragAndDropOnChild()
|
|
931 |
{
|
|
932 |
#ifdef Q_WS_QWS
|
|
933 |
QSKIP("Embedded drag-and-drop not good enough yet...", SkipAll);
|
|
934 |
#endif
|
|
935 |
|
|
936 |
const int attempts = 10;
|
|
937 |
int successes = 0;
|
|
938 |
for (int i = 0; i < attempts; ++i) {
|
|
939 |
Qt::DropAction dropAction = Qt::MoveAction;
|
|
940 |
|
|
941 |
DnDTestModel model;
|
|
942 |
QModelIndex parent = model.index(0, 0);
|
|
943 |
model.insertRow(0, parent);
|
|
944 |
model.insertColumn(0, parent);
|
|
945 |
QModelIndex child = model.index(0, 0, parent);
|
|
946 |
model.setData(child, "child");
|
|
947 |
QCOMPARE(model.rowCount(parent), 1);
|
|
948 |
DnDTestView view(dropAction, &model);
|
|
949 |
view.setExpanded(parent, true);
|
|
950 |
view.setDragDropMode(QAbstractItemView::InternalMove);
|
|
951 |
|
|
952 |
const int size = 200;
|
|
953 |
view.setFixedSize(size, size);
|
|
954 |
view.move(int(size * 1.5), int(size * 1.5));
|
|
955 |
view.show();
|
|
956 |
#if defined(Q_WS_X11)
|
|
957 |
qt_x11_wait_for_window_manager(&view);
|
|
958 |
#endif
|
|
959 |
|
|
960 |
view.dragAndDrop(view.visualRect(parent).center(),
|
|
961 |
view.visualRect(child).center());
|
|
962 |
if (model.dropAction() == dropAction)
|
|
963 |
++successes;
|
|
964 |
}
|
|
965 |
|
|
966 |
QVERIFY(successes == 0);
|
|
967 |
}
|
|
968 |
|
|
969 |
#endif // 0
|
|
970 |
#endif // !Q_OS_MAC && !Q_OS_WIN
|
|
971 |
|
|
972 |
class TestModel : public QStandardItemModel
|
|
973 |
{
|
|
974 |
public:
|
|
975 |
TestModel(int rows, int columns) : QStandardItemModel(rows, columns)
|
|
976 |
{
|
|
977 |
setData_count = 0;
|
|
978 |
}
|
|
979 |
|
|
980 |
virtual bool setData(const QModelIndex &/*index*/, const QVariant &/*value*/, int /*role = Qt::EditRole*/)
|
|
981 |
{
|
|
982 |
++setData_count;
|
|
983 |
return true;
|
|
984 |
}
|
|
985 |
|
|
986 |
int setData_count;
|
|
987 |
};
|
|
988 |
|
|
989 |
typedef QList<int> IntList;
|
|
990 |
Q_DECLARE_METATYPE(IntList)
|
|
991 |
|
|
992 |
void tst_QAbstractItemView::setItemDelegate_data()
|
|
993 |
{
|
|
994 |
// default is rows, a -1 will switch to columns
|
|
995 |
QTest::addColumn<IntList>("rowsOrColumnsWithDelegate");
|
|
996 |
QTest::addColumn<QPoint>("cellToEdit");
|
|
997 |
QTest::newRow("4 columndelegates")
|
|
998 |
<< (IntList() << -1 << 0 << 1 << 2 << 3)
|
|
999 |
<< QPoint(0, 0);
|
|
1000 |
QTest::newRow("2 identical rowdelegates on the same row")
|
|
1001 |
<< (IntList() << 0 << 0)
|
|
1002 |
<< QPoint(0, 0);
|
|
1003 |
QTest::newRow("2 identical columndelegates on the same column")
|
|
1004 |
<< (IntList() << -1 << 2 << 2)
|
|
1005 |
<< QPoint(2, 0);
|
|
1006 |
QTest::newRow("2 duplicate delegates, 1 row and 1 column")
|
|
1007 |
<< (IntList() << 0 << -1 << 2)
|
|
1008 |
<< QPoint(2, 0);
|
|
1009 |
QTest::newRow("4 duplicate delegates, 2 row and 2 column")
|
|
1010 |
<< (IntList() << 0 << 0 << -1 << 2 << 2)
|
|
1011 |
<< QPoint(2, 0);
|
|
1012 |
|
|
1013 |
}
|
|
1014 |
|
|
1015 |
void tst_QAbstractItemView::setItemDelegate()
|
|
1016 |
{
|
|
1017 |
QFETCH(IntList, rowsOrColumnsWithDelegate);
|
|
1018 |
QFETCH(QPoint, cellToEdit);
|
|
1019 |
QTableView v;
|
|
1020 |
QItemDelegate *delegate = new QItemDelegate(&v);
|
|
1021 |
TestModel model(5, 5);
|
|
1022 |
v.setModel(&model);
|
|
1023 |
|
|
1024 |
bool row = true;
|
|
1025 |
foreach (int rc, rowsOrColumnsWithDelegate) {
|
|
1026 |
if (rc == -1) {
|
|
1027 |
row = !row;
|
|
1028 |
} else {
|
|
1029 |
if (row) {
|
|
1030 |
v.setItemDelegateForRow(rc, delegate);
|
|
1031 |
} else {
|
|
1032 |
v.setItemDelegateForColumn(rc, delegate);
|
|
1033 |
}
|
|
1034 |
}
|
|
1035 |
}
|
|
1036 |
v.show();
|
|
1037 |
#ifdef Q_WS_X11
|
|
1038 |
qt_x11_wait_for_window_manager(&v);
|
|
1039 |
QCursor::setPos(v.geometry().center());
|
|
1040 |
QApplication::syncX();
|
|
1041 |
#endif
|
|
1042 |
QTest::qWait(20);
|
|
1043 |
QApplication::setActiveWindow(&v);
|
|
1044 |
|
|
1045 |
QModelIndex index = model.index(cellToEdit.y(), cellToEdit.x());
|
|
1046 |
v.edit(index);
|
|
1047 |
|
|
1048 |
// This will close the editor
|
|
1049 |
TRY_COMPARE(QApplication::focusWidget() == 0, false);
|
|
1050 |
QWidget *editor = QApplication::focusWidget();
|
|
1051 |
QVERIFY(editor);
|
|
1052 |
editor->hide();
|
|
1053 |
delete editor;
|
|
1054 |
QCOMPARE(model.setData_count, 1);
|
|
1055 |
delete delegate;
|
|
1056 |
}
|
|
1057 |
|
|
1058 |
void tst_QAbstractItemView::noFallbackToRoot()
|
|
1059 |
{
|
|
1060 |
QStandardItemModel model(0, 1);
|
|
1061 |
for (int i = 0; i < 5; ++i)
|
|
1062 |
model.appendRow(new QStandardItem("top" + QString::number(i)));
|
|
1063 |
QStandardItem *par1 = model.item(1);
|
|
1064 |
for (int j = 0; j < 15; ++j)
|
|
1065 |
par1->appendRow(new QStandardItem("sub" + QString::number(j)));
|
|
1066 |
QStandardItem *par2 = par1->child(2);
|
|
1067 |
for (int k = 0; k < 10; ++k)
|
|
1068 |
par2->appendRow(new QStandardItem("bot" + QString::number(k)));
|
|
1069 |
QStandardItem *it1 = par2->child(5);
|
|
1070 |
|
|
1071 |
QModelIndex parent1 = model.indexFromItem(par1);
|
|
1072 |
QModelIndex parent2 = model.indexFromItem(par2);
|
|
1073 |
QModelIndex item1 = model.indexFromItem(it1);
|
|
1074 |
|
|
1075 |
QTreeView v;
|
|
1076 |
v.setModel(&model);
|
|
1077 |
v.setRootIndex(parent1);
|
|
1078 |
v.setCurrentIndex(item1);
|
|
1079 |
QCOMPARE(v.currentIndex(), item1);
|
|
1080 |
QVERIFY(model.removeRows(0, 10, parent2));
|
|
1081 |
QCOMPARE(v.currentIndex(), parent2);
|
|
1082 |
QVERIFY(model.removeRows(0, 15, parent1));
|
|
1083 |
QCOMPARE(v.currentIndex(), QModelIndex());
|
|
1084 |
}
|
|
1085 |
|
|
1086 |
void tst_QAbstractItemView::setCurrentIndex_data()
|
|
1087 |
{
|
|
1088 |
QTest::addColumn<QString>("viewType");
|
|
1089 |
QTest::addColumn<int>("itemFlags");
|
|
1090 |
QTest::addColumn<bool>("result");
|
|
1091 |
|
|
1092 |
QStringList widgets;
|
|
1093 |
widgets << "QListView" << "QTreeView" << "QHeaderView" << "QTableView";
|
|
1094 |
|
|
1095 |
foreach(QString widget, widgets) {
|
|
1096 |
QTest::newRow((widget+QLatin1String(": no flags")).toLocal8Bit().constData())
|
|
1097 |
<< widget << (int)0 << false;
|
|
1098 |
QTest::newRow((widget+QLatin1String(": checkable")).toLocal8Bit().constData())
|
|
1099 |
<< widget << (int)Qt::ItemIsUserCheckable << false;
|
|
1100 |
QTest::newRow((widget+QLatin1String(": selectable")).toLocal8Bit().constData())
|
|
1101 |
<< widget << (int)Qt::ItemIsSelectable << false;
|
|
1102 |
QTest::newRow((widget+QLatin1String(": enabled")).toLocal8Bit().constData())
|
|
1103 |
<< widget << (int)Qt::ItemIsEnabled << true;
|
|
1104 |
QTest::newRow((widget+QLatin1String(": enabled|selectable")).toLocal8Bit().constData())
|
|
1105 |
<< widget << (int)(Qt::ItemIsSelectable|Qt::ItemIsEnabled) << true;
|
|
1106 |
}
|
|
1107 |
}
|
|
1108 |
|
|
1109 |
void tst_QAbstractItemView::setCurrentIndex()
|
|
1110 |
{
|
|
1111 |
QFETCH(QString, viewType);
|
|
1112 |
QFETCH(int, itemFlags);
|
|
1113 |
QFETCH(bool, result);
|
|
1114 |
|
|
1115 |
TestView *view = 0;
|
|
1116 |
if (viewType == "QListView")
|
|
1117 |
view = reinterpret_cast<TestView*>(new QListView());
|
|
1118 |
else if (viewType == "QTableView")
|
|
1119 |
view = reinterpret_cast<TestView*>(new QTableView());
|
|
1120 |
else if (viewType == "QTreeView")
|
|
1121 |
view = reinterpret_cast<TestView*>(new QTreeView());
|
|
1122 |
else if (viewType == "QHeaderView")
|
|
1123 |
view = reinterpret_cast<TestView*>(new QHeaderView(Qt::Vertical));
|
|
1124 |
else
|
|
1125 |
QVERIFY(0);
|
|
1126 |
view->show();
|
|
1127 |
|
|
1128 |
QStandardItemModel *model = new QStandardItemModel(view);
|
|
1129 |
QStandardItem *item = new QStandardItem("first item");
|
|
1130 |
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
|
1131 |
model->appendRow(item);
|
|
1132 |
|
|
1133 |
item = new QStandardItem("test item");
|
|
1134 |
item->setFlags(Qt::ItemFlags(itemFlags));
|
|
1135 |
model->appendRow(item);
|
|
1136 |
|
|
1137 |
view->setModel(model);
|
|
1138 |
|
|
1139 |
view->setCurrentIndex(model->index(0,0));
|
|
1140 |
QVERIFY(view->currentIndex() == model->index(0,0));
|
|
1141 |
view->setCurrentIndex(model->index(1,0));
|
|
1142 |
QVERIFY(view->currentIndex() == model->index(result ? 1 : 0,0));
|
|
1143 |
|
|
1144 |
delete view;
|
|
1145 |
}
|
|
1146 |
|
|
1147 |
void tst_QAbstractItemView::task221955_selectedEditor()
|
|
1148 |
{
|
|
1149 |
QPushButton *button;
|
|
1150 |
|
|
1151 |
QTreeWidget tree;
|
|
1152 |
tree.setColumnCount(2);
|
|
1153 |
|
|
1154 |
tree.addTopLevelItem(new QTreeWidgetItem(QStringList() << "Foo" <<"1"));
|
|
1155 |
tree.addTopLevelItem(new QTreeWidgetItem(QStringList() << "Bar" <<"2"));
|
|
1156 |
tree.addTopLevelItem(new QTreeWidgetItem(QStringList() << "Baz" <<"3"));
|
|
1157 |
|
|
1158 |
QTreeWidgetItem *dummy = new QTreeWidgetItem();
|
|
1159 |
tree.addTopLevelItem(dummy);
|
|
1160 |
tree.setItemWidget(dummy, 0, button = new QPushButton("More..."));
|
|
1161 |
button->setAutoFillBackground(true); // as recommended in doc
|
|
1162 |
|
|
1163 |
tree.show();
|
|
1164 |
tree.setFocus();
|
|
1165 |
tree.setCurrentIndex(tree.model()->index(1,0));
|
|
1166 |
QTest::qWait(100);
|
|
1167 |
QApplication::setActiveWindow(&tree);
|
|
1168 |
|
|
1169 |
QVERIFY(! tree.selectionModel()->selectedIndexes().contains(tree.model()->index(3,0)));
|
|
1170 |
|
|
1171 |
//We set the focus to the button, the index need to be selected
|
|
1172 |
button->setFocus();
|
|
1173 |
QTest::qWait(100);
|
|
1174 |
QVERIFY(tree.selectionModel()->selectedIndexes().contains(tree.model()->index(3,0)));
|
|
1175 |
|
|
1176 |
tree.setCurrentIndex(tree.model()->index(1,0));
|
|
1177 |
QVERIFY(! tree.selectionModel()->selectedIndexes().contains(tree.model()->index(3,0)));
|
|
1178 |
|
|
1179 |
//Same thing but with the flag NoSelection, nothing can be selected.
|
|
1180 |
tree.setFocus();
|
|
1181 |
tree.setSelectionMode(QAbstractItemView::NoSelection);
|
|
1182 |
tree.clearSelection();
|
|
1183 |
QVERIFY(tree.selectionModel()->selectedIndexes().isEmpty());
|
|
1184 |
QTest::qWait(10);
|
|
1185 |
button->setFocus();
|
|
1186 |
QTest::qWait(50);
|
|
1187 |
QVERIFY(tree.selectionModel()->selectedIndexes().isEmpty());
|
|
1188 |
}
|
|
1189 |
|
|
1190 |
void tst_QAbstractItemView::task250754_fontChange()
|
|
1191 |
{
|
|
1192 |
QString app_css = qApp->styleSheet();
|
|
1193 |
qApp->setStyleSheet("/* */");
|
|
1194 |
|
|
1195 |
QWidget w;
|
|
1196 |
QTreeView tree(&w);
|
|
1197 |
QVBoxLayout *vLayout = new QVBoxLayout(&w);
|
|
1198 |
vLayout->addWidget(&tree);
|
|
1199 |
|
|
1200 |
QStandardItemModel *m = new QStandardItemModel(this);
|
|
1201 |
for (int i=0; i<5; ++i) {
|
|
1202 |
QStandardItem *item = new QStandardItem(QString("Item number %1").arg(i));
|
|
1203 |
for (int j=0; j<5; ++j) {
|
|
1204 |
QStandardItem *child = new QStandardItem(QString("Child Item number %1").arg(j));
|
|
1205 |
item->setChild(j, 0, child);
|
|
1206 |
}
|
|
1207 |
m->setItem(i, 0, item);
|
|
1208 |
}
|
|
1209 |
tree.setModel(m);
|
|
1210 |
|
|
1211 |
w.show();
|
|
1212 |
w.resize(150,150);
|
|
1213 |
QTest::qWait(30);
|
|
1214 |
QFont font = tree.font();
|
|
1215 |
font.setPointSize(5);
|
|
1216 |
tree.setFont(font);
|
|
1217 |
QTRY_VERIFY(!tree.verticalScrollBar()->isVisible());
|
|
1218 |
|
|
1219 |
font.setPointSize(45);
|
|
1220 |
tree.setFont(font);
|
|
1221 |
//now with the huge items, the scrollbar must be visible
|
|
1222 |
QTRY_VERIFY(tree.verticalScrollBar()->isVisible());
|
|
1223 |
|
|
1224 |
qApp->setStyleSheet(app_css);
|
|
1225 |
}
|
|
1226 |
|
|
1227 |
void tst_QAbstractItemView::task200665_itemEntered()
|
|
1228 |
{
|
|
1229 |
#ifdef Q_OS_WINCE_WM
|
|
1230 |
QSKIP("On Windows Mobile the mouse tracking is unavailable at the moment", SkipAll);
|
|
1231 |
#endif
|
|
1232 |
//we test that view will emit entered
|
|
1233 |
//when the scrollbar move but not the mouse itself
|
|
1234 |
QStandardItemModel model(1000,1);
|
|
1235 |
QListView view;
|
|
1236 |
view.setModel(&model);
|
|
1237 |
view.show();
|
|
1238 |
QTest::qWait(200);
|
|
1239 |
QRect rect = view.visualRect(model.index(0,0));
|
|
1240 |
QCursor::setPos( view.viewport()->mapToGlobal(rect.center()) );
|
|
1241 |
QSignalSpy spy(&view, SIGNAL(entered(QModelIndex)));
|
|
1242 |
view.verticalScrollBar()->setValue(view.verticalScrollBar()->maximum());
|
|
1243 |
QCOMPARE(spy.count(), 1);
|
|
1244 |
|
|
1245 |
}
|
|
1246 |
|
|
1247 |
void tst_QAbstractItemView::task257481_emptyEditor()
|
|
1248 |
{
|
|
1249 |
QIcon icon = qApp->style()->standardIcon(QStyle::SP_ComputerIcon);
|
|
1250 |
|
|
1251 |
QStandardItemModel model;
|
|
1252 |
|
|
1253 |
model.appendRow( new QStandardItem(icon, QString()) );
|
|
1254 |
model.appendRow( new QStandardItem(icon, "Editor works") );
|
|
1255 |
model.appendRow( new QStandardItem( QString() ) );
|
|
1256 |
|
|
1257 |
QTreeView treeView;
|
|
1258 |
treeView.setRootIsDecorated(false);
|
|
1259 |
treeView.setModel(&model);
|
|
1260 |
treeView.show();
|
|
1261 |
|
|
1262 |
treeView.edit(model.index(0,0));
|
|
1263 |
QList<QLineEdit *> lineEditors = qFindChildren<QLineEdit *>(treeView.viewport());
|
|
1264 |
QCOMPARE(lineEditors.count(), 1);
|
|
1265 |
QVERIFY(!lineEditors.first()->size().isEmpty());
|
|
1266 |
|
|
1267 |
QTest::qWait(30);
|
|
1268 |
|
|
1269 |
treeView.edit(model.index(1,0));
|
|
1270 |
lineEditors = qFindChildren<QLineEdit *>(treeView.viewport());
|
|
1271 |
QCOMPARE(lineEditors.count(), 1);
|
|
1272 |
QVERIFY(!lineEditors.first()->size().isEmpty());
|
|
1273 |
|
|
1274 |
QTest::qWait(30);
|
|
1275 |
|
|
1276 |
treeView.edit(model.index(2,0));
|
|
1277 |
lineEditors = qFindChildren<QLineEdit *>(treeView.viewport());
|
|
1278 |
QCOMPARE(lineEditors.count(), 1);
|
|
1279 |
QVERIFY(!lineEditors.first()->size().isEmpty());
|
|
1280 |
}
|
|
1281 |
|
|
1282 |
void tst_QAbstractItemView::shiftArrowSelectionAfterScrolling()
|
|
1283 |
{
|
|
1284 |
QStandardItemModel model;
|
|
1285 |
for (int i=0; i<10; ++i) {
|
|
1286 |
QStandardItem *item = new QStandardItem(QString("%1").arg(i));
|
|
1287 |
model.setItem(i, 0, item);
|
|
1288 |
}
|
|
1289 |
|
|
1290 |
QListView view;
|
|
1291 |
view.setFixedSize(150, 250);
|
|
1292 |
view.setFlow(QListView::LeftToRight);
|
|
1293 |
view.setGridSize(QSize(100, 100));
|
|
1294 |
view.setSelectionMode(QListView::ExtendedSelection);
|
|
1295 |
view.setViewMode(QListView::IconMode);
|
|
1296 |
view.setModel(&model);
|
|
1297 |
view.show();
|
|
1298 |
QTest::qWait(30);
|
|
1299 |
|
|
1300 |
QModelIndex index0 = model.index(0, 0);
|
|
1301 |
QModelIndex index1 = model.index(1, 0);
|
|
1302 |
QModelIndex index9 = model.index(9, 0);
|
|
1303 |
|
|
1304 |
view.selectionModel()->setCurrentIndex(index0, QItemSelectionModel::NoUpdate);
|
|
1305 |
QCOMPARE(view.currentIndex(), index0);
|
|
1306 |
|
|
1307 |
view.scrollTo(index9);
|
|
1308 |
QTest::keyClick(&view, Qt::Key_Down, Qt::ShiftModifier);
|
|
1309 |
|
|
1310 |
QCOMPARE(view.currentIndex(), index1);
|
|
1311 |
QModelIndexList selected = view.selectionModel()->selectedIndexes();
|
|
1312 |
QCOMPARE(selected.count(), 2);
|
|
1313 |
QVERIFY(selected.contains(index0));
|
|
1314 |
QVERIFY(selected.contains(index1));
|
|
1315 |
}
|
|
1316 |
|
|
1317 |
void tst_QAbstractItemView::shiftSelectionAfterRubberbandSelection()
|
|
1318 |
{
|
|
1319 |
QStandardItemModel model;
|
|
1320 |
for (int i=0; i<3; ++i) {
|
|
1321 |
QStandardItem *item = new QStandardItem(QString("%1").arg(i));
|
|
1322 |
model.setItem(i, 0, item);
|
|
1323 |
}
|
|
1324 |
|
|
1325 |
QListView view;
|
|
1326 |
view.setFixedSize(150, 450);
|
|
1327 |
view.setFlow(QListView::LeftToRight);
|
|
1328 |
view.setGridSize(QSize(100, 100));
|
|
1329 |
view.setSelectionMode(QListView::ExtendedSelection);
|
|
1330 |
view.setViewMode(QListView::IconMode);
|
|
1331 |
view.setModel(&model);
|
|
1332 |
view.show();
|
|
1333 |
QTest::qWait(30);
|
|
1334 |
|
|
1335 |
QModelIndex index0 = model.index(0, 0);
|
|
1336 |
QModelIndex index1 = model.index(1, 0);
|
|
1337 |
QModelIndex index2 = model.index(2, 0);
|
|
1338 |
|
|
1339 |
view.setCurrentIndex(index0);
|
|
1340 |
QCOMPARE(view.currentIndex(), index0);
|
|
1341 |
|
|
1342 |
// Determine the points where the rubberband selection starts and ends
|
|
1343 |
QPoint pressPos = view.visualRect(index1).bottomRight() + QPoint(1, 1);
|
|
1344 |
QPoint releasePos = view.visualRect(index1).center();
|
|
1345 |
QVERIFY(!view.indexAt(pressPos).isValid());
|
|
1346 |
QCOMPARE(view.indexAt(releasePos), index1);
|
|
1347 |
|
|
1348 |
// Select item 1 using a rubberband selection
|
|
1349 |
// The mouse move event has to be created manually because the QTest framework does not
|
|
1350 |
// contain a function for mouse moves with buttons pressed
|
|
1351 |
QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::NoModifier, pressPos);
|
|
1352 |
QMouseEvent moveEvent(QEvent::MouseMove, releasePos, Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
|
|
1353 |
bool moveEventReceived = qApp->notify(view.viewport(), &moveEvent);
|
|
1354 |
QVERIFY(moveEventReceived);
|
|
1355 |
QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::NoModifier, releasePos);
|
|
1356 |
QCOMPARE(view.currentIndex(), index1);
|
|
1357 |
|
|
1358 |
// Shift-click item 2
|
|
1359 |
QPoint item2Pos = view.visualRect(index2).center();
|
|
1360 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ShiftModifier, item2Pos);
|
|
1361 |
QCOMPARE(view.currentIndex(), index2);
|
|
1362 |
|
|
1363 |
// Verify that the selection worked OK
|
|
1364 |
QModelIndexList selected = view.selectionModel()->selectedIndexes();
|
|
1365 |
QCOMPARE(selected.count(), 2);
|
|
1366 |
QVERIFY(selected.contains(index1));
|
|
1367 |
QVERIFY(selected.contains(index2));
|
|
1368 |
|
|
1369 |
// Select item 0 to revert the selection
|
|
1370 |
view.setCurrentIndex(index0);
|
|
1371 |
QCOMPARE(view.currentIndex(), index0);
|
|
1372 |
|
|
1373 |
// Repeat the same steps as above, but with a Shift-Arrow selection
|
|
1374 |
QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::NoModifier, pressPos);
|
|
1375 |
QMouseEvent moveEvent2(QEvent::MouseMove, releasePos, Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
|
|
1376 |
moveEventReceived = qApp->notify(view.viewport(), &moveEvent2);
|
|
1377 |
QVERIFY(moveEventReceived);
|
|
1378 |
QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::NoModifier, releasePos);
|
|
1379 |
QCOMPARE(view.currentIndex(), index1);
|
|
1380 |
|
|
1381 |
// Press Shift-Down
|
|
1382 |
QTest::keyClick(&view, Qt::Key_Down, Qt::ShiftModifier);
|
|
1383 |
QCOMPARE(view.currentIndex(), index2);
|
|
1384 |
|
|
1385 |
// Verify that the selection worked OK
|
|
1386 |
selected = view.selectionModel()->selectedIndexes();
|
|
1387 |
QCOMPARE(selected.count(), 2);
|
|
1388 |
QVERIFY(selected.contains(index1));
|
|
1389 |
QVERIFY(selected.contains(index2));
|
|
1390 |
}
|
|
1391 |
|
|
1392 |
void tst_QAbstractItemView::ctrlRubberbandSelection()
|
|
1393 |
{
|
|
1394 |
QStandardItemModel model;
|
|
1395 |
for (int i=0; i<3; ++i) {
|
|
1396 |
QStandardItem *item = new QStandardItem(QString("%1").arg(i));
|
|
1397 |
model.setItem(i, 0, item);
|
|
1398 |
}
|
|
1399 |
|
|
1400 |
QListView view;
|
|
1401 |
view.setFixedSize(150, 450);
|
|
1402 |
view.setFlow(QListView::LeftToRight);
|
|
1403 |
view.setGridSize(QSize(100, 100));
|
|
1404 |
view.setSelectionMode(QListView::ExtendedSelection);
|
|
1405 |
view.setViewMode(QListView::IconMode);
|
|
1406 |
view.setModel(&model);
|
|
1407 |
view.show();
|
|
1408 |
QTest::qWait(30);
|
|
1409 |
|
|
1410 |
QModelIndex index1 = model.index(1, 0);
|
|
1411 |
QModelIndex index2 = model.index(2, 0);
|
|
1412 |
|
|
1413 |
// Select item 1
|
|
1414 |
view.setCurrentIndex(index1);
|
|
1415 |
QModelIndexList selected = view.selectionModel()->selectedIndexes();
|
|
1416 |
QCOMPARE(selected.count(), 1);
|
|
1417 |
QVERIFY(selected.contains(index1));
|
|
1418 |
|
|
1419 |
// Now press control and draw a rubberband around items 1 and 2.
|
|
1420 |
// The mouse move event has to be created manually because the QTest framework does not
|
|
1421 |
// contain a function for mouse moves with buttons pressed.
|
|
1422 |
QPoint pressPos = view.visualRect(index1).topLeft() - QPoint(1, 1);
|
|
1423 |
QPoint releasePos = view.visualRect(index2).bottomRight() + QPoint(1, 1);
|
|
1424 |
QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::ControlModifier, pressPos);
|
|
1425 |
QMouseEvent moveEvent(QEvent::MouseMove, releasePos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
|
|
1426 |
bool moveEventReceived = qApp->notify(view.viewport(), &moveEvent);
|
|
1427 |
QVERIFY(moveEventReceived);
|
|
1428 |
QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::ControlModifier, releasePos);
|
|
1429 |
|
|
1430 |
// Verify that item 2 is selected now
|
|
1431 |
selected = view.selectionModel()->selectedIndexes();
|
|
1432 |
QCOMPARE(selected.count(), 1);
|
|
1433 |
QVERIFY(selected.contains(index2));
|
|
1434 |
}
|
|
1435 |
|
|
1436 |
QTEST_MAIN(tst_QAbstractItemView)
|
|
1437 |
#include "tst_qabstractitemview.moc"
|