File indexing completed on 2024-05-19 04:49:51
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Téo Mrnjavac <teo@kde.org> * 0003 * Copyright (c) 2013 Konrad Zemek <konrad.zemek@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 #include "SortScheme.h" 0019 #include "playlist/PlaylistDefines.h" 0020 0021 #include "core/support/Debug.h" 0022 0023 #include <KLocalizedString> 0024 0025 namespace Playlist 0026 { 0027 0028 SortLevel::SortLevel( Column sortCategory, Qt::SortOrder sortOrder ) 0029 : m_category( sortCategory ) 0030 , m_order( sortOrder ) 0031 { 0032 if( m_category == PlaceHolder ) 0033 debug() << "Warning: Playlist::SortLevel: for some reason somebody has created a SortLevel with a placeholder as column."; 0034 if( m_category >= NUM_COLUMNS ) 0035 debug() << "Error: Playlist::SortLevel: column number overflow."; 0036 } 0037 0038 Column 0039 SortLevel::category() const 0040 { 0041 return m_category; 0042 } 0043 0044 Qt::SortOrder 0045 SortLevel::order() const 0046 { 0047 return m_order; 0048 } 0049 0050 void 0051 SortLevel::setCategory(Column sortCategory) 0052 { 0053 m_category = sortCategory; 0054 } 0055 0056 void 0057 SortLevel::setOrder( Qt::SortOrder sortOrder ) 0058 { 0059 m_order = sortOrder; 0060 } 0061 0062 bool 0063 SortLevel::isComparable() const 0064 { 0065 return isSortableColumn( category() ); 0066 } 0067 0068 bool 0069 SortLevel::isString() const 0070 { 0071 QList< Column > strCategories; 0072 strCategories << Album << AlbumArtist << Artist << Comment << Composer << Directory << Filename 0073 << Genre << LastPlayed << Source << Title << Type << Year; 0074 if( isComparable() && strCategories.contains( category() ) ) 0075 return true; 0076 return false; 0077 } 0078 0079 bool 0080 SortLevel::isFloat() const 0081 { 0082 QList< Column > floatCategories; 0083 floatCategories << Bpm; 0084 if( isComparable() && floatCategories.contains( category() ) ) 0085 return true; 0086 return false; 0087 } 0088 0089 QString 0090 SortLevel::prettyName() const 0091 { 0092 return columnName( m_category ); 0093 } 0094 0095 // BEGIN SortScheme 0096 0097 const SortLevel & 0098 SortScheme::level( int i ) const 0099 { 0100 //SortLevel( 0 ) is a dummy, as in PlaylistDefines.h 0=PlaceHolder 0101 return (*this)[ i ]; 0102 } 0103 0104 void 0105 SortScheme::addLevel( const Playlist::SortLevel& level ) 0106 { 0107 push( level ); 0108 } 0109 0110 int 0111 SortScheme::length() const 0112 { 0113 return size(); 0114 } 0115 0116 void 0117 SortScheme::trimToLevel( int lastLevel ) 0118 { 0119 while( size() > lastLevel ) 0120 pop(); 0121 } 0122 0123 SortScheme::const_iterator 0124 SortScheme::begin() const 0125 { 0126 return QStack::begin(); 0127 } 0128 0129 SortScheme::const_iterator 0130 SortScheme::end() const 0131 { 0132 return QStack::end(); 0133 } 0134 0135 } //namespace Playlist