1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the QtDocGallery module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | //TESTED_COMPONENT=src/gallery |
43 | |
44 | #include <qgalleryquerymodel.h> |
45 | |
46 | #include <qabstractgallery.h> |
47 | #include <qgalleryqueryrequest.h> |
48 | #include <qgalleryresultset.h> |
49 | |
50 | #include <QtCore/qpointer.h> |
51 | |
52 | #include <QtTest/QtTest> |
53 | |
54 | Q_DECLARE_METATYPE(QModelIndex) |
55 | |
56 | QT_USE_DOCGALLERY_NAMESPACE |
57 | |
58 | Q_DECLARE_METATYPE(QGalleryAbstractRequest::State) |
59 | |
60 | class QtTestGallery; |
61 | |
62 | class tst_QGalleryQueryModel : public QObject |
63 | { |
64 | Q_OBJECT |
65 | public Q_SLOTS: |
66 | void initTestCase(); |
67 | |
68 | private Q_SLOTS: |
69 | void execute(); |
70 | void sortPropertyNames(); |
71 | void autoUpdate(); |
72 | void offset(); |
73 | void limit(); |
74 | void rootType(); |
75 | void rootItem(); |
76 | void scope(); |
77 | void filter(); |
78 | void indexes(); |
79 | void data(); |
80 | void flags(); |
81 | void headerData(); |
82 | void addColumn(); |
83 | void insertColumn(); |
84 | void removeColumn(); |
85 | void setRoleProperties(); |
86 | void itemsInserted(); |
87 | void itemsRemoved(); |
88 | void itemsMoved(); |
89 | void metaDataChanged(); |
90 | void invalidIndex(); |
91 | void hierarchy(); |
92 | void setGallery(); |
93 | void galleryChanged(); |
94 | void errorChanged(); |
95 | |
96 | private: |
97 | void populateGallery(QtTestGallery *gallery) const; |
98 | |
99 | QHash<int, QString> albumProperties; |
100 | QHash<int, QString> titleProperties; |
101 | QHash<int, QString> durationProperties; |
102 | QHash<int, QString> ratingProperties; |
103 | QHash<int, QString> turtleProperties; |
104 | }; |
105 | |
106 | class QtTestResultSet : public QGalleryResultSet |
107 | { |
108 | Q_OBJECT |
109 | public: |
110 | struct Row |
111 | { |
112 | Row() {} |
113 | Row(const QVariant &itemId, |
114 | const QUrl &itemUrl, |
115 | const QString &itemType, |
116 | const QHash<QString, QVariant> &metaData) |
117 | : itemId(itemId) |
118 | , itemUrl(itemUrl) |
119 | , itemType(itemType) |
120 | , metaData(metaData) {} |
121 | QVariant itemId; |
122 | QUrl itemUrl; |
123 | QString itemType; |
124 | QHash<QString, QVariant> metaData; |
125 | }; |
126 | |
127 | QtTestResultSet( |
128 | QGalleryAbstractRequest::State state, |
129 | int error, |
130 | const QString &errorString, |
131 | const QHash<QString, QGalleryProperty::Attributes> &propertyAttributes, |
132 | const QVector<Row> &rows) |
133 | : m_propertyNames(propertyAttributes.keys()) |
134 | , m_propertyAttributes(propertyAttributes) |
135 | , m_rows(rows) |
136 | , m_currentIndex(-1) |
137 | , m_insertIndex(0) |
138 | , m_insertCount(0) |
139 | { |
140 | if (error != QGalleryAbstractRequest::NoError) |
141 | QGalleryAbstractResponse::error(error, errorString); |
142 | else if (state == QGalleryAbstractRequest::Finished) |
143 | finish(); |
144 | else if (state == QGalleryAbstractRequest::Idle) |
145 | finish(idle: true); |
146 | } |
147 | |
148 | QStringList propertyNames() const { return m_propertyNames; } |
149 | |
150 | int propertyKey(const QString &propertyName) const { |
151 | return m_propertyNames.indexOf(t: propertyName); } |
152 | |
153 | QGalleryProperty::Attributes propertyAttributes(int key) const { |
154 | return m_propertyAttributes.value(key: m_propertyNames.value(i: key)); } |
155 | |
156 | QVariant::Type propertyType(int) const { return QVariant::Invalid; } |
157 | |
158 | int itemCount() const { return m_rows.count(); } |
159 | |
160 | int currentIndex() const { return m_currentIndex; } |
161 | bool fetch(int index) |
162 | { |
163 | emit currentIndexChanged(index: m_currentIndex = index); |
164 | emit currentItemChanged(); |
165 | |
166 | return isValid(); |
167 | } |
168 | |
169 | QVariant itemId() const { return m_rows.value(i: m_currentIndex).itemId; } |
170 | QUrl itemUrl() const { return m_rows.value(i: m_currentIndex).itemUrl; } |
171 | QString itemType() const { return m_rows.value(i: m_currentIndex).itemType; } |
172 | |
173 | QVariant metaData(int key) const { |
174 | return m_rows.value(i: m_currentIndex).metaData.value(key: m_propertyNames.at(i: key)); } |
175 | |
176 | bool setMetaData(int key, const QVariant &value) |
177 | { |
178 | if (isValid() && key >= 0) { |
179 | const QString propertyName = m_propertyNames.at(i: key); |
180 | |
181 | if (m_propertyAttributes.value(key: propertyName) & QGalleryProperty::CanWrite) { |
182 | m_rows[m_currentIndex].metaData[propertyName] = value; |
183 | |
184 | emit metaDataChanged(index: m_currentIndex, count: 1, keys: QList<int>() << key); |
185 | |
186 | return true; |
187 | } |
188 | } |
189 | return false; |
190 | } |
191 | |
192 | void beginInsertRows(int index) { m_insertIndex = index; m_insertCount = 0; } |
193 | void addRow() |
194 | { |
195 | m_rows.insert(i: m_insertIndex + m_insertCount++, t: Row()); |
196 | } |
197 | void addRow( |
198 | const QString &itemId, |
199 | const QUrl &itemUrl, |
200 | const QString &itemType, |
201 | const QHash<QString, QVariant> &metaData) |
202 | { |
203 | m_rows.insert(i: m_insertIndex + m_insertCount++, t: Row(itemId, itemUrl, itemType, metaData)); |
204 | } |
205 | void endInsertRows() { emit itemsInserted(index: m_insertIndex, count: m_insertCount); } |
206 | |
207 | void removeRows(int index, int count) { |
208 | m_rows.remove(i: index, n: count); emit itemsRemoved(index, count); } |
209 | |
210 | using QGalleryResultSet::metaDataChanged; |
211 | using QGalleryResultSet::itemsMoved; |
212 | |
213 | private: |
214 | QStringList m_propertyNames; |
215 | const QHash<QString, QGalleryProperty::Attributes> m_propertyAttributes; |
216 | QVector<Row> m_rows; |
217 | int m_currentIndex; |
218 | int m_insertIndex; |
219 | int m_insertCount; |
220 | }; |
221 | |
222 | class QtTestGallery : public QAbstractGallery |
223 | { |
224 | public: |
225 | QtTestGallery() |
226 | : m_state(QGalleryAbstractRequest::Finished) |
227 | , m_error(QGalleryAbstractRequest::NoError) |
228 | { |
229 | } |
230 | |
231 | bool isRequestSupported(QGalleryAbstractRequest::RequestType) const { return true; } |
232 | |
233 | void setPropertyAttributes(const QHash<QString, QGalleryProperty::Attributes> &attributes) |
234 | { |
235 | m_propertyAttributes = attributes; |
236 | } |
237 | |
238 | void setState(QGalleryAbstractRequest::State state) { m_state = state; } |
239 | void setError(int error, const QString &errorString) { |
240 | m_error = error; m_errorString = errorString; } |
241 | |
242 | void addRow() |
243 | { |
244 | m_rows.append(t: QtTestResultSet::Row()); |
245 | } |
246 | |
247 | void addRow( |
248 | const QVariant &itemId, |
249 | const QUrl &itemUrl, |
250 | const QString &itemType, |
251 | const QHash<QString, QVariant> &metaData) |
252 | { |
253 | m_rows.append(t: QtTestResultSet::Row(itemId, itemUrl, itemType, metaData)); |
254 | } |
255 | |
256 | QGalleryQueryRequest *request() const { return m_request; } |
257 | |
258 | protected: |
259 | QGalleryAbstractResponse *createResponse(QGalleryAbstractRequest *request) |
260 | { |
261 | m_request = qobject_cast<QGalleryQueryRequest *>(object: request); |
262 | |
263 | return new QtTestResultSet(m_state, m_error, m_errorString, m_propertyAttributes, m_rows); |
264 | } |
265 | |
266 | |
267 | private: |
268 | QHash<QString, QGalleryProperty::Attributes> m_propertyAttributes; |
269 | QVector<QtTestResultSet::Row> m_rows; |
270 | QPointer<QGalleryQueryRequest> m_request; |
271 | QGalleryAbstractRequest::State m_state; |
272 | int m_error; |
273 | QString m_errorString; |
274 | }; |
275 | |
276 | void tst_QGalleryQueryModel::initTestCase() |
277 | { |
278 | qRegisterMetaType<QModelIndex>(); |
279 | qRegisterMetaType<QGalleryAbstractRequest::State>(); |
280 | |
281 | albumProperties.insert(key: Qt::DisplayRole, value: QLatin1String("albumTitle" )); |
282 | albumProperties.insert(key: Qt::UserRole, value: QLatin1String("albumArtist" )); |
283 | albumProperties.insert(key: Qt::UserRole + 1, value: QLatin1String("albumId" )); |
284 | |
285 | titleProperties.insert(key: Qt::DisplayRole, value: QLatin1String("displayName" )); |
286 | titleProperties.insert(key: Qt::EditRole, value: QLatin1String("title" )); |
287 | |
288 | durationProperties.insert(key: Qt::DisplayRole, value: QLatin1String("duration" )); |
289 | |
290 | ratingProperties.insert(key: Qt::DisplayRole, value: QLatin1String("rating" )); |
291 | |
292 | turtleProperties.insert(key: Qt::DisplayRole, value: QLatin1String("turtle" )); |
293 | } |
294 | |
295 | void tst_QGalleryQueryModel::populateGallery(QtTestGallery *gallery) const |
296 | { |
297 | QHash<QString, QGalleryProperty::Attributes> attributes; |
298 | attributes.insert(key: QLatin1String("displayName" ), value: QGalleryProperty::CanRead); |
299 | attributes.insert(key: QLatin1String("title" ), value: QGalleryProperty::CanRead | QGalleryProperty::CanWrite); |
300 | attributes.insert(key: QLatin1String("albumTitle" ), value: QGalleryProperty::CanRead); |
301 | attributes.insert(key: QLatin1String("albumArtist" ), value: QGalleryProperty::CanRead); |
302 | attributes.insert(key: QLatin1String("albumId" ), value: QGalleryProperty::CanRead | QGalleryProperty::CanWrite); |
303 | attributes.insert(key: QLatin1String("duration" ), value: QGalleryProperty::CanRead); |
304 | attributes.insert(key: QLatin1String("rating" ), value: QGalleryProperty::CanRead | QGalleryProperty::CanWrite); |
305 | gallery->setPropertyAttributes(attributes); |
306 | |
307 | { |
308 | QHash<QString, QVariant> metaData; |
309 | metaData.insert(key: QLatin1String("displayName" ), value: QLatin1String("Interlude" )); |
310 | metaData.insert(key: QLatin1String("title" ), value: QLatin1String("Interlude" )); |
311 | metaData.insert(key: QLatin1String("albumTitle" ), value: QLatin1String("Greatest Hits" )); |
312 | metaData.insert(key: QLatin1String("albumArtist" ), value: QLatin1String("Self Titled" )); |
313 | metaData.insert(key: QLatin1String("albumId" ), value: QLatin1String("album:SelfTitled:GreatestHits" )); |
314 | metaData.insert(key: QLatin1String("duration" ), value: 120100); |
315 | metaData.insert(key: QLatin1String("rating" ), value: 4); |
316 | |
317 | gallery->addRow( |
318 | itemId: 3, |
319 | itemUrl: QUrl(QLatin1String("file:///music/interlude.mp3" )), |
320 | itemType: QLatin1String("Audio" ), |
321 | metaData); |
322 | } { |
323 | QHash<QString, QVariant> metaData; |
324 | metaData.insert(key: QLatin1String("displayName" ), value: QLatin1String("beep.wav" )); |
325 | metaData.insert(key: QLatin1String("duration" ), value: 600); |
326 | |
327 | gallery->addRow( |
328 | itemId: 45, |
329 | itemUrl: QUrl(QLatin1String("file:///sounds/beep.wav" )), |
330 | itemType: QLatin1String("Audio" ), |
331 | metaData); |
332 | } |
333 | } |
334 | |
335 | void tst_QGalleryQueryModel::execute() |
336 | { |
337 | QtTestGallery gallery; |
338 | |
339 | QGalleryQueryModel model(&gallery); |
340 | |
341 | QSignalSpy finishedSpy(&model, SIGNAL(finished())); |
342 | QSignalSpy canceledSpy(&model, SIGNAL(canceled())); |
343 | QSignalSpy errorSpy(&model, SIGNAL(error(int,QString))); |
344 | QSignalSpy stateSpy(&model, SIGNAL(stateChanged(QGalleryAbstractRequest::State))); |
345 | |
346 | model.execute(); |
347 | QCOMPARE(model.state(), QGalleryAbstractRequest::Finished); |
348 | QCOMPARE(model.error(), int(QGalleryAbstractRequest::NoError)); |
349 | QCOMPARE(finishedSpy.count(), 1); |
350 | QCOMPARE(canceledSpy.count(), 0); |
351 | QCOMPARE(errorSpy.count(), 0); |
352 | QCOMPARE(stateSpy.count(), 1); |
353 | QCOMPARE(stateSpy.last().value(0).value<QGalleryAbstractRequest::State>(), model.state()); |
354 | |
355 | gallery.setState(QGalleryAbstractRequest::Active); |
356 | model.execute(); |
357 | QCOMPARE(model.state(), QGalleryAbstractRequest::Active); |
358 | QCOMPARE(model.error(), int(QGalleryAbstractRequest::NoError)); |
359 | QCOMPARE(finishedSpy.count(), 1); |
360 | QCOMPARE(canceledSpy.count(), 0); |
361 | QCOMPARE(errorSpy.count(), 0); |
362 | QCOMPARE(stateSpy.count(), 2); |
363 | QCOMPARE(stateSpy.last().value(0).value<QGalleryAbstractRequest::State>(), model.state()); |
364 | |
365 | model.cancel(); |
366 | QCOMPARE(model.state(), QGalleryAbstractRequest::Canceled); |
367 | QCOMPARE(model.error(), int(QGalleryAbstractRequest::NoError)); |
368 | QCOMPARE(finishedSpy.count(), 1); |
369 | QCOMPARE(canceledSpy.count(), 1); |
370 | QCOMPARE(errorSpy.count(), 0); |
371 | QCOMPARE(stateSpy.count(), 3); |
372 | QCOMPARE(stateSpy.last().value(0).value<QGalleryAbstractRequest::State>(), model.state()); |
373 | |
374 | gallery.setError(error: 120, errorString: QLatin1String("bad connection" )); |
375 | model.execute(); |
376 | QCOMPARE(model.state(), QGalleryAbstractRequest::Error); |
377 | QCOMPARE(model.error(), 120); |
378 | QCOMPARE(model.errorString(), QLatin1String("bad connection" )); |
379 | QCOMPARE(finishedSpy.count(), 1); |
380 | QCOMPARE(canceledSpy.count(), 1); |
381 | QCOMPARE(errorSpy.count(), 1); |
382 | QCOMPARE(stateSpy.count(), 4); |
383 | QCOMPARE(errorSpy.last().value(0).toInt(), model.error()); |
384 | QCOMPARE(errorSpy.last().value(1).toString(), model.errorString()); |
385 | QCOMPARE(stateSpy.last().value(0).value<QGalleryAbstractRequest::State>(), model.state()); |
386 | |
387 | model.clear(); |
388 | QCOMPARE(model.state(), QGalleryAbstractRequest::Inactive); |
389 | QCOMPARE(model.error(), int(QGalleryAbstractRequest::NoError)); |
390 | QCOMPARE(finishedSpy.count(), 1); |
391 | QCOMPARE(canceledSpy.count(), 1); |
392 | QCOMPARE(errorSpy.count(), 1); |
393 | QCOMPARE(stateSpy.count(), 5); |
394 | } |
395 | |
396 | void tst_QGalleryQueryModel::sortPropertyNames() |
397 | { |
398 | const QStringList propertyNames = QStringList() |
399 | << QLatin1String("-rating" ) |
400 | << QLatin1String("+duration" ); |
401 | |
402 | QGalleryQueryModel model; |
403 | |
404 | QSignalSpy spy(&model, SIGNAL(sortPropertyNamesChanged())); |
405 | |
406 | QCOMPARE(model.sortPropertyNames(), QStringList()); |
407 | |
408 | model.setSortPropertyNames(QStringList()); |
409 | QCOMPARE(model.sortPropertyNames(), QStringList()); |
410 | QCOMPARE(spy.count(), 0); |
411 | |
412 | model.setSortPropertyNames(propertyNames); |
413 | QCOMPARE(model.sortPropertyNames(), propertyNames); |
414 | QCOMPARE(spy.count(), 1); |
415 | |
416 | model.setSortPropertyNames(propertyNames); |
417 | QCOMPARE(model.sortPropertyNames(), propertyNames); |
418 | QCOMPARE(spy.count(), 1); |
419 | |
420 | model.setSortPropertyNames(QStringList()); |
421 | QCOMPARE(model.sortPropertyNames(), QStringList()); |
422 | QCOMPARE(spy.count(), 2); |
423 | } |
424 | |
425 | void tst_QGalleryQueryModel::autoUpdate() |
426 | { |
427 | QGalleryQueryModel model; |
428 | |
429 | QSignalSpy spy(&model, SIGNAL(autoUpdateChanged())); |
430 | |
431 | QCOMPARE(model.autoUpdate(), false); |
432 | |
433 | model.setAutoUpdate(false); |
434 | QCOMPARE(model.autoUpdate(), false); |
435 | QCOMPARE(spy.count(), 0); |
436 | |
437 | model.setAutoUpdate(true); |
438 | QCOMPARE(model.autoUpdate(), true); |
439 | QCOMPARE(spy.count(), 1); |
440 | |
441 | model.setAutoUpdate(true); |
442 | QCOMPARE(model.autoUpdate(), true); |
443 | QCOMPARE(spy.count(), 1); |
444 | |
445 | model.setAutoUpdate(false); |
446 | QCOMPARE(model.autoUpdate(), false); |
447 | QCOMPARE(spy.count(), 2); |
448 | } |
449 | |
450 | void tst_QGalleryQueryModel::offset() |
451 | { |
452 | QGalleryQueryModel model; |
453 | |
454 | QSignalSpy spy(&model, SIGNAL(offsetChanged())); |
455 | |
456 | QCOMPARE(model.offset(), 0); |
457 | |
458 | model.setOffset(0); |
459 | QCOMPARE(model.offset(), 0); |
460 | QCOMPARE(spy.count(), 0); |
461 | |
462 | model.setOffset(-45); |
463 | QCOMPARE(model.offset(), 0); |
464 | QCOMPARE(spy.count(), 0); |
465 | |
466 | model.setOffset(32); |
467 | QCOMPARE(model.offset(), 32); |
468 | QCOMPARE(spy.count(), 1); |
469 | |
470 | model.setOffset(32); |
471 | QCOMPARE(model.offset(), 32); |
472 | QCOMPARE(spy.count(), 1); |
473 | |
474 | model.setOffset(-45); |
475 | QCOMPARE(model.offset(), 0); |
476 | QCOMPARE(spy.count(), 2); |
477 | } |
478 | |
479 | void tst_QGalleryQueryModel::limit() |
480 | { |
481 | QGalleryQueryModel model; |
482 | |
483 | QSignalSpy spy(&model, SIGNAL(limitChanged())); |
484 | |
485 | QCOMPARE(model.limit(), 0); |
486 | |
487 | model.setLimit(0); |
488 | QCOMPARE(model.limit(), 0); |
489 | QCOMPARE(spy.count(), 0); |
490 | |
491 | model.setLimit(-21); |
492 | QCOMPARE(model.limit(), 0); |
493 | QCOMPARE(spy.count(), 0); |
494 | |
495 | model.setLimit(102); |
496 | QCOMPARE(model.limit(), 102); |
497 | QCOMPARE(spy.count(), 1); |
498 | |
499 | model.setLimit(102); |
500 | QCOMPARE(model.limit(), 102); |
501 | QCOMPARE(spy.count(), 1); |
502 | |
503 | model.setLimit(-21); |
504 | QCOMPARE(model.limit(), 0); |
505 | QCOMPARE(spy.count(), 2); |
506 | } |
507 | |
508 | void tst_QGalleryQueryModel::rootType() |
509 | { |
510 | const QString itemType = QLatin1String("Audio" ); |
511 | |
512 | QGalleryQueryModel model; |
513 | |
514 | QSignalSpy spy(&model, SIGNAL(rootTypeChanged())); |
515 | |
516 | QCOMPARE(model.rootType(), QString()); |
517 | |
518 | model.setRootType(QString()); |
519 | QCOMPARE(model.rootType(), QString()); |
520 | QCOMPARE(spy.count(), 0); |
521 | |
522 | model.setRootType(itemType); |
523 | QCOMPARE(model.rootType(), itemType); |
524 | QCOMPARE(spy.count(), 1); |
525 | |
526 | model.setRootType(itemType); |
527 | QCOMPARE(model.rootType(), itemType); |
528 | QCOMPARE(spy.count(), 1); |
529 | |
530 | model.setRootType(QString()); |
531 | QCOMPARE(model.rootType(), QString()); |
532 | QCOMPARE(spy.count(), 2); |
533 | } |
534 | |
535 | void tst_QGalleryQueryModel::rootItem() |
536 | { |
537 | QGalleryQueryModel model; |
538 | |
539 | QSignalSpy spy(&model, SIGNAL(rootItemChanged())); |
540 | |
541 | QCOMPARE(model.rootItem(), QVariant()); |
542 | |
543 | model.setRootItem(QVariant()); |
544 | QCOMPARE(model.rootItem(), QVariant()); |
545 | QCOMPARE(spy.count(), 0); |
546 | |
547 | model.setRootItem(76); |
548 | QCOMPARE(model.rootItem(), QVariant(76)); |
549 | QCOMPARE(spy.count(), 1); |
550 | |
551 | model.setRootItem(76); |
552 | QCOMPARE(model.rootItem(), QVariant(76)); |
553 | QCOMPARE(spy.count(), 1); |
554 | |
555 | model.setRootItem(QLatin1String("65" )); |
556 | QCOMPARE(model.rootItem(), QVariant(QLatin1String("65" ))); |
557 | QCOMPARE(spy.count(), 2); |
558 | |
559 | model.setRootItem(QLatin1String("65" )); |
560 | QCOMPARE(model.rootItem(), QVariant(QLatin1String("65" ))); |
561 | QCOMPARE(spy.count(), 2); |
562 | |
563 | model.setRootItem(QVariant()); |
564 | QCOMPARE(model.rootItem(), QVariant()); |
565 | QCOMPARE(spy.count(), 3); |
566 | } |
567 | |
568 | void tst_QGalleryQueryModel::scope() |
569 | { |
570 | QGalleryQueryModel model; |
571 | |
572 | QSignalSpy spy(&model, SIGNAL(scopeChanged())); |
573 | |
574 | QCOMPARE(model.scope(), QGalleryQueryRequest::AllDescendants); |
575 | |
576 | model.setScope(QGalleryQueryRequest::AllDescendants); |
577 | QCOMPARE(model.scope(), QGalleryQueryRequest::AllDescendants); |
578 | QCOMPARE(spy.count(), 0); |
579 | |
580 | model.setScope(QGalleryQueryRequest::DirectDescendants); |
581 | QCOMPARE(model.scope(), QGalleryQueryRequest::DirectDescendants); |
582 | QCOMPARE(spy.count(), 1); |
583 | |
584 | model.setScope(QGalleryQueryRequest::DirectDescendants); |
585 | QCOMPARE(model.scope(), QGalleryQueryRequest::DirectDescendants); |
586 | QCOMPARE(spy.count(), 1); |
587 | |
588 | model.setScope(QGalleryQueryRequest::AllDescendants); |
589 | QCOMPARE(model.scope(), QGalleryQueryRequest::AllDescendants); |
590 | QCOMPARE(spy.count(), 2); |
591 | } |
592 | |
593 | void tst_QGalleryQueryModel::filter() |
594 | { |
595 | const QGalleryFilter filter = QGalleryMetaDataFilter( |
596 | QLatin1String("rating" ), 3, QGalleryFilter::GreaterThan); |
597 | |
598 | QGalleryQueryModel model; |
599 | |
600 | QSignalSpy spy(&model, SIGNAL(filterChanged())); |
601 | |
602 | QCOMPARE(model.filter(), QGalleryFilter()); |
603 | |
604 | model.setFilter(QGalleryFilter()); |
605 | QCOMPARE(model.filter(), QGalleryFilter()); |
606 | QCOMPARE(spy.count(), 0); |
607 | |
608 | model.setFilter(filter); |
609 | QCOMPARE(model.filter(), filter); |
610 | QCOMPARE(spy.count(), 1); |
611 | |
612 | model.setFilter(filter); |
613 | QCOMPARE(model.filter(), filter); |
614 | QCOMPARE(spy.count(), 1); |
615 | |
616 | model.setFilter(QGalleryFilter()); |
617 | QCOMPARE(model.filter(), QGalleryFilter()); |
618 | QCOMPARE(spy.count(), 2); |
619 | } |
620 | |
621 | void tst_QGalleryQueryModel::indexes() |
622 | { |
623 | QtTestGallery gallery; |
624 | populateGallery(gallery: &gallery); |
625 | |
626 | QGalleryQueryModel model(&gallery); |
627 | model.addColumn(properties: albumProperties); |
628 | model.addColumn(properties: titleProperties); |
629 | model.addColumn(property: QLatin1String("duration" ), role: Qt::DisplayRole); |
630 | model.addColumn(property: QLatin1String("rating" ), role: Qt::DisplayRole); |
631 | model.addColumn(property: QLatin1String("turtle" ), role: Qt::DisplayRole); |
632 | |
633 | QSignalSpy insertSpy(&model, SIGNAL(rowsInserted(QModelIndex,int,int))); |
634 | QSignalSpy removeSpy(&model, SIGNAL(rowsRemoved(QModelIndex,int,int))); |
635 | |
636 | QCOMPARE(model.rowCount(), 0); |
637 | QCOMPARE(model.columnCount(), 5); |
638 | |
639 | QCOMPARE(model.index(-1, -1).isValid(), false); |
640 | QCOMPARE(model.index(-1, 0).isValid(), false); |
641 | QCOMPARE(model.index(-1, 2).isValid(), false); |
642 | QCOMPARE(model.index(-1, 3).isValid(), false); |
643 | QCOMPARE(model.index(-1, 4).isValid(), false); |
644 | QCOMPARE(model.index(-1, 5).isValid(), false); |
645 | QCOMPARE(model.index( 0, -1).isValid(), false); |
646 | QCOMPARE(model.index( 0, 0).isValid(), false); |
647 | QCOMPARE(model.index( 0, 2).isValid(), false); |
648 | QCOMPARE(model.index( 0, 3).isValid(), false); |
649 | QCOMPARE(model.index( 0, 4).isValid(), false); |
650 | QCOMPARE(model.index( 0, 5).isValid(), false); |
651 | QCOMPARE(model.index( 1, -1).isValid(), false); |
652 | QCOMPARE(model.index( 1, 0).isValid(), false); |
653 | QCOMPARE(model.index( 1, 2).isValid(), false); |
654 | QCOMPARE(model.index( 1, 3).isValid(), false); |
655 | QCOMPARE(model.index( 1, 4).isValid(), false); |
656 | QCOMPARE(model.index( 1, 5).isValid(), false); |
657 | QCOMPARE(model.index( 2, -1).isValid(), false); |
658 | QCOMPARE(model.index( 2, 0).isValid(), false); |
659 | QCOMPARE(model.index( 2, 2).isValid(), false); |
660 | QCOMPARE(model.index( 2, 3).isValid(), false); |
661 | QCOMPARE(model.index( 2, 4).isValid(), false); |
662 | QCOMPARE(model.index( 2, 5).isValid(), false); |
663 | |
664 | model.execute(); |
665 | |
666 | QCOMPARE(model.rowCount(), 2); |
667 | QCOMPARE(model.columnCount(), 5); |
668 | |
669 | QCOMPARE(insertSpy.count(), 1); |
670 | QCOMPARE(insertSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
671 | QCOMPARE(insertSpy.last().at(1).toInt(), 0); |
672 | QCOMPARE(insertSpy.last().at(2).toInt(), 1); |
673 | |
674 | QCOMPARE(model.index(-1, -1).isValid(), false); |
675 | QCOMPARE(model.index(-1, 0).isValid(), false); |
676 | QCOMPARE(model.index(-1, 2).isValid(), false); |
677 | QCOMPARE(model.index(-1, 3).isValid(), false); |
678 | QCOMPARE(model.index(-1, 4).isValid(), false); |
679 | QCOMPARE(model.index(-1, 5).isValid(), false); |
680 | QCOMPARE(model.index( 0, -1).isValid(), false); |
681 | QCOMPARE(model.index( 0, 0).isValid(), true); |
682 | QCOMPARE(model.index( 0, 2).isValid(), true); |
683 | QCOMPARE(model.index( 0, 3).isValid(), true); |
684 | QCOMPARE(model.index( 0, 4).isValid(), true); |
685 | QCOMPARE(model.index( 0, 5).isValid(), false); |
686 | QCOMPARE(model.index( 1, -1).isValid(), false); |
687 | QCOMPARE(model.index( 1, 0).isValid(), true); |
688 | QCOMPARE(model.index( 1, 2).isValid(), true); |
689 | QCOMPARE(model.index( 1, 3).isValid(), true); |
690 | QCOMPARE(model.index( 1, 4).isValid(), true); |
691 | QCOMPARE(model.index( 1, 5).isValid(), false); |
692 | QCOMPARE(model.index( 2, -1).isValid(), false); |
693 | QCOMPARE(model.index( 2, 0).isValid(), false); |
694 | QCOMPARE(model.index( 2, 2).isValid(), false); |
695 | QCOMPARE(model.index( 2, 3).isValid(), false); |
696 | QCOMPARE(model.index( 2, 4).isValid(), false); |
697 | QCOMPARE(model.index( 2, 5).isValid(), false); |
698 | |
699 | model.clear(); |
700 | |
701 | QCOMPARE(model.rowCount(), 0); |
702 | QCOMPARE(model.columnCount(), 5); |
703 | |
704 | QCOMPARE(removeSpy.count(), 1); |
705 | QCOMPARE(removeSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
706 | QCOMPARE(removeSpy.last().at(1).toInt(), 0); |
707 | QCOMPARE(removeSpy.last().at(2).toInt(), 1); |
708 | |
709 | QCOMPARE(model.index(-1, -1).isValid(), false); |
710 | QCOMPARE(model.index(-1, 0).isValid(), false); |
711 | QCOMPARE(model.index(-1, 2).isValid(), false); |
712 | QCOMPARE(model.index(-1, 3).isValid(), false); |
713 | QCOMPARE(model.index(-1, 4).isValid(), false); |
714 | QCOMPARE(model.index(-1, 5).isValid(), false); |
715 | QCOMPARE(model.index( 0, -1).isValid(), false); |
716 | QCOMPARE(model.index( 0, 0).isValid(), false); |
717 | QCOMPARE(model.index( 0, 2).isValid(), false); |
718 | QCOMPARE(model.index( 0, 3).isValid(), false); |
719 | QCOMPARE(model.index( 0, 4).isValid(), false); |
720 | QCOMPARE(model.index( 0, 5).isValid(), false); |
721 | QCOMPARE(model.index( 1, -1).isValid(), false); |
722 | QCOMPARE(model.index( 1, 0).isValid(), false); |
723 | QCOMPARE(model.index( 1, 2).isValid(), false); |
724 | QCOMPARE(model.index( 1, 3).isValid(), false); |
725 | QCOMPARE(model.index( 1, 4).isValid(), false); |
726 | QCOMPARE(model.index( 1, 5).isValid(), false); |
727 | QCOMPARE(model.index( 2, -1).isValid(), false); |
728 | QCOMPARE(model.index( 2, 0).isValid(), false); |
729 | QCOMPARE(model.index( 2, 2).isValid(), false); |
730 | QCOMPARE(model.index( 2, 3).isValid(), false); |
731 | QCOMPARE(model.index( 2, 4).isValid(), false); |
732 | QCOMPARE(model.index( 2, 5).isValid(), false); |
733 | } |
734 | |
735 | void tst_QGalleryQueryModel::data() |
736 | { |
737 | QtTestGallery gallery; |
738 | populateGallery(gallery: &gallery); |
739 | |
740 | QGalleryQueryModel model(&gallery); |
741 | model.addColumn(properties: albumProperties); |
742 | model.addColumn(properties: titleProperties); |
743 | model.addColumn(property: QLatin1String("duration" ), role: Qt::DisplayRole); |
744 | model.addColumn(property: QLatin1String("rating" ), role: Qt::DisplayRole); |
745 | model.addColumn(property: QLatin1String("turtle" ), role: Qt::DisplayRole); |
746 | model.execute(); |
747 | |
748 | QModelIndex index; |
749 | |
750 | index = model.index(row: 0, column: 0); |
751 | QCOMPARE(model.itemId(index), QVariant(3)); |
752 | QCOMPARE(model.itemUrl(index), QUrl(QLatin1String("file:///music/interlude.mp3" ))); |
753 | QCOMPARE(model.itemType(index), QString::fromLatin1("Audio" )); |
754 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(QLatin1String("Greatest Hits" ))); |
755 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
756 | QCOMPARE(index.data(Qt::UserRole), QVariant(QLatin1String("Self Titled" ))); |
757 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant(QLatin1String("album:SelfTitled:GreatestHits" ))); |
758 | |
759 | index = model.index(row: 0, column: 1); |
760 | QCOMPARE(model.itemId(index), QVariant(3)); |
761 | QCOMPARE(model.itemUrl(index), QUrl(QLatin1String("file:///music/interlude.mp3" ))); |
762 | QCOMPARE(model.itemType(index), QString::fromLatin1("Audio" )); |
763 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(QLatin1String("Interlude" ))); |
764 | QCOMPARE(index.data(Qt::EditRole), QVariant(QLatin1String("Interlude" ))); |
765 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
766 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
767 | |
768 | index = model.index(row: 0, column: 2); |
769 | QCOMPARE(model.itemId(index), QVariant(3)); |
770 | QCOMPARE(model.itemUrl(index), QUrl(QLatin1String("file:///music/interlude.mp3" ))); |
771 | QCOMPARE(model.itemType(index), QString::fromLatin1("Audio" )); |
772 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(120100)); |
773 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
774 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
775 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
776 | |
777 | index = model.index(row: 0, column: 3); |
778 | QCOMPARE(model.itemId(index), QVariant(3)); |
779 | QCOMPARE(model.itemUrl(index), QUrl(QLatin1String("file:///music/interlude.mp3" ))); |
780 | QCOMPARE(model.itemType(index), QString::fromLatin1("Audio" )); |
781 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(4)); |
782 | QCOMPARE(index.data(Qt::EditRole), QVariant(4)); |
783 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
784 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
785 | |
786 | index = model.index(row: 0, column: 4); |
787 | QCOMPARE(model.itemId(index), QVariant(3)); |
788 | QCOMPARE(model.itemUrl(index), QUrl(QLatin1String("file:///music/interlude.mp3" ))); |
789 | QCOMPARE(model.itemType(index), QString::fromLatin1("Audio" )); |
790 | QCOMPARE(index.data(Qt::DisplayRole), QVariant()); |
791 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
792 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
793 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
794 | |
795 | index = model.index(row: 1, column: 0); |
796 | QCOMPARE(model.itemId(index), QVariant(45)); |
797 | QCOMPARE(model.itemUrl(index), QUrl(QLatin1String("file:///sounds/beep.wav" ))); |
798 | QCOMPARE(model.itemType(index), QString::fromLatin1("Audio" )); |
799 | QCOMPARE(index.data(Qt::DisplayRole), QVariant()); |
800 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
801 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
802 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
803 | |
804 | QCOMPARE(model.setData(index, QLatin1String("Noise" ), Qt::DisplayRole), false); |
805 | QCOMPARE(index.data(Qt::DisplayRole), QVariant()); |
806 | |
807 | QCOMPARE(model.setData(index, QLatin1String("Noise" ), Qt::EditRole), false); |
808 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
809 | |
810 | QCOMPARE(model.setData(index, QLatin1String("Effects People" ), Qt::UserRole), false); |
811 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
812 | |
813 | QCOMPARE(model.setData(index, QLatin1String("album:EffectsPeople:Noise" ), Qt::UserRole + 1), true); |
814 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant(QLatin1String("album:EffectsPeople:Noise" ))); |
815 | |
816 | index = model.index(row: 1, column: 1); |
817 | QCOMPARE(model.itemId(index), QVariant(45)); |
818 | QCOMPARE(model.itemUrl(index), QUrl(QLatin1String("file:///sounds/beep.wav" ))); |
819 | QCOMPARE(model.itemType(index), QString::fromLatin1("Audio" )); |
820 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(QLatin1String("beep.wav" ))); |
821 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
822 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
823 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
824 | |
825 | QCOMPARE(model.setData(index, QLatin1String("Beep Sound" ), Qt::DisplayRole), false); |
826 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(QLatin1String("beep.wav" ))); |
827 | |
828 | QCOMPARE(model.setData(index, QLatin1String("Beep Sound" ), Qt::EditRole), true); |
829 | QCOMPARE(index.data(Qt::EditRole), QVariant(QLatin1String("Beep Sound" ))); |
830 | |
831 | index = model.index(row: 1, column: 2); |
832 | QCOMPARE(model.itemId(index), QVariant(45)); |
833 | QCOMPARE(model.itemUrl(index), QUrl(QLatin1String("file:///sounds/beep.wav" ))); |
834 | QCOMPARE(model.itemType(index), QString::fromLatin1("Audio" )); |
835 | QCOMPARE(index.isValid(), true); |
836 | QCOMPARE(index.flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
837 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(600)); |
838 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
839 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
840 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
841 | |
842 | QCOMPARE(model.setData(index, 1000, Qt::DisplayRole), false); |
843 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(600)); |
844 | |
845 | QCOMPARE(model.setData(index, 1000, Qt::EditRole), false); |
846 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
847 | |
848 | index = model.index(row: 1, column: 3); |
849 | QCOMPARE(model.itemId(index), QVariant(45)); |
850 | QCOMPARE(model.itemUrl(index), QUrl(QLatin1String("file:///sounds/beep.wav" ))); |
851 | QCOMPARE(model.itemType(index), QString::fromLatin1("Audio" )); |
852 | QCOMPARE(index.data(Qt::DisplayRole), QVariant()); |
853 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
854 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
855 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
856 | |
857 | QCOMPARE(model.setData(index, 2, Qt::DisplayRole), true); |
858 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(2)); |
859 | QCOMPARE(index.data(Qt::EditRole), QVariant(2)); |
860 | |
861 | QCOMPARE(model.setData(index, 5, Qt::EditRole), true); |
862 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(5)); |
863 | QCOMPARE(index.data(Qt::EditRole), QVariant(5)); |
864 | |
865 | index = model.index(row: 1, column: 4); |
866 | QCOMPARE(model.itemId(index), QVariant(45)); |
867 | QCOMPARE(model.itemUrl(index), QUrl(QLatin1String("file:///sounds/beep.wav" ))); |
868 | QCOMPARE(model.itemType(index), QString::fromLatin1("Audio" )); |
869 | QCOMPARE(index.data(Qt::DisplayRole), QVariant()); |
870 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
871 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
872 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
873 | |
874 | // Random access. |
875 | index = model.index(row: 0, column: 3); |
876 | QCOMPARE(model.setData(index, 4, Qt::DisplayRole), true); |
877 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(4)); |
878 | QCOMPARE(index.data(Qt::EditRole), QVariant(4)); |
879 | |
880 | index = model.index(row: 1, column: 0); |
881 | QCOMPARE(model.itemId(index), QVariant(45)); |
882 | |
883 | index = model.index(row: 0, column: 0); |
884 | QCOMPARE(model.itemUrl(index), QUrl(QLatin1String("file:///music/interlude.mp3" ))); |
885 | |
886 | index = model.index(row: 1, column: 0); |
887 | QCOMPARE(model.itemType(index), QString::fromLatin1("Audio" )); |
888 | } |
889 | |
890 | void tst_QGalleryQueryModel::flags() |
891 | { |
892 | QtTestGallery gallery; |
893 | populateGallery(gallery: &gallery); |
894 | |
895 | QGalleryQueryModel model(&gallery); |
896 | model.addColumn(properties: albumProperties); |
897 | model.addColumn(properties: titleProperties); |
898 | model.addColumn(property: QLatin1String("duration" ), role: Qt::DisplayRole); |
899 | model.addColumn(property: QLatin1String("rating" ), role: Qt::DisplayRole); |
900 | model.addColumn(property: QLatin1String("turtle" ), role: Qt::DisplayRole); |
901 | model.execute(); |
902 | |
903 | QCOMPARE(model.index(0, 0).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
904 | QCOMPARE(model.index(0, 1).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); |
905 | QCOMPARE(model.index(0, 2).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
906 | QCOMPARE(model.index(0, 3).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); |
907 | QCOMPARE(model.index(0, 4).flags(), Qt::ItemFlags()); |
908 | |
909 | QCOMPARE(model.index(1, 0).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled);; |
910 | QCOMPARE(model.index(1, 1).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); |
911 | QCOMPARE(model.index(1, 2).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
912 | QCOMPARE(model.index(1, 3).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); |
913 | QCOMPARE(model.index(1, 4).flags(), Qt::ItemFlags()); |
914 | } |
915 | |
916 | void tst_QGalleryQueryModel::() |
917 | { |
918 | QtTestGallery gallery; |
919 | populateGallery(gallery: &gallery); |
920 | |
921 | QGalleryQueryModel model(&gallery); |
922 | |
923 | model.addColumn(property: QLatin1String("title" )); |
924 | model.addColumn(property: QLatin1String("artist" )); |
925 | model.addColumn(property: QLatin1String("duration" )); |
926 | |
927 | QCOMPARE(model.headerData(-1, Qt::Horizontal, Qt::DisplayRole), QVariant()); |
928 | QCOMPARE(model.headerData(3, Qt::Horizontal, Qt::DisplayRole), QVariant()); |
929 | QCOMPARE(model.headerData(-1, Qt::Vertical, Qt::DisplayRole), QVariant()); |
930 | QCOMPARE(model.headerData(3, Qt::Vertical, Qt::DisplayRole), QVariant()); |
931 | QCOMPARE(model.headerData(0, Qt::Vertical, Qt::DisplayRole), QVariant()); |
932 | QCOMPARE(model.headerData(2, Qt::Vertical, Qt::DisplayRole), QVariant()); |
933 | |
934 | QCOMPARE(model.setHeaderData(-1, Qt::Horizontal, QLatin1String("Hello" ), Qt::DisplayRole), false); |
935 | QCOMPARE(model.setHeaderData(3, Qt::Horizontal, QLatin1String("Hello" ), Qt::DisplayRole), false); |
936 | QCOMPARE(model.setHeaderData(-1, Qt::Vertical, QLatin1String("Hello" ), Qt::DisplayRole), false); |
937 | QCOMPARE(model.setHeaderData(3, Qt::Vertical, QLatin1String("Hello" ), Qt::DisplayRole), false); |
938 | QCOMPARE(model.setHeaderData(0, Qt::Vertical, QLatin1String("Hello" ), Qt::DisplayRole), false); |
939 | QCOMPARE(model.setHeaderData(2, Qt::Vertical, QLatin1String("Hello" ), Qt::DisplayRole), false); |
940 | |
941 | QCOMPARE(model.setHeaderData(0, Qt::Horizontal, QLatin1String("Title" ), Qt::DisplayRole), true); |
942 | QCOMPARE(model.headerData(0, Qt::Horizontal, Qt::DisplayRole), QVariant(QLatin1String("Title" ))); |
943 | QCOMPARE(model.setHeaderData(1, Qt::Horizontal, QLatin1String("Artist" ), Qt::DisplayRole), true); |
944 | QCOMPARE(model.headerData(1, Qt::Horizontal, Qt::DisplayRole), QVariant(QLatin1String("Artist" ))); |
945 | QCOMPARE(model.setHeaderData(2, Qt::Horizontal, QLatin1String("Duration" ), Qt::DisplayRole), true); |
946 | QCOMPARE(model.headerData(2, Qt::Horizontal, Qt::DisplayRole), QVariant(QLatin1String("Duration" ))); |
947 | |
948 | QCOMPARE(model.headerData(0, Qt::Horizontal, Qt::EditRole), QVariant(QLatin1String("Title" ))); |
949 | QCOMPARE(model.setHeaderData(0, Qt::Horizontal, QLatin1String("Edit" ), Qt::EditRole), true); |
950 | QCOMPARE(model.headerData(0, Qt::Horizontal, Qt::EditRole), QVariant(QLatin1String("Edit" ))); |
951 | |
952 | QCOMPARE(model.headerData(0, Qt::Horizontal, Qt::UserRole), QVariant()); |
953 | QCOMPARE(model.setHeaderData(0, Qt::Horizontal, QLatin1String("User" ), Qt::UserRole), true); |
954 | QCOMPARE(model.headerData(0, Qt::Horizontal, Qt::UserRole), QVariant(QLatin1String("User" ))); |
955 | |
956 | QCOMPARE(model.headerData(0, Qt::Horizontal, Qt::DisplayRole), QVariant(QLatin1String("Edit" ))); |
957 | } |
958 | |
959 | void tst_QGalleryQueryModel::addColumn() |
960 | { |
961 | QtTestGallery gallery; |
962 | populateGallery(gallery: &gallery); |
963 | |
964 | QGalleryQueryModel model(&gallery); |
965 | model.execute(); |
966 | |
967 | QSignalSpy columnSpy(&model, SIGNAL(columnsInserted(QModelIndex,int,int))); |
968 | |
969 | QCOMPARE(model.columnCount(), 0); |
970 | |
971 | QCOMPARE(model.index(0, 0).isValid(), false); |
972 | QCOMPARE(model.index(0, 1).isValid(), false); |
973 | QCOMPARE(model.index(0, 2).isValid(), false); |
974 | QCOMPARE(model.index(0, 3).isValid(), false); |
975 | QCOMPARE(model.index(0, 4).isValid(), false); |
976 | |
977 | model.addColumn(properties: albumProperties); |
978 | QCOMPARE(model.columnCount(), 1); |
979 | QCOMPARE(model.setHeaderData(0, Qt::Horizontal, QLatin1String("Album" )), true); |
980 | |
981 | QCOMPARE(columnSpy.count(), 1); |
982 | QCOMPARE(columnSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
983 | QCOMPARE(columnSpy.last().at(1).toInt(), 0); |
984 | QCOMPARE(columnSpy.last().at(2).toInt(), 0); |
985 | |
986 | model.addColumn(properties: titleProperties); |
987 | QCOMPARE(model.columnCount(), 2); |
988 | QCOMPARE(model.setHeaderData(1, Qt::Horizontal, QLatin1String("Title" )), true); |
989 | |
990 | QCOMPARE(columnSpy.count(), 2); |
991 | QCOMPARE(columnSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
992 | QCOMPARE(columnSpy.last().at(1).toInt(), 1); |
993 | QCOMPARE(columnSpy.last().at(2).toInt(), 1); |
994 | |
995 | model.addColumn(property: QLatin1String("duration" ), role: Qt::DisplayRole); |
996 | QCOMPARE(model.columnCount(), 3); |
997 | QCOMPARE(model.setHeaderData(2, Qt::Horizontal, QLatin1String("Duration" )), true); |
998 | |
999 | QCOMPARE(columnSpy.count(), 3); |
1000 | QCOMPARE(columnSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1001 | QCOMPARE(columnSpy.last().at(1).toInt(), 2); |
1002 | QCOMPARE(columnSpy.last().at(2).toInt(), 2); |
1003 | |
1004 | model.addColumn(property: QLatin1String("rating" ), role: Qt::DisplayRole); |
1005 | QCOMPARE(model.columnCount(), 4); |
1006 | QCOMPARE(model.setHeaderData(3, Qt::Horizontal, QLatin1String("Rating" )), true); |
1007 | |
1008 | QCOMPARE(columnSpy.count(), 4); |
1009 | QCOMPARE(columnSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1010 | QCOMPARE(columnSpy.last().at(1).toInt(), 3); |
1011 | QCOMPARE(columnSpy.last().at(2).toInt(), 3); |
1012 | |
1013 | model.addColumn(property: QLatin1String("turtle" )); |
1014 | QCOMPARE(model.columnCount(), 5); |
1015 | QCOMPARE(model.setHeaderData(4, Qt::Horizontal, QLatin1String("Turtle" )), true); |
1016 | |
1017 | QCOMPARE(columnSpy.count(), 5); |
1018 | QCOMPARE(columnSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1019 | QCOMPARE(columnSpy.last().at(1).toInt(), 4); |
1020 | QCOMPARE(columnSpy.last().at(2).toInt(), 4); |
1021 | |
1022 | QCOMPARE(model.roleProperties(0), albumProperties); |
1023 | QCOMPARE(model.roleProperties(1), titleProperties); |
1024 | QCOMPARE(model.roleProperties(2), durationProperties); |
1025 | QCOMPARE(model.roleProperties(3), ratingProperties); |
1026 | QCOMPARE(model.roleProperties(4), turtleProperties); |
1027 | |
1028 | QCOMPARE(model.index(0, 0).isValid(), true); |
1029 | QCOMPARE(model.index(0, 1).isValid(), true); |
1030 | QCOMPARE(model.index(0, 2).isValid(), true); |
1031 | QCOMPARE(model.index(0, 3).isValid(), true); |
1032 | QCOMPARE(model.index(0, 4).isValid(), true); |
1033 | |
1034 | QCOMPARE(model.index(0, 0).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
1035 | QCOMPARE(model.index(0, 1).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); |
1036 | QCOMPARE(model.index(0, 2).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
1037 | QCOMPARE(model.index(0, 3).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); |
1038 | QCOMPARE(model.index(0, 4).flags(), Qt::ItemFlags()); |
1039 | |
1040 | QCOMPARE(model.headerData(0, Qt::Horizontal), QVariant(QLatin1String("Album" ))); |
1041 | QCOMPARE(model.headerData(1, Qt::Horizontal), QVariant(QLatin1String("Title" ))); |
1042 | QCOMPARE(model.headerData(2, Qt::Horizontal), QVariant(QLatin1String("Duration" ))); |
1043 | QCOMPARE(model.headerData(3, Qt::Horizontal), QVariant(QLatin1String("Rating" ))); |
1044 | QCOMPARE(model.headerData(4, Qt::Horizontal), QVariant(QLatin1String("Turtle" ))); |
1045 | |
1046 | QModelIndex index; |
1047 | |
1048 | index = model.index(row: 0, column: 0); |
1049 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(QLatin1String("Greatest Hits" ))); |
1050 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1051 | QCOMPARE(index.data(Qt::UserRole), QVariant(QLatin1String("Self Titled" ))); |
1052 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant(QLatin1String("album:SelfTitled:GreatestHits" ))); |
1053 | |
1054 | index = model.index(row: 0, column: 1); |
1055 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(QLatin1String("Interlude" ))); |
1056 | QCOMPARE(index.data(Qt::EditRole), QVariant(QLatin1String("Interlude" ))); |
1057 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
1058 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
1059 | |
1060 | index = model.index(row: 0, column: 2); |
1061 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(120100)); |
1062 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1063 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
1064 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
1065 | |
1066 | index = model.index(row: 0, column: 3); |
1067 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(4)); |
1068 | QCOMPARE(index.data(Qt::EditRole), QVariant(4)); |
1069 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
1070 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
1071 | |
1072 | index = model.index(row: 0, column: 4); |
1073 | QCOMPARE(index.data(Qt::DisplayRole), QVariant()); |
1074 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1075 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
1076 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
1077 | |
1078 | index = model.index(row: 1, column: 0); |
1079 | QCOMPARE(index.data(Qt::DisplayRole), QVariant()); |
1080 | QCOMPARE(model.setData(index, QLatin1String("Noise" ), Qt::DisplayRole), false); |
1081 | QCOMPARE(index.data(Qt::DisplayRole), QVariant()); |
1082 | |
1083 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1084 | QCOMPARE(model.setData(index, QLatin1String("Noise" ), Qt::EditRole), false); |
1085 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1086 | |
1087 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
1088 | QCOMPARE(model.setData(index, QLatin1String("Effects People" ), Qt::UserRole), false); |
1089 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
1090 | |
1091 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
1092 | QCOMPARE(model.setData(index, QLatin1String("album:EffectsPeople:Noise" ), Qt::UserRole + 1), true); |
1093 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant(QLatin1String("album:EffectsPeople:Noise" ))); |
1094 | |
1095 | index = model.index(row: 1, column: 1); |
1096 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(QLatin1String("beep.wav" ))); |
1097 | QCOMPARE(model.setData(index, QLatin1String("Beep Sound" ), Qt::DisplayRole), false); |
1098 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(QLatin1String("beep.wav" ))); |
1099 | |
1100 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1101 | QCOMPARE(model.setData(index, QLatin1String("Beep Sound" ), Qt::EditRole), true); |
1102 | QCOMPARE(index.data(Qt::EditRole), QVariant(QLatin1String("Beep Sound" ))); |
1103 | |
1104 | index = model.index(row: 1, column: 2); |
1105 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(600)); |
1106 | QCOMPARE(model.setData(index, 1000, Qt::DisplayRole), false); |
1107 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(600)); |
1108 | |
1109 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1110 | QCOMPARE(model.setData(index, 1000, Qt::EditRole), false); |
1111 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1112 | |
1113 | index = model.index(row: 1, column: 3); |
1114 | QCOMPARE(index.data(Qt::DisplayRole), QVariant()); |
1115 | QCOMPARE(model.setData(index, 2, Qt::DisplayRole), true); |
1116 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(2)); |
1117 | QCOMPARE(index.data(Qt::EditRole), QVariant(2)); |
1118 | QCOMPARE(model.setData(index, 5, Qt::EditRole), true); |
1119 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(5)); |
1120 | QCOMPARE(index.data(Qt::EditRole), QVariant(5)); |
1121 | } |
1122 | |
1123 | void tst_QGalleryQueryModel::insertColumn() |
1124 | { |
1125 | QtTestGallery gallery; |
1126 | populateGallery(gallery: &gallery); |
1127 | |
1128 | QGalleryQueryModel model(&gallery); |
1129 | model.execute(); |
1130 | |
1131 | QSignalSpy columnSpy(&model, SIGNAL(columnsInserted(QModelIndex,int,int))); |
1132 | |
1133 | QCOMPARE(model.columnCount(), 0); |
1134 | QCOMPARE(model.index(0, 0).isValid(), false); |
1135 | QCOMPARE(model.index(0, 1).isValid(), false); |
1136 | QCOMPARE(model.index(0, 2).isValid(), false); |
1137 | QCOMPARE(model.index(0, 3).isValid(), false); |
1138 | QCOMPARE(model.index(0, 4).isValid(), false); |
1139 | |
1140 | model.insertColumn(index: 0, properties: albumProperties); |
1141 | QCOMPARE(model.columnCount(), 1); |
1142 | QCOMPARE(model.setHeaderData(0, Qt::Horizontal, QLatin1String("Album" )), true); |
1143 | QCOMPARE(model.index(0, 0).data(Qt::DisplayRole), QVariant(QLatin1String("Greatest Hits" ))); |
1144 | |
1145 | QCOMPARE(columnSpy.count(), 1); |
1146 | QCOMPARE(columnSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1147 | QCOMPARE(columnSpy.last().at(1).toInt(), 0); |
1148 | QCOMPARE(columnSpy.last().at(2).toInt(), 0); |
1149 | |
1150 | model.insertColumn(index: 0, properties: titleProperties); |
1151 | QCOMPARE(model.columnCount(), 2); |
1152 | QCOMPARE(model.setHeaderData(0, Qt::Horizontal, QLatin1String("Title" )), true); |
1153 | |
1154 | QCOMPARE(columnSpy.count(), 2); |
1155 | QCOMPARE(columnSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1156 | QCOMPARE(columnSpy.last().at(1).toInt(), 0); |
1157 | QCOMPARE(columnSpy.last().at(2).toInt(), 0); |
1158 | |
1159 | model.insertColumn(index: 1, property: QLatin1String("duration" ), role: Qt::DisplayRole); |
1160 | QCOMPARE(model.columnCount(), 3); |
1161 | QCOMPARE(model.setHeaderData(1, Qt::Horizontal, QLatin1String("Duration" )), true); |
1162 | |
1163 | QCOMPARE(columnSpy.count(), 3); |
1164 | QCOMPARE(columnSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1165 | QCOMPARE(columnSpy.last().at(1).toInt(), 1); |
1166 | QCOMPARE(columnSpy.last().at(2).toInt(), 1); |
1167 | |
1168 | model.insertColumn(index: 2, property: QLatin1String("rating" ), role: Qt::DisplayRole); |
1169 | QCOMPARE(model.columnCount(), 4); |
1170 | QCOMPARE(model.setHeaderData(2, Qt::Horizontal, QLatin1String("Rating" )), true); |
1171 | |
1172 | QCOMPARE(columnSpy.count(), 4); |
1173 | QCOMPARE(columnSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1174 | QCOMPARE(columnSpy.last().at(1).toInt(), 2); |
1175 | QCOMPARE(columnSpy.last().at(2).toInt(), 2); |
1176 | |
1177 | model.insertColumn(index: 4, property: QLatin1String("turtle" )); |
1178 | QCOMPARE(model.columnCount(), 5); |
1179 | QCOMPARE(model.setHeaderData(4, Qt::Horizontal, QLatin1String("Turtle" )), true); |
1180 | |
1181 | QCOMPARE(columnSpy.count(), 5); |
1182 | QCOMPARE(columnSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1183 | QCOMPARE(columnSpy.last().at(1).toInt(), 4); |
1184 | QCOMPARE(columnSpy.last().at(2).toInt(), 4); |
1185 | |
1186 | QCOMPARE(model.roleProperties(0), titleProperties); |
1187 | QCOMPARE(model.roleProperties(1), durationProperties); |
1188 | QCOMPARE(model.roleProperties(2), ratingProperties); |
1189 | QCOMPARE(model.roleProperties(3), albumProperties); |
1190 | QCOMPARE(model.roleProperties(4), turtleProperties); |
1191 | |
1192 | QCOMPARE(model.index(0, 0).isValid(), true); |
1193 | QCOMPARE(model.index(0, 1).isValid(), true); |
1194 | QCOMPARE(model.index(0, 2).isValid(), true); |
1195 | QCOMPARE(model.index(0, 3).isValid(), true); |
1196 | QCOMPARE(model.index(0, 4).isValid(), true); |
1197 | |
1198 | QCOMPARE(model.index(0, 0).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); |
1199 | QCOMPARE(model.index(0, 1).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
1200 | QCOMPARE(model.index(0, 2).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); |
1201 | QCOMPARE(model.index(0, 3).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
1202 | QCOMPARE(model.index(0, 4).flags(), Qt::ItemFlags()); |
1203 | |
1204 | QCOMPARE(model.headerData(0, Qt::Horizontal), QVariant(QLatin1String("Title" ))); |
1205 | QCOMPARE(model.headerData(1, Qt::Horizontal), QVariant(QLatin1String("Duration" ))); |
1206 | QCOMPARE(model.headerData(2, Qt::Horizontal), QVariant(QLatin1String("Rating" ))); |
1207 | QCOMPARE(model.headerData(3, Qt::Horizontal), QVariant(QLatin1String("Album" ))); |
1208 | QCOMPARE(model.headerData(4, Qt::Horizontal), QVariant(QLatin1String("Turtle" ))); |
1209 | |
1210 | QModelIndex index; |
1211 | |
1212 | index = model.index(row: 0, column: 0); |
1213 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(QLatin1String("Interlude" ))); |
1214 | QCOMPARE(index.data(Qt::EditRole), QVariant(QLatin1String("Interlude" ))); |
1215 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
1216 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
1217 | |
1218 | index = model.index(row: 0, column: 1); |
1219 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(120100)); |
1220 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1221 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
1222 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
1223 | |
1224 | index = model.index(row: 0, column: 2); |
1225 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(4)); |
1226 | QCOMPARE(index.data(Qt::EditRole), QVariant(4)); |
1227 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
1228 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
1229 | |
1230 | index = model.index(row: 0, column: 3); |
1231 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(QLatin1String("Greatest Hits" ))); |
1232 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1233 | QCOMPARE(index.data(Qt::UserRole), QVariant(QLatin1String("Self Titled" ))); |
1234 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant(QLatin1String("album:SelfTitled:GreatestHits" ))); |
1235 | |
1236 | index = model.index(row: 0, column: 4); |
1237 | QCOMPARE(index.data(Qt::DisplayRole), QVariant()); |
1238 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1239 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
1240 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
1241 | |
1242 | index = model.index(row: 1, column: 0); |
1243 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(QLatin1String("beep.wav" ))); |
1244 | QCOMPARE(model.setData(index, QLatin1String("Beep Sound" ), Qt::DisplayRole), false); |
1245 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(QLatin1String("beep.wav" ))); |
1246 | |
1247 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1248 | QCOMPARE(model.setData(index, QLatin1String("Beep Sound" ), Qt::EditRole), true); |
1249 | QCOMPARE(index.data(Qt::EditRole), QVariant(QLatin1String("Beep Sound" ))); |
1250 | |
1251 | index = model.index(row: 1, column: 1); |
1252 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(600)); |
1253 | QCOMPARE(model.setData(index, 1000, Qt::DisplayRole), false); |
1254 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(600)); |
1255 | |
1256 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1257 | QCOMPARE(model.setData(index, 1000, Qt::EditRole), false); |
1258 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1259 | |
1260 | index = model.index(row: 1, column: 2); |
1261 | QCOMPARE(index.data(Qt::DisplayRole), QVariant()); |
1262 | QCOMPARE(model.setData(index, 2, Qt::DisplayRole), true); |
1263 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(2)); |
1264 | QCOMPARE(index.data(Qt::EditRole), QVariant(2)); |
1265 | QCOMPARE(model.setData(index, 5, Qt::EditRole), true); |
1266 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(5)); |
1267 | QCOMPARE(index.data(Qt::EditRole), QVariant(5)); |
1268 | |
1269 | index = model.index(row: 1, column: 3); |
1270 | QCOMPARE(index.data(Qt::DisplayRole), QVariant()); |
1271 | QCOMPARE(model.setData(index, QLatin1String("Noise" ), Qt::DisplayRole), false); |
1272 | QCOMPARE(index.data(Qt::DisplayRole), QVariant()); |
1273 | |
1274 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1275 | QCOMPARE(model.setData(index, QLatin1String("Noise" ), Qt::EditRole), false); |
1276 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1277 | |
1278 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
1279 | QCOMPARE(model.setData(index, QLatin1String("Effects People" ), Qt::UserRole), false); |
1280 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
1281 | |
1282 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
1283 | QCOMPARE(model.setData(index, QLatin1String("album:EffectsPeople:Noise" ), Qt::UserRole + 1), true); |
1284 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant(QLatin1String("album:EffectsPeople:Noise" ))); |
1285 | } |
1286 | |
1287 | void tst_QGalleryQueryModel::removeColumn() |
1288 | { |
1289 | QtTestGallery gallery; |
1290 | populateGallery(gallery: &gallery); |
1291 | |
1292 | QGalleryQueryModel model(&gallery); |
1293 | |
1294 | QCOMPARE(model.index(0, 0).isValid(), false); |
1295 | QCOMPARE(model.index(0, 1).isValid(), false); |
1296 | QCOMPARE(model.index(0, 2).isValid(), false); |
1297 | QCOMPARE(model.index(0, 3).isValid(), false); |
1298 | QCOMPARE(model.index(0, 4).isValid(), false); |
1299 | |
1300 | model.addColumn(properties: albumProperties); |
1301 | model.addColumn(properties: titleProperties); |
1302 | model.addColumn(property: QLatin1String("duration" ), role: Qt::DisplayRole); |
1303 | model.addColumn(property: QLatin1String("rating" ), role: Qt::DisplayRole); |
1304 | model.addColumn(property: QLatin1String("turtle" )); |
1305 | |
1306 | QCOMPARE(model.setHeaderData(0, Qt::Horizontal, QLatin1String("Album" )), true); |
1307 | QCOMPARE(model.setHeaderData(1, Qt::Horizontal, QLatin1String("Title" )), true); |
1308 | QCOMPARE(model.setHeaderData(2, Qt::Horizontal, QLatin1String("Duration" )), true); |
1309 | QCOMPARE(model.setHeaderData(3, Qt::Horizontal, QLatin1String("Rating" )), true); |
1310 | QCOMPARE(model.setHeaderData(4, Qt::Horizontal, QLatin1String("Turtle" )), true); |
1311 | |
1312 | model.execute(); |
1313 | |
1314 | QSignalSpy columnSpy(&model, SIGNAL(columnsRemoved(QModelIndex,int,int))); |
1315 | |
1316 | model.removeColumn(index: 4); |
1317 | QCOMPARE(columnSpy.count(), 1); |
1318 | QCOMPARE(columnSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1319 | QCOMPARE(columnSpy.last().at(1).toInt(), 4); |
1320 | QCOMPARE(columnSpy.last().at(2).toInt(), 4); |
1321 | |
1322 | model.removeColumn(index: 0); |
1323 | QCOMPARE(columnSpy.count(), 2); |
1324 | QCOMPARE(columnSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1325 | QCOMPARE(columnSpy.last().at(1).toInt(), 0); |
1326 | QCOMPARE(columnSpy.last().at(2).toInt(), 0); |
1327 | |
1328 | model.removeColumn(index: 1); |
1329 | QCOMPARE(columnSpy.count(), 3); |
1330 | QCOMPARE(columnSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1331 | QCOMPARE(columnSpy.last().at(1).toInt(), 1); |
1332 | QCOMPARE(columnSpy.last().at(2).toInt(), 1); |
1333 | |
1334 | QCOMPARE(model.columnCount(), 2); |
1335 | |
1336 | QCOMPARE(model.roleProperties(0), titleProperties); |
1337 | QCOMPARE(model.roleProperties(1), ratingProperties); |
1338 | |
1339 | QCOMPARE(model.index(0, 0).isValid(), true); |
1340 | QCOMPARE(model.index(0, 1).isValid(), true); |
1341 | |
1342 | QCOMPARE(model.index(0, 0).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); |
1343 | QCOMPARE(model.index(0, 1).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); |
1344 | |
1345 | QCOMPARE(model.headerData(0, Qt::Horizontal), QVariant(QLatin1String("Title" ))); |
1346 | QCOMPARE(model.headerData(1, Qt::Horizontal), QVariant(QLatin1String("Rating" ))); |
1347 | |
1348 | QModelIndex index; |
1349 | |
1350 | index = model.index(row: 0, column: 0); |
1351 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(QLatin1String("Interlude" ))); |
1352 | QCOMPARE(index.data(Qt::EditRole), QVariant(QLatin1String("Interlude" ))); |
1353 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
1354 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
1355 | |
1356 | index = model.index(row: 0, column: 1); |
1357 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(4)); |
1358 | QCOMPARE(index.data(Qt::EditRole), QVariant(4)); |
1359 | QCOMPARE(index.data(Qt::UserRole), QVariant()); |
1360 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant()); |
1361 | |
1362 | index = model.index(row: 1, column: 0); |
1363 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(QLatin1String("beep.wav" ))); |
1364 | QCOMPARE(model.setData(index, QLatin1String("Beep Sound" ), Qt::DisplayRole), false); |
1365 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(QLatin1String("beep.wav" ))); |
1366 | |
1367 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1368 | QCOMPARE(model.setData(index, QLatin1String("Beep Sound" ), Qt::EditRole), true); |
1369 | QCOMPARE(index.data(Qt::EditRole), QVariant(QLatin1String("Beep Sound" ))); |
1370 | |
1371 | index = model.index(row: 1, column: 1); |
1372 | QCOMPARE(index.data(Qt::DisplayRole), QVariant()); |
1373 | QCOMPARE(model.setData(index, 2, Qt::DisplayRole), true); |
1374 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(2)); |
1375 | QCOMPARE(index.data(Qt::EditRole), QVariant(2)); |
1376 | QCOMPARE(model.setData(index, 5, Qt::EditRole), true); |
1377 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(5)); |
1378 | QCOMPARE(index.data(Qt::EditRole), QVariant(5)); |
1379 | } |
1380 | |
1381 | void tst_QGalleryQueryModel::setRoleProperties() |
1382 | { |
1383 | QtTestGallery gallery; |
1384 | populateGallery(gallery: &gallery); |
1385 | |
1386 | QGalleryQueryModel model(&gallery); |
1387 | model.execute(); |
1388 | QVERIFY(gallery.request() != 0); |
1389 | |
1390 | QtTestResultSet *resultSet = qobject_cast<QtTestResultSet *>(object: gallery.request()->resultSet()); |
1391 | QVERIFY(resultSet != 0); |
1392 | |
1393 | QSignalSpy dataSpy(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex))); |
1394 | |
1395 | QCOMPARE(model.index(0, 0).isValid(), false); |
1396 | |
1397 | model.addColumn(properties: albumProperties); |
1398 | QCOMPARE(model.index(0, 0).isValid(), true); |
1399 | QCOMPARE(model.index(0, 0).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
1400 | |
1401 | model.setRoleProperties(column: 0, properties: titleProperties); |
1402 | QCOMPARE(model.roleProperties(0), titleProperties); |
1403 | QCOMPARE(model.index(0, 0).isValid(), true); |
1404 | QCOMPARE(model.index(0, 0).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); |
1405 | |
1406 | QCOMPARE(dataSpy.count(), 1); |
1407 | QCOMPARE(dataSpy.last().at(0).value<QModelIndex>(), model.index(0, 0)); |
1408 | QCOMPARE(dataSpy.last().at(1).value<QModelIndex>(), model.index(1, 0)); |
1409 | |
1410 | model.setRoleProperties(column: 0, properties: durationProperties); |
1411 | QCOMPARE(model.roleProperties(0), durationProperties); |
1412 | QCOMPARE(model.index(0, 0).isValid(), true); |
1413 | QCOMPARE(model.index(0, 0).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
1414 | |
1415 | QCOMPARE(dataSpy.count(), 2); |
1416 | QCOMPARE(dataSpy.last().at(0).value<QModelIndex>(), model.index(0, 0)); |
1417 | QCOMPARE(dataSpy.last().at(1).value<QModelIndex>(), model.index(1, 0)); |
1418 | |
1419 | model.setRoleProperties(column: 0, properties: ratingProperties); |
1420 | QCOMPARE(model.roleProperties(0), ratingProperties); |
1421 | QCOMPARE(model.index(0, 0).isValid(), true); |
1422 | QCOMPARE(model.index(0, 0).flags(), Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); |
1423 | |
1424 | QCOMPARE(dataSpy.count(), 3); |
1425 | QCOMPARE(dataSpy.last().at(0).value<QModelIndex>(), model.index(0, 0)); |
1426 | QCOMPARE(dataSpy.last().at(1).value<QModelIndex>(), model.index(1, 0)); |
1427 | |
1428 | const QHash<int, QString> emptyProperties; |
1429 | |
1430 | model.setRoleProperties(column: -1, properties: albumProperties); |
1431 | QCOMPARE(model.roleProperties(-1), emptyProperties); |
1432 | QCOMPARE(dataSpy.count(), 3); |
1433 | |
1434 | model.setRoleProperties(column: 1, properties: albumProperties); |
1435 | QCOMPARE(model.roleProperties(-1), emptyProperties); |
1436 | QCOMPARE(dataSpy.count(), 3); |
1437 | |
1438 | resultSet->removeRows(index: 0, count: 2); |
1439 | |
1440 | model.setRoleProperties(column: 0, properties: albumProperties); |
1441 | QCOMPARE(model.roleProperties(0), albumProperties); |
1442 | QCOMPARE(dataSpy.count(), 3); |
1443 | } |
1444 | |
1445 | void tst_QGalleryQueryModel::itemsInserted() |
1446 | { |
1447 | QtTestGallery gallery; |
1448 | |
1449 | QGalleryQueryModel model(&gallery); |
1450 | model.execute(); |
1451 | QVERIFY(gallery.request() != 0); |
1452 | |
1453 | QtTestResultSet *resultSet = qobject_cast<QtTestResultSet *>(object: gallery.request()->resultSet()); |
1454 | QVERIFY(resultSet != 0); |
1455 | |
1456 | QSignalSpy insertSpy(&model, SIGNAL(rowsInserted(QModelIndex,int,int))); |
1457 | |
1458 | QCOMPARE(model.rowCount(), 0); |
1459 | |
1460 | resultSet->beginInsertRows(index: 0); |
1461 | resultSet->addRow(); |
1462 | resultSet->addRow(); |
1463 | resultSet->addRow(); |
1464 | resultSet->addRow(); |
1465 | resultSet->endInsertRows(); |
1466 | |
1467 | QCOMPARE(model.rowCount(), 4); |
1468 | |
1469 | QCOMPARE(insertSpy.count(), 1); |
1470 | QCOMPARE(insertSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1471 | QCOMPARE(insertSpy.last().at(1).toInt(), 0); |
1472 | QCOMPARE(insertSpy.last().at(2).toInt(), 3); |
1473 | |
1474 | resultSet->beginInsertRows(index: 2); |
1475 | resultSet->addRow(); |
1476 | resultSet->endInsertRows(); |
1477 | |
1478 | QCOMPARE(model.rowCount(), 5); |
1479 | |
1480 | QCOMPARE(insertSpy.count(), 2); |
1481 | QCOMPARE(insertSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1482 | QCOMPARE(insertSpy.last().at(1).toInt(), 2); |
1483 | QCOMPARE(insertSpy.last().at(2).toInt(), 2); |
1484 | |
1485 | resultSet->beginInsertRows(index: 5); |
1486 | resultSet->addRow(); |
1487 | resultSet->addRow(); |
1488 | resultSet->addRow(); |
1489 | resultSet->endInsertRows(); |
1490 | |
1491 | QCOMPARE(model.rowCount(), 8); |
1492 | |
1493 | QCOMPARE(insertSpy.count(), 3); |
1494 | QCOMPARE(insertSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1495 | QCOMPARE(insertSpy.last().at(1).toInt(), 5); |
1496 | QCOMPARE(insertSpy.last().at(2).toInt(), 7); |
1497 | } |
1498 | |
1499 | void tst_QGalleryQueryModel::itemsRemoved() |
1500 | { |
1501 | QtTestGallery gallery; |
1502 | |
1503 | QGalleryQueryModel model(&gallery); |
1504 | model.execute(); |
1505 | QVERIFY(gallery.request() != 0); |
1506 | |
1507 | QtTestResultSet *resultSet = qobject_cast<QtTestResultSet *>(object: gallery.request()->resultSet()); |
1508 | QVERIFY(resultSet != 0); |
1509 | |
1510 | resultSet->beginInsertRows(index: 0); |
1511 | resultSet->addRow(); |
1512 | resultSet->addRow(); |
1513 | resultSet->addRow(); |
1514 | resultSet->addRow(); |
1515 | resultSet->addRow(); |
1516 | resultSet->addRow(); |
1517 | resultSet->addRow(); |
1518 | resultSet->addRow(); |
1519 | resultSet->endInsertRows(); |
1520 | |
1521 | QCOMPARE(model.rowCount(), 8); |
1522 | |
1523 | QSignalSpy removeSpy(&model, SIGNAL(rowsRemoved(QModelIndex,int,int))); |
1524 | |
1525 | resultSet->removeRows(index: 5, count: 3); |
1526 | QCOMPARE(model.rowCount(), 5); |
1527 | |
1528 | QCOMPARE(removeSpy.count(), 1); |
1529 | QCOMPARE(removeSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1530 | QCOMPARE(removeSpy.last().at(1).toInt(), 5); |
1531 | QCOMPARE(removeSpy.last().at(2).toInt(), 7); |
1532 | |
1533 | resultSet->removeRows(index: 2, count: 1); |
1534 | QCOMPARE(model.rowCount(), 4); |
1535 | |
1536 | QCOMPARE(removeSpy.count(), 2); |
1537 | QCOMPARE(removeSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1538 | QCOMPARE(removeSpy.last().at(1).toInt(), 2); |
1539 | QCOMPARE(removeSpy.last().at(2).toInt(), 2); |
1540 | |
1541 | resultSet->removeRows(index: 0, count: 4); |
1542 | QCOMPARE(model.rowCount(), 0); |
1543 | |
1544 | QCOMPARE(removeSpy.count(), 3); |
1545 | QCOMPARE(removeSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1546 | QCOMPARE(removeSpy.last().at(1).toInt(), 0); |
1547 | QCOMPARE(removeSpy.last().at(2).toInt(), 3); |
1548 | } |
1549 | |
1550 | void tst_QGalleryQueryModel::itemsMoved() |
1551 | { |
1552 | QtTestGallery gallery; |
1553 | |
1554 | QGalleryQueryModel model(&gallery); |
1555 | model.execute(); |
1556 | QVERIFY(gallery.request() != 0); |
1557 | |
1558 | QtTestResultSet *resultSet = qobject_cast<QtTestResultSet *>(object: gallery.request()->resultSet()); |
1559 | QVERIFY(resultSet != 0); |
1560 | |
1561 | resultSet->beginInsertRows(index: 0); |
1562 | resultSet->addRow(); |
1563 | resultSet->addRow(); |
1564 | resultSet->addRow(); |
1565 | resultSet->addRow(); |
1566 | resultSet->addRow(); |
1567 | resultSet->addRow(); |
1568 | resultSet->addRow(); |
1569 | resultSet->addRow(); |
1570 | resultSet->endInsertRows(); |
1571 | |
1572 | QCOMPARE(model.rowCount(), 8); |
1573 | |
1574 | QSignalSpy moveSpy(&model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int))); |
1575 | |
1576 | resultSet->itemsMoved(from: 5, to: 2, count: 3); |
1577 | QCOMPARE(model.rowCount(), 8); |
1578 | |
1579 | QCOMPARE(moveSpy.count(), 1); |
1580 | QCOMPARE(moveSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1581 | QCOMPARE(moveSpy.last().at(1).toInt(), 5); |
1582 | QCOMPARE(moveSpy.last().at(2).toInt(), 7); |
1583 | QCOMPARE(moveSpy.last().at(3).value<QModelIndex>(), QModelIndex()); |
1584 | QCOMPARE(moveSpy.last().at(4).toInt(), 2); |
1585 | |
1586 | resultSet->itemsMoved(from: 2, to: 7, count: 1); |
1587 | QCOMPARE(model.rowCount(), 8); |
1588 | |
1589 | QCOMPARE(moveSpy.count(), 2); |
1590 | QCOMPARE(moveSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1591 | QCOMPARE(moveSpy.last().at(1).toInt(), 2); |
1592 | QCOMPARE(moveSpy.last().at(2).toInt(), 2); |
1593 | QCOMPARE(moveSpy.last().at(3).value<QModelIndex>(), QModelIndex()); |
1594 | QCOMPARE(moveSpy.last().at(4).toInt(), 7); |
1595 | |
1596 | resultSet->itemsMoved(from: 0, to: 4, count: 3); |
1597 | QCOMPARE(model.rowCount(), 8); |
1598 | |
1599 | QCOMPARE(moveSpy.count(), 3); |
1600 | QCOMPARE(moveSpy.last().at(0).value<QModelIndex>(), QModelIndex()); |
1601 | QCOMPARE(moveSpy.last().at(1).toInt(), 0); |
1602 | QCOMPARE(moveSpy.last().at(2).toInt(), 2); |
1603 | QCOMPARE(moveSpy.last().at(3).value<QModelIndex>(), QModelIndex()); |
1604 | QCOMPARE(moveSpy.last().at(4).toInt(), 4); |
1605 | } |
1606 | |
1607 | void tst_QGalleryQueryModel::metaDataChanged() |
1608 | { |
1609 | QtTestGallery gallery; |
1610 | populateGallery(gallery: &gallery); |
1611 | gallery.addRow(); |
1612 | gallery.addRow(); |
1613 | gallery.addRow(); |
1614 | gallery.addRow(); |
1615 | |
1616 | QGalleryQueryModel model(&gallery); |
1617 | |
1618 | model.addColumn(properties: albumProperties); |
1619 | model.addColumn(properties: titleProperties); |
1620 | model.addColumn(property: QLatin1String("duration" ), role: Qt::DisplayRole); |
1621 | model.addColumn(property: QLatin1String("rating" ), role: Qt::DisplayRole); |
1622 | |
1623 | model.execute(); |
1624 | QVERIFY(gallery.request() != 0); |
1625 | |
1626 | QtTestResultSet *resultSet = qobject_cast<QtTestResultSet *>(object: gallery.request()->resultSet()); |
1627 | QVERIFY(resultSet != 0); |
1628 | |
1629 | const int key0_0 = resultSet->propertyKey(propertyName: QLatin1String("albumTitle" )); |
1630 | const int key0_1 = resultSet->propertyKey(propertyName: QLatin1String("albumArtist" )); |
1631 | const int key0_2 = resultSet->propertyKey(propertyName: QLatin1String("albumId" )); |
1632 | const int key1_0 = resultSet->propertyKey(propertyName: QLatin1String("displayName" )); |
1633 | const int key1_1 = resultSet->propertyKey(propertyName: QLatin1String("title" )); |
1634 | const int key2_0 = resultSet->propertyKey(propertyName: QLatin1String("duration" )); |
1635 | const int key3_0 = resultSet->propertyKey(propertyName: QLatin1String("rating" )); |
1636 | |
1637 | QSignalSpy dataSpy(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex))); |
1638 | resultSet->metaDataChanged(index: 0, count: 1, keys: QList<int>()); |
1639 | QCOMPARE(dataSpy.count(), 0); |
1640 | |
1641 | resultSet->metaDataChanged(index: 0, count: 1, keys: QList<int>() |
1642 | << key0_0 << key0_1 << key0_2 |
1643 | << key1_0 << key1_1 |
1644 | << key2_0 |
1645 | << key3_0); |
1646 | QCOMPARE(dataSpy.count(), 1); |
1647 | QCOMPARE(dataSpy.at(dataSpy.count() - 1).at(0).value<QModelIndex>(), model.index(0, 0)); |
1648 | QCOMPARE(dataSpy.at(dataSpy.count() - 1).at(1).value<QModelIndex>(), model.index(0, 3)); |
1649 | |
1650 | resultSet->metaDataChanged(index: 1, count: 1, keys: QList<int>() << key0_2 << key3_0); |
1651 | QCOMPARE(dataSpy.count(), 3); |
1652 | QCOMPARE(dataSpy.at(dataSpy.count() - 2).at(0).value<QModelIndex>(), model.index(1, 0)); |
1653 | QCOMPARE(dataSpy.at(dataSpy.count() - 2).at(1).value<QModelIndex>(), model.index(1, 0)); |
1654 | QCOMPARE(dataSpy.at(dataSpy.count() - 1).at(0).value<QModelIndex>(), model.index(1, 3)); |
1655 | QCOMPARE(dataSpy.at(dataSpy.count() - 1).at(1).value<QModelIndex>(), model.index(1, 3)); |
1656 | |
1657 | resultSet->metaDataChanged(index: 0, count: 2, keys: QList<int>() |
1658 | << key0_0 << key0_1 << key0_2 |
1659 | << key1_0 << key1_1 |
1660 | << key2_0 |
1661 | << key3_0); |
1662 | QCOMPARE(dataSpy.count(), 4); |
1663 | QCOMPARE(dataSpy.at(dataSpy.count() - 1).at(0).value<QModelIndex>(), model.index(0, 0)); |
1664 | QCOMPARE(dataSpy.at(dataSpy.count() - 1).at(1).value<QModelIndex>(), model.index(1, 3)); |
1665 | |
1666 | resultSet->metaDataChanged(index: 1, count: 3, keys: QList<int>() << key1_1 << key2_0); |
1667 | QCOMPARE(dataSpy.count(), 5); |
1668 | QCOMPARE(dataSpy.at(dataSpy.count() - 1).at(0).value<QModelIndex>(), model.index(1, 1)); |
1669 | QCOMPARE(dataSpy.at(dataSpy.count() - 1).at(1).value<QModelIndex>(), model.index(3, 2)); |
1670 | |
1671 | resultSet->metaDataChanged(index: 0, count: 1, keys: QList<int>() << key0_1 << key1_1 << key3_0); |
1672 | QCOMPARE(dataSpy.count(), 7); |
1673 | QCOMPARE(dataSpy.at(dataSpy.count() - 2).at(0).value<QModelIndex>(), model.index(0, 0)); |
1674 | QCOMPARE(dataSpy.at(dataSpy.count() - 2).at(1).value<QModelIndex>(), model.index(0, 1)); |
1675 | QCOMPARE(dataSpy.at(dataSpy.count() - 1).at(0).value<QModelIndex>(), model.index(0, 3)); |
1676 | QCOMPARE(dataSpy.at(dataSpy.count() - 1).at(1).value<QModelIndex>(), model.index(0, 3)); |
1677 | |
1678 | model.removeColumn(index: 0); |
1679 | model.removeColumn(index: 0); |
1680 | model.removeColumn(index: 0); |
1681 | model.removeColumn(index: 0); |
1682 | |
1683 | resultSet->metaDataChanged(index: 0, count: 1, keys: QList<int>()); |
1684 | QCOMPARE(dataSpy.count(), 7); |
1685 | |
1686 | resultSet->metaDataChanged(index: 1, count: 1, keys: QList<int>() << key0_2 << key3_0); |
1687 | QCOMPARE(dataSpy.count(), 7); |
1688 | |
1689 | resultSet->metaDataChanged(index: 0, count: 2, keys: QList<int>() |
1690 | << key0_0 << key0_1 << key0_2 |
1691 | << key1_0 << key1_1 |
1692 | << key2_0 |
1693 | << key3_0); |
1694 | QCOMPARE(dataSpy.count(), 7); |
1695 | |
1696 | resultSet->metaDataChanged(index: 1, count: 3, keys: QList<int>() << key0_1 << key2_0); |
1697 | QCOMPARE(dataSpy.count(), 7); |
1698 | |
1699 | resultSet->metaDataChanged(index: 0, count: 1, keys: QList<int>() << key0_1 << key1_1 << key3_0); |
1700 | QCOMPARE(dataSpy.count(), 7); |
1701 | } |
1702 | |
1703 | void tst_QGalleryQueryModel::invalidIndex() |
1704 | { |
1705 | QtTestGallery gallery; |
1706 | populateGallery(gallery: &gallery); |
1707 | |
1708 | QGalleryQueryModel model(&gallery); |
1709 | model.addColumn(properties: albumProperties); |
1710 | model.addColumn(properties: titleProperties); |
1711 | model.addColumn(property: QLatin1String("duration" ), role: Qt::DisplayRole); |
1712 | model.addColumn(property: QLatin1String("rating" ), role: Qt::DisplayRole); |
1713 | model.addColumn(property: QLatin1String("turtle" ), role: Qt::DisplayRole); |
1714 | |
1715 | QCOMPARE(model.itemId(QModelIndex()), QVariant()); |
1716 | QCOMPARE(model.itemUrl(QModelIndex()), QUrl()); |
1717 | QCOMPARE(model.itemType(QModelIndex()), QString()); |
1718 | QCOMPARE(model.flags(QModelIndex()), Qt::ItemFlags()); |
1719 | QCOMPARE(model.data(QModelIndex(), Qt::DisplayRole), QVariant()); |
1720 | QCOMPARE(model.data(QModelIndex(), Qt::EditRole), QVariant()); |
1721 | QCOMPARE(model.data(QModelIndex(), Qt::UserRole), QVariant()); |
1722 | QCOMPARE(model.data(QModelIndex(), Qt::UserRole + 1), QVariant()); |
1723 | QCOMPARE(model.setData(QModelIndex(), QLatin1String("Hello" ), Qt::DisplayRole), false); |
1724 | QCOMPARE(model.setData(QModelIndex(), QLatin1String("Hello" ), Qt::EditRole), false); |
1725 | QCOMPARE(model.setData(QModelIndex(), QLatin1String("Hello" ), Qt::UserRole), false); |
1726 | QCOMPARE(model.setData(QModelIndex(), QLatin1String("Hello" ), Qt::UserRole + 1), false); |
1727 | QCOMPARE(model.data(QModelIndex(), Qt::DisplayRole), QVariant()); |
1728 | QCOMPARE(model.data(QModelIndex(), Qt::EditRole), QVariant()); |
1729 | QCOMPARE(model.data(QModelIndex(), Qt::UserRole), QVariant()); |
1730 | QCOMPARE(model.data(QModelIndex(), Qt::UserRole + 1), QVariant()); |
1731 | } |
1732 | void tst_QGalleryQueryModel::hierarchy() |
1733 | { |
1734 | QtTestGallery gallery; |
1735 | populateGallery(gallery: &gallery); |
1736 | |
1737 | QGalleryQueryModel model(&gallery); |
1738 | model.addColumn(properties: albumProperties); |
1739 | model.addColumn(properties: titleProperties); |
1740 | model.addColumn(property: QLatin1String("duration" ), role: Qt::DisplayRole); |
1741 | model.addColumn(property: QLatin1String("rating" ), role: Qt::DisplayRole); |
1742 | model.execute(); |
1743 | |
1744 | QModelIndex index = model.index(row: 0, column: 0); |
1745 | QCOMPARE(index.isValid(), true); |
1746 | QCOMPARE(model.parent(QModelIndex()).isValid(), false); |
1747 | QCOMPARE(model.parent(index).isValid(), false); |
1748 | QCOMPARE(model.rowCount(index), 0); |
1749 | QCOMPARE(model.columnCount(index), 0); |
1750 | QCOMPARE(model.index(-1, 0, index).isValid(), false); |
1751 | QCOMPARE(model.index(-1, 2, index).isValid(), false); |
1752 | QCOMPARE(model.index(-1, 3, index).isValid(), false); |
1753 | QCOMPARE(model.index(-1, 4, index).isValid(), false); |
1754 | QCOMPARE(model.index( 0, 0, index).isValid(), false); |
1755 | QCOMPARE(model.index( 0, 2, index).isValid(), false); |
1756 | QCOMPARE(model.index( 0, 3, index).isValid(), false); |
1757 | QCOMPARE(model.index( 0, 4, index).isValid(), false); |
1758 | QCOMPARE(model.index( 1, 0, index).isValid(), false); |
1759 | QCOMPARE(model.index( 1, 2, index).isValid(), false); |
1760 | QCOMPARE(model.index( 1, 3, index).isValid(), false); |
1761 | QCOMPARE(model.index( 1, 4, index).isValid(), false); |
1762 | QCOMPARE(model.index( 4, 0, index).isValid(), false); |
1763 | QCOMPARE(model.index( 4, 2, index).isValid(), false); |
1764 | QCOMPARE(model.index( 4, 3, index).isValid(), false); |
1765 | QCOMPARE(model.index( 4, 4, index).isValid(), false); |
1766 | QCOMPARE(model.index( 5, 0, index).isValid(), false); |
1767 | QCOMPARE(model.index( 5, 2, index).isValid(), false); |
1768 | QCOMPARE(model.index( 5, 3, index).isValid(), false); |
1769 | QCOMPARE(model.index( 5, 4, index).isValid(), false); |
1770 | } |
1771 | |
1772 | void tst_QGalleryQueryModel::setGallery() |
1773 | { |
1774 | QtTestGallery gallery; |
1775 | populateGallery(gallery: &gallery); |
1776 | |
1777 | QModelIndex index; |
1778 | |
1779 | QGalleryQueryModel model; |
1780 | model.addColumn(properties: albumProperties); |
1781 | model.addColumn(properties: titleProperties); |
1782 | model.addColumn(property: QLatin1String("duration" ), role: Qt::DisplayRole); |
1783 | model.addColumn(property: QLatin1String("rating" ), role: Qt::DisplayRole); |
1784 | model.addColumn(property: QLatin1String("turtle" ), role: Qt::DisplayRole); |
1785 | |
1786 | QVERIFY(model.gallery() == 0); |
1787 | model.execute(); |
1788 | |
1789 | index = model.index(row: 0, column: 0); |
1790 | QCOMPARE(index.isValid(), false); |
1791 | |
1792 | model.setGallery(&gallery); |
1793 | QVERIFY(model.gallery() == &gallery); |
1794 | model.execute(); |
1795 | |
1796 | index = model.index(row: 0, column: 0); |
1797 | QCOMPARE(index.isValid(), true); |
1798 | QCOMPARE(model.itemId(index), QVariant(3)); |
1799 | QCOMPARE(model.itemUrl(index), QUrl(QLatin1String("file:///music/interlude.mp3" ))); |
1800 | QCOMPARE(model.itemType(index), QString::fromLatin1("Audio" )); |
1801 | QCOMPARE(index.data(Qt::DisplayRole), QVariant(QLatin1String("Greatest Hits" ))); |
1802 | QCOMPARE(index.data(Qt::EditRole), QVariant()); |
1803 | QCOMPARE(index.data(Qt::UserRole), QVariant(QLatin1String("Self Titled" ))); |
1804 | QCOMPARE(index.data(Qt::UserRole + 1), QVariant(QLatin1String("album:SelfTitled:GreatestHits" ))); |
1805 | |
1806 | model.setGallery(0); |
1807 | QVERIFY(model.gallery() == 0); |
1808 | model.execute(); |
1809 | |
1810 | index = model.index(row: 0, column: 0); |
1811 | QCOMPARE(index.isValid(), false); |
1812 | } |
1813 | |
1814 | void tst_QGalleryQueryModel::galleryChanged() |
1815 | { |
1816 | QtTestGallery *gallery; |
1817 | gallery = new (QtTestGallery); |
1818 | QGalleryQueryModel model; |
1819 | |
1820 | QSignalSpy galleryChangedSpy(&model, SIGNAL(galleryChanged())); |
1821 | QCOMPARE(galleryChangedSpy.count(), 0); |
1822 | |
1823 | model.setGallery(gallery); |
1824 | QCOMPARE(model.gallery(), static_cast<QAbstractGallery*>(gallery)); |
1825 | QCOMPARE(galleryChangedSpy.count(), 1); |
1826 | |
1827 | } |
1828 | |
1829 | void tst_QGalleryQueryModel::errorChanged() |
1830 | { |
1831 | |
1832 | QtTestGallery gallery; |
1833 | |
1834 | QGalleryQueryModel model(&gallery); |
1835 | |
1836 | QSignalSpy errorChangedSpy(&model, SIGNAL(errorChanged())); |
1837 | |
1838 | model.execute(); |
1839 | QCOMPARE(model.error(), int(QGalleryAbstractRequest::NoError)); |
1840 | QCOMPARE(errorChangedSpy.count(),0); |
1841 | |
1842 | gallery.setError(error: 120, errorString: QLatin1String("bad connection" )); |
1843 | model.execute(); |
1844 | QCOMPARE(model.state(), QGalleryAbstractRequest::Error); |
1845 | QCOMPARE(model.error(),120); |
1846 | QCOMPARE(model.errorString(), QLatin1String("bad connection" )); |
1847 | QCOMPARE(errorChangedSpy.count(),1); |
1848 | |
1849 | |
1850 | } |
1851 | |
1852 | |
1853 | QTEST_MAIN(tst_QGalleryQueryModel) |
1854 | |
1855 | #include "tst_qgalleryquerymodel.moc" |
1856 | |
1857 | |