author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
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 <QtGui/QtGui> |
|
46 |
||
47 |
//TESTED_CLASS= |
|
48 |
//TESTED_FILES= |
|
49 |
||
50 |
class tst_QItemSelectionModel : public QObject |
|
51 |
{ |
|
52 |
Q_OBJECT |
|
53 |
||
54 |
public: |
|
55 |
tst_QItemSelectionModel(); |
|
56 |
virtual ~tst_QItemSelectionModel(); |
|
57 |
||
58 |
||
59 |
public slots: |
|
60 |
void initTestCase(); |
|
61 |
void cleanupTestCase(); |
|
62 |
void init(); |
|
63 |
private slots: |
|
64 |
void clear_data(); |
|
65 |
void clear(); |
|
66 |
void clearAndSelect(); |
|
67 |
void toggleSelection(); |
|
68 |
void select_data(); |
|
69 |
void select(); |
|
70 |
void persistentselections_data(); |
|
71 |
void persistentselections(); |
|
72 |
void resetModel(); |
|
73 |
void removeRows_data(); |
|
74 |
void removeRows(); |
|
75 |
void removeColumns_data(); |
|
76 |
void removeColumns(); |
|
77 |
void modelLayoutChanged_data(); |
|
78 |
void modelLayoutChanged(); |
|
79 |
void selectedRows_data(); |
|
80 |
void selectedRows(); |
|
81 |
void selectedColumns_data(); |
|
82 |
void selectedColumns(); |
|
83 |
void setCurrentIndex(); |
|
84 |
void splitOnInsert(); |
|
85 |
void task196285_rowIntersectsSelection(); |
|
86 |
void unselectable(); |
|
87 |
void task220420_selectedIndexes(); |
|
88 |
void task240734_layoutChanged(); |
|
89 |
void merge_data(); |
|
90 |
void merge(); |
|
91 |
void task119433_isRowSelected(); |
|
92 |
void task252069_rowIntersectsSelection(); |
|
93 |
void task232634_childrenDeselectionSignal(); |
|
94 |
void task260134_layoutChangedWithAllSelected(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
95 |
void QTBUG5671_layoutChangedWithAllSelected(); |
0 | 96 |
|
97 |
private: |
|
98 |
QAbstractItemModel *model; |
|
99 |
QItemSelectionModel *selection; |
|
100 |
}; |
|
101 |
||
102 |
QDataStream &operator<<(QDataStream &, const QModelIndex &); |
|
103 |
QDataStream &operator>>(QDataStream &, QModelIndex &); |
|
104 |
QDataStream &operator<<(QDataStream &, const QModelIndexList &); |
|
105 |
QDataStream &operator>>(QDataStream &, QModelIndexList &); |
|
106 |
||
107 |
typedef QList<int> IntList; |
|
108 |
typedef QPair<int, int> IntPair; |
|
109 |
typedef QList<IntPair> PairList; |
|
110 |
||
111 |
||
112 |
Q_DECLARE_METATYPE(PairList) |
|
113 |
Q_DECLARE_METATYPE(QModelIndex) |
|
114 |
Q_DECLARE_METATYPE(QModelIndexList) |
|
115 |
Q_DECLARE_METATYPE(IntList) |
|
116 |
Q_DECLARE_METATYPE(QItemSelection) |
|
117 |
||
118 |
class QStreamHelper: public QAbstractItemModel |
|
119 |
{ |
|
120 |
public: |
|
121 |
QStreamHelper() {} |
|
122 |
static QModelIndex create(int row = -1, int column = -1, void *data = 0) |
|
123 |
{ |
|
124 |
QStreamHelper helper; |
|
125 |
return helper.QAbstractItemModel::createIndex(row, column, data); |
|
126 |
} |
|
127 |
||
128 |
QModelIndex index(int, int, const QModelIndex&) const |
|
129 |
{ return QModelIndex(); } |
|
130 |
QModelIndex parent(const QModelIndex&) const |
|
131 |
{ return QModelIndex(); } |
|
132 |
int rowCount(const QModelIndex & = QModelIndex()) const |
|
133 |
{ return 0; } |
|
134 |
int columnCount(const QModelIndex & = QModelIndex()) const |
|
135 |
{ return 0; } |
|
136 |
QVariant data(const QModelIndex &, int = Qt::DisplayRole) const |
|
137 |
{ return QVariant(); } |
|
138 |
bool hasChildren(const QModelIndex &) const |
|
139 |
{ return false; } |
|
140 |
}; |
|
141 |
||
142 |
QDataStream &operator<<(QDataStream &s, const QModelIndex &input) |
|
143 |
{ |
|
144 |
s << input.row() |
|
145 |
<< input.column() |
|
146 |
<< reinterpret_cast<qlonglong>(input.internalPointer()); |
|
147 |
return s; |
|
148 |
} |
|
149 |
||
150 |
QDataStream &operator>>(QDataStream &s, QModelIndex &output) |
|
151 |
{ |
|
152 |
int r, c; |
|
153 |
qlonglong ptr; |
|
154 |
s >> r; |
|
155 |
s >> c; |
|
156 |
s >> ptr; |
|
157 |
output = QStreamHelper::create(r, c, reinterpret_cast<void *>(ptr)); |
|
158 |
return s; |
|
159 |
} |
|
160 |
||
161 |
QDataStream &operator<<(QDataStream &s, const QModelIndexList &input) |
|
162 |
{ |
|
163 |
s << input.count(); |
|
164 |
for (int i=0; i<input.count(); ++i) |
|
165 |
s << input.at(i); |
|
166 |
return s; |
|
167 |
} |
|
168 |
||
169 |
QDataStream &operator>>(QDataStream &s, QModelIndexList &output) |
|
170 |
{ |
|
171 |
QModelIndex tmpIndex; |
|
172 |
int count; |
|
173 |
s >> count; |
|
174 |
for (int i=0; i<count; ++i) { |
|
175 |
s >> tmpIndex; |
|
176 |
output << tmpIndex; |
|
177 |
} |
|
178 |
return s; |
|
179 |
} |
|
180 |
||
181 |
tst_QItemSelectionModel::tst_QItemSelectionModel() : model(0), selection(0) |
|
182 |
{ |
|
183 |
} |
|
184 |
||
185 |
tst_QItemSelectionModel::~tst_QItemSelectionModel() |
|
186 |
{ |
|
187 |
} |
|
188 |
||
189 |
/* |
|
190 |
This test usually uses a model with a 5x5 table |
|
191 |
------------------------------------------- |
|
192 |
| 0,0 | 0,1 | 0,2 | 0,3 | 0,4 | |
|
193 |
------------------------------------------- |
|
194 |
| 1,0 | 1,1 | 1,2 | 1,3 | 1,4 | |
|
195 |
------------------------------------------- |
|
196 |
| 2,0 | 2,1 | 2,2 | 2,3 | 2,4 | |
|
197 |
------------------------------------------- |
|
198 |
| 3,0 | 3,1 | 3,2 | 3,3 | 3,4 | |
|
199 |
------------------------------------------- |
|
200 |
| 4,0 | 4,1 | 4,2 | 4,3 | 4,4 | |
|
201 |
------------------------------------------- |
|
202 |
||
203 |
...that for each row has a children in a new 5x5 table ad infinitum. |
|
204 |
||
205 |
*/ |
|
206 |
void tst_QItemSelectionModel::initTestCase() |
|
207 |
{ |
|
208 |
qRegisterMetaType<QItemSelection>("QItemSelection"); |
|
209 |
||
210 |
model = new QStandardItemModel(5, 5); |
|
211 |
QModelIndex parent = model->index(0, 0, QModelIndex()); |
|
212 |
model->insertRows(0, 5, parent); |
|
213 |
model->insertColumns(0, 5, parent); |
|
214 |
selection = new QItemSelectionModel(model); |
|
215 |
} |
|
216 |
||
217 |
void tst_QItemSelectionModel::cleanupTestCase() |
|
218 |
{ |
|
219 |
delete selection; |
|
220 |
delete model; |
|
221 |
} |
|
222 |
||
223 |
void tst_QItemSelectionModel::init() |
|
224 |
{ |
|
225 |
selection->clear(); |
|
226 |
while (model->rowCount(QModelIndex()) > 5) |
|
227 |
model->removeRow(0, QModelIndex()); |
|
228 |
while (model->rowCount(QModelIndex()) < 5) |
|
229 |
model->insertRow(0, QModelIndex()); |
|
230 |
} |
|
231 |
||
232 |
void tst_QItemSelectionModel::clear_data() |
|
233 |
{ |
|
234 |
QTest::addColumn<QModelIndexList>("indexList"); |
|
235 |
QTest::addColumn<IntList>("commandList"); |
|
236 |
{ |
|
237 |
QModelIndexList index; |
|
238 |
IntList command; |
|
239 |
index << model->index(0, 0, QModelIndex()); |
|
240 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Rows); |
|
241 |
index << model->index(1, 0, QModelIndex()); |
|
242 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Rows); |
|
243 |
QTest::newRow("(0, 0) and (1, 0): Select|Rows") |
|
244 |
<< index |
|
245 |
<< command; |
|
246 |
} |
|
247 |
{ |
|
248 |
QModelIndexList index; |
|
249 |
IntList command; |
|
250 |
index << model->index(0, 0, QModelIndex()); |
|
251 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Columns); |
|
252 |
index << model->index(0, 1, QModelIndex()); |
|
253 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Columns); |
|
254 |
QTest::newRow("(0, 0) and (1, 0): Select|Columns") |
|
255 |
<< index |
|
256 |
<< command; |
|
257 |
} |
|
258 |
{ |
|
259 |
QModelIndexList index; |
|
260 |
IntList command; |
|
261 |
index << model->index(0, 0, QModelIndex()); |
|
262 |
command << QItemSelectionModel::Select; |
|
263 |
index << model->index(1, 1, QModelIndex()); |
|
264 |
command << QItemSelectionModel::Select; |
|
265 |
index << model->index(2, 2, QModelIndex()); |
|
266 |
command << QItemSelectionModel::SelectCurrent; |
|
267 |
QTest::newRow("(0, 0), (1, 1) and (2, 2): Select, Select, SelectCurrent") |
|
268 |
<< index |
|
269 |
<< command; |
|
270 |
} |
|
271 |
{ |
|
272 |
QModelIndexList index; |
|
273 |
IntList command; |
|
274 |
index << model->index(0, 0, QModelIndex()); |
|
275 |
command << QItemSelectionModel::Select; |
|
276 |
index << model->index(1, 1, QModelIndex()); |
|
277 |
command << QItemSelectionModel::Select; |
|
278 |
index << model->index(1, 1, QModelIndex()); |
|
279 |
command << QItemSelectionModel::Toggle; |
|
280 |
QTest::newRow("(0, 0), (1, 1) and (1, 1): Select, Select, Toggle") |
|
281 |
<< index |
|
282 |
<< command; |
|
283 |
} |
|
284 |
{ |
|
285 |
QModelIndexList index; |
|
286 |
IntList command; |
|
287 |
index << model->index(0, 0, model->index(0, 0, QModelIndex())); |
|
288 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Rows); |
|
289 |
QTest::newRow("child (0, 0) of (0, 0): Select|Rows") |
|
290 |
<< index |
|
291 |
<< command; |
|
292 |
} |
|
293 |
} |
|
294 |
||
295 |
void tst_QItemSelectionModel::clear() |
|
296 |
{ |
|
297 |
QFETCH(QModelIndexList, indexList); |
|
298 |
QFETCH(IntList, commandList); |
|
299 |
||
300 |
// do selections |
|
301 |
for (int i=0; i<indexList.count(); ++i) { |
|
302 |
selection->select(indexList.at(i), (QItemSelectionModel::SelectionFlags)commandList.at(i)); |
|
303 |
} |
|
304 |
// test that we have selected items |
|
305 |
QVERIFY(!selection->selectedIndexes().isEmpty()); |
|
306 |
selection->clear(); |
|
307 |
// test that they were all cleared |
|
308 |
QVERIFY(selection->selectedIndexes().isEmpty()); |
|
309 |
} |
|
310 |
||
311 |
void tst_QItemSelectionModel::clearAndSelect() |
|
312 |
{ |
|
313 |
// populate selectionmodel |
|
314 |
selection->select(model->index(1, 1, QModelIndex()), QItemSelectionModel::Select); |
|
315 |
QCOMPARE(selection->selectedIndexes().count(), 1); |
|
316 |
QVERIFY(selection->hasSelection()); |
|
317 |
||
318 |
// ClearAndSelect with empty selection |
|
319 |
QItemSelection emptySelection; |
|
320 |
selection->select(emptySelection, QItemSelectionModel::ClearAndSelect); |
|
321 |
||
322 |
// verify the selectionmodel is empty |
|
323 |
QVERIFY(selection->selectedIndexes().isEmpty()); |
|
324 |
QVERIFY(selection->hasSelection()==false); |
|
325 |
} |
|
326 |
||
327 |
void tst_QItemSelectionModel::toggleSelection() |
|
328 |
{ |
|
329 |
//test the toggle selection and checks whether selectedIndex |
|
330 |
//and hasSelection returns the correct value |
|
331 |
||
332 |
selection->clearSelection(); |
|
333 |
QCOMPARE(selection->selectedIndexes().count(), 0); |
|
334 |
QVERIFY(selection->hasSelection()==false); |
|
335 |
||
336 |
QModelIndex index=model->index(1, 1, QModelIndex()); |
|
337 |
// populate selectionmodel |
|
338 |
selection->select(index, QItemSelectionModel::Toggle); |
|
339 |
QCOMPARE(selection->selectedIndexes().count(), 1); |
|
340 |
QVERIFY(selection->hasSelection()==true); |
|
341 |
||
342 |
selection->select(index, QItemSelectionModel::Toggle); |
|
343 |
QCOMPARE(selection->selectedIndexes().count(), 0); |
|
344 |
QVERIFY(selection->hasSelection()==false); |
|
345 |
||
346 |
// populate selectionmodel with rows |
|
347 |
selection->select(index, QItemSelectionModel::Toggle | QItemSelectionModel::Rows); |
|
348 |
QCOMPARE(selection->selectedIndexes().count(), model->columnCount()); |
|
349 |
QVERIFY(selection->hasSelection()==true); |
|
350 |
||
351 |
selection->select(index, QItemSelectionModel::Toggle | QItemSelectionModel::Rows); |
|
352 |
QCOMPARE(selection->selectedIndexes().count(), 0); |
|
353 |
QVERIFY(selection->hasSelection()==false); |
|
354 |
||
355 |
} |
|
356 |
||
357 |
||
358 |
void tst_QItemSelectionModel::select_data() |
|
359 |
{ |
|
360 |
QTest::addColumn<QModelIndexList>("indexList"); |
|
361 |
QTest::addColumn<bool>("useRanges"); |
|
362 |
QTest::addColumn<IntList>("commandList"); |
|
363 |
QTest::addColumn<QModelIndexList>("expectedList"); |
|
364 |
||
365 |
{ |
|
366 |
QModelIndexList index; |
|
367 |
QModelIndexList expected; |
|
368 |
IntList command; |
|
369 |
index << model->index(0, 0, QModelIndex()); |
|
370 |
command << QItemSelectionModel::Select; |
|
371 |
expected << model->index(0, 0, QModelIndex()); |
|
372 |
QTest::newRow("(0, 0): Select") |
|
373 |
<< index |
|
374 |
<< false |
|
375 |
<< command |
|
376 |
<< expected; |
|
377 |
} |
|
378 |
{ |
|
379 |
QModelIndexList index; |
|
380 |
QModelIndexList expected; |
|
381 |
IntList command; |
|
382 |
index << model->index(0, 0, model->index(0, 0, QModelIndex())); |
|
383 |
command << QItemSelectionModel::Select; |
|
384 |
expected << model->index(0, 0, model->index(0, 0, QModelIndex())); |
|
385 |
QTest::newRow("child (0, 0) of (0, 0): Select") |
|
386 |
<< index |
|
387 |
<< false |
|
388 |
<< command |
|
389 |
<< expected; |
|
390 |
} |
|
391 |
{ |
|
392 |
QModelIndexList index; |
|
393 |
QModelIndexList expected; |
|
394 |
IntList command; |
|
395 |
index << model->index(0, 0, QModelIndex()); |
|
396 |
command << QItemSelectionModel::Deselect; |
|
397 |
QTest::newRow("(0, 0): Deselect") |
|
398 |
<< index |
|
399 |
<< false |
|
400 |
<< command |
|
401 |
<< expected; |
|
402 |
} |
|
403 |
{ |
|
404 |
QModelIndexList index; |
|
405 |
QModelIndexList expected; |
|
406 |
IntList command; |
|
407 |
index << model->index(0, 0, QModelIndex()); |
|
408 |
command << QItemSelectionModel::Toggle; |
|
409 |
expected << model->index(0, 0, QModelIndex()); |
|
410 |
QTest::newRow("(0, 0): Toggle") |
|
411 |
<< index |
|
412 |
<< false |
|
413 |
<< command |
|
414 |
<< expected; |
|
415 |
} |
|
416 |
{ |
|
417 |
QModelIndexList index; |
|
418 |
QModelIndexList expected; |
|
419 |
IntList command; |
|
420 |
index << model->index(0, 0, QModelIndex()); |
|
421 |
command << QItemSelectionModel::Select; |
|
422 |
index << model->index(0, 0, QModelIndex()); |
|
423 |
command << QItemSelectionModel::Toggle; |
|
424 |
QTest::newRow("(0, 0) and (0, 0): Select and Toggle") |
|
425 |
<< index |
|
426 |
<< false |
|
427 |
<< command |
|
428 |
<< expected; |
|
429 |
} |
|
430 |
{ |
|
431 |
QModelIndexList index; |
|
432 |
QModelIndexList expected; |
|
433 |
IntList command; |
|
434 |
index << model->index(0, 0, QModelIndex()); |
|
435 |
command << QItemSelectionModel::Select; |
|
436 |
index << model->index(0, 0, QModelIndex()); |
|
437 |
command << QItemSelectionModel::Deselect; |
|
438 |
QTest::newRow("(0, 0) and (0, 0): Select and Deselect") |
|
439 |
<< index |
|
440 |
<< false |
|
441 |
<< command |
|
442 |
<< expected; |
|
443 |
} |
|
444 |
{ |
|
445 |
QModelIndexList index; |
|
446 |
QModelIndexList expected; |
|
447 |
IntList command; |
|
448 |
index << model->index(0, 0, QModelIndex()); |
|
449 |
command << QItemSelectionModel::Select; |
|
450 |
index << model->index(0, 0, model->index(0, 0, QModelIndex())); |
|
451 |
command << QItemSelectionModel::ClearAndSelect; |
|
452 |
expected << model->index(0, 0, model->index(0, 0, QModelIndex())); |
|
453 |
QTest::newRow("(0, 0) and child (0, 0) of (0, 0): Select and ClearAndSelect") |
|
454 |
<< index |
|
455 |
<< false |
|
456 |
<< command |
|
457 |
<< expected; |
|
458 |
} |
|
459 |
{ |
|
460 |
QModelIndexList index; |
|
461 |
QModelIndexList expected; |
|
462 |
IntList command; |
|
463 |
index << model->index(0, 0, QModelIndex()); |
|
464 |
index << model->index(4, 0, QModelIndex()); |
|
465 |
command << QItemSelectionModel::Select; |
|
466 |
index << model->index(0, 1, QModelIndex()); |
|
467 |
index << model->index(4, 1, QModelIndex()); |
|
468 |
command << QItemSelectionModel::Select; |
|
469 |
index << model->index(0, 0, QModelIndex()); |
|
470 |
index << model->index(4, 1, QModelIndex()); |
|
471 |
command << QItemSelectionModel::Deselect; |
|
472 |
QTest::newRow("(0, 0 to 4, 0) and (0, 1 to 4, 1) and (0, 0 to 4, 1): Select and Select and Deselect") |
|
473 |
<< index |
|
474 |
<< true |
|
475 |
<< command |
|
476 |
<< expected; |
|
477 |
} |
|
478 |
{ |
|
479 |
QModelIndexList index; |
|
480 |
QModelIndexList expected; |
|
481 |
IntList command; |
|
482 |
index << model->index(0, 0, QModelIndex()); |
|
483 |
command << QItemSelectionModel::Select; |
|
484 |
index << model->index(4, 4, QModelIndex()); |
|
485 |
command << QItemSelectionModel::Select; |
|
486 |
expected << model->index(0, 0, QModelIndex()) << model->index(4, 4, QModelIndex()); |
|
487 |
QTest::newRow("(0, 0) and (4, 4): Select") |
|
488 |
<< index |
|
489 |
<< false |
|
490 |
<< command |
|
491 |
<< expected; |
|
492 |
} |
|
493 |
{ |
|
494 |
QModelIndexList index; |
|
495 |
QModelIndexList expected; |
|
496 |
IntList command; |
|
497 |
index << model->index(0, 0, QModelIndex()); |
|
498 |
command << QItemSelectionModel::Select; |
|
499 |
index << model->index(4, 4, QModelIndex()); |
|
500 |
command << QItemSelectionModel::ClearAndSelect; |
|
501 |
expected << model->index(4, 4, QModelIndex()); |
|
502 |
QTest::newRow("(0, 0) and (4, 4): Select and ClearAndSelect") |
|
503 |
<< index |
|
504 |
<< false |
|
505 |
<< command |
|
506 |
<< expected; |
|
507 |
} |
|
508 |
{ |
|
509 |
QModelIndexList index; |
|
510 |
QModelIndexList expected; |
|
511 |
IntList command; |
|
512 |
index << model->index(0, 0, QModelIndex()); |
|
513 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Rows); |
|
514 |
index << model->index(4, 4, QModelIndex()); |
|
515 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Rows); |
|
516 |
expected << model->index(0, 0, QModelIndex()) |
|
517 |
<< model->index(0, 1, QModelIndex()) |
|
518 |
<< model->index(0, 2, QModelIndex()) |
|
519 |
<< model->index(0, 3, QModelIndex()) |
|
520 |
<< model->index(0, 4, QModelIndex()) |
|
521 |
<< model->index(4, 0, QModelIndex()) |
|
522 |
<< model->index(4, 1, QModelIndex()) |
|
523 |
<< model->index(4, 2, QModelIndex()) |
|
524 |
<< model->index(4, 3, QModelIndex()) |
|
525 |
<< model->index(4, 4, QModelIndex()); |
|
526 |
QTest::newRow("(0, 0) and (4, 4): Select|Rows") |
|
527 |
<< index |
|
528 |
<< false |
|
529 |
<< command |
|
530 |
<< expected; |
|
531 |
} |
|
532 |
{ |
|
533 |
QModelIndexList index; |
|
534 |
QModelIndexList expected; |
|
535 |
IntList command; |
|
536 |
index << model->index(0, 0, model->index(0, 0, QModelIndex())); |
|
537 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Rows); |
|
538 |
index << model->index(4, 4, model->index(0, 0, QModelIndex())); |
|
539 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Rows); |
|
540 |
QModelIndex parent = model->index(0, 0, QModelIndex()); |
|
541 |
expected << model->index(0, 0, parent) |
|
542 |
<< model->index(0, 1, parent) |
|
543 |
<< model->index(0, 2, parent) |
|
544 |
<< model->index(0, 3, parent) |
|
545 |
<< model->index(0, 4, parent) |
|
546 |
<< model->index(4, 0, parent) |
|
547 |
<< model->index(4, 1, parent) |
|
548 |
<< model->index(4, 2, parent) |
|
549 |
<< model->index(4, 3, parent) |
|
550 |
<< model->index(4, 4, parent); |
|
551 |
QTest::newRow("child (0, 0) and (4, 4) of (0, 0): Select|Rows") |
|
552 |
<< index |
|
553 |
<< false |
|
554 |
<< command |
|
555 |
<< expected; |
|
556 |
} |
|
557 |
{ |
|
558 |
QModelIndexList index; |
|
559 |
QModelIndexList expected; |
|
560 |
IntList command; |
|
561 |
index << model->index(0, 0, QModelIndex()); |
|
562 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Columns); |
|
563 |
index << model->index(4, 4, QModelIndex()); |
|
564 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Columns); |
|
565 |
expected << model->index(0, 0, QModelIndex()) |
|
566 |
<< model->index(1, 0, QModelIndex()) |
|
567 |
<< model->index(2, 0, QModelIndex()) |
|
568 |
<< model->index(3, 0, QModelIndex()) |
|
569 |
<< model->index(4, 0, QModelIndex()) |
|
570 |
<< model->index(0, 4, QModelIndex()) |
|
571 |
<< model->index(1, 4, QModelIndex()) |
|
572 |
<< model->index(2, 4, QModelIndex()) |
|
573 |
<< model->index(3, 4, QModelIndex()) |
|
574 |
<< model->index(4, 4, QModelIndex()); |
|
575 |
QTest::newRow("(0, 0) and (4, 4): Select|Columns") |
|
576 |
<< index |
|
577 |
<< false |
|
578 |
<< command |
|
579 |
<< expected; |
|
580 |
} |
|
581 |
{ |
|
582 |
QModelIndexList index; |
|
583 |
QModelIndexList expected; |
|
584 |
IntList command; |
|
585 |
index << model->index(0, 0, model->index(0, 0, QModelIndex())); |
|
586 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Columns); |
|
587 |
index << model->index(4, 4, model->index(0, 0, QModelIndex())); |
|
588 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Columns); |
|
589 |
expected << model->index(0, 0, model->index(0, 0, QModelIndex())) |
|
590 |
<< model->index(1, 0, model->index(0, 0, QModelIndex())) |
|
591 |
<< model->index(2, 0, model->index(0, 0, QModelIndex())) |
|
592 |
<< model->index(3, 0, model->index(0, 0, QModelIndex())) |
|
593 |
<< model->index(4, 0, model->index(0, 0, QModelIndex())) |
|
594 |
<< model->index(0, 4, model->index(0, 0, QModelIndex())) |
|
595 |
<< model->index(1, 4, model->index(0, 0, QModelIndex())) |
|
596 |
<< model->index(2, 4, model->index(0, 0, QModelIndex())) |
|
597 |
<< model->index(3, 4, model->index(0, 0, QModelIndex())) |
|
598 |
<< model->index(4, 4, model->index(0, 0, QModelIndex())); |
|
599 |
QTest::newRow("child (0, 0) and (4, 4) of (0, 0): Select|Columns") |
|
600 |
<< index |
|
601 |
<< false |
|
602 |
<< command |
|
603 |
<< expected; |
|
604 |
} |
|
605 |
{ |
|
606 |
QModelIndexList index; |
|
607 |
QModelIndexList expected; |
|
608 |
IntList command; |
|
609 |
index << model->index(0, 0, QModelIndex()); |
|
610 |
index << model->index(4, 0, QModelIndex()); |
|
611 |
command << QItemSelectionModel::Select; |
|
612 |
expected << model->index(0, 0, QModelIndex()) |
|
613 |
<< model->index(1, 0, QModelIndex()) |
|
614 |
<< model->index(2, 0, QModelIndex()) |
|
615 |
<< model->index(3, 0, QModelIndex()) |
|
616 |
<< model->index(4, 0, QModelIndex()); |
|
617 |
QTest::newRow("(0, 0 to 4, 0): Select") |
|
618 |
<< index |
|
619 |
<< true |
|
620 |
<< command |
|
621 |
<< expected; |
|
622 |
} |
|
623 |
/* ### FAILS |
|
624 |
{ |
|
625 |
QModelIndexList index; |
|
626 |
QModelIndexList expected; |
|
627 |
IntList command; |
|
628 |
index << model->index(0, 0, QModelIndex()); |
|
629 |
index << model->index(0, 0, model->index(0, 0, QModelIndex())); |
|
630 |
command << QItemSelectionModel::Select; |
|
631 |
QTest::newRow("(0, 0 to child 0, 0): Select") |
|
632 |
<< index |
|
633 |
<< true |
|
634 |
<< command |
|
635 |
<< expected; |
|
636 |
} |
|
637 |
*/ |
|
638 |
{ |
|
639 |
QModelIndexList index; |
|
640 |
QModelIndexList expected; |
|
641 |
IntList command; |
|
642 |
index << model->index(0, 0, model->index(0, 0, QModelIndex())); |
|
643 |
index << model->index(0, 0, model->index(1, 0, QModelIndex())); |
|
644 |
command << QItemSelectionModel::Select; |
|
645 |
QTest::newRow("child (0, 0) of (0, 0) to child (0, 0) of (1, 0): Select") |
|
646 |
<< index |
|
647 |
<< true |
|
648 |
<< command |
|
649 |
<< expected; |
|
650 |
} |
|
651 |
{ |
|
652 |
QModelIndexList index; |
|
653 |
QModelIndexList expected; |
|
654 |
IntList command; |
|
655 |
index << model->index(0, 0, QModelIndex()); |
|
656 |
index << model->index(4, 4, QModelIndex()); |
|
657 |
command << QItemSelectionModel::Select; |
|
658 |
expected << model->index(0, 0, QModelIndex()) |
|
659 |
<< model->index(0, 1, QModelIndex()) |
|
660 |
<< model->index(0, 2, QModelIndex()) |
|
661 |
<< model->index(0, 3, QModelIndex()) |
|
662 |
<< model->index(0, 4, QModelIndex()) |
|
663 |
<< model->index(1, 0, QModelIndex()) |
|
664 |
<< model->index(1, 1, QModelIndex()) |
|
665 |
<< model->index(1, 2, QModelIndex()) |
|
666 |
<< model->index(1, 3, QModelIndex()) |
|
667 |
<< model->index(1, 4, QModelIndex()) |
|
668 |
<< model->index(2, 0, QModelIndex()) |
|
669 |
<< model->index(2, 1, QModelIndex()) |
|
670 |
<< model->index(2, 2, QModelIndex()) |
|
671 |
<< model->index(2, 3, QModelIndex()) |
|
672 |
<< model->index(2, 4, QModelIndex()) |
|
673 |
<< model->index(3, 0, QModelIndex()) |
|
674 |
<< model->index(3, 1, QModelIndex()) |
|
675 |
<< model->index(3, 2, QModelIndex()) |
|
676 |
<< model->index(3, 3, QModelIndex()) |
|
677 |
<< model->index(3, 4, QModelIndex()) |
|
678 |
<< model->index(4, 0, QModelIndex()) |
|
679 |
<< model->index(4, 1, QModelIndex()) |
|
680 |
<< model->index(4, 2, QModelIndex()) |
|
681 |
<< model->index(4, 3, QModelIndex()) |
|
682 |
<< model->index(4, 4, QModelIndex()); |
|
683 |
QTest::newRow("(0, 0 to 4, 4): Select") |
|
684 |
<< index |
|
685 |
<< true |
|
686 |
<< command |
|
687 |
<< expected; |
|
688 |
} |
|
689 |
{ |
|
690 |
QModelIndexList index; |
|
691 |
QModelIndexList expected; |
|
692 |
IntList command; |
|
693 |
index << model->index(0, 0, QModelIndex()); |
|
694 |
index << model->index(4, 0, QModelIndex()); |
|
695 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Rows); |
|
696 |
expected << model->index(0, 0, QModelIndex()) |
|
697 |
<< model->index(0, 1, QModelIndex()) |
|
698 |
<< model->index(0, 2, QModelIndex()) |
|
699 |
<< model->index(0, 3, QModelIndex()) |
|
700 |
<< model->index(0, 4, QModelIndex()) |
|
701 |
<< model->index(1, 0, QModelIndex()) |
|
702 |
<< model->index(1, 1, QModelIndex()) |
|
703 |
<< model->index(1, 2, QModelIndex()) |
|
704 |
<< model->index(1, 3, QModelIndex()) |
|
705 |
<< model->index(1, 4, QModelIndex()) |
|
706 |
<< model->index(2, 0, QModelIndex()) |
|
707 |
<< model->index(2, 1, QModelIndex()) |
|
708 |
<< model->index(2, 2, QModelIndex()) |
|
709 |
<< model->index(2, 3, QModelIndex()) |
|
710 |
<< model->index(2, 4, QModelIndex()) |
|
711 |
<< model->index(3, 0, QModelIndex()) |
|
712 |
<< model->index(3, 1, QModelIndex()) |
|
713 |
<< model->index(3, 2, QModelIndex()) |
|
714 |
<< model->index(3, 3, QModelIndex()) |
|
715 |
<< model->index(3, 4, QModelIndex()) |
|
716 |
<< model->index(4, 0, QModelIndex()) |
|
717 |
<< model->index(4, 1, QModelIndex()) |
|
718 |
<< model->index(4, 2, QModelIndex()) |
|
719 |
<< model->index(4, 3, QModelIndex()) |
|
720 |
<< model->index(4, 4, QModelIndex()); |
|
721 |
QTest::newRow("(0, 0 to 4, 0): Select|Rows") |
|
722 |
<< index |
|
723 |
<< true |
|
724 |
<< command |
|
725 |
<< expected; |
|
726 |
} |
|
727 |
{ |
|
728 |
QModelIndexList index; |
|
729 |
QModelIndexList expected; |
|
730 |
IntList command; |
|
731 |
index << model->index(0, 0, QModelIndex()); |
|
732 |
index << model->index(0, 4, QModelIndex()); |
|
733 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Columns); |
|
734 |
expected << model->index(0, 0, QModelIndex()) |
|
735 |
<< model->index(0, 1, QModelIndex()) |
|
736 |
<< model->index(0, 2, QModelIndex()) |
|
737 |
<< model->index(0, 3, QModelIndex()) |
|
738 |
<< model->index(0, 4, QModelIndex()) |
|
739 |
<< model->index(1, 0, QModelIndex()) |
|
740 |
<< model->index(1, 1, QModelIndex()) |
|
741 |
<< model->index(1, 2, QModelIndex()) |
|
742 |
<< model->index(1, 3, QModelIndex()) |
|
743 |
<< model->index(1, 4, QModelIndex()) |
|
744 |
<< model->index(2, 0, QModelIndex()) |
|
745 |
<< model->index(2, 1, QModelIndex()) |
|
746 |
<< model->index(2, 2, QModelIndex()) |
|
747 |
<< model->index(2, 3, QModelIndex()) |
|
748 |
<< model->index(2, 4, QModelIndex()) |
|
749 |
<< model->index(3, 0, QModelIndex()) |
|
750 |
<< model->index(3, 1, QModelIndex()) |
|
751 |
<< model->index(3, 2, QModelIndex()) |
|
752 |
<< model->index(3, 3, QModelIndex()) |
|
753 |
<< model->index(3, 4, QModelIndex()) |
|
754 |
<< model->index(4, 0, QModelIndex()) |
|
755 |
<< model->index(4, 1, QModelIndex()) |
|
756 |
<< model->index(4, 2, QModelIndex()) |
|
757 |
<< model->index(4, 3, QModelIndex()) |
|
758 |
<< model->index(4, 4, QModelIndex()); |
|
759 |
QTest::newRow("(0, 0 to 0, 4): Select|Columns") |
|
760 |
<< index |
|
761 |
<< true |
|
762 |
<< command |
|
763 |
<< expected; |
|
764 |
} |
|
765 |
{ |
|
766 |
QModelIndexList index; |
|
767 |
QModelIndexList expected; |
|
768 |
IntList command; |
|
769 |
index << model->index(0, 0, QModelIndex()); |
|
770 |
index << model->index(4, 4, QModelIndex()); |
|
771 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Rows); |
|
772 |
expected << model->index(0, 0, QModelIndex()) |
|
773 |
<< model->index(0, 1, QModelIndex()) |
|
774 |
<< model->index(0, 2, QModelIndex()) |
|
775 |
<< model->index(0, 3, QModelIndex()) |
|
776 |
<< model->index(0, 4, QModelIndex()) |
|
777 |
<< model->index(1, 0, QModelIndex()) |
|
778 |
<< model->index(1, 1, QModelIndex()) |
|
779 |
<< model->index(1, 2, QModelIndex()) |
|
780 |
<< model->index(1, 3, QModelIndex()) |
|
781 |
<< model->index(1, 4, QModelIndex()) |
|
782 |
<< model->index(2, 0, QModelIndex()) |
|
783 |
<< model->index(2, 1, QModelIndex()) |
|
784 |
<< model->index(2, 2, QModelIndex()) |
|
785 |
<< model->index(2, 3, QModelIndex()) |
|
786 |
<< model->index(2, 4, QModelIndex()) |
|
787 |
<< model->index(3, 0, QModelIndex()) |
|
788 |
<< model->index(3, 1, QModelIndex()) |
|
789 |
<< model->index(3, 2, QModelIndex()) |
|
790 |
<< model->index(3, 3, QModelIndex()) |
|
791 |
<< model->index(3, 4, QModelIndex()) |
|
792 |
<< model->index(4, 0, QModelIndex()) |
|
793 |
<< model->index(4, 1, QModelIndex()) |
|
794 |
<< model->index(4, 2, QModelIndex()) |
|
795 |
<< model->index(4, 3, QModelIndex()) |
|
796 |
<< model->index(4, 4, QModelIndex()); |
|
797 |
QTest::newRow("(0, 0 to 4, 4): Select|Rows") |
|
798 |
<< index |
|
799 |
<< true |
|
800 |
<< command |
|
801 |
<< expected; |
|
802 |
} |
|
803 |
{ |
|
804 |
QModelIndexList index; |
|
805 |
QModelIndexList expected; |
|
806 |
IntList command; |
|
807 |
index << model->index(0, 0, QModelIndex()); |
|
808 |
index << model->index(4, 4, QModelIndex()); |
|
809 |
command << (QItemSelectionModel::Select | QItemSelectionModel::Columns); |
|
810 |
expected << model->index(0, 0, QModelIndex()) |
|
811 |
<< model->index(0, 1, QModelIndex()) |
|
812 |
<< model->index(0, 2, QModelIndex()) |
|
813 |
<< model->index(0, 3, QModelIndex()) |
|
814 |
<< model->index(0, 4, QModelIndex()) |
|
815 |
<< model->index(1, 0, QModelIndex()) |
|
816 |
<< model->index(1, 1, QModelIndex()) |
|
817 |
<< model->index(1, 2, QModelIndex()) |
|
818 |
<< model->index(1, 3, QModelIndex()) |
|
819 |
<< model->index(1, 4, QModelIndex()) |
|
820 |
<< model->index(2, 0, QModelIndex()) |
|
821 |
<< model->index(2, 1, QModelIndex()) |
|
822 |
<< model->index(2, 2, QModelIndex()) |
|
823 |
<< model->index(2, 3, QModelIndex()) |
|
824 |
<< model->index(2, 4, QModelIndex()) |
|
825 |
<< model->index(3, 0, QModelIndex()) |
|
826 |
<< model->index(3, 1, QModelIndex()) |
|
827 |
<< model->index(3, 2, QModelIndex()) |
|
828 |
<< model->index(3, 3, QModelIndex()) |
|
829 |
<< model->index(3, 4, QModelIndex()) |
|
830 |
<< model->index(4, 0, QModelIndex()) |
|
831 |
<< model->index(4, 1, QModelIndex()) |
|
832 |
<< model->index(4, 2, QModelIndex()) |
|
833 |
<< model->index(4, 3, QModelIndex()) |
|
834 |
<< model->index(4, 4, QModelIndex()); |
|
835 |
QTest::newRow("(0, 0 to 4, 4): Select|Columns") |
|
836 |
<< index |
|
837 |
<< true |
|
838 |
<< command |
|
839 |
<< expected; |
|
840 |
} |
|
841 |
{ |
|
842 |
QModelIndexList index; |
|
843 |
QModelIndexList expected; |
|
844 |
IntList command; |
|
845 |
index << model->index(0, 2, QModelIndex()); |
|
846 |
index << model->index(4, 2, QModelIndex()); |
|
847 |
command << QItemSelectionModel::Select; |
|
848 |
index << model->index(2, 0, QModelIndex()); |
|
849 |
index << model->index(2, 4, QModelIndex()); |
|
850 |
command << QItemSelectionModel::Select; |
|
851 |
expected << model->index(0, 2, QModelIndex()) |
|
852 |
<< model->index(1, 2, QModelIndex()) |
|
853 |
<< model->index(2, 2, QModelIndex()) |
|
854 |
<< model->index(3, 2, QModelIndex()) |
|
855 |
<< model->index(4, 2, QModelIndex()) |
|
856 |
<< model->index(2, 0, QModelIndex()) |
|
857 |
<< model->index(2, 1, QModelIndex()) |
|
858 |
<< model->index(2, 3, QModelIndex()) |
|
859 |
<< model->index(2, 4, QModelIndex()); |
|
860 |
QTest::newRow("(0, 2 to 4, 2) and (2, 0 to 2, 4): Select") |
|
861 |
<< index |
|
862 |
<< true |
|
863 |
<< command |
|
864 |
<< expected; |
|
865 |
} |
|
866 |
{ |
|
867 |
QModelIndexList index; |
|
868 |
QModelIndexList expected; |
|
869 |
IntList command; |
|
870 |
index << model->index(0, 2, QModelIndex()); |
|
871 |
index << model->index(4, 2, QModelIndex()); |
|
872 |
command << QItemSelectionModel::Select; |
|
873 |
index << model->index(2, 0, QModelIndex()); |
|
874 |
index << model->index(2, 4, QModelIndex()); |
|
875 |
command << QItemSelectionModel::SelectCurrent; |
|
876 |
expected << model->index(2, 0, QModelIndex()) |
|
877 |
<< model->index(2, 1, QModelIndex()) |
|
878 |
<< model->index(2, 2, QModelIndex()) |
|
879 |
<< model->index(2, 3, QModelIndex()) |
|
880 |
<< model->index(2, 4, QModelIndex()); |
|
881 |
QTest::newRow("(0, 2 to 4, 2) and (2, 0 to 2, 4): Select and SelectCurrent") |
|
882 |
<< index |
|
883 |
<< true |
|
884 |
<< command |
|
885 |
<< expected; |
|
886 |
} |
|
887 |
{ |
|
888 |
QModelIndexList index; |
|
889 |
QModelIndexList expected; |
|
890 |
IntList command; |
|
891 |
index << model->index(0, 2, QModelIndex()); |
|
892 |
index << model->index(4, 2, QModelIndex()); |
|
893 |
command << QItemSelectionModel::Select; |
|
894 |
index << model->index(2, 0, QModelIndex()); |
|
895 |
index << model->index(2, 4, QModelIndex()); |
|
896 |
command << QItemSelectionModel::Toggle; |
|
897 |
expected << model->index(0, 2, QModelIndex()) |
|
898 |
<< model->index(1, 2, QModelIndex()) |
|
899 |
<< model->index(3, 2, QModelIndex()) |
|
900 |
<< model->index(4, 2, QModelIndex()) |
|
901 |
<< model->index(2, 0, QModelIndex()) |
|
902 |
<< model->index(2, 1, QModelIndex()) |
|
903 |
<< model->index(2, 3, QModelIndex()) |
|
904 |
<< model->index(2, 4, QModelIndex()); |
|
905 |
QTest::newRow("(0, 2 to 4, 2) and (2, 0 to 2, 4): Select and Toggle") |
|
906 |
<< index |
|
907 |
<< true |
|
908 |
<< command |
|
909 |
<< expected; |
|
910 |
} |
|
911 |
{ |
|
912 |
QModelIndexList index; |
|
913 |
QModelIndexList expected; |
|
914 |
IntList command; |
|
915 |
index << model->index(0, 2, QModelIndex()); |
|
916 |
index << model->index(4, 2, QModelIndex()); |
|
917 |
command << QItemSelectionModel::Select; |
|
918 |
index << model->index(2, 0, QModelIndex()); |
|
919 |
index << model->index(2, 4, QModelIndex()); |
|
920 |
command << QItemSelectionModel::Deselect; |
|
921 |
expected << model->index(0, 2, QModelIndex()) |
|
922 |
<< model->index(1, 2, QModelIndex()) |
|
923 |
<< model->index(3, 2, QModelIndex()) |
|
924 |
<< model->index(4, 2, QModelIndex()); |
|
925 |
QTest::newRow("(0, 2 to 4, 2) and (2, 0 to 2, 4): Select and Deselect") |
|
926 |
<< index |
|
927 |
<< true |
|
928 |
<< command |
|
929 |
<< expected; |
|
930 |
} |
|
931 |
||
932 |
{ |
|
933 |
QModelIndexList index; |
|
934 |
QModelIndexList expected; |
|
935 |
IntList command; |
|
936 |
index << model->index(0, 0, QModelIndex()); |
|
937 |
index << model->index(2, 2, QModelIndex()); |
|
938 |
command << QItemSelectionModel::Select; |
|
939 |
||
940 |
index << model->index(0, 0, QModelIndex()); |
|
941 |
index << model->index(0, 0, QModelIndex()); |
|
942 |
command << QItemSelectionModel::Toggle; |
|
943 |
||
944 |
expected << model->index(0, 1, QModelIndex()) |
|
945 |
<< model->index(0, 2, QModelIndex()) |
|
946 |
<< model->index(1, 0, QModelIndex()) |
|
947 |
<< model->index(1, 1, QModelIndex()) |
|
948 |
<< model->index(1, 2, QModelIndex()) |
|
949 |
<< model->index(2, 0, QModelIndex()) |
|
950 |
<< model->index(2, 1, QModelIndex()) |
|
951 |
<< model->index(2, 2, QModelIndex()); |
|
952 |
||
953 |
QTest::newRow("(0, 0 to 2, 2) and (0, 0 to 0, 0): Select and Toggle at selection boundary") |
|
954 |
<< index |
|
955 |
<< true |
|
956 |
<< command |
|
957 |
<< expected; |
|
958 |
} |
|
959 |
||
960 |
{ |
|
961 |
QModelIndexList index; |
|
962 |
QModelIndexList expected; |
|
963 |
IntList command; |
|
964 |
index << model->index(0, 0, QModelIndex()); |
|
965 |
index << model->index(2, 2, QModelIndex()); |
|
966 |
command << QItemSelectionModel::Select; |
|
967 |
||
968 |
index << model->index(0, 1, QModelIndex()); |
|
969 |
index << model->index(0, 1, QModelIndex()); |
|
970 |
command << QItemSelectionModel::Toggle; |
|
971 |
||
972 |
expected << model->index(0, 0, QModelIndex()) |
|
973 |
<< model->index(0, 2, QModelIndex()) |
|
974 |
<< model->index(1, 0, QModelIndex()) |
|
975 |
<< model->index(1, 1, QModelIndex()) |
|
976 |
<< model->index(1, 2, QModelIndex()) |
|
977 |
<< model->index(2, 0, QModelIndex()) |
|
978 |
<< model->index(2, 1, QModelIndex()) |
|
979 |
<< model->index(2, 2, QModelIndex()); |
|
980 |
||
981 |
QTest::newRow("(0, 0 to 2, 2) and (0, 1 to 0, 1): Select and Toggle at selection boundary") |
|
982 |
<< index |
|
983 |
<< true |
|
984 |
<< command |
|
985 |
<< expected; |
|
986 |
} |
|
987 |
||
988 |
{ |
|
989 |
QModelIndexList index; |
|
990 |
QModelIndexList expected; |
|
991 |
IntList command; |
|
992 |
index << model->index(0, 0, QModelIndex()); |
|
993 |
index << model->index(2, 2, QModelIndex()); |
|
994 |
command << QItemSelectionModel::Select; |
|
995 |
||
996 |
index << model->index(0, 2, QModelIndex()); |
|
997 |
index << model->index(0, 2, QModelIndex()); |
|
998 |
command << QItemSelectionModel::Toggle; |
|
999 |
||
1000 |
expected << model->index(0, 0, QModelIndex()) |
|
1001 |
<< model->index(0, 1, QModelIndex()) |
|
1002 |
<< model->index(1, 0, QModelIndex()) |
|
1003 |
<< model->index(1, 1, QModelIndex()) |
|
1004 |
<< model->index(1, 2, QModelIndex()) |
|
1005 |
<< model->index(2, 0, QModelIndex()) |
|
1006 |
<< model->index(2, 1, QModelIndex()) |
|
1007 |
<< model->index(2, 2, QModelIndex()); |
|
1008 |
||
1009 |
QTest::newRow("(0, 0 to 2, 2) and (0, 2 to 0, 2): Select and Toggle at selection boundary") |
|
1010 |
<< index |
|
1011 |
<< true |
|
1012 |
<< command |
|
1013 |
<< expected; |
|
1014 |
} |
|
1015 |
||
1016 |
{ |
|
1017 |
QModelIndexList index; |
|
1018 |
QModelIndexList expected; |
|
1019 |
IntList command; |
|
1020 |
index << model->index(0, 0, QModelIndex()); |
|
1021 |
index << model->index(2, 2, QModelIndex()); |
|
1022 |
command << QItemSelectionModel::Select; |
|
1023 |
||
1024 |
index << model->index(1, 0, QModelIndex()); |
|
1025 |
index << model->index(1, 0, QModelIndex()); |
|
1026 |
command << QItemSelectionModel::Toggle; |
|
1027 |
||
1028 |
expected << model->index(0, 0, QModelIndex()) |
|
1029 |
<< model->index(0, 1, QModelIndex()) |
|
1030 |
<< model->index(0, 2, QModelIndex()) |
|
1031 |
<< model->index(1, 1, QModelIndex()) |
|
1032 |
<< model->index(1, 2, QModelIndex()) |
|
1033 |
<< model->index(2, 0, QModelIndex()) |
|
1034 |
<< model->index(2, 1, QModelIndex()) |
|
1035 |
<< model->index(2, 2, QModelIndex()); |
|
1036 |
||
1037 |
QTest::newRow("(0, 0 to 2, 2) and (1, 0 to 1, 0): Select and Toggle at selection boundary") |
|
1038 |
<< index |
|
1039 |
<< true |
|
1040 |
<< command |
|
1041 |
<< expected; |
|
1042 |
} |
|
1043 |
||
1044 |
{ |
|
1045 |
QModelIndexList index; |
|
1046 |
QModelIndexList expected; |
|
1047 |
IntList command; |
|
1048 |
index << model->index(0, 0, QModelIndex()); |
|
1049 |
index << model->index(2, 2, QModelIndex()); |
|
1050 |
command << QItemSelectionModel::Select; |
|
1051 |
||
1052 |
index << model->index(1, 1, QModelIndex()); |
|
1053 |
index << model->index(1, 1, QModelIndex()); |
|
1054 |
command << QItemSelectionModel::Toggle; |
|
1055 |
||
1056 |
expected << model->index(0, 0, QModelIndex()) |
|
1057 |
<< model->index(0, 1, QModelIndex()) |
|
1058 |
<< model->index(0, 2, QModelIndex()) |
|
1059 |
<< model->index(1, 0, QModelIndex()) |
|
1060 |
<< model->index(1, 2, QModelIndex()) |
|
1061 |
<< model->index(2, 0, QModelIndex()) |
|
1062 |
<< model->index(2, 1, QModelIndex()) |
|
1063 |
<< model->index(2, 2, QModelIndex()); |
|
1064 |
||
1065 |
QTest::newRow("(0, 0 to 2, 2) and (1, 1 to 1, 1): Select and Toggle at selection boundary") |
|
1066 |
<< index |
|
1067 |
<< true |
|
1068 |
<< command |
|
1069 |
<< expected; |
|
1070 |
} |
|
1071 |
{ |
|
1072 |
QModelIndexList index; |
|
1073 |
QModelIndexList expected; |
|
1074 |
IntList command; |
|
1075 |
index << model->index(0, 0, QModelIndex()); |
|
1076 |
index << model->index(2, 2, QModelIndex()); |
|
1077 |
command << QItemSelectionModel::Select; |
|
1078 |
||
1079 |
index << model->index(1, 2, QModelIndex()); |
|
1080 |
index << model->index(1, 2, QModelIndex()); |
|
1081 |
command << QItemSelectionModel::Toggle; |
|
1082 |
||
1083 |
expected << model->index(0, 0, QModelIndex()) |
|
1084 |
<< model->index(0, 1, QModelIndex()) |
|
1085 |
<< model->index(0, 2, QModelIndex()) |
|
1086 |
<< model->index(1, 0, QModelIndex()) |
|
1087 |
<< model->index(1, 1, QModelIndex()) |
|
1088 |
<< model->index(2, 0, QModelIndex()) |
|
1089 |
<< model->index(2, 1, QModelIndex()) |
|
1090 |
<< model->index(2, 2, QModelIndex()); |
|
1091 |
||
1092 |
QTest::newRow("(0, 0 to 2, 2) and (1, 2 to 1, 2): Select and Toggle at selection boundary") |
|
1093 |
<< index |
|
1094 |
<< true |
|
1095 |
<< command |
|
1096 |
<< expected; |
|
1097 |
} |
|
1098 |
{ |
|
1099 |
QModelIndexList index; |
|
1100 |
QModelIndexList expected; |
|
1101 |
IntList command; |
|
1102 |
index << model->index(0, 0, QModelIndex()); |
|
1103 |
index << model->index(2, 2, QModelIndex()); |
|
1104 |
command << QItemSelectionModel::Select; |
|
1105 |
||
1106 |
index << model->index(2, 0, QModelIndex()); |
|
1107 |
index << model->index(2, 0, QModelIndex()); |
|
1108 |
command << QItemSelectionModel::Toggle; |
|
1109 |
||
1110 |
expected << model->index(0, 0, QModelIndex()) |
|
1111 |
<< model->index(0, 1, QModelIndex()) |
|
1112 |
<< model->index(0, 2, QModelIndex()) |
|
1113 |
<< model->index(1, 0, QModelIndex()) |
|
1114 |
<< model->index(1, 1, QModelIndex()) |
|
1115 |
<< model->index(1, 2, QModelIndex()) |
|
1116 |
<< model->index(2, 1, QModelIndex()) |
|
1117 |
<< model->index(2, 2, QModelIndex()); |
|
1118 |
||
1119 |
QTest::newRow("(0, 0 to 2, 2) and (2, 0 to 2, 0): Select and Toggle at selection boundary") |
|
1120 |
<< index |
|
1121 |
<< true |
|
1122 |
<< command |
|
1123 |
<< expected; |
|
1124 |
} |
|
1125 |
{ |
|
1126 |
QModelIndexList index; |
|
1127 |
QModelIndexList expected; |
|
1128 |
IntList command; |
|
1129 |
index << model->index(0, 0, QModelIndex()); |
|
1130 |
index << model->index(2, 2, QModelIndex()); |
|
1131 |
command << QItemSelectionModel::Select; |
|
1132 |
||
1133 |
index << model->index(2, 1, QModelIndex()); |
|
1134 |
index << model->index(2, 1, QModelIndex()); |
|
1135 |
command << QItemSelectionModel::Toggle; |
|
1136 |
||
1137 |
expected << model->index(0, 0, QModelIndex()) |
|
1138 |
<< model->index(0, 1, QModelIndex()) |
|
1139 |
<< model->index(0, 2, QModelIndex()) |
|
1140 |
<< model->index(1, 0, QModelIndex()) |
|
1141 |
<< model->index(1, 1, QModelIndex()) |
|
1142 |
<< model->index(1, 2, QModelIndex()) |
|
1143 |
<< model->index(2, 0, QModelIndex()) |
|
1144 |
<< model->index(2, 2, QModelIndex()); |
|
1145 |
||
1146 |
QTest::newRow("(0, 0 to 2, 2) and (2, 1 to 2, 1): Select and Toggle at selection boundary") |
|
1147 |
<< index |
|
1148 |
<< true |
|
1149 |
<< command |
|
1150 |
<< expected; |
|
1151 |
} |
|
1152 |
{ |
|
1153 |
QModelIndexList index; |
|
1154 |
QModelIndexList expected; |
|
1155 |
IntList command; |
|
1156 |
||
1157 |
index << model->index(0, 0, QModelIndex()); |
|
1158 |
index << model->index(2, 2, QModelIndex()); |
|
1159 |
command << QItemSelectionModel::Select; |
|
1160 |
||
1161 |
index << model->index(2, 2, QModelIndex()); |
|
1162 |
index << model->index(2, 2, QModelIndex()); |
|
1163 |
command << QItemSelectionModel::Toggle; |
|
1164 |
||
1165 |
expected << model->index(0, 0, QModelIndex()) |
|
1166 |
<< model->index(0, 1, QModelIndex()) |
|
1167 |
<< model->index(0, 2, QModelIndex()) |
|
1168 |
<< model->index(1, 0, QModelIndex()) |
|
1169 |
<< model->index(1, 1, QModelIndex()) |
|
1170 |
<< model->index(1, 2, QModelIndex()) |
|
1171 |
<< model->index(2, 0, QModelIndex()) |
|
1172 |
<< model->index(2, 1, QModelIndex()); |
|
1173 |
||
1174 |
QTest::newRow("(0, 0 to 2, 2) and (2, 2 to 2, 2): Select and Toggle at selection boundary") |
|
1175 |
<< index |
|
1176 |
<< true |
|
1177 |
<< command |
|
1178 |
<< expected; |
|
1179 |
} |
|
1180 |
{ |
|
1181 |
QModelIndexList indexes; |
|
1182 |
IntList commands; |
|
1183 |
QModelIndexList expected; |
|
1184 |
||
1185 |
indexes << model->index(0, 0, QModelIndex()) << model->index(0, 0, QModelIndex()) // press 0 |
|
1186 |
<< model->index(0, 0, QModelIndex()) << model->index(0, 0, QModelIndex()) // release 0 |
|
1187 |
<< model->index(1, 0, QModelIndex()) << model->index(1, 0, QModelIndex()) // press 1 |
|
1188 |
<< model->index(1, 0, QModelIndex()) << model->index(1, 0, QModelIndex()) // release 1 |
|
1189 |
<< model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex()) // press 2 |
|
1190 |
<< model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex()) // release 2 |
|
1191 |
<< model->index(3, 0, QModelIndex()) << model->index(3, 0, QModelIndex()) // press 3 |
|
1192 |
<< model->index(3, 0, QModelIndex()) << model->index(3, 0, QModelIndex()) // release 3 |
|
1193 |
<< model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex()) // press 2 again |
|
1194 |
<< model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex());// move 2 |
|
1195 |
||
1196 |
commands << (QItemSelectionModel::NoUpdate) // press 0 |
|
1197 |
<< (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 0 |
|
1198 |
<< (QItemSelectionModel::NoUpdate) // press 1 |
|
1199 |
<< (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 1 |
|
1200 |
<< (QItemSelectionModel::NoUpdate) // press 2 |
|
1201 |
<< (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 2 |
|
1202 |
<< (QItemSelectionModel::NoUpdate) // press 3 |
|
1203 |
<< (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 3 |
|
1204 |
<< (QItemSelectionModel::NoUpdate) // press 2 again |
|
1205 |
<< (QItemSelectionModel::Toggle/*Current*/|QItemSelectionModel::Rows);// move 2 |
|
1206 |
||
1207 |
expected << model->index(0, 0, QModelIndex()) |
|
1208 |
<< model->index(0, 1, QModelIndex()) |
|
1209 |
<< model->index(0, 2, QModelIndex()) |
|
1210 |
<< model->index(0, 3, QModelIndex()) |
|
1211 |
<< model->index(0, 4, QModelIndex()) |
|
1212 |
||
1213 |
<< model->index(1, 0, QModelIndex()) |
|
1214 |
<< model->index(1, 1, QModelIndex()) |
|
1215 |
<< model->index(1, 2, QModelIndex()) |
|
1216 |
<< model->index(1, 3, QModelIndex()) |
|
1217 |
<< model->index(1, 4, QModelIndex()) |
|
1218 |
/* |
|
1219 |
<< model->index(2, 0, QModelIndex()) |
|
1220 |
<< model->index(2, 1, QModelIndex()) |
|
1221 |
<< model->index(2, 2, QModelIndex()) |
|
1222 |
<< model->index(2, 3, QModelIndex()) |
|
1223 |
<< model->index(2, 4, QModelIndex()) |
|
1224 |
*/ |
|
1225 |
<< model->index(3, 0, QModelIndex()) |
|
1226 |
<< model->index(3, 1, QModelIndex()) |
|
1227 |
<< model->index(3, 2, QModelIndex()) |
|
1228 |
<< model->index(3, 3, QModelIndex()) |
|
1229 |
<< model->index(3, 4, QModelIndex()); |
|
1230 |
||
1231 |
QTest::newRow("simulated treeview multiselection behavior") |
|
1232 |
<< indexes |
|
1233 |
<< true |
|
1234 |
<< commands |
|
1235 |
<< expected; |
|
1236 |
} |
|
1237 |
} |
|
1238 |
||
1239 |
void tst_QItemSelectionModel::select() |
|
1240 |
{ |
|
1241 |
QFETCH(QModelIndexList, indexList); |
|
1242 |
QFETCH(bool, useRanges); |
|
1243 |
QFETCH(IntList, commandList); |
|
1244 |
QFETCH(QModelIndexList, expectedList); |
|
1245 |
||
1246 |
int lastCommand = 0; |
|
1247 |
// do selections |
|
1248 |
for (int i = 0; i<commandList.count(); ++i) { |
|
1249 |
if (useRanges) { |
|
1250 |
selection->select(QItemSelection(indexList.at(2*i), indexList.at(2*i+1)), |
|
1251 |
(QItemSelectionModel::SelectionFlags)commandList.at(i)); |
|
1252 |
} else { |
|
1253 |
selection->select(indexList.at(i), |
|
1254 |
(QItemSelectionModel::SelectionFlags)commandList.at(i)); |
|
1255 |
} |
|
1256 |
lastCommand = commandList.at(i); |
|
1257 |
} |
|
1258 |
||
1259 |
||
1260 |
QModelIndexList selectedList = selection->selectedIndexes(); |
|
1261 |
||
1262 |
QVERIFY(selection->hasSelection()!=selectedList.isEmpty()); |
|
1263 |
||
1264 |
// debug output |
|
1265 |
// for (int i=0; i<selectedList.count(); ++i) |
|
1266 |
// qDebug(QString("selected (%1, %2)") |
|
1267 |
// .arg(selectedList.at(i).row()) |
|
1268 |
// .arg(selectedList.at(i).column())); |
|
1269 |
||
1270 |
// test that the number of indices are as expected |
|
1271 |
QVERIFY2(selectedList.count() == expectedList.count(), |
|
1272 |
QString("expected indices: %1 actual indices: %2") |
|
1273 |
.arg(expectedList.count()) |
|
1274 |
.arg(selectedList.count()).toLatin1()); |
|
1275 |
||
1276 |
// test existence of each index |
|
1277 |
for (int i=0; i<expectedList.count(); ++i) { |
|
1278 |
QVERIFY2(selectedList.contains(expectedList.at(i)), |
|
1279 |
QString("expected index(%1, %2) not found in selectedIndexes()") |
|
1280 |
.arg(expectedList.at(i).row()) |
|
1281 |
.arg(expectedList.at(i).column()).toLatin1()); |
|
1282 |
} |
|
1283 |
||
1284 |
// test that isSelected agrees |
|
1285 |
for (int i=0; i<indexList.count(); ++i) { |
|
1286 |
QModelIndex idx = indexList.at(i); |
|
1287 |
QVERIFY2(selection->isSelected(idx) == selectedList.contains(idx), |
|
1288 |
QString("isSelected(index: %1, %2) does not match selectedIndexes()") |
|
1289 |
.arg(idx.row()) |
|
1290 |
.arg(idx.column()).toLatin1()); |
|
1291 |
} |
|
1292 |
||
1293 |
//for now we assume Rows/Columns flag is the same for all commands, therefore we just check lastCommand |
|
1294 |
// test that isRowSelected agrees |
|
1295 |
if (lastCommand & QItemSelectionModel::Rows) { |
|
1296 |
for (int i=0; i<selectedList.count(); ++i) |
|
1297 |
QVERIFY2(selection->isRowSelected(selectedList.at(i).row(), |
|
1298 |
model->parent(selectedList.at(i))), |
|
1299 |
QString("isRowSelected(row: %1) does not match selectedIndexes()") |
|
1300 |
.arg(selectedList.at(i).row()).toLatin1()); |
|
1301 |
} |
|
1302 |
||
1303 |
// test that isColumnSelected agrees |
|
1304 |
if (lastCommand & QItemSelectionModel::Columns) { |
|
1305 |
for (int i=0; i<selectedList.count(); ++i) |
|
1306 |
QVERIFY2(selection->isColumnSelected(selectedList.at(i).column(), |
|
1307 |
model->parent(selectedList.at(i))), |
|
1308 |
QString("isColumnSelected(column: %1) does not match selectedIndexes()") |
|
1309 |
.arg(selectedList.at(i).column()).toLatin1()); |
|
1310 |
} |
|
1311 |
} |
|
1312 |
||
1313 |
void tst_QItemSelectionModel::persistentselections_data() |
|
1314 |
{ |
|
1315 |
QTest::addColumn<PairList>("indexList"); |
|
1316 |
QTest::addColumn<IntList>("commandList"); |
|
1317 |
QTest::addColumn<IntList>("insertRows"); // start, count |
|
1318 |
QTest::addColumn<IntList>("insertColumns"); // start, count |
|
1319 |
QTest::addColumn<IntList>("deleteRows"); // start, count |
|
1320 |
QTest::addColumn<IntList>("deleteColumns"); // start, count |
|
1321 |
QTest::addColumn<PairList>("expectedList"); |
|
1322 |
||
1323 |
PairList index, expected; |
|
1324 |
IntList command, insertRows, insertColumns, deleteRows, deleteColumns; |
|
1325 |
||
1326 |
||
1327 |
index.clear(); expected.clear(); command.clear(); |
|
1328 |
insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); |
|
1329 |
index << IntPair(0, 0); |
|
1330 |
command << QItemSelectionModel::ClearAndSelect; |
|
1331 |
deleteRows << 4 << 1; |
|
1332 |
expected << IntPair(0, 0); |
|
1333 |
QTest::newRow("ClearAndSelect (0, 0). Delete last row.") |
|
1334 |
<< index << command |
|
1335 |
<< insertRows << insertColumns << deleteRows << deleteColumns |
|
1336 |
<< expected; |
|
1337 |
||
1338 |
index.clear(); expected.clear(); command.clear(); |
|
1339 |
insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); |
|
1340 |
index << IntPair(0, 0); |
|
1341 |
command << QItemSelectionModel::ClearAndSelect; |
|
1342 |
deleteRows << 0 << 1; |
|
1343 |
QTest::newRow("ClearAndSelect (0, 0). Delete first row.") |
|
1344 |
<< index << command |
|
1345 |
<< insertRows << insertColumns << deleteRows << deleteColumns |
|
1346 |
<< expected; |
|
1347 |
||
1348 |
index.clear(); expected.clear(); command.clear(); |
|
1349 |
insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); |
|
1350 |
index << IntPair(1, 0); |
|
1351 |
command << QItemSelectionModel::ClearAndSelect; |
|
1352 |
deleteRows << 0 << 1; |
|
1353 |
expected << IntPair(0, 0); |
|
1354 |
QTest::newRow("ClearAndSelect (1, 0). Delete first row.") |
|
1355 |
<< index << command |
|
1356 |
<< insertRows << insertColumns << deleteRows << deleteColumns |
|
1357 |
<< expected; |
|
1358 |
||
1359 |
index.clear(); expected.clear(); command.clear(); |
|
1360 |
insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); |
|
1361 |
index << IntPair(0, 0); |
|
1362 |
command << QItemSelectionModel::ClearAndSelect; |
|
1363 |
insertRows << 5 << 1; |
|
1364 |
expected << IntPair(0, 0); |
|
1365 |
QTest::newRow("ClearAndSelect (0, 0). Append row.") |
|
1366 |
<< index << command |
|
1367 |
<< insertRows << insertColumns << deleteRows << deleteColumns |
|
1368 |
<< expected; |
|
1369 |
||
1370 |
index.clear(); expected.clear(); command.clear(); |
|
1371 |
insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); |
|
1372 |
index << IntPair(0, 0); |
|
1373 |
command << QItemSelectionModel::ClearAndSelect; |
|
1374 |
insertRows << 0 << 1; |
|
1375 |
expected << IntPair(1, 0); |
|
1376 |
QTest::newRow("ClearAndSelect (0, 0). Insert before first row.") |
|
1377 |
<< index << command |
|
1378 |
<< insertRows << insertColumns << deleteRows << deleteColumns |
|
1379 |
<< expected; |
|
1380 |
||
1381 |
index.clear(); expected.clear(); command.clear(); |
|
1382 |
insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); |
|
1383 |
index << IntPair(0, 0) |
|
1384 |
<< IntPair(4, 0); |
|
1385 |
command << QItemSelectionModel::ClearAndSelect; |
|
1386 |
insertRows << 5 << 1; |
|
1387 |
expected << IntPair(0, 0) |
|
1388 |
<< IntPair(1, 0) |
|
1389 |
<< IntPair(2, 0) |
|
1390 |
<< IntPair(3, 0) |
|
1391 |
<< IntPair(4, 0); |
|
1392 |
QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Append row.") |
|
1393 |
<< index << command |
|
1394 |
<< insertRows << insertColumns << deleteRows << deleteColumns |
|
1395 |
<< expected; |
|
1396 |
||
1397 |
index.clear(); expected.clear(); command.clear(); |
|
1398 |
insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); |
|
1399 |
index << IntPair(0, 0) |
|
1400 |
<< IntPair(4, 0); |
|
1401 |
command << QItemSelectionModel::ClearAndSelect; |
|
1402 |
insertRows << 0 << 1; |
|
1403 |
expected << IntPair(1, 0) |
|
1404 |
<< IntPair(2, 0) |
|
1405 |
<< IntPair(3, 0) |
|
1406 |
<< IntPair(4, 0) |
|
1407 |
<< IntPair(5, 0); |
|
1408 |
QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Insert before first row.") |
|
1409 |
<< index << command |
|
1410 |
<< insertRows << insertColumns << deleteRows << deleteColumns |
|
1411 |
<< expected; |
|
1412 |
||
1413 |
index.clear(); expected.clear(); command.clear(); |
|
1414 |
insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); |
|
1415 |
index << IntPair(0, 0) |
|
1416 |
<< IntPair(4, 0); |
|
1417 |
command << QItemSelectionModel::ClearAndSelect; |
|
1418 |
deleteRows << 0 << 1; |
|
1419 |
expected << IntPair(0, 0) |
|
1420 |
<< IntPair(1, 0) |
|
1421 |
<< IntPair(2, 0) |
|
1422 |
<< IntPair(3, 0); |
|
1423 |
QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Delete first row.") |
|
1424 |
<< index << command |
|
1425 |
<< insertRows << insertColumns << deleteRows << deleteColumns |
|
1426 |
<< expected; |
|
1427 |
||
1428 |
index.clear(); expected.clear(); command.clear(); |
|
1429 |
insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); |
|
1430 |
index << IntPair(0, 0) |
|
1431 |
<< IntPair(4, 0); |
|
1432 |
command << QItemSelectionModel::ClearAndSelect; |
|
1433 |
deleteRows << 4 << 1; |
|
1434 |
expected << IntPair(0, 0) |
|
1435 |
<< IntPair(1, 0) |
|
1436 |
<< IntPair(2, 0) |
|
1437 |
<< IntPair(3, 0); |
|
1438 |
QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Delete last row.") |
|
1439 |
<< index << command |
|
1440 |
<< insertRows << insertColumns << deleteRows << deleteColumns |
|
1441 |
<< expected; |
|
1442 |
||
1443 |
index.clear(); expected.clear(); command.clear(); |
|
1444 |
insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); |
|
1445 |
index << IntPair(0, 0) |
|
1446 |
<< IntPair(4, 0); |
|
1447 |
command << QItemSelectionModel::ClearAndSelect; |
|
1448 |
deleteRows << 1 << 3; |
|
1449 |
expected << IntPair(0, 0) |
|
1450 |
<< IntPair(1, 0); |
|
1451 |
QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Deleting all but first and last row.") |
|
1452 |
<< index << command |
|
1453 |
<< insertRows << insertColumns << deleteRows << deleteColumns |
|
1454 |
<< expected; |
|
1455 |
||
1456 |
index.clear(); expected.clear(); command.clear(); |
|
1457 |
insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); |
|
1458 |
index << IntPair(0, 0) |
|
1459 |
<< IntPair(4, 0); |
|
1460 |
command << QItemSelectionModel::ClearAndSelect; |
|
1461 |
insertRows << 1 << 1; |
|
1462 |
expected << IntPair(0, 0) |
|
1463 |
// the inserted row should not be selected |
|
1464 |
<< IntPair(2, 0) |
|
1465 |
<< IntPair(3, 0) |
|
1466 |
<< IntPair(4, 0) |
|
1467 |
<< IntPair(5, 0); |
|
1468 |
QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Insert after first row.") |
|
1469 |
<< index << command |
|
1470 |
<< insertRows << insertColumns << deleteRows << deleteColumns |
|
1471 |
<< expected; |
|
1472 |
} |
|
1473 |
||
1474 |
void tst_QItemSelectionModel::persistentselections() |
|
1475 |
{ |
|
1476 |
QFETCH(PairList, indexList); |
|
1477 |
QFETCH(IntList, commandList); |
|
1478 |
QFETCH(IntList, insertRows); |
|
1479 |
QFETCH(IntList, insertColumns); |
|
1480 |
QFETCH(IntList, deleteRows); |
|
1481 |
QFETCH(IntList, deleteColumns); |
|
1482 |
QFETCH(PairList, expectedList); |
|
1483 |
||
1484 |
// make sure the model is sane (5x5) |
|
1485 |
QCOMPARE(model->rowCount(QModelIndex()), 5); |
|
1486 |
QCOMPARE(model->columnCount(QModelIndex()), 5); |
|
1487 |
||
1488 |
// do selections |
|
1489 |
for (int i=0; i<commandList.count(); ++i) { |
|
1490 |
if (indexList.count() == commandList.count()) { |
|
1491 |
QModelIndex index = model->index(indexList.at(i).first, |
|
1492 |
indexList.at(i).second, |
|
1493 |
QModelIndex()); |
|
1494 |
selection->select(index, (QItemSelectionModel::SelectionFlags)commandList.at(i)); |
|
1495 |
} else { |
|
1496 |
QModelIndex tl = model->index(indexList.at(2*i).first, |
|
1497 |
indexList.at(2*i).second, |
|
1498 |
QModelIndex()); |
|
1499 |
QModelIndex br = model->index(indexList.at(2*i+1).first, |
|
1500 |
indexList.at(2*i+1).second, |
|
1501 |
QModelIndex()); |
|
1502 |
selection->select(QItemSelection(tl, br), |
|
1503 |
(QItemSelectionModel::SelectionFlags)commandList.at(i)); |
|
1504 |
} |
|
1505 |
} |
|
1506 |
// test that we have selected items |
|
1507 |
QVERIFY(!selection->selectedIndexes().isEmpty()); |
|
1508 |
QVERIFY(selection->hasSelection()); |
|
1509 |
||
1510 |
// insert/delete row and/or columns |
|
1511 |
if (insertRows.count() > 1) |
|
1512 |
model->insertRows(insertRows.at(0), insertRows.at(1), QModelIndex()); |
|
1513 |
if (insertColumns.count() > 1) |
|
1514 |
model->insertColumns(insertColumns.at(0), insertColumns.at(1), QModelIndex()); |
|
1515 |
if (deleteRows.count() > 1) |
|
1516 |
model->removeRows(deleteRows.at(0), deleteRows.at(1), QModelIndex()); |
|
1517 |
if (deleteColumns.count() > 1) |
|
1518 |
model->removeColumns(deleteColumns.at(0), deleteColumns.at(1), QModelIndex()); |
|
1519 |
||
1520 |
// check that the selected items are the correct number and indexes |
|
1521 |
QModelIndexList selectedList = selection->selectedIndexes(); |
|
1522 |
QCOMPARE(selectedList.count(), expectedList.count()); |
|
1523 |
foreach(IntPair pair, expectedList) { |
|
1524 |
QModelIndex index = model->index(pair.first, pair.second, QModelIndex()); |
|
1525 |
QVERIFY(selectedList.contains(index)); |
|
1526 |
} |
|
1527 |
} |
|
1528 |
||
1529 |
// "make reset public"-model |
|
1530 |
class MyStandardItemModel: public QStandardItemModel |
|
1531 |
{ |
|
1532 |
Q_OBJECT |
|
1533 |
public: |
|
1534 |
inline MyStandardItemModel(int i1, int i2): QStandardItemModel(i1, i2) {} |
|
1535 |
inline void reset() { QStandardItemModel::reset(); } |
|
1536 |
}; |
|
1537 |
||
1538 |
void tst_QItemSelectionModel::resetModel() |
|
1539 |
{ |
|
1540 |
MyStandardItemModel model(20, 20); |
|
1541 |
QTreeView view; |
|
1542 |
view.setModel(&model); |
|
1543 |
||
1544 |
QSignalSpy spy(view.selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection))); |
|
1545 |
||
1546 |
view.selectionModel()->select(QItemSelection(model.index(0, 0), model.index(5, 5)), QItemSelectionModel::Select); |
|
1547 |
||
1548 |
QCOMPARE(spy.count(), 1); |
|
1549 |
||
1550 |
model.reset(); |
|
1551 |
||
1552 |
QVERIFY(view.selectionModel()->selection().isEmpty()); |
|
1553 |
QVERIFY(view.selectionModel()->hasSelection() == false); |
|
1554 |
||
1555 |
view.selectionModel()->select(QItemSelection(model.index(0, 0), model.index(5, 5)), QItemSelectionModel::Select); |
|
1556 |
||
1557 |
QCOMPARE(spy.count(), 2); |
|
1558 |
QCOMPARE(spy.at(1).count(), 2); |
|
1559 |
// make sure we don't get an "old selection" |
|
1560 |
QCOMPARE(spy.at(1).at(1).userType(), qMetaTypeId<QItemSelection>()); |
|
1561 |
QVERIFY(qvariant_cast<QItemSelection>(spy.at(1).at(1)).isEmpty()); |
|
1562 |
} |
|
1563 |
||
1564 |
void tst_QItemSelectionModel::removeRows_data() |
|
1565 |
{ |
|
1566 |
QTest::addColumn<int>("rowCount"); |
|
1567 |
QTest::addColumn<int>("columnCount"); |
|
1568 |
||
1569 |
QTest::addColumn<int>("selectTop"); |
|
1570 |
QTest::addColumn<int>("selectLeft"); |
|
1571 |
QTest::addColumn<int>("selectBottom"); |
|
1572 |
QTest::addColumn<int>("selectRight"); |
|
1573 |
||
1574 |
QTest::addColumn<int>("removeTop"); |
|
1575 |
QTest::addColumn<int>("removeBottom"); |
|
1576 |
||
1577 |
QTest::addColumn<int>("expectedTop"); |
|
1578 |
QTest::addColumn<int>("expectedLeft"); |
|
1579 |
QTest::addColumn<int>("expectedBottom"); |
|
1580 |
QTest::addColumn<int>("expectedRight"); |
|
1581 |
||
1582 |
QTest::newRow("4x4 <0,1><1,1>") |
|
1583 |
<< 4 << 4 |
|
1584 |
<< 0 << 1 << 1 << 1 |
|
1585 |
<< 0 << 0 |
|
1586 |
<< 0 << 1 << 0 << 1; |
|
1587 |
} |
|
1588 |
||
1589 |
void tst_QItemSelectionModel::removeRows() |
|
1590 |
{ |
|
1591 |
QFETCH(int, rowCount); |
|
1592 |
QFETCH(int, columnCount); |
|
1593 |
QFETCH(int, selectTop); |
|
1594 |
QFETCH(int, selectLeft); |
|
1595 |
QFETCH(int, selectBottom); |
|
1596 |
QFETCH(int, selectRight); |
|
1597 |
QFETCH(int, removeTop); |
|
1598 |
QFETCH(int, removeBottom); |
|
1599 |
QFETCH(int, expectedTop); |
|
1600 |
QFETCH(int, expectedLeft); |
|
1601 |
QFETCH(int, expectedBottom); |
|
1602 |
QFETCH(int, expectedRight); |
|
1603 |
||
1604 |
MyStandardItemModel model(rowCount, columnCount); |
|
1605 |
QItemSelectionModel selections(&model); |
|
1606 |
QSignalSpy spy(&selections, SIGNAL(selectionChanged(QItemSelection,QItemSelection))); |
|
1607 |
||
1608 |
QModelIndex tl = model.index(selectTop, selectLeft); |
|
1609 |
QModelIndex br = model.index(selectBottom, selectRight); |
|
1610 |
selections.select(QItemSelection(tl, br), QItemSelectionModel::ClearAndSelect); |
|
1611 |
||
1612 |
QCOMPARE(spy.count(), 1); |
|
1613 |
QVERIFY(selections.isSelected(tl)); |
|
1614 |
QVERIFY(selections.isSelected(br)); |
|
1615 |
QVERIFY(selections.hasSelection()); |
|
1616 |
||
1617 |
model.removeRows(removeTop, removeBottom - removeTop + 1); |
|
1618 |
||
1619 |
QCOMPARE(spy.count(), 2); |
|
1620 |
tl = model.index(expectedTop, expectedLeft); |
|
1621 |
br = model.index(expectedBottom, expectedRight); |
|
1622 |
QVERIFY(selections.isSelected(tl)); |
|
1623 |
QVERIFY(selections.isSelected(br)); |
|
1624 |
} |
|
1625 |
||
1626 |
void tst_QItemSelectionModel::removeColumns_data() |
|
1627 |
{ |
|
1628 |
QTest::addColumn<int>("rowCount"); |
|
1629 |
QTest::addColumn<int>("columnCount"); |
|
1630 |
||
1631 |
QTest::addColumn<int>("selectTop"); |
|
1632 |
QTest::addColumn<int>("selectLeft"); |
|
1633 |
QTest::addColumn<int>("selectBottom"); |
|
1634 |
QTest::addColumn<int>("selectRight"); |
|
1635 |
||
1636 |
QTest::addColumn<int>("removeLeft"); |
|
1637 |
QTest::addColumn<int>("removeRight"); |
|
1638 |
||
1639 |
QTest::addColumn<int>("expectedTop"); |
|
1640 |
QTest::addColumn<int>("expectedLeft"); |
|
1641 |
QTest::addColumn<int>("expectedBottom"); |
|
1642 |
QTest::addColumn<int>("expectedRight"); |
|
1643 |
||
1644 |
QTest::newRow("4x4 <0,1><1,1>") |
|
1645 |
<< 4 << 4 |
|
1646 |
<< 1 << 0 << 1 << 1 |
|
1647 |
<< 0 << 0 |
|
1648 |
<< 1 << 0 << 1 << 0; |
|
1649 |
} |
|
1650 |
||
1651 |
void tst_QItemSelectionModel::removeColumns() |
|
1652 |
{ |
|
1653 |
QFETCH(int, rowCount); |
|
1654 |
QFETCH(int, columnCount); |
|
1655 |
QFETCH(int, selectTop); |
|
1656 |
QFETCH(int, selectLeft); |
|
1657 |
QFETCH(int, selectBottom); |
|
1658 |
QFETCH(int, selectRight); |
|
1659 |
QFETCH(int, removeLeft); |
|
1660 |
QFETCH(int, removeRight); |
|
1661 |
QFETCH(int, expectedTop); |
|
1662 |
QFETCH(int, expectedLeft); |
|
1663 |
QFETCH(int, expectedBottom); |
|
1664 |
QFETCH(int, expectedRight); |
|
1665 |
||
1666 |
MyStandardItemModel model(rowCount, columnCount); |
|
1667 |
QItemSelectionModel selections(&model); |
|
1668 |
QSignalSpy spy(&selections, SIGNAL(selectionChanged(QItemSelection,QItemSelection))); |
|
1669 |
||
1670 |
QModelIndex tl = model.index(selectTop, selectLeft); |
|
1671 |
QModelIndex br = model.index(selectBottom, selectRight); |
|
1672 |
selections.select(QItemSelection(tl, br), QItemSelectionModel::ClearAndSelect); |
|
1673 |
||
1674 |
QCOMPARE(spy.count(), 1); |
|
1675 |
QVERIFY(selections.isSelected(tl)); |
|
1676 |
QVERIFY(selections.isSelected(br)); |
|
1677 |
QVERIFY(selections.hasSelection()); |
|
1678 |
||
1679 |
model.removeColumns(removeLeft, removeRight - removeLeft + 1); |
|
1680 |
||
1681 |
QCOMPARE(spy.count(), 2); |
|
1682 |
tl = model.index(expectedTop, expectedLeft); |
|
1683 |
br = model.index(expectedBottom, expectedRight); |
|
1684 |
QVERIFY(selections.isSelected(tl)); |
|
1685 |
QVERIFY(selections.isSelected(br)); |
|
1686 |
} |
|
1687 |
||
1688 |
typedef QList<IntList> IntListList; |
|
1689 |
typedef QPair<IntPair, IntPair> IntPairPair; |
|
1690 |
typedef QList<IntPairPair> IntPairPairList; |
|
1691 |
Q_DECLARE_METATYPE(IntListList) |
|
1692 |
Q_DECLARE_METATYPE(IntPairPair) |
|
1693 |
Q_DECLARE_METATYPE(IntPairPairList) |
|
1694 |
||
1695 |
void tst_QItemSelectionModel::modelLayoutChanged_data() |
|
1696 |
{ |
|
1697 |
QTest::addColumn<IntListList>("items"); |
|
1698 |
QTest::addColumn<IntPairPairList>("initialSelectedRanges"); |
|
1699 |
QTest::addColumn<int>("sortOrder"); |
|
1700 |
QTest::addColumn<int>("sortColumn"); |
|
1701 |
QTest::addColumn<IntPairPairList>("expectedSelectedRanges"); |
|
1702 |
||
1703 |
QTest::newRow("everything selected, then row order reversed") |
|
1704 |
<< (IntListList() |
|
1705 |
<< (IntList() << 0 << 1 << 2 << 3) |
|
1706 |
<< (IntList() << 3 << 2 << 1 << 0)) |
|
1707 |
<< (IntPairPairList() |
|
1708 |
<< IntPairPair(IntPair(0, 0), IntPair(3, 1))) |
|
1709 |
<< int(Qt::DescendingOrder) |
|
1710 |
<< 0 |
|
1711 |
<< (IntPairPairList() |
|
1712 |
<< IntPairPair(IntPair(0, 0), IntPair(3, 1))); |
|
1713 |
QTest::newRow("first two rows selected, then row order reversed") |
|
1714 |
<< (IntListList() |
|
1715 |
<< (IntList() << 0 << 1 << 2 << 3) |
|
1716 |
<< (IntList() << 3 << 2 << 1 << 0)) |
|
1717 |
<< (IntPairPairList() |
|
1718 |
<< IntPairPair(IntPair(0, 0), IntPair(1, 1))) |
|
1719 |
<< int(Qt::DescendingOrder) |
|
1720 |
<< 0 |
|
1721 |
<< (IntPairPairList() |
|
1722 |
<< IntPairPair(IntPair(2, 0), IntPair(3, 1))); |
|
1723 |
QTest::newRow("middle two rows selected, then row order reversed") |
|
1724 |
<< (IntListList() |
|
1725 |
<< (IntList() << 0 << 1 << 2 << 3) |
|
1726 |
<< (IntList() << 3 << 2 << 1 << 0)) |
|
1727 |
<< (IntPairPairList() |
|
1728 |
<< IntPairPair(IntPair(1, 0), IntPair(2, 1))) |
|
1729 |
<< int(Qt::DescendingOrder) |
|
1730 |
<< 0 |
|
1731 |
<< (IntPairPairList() |
|
1732 |
<< IntPairPair(IntPair(1, 0), IntPair(2, 1))); |
|
1733 |
QTest::newRow("two ranges") |
|
1734 |
<< (IntListList() |
|
1735 |
<< (IntList() << 2 << 0 << 3 << 1) |
|
1736 |
<< (IntList() << 2 << 0 << 3 << 1)) |
|
1737 |
<< (IntPairPairList() |
|
1738 |
<< IntPairPair(IntPair(1, 0), IntPair(1, 1)) |
|
1739 |
<< IntPairPair(IntPair(3, 0), IntPair(3, 1))) |
|
1740 |
<< int(Qt::AscendingOrder) |
|
1741 |
<< 0 |
|
1742 |
<< (IntPairPairList() |
|
1743 |
<< IntPairPair(IntPair(0, 0), IntPair(0, 1)) |
|
1744 |
<< IntPairPair(IntPair(1, 0), IntPair(1, 1))); |
|
1745 |
} |
|
1746 |
||
1747 |
void tst_QItemSelectionModel::modelLayoutChanged() |
|
1748 |
{ |
|
1749 |
QFETCH(IntListList, items); |
|
1750 |
QFETCH(IntPairPairList, initialSelectedRanges); |
|
1751 |
QFETCH(int, sortOrder); |
|
1752 |
QFETCH(int, sortColumn); |
|
1753 |
QFETCH(IntPairPairList, expectedSelectedRanges); |
|
1754 |
||
1755 |
MyStandardItemModel model(items.at(0).count(), items.count()); |
|
1756 |
// initialize model data |
|
1757 |
for (int i = 0; i < model.rowCount(); ++i) { |
|
1758 |
for (int j = 0; j < model.columnCount(); ++j) { |
|
1759 |
QModelIndex index = model.index(i, j); |
|
1760 |
model.setData(index, items.at(j).at(i), Qt::DisplayRole); |
|
1761 |
} |
|
1762 |
} |
|
1763 |
||
1764 |
// select initial ranges |
|
1765 |
QItemSelectionModel selectionModel(&model); |
|
1766 |
foreach (IntPairPair range, initialSelectedRanges) { |
|
1767 |
IntPair tl = range.first; |
|
1768 |
IntPair br = range.second; |
|
1769 |
QItemSelection selection( |
|
1770 |
model.index(tl.first, tl.second), |
|
1771 |
model.index(br.first, br.second)); |
|
1772 |
selectionModel.select(selection, QItemSelectionModel::Select); |
|
1773 |
} |
|
1774 |
||
1775 |
// sort the model |
|
1776 |
model.sort(sortColumn, Qt::SortOrder(sortOrder)); |
|
1777 |
||
1778 |
// verify that selection is as expected |
|
1779 |
QItemSelection selection = selectionModel.selection(); |
|
1780 |
QCOMPARE(selection.count(), expectedSelectedRanges.count()); |
|
1781 |
QVERIFY(selectionModel.hasSelection() == !expectedSelectedRanges.isEmpty()); |
|
1782 |
||
1783 |
for (int i = 0; i < expectedSelectedRanges.count(); ++i) { |
|
1784 |
IntPairPair expectedRange = expectedSelectedRanges.at(i); |
|
1785 |
IntPair expectedTl = expectedRange.first; |
|
1786 |
IntPair expectedBr = expectedRange.second; |
|
1787 |
QItemSelectionRange actualRange = selection.at(i); |
|
1788 |
QModelIndex actualTl = actualRange.topLeft(); |
|
1789 |
QModelIndex actualBr = actualRange.bottomRight(); |
|
1790 |
QCOMPARE(actualTl.row(), expectedTl.first); |
|
1791 |
QCOMPARE(actualTl.column(), expectedTl.second); |
|
1792 |
QCOMPARE(actualBr.row(), expectedBr.first); |
|
1793 |
QCOMPARE(actualBr.column(), expectedBr.second); |
|
1794 |
} |
|
1795 |
} |
|
1796 |
||
1797 |
void tst_QItemSelectionModel::selectedRows_data() |
|
1798 |
{ |
|
1799 |
QTest::addColumn<int>("rowCount"); |
|
1800 |
QTest::addColumn<int>("columnCount"); |
|
1801 |
QTest::addColumn<int>("column"); |
|
1802 |
QTest::addColumn<IntList>("selectRows"); |
|
1803 |
QTest::addColumn<IntList>("expectedRows"); |
|
1804 |
QTest::addColumn<IntList>("unexpectedRows"); |
|
1805 |
||
1806 |
QTest::newRow("10x10, first row") |
|
1807 |
<< 10 << 10 << 0 |
|
1808 |
<< (IntList() << 0) |
|
1809 |
<< (IntList() << 0) |
|
1810 |
<< (IntList() << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9); |
|
1811 |
||
1812 |
QTest::newRow("10x10, first 4 rows") |
|
1813 |
<< 10 << 10 << 0 |
|
1814 |
<< (IntList() << 0 << 1 << 2 << 3) |
|
1815 |
<< (IntList() << 0 << 1 << 2 << 3) |
|
1816 |
<< (IntList() << 4 << 5 << 6 << 7 << 8 << 9); |
|
1817 |
||
1818 |
QTest::newRow("10x10, last 4 rows") |
|
1819 |
<< 10 << 10 << 0 |
|
1820 |
<< (IntList() << 6 << 7 << 8 << 9) |
|
1821 |
<< (IntList() << 6 << 7 << 8 << 9) |
|
1822 |
<< (IntList() << 0 << 1 << 2 << 3 << 4 << 6); |
|
1823 |
} |
|
1824 |
||
1825 |
void tst_QItemSelectionModel::selectedRows() |
|
1826 |
{ |
|
1827 |
QFETCH(int, rowCount); |
|
1828 |
QFETCH(int, columnCount); |
|
1829 |
QFETCH(int, column); |
|
1830 |
QFETCH(IntList, selectRows); |
|
1831 |
QFETCH(IntList, expectedRows); |
|
1832 |
QFETCH(IntList, unexpectedRows); |
|
1833 |
||
1834 |
MyStandardItemModel model(rowCount, columnCount); |
|
1835 |
QItemSelectionModel selectionModel(&model); |
|
1836 |
||
1837 |
for (int i = 0; i < selectRows.count(); ++i) |
|
1838 |
selectionModel.select(model.index(selectRows.at(i), 0), |
|
1839 |
QItemSelectionModel::Select |
|
1840 |
|QItemSelectionModel::Rows); |
|
1841 |
||
1842 |
for (int j = 0; j < selectRows.count(); ++j) |
|
1843 |
QVERIFY(selectionModel.isRowSelected(expectedRows.at(j), QModelIndex())); |
|
1844 |
||
1845 |
for (int k = 0; k < selectRows.count(); ++k) |
|
1846 |
QVERIFY(!selectionModel.isRowSelected(unexpectedRows.at(k), QModelIndex())); |
|
1847 |
||
1848 |
QModelIndexList selectedRowIndexes = selectionModel.selectedRows(column); |
|
1849 |
QCOMPARE(selectedRowIndexes.count(), expectedRows.count()); |
|
1850 |
qSort(selectedRowIndexes); |
|
1851 |
for (int l = 0; l < selectedRowIndexes.count(); ++l) { |
|
1852 |
QCOMPARE(selectedRowIndexes.at(l).row(), expectedRows.at(l)); |
|
1853 |
QCOMPARE(selectedRowIndexes.at(l).column(), column); |
|
1854 |
} |
|
1855 |
} |
|
1856 |
||
1857 |
void tst_QItemSelectionModel::selectedColumns_data() |
|
1858 |
{ |
|
1859 |
QTest::addColumn<int>("rowCount"); |
|
1860 |
QTest::addColumn<int>("columnCount"); |
|
1861 |
QTest::addColumn<int>("row"); |
|
1862 |
QTest::addColumn<IntList>("selectColumns"); |
|
1863 |
QTest::addColumn<IntList>("expectedColumns"); |
|
1864 |
QTest::addColumn<IntList>("unexpectedColumns"); |
|
1865 |
||
1866 |
QTest::newRow("10x10, first columns") |
|
1867 |
<< 10 << 10 << 0 |
|
1868 |
<< (IntList() << 0) |
|
1869 |
<< (IntList() << 0) |
|
1870 |
<< (IntList() << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9); |
|
1871 |
||
1872 |
QTest::newRow("10x10, first 4 columns") |
|
1873 |
<< 10 << 10 << 0 |
|
1874 |
<< (IntList() << 0 << 1 << 2 << 3) |
|
1875 |
<< (IntList() << 0 << 1 << 2 << 3) |
|
1876 |
<< (IntList() << 4 << 5 << 6 << 7 << 8 << 9); |
|
1877 |
||
1878 |
QTest::newRow("10x10, last 4 columns") |
|
1879 |
<< 10 << 10 << 0 |
|
1880 |
<< (IntList() << 6 << 7 << 8 << 9) |
|
1881 |
<< (IntList() << 6 << 7 << 8 << 9) |
|
1882 |
<< (IntList() << 0 << 1 << 2 << 3 << 4 << 6); |
|
1883 |
} |
|
1884 |
||
1885 |
void tst_QItemSelectionModel::selectedColumns() |
|
1886 |
{ |
|
1887 |
QFETCH(int, rowCount); |
|
1888 |
QFETCH(int, columnCount); |
|
1889 |
QFETCH(int, row); |
|
1890 |
QFETCH(IntList, selectColumns); |
|
1891 |
QFETCH(IntList, expectedColumns); |
|
1892 |
QFETCH(IntList, unexpectedColumns); |
|
1893 |
||
1894 |
MyStandardItemModel model(rowCount, columnCount); |
|
1895 |
QItemSelectionModel selectionModel(&model); |
|
1896 |
||
1897 |
for (int i = 0; i < selectColumns.count(); ++i) |
|
1898 |
selectionModel.select(model.index(0, selectColumns.at(i)), |
|
1899 |
QItemSelectionModel::Select |
|
1900 |
|QItemSelectionModel::Columns); |
|
1901 |
||
1902 |
for (int j = 0; j < selectColumns.count(); ++j) |
|
1903 |
QVERIFY(selectionModel.isColumnSelected(expectedColumns.at(j), QModelIndex())); |
|
1904 |
||
1905 |
for (int k = 0; k < selectColumns.count(); ++k) |
|
1906 |
QVERIFY(!selectionModel.isColumnSelected(unexpectedColumns.at(k), QModelIndex())); |
|
1907 |
||
1908 |
QModelIndexList selectedColumnIndexes = selectionModel.selectedColumns(row); |
|
1909 |
QCOMPARE(selectedColumnIndexes.count(), expectedColumns.count()); |
|
1910 |
qSort(selectedColumnIndexes); |
|
1911 |
for (int l = 0; l < selectedColumnIndexes.count(); ++l) { |
|
1912 |
QCOMPARE(selectedColumnIndexes.at(l).column(), expectedColumns.at(l)); |
|
1913 |
QCOMPARE(selectedColumnIndexes.at(l).row(), row); |
|
1914 |
} |
|
1915 |
} |
|
1916 |
||
1917 |
void tst_QItemSelectionModel::setCurrentIndex() |
|
1918 |
{ |
|
1919 |
// Build up a simple tree |
|
1920 |
QStandardItemModel *treemodel = new QStandardItemModel(0, 1); |
|
1921 |
treemodel->insertRow(0, new QStandardItem(1)); |
|
1922 |
treemodel->insertRow(1, new QStandardItem(2)); |
|
1923 |
||
1924 |
QTreeView treeView; |
|
1925 |
treeView.setModel(treemodel); |
|
1926 |
QItemSelectionModel *selectionModel = treeView.selectionModel(); |
|
1927 |
selectionModel->setCurrentIndex( |
|
1928 |
treemodel->index(0, 0, treemodel->index(0, 0)), |
|
1929 |
QItemSelectionModel::SelectCurrent); |
|
1930 |
||
1931 |
QSignalSpy currentSpy(selectionModel, |
|
1932 |
SIGNAL(currentChanged(QModelIndex,QModelIndex))); |
|
1933 |
QSignalSpy rowSpy(selectionModel, |
|
1934 |
SIGNAL(currentRowChanged(QModelIndex,QModelIndex))); |
|
1935 |
QSignalSpy columnSpy(selectionModel, |
|
1936 |
SIGNAL(currentColumnChanged(QModelIndex,QModelIndex))); |
|
1937 |
||
1938 |
// Select the same row and column indexes, but with a different parent |
|
1939 |
selectionModel->setCurrentIndex( |
|
1940 |
treemodel->index(0, 0, treemodel->index(1, 0)), |
|
1941 |
QItemSelectionModel::SelectCurrent); |
|
1942 |
||
1943 |
QCOMPARE(currentSpy.count(), 1); |
|
1944 |
QCOMPARE(rowSpy.count(), 1); |
|
1945 |
QCOMPARE(columnSpy.count(), 1); |
|
1946 |
||
1947 |
// Select another row in the same parent |
|
1948 |
selectionModel->setCurrentIndex( |
|
1949 |
treemodel->index(1, 0, treemodel->index(1, 0)), |
|
1950 |
QItemSelectionModel::SelectCurrent); |
|
1951 |
||
1952 |
QCOMPARE(currentSpy.count(), 2); |
|
1953 |
QCOMPARE(rowSpy.count(), 2); |
|
1954 |
QCOMPARE(columnSpy.count(), 1); |
|
1955 |
||
1956 |
delete treemodel; |
|
1957 |
} |
|
1958 |
||
1959 |
void tst_QItemSelectionModel::splitOnInsert() |
|
1960 |
{ |
|
1961 |
QStandardItemModel model(4, 1); |
|
1962 |
QItemSelectionModel selectionModel(&model); |
|
1963 |
selectionModel.select(model.index(2, 0), QItemSelectionModel::Select); |
|
1964 |
model.insertRow(2); |
|
1965 |
model.removeRow(3); |
|
1966 |
QVERIFY(!selectionModel.isSelected(model.index(1, 0))); |
|
1967 |
} |
|
1968 |
||
1969 |
void tst_QItemSelectionModel::task196285_rowIntersectsSelection() |
|
1970 |
{ |
|
1971 |
QTableWidget table; |
|
1972 |
table.setColumnCount(1); |
|
1973 |
table.setRowCount(1); |
|
1974 |
table.setItem(0, 0, new QTableWidgetItem("foo")); |
|
1975 |
QAbstractItemModel *model = table.model(); |
|
1976 |
QItemSelectionModel *selectionModel = table.selectionModel(); |
|
1977 |
QModelIndex index = model->index(0, 0, QModelIndex()); |
|
1978 |
||
1979 |
selectionModel->select(index, QItemSelectionModel::Select); |
|
1980 |
QVERIFY(selectionModel->rowIntersectsSelection(0, QModelIndex())); |
|
1981 |
QVERIFY(selectionModel->columnIntersectsSelection(0, QModelIndex())); |
|
1982 |
||
1983 |
selectionModel->select(index, QItemSelectionModel::Deselect); |
|
1984 |
QVERIFY(!selectionModel->rowIntersectsSelection(0, QModelIndex())); |
|
1985 |
QVERIFY(!selectionModel->columnIntersectsSelection(0, QModelIndex())); |
|
1986 |
||
1987 |
selectionModel->select(index, QItemSelectionModel::Toggle); |
|
1988 |
QVERIFY(selectionModel->rowIntersectsSelection(0, QModelIndex())); |
|
1989 |
QVERIFY(selectionModel->columnIntersectsSelection(0, QModelIndex())); |
|
1990 |
||
1991 |
selectionModel->select(index, QItemSelectionModel::Toggle); |
|
1992 |
QVERIFY(!selectionModel->rowIntersectsSelection(0, QModelIndex())); |
|
1993 |
QVERIFY(!selectionModel->columnIntersectsSelection(0, QModelIndex())); |
|
1994 |
} |
|
1995 |
||
1996 |
void tst_QItemSelectionModel::unselectable() |
|
1997 |
{ |
|
1998 |
QTreeWidget w; |
|
1999 |
for (int i = 0; i < 10; ++i) |
|
2000 |
w.setItemSelected(new QTreeWidgetItem(&w), true); |
|
2001 |
QCOMPARE(w.topLevelItemCount(), 10); |
|
2002 |
QCOMPARE(w.selectionModel()->selectedIndexes().count(), 10); |
|
2003 |
QCOMPARE(w.selectionModel()->selectedRows().count(), 10); |
|
2004 |
for (int j = 0; j < 10; ++j) |
|
2005 |
w.topLevelItem(j)->setFlags(0); |
|
2006 |
QCOMPARE(w.selectionModel()->selectedIndexes().count(), 0); |
|
2007 |
QCOMPARE(w.selectionModel()->selectedRows().count(), 0); |
|
2008 |
} |
|
2009 |
||
2010 |
void tst_QItemSelectionModel::task220420_selectedIndexes() |
|
2011 |
{ |
|
2012 |
QStandardItemModel model(2, 2); |
|
2013 |
QItemSelectionModel selectionModel(&model); |
|
2014 |
QItemSelection selection; |
|
2015 |
selection.append(QItemSelectionRange(model.index(0,0))); |
|
2016 |
selection.append(QItemSelectionRange(model.index(0,1))); |
|
2017 |
||
2018 |
//we select the 1st row |
|
2019 |
selectionModel.select(selection, QItemSelectionModel::Rows | QItemSelectionModel::Select); |
|
2020 |
||
2021 |
QCOMPARE(selectionModel.selectedRows().count(), 1); |
|
2022 |
QCOMPARE(selectionModel.selectedIndexes().count(), model.columnCount()); |
|
2023 |
} |
|
2024 |
||
2025 |
||
2026 |
class QtTestTableModel: public QAbstractTableModel |
|
2027 |
{ |
|
2028 |
Q_OBJECT |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2029 |
|
0 | 2030 |
public: |
2031 |
QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0) |
|
2032 |
: QAbstractTableModel(parent), |
|
2033 |
row_count(rows), |
|
2034 |
column_count(columns) {} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2035 |
|
0 | 2036 |
int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; } |
2037 |
int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; } |
|
2038 |
bool isEditable(const QModelIndex &) const { return true; } |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2039 |
|
0 | 2040 |
QVariant data(const QModelIndex &idx, int role) const |
2041 |
{ |
|
2042 |
if (role == Qt::DisplayRole || role == Qt::EditRole) |
|
2043 |
return QString("[%1,%2]").arg(idx.row()).arg(idx.column()); |
|
2044 |
return QVariant(); |
|
2045 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2046 |
|
0 | 2047 |
int row_count; |
2048 |
int column_count; |
|
2049 |
friend class tst_QItemSelectionModel; |
|
2050 |
}; |
|
2051 |
||
2052 |
||
2053 |
void tst_QItemSelectionModel::task240734_layoutChanged() |
|
2054 |
{ |
|
2055 |
QtTestTableModel model(1,1); |
|
2056 |
QItemSelectionModel selectionModel(&model); |
|
2057 |
selectionModel.select(model.index(0,0), QItemSelectionModel::Select); |
|
2058 |
QCOMPARE(selectionModel.selectedIndexes().count() , 1); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2059 |
|
0 | 2060 |
emit model.layoutAboutToBeChanged(); |
2061 |
model.row_count = 5; |
|
2062 |
emit model.layoutChanged(); |
|
2063 |
||
2064 |
//The selection should not change. |
|
2065 |
QCOMPARE(selectionModel.selectedIndexes().count() , 1); |
|
2066 |
QCOMPARE(selectionModel.selectedIndexes().first() , model.index(0,0)); |
|
2067 |
} |
|
2068 |
||
2069 |
void tst_QItemSelectionModel::merge_data() |
|
2070 |
{ |
|
2071 |
QTest::addColumn<QItemSelection>("init"); |
|
2072 |
QTest::addColumn<QItemSelection>("other"); |
|
2073 |
QTest::addColumn<int>("command"); |
|
2074 |
QTest::addColumn<QItemSelection>("result"); |
|
2075 |
||
2076 |
QTest::newRow("Simple select") |
|
2077 |
<< QItemSelection() |
|
2078 |
<< QItemSelection(model->index(2, 1) , model->index(3, 4)) |
|
2079 |
<< int(QItemSelectionModel::Select) |
|
2080 |
<< QItemSelection(model->index(2, 1) , model->index(3, 4)); |
|
2081 |
||
2082 |
QTest::newRow("Simple deselect") |
|
2083 |
<< QItemSelection(model->index(2, 1) , model->index(3, 4)) |
|
2084 |
<< QItemSelection(model->index(2, 1) , model->index(3, 4)) |
|
2085 |
<< int(QItemSelectionModel::Deselect) |
|
2086 |
<< QItemSelection(); |
|
2087 |
||
2088 |
QTest::newRow("Simple Toggle deselect") |
|
2089 |
<< QItemSelection(model->index(2, 1) , model->index(3, 4)) |
|
2090 |
<< QItemSelection(model->index(2, 1) , model->index(3, 4)) |
|
2091 |
<< int(QItemSelectionModel::Toggle) |
|
2092 |
<< QItemSelection(); |
|
2093 |
||
2094 |
QTest::newRow("Simple Toggle select") |
|
2095 |
<< QItemSelection() |
|
2096 |
<< QItemSelection(model->index(2, 1) , model->index(3, 4)) |
|
2097 |
<< int(QItemSelectionModel::Toggle) |
|
2098 |
<< QItemSelection(model->index(2, 1) , model->index(3, 4)); |
|
2099 |
||
2100 |
QTest::newRow("Add select") |
|
2101 |
<< QItemSelection(model->index(2, 1) , model->index(3, 3)) |
|
2102 |
<< QItemSelection(model->index(2, 2) , model->index(3, 4)) |
|
2103 |
<< int(QItemSelectionModel::Select) |
|
2104 |
<< QItemSelection(model->index(2, 1) , model->index(3, 4)); |
|
2105 |
||
2106 |
QTest::newRow("Deselect") |
|
2107 |
<< QItemSelection(model->index(2, 1) , model->index(3, 4)) |
|
2108 |
<< QItemSelection(model->index(2, 2) , model->index(3, 4)) |
|
2109 |
<< int(QItemSelectionModel::Deselect) |
|
2110 |
<< QItemSelection(model->index(2, 1) , model->index(3, 1)); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2111 |
|
0 | 2112 |
QItemSelection r1(model->index(2, 1) , model->index(3, 1)); |
2113 |
r1.select(model->index(2, 4) , model->index(3, 4)); |
|
2114 |
QTest::newRow("Toggle") |
|
2115 |
<< QItemSelection(model->index(2, 1) , model->index(3, 3)) |
|
2116 |
<< QItemSelection(model->index(2, 2) , model->index(3, 4)) |
|
2117 |
<< int(QItemSelectionModel::Toggle) |
|
2118 |
<< r1; |
|
2119 |
} |
|
2120 |
||
2121 |
||
2122 |
void tst_QItemSelectionModel::merge() |
|
2123 |
{ |
|
2124 |
QFETCH(QItemSelection, init); |
|
2125 |
QFETCH(QItemSelection, other); |
|
2126 |
QFETCH(int, command); |
|
2127 |
QFETCH(QItemSelection, result); |
|
2128 |
||
2129 |
init.merge(other, QItemSelectionModel::SelectionFlags(command)); |
|
2130 |
||
2131 |
foreach(const QModelIndex &idx, init.indexes()) |
|
2132 |
QVERIFY(result.contains(idx)); |
|
2133 |
foreach(const QModelIndex &idx, result.indexes()) |
|
2134 |
QVERIFY(init.contains(idx)); |
|
2135 |
} |
|
2136 |
||
2137 |
void tst_QItemSelectionModel::task119433_isRowSelected() |
|
2138 |
{ |
|
2139 |
QStandardItemModel model(2,2); |
|
2140 |
model.setData(model.index(0,0), 0, Qt::UserRole - 1); |
|
2141 |
QItemSelectionModel sel(&model); |
|
2142 |
sel.select( QItemSelection(model.index(0,0), model.index(0, 1)), QItemSelectionModel::Select); |
|
2143 |
QCOMPARE(sel.selectedIndexes().count(), 1); |
|
2144 |
QVERIFY(sel.isRowSelected(0, QModelIndex())); |
|
2145 |
} |
|
2146 |
||
2147 |
void tst_QItemSelectionModel::task252069_rowIntersectsSelection() |
|
2148 |
{ |
|
2149 |
QStandardItemModel m; |
|
2150 |
for (int i=0; i<8; ++i) { |
|
2151 |
for (int j=0; j<8; ++j) { |
|
2152 |
QStandardItem *item = new QStandardItem(QString("Item number %1").arg(i)); |
|
2153 |
if ((i % 2 == 0 && j == 0) || |
|
2154 |
(j % 2 == 0 && i == 0) || |
|
2155 |
j == 5 || i == 5 ) { |
|
2156 |
item->setEnabled(false); |
|
2157 |
//item->setSelectable(false); |
|
2158 |
} |
|
2159 |
m.setItem(i, j, item); |
|
2160 |
} |
|
2161 |
} |
|
2162 |
||
2163 |
QItemSelectionModel selected(&m); |
|
2164 |
//nothing is selected |
|
2165 |
QVERIFY(!selected.rowIntersectsSelection(0, QModelIndex())); |
|
2166 |
QVERIFY(!selected.rowIntersectsSelection(2, QModelIndex())); |
|
2167 |
QVERIFY(!selected.rowIntersectsSelection(3, QModelIndex())); |
|
2168 |
QVERIFY(!selected.rowIntersectsSelection(5, QModelIndex())); |
|
2169 |
QVERIFY(!selected.columnIntersectsSelection(0, QModelIndex())); |
|
2170 |
QVERIFY(!selected.columnIntersectsSelection(2, QModelIndex())); |
|
2171 |
QVERIFY(!selected.columnIntersectsSelection(3, QModelIndex())); |
|
2172 |
QVERIFY(!selected.columnIntersectsSelection(5, QModelIndex())); |
|
2173 |
selected.select(m.index(2, 0), QItemSelectionModel::Select | QItemSelectionModel::Rows); |
|
2174 |
QVERIFY(!selected.rowIntersectsSelection(0, QModelIndex())); |
|
2175 |
QVERIFY( selected.rowIntersectsSelection(2, QModelIndex())); |
|
2176 |
QVERIFY(!selected.rowIntersectsSelection(3, QModelIndex())); |
|
2177 |
QVERIFY(!selected.rowIntersectsSelection(5, QModelIndex())); |
|
2178 |
QVERIFY(!selected.columnIntersectsSelection(0, QModelIndex())); |
|
2179 |
QVERIFY( selected.columnIntersectsSelection(2, QModelIndex())); |
|
2180 |
QVERIFY( selected.columnIntersectsSelection(3, QModelIndex())); |
|
2181 |
QVERIFY(!selected.columnIntersectsSelection(5, QModelIndex())); |
|
2182 |
selected.select(m.index(0, 5), QItemSelectionModel::Select | QItemSelectionModel::Columns); |
|
2183 |
QVERIFY(!selected.rowIntersectsSelection(0, QModelIndex())); |
|
2184 |
QVERIFY( selected.rowIntersectsSelection(2, QModelIndex())); |
|
2185 |
QVERIFY(!selected.rowIntersectsSelection(3, QModelIndex())); |
|
2186 |
QVERIFY(!selected.rowIntersectsSelection(5, QModelIndex())); |
|
2187 |
QVERIFY(!selected.columnIntersectsSelection(0, QModelIndex())); |
|
2188 |
QVERIFY( selected.columnIntersectsSelection(2, QModelIndex())); |
|
2189 |
QVERIFY( selected.columnIntersectsSelection(3, QModelIndex())); |
|
2190 |
QVERIFY(!selected.columnIntersectsSelection(5, QModelIndex())); |
|
2191 |
} |
|
2192 |
||
2193 |
void tst_QItemSelectionModel::task232634_childrenDeselectionSignal() |
|
2194 |
{ |
|
2195 |
QStandardItemModel model; |
|
2196 |
||
2197 |
QStandardItem *parentItem = model.invisibleRootItem(); |
|
2198 |
for (int i = 0; i < 4; ++i) { |
|
2199 |
QStandardItem *item = new QStandardItem(QString("item %0").arg(i)); |
|
2200 |
parentItem->appendRow(item); |
|
2201 |
parentItem = item; |
|
2202 |
} |
|
2203 |
||
2204 |
QModelIndex root = model.index(0,0); |
|
2205 |
QModelIndex par = root.child(0,0); |
|
2206 |
QModelIndex sel = par.child(0,0); |
|
2207 |
||
2208 |
QItemSelectionModel selectionModel(&model); |
|
2209 |
selectionModel.select(sel, QItemSelectionModel::SelectCurrent); |
|
2210 |
||
2211 |
QSignalSpy deselectSpy(&selectionModel, SIGNAL(selectionChanged(const QItemSelection& , const QItemSelection&))); |
|
2212 |
model.removeRows(0, 1, root); |
|
2213 |
QVERIFY(deselectSpy.count() == 1); |
|
2214 |
||
2215 |
// More testing stress for the patch. |
|
2216 |
model.clear(); |
|
2217 |
selectionModel.clear(); |
|
2218 |
||
2219 |
parentItem = model.invisibleRootItem(); |
|
2220 |
for (int i = 0; i < 2; ++i) { |
|
2221 |
QStandardItem *item = new QStandardItem(QString("item %0").arg(i)); |
|
2222 |
parentItem->appendRow(item); |
|
2223 |
} |
|
2224 |
for (int i = 0; i < 2; ++i) { |
|
2225 |
parentItem = model.invisibleRootItem()->child(i, 0); |
|
2226 |
for (int j = 0; j < 2; ++j) { |
|
2227 |
QStandardItem *item = new QStandardItem(QString("item %0.%1").arg(i).arg(j)); |
|
2228 |
parentItem->appendRow(item); |
|
2229 |
} |
|
2230 |
} |
|
2231 |
||
2232 |
sel = model.index(0, 0).child(0, 0); |
|
2233 |
selectionModel.select(sel, QItemSelectionModel::Select); |
|
2234 |
QModelIndex sel2 = model.index(1, 0).child(0, 0); |
|
2235 |
selectionModel.select(sel2, QItemSelectionModel::Select); |
|
2236 |
||
2237 |
QVERIFY(selectionModel.selection().contains(sel)); |
|
2238 |
QVERIFY(selectionModel.selection().contains(sel2)); |
|
2239 |
deselectSpy.clear(); |
|
2240 |
model.removeRow(0, model.index(0, 0)); |
|
2241 |
QVERIFY(deselectSpy.count() == 1); |
|
2242 |
QVERIFY(!selectionModel.selection().contains(sel)); |
|
2243 |
QVERIFY(selectionModel.selection().contains(sel2)); |
|
2244 |
} |
|
2245 |
||
2246 |
void tst_QItemSelectionModel::task260134_layoutChangedWithAllSelected() |
|
2247 |
{ |
|
2248 |
QStringListModel model( QStringList() << "foo" << "bar" << "foo2"); |
|
2249 |
QSortFilterProxyModel proxy; |
|
2250 |
proxy.setSourceModel(&model); |
|
2251 |
QItemSelectionModel selection(&proxy); |
|
2252 |
||
2253 |
||
2254 |
QCOMPARE(model.rowCount(), 3); |
|
2255 |
QCOMPARE(proxy.rowCount(), 3); |
|
2256 |
proxy.setFilterRegExp( QRegExp("f")); |
|
2257 |
QCOMPARE(proxy.rowCount(), 2); |
|
2258 |
||
2259 |
QList<QPersistentModelIndex> indexList; |
|
2260 |
indexList << proxy.index(0,0) << proxy.index(1,0); |
|
2261 |
selection.select( QItemSelection(indexList.first(), indexList.last()), QItemSelectionModel::Select); |
|
2262 |
||
2263 |
//let's check the selection hasn't changed |
|
2264 |
QCOMPARE(selection.selectedIndexes().count(), indexList.count()); |
|
2265 |
foreach(QPersistentModelIndex index, indexList) |
|
2266 |
QVERIFY(selection.isSelected(index)); |
|
2267 |
||
2268 |
proxy.setFilterRegExp(QRegExp()); |
|
2269 |
QCOMPARE(proxy.rowCount(), 3); |
|
2270 |
||
2271 |
//let's check the selection hasn't changed |
|
2272 |
QCOMPARE(selection.selectedIndexes().count(), indexList.count()); |
|
2273 |
foreach(QPersistentModelIndex index, indexList) |
|
2274 |
QVERIFY(selection.isSelected(index)); |
|
2275 |
} |
|
2276 |
||
2277 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2278 |
void tst_QItemSelectionModel::QTBUG5671_layoutChangedWithAllSelected() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2279 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2280 |
struct MyFilterModel : public QSortFilterProxyModel |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2281 |
{ // Override sort filter proxy to remove even numbered rows. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2282 |
bool filtering; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2283 |
virtual bool filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2284 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2285 |
return !filtering || !( source_row & 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2286 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2287 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2288 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2289 |
//same as task260134_layoutChangedWithAllSelected but with a sightly bigger model |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2290 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2291 |
enum { cNumRows=30, cNumCols=20 }; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2292 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2293 |
QStandardItemModel model(cNumRows, cNumCols); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2294 |
MyFilterModel proxy; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2295 |
proxy.filtering = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2296 |
proxy.setSourceModel(&model); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2297 |
QItemSelectionModel selection(&proxy); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2298 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2299 |
// Populate the tree view. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2300 |
for (unsigned int i = 0; i < cNumCols; i++) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2301 |
model.setHeaderData( i, Qt::Horizontal, QString::fromLatin1("Column %1").arg(i)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2302 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2303 |
for (unsigned int r = 0; r < cNumRows; r++) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2304 |
for (unsigned int c = 0; c < cNumCols; c++) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2305 |
model.setData(model.index(r, c, QModelIndex()), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2306 |
QString::fromLatin1("r:%1/c:%2").arg(r, c)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2307 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2308 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2309 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2310 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2311 |
QCOMPARE(model.rowCount(), int(cNumRows)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2312 |
QCOMPARE(proxy.rowCount(), int(cNumRows/2)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2313 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2314 |
selection.select( QItemSelection(proxy.index(0,0), proxy.index(proxy.rowCount() - 1, proxy.columnCount() - 1)), QItemSelectionModel::Select); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2315 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2316 |
QList<QPersistentModelIndex> indexList; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2317 |
foreach(const QModelIndex &id, selection.selectedIndexes()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2318 |
indexList << id; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2319 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2320 |
proxy.filtering = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2321 |
proxy.invalidate(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2322 |
QCOMPARE(proxy.rowCount(), int(cNumRows)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2323 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2324 |
//let's check the selection hasn't changed |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2325 |
QCOMPARE(selection.selectedIndexes().count(), indexList.count()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2326 |
foreach(QPersistentModelIndex index, indexList) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2327 |
QVERIFY(selection.isSelected(index)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2328 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2329 |
|
0 | 2330 |
QTEST_MAIN(tst_QItemSelectionModel) |
2331 |
#include "tst_qitemselectionmodel.moc" |