transactionfilterproxy.h raw
1 // Copyright (c) 2011-2021 The Limenka developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5 #ifndef LIMENKA_QT_TRANSACTIONFILTERPROXY_H
6 #define LIMENKA_QT_TRANSACTIONFILTERPROXY_H
7
8 #include <consensus/amount.h>
9
10 #include <QDateTime>
11 #include <QSortFilterProxyModel>
12
13 #include <optional>
14
15 /** Filter the transaction list according to pre-specified rules. */
16 class TransactionFilterProxy : public QSortFilterProxyModel
17 {
18 Q_OBJECT
19
20 public:
21 explicit TransactionFilterProxy(QObject *parent = nullptr);
22
23 /** Type filter bit field (all types) */
24 static const quint32 ALL_TYPES = 0xFFFFFFFF;
25
26 static quint32 TYPE(int type) { return 1<<type; }
27
28 enum WatchOnlyFilter
29 {
30 WatchOnlyFilter_All,
31 WatchOnlyFilter_Yes,
32 WatchOnlyFilter_No
33 };
34
35 /** Filter transactions between date range. Use std::nullopt for open range. */
36 void setDateRange(const std::optional<QDateTime>& from, const std::optional<QDateTime>& to);
37 void setSearchString(const QString &);
38 /**
39 @note Type filter takes a bit field created with TYPE() or ALL_TYPES
40 */
41 void setTypeFilter(quint32 modes);
42 void setMinAmount(const CAmount& minimum);
43 void setWatchOnlyFilter(WatchOnlyFilter filter);
44
45 /** Set whether to show conflicted transactions. */
46 void setShowInactive(bool showInactive);
47
48 protected:
49 bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override;
50
51 private:
52 std::optional<QDateTime> dateFrom;
53 std::optional<QDateTime> dateTo;
54 QString m_search_string;
55 quint32 typeFilter;
56 WatchOnlyFilter watchOnlyFilter{WatchOnlyFilter_All};
57 CAmount minAmount{0};
58 bool showInactive{true};
59 };
60
61 #endif // LIMENKA_QT_TRANSACTIONFILTERPROXY_H
62