File indexing completed on 2025-01-05 04:25:40
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Andreas Muetzel <andreas.muetzel@gmx.net> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef AMAROK_ALBUMSMODEL_H 0018 #define AMAROK_ALBUMSMODEL_H 0019 0020 #include "core/meta/forward_declarations.h" 0021 0022 #include <QStandardItemModel> 0023 #include <QSortFilterProxyModel> 0024 0025 /** 0026 * This Model is used to get the right mime type/data for entries in the albums treeview 0027 */ 0028 class AlbumsModel : public QStandardItemModel 0029 { 0030 Q_OBJECT 0031 0032 public: 0033 explicit AlbumsModel( QObject *parent = nullptr ); 0034 ~AlbumsModel() override {} 0035 QVariant data( const QModelIndex &index, int role ) const override; 0036 QMimeData* mimeData( const QModelIndexList &indices ) const override; 0037 QStringList mimeTypes() const override; 0038 int rowHeight() const; 0039 0040 private Q_SLOTS: 0041 void updateRowHeight(); 0042 0043 private: 0044 Meta::TrackList tracksForIndex( const QModelIndex &index ) const; 0045 int m_rowHeight; 0046 }; 0047 0048 class QCollator; 0049 0050 class AlbumsProxyModel : public QSortFilterProxyModel 0051 { 0052 Q_OBJECT 0053 Q_PROPERTY( Mode mode READ mode WRITE setMode NOTIFY modeChanged ) 0054 0055 public: 0056 explicit AlbumsProxyModel( QObject *parent ); 0057 ~AlbumsProxyModel() override; 0058 0059 enum Mode { SortByCreateDate, SortByYear }; 0060 Q_ENUM( Mode ) 0061 0062 Mode mode() const; 0063 void setMode( Mode mode ); 0064 0065 QHash<int, QByteArray> roleNames() const override; 0066 0067 Q_SIGNALS: 0068 void modeChanged(); 0069 0070 protected: 0071 /** 0072 * Determine if album @param left is less than album @param right . 0073 * 0074 * If @param left and @param right both reference albums and @c m_mode 0075 * is set to @c SortByCreateDate, @c lessThan will return @c true if 0076 * and only the album referenced by @param left has a track that was 0077 * added <em>more recently</em> than all of the tracks in the album 0078 * referenced by @param right . 0079 */ 0080 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override; 0081 0082 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override; 0083 0084 private: 0085 Mode m_mode; 0086 QCollator *m_collator; 0087 }; 0088 0089 Q_DECLARE_METATYPE( AlbumsProxyModel* ) 0090 0091 #endif