Move MainWindow::getContext() to constructor

ctx always exists, spares a few if else statements
This commit is contained in:
tobtoht 2020-10-11 19:15:21 +02:00
parent 892416bc51
commit 2bddad004d
7 changed files with 12 additions and 16 deletions

View file

@ -13,6 +13,7 @@ CalcWidget::CalcWidget(QWidget *parent) :
ui(new Ui::CalcWidget)
{
ui->setupUi(this);
m_ctx = MainWindow::getContext();
ui->imageExchange->setBackgroundRole(QPalette::Base);
QPixmap pm(":/assets/images/exchange.png");
@ -106,21 +107,15 @@ void CalcWidget::toComboChanged(const QString &data) {
}
void CalcWidget::initCrypto() {
if (this->m_ctx == nullptr)
this->m_ctx = MainWindow::getContext();
this->initComboBox();
}
void CalcWidget::initFiat() {
if(this->m_ctx == nullptr)
this->m_ctx = MainWindow::getContext();
this->initComboBox();
}
void CalcWidget::initComboBox() {
if(m_comboBoxInit || this->m_ctx == nullptr) return;
if(m_comboBoxInit) return;
QList<QString> marketsKeys = AppContext::prices->markets.keys();
QList<QString> ratesKeys = AppContext::prices->rates.keys();
if(marketsKeys.count() <= 0 || ratesKeys.count() <= 0) return;

View file

@ -31,7 +31,7 @@ public slots:
private:
Ui::CalcWidget *ui;
AppContext *m_ctx = nullptr;
AppContext *m_ctx;
bool m_comboBoxInit = false;
void initComboBox();
bool m_changing = false;

View file

@ -37,14 +37,14 @@ MainWindow * MainWindow::pMainWindow = nullptr;
MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
m_ctx(ctx),
m_aboutDialog(new AboutDialog(this)),
m_windowCalc(new CalcWindow(this))
m_ctx(ctx)
{
pMainWindow = this;
ui->setupUi(this);
m_windowSettings = new Settings(this);
m_aboutDialog = new AboutDialog(this);
m_windowCalc = new CalcWindow(this);
// light/dark theme
m_skins.insert("Native", "");

View file

@ -12,10 +12,9 @@ Settings::Settings(QWidget *parent) :
ui(new Ui::Settings)
{
ui->setupUi(this);
this->setWindowIcon(QIcon("://assets/images/appicons/64x64.png"));
m_ctx = MainWindow::getContext();
if(m_ctx == nullptr)
m_ctx = MainWindow::getContext();
this->setWindowIcon(QIcon("://assets/images/appicons/64x64.png"));
ui->tabWidget->setTabVisible(2, false);
ui->tabWidget->setTabVisible(4, false);

View file

@ -47,7 +47,7 @@ private:
private:
void setupSkinCombobox();
AppContext *m_ctx = nullptr;
AppContext *m_ctx;
Ui::Settings *ui;
};

View file

@ -15,6 +15,7 @@ TickerWidget::TickerWidget(QWidget *parent, QString symbol, QString title, bool
m_convertBalance(convertBalance)
{
ui->setupUi(this);
m_ctx = MainWindow::getContext();
// default values before API data
if (title == "") title = m_symbol;
@ -29,7 +30,7 @@ TickerWidget::TickerWidget(QWidget *parent, QString symbol, QString title, bool
connect(AppContext::prices, &Prices::fiatPricesUpdated, this, &TickerWidget::init);
connect(AppContext::prices, &Prices::cryptoPricesUpdated, this, &TickerWidget::init);
if (convertBalance)
connect(MainWindow::getContext(), &AppContext::balanceUpdated, this, &TickerWidget::init);
connect(m_ctx, &AppContext::balanceUpdated, this, &TickerWidget::init);
}
void TickerWidget::init() {

View file

@ -34,6 +34,7 @@ private:
Ui::TickerWidget *ui;
QString m_symbol;
bool m_convertBalance;
AppContext *m_ctx;
};
#endif // TICKERWIDGET_H