• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • graphics API Reference
  • KDE Home
  • Contact Us
 

digikam

  • extragear
  • graphics
  • digikam
  • core
  • showfoto
  • thumbbar
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 
38 class ShowfotoItemSortSettings
39 {
40 public:
41 
42  enum SortOrder
43  {
44  AscendingOrder = Qt::AscendingOrder,
45  DescendingOrder = Qt::DescendingOrder,
46  DefaultOrder
47  };
48 
49  enum CategorizationMode
50  {
51  NoCategories,
52  CategoryByFolder,
53  CategoryByFormat
54  };
55 
56  enum SortRole
57  {
58  SortByCreationDate,
59  SortByFileName,
60  SortByFileSize
61  };
62 
63 public:
64 
65  ShowfotoItemSortSettings();
66  ~ShowfotoItemSortSettings();
67 
68  bool operator==(const ShowfotoItemSortSettings& other) const;
69 
75  int compareCategories(const ShowfotoItemInfo& left, const ShowfotoItemInfo& right) const;
76 
77 
81  bool lessThan(const ShowfotoItemInfo& left, const ShowfotoItemInfo& right) const;
82 
86  bool lessThan(const QVariant& left, const QVariant& right) const;
87 
93  int compare(const ShowfotoItemInfo& left, const ShowfotoItemInfo& right) const;
94 
96 
97  void setCategorizationMode(CategorizationMode mode);
98  void setCategorizationSortOrder(SortOrder order);
99 
100  bool isCategorized() const
101  {
102  return (categorizationMode >= CategoryByFolder);
103  }
104 
106 
107  void setSortRole(SortRole role);
108  void setSortOrder(SortOrder order);
109 
110  int compare(const ShowfotoItemInfo& left, const ShowfotoItemInfo& right, SortRole sortRole) const;
111 
112  static Qt::SortOrder defaultSortOrderForCategorizationMode(CategorizationMode mode);
113  static Qt::SortOrder defaultSortOrderForSortRole(SortRole role);
114 
117  template <typename T>
118  static inline bool lessThanByOrder(const T& a, const T& b, Qt::SortOrder sortOrder)
119  {
120  if (sortOrder == Qt::AscendingOrder)
121  return a < b;
122  else
123  return b < a;
124  }
125 
128  template <typename T>
129  static inline int compareValue(const T& a, const T &b)
130  {
131  if (a == b)
132  return 0;
133 
134  if (a < b)
135  return -1;
136  else
137  return 1;
138  }
139 
143  static inline int compareByOrder(int compareResult, Qt::SortOrder sortOrder)
144  {
145  if (sortOrder == Qt::AscendingOrder)
146  return compareResult;
147  else
148  return - compareResult;
149  }
150 
151  template <typename T>
152  static inline int compareByOrder(const T& a, const T& b, Qt::SortOrder sortOrder)
153  {
154  return compareByOrder(compareValue(a, b), sortOrder);
155  }
156 
159  static inline int naturalCompare(const QString& a, const QString& b, Qt::SortOrder sortOrder,
160  Qt::CaseSensitivity caseSensitive = Qt::CaseSensitive)
161  {
162  QCollator collator;
163  collator.setNumericMode(true);
164  collator.setIgnorePunctuation(false);
165  collator.setCaseSensitivity(caseSensitive);
166  return (compareByOrder(collator.compare(a, b), sortOrder));
167  }
168 
169 public:
170 
171  CategorizationMode categorizationMode;
172  SortOrder categorizationSortOrder;
173 
175  Qt::SortOrder currentCategorizationSortOrder;
176  Qt::CaseSensitivity categorizationCaseSensitivity;
177 
178  SortOrder sortOrder;
179  SortRole sortRole;
180 
181  Qt::SortOrder currentSortOrder;
182  Qt::CaseSensitivity sortCaseSensitivity;
183 };
184 
185 } // namespace ShowFoto
186 
187 #endif // SHOW_FOTO_ITEM_SORT_SETTINGS_H
ShowFoto::ShowfotoItemSortSettings::lessThan
bool lessThan(const ShowfotoItemInfo &left, const ShowfotoItemInfo &right) const
Returns true if left is less than right.
Definition: showfotoitemsortsettings.cpp:147
ShowFoto::ShowfotoItemSortSettings::compareCategories
int compareCategories(const ShowfotoItemInfo &left, const ShowfotoItemInfo &right) const
Compares the categories of left and right ShowfotoItemInfos.
Definition: showfotoitemsortsettings.cpp:133
ShowFoto::ShowfotoItemSortSettings::categorizationSortOrder
SortOrder categorizationSortOrder
Definition: showfotoitemsortsettings.h:172
ShowFoto::ShowfotoItemSortSettings::setSortRole
void setSortRole(SortRole role)
— Showfoto Items Sorting ------------—
Definition: showfotoitemsortsettings.cpp:83
ShowFoto::ShowfotoItemSortSettings::operator==
bool operator==(const ShowfotoItemSortSettings &other) const
Definition: showfotoitemsortsettings.cpp:49
ShowFoto::ShowfotoItemSortSettings::~ShowfotoItemSortSettings
~ShowfotoItemSortSettings()
Definition: showfotoitemsortsettings.cpp:45
ShowFoto::ShowfotoItemSortSettings::SortByCreationDate
Definition: showfotoitemsortsettings.h:58
ShowFoto::ShowfotoItemSortSettings::DescendingOrder
Definition: showfotoitemsortsettings.h:45
ShowFoto::ShowfotoItemSortSettings::currentSortOrder
Qt::SortOrder currentSortOrder
Definition: showfotoitemsortsettings.h:181
ShowFoto::ShowfotoItemSortSettings::CategorizationMode
CategorizationMode
Definition: showfotoitemsortsettings.h:49
ShowFoto::ShowfotoItemSortSettings::SortRole
SortRole
Definition: showfotoitemsortsettings.h:56
ShowFoto::ShowfotoItemSortSettings::SortOrder
SortOrder
Definition: showfotoitemsortsettings.h:42
ShowFoto::ShowfotoItemSortSettings::categorizationMode
CategorizationMode categorizationMode
Definition: showfotoitemsortsettings.h:171
ShowFoto::ShowfotoItemSortSettings::defaultSortOrderForSortRole
static Qt::SortOrder defaultSortOrderForSortRole(SortRole role)
Definition: showfotoitemsortsettings.cpp:119
ShowFoto::ShowfotoItemSortSettings::compareValue
static int compareValue(const T &a, const T &b)
Returns the usual compare result of -1, 0, or 1 for lessThan, equals and greaterThan.
Definition: showfotoitemsortsettings.h:129
ShowFoto::ShowfotoItemSortSettings::lessThanByOrder
static bool lessThanByOrder(const T &a, const T &b, Qt::SortOrder sortOrder)
Returns a < b if sortOrder is Ascending, or b < a if order is descending.
Definition: showfotoitemsortsettings.h:118
ShowFoto::ShowfotoItemSortSettings::compareByOrder
static int compareByOrder(const T &a, const T &b, Qt::SortOrder sortOrder)
Definition: showfotoitemsortsettings.h:152
ShowFoto::ShowfotoItemSortSettings::compareByOrder
static int compareByOrder(int compareResult, Qt::SortOrder sortOrder)
Takes a typical result from a compare method (0 is equal, -1 is less than, 1 is greater than) and app...
Definition: showfotoitemsortsettings.h:143
ShowFoto::ShowfotoItemSortSettings::defaultSortOrderForCategorizationMode
static Qt::SortOrder defaultSortOrderForCategorizationMode(CategorizationMode mode)
Definition: showfotoitemsortsettings.cpp:107
order
#define order
Definition: var_defines.h:166
T
#define T
Definition: wf_filtering.cpp:23
ShowFoto::ShowfotoItemSortSettings::sortRole
SortRole sortRole
Definition: showfotoitemsortsettings.h:179
ShowFoto::ShowfotoItemSortSettings::isCategorized
bool isCategorized() const
Definition: showfotoitemsortsettings.h:100
ShowFoto::ShowfotoItemSortSettings::CategoryByFolder
Definition: showfotoitemsortsettings.h:52
ShowFoto::ShowfotoItemSortSettings::SortByFileName
Definition: showfotoitemsortsettings.h:59
QString
ShowFoto::ShowfotoItemSortSettings::sortCaseSensitivity
Qt::CaseSensitivity sortCaseSensitivity
Definition: showfotoitemsortsettings.h:182
ShowFoto::ShowfotoItemSortSettings::setCategorizationMode
void setCategorizationMode(CategorizationMode mode)
— Categories ------------—
Definition: showfotoitemsortsettings.cpp:59
ShowFoto::ShowfotoItemSortSettings
Definition: showfotoitemsortsettings.h:38
ShowFoto::ShowfotoItemSortSettings::currentCategorizationSortOrder
Qt::SortOrder currentCategorizationSortOrder
Only Ascending or Descending, never be DefaultOrder.
Definition: showfotoitemsortsettings.h:175
ShowFoto::ShowfotoItemSortSettings::ShowfotoItemSortSettings
ShowfotoItemSortSettings()
Definition: showfotoitemsortsettings.cpp:33
ShowFoto::ShowfotoItemSortSettings::AscendingOrder
Definition: showfotoitemsortsettings.h:44
showfotoiteminfo.h
ShowFoto::ShowfotoItemSortSettings::sortOrder
SortOrder sortOrder
Definition: showfotoitemsortsettings.h:178
ShowFoto::ShowfotoItemSortSettings::compare
int compare(const ShowfotoItemInfo &left, const ShowfotoItemInfo &right) const
Compares the showfotoItemInfos left and right.
Definition: showfotoitemsortsettings.cpp:174
ShowFoto::ShowfotoItemInfo
Definition: showfotoiteminfo.h:46
ShowFoto::ShowfotoItemSortSettings::DefaultOrder
sort order depends on the chosen sort role
Definition: showfotoitemsortsettings.h:46
ShowFoto::ShowfotoItemSortSettings::setSortOrder
void setSortOrder(SortOrder order)
Definition: showfotoitemsortsettings.cpp:93
ShowFoto::ShowfotoItemSortSettings::categorizationCaseSensitivity
Qt::CaseSensitivity categorizationCaseSensitivity
Definition: showfotoitemsortsettings.h:176
ShowFoto::ShowfotoItemSortSettings::SortByFileSize
Definition: showfotoitemsortsettings.h:60
ShowFoto::ShowfotoItemSortSettings::naturalCompare
static int naturalCompare(const QString &a, const QString &b, Qt::SortOrder sortOrder, Qt::CaseSensitivity caseSensitive=Qt::CaseSensitive)
Compares the two string by natural comparison and adheres to given sort order.
Definition: showfotoitemsortsettings.h:159
ShowFoto::ShowfotoItemSortSettings::setCategorizationSortOrder
void setCategorizationSortOrder(SortOrder order)
Definition: showfotoitemsortsettings.cpp:69
ShowFoto::ShowfotoItemSortSettings::CategoryByFormat
Definition: showfotoitemsortsettings.h:53
QVariant
ShowFoto::ShowfotoItemSortSettings::NoCategories
Definition: showfotoitemsortsettings.h:51
b
long b
Definition: 62/jpegint.h:371
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Thu Dec 5 2019 04:37:18 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

digikam

Skip menu "digikam"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages
-->

graphics API Reference

Skip menu "graphics API Reference"
  • digikam
  • KDiagram
  •     KChart
  •     KGantt
  • KPhotoAlbum
  •   AndroidRemoteControl
  • Krita
  •   libs
  •     KritaBasicFlakes
  •     brush
  •     KritaUndo2
  •     KritaFlake
  •     image
  •     KritaPlugin
  •     Krita
  •     KritaOdf
  •     KritaPigment
  •     KritaStore
  •     ui
  •     KritaWidgets
  •     KritaWidgetUtils
  •   plugins
  •     Assitants
  •     Extensions
  •     Filters
  •         KritaText
  •         KritaTextLayout
  •     Generators
  •     Formats
  •             src
  •     PaintOps
  •       libpaintop
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal