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_PROXYBASE_H 0019 #define AMAROK_PROXYBASE_H 0020 0021 #include "AbstractModel.h" 0022 #include "playlist/PlaylistItem.h" 0023 0024 #include <QSortFilterProxyModel> 0025 0026 namespace Playlist 0027 { 0028 0029 /** 0030 * A ProxyModel that implements all the common forwarders for the interface of any 0031 * playlist proxy. 0032 * @author Téo Mrnjavac <teo@kde.org> 0033 */ 0034 class ProxyBase : public QSortFilterProxyModel, public Playlist::AbstractModel 0035 { 0036 Q_OBJECT 0037 public: 0038 /** 0039 * Constructor. 0040 */ 0041 explicit ProxyBase( AbstractModel *belowModel, QObject *parent = nullptr ); 0042 0043 /** 0044 * Destructor. 0045 */ 0046 ~ProxyBase() override; 0047 0048 //! Inherited from Playlist::AbstractModel 0049 QAbstractItemModel* qaim() const override { return const_cast<ProxyBase*>( this ); } 0050 0051 quint64 activeId() const override; 0052 int activeRow() const override; 0053 Meta::TrackPtr activeTrack() const override; 0054 QSet<int> allRowsForTrack( const Meta::TrackPtr& track ) const override; 0055 void clearSearchTerm() override; 0056 bool containsTrack( const Meta::TrackPtr& track ) const override; 0057 int currentSearchFields() override; 0058 QString currentSearchTerm() override; 0059 bool exportPlaylist( const QString &path, bool relative = false ) override; 0060 void filterUpdated() override; 0061 int find( const QString &searchTerm, int searchFields ) override; 0062 int findNext( const QString &searchTerm, int selectedRow, int searchFields ) override; 0063 int findPrevious( const QString &searchTerm, int selectedRow, int searchFields ) override; 0064 int firstRowForTrack( const Meta::TrackPtr& track ) const override; 0065 quint64 idAt( const int row ) const override; 0066 bool rowExists( int row ) const override; 0067 int rowForId( const quint64 id ) const override; 0068 int rowFromBottomModel( const int rowInBase ) override; 0069 int rowToBottomModel( const int rowInProxy ) override; 0070 void setActiveId( const quint64 id ) override; 0071 void setActiveRow( int row ) override; 0072 void setAllUnplayed() override; 0073 void emitQueueChanged() override; 0074 int queuePositionOfRow( int row ) override; 0075 void showOnlyMatches( bool onlyMatches ) override; 0076 Item::State stateOfId( quint64 id ) const override; 0077 Item::State stateOfRow( int row ) const override; 0078 qint64 totalLength() const override; 0079 quint64 totalSize() const override; 0080 Meta::TrackPtr trackAt( int row ) const override; 0081 Meta::TrackPtr trackForId( const quint64 id ) const override; 0082 Meta::TrackList tracks() override; 0083 0084 Q_SIGNALS: 0085 //! Proxied from Playlist::Model. 0086 void activeTrackChanged( const quint64 ); 0087 void queueChanged(); 0088 0089 protected: 0090 /** 0091 * Check if a certain row in the source model matches a search term when looking at 0092 * the fields specified by the searchFields bitmask. 0093 * @param sourceModelRow The row number in the source model to match against. 0094 * @param searchTerm The search term. 0095 * @param searchFields A bitmask containing the fields that should be matched against. 0096 * @return True if a match is found in any field, false otherwise. 0097 */ 0098 bool rowMatch( int sourceModelRow, const QString &searchTerm, int searchFields ) const; 0099 0100 /** 0101 * Converts a row number in the underlying model to a row number in this proxy. 0102 * @param sourceModelRow the row number that's valid in 'sourceModel()'. 0103 * @return the row number that's valid in this proxy. 0104 */ 0105 virtual int rowFromSource( int sourceModelRow ) const; 0106 0107 /** 0108 * Converts a row number in this proxy to a row number in the underlying model. 0109 * 0110 * As a special case, 'proxyModelRow == rowCount()' returns the bottom model's 0111 * 'rowCount()'. See comment at 'rowToBottomModel()'. 0112 * 0113 * @param proxyModelRow the row number that's valid in this proxy. 0114 * @return the row number that's valid in 'sourceModel()'. 0115 */ 0116 virtual int rowToSource( int proxyModelRow ) const; 0117 0118 0119 AbstractModel *m_belowModel; 0120 }; 0121 0122 } //namespace Playlist 0123 0124 #endif //AMAROK_PROXYBASE_H