digiKam
camitemsortsettings.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-23-06
7  * Description : Sort settings for camera item infos
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_CAMITEM_SORT_SETTINGS_H
25 #define DIGIKAM_CAMITEM_SORT_SETTINGS_H
26 
27 // Qt includes
28 
29 #include <QString>
30 #include <QVariant>
31 
32 // Local includes
33 
34 #include "itemsortcollator.h"
35 
36 namespace Digikam
37 {
38 
39 class CamItemInfo;
40 
42 {
43 public:
44 
45  enum SortOrder
46  {
47  AscendingOrder = Qt::AscendingOrder,
48  DescendingOrder = Qt::DescendingOrder,
50  };
51 
53  {
58  };
59 
60  enum SortRole
61  {
68  };
69 
70 public:
71 
74 
75  bool operator==(const CamItemSortSettings& other) const;
76 
83  int compareCategories(const CamItemInfo& left, const CamItemInfo& right) const;
84 
89  bool lessThan(const CamItemInfo& left, const CamItemInfo& right) const;
90 
95  bool lessThan(const QVariant& left, const QVariant& right) const;
96 
103  int compare(const CamItemInfo& left, const CamItemInfo& right) const;
104 
107 
109 
110  void setSortRole(SortRole role);
111  void setSortOrder(SortOrder order);
112  void setStringTypeNatural(bool natural);
113 
114  int compare(const CamItemInfo& left, const CamItemInfo& right, SortRole sortRole) const;
115 
117  static Qt::SortOrder defaultSortOrderForSortRole(SortRole role);
118 
122  template <typename T>
123  static inline bool lessThanByOrder(const T& a, const T& b, Qt::SortOrder sortOrder)
124  {
125  if (sortOrder == Qt::AscendingOrder)
126  {
127  return (a < b);
128  }
129 
130  return (b < a);
131  }
132 
136  template <typename T>
137  static inline int compareValue(const T& a, const T &b)
138  {
139  if (a == b)
140  {
141  return 0;
142  }
143 
144  if (a > b)
145  {
146  return 1;
147  }
148 
149  return (-1);
150  }
151 
156  static inline int compareByOrder(int compareResult, Qt::SortOrder sortOrder)
157  {
158  if (sortOrder == Qt::AscendingOrder)
159  {
160  return compareResult;
161  }
162 
163  return (- compareResult);
164  }
165 
166  template <typename T>
167  static inline int compareByOrder(const T& a, const T& b, Qt::SortOrder sortOrder)
168  {
169  return compareByOrder(compareValue(a, b), sortOrder);
170  }
171 
175  static inline int naturalCompare(const QString& a, const QString& b, Qt::SortOrder sortOrder,
176  Qt::CaseSensitivity caseSensitive = Qt::CaseSensitive,
177  bool natural = true)
178  {
180 
181  return compareByOrder(sorter->itemCompare(a, b, caseSensitive, natural), sortOrder);
182  }
183 
184 public:
185 
188 
191  Qt::CaseSensitivity categorizationCaseSensitivity;
192 
197 
198  Qt::SortOrder currentSortOrder;
199  Qt::CaseSensitivity sortCaseSensitivity;
200 };
201 
202 } // namespace Digikam
203 
204 #endif // DIGIKAM_CAMITEM_SORT_SETTINGS_H
Definition: camiteminfo.h:48
Definition: camitemsortsettings.h:42
static int compareByOrder(const T &a, const T &b, Qt::SortOrder sortOrder)
Definition: camitemsortsettings.h:167
Qt::SortOrder currentSortOrder
Definition: camitemsortsettings.h:198
void setSortRole(SortRole role)
Definition: camitemsortsettings.cpp:90
bool lessThan(const CamItemInfo &left, const CamItemInfo &right) const
Definition: camitemsortsettings.cpp:204
int compareCategories(const CamItemInfo &left, const CamItemInfo &right) const
Definition: camitemsortsettings.cpp:172
static Qt::SortOrder defaultSortOrderForSortRole(SortRole role)
Definition: camitemsortsettings.cpp:135
CamItemSortSettings()
Definition: camitemsortsettings.cpp:37
static int compareByOrder(int compareResult, Qt::SortOrder sortOrder)
Definition: camitemsortsettings.h:156
void setStringTypeNatural(bool natural)
Definition: camitemsortsettings.cpp:115
static Qt::SortOrder defaultSortOrderForCategorizationMode(CategorizationMode mode)
Definition: camitemsortsettings.cpp:120
void setCategorizationMode(CategorizationMode mode)
Definition: camitemsortsettings.cpp:66
SortOrder sortOrder
Camera Items Sorting.
Definition: camitemsortsettings.h:194
bool isCategorized() const
Definition: camitemsortsettings.h:108
void setSortOrder(SortOrder order)
Definition: camitemsortsettings.cpp:100
CategorizationMode
Definition: camitemsortsettings.h:53
@ NoCategories
Definition: camitemsortsettings.h:54
@ CategoryByFormat
Definition: camitemsortsettings.h:56
@ CategoryByDate
Definition: camitemsortsettings.h:57
@ CategoryByFolder
Definition: camitemsortsettings.h:55
static int naturalCompare(const QString &a, const QString &b, Qt::SortOrder sortOrder, Qt::CaseSensitivity caseSensitive=Qt::CaseSensitive, bool natural=true)
Definition: camitemsortsettings.h:175
CategorizationMode categorizationMode
Definition: camitemsortsettings.h:186
SortRole sortRole
Definition: camitemsortsettings.h:195
Qt::CaseSensitivity categorizationCaseSensitivity
Definition: camitemsortsettings.h:191
bool operator==(const CamItemSortSettings &other) const
Definition: camitemsortsettings.cpp:54
~CamItemSortSettings()
Definition: camitemsortsettings.cpp:50
int compare(const CamItemInfo &left, const CamItemInfo &right) const
Definition: camitemsortsettings.cpp:251
void setCategorizationSortOrder(SortOrder order)
Definition: camitemsortsettings.cpp:76
SortOrder
Definition: camitemsortsettings.h:46
@ DescendingOrder
Definition: camitemsortsettings.h:48
@ AscendingOrder
Definition: camitemsortsettings.h:47
@ DefaultOrder
sort order depends on the chosen sort role
Definition: camitemsortsettings.h:49
Qt::CaseSensitivity sortCaseSensitivity
Definition: camitemsortsettings.h:199
static int compareValue(const T &a, const T &b)
Definition: camitemsortsettings.h:137
SortRole
Definition: camitemsortsettings.h:61
@ SortByDownloadState
Definition: camitemsortsettings.h:66
@ SortByRating
Definition: camitemsortsettings.h:67
@ SortByFileSize
Definition: camitemsortsettings.h:65
@ SortByFilePath
Definition: camitemsortsettings.h:63
@ SortByFileName
Definition: camitemsortsettings.h:62
@ SortByCreationDate
Definition: camitemsortsettings.h:64
Qt::SortOrder currentCategorizationSortOrder
Only Ascending or Descending, never be DefaultOrder.
Definition: camitemsortsettings.h:190
SortOrder categorizationSortOrder
Definition: camitemsortsettings.h:187
static bool lessThanByOrder(const T &a, const T &b, Qt::SortOrder sortOrder)
Definition: camitemsortsettings.h:123
bool strTypeNatural
Definition: camitemsortsettings.h:196
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
#define T
Definition: datefolderview.cpp:43