1 // Copyright (c) 2011-2016 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.
5 #ifndef BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H
6 #define BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H
8 #include "walletmodel.h"
10 #include <QAbstractTableModel>
11 #include <QStringList>
16 class RecentRequestEntry
19 RecentRequestEntry() : nVersion(RecentRequestEntry::CURRENT_VERSION
), id(0) { }
21 static const int CURRENT_VERSION
= 1;
25 SendCoinsRecipient recipient
;
27 ADD_SERIALIZE_METHODS
;
29 template <typename Stream
, typename Operation
>
30 inline void SerializationOp(Stream
& s
, Operation ser_action
) {
31 unsigned int nDate
= date
.toTime_t();
33 READWRITE(this->nVersion
);
38 if (ser_action
.ForRead())
39 date
= QDateTime::fromTime_t(nDate
);
43 class RecentRequestEntryLessThan
46 RecentRequestEntryLessThan(int nColumn
, Qt::SortOrder fOrder
):
47 column(nColumn
), order(fOrder
) {}
48 bool operator()(RecentRequestEntry
&left
, RecentRequestEntry
&right
) const;
55 /** Model for list of recently generated payment requests / bitcoin: URIs.
56 * Part of wallet model.
58 class RecentRequestsTableModel
: public QAbstractTableModel
63 explicit RecentRequestsTableModel(CWallet
*wallet
, WalletModel
*parent
);
64 ~RecentRequestsTableModel();
74 /** @name Methods overridden from QAbstractTableModel
76 int rowCount(const QModelIndex
&parent
) const;
77 int columnCount(const QModelIndex
&parent
) const;
78 QVariant
data(const QModelIndex
&index
, int role
) const;
79 bool setData(const QModelIndex
&index
, const QVariant
&value
, int role
);
80 QVariant
headerData(int section
, Qt::Orientation orientation
, int role
) const;
81 QModelIndex
index(int row
, int column
, const QModelIndex
&parent
) const;
82 bool removeRows(int row
, int count
, const QModelIndex
&parent
= QModelIndex());
83 Qt::ItemFlags
flags(const QModelIndex
&index
) const;
86 const RecentRequestEntry
&entry(int row
) const { return list
[row
]; }
87 void addNewRequest(const SendCoinsRecipient
&recipient
);
88 void addNewRequest(const std::string
&recipient
);
89 void addNewRequest(RecentRequestEntry
&recipient
);
92 void sort(int column
, Qt::SortOrder order
= Qt::AscendingOrder
);
93 void updateDisplayUnit();
96 WalletModel
*walletModel
;
98 QList
<RecentRequestEntry
> list
;
99 int64_t nReceiveRequestsMaxId
;
101 /** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
102 void updateAmountColumnTitle();
103 /** Gets title for amount column including current display unit if optionsModel reference available. */
104 QString
getAmountTitle();
107 #endif // BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H