digiKam
abstractalbummodel.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-23
7  * Description : Qt Model for Albums
8  *
9  * Copyright (C) 2008-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2010 by Andi Clemens <andi dot clemens at gmail dot com>
11  * Copyright (C) 2012-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_ABSTRACT_ALBUM_MODEL_H
27 #define DIGIKAM_ABSTRACT_ALBUM_MODEL_H
28 
29 // Qt includes
30 
31 #include <QAbstractItemModel>
32 #include <QHash>
33 #include <QPixmap>
34 #include <QSet>
35 
36 // Local includes
37 
38 #include "album.h"
39 #include "digikam_export.h"
40 
41 namespace Digikam
42 {
43 
44 class Album;
45 class AlbumManager;
46 class AlbumModelDragDropHandler;
47 
48 class DIGIKAM_GUI_EXPORT AbstractAlbumModel : public QAbstractItemModel
49 {
50  Q_OBJECT
51 
52 public:
53 
60  {
70  IgnoreRootAlbum
71  };
72 
74  {
76  AlbumTitleRole = Qt::UserRole,
78  AlbumTypeRole = Qt::UserRole + 1,
80  AlbumPointerRole = Qt::UserRole + 2,
82  AlbumIdRole = Qt::UserRole + 3,
84  AlbumGlobalIdRole = Qt::UserRole + 4,
86  AlbumSortRole = Qt::UserRole + 5
87  };
88 
89 public:
90 
96  explicit AbstractAlbumModel(Album::Type albumType,
97  Album* const rootAlbum,
98  RootAlbumBehavior rootBehavior = IncludeRootAlbum,
99  QObject* const parent = nullptr);
100  ~AbstractAlbumModel() override;
101 
105  void setDragDropHandler(AlbumModelDragDropHandler* handler);
106 
110  AlbumModelDragDropHandler* dragDropHandler() const;
111 
115  Album* albumForIndex(const QModelIndex& index) const;
116 
121  QModelIndex indexForAlbum(Album* album) const;
122 
127  static Album* retrieveAlbum(const QModelIndex& index);
128 
129  Album* rootAlbum() const;
130 
134  QModelIndex rootAlbumIndex() const;
135 
139  RootAlbumBehavior rootAlbumBehavior() const;
140 
144  Album::Type albumType() const;
145 
149  bool isFaceTagModel() const;
150 
151  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
152  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
153  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
154  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
155  Qt::ItemFlags flags(const QModelIndex& index) const override;
156  bool hasChildren(const QModelIndex& parent = QModelIndex()) const override;
157  QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
158  QModelIndex parent(const QModelIndex& index) const override;
159 
160  Qt::DropActions supportedDropActions() const override;
161  QStringList mimeTypes() const override;
162  bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) override;
163  QMimeData* mimeData(const QModelIndexList& indexes) const override;
164 
165 Q_SIGNALS:
166 
173 
174 protected:
175 
180  void setEnableDrag(bool enable);
181  void setEnableDrop(bool enable);
182  void setFaceTagModel(bool enable);
183 
189  virtual QVariant albumData(Album* a, int role) const;
190 
192  virtual QVariant decorationRoleData(Album* a) const;
193 
195  virtual QVariant fontRoleData(Album* a) const;
196 
198  virtual QVariant sortRoleData(Album* a) const;
199 
201  virtual QString columnHeader() const;
202 
204  virtual Qt::ItemFlags itemFlags(Album* album) const;
205 
210  virtual bool filterAlbum(Album* album) const;
211 
213  virtual void albumCleared(Album* /*album*/) {};
214 
216  virtual void allAlbumsCleared() {};
217 
218 protected Q_SLOTS:
219 
220  void slotAlbumAboutToBeAdded(Album* album, Album* parent, Album* prev);
221  void slotAlbumAdded(Album*);
222  void slotAlbumAboutToBeDeleted(Album* album);
223  void slotAlbumHasBeenDeleted(quintptr);
224  void slotAlbumsCleared();
225  void slotAlbumIconChanged(Album* album);
226  void slotAlbumRenamed(Album* album);
227 
228 private:
229 
230  class Private;
231  Private* const d;
232 };
233 
234 // ------------------------------------------------------------------
235 
236 class DIGIKAM_GUI_EXPORT AbstractSpecificAlbumModel : public AbstractAlbumModel
237 {
238  Q_OBJECT
239 
240 public:
241 
243  explicit AbstractSpecificAlbumModel(Album::Type albumType,
244  Album* const rootAlbum,
245  RootAlbumBehavior rootBehavior = IncludeRootAlbum,
246  QObject* const parent = nullptr);
247 
248 protected:
249 
250  QString columnHeader() const override;
251  void setColumnHeader(const QString& header);
252 
254  void setupThumbnailLoading();
255  void emitDataChangedForChildren(Album* album);
256 
257 protected Q_SLOTS:
258 
259  void slotGotThumbnailFromIcon(Album* album, const QPixmap& thumbnail);
260  void slotThumbnailLost(Album* album);
261  void slotReloadThumbnails();
262 
263 protected:
264 
265  QString m_columnHeader;
266 };
267 
268 // ------------------------------------------------------------------
269 
271 {
272  Q_OBJECT
273 
274 public:
275 
277 
278  explicit AbstractCountingAlbumModel(Album::Type albumType,
279  Album* const rootAlbum,
280  RootAlbumBehavior rootBehavior = IncludeRootAlbum,
281  QObject* const parent = nullptr);
282  ~AbstractCountingAlbumModel() override;
283 
284  bool showCount() const;
285 
291  virtual int albumCount(Album* album) const;
292 
293 protected:
294 
298  void setup();
299 
300 public Q_SLOTS:
301 
303  void setShowCount(bool show);
304 
310  void setCountMap(const QMap<int, int>& idCountMap);
311 
317  void excludeChildrenCount(const QModelIndex& index);
318 
323  void includeChildrenCount(const QModelIndex& index);
324 
325 protected:
326 
328  void setCount(Album* album, int count);
329 
331  virtual Album* albumForId(int id) const = 0;
332 
334  virtual QString albumName(Album* a) const;
335 
337  QVariant albumData(Album* a, int role) const override;
338  void albumCleared(Album* album) override;
339  void allAlbumsCleared() override;
340 
341 protected Q_SLOTS:
342 
343  void slotAlbumMoved(Album* album);
344 
345 private:
346 
347  void updateCount(Album* album);
348 
349 private:
350 
351  class Private;
352  Private* const d;
353 };
354 
355 // ------------------------------------------------------------------
356 
358 {
359  Q_OBJECT
360 
361 public:
362 
368  explicit AbstractCheckableAlbumModel(Album::Type albumType,
369  Album* const rootAlbum,
370  RootAlbumBehavior rootBehavior = IncludeRootAlbum,
371  QObject* const parent = nullptr);
372  ~AbstractCheckableAlbumModel() override;
373 
375  void setCheckable(bool isCheckable);
376  bool isCheckable() const;
377 
382  void setRootCheckable(bool rootIsCheckable);
383  bool rootIsCheckable() const;
384 
391  void setTristate(bool isTristate);
392  bool isTristate() const;
393 
400  void setAddExcludeTristate(bool b);
401  bool isAddExcludeTristate() const;
402 
404  bool isChecked(Album* album) const;
405 
407  Qt::CheckState checkState(Album* album) const;
408 
410  QList<Album*> checkedAlbums() const;
411 
413  QList<Album*> partiallyCheckedAlbums() const;
414 
415 public Q_SLOTS:
416 
418  void setChecked(Album* album, bool isChecked);
419 
421  void setCheckState(Album* album, Qt::CheckState state);
422 
424  void toggleChecked(Album* album);
425 
427  void resetAllCheckedAlbums();
428 
430  void resetCheckedAlbums(const QModelIndex& parent = QModelIndex());
431 
433  void resetCheckedParentAlbums(const QModelIndex& child);
434 
436  void checkAllAlbums(const QModelIndex& parent = QModelIndex());
437 
439  void checkAllParentAlbums(const QModelIndex& child);
440 
442  void invertCheckedAlbums(const QModelIndex& parent = QModelIndex());
443 
445  void setCheckStateForChildren(Album* album, Qt::CheckState state);
446 
448  void setCheckStateForParents(Album* album, Qt::CheckState state);
449 
450 Q_SIGNALS:
451 
456  void checkStateChanged(Album* album, Qt::CheckState checkState);
457 
458 protected:
459 
463  void prepareAddExcludeDecoration(Album* a, QPixmap& icon) const;
464 
465  QVariant albumData(Album* a, int role) const override;
466  Qt::ItemFlags flags(const QModelIndex& index) const override;
467  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
468 
469  void albumCleared(Album* album) override;
470  void allAlbumsCleared() override;
471 
472 private:
473 
474  void setDataForParents(const QModelIndex& child, const QVariant& value, int role = Qt::EditRole);
475  void setDataForChildren(const QModelIndex& parent, const QVariant& value, int role = Qt::EditRole);
476 
477 private:
478 
479  class Private;
480  Private* const d;
481 };
482 
483 } // namespace Digikam
484 
485 #endif // DIGIKAM_ABSTRACT_ALBUM_MODEL_H
Definition: abstractalbummodel.h:49
virtual void albumCleared(Album *)
Notification when an entry is removed.
Definition: abstractalbummodel.h:213
RootAlbumBehavior
Definition: abstractalbummodel.h:60
@ IncludeRootAlbum
Definition: abstractalbummodel.h:65
AlbumDataRole
Definition: abstractalbummodel.h:74
virtual void allAlbumsCleared()
Notification when all entries are removed.
Definition: abstractalbummodel.h:216
Definition: abstractalbummodel.h:358
void checkStateChanged(Album *album, Qt::CheckState checkState)
Definition: abstractalbummodel.h:271
virtual Album * albumForId(int id) const =0
need to implement in subclass
Definition: abstractalbummodel.h:237
QString m_columnHeader
Definition: abstractalbummodel.h:265
Definition: albummodeldragdrophandler.h:39
Abstract base class for all album types.
Definition: album.h:67
Type
Definition: album.h:71
qulonglong value
Definition: itemviewutilities.cpp:592
@ Orientation
Definition: coredbfields.h:86
@ Album
Definition: coredbfields.h:58
Definition: datefolderview.cpp:43
DropAction
Definition: itemdragdrop.cpp:60