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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright (c) 2011-2016 The Starwels developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #ifndef STARWELS_QT_RECENTREQUESTSTABLEMODEL_H
  5. #define STARWELS_QT_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) {
  23. unsigned int nDate = date.toTime_t();
  24. READWRITE(this->nVersion);
  25. READWRITE(id);
  26. READWRITE(nDate);
  27. READWRITE(recipient);
  28. if (ser_action.ForRead())
  29. date = QDateTime::fromTime_t(nDate);
  30. }
  31. };
  32. class RecentRequestEntryLessThan
  33. {
  34. public:
  35. RecentRequestEntryLessThan(int nColumn, Qt::SortOrder fOrder):
  36. column(nColumn), order(fOrder) {}
  37. bool operator()(RecentRequestEntry &left, RecentRequestEntry &right) const;
  38. private:
  39. int column;
  40. Qt::SortOrder order;
  41. };
  42. /** Model for list of recently generated payment requests / starwels: URIs.
  43. * Part of wallet model.
  44. */
  45. class RecentRequestsTableModel: public QAbstractTableModel
  46. {
  47. Q_OBJECT
  48. public:
  49. explicit RecentRequestsTableModel(CWallet *wallet, WalletModel *parent);
  50. ~RecentRequestsTableModel();
  51. enum ColumnIndex {
  52. Date = 0,
  53. Label = 1,
  54. Message = 2,
  55. Amount = 3,
  56. NUMBER_OF_COLUMNS
  57. };
  58. /** @name Methods overridden from QAbstractTableModel
  59. @{*/
  60. int rowCount(const QModelIndex &parent) const;
  61. int columnCount(const QModelIndex &parent) const;
  62. QVariant data(const QModelIndex &index, int role) const;
  63. bool setData(const QModelIndex &index, const QVariant &value, int role);
  64. QVariant headerData(int section, Qt::Orientation orientation, int role) const;
  65. QModelIndex index(int row, int column, const QModelIndex &parent) const;
  66. bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
  67. Qt::ItemFlags flags(const QModelIndex &index) const;
  68. /*@}*/
  69. const RecentRequestEntry &entry(int row) const { return list[row]; }
  70. void addNewRequest(const SendCoinsRecipient &recipient);
  71. void addNewRequest(const std::string &recipient);
  72. void addNewRequest(RecentRequestEntry &recipient);
  73. public Q_SLOTS:
  74. void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
  75. void updateDisplayUnit();
  76. private:
  77. WalletModel *walletModel;
  78. QStringList columns;
  79. QList<RecentRequestEntry> list;
  80. int64_t nReceiveRequestsMaxId;
  81. /** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
  82. void updateAmountColumnTitle();
  83. /** Gets title for amount column including current display unit if optionsModel reference available. */
  84. QString getAmountTitle();
  85. };
  86. #endif // STARWELS_QT_RECENTREQUESTSTABLEMODEL_H