dash/src/qt/transactiontablemodel.h

125 lines
4.5 KiB
C
Raw Normal View History

// Copyright (c) 2011-2015 The Bitcoin Core developers
2014-12-13 05:09:33 +01:00
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2014-11-03 16:16:40 +01:00
#ifndef BITCOIN_QT_TRANSACTIONTABLEMODEL_H
#define BITCOIN_QT_TRANSACTIONTABLEMODEL_H
2011-05-08 16:30:10 +02:00
Backport 11651 (#3358) * scripted-diff: Replace #include "" with #include <> (ryanofsky) -BEGIN VERIFY SCRIPT- for f in \ src/*.cpp \ src/*.h \ src/bench/*.cpp \ src/bench/*.h \ src/compat/*.cpp \ src/compat/*.h \ src/consensus/*.cpp \ src/consensus/*.h \ src/crypto/*.cpp \ src/crypto/*.h \ src/crypto/ctaes/*.h \ src/policy/*.cpp \ src/policy/*.h \ src/primitives/*.cpp \ src/primitives/*.h \ src/qt/*.cpp \ src/qt/*.h \ src/qt/test/*.cpp \ src/qt/test/*.h \ src/rpc/*.cpp \ src/rpc/*.h \ src/script/*.cpp \ src/script/*.h \ src/support/*.cpp \ src/support/*.h \ src/support/allocators/*.h \ src/test/*.cpp \ src/test/*.h \ src/wallet/*.cpp \ src/wallet/*.h \ src/wallet/test/*.cpp \ src/wallet/test/*.h \ src/zmq/*.cpp \ src/zmq/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT- Signed-off-by: Pasta <pasta@dashboost.org> * scripted-diff: Replace #include "" with #include <> (Dash Specific) -BEGIN VERIFY SCRIPT- for f in \ src/bls/*.cpp \ src/bls/*.h \ src/evo/*.cpp \ src/evo/*.h \ src/governance/*.cpp \ src/governance/*.h \ src/llmq/*.cpp \ src/llmq/*.h \ src/masternode/*.cpp \ src/masternode/*.h \ src/privatesend/*.cpp \ src/privatesend/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT- Signed-off-by: Pasta <pasta@dashboost.org> * build: Remove -I for everything but project root Remove -I from build system for everything but the project root, and built-in dependencies. Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/Makefile.test.include * qt: refactor: Use absolute include paths in .ui files * qt: refactor: Changes to make include paths absolute This makes all include paths in the GUI absolute. Many changes are involved as every single source file in src/qt/ assumes to be able to use relative includes. Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/qt/dash.cpp # src/qt/optionsmodel.cpp # src/qt/test/rpcnestedtests.cpp * test: refactor: Use absolute include paths for test data files * Recommend #include<> syntax in developer notes * refactor: Include obj/build.h instead of build.h * END BACKPORT #11651 Remove trailing whitespace causing travis failure * fix backport 11651 Signed-off-by: Pasta <pasta@dashboost.org> * More of 11651 * fix blockchain.cpp Signed-off-by: pasta <pasta@dashboost.org> * Add missing "qt/" in includes * Add missing "test/" in includes * Fix trailing whitespaces Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com> Co-authored-by: Russell Yanofsky <russ@yanofsky.org> Co-authored-by: MeshCollider <dobsonsa68@gmail.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2020-03-19 23:46:56 +01:00
#include <qt/bitcoinunits.h>
2014-07-25 17:43:41 +02:00
2011-05-08 16:30:10 +02:00
#include <QAbstractTableModel>
#include <QStringList>
2011-05-27 08:20:23 +02:00
class TransactionRecord;
class TransactionTablePriv;
class WalletModel;
2011-05-27 08:20:23 +02:00
class CWallet;
2011-11-13 13:19:52 +01:00
/** UI model for the transaction table of a wallet.
*/
2011-05-08 16:30:10 +02:00
class TransactionTableModel : public QAbstractTableModel
{
Q_OBJECT
2011-05-08 16:30:10 +02:00
public:
explicit TransactionTableModel(CWallet* wallet, WalletModel* parent = 0);
2011-05-27 08:20:23 +02:00
~TransactionTableModel();
2011-05-08 22:23:31 +02:00
2011-11-13 13:19:52 +01:00
enum ColumnIndex {
2011-05-08 22:23:31 +02:00
Status = 0,
Watchonly = 1,
Date = 2,
Type = 3,
ToAddress = 4,
Amount = 5
2011-11-13 13:19:52 +01:00
};
2011-05-08 16:30:10 +02:00
2011-11-13 13:19:52 +01:00
/** Roles to get specific information from a transaction row.
These are independent of column.
*/
enum RoleIndex {
/** Type of transaction */
TypeRole = Qt::UserRole,
2011-11-13 13:19:52 +01:00
/** Date and time this transaction was created */
DateRole,
Fix largest part of GUI lockups with large wallets (#3155) * [Qt] make sure transaction table entry gets updated after bump * Remove unnecessary tracking of IS lock count * Track lockedByChainLocks in TransactionRecord * Only update record when the TX was not ChainLocked before * Emit dataChanged for CT_UPDATED transactions * Use plain seconds since epoch comparison in TransactionFilterProxy::filterAcceptsRow The QDateTime::operator< calls inside TransactionFilterProxy::filterAcceptsRow turned out to be the slowest part in the UI when many TXs are inside the wallet. DateRoleInt allows us to request the plain seconds since epoch which we then use to compare against dateFrom/dateTo, which are also both stored as seconds since epoch now. * Don't invoke updateConfirmations directly and let pollBalanceChanged handle it * Implement AddressTableModel::labelForDestination This one avoids converting from string to CBitcoinAddress and calling .Get() on the result. * Also store CBitcoinAddress object and CTxDestination in TransactionRecord This avoids frequent and slow conversion * Use labelForDestination when possible This avoids unnecessary conversions * Don't set fForceCheckBalanceChanged to true when IS lock is received We already do this through updateTransaction(), which is also called when an IS lock is received for one of our own TXs. * Only update lockedByChainLocks and lockedByInstantSend when a change is possible lockedByChainLocks can never get back to false, so no need to re-check it. Same with lockedByInstantSend, except when a ChainLock overrides it. * Hold and update label in TransactionRecord Instead of looking it up in data() * Review suggestions * Use proper columns in dataChanged call in updateAddressBook
2019-10-19 12:39:02 +02:00
/** Date and time this transaction was created in MSec since epoch */
DateRoleInt,
/** Watch-only boolean */
WatchonlyRole,
/** Watch-only icon */
WatchonlyDecorationRole,
2011-11-13 13:19:52 +01:00
/** Long description (HTML format) */
LongDescriptionRole,
2011-11-13 13:19:52 +01:00
/** Address of transaction */
AddressRole,
2011-11-13 13:19:52 +01:00
/** Label of address related to transaction */
LabelRole,
2011-11-13 13:19:52 +01:00
/** Net amount of transaction */
AmountRole,
/** Transaction hash */
TxHashRole,
/** Transaction data, hex-encoded */
TxHexRole,
2017-09-07 17:59:00 +02:00
/** Whole transaction as plain text */
TxPlainTextRole,
2011-11-13 13:19:52 +01:00
/** Is transaction confirmed? */
ConfirmedRole,
2011-11-13 13:19:52 +01:00
/** Formatted amount, without brackets when unconfirmed */
FormattedAmountRole,
/** Transaction status (TransactionRecord::Status) */
2014-11-06 20:55:52 +01:00
StatusRole,
/** Unprocessed icon */
RawDecorationRole,
2011-11-13 13:19:52 +01:00
};
2011-05-08 16:30:10 +02:00
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
bool processingQueuedTransactions() const { return fProcessingQueuedTransactions; }
void updateChainLockHeight(int chainLockHeight);
int getChainLockHeight() const;
2011-05-08 16:30:10 +02:00
private:
CWallet* wallet;
WalletModel *walletModel;
2011-05-08 16:30:10 +02:00
QStringList columns;
2011-06-01 15:33:33 +02:00
TransactionTablePriv *priv;
bool fProcessingQueuedTransactions;
int cachedChainLockHeight;
void subscribeToCoreSignals();
void unsubscribeFromCoreSignals();
2011-05-27 08:20:23 +02:00
QString formatAddressLabel(const std::string &address, const QString& label, bool tooltip) const;
QVariant addressColor(const TransactionRecord *wtx) const;
2011-08-05 15:35:52 +02:00
QString formatTxStatus(const TransactionRecord *wtx) const;
QString formatTxDate(const TransactionRecord *wtx) const;
2011-07-31 17:05:34 +02:00
QString formatTxType(const TransactionRecord *wtx) const;
QString formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const;
QString formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed=true, BitcoinUnits::SeparatorStyle separators=BitcoinUnits::separatorStandard) const;
QVariant amountColor(const TransactionRecord *rec) const;
2011-08-05 15:35:52 +02:00
QString formatTooltip(const TransactionRecord *rec) const;
QVariant txStatusDecoration(const TransactionRecord *wtx) const;
QVariant txWatchonlyDecoration(const TransactionRecord *wtx) const;
2011-07-31 17:05:34 +02:00
QVariant txAddressDecoration(const TransactionRecord *wtx) const;
2011-05-28 20:32:19 +02:00
public Q_SLOTS:
/* New transaction, or transaction changed status */
void updateTransaction(const QString &hash, int status, bool showTransaction);
Fix largest part of GUI lockups with large wallets (#3155) * [Qt] make sure transaction table entry gets updated after bump * Remove unnecessary tracking of IS lock count * Track lockedByChainLocks in TransactionRecord * Only update record when the TX was not ChainLocked before * Emit dataChanged for CT_UPDATED transactions * Use plain seconds since epoch comparison in TransactionFilterProxy::filterAcceptsRow The QDateTime::operator< calls inside TransactionFilterProxy::filterAcceptsRow turned out to be the slowest part in the UI when many TXs are inside the wallet. DateRoleInt allows us to request the plain seconds since epoch which we then use to compare against dateFrom/dateTo, which are also both stored as seconds since epoch now. * Don't invoke updateConfirmations directly and let pollBalanceChanged handle it * Implement AddressTableModel::labelForDestination This one avoids converting from string to CBitcoinAddress and calling .Get() on the result. * Also store CBitcoinAddress object and CTxDestination in TransactionRecord This avoids frequent and slow conversion * Use labelForDestination when possible This avoids unnecessary conversions * Don't set fForceCheckBalanceChanged to true when IS lock is received We already do this through updateTransaction(), which is also called when an IS lock is received for one of our own TXs. * Only update lockedByChainLocks and lockedByInstantSend when a change is possible lockedByChainLocks can never get back to false, so no need to re-check it. Same with lockedByInstantSend, except when a ChainLock overrides it. * Hold and update label in TransactionRecord Instead of looking it up in data() * Review suggestions * Use proper columns in dataChanged call in updateAddressBook
2019-10-19 12:39:02 +02:00
void updateAddressBook(const QString &address, const QString &label,
bool isMine, const QString &purpose, int status);
void updateConfirmations();
void updateDisplayUnit();
/** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
void updateAmountColumnTitle();
/* Needed to update fProcessingQueuedTransactions through a QueuedConnection */
void setProcessingQueuedTransactions(bool value) { fProcessingQueuedTransactions = value; }
2011-06-03 20:48:03 +02:00
friend class TransactionTablePriv;
2011-05-08 16:30:10 +02:00
};
2014-11-03 16:16:40 +01:00
#endif // BITCOIN_QT_TRANSACTIONTABLEMODEL_H