non-static mainwindow

This commit is contained in:
tobtoht 2021-05-10 17:05:10 +02:00
parent b9995c44ec
commit cc01924858
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
14 changed files with 82 additions and 92 deletions

View file

@ -11,14 +11,14 @@
#include <QClipboard>
#include <QMessageBox>
CoinsWidget::CoinsWidget(QWidget *parent)
CoinsWidget::CoinsWidget(AppContext *ctx, QWidget *parent)
: QWidget(parent)
, ui(new Ui::CoinsWidget)
, m_ctx(ctx)
, m_headerMenu(new QMenu(this))
, m_copyMenu(new QMenu("Copy",this))
{
ui->setupUi(this);
m_ctx = MainWindow::getContext();
// header context menu
ui->coins->header()->setContextMenuPolicy(Qt::CustomContextMenu);

View file

@ -22,7 +22,7 @@ class CoinsWidget : public QWidget
Q_OBJECT
public:
explicit CoinsWidget(QWidget *parent = nullptr);
explicit CoinsWidget(AppContext *ctx, QWidget *parent = nullptr);
void setModel(CoinsModel * model, Coins * coins);
~CoinsWidget() override;
@ -54,6 +54,7 @@ private:
};
Ui::CoinsWidget *ui;
AppContext *m_ctx;
QMenu *m_contextMenu;
QMenu *m_headerMenu;
@ -68,7 +69,6 @@ private:
Coins *m_coins;
CoinsModel * m_model;
CoinsProxyModel * m_proxyModel;
AppContext *m_ctx;
void showContextMenu(const QPoint & point);
void copy(copyField field);

View file

