digiKam
importfiltermodel.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-21-06
7  * Description : Qt filter model for import items
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_FILTER_MODEL_H
25 #define DIGIKAM_IMPORT_FILTER_MODEL_H
26 
27 // Qt includes
28 
29 #include <QObject>
30 
31 // Local includes
32 
34 #include "camitemsortsettings.h"
35 #include "importimagemodel.h"
36 
37 namespace Digikam
38 {
39 class Filter;
40 class ImportFilterModel;
41 
43 {
44  Q_OBJECT
45 
46 public:
47 
48  explicit ImportSortFilterModel(QObject* const parent = nullptr);
49  ~ImportSortFilterModel() override;
50 
51  void setSourceImportModel(ImportItemModel* const sourceModel);
53 
54  void setSourceFilterModel(ImportSortFilterModel* const sourceModel);
56 
61  QModelIndex mapToSourceImportModel(const QModelIndex& proxyIndex) const;
62  QModelIndex mapFromSourceImportModel(const QModelIndex& importModelIndex) const;
63  QModelIndex mapFromDirectSourceToSourceImportModel(const QModelIndex& sourceModelIndex) const;
64 
66  QList<QModelIndex> mapListFromSource(const QList<QModelIndex>& sourceIndexes) const;
67 
68  CamItemInfo camItemInfo(const QModelIndex& index) const;
69  qlonglong camItemId(const QModelIndex& index) const;
71  QList<qlonglong> camItemIds(const QList<QModelIndex>& indexes) const;
72 
73  QModelIndex indexForPath(const QString& filePath) const;
74  QModelIndex indexForCamItemInfo(const CamItemInfo& info) const;
75  QModelIndex indexForCamItemId(qlonglong id) const;
76 
82 
84  virtual ImportFilterModel* importFilterModel() const;
85 
86 protected:
87 
88  void setSourceModel(QAbstractItemModel* sourceModel) override;
89 
91  virtual void setDirectSourceImportModel(ImportItemModel* const sourceModel);
92 
93 protected:
94 
96 };
97 
98 // ------------------------------------------------------------------------------------------
99 
101 {
102  Q_OBJECT
103 
104 public:
105 
107  {
110 
113 
116 
119 
121  // TODO: GroupIsOpenRole = ImportItemModel::FilterModelRoles + 5
123  };
124 
125 public:
126 
127  explicit ImportFilterModel(QObject* const parent = nullptr);
128  ~ImportFilterModel() override;
129 
131 
132  void setCamItemSortSettings(const CamItemSortSettings& sorter);
133 
135  void setSendCamItemInfoSignals(bool sendSignals);
136 
137  // TODO: Implement grouping in import tool.
138 /*
139  bool isGroupOpen(qlonglong group) const;
140  bool isAllGroupsOpen() const;
141 */
142  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
143  ImportFilterModel* importFilterModel() const override;
144 
145 public Q_SLOTS:
146 
150  void setStringTypeNatural(bool natural);
151  void setFilter(Filter*);
152  void setCameraThumbsController(CameraThumbsCtrl* const thumbsCtrl);
153 
154  // TODO: Implement grouping in import tool.
155 /*
156  void setGroupOpen(qlonglong group, bool open);
157  void toggleGroupOpen(qlonglong group);
158  void setAllGroupsOpen(bool open);
159 */
164  // TODO: Implement filtering in import tool.
165 /*
166  virtual void setItemFilterSettings(const ItemFilterSettings& settings);
167 */
172  // TODO: Implement filtering in import tool.
173 /*
174  virtual void setItemSortSettings(const ItemSortSettings& settings);
175 */
176 
177 Q_SIGNALS:
178 
183 
184 protected Q_SLOTS:
185 
186  void slotRowsInserted(const QModelIndex& parent, int start, int end);
187  void slotRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
189 
190 public:
191 
192  // Declared as public because of use in sub-classes.
193  class ImportFilterModelPrivate;
194 
195 protected:
196 
197  ImportFilterModelPrivate* const d_ptr;
198 
199 protected:
200 
201  void setDirectSourceImportModel(ImportItemModel* const sourceModel) override;
202 
203  bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
204 
205  int compareCategories(const QModelIndex& left, const QModelIndex& right) const override;
206  bool subSortLessThan(const QModelIndex& left, const QModelIndex& right) const override;
207 
213  virtual int compareInfosCategories(const CamItemInfo& left, const CamItemInfo& right) const;
214 
218  virtual bool infosLessThan(const CamItemInfo& left, const CamItemInfo& right) const;
219 
223  virtual QString categoryIdentifier(const CamItemInfo& info) const;
224 
225 private:
226 
227  Q_DECLARE_PRIVATE(ImportFilterModel)
228 };
229 
230 // -----------------------------------------------------------------------------------------------------
231 
233 {
234  Q_OBJECT
235 
236 public:
237 
238  explicit NoDuplicatesImportFilterModel(QObject* const parent = nullptr);
239 
240 protected:
241 
242  bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
243 };
244 
245 } // namespace Digikam
246 
247 Q_DECLARE_METATYPE(Digikam::ImportFilterModel*)
248 
249 #endif // DIGIKAM_IMPORT_FILTER_MODEL_H
Definition: camiteminfo.h:48
Definition: camitemsortsettings.h:42
CategorizationMode
Definition: camitemsortsettings.h:53
SortOrder
Definition: camitemsortsettings.h:46
SortRole
Definition: camitemsortsettings.h:61
Definition: camerathumbsctrl.h:48
Definition: dcategorizedsortfilterproxymodel.h:53
Definition: filter.h:44
Definition: importfiltermodel.h:101
void setCamItemSortSettings(const CamItemSortSettings &sorter)
Definition: importfiltermodel.cpp:334
void setFilter(Filter *)
Definition: importfiltermodel.cpp:370
void camItemInfosAdded(const QList< CamItemInfo > &infos)
ImportFilterModel(QObject *const parent=nullptr)
Definition: importfiltermodel.cpp:281
void setCameraThumbsController(CameraThumbsCtrl *const thumbsCtrl)
Definition: importfiltermodel.cpp:377
void slotRowsInserted(const QModelIndex &parent, int start, int end)
Definition: importfiltermodel.cpp:403
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: importfiltermodel.cpp:294
void setSortRole(CamItemSortSettings::SortRole role)
Definition: importfiltermodel.cpp:349
virtual QString categoryIdentifier(const CamItemInfo &info) const
Definition: importfiltermodel.cpp:527
ImportFilterModel * importFilterModel() const override
Returns this, any chained ImportFilterModel, or 0.
Definition: importfiltermodel.cpp:327
void setCategorizationMode(CamItemSortSettings::CategorizationMode mode)
Definition: importfiltermodel.cpp:342
virtual int compareInfosCategories(const CamItemInfo &left, const CamItemInfo &right) const
Definition: importfiltermodel.cpp:513
void slotProcessAdded(const QList< CamItemInfo > &)
Definition: importfiltermodel.cpp:466
ImportFilterModelPrivate *const d_ptr
Definition: importfiltermodel.h:193
bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const override
Definition: importfiltermodel.cpp:488
CamItemSortSettings camItemSortSettings() const
void slotRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
Definition: importfiltermodel.cpp:415
void camItemInfosAboutToBeRemoved(const QList< CamItemInfo > &infos)
ImportFilterModelRoles
Definition: importfiltermodel.h:107
@ CategoryFormatRole
Returns the format of the index which is used for category.
Definition: importfiltermodel.h:115
@ ImportFilterModelPointerRole
Returns true if the given camera item is a group leader, and the group is opened.
Definition: importfiltermodel.h:122
@ SortOrderRole
Returns the current sort order.
Definition: importfiltermodel.h:112
@ CategorizationModeRole
Returns the current categorization mode.
Definition: importfiltermodel.h:109
@ CategoryDateRole
Returns the date of the index which is used for category.
Definition: importfiltermodel.h:118
void setSendCamItemInfoSignals(bool sendSignals)
Enables sending camItemInfosAdded and camItemInfosAboutToBeRemoved.
Definition: importfiltermodel.cpp:383
int compareCategories(const QModelIndex &left, const QModelIndex &right) const override
Definition: importfiltermodel.cpp:471
~ImportFilterModel() override
Definition: importfiltermodel.cpp:288
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
Definition: importfiltermodel.cpp:550
void setSortOrder(CamItemSortSettings::SortOrder order)
Definition: importfiltermodel.cpp:356
void setStringTypeNatural(bool natural)
Definition: importfiltermodel.cpp:363
virtual bool infosLessThan(const CamItemInfo &left, const CamItemInfo &right) const
Definition: importfiltermodel.cpp:520
void setDirectSourceImportModel(ImportItemModel *const sourceModel) override
Reimplement if needed. Called only when model shall be set as (direct) sourceModel.
Definition: importfiltermodel.cpp:427
Definition: importimagemodel.h:43
@ FilterModelRoles
Definition: importimagemodel.h:71
Definition: importfiltermodel.h:43
void setSourceImportModel(ImportItemModel *const sourceModel)
Definition: importfiltermodel.cpp:45
QList< QModelIndex > mapListToSource(const QList< QModelIndex > &indexes) const
Definition: importfiltermodel.cpp:133
QModelIndex indexForPath(const QString &filePath) const
Definition: importfiltermodel.cpp:191
qlonglong camItemId(const QModelIndex &index) const
Definition: importfiltermodel.cpp:162
CamItemInfo camItemInfo(const QModelIndex &index) const
Definition: importfiltermodel.cpp:157
QModelIndex indexForCamItemId(qlonglong id) const
Definition: importfiltermodel.cpp:203
ImportItemModel * sourceImportModel() const
Definition: importfiltermodel.cpp:57
QModelIndex mapToSourceImportModel(const QModelIndex &proxyIndex) const
Definition: importfiltermodel.cpp:88
QList< CamItemInfo > camItemInfos(const QList< QModelIndex > &indexes) const
Definition: importfiltermodel.cpp:167
ImportSortFilterModel(QObject *const parent=nullptr)
Definition: importfiltermodel.cpp:35
void setSourceModel(QAbstractItemModel *sourceModel) override
Definition: importfiltermodel.cpp:231
~ImportSortFilterModel() override
Definition: importfiltermodel.cpp:41
QList< QModelIndex > mapListFromSource(const QList< QModelIndex > &sourceIndexes) const
Definition: importfiltermodel.cpp:145
QList< CamItemInfo > camItemInfosSorted() const
Definition: importfiltermodel.cpp:208
QModelIndex mapFromSourceImportModel(const QModelIndex &importModelIndex) const
Definition: importfiltermodel.cpp:103
ImportSortFilterModel * m_chainedModel
Definition: importfiltermodel.h:95
ImportSortFilterModel * sourceFilterModel() const
Definition: importfiltermodel.cpp:83
QModelIndex indexForCamItemInfo(const CamItemInfo &info) const
Definition: importfiltermodel.cpp:198
virtual void setDirectSourceImportModel(ImportItemModel *const sourceModel)
Reimplement if needed. Called only when model shall be set as (direct) sourceModel.
Definition: importfiltermodel.cpp:236
QModelIndex mapFromDirectSourceToSourceImportModel(const QModelIndex &sourceModelIndex) const
Definition: importfiltermodel.cpp:118
QList< qlonglong > camItemIds(const QList< QModelIndex > &indexes) const
Definition: importfiltermodel.cpp:179
virtual ImportFilterModel * importFilterModel() const
Returns this, any chained ImportFilterModel, or 0.
Definition: importfiltermodel.cpp:221
void setSourceFilterModel(ImportSortFilterModel *const sourceModel)
Definition: importfiltermodel.cpp:67
Definition: importfiltermodel.h:233
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
Definition: importfiltermodel.cpp:577
NoDuplicatesImportFilterModel(QObject *const parent=nullptr)
Definition: importfiltermodel.cpp:572
Definition: datefolderview.cpp:43