|
3 | 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
4 | 4 |
|
5 | 5 | #include <qml/models/sendrecipientslistmodel.h>
|
6 |
| -#include <qobjectdefs.h> |
7 | 6 |
|
8 | 7 | #include <qml/models/sendrecipient.h>
|
9 | 8 |
|
10 | 9 | SendRecipientsListModel::SendRecipientsListModel(QObject* parent)
|
11 | 10 | : QAbstractListModel(parent)
|
12 | 11 | {
|
13 |
| - m_recipients.append(new SendRecipient(this)); |
| 12 | + auto* recipient = new SendRecipient(this); |
| 13 | + connect(recipient->amount(), &BitcoinAmount::amountChanged, |
| 14 | + this, &SendRecipientsListModel::updateTotalAmount); |
| 15 | + m_recipients.append(recipient); |
14 | 16 | }
|
15 | 17 |
|
16 | 18 | int SendRecipientsListModel::rowCount(const QModelIndex&) const
|
@@ -48,7 +50,10 @@ void SendRecipientsListModel::add()
|
48 | 50 | {
|
49 | 51 | const int row = m_recipients.size();
|
50 | 52 | beginInsertRows(QModelIndex(), row, row);
|
51 |
| - m_recipients.append(new SendRecipient(this)); |
| 53 | + auto* recipient = new SendRecipient(this); |
| 54 | + connect(recipient->amount(), &BitcoinAmount::amountChanged, |
| 55 | + this, &SendRecipientsListModel::updateTotalAmount); |
| 56 | + m_recipients.append(recipient); |
52 | 57 | endInsertRows();
|
53 | 58 | Q_EMIT countChanged();
|
54 | 59 | setCurrentIndex(row);
|
@@ -98,3 +103,18 @@ SendRecipient* SendRecipientsListModel::currentRecipient() const
|
98 | 103 |
|
99 | 104 | return m_recipients[m_current];
|
100 | 105 | }
|
| 106 | + |
| 107 | +void SendRecipientsListModel::updateTotalAmount() |
| 108 | +{ |
| 109 | + qint64 total = 0; |
| 110 | + for (const auto& recipient : m_recipients) { |
| 111 | + total += recipient->amount()->satoshi(); |
| 112 | + } |
| 113 | + m_totalAmount = total; |
| 114 | + Q_EMIT totalAmountChanged(); |
| 115 | +} |
| 116 | + |
| 117 | +QString SendRecipientsListModel::totalAmount() const |
| 118 | +{ |
| 119 | + return BitcoinAmount::satsToBtcString(m_totalAmount); |
| 120 | +} |
0 commit comments