PIVX Core  5.6.99
P2P Digital Currency
transactiontablemodel.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2013 The Bitcoin developers
2 // Copyright (c) 2019-2021 The PIVX Core developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef PIVX_QT_TRANSACTIONTABLEMODEL_H
7 #define PIVX_QT_TRANSACTIONTABLEMODEL_H
8 
9 #include "bitcoinunits.h"
10 
11 #include <QAbstractTableModel>
12 #include <QStringList>
13 
14 #include <memory>
15 
16 namespace interfaces {
17  class Handler;
18 }
19 
20 class TransactionRecord;
22 class WalletModel;
23 
24 class CWallet;
25 
28 class TransactionTableModel : public QAbstractTableModel
29 {
30  Q_OBJECT
31 
32 public:
33  explicit TransactionTableModel(CWallet* wallet, WalletModel* parent = nullptr);
34  ~TransactionTableModel() override;
35  void init();
36 
37  enum ColumnIndex {
38  Status = 0,
39  Watchonly = 1,
40  Date = 2,
41  Type = 3,
42  ToAddress = 4,
43  Amount = 5
44  };
45 
49  enum RoleIndex {
51  TypeRole = Qt::UserRole,
75  SizeRole
76  };
77 
78  int rowCount(const QModelIndex& parent) const override;
79  int columnCount(const QModelIndex& parent) const override;
80  int size() const;
81  QVariant data(const QModelIndex& index, int role) const override;
82  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
83  QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
85 
86 Q_SIGNALS:
87  // Emitted only during startup when records gets parsed
88  void txLoaded(const QString& hash, const int txType, const int txStatus);
89  // Emitted when a transaction that belongs to this wallet gets connected to the chain and/or committed locally.
90  void txArrived(const QString& hash, const bool isCoinStake, const bool isMNReward, const bool isCSAnyType);
91 
92 private:
93  // Listeners
94  std::unique_ptr<interfaces::Handler> m_handler_transaction_changed;
95  std::unique_ptr<interfaces::Handler> m_handler_show_progress;
96 
97  CWallet* wallet{nullptr};
99  QStringList columns{};
102 
103  void subscribeToCoreSignals();
105 
106  QString lookupAddress(const std::string& address, bool tooltip) const;
107  QVariant addressColor(const TransactionRecord* wtx) const;
108  QString formatTxStatus(const TransactionRecord* wtx) const;
109  QString formatTxDate(const TransactionRecord* wtx) const;
110  QString formatTxType(const TransactionRecord* wtx) const;
111  QString formatTxToAddress(const TransactionRecord* wtx, bool tooltip) const;
112  QString formatTxAmount(const TransactionRecord* wtx, bool showUnconfirmed = true, BitcoinUnits::SeparatorStyle separators = BitcoinUnits::separatorStandard) const;
113  QString formatTooltip(const TransactionRecord* rec) const;
114  QVariant txStatusDecoration(const TransactionRecord* wtx) const;
115  QVariant txWatchonlyDecoration(const TransactionRecord* wtx) const;
116  QVariant txAddressDecoration(const TransactionRecord* wtx) const;
117 
118 public Q_SLOTS:
119  /* New transaction, or transaction changed status */
120  void updateTransaction(const QString& hash, int status, bool showTransaction);
121  void updateConfirmations();
122  void updateDisplayUnit();
125  /* Needed to update fProcessingQueuedTransactions through a QueuedConnection */
127 
128  friend class TransactionTablePriv;
129 };
130 
131 #endif // PIVX_QT_TRANSACTIONTABLEMODEL_H
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
Definition: wallet.h:577
UI model for a transaction.
UI model for the transaction table of a wallet.
QVariant txStatusDecoration(const TransactionRecord *wtx) const
TransactionTablePriv * priv
QVariant addressColor(const TransactionRecord *wtx) const
RoleIndex
Roles to get specific information from a transaction row.
@ SizeRole
Transaction size in bytes.
@ LabelRole
Label of address related to transaction.
@ TypeRole
Type of transaction.
@ StatusRole
Transaction status (TransactionRecord::Status)
@ DateRole
Date and time this transaction was created.
@ TxHashRole
Transaction hash.
@ ShieldedCreditAmountRole
Credit amount of transaction.
@ AddressRole
Address of transaction.
@ WatchonlyDecorationRole
Watch-only icon.
@ WatchonlyRole
Watch-only boolean.
@ AmountRole
Net amount of transaction.
@ ConfirmedRole
Is transaction confirmed?
@ FormattedAmountRole
Formatted amount, without brackets when unconfirmed.
QString formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed=true, BitcoinUnits::SeparatorStyle separators=BitcoinUnits::separatorStandard) const
QString formatTooltip(const TransactionRecord *rec) const
QVariant data(const QModelIndex &index, int role) const override
void txArrived(const QString &hash, const bool isCoinStake, const bool isMNReward, const bool isCSAnyType)
bool processingQueuedTransactions() const
QVariant txWatchonlyDecoration(const TransactionRecord *wtx) const
void updateTransaction(const QString &hash, int status, bool showTransaction)
QString formatTxStatus(const TransactionRecord *wtx) const
void setProcessingQueuedTransactions(bool value)
std::unique_ptr< interfaces::Handler > m_handler_transaction_changed
int columnCount(const QModelIndex &parent) const override
void txLoaded(const QString &hash, const int txType, const int txStatus)
TransactionTableModel(CWallet *wallet, WalletModel *parent=nullptr)
std::unique_ptr< interfaces::Handler > m_handler_show_progress
int rowCount(const QModelIndex &parent) const override
void updateAmountColumnTitle()
Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table hea...
QString formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QString formatTxType(const TransactionRecord *wtx) const
QString lookupAddress(const std::string &address, bool tooltip) const
QVariant txAddressDecoration(const TransactionRecord *wtx) const
QString formatTxDate(const TransactionRecord *wtx) const
Interface to PIVX wallet from Qt view code.
Definition: walletmodel.h:109