digiKam
itemsortsettings.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-05-31
7  * Description : Sort settings for use with ItemFilterModel
8  *
9  * Copyright (C) 2009 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
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_ITEM_SORT_SETTINGS_H
25 #define DIGIKAM_ITEM_SORT_SETTINGS_H
26 
27 // Qt includes
28 
29 #include <QString>
30 #include <QVariant>
31 
32 // Local includes
33 
34 #include "digikam_export.h"
35 #include "itemsortcollator.h"
36 
37 namespace Digikam
38 {
39 
40 class ItemInfo;
41 class FaceTagsIface;
42 
43 namespace DatabaseFields
44 {
45  class Set;
46 }
47 
48 class DIGIKAM_DATABASE_EXPORT ItemSortSettings
49 {
50 public:
51 
52  enum SortOrder
53  {
54  AscendingOrder = Qt::AscendingOrder,
55  DescendingOrder = Qt::DescendingOrder,
56  DefaultOrder
57  };
58 
60  {
66  CategoryByFaces
67  };
68 
69  enum SortRole
70  {
71  // Note: For legacy reasons, the order of the first five entries must remain unchanged
83  SortByManualOrderAndDate
84  };
85 
86 public:
87 
88  explicit ItemSortSettings();
89 
90  bool operator==(const ItemSortSettings& other) const;
91 
100  int compareCategories(const ItemInfo& left, const ItemInfo& right,
101  const FaceTagsIface& leftFace, const FaceTagsIface& rightFace) const;
102 
107  bool lessThan(const ItemInfo& left, const ItemInfo& right) const;
108 
115  int compare(const ItemInfo& left, const ItemInfo& right) const;
116 
122  bool lessThan(const QVariant& left, const QVariant& right) const;
123 
124  void setSortRole(SortRole role);
125  void setSortOrder(SortOrder order);
126  void setStringTypeNatural(bool natural);
127 
128 public:
129 
131 
132  void setCategorizationMode(CategorizationMode mode);
133  void setCategorizationSortOrder(SortOrder order);
134 
135 
136  bool isCategorized() const
137  {
138  return (categorizationMode >= CategoryByAlbum);
139  }
140 
141 public:
142 
144 
145  int compare(const ItemInfo& left, const ItemInfo& right, SortRole sortRole) const;
146 
147  static Qt::SortOrder defaultSortOrderForCategorizationMode(CategorizationMode mode);
148  static Qt::SortOrder defaultSortOrderForSortRole(SortRole role);
149 
150 public:
151 
153 
157  DatabaseFields::Set watchFlags() const;
158 
159 public:
160 
162 
166  template <typename T>
167  static inline bool lessThanByOrder(const T& a, const T& b, Qt::SortOrder sortOrder)
168  {
169  if (sortOrder == Qt::AscendingOrder)
170  {
171  return (a < b);
172  }
173 
174  return (b < a);
175  }
176 
180  template <typename T>
181  static inline int compareValue(const T& a, const T& b)
182  {
183  if (a == b)
184  {
185  return 0;
186  }
187 
188  if (a > b)
189  {
190  return 1;
191  }
192 
193  return (-1);
194  }
195 
200  static inline int compareByOrder(int compareResult, Qt::SortOrder sortOrder)
201  {
202  if (sortOrder == Qt::AscendingOrder)
203  {
204  return compareResult;
205  }
206 
207  return (- compareResult);
208  }
209 
210  template <typename T>
211  static inline int compareByOrder(const T& a, const T& b, Qt::SortOrder sortOrder)
212  {
213  return compareByOrder(compareValue(a, b), sortOrder);
214  }
215 
219  static inline int naturalCompare(const QString& a,
220  const QString& b,
221  Qt::SortOrder sortOrder,
222  Qt::CaseSensitivity caseSensitive = Qt::CaseSensitive,
223  bool natural = true)
224  {
226 
227  return compareByOrder(sorter->itemCompare(a, b, caseSensitive, natural), sortOrder);
228  }
229 
230 public:
231 
234 
237  Qt::CaseSensitivity categorizationCaseSensitivity;
238 
242 
243  Qt::SortOrder currentSortOrder;
244  Qt::CaseSensitivity sortCaseSensitivity;
245 };
246 
247 } // namespace Digikam
248 
249 #endif // DIGIKAM_ITEM_SORT_SETTINGS_H
Definition: coredbfields.h:389
Definition: facetagsiface.h:44
Definition: iteminfo.h:78
Definition: itemsortcollator.h:40
static ItemSortCollator * instance()
Definition: itemsortcollator.cpp:72
int itemCompare(const QString &a, const QString &b, Qt::CaseSensitivity caseSensitive, bool natural) const
Definition: itemsortcollator.cpp:77
Definition: itemsortsettings.h:49
Qt::CaseSensitivity categorizationCaseSensitivity
Definition: itemsortsettings.h:237
bool strTypeNatural
Definition: itemsortsettings.h:241
Qt::SortOrder currentSortOrder
Definition: itemsortsettings.h:243
static int naturalCompare(const QString &a, const QString &b, Qt::SortOrder sortOrder, Qt::CaseSensitivity caseSensitive=Qt::CaseSensitive, bool natural=true)
Definition: itemsortsettings.h:219
SortRole
Definition: itemsortsettings.h:70
@ SortByModificationDate
Definition: itemsortsettings.h:75
@ SortBySimilarity
Definition: itemsortsettings.h:81
@ SortByAspectRatio
width / height * 100000
Definition: itemsortsettings.h:79
@ SortByFileName
Definition: itemsortsettings.h:72
@ SortByImageSize
pixel number
Definition: itemsortsettings.h:78
@ SortByFaces
count of unconfirmed faces
Definition: itemsortsettings.h:80
@ SortByCreationDate
Definition: itemsortsettings.h:74
@ SortByFilePath
Definition: itemsortsettings.h:73
@ SortByManualOrderAndName
Definition: itemsortsettings.h:82
@ SortByFileSize
Definition: itemsortsettings.h:76
@ SortByRating
Definition: itemsortsettings.h:77
Qt::CaseSensitivity sortCaseSensitivity
Definition: itemsortsettings.h:244
static bool lessThanByOrder(const T &a, const T &b, Qt::SortOrder sortOrder)
— Utilities —
Definition: itemsortsettings.h:167
SortOrder sortOrder
Definition: itemsortsettings.h:240
bool isCategorized() const
Definition: itemsortsettings.h:136
static int compareValue(const T &a, const T &b)
Definition: itemsortsettings.h:181
Qt::SortOrder currentCategorizationSortOrder
Only Ascending or Descending, never DefaultOrder.
Definition: itemsortsettings.h:236
CategorizationMode
Definition: itemsortsettings.h:60
@ CategoryByMonth
Definition: itemsortsettings.h:65
@ OneCategory
all items in one global category
Definition: itemsortsettings.h:62
@ NoCategories
categorization switched off
Definition: itemsortsettings.h:61
@ CategoryByFormat
Definition: itemsortsettings.h:64
@ CategoryByAlbum
Definition: itemsortsettings.h:63
SortOrder categorizationSortOrder
Definition: itemsortsettings.h:233
static int compareByOrder(const T &a, const T &b, Qt::SortOrder sortOrder)
Definition: itemsortsettings.h:211
static int compareByOrder(int compareResult, Qt::SortOrder sortOrder)
Definition: itemsortsettings.h:200
CategorizationMode categorizationMode
Definition: itemsortsettings.h:232
SortOrder
Definition: itemsortsettings.h:53
SortRole sortRole
Definition: itemsortsettings.h:239
#define T
Definition: datefolderview.cpp:43
bool operator==(const SearchTextSettings &a, const SearchTextSettings &b)
Definition: searchtextbar.cpp:49