File indexing completed on 2024-05-05 04:47:28

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  * Copyright (c) 2008 Seb Ruiz <ruiz@kde.org>                                           *
0004  * Copyright (c) 2013 Ralf Engels <ralf-engels@gmx.de>                                  *
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 COLLECTIONSORTFILTERPROXYMODEL_H
0020 #define COLLECTIONSORTFILTERPROXYMODEL_H
0021 
0022 #include "core/meta/forward_declarations.h"
0023 
0024 #include <QSortFilterProxyModel>
0025 
0026 class CollectionTreeItem;
0027 class QCollator;
0028 
0029 /**
0030     This is a custom QSortFilterProxyModel that gives special sort orders for
0031     our meta objects.
0032     e.g. it sorts tracks by disc number and track number.
0033 
0034     @author Nikolaj Hald Nielsen <nhn@kde.org>
0035 */
0036 class CollectionSortFilterProxyModel : public QSortFilterProxyModel
0037 {
0038     public:
0039         explicit CollectionSortFilterProxyModel( QObject *parent = nullptr );
0040 
0041         ~CollectionSortFilterProxyModel() override;
0042 
0043         bool hasChildren(const QModelIndex &parent) const override;
0044 
0045     protected:
0046         bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
0047         bool filterAcceptsRow( int source_row, const QModelIndex & source_parent ) const override;
0048 
0049     private:
0050         QCollator *m_col;
0051 
0052         CollectionTreeItem* treeItem( const QModelIndex &index ) const;
0053         bool lessThanTrack( const QModelIndex &left, const QModelIndex &right ) const;
0054         bool lessThanAlbum( const QModelIndex &left, const QModelIndex &right ) const;
0055         bool lessThanItem( const QModelIndex &left, const QModelIndex &right ) const;
0056 };
0057 
0058 #endif