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
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2010-07-15
* Description : central Map view
*
* SPDX-FileCopyrightText: 2010 by Gabriel Voicu <ping dot gabi at gmail dot com>
* SPDX-FileCopyrightText: 2010 by Michael G. Hansen <mike at mghansen dot de>
* SPDX-FileCopyrightText: 2014-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "mapwidgetview.h"
// Qt includes
#include <QVBoxLayout>
#include <QApplication>
#include <QItemSelectionModel>
#include <QAbstractItemModel>
#include <QPersistentModelIndex>
#include <QScopedPointer>
#include <QTimer>
#include <QDir>
// KDE includes
#include <kconfiggroup.h>
// Local includes
#include "mapwidget.h"
#include "trackmanager.h"
#include "itemmarkertiler.h"
#include "digikam_debug.h"
#include "camerathumbsctrl.h"
#include "itemposition.h"
#include "iteminfo.h"
#include "itemmodel.h"
#include "importfiltermodel.h"
#include "importimagemodel.h"
#include "coredbwatch.h"
#include "coredbfields.h"
#include "itempropertiessidebardb.h"
#include "gpsiteminfosorter.h"
#include "importui.h"
namespace Digikam
{
class ItemAlbumModel;
class ItemFilterModel;
/**
* @class MapWidgetView
*
* @brief Class containing digiKam's central map view.
*/
class Q_DECL_HIDDEN MapWidgetView::Private
{
public:
Private() = default;
public:
MapWidget* mapWidget = nullptr;
ItemAlbumModel* imageModel = nullptr;
ItemFilterModel* imageFilterModel = nullptr;
ImportItemModel* importModel = nullptr;
ImportFilterModel* importFilterModel = nullptr;
QItemSelectionModel* selectionModel = nullptr;
MapViewModelHelper* mapViewModelHelper = nullptr;
GPSItemInfoSorter* gpsItemInfoSorter = nullptr;
TrackManager* trackManager = nullptr;
QTimer* modelTimer = nullptr;
MapWidgetView::Application application = MapWidgetView::ApplicationDigikam;
bool boundariesShouldBeAdjusted = false;
};
/**
* @brief Constructor
*
* @param selectionModel digiKam's selection model
* @param imageFilterModel digikam's filter model
* @param parent the parent object
* @param application the type of application host
*/
MapWidgetView::MapWidgetView(QItemSelectionModel* const selectionModel,
DCategorizedSortFilterProxyModel* const imageFilterModel,
QWidget* const parent,
const MapWidgetView::Application application)
: QWidget (parent),
StateSavingObject(this),
d (new Private)
{
d->application = application;
d->selectionModel = selectionModel;
d->modelTimer = new QTimer(this);
d->modelTimer->setSingleShot(true);
d->modelTimer->setInterval(50);
switch (d->application)
{
case ApplicationDigikam:
{
d->imageFilterModel = dynamic_cast<ItemFilterModel*>(imageFilterModel);
d->imageModel = dynamic_cast<ItemAlbumModel*>(imageFilterModel->sourceModel());
d->mapViewModelHelper = new MapViewModelHelper(d->selectionModel,
d->imageFilterModel,
this, ApplicationDigikam);
connect(d->imageModel, SIGNAL(allRefreshingFinished()),
d->modelTimer, SLOT(start()));
break;
}
case ApplicationImportUI:
{
d->importFilterModel = dynamic_cast<ImportFilterModel*>(imageFilterModel);
d->importModel = dynamic_cast<ImportItemModel*>(imageFilterModel->sourceModel());
d->mapViewModelHelper = new MapViewModelHelper(d->selectionModel,
d->importFilterModel,
this, ApplicationImportUI);
connect(d->importModel, SIGNAL(allRefreshingFinished()),
d->modelTimer, SLOT(start()));
break;
}
}
connect(d->modelTimer, SIGNAL(timeout()),
this, SLOT(slotModelChanged()));
QVBoxLayout* const vBoxLayout = new QVBoxLayout(this);
d->mapWidget = new MapWidget(this);
d->mapWidget->setAvailableMouseModes(MouseModePan | MouseModeZoomIntoGroup | MouseModeSelectThumbnail);
d->mapWidget->setVisibleMouseModes(MouseModePan | MouseModeZoomIntoGroup | MouseModeSelectThumbnail);
if (d->application == ApplicationDigikam)
{
d->mapWidget->setVisibleExtraActions(ExtraLoadTracks);
connect(d->mapWidget, &MapWidget::signalLoadTracksFromAlbums,
this, &MapWidgetView::slotLoadTracksFromAlbums);
}
ItemMarkerTiler* const geoifaceMarkerModel = new ItemMarkerTiler(d->mapViewModelHelper, this);
d->mapWidget->setGroupedModel(geoifaceMarkerModel);
d->mapWidget->setBackend(QLatin1String("marble"));
d->gpsItemInfoSorter = new GPSItemInfoSorter(this);
d->gpsItemInfoSorter->addToMapWidget(d->mapWidget);
d->trackManager = new TrackManager(this);
d->mapWidget->setTrackManager(d->trackManager);
connect(d->trackManager, &TrackManager::signalAllTrackFilesReady,
this, &MapWidgetView::slotAllTrackFilesReady);
vBoxLayout->addWidget(d->mapWidget);
vBoxLayout->addWidget(d->mapWidget->getControlWidget());
vBoxLayout->setContentsMargins(QMargins());
}
/**
* @brief Destructor
*/
MapWidgetView::~MapWidgetView()
{
}
void MapWidgetView::doLoadState()
{
KConfigGroup group = getConfigGroup();
d->gpsItemInfoSorter->setSortOptions(GPSItemInfoSorter::SortOptions(group.readEntry(QLatin1String("Sort Order"),
int(d->gpsItemInfoSorter->getSortOptions()))));
const KConfigGroup groupCentralMap = KConfigGroup(&group, QLatin1String("Central Map Widget"));
d->mapWidget->readSettingsFromGroup(&groupCentralMap);
}
void MapWidgetView::doSaveState()
{
KConfigGroup group = getConfigGroup();
group.writeEntry(QLatin1String("Sort Order"), int(d->gpsItemInfoSorter->getSortOptions()));
KConfigGroup groupCentralMap = KConfigGroup(&group, QLatin1String("Central Map Widget"));
d->mapWidget->saveSettingsToGroup(&groupCentralMap);
group.sync();
}
/**
* @brief Set the map active/inactive.
* @param state If true, the map is active.
*/
void MapWidgetView::setActive(const bool state)
{
d->mapWidget->setActive(state);
if (state && d->boundariesShouldBeAdjusted)
{
d->modelTimer->start();
}
}
/**
* @return The map's active state
*/
bool MapWidgetView::getActiveState() const
{
return d->mapWidget->getActiveState();
}
/**
* @brief Returns the ItemInfo for the current image
*/
ItemInfo MapWidgetView::currentItemInfo() const
{
/// @todo Have geoifacewidget honor the 'current index'
QModelIndex currentIndex = d->selectionModel->currentIndex();
if (!currentIndex.isValid())
{
/// @todo This is temporary until geoifacewidget marks a 'current index'
if (!d->selectionModel->hasSelection())
{
return ItemInfo();
}
currentIndex = d->selectionModel->selectedIndexes().first();
}
return d->imageFilterModel->imageInfo(currentIndex);
}
/**
* @brief Returns the CamItemInfo for the current image
*/
CamItemInfo MapWidgetView::currentCamItemInfo() const
{
/// @todo Have geoifacewidget honor the 'current index'
QModelIndex currentIndex = d->selectionModel->currentIndex();
if (!currentIndex.isValid())
{
/// @todo This is temporary until geoifacewidget marks a 'current index'
if (!d->selectionModel->hasSelection())
{
return CamItemInfo();
}
currentIndex = d->selectionModel->selectedIndexes().first();
}
return d->importFilterModel->camItemInfo(currentIndex);
}
void MapWidgetView::slotModelChanged()
{
if (!d->mapWidget->getActiveState())
{
d->boundariesShouldBeAdjusted = true;
return;
}
d->trackManager->setVisibility(false);
d->trackManager->clear();
bool hasCoordinates = false;
switch (d->application)
{
case ApplicationDigikam:
{
const auto infs = d->imageModel->imageInfos();
for (const ItemInfo& info : infs)
{
if (info.hasCoordinates())
{<--- Consider using std::any_of algorithm instead of a raw loop.
hasCoordinates = true;
break;
}
}
break;
}
case ApplicationImportUI:
{
const auto infs = d->importModel->camItemInfos();
for (const CamItemInfo& info : infs)
{
QScopedPointer<DMetadata> meta(new DMetadata(info.url().toLocalFile()));
double lat, lng;
if (
meta->getGPSLatitudeNumber(&lat) &&
meta->getGPSLongitudeNumber(&lng)
)
{
hasCoordinates = true;
break;
}
}
break;
}
}
if (!hasCoordinates)
{
setEnabled(false);
d->mapWidget->setCenter(GeoCoordinates(52.0, 6.0));
d->mapWidget->setZoom(QLatin1String("marble:1108"));
}
else
{
setEnabled(true);
d->mapWidget->adjustBoundariesToGroupedMarkers();
}
d->boundariesShouldBeAdjusted = false;
}
void MapWidgetView::slotAllTrackFilesReady()
{
if (d->trackManager->getTrackList().isEmpty())
{
return;
}
const TrackManager::Track track = d->trackManager->getTrackList().constFirst();
if ((track.id != 0) && (track.points.size() > 0))
{
d->mapWidget->setCenter(track.points.at(0).coordinates);
d->mapWidget->setZoom(QLatin1String("marble:2220"));
}
}
void MapWidgetView::slotLoadTracksFromAlbums()
{
QApplication::setOverrideCursor(Qt::WaitCursor);
d->trackManager->setVisibility(false);
d->trackManager->clear();
QList<QUrl> fileUrls;
const auto infs = d->imageModel->imageInfos();
for (const ItemInfo& info : infs)
{
if (info.hasCoordinates())
{
QUrl url = info.fileUrl().adjusted(QUrl::RemoveFilename |
QUrl::StripTrailingSlash);
if (!fileUrls.contains(url))
{
fileUrls << url;
}
}
}
if (fileUrls.isEmpty())
{
QApplication::restoreOverrideCursor();
return;
}
QList<QUrl> gpxList;
const QStringList filter({QLatin1String("*.gpx")});
for (const QUrl& url : std::as_const(fileUrls))
{
QDir dir(url.toLocalFile());
const auto inflst = dir.entryInfoList(filter, QDir::Files);
for (const QFileInfo& finfo : inflst)
{
gpxList << QUrl::fromLocalFile(finfo.filePath());
}
}
QApplication::restoreOverrideCursor();
if (!gpxList.isEmpty())
{
d->trackManager->loadTrackFiles(gpxList);
d->trackManager->setVisibility(true);
}
}
//-------------------------------------------------------------------------------------------------------------
class Q_DECL_HIDDEN MapViewModelHelper::Private
{
public:
Private() = default;
public:
ItemFilterModel* model = nullptr;
ImportFilterModel* importModel = nullptr;
QItemSelectionModel* selectionModel = nullptr;
ThumbnailLoadThread* thumbnailLoadThread = nullptr;
MapWidgetView::Application application = MapWidgetView::ApplicationDigikam;
};
MapViewModelHelper::MapViewModelHelper(QItemSelectionModel* const selection,
DCategorizedSortFilterProxyModel* const filterModel,
QObject* const parent,
const MapWidgetView::Application application)
: GeoModelHelper(parent),
d (new Private)
{
d->selectionModel = selection;
d->application = application;
switch (d->application)
{
case MapWidgetView::ApplicationDigikam:
{
d->model = dynamic_cast<ItemFilterModel*>(filterModel);
d->thumbnailLoadThread = new ThumbnailLoadThread(this);
connect(d->thumbnailLoadThread, SIGNAL(signalThumbnailLoaded(LoadingDescription,QPixmap)),
this, SLOT(slotThumbnailLoaded(LoadingDescription,QPixmap)));
// Note: Here we only monitor changes to the database, because changes to the model
// are also sent when thumbnails are generated, and we don't want to update
// the marker tiler for that!
connect(CoreDbAccess::databaseWatch(), SIGNAL(imageChange(ImageChangeset)),
this, SLOT(slotImageChange(ImageChangeset)), Qt::QueuedConnection);
break;
}
case MapWidgetView::ApplicationImportUI:
{
d->importModel = dynamic_cast<ImportFilterModel*>(filterModel);
connect(ImportUI::instance()->getCameraThumbsCtrl(), SIGNAL(signalThumbInfoReady(CamItemInfo)),
this, SLOT(slotThumbnailLoaded(CamItemInfo)));
break;
}
}
}
/**
* @brief Destructor
*/
MapViewModelHelper::~MapViewModelHelper()
{
}
/**
* @return Returns digiKam's filter model.
*/
QAbstractItemModel* MapViewModelHelper::model() const
{
switch (d->application)
{
case MapWidgetView::ApplicationDigikam:
{
return d->model;
}
case MapWidgetView::ApplicationImportUI:
{
return d->importModel;
}
}
return nullptr;
}
/**
* @return Returns digiKam's selection model.
*/
QItemSelectionModel* MapViewModelHelper::selectionModel() const
{
return d->selectionModel;
}
/**
* @brief Gets the coordinates of a marker found at current model index.
* @param index Current model index.
* @param coordinates Here will be returned the coordinates of the current marker.
* @return True, if the marker has coordinates.
*/
bool MapViewModelHelper::itemCoordinates(const QModelIndex& index, GeoCoordinates* const coordinates) const
{
switch (d->application)
{
case MapWidgetView::ApplicationDigikam:
{
const ItemInfo info = d->model->imageInfo(index);
if (info.isNull() || !info.hasCoordinates())
{
return false;
}
*coordinates = GeoCoordinates(info.latitudeNumber(), info.longitudeNumber());
break;
}
case MapWidgetView::ApplicationImportUI:
{
const CamItemInfo info = d->importModel->camItemInfo(index);
if (info.isNull())
{
return false;
}
QScopedPointer<DMetadata> meta(new DMetadata(info.url().toLocalFile()));
double lat, lng;
const bool haveCoordinates = meta->getGPSLatitudeNumber(&lat) && meta->getGPSLongitudeNumber(&lng);
if (!haveCoordinates)
{
return false;
}
GeoCoordinates tmpCoordinates(lat, lng);
double alt;
const bool haveAlt = meta->getGPSAltitude(&alt);
if (haveAlt)
{
tmpCoordinates.setAlt(alt);
}
*coordinates = tmpCoordinates;
break;
}
}
return true;
}
/**
* @brief This function retrieves the thumbnail for an index.
*
* @param index The marker's index.
* @param size The size of the thumbnail.
*
* @return If the thumbnail has been loaded in the ThumbnailLoadThread instance, it is returned.
* If not, a QPixmap is returned and ThumbnailLoadThread's signal named signalThumbnailLoaded
*is emitted when the thumbnail becomes available.
*/
QPixmap MapViewModelHelper::pixmapFromRepresentativeIndex(const QPersistentModelIndex& index, const QSize& size)
{
if (index == QPersistentModelIndex())
{
return QPixmap();
}
switch (d->application)
{
case MapWidgetView::ApplicationDigikam:
{
const ItemInfo info = d->model->imageInfo(index);
if (!info.isNull())
{
QPixmap thumbnail;
if (d->thumbnailLoadThread->find(info.thumbnailIdentifier(), thumbnail, qMax(size.width()+2, size.height()+2)))
{
return thumbnail.copy(1, 1, thumbnail.size().width()-2, thumbnail.size().height()-2);
}
else
{
return QPixmap();
}
}
break;
}
case MapWidgetView::ApplicationImportUI:
{
QPixmap thumbnail = index.data(ImportItemModel::ThumbnailRole).value<QPixmap>();
return thumbnail.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
}
return QPixmap();
}
/**
* @brief This function finds the best representative marker from a group of markers.
* This is needed to display a thumbnail for a marker group.
*
* @param list A list containing markers.
* @param sortKey Determines the sorting options and is actually of type GPSItemInfoSorter::SortOptions
*
* @return Returns the index of the marker.
*/
QPersistentModelIndex MapViewModelHelper::bestRepresentativeIndexFromList(const QList<QPersistentModelIndex>& list,
const int sortKey)
{
if (list.isEmpty())
{
return QPersistentModelIndex();
}
// first convert from QPersistentModelIndex to QModelIndex
QList<QModelIndex> indexList;
QModelIndex bestIndex;
for (int i = 0 ; i < list.count() ; ++i)
{
const QModelIndex newIndex(list.at(i));
indexList.append(newIndex);
}
switch (d->application)
{
case MapWidgetView::ApplicationDigikam:
{
// now get the ItemInfos and convert them to GPSItemInfos
const QList<ItemInfo> imageInfoList = d->model->imageInfos(indexList);
GPSItemInfo::List gpsItemInfoList;
for (const ItemInfo& imageInfo : std::as_const(imageInfoList))
{
GPSItemInfo gpsItemInfo;
if (ItemPropertiesSideBarDB::GPSItemInfofromItemInfo(imageInfo, &gpsItemInfo))
{
gpsItemInfoList << gpsItemInfo;
}
}
if (gpsItemInfoList.size() != indexList.size())
{
// this is a problem, and unexpected
return indexList.first();
}
// now determine the best available index
bestIndex = indexList.first();
GPSItemInfo bestGPSItemInfo = gpsItemInfoList.first();
for (int i = 1 ; i < gpsItemInfoList.count() ; ++i)
{
const GPSItemInfo& currentInfo = gpsItemInfoList.at(i);
if (GPSItemInfoSorter::fitsBetter(bestGPSItemInfo, SelectedNone,
currentInfo, SelectedNone,
SelectedNone, GPSItemInfoSorter::SortOptions(sortKey)))
{
bestIndex = indexList.at(i);
bestGPSItemInfo = currentInfo;
}
}
break;
}
case MapWidgetView::ApplicationImportUI:
{
// now get the CamItemInfo and convert them to GPSItemInfos
const QList<CamItemInfo> imageInfoList = d->importModel->camItemInfos(indexList);
GPSItemInfo::List gpsItemInfoList;
for (const CamItemInfo& imageInfo : std::as_const(imageInfoList))
{
QScopedPointer<DMetadata> meta(new DMetadata(imageInfo.url().toLocalFile()));
double lat, lng;
const bool hasCoordinates = meta->getGPSLatitudeNumber(&lat) && meta->getGPSLongitudeNumber(&lng);
if (!hasCoordinates)
{
continue;
}
GeoCoordinates coordinates(lat, lng);
double alt;
const bool haveAlt = meta->getGPSAltitude(&alt);
if (haveAlt)
{
coordinates.setAlt(alt);
}
GPSItemInfo gpsItemInfo;
gpsItemInfo.coordinates = coordinates;
gpsItemInfo.dateTime = meta->getItemDateTime();
gpsItemInfo.rating = meta->getItemRating();
gpsItemInfo.url = imageInfo.url();
gpsItemInfoList << gpsItemInfo;
}
if (gpsItemInfoList.size() != indexList.size())
{
// this is a problem, and unexpected
return indexList.first();
}
// now determine the best available index
bestIndex = indexList.first();
GPSItemInfo bestGPSItemInfo = gpsItemInfoList.first();
for (int i = 1 ; i < gpsItemInfoList.count() ; ++i)
{
const GPSItemInfo& currentInfo = gpsItemInfoList.at(i);
if (GPSItemInfoSorter::fitsBetter(bestGPSItemInfo, SelectedNone,
currentInfo, SelectedNone,
SelectedNone, GPSItemInfoSorter::SortOptions(sortKey)))
{
bestIndex = indexList.at(i);
bestGPSItemInfo = currentInfo;
}
}
break;
}
}
// and return the index
return QPersistentModelIndex(bestIndex);
}
/**
* @brief Because of a call to pixmapFromRepresentativeIndex, some thumbnails are not yet loaded at the time of requesting.
* When each thumbnail loads, this slot is called and emits a signal that announces the map that the thumbnail is available.
*
* This slot is used in the Digikam main application UI.
*/
void MapViewModelHelper::slotThumbnailLoaded(const LoadingDescription& loadingDescription, const QPixmap& thumb)
{
if (thumb.isNull())
{
return;
}
const QModelIndex currentIndex = d->model->indexForPath(loadingDescription.filePath);
if (currentIndex.isValid())
{
QPersistentModelIndex goodIndex(currentIndex);
Q_EMIT signalThumbnailAvailableForIndex(goodIndex, thumb.copy(1, 1, thumb.size().width()-2, thumb.size().height()-2));
}
}
/**
* @brief Because of a call to pixmapFromRepresentativeIndex, some thumbnails are not yet loaded at the time of requesting.
* When each thumbnail loads, this slot is called and emits a signal that announces to the map that the thumbnail is available.
*
* This slot is used in the ImportUI interface.
*/
void MapViewModelHelper::slotThumbnailLoaded(const CamItemInfo& info)
{
CachedItem item;
ImportUI::instance()->getCameraThumbsCtrl()->getThumbInfo(info, item);
QPixmap pix = item.second;
if (pix.isNull())
{
return;
}
const QModelIndex currentIndex = d->importModel->indexForPath(info.folder + info.name);
if (currentIndex.isValid())
{
QPersistentModelIndex goodIndex(currentIndex);
Q_EMIT signalThumbnailAvailableForIndex(goodIndex, pix.copy(1, 1, pix.size().width()-2, pix.size().height()-2));
}
}
/**
* @brief This functions is called when one clicks on a thumbnail.
*
* @param clickedIndices A list containing the marker indices belonging the group whose thumbnail has been clicked.
*/
void MapViewModelHelper::onIndicesClicked(const QList<QPersistentModelIndex>& clickedIndices)
{
/// @todo What do we do when an image is clicked?
#if 0
QList<QModelIndex> indexList;
for (int i = 0 ; i < clickedIndices.count() ; ++i)
{
const QModelIndex newIndex(clickedIndices.at(i));
indexList.append(newIndex);
}
const QList<ItemInfo> imageInfoList = d->model->imageInfos(indexList);
QList<qlonglong> imagesIdList;
for (int i = 0 ; i < imageInfoList.count() ; ++i)
{
imagesIdList.append(imageInfoList[i].id());
}
Q_EMIT signalFilteredImages(imagesIdList);
#else
Q_UNUSED(clickedIndices);
#endif
}
void MapViewModelHelper::slotImageChange(const ImageChangeset& changeset)
{
const DatabaseFields::Set changes = changeset.changes();
/*
const DatabaseFields::ItemPositions imagePositionChanges = changes;
*/
/// @todo More detailed check
if (
(changes & DatabaseFields::LatitudeNumber) ||
(changes & DatabaseFields::LongitudeNumber) ||
(changes & DatabaseFields::Altitude)
)
{
const auto ids = changeset.ids();
for (const qlonglong& id : ids)
{
const QModelIndex index = d->model->indexForImageId(id);
if (index.isValid())
{
Q_EMIT signalModelChangedDrastically();
break;
}
}
}
}
} // namespace Digikam
#include "moc_mapwidgetview.cpp"
|