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.

recentrequeststablemodel.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright (c) 2011-2014 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 RECENTREQUESTSTABLEMODEL_H
  5. #define RECENTREQUESTSTABLEMODEL_H
  6. #include "walletmodel.h"
  7. #include <QAbstractTableModel>
  8. #include <QStringList>
  9. #include <QDateTime>
  10. class CWallet;
  11. class RecentRequestEntry
  12. {
  13. public:
  14. RecentRequestEntry() : nVersion(RecentRequestEntry::CURRENT_VERSION), id(0) { }
  15. static const int CURRENT_VERSION = 1;
  16. int nVersion;
  17. int64_t id;
  18. QDateTime date;
  19. SendCoinsRecipient recipient;
  20. ADD_SERIALIZE_METHODS;
  21. template <typename Stream, typename Operation>
  22. inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
  23. unsigned int nDate = date.toTime_t();
  24. READWRITE(this->nVersion);
  25. nVersion = this->nVersion;
  26. READWRITE(id);
  27. READWRITE(nDate);
  28. READWRITE(recipient);
  29. if (ser_action.ForRead())
  30. date = QDateTime::fromTime_t(nDate);
  31. }
  32. };
  33. class RecentRequestEntryLessThan
  34. {
  35. public:
  36. RecentRequestEntryLessThan(int nColumn, Qt::SortOrder fOrder):
  37. column(nColumn), order(fOrder) {}
  38. bool operator()(RecentRequestEntry &left, RecentRequestEntry &right) const;
  39. private:
  40. int column;
  41. Qt::SortOrder order;
  42. };
  43. /** Model for list of recently generated payment requests / bitcoin: URIs.
  44. * Part of wallet model.
  45. */
  46. class RecentRequestsTableModel: public QAbstractTableModel
  47. {
  48. Q_OBJECT
  49. public:
  50. explicit RecentRequestsTableModel(CWallet *wallet, WalletModel *parent);
  51. ~RecentRequestsTableModel();
  52. enum ColumnIndex {
  53. Date = 0,
  54. Label = 1,
  55. Message = 2,
  56. Amount = 3,
  57. NUMBER_OF_COLUMNS
  58. };
  59. /** @name Methods overridden from QAbstractTableModel
  60. @{*/
  61. int rowCount(const QModelIndex &parent) const;
  62. int columnCount(const QModelIndex &parent) const;
  63. QVariant data(const QModelIndex &index, int role) const;
  64. bool setData(const QModelIndex &index, const QVariant &value, int role);
  65. QVariant headerData(int section, Qt::Orientation orientation, int role) const;
  66. QModelIndex index(int row, int column, const QModelIndex &parent) const;
  67. bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
  68. Qt::ItemFlags flags(const QModelIndex &index) const;
  69. /*@}*/
  70. const RecentRequestEntry &entry(int row) const { return list[row]; }
  71. void addNewRequest(const SendCoinsRecipient &recipient);
  72. void addNewRequest(const std::string &recipient);
  73. void addNewRequest(RecentRequestEntry &recipient);
  74. public slots:
  75. void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
  76. void updateDisplayUnit();
  77. private:
  78. WalletModel *walletModel;
  79. QStringList columns;
  80. QList<RecentRequestEntry> list;
  81. int64_t nReceiveRequestsMaxId;
  82. /** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
  83. void updateAmountColumnTitle();
  84. /** Gets title for amount column including current display unit if optionsModel reference available. */
  85. QString getAmountTitle();
  86. };
  87. #endif