From dfd230be7d075e951336075db8189f514f3bf89b Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 29 Oct 2019 14:15:19 -0700 Subject: [PATCH] Handle multiple send in tx table --- src/controller.cpp | 11 +++++++---- src/txtablemodel.cpp | 34 ++++++++++++++++------------------ src/txtablemodel.h | 2 ++ 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index a763e50..f0921fd 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -366,10 +366,13 @@ void Controller::refreshTransactions() { total_amount = total_amount + amount; } - if (items.length() == 1) { - address = items[0].address; - } else { - address = "(Multiple)"; + { + // Concat all the addresses + QList addresses; + for (auto item : items) { + addresses.push_back(item.address); + } + address = addresses.join(","); } txdata.push_back(TransactionItem{ diff --git a/src/txtablemodel.cpp b/src/txtablemodel.cpp index 04d50e3..9df59e4 100644 --- a/src/txtablemodel.cpp +++ b/src/txtablemodel.cpp @@ -69,10 +69,20 @@ bool TxTableModel::exportToCsv(QString fileName) const { return headers.size(); } +QString TxTableModel::concatMultipleMemos(const TransactionItem& dat) const { + // Concat all the memos + QString memo; + for (auto item : dat.items) { + if (!item.memo.trimmed().isEmpty()) { + memo += item.address + ": \"" + item.memo + "\"\n"; + } + } - QVariant TxTableModel::data(const QModelIndex &index, int role) const - { - // Align numeric columns (confirmations, amount) right + return memo; +}; + +QVariant TxTableModel::data(const QModelIndex &index, int role) const { + // Align numeric columns (confirmations, amount) right if (role == Qt::TextAlignmentRole && (index.column() == Column::Confirmations || index.column() == Column::Amount)) return QVariant(Qt::AlignRight | Qt::AlignVCenter); @@ -127,7 +137,7 @@ bool TxTableModel::exportToCsv(QString fileName) const { (memo.isEmpty() ? "" : " tx memo: \"" + memo + "\""); } } else { - return "Multiple"; + return concatMultipleMemos(dat); } } case Column::Address: { @@ -202,20 +212,8 @@ QString TxTableModel::getTxId(int row) const { QString TxTableModel::getMemo(int row) const { auto dat = modeldata->at(row); - bool hasMemo = false; - for (int i=0; i < dat.items.length(); i++) { - if (!dat.items[i].memo.isEmpty()) { - hasMemo = true; - } - } - - if (dat.items.length() == 1) { - return dat.items[0].memo; - } else if (hasMemo) { - return "(Multiple)"; - } else { - return ""; - } + + return concatMultipleMemos(dat); } qint64 TxTableModel::getConfirmations(int row) const { diff --git a/src/txtablemodel.h b/src/txtablemodel.h index 8e60ea7..b07b914 100644 --- a/src/txtablemodel.h +++ b/src/txtablemodel.h @@ -38,6 +38,8 @@ public: QVariant headerData(int section, Qt::Orientation orientation, int role) const; private: + QString concatMultipleMemos(const TransactionItem&) const; + QList* modeldata = nullptr; QList headers;