1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2010-01-16
* Description : test for the model holding markers
*
* SPDX-FileCopyrightText: 2010-2011 by Michael G. Hansen <mike at mghansen dot de>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "itemmarkertiler_utest.h"
// Qt includes
#include <QStandardItemModel>
// Local includes
#include "digikam_debug.h"
#include "geoifacecommon.h"
using namespace Digikam;
const int CoordinatesRole = Qt::UserRole + 0;
MarkerModelHelper::MarkerModelHelper(QAbstractItemModel* const itemModel,
QItemSelectionModel* const itemSelectionModel)
: GeoModelHelper (itemModel),
m_itemModel (itemModel),
m_itemSelectionModel(itemSelectionModel)
{
connect(itemModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
this, SLOT(slotDataChanged(QModelIndex,QModelIndex)));
}
MarkerModelHelper::~MarkerModelHelper()
{
}
void MarkerModelHelper::slotDataChanged(const QModelIndex& topLeft,
const QModelIndex& bottomRight)
{
Q_UNUSED(topLeft)
Q_UNUSED(bottomRight)
Q_EMIT signalModelChangedDrastically();
}
QAbstractItemModel* MarkerModelHelper::model() const
{
return m_itemModel;
}
QItemSelectionModel* MarkerModelHelper::selectionModel() const
{
return m_itemSelectionModel;
}
bool MarkerModelHelper::itemCoordinates(const QModelIndex& index,
GeoCoordinates* const coordinates) const
{
if (!index.data(CoordinatesRole).canConvert<GeoCoordinates>())
{
return false;
}
if (coordinates)
{
*coordinates = index.data(CoordinatesRole).value<GeoCoordinates>();
}
return true;
}
const GeoCoordinates coord_1_2 = GeoCoordinates::fromGeoUrl(QLatin1String("geo:1,2"));
const GeoCoordinates coord_50_60 = GeoCoordinates::fromGeoUrl(QLatin1String("geo:50,60"));
const GeoCoordinates coord_m50_m60 = GeoCoordinates::fromGeoUrl(QLatin1String("geo:-50,-60"));
QStandardItem* MakeItemAt(const GeoCoordinates& coordinates)
{
QStandardItem* const newItem = new QStandardItem(coordinates.geoUrl());
newItem->setData(QVariant::fromValue(coordinates), CoordinatesRole);
return newItem;
}
/**
* @brief Helper function: count the number of markers found by an iterator
*/
int CountMarkersInIterator(ItemMarkerTiler::NonEmptyIterator* const it)
{
int markerCount = 0;
while (!it->atEnd())
{
const TileIndex currentIndex = it->currentIndex();
markerCount += it->model()->getTileMarkerCount(currentIndex);
it->nextIndex();
// qCDebug(DIGIKAM_TESTS_LOG)<<currentIndex;
}
return markerCount;
}
void TestItemMarkerTiler::testNoOp()
{
}
void TestItemMarkerTiler::testIndices()
{
const int maxLevel = TileIndex::MaxLevel;
for (int l = 0 ; l <= maxLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_1_2, l);
QVERIFY(tileIndex.level() == l);
}
}
void TestItemMarkerTiler::testAddMarkers1()
{
QScopedPointer<QStandardItemModel> itemModel(new QStandardItemModel());
ItemMarkerTiler mm(new MarkerModelHelper(itemModel.data(), nullptr));
const int maxLevel = TileIndex::MaxLevel;
// there should be no tiles in the model yet:
for (int l = 0 ; l <= maxLevel ; ++l)
{
QVERIFY(mm.getTile(TileIndex::fromCoordinates(coord_50_60, l), true) == nullptr);
}
itemModel->appendRow(MakeItemAt(coord_50_60));
// now there should be tiles with one marker:
for (int l = 0 ; l <= maxLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_50_60, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QVERIFY(myTile->childrenEmpty());
QVERIFY(mm.getTileMarkerCount(tileIndex) == 1);
}
itemModel->appendRow(MakeItemAt(coord_50_60));
// now there should be tiles with two markers:
for (int l = 0 ; l <= maxLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_50_60, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QCOMPARE(mm.getTileMarkerCount(tileIndex), 2);
}
}
void TestItemMarkerTiler::testRemoveMarkers2()
{
QScopedPointer<QStandardItemModel> itemModel(new QStandardItemModel());
ItemMarkerTiler mm(new MarkerModelHelper(itemModel.data(), nullptr));
const int maxLevel = TileIndex::MaxLevel;
itemModel->appendRow(MakeItemAt(coord_50_60));
QStandardItem* const item2 = MakeItemAt(coord_50_60);
itemModel->appendRow(item2);
// now there should be tiles with two markers:
for (int l = 0 ; l <= maxLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_50_60, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QCOMPARE(mm.getTileMarkerCount(tileIndex), 2);
}
// remove one item:
qDeleteAll(itemModel->takeRow(itemModel->indexFromItem(item2).row()));
for (int l = 0 ; l <= maxLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_50_60, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QCOMPARE(mm.getTileMarkerCount(tileIndex), 1);
}
}
void TestItemMarkerTiler::testMoveMarkers1()
{
QScopedPointer<QStandardItemModel> itemModel(new QStandardItemModel());
ItemMarkerTiler mm(new MarkerModelHelper(itemModel.data(), nullptr));
const int maxLevel = TileIndex::MaxLevel;
const int fillLevel = maxLevel - 2;
// add a marker to the model and create tiles up to a certain level:
QStandardItem* const item1 = MakeItemAt(coord_1_2);
itemModel->appendRow(item1);
const QModelIndex markerIndex1 = itemModel->indexFromItem(item1);
GEOIFACE_ASSERT(markerIndex1.isValid());
for (int l = 1 ; l <= fillLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_1_2, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QVERIFY(myTile->childrenEmpty());
QCOMPARE(mm.getTileMarkerCount(tileIndex), 1);
}
// now move marker 1:
itemModel->setData(markerIndex1, QVariant::fromValue(coord_50_60), CoordinatesRole);
for (int l = 0 ; l <= fillLevel ; ++l)
{
// make sure the marker can not be found at the old position any more
TileIndex tileIndex = TileIndex::fromCoordinates(coord_1_2, l);
QVERIFY(mm.getTile(tileIndex, true) == nullptr);
QCOMPARE(mm.getTileMarkerCount(tileIndex), 0);
QVERIFY(mm.getTile(tileIndex, true) == nullptr);
// find it at the new position:
tileIndex = TileIndex::fromCoordinates(coord_50_60, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QVERIFY(myTile->childrenEmpty());
QVERIFY(mm.getTileMarkerCount(tileIndex) == 1);
}
// mm.clear();
}
void TestItemMarkerTiler::testMoveMarkers2()
{
QScopedPointer<QStandardItemModel> itemModel(new QStandardItemModel());
ItemMarkerTiler mm(new MarkerModelHelper(itemModel.data(), nullptr));
const int maxLevel = TileIndex::MaxLevel;
const int fillLevel = maxLevel - 2;
// add markers to the model and create tiles up to a certain level:
QStandardItem* const item1 = MakeItemAt(coord_1_2);
itemModel->appendRow(item1);
const QModelIndex markerIndex1 = itemModel->indexFromItem(item1);
QStandardItem* const item2 = MakeItemAt(coord_1_2);
itemModel->appendRow(item2);
// const QModelIndex markerIndex2 = itemModel->indexFromItem(item2);
for (int l = 1 ; l <= fillLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_1_2, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QVERIFY(myTile->childrenEmpty());
QVERIFY(mm.getTileMarkerCount(tileIndex) == 2);
}
QStandardItem* const item3 = MakeItemAt(coord_50_60);
itemModel->appendRow(item3);
// const QModelIndex markerIndex3 = itemModel->indexFromItem(item3);
for (int l = 1 ; l <= fillLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_50_60, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QVERIFY(myTile->childrenEmpty());
QVERIFY(mm.getTileMarkerCount(tileIndex) == 1);
}
// now move marker 1:
itemModel->setData(markerIndex1, QVariant::fromValue(coord_50_60), CoordinatesRole);
// make sure the item model was also updated:
QVERIFY(item1->data(CoordinatesRole).value<GeoCoordinates>() == coord_50_60);
for (int l = 0 ; l <= fillLevel ; ++l)
{
// make sure there is only one marker left at the old position:
TileIndex tileIndex = TileIndex::fromCoordinates(coord_1_2, l);
QVERIFY(mm.getTileMarkerCount(tileIndex) == 1);
// find it at the new position:
tileIndex = TileIndex::fromCoordinates(coord_50_60, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
if (l > fillLevel)
{
QVERIFY(myTile->childrenEmpty());
}
QVERIFY(mm.getTileMarkerCount(tileIndex) == 2);
}
// mm.clear();
}
void TestItemMarkerTiler::testIteratorWholeWorldNoBackingModel()
{
QScopedPointer<QStandardItemModel> itemModel(new QStandardItemModel());
ItemMarkerTiler mm(new MarkerModelHelper(itemModel.data(), nullptr));
const int maxLevel = TileIndex::MaxLevel;
for (int l = 0 ; l <= maxLevel ; ++l)
{
ItemMarkerTiler::NonEmptyIterator it(&mm, l);
QVERIFY( CountMarkersInIterator(&it) == 0 );
}
}
void TestItemMarkerTiler::testIteratorWholeWorld()
{
QScopedPointer<QStandardItemModel> itemModel(new QStandardItemModel());
ItemMarkerTiler mm(new MarkerModelHelper(itemModel.data(), nullptr));
const int maxLevel = TileIndex::MaxLevel;
for (int l = 0 ; l <= maxLevel ; ++l)
{
ItemMarkerTiler::NonEmptyIterator it(&mm, l);
QVERIFY( CountMarkersInIterator(&it) == 0 );
}
itemModel->appendRow(MakeItemAt(coord_1_2));
itemModel->appendRow(MakeItemAt(coord_50_60));
for (int l = 0 ; l <= maxLevel ; ++l)
{
// iterate over the whole world:
ItemMarkerTiler::NonEmptyIterator it(&mm, l);
QVERIFY( CountMarkersInIterator(&it) == 2 );
}
}
void TestItemMarkerTiler::testIteratorPartial1()
{
QScopedPointer<QStandardItemModel> itemModel(new QStandardItemModel());
ItemMarkerTiler mm(new MarkerModelHelper(itemModel.data(), nullptr));
const int maxLevel = TileIndex::MaxLevel;
itemModel->appendRow(MakeItemAt(coord_1_2));
itemModel->appendRow(MakeItemAt(coord_50_60));
for (int l = 0 ; l <= maxLevel ; ++l)
{
{
// iterate over a part which should be empty:
GeoCoordinates::PairList boundsList;
boundsList << GeoCoordinates::makePair(-10.0, -10.0, -5.0, -5.0);
ItemMarkerTiler::NonEmptyIterator it(&mm, l, boundsList);
QVERIFY( CountMarkersInIterator(&it) == 0 );
}
{
// iterate over a part which should contain one marker:
GeoCoordinates::PairList boundsList;
boundsList << GeoCoordinates::makePair(-10.0, -10.0, 5.0, 5.0);
ItemMarkerTiler::NonEmptyIterator it(&mm, l, boundsList);
QVERIFY( CountMarkersInIterator(&it) == 1 );
// iterate over a part which should contain one marker:
GeoCoordinates::PairList boundsList1;
boundsList1 << GeoCoordinates::makePair(1.0, 2.0, 5.0, 5.0);
ItemMarkerTiler::NonEmptyIterator it1(&mm, l, boundsList1);
QVERIFY( CountMarkersInIterator(&it1) == 1 );
GeoCoordinates::PairList boundsList2;
boundsList2 << GeoCoordinates::makePair(-1.0, -2.0, 1.0, 2.0);
ItemMarkerTiler::NonEmptyIterator it2(&mm, l, boundsList2);
QVERIFY( CountMarkersInIterator(&it2) == 1 );
}
{
// iterate over a part which should contain two markers:
GeoCoordinates::PairList boundsList;
boundsList << GeoCoordinates::makePair(0.0, 0.0, 60.0, 60.0);
ItemMarkerTiler::NonEmptyIterator it(&mm, l, boundsList);
QVERIFY( CountMarkersInIterator(&it) == 2 );
}
{
// iterate over two parts which should contain two markers:
GeoCoordinates::PairList boundsList;
boundsList << GeoCoordinates::makePair(0.0, 0.0, 5.0, 5.0);
boundsList << GeoCoordinates::makePair(49.0, 59.0, 51.0, 61.0);
ItemMarkerTiler::NonEmptyIterator it(&mm, l, boundsList);
QVERIFY( CountMarkersInIterator(&it) == 2 );
}
}
const GeoCoordinates coord_2_2 = GeoCoordinates(2.0, 2.0);
itemModel->appendRow(MakeItemAt(coord_2_2));
{
// at level 1, the iterator should find only one marker:
GeoCoordinates::PairList boundsList;
boundsList << GeoCoordinates::makePair(0.0, 0.0, 1.0, 2.0);
ItemMarkerTiler::NonEmptyIterator it(&mm, 1, boundsList);
QVERIFY( CountMarkersInIterator(&it) == 1 );
}
}
void TestItemMarkerTiler::testIteratorPartial2()
{
QScopedPointer<QStandardItemModel> itemModel(new QStandardItemModel());
ItemMarkerTiler mm(new MarkerModelHelper(itemModel.data(), nullptr));
const int maxLevel = TileIndex::MaxLevel;
GeoCoordinates::PairList boundsList;
boundsList << GeoCoordinates::makePair(0.55, 1.55, 0.56, 1.56);
const GeoCoordinates coordInBounds1 = GeoCoordinates(0.556, 1.556);
const GeoCoordinates coordOutOfBounds1 = GeoCoordinates(0.5, 1.5);
const GeoCoordinates coordOutOfBounds2 = GeoCoordinates(0.5, 1.6);
const GeoCoordinates coordOutOfBounds3 = GeoCoordinates(0.6, 1.5);
const GeoCoordinates coordOutOfBounds4 = GeoCoordinates(0.6, 1.6);
itemModel->appendRow(MakeItemAt(coordInBounds1));
itemModel->appendRow(MakeItemAt(coordOutOfBounds1));
itemModel->appendRow(MakeItemAt(coordOutOfBounds2));
itemModel->appendRow(MakeItemAt(coordOutOfBounds3));
itemModel->appendRow(MakeItemAt(coordOutOfBounds4));
for (int l = 3 ; l <= maxLevel ; ++l)
{
ItemMarkerTiler::NonEmptyIterator it(&mm, l, boundsList);
QVERIFY( CountMarkersInIterator(&it) == 1 );
}
}
void TestItemMarkerTiler::testRemoveMarkers1()
{
QScopedPointer<QStandardItemModel> itemModel(new QStandardItemModel());
ItemMarkerTiler mm(new MarkerModelHelper(itemModel.data(), nullptr));
const int maxLevel = TileIndex::MaxLevel;
for (int l = 0 ; l <= maxLevel ; ++l)
{
ItemMarkerTiler::NonEmptyIterator it(&mm, l);
QVERIFY(CountMarkersInIterator(&it) == 0 );
}
QStandardItem* const item1 = MakeItemAt(coord_1_2);
itemModel->appendRow(item1);
itemModel->appendRow(MakeItemAt(coord_50_60));
for (int l = 0 ; l <= maxLevel ; ++l)
{
// iterate over the whole world:
ItemMarkerTiler::NonEmptyIterator it(&mm, l);
QCOMPARE(CountMarkersInIterator(&it), 2);
}
// first make sure that comparison of indices still works
const QPersistentModelIndex index1 = itemModel->indexFromItem(item1);
const QPersistentModelIndex index2 = itemModel->indexFromItem(item1);
QCOMPARE(index1, index2);
// now remove items:
QCOMPARE(itemModel->takeRow(itemModel->indexFromItem(item1).row()).count(), 1);
delete item1;
QCOMPARE(itemModel->rowCount(), 1);
for (int l = 0 ; l <= maxLevel ; ++l)
{
// iterate over the whole world:
ItemMarkerTiler::NonEmptyIterator it(&mm, l);
QCOMPARE(CountMarkersInIterator(&it), 1);
}
}
/**
* @brief Make sure that items which are in the model before it is given to the tiled model are found by the tile model
*/
void TestItemMarkerTiler::testPreExistingMarkers()
{
QScopedPointer<QStandardItemModel> itemModel(new QStandardItemModel());
itemModel->appendRow(MakeItemAt(coord_50_60));
ItemMarkerTiler mm(new MarkerModelHelper(itemModel.data(), nullptr));
const int maxLevel = TileIndex::MaxLevel;
for (int l = 0; l <= maxLevel; ++l)
{
// iterate over the whole world:
ItemMarkerTiler::NonEmptyIterator it(&mm, l);
QVERIFY( CountMarkersInIterator(&it) == 1 );
}
}
void TestItemMarkerTiler::testSelectionState1()
{
QScopedPointer<QStandardItemModel> itemModel(new QStandardItemModel());
QItemSelectionModel* const selectionModel = new QItemSelectionModel(itemModel.data());
ItemMarkerTiler mm(new MarkerModelHelper(itemModel.data(), selectionModel));
const int maxLevel = TileIndex::MaxLevel;
QStandardItem* const item1 = MakeItemAt(coord_50_60);
item1->setSelectable(true);
itemModel->appendRow(item1);
QModelIndex item1Index = itemModel->indexFromItem(item1);
// verify the selection state of the tiles:
// make sure we do not create tiles all the way down,
// because we want to test whether the state is okay in newly created tiles
const int preMaxLevel = maxLevel -2;
for (int l = 0 ; l <= preMaxLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_50_60, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QVERIFY(mm.getTileMarkerCount(tileIndex) == 1);
QVERIFY(mm.getTileGroupState(tileIndex)==SelectedNone);
}
selectionModel->select(item1Index, QItemSelectionModel::Select);
// verify the selection state of the tiles:
for (int l = 0 ; l <= maxLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_50_60, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QCOMPARE(mm.getTileMarkerCount(tileIndex), 1);
QVERIFY(mm.getTileGroupState(tileIndex)==SelectedAll);
QVERIFY(mm.getTileSelectedCount(tileIndex)==1);
}
// add an unselected item and make sure the tilecount is still correct
QStandardItem* const item2 = MakeItemAt(coord_50_60);
item2->setSelectable(true);
itemModel->appendRow(item2);
const QPersistentModelIndex item2Index = itemModel->indexFromItem(item2);
for (int l = 0 ; l <= maxLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_50_60, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QCOMPARE(mm.getTileMarkerCount(tileIndex), 2);
QVERIFY(mm.getTileGroupState(tileIndex)==SelectedSome);
QCOMPARE(mm.getTileSelectedCount(tileIndex), 1);
}
selectionModel->select(item2Index, QItemSelectionModel::Select);
for (int l = 0 ; l <= maxLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_50_60, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QCOMPARE(mm.getTileMarkerCount(tileIndex), 2);
QCOMPARE(mm.getTileSelectedCount(tileIndex), 2);
QVERIFY(mm.getTileGroupState(tileIndex)==SelectedAll);
}
// now remove the selected item:
QCOMPARE(itemModel->takeRow(item2Index.row()).count(), 1);
delete item2;
// verify the selection state of the tiles:
for (int l = 0 ; l <= maxLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_50_60, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QCOMPARE(mm.getTileMarkerCount(tileIndex), 1);
QCOMPARE(mm.getTileSelectedCount(tileIndex), 1);
QVERIFY(mm.getTileGroupState(tileIndex)==SelectedAll);
}
// add a selected item and then move it:
QStandardItem* const item3 = MakeItemAt(coord_1_2);
item3->setSelectable(true);
itemModel->appendRow(item3);
const QPersistentModelIndex item3Index = itemModel->indexFromItem(item3);
selectionModel->select(item3Index, QItemSelectionModel::Select);
for (int l = 0 ; l <= maxLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_1_2, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QCOMPARE(mm.getTileMarkerCount(tileIndex), 1);
QCOMPARE(mm.getTileSelectedCount(tileIndex), 1);
QVERIFY(mm.getTileGroupState(tileIndex)==SelectedAll);
}
for (int l = 0 ; l <= maxLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_50_60, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QCOMPARE(mm.getTileMarkerCount(tileIndex), 1);
QCOMPARE(mm.getTileSelectedCount(tileIndex), 1);
QVERIFY(mm.getTileGroupState(tileIndex)==SelectedAll);
}
itemModel->setData(item3Index, QVariant::fromValue(coord_50_60), CoordinatesRole);
for (int l = 0 ; l <= maxLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_50_60, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QCOMPARE(mm.getTileMarkerCount(tileIndex), 2);
QCOMPARE(mm.getTileSelectedCount(tileIndex), 2);
QVERIFY(mm.getTileGroupState(tileIndex)==SelectedAll);
}
itemModel->setData(item3Index, QVariant::fromValue(coord_m50_m60), CoordinatesRole);
for (int l = 0 ; l <= maxLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_50_60, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QCOMPARE(mm.getTileMarkerCount(tileIndex), 1);
QCOMPARE(mm.getTileSelectedCount(tileIndex), 1);
QVERIFY(mm.getTileGroupState(tileIndex)==SelectedAll);
}
for (int l = 0 ; l <= maxLevel ; ++l)
{
const TileIndex tileIndex = TileIndex::fromCoordinates(coord_m50_m60, l);
ItemMarkerTiler::Tile* const myTile = mm.getTile(tileIndex, true);<--- Variable 'myTile' can be declared as pointer to const
if (!myTile)
{
QFAIL("Tile instance is null");
}
QCOMPARE(mm.getTileMarkerCount(tileIndex), 1);
QCOMPARE(mm.getTileSelectedCount(tileIndex), 1);
QVERIFY(mm.getTileGroupState(tileIndex)==SelectedAll);
}
// TODO: set a model with selected items, make sure the selections are read out
// this is currently implemented by simply setting the tiles as dirty
}
void TestItemMarkerTiler::benchmarkIteratorWholeWorld()
{
/*
* without non-empty child lists
* RESULT : TestItemMarkerTiler::benchmarkIteratorWholeWorld():
* 4,470 msecs per iteration (total: 4,470, iterations: 1)
* after adding lists:
* RESULT : TestItemMarkerTiler::benchmarkIteratorWholeWorld():
* 712 msecs per iteration (total: 712, iterations: 1)
*/
#if 0
return;
#else
QBENCHMARK
{
QScopedPointer<QStandardItemModel> itemModel(new QStandardItemModel());
ItemMarkerTiler mm(new MarkerModelHelper(itemModel.data(), 0));
const int maxLevel = TileIndex::MaxLevel;
{
int l = maxLevel-1;
ItemMarkerTiler::NonEmptyIterator it(&mm, l);
QVERIFY( CountMarkersInIterator(&it) == 0 );
}
itemModel->appendRow(MakeItemAt(coord_1_2));
itemModel->appendRow(MakeItemAt(coord_50_60));
for (qreal x = -50; x < 50; x+=1.0)
{
for (qreal y = -50; y < 50; y+=1.0)
{
itemModel->appendRow(MakeItemAt(GeoCoordinates(x,y)));
}
}
// QBENCHMARK
{
const int l = maxLevel;
// for (int l = 0; l <= maxLevel; ++l)
{
// iterate over the whole world:
ItemMarkerTiler::NonEmptyIterator it(&mm, l);
(void)CountMarkersInIterator(&it);
}
}
}
#endif
}
QTEST_GUILESS_MAIN(TestItemMarkerTiler)
#include "moc_itemmarkertiler_utest.cpp"
|