Skip to content

Commit c3cae16

Browse files
committed
qml: Add SendRecipientsList to WalletQmlModel
1 parent 120d630 commit c3cae16

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

src/qml/models/sendrecipientslistmodel.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,18 @@ QHash<int, QByteArray> SendRecipientsListModel::roleNames() const
3535
{
3636
return {
3737
{AddressRole, "address"},
38-
{LabelRole, "label"}};
38+
{LabelRole, "label"},
39+
{AmountRole, "amount"},
40+
{MessageRole, "message"},
41+
};
3942
}
4043

41-
void SendRecipientsListModel::addRecipient()
44+
void SendRecipientsListModel::add()
4245
{
43-
beginInsertRows(QModelIndex(), m_recipients.size(), m_recipients.size());
46+
const int row = m_recipients.size();
47+
beginInsertRows(QModelIndex(), row, row);
4448
m_recipients.append(new SendRecipient(this));
4549
endInsertRows();
50+
Q_EMIT countChanged();
51+
setCurrentIndex(row)
4652
}

src/qml/models/sendrecipientslistmodel.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
class SendRecipientsListModel : public QAbstractListModel
1414
{
1515
Q_OBJECT
16+
Q_PROPERTY(int recipientIndex READ recipientIndex NOTIFY recipientIndexChanged)
17+
Q_PROPERTY(int count READ count NOTIFY countChanged)
18+
Q_PROPERTY(SendRecipient* currentRecipient READ currentRecipient NOTIFY currentRecipientChanged)
1619

1720
public:
1821
enum Roles {
@@ -28,10 +31,24 @@ class SendRecipientsListModel : public QAbstractListModel
2831
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
2932
QHash<int, QByteArray> roleNames() const override;
3033

31-
void addRecipient();
34+
Q_INVOKABLE void add();
35+
Q_INVOKABLE void next();
36+
Q_INVOKABLE void prev();
37+
Q_INVOKABLE void clearAll();
38+
39+
int currentIndex() const { return m_current; }
40+
void setCurrentIndex(int row);
41+
SendRecipient* currentRecipient() const;
42+
int count() const { return m_recipients.size(); }
43+
44+
Q_SIGNALS:
45+
void currentIndexChanged();
46+
void currentRecipientChanged();
47+
void countChanged();
3248

3349
private:
3450
QList<SendRecipient*> m_recipients;
51+
int m_current{0};
3552
};
3653

3754
#endif // BITCOIN_QML_MODELS_SENDRECIPIENTSLISTMODEL_H

src/qml/models/walletqmlmodel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class WalletQmlModel : public QObject
2727
Q_PROPERTY(ActivityListModel* activityListModel READ activityListModel CONSTANT)
2828
Q_PROPERTY(CoinsListModel* coinsListModel READ coinsListModel CONSTANT)
2929
Q_PROPERTY(SendRecipient* sendRecipient READ sendRecipient CONSTANT)
30+
Q_PROPERTY(SendRecipientsListModel* sendRecipientList READ sendRecipientList CONSTANT)
3031
Q_PROPERTY(WalletQmlModelTransaction* currentTransaction READ currentTransaction NOTIFY currentTransactionChanged)
3132
Q_PROPERTY(int recipientIndex READ recipientIndex NOTIFY recipientIndexChanged)
3233
Q_PROPERTY(int recipientsCount READ recipientsCount NOTIFY recipientsCountChanged)
@@ -40,6 +41,11 @@ class WalletQmlModel : public QObject
4041
QString balance() const;
4142
ActivityListModel* activityListModel() const { return m_activity_list_model; }
4243
CoinsListModel* coinsListModel() const { return m_coins_list_model; }
44+
SendRecipient* sendRecipient() const { return m_current_recipient; }
45+
SendRecipientList* sendRecipientList() const { return m_current_recipient; }
46+
WalletQmlModelTransaction* currentTransaction() const { return m_current_transaction; }
47+
Q_INVOKABLE bool prepareTransaction();
48+
Q_INVOKABLE void sendTransaction();
4349

4450
std::set<interfaces::WalletTx> getWalletTxs() const;
4551
interfaces::WalletTx getWalletTx(const uint256& hash) const;

0 commit comments

Comments
 (0)