From 35be99170d9937564897b1b91a038e07426a0a14 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Mon, 29 Oct 2018 10:01:37 -0700 Subject: [PATCH] Add loading indicator to table. --- src/balancestablemodel.cpp | 19 ++++++++++++++++--- src/balancestablemodel.h | 2 ++ src/rpc.cpp | 7 +++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/balancestablemodel.cpp b/src/balancestablemodel.cpp index c21c4d3..f268fb1 100644 --- a/src/balancestablemodel.cpp +++ b/src/balancestablemodel.cpp @@ -3,13 +3,14 @@ #include "utils.h" BalancesTableModel::BalancesTableModel(QObject *parent) - : QAbstractTableModel(parent) -{ + : QAbstractTableModel(parent) { } void BalancesTableModel::setNewData(const QMap* balances, const QList* outputs) { + loading = false; + int currentRows = rowCount(QModelIndex()); // Copy over the utxos for our use delete utxos; @@ -39,7 +40,12 @@ BalancesTableModel::~BalancesTableModel() { int BalancesTableModel::rowCount(const QModelIndex&) const { - if (modeldata == nullptr) return 0; + if (modeldata == nullptr) { + if (loading) + return 1; + else + return 0; + } return modeldata->size(); } @@ -50,6 +56,13 @@ int BalancesTableModel::columnCount(const QModelIndex&) const QVariant BalancesTableModel::data(const QModelIndex &index, int role) const { + if (loading) { + if (role == Qt::DisplayRole) + return "Loading..."; + else + return QVariant(); + } + if (role == Qt::TextAlignmentRole && index.column() == 1) return QVariant(Qt::AlignRight | Qt::AlignVCenter); if (role == Qt::ForegroundRole) { diff --git a/src/balancestablemodel.h b/src/balancestablemodel.h index c0824ec..26937eb 100644 --- a/src/balancestablemodel.h +++ b/src/balancestablemodel.h @@ -21,6 +21,8 @@ public: private: QList>* modeldata = nullptr; QList* utxos = nullptr; + + bool loading = true; }; #endif // BALANCESTABLEMODEL_H \ No newline at end of file diff --git a/src/rpc.cpp b/src/rpc.cpp index f8c6fe2..03e7b94 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -648,9 +648,12 @@ void RPC::refreshSentZTrans() { // with the confirmed block number, so we don't have to keep calling gettransaction for the // sent items. for (TransactionItem& sentTx: newSentZTxs) { - auto error = txidList->value(sentTx.txid)["confirmations"].is_null(); + auto j = txidList->value(sentTx.txid); + if (j.is_null()) + continue; + auto error = j["confirmations"].is_null(); if (!error) - sentTx.confirmations = txidList->value(sentTx.txid)["confirmations"].get(); + sentTx.confirmations = j["confirmations"].get(); } transactionsTableModel->addZSentData(newSentZTxs);