Skip to content

Commit b2ce86c

Browse files
committed
qt: Use WalletModel* instead of wallet name in main window
1 parent d2a1adf commit b2ce86c

File tree

5 files changed

+31
-34
lines changed

5 files changed

+31
-34
lines changed

src/qt/bitcoin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2011-2018 The Bitcoin Core developers
1+
// Copyright (c) 2011-2019 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -431,7 +431,7 @@ void BitcoinApplication::addWallet(WalletModel* walletModel)
431431
window->addWallet(walletModel);
432432

433433
if (m_wallet_models.empty()) {
434-
window->setCurrentWallet(walletModel->getWalletName());
434+
window->setCurrentWallet(walletModel);
435435
}
436436

437437
#ifdef ENABLE_BIP70

src/qt/bitcoingui.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2011-2018 The Bitcoin Core developers
1+
// Copyright (c) 2011-2019 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -569,10 +569,9 @@ bool BitcoinGUI::addWallet(WalletModel *walletModel)
569569
{
570570
if(!walletFrame)
571571
return false;
572-
const QString name = walletModel->getWalletName();
573572
const QString display_name = walletModel->getDisplayName();
574573
setWalletActionsEnabled(true);
575-
m_wallet_selector->addItem(display_name, name);
574+
m_wallet_selector->addItem(display_name, QVariant::fromValue(walletModel));
576575
if (m_wallet_selector->count() == 2) {
577576
m_wallet_selector_label_action->setVisible(true);
578577
m_wallet_selector_action->setVisible(true);
@@ -584,8 +583,7 @@ bool BitcoinGUI::addWallet(WalletModel *walletModel)
584583
bool BitcoinGUI::removeWallet(WalletModel* walletModel)
585584
{
586585
if (!walletFrame) return false;
587-
QString name = walletModel->getWalletName();
588-
int index = m_wallet_selector->findData(name);
586+
int index = m_wallet_selector->findData(QVariant::fromValue(walletModel));
589587
m_wallet_selector->removeItem(index);
590588
if (m_wallet_selector->count() == 0) {
591589
setWalletActionsEnabled(false);
@@ -594,20 +592,20 @@ bool BitcoinGUI::removeWallet(WalletModel* walletModel)
594592
m_wallet_selector_action->setVisible(false);
595593
}
596594
rpcConsole->removeWallet(walletModel);
597-
return walletFrame->removeWallet(name);
595+
return walletFrame->removeWallet(walletModel);
598596
}
599597

600-
bool BitcoinGUI::setCurrentWallet(const QString& name)
598+
bool BitcoinGUI::setCurrentWallet(WalletModel* wallet_model)
601599
{
602600
if(!walletFrame)
603601
return false;
604-
return walletFrame->setCurrentWallet(name);
602+
return walletFrame->setCurrentWallet(wallet_model);
605603
}
606604

607605
bool BitcoinGUI::setCurrentWalletBySelectorIndex(int index)
608606
{
609-
QString internal_name = m_wallet_selector->itemData(index).toString();
610-
return setCurrentWallet(internal_name);
607+
WalletModel* wallet_model = m_wallet_selector->itemData(index).value<WalletModel*>();
608+
return setCurrentWallet(wallet_model);
611609
}
612610

613611
void BitcoinGUI::removeAllWallets()

src/qt/bitcoingui.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2011-2018 The Bitcoin Core developers
1+
// Copyright (c) 2011-2019 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -206,7 +206,7 @@ public Q_SLOTS:
206206
void message(const QString &title, const QString &message, unsigned int style, bool *ret = nullptr);
207207

208208
#ifdef ENABLE_WALLET
209-
bool setCurrentWallet(const QString& name);
209+
bool setCurrentWallet(WalletModel* wallet_model);
210210
bool setCurrentWalletBySelectorIndex(int index);
211211
/** Set the UI status indicators based on the currently selected wallet.
212212
*/

src/qt/walletframe.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2011-2018 The Bitcoin Core developers
1+
// Copyright (c) 2011-2019 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -46,8 +46,7 @@ bool WalletFrame::addWallet(WalletModel *walletModel)
4646
return false;
4747
}
4848

49-
const QString name = walletModel->getWalletName();
50-
if (mapWalletViews.count(name) > 0) {
49+
if (mapWalletViews.count(walletModel) > 0) {
5150
return false;
5251
}
5352

@@ -65,7 +64,7 @@ bool WalletFrame::addWallet(WalletModel *walletModel)
6564
}
6665

6766
walletStack->addWidget(walletView);
68-
mapWalletViews[name] = walletView;
67+
mapWalletViews[walletModel] = walletView;
6968

7069
// Ensure a walletView is able to show the main window
7170
connect(walletView, &WalletView::showNormalIfMinimized, [this]{
@@ -77,32 +76,32 @@ bool WalletFrame::addWallet(WalletModel *walletModel)
7776
return true;
7877
}
7978

80-
bool WalletFrame::setCurrentWallet(const QString& name)
79+
bool WalletFrame::setCurrentWallet(WalletModel* wallet_model)
8180
{
82-
if (mapWalletViews.count(name) == 0)
81+
if (mapWalletViews.count(wallet_model) == 0)
8382
return false;
8483

85-
WalletView *walletView = mapWalletViews.value(name);
84+
WalletView *walletView = mapWalletViews.value(wallet_model);
8685
walletStack->setCurrentWidget(walletView);
8786
assert(walletView);
8887
walletView->updateEncryptionStatus();
8988
return true;
9089
}
9190

92-
bool WalletFrame::removeWallet(const QString &name)
91+
bool WalletFrame::removeWallet(WalletModel* wallet_model)
9392
{
94-
if (mapWalletViews.count(name) == 0)
93+
if (mapWalletViews.count(wallet_model) == 0)
9594
return false;
9695

97-
WalletView *walletView = mapWalletViews.take(name);
96+
WalletView *walletView = mapWalletViews.take(wallet_model);
9897
walletStack->removeWidget(walletView);
9998
delete walletView;
10099
return true;
101100
}
102101

103102
void WalletFrame::removeAllWallets()
104103
{
105-
QMap<QString, WalletView*>::const_iterator i;
104+
QMap<WalletModel*, WalletView*>::const_iterator i;
106105
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
107106
walletStack->removeWidget(i.value());
108107
mapWalletViews.clear();
@@ -120,35 +119,35 @@ bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient)
120119
void WalletFrame::showOutOfSyncWarning(bool fShow)
121120
{
122121
bOutOfSync = fShow;
123-
QMap<QString, WalletView*>::const_iterator i;
122+
QMap<WalletModel*, WalletView*>::const_iterator i;
124123
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
125124
i.value()->showOutOfSyncWarning(fShow);
126125
}
127126

128127
void WalletFrame::gotoOverviewPage()
129128
{
130-
QMap<QString, WalletView*>::const_iterator i;
129+
QMap<WalletModel*, WalletView*>::const_iterator i;
131130
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
132131
i.value()->gotoOverviewPage();
133132
}
134133

135134
void WalletFrame::gotoHistoryPage()
136135
{
137-
QMap<QString, WalletView*>::const_iterator i;
136+
QMap<WalletModel*, WalletView*>::const_iterator i;
138137
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
139138
i.value()->gotoHistoryPage();
140139
}
141140

142141
void WalletFrame::gotoReceiveCoinsPage()
143142
{
144-
QMap<QString, WalletView*>::const_iterator i;
143+
QMap<WalletModel*, WalletView*>::const_iterator i;
145144
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
146145
i.value()->gotoReceiveCoinsPage();
147146
}
148147

149148
void WalletFrame::gotoSendCoinsPage(QString addr)
150149
{
151-
QMap<QString, WalletView*>::const_iterator i;
150+
QMap<WalletModel*, WalletView*>::const_iterator i;
152151
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
153152
i.value()->gotoSendCoinsPage(addr);
154153
}

src/qt/walletframe.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2011-2018 The Bitcoin Core developers
1+
// Copyright (c) 2011-2019 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -37,8 +37,8 @@ class WalletFrame : public QFrame
3737
void setClientModel(ClientModel *clientModel);
3838

3939
bool addWallet(WalletModel *walletModel);
40-
bool setCurrentWallet(const QString& name);
41-
bool removeWallet(const QString &name);
40+
bool setCurrentWallet(WalletModel* wallet_model);
41+
bool removeWallet(WalletModel* wallet_model);
4242
void removeAllWallets();
4343

4444
bool handlePaymentRequest(const SendCoinsRecipient& recipient);
@@ -53,7 +53,7 @@ class WalletFrame : public QFrame
5353
QStackedWidget *walletStack;
5454
BitcoinGUI *gui;
5555
ClientModel *clientModel;
56-
QMap<QString, WalletView*> mapWalletViews;
56+
QMap<WalletModel*, WalletView*> mapWalletViews;
5757

5858
bool bOutOfSync;
5959

0 commit comments

Comments
 (0)