@ -11,12 +11,11 @@
#include <QMessageBox>
ContactsWidget::ContactsWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::ContactsWidget)
ContactsWidget::ContactsWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::ContactsWidget)
{
ui->setupUi(this);
m_ctx = MainWindow::getContext();
// header context menu
ui->contacts->header()->setContextMenuPolicy(Qt::CustomContextMenu);
@ -69,9 +68,10 @@ void ContactsWidget::payTo() {
emit fillAddress(address);
}
void ContactsWidget::setModel(AddressBookModel *model)
void ContactsWidget::setModel(AddressBookModel *model, Wallet *wallet)
{
m_model = model;
m_wallet = wallet;
m_proxyModel = new AddressBookProxyModel;
m_proxyModel->setSourceModel(m_model);
ui->contacts->setModel(m_proxyModel);
@ -104,24 +104,31 @@ void ContactsWidget::showHeaderMenu(const QPoint& position)
void ContactsWidget::newContact(QString address, QString name)
{
auto * dialog = new ContactsDialog(this, address, name);
int ret = dialog->exec();
if (!ret) return;
if (!m_wallet) {
QMessageBox::warning(this, "Error", "No wallet opened.");
return;
}
address = dialog->getAddress();
name = dialog->getName();
ContactsDialog dialog{this, address, name};
int ret = dialog.exec();
if (ret != QDialog::Accepted) {
return;
}
bool addressValid = WalletManager::addressValid(address, m_ctx->currentWallet->nettype());
address = dialog.getAddress();
name = dialog.getName();
bool addressValid = WalletManager::addressValid(address, m_wallet->nettype());
if (!addressValid) {
QMessageBox::warning(this, "Invalid address", "Invalid address");
return;
}
int num_addresses = m_ctx->currentWallet->addressBook()->count();
int num_addresses = m_wallet->addressBook()->count();
QString address_entry;
QString name_entry;
for (int i=0; i<num_addresses; i++) {
m_ctx->currentWallet->addressBook()->getRow(i, [&address_entry, &name_entry](const AddressBookInfo &entry){
m_wallet->addressBook()->getRow(i, [&address_entry, &name_entry](const AddressBookInfo &entry){
address_entry = entry.address();
name_entry = entry.description();
});
@ -138,7 +145,7 @@ void ContactsWidget::newContact(QString address, QString name)
}
}
m_ctx->currentWallet->addressBook()->addRow(address, "", name);
m_wallet->addressBook()->addRow(address, "", name);
}
void ContactsWidget::deleteContact()

View file

@ -21,7 +21,7 @@ class ContactsWidget : public QWidget
public:
explicit ContactsWidget(QWidget *parent = nullptr);
void setModel(AddressBookModel * model);
void setModel(AddressBookModel *model, Wallet *wallet);
~ContactsWidget() override;
public slots:
@ -42,7 +42,6 @@ private slots:
private:
Ui::ContactsWidget *ui;
AppContext *m_ctx;
QAction *m_showFullAddressesAction;
QMenu *m_rowMenu;
@ -50,6 +49,7 @@ private:
QMenu *m_headerMenu;
AddressBookModel * m_model;
AddressBookProxyModel * m_proxyModel;
Wallet *m_wallet;
};
#endif // CONTACTSWIDGET_H

View file

@ -5,7 +5,9 @@
#include <QDebug>
Subaddress::Subaddress(Monero::Subaddress *subaddressImpl, QObject *parent)
: QObject(parent), m_subaddressImpl(subaddressImpl), m_unusedLookahead(0)
: QObject(parent)
, m_subaddressImpl(subaddressImpl)
, m_unusedLookahead(0)
{
getAll();
}

View file

@ -423,7 +423,7 @@ public:
// Passphrase entry for hardware wallets
void onPassphraseEntered(const QString &passphrase, bool enter_on_device, bool entry_abort=false);
virtual void onWalletPassphraseNeeded(bool on_device) override;
void onWalletPassphraseNeeded(bool on_device) override;
quint64 getBytesReceived() const;
quint64 getBytesSent() const;
@ -466,7 +466,7 @@ signals:
private:
Wallet(QObject * parent = nullptr);
Wallet(Monero::Wallet *w, QObject * parent = 0);
Wallet(Monero::Wallet *w, QObject * parent = nullptr);
~Wallet();
//! initializes wallet

View file

@ -32,17 +32,14 @@
#include "utils/WebsocketNotifier.h"
#include "utils/Updater.h"
MainWindow * MainWindow::pMainWindow = nullptr;
MainWindow::MainWindow(AppContext *ctx, QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_ctx(ctx)
{
pMainWindow = this;
ui->setupUi(this);
m_windowSettings = new Settings(this);
m_windowSettings = new Settings(m_ctx, this);
m_windowCalc = new CalcWindow(this);
m_splashDialog = new SplashDialog(this);
@ -71,7 +68,7 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent)
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, tickerWidget, &TickerWidget::init);
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_balanceWidget, &TickerWidget::init);
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_ctx, &AppContext::onPreferredFiatCurrencyChanged);
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, ui->sendWidget, QOverload<>::of(&SendWidget::onPreferredFiatCurrencyChanged));
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_sendWidget, QOverload<>::of(&SendWidget::onPreferredFiatCurrencyChanged));
connect(m_windowSettings, &Settings::amountPrecisionChanged, m_ctx, &AppContext::onAmountPrecisionChanged);
connect(m_windowSettings, &Settings::skinChanged, this, &MainWindow::skinChanged);
@ -192,13 +189,20 @@ void MainWindow::initWidgets() {
connect(ui->historyWidget, &HistoryWidget::viewOnBlockExplorer, this, &MainWindow::onViewOnBlockExplorer);
connect(ui->historyWidget, &HistoryWidget::resendTransaction, this, &MainWindow::onResendTransaction);
// [Send]
m_sendWidget = new SendWidget(m_ctx, this);
ui->sendWidgetLayout->addWidget(m_sendWidget);
// [Receive]
connect(ui->receiveWidget, &ReceiveWidget::showTransactions, [this](const QString &text) {
ui->historyWidget->setSearchText(text);
ui->tabWidget->setCurrentIndex(Tabs::HISTORY);
});
connect(ui->contactWidget, &ContactsWidget::fillAddress, ui->sendWidget, &SendWidget::fillAddress);
connect(ui->contactWidget, &ContactsWidget::fillAddress, m_sendWidget, &SendWidget::fillAddress);
// [Coins]
m_coinsWidget = new CoinsWidget(m_ctx, this);
ui->coinsWidgetLayout->addWidget(m_coinsWidget);
#ifdef HAS_LOCALMONERO
m_localMoneroWidget = new LocalMoneroWidget(this, m_ctx);
@ -618,11 +622,11 @@ void MainWindow::onWalletOpened() {
ui->historyWidget->setModel(m_ctx->currentWallet->historyModel(), m_ctx->currentWallet);
// contacts widget
ui->contactWidget->setModel(m_ctx->currentWallet->addressBookModel());
ui->contactWidget->setModel(m_ctx->currentWallet->addressBookModel(), m_ctx->currentWallet);
// coins page
m_ctx->currentWallet->coins()->refresh(m_ctx->currentWallet->currentSubaddressAccount());
ui->coinsWidget->setModel(m_ctx->currentWallet->coinsModel(), m_ctx->currentWallet->coins());
m_coinsWidget->setModel(m_ctx->currentWallet->coinsModel(), m_ctx->currentWallet->coins());
this->touchbarShowWallet();
this->updatePasswordIcon();
@ -784,7 +788,7 @@ void MainWindow::onTransactionCommitted(bool status, PendingTransaction *tx, con
if (status) { // success
QString body = QString("Successfully sent %1 transaction(s).").arg(txid.count());
QMessageBox::information(this, "Transactions sent", body);
ui->sendWidget->clearFields();
m_sendWidget->clearFields();
} else {
auto err = tx->errorString();
QString body = QString("Error committing transaction: %1").arg(err);
@ -994,7 +998,7 @@ void MainWindow::donateButtonClicked() {
if (donation <= 0)
donation = 0.1337;
ui->sendWidget->fill(globals::donationAddress, "Donation to the Feather development team", donation);
m_sendWidget->fill(globals::donationAddress, "Donation to the Feather development team", donation);
ui->tabWidget->setCurrentIndex(Tabs::SEND);
}
@ -1014,7 +1018,7 @@ void MainWindow::showCalcWindow() {
void MainWindow::payToMany() {
ui->tabWidget->setCurrentIndex(Tabs::SEND);
ui->sendWidget->payToMany();
m_sendWidget->payToMany();
QMessageBox::information(this, "Pay to many", "Enter a list of outputs in the 'Pay to' field.\n"
"One output per line.\n"
"Format: address, amount\n"
@ -1022,7 +1026,7 @@ void MainWindow::payToMany() {
}
void MainWindow::showSendScreen(const CCSEntry &entry) {
ui->sendWidget->fill(entry);
m_sendWidget->fill(entry);
ui->tabWidget->setCurrentIndex(Tabs::SEND);
}
@ -1064,14 +1068,6 @@ void MainWindow::importContacts() {
QMessageBox::information(this, "Contacts imported", QString("Total contacts imported: %1").arg(inserts));
}
MainWindow *MainWindow::getInstance() {
return pMainWindow;
}
AppContext *MainWindow::getContext(){
return pMainWindow->m_ctx;
}
QString MainWindow::loadStylesheet(const QString &resource) {
QFile f(resource);
if (!f.exists()) {
@ -1481,7 +1477,7 @@ void MainWindow::onWalletAboutToClose() {
ui->historyWidget->resetModel();
ui->contactWidget->resetModel();
ui->receiveWidget->resetModel();
ui->coinsWidget->resetModel();
m_coinsWidget->resetModel();
}
void MainWindow::onExportHistoryCSV(bool checked) {

View file

@ -36,6 +36,9 @@
#include "widgets/tickerwidget.h"
#include "wizard/WalletWizard.h"
#include "sendwidget.h"
#include "coinswidget.h"
#ifdef HAS_LOCALMONERO
#include "widgets/LocalMoneroWidget.h"
#endif
@ -68,8 +71,6 @@ Q_OBJECT
public:
explicit MainWindow(AppContext *ctx, QWidget *parent = nullptr);
static MainWindow *getInstance();
static AppContext *getContext();
~MainWindow() override;
enum Tabs {
@ -181,7 +182,6 @@ private:
void startupWarning();
bool autoOpenWallet();
static MainWindow * pMainWindow;
void closeEvent(QCloseEvent *event) override;
void cleanupBeforeClose();
QString loadStylesheet(const QString &resource);
@ -216,6 +216,8 @@ private:
XMRigWidget *m_xmrig = nullptr;
SplashDialog *m_splashDialog = nullptr;
SendWidget *m_sendWidget = nullptr;
CoinsWidget *m_coinsWidget = nullptr;
#ifdef HAS_LOCALMONERO
LocalMoneroWidget *m_localMoneroWidget = nullptr;
#endif

View file

@ -188,29 +188,11 @@
<number>11</number>
</property>
<item>
<widget class="SendWidget" name="sendWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<layout class="QVBoxLayout" name="sendWidgetLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
</widget>
</layout>
</item>
<item>
<widget class="Line" name="line_3">
@ -226,7 +208,14 @@
</widget>
</item>
<item>
<widget class="ContactsWidget" name="contactWidget" native="true"/>
<widget class="ContactsWidget" name="contactWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
@ -254,7 +243,7 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="CoinsWidget" name="coinsWidget" native="true"/>
<layout class="QVBoxLayout" name="coinsWidgetLayout"/>
</item>
</layout>
</widget>
@ -735,12 +724,6 @@
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>SendWidget</class>
<extends>QWidget</extends>
<header>sendwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ContactsWidget</class>
<extends>QWidget</extends>
@ -753,12 +736,6 @@
<header>receivewidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>CoinsWidget</class>
<extends>QWidget</extends>
<header>coinswidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>HistoryWidget</class>
<extends>QWidget</extends>

View file

@ -8,12 +8,12 @@
#include "globals.h"
#include "utils/AppData.h"
SendWidget::SendWidget(QWidget *parent)
SendWidget::SendWidget(AppContext *ctx, QWidget *parent)
: QWidget(parent)
, ui(new Ui::SendWidget)
, m_ctx(ctx)
{
ui->setupUi(this);
m_ctx = MainWindow::getContext();
QString amount_rx = R"(^\d{0,8}[\.,]\d{0,12}|(all)$)";
QRegExp rx;

View file

@ -17,7 +17,7 @@ class SendWidget : public QWidget
Q_OBJECT
public:
explicit SendWidget(QWidget *parent = nullptr);
explicit SendWidget(AppContext *ctx, QWidget *parent = nullptr);
void fill(const CCSEntry &entry);
void fill(const QString &address, const QString& description, double amount = 0);
void fill(double amount);

View file

@ -10,6 +10,12 @@
<height>231</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>

View file

@ -7,12 +7,12 @@
#include <QFileDialog>
Settings::Settings(QWidget *parent) :
QDialog(parent),
ui(new Ui::Settings)
Settings::Settings(AppContext *ctx, QWidget *parent)
: QDialog(parent)
, ui(new Ui::Settings)
, m_ctx(ctx)
{
ui->setupUi(this);
m_ctx = MainWindow::getContext();
this->setWindowIcon(QIcon("://assets/images/appicons/64x64.png"));

View file

@ -20,7 +20,7 @@ class Settings : public QDialog
Q_OBJECT
public:
explicit Settings(QWidget *parent = nullptr);
explicit Settings(AppContext *ctx, QWidget *parent = nullptr);
~Settings() override;
signals:
@ -49,8 +49,8 @@ private:
void setupSkinCombobox();
void setupLocalMoneroFrontendCombobox();
AppContext *m_ctx;
Ui::Settings *ui;
AppContext *m_ctx;
QStringList m_skins{"Native", "QDarkStyle", "Breeze/Dark", "Breeze/Light"};
QStringList m_dateFormats{"yyyy-MM-dd", "MM-dd-yyyy", "dd-MM-yyyy"};