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 #ifndef DIGIKAM_SEARCH_RESULT_MODEL_H
0017 #define DIGIKAM_SEARCH_RESULT_MODEL_H
0018 
0019 // Qt includes
0020 
0021 #include <QAbstractItemModel>
0022 #include <QItemSelectionModel>
0023 
0024 // local includes
0025 
0026 #include "searchresultbackend.h"
0027 
0028 class QItemSelection;
0029 
0030 namespace DigikamGenericGeolocationEditPlugin
0031 {
0032 
0033 class SearchResultItem;
0034 
0035 class SearchResultModel : public QAbstractItemModel
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040 
0041     class SearchResultItem
0042     {
0043     public:
0044 
0045         SearchResultBackend::SearchResult result;
0046     };
0047 
0048 public:
0049 
0050     explicit SearchResultModel(QObject* const parent = nullptr);
0051     ~SearchResultModel()                                                  override;
0052 
0053     void addResults(const SearchResultBackend::SearchResult::List& results);
0054     SearchResultItem resultItem(const QModelIndex& index)           const;
0055     bool getMarkerIcon(const QModelIndex& index,
0056                        QPoint* const offset,
0057                        QSize* const size,
0058                        QPixmap* const pixmap,
0059                        QUrl* const url)                             const;
0060     void setSelectionModel(QItemSelectionModel* const selectionModel);
0061     void clearResults();
0062     void removeRowsByIndexes(const QModelIndexList& rowsList);
0063     void removeRowsBySelection(const QItemSelection& selection);
0064 
0065     // QAbstractItemModel:
0066     int columnCount(const QModelIndex& parent = QModelIndex())      const override;
0067     bool setData(const QModelIndex& index,
0068                  const QVariant& value,
0069                  int role)                                                override;
0070     QVariant data(const QModelIndex& index,
0071                   int role = Qt::DisplayRole)                       const override;
0072     QModelIndex index(int row,
0073                       int column,
0074                       const QModelIndex& parent = QModelIndex())    const override;
0075     QModelIndex parent(const QModelIndex& index)                    const override;
0076     int rowCount(const QModelIndex& parent = QModelIndex())         const override;
0077     bool setHeaderData(int section,
0078                        Qt::Orientation orientation,
0079                        const QVariant& value, int role)                   override;
0080     QVariant headerData(int section,
0081                         Qt::Orientation orientation,
0082                         int role)                                   const override;
0083     Qt::ItemFlags flags(const QModelIndex& index)                   const override;
0084 
0085 private:
0086 
0087     class Private;
0088     Private* const d;
0089 };
0090 
0091 } // namespace DigikamGenericGeolocationEditPlugin
0092 
0093 #endif // DIGIKAM_SEARCH_RESULT_MODEL_H