Bitcoin Core  21.99.0
P2P Digital Currency
recentrequeststablemodel.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2020 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 
9 
10 #include <QAbstractTableModel>
11 #include <QStringList>
12 #include <QDateTime>
13 
14 class WalletModel;
15 
17 {
18 public:
20 
21  static const int CURRENT_VERSION = 1;
22  int nVersion;
23  int64_t id;
24  QDateTime date;
26 
28  unsigned int date_timet;
29  SER_WRITE(obj, date_timet = obj.date.toTime_t());
30  READWRITE(obj.nVersion, obj.id, date_timet, obj.recipient);
31  SER_READ(obj, obj.date = QDateTime::fromTime_t(date_timet));
32  }
33 };
34 
36 {
37 public:
38  RecentRequestEntryLessThan(int nColumn, Qt::SortOrder fOrder):
39  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 
50 class RecentRequestsTableModel: public QAbstractTableModel
51 {
52  Q_OBJECT
53 
54 public:
55  explicit RecentRequestsTableModel(WalletModel *parent);
57 
58  enum ColumnIndex {
59  Date = 0,
60  Label = 1,
61  Message = 2,
62  Amount = 3,
64  };
65 
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;
79  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:
89  QStringList columns;
90  QList<RecentRequestEntry> list;
92 
96  QString getAmountTitle();
97 };
98 
99 #endif // BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H
RecentRequestsTableModel::list
QList< RecentRequestEntry > list
Definition: recentrequeststablemodel.h:90
RecentRequestEntry::recipient
SendCoinsRecipient recipient
Definition: recentrequeststablemodel.h:25
RecentRequestEntryLessThan
Definition: recentrequeststablemodel.h:35
count
static int count
Definition: tests.c:35
RecentRequestEntry::date
QDateTime date
Definition: recentrequeststablemodel.h:24
WalletModel
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
RecentRequestsTableModel::Amount
@ Amount
Definition: recentrequeststablemodel.h:62
RecentRequestsTableModel::entry
const RecentRequestEntry & entry(int row) const
Definition: recentrequeststablemodel.h:79
RecentRequestsTableModel::columnCount
int columnCount(const QModelIndex &parent) const override
Definition: recentrequeststablemodel.cpp:45
RecentRequestEntry::SERIALIZE_METHODS
SERIALIZE_METHODS(RecentRequestEntry, obj)
Definition: recentrequeststablemodel.h:27
RecentRequestsTableModel::rowCount
int rowCount(const QModelIndex &parent) const override
Definition: recentrequeststablemodel.cpp:37
RecentRequestsTableModel::updateAmountColumnTitle
void updateAmountColumnTitle()
Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table hea...
Definition: recentrequeststablemodel.cpp:118
RecentRequestsTableModel::walletModel
WalletModel * walletModel
Definition: recentrequeststablemodel.h:88
RecentRequestsTableModel::updateDisplayUnit
void updateDisplayUnit()
Definition: recentrequeststablemodel.cpp:213
RecentRequestsTableModel::columns
QStringList columns
Definition: recentrequeststablemodel.h:89
RecentRequestsTableModel::removeRows
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Definition: recentrequeststablemodel.cpp:137
SendCoinsRecipient
Definition: sendcoinsrecipient.h:19
RecentRequestEntry::CURRENT_VERSION
static const int CURRENT_VERSION
Definition: recentrequeststablemodel.h:21
RecentRequestEntryLessThan::RecentRequestEntryLessThan
RecentRequestEntryLessThan(int nColumn, Qt::SortOrder fOrder)
Definition: recentrequeststablemodel.h:38
RecentRequestsTableModel::RecentRequestsTableModel
RecentRequestsTableModel(WalletModel *parent)
Definition: recentrequeststablemodel.cpp:17
RecentRequestsTableModel::getAmountTitle
QString getAmountTitle()
Gets title for amount column including current display unit if optionsModel reference available.
Definition: recentrequeststablemodel.cpp:125
RecentRequestsTableModel
Model for list of recently generated payment requests / bitcoin: URIs.
Definition: recentrequeststablemodel.h:50
RecentRequestEntry::nVersion
int nVersion
Definition: recentrequeststablemodel.h:22
RecentRequestsTableModel::NUMBER_OF_COLUMNS
@ NUMBER_OF_COLUMNS
Definition: recentrequeststablemodel.h:63
RecentRequestsTableModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Definition: recentrequeststablemodel.cpp:100
RecentRequestEntryLessThan::order
Qt::SortOrder order
Definition: recentrequeststablemodel.h:44
RecentRequestsTableModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: recentrequeststablemodel.cpp:159
READWRITE
#define READWRITE(...)
Definition: serialize.h:175
RecentRequestsTableModel::addNewRequest
void addNewRequest(const SendCoinsRecipient &recipient)
Definition: recentrequeststablemodel.cpp:165
RecentRequestsTableModel::nReceiveRequestsMaxId
int64_t nReceiveRequestsMaxId
Definition: recentrequeststablemodel.h:91
RecentRequestsTableModel::ColumnIndex
ColumnIndex
Definition: recentrequeststablemodel.h:58
RecentRequestsTableModel::~RecentRequestsTableModel
~RecentRequestsTableModel()
Definition: recentrequeststablemodel.cpp:32
RecentRequestsTableModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition: recentrequeststablemodel.cpp:130
RecentRequestsTableModel::Date
@ Date
Definition: recentrequeststablemodel.h:59
RecentRequestEntry::id
int64_t id
Definition: recentrequeststablemodel.h:23
RecentRequestsTableModel::Label
@ Label
Definition: recentrequeststablemodel.h:60
RecentRequestEntryLessThan::operator()
bool operator()(const RecentRequestEntry &left, const RecentRequestEntry &right) const
Definition: recentrequeststablemodel.cpp:218
RecentRequestsTableModel::sort
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder) override
Definition: recentrequeststablemodel.cpp:207
RecentRequestsTableModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: recentrequeststablemodel.cpp:53
RecentRequestsTableModel::Message
@ Message
Definition: recentrequeststablemodel.h:61
SER_WRITE
#define SER_WRITE(obj, code)
Definition: serialize.h:178
RecentRequestEntry::RecentRequestEntry
RecentRequestEntry()
Definition: recentrequeststablemodel.h:19
SER_READ
#define SER_READ(obj, code)
Definition: serialize.h:177
RecentRequestsTableModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Definition: recentrequeststablemodel.cpp:105
RecentRequestEntryLessThan::column
int column
Definition: recentrequeststablemodel.h:43
sendcoinsrecipient.h
RecentRequestEntry
Definition: recentrequeststablemodel.h:16