/*                 This file is part of the Opie Project Originally a part of the KDE Project (C) 2001 Carsten Pfeiffer =. .=l.            .>+-=  _;:,     .>    :=|. This program is free software; you can .> <`_,   >  .   <= redistribute it and/or modify it under :`=1 )Y*s>-.--   : the terms of the GNU Library General Public .="- .-=="i,     .._ License as published by the Free Software  - .   .-<_>     .<> Foundation; either version 2 of the License,      ._= =}       : or (at your option) any later version.     .%`+i>       _;_.     .i_,=:_.      -`: PARTICULAR PURPOSE. See the GNU ..}^=.=       =       ; Library General Public License for more ++=   -.     .`     .: details.  :     =  ...= . :.=-  -.   .:....=;==+<; You should have received a copy of the GNU   -_. . .   )=.  = Library General Public License along with     --        :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef OSORTABLEVALUELIST_H #define OSORTABLEVALUELIST_H #if QT_VERSION >= 0x030000 #include #include #else #include #include #endif #include template class OSortableItem : public QPair { public: OSortableItem( Key i, const T& t ) : QPair( i, t ) {} OSortableItem( const OSortableItem &rhs ) : QPair( rhs.first, rhs.second ) {} OSortableItem() {} OSortableItem &operator=( const OSortableItem& i ) { first = i.first; second = i.second; return *this; } // operators for sorting bool operator> ( const OSortableItem& i2 ) const { return (i2.first < first); } bool operator< ( const OSortableItem& i2 ) const { return (first < i2.first); } bool operator>= ( const OSortableItem& i2 ) const { return (first >= i2.first); } bool operator<= ( const OSortableItem& i2 ) const { return !(i2.first < first); } bool operator== ( const OSortableItem& i2 ) const { return (first == i2.first); } bool operator!= ( const OSortableItem& i2 ) const { return (first != i2.first); } T& value() { return second; } const T& value() const { return second; } Key index() const { return first; } }; // convenience template class OSortableValueList : public QValueList > { public: void insert( Key i, const T& t ) { QValueList >::append( OSortableItem( i, t ) ); } // add more as you please... T& operator[]( Key i ) { return QValueList >::operator[]( i ).value(); } const T& operator[]( Key i ) const { return QValueList >::operator[]( i ).value(); } void sort() { qHeapSort( *this ); } }; // template class OSortableValueListIterator : public QValueListIterator > // { // }; #endif // OSORTABLEVALUELIST_H