digiKam
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  * Copyright (C) 2008-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2009 by Johannes Wienke <languitar at semipol dot de>
11  * Copyright (C) 2014 by Mohamed_Anwer <m_dot_anwer at gmx 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_ALBUM_FILTER_MODEL_H
27 #define DIGIKAM_ALBUM_FILTER_MODEL_H
28 
29 // Qt includes
30 
31 #include <QPointer>
32 #include <QSortFilterProxyModel>
33 #include <QTreeView>
34 
35 // Local includes
36 
37 #include "albummodel.h"
38 #include "searchtextbar.h"
39 #include "digikam_export.h"
40 
41 namespace Digikam
42 {
43 
44 class DIGIKAM_GUI_EXPORT AlbumFilterModel : public QSortFilterProxyModel
45 {
46  Q_OBJECT
47 
48 public:
49 
51  {
53  NoMatch = 0,
61  SpecialMatch
62  };
63 
65  {
81  StrictFiltering
82  };
83 
84 public:
85 
86  explicit AlbumFilterModel(QObject* const parent = nullptr);
87 
93  void setSourceAlbumModel(AbstractAlbumModel* const source);
94  AbstractAlbumModel* sourceAlbumModel() const;
95 
101  void setSourceFilterModel(AlbumFilterModel* const source);
102  AlbumFilterModel* sourceFilterModel() const;
103 
104  QModelIndex mapToSourceAlbumModel(const QModelIndex& index) const;
105  QModelIndex mapFromSourceAlbumModel(const QModelIndex& index) const;
106 
108  Album* albumForIndex(const QModelIndex& index) const;
109  QModelIndex indexForAlbum(Album* album) const;
110  QModelIndex rootAlbumIndex() const;
111  QVariant dataForCurrentSortRole(Album* album) const;
112 
118  SearchTextSettings searchTextSettings() const;
119 
123  void setFilterBehavior(FilterBehavior behavior);
124 
130  MatchResult matchResult(const QModelIndex& index) const;
131 
138  virtual bool isFiltering() const;
139 
143  void updateFilter();
144 
148  template <typename T>
149  static inline int compareValue(const T& a, const T& b)
150  {
151  if (a == b)
152  {
153  return 0;
154  }
155 
156  if (a < b)
157  {
158  return -1;
159  }
160  else
161  {
162  return 1;
163  }
164  }
165 
170  static inline int compareByOrder(int compareResult, Qt::SortOrder sortOrder)
171  {
172  if (sortOrder == Qt::AscendingOrder)
173  {
174  return compareResult;
175  }
176  else
177  {
178  return (- compareResult);
179  }
180  }
181 
182  template <typename T>
183  static inline int compareByOrder(const T& a, const T& b, Qt::SortOrder sortOrder)
184  {
185  return compareByOrder(compareValue(a, b), sortOrder);
186  }
187 
188 public Q_SLOTS:
189 
196  void setSearchTextSettings(const SearchTextSettings& settings);
197 
198 Q_SIGNALS:
199 
209  void searchTextSettingsAboutToChange(bool searched, bool willSearch);
210 
218  void searchTextSettingsChanged(bool wasSearching, bool searched);
219 
224 
232  void hasSearchResult(bool hasResult);
233 
234 protected:
235 
242  MatchResult matchResult(Album* album) const;
243 
251  virtual bool matches(Album* album) const;
252 
259  void setSourceModel(QAbstractItemModel* const model) override;
260 
261  bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
262  bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
263 
264 protected Q_SLOTS:
265 
266  void slotAlbumRenamed(Album* album);
267  void slotAlbumsHaveBeenUpdated(int type);
268 
269 private:
270 
277  bool settingsFilter(const SearchTextSettings& settings) const;
278 
279 protected:
280 
283  QPointer<AlbumFilterModel> m_chainedModel;
284  QObject* m_parent;
285 };
286 
287 // -----------------------------------------------------------------------------------
288 
293 class DIGIKAM_GUI_EXPORT CheckableAlbumFilterModel : public AlbumFilterModel
294 {
295  Q_OBJECT
296 
297 public:
298 
299  explicit CheckableAlbumFilterModel(QObject* const parent = nullptr);
300 
301  void setSourceAlbumModel(AbstractCheckableAlbumModel* const source);
302  AbstractCheckableAlbumModel* sourceAlbumModel() const;
303 
304  void setSourceFilterModel(CheckableAlbumFilterModel* const source);
305 
306  void setFilterChecked(bool filter);
307  void setFilterPartiallyChecked(bool filter);
308 
309  bool isFiltering() const override;
310 
311 protected:
312 
313  bool matches(Album* album) const override;
314 
315 protected:
316 
319 };
320 
321 // -----------------------------------------------------------------------------------
322 
326 class DIGIKAM_GUI_EXPORT SearchFilterModel : public CheckableAlbumFilterModel
327 {
328  Q_OBJECT
329 
330 public:
331 
332  explicit SearchFilterModel(QObject* const parent = nullptr);
333 
334  void setSourceSearchModel(SearchModel* const source);
335  SearchModel* sourceSearchModel() const;
336 
340  void setFilterSearchType(DatabaseSearch::Type);
341  void listAllSearches();
342  void listNormalSearches();
343  void listTimelineSearches();
344  void listHaarSearches();
345  void listMapSearches();
346  void listDuplicatesSearches();
347 
351  void setListTemporarySearches(bool list);
352 
353  bool isFiltering() const override;
354 
355 protected:
356 
357  // make protected
358  void setSourceAlbumModel(AbstractAlbumModel* const source);
359 
360  void setTypeFilter(int type);
361 
362  bool matches(Album* album) const override;
363 
364 protected:
365 
368 };
369 
370 // -----------------------------------------------------------------------------------
371 
375 class DIGIKAM_GUI_EXPORT TagPropertiesFilterModel : public CheckableAlbumFilterModel
376 {
377  Q_OBJECT
378 
379 public:
380 
381  explicit TagPropertiesFilterModel(QObject* const parent = nullptr);
382 
383  void setSourceAlbumModel(TagModel* const source);
384  TagModel* sourceTagModel() const;
385 
386  void listOnlyTagsWithProperty(const QString& property);
387  void removeListOnlyProperty(const QString& property);
388  void doNotListTagsWithProperty(const QString& property);
389  void removeDoNotListProperty(const QString& property);
390 
391  bool isFiltering() const override;
392 
393 protected Q_SLOTS:
394 
395  void tagPropertiesChanged(TAlbum*);
396 
397 protected:
398 
399  bool matches(Album* album) const override;
400 
401 protected:
402 
403  QSet<QString> m_propertiesBlackList;
404  QSet<QString> m_propertiesWhiteList;
405 };
406 
407 // -----------------------------------------------------------------------------------
408 
409 class DIGIKAM_GUI_EXPORT TagsManagerFilterModel : public TagPropertiesFilterModel
410 {
411  Q_OBJECT
412 
413 public:
414 
415  explicit TagsManagerFilterModel(QObject* const data = nullptr);
416 
417  void setQuickListTags(const QList<int>& tags);
418 
419 protected:
420 
421  bool matches(Album* album) const override;
422 
423 protected:
424 
425  QSet<int> m_keywords;
426 };
427 
428 } // namespace Digikam
429 
430 #endif // DIGIKAM_ALBUM_FILTER_MODEL_H
Definition: abstractalbummodel.h:49
Definition: abstractalbummodel.h:358
Definition: albumfiltermodel.h:45
QPointer< AlbumFilterModel > m_chainedModel
Definition: albumfiltermodel.h:283
static int compareValue(const T &a, const T &b)
Definition: albumfiltermodel.h:149
FilterBehavior m_filterBehavior
Definition: albumfiltermodel.h:281
QObject * m_parent
Definition: albumfiltermodel.h:284
FilterBehavior
Definition: albumfiltermodel.h:65
@ SimpleFiltering
Definition: albumfiltermodel.h:70
@ FullFiltering
Definition: albumfiltermodel.h:76
MatchResult
Definition: albumfiltermodel.h:51
@ ParentMatch
A parent if the index is matched.
Definition: albumfiltermodel.h:57
@ ChildMatch
A child of the index is matched.
Definition: albumfiltermodel.h:59
@ DirectMatch
The index itself is matched.
Definition: albumfiltermodel.h:55
SearchTextSettings m_settings
Definition: albumfiltermodel.h:282
void searchTextSettingsChanged(bool wasSearching, bool searched)
static int compareByOrder(const T &a, const T &b, Qt::SortOrder sortOrder)
Definition: albumfiltermodel.h:183
static int compareByOrder(int compareResult, Qt::SortOrder sortOrder)
Definition: albumfiltermodel.h:170
void searchTextSettingsAboutToChange(bool searched, bool willSearch)
void hasSearchResult(bool hasResult)
Abstract base class for all album types.
Definition: album.h:67
Definition: albumfiltermodel.h:294
bool m_filterPartiallyChecked
Definition: albumfiltermodel.h:318
bool m_filterChecked
Definition: albumfiltermodel.h:317
Definition: albumfiltermodel.h:327
bool m_listTemporary
Definition: albumfiltermodel.h:367
int m_searchType
Definition: albumfiltermodel.h:366
Definition: albummodel.h:95
Definition: searchtextbar.h:43
Definition: album.h:420
Definition: albummodel.h:63
Definition: albumfiltermodel.h:376
QSet< QString > m_propertiesWhiteList
Definition: albumfiltermodel.h:404
QSet< QString > m_propertiesBlackList
Definition: albumfiltermodel.h:403
Definition: albumfiltermodel.h:410
QSet< int > m_keywords
Definition: albumfiltermodel.h:425
#define T
Type
Definition: coredbconstants.h:60
Definition: datefolderview.cpp:43