File indexing completed on 2024-05-19 04:49:51
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Téo Mrnjavac <teo@kde.org> * 0003 * Copyright (c) 2010 Nanno Langstraat <langstr@gmail.com> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify it under * 0006 * the terms of the GNU General Public License as published by the Free Software * 0007 * Foundation; either version 2 of the License, or (at your option) any later * 0008 * version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0012 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License along with * 0015 * this program. If not, see <http://www.gnu.org/licenses/>. * 0016 ****************************************************************************************/ 0017 0018 #ifndef AMAROK_SORTALGORITHMS_H 0019 #define AMAROK_SORTALGORITHMS_H 0020 0021 #include "ProxyBase.h" 0022 #include "SortScheme.h" 0023 0024 namespace Playlist 0025 { 0026 0027 /** 0028 * This struct defines a comparison functor that can be used by qSort(), qStableSort(), or 0029 * other sorting algorithms with a similar interface. 0030 * The comparison is operated on multiple levels of a Playlist::SortScheme. 0031 * @warning This functor is specific for this particular problem and wouldn't probably do 0032 * any good for sorting anything else than tracks. 0033 * @author Téo Mrnjavac <teo@kde.org> 0034 */ 0035 struct multilevelLessThan 0036 { 0037 /** 0038 * Constructor. 0039 */ 0040 multilevelLessThan() 0041 : m_scheme( SortScheme() ) 0042 { } 0043 0044 /** 0045 * Set sort scheme 0046 * @param scheme the sorting scheme that needs to be applied. 0047 */ 0048 void setSortScheme( const SortScheme & scheme ); 0049 0050 /** 0051 * Takes two row numbers from the source model and compares the corresponding indexes 0052 * based on a number of chosen criteria (columns). 0053 * @param sourceModel the source model. 0054 * @param sourceModelRowA the first row. 0055 * @param sourceModelRowB the second row. 0056 * @return true if sourceModelRowA is to be placed before sourceModelRowB, false otherwise. 0057 */ 0058 bool operator()( const QAbstractItemModel* sourceModel, int sourceModelRowA, int sourceModelRowB ) const; 0059 0060 private: 0061 template<typename T> 0062 int compareBySortableName( const AmarokSharedPointer<T> &left, const AmarokSharedPointer<T> &right ) const; 0063 0064 SortScheme m_scheme; //!< The current sorting scheme. 0065 long m_randomSalt; //!< Change the random row order from run to run. 0066 }; 0067 0068 } //namespace Playlist 0069 0070 #endif //AMAROK_SORTALGORITHMS_H