digiKam
Loading...
Searching...
No Matches
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 * SPDX-FileCopyrightText: 2013 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
13 * ============================================================ */
14
15#pragma once
16
17// Qt includes
18
19#include <QAbstractListModel>
20#include <QUrl>
21
22// Local includes
23
26#include "showfotoiteminfo.h"
27
28using namespace Digikam;
29
30namespace ShowFoto
31{
32
33typedef QPair<int, int> IntPair;
34
35class ShowfotoItemModel : public QAbstractListModel,
37{
38 Q_OBJECT
39
40public:
41
43 {
48 ShowfotoItemModelInternalId = Qt::UserRole + 1,
49
54 ThumbnailRole = Qt::UserRole + 2,
55
59 ExtraDataRole = Qt::UserRole + 3,
60
64 ExtraDataDuplicateCount = Qt::UserRole + 6,
65
66 FilterModelRoles = Qt::UserRole + 100
67 };
68
69public:
70
71 explicit ShowfotoItemModel(QObject* const parent);
72 ~ShowfotoItemModel() override;
73
78 void setKeepsFileUrlCache(bool keepCache);
79
85 ShowfotoItemInfo showfotoItemInfo(const QModelIndex& index) const;
86 ShowfotoItemInfo& showfotoItemInfoRef(const QModelIndex& index) const;
87 qlonglong showfotoItemId(const QModelIndex& index) const;
88 ShowfotoItemInfoList showfotoItemInfos(const QList<QModelIndex>& indexes) const;
89 QList<qlonglong> showfotoItemIds(const QList<QModelIndex>& indexes) const;
90
98 qlonglong showfotoItemId(int row) const;
99
103 QModelIndex indexForShowfotoItemInfo(const ShowfotoItemInfo& info) const;
104 QList<QModelIndex> indexesForShowfotoItemInfo(const ShowfotoItemInfo& info) const;
105 QModelIndex indexForShowfotoItemId(qlonglong id) const;
106 QList<QModelIndex> indexesForShowfotoItemId(qlonglong id) const;
107
113 QModelIndex indexForUrl(const QUrl& fileUrl) const;
114 QList<QModelIndex> indexesForUrl(const QUrl& fileUrl) const;
115 ShowfotoItemInfo showfotoItemInfo(const QUrl& fileUrl) const;
116 QList<ShowfotoItemInfo> showfotoItemInfos(const QUrl& fileUrl) const;
117
118 void addShowfotoItemInfo(const ShowfotoItemInfo& info);
119 void addShowfotoItemInfos(const QList<ShowfotoItemInfo>& infos);
120
125
133 void addShowfotoItemInfosSynchronously(const QList<ShowfotoItemInfo>& infos);
134
138 void setShowfotoItemInfos(const QList<ShowfotoItemInfo>& infos);
139
140 QList<ShowfotoItemInfo> showfotoItemInfos() const;
141 QList<qlonglong> showfotoItemIds() const;
142 QList<ShowfotoItemInfo> uniqueShowfotoItemInfos() const;
143
144 bool hasImage(qlonglong id) const;
145 bool hasImage(const ShowfotoItemInfo& info) const;
146
147 bool isEmpty() const;
148
152 void removeIndex(const QModelIndex& index);
153 void removeIndexs(const QList<QModelIndex>& indexes);
155 void removeShowfotoItemInfos(const QList<ShowfotoItemInfo>& infos);
156
158 int numberOfIndexesForShowfotoItemId(qlonglong id) const;
159
164 static ShowfotoItemInfo retrieveShowfotoItemInfo(const QModelIndex& index);
165 static qlonglong retrieveShowfotoItemId(const QModelIndex& index);
166
170 int rowCount(const QModelIndex& parent) const override;
171 QVariant data(const QModelIndex& index, int role) const override;
172 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
173 Qt::ItemFlags flags(const QModelIndex& index) const override;
174 QModelIndex index(int row, int column, const QModelIndex& parent) const override;
175
180
185 void setSendRemovalSignals(bool send);
186
187Q_SIGNALS:
188
193 void itemInfosAboutToBeAdded(const QList<ShowfotoItemInfo>& infos);
194
199 void itemInfosAdded(const QList<ShowfotoItemInfo>& infos);
200
207 void itemInfosAboutToBeRemoved(const QList<ShowfotoItemInfo>& infos);
208
215 void itemInfosRemoved(const QList<ShowfotoItemInfo>& infos);
216
220 void preprocess(const QList<ShowfotoItemInfo>& infos);
221 void processAdded(const QList<ShowfotoItemInfo>& infos);
222
228
235
236public Q_SLOTS:
237
239 void reAddingFinished();
240 void slotFileDeleted(const QString& folder, const QString& file, bool status);
241 void slotFileUploaded(const ShowfotoItemInfo& info);
242
243protected:
244
251
259
261 void emitDataChangedForSelections(const QItemSelection& selection);
262
266 virtual void showfotoItemInfosCleared() {};
267
271 virtual void showfotoItemInfosAboutToBeRemoved(int /*begin*/, int /*end*/) {};
272
273private:
274
275 void appendInfos(const QList<ShowfotoItemInfo>& infos);
276 void publiciseInfos(const QList<ShowfotoItemInfo>& infos);
277/*
278 void cleanSituationChecks();
279*/
280 void removeRowPairs(const QList<QPair<int, int> >& toRemove);
281/*
282 void removeRowPairsWithCheck(const QList<QPair<int, int> >& toRemove);
283*/
284 static QList<IntPair> toContiguousPairs(const QList<int>& unsorted);
285
286public:
287
289 class Private;
290
291private:
292
293 // Disable
294 ShowfotoItemModel(const ShowfotoItemModel&) = delete;
295 ShowfotoItemModel& operator=(const ShowfotoItemModel&) = delete;
296
297private:
298
299 Private* const d = nullptr;
300};
301
302} // namespace ShowFoto
303
304Q_DECLARE_METATYPE(ShowFoto::ShowfotoItemModel*)
Definition dragdropimplementations.h:30
Definition showfotoiteminfo.h:38
Definition showfotoitemmodel.h:37
QVariant data(const QModelIndex &index, int role) const override
Definition showfotoitemmodel.cpp:642
QModelIndex indexForShowfotoItemId(qlonglong id) const
Definition showfotoitemmodel.cpp:129
void removeIndex(const QModelIndex &index)
Definition showfotoitemmodel.cpp:432
bool isEmpty() const
Definition showfotoitemmodel.cpp:72
int numberOfIndexesForShowfotoItemId(qlonglong id) const
QList< ShowfotoItemInfo > uniqueShowfotoItemInfos() const
QList< QModelIndex > indexesForUrl(const QUrl &fileUrl) const
Definition showfotoitemmodel.cpp:175
void removeIndexs(const QList< QModelIndex > &indexes)
Definition showfotoitemmodel.cpp:437
QList< qlonglong > showfotoItemIds() const
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Definition showfotoitemmodel.cpp:633
void clearShowfotoItemInfos()
Definition showfotoitemmodel.cpp:251
void addShowfotoItemInfo(const ShowfotoItemInfo &info)
Definition showfotoitemmodel.cpp:219
QList< qlonglong > showfotoItemIds(const QList< QModelIndex > &indexes) const
qlonglong showfotoItemId(const QModelIndex &index) const
static ShowfotoItemInfo retrieveShowfotoItemInfo(const QModelIndex &index)
Definition showfotoitemmodel.cpp:142
void removeShowfotoItemInfos(const QList< ShowfotoItemInfo > &infos)
Definition showfotoitemmodel.cpp:424
void removeShowfotoItemInfo(const ShowfotoItemInfo &info)
Definition showfotoitemmodel.cpp:419
void preprocess(const QList< ShowfotoItemInfo > &infos)
void emitDataChangedForSelections(const QItemSelection &selection)
Definition showfotoitemmodel.cpp:306
void addShowfotoItemInfos(const QList< ShowfotoItemInfo > &infos)
Definition showfotoitemmodel.cpp:224
virtual void showfotoItemInfosCleared()
Definition showfotoitemmodel.h:266
QModelIndex indexForShowfotoItemInfo(const ShowfotoItemInfo &info) const
Definition showfotoitemmodel.cpp:119
DECLARE_MODEL_DRAG_DROP_METHODS void setSendRemovalSignals(bool send)
Definition showfotoitemmodel.cpp:457
void itemInfosAboutToBeRemoved(const QList< ShowfotoItemInfo > &infos)
QList< QModelIndex > indexesForShowfotoItemInfo(const ShowfotoItemInfo &info) const
Definition showfotoitemmodel.cpp:124
QModelIndex index(int row, int column, const QModelIndex &parent) const override
Definition showfotoitemmodel.cpp:623
void emitDataChangedForAll()
Definition showfotoitemmodel.cpp:293
ShowfotoItemModelRoles
Definition showfotoitemmodel.h:43
@ ExtraDataDuplicateCount
Definition showfotoitemmodel.h:64
@ ThumbnailRole
Definition showfotoitemmodel.h:54
@ FilterModelRoles
Definition showfotoitemmodel.h:66
@ ExtraDataRole
Definition showfotoitemmodel.h:59
@ ShowfotoItemModelInternalId
Definition showfotoitemmodel.h:48
@ ShowfotoItemModelPointerRole
Definition showfotoitemmodel.h:47
void reAddShowfotoItemInfos(const ShowfotoItemInfoList &infos)
Definition showfotoitemmodel.cpp:327
void addShowfotoItemInfosSynchronously(const QList< ShowfotoItemInfo > &infos)
Definition showfotoitemmodel.cpp:239
void itemInfosRemoved(const QList< ShowfotoItemInfo > &infos)
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition showfotoitemmodel.cpp:610
~ShowfotoItemModel() override
Definition showfotoitemmodel.cpp:67
ShowfotoItemInfo showfotoItemInfo(const QModelIndex &index) const
Definition showfotoitemmodel.cpp:77
bool hasImage(qlonglong id) const
void addShowfotoItemInfoSynchronously(const ShowfotoItemInfo &info)
Definition showfotoitemmodel.cpp:234
void itemInfosAboutToBeAdded(const QList< ShowfotoItemInfo > &infos)
void itemInfosAdded(const QList< ShowfotoItemInfo > &infos)
qlonglong showfotoItemId(int row) const
ShowfotoItemInfo & showfotoItemInfoRef(const QModelIndex &index) const
Definition showfotoitemmodel.cpp:87
void slotFileUploaded(const ShowfotoItemInfo &info)
Definition showfotoitemmodel.cpp:350
void processAdded(const QList< ShowfotoItemInfo > &infos)
static qlonglong retrieveShowfotoItemId(const QModelIndex &index)
void slotFileDeleted(const QString &folder, const QString &file, bool status)
Definition showfotoitemmodel.cpp:340
void setKeepsFileUrlCache(bool keepCache)
void reAddingFinished()
Definition showfotoitemmodel.cpp:332
void setShowfotoItemInfos(const QList< ShowfotoItemInfo > &infos)
Definition showfotoitemmodel.cpp:277
int numberOfIndexesForShowfotoItemInfo(const ShowfotoItemInfo &info) const
QList< ShowfotoItemInfo > showfotoItemInfos() const
Definition showfotoitemmodel.cpp:283
int rowCount(const QModelIndex &parent) const override
Definition showfotoitemmodel.cpp:600
QList< QModelIndex > indexesForShowfotoItemId(qlonglong id) const
virtual void showfotoItemInfosAboutToBeRemoved(int, int)
Definition showfotoitemmodel.h:271
QModelIndex indexForUrl(const QUrl &fileUrl) const
Definition showfotoitemmodel.cpp:160
#define DECLARE_MODEL_DRAG_DROP_METHODS
Definition dragdropimplementations.h:80
Definition datefolderview.cpp:34
Definition showfotofolderviewbar.cpp:43
QList< ShowfotoItemInfo > ShowfotoItemInfoList
Definition showfotoiteminfo.h:81
QPair< int, int > IntPair
Definition showfotoitemmodel.h:33