1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2010-03-21
7  * Description : A model to hold GPS information about items.
8  *
9  * Copyright (C) 2010-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2010      by Michael G. Hansen <mike at mghansen dot de>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_GPS_ITEM_MODEL_H
26 #define DIGIKAM_GPS_ITEM_MODEL_H
27 
28 // Qt includes
29 
30 #include <QAbstractItemModel>
31 #include <QPixmap>
32 
33 // Local includes
34 
35 #include "gpsitemcontainer.h"
36 #include "thumbnailloadthread.h"
37 #include "digikam_export.h"
38 
39 namespace Digikam
40 {
41 
42 class DIGIKAM_EXPORT GPSItemModel : public QAbstractItemModel
43 {
44     Q_OBJECT
45 
46 public:
47 
48     explicit GPSItemModel(QObject* const parent = nullptr);
49     ~GPSItemModel()                                                                                       override;
50 
51     // own functions:
52 
53     void addItem(GPSItemContainer* const newItem);
54     void setColumnCount(const int nColumns);
55     GPSItemContainer* itemFromIndex(const QModelIndex& index)                                       const;
56     GPSItemContainer* itemFromUrl(const QUrl& url)                                                  const;
57     QModelIndex indexFromUrl(const QUrl& url)                                                       const;
58 
59     QPixmap getPixmapForIndex(const QPersistentModelIndex& itemIndex, const int size);
60 
61     // QAbstractItemModel customizations:
62 
63     int columnCount(const QModelIndex& parent = QModelIndex())                                      const override;
64     bool setData(const QModelIndex& index, const QVariant& value, int role)                               override;
65     QVariant data(const QModelIndex& index, int role = Qt::DisplayRole)                             const override;
66     QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex())               const override;
67     QModelIndex parent(const QModelIndex& index)                                                    const override;
68     int rowCount(const QModelIndex& parent = QModelIndex())                                         const override;
69     bool setHeaderData(int section, Qt::Orientation orientation, const QVariant& value, int role)         override;
70     QVariant headerData(int section, Qt::Orientation orientation, int role)                         const override;
71     Qt::ItemFlags flags(const QModelIndex& index)                                                   const override;
72     Qt::DropActions supportedDragActions()                                                          const override;
73 
74 protected:
75 
76     void itemChanged(GPSItemContainer* const changedItem);
77 
78 Q_SIGNALS:
79 
80     void signalThumbnailForIndexAvailable(const QPersistentModelIndex& index, const QPixmap& pixmap);
81 
82 protected Q_SLOTS:
83 
84     void slotThumbnailLoaded(const LoadingDescription&, const QPixmap&);
85 
86 private:
87 
88     class Private;
89     Private* const d;
90 
91     friend class GPSItemContainer;
92 };
93 
94 } // namespace Digikam
95 
96 #endif // DIGIKAM_GPS_ITEM_MODEL_H
97