File indexing completed on 2024-05-19 04:49:51
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * Copyright (c) 2009 Téo Mrnjavac <teo@kde.org> * 0004 * Copyright (c) 2010 Nanno Langstraat <langstr@gmail.com> * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify it under * 0007 * the terms of the GNU General Public License as published by the Free Software * 0008 * Foundation; either version 2 of the License, or (at your option) any later * 0009 * version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0013 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License along with * 0016 * this program. If not, see <http://www.gnu.org/licenses/>. * 0017 ****************************************************************************************/ 0018 0019 #ifndef AMAROK_PLAYLIST_SORTFILTERPROXY_H 0020 #define AMAROK_PLAYLIST_SORTFILTERPROXY_H 0021 0022 #include "ProxyBase.h" 0023 0024 #include "SortAlgorithms.h" 0025 #include "SortScheme.h" 0026 0027 0028 namespace Playlist 0029 { 0030 0031 /** 0032 * Sorting interface; rest of Amarok shouldn't care whether sort is in 1 QSFPM with filter or not, 0033 */ 0034 class SortProxy 0035 { 0036 public: 0037 /** 0038 * Destructor. 0039 */ 0040 virtual ~SortProxy() { } 0041 0042 /** 0043 * Checks if the SortProxy is currently applying a SortScheme. 0044 * @return true if the SortProxy is sorting, otherwise false. 0045 */ 0046 virtual bool isSorted() = 0; 0047 0048 /** 0049 * Applies a sorting scheme to the playlist. 0050 * @param scheme the sorting scheme that will be applied. 0051 */ 0052 virtual void updateSortMap( const SortScheme &scheme ) = 0; 0053 }; 0054 0055 0056 /** 0057 * A proxy model that: 0058 * - Does multilevel sorting on the Playlist. 0059 * - Filters the Playlist based on a search term. 0060 */ 0061 class SortFilterProxy : public ProxyBase, public SortProxy 0062 { 0063 Q_OBJECT 0064 0065 public: 0066 //! Basics. 0067 explicit SortFilterProxy( AbstractModel *belowModel, QObject *parent = nullptr ); 0068 ~SortFilterProxy() override; 0069 0070 //! Sort-related functions. 0071 //! SortProxy public functions 0072 bool isSorted() override; 0073 void updateSortMap( const SortScheme &scheme ) override; 0074 0075 //! Filter-related functions. 0076 //! Playlist::AbstractModel search-related functions. 0077 void clearSearchTerm() override; 0078 void filterUpdated() override; 0079 0080 /** This will set the search term for the filter. 0081 filterUpdated() must be called to update the results. 0082 This allows client 'PrettyListView' to give the user the time to type a few 0083 characters before we do a filter run that might block for a few seconds. 0084 */ 0085 int find( const QString & searchTerm, int searchFields = MatchTrack ) override; 0086 void showOnlyMatches( bool onlyMatches ) override; 0087 0088 //!Q_SIGNALS: 0089 //! Emits signals inherited from QSortFilterProxy 0090 //! Emits signals inherited from Playlist::AbstractModel / ProxyBase 0091 0092 private: 0093 /** 0094 * Reimplemented from QSortFilterProxyModel. The sort comparison function. 0095 * @param left the first index to compare. 0096 * @param right the second index to compare. 0097 * @return true if left is to be placed before right, false otherwise. 0098 */ 0099 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override; 0100 0101 /** 0102 * Reimplemented from QSortFilterProxyModel. The filter decision function. 0103 * When not in 'showOnlyMatches' mode, this always returns true. 0104 * @param sourceModelRow The row in 'sourceModel()' to check. 0105 * @param sourceModelParent Ignored. 0106 * @return True if the row should be included, false otherwise. 0107 */ 0108 bool filterAcceptsRow( int sourceModelRow, const QModelIndex &sourceModelParent ) const override; 0109 0110 0111 SortScheme m_scheme; //!< The current sorting scheme. 0112 multilevelLessThan m_mlt; //!< Decision object for current sorting scheme. 0113 0114 QString m_currentSearchTerm; 0115 int m_currentSearchFields; 0116 0117 bool m_showOnlyMatches; 0118 }; 0119 0120 } // namespace Playlist 0121 0122 #endif