mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Merge #16349: qt: Remove redundant WalletController::addWallet slot
6285a318d77dbfdf50f893963ebfb2973746f757 Remove redundant WalletController::addWallet slot (Hennadii Stepanov) Pull request description: ~~Fix #15453.~~ It is fixed by https://github.com/bitcoin/bitcoin/pull/16348#issuecomment-509308347 The _only_ reason of these lines on master (8c69fae94410f54bad13be0f34d54370fddbf4b3)2679bb8919/src/qt/walletcontroller.cpp (L121-L128)
is to `Q_EMIT walletAdded(wallet_model);` in a thread-safe manner; This PR makes this in a line of code:1b83875006/src/qt/walletcontroller.cpp (L121)
EDITED: To establish the ownership of a new `WalletModel` object is not necessary on the master (https://github.com/bitcoin/bitcoin/pull/16349#discussion_r301679192 by **promag**). But: > it's good habit to set ownership And I agree. It is a safe practice. ACKs for top commit: promag: ACK 6285a318d77dbfdf50f893963ebfb2973746f757. jonasschnelli: utACK 6285a318d77dbfdf50f893963ebfb2973746f757 ryanofsky: utACK 6285a318d77dbfdf50f893963ebfb2973746f757. Only change since last review is rebasing and restoring a deleted comment. I do think the comments I suggested last review would be better than this one, but this is at least better than before. Tree-SHA512: 90370cb1fe853b84dd16c3781ba4f97f3f4deca56bba0203e457f37b3220fd13228cf8495fd882ff18b7c782c27544cc2e7a88aaec5b69b9ef6d8626bdaaf332
This commit is contained in:
parent
a4e2c74b50
commit
eedd48926c
@ -98,6 +98,9 @@ WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wal
|
|||||||
|
|
||||||
// Instantiate model and register it.
|
// Instantiate model and register it.
|
||||||
WalletModel* wallet_model = new WalletModel(std::move(wallet), m_node, m_options_model, nullptr);
|
WalletModel* wallet_model = new WalletModel(std::move(wallet), m_node, m_options_model, nullptr);
|
||||||
|
// Handler callback runs in a different thread so fix wallet model thread affinity.
|
||||||
|
wallet_model->moveToThread(thread());
|
||||||
|
wallet_model->setParent(this);
|
||||||
m_wallets.push_back(wallet_model);
|
m_wallets.push_back(wallet_model);
|
||||||
|
|
||||||
// WalletModel::startPollBalance needs to be called in a thread managed by
|
// WalletModel::startPollBalance needs to be called in a thread managed by
|
||||||
@ -124,25 +127,11 @@ WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wal
|
|||||||
connect(wallet_model, &WalletModel::coinsSent, this, &WalletController::coinsSent);
|
connect(wallet_model, &WalletModel::coinsSent, this, &WalletController::coinsSent);
|
||||||
|
|
||||||
// Notify walletAdded signal on the GUI thread.
|
// Notify walletAdded signal on the GUI thread.
|
||||||
if (QThread::currentThread() == thread()) {
|
Q_EMIT walletAdded(wallet_model);
|
||||||
addWallet(wallet_model);
|
|
||||||
} else {
|
|
||||||
// Handler callback runs in a different thread so fix wallet model thread affinity.
|
|
||||||
wallet_model->moveToThread(thread());
|
|
||||||
bool invoked = QMetaObject::invokeMethod(this, "addWallet", Qt::QueuedConnection, Q_ARG(WalletModel*, wallet_model));
|
|
||||||
assert(invoked);
|
|
||||||
}
|
|
||||||
|
|
||||||
return wallet_model;
|
return wallet_model;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WalletController::addWallet(WalletModel* wallet_model)
|
|
||||||
{
|
|
||||||
// Take ownership of the wallet model and register it.
|
|
||||||
wallet_model->setParent(this);
|
|
||||||
Q_EMIT walletAdded(wallet_model);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WalletController::removeAndDeleteWallet(WalletModel* wallet_model)
|
void WalletController::removeAndDeleteWallet(WalletModel* wallet_model)
|
||||||
{
|
{
|
||||||
// Unregister wallet model.
|
// Unregister wallet model.
|
||||||
|
@ -50,9 +50,6 @@ public:
|
|||||||
OpenWalletActivity* openWallet(const std::string& name, QWidget* parent = nullptr);
|
OpenWalletActivity* openWallet(const std::string& name, QWidget* parent = nullptr);
|
||||||
void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
|
void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void addWallet(WalletModel* wallet_model);
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void walletAdded(WalletModel* wallet_model);
|
void walletAdded(WalletModel* wallet_model);
|
||||||
void walletRemoved(WalletModel* wallet_model);
|
void walletRemoved(WalletModel* wallet_model);
|
||||||
|
Loading…
Reference in New Issue
Block a user