tpasswordfiltermodel.h - sailfish-safe - Sailfish frontend for safe(1)
HTML git clone git://git.z3bra.org/sailfish-safe.git
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
tpasswordfiltermodel.h (1889B)
---
1 /*
2 * Copyright (C) 2018 Daniel Vrátil <dvratil@kde.org>
3 * 2021 Willy Goiffon <contact@z3bra.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License as
7 * published by the Free Software Foundation; either version 2, or
8 * (at your option) any later version.
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 Library General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21 #ifndef PASSWORDFILTERMODEL_H_
22 #define PASSWORDFILTERMODEL_H_
23
24 #include <QSortFilterProxyModel>
25 #include <QVector>
26
27 class QStringRef;
28 class KDescendantsProxyModel;
29
30 class PasswordFilterModel : public QSortFilterProxyModel
31 {
32 Q_OBJECT
33
34 Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
35 public:
36 explicit PasswordFilterModel(QObject *parent = nullptr);
37
38 void setSourceModel(QAbstractItemModel *sourceModel) override;
39
40 QString filter() const;
41 void setFilter(const QString &filter);
42
43 QVariant data(const QModelIndex &index, int role) const override;
44
45 Q_SIGNALS:
46 void filterChanged();
47
48 protected:
49 bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
50 bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
51
52 private:
53 KDescendantsProxyModel *mFlatModel = nullptr;
54 QString mFilter;
55 QVector<QStringRef> mParts;
56 mutable QHash<QModelIndex, int> mSortingLookup;
57 };
58
59 #endif