Utility class for sorting library entry items. More...
#include <klflib.h>
Public Member Functions | |
KLFLibEntrySorter (int propId=-1, Qt::SortOrder order=Qt::AscendingOrder) | |
KLFLibEntrySorter (const KLFLibEntrySorter *clone) | |
virtual | ~KLFLibEntrySorter () |
bool | isValid () const |
int | propId () const |
The currently set property that will be queried in the items we're sorting. More... | |
Qt::SortOrder | order () const |
The currently set sorting order. More... | |
virtual void | setPropId (int propId) |
Set the KLFLibEntry property id the sort will take into account. More... | |
virtual void | setOrder (Qt::SortOrder order) |
Set the sort order. More... | |
virtual QString | entryValue (const KLFLibEntry &entry, int propId) const |
Returns a string representation of the given property in the given entry. More... | |
virtual bool | compareLessThan (const KLFLibEntry &a, const KLFLibEntry &b, int propId, Qt::SortOrder order) const |
Compares entries two entries according to the given property and order. More... | |
virtual bool | operator() (const KLFLibEntry &a, const KLFLibEntry &b) const |
Utility class for sorting library entry items.
This class can be used as a sorter to sort entry items.
This class functions as follows:
-1
, to indicate an invalid sorter (maybe to indicate that a list should not be sorted). However, the functions entryValue(), compareLessThan() and operator()() are NOT meant to be used with an invalid propId
. In other words, if isValid() is false (or equivalently, if propId() is negative), don't attempt any sorting or comparisions.To customize the behaviour of this class, you may subclass it and reimplement any level of its behavior, eg. you may want to just reimplement entryValue() to alter the string representation of the values of some properties, or you could reimplement compareLessThan() to do more sophisticated comparisions.
KLFLibEntrySorter::KLFLibEntrySorter | ( | int | propId = -1 , |
Qt::SortOrder | order = Qt::AscendingOrder |
||
) |
Definition at line 209 of file klflib.cpp.
KLFLibEntrySorter::KLFLibEntrySorter | ( | const KLFLibEntrySorter * | clone | ) |
Used to "circumvent" the copy-constructor issues of reimplemented functions. If an object is constructed using this constructor all calls to entryValue(), compareLessThan(), and operator()() are redirected to clone's.
Calls to setPropId() and setOrder() will fail and emit a warning.
In particular, never pass 'this' nor 'NULL' as clone!
Definition at line 213 of file klflib.cpp.
|
virtual |
Definition at line 218 of file klflib.cpp.
|
virtual |
Compares entries two entries according to the given property and order.
Compares the given property of entries a
and b
.
When order
is Qt::Ascending
, if a
is found to be less than (and not equal) to b
, then TRUE is returned, otherwise FALSE is returned.
If the order
is Qt::Descending
, if b
is found to be less than (and not equal) to a
, then TRUE is returned, otherwise FALSE is returned.
Definition at line 263 of file klflib.cpp.
References compareLessThan(), entryValue(), and QString::localeAwareCompare().
Referenced by compareLessThan(), and operator()().
|
virtual |
Returns a string representation of the given property in the given entry.
Definition at line 241 of file klflib.cpp.
References KLFLibEntry::DateTime, entryValue(), QSize::height(), KLFLibEntry::Preview, KLFLibEntry::PreviewSize, KLFLibEntry::previewSize(), KLFPropertizedObject::property(), QVariant::toDateTime(), QVariant::toString(), and QSize::width().
Referenced by compareLessThan(), entryValue(), and KLFLibModelCache::nodeValue().
|
virtual |
This is a wrapper that calls compareLessThan() with the previously set propId() and order().
Definition at line 276 of file klflib.cpp.
References compareLessThan().
|
inline |
The currently set sorting order.
Definition at line 296 of file klflib.h.
Referenced by KLFLibModelCache::KLFLibModelSorter::operator()(), KLFLibModel::setFlavorFlags(), setOrder(), and KLFLibModelCache::sortCategory().
|
inline |
The currently set property that will be queried in the items we're sorting.
Definition at line 294 of file klflib.h.
Referenced by KLFLibModelCache::KLFLibModelSorter::operator()(), KLFLibModel::setFlavorFlags(), setPropId(), and KLFLibModelCache::sortCategory().
|
virtual |
Set the sort order.
Definition at line 230 of file klflib.cpp.
References order().
Referenced by KLFLibModel::sort().
|
virtual |
Set the KLFLibEntry property id the sort will take into account.
Definition at line 222 of file klflib.cpp.
References propId().
Referenced by KLFLibModel::sort().