diff --git a/src/recurring.cpp b/src/recurring.cpp index b8e6672..798b13d 100644 --- a/src/recurring.cpp +++ b/src/recurring.cpp @@ -108,4 +108,7 @@ QDateTime Recurring::getNextPaymentDate(Schedule s) { return nextDate; -} \ No newline at end of file +} + +// Singleton +Recurring* Recurring::instance = nullptr; \ No newline at end of file diff --git a/src/recurring.h b/src/recurring.h index 32f62ec..c105149 100644 --- a/src/recurring.h +++ b/src/recurring.h @@ -37,12 +37,15 @@ struct RecurringPaymentInfo { class Recurring { public: - Recurring() = default; + static Recurring* getInstance() { if (!instance) { instance = new Recurring(); } return instance; } - static RecurringPaymentInfo* getNewRecurringFromTx(QWidget* parent, MainWindow* main, Tx tx, RecurringPaymentInfo* rpi); + RecurringPaymentInfo* getNewRecurringFromTx(QWidget* parent, MainWindow* main, Tx tx, RecurringPaymentInfo* rpi); - static QDateTime getNextPaymentDate(Schedule s); - static void updateInfoWithTx(RecurringPaymentInfo* r, Tx tx); + QDateTime getNextPaymentDate(Schedule s); + void updateInfoWithTx(RecurringPaymentInfo* r, Tx tx); +private: + Recurring() = default; + static Recurring* instance; }; diff --git a/src/sendtab.cpp b/src/sendtab.cpp index a126aaf..ec2148a 100644 --- a/src/sendtab.cpp +++ b/src/sendtab.cpp @@ -103,7 +103,8 @@ void MainWindow::setupSendTab() { void MainWindow::editSchedule() { // Open the edit schedule dialog - RecurringPaymentInfo* recurringInfo = Recurring::getNewRecurringFromTx(this, this, createTxFromSendPage(), this->sendTxRecurringInfo); + RecurringPaymentInfo* recurringInfo = Recurring::getInstance()->getNewRecurringFromTx(this, this, + createTxFromSendPage(), this->sendTxRecurringInfo); if (recurringInfo == nullptr) { } @@ -505,7 +506,7 @@ bool MainWindow::confirmTx(Tx tx, RecurringPaymentInfo* rpi) { // Update the recurring info with the latest Tx if (rpi != nullptr) { - Recurring::updateInfoWithTx(rpi, tx); + Recurring::getInstance()->updateInfoWithTx(rpi, tx); } // Show a confirmation dialog