digiKam
Loading...
Searching...
No Matches
albumfiltermodel.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-24
7 * Description : Qt Model for Albums - filter model
8 *
9 * SPDX-FileCopyrightText: 2008-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10 * SPDX-FileCopyrightText: 2009 by Johannes Wienke <languitar at semipol dot de>
11 * SPDX-FileCopyrightText: 2014 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
12 *
13 * SPDX-License-Identifier: GPL-2.0-or-later
14 *
15 * ============================================================ */
16
17#pragma once
18
19// Qt includes
20
21#include <QPointer>
22#include <QSortFilterProxyModel>
23#include <QTreeView>
24
25// Local includes
26
27#include "albummodel.h"
28#include "searchtextbar.h"
29#include "digikam_export.h"
30
31namespace Digikam
32{
33
34class DIGIKAM_GUI_EXPORT AlbumFilterModel : public QSortFilterProxyModel
35{
36 Q_OBJECT
37
38public:
39
41 {
43 NoMatch = 0,
51 SpecialMatch
52 };
53
55 {
71 StrictFiltering
72 };
73
74public:
75
76 explicit AlbumFilterModel(QObject* const parent = nullptr);
77
83 void setSourceAlbumModel(AbstractAlbumModel* const source);
84 AbstractAlbumModel* sourceAlbumModel() const;
85
91 void setSourceFilterModel(AlbumFilterModel* const source);
92 AlbumFilterModel* sourceFilterModel() const;
93
94 QModelIndex mapToSourceAlbumModel(const QModelIndex& index) const;
95 QModelIndex mapFromSourceAlbumModel(const QModelIndex& index) const;
96
98 Album* albumForIndex(const QModelIndex& index) const;
99 QModelIndex indexForAlbum(Album* album) const;
100 QModelIndex rootAlbumIndex() const;
101 QVariant dataForCurrentSortRole(Album* album) const;
102
108 SearchTextSettings searchTextSettings() const;
109
113 void setFilterBehavior(FilterBehavior behavior);
114
120 MatchResult matchResult(const QModelIndex& index) const;
121
128 virtual bool isFiltering() const;
129
133 void updateFilter();
134
138 template <typename T>
139 static inline int compareValue(const T& a, const T& b)
140 {
141 if (a == b)
142 {
143 return 0;
144 }
145
146 if (a < b)
147 {
148 return -1;
149 }
150 else
151 {
152 return 1;
153 }
154 }
155
160 static inline int compareByOrder(int compareResult, Qt::SortOrder sortOrder)
161 {
162 if (sortOrder == Qt::AscendingOrder)
163 {
164 return compareResult;
165 }
166 else
167 {
168 return (- compareResult);
169 }
170 }
171
172 template <typename T>
173 static inline int compareByOrder(const T& a, const T& b, Qt::SortOrder sortOrder)
174 {
175 return compareByOrder(compareValue(a, b), sortOrder);
176 }
177
178public Q_SLOTS:
179
186 void setSearchTextSettings(const SearchTextSettings& settings);
187
188Q_SIGNALS:
189
199 void searchTextSettingsAboutToChange(bool searched, bool willSearch);
200
208 void searchTextSettingsChanged(bool wasSearching, bool searched);
209
214
222 void hasSearchResult(bool hasResult);
223
224protected:
225
232 MatchResult matchResult(Album* album) const;
233
241 virtual bool matches(Album* album) const;
242
249 void setSourceModel(QAbstractItemModel* const model) override;
250
251 bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
252 bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
253
254protected Q_SLOTS:
255
256 void slotAlbumRenamed(Album* album);
257 void slotAlbumsHaveBeenUpdated(int type);
258
259private:
260
267 bool settingsFilter(const SearchTextSettings& settings) const;
268
269protected:
270
271 FilterBehavior m_filterBehavior = FullFiltering;
273 QPointer<AlbumFilterModel> m_chainedModel = nullptr;
274 QObject* m_parent = nullptr;
275};
276
277// -----------------------------------------------------------------------------------
278
283class DIGIKAM_GUI_EXPORT CheckableAlbumFilterModel : public AlbumFilterModel
284{
285 Q_OBJECT
286
287public:
288
289 explicit CheckableAlbumFilterModel(QObject* const parent = nullptr);
290
291 void setSourceAlbumModel(AbstractCheckableAlbumModel* const source);
292 AbstractCheckableAlbumModel* sourceAlbumModel() const;
293
294 void setSourceFilterModel(CheckableAlbumFilterModel* const source);
295
296 void setFilterChecked(bool filter);
297 void setFilterPartiallyChecked(bool filter);
298
299 bool isFiltering() const override;
300
301protected:
302
303 bool matches(Album* album) const override;
304
305protected:
306
307 bool m_filterChecked = false;
308 bool m_filterPartiallyChecked = false;
309};
310
311// -----------------------------------------------------------------------------------
312
316class DIGIKAM_GUI_EXPORT SearchFilterModel : public CheckableAlbumFilterModel
317{
318 Q_OBJECT
319
320public:
321
322 explicit SearchFilterModel(QObject* const parent = nullptr);
323
324 void setSourceSearchModel(SearchModel* const source);
325 SearchModel* sourceSearchModel() const;
326
330 void setFilterSearchType(DatabaseSearch::Type);
331 void listAllSearches();
332 void listNormalSearches();
333 void listTimelineSearches();
334 void listHaarSearches();
335 void listMapSearches();
336 void listDuplicatesSearches();
337
341 void setListTemporarySearches(bool list);
342
343 bool isFiltering() const override;
344
345protected:
346
347 // make protected
348 void setSourceAlbumModel(AbstractAlbumModel* const source);
349
350 void setTypeFilter(int type);
351
352 bool matches(Album* album) const override;
353
354protected:
355
356 int m_searchType = -1;
357 bool m_listTemporary = false;
358};
359
360// -----------------------------------------------------------------------------------
361
366{
367 Q_OBJECT
368
369public:
370
371 explicit TagPropertiesFilterModel(QObject* const parent = nullptr);
372
373 void setSourceAlbumModel(TagModel* const source);
374 TagModel* sourceTagModel() const;
375
376 void listOnlyTagsWithProperty(const QString& property);
377 void removeListOnlyProperty(const QString& property);
378 void doNotListTagsWithProperty(const QString& property);
379 void removeDoNotListProperty(const QString& property);
380
381 bool isFiltering() const override;
382
383protected Q_SLOTS:
384
385 void tagPropertiesChanged(TAlbum*);
386
387protected:
388
389 bool matches(Album* album) const override;
390
391protected:
392
395};
396
397// -----------------------------------------------------------------------------------
398
399class DIGIKAM_GUI_EXPORT TagsManagerFilterModel : public TagPropertiesFilterModel
400{
401 Q_OBJECT
402
403public:
404
405 explicit TagsManagerFilterModel(QObject* const data = nullptr);
406
407 void setQuickListTags(const QList<int>& tags);
408
409protected:
410
411 bool matches(Album* album) const override;
412
413protected:
414
415 QSet<int> m_keywords;
416};
417
418} // namespace Digikam
Definition abstractalbummodel.h:39
Definition abstractalbummodel.h:357
Definition albumfiltermodel.h:35
static int compareValue(const T &a, const T &b)
Definition albumfiltermodel.h:139
FilterBehavior
Definition albumfiltermodel.h:55
@ SimpleFiltering
Definition albumfiltermodel.h:60
@ FullFiltering
Definition albumfiltermodel.h:66
MatchResult
Definition albumfiltermodel.h:41
@ ParentMatch
A parent if the index is matched.
Definition albumfiltermodel.h:47
@ ChildMatch
A child of the index is matched.
Definition albumfiltermodel.h:49
@ DirectMatch
The index itself is matched.
Definition albumfiltermodel.h:45
SearchTextSettings m_settings
Definition albumfiltermodel.h:272
void searchTextSettingsChanged(bool wasSearching, bool searched)
static int compareByOrder(const T &a, const T &b, Qt::SortOrder sortOrder)
Definition albumfiltermodel.h:173
static int compareByOrder(int compareResult, Qt::SortOrder sortOrder)
Definition albumfiltermodel.h:160
void searchTextSettingsAboutToChange(bool searched, bool willSearch)
void hasSearchResult(bool hasResult)
Abstract base class for all album types.
Definition album.h:57
Definition albumfiltermodel.h:284
Definition albumfiltermodel.h:317
Definition albummodel.h:89
Definition searchtextbar.h:33
Definition album.h:421
Definition albummodel.h:57
Definition albumfiltermodel.h:366
QSet< QString > m_propertiesWhiteList
Definition albumfiltermodel.h:394
QSet< QString > m_propertiesBlackList
Definition albumfiltermodel.h:393
Definition albumfiltermodel.h:400
QSet< int > m_keywords
Definition albumfiltermodel.h:415
#define T
Type
Definition coredbconstants.h:34
Definition datefolderview.cpp:34