digiKam
importimagemodel.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2012-05-22
7  * Description : Qt model for camera entries
8  *
9  * Copyright (C) 2012 by Islam Wazery <wazery at ubuntu dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_IMPORT_IMAGE_MODEL_H
25 #define DIGIKAM_IMPORT_IMAGE_MODEL_H
26 
27 // Qt includes
28 
29 #include <QAbstractListModel>
30 #include <QUrl>
31 
32 // Local includes
33 
35 #include "camerathumbsctrl.h"
36 #include "camiteminfo.h"
37 
38 namespace Digikam
39 {
40 class AbstractItemDragDropHandler;
41 
42 class ImportItemModel : public QAbstractListModel, public DragDropModelImplementation
43 {
44  Q_OBJECT
45 
46 public:
47 
49  {
54  ImportItemModelInternalId = Qt::UserRole + 1,
55 
60  ThumbnailRole = Qt::UserRole + 2,
64  ExtraDataRole = Qt::UserRole + 3,
65 
69  ExtraDataDuplicateCount = Qt::UserRole + 6,
70 
71  FilterModelRoles = Qt::UserRole + 100
72  };
73 
74 public:
75 
76  explicit ImportItemModel(QObject* const parent = nullptr);
77  ~ImportItemModel() override;
78 
82  virtual void setCameraThumbsController(CameraThumbsCtrl* const controller);
83 
88  void setKeepsFileUrlCache(bool keepCache);
89  bool keepsFileUrlCache() const;
90 
96  CamItemInfo camItemInfo(const QModelIndex& index) const;
97  CamItemInfo& camItemInfoRef(const QModelIndex& index) const;
98  qlonglong camItemId(const QModelIndex& index) const;
99  CamItemInfoList camItemInfos(const QList<QModelIndex>& indexes) const;
100  QList<qlonglong> camItemIds(const QList<QModelIndex>& indexes) const;
101 
107  CamItemInfo camItemInfo(int row) const;
108  CamItemInfo& camItemInfoRef(int row) const;
109  qlonglong camItemId(int row) const;
110 
114  QModelIndex indexForCamItemInfo(const CamItemInfo& info) const;
116  QModelIndex indexForCamItemId(qlonglong id) const;
117  QList<QModelIndex> indexesForCamItemId(qlonglong id) const;
118 
124  QModelIndex indexForUrl(const QUrl& fileUrl) const;
125  QList<QModelIndex> indexesForUrl(const QUrl& fileUrl) const;
126  CamItemInfo camItemInfo(const QUrl& fileUrl) const;
127  QList<CamItemInfo> camItemInfos(const QUrl& fileUrl) const;
128 
132  void clearCamItemInfos();
133 
140  void addCamItemInfoSynchronously(const CamItemInfo& info);
142 
146  void setCamItemInfos(const CamItemInfoList& infos);
147 
151 
152  bool hasImage(qlonglong id) const;
153  bool hasImage(const CamItemInfo& info) const;
154 
155  bool isEmpty() const;
156 
160  void removeIndex(const QModelIndex& index);
161  void removeIndexs(const QList<QModelIndex>& indexes);
162  void removeCamItemInfo(const CamItemInfo& info);
163  void removeCamItemInfos(const QList<CamItemInfo>& infos);
164 
165  int numberOfIndexesForCamItemInfo(const CamItemInfo& info) const;
166  int numberOfIndexesForCamItemId(qlonglong id) const;
167 
172  static CamItemInfo retrieveCamItemInfo(const QModelIndex& index);
173  static qlonglong retrieveCamItemId(const QModelIndex& index);
174 
176  int rowCount(const QModelIndex& parent) const override;
177  QVariant data(const QModelIndex& index, int role) const override;
178  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
179  Qt::ItemFlags flags(const QModelIndex& index) const override;
180  QModelIndex index(int row, int column, const QModelIndex& parent) const override;
181 
184 
189  void setSendRemovalSignals(bool send);
190 
196  bool isRefreshing() const;
197 
198 Q_SIGNALS:
199 
205 
210  void itemInfosAdded(const QList<CamItemInfo>& infos);
211 
219 
227 
231  void preprocess(const QList<CamItemInfo>& infos);
232  void processAdded(const QList<CamItemInfo>& infos);
233 
239 
246 
247 public Q_SLOTS:
248 
249  void reAddCamItemInfos(const CamItemInfoList& infos);
250  void reAddingFinished();
251  void slotFileDeleted(const QString& folder, const QString& file, bool status);
252  void slotFileUploaded(const CamItemInfo& info);
253  void addCamItemInfo(const CamItemInfo& info);
254  void addCamItemInfos(const CamItemInfoList& infos);
255 
256 protected:
257 
264  void startRefresh();
265  void finishRefresh();
266 
273  bool hasIncrementalRefreshPending() const;
274 
282 
283  void emitDataChangedForAll();
284  void emitDataChangedForSelections(const QItemSelection& selection);
285 
289  virtual void camItemInfosCleared() {};
290 
294  virtual void itemInfosAboutToBeRemoved(int /*begin*/, int /*end*/) {};
295 
296 private:
297 
298  void appendInfos(const CamItemInfoList& infos);
299  void publiciseInfos(const CamItemInfoList& infos);
300  void cleanSituationChecks();
301  void removeRowPairs(const QList<QPair<int, int> >& toRemove);
302  void removeRowPairsWithCheck(const QList<QPair<int, int> >& toRemove);
303 
304 public:
305 
306  // NOTE: Declared public because it's used in ItemModelIncrementalUpdater class
307  class Private;
308 
309 private:
310 
311  // Disable
312  ImportItemModel(const ImportItemModel&) = delete;
313  ImportItemModel& operator=(const ImportItemModel&) = delete;
314 
315 private:
316 
317  Private* const d;
318 };
319 
320 } // namespace Digikam
321 
322 Q_DECLARE_METATYPE(Digikam::ImportItemModel*)
323 
324 #endif // DIGIKAM_IMPORT_IMAGE_MODEL_H
Definition: camiteminfo.h:48
Definition: camerathumbsctrl.h:48
Definition: dragdropimplementations.h:40
Definition: importimagemodel.h:43
QList< CamItemInfo > uniqueCamItemInfos() const
Definition: importimagemodel.cpp:504
bool keepsFileUrlCache() const
Definition: importimagemodel.cpp:139
DECLARE_MODEL_DRAG_DROP_METHODS void setSendRemovalSignals(bool send)
DragDrop methods.
Definition: importimagemodel.cpp:793
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Definition: importimagemodel.cpp:1064
void addCamItemInfoSynchronously(const CamItemInfo &info)
Definition: importimagemodel.cpp:452
bool isEmpty() const
Definition: importimagemodel.cpp:144
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: importimagemodel.cpp:1083
bool hasIncrementalRefreshPending() const
Definition: importimagemodel.cpp:683
void processAdded(const QList< CamItemInfo > &infos)
void startIncrementalRefresh()
Definition: importimagemodel.cpp:688
QModelIndex index(int row, int column, const QModelIndex &parent) const override
Definition: importimagemodel.cpp:1097
QModelIndex indexForCamItemInfo(const CamItemInfo &info) const
Definition: importimagemodel.cpp:233
int rowCount(const QModelIndex &parent) const override
QAbstractListModel implementation.
Definition: importimagemodel.cpp:1073
void finishRefresh()
Definition: importimagemodel.cpp:597
void setCamItemInfos(const CamItemInfoList &infos)
Definition: importimagemodel.cpp:488
void slotFileDeleted(const QString &folder, const QString &file, bool status)
Definition: importimagemodel.cpp:576
virtual void itemInfosAboutToBeRemoved(int, int)
Definition: importimagemodel.h:294
QVariant data(const QModelIndex &index, int role) const override
Definition: importimagemodel.cpp:1035
ImportItemModel(QObject *const parent=nullptr)
Definition: importimagemodel.cpp:109
QModelIndex indexForCamItemId(qlonglong id) const
Definition: importimagemodel.cpp:243
void emitDataChangedForSelections(const QItemSelection &selection)
Definition: importimagemodel.cpp:544
void preprocess(const QList< CamItemInfo > &infos)
int numberOfIndexesForCamItemId(qlonglong id) const
Definition: importimagemodel.cpp:274
void reAddingFinished()
Definition: importimagemodel.cpp:570
int numberOfIndexesForCamItemInfo(const CamItemInfo &info) const
Definition: importimagemodel.cpp:269
static CamItemInfo retrieveCamItemInfo(const QModelIndex &index)
Definition: importimagemodel.cpp:288
virtual void camItemInfosCleared()
Definition: importimagemodel.h:289
void reAddCamItemInfos(const CamItemInfoList &infos)
Definition: importimagemodel.cpp:565
QList< CamItemInfo > camItemInfos() const
Definition: importimagemodel.cpp:494
void itemInfosAboutToBeAdded(const QList< CamItemInfo > &infos)
qlonglong camItemId(const QModelIndex &index) const
Definition: importimagemodel.cpp:169
static qlonglong retrieveCamItemId(const QModelIndex &index)
Definition: importimagemodel.cpp:307
virtual void setCameraThumbsController(CameraThumbsCtrl *const controller)
Definition: importimagemodel.cpp:120
QList< qlonglong > camItemIds() const
Definition: importimagemodel.cpp:499
void clearCamItemInfos()
Definition: importimagemodel.cpp:468
void slotFileUploaded(const CamItemInfo &info)
Definition: importimagemodel.cpp:587
QModelIndex indexForUrl(const QUrl &fileUrl) const
Definition: importimagemodel.cpp:325
void itemInfosAdded(const QList< CamItemInfo > &infos)
void removeIndexs(const QList< QModelIndex > &indexes)
Definition: importimagemodel.cpp:751
ImportItemModelRoles
Definition: importimagemodel.h:49
@ ExtraDataRole
Definition: importimagemodel.h:64
@ FilterModelRoles
Definition: importimagemodel.h:71
@ ImportItemModelPointerRole
Definition: importimagemodel.h:53
@ ExtraDataDuplicateCount
Definition: importimagemodel.h:69
@ ImportItemModelInternalId
Definition: importimagemodel.h:54
@ ThumbnailRole
Definition: importimagemodel.h:60
QList< QModelIndex > indexesForUrl(const QUrl &fileUrl) const
Definition: importimagemodel.cpp:347
void removeCamItemInfos(const QList< CamItemInfo > &infos)
Definition: importimagemodel.cpp:776
void requestIncrementalRefresh()
Definition: importimagemodel.cpp:671
void addCamItemInfo(const CamItemInfo &info)
Definition: importimagemodel.cpp:430
QList< QModelIndex > indexesForCamItemId(qlonglong id) const
Definition: importimagemodel.cpp:255
void finishIncrementalRefresh()
Definition: importimagemodel.cpp:695
void itemInfosRemoved(const QList< CamItemInfo > &infos)
void itemInfosAboutToBeRemoved(const QList< CamItemInfo > &infos)
void removeIndex(const QModelIndex &index)
Definition: importimagemodel.cpp:746
~ImportItemModel() override
Definition: importimagemodel.cpp:115
void emitDataChangedForAll()
Definition: importimagemodel.cpp:532
bool hasImage(qlonglong id) const
Definition: importimagemodel.cpp:522
CamItemInfo camItemInfo(const QModelIndex &index) const
Definition: importimagemodel.cpp:149
bool isRefreshing() const
Definition: importimagemodel.cpp:603
void addCamItemInfos(const CamItemInfoList &infos)
Definition: importimagemodel.cpp:435
void setKeepsFileUrlCache(bool keepCache)
Definition: importimagemodel.cpp:134
void addCamItemInfosSynchronously(const Digikam::CamItemInfoList &infos)
Definition: importimagemodel.cpp:457
void removeCamItemInfo(const CamItemInfo &info)
Definition: importimagemodel.cpp:771
CamItemInfo & camItemInfoRef(const QModelIndex &index) const
Definition: importimagemodel.cpp:159
void startRefresh()
Definition: importimagemodel.cpp:592
QList< QModelIndex > indexesForCamItemInfo(const CamItemInfo &info) const
Definition: importimagemodel.cpp:238
#define DECLARE_MODEL_DRAG_DROP_METHODS
Definition: dragdropimplementations.h:90
@ Orientation
Definition: coredbfields.h:86
Definition: datefolderview.cpp:43