digiKam
showfotoitemsortsettings.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 : 29-07-2013
7  * Description : Sort settings for showfoto item infos
8  *
9  * Copyright (C) 2013 by Mohamed_Anwer <m_dot_anwer at gmx 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 SHOW_FOTO_ITEM_SORT_SETTINGS_H
25 #define SHOW_FOTO_ITEM_SORT_SETTINGS_H
26 
27 // Qt includes
28 
29 #include <QCollator>
30 
31 // Local includes
32 
33 #include "showfotoiteminfo.h"
34 
35 namespace ShowFoto
36 {
37 
39 {
40 public:
41 
42  enum SortOrder
43  {
44  AscendingOrder = Qt::AscendingOrder,
45  DescendingOrder = Qt::DescendingOrder,
47  };
48 
50  {
54  };
55 
56  enum SortRole
57  {
61  };
62 
63 public:
64 
67 
68  bool operator==(const ShowfotoItemSortSettings& other) const;
69 
76  int compareCategories(const ShowfotoItemInfo& left, const ShowfotoItemInfo& right) const;
77 
78 
83  bool lessThan(const ShowfotoItemInfo& left, const ShowfotoItemInfo& right) const;
84 
89  bool lessThan(const QVariant& left, const QVariant& right) const;
90 
97  int compare(const ShowfotoItemInfo& left, const ShowfotoItemInfo& right) const;
98 
100 
103 
104  bool isCategorized() const
105  {
107  }
108 
110 
111  void setSortRole(SortRole role);
112  void setSortOrder(SortOrder order);
113 
114  int compare(const ShowfotoItemInfo& left, const ShowfotoItemInfo& 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  else
130  {
131  return (b < a);
132  }
133  }
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 
181  static inline int naturalCompare(const QString& a, const QString& b, Qt::SortOrder sortOrder,
182  Qt::CaseSensitivity caseSensitive = Qt::CaseSensitive)
183  {
184  QCollator collator;
185  collator.setNumericMode(true);
186  collator.setIgnorePunctuation(false);
187  collator.setCaseSensitivity(caseSensitive);
188 
189  return (compareByOrder(collator.compare(a, b), sortOrder));
190  }
191 
192 public:
193 
196 
199  Qt::CaseSensitivity categorizationCaseSensitivity;
200 
203 
204  Qt::SortOrder currentSortOrder;
205  Qt::CaseSensitivity sortCaseSensitivity;
206 };
207 
208 } // namespace ShowFoto
209 
210 #endif // SHOW_FOTO_ITEM_SORT_SETTINGS_H
Definition: showfotoiteminfo.h:48
Definition: showfotoitemsortsettings.h:39
Qt::CaseSensitivity sortCaseSensitivity
Definition: showfotoitemsortsettings.h:205
void setCategorizationSortOrder(SortOrder order)
Definition: showfotoitemsortsettings.cpp:71
CategorizationMode categorizationMode
Definition: showfotoitemsortsettings.h:194
SortOrder categorizationSortOrder
Definition: showfotoitemsortsettings.h:195
static int compareValue(const T &a, const T &b)
Definition: showfotoitemsortsettings.h:139
static bool lessThanByOrder(const T &a, const T &b, Qt::SortOrder sortOrder)
Definition: showfotoitemsortsettings.h:123
SortRole sortRole
Definition: showfotoitemsortsettings.h:202
void setSortOrder(SortOrder order)
Definition: showfotoitemsortsettings.cpp:95
static int compareByOrder(const T &a, const T &b, Qt::SortOrder sortOrder)
Definition: showfotoitemsortsettings.h:173
Qt::SortOrder currentCategorizationSortOrder
Only Ascending or Descending, never be DefaultOrder.
Definition: showfotoitemsortsettings.h:198
bool isCategorized() const
Definition: showfotoitemsortsettings.h:104
int compareCategories(const ShowfotoItemInfo &left, const ShowfotoItemInfo &right) const
Definition: showfotoitemsortsettings.cpp:145
SortOrder
Definition: showfotoitemsortsettings.h:43
@ DefaultOrder
sort order depends on the chosen sort role
Definition: showfotoitemsortsettings.h:46
@ AscendingOrder
Definition: showfotoitemsortsettings.h:44
@ DescendingOrder
Definition: showfotoitemsortsettings.h:45
void setSortRole(SortRole role)
— Showfoto Items Sorting ------------—
Definition: showfotoitemsortsettings.cpp:85
SortRole
Definition: showfotoitemsortsettings.h:57
@ SortByFileName
Definition: showfotoitemsortsettings.h:59
@ SortByFileSize
Definition: showfotoitemsortsettings.h:60
@ SortByCreationDate
Definition: showfotoitemsortsettings.h:58
Qt::SortOrder currentSortOrder
Definition: showfotoitemsortsettings.h:204
bool lessThan(const ShowfotoItemInfo &left, const ShowfotoItemInfo &right) const
Definition: showfotoitemsortsettings.cpp:167
ShowfotoItemSortSettings()
Definition: showfotoitemsortsettings.cpp:33
Qt::CaseSensitivity categorizationCaseSensitivity
Definition: showfotoitemsortsettings.h:199
CategorizationMode
Definition: showfotoitemsortsettings.h:50
@ CategoryByFolder
Definition: showfotoitemsortsettings.h:52
@ CategoryByFormat
Definition: showfotoitemsortsettings.h:53
@ NoCategories
Definition: showfotoitemsortsettings.h:51
static int naturalCompare(const QString &a, const QString &b, Qt::SortOrder sortOrder, Qt::CaseSensitivity caseSensitive=Qt::CaseSensitive)
Definition: showfotoitemsortsettings.h:181
SortOrder sortOrder
Definition: showfotoitemsortsettings.h:201
bool operator==(const ShowfotoItemSortSettings &other) const
Definition: showfotoitemsortsettings.cpp:49
int compare(const ShowfotoItemInfo &left, const ShowfotoItemInfo &right) const
Definition: showfotoitemsortsettings.cpp:194
static Qt::SortOrder defaultSortOrderForSortRole(SortRole role)
Definition: showfotoitemsortsettings.cpp:123
~ShowfotoItemSortSettings()
Definition: showfotoitemsortsettings.cpp:45
void setCategorizationMode(CategorizationMode mode)
— Categories ------------—
Definition: showfotoitemsortsettings.cpp:61
static Qt::SortOrder defaultSortOrderForCategorizationMode(CategorizationMode mode)
Definition: showfotoitemsortsettings.cpp:109
static int compareByOrder(int compareResult, Qt::SortOrder sortOrder)
Definition: showfotoitemsortsettings.h:160
#define T
Definition: showfotofolderviewbar.cpp:52