diff --git a/kmymoney/kmymoney.cpp b/kmymoney/kmymoney.cpp --- a/kmymoney/kmymoney.cpp +++ b/kmymoney/kmymoney.cpp @@ -47,6 +47,7 @@ #include #include #include +#include // ---------------------------------------------------------------------------- // KDE Includes @@ -108,6 +109,8 @@ #include "wizards/newuserwizard/knewuserwizard.h" #include "wizards/newaccountwizard/knewaccountwizard.h" #include "dialogs/kbalancewarning.h" +#include "widgets/kmymoneyaccountselector.h" +#include "widgets/kmymoneypayeecombo.h" #include "widgets/onlinejobmessagesview.h" #include "widgets/kmymoneymvccombo.h" diff --git a/kmymoney/widgets/CMakeLists.txt b/kmymoney/widgets/CMakeLists.txt --- a/kmymoney/widgets/CMakeLists.txt +++ b/kmymoney/widgets/CMakeLists.txt @@ -8,7 +8,7 @@ kmymoneycombo.h kmymoneymvccombo.h kmymoneycompletion.h kmymoneycurrencyselector.h kmymoneydateinput.h kmymoneyedit.h kmymoneylineedit.h kmymoneyselector.h - kmymoneytitlelabel.h kmymoneywizard.h register.h registeritem.h groupmarker.h fancydategroupmarker.h + kmymoneytitlelabel.h register.h registeritem.h groupmarker.h fancydategroupmarker.h scheduledtransaction.h selectedtransaction.h selectedtransactions.h stdtransactiondownloaded.h stdtransactionmatched.h transactioneditorcontainer.h transactionform.h transaction.h investtransaction.h stdtransaction.h @@ -97,8 +97,6 @@ kmymoneycompletion.cpp kmymoneytitlelabel.cpp kmymoneydateedit.cpp - kmymoneywizard.cpp - kmymoneywizardpage.cpp kpricetreeitem.cpp registeritem.cpp registerfilter.cpp diff --git a/kmymoney/widgets/kmymoneywizard.cpp b/kmymoney/widgets/kmymoneywizard.cpp deleted file mode 100644 --- a/kmymoney/widgets/kmymoneywizard.cpp +++ /dev/null @@ -1,339 +0,0 @@ -/*************************************************************************** - kmymoneywizard.cpp - ------------------- - copyright : (C) 2006 by Thomas Baumagrt - email : ipwizard@users.sourceforge.net - (C) 2017 by Łukasz Wojniłowicz - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -// ---------------------------------------------------------------------------- -// QT Includes - -#include -#include -#include -#include -#include -#include -#include -#include - -// ---------------------------------------------------------------------------- -// KDE Includes - -#include -#include -#include -#include - -// ---------------------------------------------------------------------------- -// Project Includes - -#include "kmymoneywizardpage.h" -#include "kmymoneytitlelabel.h" -#include "icons/icons.h" -#include "kmymoneywizard.h" - -using namespace Icons; - -KMyMoneyWizard::KMyMoneyWizard(QWidget *parent, bool modal, Qt::WindowFlags f) : - QDialog(parent, f), - m_step(0) -{ - setModal(modal); - - // enable the little grip in the right corner - setSizeGripEnabled(true); - - // create buttons - m_cancelButton = new QPushButton(i18n("&Cancel"), this); - m_backButton = new QPushButton(i18nc("Go to previous page of the wizard", "&Back"), this); - m_nextButton = new QPushButton(i18nc("Go to next page of the wizard", "&Next"), this); - m_finishButton = new QPushButton(i18nc("Finish the wizard", "&Finish"), this); - m_helpButton = new QPushButton(i18n("&Help"), this); - - if (style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons, 0, this)) { - m_backButton->setIcon(KStandardGuiItem::back(KStandardGuiItem::UseRTL).icon()); - m_nextButton->setIcon(KStandardGuiItem::forward(KStandardGuiItem::UseRTL).icon()); - m_finishButton->setIcon(QIcon::fromTheme(g_Icons[Icon::DialogOKApply])); - m_cancelButton->setIcon(QIcon::fromTheme(g_Icons[Icon::DialogCancel])); - m_helpButton->setIcon(QIcon::fromTheme(g_Icons[Icon::HelpContents])); - } - - // create button layout - m_buttonLayout = new QHBoxLayout; - m_buttonLayout->addWidget(m_helpButton); - m_buttonLayout->addStretch(1); - m_buttonLayout->addWidget(m_backButton); - m_buttonLayout->addWidget(m_nextButton); - m_buttonLayout->addWidget(m_finishButton); - m_buttonLayout->addWidget(m_cancelButton); - - // create wizard layout - m_wizardLayout = new QVBoxLayout(this); - m_wizardLayout->setContentsMargins(6, 6, 6, 6); - m_wizardLayout->setSpacing(0); - m_wizardLayout->setObjectName("wizardLayout"); - m_titleLabel = new KMyMoneyTitleLabel(this); - m_titleLabel->setObjectName("titleLabel"); - m_wizardLayout->addWidget(m_titleLabel); - - QHBoxLayout* hboxLayout = new QHBoxLayout; - hboxLayout->setContentsMargins(0, 0, 0, 0); - hboxLayout->setSpacing(6); - hboxLayout->setObjectName("hboxLayout"); - - // create stage layout and frame - m_stepFrame = new QFrame(this); - m_stepFrame->setObjectName("stepFrame"); - QPalette palette = m_stepFrame->palette(); - palette.setColor(m_stepFrame->backgroundRole(), KColorScheme::NormalText); - m_stepFrame->setPalette(palette); - m_stepLayout = new QVBoxLayout(m_stepFrame); - m_stepLayout->setContentsMargins(11, 11, 11, 11); - m_stepLayout->setSpacing(6); - m_stepLayout->setObjectName("stepLayout"); - m_stepLayout->addWidget(new QLabel(QString(), m_stepFrame)); - m_stepLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding)); - m_stepLabel = new QLabel(m_stepFrame); - m_stepLabel->setAlignment(Qt::AlignHCenter); - m_stepLayout->addWidget(m_stepLabel); - hboxLayout->addWidget(m_stepFrame); - - m_stepPalette = m_stepLabel->palette(); - - // add a vertical line between the stepFrame and the pages - QFrame* line = new QFrame(this); - line->setObjectName("line"); - line->setFrameShadow(QFrame::Sunken); - line->setFrameShape(QFrame::VLine); - hboxLayout->addWidget(line); - - // create page layout - m_pageLayout = new QVBoxLayout; - m_pageLayout->setContentsMargins(0, 0, 0, 0); - m_pageLayout->setSpacing(6); - m_pageLayout->setObjectName("pageLayout"); - - // the page will be inserted later dynamically above this line - line = new QFrame(this); - line->setObjectName("line"); - line->setFrameShadow(QFrame::Sunken); - line->setFrameShape(QFrame::HLine); - m_pageLayout->addWidget(line); - m_pageLayout->addLayout(m_buttonLayout); - - // now glue everything together - hboxLayout->addLayout(m_pageLayout); - m_wizardLayout->addLayout(hboxLayout); - - resize(QSize(670, 550).expandedTo(minimumSizeHint())); - - m_titleLabel->setText(i18n("No Title specified")); - m_titleLabel->setRightImageFile("pics/titlelabel_background.png"); - - m_finishButton->hide(); - - connect(m_backButton, &QAbstractButton::clicked, this, &KMyMoneyWizard::backButtonClicked); - connect(m_nextButton, &QAbstractButton::clicked, this, &KMyMoneyWizard::nextButtonClicked); - connect(m_cancelButton, &QAbstractButton::clicked, this, &QDialog::reject); - connect(m_finishButton, &QAbstractButton::clicked, this, &KMyMoneyWizard::accept); - connect(m_helpButton, &QAbstractButton::clicked, this, &KMyMoneyWizard::helpButtonClicked); -} - -KMyMoneyWizard::~KMyMoneyWizard() -{ -} - -void KMyMoneyWizard::setTitle(const QString& txt) -{ - m_titleLabel->setText(txt); -} - -void KMyMoneyWizard::addStep(const QString& text) -{ - QLabel* step = new QLabel(text, m_stepFrame); - step->setFrameStyle(QFrame::Panel | QFrame::Raised); - step->setAlignment(Qt::AlignHCenter); - step->setFrameStyle(QFrame::Box | QFrame::Sunken); - step->setMargin(2); - step->setPalette(m_stepPalette); - - m_steps.append(step); - m_stepLayout->insertWidget(m_steps.count(), step); - - QFont font(step->font()); - font.setBold(true); - QFontMetrics fm(font); - int w = fm.width(text) + 30; - if (m_stepFrame->minimumWidth() < w) { - m_stepFrame->setMinimumWidth(w); - } -} - -QList KMyMoneyWizard::historyPages() const -{ - return m_history; -} - -void KMyMoneyWizard::setStepHidden(int step, bool hidden) -{ - if ((step < 1) || (step > m_steps.count())) - return; - - m_steps[--step]->setHidden(hidden); - updateStepCount(); -} - -void KMyMoneyWizard::selectStep(int step) -{ - if ((step < 1) || (step > m_steps.count())) - return; - - m_step = step; - QList::iterator it_l; - QFont f = m_steps[0]->font(); - for (it_l = m_steps.begin(); it_l != m_steps.end(); ++it_l) { - f.setBold(false); - (*it_l)->setFrameStyle(QFrame::NoFrame); - if (--step == 0) { - f.setBold(true); - (*it_l)->setFrameStyle(QFrame::Box | QFrame::Sunken); - } - (*it_l)->setFont(f); - } - updateStepCount(); -} - -void KMyMoneyWizard::reselectStep() -{ - selectStep(m_step); -} - -void KMyMoneyWizard::setHelpContext(const QString& ctx) -{ - m_helpContext = ctx; -} - -void KMyMoneyWizard::updateStepCount() -{ - QList::iterator it_l; - int stepCount = 0; - int hiddenAdjust = 0; - int step = 0; - for (it_l = m_steps.begin(); it_l != m_steps.end(); ++it_l) { - if (!(*it_l)->isHidden()) - ++stepCount; - else if (step < m_step) - hiddenAdjust++; - ++step; - } - m_stepLabel->setText(i18n("Step %1 of %2", (m_step - hiddenAdjust), stepCount)); -} - -void KMyMoneyWizard::setFirstPage(KMyMoneyWizardPage* page) -{ - page->resetPage(); - m_history.clear(); - m_history.append(page); - switchPage(0); -} - -void KMyMoneyWizard::switchPage(KMyMoneyWizardPage* oldPage) -{ - if (oldPage) { - oldPage->widget()->hide(); - m_pageLayout->removeWidget(oldPage->widget()); - disconnect(oldPage->object(), SIGNAL(completeStateChanged()), this, SLOT(completeStateChanged())); - } - KMyMoneyWizardPage* newPage = m_history.back(); - if (newPage) { - m_pageLayout->insertWidget(0, newPage->widget()); - connect(newPage->object(), SIGNAL(completeStateChanged()), this, SLOT(completeStateChanged())); - newPage->widget()->show(); - selectStep(newPage->step()); - if (newPage->isLastPage()) { - m_nextButton->setDefault(false); - m_finishButton->setDefault(true); - } else { - m_finishButton->setDefault(false); - m_nextButton->setDefault(true); - } - QWidget* w = newPage->initialFocusWidget(); - if (w) - w->setFocus(); - } - completeStateChanged(); -} - -void KMyMoneyWizard::backButtonClicked() -{ - KMyMoneyWizardPage* oldPage = m_history.back(); - m_history.pop_back(); - oldPage->leavePage(); - oldPage->resetPage(); - switchPage(oldPage); -} - -void KMyMoneyWizard::nextButtonClicked() -{ - // make sure it is really complete. Some widgets only change state during focusOutEvent, - // so we just create such an animal by changing the focus to the next button and - // check again for copmpleness - m_nextButton->setFocus(); - KMyMoneyWizardPage* oldPage = m_history.back(); - if (oldPage->isComplete()) { - KMyMoneyWizardPage* newPage = oldPage->nextPage(); - m_history.append(newPage); - newPage->enterPage(); - newPage->resetPage(); - switchPage(oldPage); - } -} - -void KMyMoneyWizard::helpButtonClicked() -{ - KMyMoneyWizardPage* currentPage = m_history.back(); - QString ctx = currentPage->helpContext(); - if (ctx.isEmpty()) - ctx = m_helpContext; - KHelpClient::invokeHelp(ctx); -} - -void KMyMoneyWizard::completeStateChanged() -{ - KMyMoneyWizardPage* currentPage = m_history.back(); - bool lastPage = currentPage->isLastPage(); - - m_finishButton->setVisible(lastPage); - m_nextButton->setVisible(!lastPage); - - QPushButton* button; - - button = lastPage ? m_finishButton : m_nextButton; - - auto rc = currentPage->isComplete(); - button->setEnabled(rc); - - m_backButton->setEnabled(m_history.count() > 1); -} - -void KMyMoneyWizard::accept() -{ - // make sure it is really complete. Some widgets only change state during focusOutEvent, - // so we just create such an animal by changing the focus to the finish button and - // check again for completeness. - m_finishButton->setFocus(); - KMyMoneyWizardPage* page = m_history.back(); - if (page->isComplete()) - QDialog::accept(); -} diff --git a/kmymoney/wizards/CMakeLists.txt b/kmymoney/wizards/CMakeLists.txt --- a/kmymoney/wizards/CMakeLists.txt +++ b/kmymoney/wizards/CMakeLists.txt @@ -8,3 +8,12 @@ add_subdirectory( newinvestmentwizard ) add_subdirectory( newloanwizard ) add_subdirectory( endingbalancedlg ) + +set(kmymoneywizard_sources + kmymoneywizard.cpp + kmymoneywizardpage.cpp + ) + +add_library(kmymoneywizard STATIC ${kmymoneywizard_sources}) + +target_link_libraries(kmymoneywizard KF5::XmlGui KF5::TextWidgets) diff --git a/kmymoney/wizards/endingbalancedlg/CMakeLists.txt b/kmymoney/wizards/endingbalancedlg/CMakeLists.txt --- a/kmymoney/wizards/endingbalancedlg/CMakeLists.txt +++ b/kmymoney/wizards/endingbalancedlg/CMakeLists.txt @@ -9,11 +9,11 @@ ) set (libendingbalancedlg_a_UI - kendingbalancedlgdecl.ui - checkingstartwizardpagedecl.ui - checkingstatementinfowizardpagedecl.ui - interestchargecheckingswizardpagedecl.ui - previouspostponewizardpagedecl.ui + kendingbalancedlg.ui + checkingstartwizardpage.ui + checkingstatementinfowizardpage.ui + interestchargecheckingswizardpage.ui + previouspostponewizardpage.ui ) ki18n_wrap_ui(libendingbalancedlg_a_SOURCES ${libendingbalancedlg_a_UI} ) diff --git a/kmymoney/wizards/endingbalancedlg/checkingstartwizardpage.h b/kmymoney/wizards/endingbalancedlg/checkingstartwizardpage.h --- a/kmymoney/wizards/endingbalancedlg/checkingstartwizardpage.h +++ b/kmymoney/wizards/endingbalancedlg/checkingstartwizardpage.h @@ -29,26 +29,24 @@ // ---------------------------------------------------------------------------- // Project Includes -#include "ui_checkingstartwizardpagedecl.h" +namespace Ui { class CheckingStartWizardPage; } /** * This class implements the CheckingStart page of the * @ref KEndingBalanceDlg wizard. */ -class CheckingStartWizardPageDecl : public QWizardPage, public Ui::CheckingStartWizardPageDecl -{ -public: - CheckingStartWizardPageDecl(QWidget *parent) : QWizardPage(parent) { - setupUi(this); - } -}; -class CheckingStartWizardPage : public CheckingStartWizardPageDecl +class CheckingStartWizardPage : public QWizardPage { Q_OBJECT + Q_DISABLE_COPY(CheckingStartWizardPage) + public: - explicit CheckingStartWizardPage(QWidget *parent = 0); + explicit CheckingStartWizardPage(QWidget *parent = nullptr); + ~CheckingStartWizardPage(); +private: + Ui::CheckingStartWizardPage *ui; }; #endif diff --git a/kmymoney/wizards/endingbalancedlg/checkingstartwizardpage.cpp b/kmymoney/wizards/endingbalancedlg/checkingstartwizardpage.cpp --- a/kmymoney/wizards/endingbalancedlg/checkingstartwizardpage.cpp +++ b/kmymoney/wizards/endingbalancedlg/checkingstartwizardpage.cpp @@ -20,20 +20,24 @@ // ---------------------------------------------------------------------------- // QT Includes - // ---------------------------------------------------------------------------- // KDE Includes - // ---------------------------------------------------------------------------- // Project Includes +#include "ui_checkingstartwizardpage.h" -CheckingStartWizardPage::CheckingStartWizardPage(QWidget *parent) - : CheckingStartWizardPageDecl(parent) +CheckingStartWizardPage::CheckingStartWizardPage(QWidget *parent) : + QWizardPage(parent), + ui(new Ui::CheckingStartWizardPage) { - + ui->setupUi(this); // Register the fields with the QWizard and connect the // appropriate signals to update the "Next" button correctly +} +CheckingStartWizardPage::~CheckingStartWizardPage() +{ + delete ui; } diff --git a/kmymoney/wizards/endingbalancedlg/checkingstartwizardpagedecl.ui b/kmymoney/wizards/endingbalancedlg/checkingstartwizardpage.ui rename from kmymoney/wizards/endingbalancedlg/checkingstartwizardpagedecl.ui rename to kmymoney/wizards/endingbalancedlg/checkingstartwizardpage.ui --- a/kmymoney/wizards/endingbalancedlg/checkingstartwizardpagedecl.ui +++ b/kmymoney/wizards/endingbalancedlg/checkingstartwizardpage.ui @@ -1,7 +1,7 @@ - CheckingStartWizardPageDecl - + CheckingStartWizardPage + 6 diff --git a/kmymoney/wizards/endingbalancedlg/checkingstatementinfowizardpage.h b/kmymoney/wizards/endingbalancedlg/checkingstatementinfowizardpage.h --- a/kmymoney/wizards/endingbalancedlg/checkingstatementinfowizardpage.h +++ b/kmymoney/wizards/endingbalancedlg/checkingstatementinfowizardpage.h @@ -29,26 +29,23 @@ // ---------------------------------------------------------------------------- // Project Includes -#include "ui_checkingstatementinfowizardpagedecl.h" +namespace Ui { class CheckingStatementInfoWizardPage; } /** * This class implements the CheckingStatementInfo page of the * @ref KEndingBalanceDlg wizard. */ -class CheckingStatementInfoWizardPageDecl : public QWizardPage, public Ui::CheckingStatementInfoWizardPageDecl -{ -public: - CheckingStatementInfoWizardPageDecl(QWidget *parent) : QWizardPage(parent) { - setupUi(this); - } -}; -class CheckingStatementInfoWizardPage : public CheckingStatementInfoWizardPageDecl +class CheckingStatementInfoWizardPage : public QWizardPage { Q_OBJECT + Q_DISABLE_COPY(CheckingStatementInfoWizardPage) + public: - explicit CheckingStatementInfoWizardPage(QWidget *parent = 0); + explicit CheckingStatementInfoWizardPage(QWidget *parent = nullptr); + ~CheckingStatementInfoWizardPage(); + Ui::CheckingStatementInfoWizardPage *ui; }; #endif diff --git a/kmymoney/wizards/endingbalancedlg/checkingstatementinfowizardpage.cpp b/kmymoney/wizards/endingbalancedlg/checkingstatementinfowizardpage.cpp --- a/kmymoney/wizards/endingbalancedlg/checkingstatementinfowizardpage.cpp +++ b/kmymoney/wizards/endingbalancedlg/checkingstatementinfowizardpage.cpp @@ -20,27 +20,33 @@ // ---------------------------------------------------------------------------- // QT Includes - // ---------------------------------------------------------------------------- // KDE Includes - // ---------------------------------------------------------------------------- // Project Includes +#include "ui_checkingstatementinfowizardpage.h" -CheckingStatementInfoWizardPage::CheckingStatementInfoWizardPage(QWidget *parent) - : CheckingStatementInfoWizardPageDecl(parent) +CheckingStatementInfoWizardPage::CheckingStatementInfoWizardPage(QWidget *parent) : + QWizardPage(parent), + ui(new Ui::CheckingStatementInfoWizardPage) { - m_statementDate->setDate(QDate::currentDate()); + ui->setupUi(this); + ui->m_statementDate->setDate(QDate::currentDate()); // Register the fields with the QWizard and connect the // appropriate signals to update the "Next" button correctly - registerField("statementDate", m_statementDate, "date", SIGNAL(dateChanged(QDate))); + registerField("statementDate", ui->m_statementDate, "date", SIGNAL(dateChanged(QDate))); - registerField("endingBalance", m_endingBalance, "value", SIGNAL(textChanged())); - registerField("endingBalanceValid", m_endingBalance, "valid", SIGNAL(textChanged())); - registerField("previousBalance", m_previousBalance, "value", SIGNAL(textChanged())); - registerField("previousBalanceValid", m_previousBalance, "valid", SIGNAL(textChanged())); + registerField("endingBalance", ui->m_endingBalance, "value", SIGNAL(textChanged())); + registerField("endingBalanceValid", ui->m_endingBalance, "valid", SIGNAL(textChanged())); + registerField("previousBalance", ui->m_previousBalance, "value", SIGNAL(textChanged())); + registerField("previousBalanceValid", ui->m_previousBalance, "valid", SIGNAL(textChanged())); +} + +CheckingStatementInfoWizardPage::~CheckingStatementInfoWizardPage() +{ + delete ui; } diff --git a/kmymoney/wizards/endingbalancedlg/checkingstatementinfowizardpagedecl.ui b/kmymoney/wizards/endingbalancedlg/checkingstatementinfowizardpage.ui rename from kmymoney/wizards/endingbalancedlg/checkingstatementinfowizardpagedecl.ui rename to kmymoney/wizards/endingbalancedlg/checkingstatementinfowizardpage.ui --- a/kmymoney/wizards/endingbalancedlg/checkingstatementinfowizardpagedecl.ui +++ b/kmymoney/wizards/endingbalancedlg/checkingstatementinfowizardpage.ui @@ -1,7 +1,7 @@ - CheckingStatementInfoWizardPageDecl - + CheckingStatementInfoWizardPage + 6 diff --git a/kmymoney/wizards/endingbalancedlg/interestchargecheckingswizardpage.h b/kmymoney/wizards/endingbalancedlg/interestchargecheckingswizardpage.h --- a/kmymoney/wizards/endingbalancedlg/interestchargecheckingswizardpage.h +++ b/kmymoney/wizards/endingbalancedlg/interestchargecheckingswizardpage.h @@ -29,31 +29,28 @@ // ---------------------------------------------------------------------------- // Project Includes -#include "ui_interestchargecheckingswizardpagedecl.h" +namespace Ui { class InterestChargeCheckingsWizardPage; } /** * This class implements the InterestChargeCheckings page of the * @ref KEndingBalanceDlg wizard. */ -class InterestChargeCheckingsWizardPageDecl : public QWizardPage, public Ui::InterestChargeCheckingsWizardPageDecl -{ -public: - InterestChargeCheckingsWizardPageDecl(QWidget *parent) : QWizardPage(parent) { - setupUi(this); - } -}; -class InterestChargeCheckingsWizardPage : public InterestChargeCheckingsWizardPageDecl +class InterestChargeCheckingsWizardPage : public QWizardPage { Q_OBJECT + Q_DISABLE_COPY(InterestChargeCheckingsWizardPage) + public: - explicit InterestChargeCheckingsWizardPage(QWidget *parent = 0); + explicit InterestChargeCheckingsWizardPage(QWidget *parent = nullptr); + ~InterestChargeCheckingsWizardPage(); /** * Overload the isComplete function to control the Next button */ bool isComplete() const; + Ui::InterestChargeCheckingsWizardPage *ui; }; #endif diff --git a/kmymoney/wizards/endingbalancedlg/interestchargecheckingswizardpage.cpp b/kmymoney/wizards/endingbalancedlg/interestchargecheckingswizardpage.cpp --- a/kmymoney/wizards/endingbalancedlg/interestchargecheckingswizardpage.cpp +++ b/kmymoney/wizards/endingbalancedlg/interestchargecheckingswizardpage.cpp @@ -20,47 +20,49 @@ // ---------------------------------------------------------------------------- // QT Includes - // ---------------------------------------------------------------------------- // KDE Includes - // ---------------------------------------------------------------------------- // Project Includes +#include "ui_interestchargecheckingswizardpage.h" -InterestChargeCheckingsWizardPage::InterestChargeCheckingsWizardPage(QWidget *parent) - : InterestChargeCheckingsWizardPageDecl(parent) +InterestChargeCheckingsWizardPage::InterestChargeCheckingsWizardPage(QWidget *parent) : + QWizardPage(parent), + ui(new Ui::InterestChargeCheckingsWizardPage) { - + ui->setupUi(this); // Register the fields with the QWizard and connect the // appropriate signals to update the "Next" button correctly - registerField("interestDateEdit", m_interestDateEdit, "date", SIGNAL(dateChanged(QDate))); - registerField("chargesDateEdit", m_chargesDateEdit, "date", SIGNAL(dateChanged(QDate))); + registerField("interestDateEdit", ui->m_interestDateEdit, "date", SIGNAL(dateChanged(QDate))); + registerField("chargesDateEdit", ui->m_chargesDateEdit, "date", SIGNAL(dateChanged(QDate))); - registerField("interestEdit", m_interestEdit, "value", SIGNAL(textChanged())); - registerField("interestEditValid", m_interestEdit, "valid", SIGNAL(textChanged())); - registerField("chargesEdit", m_chargesEdit, "value", SIGNAL(textChanged())); - registerField("chargesEditValid", m_chargesEdit, "valid", SIGNAL(textChanged())); + registerField("interestEdit", ui->m_interestEdit, "value", SIGNAL(textChanged())); + registerField("interestEditValid", ui->m_interestEdit, "valid", SIGNAL(textChanged())); + registerField("chargesEdit", ui->m_chargesEdit, "value", SIGNAL(textChanged())); + registerField("chargesEditValid", ui->m_chargesEdit, "valid", SIGNAL(textChanged())); - registerField("interestCategoryEdit", m_interestCategoryEdit, "selectedItem", SIGNAL(itemSelected(QString))); - registerField("chargesCategoryEdit", m_chargesCategoryEdit, "selectedItem", SIGNAL(itemSelected(QString))); + registerField("interestCategoryEdit", ui->m_interestCategoryEdit, "selectedItem", SIGNAL(itemSelected(QString))); + registerField("chargesCategoryEdit", ui->m_chargesCategoryEdit, "selectedItem", SIGNAL(itemSelected(QString))); - registerField("payeeEdit", m_payeeEdit, "selectedItem", SIGNAL(itemSelected(QString))); - - connect(m_interestEdit, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged())); - connect(m_interestCategoryEdit, SIGNAL(editTextChanged(QString)), this, SIGNAL(completeChanged())); - connect(m_chargesEdit, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged())); - connect(m_chargesCategoryEdit, SIGNAL(editTextChanged(QString)), this, SIGNAL(completeChanged())); + registerField("payeeEdit", ui->m_payeeEdit, "selectedItem", SIGNAL(itemSelected(QString))); + connect(ui->m_interestEdit, &KMyMoneyEdit::textChanged, this, &QWizardPage::completeChanged); + connect(ui->m_interestCategoryEdit, &QComboBox::editTextChanged, this, &QWizardPage::completeChanged); + connect(ui->m_chargesEdit, &KMyMoneyEdit::textChanged, this, &QWizardPage::completeChanged); + connect(ui->m_chargesCategoryEdit, &QComboBox::editTextChanged, this, &QWizardPage::completeChanged); +} +InterestChargeCheckingsWizardPage::~InterestChargeCheckingsWizardPage() +{ + delete ui; } bool InterestChargeCheckingsWizardPage::isComplete() const { - int cnt1, cnt2; - cnt1 = !m_interestEdit->value().isZero() + !m_interestCategoryEdit->selectedItem().isEmpty(); - cnt2 = !m_chargesEdit->value().isZero() + !m_chargesCategoryEdit->selectedItem().isEmpty(); + auto cnt1 = !ui->m_interestEdit->value().isZero() + !ui->m_interestCategoryEdit->selectedItem().isEmpty(); + auto cnt2 = !ui->m_chargesEdit->value().isZero() + !ui->m_chargesCategoryEdit->selectedItem().isEmpty(); if (cnt1 == 1 || cnt2 == 1) return false; diff --git a/kmymoney/wizards/endingbalancedlg/interestchargecheckingswizardpagedecl.ui b/kmymoney/wizards/endingbalancedlg/interestchargecheckingswizardpage.ui rename from kmymoney/wizards/endingbalancedlg/interestchargecheckingswizardpagedecl.ui rename to kmymoney/wizards/endingbalancedlg/interestchargecheckingswizardpage.ui --- a/kmymoney/wizards/endingbalancedlg/interestchargecheckingswizardpagedecl.ui +++ b/kmymoney/wizards/endingbalancedlg/interestchargecheckingswizardpage.ui @@ -1,7 +1,7 @@ - InterestChargeCheckingsWizardPageDecl - + InterestChargeCheckingsWizardPage + Interest / Charges diff --git a/kmymoney/wizards/endingbalancedlg/kendingbalancedlg.h b/kmymoney/wizards/endingbalancedlg/kendingbalancedlg.h --- a/kmymoney/wizards/endingbalancedlg/kendingbalancedlg.h +++ b/kmymoney/wizards/endingbalancedlg/kendingbalancedlg.h @@ -28,12 +28,9 @@ // ---------------------------------------------------------------------------- // Project Includes -#include "ui_kendingbalancedlgdecl.h" - -#include "mymoneyaccount.h" - class QDate; +class MyMoneyMoney; class MyMoneyAccount; class MyMoneyTransaction; @@ -45,32 +42,27 @@ * * @author Thomas Baumgart */ -class KEndingBalanceDlgDecl : public QWizard, public Ui::KEndingBalanceDlgDecl -{ -public: - KEndingBalanceDlgDecl(QWidget *parent) : QWizard(parent) { - setupUi(this); - } -}; -class KEndingBalanceDlg : public KEndingBalanceDlgDecl + +class KEndingBalanceDlgPrivate; +class KEndingBalanceDlg : public QWizard { Q_OBJECT + Q_DISABLE_COPY(KEndingBalanceDlg) + public: enum { Page_CheckingStart, Page_PreviousPostpone, Page_CheckingStatementInfo, Page_InterestChargeCheckings }; - explicit KEndingBalanceDlg(const MyMoneyAccount& account, QWidget *parent = 0); + explicit KEndingBalanceDlg(const MyMoneyAccount& account, QWidget *parent = nullptr); ~KEndingBalanceDlg(); - const MyMoneyMoney endingBalance() const; - const MyMoneyMoney previousBalance() const; - const QDate statementDate() const { - return field("statementDate").toDate(); - }; + MyMoneyMoney endingBalance() const; + MyMoneyMoney previousBalance() const; + QDate statementDate() const; - const MyMoneyTransaction interestTransaction(); - const MyMoneyTransaction chargeTransaction(); + MyMoneyTransaction interestTransaction(); + MyMoneyTransaction chargeTransaction(); /** * This method returns the id of the next page in the wizard. @@ -82,7 +74,7 @@ protected: bool createTransaction(MyMoneyTransaction& t, const int sign, const MyMoneyMoney& amount, const QString& category, const QDate& date); - const MyMoneyMoney adjustedReturnValue(const MyMoneyMoney& v) const; + MyMoneyMoney adjustedReturnValue(const MyMoneyMoney& v) const; void createCategory(const QString& txt, QString& id, const MyMoneyAccount& parent); protected slots: @@ -105,10 +97,8 @@ void createCategory(MyMoneyAccount& acc, const MyMoneyAccount& parent); private: - /// \internal d-pointer class. - class Private; - /// \internal d-pointer instance. - Private* const d; + KEndingBalanceDlgPrivate * const d_ptr; + Q_DECLARE_PRIVATE(KEndingBalanceDlg) }; #endif diff --git a/kmymoney/wizards/endingbalancedlg/kendingbalancedlg.cpp b/kmymoney/wizards/endingbalancedlg/kendingbalancedlg.cpp --- a/kmymoney/wizards/endingbalancedlg/kendingbalancedlg.cpp +++ b/kmymoney/wizards/endingbalancedlg/kendingbalancedlg.cpp @@ -34,6 +34,11 @@ // ---------------------------------------------------------------------------- // Project Includes +#include "ui_kendingbalancedlg.h" +#include "ui_checkingstatementinfowizardpage.h" +#include "ui_interestchargecheckingswizardpage.h" + +#include "mymoneymoney.h" #include "mymoneyutils.h" #include "kmymoneyedit.h" #include "mymoneysplit.h" @@ -50,13 +55,24 @@ #include "kcurrencycalculator.h" #include "kmymoneysettings.h" -class KEndingBalanceDlg::Private +class KEndingBalanceDlgPrivate { + Q_DISABLE_COPY(KEndingBalanceDlgPrivate) + public: - explicit Private(int numPages) - : m_pages(numPages, true) {} + KEndingBalanceDlgPrivate(int numPages) : + ui(new Ui::KEndingBalanceDlg), + m_pages(numPages, true) + { + } + + ~KEndingBalanceDlgPrivate() + { + delete ui; + } + Ui::KEndingBalanceDlg *ui; MyMoneyTransaction m_tInterest; MyMoneyTransaction m_tCharges; MyMoneyAccount m_account; @@ -65,9 +81,10 @@ }; KEndingBalanceDlg::KEndingBalanceDlg(const MyMoneyAccount& account, QWidget *parent) : - KEndingBalanceDlgDecl(parent), - d(new Private(Page_InterestChargeCheckings + 1)) + QWizard(parent), + d_ptr(new KEndingBalanceDlgPrivate(Page_InterestChargeCheckings + 1)) { + Q_D(KEndingBalanceDlg); setModal(true); QString value; MyMoneyMoney endBalance, startBalance; @@ -76,7 +93,7 @@ MyMoneySecurity currency = MyMoneyFile::instance()->security(account.currencyId()); //FIXME: port - m_statementInfoPageCheckings->m_enterInformationLabel->setText(QString("") + i18n("Please enter the following fields with the information as you find them on your statement. Make sure to enter all values in %1.", currency.name()) + QString("")); + d->ui->m_statementInfoPageCheckings->ui->m_enterInformationLabel->setText(QString("") + i18n("Please enter the following fields with the information as you find them on your statement. Make sure to enter all values in %1.", currency.name()) + QString("")); // If the previous reconciliation was postponed, // we show a different first page @@ -96,7 +113,7 @@ } else { d->m_pages.clearBit(Page_CheckingStart); d->m_pages.clearBit(Page_InterestChargeCheckings); - //removePage(m_interestChargeCheckings); + //removePage(d->ui->m_interestChargeCheckings); // make sure, we show the correct start page setStartId(Page_PreviousPostpone); @@ -109,33 +126,33 @@ endBalance = MyMoneyMoney(value) * factor; //FIXME: port - m_statementInfoPageCheckings->m_previousBalance->setValue(startBalance); - m_statementInfoPageCheckings->m_endingBalance->setValue(endBalance); + d->ui->m_statementInfoPageCheckings->ui->m_previousBalance->setValue(startBalance); + d->ui->m_statementInfoPageCheckings->ui->m_endingBalance->setValue(endBalance); } // We don't need to add the default into the list (see ::help() why) // m_helpAnchor[m_startPageCheckings] = QString(QString()); - d->m_helpAnchor[m_interestChargeCheckings] = QString("details.reconcile.wizard.interest"); - d->m_helpAnchor[m_statementInfoPageCheckings] = QString("details.reconcile.wizard.statement"); + d->m_helpAnchor[d->ui->m_interestChargeCheckings] = QString("details.reconcile.wizard.interest"); + d->m_helpAnchor[d->ui->m_statementInfoPageCheckings] = QString("details.reconcile.wizard.statement"); value = account.value("statementDate"); if (!value.isEmpty()) setField("statementDate", QDate::fromString(value, Qt::ISODate)); //FIXME: port - m_statementInfoPageCheckings->m_lastStatementDate->setText(QString()); + d->ui->m_statementInfoPageCheckings->ui->m_lastStatementDate->setText(QString()); if (account.lastReconciliationDate().isValid()) { - m_statementInfoPageCheckings->m_lastStatementDate->setText(i18n("Last reconciled statement: %1", QLocale().toString(account.lastReconciliationDate()))); + d->ui->m_statementInfoPageCheckings->ui->m_lastStatementDate->setText(i18n("Last reconciled statement: %1", QLocale().toString(account.lastReconciliationDate()))); } // connect the signals with the slots - connect(MyMoneyFile::instance(), SIGNAL(dataChanged()), this, SLOT(slotReloadEditWidgets())); - connect(m_statementInfoPageCheckings->m_statementDate, SIGNAL(dateChanged(QDate)), this, SLOT(slotUpdateBalances())); - connect(m_interestChargeCheckings->m_interestCategoryEdit, SIGNAL(createItem(QString,QString&)), this, SLOT(slotCreateInterestCategory(QString,QString&))); - connect(m_interestChargeCheckings->m_chargesCategoryEdit, SIGNAL(createItem(QString,QString&)), this, SLOT(slotCreateChargesCategory(QString,QString&))); - connect(m_interestChargeCheckings->m_payeeEdit, SIGNAL(createItem(QString,QString&)), this, SIGNAL(createPayee(QString,QString&))); + connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &KEndingBalanceDlg::slotReloadEditWidgets); + connect(d->ui->m_statementInfoPageCheckings->ui->m_statementDate, &KMyMoneyDateInput::dateChanged, this, &KEndingBalanceDlg::slotUpdateBalances); + connect(d->ui->m_interestChargeCheckings->ui->m_interestCategoryEdit, &KMyMoneyCombo::createItem, this, &KEndingBalanceDlg::slotCreateInterestCategory); + connect(d->ui->m_interestChargeCheckings->ui->m_chargesCategoryEdit, &KMyMoneyCombo::createItem, this, &KEndingBalanceDlg::slotCreateChargesCategory); + connect(d->ui->m_interestChargeCheckings->ui->m_payeeEdit, &KMyMoneyMVCCombo::createItem, this, &KEndingBalanceDlg::createPayee); - KMyMoneyMVCCombo::setSubstringSearchForChildren(m_interestChargeCheckings, !KMyMoneySettings::stringMatchFromStart()); + KMyMoneyMVCCombo::setSubstringSearchForChildren(d->ui->m_interestChargeCheckings, !KMyMoneySettings::stringMatchFromStart()); slotReloadEditWidgets(); @@ -160,11 +177,13 @@ KEndingBalanceDlg::~KEndingBalanceDlg() { + Q_D(KEndingBalanceDlg); delete d; } void KEndingBalanceDlg::slotUpdateBalances() { + Q_D(KEndingBalanceDlg); MYMONEYTRACER(tracer); // determine the beginning balance and ending balance based on the following @@ -190,7 +209,7 @@ it = transactionList.constBegin(); if (it != transactionList.constEnd()) { oldestTransactionDate = (*it).first.postDate(); - m_statementInfoPageCheckings->m_oldestTransactionDate->setText(i18n("Oldest unmarked transaction: %1", QLocale().toString(oldestTransactionDate))); + d->ui->m_statementInfoPageCheckings->ui->m_oldestTransactionDate->setText(i18n("Oldest unmarked transaction: %1", QLocale().toString(oldestTransactionDate))); } filter.addState((int)eMyMoney::TransactionFilter::State::Cleared); @@ -233,8 +252,8 @@ } } //FIXME: port - m_statementInfoPageCheckings->m_previousBalance->setValue(startBalance); - m_statementInfoPageCheckings->m_endingBalance->setValue(endBalance); + d->ui->m_statementInfoPageCheckings->ui->m_previousBalance->setValue(startBalance); + d->ui->m_statementInfoPageCheckings->ui->m_endingBalance->setValue(endBalance); tracer.printf("total balance = %s", qPrintable(endBalance.formatMoney(QString(), 2))); tracer.printf("start balance = %s", qPrintable(startBalance.formatMoney(QString(), 2))); @@ -244,9 +263,10 @@ void KEndingBalanceDlg::accept() { + Q_D(KEndingBalanceDlg); if ((!field("interestEditValid").toBool() || createTransaction(d->m_tInterest, -1, field("interestEdit").value(), field("interestCategoryEdit").toString(), field("interestDateEdit").toDate())) && (!field("chargesEditValid").toBool() || createTransaction(d->m_tCharges, 1, field("chargesEdit").value(), field("chargesCategoryEdit").toString(), field("chargesDateEdit").toDate()))) - KEndingBalanceDlgDecl::accept(); + QWizard::accept(); } void KEndingBalanceDlg::slotCreateInterestCategory(const QString& txt, QString& id) @@ -269,23 +289,32 @@ id = acc.id(); } -const MyMoneyMoney KEndingBalanceDlg::endingBalance() const +MyMoneyMoney KEndingBalanceDlg::endingBalance() const +{ + Q_D(const KEndingBalanceDlg); + return adjustedReturnValue(d->ui->m_statementInfoPageCheckings->ui->m_endingBalance->value()); +} + +MyMoneyMoney KEndingBalanceDlg::previousBalance() const { - return adjustedReturnValue(m_statementInfoPageCheckings->m_endingBalance->value()); + Q_D(const KEndingBalanceDlg); + return adjustedReturnValue(d->ui->m_statementInfoPageCheckings->ui->m_previousBalance->value()); } -const MyMoneyMoney KEndingBalanceDlg::previousBalance() const +QDate KEndingBalanceDlg::statementDate() const { - return adjustedReturnValue(m_statementInfoPageCheckings->m_previousBalance->value()); + return field("statementDate").toDate(); } -const MyMoneyMoney KEndingBalanceDlg::adjustedReturnValue(const MyMoneyMoney& v) const +MyMoneyMoney KEndingBalanceDlg::adjustedReturnValue(const MyMoneyMoney& v) const { + Q_D(const KEndingBalanceDlg); return d->m_account.accountGroup() == eMyMoney::Account::Liability ? -v : v; } void KEndingBalanceDlg::slotReloadEditWidgets() { + Q_D(KEndingBalanceDlg); QString payeeId, interestId, chargesId; // keep current selected items @@ -295,15 +324,15 @@ // load the payee and category widgets with data from the engine //FIXME: port - m_interestChargeCheckings->m_payeeEdit->loadPayees(MyMoneyFile::instance()->payeeList()); + d->ui->m_interestChargeCheckings->ui->m_payeeEdit->loadPayees(MyMoneyFile::instance()->payeeList()); // a user request to show all categories in both selectors due to a valid use case. AccountSet aSet; aSet.addAccountGroup(eMyMoney::Account::Expense); aSet.addAccountGroup(eMyMoney::Account::Income); //FIXME: port - aSet.load(m_interestChargeCheckings->m_interestCategoryEdit->selector()); - aSet.load(m_interestChargeCheckings->m_chargesCategoryEdit->selector()); + aSet.load(d->ui->m_interestChargeCheckings->ui->m_interestCategoryEdit->selector()); + aSet.load(d->ui->m_interestChargeCheckings->ui->m_chargesCategoryEdit->selector()); // reselect currently selected items if (!payeeId.isEmpty()) @@ -314,18 +343,21 @@ setField("chargesCategoryEdit", chargesId); } -const MyMoneyTransaction KEndingBalanceDlg::interestTransaction() +MyMoneyTransaction KEndingBalanceDlg::interestTransaction() { + Q_D(KEndingBalanceDlg); return d->m_tInterest; } -const MyMoneyTransaction KEndingBalanceDlg::chargeTransaction() +MyMoneyTransaction KEndingBalanceDlg::chargeTransaction() { + Q_D(KEndingBalanceDlg); return d->m_tCharges; } bool KEndingBalanceDlg::createTransaction(MyMoneyTransaction &t, const int sign, const MyMoneyMoney& amount, const QString& category, const QDate& date) { + Q_D(KEndingBalanceDlg); t = MyMoneyTransaction(); if (category.isEmpty() || !date.isValid()) @@ -371,6 +403,7 @@ void KEndingBalanceDlg::help() { + Q_D(KEndingBalanceDlg); QString anchor = d->m_helpAnchor[currentPage()]; if (anchor.isEmpty()) anchor = QString("details.reconcile.whatis"); @@ -380,6 +413,7 @@ int KEndingBalanceDlg::nextId() const { + Q_D(const KEndingBalanceDlg); // Starting from the current page, look for the first enabled page // and return that value // If the end of the list is encountered first, then return -1. diff --git a/kmymoney/wizards/endingbalancedlg/kendingbalancedlgdecl.ui b/kmymoney/wizards/endingbalancedlg/kendingbalancedlg.ui rename from kmymoney/wizards/endingbalancedlg/kendingbalancedlgdecl.ui rename to kmymoney/wizards/endingbalancedlg/kendingbalancedlg.ui --- a/kmymoney/wizards/endingbalancedlg/kendingbalancedlgdecl.ui +++ b/kmymoney/wizards/endingbalancedlg/kendingbalancedlg.ui @@ -1,7 +1,7 @@ - KEndingBalanceDlgDecl - + KEndingBalanceDlg + 0 diff --git a/kmymoney/wizards/endingbalancedlg/previouspostponewizardpage.h b/kmymoney/wizards/endingbalancedlg/previouspostponewizardpage.h --- a/kmymoney/wizards/endingbalancedlg/previouspostponewizardpage.h +++ b/kmymoney/wizards/endingbalancedlg/previouspostponewizardpage.h @@ -29,26 +29,23 @@ // ---------------------------------------------------------------------------- // Project Includes -#include "ui_previouspostponewizardpagedecl.h" +namespace Ui { class PreviousPostponeWizardPage; } /** * This class implements the PreviousPostpone page of the * @ref KEndingBalanceDlg wizard. */ -class PreviousPostponeWizardPageDecl : public QWizardPage, public Ui::PreviousPostponeWizardPageDecl -{ -public: - PreviousPostponeWizardPageDecl(QWidget *parent) : QWizardPage(parent) { - setupUi(this); - } -}; -class PreviousPostponeWizardPage : public PreviousPostponeWizardPageDecl +class PreviousPostponeWizardPage : public QWizardPage { Q_OBJECT + Q_DISABLE_COPY(PreviousPostponeWizardPage) + public: - explicit PreviousPostponeWizardPage(QWidget *parent = 0); + explicit PreviousPostponeWizardPage(QWidget *parent = nullptr); + ~PreviousPostponeWizardPage(); + Ui::PreviousPostponeWizardPage *ui; }; #endif diff --git a/kmymoney/wizards/endingbalancedlg/previouspostponewizardpage.cpp b/kmymoney/wizards/endingbalancedlg/previouspostponewizardpage.cpp --- a/kmymoney/wizards/endingbalancedlg/previouspostponewizardpage.cpp +++ b/kmymoney/wizards/endingbalancedlg/previouspostponewizardpage.cpp @@ -20,20 +20,25 @@ // ---------------------------------------------------------------------------- // QT Includes - // ---------------------------------------------------------------------------- // KDE Includes - // ---------------------------------------------------------------------------- // Project Includes +#include "ui_previouspostponewizardpage.h" -PreviousPostponeWizardPage::PreviousPostponeWizardPage(QWidget *parent) - : PreviousPostponeWizardPageDecl(parent) +PreviousPostponeWizardPage::PreviousPostponeWizardPage(QWidget *parent) : + QWizardPage(parent), + ui(new Ui::PreviousPostponeWizardPage) { - + ui->setupUi(this); // Register the fields with the QWizard and connect the // appropriate signals to update the "Next" button correctly } + +PreviousPostponeWizardPage::~PreviousPostponeWizardPage() +{ + delete ui; +} diff --git a/kmymoney/wizards/endingbalancedlg/previouspostponewizardpagedecl.ui b/kmymoney/wizards/endingbalancedlg/previouspostponewizardpage.ui rename from kmymoney/wizards/endingbalancedlg/previouspostponewizardpagedecl.ui rename to kmymoney/wizards/endingbalancedlg/previouspostponewizardpage.ui --- a/kmymoney/wizards/endingbalancedlg/previouspostponewizardpagedecl.ui +++ b/kmymoney/wizards/endingbalancedlg/previouspostponewizardpage.ui @@ -1,7 +1,7 @@ - PreviousPostponeWizardPageDecl - + PreviousPostponeWizardPage + 6 diff --git a/kmymoney/widgets/kmymoneywizard.h b/kmymoney/wizards/kmymoneywizard.h rename from kmymoney/widgets/kmymoneywizard.h rename to kmymoney/wizards/kmymoneywizard.h --- a/kmymoney/widgets/kmymoneywizard.h +++ b/kmymoney/wizards/kmymoneywizard.h @@ -140,6 +140,7 @@ * @note The implementation of this class is heavily based on ideas found at * http://doc.trolltech.com/4.1/dialogs-complexwizard.html */ +class KMyMoneyWizardPrivate; class KMyMoneyWizard : public QDialog { friend class KMyMoneyWizardPage; @@ -202,96 +203,24 @@ void createCategory(const QString& txt, QString& id); protected: + KMyMoneyWizardPrivate * const d_ptr; + KMyMoneyWizard(KMyMoneyWizardPrivate &dd, QWidget* parent = nullptr, bool modal = false, Qt::WindowFlags f = 0); /** * Constructor (kept protected, so that one cannot create such an object directly) */ explicit KMyMoneyWizard(QWidget* parent = nullptr, bool modal = false, Qt::WindowFlags f = 0); - /** - * This method sets up the first page after creation of the object - * - * @param page pointer to first page of wizard - */ - void setFirstPage(KMyMoneyWizardPage* page); - - /** - * This method allows to hide or show a @p step. - * - * @param step step to be shown/hidden - * @param hidden hide step if true (the default) or show it if false - */ - void setStepHidden(int step, bool hidden = true); - protected slots: - virtual void accept(); + void accept() override; void completeStateChanged(); -private: - void updateStepCount(); - private slots: void backButtonClicked(); void nextButtonClicked(); void helpButtonClicked(); -protected: - /* - * The buttons - */ - QPushButton* m_cancelButton; - QPushButton* m_backButton; - QPushButton* m_nextButton; - QPushButton* m_finishButton; - QPushButton* m_helpButton; - private: - /** - * Switch to page which is currently the top of the history stack. - * @p oldPage is a pointer to the current page or 0 if no page - * is shown. - * - * @param oldPage pointer to currently displayed page - */ - void switchPage(KMyMoneyWizardPage* oldPage); - - /** - * This method selects the step given by @p step. - * - * @param step step to be selected - */ - void selectStep(int step); - - /* - * The layouts - */ - QVBoxLayout* m_wizardLayout; - QVBoxLayout* m_stepLayout; - QVBoxLayout* m_pageLayout; - QHBoxLayout* m_buttonLayout; - - /* - * Some misc. widgets required - */ - QFrame* m_stepFrame; - QLabel* m_stepLabel; - QPalette m_stepPalette; - - QList m_steps; // the list of step labels - int m_step; // the currently selected step - - /* - * The title bar - */ - KMyMoneyTitleLabel* m_titleLabel; - - /* - * The history stack - */ - QList m_history; - - QString m_helpContext; + Q_DECLARE_PRIVATE(KMyMoneyWizard) }; - - #endif diff --git a/kmymoney/wizards/kmymoneywizard.cpp b/kmymoney/wizards/kmymoneywizard.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/kmymoneywizard.cpp @@ -0,0 +1,184 @@ +/*************************************************************************** + kmymoneywizard.cpp + ------------------- + copyright : (C) 2006 by Thomas Baumagrt + email : ipwizard@users.sourceforge.net + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kmymoneywizard.h" +#include "kmymoneywizard_p.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include +#include +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "kmymoneywizardpage.h" +#include "kmymoneytitlelabel.h" +#include "icons/icons.h" + +using namespace Icons; + +KMyMoneyWizard::KMyMoneyWizard(QWidget *parent, bool modal, Qt::WindowFlags f) : + QDialog(parent, f), + d_ptr(new KMyMoneyWizardPrivate(this)) +{ + Q_D(KMyMoneyWizard); + d->init(modal); +} + +KMyMoneyWizard::KMyMoneyWizard(KMyMoneyWizardPrivate &dd, QWidget* parent, bool modal, Qt::WindowFlags f) : + QDialog(parent, f), + d_ptr(&dd) +{ + Q_D(KMyMoneyWizard); + d->init(modal); +} + +KMyMoneyWizard::~KMyMoneyWizard() +{ + Q_D(KMyMoneyWizard); + delete d; +} + +void KMyMoneyWizard::setTitle(const QString& txt) +{ + Q_D(KMyMoneyWizard); + d->m_titleLabel->setText(txt); +} + +void KMyMoneyWizard::addStep(const QString& text) +{ + Q_D(KMyMoneyWizard); + QLabel* step = new QLabel(text, d->m_stepFrame); + step->setFrameStyle(QFrame::Panel | QFrame::Raised); + step->setAlignment(Qt::AlignHCenter); + step->setFrameStyle(QFrame::Box | QFrame::Sunken); + step->setMargin(2); + step->setPalette(d->m_stepPalette); + + d->m_steps.append(step); + d->m_stepLayout->insertWidget(d->m_steps.count(), step); + + QFont font(step->font()); + font.setBold(true); + QFontMetrics fm(font); + int w = fm.width(text) + 30; + if (d->m_stepFrame->minimumWidth() < w) { + d->m_stepFrame->setMinimumWidth(w); + } +} + +QList KMyMoneyWizard::historyPages() const +{ + Q_D(const KMyMoneyWizard); + return d->m_history; +} + +void KMyMoneyWizard::reselectStep() +{ + Q_D(KMyMoneyWizard); + d->selectStep(d->m_step); +} + +void KMyMoneyWizard::setHelpContext(const QString& ctx) +{ + Q_D(KMyMoneyWizard); + d->m_helpContext = ctx; +} + +void KMyMoneyWizard::backButtonClicked() +{ + Q_D(KMyMoneyWizard); + KMyMoneyWizardPage* oldPage = d->m_history.back(); + d->m_history.pop_back(); + oldPage->leavePage(); + oldPage->resetPage(); + d->switchPage(oldPage); +} + +void KMyMoneyWizard::nextButtonClicked() +{ + Q_D(KMyMoneyWizard); + // make sure it is really complete. Some widgets only change state during focusOutEvent, + // so we just create such an animal by changing the focus to the next button and + // check again for copmpleness + d->m_nextButton->setFocus(); + KMyMoneyWizardPage* oldPage = d->m_history.back(); + if (oldPage->isComplete()) { + KMyMoneyWizardPage* newPage = oldPage->nextPage(); + d->m_history.append(newPage); + newPage->enterPage(); + newPage->resetPage(); + d->switchPage(oldPage); + } +} + +void KMyMoneyWizard::helpButtonClicked() +{ + Q_D(KMyMoneyWizard); + KMyMoneyWizardPage* currentPage = d->m_history.back(); + QString ctx = currentPage->helpContext(); + if (ctx.isEmpty()) + ctx = d->m_helpContext; + KHelpClient::invokeHelp(ctx); +} + +void KMyMoneyWizard::completeStateChanged() +{ + Q_D(KMyMoneyWizard); + KMyMoneyWizardPage* currentPage = d->m_history.back(); + bool lastPage = currentPage->isLastPage(); + + d->m_finishButton->setVisible(lastPage); + d->m_nextButton->setVisible(!lastPage); + + QPushButton* button; + + button = lastPage ? d->m_finishButton : d->m_nextButton; + + auto rc = currentPage->isComplete(); + button->setEnabled(rc); + + d->m_backButton->setEnabled(d->m_history.count() > 1); +} + +void KMyMoneyWizard::accept() +{ + Q_D(KMyMoneyWizard); + // make sure it is really complete. Some widgets only change state during focusOutEvent, + // so we just create such an animal by changing the focus to the finish button and + // check again for completeness. + d->m_finishButton->setFocus(); + KMyMoneyWizardPage* page = d->m_history.back(); + if (page->isComplete()) + QDialog::accept(); +} diff --git a/kmymoney/wizards/kmymoneywizard_p.h b/kmymoney/wizards/kmymoneywizard_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/kmymoneywizard_p.h @@ -0,0 +1,320 @@ +/*************************************************************************** + kmymoneywizard_p.h + ------------------- + copyright : (C) 2006 by Thomas Baumagrt + email : ipwizard@users.sourceforge.net + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KMYMONEYWIZARD_P_H +#define KMYMONEYWIZARD_P_H + +#include "kmymoneywizard.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include +#include +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "kmymoneywizardpage.h" +#include "kmymoneytitlelabel.h" +#include "icons/icons.h" + +using namespace Icons; + +class KMyMoneyWizardPrivate +{ + Q_DISABLE_COPY(KMyMoneyWizardPrivate) + Q_DECLARE_PUBLIC(KMyMoneyWizard) + +public: + KMyMoneyWizardPrivate(KMyMoneyWizard *qq) : + q_ptr(qq), + m_step(0) + { + } + + virtual ~KMyMoneyWizardPrivate() + { + } + + void init(bool modal) + { + Q_Q(KMyMoneyWizard); + q->setModal(modal); + + // enable the little grip in the right corner + q->setSizeGripEnabled(true); + + // create buttons + m_cancelButton = new QPushButton(i18n("&Cancel"), q); + m_backButton = new QPushButton(i18nc("Go to previous page of the wizard", "&Back"), q); + m_nextButton = new QPushButton(i18nc("Go to next page of the wizard", "&Next"), q); + m_finishButton = new QPushButton(i18nc("Finish the wizard", "&Finish"), q); + m_helpButton = new QPushButton(i18n("&Help"), q); + + if (q->style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons, 0, q)) { + m_backButton->setIcon(KStandardGuiItem::back(KStandardGuiItem::UseRTL).icon()); + m_nextButton->setIcon(KStandardGuiItem::forward(KStandardGuiItem::UseRTL).icon()); + m_finishButton->setIcon(QIcon::fromTheme(g_Icons[Icon::DialogOKApply])); + m_cancelButton->setIcon(QIcon::fromTheme(g_Icons[Icon::DialogCancel])); + m_helpButton->setIcon(QIcon::fromTheme(g_Icons[Icon::HelpContents])); + } + + // create button layout + m_buttonLayout = new QHBoxLayout; + m_buttonLayout->addWidget(m_helpButton); + m_buttonLayout->addStretch(1); + m_buttonLayout->addWidget(m_backButton); + m_buttonLayout->addWidget(m_nextButton); + m_buttonLayout->addWidget(m_finishButton); + m_buttonLayout->addWidget(m_cancelButton); + + // create wizard layout + m_wizardLayout = new QVBoxLayout(q); + m_wizardLayout->setContentsMargins(6, 6, 6, 6); + m_wizardLayout->setSpacing(0); + m_wizardLayout->setObjectName("wizardLayout"); + m_titleLabel = new KMyMoneyTitleLabel(q); + m_titleLabel->setObjectName("titleLabel"); + m_wizardLayout->addWidget(m_titleLabel); + + QHBoxLayout* hboxLayout = new QHBoxLayout; + hboxLayout->setContentsMargins(0, 0, 0, 0); + hboxLayout->setSpacing(6); + hboxLayout->setObjectName("hboxLayout"); + + // create stage layout and frame + m_stepFrame = new QFrame(q); + m_stepFrame->setObjectName("stepFrame"); + QPalette palette = m_stepFrame->palette(); + palette.setColor(m_stepFrame->backgroundRole(), KColorScheme::NormalText); + m_stepFrame->setPalette(palette); + m_stepLayout = new QVBoxLayout(m_stepFrame); + m_stepLayout->setContentsMargins(11, 11, 11, 11); + m_stepLayout->setSpacing(6); + m_stepLayout->setObjectName("stepLayout"); + m_stepLayout->addWidget(new QLabel(QString(), m_stepFrame)); + m_stepLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding)); + m_stepLabel = new QLabel(m_stepFrame); + m_stepLabel->setAlignment(Qt::AlignHCenter); + m_stepLayout->addWidget(m_stepLabel); + hboxLayout->addWidget(m_stepFrame); + + m_stepPalette = m_stepLabel->palette(); + + // add a vertical line between the stepFrame and the pages + QFrame* line = new QFrame(q); + line->setObjectName("line"); + line->setFrameShadow(QFrame::Sunken); + line->setFrameShape(QFrame::VLine); + hboxLayout->addWidget(line); + + // create page layout + m_pageLayout = new QVBoxLayout; + m_pageLayout->setContentsMargins(0, 0, 0, 0); + m_pageLayout->setSpacing(6); + m_pageLayout->setObjectName("pageLayout"); + + // the page will be inserted later dynamically above q line + line = new QFrame(q); + line->setObjectName("line"); + line->setFrameShadow(QFrame::Sunken); + line->setFrameShape(QFrame::HLine); + m_pageLayout->addWidget(line); + m_pageLayout->addLayout(m_buttonLayout); + + // now glue everything together + hboxLayout->addLayout(m_pageLayout); + m_wizardLayout->addLayout(hboxLayout); + + q->resize(QSize(670, 550).expandedTo(q->minimumSizeHint())); + + m_titleLabel->setText(i18n("No Title specified")); + m_titleLabel->setRightImageFile("pics/titlelabel_background.png"); + + m_finishButton->hide(); + + q->connect(m_backButton, &QAbstractButton::clicked, q, &KMyMoneyWizard::backButtonClicked); + q->connect(m_nextButton, &QAbstractButton::clicked, q, &KMyMoneyWizard::nextButtonClicked); + q->connect(m_cancelButton, &QAbstractButton::clicked, q, &QDialog::reject); + q->connect(m_finishButton, &QAbstractButton::clicked, q, &KMyMoneyWizard::accept); + q->connect(m_helpButton, &QAbstractButton::clicked, q, &KMyMoneyWizard::helpButtonClicked); + } + + /** + * Switch to page which is currently the top of the history stack. + * @p oldPage is a pointer to the current page or 0 if no page + * is shown. + * + * @param oldPage pointer to currently displayed page + */ + void switchPage(KMyMoneyWizardPage* oldPage) + { + Q_Q(KMyMoneyWizard); + if (oldPage) { + oldPage->widget()->hide(); + m_pageLayout->removeWidget(oldPage->widget()); + q->disconnect(oldPage->object(), SIGNAL(completeStateChanged()), q, SLOT(completeStateChanged())); + } + KMyMoneyWizardPage* newPage = m_history.back(); + if (newPage) { + m_pageLayout->insertWidget(0, newPage->widget()); + q->connect(newPage->object(), SIGNAL(completeStateChanged()), q, SLOT(completeStateChanged())); + newPage->widget()->show(); + selectStep(newPage->step()); + if (newPage->isLastPage()) { + m_nextButton->setDefault(false); + m_finishButton->setDefault(true); + } else { + m_finishButton->setDefault(false); + m_nextButton->setDefault(true); + } + QWidget* w = newPage->initialFocusWidget(); + if (w) + w->setFocus(); + } + q->completeStateChanged(); + } + + /** + * This method selects the step given by @p step. + * + * @param step step to be selected + */ + void selectStep(int step) + { + Q_Q(KMyMoneyWizard); + if ((step < 1) || (step > m_steps.count())) + return; + + m_step = step; + QList::iterator it_l; + QFont f = m_steps[0]->font(); + for (it_l = m_steps.begin(); it_l != m_steps.end(); ++it_l) { + f.setBold(false); + (*it_l)->setFrameStyle(QFrame::NoFrame); + if (--step == 0) { + f.setBold(true); + (*it_l)->setFrameStyle(QFrame::Box | QFrame::Sunken); + } + (*it_l)->setFont(f); + } + updateStepCount(); + } + + /** + * This method sets up the first page after creation of the object + * + * @param page pointer to first page of wizard + */ + void setFirstPage(KMyMoneyWizardPage* page) + { + page->resetPage(); + m_history.clear(); + m_history.append(page); + switchPage(0); + } + + /** + * This method allows to hide or show a @p step. + * + * @param step step to be shown/hidden + * @param hidden hide step if true (the default) or show it if false + */ + void setStepHidden(int step, bool hidden = true) + { + Q_Q(KMyMoneyWizard); + if ((step < 1) || (step > m_steps.count())) + return; + + m_steps[--step]->setHidden(hidden); + updateStepCount(); + } + + void updateStepCount() + { + QList::iterator it_l; + int stepCount = 0; + int hiddenAdjust = 0; + int step = 0; + for (it_l = m_steps.begin(); it_l != m_steps.end(); ++it_l) { + if (!(*it_l)->isHidden()) + ++stepCount; + else if (step < m_step) + hiddenAdjust++; + ++step; + } + m_stepLabel->setText(i18n("Step %1 of %2", (m_step - hiddenAdjust), stepCount)); + } + + KMyMoneyWizard *q_ptr; + + /* + * The buttons + */ + QPushButton* m_cancelButton; + QPushButton* m_backButton; + QPushButton* m_nextButton; + QPushButton* m_finishButton; + QPushButton* m_helpButton; + + /* + * The layouts + */ + QVBoxLayout* m_wizardLayout; + QVBoxLayout* m_stepLayout; + QVBoxLayout* m_pageLayout; + QHBoxLayout* m_buttonLayout; + + /* + * Some misc. widgets required + */ + QFrame* m_stepFrame; + QLabel* m_stepLabel; + QPalette m_stepPalette; + + QList m_steps; // the list of step labels + int m_step; // the currently selected step + + /* + * The title bar + */ + KMyMoneyTitleLabel* m_titleLabel; + + /* + * The history stack + */ + QList m_history; + + QString m_helpContext; +}; + +#endif diff --git a/kmymoney/widgets/kmymoneywizardpage.h b/kmymoney/wizards/kmymoneywizardpage.h rename from kmymoney/widgets/kmymoneywizardpage.h rename to kmymoney/wizards/kmymoneywizardpage.h --- a/kmymoney/widgets/kmymoneywizardpage.h +++ b/kmymoney/wizards/kmymoneywizardpage.h @@ -18,6 +18,8 @@ #ifndef KMYMONEYWIZARDPAGE_H #define KMYMONEYWIZARDPAGE_H +#include "kmymoneywizardpage_p.h" + // ---------------------------------------------------------------------------- // QT Includes @@ -39,7 +41,6 @@ class KMyMoneyTitleLabel; class KMyMoneyWizard; -class KMyMoneyWizardPagePrivate; class KMandatoryFieldGroup; /** @@ -139,6 +140,7 @@ * @note The implementation of this class is heavily based on ideas found at * http://doc.trolltech.com/4.1/dialogs-complexwizard.html */ +class KMyMoneyWizardPagePrivate; class KMyMoneyWizardPage { public: @@ -215,7 +217,7 @@ * by application code for signal/slot connections as well. * Other use is not foreseen. */ - QObject* object() const; + const KMyMoneyWizardPagePrivate *object() const; /** * This method returns a pointer to the widget which should @@ -236,10 +238,15 @@ virtual ~KMyMoneyWizardPage(); protected: + KMyMoneyWizardPagePrivate * const d_ptr; + + KMyMoneyWizardPage(KMyMoneyWizardPagePrivate &dd, uint step, QWidget *widget); + Q_DECLARE_PRIVATE(KMyMoneyWizardPage) + /** * Constructor (kept protected, so that one cannot create such an object directly) */ - explicit KMyMoneyWizardPage(unsigned int step, QWidget* widget); + explicit KMyMoneyWizardPage(uint step, QWidget* widget); /** * This method must be called by the implementation when the @@ -249,41 +256,6 @@ * @note If you do not override isComplete() then there is no need * to call this method. */ - void completeStateChanged() const; - -protected: - KMandatoryFieldGroup* m_mandatoryGroup; - -private: - unsigned int m_step; - QWidget* m_widget; - KMyMoneyWizardPagePrivate* const d; -}; - - -/** - * The general base class for wizard pages - * - * @author Thomas Baumgart - */ -template -class WizardPage : public KMyMoneyWizardPage -{ -public: - WizardPage(unsigned int step, QWidget* widget, T* parent) : - KMyMoneyWizardPage(step, widget), - m_wizard(parent), - m_wizardBase(parent) { - } - virtual ~WizardPage() {} - virtual KMyMoneyWizard* wizard() const { - return m_wizardBase; - } - -protected: - T* m_wizard; - KMyMoneyWizard* m_wizardBase; + void completeStateChanged(); }; - - #endif diff --git a/kmymoney/widgets/kmymoneywizardpage.cpp b/kmymoney/wizards/kmymoneywizardpage.cpp rename from kmymoney/widgets/kmymoneywizardpage.cpp rename to kmymoney/wizards/kmymoneywizardpage.cpp --- a/kmymoney/widgets/kmymoneywizardpage.cpp +++ b/kmymoney/wizards/kmymoneywizardpage.cpp @@ -16,6 +16,7 @@ ***************************************************************************/ #include "kmymoneywizardpage.h" +#include "kmymoneywizardpage_p.h" #include "kmymoneywizard_p.h" // ---------------------------------------------------------------------------- @@ -34,33 +35,37 @@ #include "kguiutils.h" #include "kmymoneywizard.h" -KMyMoneyWizardPagePrivate::KMyMoneyWizardPagePrivate(QObject* parent) : - QObject(parent) +KMyMoneyWizardPage::KMyMoneyWizardPage(uint step, QWidget* widget) : + d_ptr(new KMyMoneyWizardPagePrivate(widget)) { + Q_D(KMyMoneyWizardPage); + d->m_step = step; + d->m_widget = widget; + d->m_mandatoryGroup = new KMandatoryFieldGroup(widget); + QObject::connect(d->m_mandatoryGroup, static_cast(&KMandatoryFieldGroup::stateChanged), object(), &KMyMoneyWizardPagePrivate::completeStateChanged); + widget->hide(); } -void KMyMoneyWizardPagePrivate::emitCompleteStateChanged() -{ - emit completeStateChanged(); -} - - -KMyMoneyWizardPage::KMyMoneyWizardPage(unsigned int step, QWidget* widget) : - m_step(step), - m_widget(widget), - d(new KMyMoneyWizardPagePrivate(widget)) +KMyMoneyWizardPage::KMyMoneyWizardPage(KMyMoneyWizardPagePrivate &dd, uint step, QWidget *widget) : + d_ptr(&dd) { - m_mandatoryGroup = new KMandatoryFieldGroup(widget); - QObject::connect(m_mandatoryGroup, SIGNAL(stateChanged()), object(), SIGNAL(completeStateChanged())); + Q_D(KMyMoneyWizardPage); + d->m_step = step; + d->m_widget = widget; + d->m_mandatoryGroup = new KMandatoryFieldGroup(widget); + QObject::connect(d->m_mandatoryGroup, static_cast(&KMandatoryFieldGroup::stateChanged), object(), &KMyMoneyWizardPagePrivate::completeStateChanged); widget->hide(); } KMyMoneyWizardPage::~KMyMoneyWizardPage() { + Q_D(KMyMoneyWizardPage); + delete d; } -QObject* KMyMoneyWizardPage::object() const +const KMyMoneyWizardPagePrivate* KMyMoneyWizardPage::object() const { + Q_D(const KMyMoneyWizardPage); return d; } @@ -69,8 +74,9 @@ return nullptr; } -void KMyMoneyWizardPage::completeStateChanged() const +void KMyMoneyWizardPage::completeStateChanged() { + Q_D(KMyMoneyWizardPage); d->emitCompleteStateChanged(); } @@ -98,21 +104,24 @@ bool KMyMoneyWizardPage::isComplete() const { + Q_D(const KMyMoneyWizardPage); if (!isLastPage()) - wizard()->m_nextButton->setToolTip(i18n("Continue with next page")); + wizard()->d_func()->m_nextButton->setToolTip(i18n("Continue with next page")); else - wizard()->m_finishButton->setToolTip(i18n("Finish wizard")); - return m_mandatoryGroup->isEnabled(); + wizard()->d_func()->m_finishButton->setToolTip(i18n("Finish wizard")); + return d->m_mandatoryGroup->isEnabled(); } unsigned int KMyMoneyWizardPage::step() const { - return m_step; + Q_D(const KMyMoneyWizardPage); + return d->m_step; } QWidget* KMyMoneyWizardPage::widget() const { - return m_widget; + Q_D(const KMyMoneyWizardPage); + return d->m_widget; } QString KMyMoneyWizardPage::helpContext() const diff --git a/kmymoney/widgets/kmymoneywizard_p.h b/kmymoney/wizards/kmymoneywizardpage_p.h rename from kmymoney/widgets/kmymoneywizard_p.h rename to kmymoney/wizards/kmymoneywizardpage_p.h --- a/kmymoney/widgets/kmymoneywizard_p.h +++ b/kmymoney/wizards/kmymoneywizardpage_p.h @@ -1,5 +1,5 @@ /*************************************************************************** - kmymoneywizard_p.h + kmymoneywizardpage_p.h ------------------- copyright : (C) 2006 by Thomas Baumagrt email : ipwizard@users.sourceforge.net @@ -15,8 +15,8 @@ * * ***************************************************************************/ -#ifndef KMYMONEYWIZARD_P_H -#define KMYMONEYWIZARD_P_H +#ifndef KMYMONEYWIZARDPAGE_P_H +#define KMYMONEYWIZARDPAGE_P_H // ---------------------------------------------------------------------------- // QT Includes @@ -29,6 +29,8 @@ // ---------------------------------------------------------------------------- // Project Includes +#include "kguiutils.h" + /** * @author Thomas Baumgart (C) 2006 * @@ -37,19 +39,33 @@ * the KMyMoneyWizardPage object which cannot be * derived from QObject directly. */ + class KMyMoneyWizardPagePrivate : public QObject { - Q_OBJECT + Q_OBJECT + Q_DISABLE_COPY(KMyMoneyWizardPagePrivate) + public: - /** - * Constructor - */ - explicit KMyMoneyWizardPagePrivate(QObject* parent); + explicit KMyMoneyWizardPagePrivate(QObject* parent) : + QObject(parent) + { + } + + virtual ~KMyMoneyWizardPagePrivate() + { + } + + void emitCompleteStateChanged() + { + emit completeStateChanged(); + } - void emitCompleteStateChanged(void); + uint m_step; + QWidget *m_widget; + KMandatoryFieldGroup *m_mandatoryGroup; signals: - void completeStateChanged(void); + void completeStateChanged(void); }; #endif diff --git a/kmymoney/wizards/newaccountwizard/CMakeLists.txt b/kmymoney/wizards/newaccountwizard/CMakeLists.txt --- a/kmymoney/wizards/newaccountwizard/CMakeLists.txt +++ b/kmymoney/wizards/newaccountwizard/CMakeLists.txt @@ -2,21 +2,33 @@ set (libnewaccountwizard_a_SOURCES knewaccountwizard.cpp + kaccountsummarypage.cpp + kaccounttypepage.cpp + kbrokeragepage.cpp + kcreditcardschedulepage.cpp + kgeneralloaninfopage.cpp + khierarchypage.cpp + kinstitutionpage.cpp + kloandetailspage.cpp + kloanpaymentpage.cpp + kloanpayoutpage.cpp + kloanschedulepage.cpp + hierarchyfilterproxymodel.cpp ) set (libnewaccountwizard_a_UI - kaccountsummarypagedecl.ui kaccounttypepagedecl.ui - kbrokeragepagedecl.ui kgeneralloaninfopagedecl.ui - khierarchypagedecl.ui kinstitutionpagedecl.ui - kloandetailspagedecl.ui kloanpaymentpagedecl.ui - kloanpayoutpagedecl.ui kloanschedulepagedecl.ui kschedulepagedecl.ui + kaccountsummarypage.ui kaccounttypepage.ui + kbrokeragepage.ui kgeneralloaninfopage.ui + kgeneralloaninfopage.ui kinstitutionpage.ui + kloandetailspage.ui kloanpaymentpage.ui + kloanpayoutpage.ui kloanschedulepage.ui kcreditcardschedulepage.ui khierarchypage.ui ) ki18n_wrap_ui(libnewaccountwizard_a_SOURCES ${libnewaccountwizard_a_UI} ) add_library(newaccountwizard STATIC ${libnewaccountwizard_a_SOURCES}) # TODO: clean dependencies -target_link_libraries(newaccountwizard KF5::XmlGui KF5::Service KF5::IconThemes KF5::ConfigGui KF5::WidgetsAddons KF5::TextWidgets KF5::Completion Qt5::Widgets Qt5::Xml Qt5::Sql Alkimia::alkimia) +target_link_libraries(newaccountwizard kmymoneywizard KF5::XmlGui KF5::Service KF5::IconThemes KF5::ConfigGui KF5::WidgetsAddons KF5::TextWidgets KF5::Completion Qt5::Widgets Qt5::Xml Qt5::Sql Alkimia::alkimia) # we rely on some dialogs to be generated add_dependencies(newaccountwizard dialogs) diff --git a/kmymoney/wizards/newaccountwizard/hierarchyfilterproxymodel.h b/kmymoney/wizards/newaccountwizard/hierarchyfilterproxymodel.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/hierarchyfilterproxymodel.h @@ -0,0 +1,52 @@ +/*************************************************************************** + hierarchyfilterproxymodel.h + ------------------- + begin : Tue Sep 25 2007 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef HIERACHRYFILTERPROXYMODEL_H +#define HIERACHRYFILTERPROXYMODEL_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "accountsproxymodel.h" + + +class Wizard; +class MyMoneyInstitution; + +namespace NewAccountWizard +{ + class HierarchyFilterProxyModel : public AccountsProxyModel + { + Q_OBJECT + Q_DISABLE_COPY(HierarchyFilterProxyModel) + + public: + explicit HierarchyFilterProxyModel(QObject *parent = 0); + + protected: + bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; + bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const; + }; +} // namespace + +#endif diff --git a/kmymoney/wizards/newaccountwizard/hierarchyfilterproxymodel.cpp b/kmymoney/wizards/newaccountwizard/hierarchyfilterproxymodel.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/hierarchyfilterproxymodel.cpp @@ -0,0 +1,65 @@ +/*************************************************************************** + hierarchyfilterproxymodel.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "hierarchyfilterproxymodel.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "accountsmodel.h" +#include "accountsproxymodel.h" +#include "modelenums.h" + +namespace NewAccountWizard +{ + HierarchyFilterProxyModel::HierarchyFilterProxyModel(QObject *parent) + : AccountsProxyModel(parent) + { + } + + /** + * Filter the favorites accounts group. + */ + bool HierarchyFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const + { + if (!source_parent.isValid()) { + auto accCol = m_mdlColumns->indexOf(eAccountsModel::Column::Account); + QVariant data = sourceModel()->index(source_row, accCol, source_parent).data((int)eAccountsModel::Role::ID); + if (data.isValid() && data.toString() == AccountsModel::favoritesAccountId) + return false; + } + return AccountsProxyModel::filterAcceptsRow(source_row, source_parent); + } + + /** + * Filter all but the first column. + */ + bool HierarchyFilterProxyModel::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const + { + Q_UNUSED(source_parent) + if (source_column == 0) + return true; + return false; + } +} diff --git a/kmymoney/wizards/newaccountwizard/kaccountsummarypage.h b/kmymoney/wizards/newaccountwizard/kaccountsummarypage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kaccountsummarypage.h @@ -0,0 +1,57 @@ +/*************************************************************************** + kaccountsummarypage.h + ------------------- + begin : Tue Sep 25 2007 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTACCOUNTSUMMARYPAGE_H +#define KNEWACCOUNTACCOUNTSUMMARYPAGE_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" + +namespace NewAccountWizard +{ + class Wizard; + + class AccountSummaryPagePrivate; + class AccountSummaryPage : public QWidget, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(AccountSummaryPage) + + public: + explicit AccountSummaryPage(Wizard* parent); + ~AccountSummaryPage() override; + + void enterPage(void); + QWidget* initialFocusWidget(void) const override; + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, AccountSummaryPage) + friend class Wizard; + }; +} // namespace + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kaccountsummarypage.cpp b/kmymoney/wizards/newaccountwizard/kaccountsummarypage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kaccountsummarypage.cpp @@ -0,0 +1,229 @@ +/*************************************************************************** + kaccountsummarypage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kaccountsummarypage.h" +#include "kaccountsummarypage_p.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kaccountsummarypage.h" + +#include "kaccountsummarypage.h" +#include "kaccounttypepage.h" +#include "kbrokeragepage.h" +#include "kcreditcardschedulepage.h" +#include "kgeneralloaninfopage.h" +#include "khierarchypage.h" +#include "kinstitutionpage.h" +#include "kloandetailspage.h" +#include "kloanpaymentpage.h" +#include "kloanpayoutpage.h" +#include "kloanschedulepage.h" + +#include "kaccountsummarypage_p.h" +#include "kaccounttypepage_p.h" +#include "kbrokeragepage_p.h" +#include "kcreditcardschedulepage_p.h" +#include "kgeneralloaninfopage_p.h" +#include "khierarchypage_p.h" +#include "kinstitutionpage_p.h" +#include "kloandetailspage_p.h" +#include "kloanpaymentpage_p.h" +#include "kloanpayoutpage_p.h" +#include "kloanschedulepage_p.h" + +#include "kmymoneycategory.h" +#include "kmymoneycurrencyselector.h" +#include "kmymoneydateinput.h" +#include "kmymoneyedit.h" +#include "kmymoneyfrequencycombo.h" +#include "kmymoneygeneralcombo.h" +#include "kmymoneypayeecombo.h" +#include "knewaccountwizard.h" +#include "knewaccountwizard_p.h" +#include "mymoneyaccount.h" +#include "mymoneyenums.h" +#include "mymoneyfile.h" +#include "mymoneyinstitution.h" +#include "mymoneymoney.h" +#include "mymoneyprice.h" +#include "mymoneyschedule.h" +#include "mymoneysecurity.h" +#include "mymoneyutils.h" +#include "wizardpage.h" + +using namespace NewAccountWizard; +using namespace Icons; +using namespace eMyMoney; + +namespace NewAccountWizard +{ + AccountSummaryPage::AccountSummaryPage(Wizard* wizard) : + QWidget(wizard), + WizardPage(*new AccountSummaryPagePrivate(wizard), StepFinish, this, wizard) + { + Q_D(AccountSummaryPage); + d->ui->setupUi(this); + } + + AccountSummaryPage::~AccountSummaryPage() + { + } + + void AccountSummaryPage::enterPage() + { + Q_D(AccountSummaryPage); + MyMoneyAccount acc = d->m_wizard->account(); + MyMoneySecurity sec = d->m_wizard->d_func()->currency(); + acc.fraction(sec); + + // assign an id to the account inside the wizard which is required for a schedule + // get the schedule and clear the id again in the wizards object. + MyMoneyAccount tmp(QLatin1String("Phony-ID"), acc); + d->m_wizard->setAccount(tmp); + MyMoneySchedule sch = d->m_wizard->schedule(); + d->m_wizard->setAccount(acc); + + d->ui->m_dataList->clear(); + + // Account data + d->ui->m_dataList->setFontWeight(QFont::Bold); + d->ui->m_dataList->append(i18n("Account information")); + d->ui->m_dataList->setFontWeight(QFont::Normal); + d->ui->m_dataList->append(i18nc("Account name", "Name: %1", acc.name())); + if (!acc.isLoan()) + d->ui->m_dataList->append(i18n("Subaccount of %1", d->m_wizard->parentAccount().name())); + QString accTypeText; + if (acc.accountType() == Account::AssetLoan) + accTypeText = i18n("Loan"); + else + accTypeText = d->m_wizard->d_func()->m_accountTypePage->d_func()->ui->m_typeSelection->currentText(); + d->ui->m_dataList->append(i18n("Type: %1", accTypeText)); + + d->ui->m_dataList->append(i18n("Currency: %1", d->m_wizard->d_func()->currency().name())); + d->ui->m_dataList->append(i18n("Opening date: %1", QLocale().toString(acc.openingDate()))); + if (d->m_wizard->d_func()->currency().id() != MyMoneyFile::instance()->baseCurrency().id()) { + d->ui->m_dataList->append(i18n("Conversion rate: %1", d->m_wizard->conversionRate().rate(QString()).formatMoney(QString(), d->m_wizard->d_func()->currency().pricePrecision()))); + } + if (!acc.isLoan() || !d->m_wizard->openingBalance().isZero()) + d->ui->m_dataList->append(i18n("Opening balance: %1", MyMoneyUtils::formatMoney(d->m_wizard->openingBalance(), acc, sec))); + + if (!d->m_wizard->d_func()->m_institutionPage->institution().id().isEmpty()) { + d->ui->m_dataList->append(i18n("Institution: %1", d->m_wizard->d_func()->m_institutionPage->institution().name())); + if (!acc.number().isEmpty()) { + d->ui->m_dataList->append(i18n("Number: %1", acc.number())); + } + if (!acc.value("iban").isEmpty()) { + d->ui->m_dataList->append(i18n("IBAN: %1", acc.value("iban"))); + } + } + + if (acc.accountType() == Account::Investment) { + if (d->m_wizard->d_func()->m_brokeragepage->d_func()->ui->m_createBrokerageButton->isChecked()) { + d->ui->m_dataList->setFontWeight(QFont::Bold); + d->ui->m_dataList->append(i18n("Brokerage Account")); + d->ui->m_dataList->setFontWeight(QFont::Normal); + + d->ui->m_dataList->append(i18nc("Account name", "Name: %1 (Brokerage)", acc.name())); + d->ui->m_dataList->append(i18n("Currency: %1", d->m_wizard->d_func()->m_brokeragepage->d_func()->ui->m_brokerageCurrency->security().name())); + if (d->m_wizard->d_func()->m_brokeragepage->d_func()->ui->m_accountNumber->isEnabled() && !d->m_wizard->d_func()->m_brokeragepage->d_func()->ui->m_accountNumber->text().isEmpty()) + d->ui->m_dataList->append(i18n("Number: %1", d->m_wizard->d_func()->m_brokeragepage->d_func()->ui->m_accountNumber->text())); + if (d->m_wizard->d_func()->m_brokeragepage->d_func()->ui->m_iban->isEnabled() && !d->m_wizard->d_func()->m_brokeragepage->d_func()->ui->m_iban->text().isEmpty()) + d->ui->m_dataList->append(i18n("IBAN: %1", d->m_wizard->d_func()->m_brokeragepage->d_func()->ui->m_iban->text())); + } + } + + // Loan + if (acc.isLoan()) { + d->ui->m_dataList->setFontWeight(QFont::Bold); + d->ui->m_dataList->append(i18n("Loan information")); + d->ui->m_dataList->setFontWeight(QFont::Normal); + if (d->m_wizard->moneyBorrowed()) { + d->ui->m_dataList->append(i18n("Amount borrowed: %1", d->m_wizard->d_func()->m_loanDetailsPage->d_func()->ui->m_loanAmount->value().formatMoney(d->m_wizard->d_func()->currency().tradingSymbol(), d->m_wizard->d_func()->precision()))); + } else { + d->ui->m_dataList->append(i18n("Amount lent: %1", d->m_wizard->d_func()->m_loanDetailsPage->d_func()->ui->m_loanAmount->value().formatMoney(d->m_wizard->d_func()->currency().tradingSymbol(), d->m_wizard->d_func()->precision()))); + } + d->ui->m_dataList->append(i18n("Interest rate: %1 %", d->m_wizard->d_func()->m_loanDetailsPage->d_func()->ui->m_interestRate->value().formatMoney(QString(), -1))); + d->ui->m_dataList->append(i18n("Interest rate is %1", d->m_wizard->d_func()->m_generalLoanInfoPage->d_func()->ui->m_interestType->currentText())); + d->ui->m_dataList->append(i18n("Principal and interest: %1", MyMoneyUtils::formatMoney(d->m_wizard->d_func()->m_loanDetailsPage->d_func()->ui->m_paymentAmount->value(), acc, sec))); + d->ui->m_dataList->append(i18n("Additional Fees: %1", MyMoneyUtils::formatMoney(d->m_wizard->d_func()->m_loanPaymentPage->additionalFees(), acc, sec))); + d->ui->m_dataList->append(i18n("Payment frequency: %1", d->m_wizard->d_func()->m_generalLoanInfoPage->d_func()->ui->m_paymentFrequency->currentText())); + d->ui->m_dataList->append(i18n("Payment account: %1", d->m_wizard->d_func()->m_loanSchedulePage->d_func()->ui->m_paymentAccount->currentText())); + + if (!d->m_wizard->d_func()->m_loanPayoutPage->d_func()->ui->m_noPayoutTransaction->isChecked() && d->m_wizard->openingBalance().isZero()) { + d->ui->m_dataList->setFontWeight(QFont::Bold); + d->ui->m_dataList->append(i18n("Payout information")); + d->ui->m_dataList->setFontWeight(QFont::Normal); + if (d->m_wizard->d_func()->m_loanPayoutPage->d_func()->ui->m_refinanceLoan->isChecked()) { + d->ui->m_dataList->append(i18n("Refinance: %1", d->m_wizard->d_func()->m_loanPayoutPage->d_func()->ui->m_loanAccount->currentText())); + } else { + if (d->m_wizard->moneyBorrowed()) + d->ui->m_dataList->append(i18n("Transfer amount to %1", d->m_wizard->d_func()->m_loanPayoutPage->d_func()->ui->m_assetAccount->currentText())); + else + d->ui->m_dataList->append(i18n("Transfer amount from %1", d->m_wizard->d_func()->m_loanPayoutPage->d_func()->ui->m_assetAccount->currentText())); + } + d->ui->m_dataList->append(i18n("Payment date: %1 ", QLocale().toString(d->m_wizard->d_func()->m_loanPayoutPage->d_func()->ui->m_payoutDate->date()))); + } + } + + // Schedule + if (!(sch == MyMoneySchedule())) { + d->ui->m_dataList->setFontWeight(QFont::Bold); + d->ui->m_dataList->append(i18n("Schedule information")); + d->ui->m_dataList->setFontWeight(QFont::Normal); + d->ui->m_dataList->append(i18nc("Schedule name", "Name: %1", sch.name())); + if (acc.accountType() == Account::CreditCard) { + MyMoneyAccount paymentAccount = MyMoneyFile::instance()->account(d->m_wizard->d_func()->m_schedulePage->d_func()->ui->m_paymentAccount->selectedItem()); + d->ui->m_dataList->append(i18n("Occurrence: Monthly")); + d->ui->m_dataList->append(i18n("Paid from %1", paymentAccount.name())); + d->ui->m_dataList->append(i18n("Pay to %1", d->m_wizard->d_func()->m_schedulePage->d_func()->ui->m_payee->currentText())); + d->ui->m_dataList->append(i18n("Amount: %1", MyMoneyUtils::formatMoney(d->m_wizard->d_func()->m_schedulePage->d_func()->ui->m_amount->value(), acc, sec))); + d->ui->m_dataList->append(i18n("First payment due on %1", QLocale().toString(sch.nextDueDate()))); + d->ui->m_dataList->append(i18n("Payment method: %1", d->m_wizard->d_func()->m_schedulePage->d_func()->ui->m_method->currentText())); + } + if (acc.isLoan()) { + d->ui->m_dataList->append(i18n("Occurrence: %1", d->m_wizard->d_func()->m_generalLoanInfoPage->d_func()->ui->m_paymentFrequency->currentText())); + d->ui->m_dataList->append(i18n("Amount: %1", MyMoneyUtils::formatMoney(d->m_wizard->d_func()->m_loanPaymentPage->basePayment() + d->m_wizard->d_func()->m_loanPaymentPage->additionalFees(), acc, sec))); + d->ui->m_dataList->append(i18n("First payment due on %1", QLocale().toString(d->m_wizard->d_func()->m_loanSchedulePage->firstPaymentDueDate()))); + } + } + } + + QWidget* AccountSummaryPage::initialFocusWidget(void) const + { + Q_D(const AccountSummaryPage); + return d->ui->m_dataList; + } + +} diff --git a/kmymoney/wizards/newaccountwizard/kaccountsummarypagedecl.ui b/kmymoney/wizards/newaccountwizard/kaccountsummarypage.ui rename from kmymoney/wizards/newaccountwizard/kaccountsummarypagedecl.ui rename to kmymoney/wizards/newaccountwizard/kaccountsummarypage.ui --- a/kmymoney/wizards/newaccountwizard/kaccountsummarypagedecl.ui +++ b/kmymoney/wizards/newaccountwizard/kaccountsummarypage.ui @@ -3,8 +3,8 @@ - KAccountSummaryPageDecl - + KAccountSummaryPage + 0 diff --git a/kmymoney/wizards/newaccountwizard/kaccountsummarypage_p.h b/kmymoney/wizards/newaccountwizard/kaccountsummarypage_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kaccountsummarypage_p.h @@ -0,0 +1,59 @@ +/*************************************************************************** + kaccountsummarypage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTACCOUNTSUMMARYPAGE_P_H +#define KNEWACCOUNTACCOUNTSUMMARYPAGE_P_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kaccountsummarypage.h" + +#include "wizardpage_p.h" + +namespace NewAccountWizard +{ + class Wizard; + + class AccountSummaryPagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(AccountSummaryPagePrivate) + + public: + AccountSummaryPagePrivate(QObject* parent) : + WizardPagePrivate(parent), + ui(new Ui::KAccountSummaryPage) + { + } + + ~AccountSummaryPagePrivate() + { + delete ui; + } + + Ui::KAccountSummaryPage *ui; + }; +} + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kaccounttypepage.h b/kmymoney/wizards/newaccountwizard/kaccounttypepage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kaccounttypepage.h @@ -0,0 +1,86 @@ +/*************************************************************************** + kaccounttypepage.h + ------------------- + begin : Tue Sep 25 2007 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDACCOUNTTYPEPAGE_H +#define KNEWACCOUNTWIZARDACCOUNTTYPEPAGE_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" + +class MyMoneyAccount; +class MyMoneySecurity; + +namespace eMyMoney { enum class Account; } + +namespace NewAccountWizard +{ + class Wizard; + + class AccountTypePagePrivate; + class AccountTypePage : public QWidget, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(AccountTypePage) + + public: + explicit AccountTypePage(Wizard* parent); + ~AccountTypePage() override; + + virtual bool isComplete(void) const; + KMyMoneyWizardPage* nextPage(void) const; + + QWidget* initialFocusWidget(void) const override; + + eMyMoney::Account accountType(void) const; + const MyMoneyAccount& parentAccount(void); + bool allowsParentAccount(void) const; + const MyMoneySecurity& currency(void) const; + + void setAccount(const MyMoneyAccount& acc); + + private: + void hideShowPages(eMyMoney::Account i) const; + void priceWarning(bool); + + private slots: + void slotUpdateType(int i); + void slotUpdateCurrency(void); + void slotUpdateConversionRate(const QString&); + void slotGetOnlineQuote(void); + void slotPriceWarning(void); + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, AccountTypePage) + friend class Wizard; + friend class AccountSummaryPage; + friend class BrokeragePage; + friend class CreditCardSchedulePage; + friend class LoanPayoutPage; + }; +} // namespace + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kaccounttypepage.cpp b/kmymoney/wizards/newaccountwizard/kaccounttypepage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kaccounttypepage.cpp @@ -0,0 +1,271 @@ +/*************************************************************************** + kaccounttypepage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kaccounttypepage.h" +#include "kaccounttypepage_p.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include +#include +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kaccounttypepage.h" + +#include "kequitypriceupdatedlg.h" +#include "kmymoneycurrencyselector.h" +#include "kmymoneydateinput.h" +#include "kmymoneyedit.h" +#include "kmymoneygeneralcombo.h" +#include "kmymoneyglobalsettings.h" +#include "kmymoneywizardpage.h" +#include "knewaccountwizard.h" +#include "knewaccountwizard_p.h" +#include "kbrokeragepage.h" +#include "kcreditcardschedulepage.h" +#include "kgeneralloaninfopage.h" +#include "khierarchypage.h" +#include "mymoneyaccount.h" +#include "mymoneyfile.h" +#include "mymoneymoney.h" +#include "mymoneyprice.h" +#include "mymoneysecurity.h" +#include "wizardpage.h" +#include "mymoneyenums.h" + +using namespace eMyMoney; + +namespace NewAccountWizard +{ + AccountTypePage::AccountTypePage(Wizard* wizard) : + QWidget(wizard), + WizardPage(*new AccountTypePagePrivate(wizard), StepAccount, this, wizard) + { + Q_D(AccountTypePage); + d->ui->setupUi(this); + d->m_showPriceWarning = true; + d->ui->m_typeSelection->insertItem(i18n("Checking"), (int)Account::Checkings); + d->ui->m_typeSelection->insertItem(i18n("Savings"), (int)Account::Savings); + d->ui->m_typeSelection->insertItem(i18n("Credit Card"), (int)Account::CreditCard); + d->ui->m_typeSelection->insertItem(i18n("Cash"), (int)Account::Cash); + d->ui->m_typeSelection->insertItem(i18n("Loan"), (int)Account::Loan); + d->ui->m_typeSelection->insertItem(i18n("Investment"), (int)Account::Investment); + d->ui->m_typeSelection->insertItem(i18n("Asset"), (int)Account::Asset); + d->ui->m_typeSelection->insertItem(i18n("Liability"), (int)Account::Liability); + if (KMyMoneyGlobalSettings::expertMode()) { + d->ui->m_typeSelection->insertItem(i18n("Equity"), (int)Account::Equity); + } + + d->ui->m_typeSelection->setCurrentItem((int)Account::Checkings); + + d->ui->m_currencyComboBox->setSecurity(MyMoneyFile::instance()->baseCurrency()); + + d->m_mandatoryGroup->add(d->ui->m_accountName); + d->m_mandatoryGroup->add(d->ui->m_conversionRate->lineedit()); + + d->ui->m_conversionRate->setValue(MyMoneyMoney::ONE); + slotUpdateCurrency(); + + connect(d->ui->m_typeSelection, &KMyMoneyGeneralCombo::itemSelected, this, &AccountTypePage::slotUpdateType); + connect(d->ui->m_currencyComboBox, static_cast(&QComboBox::activated), this, &AccountTypePage::slotUpdateCurrency); + connect(d->ui->m_conversionRate, &KMyMoneyEdit::textChanged, this, &AccountTypePage::slotUpdateConversionRate); + connect(d->ui->m_conversionRate, &KMyMoneyEdit::valueChanged, this, &AccountTypePage::slotPriceWarning); + connect(d->ui->m_onlineQuote, &QAbstractButton::clicked, this, &AccountTypePage::slotGetOnlineQuote); + } + + AccountTypePage::~AccountTypePage() + { + } + + void AccountTypePage::slotUpdateType(int i) + { + Q_D(AccountTypePage); + hideShowPages(static_cast(i)); + d->ui->m_openingBalance->setDisabled(static_cast(i) == Account::Equity); + } + + void AccountTypePage::hideShowPages(Account accountType) const + { + Q_D(const AccountTypePage); + bool hideSchedulePage = (accountType != Account::CreditCard) + && (accountType != Account::Loan); + bool hideLoanPage = (accountType != Account::Loan); + d->m_wizard->d_func()->setStepHidden(StepDetails, hideLoanPage); + d->m_wizard->d_func()->setStepHidden(StepPayments, hideLoanPage); + d->m_wizard->d_func()->setStepHidden(StepFees, hideLoanPage); + d->m_wizard->d_func()->setStepHidden(StepSchedule, hideSchedulePage); + d->m_wizard->d_func()->setStepHidden(StepPayout, (accountType != Account::Loan)); + d->m_wizard->d_func()->setStepHidden(StepBroker, accountType != Account::Investment); + d->m_wizard->d_func()->setStepHidden(StepParentAccount, accountType == Account::Loan); + // Force an update of the steps in case the list has changed + d->m_wizard->reselectStep(); + } + + KMyMoneyWizardPage* AccountTypePage::nextPage() const + { + Q_D(const AccountTypePage); + if (accountType() == Account::Loan) + return d->m_wizard->d_func()->m_generalLoanInfoPage; + if (accountType() == Account::CreditCard) + return d->m_wizard->d_func()->m_schedulePage; + if (accountType() == Account::Investment) + return d->m_wizard->d_func()->m_brokeragepage; + return d->m_wizard->d_func()->m_hierarchyPage; + } + + QWidget* AccountTypePage::initialFocusWidget(void) const + { + Q_D(const AccountTypePage); + return d->ui->m_accountName; + } + + void AccountTypePage::slotUpdateCurrency() + { + Q_D(AccountTypePage); + MyMoneyAccount acc; + acc.setAccountType(accountType()); + + d->ui->m_openingBalance->setPrecision(MyMoneyMoney::denomToPrec(acc.fraction(currency()))); + + bool show = d->ui->m_currencyComboBox->security().id() != MyMoneyFile::instance()->baseCurrency().id(); + d->ui->m_conversionLabel->setVisible(show); + d->ui->m_conversionRate->setVisible(show); + d->ui->m_conversionExample->setVisible(show); + d->ui->m_onlineQuote->setVisible(show); + d->ui->m_conversionRate->setEnabled(show); // make sure to include/exclude in mandatoryGroup + d->ui->m_conversionRate->setPrecision(d->ui->m_currencyComboBox->security().pricePrecision()); + d->m_mandatoryGroup->changed(); + slotUpdateConversionRate(d->ui->m_conversionRate->lineedit()->text()); + } + + void AccountTypePage::slotGetOnlineQuote() + { + Q_D(AccountTypePage); + QString id = MyMoneyFile::instance()->baseCurrency().id() + ' ' + d->ui->m_currencyComboBox->security().id(); + QPointer dlg = new KEquityPriceUpdateDlg(this, id); + if (dlg->exec() == QDialog::Accepted) { + const MyMoneyPrice &price = dlg->price(id); + if (price.isValid()) { + d->ui->m_conversionRate->setValue(price.rate(d->ui->m_currencyComboBox->security().id())); + if (price.date() != d->ui->m_openingDate->date()) { + priceWarning(true); + } + } + } + delete dlg; + } + + void AccountTypePage::slotPriceWarning() + { + priceWarning(false); + } + + void AccountTypePage::priceWarning(bool always) + { + Q_D(AccountTypePage); + if (d->m_showPriceWarning || always) { + KMessageBox::information(this, i18n("Please make sure to enter the correct conversion for the selected opening date. If you requested an online quote it might be provided for a different date."), i18n("Check date")); + } + d->m_showPriceWarning = false; + } + + void AccountTypePage::slotUpdateConversionRate(const QString& txt) + { + Q_D(AccountTypePage); + d->ui->m_conversionExample->setText(i18n("1 %1 equals %2", MyMoneyFile::instance()->baseCurrency().tradingSymbol(), MyMoneyMoney(txt).formatMoney(d->ui->m_currencyComboBox->security().tradingSymbol(), d->ui->m_currencyComboBox->security().pricePrecision()))); + } + + bool AccountTypePage::isComplete() const + { + Q_D(const AccountTypePage); + // check that the conversion rate is positive if enabled + bool rc = !d->ui->m_conversionRate->isVisible() || (!d->ui->m_conversionRate->value().isZero() && !d->ui->m_conversionRate->value().isNegative()); + if (!rc) { + d->m_wizard->d_func()->m_nextButton->setToolTip(i18n("Conversion rate is not positive")); + + } else { + rc = KMyMoneyWizardPage::isComplete(); + + if (!rc) { + d->m_wizard->d_func()->m_nextButton->setToolTip(i18n("No account name supplied")); + } + } + hideShowPages(accountType()); + return rc; + } + + Account AccountTypePage::accountType() const + { + Q_D(const AccountTypePage); + return static_cast(d->ui->m_typeSelection->currentItem()); + } + + const MyMoneySecurity& AccountTypePage::currency() const + { + Q_D(const AccountTypePage); + return d->ui->m_currencyComboBox->security(); + } + + void AccountTypePage::setAccount(const MyMoneyAccount& acc) + { + Q_D(const AccountTypePage); + if (acc.accountType() != Account::Unknown) { + if (acc.accountType() == Account::AssetLoan) { + d->ui->m_typeSelection->setCurrentItem((int)Account::Loan); + } else { + d->ui->m_typeSelection->setCurrentItem((int)acc.accountType()); + } + } + d->ui->m_openingDate->setDate(acc.openingDate()); + d->ui->m_accountName->setText(acc.name()); + } + + const MyMoneyAccount& AccountTypePage::parentAccount() + { + switch (accountType()) { + case Account::CreditCard: + case Account::Liability: + case Account::Loan: // Can be either but we return liability here + return MyMoneyFile::instance()->liability(); + break; + case Account::Equity: + return MyMoneyFile::instance()->equity(); + default: + break; + } + return MyMoneyFile::instance()->asset(); + } + + bool AccountTypePage::allowsParentAccount() const + { + return accountType() != Account::Loan; + } +} diff --git a/kmymoney/wizards/newaccountwizard/kaccounttypepagedecl.ui b/kmymoney/wizards/newaccountwizard/kaccounttypepage.ui rename from kmymoney/wizards/newaccountwizard/kaccounttypepagedecl.ui rename to kmymoney/wizards/newaccountwizard/kaccounttypepage.ui --- a/kmymoney/wizards/newaccountwizard/kaccounttypepagedecl.ui +++ b/kmymoney/wizards/newaccountwizard/kaccounttypepage.ui @@ -1,7 +1,7 @@ - KAccountTypePageDecl - + KAccountTypePage + 0 diff --git a/kmymoney/wizards/newaccountwizard/kaccounttypepage_p.h b/kmymoney/wizards/newaccountwizard/kaccounttypepage_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kaccounttypepage_p.h @@ -0,0 +1,60 @@ +/*************************************************************************** + kaccounttypepage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDACCOUNTTYPEPAGE_P_H +#define KNEWACCOUNTWIZARDACCOUNTTYPEPAGE_P_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kaccounttypepage.h" + +#include "wizardpage_p.h" + +namespace NewAccountWizard +{ + class Wizard; + + class AccountTypePagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(AccountTypePagePrivate) + + public: + AccountTypePagePrivate(QObject* parent) : + WizardPagePrivate(parent), + ui(new Ui::KAccountTypePage) + { + } + + ~AccountTypePagePrivate() + { + delete ui; + } + + Ui::KAccountTypePage *ui; + bool m_showPriceWarning; + }; +} + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kbrokeragepage.h b/kmymoney/wizards/newaccountwizard/kbrokeragepage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kbrokeragepage.h @@ -0,0 +1,63 @@ +/*************************************************************************** + kbrokeragepage.h + ------------------- + begin : Tue Sep 25 2007 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDBROKERAGEPAGE_H +#define KNEWACCOUNTWIZARDBROKERAGEPAGE_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" + +namespace NewAccountWizard +{ + class Wizard; + + class BrokeragePagePrivate; + class BrokeragePage : public QWidget, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(BrokeragePage) + + public: + explicit BrokeragePage(Wizard* parent); + ~BrokeragePage() override; + + KMyMoneyWizardPage* nextPage(void) const; + void enterPage(void); + + QWidget* initialFocusWidget(void) const override; + + private slots: + void slotLoadWidgets(void); + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, BrokeragePage) + friend class Wizard; + friend class AccountSummaryPage; + }; +} // namespace + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kbrokeragepage.cpp b/kmymoney/wizards/newaccountwizard/kbrokeragepage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kbrokeragepage.cpp @@ -0,0 +1,100 @@ +/*************************************************************************** + kbrokeragepage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kbrokeragepage.h" +#include "kbrokeragepage_p.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kbrokeragepage.h" + +#include "kmymoneycurrencyselector.h" +#include "knewaccountwizard.h" +#include "knewaccountwizard_p.h" +#include "kaccounttypepage.h" +#include "kaccounttypepage_p.h" +#include "kbrokeragepage_p.h" +#include "khierarchypage.h" +#include "kinstitutionpage.h" +#include "kinstitutionpage_p.h" +#include "mymoneyfile.h" +#include "mymoneysecurity.h" +#include "wizardpage.h" + +namespace NewAccountWizard +{ + BrokeragePage::BrokeragePage(Wizard* wizard) : + QWidget(wizard), + WizardPage(*new BrokeragePagePrivate(wizard), StepBroker, this, wizard) + { + Q_D(BrokeragePage); + d->ui->setupUi(this); + connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &BrokeragePage::slotLoadWidgets); + } + + BrokeragePage::~BrokeragePage() + { + } + + void BrokeragePage::slotLoadWidgets() + { + Q_D(BrokeragePage); + d->ui->m_brokerageCurrency->update(QString("x")); + } + + void BrokeragePage::enterPage() + { + Q_D(BrokeragePage); + // assign the currency of the investment account to the + // brokerage account if nothing else has ever been selected + if (d->ui->m_brokerageCurrency->security().id().isEmpty()) { + d->ui->m_brokerageCurrency->setSecurity(d->m_wizard->d_func()->m_accountTypePage->d_func()->ui->m_currencyComboBox->security()); + } + + // check if the institution relevant fields should be enabled or not + bool enabled = d->m_wizard->d_func()->m_institutionPage->d_func()->ui->m_accountNumber->isEnabled(); + d->ui->m_accountNumberLabel->setEnabled(enabled); + d->ui->m_accountNumber->setEnabled(enabled); + d->ui->m_ibanLabel->setEnabled(enabled); + d->ui->m_iban->setEnabled(enabled); + } + + QWidget* BrokeragePage::initialFocusWidget(void) const + { + Q_D(const BrokeragePage); + return d->ui->m_createBrokerageButton; + } + + KMyMoneyWizardPage* BrokeragePage::nextPage() const + { + Q_D(const BrokeragePage); + return d->m_wizard->d_func()->m_hierarchyPage; + } +} diff --git a/kmymoney/wizards/newaccountwizard/kbrokeragepagedecl.ui b/kmymoney/wizards/newaccountwizard/kbrokeragepage.ui rename from kmymoney/wizards/newaccountwizard/kbrokeragepagedecl.ui rename to kmymoney/wizards/newaccountwizard/kbrokeragepage.ui --- a/kmymoney/wizards/newaccountwizard/kbrokeragepagedecl.ui +++ b/kmymoney/wizards/newaccountwizard/kbrokeragepage.ui @@ -1,7 +1,7 @@ - KBrokeragePageDecl - + KBrokeragePage + 0 diff --git a/kmymoney/wizards/newaccountwizard/kbrokeragepage_p.h b/kmymoney/wizards/newaccountwizard/kbrokeragepage_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kbrokeragepage_p.h @@ -0,0 +1,59 @@ +/*************************************************************************** + kbrokeragepage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDBROKERAGEPAGE_P_H +#define KNEWACCOUNTWIZARDBROKERAGEPAGE_P_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kbrokeragepage.h" + +#include "wizardpage_p.h" + +namespace NewAccountWizard +{ + class Wizard; + + class BrokeragePagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(BrokeragePagePrivate) + + public: + BrokeragePagePrivate(QObject* parent) : + WizardPagePrivate(parent), + ui(new Ui::KBrokeragePage) + { + } + + ~BrokeragePagePrivate() + { + delete ui; + } + + Ui::KBrokeragePage *ui; + }; +} + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kcreditcardschedulepage.h b/kmymoney/wizards/newaccountwizard/kcreditcardschedulepage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kcreditcardschedulepage.h @@ -0,0 +1,65 @@ +/*************************************************************************** + kcreditcardschedulepage.h + ------------------- + begin : Tue Sep 25 2007 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDCREDITCARDSCHEDULE_H +#define KNEWACCOUNTWIZARDCREDITCARDSCHEDULE_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" + +namespace NewAccountWizard +{ + class Wizard; + + class CreditCardSchedulePagePrivate; + class CreditCardSchedulePage : public QWidget, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(CreditCardSchedulePage) + + public: + explicit CreditCardSchedulePage(Wizard* parent); + ~CreditCardSchedulePage() override; + + KMyMoneyWizardPage* nextPage(void) const; + virtual bool isComplete(void) const; + void enterPage(void); + + QWidget* initialFocusWidget(void) const override; + + private slots: + void slotLoadWidgets(void); + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, CreditCardSchedulePage) + friend class Wizard; + friend class AccountSummaryPage; + }; + +} // namespace + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kcreditcardschedulepage.cpp b/kmymoney/wizards/newaccountwizard/kcreditcardschedulepage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kcreditcardschedulepage.cpp @@ -0,0 +1,161 @@ +/*************************************************************************** + kcreditcardschedulepage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kcreditcardschedulepage.h" +#include "kcreditcardschedulepage_p.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kcreditcardschedulepage.h" + +#include "kmymoneyaccountselector.h" +#include "kmymoneycategory.h" +#include "kmymoneydateinput.h" +#include "kmymoneyedit.h" +#include "kmymoneygeneralcombo.h" +#include "kmymoneypayeecombo.h" +#include "knewaccountwizard.h" +#include "knewaccountwizard_p.h" +#include "kaccounttypepage.h" +#include "kaccounttypepage_p.h" +#include "kcreditcardschedulepage_p.h" +#include "khierarchypage.h" +#include "mymoneyenums.h" +#include "mymoneyfile.h" +#include "mymoneypayee.h" +#include "wizardpage.h" + +using namespace eMyMoney; + +namespace NewAccountWizard +{ + CreditCardSchedulePage::CreditCardSchedulePage(Wizard* wizard) : + QWidget(wizard), + WizardPage(*new CreditCardSchedulePagePrivate(wizard), StepSchedule, this, wizard) + { + Q_D(CreditCardSchedulePage); + d->ui->setupUi(this); + d->m_mandatoryGroup->add(d->ui->m_name); + d->m_mandatoryGroup->add(d->ui->m_payee); + d->m_mandatoryGroup->add(d->ui->m_amount->lineedit()); + d->m_mandatoryGroup->add(d->ui->m_paymentAccount); + connect(d->ui->m_paymentAccount, &KMyMoneyCombo::itemSelected, object(), &KMyMoneyWizardPagePrivate::completeStateChanged); + connect(d->ui->m_payee, &KMyMoneyMVCCombo::itemSelected, object(), &KMyMoneyWizardPagePrivate::completeStateChanged); + connect(d->ui->m_date, &KMyMoneyDateInput::dateChanged, object(), &KMyMoneyWizardPagePrivate::completeStateChanged); + + connect(d->ui->m_payee, &KMyMoneyMVCCombo::createItem, wizard, &KMyMoneyWizard::createPayee); + + d->ui->m_reminderCheckBox->setChecked(true); + connect(d->ui->m_reminderCheckBox, &QAbstractButton::toggled, object(), &KMyMoneyWizardPagePrivate::completeStateChanged); + + connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &CreditCardSchedulePage::slotLoadWidgets); + + d->ui->m_method->insertItem(i18n("Write check"), (int)Schedule::PaymentType::WriteChecque); +#if 0 + d->ui->m_method->insertItem(i18n("Direct debit"), Schedule::PaymentType::DirectDebit); + d->ui->m_method->insertItem(i18n("Bank transfer"), Schedule::PaymentType::BankTransfer); +#endif + d->ui->m_method->insertItem(i18n("Standing order"), (int)Schedule::PaymentType::StandingOrder); + d->ui->m_method->insertItem(i18n("Manual deposit"), (int)Schedule::PaymentType::ManualDeposit); + d->ui->m_method->insertItem(i18n("Direct deposit"), (int)Schedule::PaymentType::DirectDeposit); + d->ui->m_method->insertItem(i18nc("Other payment method", "Other"), (int)Schedule::PaymentType::Other); + d->ui->m_method->setCurrentItem((int)Schedule::PaymentType::DirectDebit); + + slotLoadWidgets(); + } + + CreditCardSchedulePage::~CreditCardSchedulePage() + { + } + + void CreditCardSchedulePage::enterPage() + { + Q_D(CreditCardSchedulePage); + if (d->ui->m_name->text().isEmpty()) + d->ui->m_name->setText(i18n("Credit Card %1 monthly payment", d->m_wizard->d_func()->m_accountTypePage->d_func()->ui->m_accountName->text())); + } + + QWidget* CreditCardSchedulePage::initialFocusWidget(void) const + { + Q_D(const CreditCardSchedulePage); + return d->ui->m_reminderCheckBox; + } + + bool CreditCardSchedulePage::isComplete() const + { + Q_D(const CreditCardSchedulePage); + bool rc = true; + QString msg = i18n("Finish entry and create account"); + if (d->ui->m_reminderCheckBox->isChecked()) { + msg = i18n("Finish entry and create account and schedule"); + if (d->ui->m_date->date() < d->m_wizard->d_func()->m_accountTypePage->d_func()->ui->m_openingDate->date()) { + rc = false; + msg = i18n("Next due date is prior to opening date"); + } + if (d->ui->m_paymentAccount->selectedItem().isEmpty()) { + rc = false; + msg = i18n("No account selected"); + } + if (d->ui->m_amount->lineedit()->text().isEmpty()) { + rc = false; + msg = i18n("No amount for payment selected"); + } + if (d->ui->m_payee->selectedItem().isEmpty()) { + rc = false; + msg = i18n("No payee for payment selected"); + } + if (d->ui->m_name->text().isEmpty()) { + rc = false; + msg = i18n("No name assigned for schedule"); + } + } + d->m_wizard->d_func()->m_finishButton->setToolTip(msg); + + return rc; + } + + void CreditCardSchedulePage::slotLoadWidgets() + { + Q_D(CreditCardSchedulePage); + AccountSet set; + set.addAccountGroup(Account::Asset); + set.load(d->ui->m_paymentAccount->selector()); + + d->ui->m_payee->loadPayees(MyMoneyFile::instance()->payeeList()); + } + + KMyMoneyWizardPage* CreditCardSchedulePage::nextPage() const + { + Q_D(const CreditCardSchedulePage); + return d->m_wizard->d_func()->m_hierarchyPage; + } +} diff --git a/kmymoney/wizards/newaccountwizard/kschedulepagedecl.ui b/kmymoney/wizards/newaccountwizard/kcreditcardschedulepage.ui rename from kmymoney/wizards/newaccountwizard/kschedulepagedecl.ui rename to kmymoney/wizards/newaccountwizard/kcreditcardschedulepage.ui --- a/kmymoney/wizards/newaccountwizard/kschedulepagedecl.ui +++ b/kmymoney/wizards/newaccountwizard/kcreditcardschedulepage.ui @@ -3,8 +3,8 @@ - KSchedulePageDecl - + KCreditCardSchedulePage + 0 diff --git a/kmymoney/wizards/newaccountwizard/kcreditcardschedulepage_p.h b/kmymoney/wizards/newaccountwizard/kcreditcardschedulepage_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kcreditcardschedulepage_p.h @@ -0,0 +1,59 @@ +/*************************************************************************** + kcreditcardschedulepage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDCREDITCARDSCHEDULE_P_H +#define KNEWACCOUNTWIZARDCREDITCARDSCHEDULE_P_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kcreditcardschedulepage.h" + +#include "wizardpage_p.h" + +namespace NewAccountWizard +{ + class Wizard; + + class CreditCardSchedulePagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(CreditCardSchedulePagePrivate) + + public: + CreditCardSchedulePagePrivate(QObject* parent) : + WizardPagePrivate(parent), + ui(new Ui::KCreditCardSchedulePage) + { + } + + ~CreditCardSchedulePagePrivate() + { + delete ui; + } + + Ui::KCreditCardSchedulePage *ui; + }; +} + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kgeneralloaninfopage.h b/kmymoney/wizards/newaccountwizard/kgeneralloaninfopage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kgeneralloaninfopage.h @@ -0,0 +1,75 @@ +/*************************************************************************** + kgeneralloaninfopage.h + ------------------- + begin : Tue Sep 25 2007 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDGENERALLOANINFOPAGE_H +#define KNEWACCOUNTWIZARDGENERALLOANINFOPAGE_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" + +class MyMoneyAccount; + +namespace NewAccountWizard +{ + class Wizard; + + class GeneralLoanInfoPagePrivate; + class GeneralLoanInfoPage : public QWidget, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(GeneralLoanInfoPage) + + public: + explicit GeneralLoanInfoPage(Wizard* parent); + ~GeneralLoanInfoPage() override; + + KMyMoneyWizardPage* nextPage(void) const; + virtual bool isComplete(void) const; + void enterPage(void); + const MyMoneyAccount& parentAccount(void); + + QWidget* initialFocusWidget(void) const override; + + /** + * Returns @p true if the user decided to record all payments, @p false otherwise. + */ + bool recordAllPayments(void) const; + + private slots: + void slotLoadWidgets(void); + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, GeneralLoanInfoPage) + friend class Wizard; + friend class AccountSummaryPage; + friend class LoanDetailsPage; + friend class LoanSchedulePage; + friend class WizardPrivate; + }; +} // namespace + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kgeneralloaninfopage.cpp b/kmymoney/wizards/newaccountwizard/kgeneralloaninfopage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kgeneralloaninfopage.cpp @@ -0,0 +1,175 @@ +/*************************************************************************** + kgeneralloaninfopage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kgeneralloaninfopage.h" +#include "kgeneralloaninfopage_p.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include +#include +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kgeneralloaninfopage.h" + +#include "kmymoneydateinput.h" +#include "kmymoneyedit.h" +#include "kmymoneyfrequencycombo.h" +#include "kmymoneypayeecombo.h" +#include "kmymoneywizardpage.h" +#include "knewaccountwizard.h" +#include "knewaccountwizard_p.h" +#include "kgeneralloaninfopage_p.h" +#include "kloandetailspage.h" +#include "mymoneyenums.h" +#include "mymoneyfile.h" +#include "mymoneymoney.h" +#include "mymoneypayee.h" +#include "wizardpage.h" + +using namespace eMyMoney; + +namespace NewAccountWizard +{ + GeneralLoanInfoPage::GeneralLoanInfoPage(Wizard* wizard) : + QWidget(wizard), + WizardPage(*new GeneralLoanInfoPagePrivate(wizard), StepDetails, this, wizard) + { + Q_D(GeneralLoanInfoPage); + d->ui->setupUi(this); + d->m_firstTime = true; + d->m_mandatoryGroup->add(d->ui->m_payee); + + // remove the unsupported payment and compounding frequencies and setup default + d->ui->m_paymentFrequency->removeItem((int)Schedule::Occurrence::Once); + d->ui->m_paymentFrequency->removeItem((int)Schedule::Occurrence::EveryOtherYear); + d->ui->m_paymentFrequency->setCurrentItem((int)Schedule::Occurrence::Monthly); + d->ui->m_compoundFrequency->removeItem((int)Schedule::Occurrence::Once); + d->ui->m_compoundFrequency->removeItem((int)Schedule::Occurrence::EveryOtherYear); + d->ui->m_compoundFrequency->setCurrentItem((int)Schedule::Occurrence::Monthly); + + slotLoadWidgets(); + + connect(d->ui->m_payee, &KMyMoneyMVCCombo::createItem, wizard, &KMyMoneyWizard::createPayee); + connect(d->ui->m_anyPayments, static_cast(&QComboBox::activated), object(), &KMyMoneyWizardPagePrivate::completeStateChanged); + connect(d->ui->m_recordings, static_cast(&QComboBox::activated), object(), &KMyMoneyWizardPagePrivate::completeStateChanged); + + connect(d->ui->m_interestType, static_cast(&QComboBox::activated), object(), &KMyMoneyWizardPagePrivate::completeStateChanged); + connect(d->ui->m_interestChangeDateEdit, &KMyMoneyDateInput::dateChanged, object(), &KMyMoneyWizardPagePrivate::completeStateChanged); + connect(d->ui->m_openingBalance, &KMyMoneyEdit::textChanged, object(), &KMyMoneyWizardPagePrivate::completeStateChanged); + + connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &GeneralLoanInfoPage::slotLoadWidgets); + } + + GeneralLoanInfoPage::~GeneralLoanInfoPage() + { + } + + KMyMoneyWizardPage* GeneralLoanInfoPage::nextPage() const + { + Q_D(const GeneralLoanInfoPage); + return d->m_wizard->d_func()->m_loanDetailsPage; + } + + bool GeneralLoanInfoPage::recordAllPayments() const + { + Q_D(const GeneralLoanInfoPage); + bool rc = true; // all payments + if (d->ui->m_recordings->isEnabled()) { + if (d->ui->m_recordings->currentIndex() != 0) + rc = false; + } + return rc; + } + + void GeneralLoanInfoPage::enterPage() + { + Q_D(GeneralLoanInfoPage); + if (d->m_firstTime) { + // setup default dates to last of this month and one year on top + QDate firstDay(QDate::currentDate().year(), QDate::currentDate().month(), 1); + d->ui->m_firstPaymentDate->setDate(firstDay.addMonths(1).addDays(-1)); + d->ui->m_interestChangeDateEdit->setDate(d->ui->m_firstPaymentDate->date().addYears(1));; + d->m_firstTime = false; + } + } + + bool GeneralLoanInfoPage::isComplete() const + { + Q_D(const GeneralLoanInfoPage); + d->m_wizard->d_func()->setStepHidden(StepPayout, !d->m_wizard->openingBalance().isZero()); + bool rc = KMyMoneyWizardPage::isComplete(); + if (!rc) { + d->m_wizard->d_func()->m_nextButton->setToolTip(i18n("No payee supplied")); + } + + // fixup availability of items on this page + d->ui->m_recordings->setDisabled(d->ui->m_anyPayments->currentIndex() == 0); + + d->ui->m_interestFrequencyAmountEdit->setDisabled(d->ui->m_interestType->currentIndex() == 0); + d->ui->m_interestFrequencyUnitEdit->setDisabled(d->ui->m_interestType->currentIndex() == 0); + d->ui->m_interestChangeDateEdit->setDisabled(d->ui->m_interestType->currentIndex() == 0); + + d->ui->m_openingBalance->setDisabled(recordAllPayments()); + + if (d->ui->m_openingBalance->isEnabled() && d->ui->m_openingBalance->lineedit()->text().length() == 0) { + rc = false; + d->m_wizard->d_func()->m_nextButton->setToolTip(i18n("No opening balance supplied")); + } + + if (rc + && (d->ui->m_interestType->currentIndex() != 0) + && (d->ui->m_interestChangeDateEdit->date() <= d->ui->m_firstPaymentDate->date())) { + rc = false; + d->m_wizard->d_func()->m_nextButton->setToolTip(i18n("An interest change can only happen after the first payment")); + } + return rc; + } + + const MyMoneyAccount& GeneralLoanInfoPage::parentAccount() + { + Q_D(GeneralLoanInfoPage); + return (d->ui->m_loanDirection->currentIndex() == 0) + ? MyMoneyFile::instance()->liability() + : MyMoneyFile::instance()->asset(); + } + + QWidget* GeneralLoanInfoPage::initialFocusWidget(void) const + { + Q_D(const GeneralLoanInfoPage); + return d->ui->m_loanDirection; + } + + void GeneralLoanInfoPage::slotLoadWidgets() + { + Q_D(GeneralLoanInfoPage); + d->ui->m_payee->loadPayees(MyMoneyFile::instance()->payeeList()); + } + +} diff --git a/kmymoney/wizards/newaccountwizard/kgeneralloaninfopagedecl.ui b/kmymoney/wizards/newaccountwizard/kgeneralloaninfopage.ui rename from kmymoney/wizards/newaccountwizard/kgeneralloaninfopagedecl.ui rename to kmymoney/wizards/newaccountwizard/kgeneralloaninfopage.ui --- a/kmymoney/wizards/newaccountwizard/kgeneralloaninfopagedecl.ui +++ b/kmymoney/wizards/newaccountwizard/kgeneralloaninfopage.ui @@ -3,8 +3,8 @@ - KGeneralLoanInfoPageDecl - + KGeneralLoanInfoPage + 0 diff --git a/kmymoney/wizards/newaccountwizard/kgeneralloaninfopage_p.h b/kmymoney/wizards/newaccountwizard/kgeneralloaninfopage_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kgeneralloaninfopage_p.h @@ -0,0 +1,60 @@ +/*************************************************************************** + kgeneralloaninfopage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDGENERALLOANINFOPAGE_P_H +#define KNEWACCOUNTWIZARDGENERALLOANINFOPAGE_P_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kgeneralloaninfopage.h" + +#include "wizardpage_p.h" + +namespace NewAccountWizard +{ + class Wizard; + + class GeneralLoanInfoPagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(GeneralLoanInfoPagePrivate) + + public: + GeneralLoanInfoPagePrivate(QObject* parent) : + WizardPagePrivate(parent), + ui(new Ui::KGeneralLoanInfoPage) + { + } + + ~GeneralLoanInfoPagePrivate() + { + delete ui; + } + + Ui::KGeneralLoanInfoPage *ui; + bool m_firstTime; + }; +} + +#endif diff --git a/kmymoney/wizards/newaccountwizard/khierarchypage.h b/kmymoney/wizards/newaccountwizard/khierarchypage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/khierarchypage.h @@ -0,0 +1,69 @@ +/*************************************************************************** + khierarchypage.h + ------------------- + begin : Tue Sep 25 2007 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDHIERACHRYPAGE_H +#define KNEWACCOUNTWIZARDHIERACHRYPAGE_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" + +class MyMoneyAccount; + +namespace NewAccountWizard +{ + class Wizard; + class HierarchyFilterProxyModel; + + class HierarchyPagePrivate; + class HierarchyPage : public QWidget, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(HierarchyPage) + + public: + explicit HierarchyPage(Wizard* parent); + ~HierarchyPage() override; + + void enterPage(void); + KMyMoneyWizardPage* nextPage(void) const; + QWidget* initialFocusWidget(void) const override; + const MyMoneyAccount& parentAccount(void); + + bool isComplete(void) const; + + protected slots: + void parentAccountChanged(); + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, HierarchyPage) + friend class Wizard; + friend class AccountSummaryPage; + }; + +} // namespace + +#endif diff --git a/kmymoney/wizards/newaccountwizard/khierarchypage.cpp b/kmymoney/wizards/newaccountwizard/khierarchypage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/khierarchypage.cpp @@ -0,0 +1,127 @@ +/*************************************************************************** + khierarchypage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "khierarchypage.h" +#include "khierarchypage_p.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_khierarchypage.h" + +#include "accountsmodel.h" +#include "hierarchyfilterproxymodel.h" +#include "kmymoneyaccounttreeview.h" +#include "kmymoneyglobalsettings.h" +#include "knewaccountwizard.h" +#include "knewaccountwizard_p.h" +#include "kaccountsummarypage.h" +#include "kaccounttypepage.h" +#include "khierarchypage_p.h" +#include "modelenums.h" +#include "models.h" +#include "mymoneyaccount.h" +#include "mymoneyenums.h" +#include "wizardpage.h" + +using namespace eMyMoney; + +namespace NewAccountWizard +{ + HierarchyPage::HierarchyPage(Wizard* wizard) : + QWidget(wizard), + WizardPage(*new HierarchyPagePrivate(wizard), StepParentAccount, this, wizard) + { + Q_D(HierarchyPage); + d->ui->setupUi(this); + d->m_filterProxyModel = nullptr; + // the proxy filter model + d->m_filterProxyModel = new HierarchyFilterProxyModel(this); + d->m_filterProxyModel->setHideClosedAccounts(true); + d->m_filterProxyModel->setHideEquityAccounts(!KMyMoneyGlobalSettings::expertMode()); + d->m_filterProxyModel->addAccountGroup(QVector {Account::Asset, Account::Liability}); + auto const model = Models::instance()->accountsModel(); + d->m_filterProxyModel->setSourceModel(model); + d->m_filterProxyModel->setSourceColumns(model->getColumns()); + d->m_filterProxyModel->setDynamicSortFilter(true); + + d->ui->m_parentAccounts->setModel(d->m_filterProxyModel); + d->ui->m_parentAccounts->sortByColumn((int)eAccountsModel::Column::Account, Qt::AscendingOrder); + + connect(d->ui->m_parentAccounts->selectionModel(), &QItemSelectionModel::currentChanged, this, &HierarchyPage::parentAccountChanged); + } + + HierarchyPage::~HierarchyPage() + { + } + + void HierarchyPage::enterPage() + { + Q_D(HierarchyPage); + // Ensure that the list reflects the Account Type + MyMoneyAccount topAccount = d->m_wizard->d_func()->m_accountTypePage->parentAccount(); + d->m_filterProxyModel->clear(); + d->m_filterProxyModel->addAccountGroup(QVector {topAccount.accountGroup()}); + d->ui->m_parentAccounts->expandAll(); + } + + KMyMoneyWizardPage* HierarchyPage::nextPage() const + { + Q_D(const HierarchyPage); + return d->m_wizard->d_func()->m_accountSummaryPage; + } + + QWidget* HierarchyPage::initialFocusWidget(void) const + { + Q_D(const HierarchyPage); + return d->ui->m_parentAccounts; + } + + const MyMoneyAccount& HierarchyPage::parentAccount() + { + Q_D(HierarchyPage); + QVariant data = d->ui->m_parentAccounts->model()->data(d->ui->m_parentAccounts->currentIndex(), (int)eAccountsModel::Role::Account); + if (data.isValid()) { + d->m_parentAccount = data.value(); + } else { + d->m_parentAccount = MyMoneyAccount(); + } + return d->m_parentAccount; + } + + bool HierarchyPage::isComplete() const + { + Q_D(const HierarchyPage); + return d->ui->m_parentAccounts->currentIndex().isValid(); + } + + void HierarchyPage::parentAccountChanged() + { + completeStateChanged(); + } +} diff --git a/kmymoney/wizards/newaccountwizard/khierarchypagedecl.ui b/kmymoney/wizards/newaccountwizard/khierarchypage.ui rename from kmymoney/wizards/newaccountwizard/khierarchypagedecl.ui rename to kmymoney/wizards/newaccountwizard/khierarchypage.ui --- a/kmymoney/wizards/newaccountwizard/khierarchypagedecl.ui +++ b/kmymoney/wizards/newaccountwizard/khierarchypage.ui @@ -1,7 +1,7 @@ - KHierarchyPageDecl - + KHierarchyPage + 0 diff --git a/kmymoney/wizards/newaccountwizard/khierarchypage_p.h b/kmymoney/wizards/newaccountwizard/khierarchypage_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/khierarchypage_p.h @@ -0,0 +1,63 @@ +/*************************************************************************** + khierarchypage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDHIERACHRYPAGE_P_H +#define KNEWACCOUNTWIZARDHIERACHRYPAGE_P_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_khierarchypage.h" + +#include "wizardpage_p.h" +#include "mymoneyaccount.h" + +namespace NewAccountWizard +{ + class Wizard; + class HierarchyFilterProxyModel; + + class HierarchyPagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(HierarchyPagePrivate) + + public: + HierarchyPagePrivate(QObject* parent) : + WizardPagePrivate(parent), + ui(new Ui::KHierarchyPage) + { + } + + ~HierarchyPagePrivate() + { + delete ui; + } + + Ui::KHierarchyPage *ui; + HierarchyFilterProxyModel *m_filterProxyModel; + MyMoneyAccount m_parentAccount; + }; +} + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kinstitutionpage.h b/kmymoney/wizards/newaccountwizard/kinstitutionpage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kinstitutionpage.h @@ -0,0 +1,75 @@ +/*************************************************************************** + kinstitutionpage.h + ------------------- + begin : Tue Sep 25 2007 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDINSTITUTION_H +#define KNEWACCOUNTWIZARDINSTITUTION_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" + +class MyMoneyInstitution; + +namespace NewAccountWizard +{ + class Wizard; + + class InstitutionPagePrivate; + class InstitutionPage : public QWidget, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(InstitutionPage) + + public: + explicit InstitutionPage(Wizard* parent); + ~InstitutionPage() override; + KMyMoneyWizardPage* nextPage(void) const; + + QWidget* initialFocusWidget(void) const override; + + /** + * Returns the information about an institution if entered by + * the user. If the id field is empty, then he did not enter + * such information. + */ + const MyMoneyInstitution& institution(void) const; + + void selectExistingInstitution(const QString& id); + + private slots: + void slotLoadWidgets(void); + void slotNewInstitution(void); + void slotSelectInstitution(int index); + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, InstitutionPage) + friend class Wizard; + friend class AccountSummaryPage; + friend class BrokeragePage; + }; +} // namespace + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kinstitutionpage.cpp b/kmymoney/wizards/newaccountwizard/kinstitutionpage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kinstitutionpage.cpp @@ -0,0 +1,147 @@ +/*************************************************************************** + kinstitutionpage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kinstitutionpage.h" +#include "kinstitutionpage_p.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kinstitutionpage.h" + +#include "knewaccountwizard.h" +#include "knewaccountwizard_p.h" +#include "kaccounttypepage.h" +#include "kinstitutionpage_p.h" +#include "mymoneyfile.h" +#include "mymoneyinstitution.h" +#include "wizardpage.h" + +namespace NewAccountWizard +{ + InstitutionPage::InstitutionPage(Wizard* wizard) : + QWidget(wizard), + WizardPage(*new InstitutionPagePrivate(wizard),StepInstitution, this, wizard) + { + Q_D(InstitutionPage); + d->ui->setupUi(this); + connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &InstitutionPage::slotLoadWidgets); + connect(d_func()->ui->m_newInstitutionButton, &QAbstractButton::clicked, this, &InstitutionPage::slotNewInstitution); + connect(d_func()->ui->m_institutionComboBox, static_cast(&QComboBox::activated), this, &InstitutionPage::slotSelectInstitution); + + slotLoadWidgets(); + d_func()->ui->m_institutionComboBox->setCurrentItem(0); + slotSelectInstitution(0); + } + + InstitutionPage::~InstitutionPage() + { + } + + void InstitutionPage::slotLoadWidgets() + { + Q_D(InstitutionPage); + d_func()->ui->m_institutionComboBox->clear(); + + d->m_list.clear(); + MyMoneyFile::instance()->institutionList(d->m_list); + qSort(d->m_list); + + QList::const_iterator it_l; + d->ui->m_institutionComboBox->addItem(QString()); + for (it_l = d->m_list.constBegin(); it_l != d->m_list.constEnd(); ++it_l) { + d->ui->m_institutionComboBox->addItem((*it_l).name()); + } + } + + void InstitutionPage::slotNewInstitution() + { + Q_D(InstitutionPage); + MyMoneyInstitution institution; + + emit d->m_wizard->createInstitution(institution); + + if (!institution.id().isEmpty()) { + QList::const_iterator it_l; + int i = 0; + for (it_l = d->m_list.constBegin(); it_l != d->m_list.constEnd(); ++it_l) { + if ((*it_l).id() == institution.id()) { + // select the item and remember that the very first one is the empty item + d->ui->m_institutionComboBox->setCurrentIndex(i + 1); + slotSelectInstitution(i + 1); + d->ui->m_accountNumber->setFocus(); + break; + } + ++i; + } + } + } + + void InstitutionPage::slotSelectInstitution(const int index) + { + Q_D(InstitutionPage); + d->ui->m_accountNumber->setEnabled(index != 0); + d->ui->m_iban->setEnabled(index != 0); + } + + void InstitutionPage::selectExistingInstitution(const QString& id) + { + Q_D(InstitutionPage); + for (int i = 0; i < d->m_list.length(); ++i) { + if (d->m_list[i].id() == id) { + d->ui->m_institutionComboBox->setCurrentIndex(i + 1); + slotSelectInstitution(i + 1); + break; + } + } + } + + const MyMoneyInstitution& InstitutionPage::institution() const + { + Q_D(const InstitutionPage); + static MyMoneyInstitution emptyInstitution; + if (d->ui->m_institutionComboBox->currentIndex() == 0) + return emptyInstitution; + + return d->m_list[d->ui->m_institutionComboBox->currentIndex()-1]; + } + + KMyMoneyWizardPage* InstitutionPage::nextPage() const + { + Q_D(const InstitutionPage); + return d->m_wizard->d_func()->m_accountTypePage; + } + + QWidget* InstitutionPage::initialFocusWidget(void) const + { + Q_D(const InstitutionPage); + return d->ui->m_institutionComboBox; + } +} diff --git a/kmymoney/wizards/newaccountwizard/kinstitutionpagedecl.ui b/kmymoney/wizards/newaccountwizard/kinstitutionpage.ui rename from kmymoney/wizards/newaccountwizard/kinstitutionpagedecl.ui rename to kmymoney/wizards/newaccountwizard/kinstitutionpage.ui --- a/kmymoney/wizards/newaccountwizard/kinstitutionpagedecl.ui +++ b/kmymoney/wizards/newaccountwizard/kinstitutionpage.ui @@ -1,7 +1,7 @@ - KInstitutionPageDecl - + KInstitutionPage + 0 diff --git a/kmymoney/wizards/newaccountwizard/kinstitutionpage_p.h b/kmymoney/wizards/newaccountwizard/kinstitutionpage_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kinstitutionpage_p.h @@ -0,0 +1,61 @@ +/*************************************************************************** + kinstitutionpage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDINSTITUTION_P_H +#define KNEWACCOUNTWIZARDINSTITUTION_P_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kinstitutionpage.h" + +#include "wizardpage_p.h" +#include "mymoneyinstitution.h" + +namespace NewAccountWizard +{ + class Wizard; + + class InstitutionPagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(InstitutionPagePrivate) + + public: + InstitutionPagePrivate(QObject* parent) : + WizardPagePrivate(parent), + ui(new Ui::KInstitutionPage) + { + } + + ~InstitutionPagePrivate() + { + delete ui; + } + + Ui::KInstitutionPage *ui; + QList m_list; + }; +} + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kloandetailspage.h b/kmymoney/wizards/newaccountwizard/kloandetailspage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kloandetailspage.h @@ -0,0 +1,80 @@ +/*************************************************************************** + kloandetailspage.h + ------------------- + begin : Tue Sep 25 2007 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDLOANDETAILSPAGE_H +#define KNEWACCOUNTWIZARDLOANDETAILSPAGE_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" + +namespace NewAccountWizard +{ + class Wizard; + + class LoanDetailsPagePrivate; + class LoanDetailsPage : public QWidget, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(LoanDetailsPage) + + public: + explicit LoanDetailsPage(Wizard* parent); + ~LoanDetailsPage() override; + + void enterPage(void); + KMyMoneyWizardPage* nextPage(void) const; + virtual bool isComplete(void) const; + + QWidget* initialFocusWidget(void) const override; + + /** + * This method returns the number of payments depending on + * the settings of m_termAmount and m_termUnit widgets + */ + int term(void) const; + + private: + /** + * This method is used to update the term widgets + * according to the length of the given @a term. + * The term is also converted into a string and returned. + */ + QString updateTermWidgets(const double term); + + private slots: + void slotValuesChanged(void); + void slotCalculate(void); + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, LoanDetailsPage) + friend class Wizard; + friend class AccountSummaryPage; + friend class LoanPaymentPage; + }; +} // namespace + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kloandetailspage.cpp b/kmymoney/wizards/newaccountwizard/kloandetailspage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kloandetailspage.cpp @@ -0,0 +1,424 @@ +/*************************************************************************** + kloandetailspage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kloandetailspage.h" +#include "kloandetailspage_p.h" + +#include + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kgeneralloaninfopage.h" +#include "ui_kloandetailspage.h" + +#include "kmymoneyedit.h" +#include "kmymoneyfrequencycombo.h" +#include "knewaccountwizard.h" +#include "knewaccountwizard_p.h" +#include "kgeneralloaninfopage.h" +#include "kgeneralloaninfopage_p.h" +#include "kloandetailspage_p.h" +#include "kloanpaymentpage.h" +#include "mymoneyenums.h" +#include "mymoneyexception.h" +#include "mymoneyfinancialcalculator.h" +#include "mymoneymoney.h" +#include "wizardpage.h" + +using namespace eMyMoney; + +namespace NewAccountWizard +{ + LoanDetailsPage::LoanDetailsPage(Wizard* wizard) : + QWidget(wizard), + WizardPage(*new LoanDetailsPagePrivate(wizard), StepPayments, this, wizard) + { + Q_D(LoanDetailsPage); + d->m_needCalculate = true; + d->ui->setupUi(this); + // force the balloon payment to zero (default) + d->ui->m_balloonAmount->setValue(MyMoneyMoney()); + // allow any precision for the interest rate + d->ui->m_interestRate->setPrecision(-1); + + connect(d->ui->m_paymentDue, static_cast(&QComboBox::activated), this, &LoanDetailsPage::slotValuesChanged); + + connect(d->ui->m_termAmount, static_cast(&QSpinBox::valueChanged), this, &LoanDetailsPage::slotValuesChanged); + connect(d->ui->m_termUnit, static_cast(&QComboBox::highlighted), this, &LoanDetailsPage::slotValuesChanged); + connect(d->ui->m_loanAmount, &KMyMoneyEdit::textChanged, this, &LoanDetailsPage::slotValuesChanged); + connect(d->ui->m_interestRate, &KMyMoneyEdit::textChanged, this, &LoanDetailsPage::slotValuesChanged); + connect(d->ui->m_paymentAmount, &KMyMoneyEdit::textChanged, this, &LoanDetailsPage::slotValuesChanged); + connect(d->ui->m_balloonAmount, &KMyMoneyEdit::textChanged, this, &LoanDetailsPage::slotValuesChanged); + + connect(d->ui->m_calculateButton, &QAbstractButton::clicked, this, &LoanDetailsPage::slotCalculate); + } + + LoanDetailsPage::~LoanDetailsPage() + { + } + + void LoanDetailsPage::enterPage() + { + Q_D(LoanDetailsPage); + // we need to remove a bunch of entries of the payment frequencies + d->ui->m_termUnit->clear(); + + d->m_mandatoryGroup->clear(); + if (!d->m_wizard->openingBalance().isZero()) { + d->m_mandatoryGroup->add(d->ui->m_loanAmount->lineedit()); + if (d->ui->m_loanAmount->lineedit()->text().length() == 0) { + d->ui->m_loanAmount->setValue(d->m_wizard->openingBalance().abs()); + } + } + + switch (d->m_wizard->d_func()->m_generalLoanInfoPage->d_func()->ui->m_paymentFrequency->currentItem()) { + default: + d->ui->m_termUnit->insertItem(i18n("Payments"), (int)Schedule::Occurrence::Once); + d->ui->m_termUnit->setCurrentItem((int)Schedule::Occurrence::Once); + break; + case Schedule::Occurrence::Monthly: + d->ui->m_termUnit->insertItem(i18n("Months"), (int)Schedule::Occurrence::Monthly); + d->ui->m_termUnit->insertItem(i18n("Years"), (int)Schedule::Occurrence::Yearly); + d->ui->m_termUnit->setCurrentItem((int)Schedule::Occurrence::Monthly); + break; + case Schedule::Occurrence::Yearly: + d->ui->m_termUnit->insertItem(i18n("Years"), (int)Schedule::Occurrence::Yearly); + d->ui->m_termUnit->setCurrentItem((int)Schedule::Occurrence::Yearly); + break; + } + } + + void LoanDetailsPage::slotValuesChanged() + { + Q_D(LoanDetailsPage); + d->m_needCalculate = true; + d->m_wizard->completeStateChanged(); + } + + void LoanDetailsPage::slotCalculate() + { + Q_D(LoanDetailsPage); + MyMoneyFinancialCalculator calc; + double val; + int PF, CF; + QString result; + bool moneyBorrowed = d->m_wizard->moneyBorrowed(); + bool moneyLend = !moneyBorrowed; + + // FIXME: for now, we only support interest calculation at the end of the period + calc.setBep(); + // FIXME: for now, we only support periodic compounding + calc.setDisc(); + + PF = d->m_wizard->d_func()->m_generalLoanInfoPage->d_func()->ui->m_paymentFrequency->eventsPerYear(); + CF = d->m_wizard->d_func()->m_generalLoanInfoPage->d_func()->ui->m_compoundFrequency->eventsPerYear(); + + if (PF == 0 || CF == 0) + return; + + calc.setPF(PF); + calc.setCF(CF); + + + if (!d->ui->m_loanAmount->lineedit()->text().isEmpty()) { + val = d->ui->m_loanAmount->value().abs().toDouble(); + if (moneyBorrowed) + val = -val; + calc.setPv(val); + } + + if (!d->ui->m_interestRate->lineedit()->text().isEmpty()) { + val = d->ui->m_interestRate->value().abs().toDouble(); + calc.setIr(val); + } + + if (!d->ui->m_paymentAmount->lineedit()->text().isEmpty()) { + val = d->ui->m_paymentAmount->value().abs().toDouble(); + if (moneyLend) + val = -val; + calc.setPmt(val); + } + + if (!d->ui->m_balloonAmount->lineedit()->text().isEmpty()) { + val = d->ui->m_balloonAmount->value().abs().toDouble(); + if (moneyLend) + val = -val; + calc.setFv(val); + } + + if (d->ui->m_termAmount->value() != 0) { + calc.setNpp(term()); + } + + // setup of parameters is done, now do the calculation + try { + if (d->ui->m_loanAmount->lineedit()->text().isEmpty()) { + // calculate the amount of the loan out of the other information + val = calc.presentValue(); + d->ui->m_loanAmount->loadText(MyMoneyMoney(static_cast(val)).abs().formatMoney(QString(), d->m_wizard->d_func()->precision())); + result = i18n("KMyMoney has calculated the amount of the loan as %1.", d->ui->m_loanAmount->lineedit()->text()); + + } else if (d->ui->m_interestRate->lineedit()->text().isEmpty()) { + // calculate the interest rate out of the other information + val = calc.interestRate(); + + d->ui->m_interestRate->loadText(MyMoneyMoney(static_cast(val)).abs().formatMoney(QString(), 3)); + result = i18n("KMyMoney has calculated the interest rate to %1%.", d->ui->m_interestRate->lineedit()->text()); + + } else if (d->ui->m_paymentAmount->lineedit()->text().isEmpty()) { + // calculate the periodical amount of the payment out of the other information + val = calc.payment(); + d->ui->m_paymentAmount->setValue(MyMoneyMoney(static_cast(val)).abs()); + // reset payment as it might have changed due to rounding + val = d->ui->m_paymentAmount->value().abs().toDouble(); + if (moneyLend) + val = -val; + calc.setPmt(val); + + result = i18n("KMyMoney has calculated a periodic payment of %1 to cover principal and interest.", d->ui->m_paymentAmount->lineedit()->text()); + + val = calc.futureValue(); + if ((moneyBorrowed && val < 0 && qAbs(val) >= qAbs(calc.payment())) + || (moneyLend && val > 0 && qAbs(val) >= qAbs(calc.payment()))) { + calc.setNpp(calc.npp() - 1); + // updateTermWidgets(calc.npp()); + val = calc.futureValue(); + MyMoneyMoney refVal(static_cast(val)); + d->ui->m_balloonAmount->loadText(refVal.abs().formatMoney(QString(), d->m_wizard->d_func()->precision())); + result += QString(" "); + result += i18n("The number of payments has been decremented and the balloon payment has been modified to %1.", d->ui->m_balloonAmount->lineedit()->text()); + } else if ((moneyBorrowed && val < 0 && qAbs(val) < qAbs(calc.payment())) + || (moneyLend && val > 0 && qAbs(val) < qAbs(calc.payment()))) { + d->ui->m_balloonAmount->loadText(MyMoneyMoney().formatMoney(QString(), d->m_wizard->d_func()->precision())); + } else { + MyMoneyMoney refVal(static_cast(val)); + d->ui->m_balloonAmount->loadText(refVal.abs().formatMoney(QString(), d->m_wizard->d_func()->precision())); + result += i18n("The balloon payment has been modified to %1.", d->ui->m_balloonAmount->lineedit()->text()); + } + + } else if (d->ui->m_termAmount->value() == 0) { + // calculate the number of payments out of the other information + val = calc.numPayments(); + if (val == 0) + throw MYMONEYEXCEPTION("incorrect fincancial calculation"); + + // if the number of payments has a fractional part, then we + // round it to the smallest integer and calculate the balloon payment + result = i18n("KMyMoney has calculated the term of your loan as %1. ", updateTermWidgets(qFloor(val))); + + if (val != qFloor(val)) { + calc.setNpp(qFloor(val)); + val = calc.futureValue(); + MyMoneyMoney refVal(static_cast(val)); + d->ui->m_balloonAmount->loadText(refVal.abs().formatMoney(QString(), d->m_wizard->d_func()->precision())); + result += i18n("The balloon payment has been modified to %1.", d->ui->m_balloonAmount->lineedit()->text()); + } + + } else { + // calculate the future value of the loan out of the other information + val = calc.futureValue(); + + // we differentiate between the following cases: + // a) the future value is greater than a payment + // b) the future value is less than a payment or the loan is overpaid + // c) all other cases + // + // a) means, we have paid more than we owed. This can't be + // b) means, we paid more than we owed but the last payment is + // less in value than regular payments. That means, that the + // future value is to be treated as (fully payed back) + // c) the loan is not payed back yet + if ((moneyBorrowed && val < 0 && qAbs(val) > qAbs(calc.payment())) + || (moneyLend && val > 0 && qAbs(val) > qAbs(calc.payment()))) { + // case a) + qDebug("Future Value is %f", val); + throw MYMONEYEXCEPTION("incorrect fincancial calculation"); + + } else if ((moneyBorrowed && val < 0 && qAbs(val) <= qAbs(calc.payment())) + || (moneyLend && val > 0 && qAbs(val) <= qAbs(calc.payment()))) { + // case b) + val = 0; + } + + MyMoneyMoney refVal(static_cast(val)); + result = i18n("KMyMoney has calculated a balloon payment of %1 for this loan.", refVal.abs().formatMoney(QString(), d->m_wizard->d_func()->precision())); + + if (!d->ui->m_balloonAmount->lineedit()->text().isEmpty()) { + if ((d->ui->m_balloonAmount->value().abs() - refVal.abs()).abs().toDouble() > 1) { + throw MYMONEYEXCEPTION("incorrect fincancial calculation"); + } + result = i18n("KMyMoney has successfully verified your loan information."); + } + d->ui->m_balloonAmount->loadText(refVal.abs().formatMoney(QString(), d->m_wizard->d_func()->precision())); + } + + } catch (const MyMoneyException &) { + KMessageBox::error(0, + i18n("You have entered mis-matching information. Please modify " + "your figures or leave one value empty " + "to let KMyMoney calculate it for you"), + i18n("Calculation error")); + return; + } + + result += i18n("\n\nAccept this or modify the loan information and recalculate."); + + KMessageBox::information(0, result, i18n("Calculation successful")); + d->m_needCalculate = false; + + // now update change + d->m_wizard->completeStateChanged(); + } + + int LoanDetailsPage::term() const + { + Q_D(const LoanDetailsPage); + int factor = 0; + + if (d->ui->m_termAmount->value() != 0) { + factor = 1; + switch (d->ui->m_termUnit->currentItem()) { + case Schedule::Occurrence::Yearly: // years + factor = 12; + // intentional fall through + + case Schedule::Occurrence::Monthly: // months + factor *= 30; + factor *= d->ui->m_termAmount->value(); + // factor now is the duration in days. we divide this by the + // payment frequency and get the number of payments + factor /= d->m_wizard->d_func()->m_generalLoanInfoPage->d_func()->ui->m_paymentFrequency->daysBetweenEvents(); + break; + + default: + qDebug("Unknown term unit %d in LoanDetailsPage::term(). Using payments.", (int)d->ui->m_termUnit->currentItem()); + // intentional fall through + + case Schedule::Occurrence::Once: // payments + factor = d->ui->m_termAmount->value(); + break; + } + } + return factor; + } + + QString LoanDetailsPage::updateTermWidgets(const double val) + { + Q_D(LoanDetailsPage); + long vl = qFloor(val); + + QString valString; + Schedule::Occurrence unit = d->ui->m_termUnit->currentItem(); + + if ((unit == Schedule::Occurrence::Monthly) + && ((vl % 12) == 0)) { + vl /= 12; + unit = Schedule::Occurrence::Yearly; + } + + switch (unit) { + case Schedule::Occurrence::Monthly: + valString = i18np("one month", "%1 months", vl); + d->ui->m_termUnit->setCurrentItem((int)Schedule::Occurrence::Monthly); + break; + case Schedule::Occurrence::Yearly: + valString = i18np("one year", "%1 years", vl); + d->ui->m_termUnit->setCurrentItem((int)Schedule::Occurrence::Yearly); + break; + default: + valString = i18np("one payment", "%1 payments", vl); + d->ui->m_termUnit->setCurrentItem((int)Schedule::Occurrence::Once); + break; + } + d->ui->m_termAmount->setValue(vl); + return valString; + } + + bool LoanDetailsPage::isComplete() const + { + Q_D(const LoanDetailsPage); + // bool rc = KMyMoneyWizardPage::isComplete(); + + int fieldCnt = 0; + + if (d->ui->m_loanAmount->lineedit()->text().length() > 0) { + fieldCnt++; + } + + if (d->ui->m_interestRate->lineedit()->text().length() > 0) { + fieldCnt++; + } + + if (d->ui->m_termAmount->value() != 0) { + fieldCnt++; + } + + if (d->ui->m_paymentAmount->lineedit()->text().length() > 0) { + fieldCnt++; + } + + if (d->ui->m_balloonAmount->lineedit()->text().length() > 0) { + fieldCnt++; + } + + d->ui->m_calculateButton->setEnabled(fieldCnt == 4 || (fieldCnt == 5 && d->m_needCalculate)); + + d->ui->m_calculateButton->setAutoDefault(false); + d->ui->m_calculateButton->setDefault(false); + if (d->m_needCalculate && fieldCnt == 4) { + d->m_wizard->d_func()->m_nextButton->setToolTip(i18n("Press Calculate to verify the values")); + d->ui->m_calculateButton->setAutoDefault(true); + d->ui->m_calculateButton->setDefault(true); + } else if (fieldCnt != 5) { + d->m_wizard->d_func()->m_nextButton->setToolTip(i18n("Not all details supplied")); + d->ui->m_calculateButton->setAutoDefault(true); + d->ui->m_calculateButton->setDefault(true); + } + d->m_wizard->d_func()->m_nextButton->setAutoDefault(!d->ui->m_calculateButton->autoDefault()); + d->m_wizard->d_func()->m_nextButton->setDefault(!d->ui->m_calculateButton->autoDefault()); + + return (fieldCnt == 5) && !d->m_needCalculate; + } + + QWidget* LoanDetailsPage::initialFocusWidget(void) const + { + Q_D(const LoanDetailsPage); + return d->ui->m_paymentDue; + } + + KMyMoneyWizardPage* LoanDetailsPage::nextPage() const + { + Q_D(const LoanDetailsPage); + return d->m_wizard->d_func()->m_loanPaymentPage; + } +} diff --git a/kmymoney/wizards/newaccountwizard/kloandetailspagedecl.ui b/kmymoney/wizards/newaccountwizard/kloandetailspage.ui rename from kmymoney/wizards/newaccountwizard/kloandetailspagedecl.ui rename to kmymoney/wizards/newaccountwizard/kloandetailspage.ui --- a/kmymoney/wizards/newaccountwizard/kloandetailspagedecl.ui +++ b/kmymoney/wizards/newaccountwizard/kloandetailspage.ui @@ -3,8 +3,8 @@ - KLoanDetailsPageDecl - + KLoanDetailsPage + 0 diff --git a/kmymoney/wizards/newaccountwizard/kloandetailspage_p.h b/kmymoney/wizards/newaccountwizard/kloandetailspage_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kloandetailspage_p.h @@ -0,0 +1,60 @@ +/*************************************************************************** + kloandetailspage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDLOANDETAILSPAGE_P_H +#define KNEWACCOUNTWIZARDLOANDETAILSPAGE_P_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kloandetailspage.h" + +#include "wizardpage_p.h" + +namespace NewAccountWizard +{ + class Wizard; + + class LoanDetailsPagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(LoanDetailsPagePrivate) + + public: + LoanDetailsPagePrivate(QObject* parent) : + WizardPagePrivate(parent), + ui(new Ui::KLoanDetailsPage) + { + } + + ~LoanDetailsPagePrivate() + { + delete ui; + } + + Ui::KLoanDetailsPage *ui; + bool m_needCalculate; + }; +} + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kloanpaymentpage.h b/kmymoney/wizards/newaccountwizard/kloanpaymentpage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kloanpaymentpage.h @@ -0,0 +1,85 @@ +/*************************************************************************** + kloanpaymentpage.h + ------------------- + begin : Tue Sep 25 2007 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDLOANPAYMENTPAGE_H +#define KNEWACCOUNTWIZARDLOANPAYMENTPAGE_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" + +class MyMoneyMoney; +class MyMoneySplit; + +namespace NewAccountWizard +{ + class Wizard; + + class LoanPaymentPagePrivate; + class LoanPaymentPage : public QWidget, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(LoanPaymentPage) + + public: + explicit LoanPaymentPage(Wizard* parent); + ~LoanPaymentPage() override; + + KMyMoneyWizardPage* nextPage() const; + + void enterPage(void); + + /** + * This method returns the sum of the additional fees + */ + MyMoneyMoney additionalFees() const; + + /** + * This method returns the base payment, that's principal and interest + */ + MyMoneyMoney basePayment() const; + + /** + * This method returns the splits that make up the additional fees in @p list. + * @note The splits may contain assigned ids which the caller must remove before + * adding the splits to a MyMoneyTransaction object. + */ + void additionalFeesSplits(QList& list); + + protected slots: + void slotAdditionalFees(); + + protected: + void updateAmounts(); + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, LoanPaymentPage) + friend class Wizard; + friend class AccountSummaryPage; + }; +} // namespace + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kloanpaymentpage.cpp b/kmymoney/wizards/newaccountwizard/kloanpaymentpage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kloanpaymentpage.cpp @@ -0,0 +1,152 @@ +/*************************************************************************** + kloanpaymentpage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kloanpaymentpage.h" +#include "kloanpaymentpage_p.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kloanpaymentpage.h" + +#include "kmymoneyedit.h" +#include "knewaccountwizard.h" +#include "knewaccountwizard_p.h" +#include "kloandetailspage.h" +#include "kloandetailspage_p.h" +#include "kloanpaymentpage_p.h" +#include "kloanschedulepage.h" +#include "ksplittransactiondlg.h" +#include "mymoneyaccount.h" +#include "mymoneysecurity.h" +#include "mymoneysplit.h" +#include "mymoneytransaction.h" +#include "wizardpage.h" + +namespace NewAccountWizard +{ + LoanPaymentPage::LoanPaymentPage(Wizard* wizard) : + QWidget(wizard), + WizardPage(*new LoanPaymentPagePrivate(wizard), StepFees, this, wizard) + { + Q_D(LoanPaymentPage); + d->ui->setupUi(this); + d->phonyAccount = MyMoneyAccount(QLatin1String("Phony-ID"), MyMoneyAccount()); + + d->phonySplit.setAccountId(d->phonyAccount.id()); + d->phonySplit.setValue(MyMoneyMoney()); + d->phonySplit.setShares(MyMoneyMoney()); + + d->additionalFeesTransaction.addSplit(d->phonySplit); + + connect(d->ui->m_additionalFeesButton, &QAbstractButton::clicked, this, &LoanPaymentPage::slotAdditionalFees); + } + + LoanPaymentPage::~LoanPaymentPage() + { + } + + MyMoneyMoney LoanPaymentPage::basePayment() const + { + Q_D(const LoanPaymentPage); + return d->m_wizard->d_func()->m_loanDetailsPage->d_func()->ui->m_paymentAmount->value(); + } + + MyMoneyMoney LoanPaymentPage::additionalFees() const + { + Q_D(const LoanPaymentPage); + return d->additionalFees; + } + + void LoanPaymentPage::additionalFeesSplits(QList& list) + { + Q_D(LoanPaymentPage); + list.clear(); + + QList::ConstIterator it; + for (it = d->additionalFeesTransaction.splits().constBegin(); it != d->additionalFeesTransaction.splits().constEnd(); ++it) { + if ((*it).accountId() != d->phonyAccount.id()) { + list << (*it); + } + } + } + + void LoanPaymentPage::updateAmounts() + { + Q_D(LoanPaymentPage); + d->ui->m_additionalFees->setText(d->additionalFees.formatMoney(d->m_wizard->d_func()->currency().tradingSymbol(), d->m_wizard->d_func()->precision())); + d->ui->m_totalPayment->setText((basePayment() + d->additionalFees).formatMoney(d->m_wizard->d_func()->currency().tradingSymbol(), d->m_wizard->d_func()->precision())); + } + + void LoanPaymentPage::enterPage() + { + Q_D(LoanPaymentPage); + const MyMoneySecurity& currency = d->m_wizard->d_func()->currency(); + + d->ui->m_basePayment->setText(basePayment().formatMoney(currency.tradingSymbol(), d->m_wizard->d_func()->precision())); + d->phonyAccount.setCurrencyId(currency.id()); + d->additionalFeesTransaction.setCommodity(currency.id()); + + updateAmounts(); + } + + void LoanPaymentPage::slotAdditionalFees() + { + Q_D(LoanPaymentPage); + QMap priceInfo; + QPointer dlg = new KSplitTransactionDlg(d->additionalFeesTransaction, d->phonySplit, d->phonyAccount, false, !d->m_wizard->moneyBorrowed(), MyMoneyMoney(), priceInfo); + + // connect(dlg, SIGNAL(newCategory(MyMoneyAccount&)), this, SIGNAL(newCategory(MyMoneyAccount&))); + + if (dlg->exec() == QDialog::Accepted) { + d->additionalFeesTransaction = dlg->transaction(); + // sum up the additional fees + QList::ConstIterator it; + + d->additionalFees = MyMoneyMoney(); + for (it = d->additionalFeesTransaction.splits().constBegin(); it != d->additionalFeesTransaction.splits().constEnd(); ++it) { + if ((*it).accountId() != d->phonyAccount.id()) { + d->additionalFees += (*it).shares(); + } + } + updateAmounts(); + } + + delete dlg; + } + + KMyMoneyWizardPage* LoanPaymentPage::nextPage() const + { + Q_D(const LoanPaymentPage); + return d->m_wizard->d_func()->m_loanSchedulePage; + } + +} diff --git a/kmymoney/wizards/newaccountwizard/kloanpaymentpagedecl.ui b/kmymoney/wizards/newaccountwizard/kloanpaymentpage.ui rename from kmymoney/wizards/newaccountwizard/kloanpaymentpagedecl.ui rename to kmymoney/wizards/newaccountwizard/kloanpaymentpage.ui --- a/kmymoney/wizards/newaccountwizard/kloanpaymentpagedecl.ui +++ b/kmymoney/wizards/newaccountwizard/kloanpaymentpage.ui @@ -3,8 +3,8 @@ - KLoanPaymentPageDecl - + KLoanPaymentPage + 0 diff --git a/kmymoney/wizards/newaccountwizard/kloanpaymentpage_p.h b/kmymoney/wizards/newaccountwizard/kloanpaymentpage_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kloanpaymentpage_p.h @@ -0,0 +1,67 @@ +/*************************************************************************** + kloanpaymentpage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDLOANPAYMENTPAGE_P_H +#define KNEWACCOUNTWIZARDLOANPAYMENTPAGE_P_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kloanpaymentpage.h" + +#include "wizardpage_p.h" +#include "mymoneyaccount.h" +#include "mymoneymoney.h" +#include "mymoneysplit.h" +#include "mymoneytransaction.h" + +namespace NewAccountWizard +{ + class Wizard; + + class LoanPaymentPagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(LoanPaymentPagePrivate) + + public: + LoanPaymentPagePrivate(QObject* parent) : + WizardPagePrivate(parent), + ui(new Ui::KLoanPaymentPage) + { + } + + ~LoanPaymentPagePrivate() + { + delete ui; + } + + Ui::KLoanPaymentPage *ui; + MyMoneyAccount phonyAccount; + MyMoneySplit phonySplit; + MyMoneyTransaction additionalFeesTransaction; + MyMoneyMoney additionalFees; + }; +} + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kloanpayoutpage.h b/kmymoney/wizards/newaccountwizard/kloanpayoutpage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kloanpayoutpage.h @@ -0,0 +1,69 @@ +/*************************************************************************** + kloanpayoutpage.h + ------------------- + begin : Tue Sep 25 2007 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDPAYOUT_H +#define KNEWACCOUNTWIZARDPAYOUT_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" + +namespace NewAccountWizard +{ + class Wizard; + + class LoanPayoutPagePrivate; + class LoanPayoutPage : public QWidget, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(LoanPayoutPage) + + public: + explicit LoanPayoutPage(Wizard* parent); + ~LoanPayoutPage() override; + + void enterPage(void); + virtual bool isComplete(void) const; + + KMyMoneyWizardPage* nextPage(void) const; + + QWidget* initialFocusWidget(void) const override; + + QString payoutAccountId(void) const; + + private slots: + void slotLoadWidgets(void); + void slotCreateAssetAccount(void); + void slotButtonsToggled(void); + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, LoanPayoutPage) + friend class Wizard; + friend class AccountSummaryPage; + }; +} // namespace + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kloanpayoutpage.cpp b/kmymoney/wizards/newaccountwizard/kloanpayoutpage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kloanpayoutpage.cpp @@ -0,0 +1,173 @@ +/*************************************************************************** + kloanpayoutpage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kloanpayoutpage.h" +#include "kloanpayoutpage_p.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kaccounttypepage.h" +#include "ui_kloanpayoutpage.h" + +#include +#include "icons.h" +#include "kmymoneyaccountselector.h" +#include "kmymoneycategory.h" +#include "kmymoneydateinput.h" +#include "kmymoneywizardpage.h" +#include "knewaccountwizard.h" +#include "knewaccountwizard_p.h" +#include "kaccountsummarypage.h" +#include "kaccounttypepage.h" +#include "kaccounttypepage_p.h" +#include "kloanpayoutpage_p.h" +#include "mymoneyaccount.h" +#include "mymoneyenums.h" +#include "mymoneyfile.h" +#include "wizardpage.h" + +using namespace NewAccountWizard; +using namespace Icons; +using namespace eMyMoney; + +namespace NewAccountWizard +{ + LoanPayoutPage::LoanPayoutPage(Wizard* wizard) : + QWidget(wizard), + WizardPage(*new LoanPayoutPagePrivate(wizard), StepPayout, this, wizard) + { + Q_D(LoanPayoutPage); + d->ui->setupUi(this); + d->m_mandatoryGroup->add(d->ui->m_assetAccount->lineEdit()); + d->m_mandatoryGroup->add(d->ui->m_loanAccount->lineEdit()); + + KGuiItem createAssetButtenItem(i18n("&Create..."), + QIcon::fromTheme(g_Icons[Icon::DocumentNew]), + i18n("Create a new asset account"), + i18n("If the asset account does not yet exist, press this button to create it.")); + KGuiItem::assign(d->ui->m_createAssetButton, createAssetButtenItem); + d->ui->m_createAssetButton->setToolTip(createAssetButtenItem.toolTip()); + d->ui->m_createAssetButton->setWhatsThis(createAssetButtenItem.whatsThis()); + connect(d->ui->m_createAssetButton, &QAbstractButton::clicked, this, &LoanPayoutPage::slotCreateAssetAccount); + + connect(d->ui->m_noPayoutTransaction, &QAbstractButton::toggled, this, &LoanPayoutPage::slotButtonsToggled); + connect(d->ui->m_refinanceLoan, &QAbstractButton::toggled, this, &LoanPayoutPage::slotButtonsToggled); + + connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &LoanPayoutPage::slotLoadWidgets); + slotLoadWidgets(); + } + + LoanPayoutPage::~LoanPayoutPage() + { + } + + void LoanPayoutPage::slotButtonsToggled() + { + Q_D(LoanPayoutPage); + // we don't go directly, as the order of the emission of signals to slots is + // not defined. Using a single shot timer postpones the call of m_mandatoryGroup::changed() + // until the next round of the main loop so we can be sure to see all relevant changes + // that happened in the meantime (eg. widgets are enabled and disabled) + QTimer::singleShot(0, d->m_mandatoryGroup, SLOT(changed())); + } + + void LoanPayoutPage::slotCreateAssetAccount() + { + Q_D(LoanPayoutPage); + MyMoneyAccount acc; + acc.setAccountType(Account::Asset); + acc.setOpeningDate(d->m_wizard->d_func()->m_accountTypePage->d_func()->ui->m_openingDate->date()); + + emit d->m_wizard->createAccount(acc); + + if (!acc.id().isEmpty()) { + d->ui->m_assetAccount->setSelectedItem(acc.id()); + } + } + + void LoanPayoutPage::slotLoadWidgets() + { + Q_D(LoanPayoutPage); + AccountSet set; + set.addAccountGroup(Account::Asset); + set.load(d->ui->m_assetAccount->selector()); + + set.clear(); + set.addAccountType(Account::Loan); + set.load(d->ui->m_loanAccount->selector()); + } + + void LoanPayoutPage::enterPage() + { + Q_D(LoanPayoutPage); + // only allow to create new asset accounts for liability loans + d->ui->m_createAssetButton->setEnabled(d->m_wizard->moneyBorrowed()); + d->ui->m_refinanceLoan->setEnabled(d->m_wizard->moneyBorrowed()); + if (!d->m_wizard->moneyBorrowed()) { + d->ui->m_refinanceLoan->setChecked(false); + } + d->ui->m_payoutDetailFrame->setDisabled(d->ui->m_noPayoutTransaction->isChecked()); + } + + KMyMoneyWizardPage* LoanPayoutPage::nextPage() const + { + Q_D(const LoanPayoutPage); + return d->m_wizard->d_func()->m_accountSummaryPage; + } + + QWidget* LoanPayoutPage::initialFocusWidget(void) const + { + Q_D(const LoanPayoutPage); + return d->ui->m_noPayoutTransaction; + } + + bool LoanPayoutPage::isComplete() const + { + Q_D(const LoanPayoutPage); + return KMyMoneyWizardPage::isComplete() | d->ui->m_noPayoutTransaction->isChecked(); + } + + QString LoanPayoutPage::payoutAccountId() const + { + Q_D(const LoanPayoutPage); + if (d->ui->m_refinanceLoan->isChecked()) { + return d->ui->m_loanAccount->selectedItem(); + } else { + return d->ui->m_assetAccount->selectedItem(); + } + } + +} diff --git a/kmymoney/wizards/newaccountwizard/kloanpayoutpagedecl.ui b/kmymoney/wizards/newaccountwizard/kloanpayoutpage.ui rename from kmymoney/wizards/newaccountwizard/kloanpayoutpagedecl.ui rename to kmymoney/wizards/newaccountwizard/kloanpayoutpage.ui --- a/kmymoney/wizards/newaccountwizard/kloanpayoutpagedecl.ui +++ b/kmymoney/wizards/newaccountwizard/kloanpayoutpage.ui @@ -3,8 +3,8 @@ - KLoanPayoutPageDecl - + KLoanPayoutPage + 0 diff --git a/kmymoney/wizards/newaccountwizard/kloanpayoutpage_p.h b/kmymoney/wizards/newaccountwizard/kloanpayoutpage_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kloanpayoutpage_p.h @@ -0,0 +1,59 @@ +/*************************************************************************** + kloanpayoutpage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDPAYOUT_P_H +#define KNEWACCOUNTWIZARDPAYOUT_P_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kloanpayoutpage.h" + +#include "wizardpage_p.h" + +namespace NewAccountWizard +{ + class Wizard; + + class LoanPayoutPagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(LoanPayoutPagePrivate) + + public: + LoanPayoutPagePrivate(QObject* parent) : + WizardPagePrivate(parent), + ui(new Ui::KLoanPayoutPage) + { + } + + ~LoanPayoutPagePrivate() + { + delete ui; + } + + Ui::KLoanPayoutPage *ui; + }; +} + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kloanschedulepage.h b/kmymoney/wizards/newaccountwizard/kloanschedulepage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kloanschedulepage.h @@ -0,0 +1,72 @@ +/*************************************************************************** + kloanschedulepage.h + ------------------- + begin : Tue Sep 25 2007 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDLOANSCHEDULEPAGE_H +#define KNEWACCOUNTWIZARDLOANSCHEDULEPAGE_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" + +class QDate; + +namespace NewAccountWizard +{ + class Wizard; + + class LoanSchedulePagePrivate; + class LoanSchedulePage : public QWidget, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(LoanSchedulePage) + + public: + explicit LoanSchedulePage(Wizard* parent); + ~LoanSchedulePage() override; + + void enterPage(void); + + KMyMoneyWizardPage* nextPage(void) const; + + /** + * This method returns the due date of the first payment to be recorded. + */ + QDate firstPaymentDueDate(void) const; + + QWidget* initialFocusWidget(void) const override; + + private slots: + void slotLoadWidgets(void); + void slotCreateCategory(const QString& name, QString& id); + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, LoanSchedulePage) + friend class Wizard; + friend class AccountSummaryPage; + }; +} // namespace + +#endif diff --git a/kmymoney/wizards/newaccountwizard/kloanschedulepage.cpp b/kmymoney/wizards/newaccountwizard/kloanschedulepage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kloanschedulepage.cpp @@ -0,0 +1,142 @@ +/*************************************************************************** + kloanschedulepage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kloanschedulepage.h" +#include "kloanschedulepage_p.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include +#include +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kgeneralloaninfopage.h" +#include "ui_kloanschedulepage.h" + +#include +#include "kmymoneyaccountselector.h" +#include "kmymoneycategory.h" +#include "kmymoneydateinput.h" +#include "knewaccountwizard.h" +#include "knewaccountwizard_p.h" +#include "kaccountsummarypage.h" +#include "kgeneralloaninfopage.h" +#include "kgeneralloaninfopage_p.h" +#include "kloanpayoutpage.h" +#include "mymoneyaccount.h" +#include "mymoneyfile.h" +#include "mymoneymoney.h" +#include "wizardpage.h" +#include "mymoneyenums.h" + +using namespace NewAccountWizard; +using namespace Icons; +using namespace eMyMoney; + +namespace NewAccountWizard +{ + LoanSchedulePage::LoanSchedulePage(Wizard* wizard) : + QWidget(wizard), + WizardPage(*new LoanSchedulePagePrivate(wizard), StepSchedule, this, wizard) + { + Q_D(const LoanSchedulePage); + d->ui->setupUi(this); + d->m_mandatoryGroup->add(d->ui->m_interestCategory->lineEdit()); + d->m_mandatoryGroup->add(d->ui->m_paymentAccount->lineEdit()); + connect(d->ui->m_interestCategory, &KMyMoneyCombo::createItem, this, &LoanSchedulePage::slotCreateCategory); + connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &LoanSchedulePage::slotLoadWidgets); + } + + LoanSchedulePage::~LoanSchedulePage() + { + } + + void LoanSchedulePage::slotCreateCategory(const QString& name, QString& id) + { + Q_D(LoanSchedulePage); + MyMoneyAccount acc, parent; + acc.setName(name); + + if (d->m_wizard->moneyBorrowed()) + parent = MyMoneyFile::instance()->expense(); + else + parent = MyMoneyFile::instance()->income(); + + emit d->m_wizard->createCategory(acc, parent); + + // return id + id = acc.id(); + } + + QDate LoanSchedulePage::firstPaymentDueDate() const + { + Q_D(const LoanSchedulePage); + if (d->ui->m_firstPaymentDueDate->isEnabled()) + return d->ui->m_firstPaymentDueDate->date(); + return d->m_wizard->d_func()->m_generalLoanInfoPage->d_func()->ui->m_firstPaymentDate->date(); + } + + QWidget* LoanSchedulePage::initialFocusWidget(void) const + { + Q_D(const LoanSchedulePage); + return d->ui->m_interestCategory; + } + + void LoanSchedulePage::enterPage() + { + Q_D(LoanSchedulePage); + d->ui->m_interestCategory->setFocus(); + d->ui->m_firstPaymentDueDate->setDisabled(d->m_wizard->d_func()->m_generalLoanInfoPage->recordAllPayments()); + slotLoadWidgets(); + } + + void LoanSchedulePage::slotLoadWidgets() + { + Q_D(LoanSchedulePage); + AccountSet set; + if (d->m_wizard->moneyBorrowed()) + set.addAccountGroup(Account::Expense); + else + set.addAccountGroup(Account::Income); + set.load(d->ui->m_interestCategory->selector()); + + set.clear(); + set.addAccountGroup(Account::Asset); + set.load(d->ui->m_paymentAccount->selector()); + } + + KMyMoneyWizardPage* LoanSchedulePage::nextPage() const + { + Q_D(const LoanSchedulePage); + // if the balance widget of the general loan info page is enabled and + // the value is not zero, then the payout already happened and we don't + // aks for it. + if (d->m_wizard->openingBalance().isZero()) + return d->m_wizard->d_func()->m_loanPayoutPage; + return d->m_wizard->d_func()->m_accountSummaryPage; + } +} diff --git a/kmymoney/wizards/newaccountwizard/kloanschedulepagedecl.ui b/kmymoney/wizards/newaccountwizard/kloanschedulepage.ui rename from kmymoney/wizards/newaccountwizard/kloanschedulepagedecl.ui rename to kmymoney/wizards/newaccountwizard/kloanschedulepage.ui --- a/kmymoney/wizards/newaccountwizard/kloanschedulepagedecl.ui +++ b/kmymoney/wizards/newaccountwizard/kloanschedulepage.ui @@ -3,8 +3,8 @@ - KLoanSchedulePageDecl - + KLoanSchedulePage + 0 diff --git a/kmymoney/wizards/newaccountwizard/kloanschedulepage_p.h b/kmymoney/wizards/newaccountwizard/kloanschedulepage_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newaccountwizard/kloanschedulepage_p.h @@ -0,0 +1,59 @@ +/*************************************************************************** + kloanschedulepage.cpp + ------------------- + begin : Tue Sep 25 2006 + copyright : (C) 2007 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWACCOUNTWIZARDLOANSCHEDULEPAGE_P_H +#define KNEWACCOUNTWIZARDLOANSCHEDULEPAGE_P_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kloanschedulepage.h" + +#include "wizardpage_p.h" + +namespace NewAccountWizard +{ + class Wizard; + + class LoanSchedulePagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(LoanSchedulePagePrivate) + + public: + LoanSchedulePagePrivate(QObject* parent) : + WizardPagePrivate(parent), + ui(new Ui::KLoanSchedulePage) + { + } + + ~LoanSchedulePagePrivate() + { + delete ui; + } + + Ui::KLoanSchedulePage *ui; + }; +} + +#endif diff --git a/kmymoney/wizards/newaccountwizard/knewaccountwizard.h b/kmymoney/wizards/newaccountwizard/knewaccountwizard.h --- a/kmymoney/wizards/newaccountwizard/knewaccountwizard.h +++ b/kmymoney/wizards/newaccountwizard/knewaccountwizard.h @@ -4,6 +4,7 @@ begin : Tue Sep 25 2007 copyright : (C) 2007 Thomas Baumgart email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz ***************************************************************************/ /*************************************************************************** @@ -25,104 +26,107 @@ // Project Includes #include "kmymoneywizard.h" -#include "mymoneyaccountloan.h" -#include "mymoneymoney.h" -#include "mymoneyschedule.h" +class MyMoneyMoney; class MyMoneyPrice; -class MyMoneySecurity; class MyMoneyInstitution; class MyMoneyTransaction; +class MyMoneySchedule; +class MyMoneyAccount; /** * @author Thomas Baumgart */ namespace NewAccountWizard { + enum steps { + StepInstitution = 1, + StepAccount, + StepBroker, + StepDetails, + StepPayments, + StepFees, + StepSchedule, + StepPayout, + StepParentAccount, + StepFinish + }; -class AccountTypePage; -class InstitutionPage; -class BrokeragePage; -class CreditCardSchedulePage; -class GeneralLoanInfoPage; -class LoanDetailsPage; -class LoanPaymentPage; -class LoanSchedulePage; -class LoanPayoutPage; -class HierarchyPage; -class AccountSummaryPage; - -/** + /** * @author Thomas Baumgart * * This class implements the new account wizard which is used to gather * the required information from the user to create a new account */ -class Wizard : public KMyMoneyWizard -{ - friend class AccountTypePage; - friend class InstitutionPage; - friend class BrokeragePage; - friend class CreditCardSchedulePage; - friend class GeneralLoanInfoPage; - friend class LoanDetailsPage; - friend class LoanPaymentPage; - friend class LoanSchedulePage; - friend class LoanPayoutPage; - friend class HierarchyPage; - friend class AccountSummaryPage; - - Q_OBJECT -public: - explicit Wizard(QWidget* parent = 0, bool modal = false, Qt::WindowFlags flags = 0); - - /** + class WizardPrivate; + class Wizard : public KMyMoneyWizard + { + friend class AccountTypePage; + friend class InstitutionPage; + friend class BrokeragePage; + friend class CreditCardSchedulePage; + friend class GeneralLoanInfoPage; + friend class LoanDetailsPage; + friend class LoanPaymentPage; + friend class LoanSchedulePage; + friend class LoanPayoutPage; + friend class HierarchyPage; + friend class AccountSummaryPage; + + Q_OBJECT + Q_DISABLE_COPY(Wizard) + + public: + explicit Wizard(QWidget *parent = nullptr, bool modal = false, Qt::WindowFlags flags = 0); + ~Wizard() override; + + /** * Returns the information about the account as entered by * the user. */ - const MyMoneyAccount& account(); + const MyMoneyAccount& account(); - /** + /** * Method to load the generated account information back into the widget */ - void setAccount(const MyMoneyAccount& acc); + void setAccount(const MyMoneyAccount& acc); - /** + /** * Returns the information about the parent account as entered by * the user. * @note For now it's either fixed as Asset or Liability. We will provide * user selected parent accounts later. */ - const MyMoneyAccount& parentAccount(); + const MyMoneyAccount& parentAccount(); - /** + /** * Returns information about the schedule. If the returned value * equals MyMoneySchedule() then the user did not select to create * a schedule. */ - const MyMoneySchedule& schedule(); + const MyMoneySchedule& schedule(); - /** + /** * This method returns the value of the opening balance * entered by the user */ - MyMoneyMoney openingBalance() const; + MyMoneyMoney openingBalance() const; - /** + /** * This method returns the interest rate as factor, ie an * interest rate of 6.5% will be returned as 0.065 */ - MyMoneyMoney interestRate() const; + MyMoneyMoney interestRate() const; - /** + /** * This method returns the payout transaction for loans. * If the account to be created is not a loan or no * payout transaction should be generated, this method * returns an emtpy transaction. */ - MyMoneyTransaction payoutTransaction(); + MyMoneyTransaction payoutTransaction(); - /** + /** * This method returns a MyMoneyAccount() object filled * with the data to create a brokerage account. If the * user selected not to create a brokerage account or @@ -132,55 +136,31 @@ * @note Make sure to call the account() method before you call this method. * Otherwise the returned object might contain unexpected results. */ - MyMoneyAccount brokerageAccount() const; + MyMoneyAccount brokerageAccount() const; - /** + /** * This method returns the conversion rate */ - MyMoneyPrice conversionRate() const; - -protected: - /** - * This method returns the currently selected currency for the account - */ - const MyMoneySecurity& currency() const; + MyMoneyPrice conversionRate() const; - /** - * This method returns the precision in digits for the selected currency. - * @sa currency() - */ - int precision() const; + signals: + void createInstitution(MyMoneyInstitution& institution); + void createAccount(MyMoneyAccount& account); + void createCategory(MyMoneyAccount&, const MyMoneyAccount&); - /** + protected: + /** * This method returns information about the selection of the user * if the loan is for borrowing or lending money. * * @retval true loan is for money borrowed * @retval false loan is for money lent */ - bool moneyBorrowed() const; - -signals: - void createInstitution(MyMoneyInstitution& institution); - void createAccount(MyMoneyAccount& account); - void createCategory(MyMoneyAccount&, const MyMoneyAccount&); - -private: - InstitutionPage* m_institutionPage; - AccountTypePage* m_accountTypePage; - BrokeragePage* m_brokeragepage; - CreditCardSchedulePage* m_schedulePage; - GeneralLoanInfoPage* m_generalLoanInfoPage; - LoanDetailsPage* m_loanDetailsPage; - LoanPaymentPage* m_loanPaymentPage; - LoanSchedulePage* m_loanSchedulePage; - LoanPayoutPage* m_loanPayoutPage; - HierarchyPage* m_hierarchyPage; - AccountSummaryPage* m_accountSummaryPage; - - MyMoneyAccountLoan m_account; - MyMoneySchedule m_schedule; -}; + bool moneyBorrowed() const; + + private: + Q_DECLARE_PRIVATE(Wizard) + }; } // namespace diff --git a/kmymoney/wizards/newaccountwizard/knewaccountwizard.cpp b/kmymoney/wizards/newaccountwizard/knewaccountwizard.cpp --- a/kmymoney/wizards/newaccountwizard/knewaccountwizard.cpp +++ b/kmymoney/wizards/newaccountwizard/knewaccountwizard.cpp @@ -4,6 +4,7 @@ begin : Tue Sep 25 2006 copyright : (C) 2007 Thomas Baumgart email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz ***************************************************************************/ /*************************************************************************** @@ -22,41 +23,45 @@ // QT Includes #include -#include #include -#include -#include -#include // ---------------------------------------------------------------------------- // KDE Includes #include #include -#include // ---------------------------------------------------------------------------- // Project Includes +#include "kaccountsummarypage.h" +#include "kaccounttypepage.h" +#include "kbrokeragepage.h" +#include "kcreditcardschedulepage.h" +#include "kgeneralloaninfopage.h" +#include "khierarchypage.h" +#include "kinstitutionpage.h" +#include "kloandetailspage.h" +#include "kloanpaymentpage.h" +#include "kloanpayoutpage.h" +#include "kloanschedulepage.h" + +#include "kaccounttypepage_p.h" +#include "kbrokeragepage_p.h" +#include "kcreditcardschedulepage_p.h" +#include "kgeneralloaninfopage_p.h" +#include "kinstitutionpage_p.h" +#include "kloandetailspage_p.h" +#include "kloanpayoutpage_p.h" +#include "kloanschedulepage_p.h" + #include "kmymoneycurrencyselector.h" -#include "kmymoneyaccountselector.h" -#include "mymoneyfinancialcalculator.h" #include "kcurrencycalculator.h" #include "kmymoneyglobalsettings.h" -#include -#include "mymoneyutils.h" -#include "ksplittransactiondlg.h" -#include "kequitypriceupdatedlg.h" -#include "accountsmodel.h" -#include "accountsproxymodel.h" -#include "models.h" -#include "modelenums.h" -#include "icons.h" #include "mymoneyfile.h" #include "mymoneyinstitution.h" #include "mymoneyaccountloan.h" -#include "mymoneypayee.h" #include "mymoneyprice.h" #include "mymoneysplit.h" #include "mymoneytransaction.h" @@ -67,1609 +72,308 @@ namespace NewAccountWizard { -enum steps { - StepInstitution = 1, - StepAccount, - StepBroker, - StepDetails, - StepPayments, - StepFees, - StepSchedule, - StepPayout, - StepParentAccount, - StepFinish -}; - -Wizard::Wizard(QWidget *parent, bool modal, Qt::WindowFlags flags) - : KMyMoneyWizard(parent, modal, flags) -{ - setTitle(i18n("KMyMoney New Account Setup")); - addStep(i18n("Institution")); - addStep(i18n("Account")); - addStep(i18n("Broker")); - addStep(i18n("Details")); - addStep(i18n("Payments")); - addStep(i18n("Fees")); - addStep(i18n("Schedule")); - addStep(i18n("Payout")); - addStep(i18n("Parent Account")); - addStep(i18nc("Finish the wizard", "Finish")); - setStepHidden(StepBroker); - setStepHidden(StepSchedule); - setStepHidden(StepPayout); - setStepHidden(StepDetails); - setStepHidden(StepPayments); - setStepHidden(StepFees); - - m_institutionPage = new InstitutionPage(this); - m_accountTypePage = new AccountTypePage(this); - // Investment Pages - m_brokeragepage = new BrokeragePage(this); - // Credit Card Pages - m_schedulePage = new CreditCardSchedulePage(this); - // Loan Pages - m_generalLoanInfoPage = new GeneralLoanInfoPage(this); - m_loanDetailsPage = new LoanDetailsPage(this); - m_loanPaymentPage = new LoanPaymentPage(this); - m_loanSchedulePage = new LoanSchedulePage(this); - m_loanPayoutPage = new LoanPayoutPage(this); - // Not a loan page - m_hierarchyPage = new HierarchyPage(this); - // Finish - m_accountSummaryPage = new AccountSummaryPage(this); - - setFirstPage(m_institutionPage); -} - -void Wizard::setAccount(const MyMoneyAccount& acc) -{ - m_account = acc; - m_accountTypePage->setAccount(m_account); - - if (!acc.institutionId().isEmpty()) { - m_institutionPage->selectExistingInstitution(acc.institutionId()); - } -} - -const MyMoneySecurity& Wizard::currency() const -{ - return m_accountTypePage->currency(); -} - -MyMoneyMoney Wizard::interestRate() const -{ - return m_loanDetailsPage->m_interestRate->value() / MyMoneyMoney(100, 1); -} - -int Wizard::precision() const -{ - return MyMoneyMoney::denomToPrec(currency().smallestAccountFraction()); -} - -const MyMoneyAccount& Wizard::account() -{ - m_account = MyMoneyAccountLoan(); - m_account.setName(m_accountTypePage->m_accountName->text()); - m_account.setOpeningDate(m_accountTypePage->m_openingDate->date()); - m_account.setAccountType(m_accountTypePage->accountType()); - m_account.setInstitutionId(m_institutionPage->institution().id()); - m_account.setNumber(m_institutionPage->m_accountNumber->text()); - m_account.setValue("iban", m_institutionPage->m_iban->text()); - if (m_accountTypePage->m_preferredAccount->isChecked()) - m_account.setValue("PreferredAccount", "Yes"); - else - m_account.deletePair("PreferredAccount"); - - m_account.setCurrencyId(currency().id()); - if (m_account.isLoan()) { - // in case we lend the money we adjust the account type - if (!moneyBorrowed()) - m_account.setAccountType(Account::AssetLoan); - m_account.setLoanAmount(m_loanDetailsPage->m_loanAmount->value()); - m_account.setInterestRate(m_loanSchedulePage->firstPaymentDueDate(), m_loanDetailsPage->m_interestRate->value()); - m_account.setInterestCalculation(m_loanDetailsPage->m_paymentDue->currentIndex() == 0 ? MyMoneyAccountLoan::paymentReceived : MyMoneyAccountLoan::paymentDue); - m_account.setFixedInterestRate(m_generalLoanInfoPage->m_interestType->currentIndex() == 0); - m_account.setFinalPayment(m_loanDetailsPage->m_balloonAmount->value()); - m_account.setTerm(m_loanDetailsPage->term()); - m_account.setPeriodicPayment(m_loanDetailsPage->m_paymentAmount->value()); - m_account.setPayee(m_generalLoanInfoPage->m_payee->selectedItem()); - m_account.setInterestCompounding((int)m_generalLoanInfoPage->m_compoundFrequency->currentItem()); - - if (!m_account.fixedInterestRate()) { - m_account.setNextInterestChange(m_generalLoanInfoPage->m_interestChangeDateEdit->date()); - m_account.setInterestChangeFrequency(m_generalLoanInfoPage->m_interestFrequencyAmountEdit->value(), m_generalLoanInfoPage->m_interestFrequencyUnitEdit->currentIndex()); + Wizard::Wizard(QWidget *parent, bool modal, Qt::WindowFlags flags) + : KMyMoneyWizard(*new WizardPrivate(this), parent, modal, flags) + { + Q_D(Wizard); + setTitle(i18n("KMyMoney New Account Setup")); + addStep(i18n("Institution")); + addStep(i18n("Account")); + addStep(i18n("Broker")); + addStep(i18n("Details")); + addStep(i18n("Payments")); + addStep(i18n("Fees")); + addStep(i18n("Schedule")); + addStep(i18n("Payout")); + addStep(i18n("Parent Account")); + addStep(i18nc("Finish the wizard", "Finish")); + d->setStepHidden(StepBroker); + d->setStepHidden(StepSchedule); + d->setStepHidden(StepPayout); + d->setStepHidden(StepDetails); + d->setStepHidden(StepPayments); + d->setStepHidden(StepFees); + + d->m_institutionPage = new InstitutionPage(this); + d->m_accountTypePage = new AccountTypePage(this); + // Investment Pages + d->m_brokeragepage = new BrokeragePage(this); + // Credit Card Pages + d->m_schedulePage = new CreditCardSchedulePage(this); + // Loan Pages + d->m_generalLoanInfoPage = new GeneralLoanInfoPage(this); + d->m_loanDetailsPage = new LoanDetailsPage(this); + d->m_loanPaymentPage = new LoanPaymentPage(this); + d->m_loanSchedulePage = new LoanSchedulePage(this); + d->m_loanPayoutPage = new LoanPayoutPage(this); + // Not a loan page + d->m_hierarchyPage = new HierarchyPage(this); + // Finish + d->m_accountSummaryPage = new AccountSummaryPage(this); + + d->setFirstPage(d->m_institutionPage); + } + + Wizard::~Wizard() + { + } + + void Wizard::setAccount(const MyMoneyAccount& acc) + { + Q_D(Wizard); + d->m_account = acc; + d->m_accountTypePage->setAccount(d->m_account); + + if (!acc.institutionId().isEmpty()) { + d->m_institutionPage->selectExistingInstitution(acc.institutionId()); } } - return m_account; -} - -MyMoneyTransaction Wizard::payoutTransaction() -{ - MyMoneyTransaction t; - if (m_account.isLoan() // we're creating a loan - && openingBalance().isZero() // and don't have an opening balance - && !m_loanPayoutPage->m_noPayoutTransaction->isChecked()) { // and the user wants to have a payout transaction - t.setPostDate(m_loanPayoutPage->m_payoutDate->date()); - t.setCommodity(m_account.currencyId()); - MyMoneySplit s; - s.setAccountId(m_account.id()); - s.setShares(m_loanDetailsPage->m_loanAmount->value()); - if (moneyBorrowed()) - s.setShares(-s.shares()); - s.setValue(s.shares()); - t.addSplit(s); - - s.clearId(); - s.setValue(-s.value()); - s.setAccountId(m_loanPayoutPage->payoutAccountId()); - MyMoneyMoney shares; - KCurrencyCalculator::setupSplitPrice(shares, t, s, QMap(), this); - s.setShares(shares); - t.addSplit(s); - } - return t; -} - -const MyMoneyAccount& Wizard::parentAccount() -{ - return m_accountTypePage->allowsParentAccount() - ? m_hierarchyPage->parentAccount() - : (m_accountTypePage->accountType() == Account::Loan - ? m_generalLoanInfoPage->parentAccount() - : m_accountTypePage->parentAccount()); -} - -MyMoneyAccount Wizard::brokerageAccount() const -{ - MyMoneyAccount account; - if (m_account.accountType() == Account::Investment - && m_brokeragepage->m_createBrokerageButton->isChecked()) { - account.setName(m_account.brokerageName()); - account.setAccountType(Account::Checkings); - account.setInstitutionId(m_account.institutionId()); - account.setOpeningDate(m_account.openingDate()); - account.setCurrencyId(m_brokeragepage->m_brokerageCurrency->security().id()); - if (m_brokeragepage->m_accountNumber->isEnabled() && !m_brokeragepage->m_accountNumber->text().isEmpty()) - account.setNumber(m_brokeragepage->m_accountNumber->text()); - if (m_brokeragepage->m_iban->isEnabled() && !m_brokeragepage->m_iban->text().isEmpty()) - account.setValue("iban", m_brokeragepage->m_iban->text()); - } - return account; -} - -const MyMoneySchedule& Wizard::schedule() -{ - m_schedule = MyMoneySchedule(); - if (!m_account.id().isEmpty()) { - if (m_schedulePage->m_reminderCheckBox->isChecked() && (m_account.accountType() == Account::CreditCard)) { - m_schedule.setName(m_schedulePage->m_name->text()); - m_schedule.setType(Schedule::Type::Transfer); - m_schedule.setPaymentType(static_cast(m_schedulePage->m_method->currentItem())); - m_schedule.setFixed(false); - m_schedule.setOccurrencePeriod(Schedule::Occurrence::Monthly); - m_schedule.setOccurrenceMultiplier(1); - MyMoneyTransaction t; + MyMoneyMoney Wizard::interestRate() const + { + Q_D(const Wizard); + return d->m_loanDetailsPage->d_func()->ui->m_interestRate->value() / MyMoneyMoney(100, 1); + } + + + + const MyMoneyAccount& Wizard::account() + { + Q_D(Wizard); + d->m_account = MyMoneyAccountLoan(); + d->m_account.setName(d->m_accountTypePage->d_func()->ui->m_accountName->text()); + d->m_account.setOpeningDate(d->m_accountTypePage->d_func()->ui->m_openingDate->date()); + d->m_account.setAccountType(d->m_accountTypePage->accountType()); + d->m_account.setInstitutionId(d->m_institutionPage->institution().id()); + d->m_account.setNumber(d->m_institutionPage->d_func()->ui->m_accountNumber->text()); + d->m_account.setValue("iban", d->m_institutionPage->d_func()->ui->m_iban->text()); + if (d->m_accountTypePage->d_func()->ui->m_preferredAccount->isChecked()) + d->m_account.setValue("PreferredAccount", "Yes"); + else + d->m_account.deletePair("PreferredAccount"); + + d->m_account.setCurrencyId(d->currency().id()); + if (d->m_account.isLoan()) { + // in case we lend the money we adjust the account type + if (!moneyBorrowed()) + d->m_account.setAccountType(Account::AssetLoan); + d->m_account.setLoanAmount(d->m_loanDetailsPage->d_func()->ui->m_loanAmount->value()); + d->m_account.setInterestRate(d->m_loanSchedulePage->firstPaymentDueDate(), d->m_loanDetailsPage->d_func()->ui->m_interestRate->value()); + d->m_account.setInterestCalculation(d->m_loanDetailsPage->d_func()->ui->m_paymentDue->currentIndex() == 0 ? MyMoneyAccountLoan::paymentReceived : MyMoneyAccountLoan::paymentDue); + d->m_account.setFixedInterestRate(d->m_generalLoanInfoPage->d_func()->ui->m_interestType->currentIndex() == 0); + d->m_account.setFinalPayment(d->m_loanDetailsPage->d_func()->ui->m_balloonAmount->value()); + d->m_account.setTerm(d->m_loanDetailsPage->term()); + d->m_account.setPeriodicPayment(d->m_loanDetailsPage->d_func()->ui->m_paymentAmount->value()); + d->m_account.setPayee(d->m_generalLoanInfoPage->d_func()->ui->m_payee->selectedItem()); + d->m_account.setInterestCompounding((int)d->m_generalLoanInfoPage->d_func()->ui->m_compoundFrequency->currentItem()); + + if (!d->m_account.fixedInterestRate()) { + d->m_account.setNextInterestChange(d->m_generalLoanInfoPage->d_func()->ui->m_interestChangeDateEdit->date()); + d->m_account.setInterestChangeFrequency(d->m_generalLoanInfoPage->d_func()->ui->m_interestFrequencyAmountEdit->value(), d->m_generalLoanInfoPage->d_func()->ui->m_interestFrequencyUnitEdit->currentIndex()); + } + } + return d->m_account; + } + + MyMoneyTransaction Wizard::payoutTransaction() + { + Q_D(Wizard); + MyMoneyTransaction t; + if (d->m_account.isLoan() // we're creating a loan + && openingBalance().isZero() // and don't have an opening balance + && !d->m_loanPayoutPage->d_func()->ui->m_noPayoutTransaction->isChecked()) { // and the user wants to have a payout transaction + t.setPostDate(d->m_loanPayoutPage->d_func()->ui->m_payoutDate->date()); + t.setCommodity(d->m_account.currencyId()); MyMoneySplit s; - s.setPayeeId(m_schedulePage->m_payee->selectedItem()); - s.setAccountId(m_schedulePage->m_paymentAccount->selectedItem()); - s.setMemo(i18n("Credit card payment")); - s.setShares(-m_schedulePage->m_amount->value()); + s.setAccountId(d->m_account.id()); + s.setShares(d->m_loanDetailsPage->d_func()->ui->m_loanAmount->value()); + if (moneyBorrowed()) + s.setShares(-s.shares()); s.setValue(s.shares()); t.addSplit(s); s.clearId(); - s.setAccountId(m_account.id()); - s.setShares(m_schedulePage->m_amount->value()); - s.setValue(s.shares()); + s.setValue(-s.value()); + s.setAccountId(d->m_loanPayoutPage->payoutAccountId()); + MyMoneyMoney shares; + KCurrencyCalculator::setupSplitPrice(shares, t, s, QMap(), this); + s.setShares(shares); t.addSplit(s); + } + return t; + } + + const MyMoneyAccount& Wizard::parentAccount() + { + Q_D(Wizard); + return d->m_accountTypePage->allowsParentAccount() + ? d->m_hierarchyPage->parentAccount() + : (d->m_accountTypePage->accountType() == Account::Loan + ? d->m_generalLoanInfoPage->parentAccount() + : d->m_accountTypePage->parentAccount()); + } + + MyMoneyAccount Wizard::brokerageAccount() const + { + Q_D(const Wizard); + MyMoneyAccount account; + if (d->m_account.accountType() == Account::Investment + && d->m_brokeragepage->d_func()->ui->m_createBrokerageButton->isChecked()) { + account.setName(d->m_account.brokerageName()); + account.setAccountType(Account::Checkings); + account.setInstitutionId(d->m_account.institutionId()); + account.setOpeningDate(d->m_account.openingDate()); + account.setCurrencyId(d->m_brokeragepage->d_func()->ui->m_brokerageCurrency->security().id()); + if (d->m_brokeragepage->d_func()->ui->m_accountNumber->isEnabled() && !d->m_brokeragepage->d_func()->ui->m_accountNumber->text().isEmpty()) + account.setNumber(d->m_brokeragepage->d_func()->ui->m_accountNumber->text()); + if (d->m_brokeragepage->d_func()->ui->m_iban->isEnabled() && !d->m_brokeragepage->d_func()->ui->m_iban->text().isEmpty()) + account.setValue("iban", d->m_brokeragepage->d_func()->ui->m_iban->text()); + } + return account; + } + + const MyMoneySchedule& Wizard::schedule() + { + Q_D(Wizard); + d->m_schedule = MyMoneySchedule(); + + if (!d->m_account.id().isEmpty()) { + if (d->m_schedulePage->d_func()->ui->m_reminderCheckBox->isChecked() && (d->m_account.accountType() == Account::CreditCard)) { + d->m_schedule.setName(d->m_schedulePage->d_func()->ui->m_name->text()); + d->m_schedule.setType(Schedule::Type::Transfer); + d->m_schedule.setPaymentType(static_cast(d->m_schedulePage->d_func()->ui->m_method->currentItem())); + d->m_schedule.setFixed(false); + d->m_schedule.setOccurrencePeriod(Schedule::Occurrence::Monthly); + d->m_schedule.setOccurrenceMultiplier(1); + MyMoneyTransaction t; + MyMoneySplit s; + s.setPayeeId(d->m_schedulePage->d_func()->ui->m_payee->selectedItem()); + s.setAccountId(d->m_schedulePage->d_func()->ui->m_paymentAccount->selectedItem()); + s.setMemo(i18n("Credit card payment")); + s.setShares(-d->m_schedulePage->d_func()->ui->m_amount->value()); + s.setValue(s.shares()); + t.addSplit(s); - // setup the next due date - t.setPostDate(m_schedulePage->m_date->date()); - m_schedule.setTransaction(t); - - } else if (m_account.isLoan()) { - m_schedule.setName(i18n("Loan payment for %1", m_accountTypePage->m_accountName->text())); - m_schedule.setType(Schedule::Type::LoanPayment); - if (moneyBorrowed()) - m_schedule.setPaymentType(Schedule::PaymentType::DirectDebit); - else - m_schedule.setPaymentType(Schedule::PaymentType::DirectDeposit); - - m_schedule.setFixed(true); - m_schedule.setOccurrence(m_generalLoanInfoPage->m_paymentFrequency->currentItem()); + s.clearId(); + s.setAccountId(d->m_account.id()); + s.setShares(d->m_schedulePage->d_func()->ui->m_amount->value()); + s.setValue(s.shares()); + t.addSplit(s); - MyMoneyTransaction t; - t.setCommodity(m_account.currencyId()); - MyMoneySplit s; - // payment split - s.setPayeeId(m_generalLoanInfoPage->m_payee->selectedItem()); - s.setAccountId(m_loanSchedulePage->m_paymentAccount->selectedItem()); - s.setMemo(i18n("Loan payment")); - s.setValue(m_loanPaymentPage->basePayment() + m_loanPaymentPage->additionalFees()); - if (moneyBorrowed()) { - s.setValue(-s.value()); - } - s.setShares(s.value()); - if (m_account.id() != QLatin1String("Phony-ID")) { - // if the real account is already set perform the currency conversion if it's necessary - MyMoneyMoney paymentShares; - KCurrencyCalculator::setupSplitPrice(paymentShares, t, s, QMap(), this); - s.setShares(paymentShares); - } - t.addSplit(s); + // setup the next due date + t.setPostDate(d->m_schedulePage->d_func()->ui->m_date->date()); + d->m_schedule.setTransaction(t); - // principal split - s.clearId(); - s.setAccountId(m_account.id()); - s.setShares(MyMoneyMoney::autoCalc); - s.setValue(MyMoneyMoney::autoCalc); - s.setMemo(i18n("Amortization")); - s.setAction(MyMoneySplit::ActionAmortization); - t.addSplit(s); + } else if (d->m_account.isLoan()) { + d->m_schedule.setName(i18n("Loan payment for %1", d->m_accountTypePage->d_func()->ui->m_accountName->text())); + d->m_schedule.setType(Schedule::Type::LoanPayment); + if (moneyBorrowed()) + d->m_schedule.setPaymentType(Schedule::PaymentType::DirectDebit); + else + d->m_schedule.setPaymentType(Schedule::PaymentType::DirectDeposit); + + d->m_schedule.setFixed(true); + d->m_schedule.setOccurrence(d->m_generalLoanInfoPage->d_func()->ui->m_paymentFrequency->currentItem()); + + MyMoneyTransaction t; + t.setCommodity(d->m_account.currencyId()); + MyMoneySplit s; + // payment split + s.setPayeeId(d->m_generalLoanInfoPage->d_func()->ui->m_payee->selectedItem()); + s.setAccountId(d->m_loanSchedulePage->d_func()->ui->m_paymentAccount->selectedItem()); + s.setMemo(i18n("Loan payment")); + s.setValue(d->m_loanPaymentPage->basePayment() + d->m_loanPaymentPage->additionalFees()); + if (moneyBorrowed()) { + s.setValue(-s.value()); + } + s.setShares(s.value()); + if (d->m_account.id() != QLatin1String("Phony-ID")) { + // if the real account is already set perform the currency conversion if it's necessary + MyMoneyMoney paymentShares; + KCurrencyCalculator::setupSplitPrice(paymentShares, t, s, QMap(), this); + s.setShares(paymentShares); + } + t.addSplit(s); - // interest split - //only add if interest is above zero - if (!m_loanDetailsPage->m_interestRate->value().isZero()) { + // principal split s.clearId(); - s.setAccountId(m_loanSchedulePage->m_interestCategory->selectedItem()); + s.setAccountId(d->m_account.id()); s.setShares(MyMoneyMoney::autoCalc); s.setValue(MyMoneyMoney::autoCalc); - s.setMemo(i18n("Interest")); - s.setAction(MyMoneySplit::ActionInterest); + s.setMemo(i18n("Amortization")); + s.setAction(MyMoneySplit::ActionAmortization); t.addSplit(s); - } - // additional fee splits - QList additionalSplits; - m_loanPaymentPage->additionalFeesSplits(additionalSplits); - QList::const_iterator it; - MyMoneyMoney factor(moneyBorrowed() ? 1 : -1, 1); + // interest split + //only add if interest is above zero + if (!d->m_loanDetailsPage->d_func()->ui->m_interestRate->value().isZero()) { + s.clearId(); + s.setAccountId(d->m_loanSchedulePage->d_func()->ui->m_interestCategory->selectedItem()); + s.setShares(MyMoneyMoney::autoCalc); + s.setValue(MyMoneyMoney::autoCalc); + s.setMemo(i18n("Interest")); + s.setAction(MyMoneySplit::ActionInterest); + t.addSplit(s); + } - for (it = additionalSplits.constBegin(); it != additionalSplits.constEnd(); ++it) { - s = (*it); - s.clearId(); - s.setShares(s.shares() * factor); - s.setValue(s.value() * factor); - t.addSplit(s); - } + // additional fee splits + QList additionalSplits; + d->m_loanPaymentPage->additionalFeesSplits(additionalSplits); + QList::const_iterator it; + MyMoneyMoney factor(moneyBorrowed() ? 1 : -1, 1); + + for (it = additionalSplits.constBegin(); it != additionalSplits.constEnd(); ++it) { + s = (*it); + s.clearId(); + s.setShares(s.shares() * factor); + s.setValue(s.value() * factor); + t.addSplit(s); + } - // setup the next due date - t.setPostDate(m_loanSchedulePage->firstPaymentDueDate()); - m_schedule.setTransaction(t); + // setup the next due date + t.setPostDate(d->m_loanSchedulePage->firstPaymentDueDate()); + d->m_schedule.setTransaction(t); + } } + return d->m_schedule; } - return m_schedule; -} - -MyMoneyMoney Wizard::openingBalance() const -{ - // equity accounts don't have an opening balance - if (m_accountTypePage->accountType() == Account::Equity) - return MyMoneyMoney(); - if (m_accountTypePage->accountType() == Account::Loan) { - if (m_generalLoanInfoPage->recordAllPayments()) + MyMoneyMoney Wizard::openingBalance() const + { + Q_D(const Wizard); + // equity accounts don't have an opening balance + if (d->m_accountTypePage->accountType() == Account::Equity) return MyMoneyMoney(); - if (moneyBorrowed()) - return -(m_generalLoanInfoPage->m_openingBalance->value()); - return m_generalLoanInfoPage->m_openingBalance->value(); - } - return m_accountTypePage->m_openingBalance->value(); -} -MyMoneyPrice Wizard::conversionRate() const -{ - if (MyMoneyFile::instance()->baseCurrency().id() == m_accountTypePage->m_currencyComboBox->security().id()) + if (d->m_accountTypePage->accountType() == Account::Loan) { + if (d->m_generalLoanInfoPage->recordAllPayments()) + return MyMoneyMoney(); + if (moneyBorrowed()) + return -(d->m_generalLoanInfoPage->d_func()->ui->m_openingBalance->value()); + return d->m_generalLoanInfoPage->d_func()->ui->m_openingBalance->value(); + } + return d->m_accountTypePage->d_func()->ui->m_openingBalance->value(); + } + + MyMoneyPrice Wizard::conversionRate() const + { + Q_D(const Wizard); + if (MyMoneyFile::instance()->baseCurrency().id() == d->m_accountTypePage->d_func()->ui->m_currencyComboBox->security().id()) + return MyMoneyPrice(MyMoneyFile::instance()->baseCurrency().id(), + d->m_accountTypePage->d_func()->ui->m_currencyComboBox->security().id(), + d->m_accountTypePage->d_func()->ui->m_openingDate->date(), + MyMoneyMoney::ONE, + i18n("User")); return MyMoneyPrice(MyMoneyFile::instance()->baseCurrency().id(), - m_accountTypePage->m_currencyComboBox->security().id(), - m_accountTypePage->m_openingDate->date(), - MyMoneyMoney::ONE, + d->m_accountTypePage->d_func()->ui->m_currencyComboBox->security().id(), + d->m_accountTypePage->d_func()->ui->m_openingDate->date(), + d->m_accountTypePage->d_func()->ui->m_conversionRate->value(), i18n("User")); - return MyMoneyPrice(MyMoneyFile::instance()->baseCurrency().id(), - m_accountTypePage->m_currencyComboBox->security().id(), - m_accountTypePage->m_openingDate->date(), - m_accountTypePage->m_conversionRate->value(), - i18n("User")); -} - -bool Wizard::moneyBorrowed() const -{ - return m_generalLoanInfoPage->m_loanDirection->currentIndex() == 0; -} - -class InstitutionPage::Private -{ -public: - QList m_list; -}; - -InstitutionPage::InstitutionPage(Wizard* wizard) : - KInstitutionPageDecl(wizard), - WizardPage(StepInstitution, this, wizard), - d(new Private()) -{ - connect(MyMoneyFile::instance(), SIGNAL(dataChanged()), this, SLOT(slotLoadWidgets())); - connect(m_newInstitutionButton, SIGNAL(clicked()), this, SLOT(slotNewInstitution())); - connect(m_institutionComboBox, SIGNAL(activated(int)), this, SLOT(slotSelectInstitution(int))); - - slotLoadWidgets(); - m_institutionComboBox->setCurrentItem(0); - slotSelectInstitution(0); -} - -InstitutionPage::~InstitutionPage() -{ - delete d; -} - -void InstitutionPage::slotLoadWidgets() -{ - m_institutionComboBox->clear(); - - d->m_list.clear(); - MyMoneyFile::instance()->institutionList(d->m_list); - qSort(d->m_list); - - QList::const_iterator it_l; - m_institutionComboBox->addItem(QString()); - for (it_l = d->m_list.constBegin(); it_l != d->m_list.constEnd(); ++it_l) { - m_institutionComboBox->addItem((*it_l).name()); - } -} - -void InstitutionPage::slotNewInstitution() -{ - MyMoneyInstitution institution; - - emit m_wizard->createInstitution(institution); - - if (!institution.id().isEmpty()) { - QList::const_iterator it_l; - int i = 0; - for (it_l = d->m_list.constBegin(); it_l != d->m_list.constEnd(); ++it_l) { - if ((*it_l).id() == institution.id()) { - // select the item and remember that the very first one is the empty item - m_institutionComboBox->setCurrentIndex(i + 1); - slotSelectInstitution(i + 1); - m_accountNumber->setFocus(); - break; - } - ++i; - } - } -} - -void InstitutionPage::slotSelectInstitution(const int index) -{ - m_accountNumber->setEnabled(index != 0); - m_iban->setEnabled(index != 0); -} - -void InstitutionPage::selectExistingInstitution(const QString& id) -{ - for (int i = 0; i < d->m_list.length(); ++i) { - if (d->m_list[i].id() == id) { - m_institutionComboBox->setCurrentIndex(i + 1); - slotSelectInstitution(i + 1); - break; - } - } -} - -const MyMoneyInstitution& InstitutionPage::institution() const -{ - static MyMoneyInstitution emptyInstitution; - if (m_institutionComboBox->currentIndex() == 0) - return emptyInstitution; - - return d->m_list[m_institutionComboBox->currentIndex()-1]; -} - -KMyMoneyWizardPage* InstitutionPage::nextPage() const -{ - return m_wizard->m_accountTypePage; -} - -AccountTypePage::AccountTypePage(Wizard* wizard) : - KAccountTypePageDecl(wizard), - WizardPage(StepAccount, this, wizard), - m_showPriceWarning(true) -{ - m_typeSelection->insertItem(i18n("Checking"), (int)Account::Checkings); - m_typeSelection->insertItem(i18n("Savings"), (int)Account::Savings); - m_typeSelection->insertItem(i18n("Credit Card"), (int)Account::CreditCard); - m_typeSelection->insertItem(i18n("Cash"), (int)Account::Cash); - m_typeSelection->insertItem(i18n("Loan"), (int)Account::Loan); - m_typeSelection->insertItem(i18n("Investment"), (int)Account::Investment); - m_typeSelection->insertItem(i18n("Asset"), (int)Account::Asset); - m_typeSelection->insertItem(i18n("Liability"), (int)Account::Liability); - if (KMyMoneyGlobalSettings::expertMode()) { - m_typeSelection->insertItem(i18n("Equity"), (int)Account::Equity); - } - - m_typeSelection->setCurrentItem((int)Account::Checkings); - - m_currencyComboBox->setSecurity(MyMoneyFile::instance()->baseCurrency()); - - m_mandatoryGroup->add(m_accountName); - m_mandatoryGroup->add(m_conversionRate->lineedit()); - - m_conversionRate->setValue(MyMoneyMoney::ONE); - slotUpdateCurrency(); - - connect(m_typeSelection, SIGNAL(itemSelected(int)), this, SLOT(slotUpdateType(int))); - connect(m_currencyComboBox, SIGNAL(activated(int)), this, SLOT(slotUpdateCurrency())); - connect(m_conversionRate, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateConversionRate(QString))); - connect(m_conversionRate, SIGNAL(valueChanged(QString)), this, SLOT(slotPriceWarning())); - connect(m_onlineQuote, SIGNAL(clicked()), this, SLOT(slotGetOnlineQuote())); -} - -void AccountTypePage::slotUpdateType(int i) -{ - hideShowPages(static_cast(i)); - m_openingBalance->setDisabled(static_cast(i) == Account::Equity); -} - -void AccountTypePage::hideShowPages(Account accountType) const -{ - bool hideSchedulePage = (accountType != Account::CreditCard) - && (accountType != Account::Loan); - bool hideLoanPage = (accountType != Account::Loan); - m_wizard->setStepHidden(StepDetails, hideLoanPage); - m_wizard->setStepHidden(StepPayments, hideLoanPage); - m_wizard->setStepHidden(StepFees, hideLoanPage); - m_wizard->setStepHidden(StepSchedule, hideSchedulePage); - m_wizard->setStepHidden(StepPayout, (accountType != Account::Loan)); - m_wizard->setStepHidden(StepBroker, accountType != Account::Investment); - m_wizard->setStepHidden(StepParentAccount, accountType == Account::Loan); - // Force an update of the steps in case the list has changed - m_wizard->reselectStep(); -} - -KMyMoneyWizardPage* AccountTypePage::nextPage() const -{ - if (accountType() == Account::Loan) - return m_wizard->m_generalLoanInfoPage; - if (accountType() == Account::CreditCard) - return m_wizard->m_schedulePage; - if (accountType() == Account::Investment) - return m_wizard->m_brokeragepage; - return m_wizard->m_hierarchyPage; -} - -void AccountTypePage::slotUpdateCurrency() -{ - MyMoneyAccount acc; - acc.setAccountType(accountType()); - - m_openingBalance->setPrecision(MyMoneyMoney::denomToPrec(acc.fraction(currency()))); - - bool show = m_currencyComboBox->security().id() != MyMoneyFile::instance()->baseCurrency().id(); - m_conversionLabel->setVisible(show); - m_conversionRate->setVisible(show); - m_conversionExample->setVisible(show); - m_onlineQuote->setVisible(show); - m_conversionRate->setEnabled(show); // make sure to include/exclude in mandatoryGroup - m_conversionRate->setPrecision(m_currencyComboBox->security().pricePrecision()); - m_mandatoryGroup->changed(); - slotUpdateConversionRate(m_conversionRate->lineedit()->text()); -} - -void AccountTypePage::slotGetOnlineQuote() -{ - QString id = MyMoneyFile::instance()->baseCurrency().id() + ' ' + m_currencyComboBox->security().id(); - QPointer dlg = new KEquityPriceUpdateDlg(this, id); - if (dlg->exec() == QDialog::Accepted) { - const MyMoneyPrice &price = dlg->price(id); - if (price.isValid()) { - m_conversionRate->setValue(price.rate(m_currencyComboBox->security().id())); - if (price.date() != m_openingDate->date()) { - priceWarning(true); - } - } - } - delete dlg; -} - -void AccountTypePage::slotPriceWarning() -{ - priceWarning(false); -} - -void AccountTypePage::priceWarning(bool always) -{ - if (m_showPriceWarning || always) { - KMessageBox::information(this, i18n("Please make sure to enter the correct conversion for the selected opening date. If you requested an online quote it might be provided for a different date."), i18n("Check date")); - } - m_showPriceWarning = false; -} - -void AccountTypePage::slotUpdateConversionRate(const QString& txt) -{ - m_conversionExample->setText(i18n("1 %1 equals %2", MyMoneyFile::instance()->baseCurrency().tradingSymbol(), MyMoneyMoney(txt).formatMoney(m_currencyComboBox->security().tradingSymbol(), m_currencyComboBox->security().pricePrecision()))); -} - -bool AccountTypePage::isComplete() const -{ - // check that the conversion rate is positive if enabled - bool rc = !m_conversionRate->isVisible() || (!m_conversionRate->value().isZero() && !m_conversionRate->value().isNegative()); - if (!rc) { - m_wizard->m_nextButton->setToolTip(i18n("Conversion rate is not positive")); - - } else { - rc = KMyMoneyWizardPage::isComplete(); - - if (!rc) { - m_wizard->m_nextButton->setToolTip(i18n("No account name supplied")); - } - } - hideShowPages(accountType()); - return rc; -} - -Account AccountTypePage::accountType() const -{ - return static_cast(m_typeSelection->currentItem()); -} - -const MyMoneySecurity& AccountTypePage::currency() const -{ - return m_currencyComboBox->security(); -} - -void AccountTypePage::setAccount(const MyMoneyAccount& acc) -{ - if (acc.accountType() != Account::Unknown) { - if (acc.accountType() == Account::AssetLoan) { - m_typeSelection->setCurrentItem((int)Account::Loan); - } else { - m_typeSelection->setCurrentItem((int)acc.accountType()); - } - } - m_openingDate->setDate(acc.openingDate()); - m_accountName->setText(acc.name()); -} - -const MyMoneyAccount& AccountTypePage::parentAccount() -{ - switch (accountType()) { - case Account::CreditCard: - case Account::Liability: - case Account::Loan: // Can be either but we return liability here - return MyMoneyFile::instance()->liability(); - break; - case Account::Equity: - return MyMoneyFile::instance()->equity(); - default: - break; - } - return MyMoneyFile::instance()->asset(); -} - -bool AccountTypePage::allowsParentAccount() const -{ - return accountType() != Account::Loan; -} - -BrokeragePage::BrokeragePage(Wizard* wizard) : - KBrokeragePageDecl(wizard), - WizardPage(StepBroker, this, wizard) -{ - connect(MyMoneyFile::instance(), SIGNAL(dataChanged()), this, SLOT(slotLoadWidgets())); -} - -void BrokeragePage::slotLoadWidgets() -{ - m_brokerageCurrency->update(QString("x")); -} - -void BrokeragePage::enterPage() -{ - // assign the currency of the investment account to the - // brokerage account if nothing else has ever been selected - if (m_brokerageCurrency->security().id().isEmpty()) { - m_brokerageCurrency->setSecurity(m_wizard->m_accountTypePage->m_currencyComboBox->security()); - } - - // check if the institution relevant fields should be enabled or not - bool enabled = m_wizard->m_institutionPage->m_accountNumber->isEnabled(); - m_accountNumberLabel->setEnabled(enabled); - m_accountNumber->setEnabled(enabled); - m_ibanLabel->setEnabled(enabled); - m_iban->setEnabled(enabled); -} - -KMyMoneyWizardPage* BrokeragePage::nextPage() const -{ - return m_wizard->m_hierarchyPage; -} - -CreditCardSchedulePage::CreditCardSchedulePage(Wizard* wizard) : - KSchedulePageDecl(wizard), - WizardPage(StepSchedule, this, wizard) -{ - m_mandatoryGroup->add(m_name); - m_mandatoryGroup->add(m_payee); - m_mandatoryGroup->add(m_amount->lineedit()); - m_mandatoryGroup->add(m_paymentAccount); - connect(m_paymentAccount, SIGNAL(itemSelected(QString)), object(), SIGNAL(completeStateChanged())); - connect(m_payee, SIGNAL(itemSelected(QString)), object(), SIGNAL(completeStateChanged())); - connect(m_date, SIGNAL(dateChanged(QDate)), object(), SIGNAL(completeStateChanged())); - - connect(m_payee, SIGNAL(createItem(QString,QString&)), wizard, SIGNAL(createPayee(QString,QString&))); - - m_reminderCheckBox->setChecked(true); - connect(m_reminderCheckBox, SIGNAL(toggled(bool)), object(), SIGNAL(completeStateChanged())); - - connect(MyMoneyFile::instance(), SIGNAL(dataChanged()), this, SLOT(slotLoadWidgets())); - - m_method->insertItem(i18n("Write check"), (int)Schedule::PaymentType::WriteChecque); -#if 0 - m_method->insertItem(i18n("Direct debit"), Schedule::PaymentType::DirectDebit); - m_method->insertItem(i18n("Bank transfer"), Schedule::PaymentType::BankTransfer); -#endif - m_method->insertItem(i18n("Standing order"), (int)Schedule::PaymentType::StandingOrder); - m_method->insertItem(i18n("Manual deposit"), (int)Schedule::PaymentType::ManualDeposit); - m_method->insertItem(i18n("Direct deposit"), (int)Schedule::PaymentType::DirectDeposit); - m_method->insertItem(i18nc("Other payment method", "Other"), (int)Schedule::PaymentType::Other); - m_method->setCurrentItem((int)Schedule::PaymentType::DirectDebit); - - slotLoadWidgets(); -} - -void CreditCardSchedulePage::enterPage() -{ - if (m_name->text().isEmpty()) - m_name->setText(i18n("Credit Card %1 monthly payment", m_wizard->m_accountTypePage->m_accountName->text())); -} - -bool CreditCardSchedulePage::isComplete() const -{ - bool rc = true; - QString msg = i18n("Finish entry and create account"); - if (m_reminderCheckBox->isChecked()) { - msg = i18n("Finish entry and create account and schedule"); - if (m_date->date() < m_wizard->m_accountTypePage->m_openingDate->date()) { - rc = false; - msg = i18n("Next due date is prior to opening date"); - } - if (m_paymentAccount->selectedItem().isEmpty()) { - rc = false; - msg = i18n("No account selected"); - } - if (m_amount->lineedit()->text().isEmpty()) { - rc = false; - msg = i18n("No amount for payment selected"); - } - if (m_payee->selectedItem().isEmpty()) { - rc = false; - msg = i18n("No payee for payment selected"); - } - if (m_name->text().isEmpty()) { - rc = false; - msg = i18n("No name assigned for schedule"); - } - } - m_wizard->m_finishButton->setToolTip(msg); - - return rc; -} - -void CreditCardSchedulePage::slotLoadWidgets() -{ - AccountSet set; - set.addAccountGroup(Account::Asset); - set.load(m_paymentAccount->selector()); - - m_payee->loadPayees(MyMoneyFile::instance()->payeeList()); -} - -KMyMoneyWizardPage* CreditCardSchedulePage::nextPage() const -{ - return m_wizard->m_hierarchyPage; -} - -GeneralLoanInfoPage::GeneralLoanInfoPage(Wizard* wizard) : - KGeneralLoanInfoPageDecl(wizard), - WizardPage(StepDetails, this, wizard), - m_firstTime(true) -{ - m_mandatoryGroup->add(m_payee); - - // remove the unsupported payment and compounding frequencies and setup default - m_paymentFrequency->removeItem((int)Schedule::Occurrence::Once); - m_paymentFrequency->removeItem((int)Schedule::Occurrence::EveryOtherYear); - m_paymentFrequency->setCurrentItem((int)Schedule::Occurrence::Monthly); - m_compoundFrequency->removeItem((int)Schedule::Occurrence::Once); - m_compoundFrequency->removeItem((int)Schedule::Occurrence::EveryOtherYear); - m_compoundFrequency->setCurrentItem((int)Schedule::Occurrence::Monthly); - - slotLoadWidgets(); - - connect(m_payee, SIGNAL(createItem(QString,QString&)), wizard, SIGNAL(createPayee(QString,QString&))); - connect(m_anyPayments, SIGNAL(activated(int)), object(), SIGNAL(completeStateChanged())); - connect(m_recordings, SIGNAL(activated(int)), object(), SIGNAL(completeStateChanged())); - - connect(m_interestType, SIGNAL(activated(int)), object(), SIGNAL(completeStateChanged())); - connect(m_interestChangeDateEdit, SIGNAL(dateChanged(QDate)), object(), SIGNAL(completeStateChanged())); - connect(m_openingBalance, SIGNAL(textChanged(QString)), object(), SIGNAL(completeStateChanged())); - - connect(MyMoneyFile::instance(), SIGNAL(dataChanged()), this, SLOT(slotLoadWidgets())); -} - -KMyMoneyWizardPage* GeneralLoanInfoPage::nextPage() const -{ - return m_wizard->m_loanDetailsPage; -} - -bool GeneralLoanInfoPage::recordAllPayments() const -{ - bool rc = true; // all payments - if (m_recordings->isEnabled()) { - if (m_recordings->currentIndex() != 0) - rc = false; - } - return rc; -} - -void GeneralLoanInfoPage::enterPage() -{ - if (m_firstTime) { - // setup default dates to last of this month and one year on top - QDate firstDay(QDate::currentDate().year(), QDate::currentDate().month(), 1); - m_firstPaymentDate->setDate(firstDay.addMonths(1).addDays(-1)); - m_interestChangeDateEdit->setDate(m_firstPaymentDate->date().addYears(1));; - m_firstTime = false; - } -} - -bool GeneralLoanInfoPage::isComplete() const -{ - m_wizard->setStepHidden(StepPayout, !m_wizard->openingBalance().isZero()); - bool rc = KMyMoneyWizardPage::isComplete(); - if (!rc) { - m_wizard->m_nextButton->setToolTip(i18n("No payee supplied")); - } - - // fixup availability of items on this page - m_recordings->setDisabled(m_anyPayments->currentIndex() == 0); - - m_interestFrequencyAmountEdit->setDisabled(m_interestType->currentIndex() == 0); - m_interestFrequencyUnitEdit->setDisabled(m_interestType->currentIndex() == 0); - m_interestChangeDateEdit->setDisabled(m_interestType->currentIndex() == 0); - - m_openingBalance->setDisabled(recordAllPayments()); - - if (m_openingBalance->isEnabled() && m_openingBalance->lineedit()->text().length() == 0) { - rc = false; - m_wizard->m_nextButton->setToolTip(i18n("No opening balance supplied")); } - if (rc - && (m_interestType->currentIndex() != 0) - && (m_interestChangeDateEdit->date() <= m_firstPaymentDate->date())) { - rc = false; - m_wizard->m_nextButton->setToolTip(i18n("An interest change can only happen after the first payment")); + bool Wizard::moneyBorrowed() const + { + Q_D(const Wizard); + return d->m_generalLoanInfoPage->d_func()->ui->m_loanDirection->currentIndex() == 0; } - return rc; -} - -const MyMoneyAccount& GeneralLoanInfoPage::parentAccount() -{ - return (m_loanDirection->currentIndex() == 0) - ? MyMoneyFile::instance()->liability() - : MyMoneyFile::instance()->asset(); -} - -void GeneralLoanInfoPage::slotLoadWidgets() -{ - m_payee->loadPayees(MyMoneyFile::instance()->payeeList()); -} - -LoanDetailsPage::LoanDetailsPage(Wizard* wizard) : - KLoanDetailsPageDecl(wizard), - WizardPage(StepPayments, this, wizard), - m_needCalculate(true) -{ - // force the balloon payment to zero (default) - m_balloonAmount->setValue(MyMoneyMoney()); - // allow any precision for the interest rate - m_interestRate->setPrecision(-1); - - connect(m_paymentDue, SIGNAL(activated(int)), this, SLOT(slotValuesChanged())); - - connect(m_termAmount, SIGNAL(valueChanged(int)), this, SLOT(slotValuesChanged())); - connect(m_termUnit, SIGNAL(highlighted(int)), this, SLOT(slotValuesChanged())); - connect(m_loanAmount, SIGNAL(textChanged(QString)), this, SLOT(slotValuesChanged())); - connect(m_interestRate, SIGNAL(textChanged(QString)), this, SLOT(slotValuesChanged())); - connect(m_paymentAmount, SIGNAL(textChanged(QString)), this, SLOT(slotValuesChanged())); - connect(m_balloonAmount, SIGNAL(textChanged(QString)), this, SLOT(slotValuesChanged())); - - connect(m_calculateButton, SIGNAL(clicked()), this, SLOT(slotCalculate())); -} - -void LoanDetailsPage::enterPage() -{ - // we need to remove a bunch of entries of the payment frequencies - m_termUnit->clear(); - - m_mandatoryGroup->clear(); - if (!m_wizard->openingBalance().isZero()) { - m_mandatoryGroup->add(m_loanAmount->lineedit()); - if (m_loanAmount->lineedit()->text().length() == 0) { - m_loanAmount->setValue(m_wizard->openingBalance().abs()); - } - } - - switch (m_wizard->m_generalLoanInfoPage->m_paymentFrequency->currentItem()) { - default: - m_termUnit->insertItem(i18n("Payments"), (int)Schedule::Occurrence::Once); - m_termUnit->setCurrentItem((int)Schedule::Occurrence::Once); - break; - case Schedule::Occurrence::Monthly: - m_termUnit->insertItem(i18n("Months"), (int)Schedule::Occurrence::Monthly); - m_termUnit->insertItem(i18n("Years"), (int)Schedule::Occurrence::Yearly); - m_termUnit->setCurrentItem((int)Schedule::Occurrence::Monthly); - break; - case Schedule::Occurrence::Yearly: - m_termUnit->insertItem(i18n("Years"), (int)Schedule::Occurrence::Yearly); - m_termUnit->setCurrentItem((int)Schedule::Occurrence::Yearly); - break; - } -} - -void LoanDetailsPage::slotValuesChanged() -{ - m_needCalculate = true; - m_wizard->completeStateChanged(); -} - -void LoanDetailsPage::slotCalculate() -{ - MyMoneyFinancialCalculator calc; - double val; - int PF, CF; - QString result; - bool moneyBorrowed = m_wizard->moneyBorrowed(); - bool moneyLend = !moneyBorrowed; - - // FIXME: for now, we only support interest calculation at the end of the period - calc.setBep(); - // FIXME: for now, we only support periodic compounding - calc.setDisc(); - - PF = m_wizard->m_generalLoanInfoPage->m_paymentFrequency->eventsPerYear(); - CF = m_wizard->m_generalLoanInfoPage->m_compoundFrequency->eventsPerYear(); - - if (PF == 0 || CF == 0) - return; - - calc.setPF(PF); - calc.setCF(CF); - - - if (!m_loanAmount->lineedit()->text().isEmpty()) { - val = m_loanAmount->value().abs().toDouble(); - if (moneyBorrowed) - val = -val; - calc.setPv(val); - } - - if (!m_interestRate->lineedit()->text().isEmpty()) { - val = m_interestRate->value().abs().toDouble(); - calc.setIr(val); - } - - if (!m_paymentAmount->lineedit()->text().isEmpty()) { - val = m_paymentAmount->value().abs().toDouble(); - if (moneyLend) - val = -val; - calc.setPmt(val); - } - - if (!m_balloonAmount->lineedit()->text().isEmpty()) { - val = m_balloonAmount->value().abs().toDouble(); - if (moneyLend) - val = -val; - calc.setFv(val); - } - - if (m_termAmount->value() != 0) { - calc.setNpp(term()); - } - - // setup of parameters is done, now do the calculation - try { - if (m_loanAmount->lineedit()->text().isEmpty()) { - // calculate the amount of the loan out of the other information - val = calc.presentValue(); - m_loanAmount->loadText(MyMoneyMoney(static_cast(val)).abs().formatMoney(QString(), m_wizard->precision())); - result = i18n("KMyMoney has calculated the amount of the loan as %1.", m_loanAmount->lineedit()->text()); - - } else if (m_interestRate->lineedit()->text().isEmpty()) { - // calculate the interest rate out of the other information - val = calc.interestRate(); - - m_interestRate->loadText(MyMoneyMoney(static_cast(val)).abs().formatMoney(QString(), 3)); - result = i18n("KMyMoney has calculated the interest rate to %1%.", m_interestRate->lineedit()->text()); - - } else if (m_paymentAmount->lineedit()->text().isEmpty()) { - // calculate the periodical amount of the payment out of the other information - val = calc.payment(); - m_paymentAmount->setValue(MyMoneyMoney(static_cast(val)).abs()); - // reset payment as it might have changed due to rounding - val = m_paymentAmount->value().abs().toDouble(); - if (moneyLend) - val = -val; - calc.setPmt(val); - - result = i18n("KMyMoney has calculated a periodic payment of %1 to cover principal and interest.", m_paymentAmount->lineedit()->text()); - - val = calc.futureValue(); - if ((moneyBorrowed && val < 0 && qAbs(val) >= qAbs(calc.payment())) - || (moneyLend && val > 0 && qAbs(val) >= qAbs(calc.payment()))) { - calc.setNpp(calc.npp() - 1); - // updateTermWidgets(calc.npp()); - val = calc.futureValue(); - MyMoneyMoney refVal(static_cast(val)); - m_balloonAmount->loadText(refVal.abs().formatMoney(QString(), m_wizard->precision())); - result += QString(" "); - result += i18n("The number of payments has been decremented and the balloon payment has been modified to %1.", m_balloonAmount->lineedit()->text()); - } else if ((moneyBorrowed && val < 0 && qAbs(val) < qAbs(calc.payment())) - || (moneyLend && val > 0 && qAbs(val) < qAbs(calc.payment()))) { - m_balloonAmount->loadText(MyMoneyMoney().formatMoney(QString(), m_wizard->precision())); - } else { - MyMoneyMoney refVal(static_cast(val)); - m_balloonAmount->loadText(refVal.abs().formatMoney(QString(), m_wizard->precision())); - result += i18n("The balloon payment has been modified to %1.", m_balloonAmount->lineedit()->text()); - } - - } else if (m_termAmount->value() == 0) { - // calculate the number of payments out of the other information - val = calc.numPayments(); - if (val == 0) - throw MYMONEYEXCEPTION("incorrect fincancial calculation"); - - // if the number of payments has a fractional part, then we - // round it to the smallest integer and calculate the balloon payment - result = i18n("KMyMoney has calculated the term of your loan as %1. ", updateTermWidgets(qFloor(val))); - - if (val != qFloor(val)) { - calc.setNpp(qFloor(val)); - val = calc.futureValue(); - MyMoneyMoney refVal(static_cast(val)); - m_balloonAmount->loadText(refVal.abs().formatMoney(QString(), m_wizard->precision())); - result += i18n("The balloon payment has been modified to %1.", m_balloonAmount->lineedit()->text()); - } - - } else { - // calculate the future value of the loan out of the other information - val = calc.futureValue(); - - // we differentiate between the following cases: - // a) the future value is greater than a payment - // b) the future value is less than a payment or the loan is overpaid - // c) all other cases - // - // a) means, we have paid more than we owed. This can't be - // b) means, we paid more than we owed but the last payment is - // less in value than regular payments. That means, that the - // future value is to be treated as (fully payed back) - // c) the loan is not payed back yet - if ((moneyBorrowed && val < 0 && qAbs(val) > qAbs(calc.payment())) - || (moneyLend && val > 0 && qAbs(val) > qAbs(calc.payment()))) { - // case a) - qDebug("Future Value is %f", val); - throw MYMONEYEXCEPTION("incorrect fincancial calculation"); - - } else if ((moneyBorrowed && val < 0 && qAbs(val) <= qAbs(calc.payment())) - || (moneyLend && val > 0 && qAbs(val) <= qAbs(calc.payment()))) { - // case b) - val = 0; - } - - MyMoneyMoney refVal(static_cast(val)); - result = i18n("KMyMoney has calculated a balloon payment of %1 for this loan.", refVal.abs().formatMoney(QString(), m_wizard->precision())); - - if (!m_balloonAmount->lineedit()->text().isEmpty()) { - if ((m_balloonAmount->value().abs() - refVal.abs()).abs().toDouble() > 1) { - throw MYMONEYEXCEPTION("incorrect fincancial calculation"); - } - result = i18n("KMyMoney has successfully verified your loan information."); - } - m_balloonAmount->loadText(refVal.abs().formatMoney(QString(), m_wizard->precision())); - } - - } catch (const MyMoneyException &) { - KMessageBox::error(0, - i18n("You have entered mis-matching information. Please modify " - "your figures or leave one value empty " - "to let KMyMoney calculate it for you"), - i18n("Calculation error")); - return; - } - - result += i18n("\n\nAccept this or modify the loan information and recalculate."); - - KMessageBox::information(0, result, i18n("Calculation successful")); - m_needCalculate = false; - - // now update change - m_wizard->completeStateChanged(); -} - -int LoanDetailsPage::term() const -{ - int factor = 0; - - if (m_termAmount->value() != 0) { - factor = 1; - switch (m_termUnit->currentItem()) { - case Schedule::Occurrence::Yearly: // years - factor = 12; - // intentional fall through - - case Schedule::Occurrence::Monthly: // months - factor *= 30; - factor *= m_termAmount->value(); - // factor now is the duration in days. we divide this by the - // payment frequency and get the number of payments - factor /= m_wizard->m_generalLoanInfoPage->m_paymentFrequency->daysBetweenEvents(); - break; - - default: - qDebug("Unknown term unit %d in LoanDetailsPage::term(). Using payments.", (int)m_termUnit->currentItem()); - // intentional fall through - - case Schedule::Occurrence::Once: // payments - factor = m_termAmount->value(); - break; - } - } - return factor; -} - -QString LoanDetailsPage::updateTermWidgets(const double val) -{ - long vl = qFloor(val); - - QString valString; - Schedule::Occurrence unit = m_termUnit->currentItem(); - - if ((unit == Schedule::Occurrence::Monthly) - && ((vl % 12) == 0)) { - vl /= 12; - unit = Schedule::Occurrence::Yearly; - } - - switch (unit) { - case Schedule::Occurrence::Monthly: - valString = i18np("one month", "%1 months", vl); - m_termUnit->setCurrentItem((int)Schedule::Occurrence::Monthly); - break; - case Schedule::Occurrence::Yearly: - valString = i18np("one year", "%1 years", vl); - m_termUnit->setCurrentItem((int)Schedule::Occurrence::Yearly); - break; - default: - valString = i18np("one payment", "%1 payments", vl); - m_termUnit->setCurrentItem((int)Schedule::Occurrence::Once); - break; - } - m_termAmount->setValue(vl); - return valString; -} - -bool LoanDetailsPage::isComplete() const -{ - // bool rc = KMyMoneyWizardPage::isComplete(); - - int fieldCnt = 0; - - if (m_loanAmount->lineedit()->text().length() > 0) { - fieldCnt++; - } - - if (m_interestRate->lineedit()->text().length() > 0) { - fieldCnt++; - } - - if (m_termAmount->value() != 0) { - fieldCnt++; - } - - if (m_paymentAmount->lineedit()->text().length() > 0) { - fieldCnt++; - } - - if (m_balloonAmount->lineedit()->text().length() > 0) { - fieldCnt++; - } - - m_calculateButton->setEnabled(fieldCnt == 4 || (fieldCnt == 5 && m_needCalculate)); - - m_calculateButton->setAutoDefault(false); - m_calculateButton->setDefault(false); - if (m_needCalculate && fieldCnt == 4) { - m_wizard->m_nextButton->setToolTip(i18n("Press Calculate to verify the values")); - m_calculateButton->setAutoDefault(true); - m_calculateButton->setDefault(true); - } else if (fieldCnt != 5) { - m_wizard->m_nextButton->setToolTip(i18n("Not all details supplied")); - m_calculateButton->setAutoDefault(true); - m_calculateButton->setDefault(true); - } - m_wizard->m_nextButton->setAutoDefault(!m_calculateButton->autoDefault()); - m_wizard->m_nextButton->setDefault(!m_calculateButton->autoDefault()); - - return (fieldCnt == 5) && !m_needCalculate; -} - -KMyMoneyWizardPage* LoanDetailsPage::nextPage() const -{ - return m_wizard->m_loanPaymentPage; -} - - -class LoanPaymentPage::Private -{ -public: - MyMoneyAccount phonyAccount; - MyMoneySplit phonySplit; - MyMoneyTransaction additionalFeesTransaction; - MyMoneyMoney additionalFees; -}; - -LoanPaymentPage::LoanPaymentPage(Wizard* wizard) : - KLoanPaymentPageDecl(wizard), - WizardPage(StepFees, this, wizard), - d(new Private) -{ - d->phonyAccount = MyMoneyAccount(QLatin1String("Phony-ID"), MyMoneyAccount()); - - d->phonySplit.setAccountId(d->phonyAccount.id()); - d->phonySplit.setValue(MyMoneyMoney()); - d->phonySplit.setShares(MyMoneyMoney()); - - d->additionalFeesTransaction.addSplit(d->phonySplit); - - connect(m_additionalFeesButton, SIGNAL(clicked()), this, SLOT(slotAdditionalFees())); -} - -LoanPaymentPage::~LoanPaymentPage() -{ - delete d; -} - -MyMoneyMoney LoanPaymentPage::basePayment() const -{ - return m_wizard->m_loanDetailsPage->m_paymentAmount->value(); -} - -MyMoneyMoney LoanPaymentPage::additionalFees() const -{ - return d->additionalFees; -} - -void LoanPaymentPage::additionalFeesSplits(QList& list) -{ - list.clear(); - - QList::ConstIterator it; - for (it = d->additionalFeesTransaction.splits().constBegin(); it != d->additionalFeesTransaction.splits().constEnd(); ++it) { - if ((*it).accountId() != d->phonyAccount.id()) { - list << (*it); - } - } -} - -void LoanPaymentPage::updateAmounts() -{ - m_additionalFees->setText(d->additionalFees.formatMoney(m_wizard->currency().tradingSymbol(), m_wizard->precision())); - m_totalPayment->setText((basePayment() + d->additionalFees).formatMoney(m_wizard->currency().tradingSymbol(), m_wizard->precision())); -} - -void LoanPaymentPage::enterPage() -{ - const MyMoneySecurity& currency = m_wizard->currency(); - - m_basePayment->setText(basePayment().formatMoney(currency.tradingSymbol(), m_wizard->precision())); - d->phonyAccount.setCurrencyId(currency.id()); - d->additionalFeesTransaction.setCommodity(currency.id()); - - updateAmounts(); -} - -void LoanPaymentPage::slotAdditionalFees() -{ - QMap priceInfo; - QPointer dlg = new KSplitTransactionDlg(d->additionalFeesTransaction, d->phonySplit, d->phonyAccount, false, !m_wizard->moneyBorrowed(), MyMoneyMoney(), priceInfo); - - // connect(dlg, SIGNAL(newCategory(MyMoneyAccount&)), this, SIGNAL(newCategory(MyMoneyAccount&))); - - if (dlg->exec() == QDialog::Accepted) { - d->additionalFeesTransaction = dlg->transaction(); - // sum up the additional fees - QList::ConstIterator it; - - d->additionalFees = MyMoneyMoney(); - for (it = d->additionalFeesTransaction.splits().constBegin(); it != d->additionalFeesTransaction.splits().constEnd(); ++it) { - if ((*it).accountId() != d->phonyAccount.id()) { - d->additionalFees += (*it).shares(); - } - } - updateAmounts(); - } - - delete dlg; -} - -KMyMoneyWizardPage* LoanPaymentPage::nextPage() const -{ - return m_wizard->m_loanSchedulePage; -} - - -LoanSchedulePage::LoanSchedulePage(Wizard* wizard) : - KLoanSchedulePageDecl(wizard), - WizardPage(StepSchedule, this, wizard) -{ - m_mandatoryGroup->add(m_interestCategory->lineEdit()); - m_mandatoryGroup->add(m_paymentAccount->lineEdit()); - connect(m_interestCategory, SIGNAL(createItem(QString,QString&)), this, SLOT(slotCreateCategory(QString,QString&))); - connect(MyMoneyFile::instance(), SIGNAL(dataChanged()), this, SLOT(slotLoadWidgets())); -} - -void LoanSchedulePage::slotCreateCategory(const QString& name, QString& id) -{ - MyMoneyAccount acc, parent; - acc.setName(name); - - if (m_wizard->moneyBorrowed()) - parent = MyMoneyFile::instance()->expense(); - else - parent = MyMoneyFile::instance()->income(); - - emit m_wizard->createCategory(acc, parent); - - // return id - id = acc.id(); -} - -QDate LoanSchedulePage::firstPaymentDueDate() const -{ - if (m_firstPaymentDueDate->isEnabled()) - return m_firstPaymentDueDate->date(); - return m_wizard->m_generalLoanInfoPage->m_firstPaymentDate->date(); -} - -void LoanSchedulePage::enterPage() -{ - m_interestCategory->setFocus(); - m_firstPaymentDueDate->setDisabled(m_wizard->m_generalLoanInfoPage->recordAllPayments()); - slotLoadWidgets(); -} - -void LoanSchedulePage::slotLoadWidgets() -{ - AccountSet set; - if (m_wizard->moneyBorrowed()) - set.addAccountGroup(Account::Expense); - else - set.addAccountGroup(Account::Income); - set.load(m_interestCategory->selector()); - - set.clear(); - set.addAccountGroup(Account::Asset); - set.load(m_paymentAccount->selector()); -} - -KMyMoneyWizardPage* LoanSchedulePage::nextPage() const -{ - // if the balance widget of the general loan info page is enabled and - // the value is not zero, then the payout already happened and we don't - // aks for it. - if (m_wizard->openingBalance().isZero()) - return m_wizard->m_loanPayoutPage; - return m_wizard->m_accountSummaryPage; -} - -LoanPayoutPage::LoanPayoutPage(Wizard* wizard) : - KLoanPayoutPageDecl(wizard), - WizardPage(StepPayout, this, wizard) -{ - m_mandatoryGroup->add(m_assetAccount->lineEdit()); - m_mandatoryGroup->add(m_loanAccount->lineEdit()); - - KGuiItem createAssetButtenItem(i18n("&Create..."), - QIcon::fromTheme(g_Icons[Icon::DocumentNew]), - i18n("Create a new asset account"), - i18n("If the asset account does not yet exist, press this button to create it.")); - KGuiItem::assign(m_createAssetButton, createAssetButtenItem); - m_createAssetButton->setToolTip(createAssetButtenItem.toolTip()); - m_createAssetButton->setWhatsThis(createAssetButtenItem.whatsThis()); - connect(m_createAssetButton, SIGNAL(clicked()), this, SLOT(slotCreateAssetAccount())); - - connect(m_noPayoutTransaction, SIGNAL(toggled(bool)), this, SLOT(slotButtonsToggled())); - connect(m_refinanceLoan, SIGNAL(toggled(bool)), this, SLOT(slotButtonsToggled())); - - connect(MyMoneyFile::instance(), SIGNAL(dataChanged()), this, SLOT(slotLoadWidgets())); - slotLoadWidgets(); -} - -void LoanPayoutPage::slotButtonsToggled() -{ - // we don't go directly, as the order of the emission of signals to slots is - // not defined. Using a single shot timer postpones the call of m_mandatoryGroup::changed() - // until the next round of the main loop so we can be sure to see all relevant changes - // that happened in the meantime (eg. widgets are enabled and disabled) - QTimer::singleShot(0, m_mandatoryGroup, SLOT(changed())); -} - -void LoanPayoutPage::slotCreateAssetAccount() -{ - MyMoneyAccount acc; - acc.setAccountType(Account::Asset); - acc.setOpeningDate(m_wizard->m_accountTypePage->m_openingDate->date()); - - emit m_wizard->createAccount(acc); - - if (!acc.id().isEmpty()) { - m_assetAccount->setSelectedItem(acc.id()); - } -} - -void LoanPayoutPage::slotLoadWidgets() -{ - AccountSet set; - set.addAccountGroup(Account::Asset); - set.load(m_assetAccount->selector()); - - set.clear(); - set.addAccountType(Account::Loan); - set.load(m_loanAccount->selector()); -} - -void LoanPayoutPage::enterPage() -{ - // only allow to create new asset accounts for liability loans - m_createAssetButton->setEnabled(m_wizard->moneyBorrowed()); - m_refinanceLoan->setEnabled(m_wizard->moneyBorrowed()); - if (!m_wizard->moneyBorrowed()) { - m_refinanceLoan->setChecked(false); - } - m_payoutDetailFrame->setDisabled(m_noPayoutTransaction->isChecked()); -} - -KMyMoneyWizardPage* LoanPayoutPage::nextPage() const -{ - return m_wizard->m_accountSummaryPage; -} - -bool LoanPayoutPage::isComplete() const -{ - return KMyMoneyWizardPage::isComplete() | m_noPayoutTransaction->isChecked(); -} - -QString LoanPayoutPage::payoutAccountId() const -{ - if (m_refinanceLoan->isChecked()) { - return m_loanAccount->selectedItem(); - } else { - return m_assetAccount->selectedItem(); - } -} - -HierarchyFilterProxyModel::HierarchyFilterProxyModel(QObject *parent) - : AccountsProxyModel(parent) -{ -} - -/** - * Filter the favorites accounts group. - */ -bool HierarchyFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const -{ - if (!source_parent.isValid()) { - auto accCol = m_mdlColumns->indexOf(eAccountsModel::Column::Account); - QVariant data = sourceModel()->index(source_row, accCol, source_parent).data((int)eAccountsModel::Role::ID); - if (data.isValid() && data.toString() == AccountsModel::favoritesAccountId) - return false; - } - return AccountsProxyModel::filterAcceptsRow(source_row, source_parent); -} - -/** - * Filter all but the first column. - */ -bool HierarchyFilterProxyModel::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const -{ - Q_UNUSED(source_parent) - if (source_column == 0) - return true; - return false; -} - -HierarchyPage::HierarchyPage(Wizard* wizard) : - KHierarchyPageDecl(wizard), - WizardPage(StepParentAccount, this, wizard), - m_filterProxyModel(nullptr) -{ - // the proxy filter model - m_filterProxyModel = new HierarchyFilterProxyModel(this); - m_filterProxyModel->setHideClosedAccounts(true); - m_filterProxyModel->setHideEquityAccounts(!KMyMoneyGlobalSettings::expertMode()); - m_filterProxyModel->addAccountGroup(QVector {Account::Asset, Account::Liability}); - auto const model = Models::instance()->accountsModel(); - m_filterProxyModel->setSourceModel(model); - m_filterProxyModel->setSourceColumns(model->getColumns()); - m_filterProxyModel->setDynamicSortFilter(true); - - m_parentAccounts->setModel(m_filterProxyModel); - m_parentAccounts->sortByColumn((int)eAccountsModel::Column::Account, Qt::AscendingOrder); - - connect(m_parentAccounts->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(parentAccountChanged())); -} - -void HierarchyPage::enterPage() -{ - // Ensure that the list reflects the Account Type - MyMoneyAccount topAccount = m_wizard->m_accountTypePage->parentAccount(); - m_filterProxyModel->clear(); - m_filterProxyModel->addAccountGroup(QVector {topAccount.accountGroup()}); - m_parentAccounts->expandAll(); -} - -KMyMoneyWizardPage* HierarchyPage::nextPage() const -{ - return m_wizard->m_accountSummaryPage; -} - -const MyMoneyAccount& HierarchyPage::parentAccount() -{ - QVariant data = m_parentAccounts->model()->data(m_parentAccounts->currentIndex(), (int)eAccountsModel::Role::Account); - if (data.isValid()) { - m_parentAccount = data.value(); - } else { - m_parentAccount = MyMoneyAccount(); - } - return m_parentAccount; -} - -bool HierarchyPage::isComplete() const -{ - return m_parentAccounts->currentIndex().isValid(); -} - -void HierarchyPage::parentAccountChanged() -{ - completeStateChanged(); -} - -AccountSummaryPage::AccountSummaryPage(Wizard* wizard) : - KAccountSummaryPageDecl(wizard), - WizardPage(StepFinish, this, wizard) -{ -} - -void AccountSummaryPage::enterPage() -{ - MyMoneyAccount acc = m_wizard->account(); - MyMoneySecurity sec = m_wizard->currency(); - acc.fraction(sec); - - // assign an id to the account inside the wizard which is required for a schedule - // get the schedule and clear the id again in the wizards object. - MyMoneyAccount tmp(QLatin1String("Phony-ID"), acc); - m_wizard->setAccount(tmp); - MyMoneySchedule sch = m_wizard->schedule(); - m_wizard->setAccount(acc); - - m_dataList->clear(); - - - - // Account data - m_dataList->setFontWeight(QFont::Bold); - m_dataList->append(i18n("Account information")); - m_dataList->setFontWeight(QFont::Normal); - m_dataList->append(i18nc("Account name", "Name: %1", acc.name())); - if (!acc.isLoan()) - m_dataList->append(i18n("Subaccount of %1", m_wizard->parentAccount().name())); - QString accTypeText; - if (acc.accountType() == Account::AssetLoan) - accTypeText = i18n("Loan"); - else - accTypeText = m_wizard->m_accountTypePage->m_typeSelection->currentText(); - m_dataList->append(i18n("Type: %1", accTypeText)); - - m_dataList->append(i18n("Currency: %1", m_wizard->currency().name())); - m_dataList->append(i18n("Opening date: %1", QLocale().toString(acc.openingDate()))); - if (m_wizard->currency().id() != MyMoneyFile::instance()->baseCurrency().id()) { - m_dataList->append(i18n("Conversion rate: %1", m_wizard->conversionRate().rate(QString()).formatMoney(QString(), m_wizard->currency().pricePrecision()))); - } - if (!acc.isLoan() || !m_wizard->openingBalance().isZero()) - m_dataList->append(i18n("Opening balance: %1", MyMoneyUtils::formatMoney(m_wizard->openingBalance(), acc, sec))); - - if (!m_wizard->m_institutionPage->institution().id().isEmpty()) { - m_dataList->append(i18n("Institution: %1", m_wizard->m_institutionPage->institution().name())); - if (!acc.number().isEmpty()) { - m_dataList->append(i18n("Number: %1", acc.number())); - } - if (!acc.value("iban").isEmpty()) { - m_dataList->append(i18n("IBAN: %1", acc.value("iban"))); - } - } - - if (acc.accountType() == Account::Investment) { - if (m_wizard->m_brokeragepage->m_createBrokerageButton->isChecked()) { - m_dataList->setFontWeight(QFont::Bold); - m_dataList->append(i18n("Brokerage Account")); - m_dataList->setFontWeight(QFont::Normal); - - m_dataList->append(i18nc("Account name", "Name: %1 (Brokerage)", acc.name())); - m_dataList->append(i18n("Currency: %1", m_wizard->m_brokeragepage->m_brokerageCurrency->security().name())); - if (m_wizard->m_brokeragepage->m_accountNumber->isEnabled() && !m_wizard->m_brokeragepage->m_accountNumber->text().isEmpty()) - m_dataList->append(i18n("Number: %1", m_wizard->m_brokeragepage->m_accountNumber->text())); - if (m_wizard->m_brokeragepage->m_iban->isEnabled() && !m_wizard->m_brokeragepage->m_iban->text().isEmpty()) - m_dataList->append(i18n("IBAN: %1", m_wizard->m_brokeragepage->m_iban->text())); - } - } - - // Loan - if (acc.isLoan()) { - m_dataList->setFontWeight(QFont::Bold); - m_dataList->append(i18n("Loan information")); - m_dataList->setFontWeight(QFont::Normal); - if (m_wizard->moneyBorrowed()) { - m_dataList->append(i18n("Amount borrowed: %1", m_wizard->m_loanDetailsPage->m_loanAmount->value().formatMoney(m_wizard->currency().tradingSymbol(), m_wizard->precision()))); - } else { - m_dataList->append(i18n("Amount lent: %1", m_wizard->m_loanDetailsPage->m_loanAmount->value().formatMoney(m_wizard->currency().tradingSymbol(), m_wizard->precision()))); - } - m_dataList->append(i18n("Interest rate: %1 %", m_wizard->m_loanDetailsPage->m_interestRate->value().formatMoney(QString(), -1))); - m_dataList->append(i18n("Interest rate is %1", m_wizard->m_generalLoanInfoPage->m_interestType->currentText())); - m_dataList->append(i18n("Principal and interest: %1", MyMoneyUtils::formatMoney(m_wizard->m_loanDetailsPage->m_paymentAmount->value(), acc, sec))); - m_dataList->append(i18n("Additional Fees: %1", MyMoneyUtils::formatMoney(m_wizard->m_loanPaymentPage->additionalFees(), acc, sec))); - m_dataList->append(i18n("Payment frequency: %1", m_wizard->m_generalLoanInfoPage->m_paymentFrequency->currentText())); - m_dataList->append(i18n("Payment account: %1", m_wizard->m_loanSchedulePage->m_paymentAccount->currentText())); - - if (!m_wizard->m_loanPayoutPage->m_noPayoutTransaction->isChecked() && m_wizard->openingBalance().isZero()) { - m_dataList->setFontWeight(QFont::Bold); - m_dataList->append(i18n("Payout information")); - m_dataList->setFontWeight(QFont::Normal); - if (m_wizard->m_loanPayoutPage->m_refinanceLoan->isChecked()) { - m_dataList->append(i18n("Refinance: %1", m_wizard->m_loanPayoutPage->m_loanAccount->currentText())); - } else { - if (m_wizard->moneyBorrowed()) - m_dataList->append(i18n("Transfer amount to %1", m_wizard->m_loanPayoutPage->m_assetAccount->currentText())); - else - m_dataList->append(i18n("Transfer amount from %1", m_wizard->m_loanPayoutPage->m_assetAccount->currentText())); - } - m_dataList->append(i18n("Payment date: %1 ", QLocale().toString(m_wizard->m_loanPayoutPage->m_payoutDate->date()))); - } - } - - // Schedule - if (!(sch == MyMoneySchedule())) { - m_dataList->setFontWeight(QFont::Bold); - m_dataList->append(i18n("Schedule information")); - m_dataList->setFontWeight(QFont::Normal); - m_dataList->append(i18nc("Schedule name", "Name: %1", sch.name())); - if (acc.accountType() == Account::CreditCard) { - MyMoneyAccount paymentAccount = MyMoneyFile::instance()->account(m_wizard->m_schedulePage->m_paymentAccount->selectedItem()); - m_dataList->append(i18n("Occurrence: Monthly")); - m_dataList->append(i18n("Paid from %1", paymentAccount.name())); - m_dataList->append(i18n("Pay to %1", m_wizard->m_schedulePage->m_payee->currentText())); - m_dataList->append(i18n("Amount: %1", MyMoneyUtils::formatMoney(m_wizard->m_schedulePage->m_amount->value(), acc, sec))); - m_dataList->append(i18n("First payment due on %1", QLocale().toString(sch.nextDueDate()))); - m_dataList->append(i18n("Payment method: %1", m_wizard->m_schedulePage->m_method->currentText())); - } - if (acc.isLoan()) { - m_dataList->append(i18n("Occurrence: %1", m_wizard->m_generalLoanInfoPage->m_paymentFrequency->currentText())); - m_dataList->append(i18n("Amount: %1", MyMoneyUtils::formatMoney(m_wizard->m_loanPaymentPage->basePayment() + m_wizard->m_loanPaymentPage->additionalFees(), acc, sec))); - m_dataList->append(i18n("First payment due on %1", QLocale().toString(m_wizard->m_loanSchedulePage->firstPaymentDueDate()))); - } - } -} } diff --git a/kmymoney/wizards/newaccountwizard/knewaccountwizard_p.h b/kmymoney/wizards/newaccountwizard/knewaccountwizard_p.h --- a/kmymoney/wizards/newaccountwizard/knewaccountwizard_p.h +++ b/kmymoney/wizards/newaccountwizard/knewaccountwizard_p.h @@ -21,435 +21,80 @@ // ---------------------------------------------------------------------------- // QT Includes -#include -#include - // ---------------------------------------------------------------------------- // KDE Includes -#include -#include - // ---------------------------------------------------------------------------- // Project Includes -#include "kmymoneywizardpage.h" -#include -#include -#include -#include -#include -#include "accountsproxymodel.h" - -#include "ui_kinstitutionpagedecl.h" -#include "ui_kaccounttypepagedecl.h" -#include "ui_kbrokeragepagedecl.h" -#include "ui_kschedulepagedecl.h" -#include "ui_kgeneralloaninfopagedecl.h" -#include "ui_kloandetailspagedecl.h" -#include "ui_kloanpaymentpagedecl.h" -#include "ui_kloanschedulepagedecl.h" -#include "ui_kloanpayoutpagedecl.h" -#include "ui_khierarchypagedecl.h" -#include "ui_kaccountsummarypagedecl.h" - -class Wizard; -class MyMoneyInstitution; +#include "kmymoneywizard_p.h" +#include "knewaccountwizard.h" +#include "kaccounttypepage.h" +#include "mymoneyaccountloan.h" +#include "mymoneymoney.h" +#include "mymoneyschedule.h" +#include "mymoneysecurity.h" namespace NewAccountWizard { - - -class KInstitutionPageDecl : public QWidget, public Ui::KInstitutionPageDecl -{ -public: - KInstitutionPageDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; - -class InstitutionPage : public KInstitutionPageDecl, public WizardPage -{ - Q_OBJECT -public: - InstitutionPage(Wizard* parent); - ~InstitutionPage(); - KMyMoneyWizardPage* nextPage(void) const; - - QWidget* initialFocusWidget(void) const { - return m_institutionComboBox; - } - - /** - * Returns the information about an institution if entered by - * the user. If the id field is empty, then he did not enter - * such information. - */ - const MyMoneyInstitution& institution(void) const; - - void selectExistingInstitution(const QString& id); - -private slots: - void slotLoadWidgets(void); - void slotNewInstitution(void); - void slotSelectInstitution(int index); - -private: - /// \internal d-pointer class. - class Private; - /// \internal d-pointer instance. - Private* const d; -}; - - -class KAccountTypePageDecl : public QWidget, public Ui::KAccountTypePageDecl -{ -public: - KAccountTypePageDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; - -class AccountTypePage : public KAccountTypePageDecl, public WizardPage -{ - Q_OBJECT -public: - AccountTypePage(Wizard* parent); - virtual bool isComplete(void) const; - KMyMoneyWizardPage* nextPage(void) const; - - QWidget* initialFocusWidget(void) const { - return m_accountName; - } - - eMyMoney::Account accountType(void) const; - const MyMoneyAccount& parentAccount(void); - bool allowsParentAccount(void) const; - const MyMoneySecurity& currency(void) const; - - void setAccount(const MyMoneyAccount& acc); - -private: - void hideShowPages(eMyMoney::Account i) const; - void priceWarning(bool); - -private slots: - void slotUpdateType(int i); - void slotUpdateCurrency(void); - void slotUpdateConversionRate(const QString&); - void slotGetOnlineQuote(void); - void slotPriceWarning(void); - -private: - bool m_showPriceWarning; -}; - - -class KBrokeragePageDecl : public QWidget, public Ui::KBrokeragePageDecl -{ -public: - KBrokeragePageDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; - -class BrokeragePage : public KBrokeragePageDecl, public WizardPage -{ - Q_OBJECT -public: - BrokeragePage(Wizard* parent); - KMyMoneyWizardPage* nextPage(void) const; - void enterPage(void); - - QWidget* initialFocusWidget(void) const { - return m_createBrokerageButton; - } - -private slots: - void slotLoadWidgets(void); -}; - - -class KSchedulePageDecl : public QWidget, public Ui::KSchedulePageDecl -{ -public: - KSchedulePageDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; - -class CreditCardSchedulePage : public KSchedulePageDecl, public WizardPage -{ - Q_OBJECT -public: - CreditCardSchedulePage(Wizard* parent); - KMyMoneyWizardPage* nextPage(void) const; - virtual bool isComplete(void) const; - void enterPage(void); - - QWidget* initialFocusWidget(void) const { - return m_reminderCheckBox; - } - -private slots: - void slotLoadWidgets(void); -}; - - -class KGeneralLoanInfoPageDecl : public QWidget, public Ui::KGeneralLoanInfoPageDecl -{ -public: - KGeneralLoanInfoPageDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; - -class GeneralLoanInfoPage : public KGeneralLoanInfoPageDecl, public WizardPage -{ - Q_OBJECT -public: - GeneralLoanInfoPage(Wizard* parent); - KMyMoneyWizardPage* nextPage(void) const; - virtual bool isComplete(void) const; - void enterPage(void); - const MyMoneyAccount& parentAccount(void); - - QWidget* initialFocusWidget(void) const { - return m_loanDirection; - } - - /** - * Returns @p true if the user decided to record all payments, @p false otherwise. - */ - bool recordAllPayments(void) const; - -private slots: - void slotLoadWidgets(void); - -private: - bool m_firstTime; -}; - - -class KLoanDetailsPageDecl : public QWidget, public Ui::KLoanDetailsPageDecl -{ -public: - KLoanDetailsPageDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; - -class LoanDetailsPage : public KLoanDetailsPageDecl, public WizardPage -{ - Q_OBJECT -public: - LoanDetailsPage(Wizard* parent); - void enterPage(void); - KMyMoneyWizardPage* nextPage(void) const; - virtual bool isComplete(void) const; - - QWidget* initialFocusWidget(void) const { - return m_paymentDue; - } - - /** - * This method returns the number of payments depending on - * the settings of m_termAmount and m_termUnit widgets - */ - int term(void) const; - -private: - /** - * This method is used to update the term widgets - * according to the length of the given @a term. - * The term is also converted into a string and returned. - */ - QString updateTermWidgets(const double term); - -private: - bool m_needCalculate; - -private slots: - void slotValuesChanged(void); - void slotCalculate(void); -}; - - -class KLoanPaymentPageDecl : public QWidget, public Ui::KLoanPaymentPageDecl -{ -public: - KLoanPaymentPageDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; - -class LoanPaymentPage : public KLoanPaymentPageDecl, public WizardPage -{ - Q_OBJECT -public: - LoanPaymentPage(Wizard* parent); - ~LoanPaymentPage(); - - KMyMoneyWizardPage* nextPage(void) const; - - void enterPage(void); - - /** - * This method returns the sum of the additional fees - */ - MyMoneyMoney additionalFees(void) const; - - /** - * This method returns the base payment, that's principal and interest - */ - MyMoneyMoney basePayment(void) const; - - /** - * This method returns the splits that make up the additional fees in @p list. - * @note The splits may contain assigned ids which the caller must remove before - * adding the splits to a MyMoneyTransaction object. + class AccountTypePage; + class InstitutionPage; + class BrokeragePage; + class CreditCardSchedulePage; + class GeneralLoanInfoPage; + class LoanDetailsPage; + class LoanPaymentPage; + class LoanSchedulePage; + class LoanPayoutPage; + class HierarchyPage; + class AccountSummaryPage; + + class WizardPrivate : public KMyMoneyWizardPrivate + { + Q_DISABLE_COPY(WizardPrivate) + + public: + WizardPrivate(Wizard *qq): + KMyMoneyWizardPrivate(qq) + { + } + + ~WizardPrivate() + { + } + + /** + * This method returns the currently selected currency for the account */ - void additionalFeesSplits(QList& list); - -protected slots: - void slotAdditionalFees(void); - -protected: - void updateAmounts(void); - -private: - /// \internal d-pointer class. - class Private; - /// \internal d-pointer instance. - Private* const d; -}; - - -class KLoanSchedulePageDecl : public QWidget, public Ui::KLoanSchedulePageDecl -{ -public: - KLoanSchedulePageDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; - -class LoanSchedulePage : public KLoanSchedulePageDecl, public WizardPage -{ - Q_OBJECT -public: - LoanSchedulePage(Wizard* parent); - void enterPage(void); - - KMyMoneyWizardPage* nextPage(void) const; - - /** - * This method returns the due date of the first payment to be recorded. + const MyMoneySecurity& currency() const + { + return m_accountTypePage->currency(); + } + + /** + * This method returns the precision in digits for the selected currency. + * @sa currency() */ - QDate firstPaymentDueDate(void) const; - - QWidget* initialFocusWidget(void) const { - return m_interestCategory; - } - -private slots: - void slotLoadWidgets(void); - void slotCreateCategory(const QString& name, QString& id); -}; - - -class KLoanPayoutPageDecl : public QWidget, public Ui::KLoanPayoutPageDecl -{ -public: - KLoanPayoutPageDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; - -class LoanPayoutPage : public KLoanPayoutPageDecl, public WizardPage -{ - Q_OBJECT -public: - LoanPayoutPage(Wizard* parent); - void enterPage(void); - virtual bool isComplete(void) const; - - KMyMoneyWizardPage* nextPage(void) const; - - QWidget* initialFocusWidget(void) const { - return m_noPayoutTransaction; - } - - QString payoutAccountId(void) const; - -private slots: - void slotLoadWidgets(void); - void slotCreateAssetAccount(void); - void slotButtonsToggled(void); -}; - -class HierarchyFilterProxyModel : public AccountsProxyModel -{ - Q_OBJECT - -public: - HierarchyFilterProxyModel(QObject *parent = 0); - -protected: - bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; - bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const; -}; - -class KHierarchyPageDecl : public QWidget, public Ui::KHierarchyPageDecl -{ -public: - KHierarchyPageDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; - -class HierarchyPage : public KHierarchyPageDecl, public WizardPage -{ - Q_OBJECT - -public: - HierarchyPage(Wizard* parent); - void enterPage(void); - KMyMoneyWizardPage* nextPage(void) const; - QWidget* initialFocusWidget(void) const { - return m_parentAccounts; - } - const MyMoneyAccount& parentAccount(void); - - bool isComplete(void) const; - -protected slots: - void parentAccountChanged(); - -private: - HierarchyFilterProxyModel *m_filterProxyModel; - MyMoneyAccount m_parentAccount; -}; - - -class KAccountSummaryPageDecl : public QWidget, public Ui::KAccountSummaryPageDecl -{ -public: - KAccountSummaryPageDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; - -class AccountSummaryPage : public KAccountSummaryPageDecl, public WizardPage -{ - Q_OBJECT -public: - AccountSummaryPage(Wizard* parent); - void enterPage(void); - QWidget* initialFocusWidget(void) const { - return m_dataList; - } -}; - + int precision() const + { + return MyMoneyMoney::denomToPrec(currency().smallestAccountFraction()); + } + + InstitutionPage* m_institutionPage; + AccountTypePage* m_accountTypePage; + BrokeragePage* m_brokeragepage; + CreditCardSchedulePage* m_schedulePage; + GeneralLoanInfoPage* m_generalLoanInfoPage; + LoanDetailsPage* m_loanDetailsPage; + LoanPaymentPage* m_loanPaymentPage; + LoanSchedulePage* m_loanSchedulePage; + LoanPayoutPage* m_loanPayoutPage; + HierarchyPage* m_hierarchyPage; + AccountSummaryPage* m_accountSummaryPage; + + MyMoneyAccountLoan m_account; + MyMoneySchedule m_schedule; + }; } // namespace #endif diff --git a/kmymoney/wizards/newinvestmentwizard/kinvestmentdetailswizardpage.cpp b/kmymoney/wizards/newinvestmentwizard/kinvestmentdetailswizardpage.cpp --- a/kmymoney/wizards/newinvestmentwizard/kinvestmentdetailswizardpage.cpp +++ b/kmymoney/wizards/newinvestmentwizard/kinvestmentdetailswizardpage.cpp @@ -147,5 +147,5 @@ void KInvestmentDetailsWizardPage::setupInvestmentSymbol() { ui->m_investmentSymbol->setFocus(); - connect(ui->m_investmentSymbol, SIGNAL(lineChanged(QString)), this, SIGNAL(checkForExistingSymbol(QString))); + connect(ui->m_investmentSymbol, &KMyMoneyLineEdit::lineChanged, this, &KInvestmentDetailsWizardPage::checkForExistingSymbol); } diff --git a/kmymoney/wizards/newinvestmentwizard/knewinvestmentwizard.h b/kmymoney/wizards/newinvestmentwizard/knewinvestmentwizard.h --- a/kmymoney/wizards/newinvestmentwizard/knewinvestmentwizard.h +++ b/kmymoney/wizards/newinvestmentwizard/knewinvestmentwizard.h @@ -47,17 +47,17 @@ /** * Use this constructor for the creation of a new investment */ - explicit KNewInvestmentWizard(QWidget *parent = 0); + explicit KNewInvestmentWizard(QWidget *parent = nullptr); /** * Use this constructor for the modification of an existing investment */ - explicit KNewInvestmentWizard(const MyMoneyAccount& acc, QWidget *parent = 0); + explicit KNewInvestmentWizard(const MyMoneyAccount& acc, QWidget *parent = nullptr); /** * Use this constructor for the modification of an existing security */ - explicit KNewInvestmentWizard(const MyMoneySecurity& sec, QWidget *parent = 0); + explicit KNewInvestmentWizard(const MyMoneySecurity& sec, QWidget *parent = nullptr); ~KNewInvestmentWizard(); diff --git a/kmymoney/wizards/newinvestmentwizard/knewinvestmentwizard.cpp b/kmymoney/wizards/newinvestmentwizard/knewinvestmentwizard.cpp --- a/kmymoney/wizards/newinvestmentwizard/knewinvestmentwizard.cpp +++ b/kmymoney/wizards/newinvestmentwizard/knewinvestmentwizard.cpp @@ -41,8 +41,6 @@ #include "webpricequote.h" #include "kmymoneyutils.h" -namespace Ui { class KNewInvestmentWizard; } - class KNewInvestmentWizardPrivate { Q_DISABLE_COPY(KNewInvestmentWizardPrivate) diff --git a/kmymoney/wizards/newloanwizard/additionalfeeswizardpage.cpp b/kmymoney/wizards/newloanwizard/additionalfeeswizardpage.cpp --- a/kmymoney/wizards/newloanwizard/additionalfeeswizardpage.cpp +++ b/kmymoney/wizards/newloanwizard/additionalfeeswizardpage.cpp @@ -55,7 +55,7 @@ i18n("Enter additional fees"), i18n("Use this to add any additional fees other than principal and interest contained in your periodical payments.")); KGuiItem::assign(ui->m_additionalFeeButton, additionalFeeButtonItem); - connect(ui->m_additionalFeeButton, SIGNAL(clicked()), this, SLOT(slotAdditionalFees())); + connect(ui->m_additionalFeeButton, &QAbstractButton::clicked, this, &AdditionalFeesWizardPage::slotAdditionalFees); } AdditionalFeesWizardPage::~AdditionalFeesWizardPage() diff --git a/kmymoney/wizards/newloanwizard/assetaccountwizardpage.cpp b/kmymoney/wizards/newloanwizard/assetaccountwizardpage.cpp --- a/kmymoney/wizards/newloanwizard/assetaccountwizardpage.cpp +++ b/kmymoney/wizards/newloanwizard/assetaccountwizardpage.cpp @@ -50,8 +50,8 @@ registerField("paymentDate", ui->m_paymentDate, "date"); registerField("assetAccountEdit", ui->m_assetAccountEdit, "selectedItems"); - connect(ui->m_assetAccountEdit, SIGNAL(stateChanged()), this, SIGNAL(completeChanged())); - connect(ui->m_dontCreatePayoutCheckBox, SIGNAL(clicked()), this, SIGNAL(completeChanged())); + connect(ui->m_assetAccountEdit, &KMyMoneySelector::stateChanged, this, &QWizardPage::completeChanged); + connect(ui->m_dontCreatePayoutCheckBox, &QAbstractButton::clicked, this, &QWizardPage::completeChanged); // load button icons KGuiItem createAssetButtonItem(i18n("&Create..."), @@ -59,7 +59,7 @@ i18n("Create a new asset account"), i18n("Use this to create a new account to which the initial payment should be made")); KGuiItem::assign(ui->m_createNewAssetButton, createAssetButtonItem); - connect(ui->m_createNewAssetButton, SIGNAL(clicked()), kmymoney, SLOT(slotAccountNew())); + connect(ui->m_createNewAssetButton, &QAbstractButton::clicked, kmymoney, static_cast(&KMyMoneyApp::slotAccountNew)); ui->m_assetAccountEdit->removeButtons(); ui->m_dontCreatePayoutCheckBox->setChecked(false); diff --git a/kmymoney/wizards/newloanwizard/effectivedatewizardpage.cpp b/kmymoney/wizards/newloanwizard/effectivedatewizardpage.cpp --- a/kmymoney/wizards/newloanwizard/effectivedatewizardpage.cpp +++ b/kmymoney/wizards/newloanwizard/effectivedatewizardpage.cpp @@ -42,7 +42,7 @@ // Register the fields with the QWizard and connect the // appropriate signals to update the "Next" button correctly registerField("effectiveChangeDateEdit", ui->m_effectiveChangeDateEdit, "date", SIGNAL(dateChanged(QDate))); - connect(ui->m_effectiveChangeDateEdit, SIGNAL(dateChanged(QDate)), this, SIGNAL(completeChanged())); + connect(ui->m_effectiveChangeDateEdit, &KMyMoneyDateInput::dateChanged, this, &QWizardPage::completeChanged); } EffectiveDateWizardPage::~EffectiveDateWizardPage() diff --git a/kmymoney/wizards/newloanwizard/firstpaymentwizardpage.cpp b/kmymoney/wizards/newloanwizard/firstpaymentwizardpage.cpp --- a/kmymoney/wizards/newloanwizard/firstpaymentwizardpage.cpp +++ b/kmymoney/wizards/newloanwizard/firstpaymentwizardpage.cpp @@ -40,7 +40,7 @@ // Register the fields with the QWizard and connect the // appropriate signals to update the "Next" button correctly registerField("firstDueDateEdit", ui->m_firstDueDateEdit, "date"); - connect(ui->m_firstDueDateEdit, SIGNAL(dateChanged(QDate)), this, SIGNAL(completeChanged())); + connect(ui->m_firstDueDateEdit, &KMyMoneyDateInput::dateChanged, this, &QWizardPage::completeChanged); } FirstPaymentWizardPage::~FirstPaymentWizardPage() diff --git a/kmymoney/wizards/newloanwizard/interestcategorywizardpage.cpp b/kmymoney/wizards/newloanwizard/interestcategorywizardpage.cpp --- a/kmymoney/wizards/newloanwizard/interestcategorywizardpage.cpp +++ b/kmymoney/wizards/newloanwizard/interestcategorywizardpage.cpp @@ -51,7 +51,7 @@ // appropriate signals to update the "Next" button correctly registerField("interestAccountEdit", ui->m_interestAccountEdit, "selectedItems"); - connect(ui->m_interestAccountEdit, SIGNAL(stateChanged()), this, SIGNAL(completeChanged())); + connect(ui->m_interestAccountEdit, &KMyMoneySelector::stateChanged, this, &QWizardPage::completeChanged); ui->m_interestAccountEdit->removeButtons(); // load button icons @@ -60,7 +60,7 @@ i18n("Create a new category"), i18n("Use this to open the new account editor")); KGuiItem::assign(ui->m_createCategoryButton, createCategoryButtonItem); - connect(ui->m_createCategoryButton, SIGNAL(clicked()), this, SLOT(slotCreateCategory())); + connect(ui->m_createCategoryButton, &QAbstractButton::clicked, this, &InterestCategoryWizardPage::slotCreateCategory); } InterestCategoryWizardPage::~InterestCategoryWizardPage() diff --git a/kmymoney/wizards/newloanwizard/interesteditwizardpage.cpp b/kmymoney/wizards/newloanwizard/interesteditwizardpage.cpp --- a/kmymoney/wizards/newloanwizard/interesteditwizardpage.cpp +++ b/kmymoney/wizards/newloanwizard/interesteditwizardpage.cpp @@ -39,7 +39,7 @@ // Register the fields with the QWizard and connect the // appropriate signals to update the "Next" button correctly registerField("newInterestRateEdit", ui->m_newInterestRateEdit, "value", SIGNAL(textChanged(QString))); - connect(ui->m_newInterestRateEdit, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged())); + connect(ui->m_newInterestRateEdit, &KMyMoneyEdit::textChanged, this, &QWizardPage::completeChanged); } InterestEditWizardPage::~InterestEditWizardPage() diff --git a/kmymoney/wizards/newloanwizard/knewloanwizard.cpp b/kmymoney/wizards/newloanwizard/knewloanwizard.cpp --- a/kmymoney/wizards/newloanwizard/knewloanwizard.cpp +++ b/kmymoney/wizards/newloanwizard/knewloanwizard.cpp @@ -34,10 +34,7 @@ // ---------------------------------------------------------------------------- // Project Includes -#include "kmymoneydateinput.h" -#include "kmymoneyedit.h" #include "kmymoneyaccountselector.h" - #include "mymoneypayee.h" KNewLoanWizard::KNewLoanWizard(QWidget *parent) : diff --git a/kmymoney/wizards/newloanwizard/loanamountwizardpage.cpp b/kmymoney/wizards/newloanwizard/loanamountwizardpage.cpp --- a/kmymoney/wizards/newloanwizard/loanamountwizardpage.cpp +++ b/kmymoney/wizards/newloanwizard/loanamountwizardpage.cpp @@ -42,7 +42,7 @@ registerField("loanAmountEdit", ui->m_loanAmountEdit, "value", SIGNAL(textChanged())); registerField("loanAmountEditValid", ui->m_loanAmountEdit, "valid", SIGNAL(textChanged())); - connect(ui->m_loanAmountEdit, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged())); + connect(ui->m_loanAmountEdit, &KMyMoneyEdit::textChanged, this, &QWizardPage::completeChanged); registerField("loanAmount1", ui->m_loanAmount1, "text"); registerField("interestRate1", ui->m_interestRate1, "text"); diff --git a/kmymoney/wizards/newloanwizard/loanattributeswizardpage.cpp b/kmymoney/wizards/newloanwizard/loanattributeswizardpage.cpp --- a/kmymoney/wizards/newloanwizard/loanattributeswizardpage.cpp +++ b/kmymoney/wizards/newloanwizard/loanattributeswizardpage.cpp @@ -46,8 +46,8 @@ // Register the fields with the QWizard and connect the // appropriate signals to update the "Next" button correctly registerField("institution", ui->m_qcomboboxInstitutions); - connect(ui->m_qcomboboxInstitutions, SIGNAL(currentIndexChanged(int)), this, SIGNAL(completeChanged())); - connect(ui->m_qbuttonNew, SIGNAL(clicked()), this, SLOT(slotNewClicked())); + connect(ui->m_qcomboboxInstitutions, static_cast(&QComboBox::currentIndexChanged), this, &QWizardPage::completeChanged); + connect(ui->m_qbuttonNew, &QAbstractButton::clicked, this, &LoanAttributesWizardPage::slotNewClicked); ui->m_qcomboboxInstitutions->clear(); diff --git a/kmymoney/wizards/newloanwizard/namewizardpage.cpp b/kmymoney/wizards/newloanwizard/namewizardpage.cpp --- a/kmymoney/wizards/newloanwizard/namewizardpage.cpp +++ b/kmymoney/wizards/newloanwizard/namewizardpage.cpp @@ -40,7 +40,7 @@ // Register the fields with the QWizard and connect the // appropriate signals to update the "Next" button correctly registerField("payeeEdit", ui->m_payeeEdit, "selectedItem", SIGNAL(itemSelected(QString))); - connect(ui->m_nameEdit, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged())); + connect(ui->m_nameEdit, &QLineEdit::textChanged, this, &QWizardPage::completeChanged); } NameWizardPage::~NameWizardPage() diff --git a/kmymoney/wizards/newloanwizard/paymenteditwizardpage.cpp b/kmymoney/wizards/newloanwizard/paymenteditwizardpage.cpp --- a/kmymoney/wizards/newloanwizard/paymenteditwizardpage.cpp +++ b/kmymoney/wizards/newloanwizard/paymenteditwizardpage.cpp @@ -40,7 +40,7 @@ registerField("newPaymentEdit", ui->m_newPaymentEdit, "value", SIGNAL(textChanged())); registerField("newPaymentEditValid", ui->m_newPaymentEdit, "valid", SIGNAL(textChanged())); - connect(ui->m_newPaymentEdit, SIGNAL(textChanged(QString)), this, SIGNAL(completeChanged())); + connect(ui->m_newPaymentEdit, &KMyMoneyEdit::textChanged, this, &QWizardPage::completeChanged); } PaymentEditWizardPage::~PaymentEditWizardPage() diff --git a/kmymoney/wizards/newloanwizard/paymentfrequencywizardpage.cpp b/kmymoney/wizards/newloanwizard/paymentfrequencywizardpage.cpp --- a/kmymoney/wizards/newloanwizard/paymentfrequencywizardpage.cpp +++ b/kmymoney/wizards/newloanwizard/paymentfrequencywizardpage.cpp @@ -23,13 +23,12 @@ // ---------------------------------------------------------------------------- // KDE Includes - // ---------------------------------------------------------------------------- // Project Includes #include "ui_paymentfrequencywizardpage.h" -#include "mymoneyschedule.h" +#include "mymoneyenums.h" PaymentFrequencyWizardPage::PaymentFrequencyWizardPage(QWidget *parent) : QWizardPage(parent), diff --git a/kmymoney/wizards/newloanwizard/schedulewizardpage.cpp b/kmymoney/wizards/newloanwizard/schedulewizardpage.cpp --- a/kmymoney/wizards/newloanwizard/schedulewizardpage.cpp +++ b/kmymoney/wizards/newloanwizard/schedulewizardpage.cpp @@ -41,8 +41,8 @@ registerField("nextDueDateEdit", ui->m_nextDueDateEdit, "date", SIGNAL(dateChanged(QDate))); registerField("paymentAccountEdit", ui->m_paymentAccountEdit, "selectedItems"); - connect(ui->m_nextDueDateEdit, SIGNAL(dateChanged(QDate)), this, SIGNAL(completeChanged())); - connect(ui->m_paymentAccountEdit, SIGNAL(stateChanged()), this, SIGNAL(completeChanged())); + connect(ui->m_nextDueDateEdit, &KMyMoneyDateInput::dateChanged, this, &QWizardPage::completeChanged); + connect(ui->m_paymentAccountEdit, &KMyMoneySelector::stateChanged, this, &QWizardPage::completeChanged); ui->m_paymentAccountEdit->removeButtons(); } diff --git a/kmymoney/wizards/newuserwizard/CMakeLists.txt b/kmymoney/wizards/newuserwizard/CMakeLists.txt --- a/kmymoney/wizards/newuserwizard/CMakeLists.txt +++ b/kmymoney/wizards/newuserwizard/CMakeLists.txt @@ -2,12 +2,20 @@ set (libnewuserwizard_a_SOURCES knewuserwizard.cpp + kaccountpage.cpp + kcategoriespage.cpp + kcurrencypage.cpp + kfilepage.cpp + kgeneralpage.cpp + kintropage.cpp + kpreferencepage.cpp ) set (libnewuserwizard_a_UI - kaccountpagedecl.ui kcurrencypagedecl.ui kfilepagedecl.ui - kgeneralpagedecl.ui kintropagedecl.ui kpasswordpagedecl.ui - kpreferencepagedecl.ui + kaccountpage.ui kcurrencypage.ui + kfilepage.ui kgeneralpage.ui + kintropage.ui kpreferencepage.ui + kpasswordpage.ui ) # The handling of these ui files depends @@ -16,6 +24,6 @@ add_library(newuserwizard STATIC ${libnewuserwizard_a_SOURCES}) # TODO: clean dependencies -target_link_libraries(newuserwizard KF5::ConfigGui KF5::KIOWidgets KF5::TextWidgets KF5::Completion Qt5::Widgets Qt5::Sql Qt5::Xml Alkimia::alkimia) +target_link_libraries(newuserwizard kmymoneywizard KF5::ConfigGui KF5::KIOWidgets KF5::TextWidgets KF5::Completion KF5::ConfigWidgets Qt5::Widgets Qt5::Xml Alkimia::alkimia) add_dependencies(newuserwizard widgets wizardpages) diff --git a/kmymoney/wizards/newuserwizard/kaccountpage.h b/kmymoney/wizards/newuserwizard/kaccountpage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kaccountpage.h @@ -0,0 +1,61 @@ +/*************************************************************************** + kaccountpage.h + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWUSERWIZARDACCOUNTPAGE_H +#define KNEWUSERWIZARDACCOUNTPAGE_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" + +class KMyMoneyWizardPage; + +namespace NewUserWizard +{ + class Wizard; + + /** + * Wizard page collecting information about the checking account + */ + class AccountPagePrivate; + class AccountPage : public QWidget, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(AccountPage) + + public: + explicit AccountPage(Wizard* parent); + ~AccountPage() override; + + KMyMoneyWizardPage* nextPage(void) const override; + + bool isComplete(void) const override; + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, AccountPage) + friend class Wizard; + friend class CurrencyPage; + }; +} // namespace + +#endif diff --git a/kmymoney/wizards/newuserwizard/kaccountpage.cpp b/kmymoney/wizards/newuserwizard/kaccountpage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kaccountpage.cpp @@ -0,0 +1,75 @@ +/*************************************************************************** + kaccountpage.cpp + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kaccountpage.h" +#include "kaccountpage_p.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kaccountpage.h" + +#include "kmymoneydateinput.h" +#include "knewuserwizard.h" +#include "knewuserwizard_p.h" +#include "kcategoriespage.h" +#include "wizardpage.h" + +namespace NewUserWizard +{ + AccountPage::AccountPage(Wizard* wizard) : + QWidget(wizard), + WizardPage(*new AccountPagePrivate(wizard), stepCount, this, wizard) // don't inc. the step count here + { + Q_D(AccountPage); + d->ui->setupUi(this); + d->m_mandatoryGroup->add(d->ui->m_accountNameEdit); + connect(d->m_mandatoryGroup, static_cast(&KMandatoryFieldGroup::stateChanged), object(), &KMyMoneyWizardPagePrivate::completeStateChanged); + connect(d->ui->m_haveCheckingAccountButton, &QAbstractButton::toggled, object(), &KMyMoneyWizardPagePrivate::completeStateChanged); + d->ui->m_accountNameEdit->setFocus(); + d->ui->m_openingDateEdit->setDate(QDate(QDate::currentDate().year(), 1, 1)); + } + + AccountPage::~AccountPage() + { + } + + KMyMoneyWizardPage* AccountPage::nextPage() const + { + Q_D(const AccountPage); + return d->m_wizard->d_func()->m_categoriesPage; + } + + bool AccountPage::isComplete() const + { + Q_D(const AccountPage); + return !d->ui->m_haveCheckingAccountButton->isChecked() || d->m_mandatoryGroup->isEnabled(); + } + +} diff --git a/kmymoney/wizards/newuserwizard/kaccountpagedecl.ui b/kmymoney/wizards/newuserwizard/kaccountpage.ui rename from kmymoney/wizards/newuserwizard/kaccountpagedecl.ui rename to kmymoney/wizards/newuserwizard/kaccountpage.ui --- a/kmymoney/wizards/newuserwizard/kaccountpagedecl.ui +++ b/kmymoney/wizards/newuserwizard/kaccountpage.ui @@ -3,8 +3,8 @@ - KAccountPageDecl - + KAccountPage + 0 diff --git a/kmymoney/wizards/newuserwizard/kaccountpage_p.h b/kmymoney/wizards/newuserwizard/kaccountpage_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kaccountpage_p.h @@ -0,0 +1,57 @@ +/*************************************************************************** + kaccountpage_p.h + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWUSERWIZARDACCOUNTPAGE_P_H +#define KNEWUSERWIZARDACCOUNTPAGE_P_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kaccountpage.h" +#include "wizardpage.h" + +namespace NewUserWizard +{ + class Wizard; + + class AccountPagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(AccountPagePrivate) + + public: + AccountPagePrivate(QObject* parent) : + WizardPagePrivate(parent), + ui(new Ui::KAccountPage) + { + } + + ~AccountPagePrivate() + { + delete ui; + } + + Ui::KAccountPage *ui; + }; +} +#endif diff --git a/kmymoney/wizards/newuserwizard/kcategoriespage.h b/kmymoney/wizards/newuserwizard/kcategoriespage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kcategoriespage.h @@ -0,0 +1,62 @@ +/*************************************************************************** + kcategoriespage.h + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWUSERWIZARDCATEGORIESPAGE_H +#define KNEWUSERWIZARDCATEGORIESPAGE_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" +#include "accounts.h" + +class KMyMoneyWizardPage; +class MyMoneyTemplate; + +template class QList; + +namespace NewUserWizard +{ + class Wizard; + /** + * Wizard page collecting information about the account templates. + * + * @author Thomas Baumgart + */ + class CategoriesPagePrivate; + class CategoriesPage : public Accounts, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(CategoriesPage) + + public: + explicit CategoriesPage(Wizard* parent); + ~CategoriesPage() override; + + KMyMoneyWizardPage* nextPage(void) const override; + QList selectedTemplates(void) const; + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, CategoriesPage) + friend class Wizard; + }; +} // namespace + +#endif diff --git a/kmymoney/wizards/newuserwizard/kcategoriespage.cpp b/kmymoney/wizards/newuserwizard/kcategoriespage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kcategoriespage.cpp @@ -0,0 +1,75 @@ +/*************************************************************************** + kcategoriespage.cpp + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kcategoriespage.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_accounts.h" + +#include "kaccounttemplateselector.h" +#include "knewuserwizard.h" +#include "knewuserwizard_p.h" +#include "kpreferencepage.h" +#include "mymoneytemplate.h" + +namespace NewUserWizard +{ + class CategoriesPagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(CategoriesPagePrivate) + + public: + CategoriesPagePrivate(QObject* parent) : + WizardPagePrivate(parent) + { + } + }; + + CategoriesPage::CategoriesPage(Wizard* wizard) : + Accounts(wizard), + WizardPage(*new CategoriesPagePrivate(wizard), stepCount++, this, wizard) + { + } + + CategoriesPage::~CategoriesPage() + { + } + + KMyMoneyWizardPage* CategoriesPage::nextPage() const + { + Q_D(const CategoriesPage); + return d->m_wizard->d_func()->m_preferencePage; + } + + QList CategoriesPage::selectedTemplates() const + { + Q_D(const CategoriesPage); + return ui->m_templateSelector->selectedTemplates(); + } + +} diff --git a/kmymoney/wizards/newuserwizard/kcurrencypage.h b/kmymoney/wizards/newuserwizard/kcurrencypage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kcurrencypage.h @@ -0,0 +1,59 @@ +/*************************************************************************** + kcurrencypage.h + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWUSERWIZARDCURRENCYPAGE_H +#define KNEWUSERWIZARDCURRENCYPAGE_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" +#include "currency.h" + +class KMyMoneyWizardPage; + +namespace NewUserWizard +{ + class Wizard; + /** + * Wizard page collecting information about the base currency + * + * @author Thomas Baumgart + */ + class CurrencyPagePrivate; + class CurrencyPage : public Currency, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(CurrencyPage) + + public: + explicit CurrencyPage(Wizard* parent); + ~CurrencyPage() override; + + void enterPage(void); + KMyMoneyWizardPage* nextPage(void) const override; + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, CurrencyPage) + friend class Wizard; + }; +} // namespace + +#endif diff --git a/kmymoney/wizards/newuserwizard/kcurrencypage.cpp b/kmymoney/wizards/newuserwizard/kcurrencypage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kcurrencypage.cpp @@ -0,0 +1,126 @@ +/*************************************************************************** + kcurrencypage.cpp + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kcurrencypage.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "icons/icons.h" +#include "knewuserwizard.h" +#include "knewuserwizard_p.h" +#include "kaccountpage.h" +#include "kaccountpage_p.h" +#include "mymoneyfile.h" +#include "mymoneysecurity.h" +#include "ui_currency.h" +#include "ui_kaccountpage.h" +#include "wizardpage.h" + +using namespace Icons; + +namespace NewUserWizard +{ + class CurrencyPagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(CurrencyPagePrivate) + + public: + CurrencyPagePrivate(QObject* parent) : + WizardPagePrivate(parent) + { + } + }; + + CurrencyPage::CurrencyPage(Wizard* wizard) : + Currency(wizard), + WizardPage(*new CurrencyPagePrivate(wizard), stepCount++, this, wizard) + { + Q_D(CurrencyPage); + QTreeWidgetItem *first = 0; + + QList list = MyMoneyFile::instance()->availableCurrencyList(); + QList::const_iterator it; + + QString localCurrency(QLocale().currencySymbol(QLocale::CurrencyIsoCode)); + QString baseCurrency = MyMoneyFile::instance()->baseCurrency().id(); + + + ui->m_currencyList->clear(); + for (it = list.constBegin(); it != list.constEnd(); ++it) { + QTreeWidgetItem* p = insertCurrency(*it); + if ((*it).id() == baseCurrency) { + first = p; + QIcon icon = QIcon::fromTheme(g_Icons[Icon::ViewBankAccount]); + p->setIcon(0, icon); + } else { + p->setIcon(0, QIcon()); + } + if (!first && (*it).id() == localCurrency) + first = p; + } + + QTreeWidgetItemIterator itemsIt = QTreeWidgetItemIterator(ui->m_currencyList, QTreeWidgetItemIterator::All); + + if (first == 0) + first = *itemsIt; + if (first != 0) { + ui->m_currencyList->setCurrentItem(first); + ui->m_currencyList->setItemSelected(first, true); + ui->m_currencyList->scrollToItem(first, QTreeView::PositionAtTop); + } + } + + CurrencyPage::~CurrencyPage() + { + } + + void CurrencyPage::enterPage() + { + Q_D(CurrencyPage); + ui->m_currencyList->setFocus(); + } + + KMyMoneyWizardPage* CurrencyPage::nextPage() const + { + Q_D(const CurrencyPage); + QString selCur = selectedCurrency(); + QList currencies = MyMoneyFile::instance()->availableCurrencyList(); + foreach (auto currency, currencies) { + if (selCur == currency.id()) { + d->m_wizard->d_func()->m_baseCurrency = currency; + break; + } + } + d->m_wizard->d_func()->m_accountPage->d_func()->ui->m_accountCurrencyLabel->setText(d->m_wizard->d_func()->m_baseCurrency.tradingSymbol()); + return d->m_wizard->d_func()->m_accountPage; + } + +} diff --git a/kmymoney/wizards/newuserwizard/kcurrencypagedecl.ui b/kmymoney/wizards/newuserwizard/kcurrencypage.ui rename from kmymoney/wizards/newuserwizard/kcurrencypagedecl.ui rename to kmymoney/wizards/newuserwizard/kcurrencypage.ui --- a/kmymoney/wizards/newuserwizard/kcurrencypagedecl.ui +++ b/kmymoney/wizards/newuserwizard/kcurrencypage.ui @@ -3,8 +3,8 @@ - KCurrencyPageDecl - + KCurrencyPage + 0 diff --git a/kmymoney/wizards/newuserwizard/kfilepage.h b/kmymoney/wizards/newuserwizard/kfilepage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kfilepage.h @@ -0,0 +1,58 @@ +/*************************************************************************** + kfilepage.h + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWUSERWIZARDFILEPAGE_H +#define KNEWUSERWIZARDFILEPAGE_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" + +namespace NewUserWizard +{ + class Wizard; + /** + * Wizard page to allow selecting the filename + * + * @author Thomas Baumgart + */ + class FilePagePrivate; + class FilePage : public QWidget, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(FilePage) + + public: + explicit FilePage(Wizard* parent); + ~FilePage() override; + + bool isComplete(void) const override; + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, FilePage) + friend class Wizard; + }; + +} // namespace + +#endif diff --git a/kmymoney/wizards/newuserwizard/kfilepage.cpp b/kmymoney/wizards/newuserwizard/kfilepage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kfilepage.cpp @@ -0,0 +1,104 @@ +/*************************************************************************** + kfilepage.cpp + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kfilepage.h" +#include "kfilepage_p.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kfilepage.h" +#include "knewuserwizard.h" + +namespace NewUserWizard +{ + FilePage::FilePage(Wizard* wizard) : + QWidget(wizard), + WizardPage(*new FilePagePrivate(wizard), stepCount++, this, wizard) + { + Q_D(FilePage); + d->ui->setupUi(this); + d->m_mandatoryGroup->add(d->ui->m_dataFileEdit->lineEdit()); + connect(d->m_mandatoryGroup, static_cast(&KMandatoryFieldGroup::stateChanged), object(), &KMyMoneyWizardPagePrivate::completeStateChanged); + + KUser user; + QString folder = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); + if (folder.isEmpty() || !QDir().exists(folder)) + folder = QDir::homePath(); + d->ui->m_dataFileEdit->setStartDir(QUrl::fromLocalFile(folder)); + d->ui->m_dataFileEdit->setUrl(QUrl::fromLocalFile(folder + QLatin1Char('/') + user.loginName() + QLatin1String(".kmy"))); + d->ui->m_dataFileEdit->setFilter(i18n("*.kmy *.xml|KMyMoney files\n*|All files")); + d->ui->m_dataFileEdit->setMode(KFile::File); + } + + FilePage::~FilePage() + { + } + + bool FilePage::isComplete() const + { + Q_D(const FilePage); + //! @todo Allow to overwrite files + bool rc = d->m_mandatoryGroup->isEnabled(); + d->ui->m_existingFileLabel->hide(); + d->ui->m_finishLabel->show(); + if (rc) { + // if a filename is present, check that + // a) the file does not exist + // b) the directory does exist + // c) the file is stored locally (because we cannot check previous conditions if it is not) + const QUrl fullPath = d->ui->m_dataFileEdit->url(); + QFileInfo directory{fullPath.adjusted(QUrl::RemoveFilename).toLocalFile()}; + qDebug() << "Selected fileptah: " << fullPath << " " << directory.absoluteFilePath() << " dir: " << directory.isDir(); + rc = false; + if (!fullPath.isValid() || !fullPath.isLocalFile()) { + d->ui->m_dataFileEdit->setToolTip(i18n("The path has to be valid and cannot be on a remote location.")); + } else if (QFileInfo::exists(fullPath.toLocalFile())) { + d->ui->m_dataFileEdit->setToolTip(i18n("The file exists already. Please create a new file.")); + } else if (!directory.isDir()) { + d->ui->m_dataFileEdit->setToolTip(i18n("The destination directory does not exist or cannot be written to.")); + } else { + d->ui->m_dataFileEdit->setToolTip(""); + rc = true; + } + + d->ui->m_existingFileLabel->setHidden(rc); + d->ui->m_finishLabel->setVisible(rc); + } + return rc; + } + +} diff --git a/kmymoney/wizards/newuserwizard/kfilepagedecl.ui b/kmymoney/wizards/newuserwizard/kfilepage.ui rename from kmymoney/wizards/newuserwizard/kfilepagedecl.ui rename to kmymoney/wizards/newuserwizard/kfilepage.ui --- a/kmymoney/wizards/newuserwizard/kfilepagedecl.ui +++ b/kmymoney/wizards/newuserwizard/kfilepage.ui @@ -1,7 +1,7 @@ - KFilePageDecl - + KFilePage + 0 diff --git a/kmymoney/wizards/newuserwizard/kfilepage_p.h b/kmymoney/wizards/newuserwizard/kfilepage_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kfilepage_p.h @@ -0,0 +1,57 @@ +/*************************************************************************** + kfilepage_p.h + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWUSERWIZARDFILEPAGE_P_H +#define KNEWUSERWIZARDFILEPAGE_P_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kfilepage.h" +#include "wizardpage.h" + +namespace NewUserWizard +{ + class Wizard; + + class FilePagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(FilePagePrivate) + + public: + FilePagePrivate(QObject* parent) : + WizardPagePrivate(parent), + ui(new Ui::KFilePage) + { + } + + ~FilePagePrivate() + { + delete ui; + } + + Ui::KFilePage *ui; + }; +} +#endif diff --git a/kmymoney/wizards/newuserwizard/kgeneralpage.h b/kmymoney/wizards/newuserwizard/kgeneralpage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kgeneralpage.h @@ -0,0 +1,63 @@ +/*************************************************************************** + kgeneralpage.h + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWUSERWIZARDGENERALPAGE_H +#define KNEWUSERWIZARDGENERALPAGE_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" +#include "userinfo.h" + +class KMyMoneyWizardPage; +class ContactData; + +namespace NewUserWizard +{ + class Wizard; + /** + * Wizard page collecting information about the user + * + * @author Thomas Baumgart + */ + class GeneralPagePrivate; + class GeneralPage : public UserInfo, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(GeneralPage) + + public: + explicit GeneralPage(Wizard* parent); + ~GeneralPage() override; + + KMyMoneyWizardPage* nextPage(void) const override; + + protected slots: + void slotLoadFromAddressBook(void); + void slotContactFetched(const ContactData &identity); + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, GeneralPage) + friend class Wizard; + }; +} // namespace + +#endif diff --git a/kmymoney/wizards/newuserwizard/kgeneralpage.cpp b/kmymoney/wizards/newuserwizard/kgeneralpage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kgeneralpage.cpp @@ -0,0 +1,114 @@ +/*************************************************************************** + kgeneralpage.cpp + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kgeneralpage.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include +#include +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "userinfo.h" +#include "ui_userinfo.h" + +#include "knewuserwizard.h" +#include "knewuserwizard_p.h" + +#include "mymoneycontact.h" +#include "kcurrencypage.h" + +class KMyMoneyWizardPage; + +namespace NewUserWizard +{ + class GeneralPagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(GeneralPagePrivate) + + public: + GeneralPagePrivate(QObject* parent) : + WizardPagePrivate(parent) + { + } + + MyMoneyContact *m_contact; + }; + + GeneralPage::GeneralPage(Wizard* wizard) : + UserInfo(wizard), + WizardPage(*new GeneralPagePrivate(wizard), stepCount++, this, wizard) + { + Q_D(GeneralPage); + d->m_contact = new MyMoneyContact(this); + ui->m_userNameEdit->setFocus(); + + ui->m_loadAddressButton->setEnabled(d->m_contact->ownerExists()); + connect(ui->m_loadAddressButton, &QAbstractButton::clicked, this, &GeneralPage::slotLoadFromAddressBook); + } + + GeneralPage::~GeneralPage() + { + } + + void GeneralPage::slotLoadFromAddressBook() + { + Q_D(GeneralPage); + ui->m_userNameEdit->setText(d->m_contact->ownerFullName()); + ui->m_emailEdit->setText(d->m_contact->ownerEmail()); + if (ui->m_emailEdit->text().isEmpty()) { + KMessageBox::sorry(this, i18n("Unable to load data, because no contact has been associated with the owner of the standard address book."), i18n("Address book import")); + return; + } + ui->m_loadAddressButton->setEnabled(false); + connect(d->m_contact, &MyMoneyContact::contactFetched, this, &GeneralPage::slotContactFetched); + d->m_contact->fetchContact(ui->m_emailEdit->text()); + } + + void GeneralPage::slotContactFetched(const ContactData &identity) + { + Q_D(GeneralPage); + ui->m_loadAddressButton->setEnabled(true); + if (identity.email.isEmpty()) + return; + ui->m_telephoneEdit->setText(identity.phoneNumber); + QString sep; + if (!identity.country.isEmpty() && !identity.region.isEmpty()) + sep = " / "; + ui->m_countyEdit->setText(QString("%1%2%3").arg(identity.country, sep, identity.region)); + ui->m_postcodeEdit->setText(identity.postalCode); + ui->m_townEdit->setText(identity.locality); + ui->m_streetEdit->setText(identity.street); + } + + KMyMoneyWizardPage* GeneralPage::nextPage() const + { + Q_D(const GeneralPage); + return d->m_wizard->d_func()->m_currencyPage; + } + +} diff --git a/kmymoney/wizards/newuserwizard/kgeneralpagedecl.ui b/kmymoney/wizards/newuserwizard/kgeneralpage.ui rename from kmymoney/wizards/newuserwizard/kgeneralpagedecl.ui rename to kmymoney/wizards/newuserwizard/kgeneralpage.ui --- a/kmymoney/wizards/newuserwizard/kgeneralpagedecl.ui +++ b/kmymoney/wizards/newuserwizard/kgeneralpage.ui @@ -3,8 +3,8 @@ - KGeneralPageDecl - + KGeneralPage + 0 diff --git a/kmymoney/wizards/newuserwizard/kintropage.h b/kmymoney/wizards/newuserwizard/kintropage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kintropage.h @@ -0,0 +1,55 @@ +/*************************************************************************** + kintropage.h + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWUSERWIZARDINTROPAGE_H +#define KNEWUSERWIZARDINTROPAGE_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" + +class KMyMoneyWizardPage; + +namespace NewUserWizard +{ + class Wizard; + + class IntroPagePrivate; + class IntroPage : public QWidget, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(IntroPage) + + public: + explicit IntroPage(Wizard* parent); + ~IntroPage() override; + + KMyMoneyWizardPage* nextPage(void) const override; + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, IntroPage) + friend class Wizard; + }; +} // namespace + +#endif diff --git a/kmymoney/wizards/newuserwizard/kintropage.cpp b/kmymoney/wizards/newuserwizard/kintropage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kintropage.cpp @@ -0,0 +1,77 @@ +/*************************************************************************** + kintropage.cpp + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kintropage.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kintropage.h" + +#include "knewuserwizard.h" +#include "knewuserwizard_p.h" +#include "kgeneralpage.h" + +class KMyMoneyWizardPage; + +namespace NewUserWizard +{ + class IntroPagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(IntroPagePrivate) + + public: + IntroPagePrivate(QObject* parent) : + WizardPagePrivate(parent), + ui(new Ui::KIntroPage) + { + } + + ~IntroPagePrivate() + { + delete ui; + } + + Ui::KIntroPage *ui; + }; + + IntroPage::IntroPage(Wizard* wizard) : + QWidget(wizard), + WizardPage(*new IntroPagePrivate(wizard), stepCount++, this, wizard) + { + Q_D(IntroPage); + d->ui->setupUi(this); + } + + IntroPage::~IntroPage() + { + } + + KMyMoneyWizardPage* IntroPage::nextPage() const + { + Q_D(const IntroPage); + return d->m_wizard->d_func()->m_generalPage; + } + +} diff --git a/kmymoney/wizards/newuserwizard/kintropagedecl.ui b/kmymoney/wizards/newuserwizard/kintropage.ui rename from kmymoney/wizards/newuserwizard/kintropagedecl.ui rename to kmymoney/wizards/newuserwizard/kintropage.ui --- a/kmymoney/wizards/newuserwizard/kintropagedecl.ui +++ b/kmymoney/wizards/newuserwizard/kintropage.ui @@ -3,8 +3,8 @@ - KIntroPageDecl - + KIntroPage + 0 diff --git a/kmymoney/wizards/newuserwizard/knewuserwizard.h b/kmymoney/wizards/newuserwizard/knewuserwizard.h --- a/kmymoney/wizards/newuserwizard/knewuserwizard.h +++ b/kmymoney/wizards/newuserwizard/knewuserwizard.h @@ -4,6 +4,7 @@ begin : Sat Feb 18 2006 copyright : (C) 2006 Thomas Baumgart email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz ***************************************************************************/ /*************************************************************************** @@ -40,89 +41,79 @@ */ namespace NewUserWizard { + extern int stepCount; -class IntroPage; -class GeneralPage; -class CurrencyPage; -class AccountPage; -class CategoriesPage; -class PreferencePage; -class FilePage; - -/** + /** * @author Thomas Baumgart * * This class implements the new user wizard which is used to gather * some initial information from the user who creates a new KMyMoney * 'file'. */ -class Wizard : public KMyMoneyWizard -{ - friend class IntroPage; - friend class GeneralPage; - friend class CurrencyPage; - friend class AccountPage; - friend class CategoriesPage; - friend class PreferencePage; - friend class FilePage; - - Q_OBJECT -public: - explicit Wizard(QWidget* parent = 0, bool modal = false, Qt::WindowFlags flags = 0); - /** + class WizardPrivate; + class Wizard : public KMyMoneyWizard + { + friend class IntroPage; + friend class GeneralPage; + friend class CurrencyPage; + friend class AccountPage; + friend class CategoriesPage; + friend class PreferencePage; + friend class FilePage; + + Q_OBJECT + Q_DISABLE_COPY(Wizard) + + public: + explicit Wizard(QWidget *parent = nullptr, bool modal = false, Qt::WindowFlags flags = 0); + ~Wizard() override; + /** * Returns the personal information of the user (e.g. name, address, etc.) */ - MyMoneyPayee user() const; + MyMoneyPayee user() const; - /** + /** * Returns the URL that the user has chosen to store the file */ - QUrl url() const; + QUrl url() const; - /** + /** * Returns the information about an institution if entered by * the user. If the name field is empty, then he did not enter * such information. */ - MyMoneyInstitution institution() const; + MyMoneyInstitution institution() const; - /** + /** * Returns the information about a checking account if entered by * the user. If the name field is empty, then he did not enter * such information. */ - MyMoneyAccount account() const; + MyMoneyAccount account() const; - /** + /** * Returns the opening balance value provided by the user. not enter */ - MyMoneyMoney openingBalance() const; + MyMoneyMoney openingBalance() const; - /** + /** * Returns the security to be used as base currency. */ - MyMoneySecurity baseCurrency() const; + MyMoneySecurity baseCurrency() const; - /** + /** * Returns a list of templates including accounts to be created */ - QList templates() const; + QList templates() const; - /** + /** * True if the settings dialog should be launched after the wizard is finished. */ - bool startSettingsAfterFinished() const; - -private: - MyMoneySecurity m_baseCurrency; - IntroPage* m_introPage; - GeneralPage* m_generalPage; - CurrencyPage* m_currencyPage; - AccountPage* m_accountPage; - CategoriesPage* m_categoriesPage; - PreferencePage* m_preferencePage; - FilePage* m_filePage; -}; + bool startSettingsAfterFinished() const; + + private: + Q_DECLARE_PRIVATE(Wizard) + }; } // namespace diff --git a/kmymoney/wizards/newuserwizard/knewuserwizard.cpp b/kmymoney/wizards/newuserwizard/knewuserwizard.cpp --- a/kmymoney/wizards/newuserwizard/knewuserwizard.cpp +++ b/kmymoney/wizards/newuserwizard/knewuserwizard.cpp @@ -4,6 +4,7 @@ begin : Sat Feb 18 2006 copyright : (C) 2006 Thomas Baumgart email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz ***************************************************************************/ /*************************************************************************** @@ -21,342 +22,144 @@ // ---------------------------------------------------------------------------- // QT Includes -#include #include -#include -#include -#include #include -#include // ---------------------------------------------------------------------------- // KDE Includes #include -#include -#include // ---------------------------------------------------------------------------- // Project Includes +#include "kaccountpage.h" +#include "kaccountpage_p.h" +#include "kcategoriespage.h" +#include "kcurrencypage.h" +#include "kfilepage.h" +#include "kfilepage_p.h" +#include "kgeneralpage.h" +#include "kintropage.h" +#include "kpreferencepage.h" +#include "kpreferencepage_p.h" + #include "mymoneysecurity.h" -#include "mymoneyfile.h" -#include #include "mymoneypayee.h" #include "mymoneymoney.h" #include "mymoneyinstitution.h" #include "mymoneyaccount.h" #include "kmymoneydateinput.h" #include "kmymoneyedit.h" -#include #include "kmymoneyglobalsettings.h" -#include "icons/icons.h" - -using namespace Icons; +#include "mymoneytemplate.h" +#include "wizardpage.h" namespace NewUserWizard { - -static int stepCount; - -Wizard::Wizard(QWidget *parent, bool modal, Qt::WindowFlags flags) : - KMyMoneyWizard(parent, modal, flags), - m_introPage(0) -{ - bool isFirstTime = KMyMoneyGlobalSettings::firstTimeRun(); - - stepCount = 1; - - setTitle(i18n("KMyMoney New File Setup")); - if (isFirstTime) - addStep(i18nc("New file wizard introduction", "Introduction")); - addStep(i18n("Personal Data")); - addStep(i18n("Select Currency")); - addStep(i18n("Select Accounts")); - addStep(i18n("Set preferences")); - addStep(i18nc("Finish the wizard", "Finish")); - - if (isFirstTime) - m_introPage = new IntroPage(this); - m_generalPage = new GeneralPage(this); - m_currencyPage = new CurrencyPage(this); - m_accountPage = new AccountPage(this); - m_categoriesPage = new CategoriesPage(this); - m_preferencePage = new PreferencePage(this); - m_filePage = new FilePage(this); - - m_accountPage->m_haveCheckingAccountButton->setChecked(true); - if (isFirstTime) - setFirstPage(m_introPage); - else - setFirstPage(m_generalPage); - - setHelpContext("firsttime-3"); -} - -MyMoneyPayee Wizard::user() const -{ - return m_generalPage->user(); -} - -QUrl Wizard::url() const -{ - return m_filePage->m_dataFileEdit->url(); -} - -MyMoneyInstitution Wizard::institution() const -{ - MyMoneyInstitution inst; - if (m_accountPage->m_haveCheckingAccountButton->isChecked()) { - if (m_accountPage->m_institutionNameEdit->text().length()) { - inst.setName(m_accountPage->m_institutionNameEdit->text()); - if (m_accountPage->m_institutionNumberEdit->text().length()) - inst.setSortcode(m_accountPage->m_institutionNumberEdit->text()); - } + int stepCount = 0; + + Wizard::Wizard(QWidget *parent, bool modal, Qt::WindowFlags flags) : + KMyMoneyWizard(*new WizardPrivate(this), parent, modal, flags) + { + Q_D(Wizard); + bool isFirstTime = KMyMoneyGlobalSettings::firstTimeRun(); + + stepCount = 1; + + setTitle(i18n("KMyMoney New File Setup")); + if (isFirstTime) + addStep(i18nc("New file wizard introduction", "Introduction")); + addStep(i18n("Personal Data")); + addStep(i18n("Select Currency")); + addStep(i18n("Select Accounts")); + addStep(i18n("Set preferences")); + addStep(i18nc("Finish the wizard", "Finish")); + + if (isFirstTime) + d->m_introPage = new IntroPage(this); + d->m_generalPage = new GeneralPage(this); + d->m_currencyPage = new CurrencyPage(this); + d->m_accountPage = new AccountPage(this); + d->m_categoriesPage = new CategoriesPage(this); + d->m_preferencePage = new PreferencePage(this); + d->m_filePage = new FilePage(this); + + d->m_accountPage->d_func()->ui->m_haveCheckingAccountButton->setChecked(true); + if (isFirstTime) + d->setFirstPage(d->m_introPage); + else + d->setFirstPage(d->m_generalPage); + + setHelpContext("firsttime-3"); } - return inst; -} -MyMoneyAccount Wizard::account() const -{ - MyMoneyAccount acc; - if (m_accountPage->m_haveCheckingAccountButton->isChecked()) { - acc.setName(m_accountPage->m_accountNameEdit->text()); - if (m_accountPage->m_accountNumberEdit->text().length()) - acc.setNumber(m_accountPage->m_accountNumberEdit->text()); - acc.setOpeningDate(m_accountPage->m_openingDateEdit->date()); - acc.setCurrencyId(m_baseCurrency.id()); - acc.setAccountType(eMyMoney::Account::Checkings); + Wizard::~Wizard() + { } - return acc; -} - -MyMoneyMoney Wizard::openingBalance() const -{ - return m_accountPage->m_openingBalanceEdit->value(); -} - -MyMoneySecurity Wizard::baseCurrency() const -{ - return m_baseCurrency; -} - -QList Wizard::templates() const -{ - return m_categoriesPage->selectedTemplates(); -} - -bool Wizard::startSettingsAfterFinished() const -{ - return m_preferencePage->m_openConfigAfterFinished->checkState() == Qt::Checked; -} - -IntroPage::IntroPage(Wizard* wizard) : - KIntroPageDecl(wizard), - WizardPage(stepCount++, this, wizard) -{ -} -KMyMoneyWizardPage* IntroPage::nextPage() const -{ - return m_wizard->m_generalPage; -} - -GeneralPage::GeneralPage(Wizard* wizard) : - UserInfo(wizard), - WizardPage(stepCount++, this, wizard), - m_contact(new MyMoneyContact(this)) -{ - m_userNameEdit->setFocus(); - - m_loadAddressButton->setEnabled(m_contact->ownerExists()); - connect(m_loadAddressButton, SIGNAL(clicked()), this, SLOT(slotLoadFromAddressBook())); -} - -void GeneralPage::slotLoadFromAddressBook() -{ - m_userNameEdit->setText(m_contact->ownerFullName()); - m_emailEdit->setText(m_contact->ownerEmail()); - if (m_emailEdit->text().isEmpty()) { - KMessageBox::sorry(this, i18n("Unable to load data, because no contact has been associated with the owner of the standard address book."), i18n("Address book import")); - return; + MyMoneyPayee Wizard::user() const + { + Q_D(const Wizard); + return d->m_generalPage->user(); } - m_loadAddressButton->setEnabled(false); - connect(m_contact, SIGNAL(contactFetched(ContactData)), this, SLOT(slotContactFetched(ContactData))); - m_contact->fetchContact(m_emailEdit->text()); -} - -void GeneralPage::slotContactFetched(const ContactData &identity) -{ - m_loadAddressButton->setEnabled(true); - if (identity.email.isEmpty()) - return; - m_telephoneEdit->setText(identity.phoneNumber); - QString sep; - if (!identity.country.isEmpty() && !identity.region.isEmpty()) - sep = " / "; - m_countyEdit->setText(QString("%1%2%3").arg(identity.country, sep, identity.region)); - m_postcodeEdit->setText(identity.postalCode); - m_townEdit->setText(identity.locality); - m_streetEdit->setText(identity.street); -} -KMyMoneyWizardPage* GeneralPage::nextPage() const -{ - return m_wizard->m_currencyPage; -} - -CurrencyPage::CurrencyPage(Wizard* wizard) : - Currency(wizard), - WizardPage(stepCount++, this, wizard) -{ - QTreeWidgetItem *first = 0; - - QList list = MyMoneyFile::instance()->availableCurrencyList(); - QList::const_iterator it; - - QString localCurrency(QLocale().currencySymbol(QLocale::CurrencyIsoCode)); - QString baseCurrency = MyMoneyFile::instance()->baseCurrency().id(); - - - m_currencyList->clear(); - for (it = list.constBegin(); it != list.constEnd(); ++it) { - QTreeWidgetItem* p = insertCurrency(*it); - if ((*it).id() == baseCurrency) { - first = p; - QIcon icon = QIcon::fromTheme(g_Icons[Icon::ViewBankAccount]); - p->setIcon(0, icon); - } else { - p->setIcon(0, QIcon()); - } - if (!first && (*it).id() == localCurrency) - first = p; + QUrl Wizard::url() const + { + Q_D(const Wizard); + return d->m_filePage->d_func()->ui->m_dataFileEdit->url(); } - QTreeWidgetItemIterator itemsIt = QTreeWidgetItemIterator(m_currencyList, QTreeWidgetItemIterator::All); - - if (first == 0) - first = *itemsIt; - if (first != 0) { - m_currencyList->setCurrentItem(first); - m_currencyList->setItemSelected(first, true); - m_currencyList->scrollToItem(first, QTreeView::PositionAtTop); + MyMoneyInstitution Wizard::institution() const + { + Q_D(const Wizard); + MyMoneyInstitution inst; + if (d->m_accountPage->d_func()->ui->m_haveCheckingAccountButton->isChecked()) { + if (d->m_accountPage->d_func()->ui->m_institutionNameEdit->text().length()) { + inst.setName(d->m_accountPage->d_func()->ui->m_institutionNameEdit->text()); + if (d->m_accountPage->d_func()->ui->m_institutionNumberEdit->text().length()) + inst.setSortcode(d->m_accountPage->d_func()->ui->m_institutionNumberEdit->text()); + } + } + return inst; } -} -void CurrencyPage::enterPage() -{ - m_currencyList->setFocus(); -} - -KMyMoneyWizardPage* CurrencyPage::nextPage() const -{ - QString selCur = selectedCurrency(); - QList currencies = MyMoneyFile::instance()->availableCurrencyList(); - foreach (auto currency, currencies) { - if (selCur == currency.id()) { - m_wizard->m_baseCurrency = currency; - break; + MyMoneyAccount Wizard::account() const + { + Q_D(const Wizard); + MyMoneyAccount acc; + if (d->m_accountPage->d_func()->ui->m_haveCheckingAccountButton->isChecked()) { + acc.setName(d->m_accountPage->d_func()->ui->m_accountNameEdit->text()); + if (d->m_accountPage->d_func()->ui->m_accountNumberEdit->text().length()) + acc.setNumber(d->m_accountPage->d_func()->ui->m_accountNumberEdit->text()); + acc.setOpeningDate(d->m_accountPage->d_func()->ui->m_openingDateEdit->date()); + acc.setCurrencyId(d->m_baseCurrency.id()); + acc.setAccountType(eMyMoney::Account::Checkings); } + return acc; } - m_wizard->m_accountPage->m_accountCurrencyLabel->setText(m_wizard->m_baseCurrency.tradingSymbol()); - return m_wizard->m_accountPage; -} - -AccountPage::AccountPage(Wizard* wizard) : - KAccountPageDecl(wizard), - WizardPage(stepCount, this, wizard) // don't inc. the step count here -{ - m_mandatoryGroup->add(m_accountNameEdit); - connect(m_mandatoryGroup, SIGNAL(stateChanged()), object(), SIGNAL(completeStateChanged())); - connect(m_haveCheckingAccountButton, SIGNAL(toggled(bool)), object(), SIGNAL(completeStateChanged())); - m_accountNameEdit->setFocus(); - m_openingDateEdit->setDate(QDate(QDate::currentDate().year(), 1, 1)); -} - -KMyMoneyWizardPage* AccountPage::nextPage() const -{ - return m_wizard->m_categoriesPage; -} -bool AccountPage::isComplete() const -{ - return !m_haveCheckingAccountButton->isChecked() || m_mandatoryGroup->isEnabled(); -} - -CategoriesPage::CategoriesPage(Wizard* wizard) : - Accounts(wizard), - WizardPage(stepCount++, this, wizard) -{ -} - -KMyMoneyWizardPage* CategoriesPage::nextPage() const -{ - return m_wizard->m_preferencePage; -} - -QList CategoriesPage::selectedTemplates() const -{ - return m_templateSelector->selectedTemplates(); -} - -PreferencePage::PreferencePage(Wizard* wizard) : - KPreferencePageDecl(wizard), - WizardPage(stepCount++, this, wizard) -{ -} - -KMyMoneyWizardPage* PreferencePage::nextPage() const -{ - return m_wizard->m_filePage; -} - -FilePage::FilePage(Wizard* wizard) : - KFilePageDecl(wizard), - WizardPage(stepCount++, this, wizard) -{ - m_mandatoryGroup->add(m_dataFileEdit->lineEdit()); - connect(m_mandatoryGroup, SIGNAL(stateChanged()), object(), SIGNAL(completeStateChanged())); + MyMoneyMoney Wizard::openingBalance() const + { + Q_D(const Wizard); + return d->m_accountPage->d_func()->ui->m_openingBalanceEdit->value(); + } - KUser user; - QString folder = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); - if (folder.isEmpty() || !QDir().exists(folder)) - folder = QDir::homePath(); - m_dataFileEdit->setStartDir(QUrl::fromLocalFile(folder)); - m_dataFileEdit->setUrl(QUrl::fromLocalFile(folder + QLatin1Char('/') + user.loginName() + QLatin1String(".kmy"))); - m_dataFileEdit->setFilter(i18n("*.kmy *.xml|KMyMoney files\n*|All files")); - m_dataFileEdit->setMode(KFile::File); -} + MyMoneySecurity Wizard::baseCurrency() const + { + Q_D(const Wizard); + return d->m_baseCurrency; + } -bool FilePage::isComplete() const -{ - //! @todo Allow to overwrite files - bool rc = m_mandatoryGroup->isEnabled(); - m_existingFileLabel->hide(); - m_finishLabel->show(); - if (rc) { - // if a filename is present, check that - // a) the file does not exist - // b) the directory does exist - // c) the file is stored locally (because we cannot check previous conditions if it is not) - const QUrl fullPath = m_dataFileEdit->url(); - QFileInfo directory{fullPath.adjusted(QUrl::RemoveFilename).toLocalFile()}; - qDebug() << "Selected fileptah: " << fullPath << " " << directory.absoluteFilePath() << " dir: " << directory.isDir(); - rc = false; - if (!fullPath.isValid() || !fullPath.isLocalFile()) { - m_dataFileEdit->setToolTip(i18n("The path has to be valid and cannot be on a remote location.")); - } else if (QFileInfo::exists(fullPath.toLocalFile())) { - m_dataFileEdit->setToolTip(i18n("The file exists already. Please create a new file.")); - } else if (!directory.isDir()) { - m_dataFileEdit->setToolTip(i18n("The destination directory does not exist or cannot be written to.")); - } else { - m_dataFileEdit->setToolTip(""); - rc = true; - } + QList Wizard::templates() const + { + Q_D(const Wizard); + return d->m_categoriesPage->selectedTemplates(); + } - m_existingFileLabel->setHidden(rc); - m_finishLabel->setVisible(rc); + bool Wizard::startSettingsAfterFinished() const + { + Q_D(const Wizard); + return d->m_preferencePage->d_func()->ui->m_openConfigAfterFinished->checkState() == Qt::Checked; } - return rc; -} } diff --git a/kmymoney/wizards/newuserwizard/knewuserwizard_p.h b/kmymoney/wizards/newuserwizard/knewuserwizard_p.h --- a/kmymoney/wizards/newuserwizard/knewuserwizard_p.h +++ b/kmymoney/wizards/newuserwizard/knewuserwizard_p.h @@ -21,159 +21,47 @@ // ---------------------------------------------------------------------------- // QT Includes -#include - // ---------------------------------------------------------------------------- // Project Includes -#include -#include "kmymoneywizardpage.h" - -#include "ui_kintropagedecl.h" -#include "ui_kaccountpagedecl.h" -#include "ui_kpreferencepagedecl.h" -#include "ui_kfilepagedecl.h" - -#include "userinfo.h" -#include "currency.h" -#include "accounts.h" - -#include "mymoneytemplate.h" -#include "mymoneycontact.h" - -class Wizard; -class KJob; +#include "knewuserwizard.h" +#include "kmymoneywizard_p.h" +#include "mymoneysecurity.h" namespace NewUserWizard { - -class KIntroPageDecl : public QWidget, public Ui::KIntroPageDecl -{ -public: - KIntroPageDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; - -class IntroPage : public KIntroPageDecl, public WizardPage -{ - Q_OBJECT -public: - IntroPage(Wizard* parent); - KMyMoneyWizardPage* nextPage(void) const; -}; - -/** - * Wizard page collecting information about the user - * - * @author Thomas Baumgart - */ -class GeneralPage : public UserInfo, public WizardPage -{ - Q_OBJECT -public: - GeneralPage(Wizard* parent); - KMyMoneyWizardPage* nextPage(void) const; - -protected slots: - void slotLoadFromAddressBook(void); - void slotContactFetched(const ContactData &identity); - -private: - MyMoneyContact *m_contact; -}; - -/** - * Wizard page collecting information about the base currency - * - * @author Thomas Baumgart - */ -class CurrencyPage : public Currency, public WizardPage -{ - Q_OBJECT -public: - CurrencyPage(Wizard* parent); - void enterPage(void); - KMyMoneyWizardPage* nextPage(void) const; -}; - -/** - * Wizard page collecting information about the checking account - */ - -class KAccountPageDecl : public QWidget, public Ui::KAccountPageDecl -{ -public: - KAccountPageDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; -class AccountPage : public KAccountPageDecl, public WizardPage -{ - Q_OBJECT -public: - AccountPage(Wizard* parent); - KMyMoneyWizardPage* nextPage(void) const; - - virtual bool isComplete(void) const; -}; - -/** - * Wizard page collecting information about the account templates. - * - * @author Thomas Baumgart - */ -class CategoriesPage : public Accounts, public WizardPage -{ - Q_OBJECT -public: - CategoriesPage(Wizard* parent); - KMyMoneyWizardPage* nextPage(void) const; - QList selectedTemplates(void) const; -}; - -/** - * Wizard page to allow changing the preferences during setup - * - * @author Thomas Baumgart - */ - -class KPreferencePageDecl : public QWidget, public Ui::KPreferencePageDecl -{ -public: - KPreferencePageDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; -class PreferencePage : public KPreferencePageDecl, public WizardPage -{ - Q_OBJECT -public: - PreferencePage(Wizard* parent); - KMyMoneyWizardPage* nextPage(void) const; -}; - -/** - * Wizard page to allow selecting the filename - * - * @author Thomas Baumgart - */ - -class KFilePageDecl : public QWidget, public Ui::KFilePageDecl -{ -public: - KFilePageDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; -class FilePage : public KFilePageDecl, public WizardPage -{ - Q_OBJECT -public: - FilePage(Wizard* parent); - - virtual bool isComplete(void) const; -}; + class IntroPage; + class GeneralPage; + class CurrencyPage; + class AccountPage; + class CategoriesPage; + class PreferencePage; + class FilePage; + + class WizardPrivate : public KMyMoneyWizardPrivate + { + Q_DISABLE_COPY(WizardPrivate) + + public: + WizardPrivate(Wizard *qq): + KMyMoneyWizardPrivate(qq), + m_introPage(nullptr) + { + } + + ~WizardPrivate() + { + } + + MyMoneySecurity m_baseCurrency; + IntroPage* m_introPage; + GeneralPage* m_generalPage; + CurrencyPage* m_currencyPage; + AccountPage* m_accountPage; + CategoriesPage* m_categoriesPage; + PreferencePage* m_preferencePage; + FilePage* m_filePage; + }; } // namespace diff --git a/kmymoney/wizards/newuserwizard/kpasswordpagedecl.ui b/kmymoney/wizards/newuserwizard/kpasswordpage.ui rename from kmymoney/wizards/newuserwizard/kpasswordpagedecl.ui rename to kmymoney/wizards/newuserwizard/kpasswordpage.ui --- a/kmymoney/wizards/newuserwizard/kpasswordpagedecl.ui +++ b/kmymoney/wizards/newuserwizard/kpasswordpage.ui @@ -3,8 +3,8 @@ - KPasswordPageDecl - + KPasswordPage + true diff --git a/kmymoney/wizards/newuserwizard/kpreferencepage.h b/kmymoney/wizards/newuserwizard/kpreferencepage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kpreferencepage.h @@ -0,0 +1,60 @@ +/*************************************************************************** + kpreferencepage.h + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWUSERWIZARDPREFERENCEPAGE_H +#define KNEWUSERWIZARDPREFERENCEPAGE_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "wizardpage.h" + +class KMyMoneyWizardPage; + +namespace NewUserWizard +{ + class Wizard; + + /** + * Wizard page to allow changing the preferences during setup + * + * @author Thomas Baumgart + */ + class PreferencePagePrivate; + class PreferencePage : public QWidget, public WizardPage + { + Q_OBJECT + Q_DISABLE_COPY(PreferencePage) + + public: + explicit PreferencePage(Wizard* parent); + ~PreferencePage() override; + + KMyMoneyWizardPage* nextPage(void) const override; + + private: + Q_DECLARE_PRIVATE_D(WizardPage::d_ptr, PreferencePage) + friend class Wizard; + }; +} // namespace + +#endif diff --git a/kmymoney/wizards/newuserwizard/kpreferencepage.cpp b/kmymoney/wizards/newuserwizard/kpreferencepage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kpreferencepage.cpp @@ -0,0 +1,57 @@ +/*************************************************************************** + kpreferencepage.cpp + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kpreferencepage.h" +#include "kpreferencepage_p.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kpreferencepage.h" + +#include "knewuserwizard.h" +#include "knewuserwizard_p.h" +#include "kfilepage.h" + +namespace NewUserWizard +{ + PreferencePage::PreferencePage(Wizard* wizard) : + QWidget(wizard), + WizardPage(*new PreferencePagePrivate(wizard), stepCount++, this, wizard) + { + Q_D(PreferencePage); + d->ui->setupUi(this); + } + + PreferencePage::~PreferencePage() + { + } + + KMyMoneyWizardPage* PreferencePage::nextPage() const + { + Q_D(const PreferencePage); + return d->m_wizard->d_func()->m_filePage; + } + +} diff --git a/kmymoney/wizards/newuserwizard/kpreferencepagedecl.ui b/kmymoney/wizards/newuserwizard/kpreferencepage.ui rename from kmymoney/wizards/newuserwizard/kpreferencepagedecl.ui rename to kmymoney/wizards/newuserwizard/kpreferencepage.ui --- a/kmymoney/wizards/newuserwizard/kpreferencepagedecl.ui +++ b/kmymoney/wizards/newuserwizard/kpreferencepage.ui @@ -1,7 +1,7 @@ - KPreferencePageDecl - + KPreferencePage + 0 diff --git a/kmymoney/wizards/newuserwizard/kpreferencepage_p.h b/kmymoney/wizards/newuserwizard/kpreferencepage_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/newuserwizard/kpreferencepage_p.h @@ -0,0 +1,56 @@ +/*************************************************************************** + kpreferencepage_p.h + ------------------- + begin : Sat Feb 18 2006 + copyright : (C) 2006 Thomas Baumgart + email : Thomas Baumgart + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KNEWUSERWIZARDPREFERENCEPAGE_P_H +#define KNEWUSERWIZARDPREFERENCEPAGE_P_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "ui_kpreferencepage.h" +#include "wizardpage.h" + +namespace NewUserWizard +{ + class Wizard; + class PreferencePagePrivate : public WizardPagePrivate + { + Q_DISABLE_COPY(PreferencePagePrivate) + + public: + PreferencePagePrivate(QObject* parent) : + WizardPagePrivate(parent), + ui(new Ui::KPreferencePage) + { + } + + ~PreferencePagePrivate() + { + delete ui; + } + + Ui::KPreferencePage *ui; + }; +} +#endif diff --git a/kmymoney/wizards/wizardpage.h b/kmymoney/wizards/wizardpage.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/wizardpage.h @@ -0,0 +1,75 @@ +/*************************************************************************** + wizardpage.h + ------------------- + copyright : (C) 2006 by Thomas Baumagrt + email : ipwizard@users.sourceforge.net + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef WIZARDPAGE_H +#define WIZARDPAGE_H + +#include "wizardpage_p.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "kmymoneywizardpage.h" + +class KMyMoneyWizard; + +/** + * The general base class for wizard pages + * + * @author Thomas Baumgart + */ + +template +class WizardPage : public KMyMoneyWizardPage +{ +public: + WizardPage(uint step, QWidget* widget, T* parent) : + KMyMoneyWizardPage(*new WizardPagePrivate(widget), step, widget) + { + d_func()->m_wizard = parent; + d_func()->m_wizardBase = parent; + } + + ~WizardPage() override + { + } + + virtual KMyMoneyWizard* wizard() const + { + return d_func()->m_wizardBase; + } + +protected: + using KMyMoneyWizardPage::d_ptr; + inline WizardPagePrivate* d_func() { return reinterpret_cast *>(qGetPtrHelper(d_ptr)); } + inline const WizardPagePrivate* d_func() const { return reinterpret_cast *>(qGetPtrHelper(d_ptr)); } + friend class WizardPagePrivate; + WizardPage(WizardPagePrivate &dd, uint step, QWidget* widget, T* parent) : + KMyMoneyWizardPage(dd, step, widget) + { + d_func()->m_wizard = parent; + d_func()->m_wizardBase = parent; + } +}; + +#endif diff --git a/kmymoney/wizards/wizardpage_p.h b/kmymoney/wizards/wizardpage_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/wizards/wizardpage_p.h @@ -0,0 +1,47 @@ +/*************************************************************************** + wizardpage_p.h + ------------------- + copyright : (C) 2006 by Thomas Baumagrt + email : ipwizard@users.sourceforge.net + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef WIZARDPAGE_P_H +#define WIZARDPAGE_P_H + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "kmymoneywizardpage_p.h" + +class KMyMoneyWizard; + +template +class WizardPagePrivate : public KMyMoneyWizardPagePrivate +{ +public: + WizardPagePrivate(QObject* parent) : + KMyMoneyWizardPagePrivate(parent) + { + } + + T* m_wizard; + KMyMoneyWizard* m_wizardBase; +}; + +#endif diff --git a/kmymoney/wizards/wizardpages/CMakeLists.txt b/kmymoney/wizards/wizardpages/CMakeLists.txt --- a/kmymoney/wizards/wizardpages/CMakeLists.txt +++ b/kmymoney/wizards/wizardpages/CMakeLists.txt @@ -6,7 +6,7 @@ ) set (libwizardpages_a_UI - accountsdecl.ui currencydecl.ui userinfodecl.ui + accounts.ui currency.ui userinfo.ui ) ki18n_wrap_ui(wizardpages_ui_srcs ${libwizardpages_a_UI} ) @@ -18,5 +18,5 @@ add_library(wizardpages STATIC ${libwizardpages_a_SOURCES} ${wizardpages_ui_srcs}) # TODO: fix widgets library public dependencies -target_link_libraries(wizardpages KF5::KIOWidgets KF5::TextWidgets KF5::Completion Alkimia::alkimia Qt5::Sql Qt5::Xml) +target_link_libraries(wizardpages KF5::KIOWidgets KF5::TextWidgets Alkimia::alkimia Qt5::Xml) diff --git a/kmymoney/wizards/wizardpages/accounts.h b/kmymoney/wizards/wizardpages/accounts.h --- a/kmymoney/wizards/wizardpages/accounts.h +++ b/kmymoney/wizards/wizardpages/accounts.h @@ -21,30 +21,27 @@ // ---------------------------------------------------------------------------- // QT Includes +#include + // ---------------------------------------------------------------------------- // Project Includes -#include "ui_accountsdecl.h" +namespace Ui { class Accounts; } /** * @author Thomas Baumgart */ -class AccountsDecl : public QWidget, public Ui::AccountsDecl -{ -public: - AccountsDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; - -class Accounts : public AccountsDecl +class Accounts : public QWidget { Q_OBJECT + Q_DISABLE_COPY(Accounts) + public: - Accounts(QWidget* parent = 0); + explicit Accounts(QWidget *parent = nullptr); + virtual ~Accounts(); -private: + Ui::Accounts *ui; }; diff --git a/kmymoney/wizards/wizardpages/accounts.cpp b/kmymoney/wizards/wizardpages/accounts.cpp --- a/kmymoney/wizards/wizardpages/accounts.cpp +++ b/kmymoney/wizards/wizardpages/accounts.cpp @@ -26,7 +26,16 @@ // ---------------------------------------------------------------------------- // Project Includes +#include "ui_accounts.h" + Accounts::Accounts(QWidget* parent) : - AccountsDecl(parent) + QWidget(parent), + ui(new Ui::Accounts) +{ + ui->setupUi(this); +} + +Accounts::~Accounts() { + delete ui; } diff --git a/kmymoney/wizards/wizardpages/accountsdecl.ui b/kmymoney/wizards/wizardpages/accounts.ui rename from kmymoney/wizards/wizardpages/accountsdecl.ui rename to kmymoney/wizards/wizardpages/accounts.ui --- a/kmymoney/wizards/wizardpages/accountsdecl.ui +++ b/kmymoney/wizards/wizardpages/accounts.ui @@ -3,8 +3,8 @@ - AccountsDecl - + Accounts + 0 diff --git a/kmymoney/wizards/wizardpages/currency.h b/kmymoney/wizards/wizardpages/currency.h --- a/kmymoney/wizards/wizardpages/currency.h +++ b/kmymoney/wizards/wizardpages/currency.h @@ -20,34 +20,35 @@ // ---------------------------------------------------------------------------- // QT Includes + #include // ---------------------------------------------------------------------------- // Project Includes -#include "ui_currencydecl.h" - +class QTreeWidgetItem; class MyMoneySecurity; +namespace Ui { class Currency; } + /** * @author Thomas Baumgart */ -class CurrencyDecl : public QWidget, public Ui::CurrencyDecl -{ -public: - CurrencyDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; -class Currency : public CurrencyDecl +class Currency : public QWidget { Q_OBJECT + Q_DISABLE_COPY(Currency) + public: - Currency(QWidget* parent = 0); + explicit Currency(QWidget *parent = nullptr); + virtual ~Currency(); + QTreeWidgetItem* insertCurrency(const MyMoneySecurity& sec); void selectCurrency(const MyMoneySecurity& sec); QString selectedCurrency() const; + + Ui::Currency *ui; }; #endif diff --git a/kmymoney/wizards/wizardpages/currency.cpp b/kmymoney/wizards/wizardpages/currency.cpp --- a/kmymoney/wizards/wizardpages/currency.cpp +++ b/kmymoney/wizards/wizardpages/currency.cpp @@ -29,13 +29,21 @@ // ---------------------------------------------------------------------------- // Project Includes +#include "ui_currency.h" #include "mymoneysecurity.h" Currency::Currency(QWidget* parent) : - CurrencyDecl(parent) + QWidget(parent), + ui(new Ui::Currency) { - m_currencyList->setAllColumnsShowFocus(true); - m_currencyList->setColumnWidth(0, size().width()*6 / 10); + ui->setupUi(this); + ui->m_currencyList->setAllColumnsShowFocus(true); + ui->m_currencyList->setColumnWidth(0, size().width()*6 / 10); +} + +Currency::~Currency() +{ + delete ui; } QTreeWidgetItem* Currency::insertCurrency(const MyMoneySecurity& sec) @@ -45,26 +53,25 @@ item.append(QString(sec.id())); item.append(sec.tradingSymbol()); - return new QTreeWidgetItem(m_currencyList, item); + return new QTreeWidgetItem(ui->m_currencyList, item); } void Currency::selectCurrency(const MyMoneySecurity& sec) { - QList selectedItems = m_currencyList->findItems(sec.id(), Qt::MatchExactly, 1); + QList selectedItems = ui->m_currencyList->findItems(sec.id(), Qt::MatchExactly, 1); QList::iterator itemIt = selectedItems.begin(); while (itemIt != selectedItems.end()) { (*itemIt)->setSelected(true); - m_currencyList->scrollToItem(*itemIt); + ui->m_currencyList->scrollToItem(*itemIt); } } - QString Currency::selectedCurrency() const { QString id; - if (m_currencyList->selectedItems().size() > 0) { - id = m_currencyList->selectedItems().at(0)->text(1); + if (ui->m_currencyList->selectedItems().size() > 0) { + id = ui->m_currencyList->selectedItems().at(0)->text(1); } return id; } diff --git a/kmymoney/wizards/wizardpages/currencydecl.ui b/kmymoney/wizards/wizardpages/currency.ui rename from kmymoney/wizards/wizardpages/currencydecl.ui rename to kmymoney/wizards/wizardpages/currency.ui --- a/kmymoney/wizards/wizardpages/currencydecl.ui +++ b/kmymoney/wizards/wizardpages/currency.ui @@ -1,7 +1,7 @@ - CurrencyDecl - + Currency + 0 diff --git a/kmymoney/wizards/wizardpages/userinfo.h b/kmymoney/wizards/wizardpages/userinfo.h --- a/kmymoney/wizards/wizardpages/userinfo.h +++ b/kmymoney/wizards/wizardpages/userinfo.h @@ -21,31 +21,30 @@ // ---------------------------------------------------------------------------- // QT Includes +#include + // ---------------------------------------------------------------------------- // Project Includes -#include "ui_userinfodecl.h" +namespace Ui { class UserInfo; } + class MyMoneyPayee; /** * @author Thomas Baumgart */ -class UserInfoDecl : public QWidget, public Ui::UserInfoDecl -{ -public: - UserInfoDecl(QWidget *parent) : QWidget(parent) { - setupUi(this); - } -}; -class UserInfo : public UserInfoDecl +class UserInfo : public QWidget { Q_OBJECT + Q_DISABLE_COPY(UserInfo) + public: - UserInfo(QWidget* parent = 0); - MyMoneyPayee user() const; + explicit UserInfo(QWidget *parent = nullptr); + virtual ~UserInfo(); -private: + MyMoneyPayee user() const; + Ui::UserInfo *ui; }; diff --git a/kmymoney/wizards/wizardpages/userinfo.cpp b/kmymoney/wizards/wizardpages/userinfo.cpp --- a/kmymoney/wizards/wizardpages/userinfo.cpp +++ b/kmymoney/wizards/wizardpages/userinfo.cpp @@ -26,24 +26,31 @@ // ---------------------------------------------------------------------------- // Project Includes +#include "ui_userinfo.h" #include "mymoneypayee.h" - UserInfo::UserInfo(QWidget* parent) : - UserInfoDecl(parent) + QWidget(parent), + ui(new Ui::UserInfo) +{ + ui->setupUi(this); + ui->m_userNameEdit->setFocus(); +} + +UserInfo::~UserInfo() { - m_userNameEdit->setFocus(); + delete ui; } MyMoneyPayee UserInfo::user() const { MyMoneyPayee user; - user.setName(m_userNameEdit->text()); - user.setAddress(m_streetEdit->text()); - user.setCity(m_townEdit->text()); - user.setState(m_countyEdit->text()); - user.setPostcode(m_postcodeEdit->text()); - user.setTelephone(m_telephoneEdit->text()); - user.setEmail(m_emailEdit->text()); + user.setName(ui->m_userNameEdit->text()); + user.setAddress(ui->m_streetEdit->text()); + user.setCity(ui->m_townEdit->text()); + user.setState(ui->m_countyEdit->text()); + user.setPostcode(ui->m_postcodeEdit->text()); + user.setTelephone(ui->m_telephoneEdit->text()); + user.setEmail(ui->m_emailEdit->text()); return user; } diff --git a/kmymoney/wizards/wizardpages/userinfodecl.ui b/kmymoney/wizards/wizardpages/userinfo.ui rename from kmymoney/wizards/wizardpages/userinfodecl.ui rename to kmymoney/wizards/wizardpages/userinfo.ui --- a/kmymoney/wizards/wizardpages/userinfodecl.ui +++ b/kmymoney/wizards/wizardpages/userinfo.ui @@ -3,8 +3,8 @@ - UserInfoDecl - + UserInfo + 0