addresstablemodel.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
  2. #ifndef ADDRESSTABLEMODEL_H
  3. #define ADDRESSTABLEMODEL_H
  4. #include <QAbstractTableModel>
  5. #include <QStringList>
  6. class AddressTablePriv;
  7. class CWallet;
  8. class WalletModel;
  9. class AddressTableModel : public QAbstractTableModel
  10. {
  11. Q_OBJECT
  12. public:
  13. explicit AddressTableModel(CWallet *wallet, WalletModel *parent = 0);
  14. ~AddressTableModel();
  15. enum ColumnIndex {
  16. Label = 0, /**< User specified label */
  17. Address = 1 /**< Ecoin address */
  18. };
  19. enum RoleIndex {
  20. TypeRole = Qt::UserRole /**< Type of address (#Send or #Receive) */
  21. };
  22. /** Return status of edit/insert operation */
  23. enum EditStatus {
  24. OK, /**< Everything ok */
  25. NO_CHANGES, /**< No changes were made during edit operation */
  26. INVALID_ADDRESS, /**< Unparseable address */
  27. DUPLICATE_ADDRESS, /**< Address already in address book */
  28. WALLET_UNLOCK_FAILURE, /**< Wallet could not be unlocked to create new receiving address */
  29. KEY_GENERATION_FAILURE /**< Generating a new public key for a receiving address failed */
  30. };
  31. static const QString Send; /**< Specifies send address */
  32. static const QString Receive; /**< Specifies receive address */
  33. int rowCount(const QModelIndex &parent) const;
  34. int columnCount(const QModelIndex &parent) const;
  35. QVariant data(const QModelIndex &index, int role) const;
  36. bool setData(const QModelIndex &index, const QVariant &value, int role);
  37. QVariant headerData(int section, Qt::Orientation orientation, int role) const;
  38. QModelIndex index(int row, int column, const QModelIndex &parent) const;
  39. bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
  40. Qt::ItemFlags flags(const QModelIndex &index) const;
  41. QString addRow(const QString &type, const QString &label, const QString &address);
  42. QString labelForAddress(const QString &address) const;
  43. int lookupAddress(const QString &address) const;
  44. EditStatus getEditStatus() const { return editStatus; }
  45. private:
  46. WalletModel *walletModel;
  47. CWallet *wallet;
  48. AddressTablePriv *priv;
  49. QStringList columns;
  50. EditStatus editStatus;
  51. void emitDataChanged(int index);
  52. signals:
  53. void defaultAddressChanged(const QString &address);
  54. public slots:
  55. void updateEntry(const QString &address, const QString &label, bool isMine, int status);
  56. friend class AddressTablePriv;
  57. };
  58. #endif // ADDRESSTABLEMODEL_H