mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-21 14:34:49 +01:00
qt, refactor: Pass WalletModel object to WalletView constructor
An instance of the WalletView class without walletModel data member being set is invalid. So, it is better to set it in the constructor.
This commit is contained in:
parent
774a4f517c
commit
404373bc6a
4 changed files with 39 additions and 45 deletions
|
@ -676,7 +676,7 @@ void BitcoinGUI::addWallet(WalletModel* walletModel)
|
||||||
{
|
{
|
||||||
if (!walletFrame) return;
|
if (!walletFrame) return;
|
||||||
|
|
||||||
WalletView* wallet_view = new WalletView(platformStyle, walletFrame);
|
WalletView* wallet_view = new WalletView(walletModel, platformStyle, walletFrame);
|
||||||
if (!walletFrame->addWallet(walletModel, wallet_view)) return;
|
if (!walletFrame->addWallet(walletModel, wallet_view)) return;
|
||||||
|
|
||||||
rpcConsole->addWallet(walletModel);
|
rpcConsole->addWallet(walletModel);
|
||||||
|
|
|
@ -71,7 +71,6 @@ bool WalletFrame::addWallet(WalletModel* walletModel, WalletView* walletView)
|
||||||
if (mapWalletViews.count(walletModel) > 0) return false;
|
if (mapWalletViews.count(walletModel) > 0) return false;
|
||||||
|
|
||||||
walletView->setClientModel(clientModel);
|
walletView->setClientModel(clientModel);
|
||||||
walletView->setWalletModel(walletModel);
|
|
||||||
walletView->showOutOfSyncWarning(bOutOfSync);
|
walletView->showOutOfSyncWarning(bOutOfSync);
|
||||||
|
|
||||||
WalletView* current_wallet_view = currentWalletView();
|
WalletView* current_wallet_view = currentWalletView();
|
||||||
|
|
|
@ -30,19 +30,24 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent):
|
WalletView::WalletView(WalletModel* wallet_model, const PlatformStyle* _platformStyle, QWidget* parent)
|
||||||
QStackedWidget(parent),
|
: QStackedWidget(parent),
|
||||||
clientModel(nullptr),
|
clientModel(nullptr),
|
||||||
walletModel(nullptr),
|
walletModel(wallet_model),
|
||||||
platformStyle(_platformStyle)
|
platformStyle(_platformStyle)
|
||||||
{
|
{
|
||||||
|
assert(walletModel);
|
||||||
|
|
||||||
// Create tabs
|
// Create tabs
|
||||||
overviewPage = new OverviewPage(platformStyle);
|
overviewPage = new OverviewPage(platformStyle);
|
||||||
|
overviewPage->setWalletModel(walletModel);
|
||||||
|
|
||||||
transactionsPage = new QWidget(this);
|
transactionsPage = new QWidget(this);
|
||||||
QVBoxLayout *vbox = new QVBoxLayout();
|
QVBoxLayout *vbox = new QVBoxLayout();
|
||||||
QHBoxLayout *hbox_buttons = new QHBoxLayout();
|
QHBoxLayout *hbox_buttons = new QHBoxLayout();
|
||||||
transactionView = new TransactionView(platformStyle, this);
|
transactionView = new TransactionView(platformStyle, this);
|
||||||
|
transactionView->setModel(walletModel);
|
||||||
|
|
||||||
vbox->addWidget(transactionView);
|
vbox->addWidget(transactionView);
|
||||||
QPushButton *exportButton = new QPushButton(tr("&Export"), this);
|
QPushButton *exportButton = new QPushButton(tr("&Export"), this);
|
||||||
exportButton->setToolTip(tr("Export the data in the current tab to a file"));
|
exportButton->setToolTip(tr("Export the data in the current tab to a file"));
|
||||||
|
@ -55,10 +60,16 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent):
|
||||||
transactionsPage->setLayout(vbox);
|
transactionsPage->setLayout(vbox);
|
||||||
|
|
||||||
receiveCoinsPage = new ReceiveCoinsDialog(platformStyle);
|
receiveCoinsPage = new ReceiveCoinsDialog(platformStyle);
|
||||||
|
receiveCoinsPage->setModel(walletModel);
|
||||||
|
|
||||||
sendCoinsPage = new SendCoinsDialog(platformStyle);
|
sendCoinsPage = new SendCoinsDialog(platformStyle);
|
||||||
|
sendCoinsPage->setModel(walletModel);
|
||||||
|
|
||||||
usedSendingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::SendingTab, this);
|
usedSendingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::SendingTab, this);
|
||||||
|
usedSendingAddressesPage->setModel(walletModel->getAddressTableModel());
|
||||||
|
|
||||||
usedReceivingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::ReceivingTab, this);
|
usedReceivingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::ReceivingTab, this);
|
||||||
|
usedReceivingAddressesPage->setModel(walletModel->getAddressTableModel());
|
||||||
|
|
||||||
addWidget(overviewPage);
|
addWidget(overviewPage);
|
||||||
addWidget(transactionsPage);
|
addWidget(transactionsPage);
|
||||||
|
@ -84,6 +95,21 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent):
|
||||||
connect(transactionView, &TransactionView::message, this, &WalletView::message);
|
connect(transactionView, &TransactionView::message, this, &WalletView::message);
|
||||||
|
|
||||||
connect(this, &WalletView::setPrivacy, overviewPage, &OverviewPage::setPrivacy);
|
connect(this, &WalletView::setPrivacy, overviewPage, &OverviewPage::setPrivacy);
|
||||||
|
|
||||||
|
// Receive and pass through messages from wallet model
|
||||||
|
connect(walletModel, &WalletModel::message, this, &WalletView::message);
|
||||||
|
|
||||||
|
// Handle changes in encryption status
|
||||||
|
connect(walletModel, &WalletModel::encryptionStatusChanged, this, &WalletView::encryptionStatusChanged);
|
||||||
|
|
||||||
|
// Balloon pop-up for new transaction
|
||||||
|
connect(walletModel->getTransactionTableModel(), &TransactionTableModel::rowsInserted, this, &WalletView::processNewTransaction);
|
||||||
|
|
||||||
|
// Ask for passphrase if needed
|
||||||
|
connect(walletModel, &WalletModel::requireUnlock, this, &WalletView::unlockWallet);
|
||||||
|
|
||||||
|
// Show progress dialog
|
||||||
|
connect(walletModel, &WalletModel::showProgress, this, &WalletView::showProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
WalletView::~WalletView()
|
WalletView::~WalletView()
|
||||||
|
@ -99,37 +125,6 @@ void WalletView::setClientModel(ClientModel *_clientModel)
|
||||||
if (walletModel) walletModel->setClientModel(_clientModel);
|
if (walletModel) walletModel->setClientModel(_clientModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WalletView::setWalletModel(WalletModel *_walletModel)
|
|
||||||
{
|
|
||||||
this->walletModel = _walletModel;
|
|
||||||
|
|
||||||
// Put transaction list in tabs
|
|
||||||
transactionView->setModel(_walletModel);
|
|
||||||
overviewPage->setWalletModel(_walletModel);
|
|
||||||
receiveCoinsPage->setModel(_walletModel);
|
|
||||||
sendCoinsPage->setModel(_walletModel);
|
|
||||||
usedReceivingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
|
|
||||||
usedSendingAddressesPage->setModel(_walletModel ? _walletModel->getAddressTableModel() : nullptr);
|
|
||||||
|
|
||||||
if (_walletModel)
|
|
||||||
{
|
|
||||||
// Receive and pass through messages from wallet model
|
|
||||||
connect(_walletModel, &WalletModel::message, this, &WalletView::message);
|
|
||||||
|
|
||||||
// Handle changes in encryption status
|
|
||||||
connect(_walletModel, &WalletModel::encryptionStatusChanged, this, &WalletView::encryptionStatusChanged);
|
|
||||||
|
|
||||||
// Balloon pop-up for new transaction
|
|
||||||
connect(_walletModel->getTransactionTableModel(), &TransactionTableModel::rowsInserted, this, &WalletView::processNewTransaction);
|
|
||||||
|
|
||||||
// Ask for passphrase if needed
|
|
||||||
connect(_walletModel, &WalletModel::requireUnlock, this, &WalletView::unlockWallet);
|
|
||||||
|
|
||||||
// Show progress dialog
|
|
||||||
connect(_walletModel, &WalletModel::showProgress, this, &WalletView::showProgress);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
|
void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
|
||||||
{
|
{
|
||||||
// Prevent balloon-spam when initial block download is in progress
|
// Prevent balloon-spam when initial block download is in progress
|
||||||
|
|
|
@ -35,7 +35,7 @@ class WalletView : public QStackedWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit WalletView(const PlatformStyle *platformStyle, QWidget *parent);
|
explicit WalletView(WalletModel* wallet_model, const PlatformStyle* platformStyle, QWidget* parent);
|
||||||
~WalletView();
|
~WalletView();
|
||||||
|
|
||||||
/** Set the client model.
|
/** Set the client model.
|
||||||
|
@ -43,11 +43,6 @@ public:
|
||||||
*/
|
*/
|
||||||
void setClientModel(ClientModel *clientModel);
|
void setClientModel(ClientModel *clientModel);
|
||||||
WalletModel *getWalletModel() { return walletModel; }
|
WalletModel *getWalletModel() { return walletModel; }
|
||||||
/** Set the wallet model.
|
|
||||||
The wallet model represents a bitcoin wallet, and offers access to the list of transactions, address book and sending
|
|
||||||
functionality.
|
|
||||||
*/
|
|
||||||
void setWalletModel(WalletModel *walletModel);
|
|
||||||
|
|
||||||
bool handlePaymentRequest(const SendCoinsRecipient& recipient);
|
bool handlePaymentRequest(const SendCoinsRecipient& recipient);
|
||||||
|
|
||||||
|
@ -55,7 +50,12 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ClientModel *clientModel;
|
ClientModel *clientModel;
|
||||||
WalletModel *walletModel;
|
|
||||||
|
//!
|
||||||
|
//! The wallet model represents a bitcoin wallet, and offers access to
|
||||||
|
//! the list of transactions, address book and sending functionality.
|
||||||
|
//!
|
||||||
|
WalletModel* const walletModel;
|
||||||
|
|
||||||
OverviewPage *overviewPage;
|
OverviewPage *overviewPage;
|
||||||
QWidget *transactionsPage;
|
QWidget *transactionsPage;
|
||||||
|
|
Loading…
Add table
Reference in a new issue