diff --git a/src/qt/sendcoinsdialog.h b/src/qt/sendcoinsdialog.h --- a/src/qt/sendcoinsdialog.h +++ b/src/qt/sendcoinsdialog.h @@ -30,8 +30,8 @@ Q_OBJECT public: - explicit SendCoinsDialog(const PlatformStyle *platformStyle, - QWidget *parent = nullptr); + SendCoinsDialog(const PlatformStyle *platformStyle, WalletModel *model, + QWidget *parent = nullptr); ~SendCoinsDialog(); void setClientModel(ClientModel *clientModel); diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -29,9 +29,9 @@ #include SendCoinsDialog::SendCoinsDialog(const PlatformStyle *_platformStyle, - QWidget *parent) + WalletModel *_model, QWidget *parent) : QDialog(parent), ui(new Ui::SendCoinsDialog), clientModel(nullptr), - model(nullptr), fNewRecipientAllowed(true), fFeeMinimized(true), + model(_model), fNewRecipientAllowed(true), fFeeMinimized(true), platformStyle(_platformStyle) { ui->setupUi(this); @@ -139,6 +139,9 @@ ui->checkBoxMinimumFee->setChecked( settings.value("fPayOnlyMinFee").toBool()); minimizeFeeSection(settings.value("fFeeSectionMinimized").toBool()); + + // Set the model properly. + setModel(model); } void SendCoinsDialog::setClientModel(ClientModel *_clientModel) { @@ -417,8 +420,7 @@ } SendCoinsEntry *SendCoinsDialog::addEntry() { - SendCoinsEntry *entry = new SendCoinsEntry(platformStyle, this); - entry->setModel(model); + SendCoinsEntry *entry = new SendCoinsEntry(platformStyle, model, this); ui->entries->addWidget(entry); connect(entry, SIGNAL(removeEntry(SendCoinsEntry *)), this, SLOT(removeEntry(SendCoinsEntry *))); diff --git a/src/qt/sendcoinsentry.h b/src/qt/sendcoinsentry.h --- a/src/qt/sendcoinsentry.h +++ b/src/qt/sendcoinsentry.h @@ -25,8 +25,8 @@ Q_OBJECT public: - explicit SendCoinsEntry(const PlatformStyle *platformStyle, - QWidget *parent = nullptr); + SendCoinsEntry(const PlatformStyle *platformStyle, WalletModel *model, + QWidget *parent = nullptr); ~SendCoinsEntry(); void setModel(WalletModel *model); diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp --- a/src/qt/sendcoinsentry.cpp +++ b/src/qt/sendcoinsentry.cpp @@ -17,8 +17,8 @@ #include SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, - QWidget *parent) - : QStackedWidget(parent), ui(new Ui::SendCoinsEntry), model(nullptr), + WalletModel *_model, QWidget *parent) + : QStackedWidget(parent), ui(new Ui::SendCoinsEntry), model(_model), platformStyle(_platformStyle) { ui->setupUi(this); @@ -32,13 +32,6 @@ ui->deleteButton_s->setIcon( platformStyle->SingleColorIcon(":/icons/remove")); - ui->messageTextLabel->setToolTip( - tr("A message that was attached to the %1 URI which will be" - " stored with the transaction for your reference. Note: " - "This message will not be sent over the Bitcoin network.") - .arg(QString::fromStdString( - model->getChainParams().CashAddrPrefix()))); - setCurrentWidget(ui->SendCoins); if (platformStyle->getUseExtraSpacing()) { @@ -63,6 +56,9 @@ connect(ui->deleteButton_s, SIGNAL(clicked()), this, SLOT(deleteClicked())); connect(ui->useAvailableBalanceButton, SIGNAL(clicked()), this, SLOT(useAvailableBalanceClicked())); + + // Set the model properly. + setModel(model); } SendCoinsEntry::~SendCoinsEntry() { @@ -94,6 +90,15 @@ void SendCoinsEntry::setModel(WalletModel *_model) { this->model = _model; + if (_model) { + ui->messageTextLabel->setToolTip( + tr("A message that was attached to the %1 URI which will be stored " + "with the transaction for your reference. Note: This message " + "will not be sent over the Bitcoin network.") + .arg(QString::fromStdString( + _model->getChainParams().CashAddrPrefix()))); + } + if (_model && _model->getOptionsModel()) { connect(_model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); diff --git a/src/qt/test/wallettests.cpp b/src/qt/test/wallettests.cpp --- a/src/qt/test/wallettests.cpp +++ b/src/qt/test/wallettests.cpp @@ -144,16 +144,15 @@ // Create widgets for sending coins and listing transactions. std::unique_ptr platformStyle( PlatformStyle::instantiate("other")); - SendCoinsDialog sendCoinsDialog(platformStyle.get()); auto node = interfaces::MakeNode(); OptionsModel optionsModel(*node); AddWallet(&wallet); WalletModel walletModel(std::move(node->getWallets().back()), *node, platformStyle.get(), &optionsModel); RemoveWallet(&wallet); - sendCoinsDialog.setModel(&walletModel); // Send two transactions, and verify they are added to transaction list. + SendCoinsDialog sendCoinsDialog(platformStyle.get(), &walletModel); TransactionTableModel *transactionTableModel = walletModel.getTransactionTableModel(); QCOMPARE(transactionTableModel->rowCount({}), 105); diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -44,10 +44,9 @@ return false; } - WalletView *walletView = new WalletView(platformStyle, this); + WalletView *walletView = new WalletView(platformStyle, walletModel, this); walletView->setBitcoinGUI(gui); walletView->setClientModel(clientModel); - walletView->setWalletModel(walletModel); walletView->showOutOfSyncWarning(bOutOfSync); /* TODO we should goto the currently selected page once dynamically adding diff --git a/src/qt/walletview.h b/src/qt/walletview.h --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -36,7 +36,8 @@ Q_OBJECT public: - WalletView(const PlatformStyle *platformStyle, QWidget *parent); + WalletView(const PlatformStyle *platformStyle, WalletModel *walletModel, + QWidget *parent); ~WalletView(); void setBitcoinGUI(BitcoinGUI *gui); diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -29,8 +29,9 @@ #include #include -WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent) - : QStackedWidget(parent), clientModel(nullptr), walletModel(nullptr), +WalletView::WalletView(const PlatformStyle *_platformStyle, + WalletModel *_walletModel, QWidget *parent) + : QStackedWidget(parent), clientModel(nullptr), walletModel(_walletModel), platformStyle(_platformStyle) { // Create tabs overviewPage = new OverviewPage(platformStyle); @@ -52,7 +53,7 @@ transactionsPage->setLayout(vbox); receiveCoinsPage = new ReceiveCoinsDialog(platformStyle); - sendCoinsPage = new SendCoinsDialog(platformStyle); + sendCoinsPage = new SendCoinsDialog(platformStyle, walletModel); usedSendingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, @@ -92,6 +93,9 @@ // Pass through messages from transactionView connect(transactionView, SIGNAL(message(QString, QString, unsigned int)), this, SIGNAL(message(QString, QString, unsigned int))); + + // Set the model properly. + setWalletModel(walletModel); } WalletView::~WalletView() {}