]>
Commit | Line | Data |
---|---|---|
57702541 | 1 | // Copyright (c) 2011-2014 The Bitcoin developers |
666893b1 WL |
2 | // Distributed under the MIT/X11 software license, see the accompanying |
3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | |
4 | ||
5 | #ifndef RECENTREQUESTSTABLEMODEL_H | |
6 | #define RECENTREQUESTSTABLEMODEL_H | |
7 | ||
7df07b3f PK |
8 | #include "walletmodel.h" |
9 | ||
666893b1 WL |
10 | #include <QAbstractTableModel> |
11 | #include <QStringList> | |
12 | #include <QDateTime> | |
13 | ||
666893b1 WL |
14 | class CWallet; |
15 | ||
8476d5d4 | 16 | class RecentRequestEntry |
666893b1 | 17 | { |
8476d5d4 CL |
18 | public: |
19 | RecentRequestEntry() : nVersion(RecentRequestEntry::CURRENT_VERSION), id(0) { } | |
20 | ||
4bee715b | 21 | static const int CURRENT_VERSION = 1; |
8476d5d4 CL |
22 | int nVersion; |
23 | int64_t id; | |
666893b1 WL |
24 | QDateTime date; |
25 | SendCoinsRecipient recipient; | |
8476d5d4 CL |
26 | |
27 | IMPLEMENT_SERIALIZE | |
8476d5d4 | 28 | |
3d796f89 KD |
29 | template <typename T, typename Stream, typename Operation> |
30 | inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { | |
31 | size_t nSerSize = 0; | |
32 | bool fRead = boost::is_same<Operation, CSerActionUnserialize>(); | |
33 | ||
34 | RecentRequestEntry* pthis = const_cast<RecentRequestEntry*>(thisPtr); | |
35 | ||
36 | unsigned int nDate = thisPtr->date.toTime_t(); | |
8476d5d4 CL |
37 | |
38 | READWRITE(pthis->nVersion); | |
39 | nVersion = pthis->nVersion; | |
3d796f89 | 40 | READWRITE(thisPtr->id); |
8476d5d4 | 41 | READWRITE(nDate); |
3d796f89 | 42 | READWRITE(thisPtr->recipient); |
8476d5d4 CL |
43 | |
44 | if (fRead) | |
45 | pthis->date = QDateTime::fromTime_t(nDate); | |
3d796f89 KD |
46 | |
47 | return nSerSize; | |
48 | } | |
666893b1 WL |
49 | }; |
50 | ||
4d901023 CL |
51 | class RecentRequestEntryLessThan |
52 | { | |
53 | public: | |
54 | RecentRequestEntryLessThan(int nColumn, Qt::SortOrder fOrder): | |
55 | column(nColumn), order(fOrder) {} | |
4bee715b | 56 | bool operator()(RecentRequestEntry &left, RecentRequestEntry &right) const; |
4d901023 CL |
57 | |
58 | private: | |
59 | int column; | |
60 | Qt::SortOrder order; | |
61 | }; | |
62 | ||
d7aa1ec8 | 63 | /** Model for list of recently generated payment requests / bitcoin: URIs. |
666893b1 WL |
64 | * Part of wallet model. |
65 | */ | |
66 | class RecentRequestsTableModel: public QAbstractTableModel | |
67 | { | |
68 | Q_OBJECT | |
69 | ||
70 | public: | |
7df07b3f | 71 | explicit RecentRequestsTableModel(CWallet *wallet, WalletModel *parent); |
666893b1 WL |
72 | ~RecentRequestsTableModel(); |
73 | ||
74 | enum ColumnIndex { | |
75 | Date = 0, | |
76 | Label = 1, | |
77 | Message = 2, | |
4d901023 CL |
78 | Amount = 3, |
79 | NUMBER_OF_COLUMNS | |
666893b1 WL |
80 | }; |
81 | ||
82 | /** @name Methods overridden from QAbstractTableModel | |
83 | @{*/ | |
84 | int rowCount(const QModelIndex &parent) const; | |
85 | int columnCount(const QModelIndex &parent) const; | |
86 | QVariant data(const QModelIndex &index, int role) const; | |
87 | bool setData(const QModelIndex &index, const QVariant &value, int role); | |
88 | QVariant headerData(int section, Qt::Orientation orientation, int role) const; | |
89 | QModelIndex index(int row, int column, const QModelIndex &parent) const; | |
90 | bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); | |
91 | Qt::ItemFlags flags(const QModelIndex &index) const; | |
92 | /*@}*/ | |
93 | ||
94 | const RecentRequestEntry &entry(int row) const { return list[row]; } | |
95 | void addNewRequest(const SendCoinsRecipient &recipient); | |
8476d5d4 CL |
96 | void addNewRequest(const std::string &recipient); |
97 | void addNewRequest(RecentRequestEntry &recipient); | |
666893b1 | 98 | |
4d901023 CL |
99 | public slots: |
100 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); | |
8969828d | 101 | void updateDisplayUnit(); |
4d901023 | 102 | |
666893b1 WL |
103 | private: |
104 | WalletModel *walletModel; | |
105 | QStringList columns; | |
106 | QList<RecentRequestEntry> list; | |
8476d5d4 | 107 | int64_t nReceiveRequestsMaxId; |
8969828d | 108 | |
109 | /** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */ | |
110 | void updateAmountColumnTitle(); | |
111 | /** Gets title for amount column including current display unit if optionsModel reference available. */ | |
112 | QString getAmountTitle(); | |
666893b1 WL |
113 | }; |
114 | ||
115 | #endif |