Qt 4.8
Public Functions | Properties | List of all members
QDirSortItemComparator Class Reference

Public Functions

bool operator() (const QDirSortItem &, const QDirSortItem &)
 
 QDirSortItemComparator (int flags)
 

Properties

int qt_cmp_si_sort_flags
 

Detailed Description

Definition at line 223 of file qdir.cpp.

Constructors and Destructors

◆ QDirSortItemComparator()

QDirSortItemComparator::QDirSortItemComparator ( int  flags)
inline

Definition at line 227 of file qdir.cpp.

227 : qt_cmp_si_sort_flags(flags) {}

Functions

◆ operator()()

bool QDirSortItemComparator::operator() ( const QDirSortItem n1,
const QDirSortItem n2 
)

Definition at line 231 of file qdir.cpp.

232 {
233  const QDirSortItem* f1 = &n1;
234  const QDirSortItem* f2 = &n2;
235 
236  if ((qt_cmp_si_sort_flags & QDir::DirsFirst) && (f1->item.isDir() != f2->item.isDir()))
237  return f1->item.isDir();
238  if ((qt_cmp_si_sort_flags & QDir::DirsLast) && (f1->item.isDir() != f2->item.isDir()))
239  return !f1->item.isDir();
240 
241  int r = 0;
242  int sortBy = (qt_cmp_si_sort_flags & QDir::SortByMask)
244 
245  switch (sortBy) {
246  case QDir::Time:
247  r = f1->item.lastModified().secsTo(f2->item.lastModified());
248  break;
249  case QDir::Size:
250  r = int(qBound<qint64>(-1, f2->item.size() - f1->item.size(), 1));
251  break;
252  case QDir::Type:
253  {
255 
256  if (f1->suffix_cache.isNull())
257  f1->suffix_cache = ic ? f1->item.suffix().toLower()
258  : f1->item.suffix();
259  if (f2->suffix_cache.isNull())
260  f2->suffix_cache = ic ? f2->item.suffix().toLower()
261  : f2->item.suffix();
262 
265  : f1->suffix_cache.compare(f2->suffix_cache);
266  }
267  break;
268  default:
269  ;
270  }
271 
272  if (r == 0 && sortBy != QDir::Unsorted) {
273  // Still not sorted - sort by name
275 
276  if (f1->filename_cache.isNull())
277  f1->filename_cache = ic ? f1->item.fileName().toLower()
278  : f1->item.fileName();
279  if (f2->filename_cache.isNull())
280  f2->filename_cache = ic ? f2->item.fileName().toLower()
281  : f2->item.fileName();
282 
286  }
287  if (r == 0) // Enforce an order - the order the items appear in the array
288  r = (&n1) - (&n2);
290  return r > 0;
291  return r < 0;
292 }
QString fileName() const
Returns the name of the file, excluding the path.
Definition: qfileinfo.cpp:726
QFileInfo item
Definition: qdir.cpp:219
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
Definition: qfileinfo.cpp:990
int secsTo(const QDateTime &) const
Returns the number of seconds from this datetime to the other datetime.
Definition: qdatetime.cpp:2914
int localeAwareCompare(const QString &s) const
Definition: qstring.cpp:5197
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
int compare(const QString &s) const
Definition: qstring.cpp:5037
qint64 size() const
Returns the file size in bytes.
Definition: qfileinfo.cpp:1248
QString filename_cache
Definition: qdir.cpp:217
QString suffix() const
Returns the suffix of the file.
Definition: qfileinfo.cpp:834
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
QString suffix_cache
Definition: qdir.cpp:218
QDateTime lastModified() const
Returns the date and time when the file was last modified.
Definition: qfileinfo.cpp:1296

Properties

◆ qt_cmp_si_sort_flags

int QDirSortItemComparator::qt_cmp_si_sort_flags
private

Definition at line 225 of file qdir.cpp.


The documentation for this class was generated from the following file: