[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project
Public Member Functions | List of all members
KLFLibEntrySorter Class Reference

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
 

Detailed Description

Utility class for sorting library entry items.

This class can be used as a sorter to sort entry items.

This class functions as follows:

Note
The column number may be set to be equal -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.

Note
There is no copy constructor. If there was, there would be no way of customizing the sort behavior. To use the entry sorter in contexts where you need to copy an object, use the clone mechanism with the clone constructor. (Although this should scarcely be needed ...).

Definition at line 276 of file klflib.h.

Constructor & Destructor Documentation

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.

KLFLibEntrySorter::~KLFLibEntrySorter ( )
virtual

Definition at line 218 of file klflib.cpp.

Member Function Documentation

bool KLFLibEntrySorter::compareLessThan ( const KLFLibEntry a,
const KLFLibEntry b,
int  propId,
Qt::SortOrder  order 
) const
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()().

QString KLFLibEntrySorter::entryValue ( const KLFLibEntry entry,
int  propId 
) const
virtual
bool KLFLibEntrySorter::isValid ( ) const
inline

Definition at line 291 of file klflib.h.

bool KLFLibEntrySorter::operator() ( const KLFLibEntry a,
const KLFLibEntry b 
) const
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().

Qt::SortOrder KLFLibEntrySorter::order ( ) const
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().

int KLFLibEntrySorter::propId ( ) const
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().

void KLFLibEntrySorter::setOrder ( Qt::SortOrder  order)
virtual

Set the sort order.

Definition at line 230 of file klflib.cpp.

References order().

Referenced by KLFLibModel::sort().

void KLFLibEntrySorter::setPropId ( int  propId)
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().


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

Generated by doxygen 1.8.8