transactiontablemodel.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
  2. #ifndef TRANSACTIONTABLEMODEL_H
  3. #define TRANSACTIONTABLEMODEL_H
  4. #include <QAbstractTableModel>
  5. #include <QStringList>
  6. class CWallet;
  7. class TransactionTablePriv;
  8. class TransactionRecord;
  9. class WalletModel;
  10. class TransactionTableModel : public QAbstractTableModel
  11. {
  12. Q_OBJECT
  13. public:
  14. explicit TransactionTableModel(CWallet* wallet, WalletModel *parent = 0);
  15. ~TransactionTableModel();
  16. enum ColumnIndex {
  17. Status = 0,
  18. Date = 1,
  19. Type = 2,
  20. ToAddress = 3,
  21. Amount = 4
  22. };
  23. enum RoleIndex {
  24. /** Type of transaction */
  25. TypeRole = Qt::UserRole,
  26. /** Date and time this transaction was created */
  27. DateRole,
  28. /** Long description (HTML format) */
  29. LongDescriptionRole,
  30. /** Address of transaction */
  31. AddressRole,
  32. /** Label of address related to transaction */
  33. LabelRole,
  34. /** Net amount of transaction */
  35. AmountRole,
  36. /** Unique identifier */
  37. TxIDRole,
  38. /** Is transaction confirmed? */
  39. ConfirmedRole,
  40. /** Formatted amount, without brackets when unconfirmed */
  41. FormattedAmountRole
  42. };
  43. int rowCount(const QModelIndex &parent) const;
  44. int columnCount(const QModelIndex &parent) const;
  45. QVariant data(const QModelIndex &index, int role) const;
  46. QVariant headerData(int section, Qt::Orientation orientation, int role) const;
  47. QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
  48. private:
  49. CWallet* wallet;
  50. WalletModel *walletModel;
  51. QStringList columns;
  52. TransactionTablePriv *priv;
  53. int cachedNumBlocks;
  54. QString lookupAddress(const std::string &address, bool tooltip) const;
  55. QVariant addressColor(const TransactionRecord *wtx) const;
  56. QString formatTxStatus(const TransactionRecord *wtx) const;
  57. QString formatTxDate(const TransactionRecord *wtx) const;
  58. QString formatTxType(const TransactionRecord *wtx) const;
  59. QString formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const;
  60. QString formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed=true) const;
  61. QString formatTooltip(const TransactionRecord *rec) const;
  62. QVariant txStatusDecoration(const TransactionRecord *wtx) const;
  63. QVariant txAddressDecoration(const TransactionRecord *wtx) const;
  64. public slots:
  65. void updateTransaction(const QString &hash, int status);
  66. void updateConfirmations();
  67. void updateDisplayUnit();
  68. friend class TransactionTablePriv;
  69. };
  70. #endif