Line data Source code
1 : // Copyright (c) 2011-2019 The Bitcoin Core 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 BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H 6 : #define BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H 7 : 8 : #include <qt/sendcoinsrecipient.h> 9 : 10 : #include <QAbstractTableModel> 11 : #include <QStringList> 12 : #include <QDateTime> 13 : 14 : class WalletModel; 15 : 16 0 : class RecentRequestEntry 17 : { 18 : public: 19 0 : RecentRequestEntry() : nVersion(RecentRequestEntry::CURRENT_VERSION), id(0) { } 20 : 21 : static const int CURRENT_VERSION = 1; 22 : int nVersion; 23 : int64_t id; 24 : QDateTime date; 25 : SendCoinsRecipient recipient; 26 : 27 0 : SERIALIZE_METHODS(RecentRequestEntry, obj) { 28 0 : unsigned int date_timet; 29 0 : SER_WRITE(obj, date_timet = obj.date.toTime_t()); 30 0 : READWRITE(obj.nVersion, obj.id, date_timet, obj.recipient); 31 0 : SER_READ(obj, obj.date = QDateTime::fromTime_t(date_timet)); 32 0 : } 33 : }; 34 : 35 : class RecentRequestEntryLessThan 36 : { 37 : public: 38 0 : RecentRequestEntryLessThan(int nColumn, Qt::SortOrder fOrder): 39 0 : column(nColumn), order(fOrder) {} 40 : bool operator()(const RecentRequestEntry& left, const RecentRequestEntry& right) const; 41 : 42 : private: 43 : int column; 44 : Qt::SortOrder order; 45 : }; 46 : 47 : /** Model for list of recently generated payment requests / bitcoin: URIs. 48 : * Part of wallet model. 49 : */ 50 : class RecentRequestsTableModel: public QAbstractTableModel 51 : { 52 0 : Q_OBJECT 53 : 54 : public: 55 : explicit RecentRequestsTableModel(WalletModel *parent); 56 : ~RecentRequestsTableModel(); 57 : 58 : enum ColumnIndex { 59 : Date = 0, 60 : Label = 1, 61 : Message = 2, 62 : Amount = 3, 63 : NUMBER_OF_COLUMNS 64 : }; 65 : 66 : /** @name Methods overridden from QAbstractTableModel 67 : @{*/ 68 : int rowCount(const QModelIndex &parent) const override; 69 : int columnCount(const QModelIndex &parent) const override; 70 : QVariant data(const QModelIndex &index, int role) const override; 71 : bool setData(const QModelIndex &index, const QVariant &value, int role) override; 72 : QVariant headerData(int section, Qt::Orientation orientation, int role) const override; 73 : QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 74 : bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; 75 : Qt::ItemFlags flags(const QModelIndex &index) const override; 76 : void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; 77 : /*@}*/ 78 : 79 0 : const RecentRequestEntry &entry(int row) const { return list[row]; } 80 : void addNewRequest(const SendCoinsRecipient &recipient); 81 : void addNewRequest(const std::string &recipient); 82 : void addNewRequest(RecentRequestEntry &recipient); 83 : 84 : public Q_SLOTS: 85 : void updateDisplayUnit(); 86 : 87 : private: 88 : WalletModel *walletModel; 89 : QStringList columns; 90 : QList<RecentRequestEntry> list; 91 : int64_t nReceiveRequestsMaxId{0}; 92 : 93 : /** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */ 94 : void updateAmountColumnTitle(); 95 : /** Gets title for amount column including current display unit if optionsModel reference available. */ 96 : QString getAmountTitle(); 97 : }; 98 : 99 : #endif // BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H