digiKam
itemmodel.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 : 2009-03-05
7  * Description : Qt item model for database entries
8  *
9  * Copyright (C) 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2012-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
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_ITEM_MODEL_H
26 #define DIGIKAM_ITEM_MODEL_H
27 
28 // Qt includes
29 
30 #include <QAbstractListModel>
31 
32 // Local includes
33 
35 #include "iteminfo.h"
36 #include "digikam_export.h"
37 
38 class QItemSelection;
39 
40 namespace Digikam
41 {
42 
43 class ImageChangeset;
44 class ImageTagChangeset;
45 
46 namespace DatabaseFields
47 {
48 class Set;
49 }
50 
51 class DIGIKAM_DATABASE_EXPORT ItemModel : public QAbstractListModel,
53 {
54  Q_OBJECT
55 
56 public:
57 
59  {
63  ItemModelPointerRole = Qt::UserRole,
64  ItemModelInternalId = Qt::UserRole + 1,
65 
70  ThumbnailRole = Qt::UserRole + 2,
71 
75  CreationDateRole = Qt::UserRole + 3,
76 
80  ExtraDataRole = Qt::UserRole + 5,
81 
85  ExtraDataDuplicateCount = Qt::UserRole + 6,
86 
91  LTLeftPanelRole = Qt::UserRole + 50,
92 
96  LTRightPanelRole = Qt::UserRole + 51,
97 
101  SubclassRoles = Qt::UserRole + 100,
102 
106  FilterModelRoles = Qt::UserRole + 500
107  };
108 
109 public:
110 
111  explicit ItemModel(QObject* const parent = nullptr);
112  ~ItemModel() override;
113 
118  void setKeepsFilePathCache(bool keepCache);
119  bool keepsFilePathCache() const;
120 
126  void setWatchFlags(const DatabaseFields::Set& set);
127 
134  ItemInfo imageInfo(const QModelIndex& index) const;
135  ItemInfo& imageInfoRef(const QModelIndex& index) const;
136  qlonglong imageId(const QModelIndex& index) const;
137  QList<ItemInfo> imageInfos(const QList<QModelIndex>& indexes) const;
138  QList<qlonglong> imageIds(const QList<QModelIndex>& indexes) const;
139 
145  ItemInfo imageInfo(int row) const;
146  ItemInfo& imageInfoRef(int row) const;
147  qlonglong imageId(int row) const;
148 
152  QModelIndex indexForItemInfo(const ItemInfo& info) const;
153  QModelIndex indexForItemInfo(const ItemInfo& info, const QVariant& extraValue) const;
154  QModelIndex indexForImageId(qlonglong id) const;
155  QModelIndex indexForImageId(qlonglong id, const QVariant& extraValue) const;
156  QList<QModelIndex> indexesForItemInfo(const ItemInfo& info) const;
157  QList<QModelIndex> indexesForImageId(qlonglong id) const;
158 
159  int numberOfIndexesForItemInfo(const ItemInfo& info) const;
160  int numberOfIndexesForImageId(qlonglong id) const;
161 
169  QModelIndex indexForPath(const QString& filePath) const;
170  ItemInfo imageInfo(const QString& filePath) const;
171  QList<QModelIndex> indexesForPath(const QString& filePath) const;
172  QList<ItemInfo> imageInfos(const QString& filePath) const;
173 
180  void addItemInfo(const ItemInfo& info);
181  void addItemInfos(const QList<ItemInfo>& infos);
182  void addItemInfos(const QList<ItemInfo>& infos, const QList<QVariant>& extraValues);
183 
187  void clearItemInfos();
188 
192  void setItemInfos(const QList<ItemInfo>& infos);
193 
197  void removeIndex(const QModelIndex& indexes);
198  void removeIndexes(const QList<QModelIndex>& indexes);
199  void removeItemInfo(const ItemInfo& info);
200  void removeItemInfos(const QList<ItemInfo>& infos);
201  void removeItemInfos(const QList<ItemInfo>& infos, const QList<QVariant>& extraValues);
202 
210  void addItemInfoSynchronously(const ItemInfo& info);
211  void addItemInfosSynchronously(const QList<ItemInfo>& infos);
212  void addItemInfosSynchronously(const QList<ItemInfo>& infos, const QList<QVariant>& extraValues);
213 
219  void ensureHasItemInfo(const ItemInfo& info);
220  void ensureHasItemInfos(const QList<ItemInfo>& infos);
221  void ensureHasItemInfos(const QList<ItemInfo>& infos, const QList<QVariant>& extraValues);
222 
226  void ensureHasGroupedImages(const ItemInfo& groupLeader);
227 
228  QList<ItemInfo> imageInfos() const;
229  QList<qlonglong> imageIds() const;
230  QList<ItemInfo> uniqueItemInfos() const;
231 
232  bool hasImage(qlonglong id) const;
233  bool hasImage(const ItemInfo& info) const;
234  bool hasImage(const ItemInfo& info, const QVariant& extraValue) const;
235  bool hasImage(qlonglong id, const QVariant& extraValue) const;
236 
237  bool isEmpty() const;
238  int itemCount() const;
239 
240  // Drag and Drop
242 
255  void setPreprocessor(QObject* const processor);
256  void unsetPreprocessor(QObject* const processor);
257 
263  bool isRefreshing() const;
264 
269  void setSendRemovalSignals(bool send);
270 
271  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
272  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
273  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
274  Qt::ItemFlags flags(const QModelIndex& index) const override;
275  QModelIndex index(int row, int column = 0, const QModelIndex& parent = QModelIndex()) const override;
276 
281  static ItemInfo retrieveItemInfo(const QModelIndex& index);
282  static qlonglong retrieveImageId(const QModelIndex& index);
283 
284 Q_SIGNALS:
285 
291 
296  void imageInfosAdded(const QList<ItemInfo>& infos);
297 
305 
312  void imageInfosRemoved(const QList<ItemInfo>& infos);
313 
317  void preprocess(const QList<ItemInfo>& infos, const QList<QVariant>&);
318  void processAdded(const QList<ItemInfo>& infos, const QList<QVariant>&);
319 
324  void imageChange(const ImageChangeset&, const QItemSelection&);
325 
330  void imageTagChange(const ImageTagChangeset&, const QItemSelection&);
331 
337 
344 
345 public Q_SLOTS:
346 
347  void reAddItemInfos(const QList<ItemInfo>& infos, const QList<QVariant>& extraValues);
348  void reAddingFinished();
349 
350 protected:
351 
358  void startRefresh();
359  void finishRefresh();
360 
366  void requestIncrementalRefresh();
367  bool hasIncrementalRefreshPending() const;
368 
374  void startIncrementalRefresh();
375  void finishIncrementalRefresh();
376 
377  void emitDataChangedForAll();
378  void emitDataChangedForSelection(const QItemSelection& selection);
379 
383  virtual void imageInfosCleared() {};
384 
388  virtual void imageInfosAboutToBeRemoved(int /*begin*/, int /*end*/) {};
389 
390 protected Q_SLOTS:
391 
392  virtual void slotImageChange(const ImageChangeset& changeset);
393  virtual void slotImageTagChange(const ImageTagChangeset& changeset);
394 
395 private:
396 
397  void appendInfos(const QList<ItemInfo>& infos, const QList<QVariant>& extraValues);
398  void appendInfosChecked(const QList<ItemInfo>& infos, const QList<QVariant>& extraValues);
399  void publiciseInfos(const QList<ItemInfo>& infos, const QList<QVariant>& extraValues);
400  void cleanSituationChecks();
401  void removeRowPairsWithCheck(const QList<QPair<int, int> >& toRemove);
402  void removeRowPairs(const QList<QPair<int, int> >& toRemove);
403 
404 public:
405 
406  // Declared public because it's used in ItemModelIncrementalUpdater class
407  class Private;
408 
409 private:
410 
411  // Disable
412  ItemModel(const ItemModel&) = delete;
413  ItemModel& operator=(const ItemModel&) = delete;
414 
415  Private* const d;
416 };
417 
418 } // namespace Digikam
419 
420 Q_DECLARE_METATYPE(Digikam::ItemModel*)
421 
422 #endif // DIGIKAM_ITEM_MODEL_H
Definition: coredbfields.h:389
Definition: dragdropimplementations.h:40
Definition: coredbchangesets.h:48
Definition: coredbchangesets.h:80
Definition: iteminfo.h:78
Definition: itemmodel.h:53
ItemModelRoles
Definition: itemmodel.h:59
virtual void imageInfosAboutToBeRemoved(int, int)
Definition: itemmodel.h:388
virtual void imageInfosCleared()
Definition: itemmodel.h:383
void imageInfosAdded(const QList< ItemInfo > &infos)
void imageInfosRemoved(const QList< ItemInfo > &infos)
void readyForIncrementalRefresh()
void imageInfosAboutToBeRemoved(const QList< ItemInfo > &infos)
void preprocess(const QList< ItemInfo > &infos, const QList< QVariant > &)
void allRefreshingFinished()
void imageChange(const ImageChangeset &, const QItemSelection &)
void imageInfosAboutToBeAdded(const QList< ItemInfo > &infos)
void imageTagChange(const ImageTagChangeset &, const QItemSelection &)
void processAdded(const QList< ItemInfo > &infos, const QList< QVariant > &)
#define DECLARE_MODEL_DRAG_DROP_METHODS
Definition: dragdropimplementations.h:90
@ Orientation
Definition: coredbfields.h:86
Definition: datefolderview.cpp:43