You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

transactiontablemodel.h 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright (c) 2011-2013 The Bitcoin developers
  2. // Distributed under the MIT/X11 software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #ifndef TRANSACTIONTABLEMODEL_H
  5. #define TRANSACTIONTABLEMODEL_H
  6. #include <QAbstractTableModel>
  7. #include <QStringList>
  8. class TransactionRecord;
  9. class TransactionTablePriv;
  10. class WalletModel;
  11. class CWallet;
  12. /** UI model for the transaction table of a wallet.
  13. */
  14. class TransactionTableModel : public QAbstractTableModel
  15. {
  16. Q_OBJECT
  17. public:
  18. explicit TransactionTableModel(CWallet* wallet, WalletModel *parent = 0);
  19. ~TransactionTableModel();
  20. enum ColumnIndex {
  21. Status = 0,
  22. Date = 1,
  23. Type = 2,
  24. ToAddress = 3,
  25. Amount = 4
  26. };
  27. /** Roles to get specific information from a transaction row.
  28. These are independent of column.
  29. */
  30. enum RoleIndex {
  31. /** Type of transaction */
  32. TypeRole = Qt::UserRole,
  33. /** Date and time this transaction was created */
  34. DateRole,
  35. /** Long description (HTML format) */
  36. LongDescriptionRole,
  37. /** Address of transaction */
  38. AddressRole,
  39. /** Label of address related to transaction */
  40. LabelRole,
  41. /** Net amount of transaction */
  42. AmountRole,
  43. /** Unique identifier */
  44. TxIDRole,
  45. /** Transaction hash */
  46. TxHashRole,
  47. /** Is transaction confirmed? */
  48. ConfirmedRole,
  49. /** Formatted amount, without brackets when unconfirmed */
  50. FormattedAmountRole,
  51. /** Transaction status (TransactionRecord::Status) */
  52. StatusRole
  53. };
  54. int rowCount(const QModelIndex &parent) const;
  55. int columnCount(const QModelIndex &parent) const;
  56. QVariant data(const QModelIndex &index, int role) const;
  57. QVariant headerData(int section, Qt::Orientation orientation, int role) const;
  58. QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
  59. private:
  60. CWallet* wallet;
  61. WalletModel *walletModel;
  62. QStringList columns;
  63. TransactionTablePriv *priv;
  64. QString lookupAddress(const std::string &address, bool tooltip) const;
  65. QVariant addressColor(const TransactionRecord *wtx) const;
  66. QString formatTxStatus(const TransactionRecord *wtx) const;
  67. QString formatTxDate(const TransactionRecord *wtx) const;
  68. QString formatTxType(const TransactionRecord *wtx) const;
  69. QString formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const;
  70. QString formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed=true) const;
  71. QString formatTooltip(const TransactionRecord *rec) const;
  72. QVariant txStatusDecoration(const TransactionRecord *wtx) const;
  73. QVariant txAddressDecoration(const TransactionRecord *wtx) const;
  74. public slots:
  75. void updateTransaction(const QString &hash, int status);
  76. void updateConfirmations();
  77. void updateDisplayUnit();
  78. friend class TransactionTablePriv;
  79. };
  80. #endif // TRANSACTIONTABLEMODEL_H