digiKam
showfotoitemmodel.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 : 2013-07-05
7  * Description : Qt model for Showfoto entries
8  *
9  * Copyright (C) 2013 by Mohamed_Anwer <m_dot_anwer at gmx 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 SHOW_FOTO_ITEM_MODEL_H
25 #define SHOW_FOTO_ITEM_MODEL_H
26 
27 // Qt includes
28 
29 #include <QAbstractListModel>
30 #include <QUrl>
31 
32 // Local includes
33 
36 #include "showfotoiteminfo.h"
37 
38 using namespace Digikam;
39 
40 namespace ShowFoto
41 {
42 
43 typedef QPair<int, int> IntPair;
44 
45 class ShowfotoItemModel : public QAbstractListModel,
47 {
48  Q_OBJECT
49 
50 public:
51 
53  {
57  ShowfotoItemModelPointerRole = Qt::UserRole,
58  ShowfotoItemModelInternalId = Qt::UserRole + 1,
59 
64  ThumbnailRole = Qt::UserRole + 2,
65 
69  ExtraDataRole = Qt::UserRole + 3,
70 
74  ExtraDataDuplicateCount = Qt::UserRole + 6,
75 
76  FilterModelRoles = Qt::UserRole + 100
77  };
78 
79 public:
80 
81  explicit ShowfotoItemModel(QObject* const parent);
82  ~ShowfotoItemModel() override;
83 
88  void setKeepsFileUrlCache(bool keepCache);
89 
95  ShowfotoItemInfo showfotoItemInfo(const QModelIndex& index) const;
96  ShowfotoItemInfo& showfotoItemInfoRef(const QModelIndex& index) const;
97  qlonglong showfotoItemId(const QModelIndex& index) const;
98  ShowfotoItemInfoList showfotoItemInfos(const QList<QModelIndex>& indexes) const;
100 
106  ShowfotoItemInfo showfotoItemInfo(int row) const;
107  ShowfotoItemInfo& showfotoItemInfoRef(int row) const;
108  qlonglong showfotoItemId(int row) const;
109 
113  QModelIndex indexForShowfotoItemInfo(const ShowfotoItemInfo& info) const;
114  QList<QModelIndex> indexesForShowfotoItemInfo(const ShowfotoItemInfo& info) const;
115  QModelIndex indexForShowfotoItemId(qlonglong id) const;
117 
123  QModelIndex indexForUrl(const QUrl& fileUrl) const;
124  QList<QModelIndex> indexesForUrl(const QUrl& fileUrl) const;
125  ShowfotoItemInfo showfotoItemInfo(const QUrl& fileUrl) const;
126  QList<ShowfotoItemInfo> showfotoItemInfos(const QUrl& fileUrl) const;
127 
128  void addShowfotoItemInfo(const ShowfotoItemInfo& info);
129  void addShowfotoItemInfos(const QList<ShowfotoItemInfo>& infos);
130 
134  void clearShowfotoItemInfos();
135 
142  void addShowfotoItemInfoSynchronously(const ShowfotoItemInfo& info);
143  void addShowfotoItemInfosSynchronously(const QList<ShowfotoItemInfo>& infos);
144 
148  void setShowfotoItemInfos(const QList<ShowfotoItemInfo>& infos);
149 
150  QList<ShowfotoItemInfo> showfotoItemInfos() const;
153 
154  bool hasImage(qlonglong id) const;
155  bool hasImage(const ShowfotoItemInfo& info) const;
156 
157  bool isEmpty() const;
158 
162  void removeIndex(const QModelIndex& index);
163  void removeIndexs(const QList<QModelIndex>& indexes);
164  void removeShowfotoItemInfo(const ShowfotoItemInfo& info);
165  void removeShowfotoItemInfos(const QList<ShowfotoItemInfo>& infos);
166 
168  int numberOfIndexesForShowfotoItemId(qlonglong id) const;
169 
174  static ShowfotoItemInfo retrieveShowfotoItemInfo(const QModelIndex& index);
175  static qlonglong retrieveShowfotoItemId(const QModelIndex& index);
176 
180  int rowCount(const QModelIndex& parent) const override;
181  QVariant data(const QModelIndex& index, int role) const override;
182  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
183  Qt::ItemFlags flags(const QModelIndex& index) const override;
184  QModelIndex index(int row, int column, const QModelIndex& parent) const override;
185 
190 
195  void setSendRemovalSignals(bool send);
196 
197 Q_SIGNALS:
198 
204 
210 
218 
226 
232 
238 
245 
246 public Q_SLOTS:
247 
248  void reAddShowfotoItemInfos(const ShowfotoItemInfoList& infos);
249  void reAddingFinished();
250  void slotFileDeleted(const QString& folder, const QString& file, bool status);
251  void slotFileUploaded(const ShowfotoItemInfo& info);
252 
253 protected:
254 
261 
269 
270  void emitDataChangedForAll();
271  void emitDataChangedForSelections(const QItemSelection& selection);
272 
276  virtual void showfotoItemInfosCleared() {};
277 
281  virtual void showfotoItemInfosAboutToBeRemoved(int /*begin*/, int /*end*/) {};
282 
283 private:
284 
285  void appendInfos(const QList<ShowfotoItemInfo>& infos);
286  void publiciseInfos(const QList<ShowfotoItemInfo>& infos);
287 /*
288  void cleanSituationChecks();
289 */
290  void removeRowPairs(const QList<QPair<int, int> >& toRemove);
291 /*
292  void removeRowPairsWithCheck(const QList<QPair<int, int> >& toRemove);
293 */
294  static QList<IntPair> toContiguousPairs(const QList<int>& unsorted);
295 
296 public:
297 
299  class Private;
300 
301 private:
302 
303  // Disable
304  ShowfotoItemModel(const ShowfotoItemModel&) = delete;
305  ShowfotoItemModel& operator=(const ShowfotoItemModel&) = delete;
306 
307 private:
308 
309  Private* const d;
310 };
311 
312 } // namespace ShowFoto
313 
314 Q_DECLARE_METATYPE(ShowFoto::ShowfotoItemModel*)
315 
316 #endif // SHOW_FOTO_IMAGE_MODEL_H
Definition: dragdropimplementations.h:40
Definition: showfotoiteminfo.h:48
Definition: showfotoitemmodel.h:47
int numberOfIndexesForShowfotoItemId(qlonglong id) const
qlonglong showfotoItemId(const QModelIndex &index) const
void preprocess(const QList< ShowfotoItemInfo > &infos)
virtual void showfotoItemInfosCleared()
Definition: showfotoitemmodel.h:276
void itemInfosAboutToBeRemoved(const QList< ShowfotoItemInfo > &infos)
ShowfotoItemModelRoles
Definition: showfotoitemmodel.h:53
void itemInfosRemoved(const QList< ShowfotoItemInfo > &infos)
QList< qlonglong > showfotoItemIds(const QList< QModelIndex > &indexes) const
bool hasImage(qlonglong id) const
void itemInfosAboutToBeAdded(const QList< ShowfotoItemInfo > &infos)
QList< qlonglong > showfotoItemIds() const
void itemInfosAdded(const QList< ShowfotoItemInfo > &infos)
qlonglong showfotoItemId(int row) const
void processAdded(const QList< ShowfotoItemInfo > &infos)
static qlonglong retrieveShowfotoItemId(const QModelIndex &index)
QList< ShowfotoItemInfo > uniqueShowfotoItemInfos() const
void setKeepsFileUrlCache(bool keepCache)
QList< QModelIndex > indexesForShowfotoItemId(qlonglong id) const
int numberOfIndexesForShowfotoItemInfo(const ShowfotoItemInfo &info) const
virtual void showfotoItemInfosAboutToBeRemoved(int, int)
Definition: showfotoitemmodel.h:281
#define DECLARE_MODEL_DRAG_DROP_METHODS
Definition: dragdropimplementations.h:90
@ Orientation
Definition: coredbfields.h:86
Definition: datefolderview.cpp:43
QPair< int, int > IntPair
Definition: itemmodel.cpp:123
Definition: showfotofolderviewbar.cpp:52