1 /***************************************************************************
2 **                                                                        **
3 **  Polyphone, a soundfont editor                                         **
4 **  Copyright (C) 2013-2020 Davy Triponney                                **
5 **                                                                        **
6 **  This program is free software: you can redistribute it and/or modify  **
7 **  it under the terms of the GNU General Public License as published by  **
8 **  the Free Software Foundation, either version 3 of the License, or     **
9 **  (at your option) any later version.                                   **
10 **                                                                        **
11 **  This program is distributed in the hope that it will be useful,       **
12 **  but WITHOUT ANY WARRANTY; without even the implied warranty of        **
13 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          **
14 **  GNU General Public License for more details.                          **
15 **                                                                        **
16 **  You should have received a copy of the GNU General Public License     **
17 **  along with this program. If not, see http://www.gnu.org/licenses/.    **
18 **                                                                        **
19 ****************************************************************************
20 **           Author: Davy Triponney                                       **
21 **  Website/Contact: https://www.polyphone-soundfonts.com                 **
22 **             Date: 01.01.2013                                           **
23 ***************************************************************************/
24 
25 #ifndef TREESORTFILTERPROXY_H
26 #define TREESORTFILTERPROXY_H
27 
28 #include <QSortFilterProxyModel>
29 #include "basetypes.h"
30 class TreeView;
31 class SoundfontManager;
32 
33 class TreeSortFilterProxy : public QSortFilterProxyModel
34 {
35     Q_OBJECT
36 
37 public:
38     TreeSortFilterProxy(int indexSf2, TreeView * treeView, QAbstractItemModel * model);
39     bool isFiltered(EltID id);
40 
41 public slots:
42     void filterChanged(QString filter);
43 
44 protected:
45     bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
46     bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
47 
48 private slots:
49     void divisionSortChanged();
50 
51 private:
52     void findMatches(int idSf2, QString filter);
53     bool lessThan(QString left, QString right) const;
54 
55     int _indexSf2;
56     TreeView * _treeView;
57     QList<int> _matchingSamples;
58     QList<int> _matchingInstruments;
59     QList<int> _matchingPresets;
60     int _bestMatchSample, _bestMatchInstrument, _bestMatchPreset;
61     QString _bestMatchSampleName, _bestMatchInstrumentName, _bestMatchPresetName;
62     SoundfontManager * _sm;
63     int _sortType;
64 };
65 
66 #endif // TREESORTFILTERPROXY_H
67