From 4ba08d6a7a5ada326fbc100b38c2dde22fd9267c Mon Sep 17 00:00:00 2001 From: Chaozer Date: Wed, 2 Sep 2020 01:18:17 +0200 Subject: [PATCH] Fixes to the QT code to allow the use of robin hood in the wallet model --- src/qt/addeditadrenalinenode.cpp | 10 +++++++++- src/qt/transactiontablemodel.cpp | 33 +++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/qt/addeditadrenalinenode.cpp b/src/qt/addeditadrenalinenode.cpp index 6c7bc9d..5a2b57a 100644 --- a/src/qt/addeditadrenalinenode.cpp +++ b/src/qt/addeditadrenalinenode.cpp @@ -1,3 +1,8 @@ +// Copyright (c) 2015-2020 The Neutron Developers +// +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + #include "addeditadrenalinenode.h" #include "ui_addeditadrenalinenode.h" @@ -66,14 +71,17 @@ void AddEditAdrenalineNode::on_okButton_clicked() { CScript scriptPubKey; scriptPubKey.SetDestination(account.vchPubKey.GetID()); - for (map::iterator it = pwalletMain->mapWallet.begin(); + for (auto it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end() && account.vchPubKey.IsValid(); ++it) { const CWalletTx& wtx = (*it).second; + BOOST_FOREACH(const CTxOut& txout, wtx.vout) + { if (txout.scriptPubKey == scriptPubKey) bKeyUsed = true; + } } } diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index 7435666..031643a 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -1,3 +1,8 @@ +// Copyright (c) 2015-2020 The Neutron Developers +// +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + #include "transactiontablemodel.h" #include "guiutil.h" #include "transactionrecord.h" @@ -21,12 +26,12 @@ // Amount column is right-aligned it contains numbers static int column_alignments[] = { - Qt::AlignLeft|Qt::AlignVCenter, - Qt::AlignLeft|Qt::AlignVCenter, - Qt::AlignLeft|Qt::AlignVCenter, - Qt::AlignLeft|Qt::AlignVCenter, - Qt::AlignRight|Qt::AlignVCenter - }; + Qt::AlignLeft|Qt::AlignVCenter, + Qt::AlignLeft|Qt::AlignVCenter, + Qt::AlignLeft|Qt::AlignVCenter, + Qt::AlignLeft|Qt::AlignVCenter, + Qt::AlignRight|Qt::AlignVCenter +}; // Comparison operator for sort/binary search of model tx list struct TxLessThan @@ -71,7 +76,7 @@ class TransactionTablePriv cachedWallet.clear(); { LOCK(wallet->cs_wallet); - for(std::map::iterator it = wallet->mapWallet.begin(); it != wallet->mapWallet.end(); ++it) + for(auto it = wallet->mapWallet.begin(); it != wallet->mapWallet.end(); ++it) { if(TransactionRecord::showTransaction(it->second)) cachedWallet.append(TransactionRecord::decomposeTransaction(wallet, it->second)); @@ -91,14 +96,16 @@ class TransactionTablePriv LOCK(wallet->cs_wallet); // Find transaction in wallet - std::map::iterator mi = wallet->mapWallet.find(hash); + auto mi = wallet->mapWallet.find(hash); bool inWallet = mi != wallet->mapWallet.end(); // Find bounds of this transaction in model QList::iterator lower = qLowerBound( cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan()); + QList::iterator upper = qUpperBound( cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan()); + int lowerIndex = (lower - cachedWallet.begin()); int upperIndex = (upper - cachedWallet.begin()); bool inModel = (lower != upper); @@ -185,7 +192,7 @@ class TransactionTablePriv { { LOCK(wallet->cs_wallet); - std::map::iterator mi = wallet->mapWallet.find(rec->hash); + auto mi = wallet->mapWallet.find(rec->hash); if(mi != wallet->mapWallet.end()) { @@ -205,7 +212,7 @@ class TransactionTablePriv { { LOCK(wallet->cs_wallet); - std::map::iterator mi = wallet->mapWallet.find(rec->hash); + auto mi = wallet->mapWallet.find(rec->hash); if(mi != wallet->mapWallet.end()) { return TransactionDesc::toHTML(wallet, mi->second); @@ -473,11 +480,13 @@ QVariant TransactionTableModel::txStatusDecoration(const TransactionRecord *wtx) QString TransactionTableModel::formatTooltip(const TransactionRecord *rec) const { QString tooltip = formatTxStatus(rec) + QString("\n") + formatTxType(rec); + if(rec->type==TransactionRecord::RecvFromOther || rec->type==TransactionRecord::SendToOther || rec->type==TransactionRecord::SendToAddress || rec->type==TransactionRecord::RecvWithAddress) { tooltip += QString(" ") + formatTxToAddress(rec, true); } + return tooltip; } @@ -485,6 +494,7 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const { if(!index.isValid()) return QVariant(); + TransactionRecord *rec = static_cast(index.internalPointer()); switch(role) @@ -581,7 +591,8 @@ QVariant TransactionTableModel::headerData(int section, Qt::Orientation orientat else if (role == Qt::TextAlignmentRole) { return column_alignments[section]; - } else if (role == Qt::ToolTipRole) + } + else if (role == Qt::ToolTipRole) { switch(section) {