Debian Codegraph @

maz-db/src/MazDBSortProxy.h

raw symbols SCIP
1 /* Copyright (C) 2017 Dan Chapman <[email protected]>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef MAZDBSORTPROXY_H
19 #define MAZDBSORTPROXY_H
20
21 #include <QObject>
22 #include <QAbstractItemModel>
23 #include <QSortFilterProxyModel>
24 #include <QJSValue>
25
26 class MazDBListModel;
27 class MazDBSortProxy : public QSortFilterProxyModel
28 {
29 Q_OBJECT
30 Q_PROPERTY(QAbstractItemModel* model READ sourceModel WRITE setModel NOTIFY modelChanged)
31 Q_PROPERTY(QString sortBy READ sortBy WRITE setSortBy NOTIFY sortByChanged)
32 Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder NOTIFY sortOrderChanged)
33 Q_PROPERTY(QJSValue sortCallBack READ sortCallBack WRITE setSortCallBack NOTIFY sortCallBackChanged)
34
35 public:
36 explicit MazDBSortProxy(QObject *parent = 0);
37 virtual QHash<int, QByteArray> roleNames() const override;
38
39 QString sortBy() const;
40
41 QJSValue sortCallBack() const;
42
43 signals:
44 void modelChanged();
45 void sortByChanged(QString sortBy);
46 void sortOrderChanged();
47
48 void sortCallBackChanged(QJSValue sortCallBack);
49
50 public slots:
51 void setModel(QAbstractItemModel* model);
52 void setSortBy(QString sortBy);
53 void setSortOrder(Qt::SortOrder order);
54 void setSortCallBack(QJSValue sortCallBack);
55
56 protected:
57 virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
58
59 private:
60 void reload();
61 int roleFromName(const QString &role) const;
62 QString m_sortBy;
63 Qt::SortOrder m_sortOrder;
64 QJSValue m_sortCallBack;
65 };
66
67 #endif // MAZDBSORTPROXY_H