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