Add loading indicator to table.

This commit is contained in:
Aditya Kulkarni
2018-10-29 10:01:37 -07:00
parent 1adb4cf820
commit 35be99170d
3 changed files with 23 additions and 5 deletions

View File

@@ -3,13 +3,14 @@
#include "utils.h" #include "utils.h"
BalancesTableModel::BalancesTableModel(QObject *parent) BalancesTableModel::BalancesTableModel(QObject *parent)
: QAbstractTableModel(parent) : QAbstractTableModel(parent) {
{
} }
void BalancesTableModel::setNewData(const QMap<QString, double>* balances, void BalancesTableModel::setNewData(const QMap<QString, double>* balances,
const QList<UnspentOutput>* outputs) const QList<UnspentOutput>* outputs)
{ {
loading = false;
int currentRows = rowCount(QModelIndex()); int currentRows = rowCount(QModelIndex());
// Copy over the utxos for our use // Copy over the utxos for our use
delete utxos; delete utxos;
@@ -39,7 +40,12 @@ BalancesTableModel::~BalancesTableModel() {
int BalancesTableModel::rowCount(const QModelIndex&) const int BalancesTableModel::rowCount(const QModelIndex&) const
{ {
if (modeldata == nullptr) return 0; if (modeldata == nullptr) {
if (loading)
return 1;
else
return 0;
}
return modeldata->size(); return modeldata->size();
} }
@@ -50,6 +56,13 @@ int BalancesTableModel::columnCount(const QModelIndex&) const
QVariant BalancesTableModel::data(const QModelIndex &index, int role) 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::TextAlignmentRole && index.column() == 1) return QVariant(Qt::AlignRight | Qt::AlignVCenter);
if (role == Qt::ForegroundRole) { if (role == Qt::ForegroundRole) {

View File

@@ -21,6 +21,8 @@ public:
private: private:
QList<std::tuple<QString, QString>>* modeldata = nullptr; QList<std::tuple<QString, QString>>* modeldata = nullptr;
QList<UnspentOutput>* utxos = nullptr; QList<UnspentOutput>* utxos = nullptr;
bool loading = true;
}; };
#endif // BALANCESTABLEMODEL_H #endif // BALANCESTABLEMODEL_H

View File

@@ -648,9 +648,12 @@ void RPC::refreshSentZTrans() {
// with the confirmed block number, so we don't have to keep calling gettransaction for the // with the confirmed block number, so we don't have to keep calling gettransaction for the
// sent items. // sent items.
for (TransactionItem& sentTx: newSentZTxs) { 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) if (!error)
sentTx.confirmations = txidList->value(sentTx.txid)["confirmations"].get<json::number_unsigned_t>(); sentTx.confirmations = j["confirmations"].get<json::number_unsigned_t>();
} }
transactionsTableModel->addZSentData(newSentZTxs); transactionsTableModel->addZSentData(newSentZTxs);