File indexing completed on 2025-01-19 03:51:19
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-06-01 0007 * Description : A widget to search for places. 0008 * 0009 * SPDX-FileCopyrightText: 2010-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2010-2011 by Michael G. Hansen <mike at mghansen dot de> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "searchresultmodelhelper.h" 0017 0018 // Qt includes 0019 0020 #include <QContextMenuEvent> 0021 #include <QListView> 0022 #include <QPainter> 0023 #include <QPushButton> 0024 #include <QToolButton> 0025 #include <QTreeView> 0026 #include <QVBoxLayout> 0027 #include <QWidget> 0028 #include <QMenu> 0029 #include <QAction> 0030 #include <QComboBox> 0031 #include <QStandardPaths> 0032 #include <QLineEdit> 0033 #include <QMessageBox> 0034 0035 // KDE includes 0036 0037 #include <kconfiggroup.h> 0038 #include <klocalizedstring.h> 0039 0040 // Local includes 0041 0042 #include "gpscommon.h" 0043 0044 using namespace Digikam; 0045 0046 namespace DigikamGenericGeolocationEditPlugin 0047 { 0048 0049 class Q_DECL_HIDDEN SearchResultModelHelper::Private 0050 { 0051 public: 0052 0053 explicit Private() 0054 : model (nullptr), 0055 selectionModel(nullptr), 0056 imageModel (nullptr), 0057 visible (true) 0058 { 0059 } 0060 0061 SearchResultModel* model; 0062 QItemSelectionModel* selectionModel; 0063 GPSItemModel* imageModel; 0064 bool visible; 0065 }; 0066 0067 SearchResultModelHelper::SearchResultModelHelper(SearchResultModel* const resultModel, 0068 QItemSelectionModel* const selectionModel, 0069 GPSItemModel* const imageModel, 0070 QObject* const parent) 0071 : GeoModelHelper(parent), 0072 d (new Private()) 0073 { 0074 d->model = resultModel; 0075 d->selectionModel = selectionModel; 0076 d->imageModel = imageModel; 0077 } 0078 0079 SearchResultModelHelper::~SearchResultModelHelper() 0080 { 0081 delete d; 0082 } 0083 0084 QAbstractItemModel* SearchResultModelHelper::model() const 0085 { 0086 return d->model; 0087 } 0088 0089 QItemSelectionModel* SearchResultModelHelper::selectionModel() const 0090 { 0091 return d->selectionModel; 0092 } 0093 0094 bool SearchResultModelHelper::itemCoordinates(const QModelIndex& index, 0095 GeoCoordinates* const coordinates) const 0096 { 0097 const SearchResultModel::SearchResultItem item = d->model->resultItem(index); 0098 *coordinates = item.result.coordinates; 0099 0100 return true; 0101 } 0102 0103 void SearchResultModelHelper::setVisibility(const bool state) 0104 { 0105 d->visible = state; 0106 Q_EMIT signalVisibilityChanged(); 0107 } 0108 0109 bool SearchResultModelHelper::itemIcon(const QModelIndex& index, 0110 QPoint* const offset, 0111 QSize* const size, 0112 QPixmap* const pixmap, 0113 QUrl* const url) const 0114 { 0115 return d->model->getMarkerIcon(index, offset, size, pixmap, url); 0116 } 0117 0118 GeoModelHelper::PropertyFlags SearchResultModelHelper::modelFlags() const 0119 { 0120 return (FlagSnaps | (d->visible ? FlagVisible:FlagNull)); 0121 } 0122 0123 GeoModelHelper::PropertyFlags SearchResultModelHelper::itemFlags(const QModelIndex& /*index*/) const 0124 { 0125 return (FlagVisible | FlagSnaps); 0126 } 0127 0128 void SearchResultModelHelper::snapItemsTo(const QModelIndex& targetIndex, 0129 const QList<QModelIndex>& snappedIndices) 0130 { 0131 GPSUndoCommand* const undoCommand = new GPSUndoCommand(); 0132 SearchResultModel::SearchResultItem targetItem = d->model->resultItem(targetIndex); 0133 const GeoCoordinates& targetCoordinates = targetItem.result.coordinates; 0134 0135 for (int i = 0 ; i < snappedIndices.count() ; ++i) 0136 { 0137 const QPersistentModelIndex itemIndex = snappedIndices.at(i); 0138 GPSItemContainer* const item = d->imageModel->itemFromIndex(itemIndex); 0139 0140 GPSUndoCommand::UndoInfo undoInfo(itemIndex); 0141 undoInfo.readOldDataFromItem(item); 0142 0143 GPSDataContainer newData; 0144 newData.setCoordinates(targetCoordinates); 0145 item->setGPSData(newData); 0146 0147 undoInfo.readNewDataFromItem(item); 0148 0149 undoCommand->addUndoInfo(undoInfo); 0150 } 0151 0152 undoCommand->setText(i18np("1 image snapped to '%2'", 0153 "%1 images snapped to '%2'", snappedIndices.count(), targetItem.result.name)); 0154 0155 Q_EMIT signalUndoCommand(undoCommand); 0156 } 0157 0158 } // namespace DigikamGenericGeolocationEditPlugin 0159 0160 #include "moc_searchresultmodelhelper.cpp"