File indexing completed on 2025-01-05 03:58:36
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-12-01 0007 * Description : world map widget library 0008 * 0009 * SPDX-FileCopyrightText: 2010-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2009-2011 by Michael G. Hansen <mike at mghansen dot de> 0011 * SPDX-FileCopyrightText: 2014 by Justus Schwartz <justus at gmx dot li> 0012 * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #include "mapwidget_p.h" 0018 0019 namespace Digikam 0020 { 0021 0022 void MapWidget::addUngroupedModel(GeoModelHelper* const modelHelper) 0023 { 0024 s->ungroupedModels << modelHelper; 0025 0026 /// @todo monitor all model signals! 0027 0028 connect(modelHelper->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), 0029 this, SLOT(slotUngroupedModelChanged())); 0030 0031 connect(modelHelper->model(), SIGNAL(rowsInserted(QModelIndex,int,int)), 0032 this, SLOT(slotUngroupedModelChanged())); 0033 0034 connect(modelHelper->model(), SIGNAL(modelReset()), 0035 this, SLOT(slotUngroupedModelChanged())); 0036 0037 connect(modelHelper, SIGNAL(signalVisibilityChanged()), 0038 this, SLOT(slotUngroupedModelChanged())); 0039 0040 if (modelHelper->selectionModel()) 0041 { 0042 connect(modelHelper->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), 0043 this, SLOT(slotUngroupedModelChanged())); 0044 } 0045 0046 Q_EMIT signalUngroupedModelChanged(s->ungroupedModels.count() - 1); 0047 } 0048 0049 void MapWidget::removeUngroupedModel(GeoModelHelper* const modelHelper) 0050 { 0051 if (!modelHelper) 0052 { 0053 return; 0054 } 0055 0056 const int modelIndex = s->ungroupedModels.indexOf(modelHelper); 0057 0058 if (modelIndex < 0) 0059 { 0060 return; 0061 } 0062 0063 /// @todo monitor all model signals! 0064 0065 disconnect(modelHelper->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), 0066 this, SLOT(slotUngroupedModelChanged())); 0067 0068 disconnect(modelHelper->model(), SIGNAL(rowsInserted(QModelIndex,int,int)), 0069 this, SLOT(slotUngroupedModelChanged())); 0070 0071 disconnect(modelHelper->model(), SIGNAL(modelReset()), 0072 this, SLOT(slotUngroupedModelChanged())); 0073 0074 disconnect(modelHelper, SIGNAL(signalVisibilityChanged()), 0075 this, SLOT(slotUngroupedModelChanged())); 0076 0077 if (modelHelper->selectionModel()) 0078 { 0079 disconnect(modelHelper->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), 0080 this, SLOT(slotUngroupedModelChanged())); 0081 } 0082 0083 s->ungroupedModels.removeAt(modelIndex); 0084 0085 // the indices changed, therefore send out notifications 0086 // sending out a signal with i=s->ungroupedModel.count() 0087 // will cause the backends to see that the last model is missing 0088 0089 for (int i = modelIndex ; i <= s->ungroupedModels.count() ; ++i) 0090 { 0091 Q_EMIT signalUngroupedModelChanged(i); 0092 } 0093 } 0094 0095 void MapWidget::setGroupedModel(AbstractMarkerTiler* const markerModel) 0096 { 0097 s->markerModel = markerModel; 0098 0099 if (s->markerModel) 0100 { 0101 s->markerModel->setActive(s->activeState); 0102 0103 /// @todo this needs some buffering for the google maps backend 0104 0105 connect(s->markerModel, SIGNAL(signalTilesOrSelectionChanged()), 0106 this, SLOT(slotRequestLazyReclustering())); 0107 0108 if (d->currentBackend) 0109 { 0110 connect(s->markerModel, SIGNAL(signalThumbnailAvailableForIndex(QVariant,QPixmap)), 0111 d->currentBackend, SLOT(slotThumbnailAvailableForIndex(QVariant,QPixmap))); 0112 } 0113 } 0114 0115 slotRequestLazyReclustering(); 0116 } 0117 0118 void MapWidget::setDragDropHandler(GeoDragDropHandler* const dragDropHandler) 0119 { 0120 d->dragDropHandler = dragDropHandler; 0121 } 0122 0123 void MapWidget::setTrackManager(TrackManager* const trackManager) 0124 { 0125 s->trackManager = trackManager; 0126 0127 // Some backends track the track manager activity even when not active 0128 // therefore they have to be notified. 0129 0130 Q_FOREACH (MapBackend* const backend, d->loadedBackends) 0131 { 0132 backend->slotTrackManagerChanged(); 0133 } 0134 } 0135 0136 0137 void MapWidget::slotUngroupedModelChanged() 0138 { 0139 // determine the index under which we handle this model 0140 0141 QObject* const senderObject = sender(); 0142 QAbstractItemModel* const senderModel = qobject_cast<QAbstractItemModel*>(senderObject); 0143 0144 if (senderModel) 0145 { 0146 for (int i = 0 ; i < s->ungroupedModels.count() ; ++i) 0147 { 0148 if (s->ungroupedModels.at(i)->model() == senderModel) 0149 { 0150 Q_EMIT signalUngroupedModelChanged(i); 0151 0152 break; 0153 } 0154 } 0155 return; 0156 } 0157 0158 GeoModelHelper* const senderHelper = qobject_cast<GeoModelHelper*>(senderObject); 0159 0160 if (senderHelper) 0161 { 0162 for (int i = 0 ; i < s->ungroupedModels.count() ; ++i) 0163 { 0164 if (s->ungroupedModels.at(i) == senderHelper) 0165 { 0166 Q_EMIT signalUngroupedModelChanged(i); 0167 0168 break; 0169 } 0170 } 0171 } 0172 0173 QItemSelectionModel* const senderSelectionModel = qobject_cast<QItemSelectionModel*>(senderObject); 0174 0175 if (senderSelectionModel) 0176 { 0177 for (int i = 0 ; i < s->ungroupedModels.count() ; ++i) 0178 { 0179 if (s->ungroupedModels.at(i)->selectionModel() == senderSelectionModel) 0180 { 0181 Q_EMIT signalUngroupedModelChanged(i); 0182 0183 break; 0184 } 0185 } 0186 0187 return; 0188 } 0189 } 0190 0191 } // namespace Digikam