Bitcoin Core  27.99.0
P2P Digital Currency
transactiontablemodel.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_TRANSACTIONTABLEMODEL_H
6 #define BITCOIN_QT_TRANSACTIONTABLEMODEL_H
7 
8 #include <qt/bitcoinunits.h>
9 
10 #include <QAbstractTableModel>
11 #include <QStringList>
12 
13 #include <memory>
14 
15 namespace interfaces {
16 class Handler;
17 }
18 
19 class PlatformStyle;
20 class TransactionRecord;
22 class WalletModel;
23 
26 class TransactionTableModel : public QAbstractTableModel
27 {
28  Q_OBJECT
29 
30 public:
31  explicit TransactionTableModel(const PlatformStyle *platformStyle, WalletModel *parent = nullptr);
33 
34  enum ColumnIndex {
35  Status = 0,
36  Watchonly = 1,
37  Date = 2,
38  Type = 3,
39  ToAddress = 4,
40  Amount = 5
41  };
42 
46  enum RoleIndex {
48  TypeRole = Qt::UserRole,
77  };
78 
79  int rowCount(const QModelIndex &parent) const override;
80  int columnCount(const QModelIndex &parent) const override;
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 private:
88  std::unique_ptr<interfaces::Handler> m_handler_transaction_changed;
89  std::unique_ptr<interfaces::Handler> m_handler_show_progress;
90  QStringList columns;
94 
97 
98  QString lookupAddress(const std::string &address, bool tooltip) const;
99  QVariant addressColor(const TransactionRecord *wtx) const;
100  QString formatTxStatus(const TransactionRecord *wtx) const;
101  QString formatTxDate(const TransactionRecord *wtx) const;
102  QString formatTxType(const TransactionRecord *wtx) const;
103  QString formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const;
104  QString formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed=true, BitcoinUnits::SeparatorStyle separators=BitcoinUnits::SeparatorStyle::STANDARD) const;
105  QString formatTooltip(const TransactionRecord *rec) const;
106  QVariant txStatusDecoration(const TransactionRecord *wtx) const;
107  QVariant txWatchonlyDecoration(const TransactionRecord *wtx) const;
108  QVariant txAddressDecoration(const TransactionRecord *wtx) const;
109 
110 public Q_SLOTS:
111  /* New transaction, or transaction changed status */
112  void updateTransaction(const QString &hash, int status, bool showTransaction);
113  void updateConfirmations();
114  void updateDisplayUnit();
117  /* Needed to update fProcessingQueuedTransactions through a QueuedConnection */
119 
120  friend class TransactionTablePriv;
121 };
122 
123 #endif // BITCOIN_QT_TRANSACTIONTABLEMODEL_H
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.
@ TxPlainTextRole
Whole transaction as plain text.
@ LabelRole
Label of address related to transaction.
@ LongDescriptionRole
Long description (HTML format)
@ TypeRole
Type of transaction.
@ StatusRole
Transaction status (TransactionRecord::Status)
@ DateRole
Date and time this transaction was created.
@ TxHashRole
Transaction hash.
@ TxHexRole
Transaction data, hex-encoded.
@ RawDecorationRole
Unprocessed icon.
@ 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 formatTooltip(const TransactionRecord *rec) const
QString formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed=true, BitcoinUnits::SeparatorStyle separators=BitcoinUnits::SeparatorStyle::STANDARD) const
QVariant data(const QModelIndex &index, int role) const override
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
std::unique_ptr< interfaces::Handler > m_handler_show_progress
TransactionTableModel(const PlatformStyle *platformStyle, WalletModel *parent=nullptr)
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
const PlatformStyle * platformStyle
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 Bitcoin wallet from Qt view code.
Definition: walletmodel.h:48