aboutsummaryrefslogtreecommitdiff
path: root/src/qt/transactiontablemodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qt/transactiontablemodel.cpp')
-rw-r--r--src/qt/transactiontablemodel.cpp56
1 files changed, 30 insertions, 26 deletions
diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp
index a7556eed04..b68ceaedbb 100644
--- a/src/qt/transactiontablemodel.cpp
+++ b/src/qt/transactiontablemodel.cpp
@@ -25,6 +25,8 @@
#include <QDateTime>
#include <QDebug>
#include <QIcon>
+#include <QLatin1Char>
+#include <QLatin1String>
#include <QList>
@@ -96,18 +98,20 @@ public:
*/
QList<TransactionRecord> cachedWallet;
- bool fQueueNotifications = false;
+ /** True when model finishes loading all wallet transactions on start */
+ bool m_loaded = false;
+ /** True when transactions are being notified, for instance when scanning */
+ bool m_loading = false;
std::vector< TransactionNotification > vQueueNotifications;
void NotifyTransactionChanged(const uint256 &hash, ChangeType status);
- void ShowProgress(const std::string &title, int nProgress);
+ void DispatchNotifications();
/* Query entire wallet anew from core.
*/
void refreshWallet(interfaces::Wallet& wallet)
{
- qDebug() << "TransactionTablePriv::refreshWallet";
- cachedWallet.clear();
+ assert(!m_loaded);
{
for (const auto& wtx : wallet.getWalletTxs()) {
if (TransactionRecord::showTransaction()) {
@@ -115,6 +119,8 @@ public:
}
}
}
+ m_loaded = true;
+ DispatchNotifications();
}
/* Update our model of the wallet incrementally, to synchronize our model of the wallet
@@ -249,12 +255,12 @@ TransactionTableModel::TransactionTableModel(const PlatformStyle *_platformStyle
fProcessingQueuedTransactions(false),
platformStyle(_platformStyle)
{
+ subscribeToCoreSignals();
+
columns << QString() << QString() << tr("Date") << tr("Type") << tr("Label") << BitcoinUnits::getAmountColumnTitle(walletModel->getOptionsModel()->getDisplayUnit());
priv->refreshWallet(walletModel->wallet());
connect(walletModel->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &TransactionTableModel::updateDisplayUnit);
-
- subscribeToCoreSignals();
}
TransactionTableModel::~TransactionTableModel()
@@ -409,9 +415,9 @@ QVariant TransactionTableModel::txAddressDecoration(const TransactionRecord *wtx
QString TransactionTableModel::formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const
{
QString watchAddress;
- if (tooltip) {
+ if (tooltip && wtx->involvesWatchAddress) {
// Mark transactions involving watch-only addresses by adding " (watch-only)"
- watchAddress = wtx->involvesWatchAddress ? QString(" (") + tr("watch-only") + QString(")") : "";
+ watchAddress = QLatin1String(" (") + tr("watch-only") + QLatin1Char(')');
}
switch(wtx->type)
@@ -719,7 +725,7 @@ void TransactionTablePriv::NotifyTransactionChanged(const uint256 &hash, ChangeT
TransactionNotification notification(hash, status, showTransaction);
- if (fQueueNotifications)
+ if (!m_loaded || m_loading)
{
vQueueNotifications.push_back(notification);
return;
@@ -727,36 +733,34 @@ void TransactionTablePriv::NotifyTransactionChanged(const uint256 &hash, ChangeT
notification.invoke(parent);
}
-void TransactionTablePriv::ShowProgress(const std::string &title, int nProgress)
+void TransactionTablePriv::DispatchNotifications()
{
- if (nProgress == 0)
- fQueueNotifications = true;
+ if (!m_loaded || m_loading) return;
- if (nProgress == 100)
+ if (vQueueNotifications.size() > 10) { // prevent balloon spam, show maximum 10 balloons
+ bool invoked = QMetaObject::invokeMethod(parent, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, true));
+ assert(invoked);
+ }
+ for (unsigned int i = 0; i < vQueueNotifications.size(); ++i)
{
- fQueueNotifications = false;
- if (vQueueNotifications.size() > 10) { // prevent balloon spam, show maximum 10 balloons
- bool invoked = QMetaObject::invokeMethod(parent, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, true));
+ if (vQueueNotifications.size() - i <= 10) {
+ bool invoked = QMetaObject::invokeMethod(parent, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, false));
assert(invoked);
}
- for (unsigned int i = 0; i < vQueueNotifications.size(); ++i)
- {
- if (vQueueNotifications.size() - i <= 10) {
- bool invoked = QMetaObject::invokeMethod(parent, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, false));
- assert(invoked);
- }
- vQueueNotifications[i].invoke(parent);
- }
- vQueueNotifications.clear();
+ vQueueNotifications[i].invoke(parent);
}
+ vQueueNotifications.clear();
}
void TransactionTableModel::subscribeToCoreSignals()
{
// Connect signals to wallet
m_handler_transaction_changed = walletModel->wallet().handleTransactionChanged(std::bind(&TransactionTablePriv::NotifyTransactionChanged, priv, std::placeholders::_1, std::placeholders::_2));
- m_handler_show_progress = walletModel->wallet().handleShowProgress(std::bind(&TransactionTablePriv::ShowProgress, priv, std::placeholders::_1, std::placeholders::_2));
+ m_handler_show_progress = walletModel->wallet().handleShowProgress([this](const std::string&, int progress) {
+ priv->m_loading = progress < 100;
+ priv->DispatchNotifications();
+ });
}
void TransactionTableModel::unsubscribeFromCoreSignals()