File indexing completed on 2024-05-19 04:49:51
0001 /**************************************************************************************** 0002 * Copyright (c) 2007-2008 Ian Monroe <ian@monroe.nu> * 0003 * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org> * 0004 * Copyright (c) 2008 Seb Ruiz <ruiz@kde.org> * 0005 * Copyright (c) 2008 Soren Harward <stharward@gmail.com> * 0006 * Copyright (c) 2009 Téo Mrnjavac <teo@kde.org> * 0007 * Copyright (c) 2010 Nanno Langstraat <langstr@gmail.com> * 0008 * * 0009 * This program is free software; you can redistribute it and/or modify it under * 0010 * the terms of the GNU General Public License as published by the Free Software * 0011 * Foundation; either version 2 of the License, or (at your option) version 3 or * 0012 * any later version accepted by the membership of KDE e.V. (or its successor approved * 0013 * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of * 0014 * version 3 of the license. * 0015 * * 0016 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0017 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0018 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License along with * 0021 * this program. If not, see <http://www.gnu.org/licenses/>. * 0022 ****************************************************************************************/ 0023 0024 #ifndef AMAROK_PLAYLISTGROUPINGPROXY_H 0025 #define AMAROK_PLAYLISTGROUPINGPROXY_H 0026 0027 #include "ProxyBase.h" 0028 #include "core/meta/forward_declarations.h" 0029 0030 #include <QHash> 0031 #include <QModelIndex> 0032 #include <KLocalizedString> 0033 0034 namespace Playlist 0035 { 0036 0037 // Extension of Playlist::DataRoles 0038 enum GroupDataRoles 0039 { 0040 GroupRole = 0x1000, 0041 GroupedTracksRole // deprecated 0042 }; 0043 0044 namespace Grouping 0045 { 0046 enum GroupMode 0047 { 0048 None = 1, 0049 Head, 0050 Head_Collapsed, // deprecated 0051 Body, 0052 Tail, 0053 Collapsed, // deprecated 0054 Invalid 0055 }; 0056 } 0057 0058 class GroupingProxy : public ProxyBase 0059 { 0060 Q_OBJECT 0061 0062 public: 0063 explicit GroupingProxy( AbstractModel *belowModel, QObject *parent = nullptr ); 0064 ~GroupingProxy() override; 0065 0066 static GroupingProxy* instance(); 0067 static void destroy(); 0068 0069 0070 //! Configuration 0071 QString groupingCategory() const; 0072 /** 0073 * The criterion by which adjacent items are divided into groups. 0074 * @param groupingCategory A string from 'groupableCategories', or "None", or empty string. 0075 */ 0076 void setGroupingCategory( const QString &groupingCategory ); 0077 0078 0079 //! Grouping info functions 0080 /** 0081 * @return true if 'index' is the first item of a Group. 0082 */ 0083 bool isFirstInGroup( const QModelIndex & index ); 0084 0085 /** 0086 * @return true if 'index' is the last item of a Group. 0087 */ 0088 bool isLastInGroup( const QModelIndex & index ); 0089 0090 /** 0091 * @return The first item of the Group that 'index' belongs to. 0092 */ 0093 QModelIndex firstIndexInSameGroup( const QModelIndex & index ); 0094 0095 /** 0096 * @return The last item of the Group that 'index' belongs to. 0097 */ 0098 QModelIndex lastIndexInSameGroup( const QModelIndex & index ); 0099 0100 /** 0101 * @return The number of items in the Group that 'index' belongs to. 0102 */ 0103 int groupRowCount( const QModelIndex & index ); 0104 0105 /** 0106 * @return The play length (in seconds) of the Group that 'index' belongs to. 0107 */ 0108 int groupPlayLength( const QModelIndex & index ); 0109 0110 0111 //! Custom version of functions inherited from QSortFilterProxyModel 0112 QVariant data( const QModelIndex &index, int role ) const override; 0113 0114 //Q_SIGNALS: 0115 // Emits signals inherited from QSortFilterProxy 0116 0117 // Emits signals inherited from Playlist::AbstractModel / ProxyBase 0118 0119 private Q_SLOTS: 0120 /** 0121 * Handlers for the standard QAbstractItemModel signals. 0122 */ 0123 void proxyDataChanged( const QModelIndex& topLeft, const QModelIndex& bottomRight ); 0124 void proxyLayoutChanged(); 0125 void proxyModelReset(); 0126 void proxyRowsInserted( const QModelIndex& parent, int start, int end ); 0127 void proxyRowsRemoved( const QModelIndex& parent, int start, int end ); 0128 0129 private: 0130 /** 0131 * This function determines the "Status within the group" of a model row. 0132 */ 0133 Grouping::GroupMode groupModeForIndex( const QModelIndex & index ); 0134 0135 /** 0136 * This function is used to determine if 2 tracks belong in the same group. 0137 * The track pointers are allowed to be invalid. 0138 * @return true if track should be grouped together, false otherwise 0139 */ 0140 bool shouldBeGrouped( Meta::TrackPtr track1, Meta::TrackPtr track2 ); 0141 0142 /** 0143 * Invalidate any cached assumptions about model rows. 0144 */ 0145 void invalidateGrouping(); 0146 0147 0148 // Variables 0149 QString m_groupingCategory; 0150 int m_groupingCategoryIndex; 0151 0152 QHash<int, Grouping::GroupMode> m_cachedGroupModeForRow; 0153 }; 0154 0155 } // namespace Playlist 0156 0157 #endif