File indexing completed on 2025-01-05 03:58:31

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2010-03-22
0007  * Description : Drag-and-drop handler for geolocation interface integration.
0008  *
0009  * SPDX-FileCopyrightText: 2010-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2010      by Michael G. Hansen <mike at mghansen dot de>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "mapdragdrophandler.h"
0017 
0018 // Qt includes
0019 
0020 #include <QDropEvent>
0021 
0022 // local includes
0023 
0024 #include "gpsgeoifacemodelhelper.h"
0025 
0026 namespace Digikam
0027 {
0028 
0029 MapDragDropHandler::MapDragDropHandler(QAbstractItemModel* const /*pModel*/,
0030                                        GPSGeoIfaceModelHelper* const parent)
0031     : GeoDragDropHandler(parent),
0032       gpsGeoIfaceModelHelper(parent)
0033 {
0034 }
0035 
0036 MapDragDropHandler::~MapDragDropHandler()
0037 {
0038 }
0039 
0040 Qt::DropAction MapDragDropHandler::accepts(const QDropEvent* /*e*/)
0041 {
0042     return Qt::CopyAction;
0043 }
0044 
0045 bool MapDragDropHandler::dropEvent(const QDropEvent* e, const GeoCoordinates& dropCoordinates)
0046 {
0047     const MapDragData* const mimeData = qobject_cast<const MapDragData*>(e->mimeData());
0048 
0049     if (!mimeData)
0050     {
0051         return false;
0052     }
0053 
0054     QList<QPersistentModelIndex> droppedIndices;
0055 
0056     for (int i = 0 ; i < mimeData->draggedIndices.count() ; ++i)
0057     {
0058         // TODO: correctly handle items with multiple columns
0059 
0060         QModelIndex itemIndex = mimeData->draggedIndices.at(i);
0061 
0062         if (itemIndex.column() == 0)
0063         {
0064             droppedIndices << itemIndex;
0065         }
0066     }
0067 
0068     gpsGeoIfaceModelHelper->onIndicesMoved(droppedIndices, dropCoordinates, QPersistentModelIndex());
0069 
0070     return true;
0071 }
0072 
0073 QMimeData* MapDragDropHandler::createMimeData(const QList<QPersistentModelIndex>& modelIndices)
0074 {
0075     Q_UNUSED(modelIndices);
0076 
0077     return nullptr;
0078 }
0079 
0080 } // namespace Digikam
0081 
0082 #include "moc_mapdragdrophandler.cpp"