diff --git a/kmymoney/dialogs/settings/ksettingskmymoney.cpp b/kmymoney/dialogs/settings/ksettingskmymoney.cpp index 9f3128e34..9683888d2 100644 --- a/kmymoney/dialogs/settings/ksettingskmymoney.cpp +++ b/kmymoney/dialogs/settings/ksettingskmymoney.cpp @@ -1,89 +1,89 @@ /* * This file is part of KMyMoney, A Personal Finance Manager by KDE * Copyright (C) 2016 Christian Dávid * (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. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "ksettingskmymoney.h" #include #include #include "ksettingsgeneral.h" #include "ksettingsregister.h" #include "ksettingsgpg.h" #include "ksettingscolors.h" #include "ksettingsfonts.h" #include "ksettingsicons.h" #include "ksettingsschedules.h" #include "ksettingsonlinequotes.h" #include "ksettingshome.h" #include "ksettingsreports.h" #include "ksettingsplugins.h" #include "icons.h" using namespace Icons; KSettingsKMyMoney::KSettingsKMyMoney(QWidget *parent, const QString &name, KCoreConfigSkeleton *config) : KConfigDialog(parent, name, config) { // create the pages ... const auto generalPage = new KSettingsGeneral(); const auto registerPage = new KSettingsRegister(); const auto homePage = new KSettingsHome(); const auto schedulesPage = new KSettingsSchedules(); const auto encryptionPage = new KSettingsGpg(); const auto colorsPage = new KSettingsColors(); const auto fontsPage = new KSettingsFonts(); const auto iconsPage = new KSettingsIcons(); const auto onlineQuotesPage = new KSettingsOnlineQuotes(); const auto reportsPage = new KSettingsReports(); const auto pluginsPage = new KSettingsPlugins(); addPage(generalPage, i18nc("General settings", "General"), Icons::get(Icon::SystemRun).name()); addPage(homePage, i18n("Home"), Icons::get(Icon::ViewHome).name()); addPage(registerPage, i18nc("Ledger view settings", "Ledger"), Icons::get(Icon::ViewFinancialList).name()); - addPage(schedulesPage, i18nc("use \u2028 as line break", "Scheduled\u2028transactions"), Icons::get(Icon::ViewSchedules).name()); + addPage(schedulesPage, i18n("Scheduled\u2028transactions"), Icons::get(Icon::ViewSchedules).name()); addPage(onlineQuotesPage, i18n("Online Quotes"), Icons::get(Icon::PreferencesNetwork).name()); addPage(reportsPage, i18nc("Report settings", "Reports"), Icons::get(Icon::ViewReports).name()); addPage(encryptionPage, i18n("Encryption"), Icons::get(Icon::Kgpg).name()); addPage(colorsPage, i18n("Colors"), Icons::get(Icon::PreferencesColor).name()); addPage(fontsPage, i18n("Fonts"), Icons::get(Icon::PreferencesFont).name()); addPage(iconsPage, i18n("Icons"), Icons::get(Icon::PreferencesIcon).name()); addPage(pluginsPage, i18n("Plugins"), Icons::get(Icon::NetworkDisconect).name(), QString(), false); setHelp("details.settings", "kmymoney"); connect(this, &KConfigDialog::rejected, schedulesPage, &KSettingsSchedules::slotResetRegion); connect(this, &KConfigDialog::rejected, iconsPage, &KSettingsIcons::slotResetTheme); connect(this, &KConfigDialog::settingsChanged, generalPage, &KSettingsGeneral::slotUpdateEquitiesVisibility); auto defaultButton = button(QDialogButtonBox::RestoreDefaults); auto applyButton = button(QDialogButtonBox::Apply); connect(this, &KConfigDialog::accepted, pluginsPage, &KSettingsPlugins::slotSavePluginConfiguration); connect(applyButton, &QPushButton::clicked, pluginsPage, &KSettingsPlugins::slotSavePluginConfiguration); connect(defaultButton, &QPushButton::clicked, pluginsPage, &KSettingsPlugins::slotResetToDefaults); connect(pluginsPage, &KSettingsPlugins::changed, this, &KSettingsKMyMoney::slotPluginsChanged); connect(pluginsPage, &KSettingsPlugins::settingsChanged, this, &KConfigDialog::settingsChanged); } void KSettingsKMyMoney::slotPluginsChanged(bool changed) { auto applyButton = button(QDialogButtonBox::Apply); applyButton->setEnabled(changed); } diff --git a/kmymoney/views/kmymoneyview.cpp b/kmymoney/views/kmymoneyview.cpp index 8f534fed6..f31a8b328 100644 --- a/kmymoney/views/kmymoneyview.cpp +++ b/kmymoney/views/kmymoneyview.cpp @@ -1,956 +1,919 @@ /*************************************************************************** kmymoneyview.cpp ------------------- copyright : (C) 2000-2001 by Michael Edwardes 2004 by Thomas Baumgart 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 #include "kmymoneyview.h" // ---------------------------------------------------------------------------- // Std Includes #include // ---------------------------------------------------------------------------- // QT Includes #include #include #include #include #include #include #include #include #include // ---------------------------------------------------------------------------- // KDE Includes #include #include #include #include #include #include #include #include #include #ifdef KF5Activities_FOUND #include #endif // ---------------------------------------------------------------------------- // Project Includes #ifdef ENABLE_UNFINISHEDFEATURES #include "simpleledgerview.h" #endif #include "kmymoneysettings.h" #include "kmymoneytitlelabel.h" #include #include "kcurrencyeditdlg.h" #include "mymoneystoragemgr.h" #include "mymoneystoragebin.h" #include "mymoneyexception.h" #include "mymoneystoragexml.h" #include "mymoneystorageanon.h" #include "khomeview.h" #include "kaccountsview.h" #include "kcategoriesview.h" #include "kinstitutionsview.h" #include "kpayeesview.h" #include "ktagsview.h" #include "kscheduledview.h" #include "kgloballedgerview.h" #include "kinvestmentview.h" #include "kreportsview.h" #include "kbudgetview.h" #include "konlinejoboutbox.h" #include "kmymoney.h" #include "models.h" #include "accountsmodel.h" #include "equitiesmodel.h" #include "securitiesmodel.h" #include "icons.h" #include "amountedit.h" #include "kmymoneyaccounttreeview.h" #include "accountsviewproxymodel.h" #include "mymoneyprice.h" #include "mymoneyschedule.h" #include "mymoneysplit.h" #include "mymoneyaccount.h" #include "mymoneyinstitution.h" #include "kmymoneyedit.h" #include "mymoneyfile.h" #include "mymoneysecurity.h" #include "mymoneyreport.h" #include "kmymoneyplugin.h" #include "mymoneyenums.h" using namespace Icons; using namespace eMyMoney; typedef void(KMyMoneyView::*KMyMoneyViewFunc)(); KMyMoneyView::KMyMoneyView(KMyMoneyApp *kmymoney) : KPageWidget(nullptr), m_header(0), m_inConstructor(true), m_lastViewSelected(0), m_storagePlugins(nullptr) #ifdef KF5Activities_FOUND , m_activityResourceInstance(0) #endif { // this is a workaround for the bug in KPageWidget that causes the header to be shown // for a short while during page switch which causes a kind of bouncing of the page's // content and if the page's content is at it's minimum size then during a page switch // the main window's size is also increased to fit the header that is shown for a sort // period - reading the code in kpagewidget.cpp we know that the header should be at (1,1) // in a grid layout so if we find it there remove it for good to avoid the described issues QGridLayout* gridLayout = qobject_cast(layout()); if (gridLayout) { QLayoutItem* headerItem = gridLayout->itemAtPosition(1, 1); // make sure that we remove only the header - we avoid surprises if the header is not at (1,1) in the layout if (headerItem && qobject_cast(headerItem->widget()) != NULL) { gridLayout->removeItem(headerItem); // after we remove the KPageWidget standard header replace it with our own title label m_header = new KMyMoneyTitleLabel(this); m_header->setObjectName("titleLabel"); m_header->setMinimumSize(QSize(100, 30)); m_header->setRightImageFile("pics/titlelabel_background.png"); m_header->setVisible(KMyMoneySettings::showTitleBar()); gridLayout->addWidget(m_header, 1, 1); } } // newStorage(); m_model = new KPageWidgetModel(this); // cannot be parentless, otherwise segfaults at exit connect(kmymoney, &KMyMoneyApp::fileLoaded, this, &KMyMoneyView::slotRefreshViews); - // Page 0 - m_homeView = new KHomeView; - viewFrames[View::Home] = m_model->addPage(m_homeView, i18n("Home")); - viewFrames[View::Home]->setIcon(Icons::get(Icon::ViewHome)); - connect(m_homeView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_homeView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::resetViewSelection); - - // Page 1 - m_institutionsView = new KInstitutionsView; - viewFrames[View::Institutions] = m_model->addPage(m_institutionsView, i18n("Institutions")); - viewFrames[View::Institutions]->setIcon(Icons::get(Icon::ViewInstitutions)); - connect(m_institutionsView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_institutionsView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::resetViewSelection); - - // Page 2 - m_accountsView = new KAccountsView; - viewFrames[View::Accounts] = m_model->addPage(m_accountsView, i18n("Accounts")); - viewFrames[View::Accounts]->setIcon(Icons::get(Icon::ViewAccounts)); - connect(m_accountsView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_accountsView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::resetViewSelection); - - // Page 3 - m_scheduledView = new KScheduledView; -//this is to solve the way long strings are handled differently among versions of KPageWidget - viewFrames[View::Schedules] = m_model->addPage(m_scheduledView, i18nc("use \u2028 as line break", "Scheduled\u2028transactions")); - viewFrames[View::Schedules]->setIcon(Icons::get(Icon::ViewSchedules)); - connect(m_scheduledView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_scheduledView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::resetViewSelection); - - // Page 4 - m_categoriesView = new KCategoriesView; - viewFrames[View::Categories] = m_model->addPage(m_categoriesView, i18n("Categories")); - viewFrames[View::Categories]->setIcon(Icons::get(Icon::ViewCategories)); - connect(m_categoriesView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_categoriesView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::resetViewSelection); - - // Page 5 - m_tagsView = new KTagsView; - viewFrames[View::Tags] = m_model->addPage(m_tagsView, i18n("Tags")); - viewFrames[View::Tags]->setIcon(Icons::get(Icon::ViewTags)); - connect(m_tagsView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_tagsView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::resetViewSelection); - - // Page 6 - m_payeesView = new KPayeesView; - viewFrames[View::Payees] = m_model->addPage(m_payeesView, i18n("Payees")); - viewFrames[View::Payees]->setIcon(Icons::get(Icon::ViewPayees)); - connect(m_payeesView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_payeesView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::resetViewSelection); - - // Page 7 - m_ledgerView = new KGlobalLedgerView; - viewFrames[View::Ledgers] = m_model->addPage(m_ledgerView, i18n("Ledgers")); - viewFrames[View::Ledgers]->setIcon(Icons::get(Icon::ViewLedgers)); - connect(m_ledgerView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_ledgerView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::resetViewSelection); - - // Page 8 - m_investmentView = new KInvestmentView; - viewFrames[View::Investments] = m_model->addPage(m_investmentView, i18n("Investments")); - viewFrames[View::Investments]->setIcon(Icons::get(Icon::ViewInvestment)); - connect(m_investmentView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_investmentView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::resetViewSelection); - - // Page 9 - m_reportsView = new KReportsView; - viewFrames[View::Reports] = m_model->addPage(m_reportsView, i18n("Reports")); - viewFrames[View::Reports]->setIcon(Icons::get(Icon::ViewReports)); - connect(m_reportsView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_reportsView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::resetViewSelection); - - // Page 10 - m_budgetView = new KBudgetView; - viewFrames[View::Budget] = m_model->addPage(m_budgetView, i18n("Budgets")); - viewFrames[View::Budget]->setIcon(Icons::get(Icon::ViewBudgets)); - connect(m_budgetView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_budgetView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::resetViewSelection); - - // Page 11 - // KForecastView - - // Page 12 - m_onlineJobOutboxView = new KOnlineJobOutbox; - addView(m_onlineJobOutboxView, i18n("Outbox"), View::OnlineJobOutbox); - connect(m_onlineJobOutboxView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_onlineJobOutboxView, &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::resetViewSelection); - - connect(m_reportsView, &KReportsView::switchViewRequested, this, &KMyMoneyView::slotSwitchView); - connect(m_ledgerView, &KGlobalLedgerView::switchViewRequested, this, &KMyMoneyView::slotSwitchView); - connect(m_homeView, &KHomeView::ledgerSelected, m_ledgerView, &KGlobalLedgerView::slotLedgerSelected); - - connect(kmymoney, &KMyMoneyApp::transactionSelected, m_ledgerView, &KGlobalLedgerView::slotLedgerSelected); + viewBases[View::Home] = new KHomeView; + viewBases[View::Institutions] = new KInstitutionsView; + viewBases[View::Accounts] = new KAccountsView; + viewBases[View::Schedules] = new KScheduledView; + viewBases[View::Categories] = new KCategoriesView; + viewBases[View::Tags] = new KTagsView; + viewBases[View::Payees] = new KPayeesView; + viewBases[View::Ledgers] = new KGlobalLedgerView; + viewBases[View::Investments] = new KInvestmentView; + viewBases[View::Reports] = new KReportsView; + viewBases[View::Budget] = new KBudgetView; + viewBases[View::OnlineJobOutbox] = new KOnlineJobOutbox; + #ifdef ENABLE_UNFINISHEDFEATURES + viewBases[View::NewLedgers] = new SimpleLedgerView; + #endif -#ifdef ENABLE_UNFINISHEDFEATURES - m_simpleLedgerView = new SimpleLedgerView(kmymoney, this); - KPageWidgetItem* frame = m_model->addPage(m_simpleLedgerView, i18n("New ledger")); - frame->setIcon(Icons::get(Icon::DocumentProperties)); -#endif + struct viewInfo + { + View id; + QString name; + Icon icon; + }; + + const QVector viewsInfo + { + {View::Home, i18n("Home"), Icon::ViewHome}, + {View::Institutions, i18n("Institutions"), Icon::ViewInstitutions}, + {View::Accounts, i18n("Accounts"), Icon::ViewAccounts}, + {View::Schedules, i18n("Scheduled\u2028transactions"), Icon::ViewSchedules}, + {View::Categories, i18n("Categories"), Icon::ViewCategories}, + {View::Tags, i18n("Tags"), Icon::ViewTags}, + {View::Payees, i18n("Payees"), Icon::ViewPayees}, + {View::Ledgers, i18n("Ledgers"), Icon::ViewLedgers}, + {View::Investments, i18n("Investments"), Icon::ViewInvestment}, + {View::Reports, i18n("Reports"), Icon::ViewReports}, + {View::Budget, i18n("Budgets"), Icon::ViewBudgets}, + {View::OnlineJobOutbox, i18n("Outbox"), Icon::ViewOutbox}, + #ifdef ENABLE_UNFINISHEDFEATURES + {View::NewLedgers, i18n("New ledger"), Icon::DocumentProperties}, + #endif + }; + + for (const viewInfo& view : viewsInfo) { + viewFrames[view.id] = m_model->addPage(viewBases[view.id], view.name); + viewFrames[view.id]->setIcon(Icons::get(view.icon)); + connect(viewBases[view.id], &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::connectView); + connect(viewBases[view.id], &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::resetViewSelection); + } + + const auto& homeView = static_cast(viewBases[View::Home]); + const auto& ledgersView = static_cast(viewBases[View::Ledgers]); + const auto& reportsView = static_cast(viewBases[View::Reports]); + connect(reportsView, &KReportsView::switchViewRequested, this, &KMyMoneyView::showPage); + connect(ledgersView, &KGlobalLedgerView::switchViewRequested, this, &KMyMoneyView::showPage); + connect(homeView, &KHomeView::ledgerSelected, ledgersView, &KGlobalLedgerView::slotLedgerSelected); + connect(kmymoney, &KMyMoneyApp::transactionSelected, ledgersView, &KGlobalLedgerView::slotLedgerSelected); //set the model setModel(m_model); setCurrentPage(viewFrames[View::Home]); connect(this, SIGNAL(currentPageChanged(QModelIndex,QModelIndex)), this, SLOT(slotCurrentPageChanged(QModelIndex,QModelIndex))); updateViewType(); m_inConstructor = false; // add fast switching of main views through Ctrl + NUM_X struct pageInfo { View view; KMyMoneyViewFunc callback; QString text; QKeySequence shortcut = QKeySequence(); }; const QVector pageInfos { {View::Home, &KMyMoneyView::slotShowHomePage, i18n("Show home page"), Qt::CTRL + Qt::Key_1}, {View::Institutions, &KMyMoneyView::slotShowInstitutionsPage, i18n("Show institutions page"), Qt::CTRL + Qt::Key_2}, {View::Accounts, &KMyMoneyView::slotShowAccountsPage, i18n("Show accounts page"), Qt::CTRL + Qt::Key_3}, {View::Schedules, &KMyMoneyView::slotShowSchedulesPage, i18n("Show scheduled transactions page"), Qt::CTRL + Qt::Key_4}, {View::Categories, &KMyMoneyView::slotShowCategoriesPage, i18n("Show categories page"), Qt::CTRL + Qt::Key_5}, {View::Tags, &KMyMoneyView::slotShowTagsPage, i18n("Show tags page"), }, {View::Payees, &KMyMoneyView::slotShowPayeesPage, i18n("Show payees page"), Qt::CTRL + Qt::Key_6}, {View::Ledgers, &KMyMoneyView::slotShowLedgersPage, i18n("Show ledgers page"), Qt::CTRL + Qt::Key_7}, {View::Investments, &KMyMoneyView::slotShowInvestmentsPage, i18n("Show investments page"), Qt::CTRL + Qt::Key_8}, {View::Reports, &KMyMoneyView::slotShowReportsPage, i18n("Show reports page"), Qt::CTRL + Qt::Key_9}, {View::Budget, &KMyMoneyView::slotShowBudgetPage, i18n("Show budget page"), }, {View::Forecast, &KMyMoneyView::slotShowForecastPage, i18n("Show forecast page"), }, {View::OnlineJobOutbox, &KMyMoneyView::slotShowOutboxPage, i18n("Show outbox page") } }; QHash lutActions; auto aC = kmymoney->actionCollection(); auto pageCount = 0; foreach (const pageInfo info, pageInfos) { auto a = new QAction(this); // KActionCollection::addAction by name sets object name anyways, // so, as better alternative, set it here right from the start a->setObjectName(QLatin1String("ShowPage") + QString::number(pageCount++)); a->setText(info.text); connect(a, &QAction::triggered, this, info.callback); lutActions.insert(info.view, a); // store QAction's pointer for later processing if (!info.shortcut.isEmpty()) aC->setDefaultShortcut(a, info.shortcut); } aC->addActions(lutActions.values()); // Initialize kactivities resource instance #ifdef KF5Activities_FOUND m_activityResourceInstance = new KActivities::ResourceInstance(window()->winId(), this); connect(kmymoney, SIGNAL(fileLoaded(QUrl)), m_activityResourceInstance, SLOT(setUri(QUrl))); #endif } KMyMoneyView::~KMyMoneyView() { KMyMoneySettings::setLastViewSelected(m_lastViewSelected); #ifdef KF5Activities_FOUND delete m_activityResourceInstance; #endif // removeStorage(); } void KMyMoneyView::slotFileOpened() { #ifdef ENABLE_UNFINISHEDFEATURES - m_simpleLedgerView->openFavoriteLedgers(); + static_cast(viewBases[View::NewLedgers])->openFavoriteLedgers(); #endif switchToDefaultView(); } void KMyMoneyView::slotFileClosed() { - if (m_reportsView) - m_reportsView->slotCloseAll(); + + if (viewBases.contains(View::Reports)) + static_cast(viewBases[View::Reports])->slotCloseAll(); #ifdef ENABLE_UNFINISHEDFEATURES - m_simpleLedgerView->closeLedgers(); + static_cast(viewBases[View::NewLedgers])->closeLedgers(); #endif slotShowHomePage(); } void KMyMoneyView::slotShowHomePage() { - showPage(viewFrames[View::Home]); + showPageAndFocus(View::Home); } void KMyMoneyView::slotShowInstitutionsPage() { - showPage(viewFrames[View::Institutions]); - m_institutionsView->setDefaultFocus(); + showPageAndFocus(View::Institutions); } void KMyMoneyView::slotShowAccountsPage() { - showPage(viewFrames[View::Accounts]); - m_accountsView->setDefaultFocus(); + showPageAndFocus(View::Accounts); } void KMyMoneyView::slotShowSchedulesPage() { - showPage(viewFrames[View::Schedules]); - m_scheduledView->setDefaultFocus(); + showPageAndFocus(View::Schedules); } void KMyMoneyView::slotShowCategoriesPage() { - showPage(viewFrames[View::Categories]); - m_categoriesView->setDefaultFocus(); + showPageAndFocus(View::Categories); } void KMyMoneyView::slotShowTagsPage() { - showPage(viewFrames[View::Tags]); - m_tagsView->setDefaultFocus(); + showPageAndFocus(View::Tags); } void KMyMoneyView::slotShowPayeesPage() { - showPage(viewFrames[View::Payees]); - m_payeesView->setDefaultFocus(); + showPageAndFocus(View::Payees); } void KMyMoneyView::slotShowLedgersPage() { - showPage(viewFrames[View::Ledgers]); - m_ledgerView->setDefaultFocus(); + showPageAndFocus(View::Ledgers); } void KMyMoneyView::slotShowInvestmentsPage() { - showPage(viewFrames[View::Investments]); - m_investmentView->setDefaultFocus(); + showPageAndFocus(View::Investments); } void KMyMoneyView::slotShowReportsPage() { - showPage(viewFrames[View::Reports]); - m_reportsView->setDefaultFocus(); + showPageAndFocus(View::Reports); } void KMyMoneyView::slotShowBudgetPage() { - showPage(viewFrames[View::Budget]); - m_budgetView->setDefaultFocus(); + showPageAndFocus(View::Budget); } void KMyMoneyView::slotShowForecastPage() { - if (viewFrames.contains(View::Forecast)) { - showPage(viewFrames[View::Forecast]); - viewBases[View::Forecast]->setDefaultFocus(); - } + showPageAndFocus(View::Forecast); } void KMyMoneyView::slotShowOutboxPage() { - if (viewFrames[View::OnlineJobOutbox]) { - showPage(viewFrames[View::OnlineJobOutbox]); - viewBases[View::OnlineJobOutbox]->setDefaultFocus(); - } + showPageAndFocus(View::OnlineJobOutbox); } void KMyMoneyView::showTitleBar(bool show) { if (m_header) m_header->setVisible(show); } void KMyMoneyView::updateViewType() { // set the face type KPageView::FaceType faceType = KPageView::List; switch (KMyMoneySettings::viewType()) { case 0: faceType = KPageView::List; break; case 1: faceType = KPageView::Tree; break; case 2: faceType = KPageView::Tabbed; break; } if (faceType != KMyMoneyView::faceType()) { setFaceType(faceType); if (faceType == KPageView::Tree) { QList views = findChildren(); foreach (QTreeView * view, views) { if (view && (view->parent() == this)) { view->setRootIsDecorated(false); break; } } } } } void KMyMoneyView::slotAccountTreeViewChanged(const eAccountsModel::Column column, const bool show) { - QVector proxyModels {m_institutionsView->getProxyModel(), m_accountsView->getProxyModel(), - m_categoriesView->getProxyModel(), m_budgetView->getProxyModel()}; + QVector proxyModels + { + static_cast(viewBases[View::Institutions])->getProxyModel(), + static_cast(viewBases[View::Accounts])->getProxyModel(), + static_cast(viewBases[View::Categories])->getProxyModel(), + static_cast(viewBases[View::Budget])->getProxyModel(), + }; for (auto i = proxyModels.count() - 1; i >= 0; --i) { // weed out unloaded views if (!proxyModels.at(i)) proxyModels.removeAt(i); } QString question; if (show) question = i18n("Do you want to show %1 column on every loaded view?", AccountsModel::getHeaderName(column)); else question = i18n("Do you want to hide %1 column on every loaded view?", AccountsModel::getHeaderName(column)); if (proxyModels.count() == 1 || // no need to ask what to do with other views because they aren't loaded KMessageBox::questionYesNo(this, question, QString(), KStandardGuiItem::yes(), KStandardGuiItem::no(), QStringLiteral("ShowColumnOnEveryView")) == KMessageBox::Yes) { Models::instance()->accountsModel()->setColumnVisibility(column, show); Models::instance()->institutionsModel()->setColumnVisibility(column, show); foreach(AccountsViewProxyModel *proxyModel, proxyModels) { if (!proxyModel) continue; proxyModel->setColumnVisibility(column, show); proxyModel->invalidate(); } } else if(show) { // in case we need to show it, we have to make sure to set the visibility // in the base model as well. Otherwise, we don't see the column through the proxy model Models::instance()->accountsModel()->setColumnVisibility(column, show); Models::instance()->institutionsModel()->setColumnVisibility(column, show); } } void KMyMoneyView::setOnlinePlugins(QMap& plugins) { - m_accountsView->setOnlinePlugins(plugins); - if (m_onlineJobOutboxView) { - m_onlineJobOutboxView->setOnlinePlugins(plugins); - } - if (plugins.isEmpty()) { - removeView(View::OnlineJobOutbox); - m_onlineJobOutboxView = nullptr; + static_cast(viewBases[View::Accounts])->setOnlinePlugins(plugins); + if (viewBases.contains(View::OnlineJobOutbox)) { + if (plugins.isEmpty()) + removeView(View::OnlineJobOutbox); + else + static_cast(viewBases[View::OnlineJobOutbox])->setOnlinePlugins(plugins); } } void KMyMoneyView::setStoragePlugins(QMap& plugins) { m_storagePlugins = &plugins; } eDialogs::ScheduleResultCode KMyMoneyView::enterSchedule(MyMoneySchedule& schedule, bool autoEnter, bool extendedKeys) { - return m_scheduledView->enterSchedule(schedule, autoEnter, extendedKeys); + + return static_cast(viewBases[View::Schedules])->enterSchedule(schedule, autoEnter, extendedKeys); } void KMyMoneyView::addView(KMyMoneyViewBase* view, const QString& name, View idView) { auto isViewInserted = false; for (auto i = (int)idView; i < (int)View::None; ++i) { if (viewFrames.contains((View)i)) { viewFrames[idView] = m_model->insertPage(viewFrames[(View)i],view, name); viewBases[idView] = view; isViewInserted = true; break; } } if (!isViewInserted) viewFrames[idView] = m_model->addPage(view, name); auto icon = Icon::ViewForecast; switch (idView) { case View::Forecast: icon = Icon::ViewForecast; break; case View::OnlineJobOutbox: icon = Icon::ViewOutbox; break; default: break; } viewFrames[idView]->setIcon(Icons::get(icon)); } void KMyMoneyView::removeView(View idView) { m_model->removePage(viewFrames[idView]); viewFrames.remove(idView); viewBases.remove(idView); } bool KMyMoneyView::showPageHeader() const { return false; } -void KMyMoneyView::slotSwitchView(View view) +void KMyMoneyView::showPageAndFocus(View idView) { - showPage(viewFrames[view]); + if (viewFrames.contains(idView)) { + showPage(idView); + viewBases[idView]->setDefaultFocus(); + } } -void KMyMoneyView::showPage(KPageWidgetItem* pageItem) +void KMyMoneyView::showPage(View idView) { + const auto pageItem = viewFrames[idView]; // reset all selected items before showing the selected view // but not while we're in our own constructor if (!m_inConstructor && pageItem != currentPage()) { kmymoney->slotResetSelections(); } // pretend we're in the constructor to avoid calling the // above resets. For some reason which I don't know the details // of, KJanusWidget::showPage() calls itself recursively. This // screws up the action handling, as items could have been selected // in the meantime. We prevent this by setting the m_inConstructor // to true and reset it to the previos value when we leave this method. bool prevConstructor = m_inConstructor; m_inConstructor = true; setCurrentPage(pageItem); m_inConstructor = prevConstructor; if (!m_inConstructor) { // fixup some actions that are dependant on the view // this does not work during construction kmymoney->slotUpdateActions(); } } bool KMyMoneyView::canPrint() { bool rc = ( viewFrames[View::Reports] == currentPage() || viewFrames[View::Home] == currentPage() ); return rc; } void KMyMoneyView::enableViewsIfFileOpen(bool fileOpen) { // call set enabled only if the state differs to avoid widgets 'bouncing on the screen' while doing this for (auto i = (int)View::Home; i < (int)View::None; ++i) if (viewFrames.contains(View(i))) if (viewFrames[View(i)]->isEnabled() != fileOpen) viewFrames[View(i)]->setEnabled(fileOpen); emit viewStateChanged(fileOpen); } void KMyMoneyView::switchToDefaultView() { - KPageWidgetItem* page; - if (KMyMoneySettings::startLastViewSelected() != 0) - page = viewFrames.value(static_cast(KMyMoneySettings::lastViewSelected())); - else - page = viewFrames[View::Home]; + const auto idView = KMyMoneySettings::startLastViewSelected() ? + static_cast(KMyMoneySettings::lastViewSelected()) : + View::Home; // if we currently see a different page, then select the right one - if (page != currentPage()) - showPage(page); + if (viewFrames.contains(idView) && viewFrames[idView] != currentPage()) + showPage(idView); } void KMyMoneyView::slotPayeeSelected(const QString& payee, const QString& account, const QString& transaction) { - showPage(viewFrames[View::Payees]); - m_payeesView->slotSelectPayeeAndTransaction(payee, account, transaction); + showPage(View::Payees); + static_cast(viewBases[View::Payees])->slotSelectPayeeAndTransaction(payee, account, transaction); } void KMyMoneyView::slotTagSelected(const QString& tag, const QString& account, const QString& transaction) { - showPage(viewFrames[View::Tags]); - m_tagsView->slotSelectTagAndTransaction(tag, account, transaction); + showPage(View::Tags); + static_cast(viewBases[View::Tags])->slotSelectTagAndTransaction(tag, account, transaction); } void KMyMoneyView::finishReconciliation(const MyMoneyAccount& /* account */) { Models::instance()->accountsModel()->slotReconcileAccount(MyMoneyAccount(), QDate(), MyMoneyMoney()); - m_ledgerView->slotSetReconcileAccount(MyMoneyAccount(), QDate(), MyMoneyMoney()); + static_cast(viewBases[View::Ledgers])->slotSetReconcileAccount(MyMoneyAccount(), QDate(), MyMoneyMoney()); } void KMyMoneyView::slotSetBaseCurrency(const MyMoneySecurity& baseCurrency) { if (!baseCurrency.id().isEmpty()) { QString baseId; try { baseId = MyMoneyFile::instance()->baseCurrency().id(); } catch (const MyMoneyException &e) { qDebug("%s", qPrintable(e.what())); } if (baseCurrency.id() != baseId) { MyMoneyFileTransaction ft; try { MyMoneyFile::instance()->setBaseCurrency(baseCurrency); ft.commit(); } catch (const MyMoneyException &e) { KMessageBox::sorry(this, i18n("Cannot set %1 as base currency: %2", baseCurrency.name(), e.what()), i18n("Set base currency")); } } AmountEdit::setStandardPrecision(MyMoneyMoney::denomToPrec(MyMoneyFile::instance()->baseCurrency().smallestAccountFraction())); KMyMoneyEdit::setStandardPrecision(MyMoneyMoney::denomToPrec(MyMoneyFile::instance()->baseCurrency().smallestAccountFraction())); } } void KMyMoneyView::viewAccountList(const QString& /*selectAccount*/) { if (viewFrames[View::Accounts] != currentPage()) - showPage(viewFrames[View::Accounts]); - m_accountsView->show(); + showPage(View::Accounts); + viewBases[View::Accounts]->show(); } void KMyMoneyView::slotRefreshViews() { + const auto& investmentsView = static_cast(viewBases[View::Investments]); + const auto& ledgersView = static_cast(viewBases[View::Ledgers]); // turn off sync between ledger and investment view - disconnect(m_investmentView, &KInvestmentView::accountSelected, m_ledgerView, static_cast(&KGlobalLedgerView::slotSelectAccount)); - disconnect(m_ledgerView, &KGlobalLedgerView::objectSelected, m_investmentView, static_cast(&KInvestmentView::slotSelectAccount)); - + disconnect(investmentsView, &KInvestmentView::accountSelected, ledgersView, static_cast(&KGlobalLedgerView::slotSelectAccount)); + disconnect(ledgersView, &KGlobalLedgerView::objectSelected, investmentsView, static_cast(&KInvestmentView::slotSelectAccount)); // TODO turn sync between ledger and investment view if selected by user if (KMyMoneySettings::syncLedgerInvestment()) { - connect(m_investmentView, &KInvestmentView::accountSelected, m_ledgerView, static_cast(&KGlobalLedgerView::slotSelectAccount)); - connect(m_ledgerView, &KGlobalLedgerView::objectSelected, m_investmentView, static_cast(&KInvestmentView::slotSelectAccount)); + connect(investmentsView, &KInvestmentView::accountSelected, ledgersView, static_cast(&KGlobalLedgerView::slotSelectAccount)); + connect(ledgersView, &KGlobalLedgerView::objectSelected, investmentsView, static_cast(&KInvestmentView::slotSelectAccount)); } showTitleBar(KMyMoneySettings::showTitleBar()); - m_accountsView->refresh(); - m_institutionsView->refresh(); - m_categoriesView->refresh(); - m_payeesView->refresh(); - m_tagsView->refresh(); - m_ledgerView->refresh(); - m_budgetView->refresh(); - m_homeView->refresh(); - m_investmentView->refresh(); - m_reportsView->refresh(); - m_scheduledView->refresh(); for (auto i = (int)View::Home; i < (int)View::None; ++i) if (viewBases.contains(View(i))) viewBases[View(i)]->refresh(); - m_payeesView->slotClosePayeeIdentifierSource(); + static_cast(viewBases[View::Payees])->slotClosePayeeIdentifierSource(); } void KMyMoneyView::slotShowTransactionDetail(bool detailed) { KMyMoneySettings::setShowRegisterDetailed(detailed); slotRefreshViews(); } void KMyMoneyView::slotCurrentPageChanged(const QModelIndex current, const QModelIndex) { // remember the current page m_lastViewSelected = current.row(); // set the current page's title in the header if (m_header) m_header->setText(m_model->data(current, KPageModel::HeaderRole).toString()); } void KMyMoneyView::createSchedule(MyMoneySchedule newSchedule, MyMoneyAccount& newAccount) { // Add the schedule only if one exists // // Remember to modify the first split to reference the newly created account if (!newSchedule.name().isEmpty()) { MyMoneyFileTransaction ft; try { // We assume at least 2 splits in the transaction MyMoneyTransaction t = newSchedule.transaction(); if (t.splitCount() < 2) { throw MYMONEYEXCEPTION("Transaction for schedule has less than 2 splits!"); } // now search the split that does not have an account reference // and set it up to be the one of the account we just added // to the account pool. Note: the schedule code used to leave // this always the first split, but the loan code leaves it as // the second one. So I thought, searching is a good alternative .... foreach (const auto split, t.splits()) { if (split.accountId().isEmpty()) { MyMoneySplit s = split; s.setAccountId(newAccount.id()); t.modifySplit(s); break; } } newSchedule.setTransaction(t); MyMoneyFile::instance()->addSchedule(newSchedule); // in case of a loan account, we keep a reference to this // schedule in the account if (newAccount.isLoan()) { newAccount.setValue("schedule", newSchedule.id()); MyMoneyFile::instance()->modifyAccount(newAccount); } ft.commit(); } catch (const MyMoneyException &e) { KMessageBox::information(this, i18n("Unable to add schedule: %1", e.what())); } } } void KMyMoneyView::slotPrintView() { if (viewFrames[View::Reports] == currentPage()) - m_reportsView->slotPrintView(); + static_cast(viewBases[View::Reports])->slotPrintView(); else if (viewFrames[View::Home] == currentPage()) - m_homeView->slotPrintView(); + static_cast(viewBases[View::Home])->slotPrintView(); } void KMyMoneyView::resetViewSelection(const View) { emit aboutToChangeView(); } void KMyMoneyView::connectView(const View view) { KMyMoneyAccountTreeView *treeView; + + if (!viewBases.contains(view)) + return; + + disconnect(viewBases[view], &KMyMoneyViewBase::aboutToShow, this, &KMyMoneyView::connectView); + switch (view) { case View::Home: - disconnect(m_homeView, &KHomeView::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_homeView, &KHomeView::objectSelected, this, &KMyMoneyView::slotObjectSelected); - connect(m_homeView, &KHomeView::openObjectRequested, this, &KMyMoneyView::slotOpenObjectRequested); + { + const auto homeView = static_cast(viewBases[view]); + connect(homeView, &KHomeView::objectSelected, this, &KMyMoneyView::slotObjectSelected); + connect(homeView, &KHomeView::openObjectRequested, this, &KMyMoneyView::slotOpenObjectRequested); // views can wait since they are going to be refresed in slotRefreshViews - connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, m_homeView, &KHomeView::refresh); + connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, homeView, &KHomeView::refresh); break; - + } case View::Accounts: - disconnect(m_accountsView, &KAccountsView::aboutToShow, this, &KMyMoneyView::connectView); - treeView = m_accountsView->getTreeView(); + { + const auto accountsView = static_cast(viewBases[view]); + treeView = static_cast(viewBases[view])->getTreeView(); connect(treeView, &KMyMoneyAccountTreeView::openObjectRequested, this, &KMyMoneyView::slotOpenObjectRequested); connect(treeView, &KMyMoneyAccountTreeView::contextMenuRequested, this, &KMyMoneyView::slotContextMenuRequested); connect(treeView, &KMyMoneyAccountTreeView::columnToggled, this, &KMyMoneyView::slotAccountTreeViewChanged); - connect(m_accountsView, &KAccountsView::objectSelected, this, &KMyMoneyView::slotObjectSelected); - connect(Models::instance()->accountsModel(), &AccountsModel::netWorthChanged, m_accountsView, &KAccountsView::slotNetWorthChanged); + connect(accountsView, &KAccountsView::objectSelected, this, &KMyMoneyView::slotObjectSelected); + connect(Models::instance()->accountsModel(), &AccountsModel::netWorthChanged, accountsView, &KAccountsView::slotNetWorthChanged); break; + } case View::Schedules: - disconnect(m_scheduledView, &KScheduledView::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_scheduledView, &KScheduledView::openObjectRequested, this, &KMyMoneyView::slotOpenObjectRequested); - connect(m_scheduledView, &KScheduledView::objectSelected, this, &KMyMoneyView::slotObjectSelected); - connect(m_scheduledView, &KScheduledView::contextMenuRequested, this, &KMyMoneyView::slotContextMenuRequested); + { + const auto schedulesView = static_cast(viewBases[view]); + connect(schedulesView, &KScheduledView::openObjectRequested, this, &KMyMoneyView::slotOpenObjectRequested); + connect(schedulesView, &KScheduledView::objectSelected, this, &KMyMoneyView::slotObjectSelected); + connect(schedulesView, &KScheduledView::contextMenuRequested, this, &KMyMoneyView::slotContextMenuRequested); break; + } case View::Institutions: - disconnect(m_institutionsView, &KInstitutionsView::aboutToShow, this, &KMyMoneyView::connectView); - treeView = m_institutionsView->getTreeView(); + { + const auto institutionsView = static_cast(viewBases[view]); + treeView = static_cast(viewBases[view])->getTreeView(); connect(treeView, &KMyMoneyAccountTreeView::openObjectRequested, this, &KMyMoneyView::slotOpenObjectRequested); connect(treeView, &KMyMoneyAccountTreeView::contextMenuRequested, this, &KMyMoneyView::slotContextMenuRequested); connect(treeView, &KMyMoneyAccountTreeView::columnToggled, this, &KMyMoneyView::slotAccountTreeViewChanged); - connect(m_institutionsView, &KInstitutionsView::objectSelected, this, &KMyMoneyView::slotObjectSelected); - connect(Models::instance()->institutionsModel(), &AccountsModel::netWorthChanged, m_institutionsView, &KInstitutionsView::slotNetWorthChanged); + connect(institutionsView, &KInstitutionsView::objectSelected, this, &KMyMoneyView::slotObjectSelected); + connect(Models::instance()->institutionsModel(), &AccountsModel::netWorthChanged, institutionsView, &KInstitutionsView::slotNetWorthChanged); break; + } case View::Categories: - disconnect(m_categoriesView, &KCategoriesView::aboutToShow, this, &KMyMoneyView::connectView); - treeView = m_categoriesView->getTreeView(); + { + const auto categoriesView = static_cast(viewBases[view]); + treeView = static_cast(viewBases[view])->getTreeView(); connect(treeView, &KMyMoneyAccountTreeView::openObjectRequested, this, &KMyMoneyView::slotOpenObjectRequested); connect(treeView, &KMyMoneyAccountTreeView::objectSelected, this, &KMyMoneyView::slotObjectSelected); connect(treeView, &KMyMoneyAccountTreeView::contextMenuRequested, this, &KMyMoneyView::slotContextMenuRequested); connect(treeView, &KMyMoneyAccountTreeView::columnToggled, this, &KMyMoneyView::slotAccountTreeViewChanged); - connect(m_categoriesView, &KCategoriesView::objectSelected, this, &KMyMoneyView::slotObjectSelected); - connect(Models::instance()->institutionsModel(), &AccountsModel::profitChanged, m_categoriesView, &KCategoriesView::slotProfitChanged); + connect(categoriesView, &KCategoriesView::objectSelected, this, &KMyMoneyView::slotObjectSelected); + connect(Models::instance()->institutionsModel(), &AccountsModel::profitChanged, categoriesView, &KCategoriesView::slotProfitChanged); break; + } case View::Tags: - disconnect(m_tagsView, &KTagsView::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_tagsView, &KTagsView::transactionSelected, m_ledgerView, &KGlobalLedgerView::slotLedgerSelected); + { + const auto tagsView = static_cast(viewBases[view]); + const auto ledgersView = static_cast(viewBases[View::Ledgers]); + connect(tagsView, &KTagsView::transactionSelected, ledgersView, &KGlobalLedgerView::slotLedgerSelected); break; + } case View::Payees: - disconnect(m_payeesView, &KTagsView::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_payeesView, &KPayeesView::transactionSelected, m_ledgerView, &KGlobalLedgerView::slotLedgerSelected); + { + const auto payeesView = static_cast(viewBases[view]); + const auto ledgersView = static_cast(viewBases[View::Ledgers]); + connect(payeesView, &KPayeesView::transactionSelected, ledgersView, &KGlobalLedgerView::slotLedgerSelected); break; + } case View::Ledgers: - disconnect(m_ledgerView, &KGlobalLedgerView::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_ledgerView, &KGlobalLedgerView::openObjectRequested, this, &KMyMoneyView::slotOpenObjectRequested); - connect(m_ledgerView, &KGlobalLedgerView::openPayeeRequested, this, &KMyMoneyView::slotPayeeSelected); - connect(m_ledgerView, &KGlobalLedgerView::objectSelected, this, &KMyMoneyView::slotObjectSelected); - connect(m_ledgerView, &KGlobalLedgerView::transactionsSelected, this, &KMyMoneyView::slotTransactionsSelected); - connect(m_ledgerView, &KGlobalLedgerView::contextMenuRequested, this, &KMyMoneyView::slotContextMenuRequested); - connect(m_ledgerView, &KGlobalLedgerView::transactionsContextMenuRequested, this, &KMyMoneyView::slotTransactionsMenuRequested); - connect(m_ledgerView, &KGlobalLedgerView::statusProgress, this, &KMyMoneyView::statusProgress); - connect(m_ledgerView, &KGlobalLedgerView::statusMsg, this, &KMyMoneyView::statusMsg); - - connect(m_ledgerView, &KGlobalLedgerView::accountReconciled, this, &KMyMoneyView::accountReconciled); - connect(m_ledgerView, &KGlobalLedgerView::enterOverdueSchedulesRequested, m_scheduledView, &KScheduledView::slotEnterOverdueSchedules); - connect(m_scheduledView, &KScheduledView::enterOverdueSchedulesFinished, m_ledgerView, &KGlobalLedgerView::slotContinueReconciliation); + { + const auto ledgersView = static_cast(viewBases[view]); + const auto schedulesView = static_cast(viewBases[View::Schedules]); + connect(ledgersView, &KGlobalLedgerView::openObjectRequested, this, &KMyMoneyView::slotOpenObjectRequested); + connect(ledgersView, &KGlobalLedgerView::openPayeeRequested, this, &KMyMoneyView::slotPayeeSelected); + connect(ledgersView, &KGlobalLedgerView::objectSelected, this, &KMyMoneyView::slotObjectSelected); + connect(ledgersView, &KGlobalLedgerView::transactionsSelected, this, &KMyMoneyView::slotTransactionsSelected); + connect(ledgersView, &KGlobalLedgerView::contextMenuRequested, this, &KMyMoneyView::slotContextMenuRequested); + connect(ledgersView, &KGlobalLedgerView::transactionsContextMenuRequested, this, &KMyMoneyView::slotTransactionsMenuRequested); + connect(ledgersView, &KGlobalLedgerView::statusProgress, this, &KMyMoneyView::statusProgress); + connect(ledgersView, &KGlobalLedgerView::statusMsg, this, &KMyMoneyView::statusMsg); + + connect(ledgersView, &KGlobalLedgerView::accountReconciled, this, &KMyMoneyView::accountReconciled); + connect(ledgersView, &KGlobalLedgerView::enterOverdueSchedulesRequested, schedulesView, &KScheduledView::slotEnterOverdueSchedules); + connect(schedulesView, &KScheduledView::enterOverdueSchedulesFinished, ledgersView, &KGlobalLedgerView::slotContinueReconciliation); break; + } case View::Budget: - disconnect(m_budgetView, &KBudgetView::aboutToShow, this, &KMyMoneyView::connectView); - treeView = m_budgetView->getTreeView(); + { + const auto budgetView = static_cast(viewBases[view]); + treeView = static_cast(viewBases[view])->getTreeView(); connect(treeView, &KMyMoneyAccountTreeView::openObjectRequested, this, &KMyMoneyView::slotOpenObjectRequested); connect(treeView, &KMyMoneyAccountTreeView::contextMenuRequested, this, &KMyMoneyView::slotContextMenuRequested); connect(treeView, &KMyMoneyAccountTreeView::columnToggled, this, &KMyMoneyView::slotAccountTreeViewChanged); - connect(m_budgetView, &KBudgetView::objectSelected, this, &KMyMoneyView::slotObjectSelected); + connect(budgetView, &KBudgetView::objectSelected, this, &KMyMoneyView::slotObjectSelected); break; + } case View::Investments: - disconnect(m_investmentView, &KInvestmentView::aboutToShow, this, &KMyMoneyView::connectView); - - connect(m_investmentView, &KInvestmentView::objectSelected, this, &KMyMoneyView::slotObjectSelected); - connect(m_investmentView, &KInvestmentView::contextMenuRequested, this, &KMyMoneyView::slotContextMenuRequested); + { + const auto investmentsView = static_cast(viewBases[view]); + connect(investmentsView, &KInvestmentView::objectSelected, this, &KMyMoneyView::slotObjectSelected); + connect(investmentsView, &KInvestmentView::contextMenuRequested, this, &KMyMoneyView::slotContextMenuRequested); break; + } case View::Reports: - disconnect(m_reportsView, &KReportsView::aboutToShow, this, &KMyMoneyView::connectView); - connect(m_reportsView, &KReportsView::transactionSelected, m_ledgerView, &KGlobalLedgerView::slotLedgerSelected); - break; - - case View::OnlineJobOutbox: - disconnect(m_onlineJobOutboxView, &KOnlineJobOutbox::aboutToShow, this, &KMyMoneyView::connectView); + { + const auto reportsView = static_cast(viewBases[view]); + const auto ledgersView = static_cast(viewBases[View::Ledgers]); + connect(reportsView, &KReportsView::transactionSelected, ledgersView, &KGlobalLedgerView::slotLedgerSelected); break; + } default: break; } } void KMyMoneyView::slotOpenObjectRequested(const MyMoneyObject& obj) { if (typeid(obj) == typeid(MyMoneyAccount)) { const auto& acc = static_cast(obj); // check if we can open this account // currently it make's sense for asset and liability accounts if (!MyMoneyFile::instance()->isStandardAccount(acc.id())) - m_ledgerView->slotLedgerSelected(acc.id(), QString()); + static_cast(viewBases[View::Ledgers])->slotLedgerSelected(acc.id(), QString()); } else if (typeid(obj) == typeid(MyMoneyInstitution)) { // const auto& inst = static_cast(obj); - m_institutionsView->slotEditInstitution(); + static_cast(viewBases[View::Institutions])->slotEditInstitution(); } else if (typeid(obj) == typeid(MyMoneySchedule)) { - m_scheduledView->slotEditSchedule(); + static_cast(viewBases[View::Schedules])->slotEditSchedule(); } else if (typeid(obj) == typeid(MyMoneyReport)) { const auto& rep = static_cast(obj); - m_reportsView->slotOpenReport(rep); + static_cast(viewBases[View::Reports])->slotOpenReport(rep); } } void KMyMoneyView::slotObjectSelected(const MyMoneyObject& obj) { // carrying some slots over to views isn't easy for all slots... // ...so calls to kmymoney still must be here if (typeid(obj) == typeid(MyMoneyAccount)) { - m_investmentView->updateActions(obj); - m_categoriesView->updateActions(obj); - m_accountsView->updateActions(obj); - m_ledgerView->updateActions(obj); - m_reportsView->updateActions(obj); - if (m_onlineJobOutboxView) { - m_onlineJobOutboxView->updateActions(obj); - } + QVector views {View::Investments, View::Categories, View::Accounts, + View::Ledgers, View::Reports, View::OnlineJobOutbox}; + for (const auto view : views) + if (viewBases.contains(view)) + viewBases[view]->updateActions(obj); // for plugin only const auto& acc = static_cast(obj); if (!acc.isIncomeExpense() && !MyMoneyFile::instance()->isStandardAccount(acc.id())) emit accountSelected(acc); } else if (typeid(obj) == typeid(MyMoneyInstitution)) { - m_institutionsView->updateActions(obj); + viewBases[View::Institutions]->updateActions(obj); } else if (typeid(obj) == typeid(MyMoneySchedule)) { - m_scheduledView->updateActions(obj); + viewBases[View::Schedules]->updateActions(obj); } } void KMyMoneyView::slotContextMenuRequested(const MyMoneyObject& obj) { if (typeid(obj) == typeid(MyMoneyAccount)) { const auto& acc = static_cast(obj); if (acc.isInvest()) { - m_investmentView->slotShowInvestmentMenu(acc); + static_cast(viewBases[View::Investments])->slotShowInvestmentMenu(acc); return; } else if (acc.isIncomeExpense()) { - m_categoriesView->slotShowCategoriesMenu(acc); + static_cast(viewBases[View::Categories])->slotShowCategoriesMenu(acc); } else { - m_accountsView->slotShowAccountMenu(acc); + static_cast(viewBases[View::Accounts])->slotShowAccountMenu(acc); } } else if (typeid(obj) == typeid(MyMoneyInstitution)) { const auto& inst = static_cast(obj); - m_institutionsView->slotShowInstitutionsMenu(inst); + static_cast(viewBases[View::Institutions])->slotShowInstitutionsMenu(inst); } else if (typeid(obj) == typeid(MyMoneySchedule)) { const auto& sch = static_cast(obj); - m_scheduledView->slotShowScheduleMenu(sch); + static_cast(viewBases[View::Schedules])->slotShowScheduleMenu(sch); } } void KMyMoneyView::slotTransactionsMenuRequested(const KMyMoneyRegister::SelectedTransactions& list) { Q_UNUSED(list) - m_ledgerView->slotShowTransactionMenu(MyMoneySplit()); + static_cast(viewBases[View::Ledgers])->slotShowTransactionMenu(MyMoneySplit()); } void KMyMoneyView::slotTransactionsSelected(const KMyMoneyRegister::SelectedTransactions& list) { - m_ledgerView->updateLedgerActions(list); + static_cast(viewBases[View::Ledgers])->updateLedgerActions(list); emit transactionsSelected(list); // for plugins } diff --git a/kmymoney/views/kmymoneyview.h b/kmymoney/views/kmymoneyview.h index ead90e6b2..b9b6313fb 100644 --- a/kmymoney/views/kmymoneyview.h +++ b/kmymoney/views/kmymoneyview.h @@ -1,385 +1,367 @@ /*************************************************************************** kmymoneyview.h ------------------- copyright : (C) 2000-2001 by Michael Edwardes 2004 by Thomas Baumgart 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 KMYMONEYVIEW_H #define KMYMONEYVIEW_H #include // ---------------------------------------------------------------------------- // QT Includes #include // ---------------------------------------------------------------------------- // KDE Includes #include // ---------------------------------------------------------------------------- // Project Includes #include "selectedtransactions.h" #ifdef KF5Activities_FOUND namespace KActivities { class ResourceInstance; } #endif namespace eAccountsModel { enum class Column; } namespace eMenu { enum class Action; } namespace KMyMoneyPlugin { class OnlinePlugin; } namespace KMyMoneyPlugin { class StoragePlugin; } namespace eDialogs { enum class ScheduleResultCode; } namespace Icons { enum class Icon; } class KMyMoneyApp; class KHomeView; class KAccountsView; class KCategoriesView; class KInstitutionsView; class KPayeesView; class KTagsView; class KBudgetView; class KScheduledView; class KGlobalLedgerView; class IMyMoneyOperationsFormat; class MyMoneyTransaction; class KInvestmentView; class KReportsView; class SimpleLedgerView; class MyMoneySchedule; class MyMoneySecurity; class MyMoneyReport; class TransactionEditor; class KOnlineJobOutbox; class KMyMoneyTitleLabel; class MyMoneyAccount; class MyMoneyMoney; class MyMoneyObject; class QLabel; class KMyMoneyViewBase; /** * This class represents the view of the MyMoneyFile which contains * Banks/Accounts/Transactions, Recurring transactions (or Bills & Deposits) * and scripts (yet to be implemented). Each different aspect of the file * is represented by a tab within the view. * * @author Michael Edwardes 2001 Copyright 2000-2001 * * @short Handles the view of the MyMoneyFile. */ enum class View; class KMyMoneyView : public KPageWidget { Q_OBJECT public: // file actions for plugin enum fileActions { preOpen, postOpen, preSave, postSave, preClose, postClose }; private: enum menuID { AccountNew = 1, AccountOpen, AccountReconcile, AccountEdit, AccountDelete, AccountOnlineMap, AccountOnlineUpdate, AccountOfxConnect, CategoryNew }; enum storageTypeE { Memory = 0, Database } _storageType; KPageWidgetModel* m_model; - KHomeView *m_homeView; - KAccountsView *m_accountsView; - KInstitutionsView *m_institutionsView; - KCategoriesView *m_categoriesView; - KPayeesView *m_payeesView; - KTagsView *m_tagsView; - KBudgetView *m_budgetView; - KScheduledView *m_scheduledView; - KGlobalLedgerView *m_ledgerView; - KInvestmentView *m_investmentView; - KReportsView* m_reportsView; - KOnlineJobOutbox* m_onlineJobOutboxView; - - #ifdef ENABLE_UNFINISHEDFEATURES - SimpleLedgerView* m_simpleLedgerView; - #endif - QHash viewFrames; QHash viewBases; KMyMoneyTitleLabel* m_header; bool m_inConstructor; int m_lastViewSelected; QMap* m_storagePlugins; #ifdef KF5Activities_FOUND private: KActivities::ResourceInstance * m_activityResourceInstance; #endif private: void viewAccountList(const QString& selectAccount); // Show the accounts view void createSchedule(MyMoneySchedule s, MyMoneyAccount& a); public: /** * The constructor for KMyMoneyView. Just creates all the tabs for the * different aspects of the MyMoneyFile. */ explicit KMyMoneyView(KMyMoneyApp *kmymoney); /** * Destructor */ ~KMyMoneyView(); /** * This method enables the state of all views (except home view) according * to an open file. */ void enableViewsIfFileOpen(bool fileOpen); void switchToDefaultView(); void switchToHomeView(); void addWidget(QWidget* w); - void showPage(KPageWidgetItem* pageItem); + void showPageAndFocus(View idView); + void showPage(View idView); /** * check if the current view allows to print something * * @retval true Yes, view allows to print * @retval false No, view cannot print */ bool canPrint(); void finishReconciliation(const MyMoneyAccount& account); void showTitleBar(bool show); /** * This method changes the view type according to the settings. */ void updateViewType(); void slotAccountTreeViewChanged(const eAccountsModel::Column column, const bool show); void setOnlinePlugins(QMap& plugins); void setStoragePlugins(QMap& plugins); // TODO: remove that function /** * ugly proxy function */ eDialogs::ScheduleResultCode enterSchedule(MyMoneySchedule& schedule, bool autoEnter, bool extendedKeys); void addView(KMyMoneyViewBase* view, const QString& name, View idView); void removeView(View idView); protected: /** * Overwritten because KMyMoney has it's custom header. */ virtual bool showPageHeader() const; public Q_SLOTS: /** * This slot writes information about the page passed as argument @a current * in the kmymoney.rc file so that it can be selected automatically when * the application is started again. * * @param current QModelIndex of the current page item * @param previous QModelIndex of the previous page item */ void slotCurrentPageChanged(const QModelIndex current, const QModelIndex previous); /** * Brings up a dialog to change the list(s) settings and saves them into the * class KMyMoneySettings (a singleton). * * @see KListSettingsDlg * Refreshes all views. Used e.g. after settings have been changed or * data has been loaded from external sources (QIF import). **/ void slotRefreshViews(); /** * Called, whenever the payees view should pop up and a specific * transaction in an account should be shown. * * @param payeeId The ID of the payee to be shown * @param accountId The ID of the account to be shown * @param transactionId The ID of the transaction to be selected */ void slotPayeeSelected(const QString& payeeId, const QString& accountId, const QString& transactionId); /** * Called, whenever the tags view should pop up and a specific * transaction in an account should be shown. * * @param tagId The ID of the tag to be shown * @param accountId The ID of the account to be shown * @param transactionId The ID of the transaction to be selected */ void slotTagSelected(const QString& tagId, const QString& accountId, const QString& transactionId); /** * This slot prints the current view. */ void slotPrintView(); /** * Called when the user changes the detail * setting of the transaction register * * @param detailed if true, the register is shown with all details */ void slotShowTransactionDetail(bool detailed); /** * Informs respective views about selected object, so they can * update action states and current object. * @param obj Account, Category, Investment, Stock, Institution */ void slotObjectSelected(const MyMoneyObject& obj); void slotTransactionsSelected(const KMyMoneyRegister::SelectedTransactions& list); void slotFileOpened(); void slotFileClosed(); private Q_SLOTS: /** * This slots switches the view to the specific page */ void slotShowHomePage(); void slotShowInstitutionsPage(); void slotShowAccountsPage(); void slotShowSchedulesPage(); void slotShowCategoriesPage(); void slotShowTagsPage(); void slotShowPayeesPage(); void slotShowLedgersPage(); void slotShowInvestmentsPage(); void slotShowReportsPage(); void slotShowBudgetPage(); void slotShowForecastPage(); void slotShowOutboxPage(); /** * Opens object in ledgers or edits in case of institution * @param obj Account, Category, Investment, Stock, Institution */ void slotOpenObjectRequested(const MyMoneyObject& obj); /** * Opens context menu based on objects's type * @param obj Account, Category, Investment, Stock, Institution */ void slotContextMenuRequested(const MyMoneyObject& obj); void slotTransactionsMenuRequested(const KMyMoneyRegister::SelectedTransactions& list); - void slotSwitchView(View view); - protected Q_SLOTS: /** * eventually replace this with KMyMoneyApp::slotCurrencySetBase(). * it contains the same code * * @deprecated */ void slotSetBaseCurrency(const MyMoneySecurity& baseCurrency); private: /** * Internal method used by slotAccountNew() and slotAccountCategory(). */ void accountNew(const bool createCategory); void resetViewSelection(const View); void connectView(const View); Q_SIGNALS: /** * This signal is emitted whenever a view is selected. * The parameter @p view is identified as one of KMyMoneyView::viewID. */ void viewActivated(int view); /** * This signal is emitted whenever a new view is about to be selected. */ void aboutToChangeView(); void accountSelectedForContextMenu(const MyMoneyAccount& acc); void viewStateChanged(bool enabled); /** * This signal is emitted to inform the kmmFile plugin when various file actions * occur. The Action parameter distinguishes between them. */ void kmmFilePlugin(unsigned int action); /** * @brief proxy signal */ void statusMsg(const QString& txt); /** * @brief proxy signal */ void statusProgress(int cnt, int base); void accountReconciled(const MyMoneyAccount& account, const QDate& date, const MyMoneyMoney& startingBalance, const MyMoneyMoney& endingBalance, const QList >& transactionList); /** * This signal is emitted when a transaction/list of transactions has been selected by * the GUI. If no transaction is selected or the selection is removed, * @p transactions is identical to an empty QList. This signal is used * by plugins to get information about changes. */ void transactionsSelected(const KMyMoneyRegister::SelectedTransactions& transactions); /** * This signal is emitted when a new account has been selected by * the GUI. If no account is selected or the selection is removed, * @a account is identical to MyMoneyAccount(). This signal is used * by plugins to get information about changes. */ void accountSelected(const MyMoneyAccount& account); }; #endif diff --git a/kmymoney/views/simpleledgerview.cpp b/kmymoney/views/simpleledgerview.cpp index 64fee888b..5ecb173e9 100644 --- a/kmymoney/views/simpleledgerview.cpp +++ b/kmymoney/views/simpleledgerview.cpp @@ -1,249 +1,258 @@ /*************************************************************************** simpleledgerview.cpp ------------------- begin : Sat Aug 8 2015 copyright : (C) 2015 by 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. * * * ***************************************************************************/ #include "simpleledgerview.h" // ---------------------------------------------------------------------------- // QT Includes #include // ---------------------------------------------------------------------------- // KDE Includes // ---------------------------------------------------------------------------- // Project Includes +#include "kmymoneyviewbase_p.h" #include "ledgerviewpage.h" #include "models.h" #include "accountsmodel.h" #include "kmymoneyaccountcombo.h" #include "ui_simpleledgerview.h" #include "icons/icons.h" -#include "kmymoneyview.h" #include "mymoneyfile.h" #include "mymoneyaccount.h" #include "mymoneyenums.h" #include "modelenums.h" using namespace Icons; -class SimpleLedgerView::Private +class SimpleLedgerViewPrivate : public KMyMoneyViewBasePrivate { + Q_DECLARE_PUBLIC(SimpleLedgerView) + public: - Private(SimpleLedgerView* p) - : parent(p) + explicit SimpleLedgerViewPrivate(SimpleLedgerView* qq) + : q_ptr(qq) , ui(new Ui_SimpleLedgerView) - , accountsModel(new AccountNamesFilterProxyModel(parent)) , newTabWidget(0) , lastIdx(-1) , inModelUpdate(false) , m_needLoad(true) {} - ~Private() {} + ~SimpleLedgerViewPrivate() + { + delete ui; + } + + void init() + { + Q_Q(SimpleLedgerView); + m_needLoad = false; + ui->setupUi(q); + ui->ledgerTab->setTabIcon(0, Icons::get(Icon::ListAdd)); + ui->ledgerTab->setTabText(0, QString()); + newTabWidget = ui->ledgerTab->widget(0); + + accountsModel= new AccountNamesFilterProxyModel(q); + + // remove close button from new page + QTabBar* bar = ui->ledgerTab->findChild(); + if(bar) { + QTabBar::ButtonPosition closeSide = (QTabBar::ButtonPosition)q->style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, newTabWidget); + QWidget *w = bar->tabButton(0, closeSide); + bar->setTabButton(0, closeSide, 0); + w->deleteLater(); + q->connect(bar, SIGNAL(tabMoved(int,int)), q, SLOT(checkTabOrder(int,int))); + } + + q->connect(ui->accountCombo, SIGNAL(accountSelected(QString)), q, SLOT(openNewLedger(QString))); + q->connect(ui->ledgerTab, &QTabWidget::currentChanged, q, &SimpleLedgerView::tabSelected); + q->connect(Models::instance(), &Models::modelsLoaded, q, &SimpleLedgerView::updateModels); + q->connect(ui->ledgerTab, &QTabWidget::tabCloseRequested, q, &SimpleLedgerView::closeLedger); - SimpleLedgerView* parent; + accountsModel->addAccountGroup(QVector {eMyMoney::Account::Type::Asset, eMyMoney::Account::Type::Liability, eMyMoney::Account::Type::Equity}); + + accountsModel->setHideEquityAccounts(false); + auto const model = Models::instance()->accountsModel(); + accountsModel->setSourceModel(model); + accountsModel->setSourceColumns(model->getColumns()); + accountsModel->sort((int)eAccountsModel::Column::Account); + ui->accountCombo->setModel(accountsModel); + + q->tabSelected(0); + q->updateModels(); + q->openFavoriteLedgers(); + } + + SimpleLedgerView* q_ptr; Ui_SimpleLedgerView* ui; AccountNamesFilterProxyModel* accountsModel; QWidget* newTabWidget; int lastIdx; bool inModelUpdate; bool m_needLoad; }; -SimpleLedgerView::SimpleLedgerView(KMyMoneyApp *kmymoney, KMyMoneyView *kmymoneyview) - : QWidget(nullptr) - , d(new Private(this)) - , m_kmymoney(kmymoney) - , m_kmymoneyview(kmymoneyview) +SimpleLedgerView::SimpleLedgerView(QWidget *parent) : + KMyMoneyViewBase(*new SimpleLedgerViewPrivate(this), parent) { } SimpleLedgerView::~SimpleLedgerView() { - if (!d->m_needLoad) - delete d->ui; - delete d; -} - -void SimpleLedgerView::init() -{ - d->m_needLoad = false; - d->ui->setupUi(this); - d->ui->ledgerTab->setTabIcon(0, Icons::get(Icon::ListAdd)); - d->ui->ledgerTab->setTabText(0, QString()); - d->newTabWidget = d->ui->ledgerTab->widget(0); - - // remove close button from new page - QTabBar* bar = d->ui->ledgerTab->findChild(); - if(bar) { - QTabBar::ButtonPosition closeSide = (QTabBar::ButtonPosition)style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, d->newTabWidget); - QWidget *w = bar->tabButton(0, closeSide); - bar->setTabButton(0, closeSide, 0); - w->deleteLater(); - connect(bar, SIGNAL(tabMoved(int,int)), this, SLOT(checkTabOrder(int,int))); - } - - connect(d->ui->accountCombo, SIGNAL(accountSelected(QString)), this, SLOT(openNewLedger(QString))); - connect(d->ui->ledgerTab, &QTabWidget::currentChanged, this, &SimpleLedgerView::tabSelected); - connect(Models::instance(), &Models::modelsLoaded, this, &SimpleLedgerView::updateModels); - connect(d->ui->ledgerTab, &QTabWidget::tabCloseRequested, this, &SimpleLedgerView::closeLedger); - - d->accountsModel->addAccountGroup(QVector {eMyMoney::Account::Type::Asset, eMyMoney::Account::Type::Liability, eMyMoney::Account::Type::Equity}); - - d->accountsModel->setHideEquityAccounts(false); - auto const model = Models::instance()->accountsModel(); - d->accountsModel->setSourceModel(model); - d->accountsModel->setSourceColumns(model->getColumns()); - d->accountsModel->sort((int)eAccountsModel::Column::Account); - d->ui->accountCombo->setModel(d->accountsModel); - - tabSelected(0); - updateModels(); - openFavoriteLedgers(); } void SimpleLedgerView::openNewLedger(QString accountId) { + Q_D(SimpleLedgerView); if(d->inModelUpdate || accountId.isEmpty()) return; LedgerViewPage* view = 0; // check if ledger is already opened for(int idx=0; idx < d->ui->ledgerTab->count()-1; ++idx) { view = qobject_cast(d->ui->ledgerTab->widget(idx)); if(view) { if(accountId == view->accountId()) { d->ui->ledgerTab->setCurrentIndex(idx); return; } } } // need a new tab, we insert it before the rightmost one QModelIndex index = Models::instance()->accountsModel()->accountById(accountId); if(index.isValid()) { // create new ledger view page MyMoneyAccount acc = Models::instance()->accountsModel()->data(index, (int)eAccountsModel::Role::Account).value(); view = new LedgerViewPage(this); view->setShowEntryForNewTransaction(); view->setAccount(acc); /// @todo setup current global setting for form visibility // view->showTransactionForm(...); // insert new ledger view page in tab view int newIdx = d->ui->ledgerTab->insertTab(d->ui->ledgerTab->count()-1, view, acc.name()); d->ui->ledgerTab->setCurrentIndex(d->ui->ledgerTab->count()-1); d->ui->ledgerTab->setCurrentIndex(newIdx); } } void SimpleLedgerView::tabSelected(int idx) { + Q_D(SimpleLedgerView); // qDebug() << "tabSelected" << idx << (d->ui->ledgerTab->count()-1); if(idx != (d->ui->ledgerTab->count()-1)) { d->lastIdx = idx; } } void SimpleLedgerView::updateModels() { + Q_D(SimpleLedgerView); d->inModelUpdate = true; // d->ui->accountCombo-> d->ui->accountCombo->expandAll(); d->ui->accountCombo->setSelected(MyMoneyFile::instance()->asset().id()); d->inModelUpdate = false; } void SimpleLedgerView::closeLedger(int idx) { + Q_D(SimpleLedgerView); // don't react on the close request for the new ledger function if(idx != (d->ui->ledgerTab->count()-1)) { d->ui->ledgerTab->removeTab(idx); } } void SimpleLedgerView::checkTabOrder(int from, int to) { + Q_D(SimpleLedgerView); if(d->inModelUpdate) return; QTabBar* bar = d->ui->ledgerTab->findChild(); if(bar) { const int rightMostIdx = d->ui->ledgerTab->count()-1; if(from == rightMostIdx) { // someone tries to move the new account tab away from the rightmost position d->inModelUpdate = true; bar->moveTab(to, from); d->inModelUpdate = false; } } } void SimpleLedgerView::showTransactionForm(bool show) { emit showForms(show); } void SimpleLedgerView::closeLedgers() { + Q_D(SimpleLedgerView); if (d->m_needLoad) return; auto tabCount = d->ui->ledgerTab->count(); // check that we have a least one tab that can be closed if(tabCount > 1) { // we keep the tab with the selector open at all times // which is located in the right most position --tabCount; do { --tabCount; closeLedger(tabCount); } while(tabCount > 0); } } void SimpleLedgerView::openFavoriteLedgers() { + Q_D(SimpleLedgerView); if (d->m_needLoad) return; AccountsModel* model = Models::instance()->accountsModel(); QModelIndex start = model->index(0, 0); QModelIndexList indexes = model->match(start, (int)eAccountsModel::Role::Favorite, QVariant(true), -1, Qt::MatchRecursive); // indexes now has a list of favorite accounts but two entries for each. // that doesn't matter here, since openNewLedger() can handle duplicates Q_FOREACH(QModelIndex index, indexes) { openNewLedger(model->data(index, (int)eAccountsModel::Role::ID).toString()); } d->ui->ledgerTab->setCurrentIndex(0); } void SimpleLedgerView::showEvent(QShowEvent* event) { + Q_D(SimpleLedgerView); if (d->m_needLoad) - init(); + d->init(); // don't forget base class implementation QWidget::showEvent(event); } diff --git a/kmymoney/views/simpleledgerview.h b/kmymoney/views/simpleledgerview.h index 7132ac361..22d7ec721 100644 --- a/kmymoney/views/simpleledgerview.h +++ b/kmymoney/views/simpleledgerview.h @@ -1,83 +1,73 @@ /*************************************************************************** simpleledgerview.h ------------------- begin : Sat Aug 8 2015 copyright : (C) 2015 by 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 SIMPLELEDGERVIEW_H #define SIMPLELEDGERVIEW_H // ---------------------------------------------------------------------------- // QT Includes -#include - // ---------------------------------------------------------------------------- // KDE Includes // ---------------------------------------------------------------------------- // Project Includes +#include "kmymoneyviewbase.h" -class KMyMoneyApp; -class KMyMoneyView; - -class SimpleLedgerView : public QWidget +class SimpleLedgerViewPrivate; +class SimpleLedgerView : public KMyMoneyViewBase { Q_OBJECT + public: - explicit SimpleLedgerView(KMyMoneyApp *kmymoney, KMyMoneyView *kmymoneyview); - virtual ~SimpleLedgerView(); + explicit SimpleLedgerView(QWidget *parent = nullptr); + ~SimpleLedgerView() override; virtual void showTransactionForm(bool = true); public Q_SLOTS: /** * This method closes all open ledgers */ void closeLedgers(); /** * This slot creates tabs for the favorite ledgers if not already open */ void openFavoriteLedgers(); - void showEvent(QShowEvent* event); + void showEvent(QShowEvent* event) override; protected: protected Q_SLOTS: void tabSelected(int idx); void openNewLedger(QString accountId); void updateModels(); void closeLedger(int idx); void checkTabOrder(int from, int to); Q_SIGNALS: void showForms(bool show); private: - class Private; - Private * const d; - - KMyMoneyApp *m_kmymoney; - KMyMoneyView *m_kmymoneyview; - - /** Initializes page and sets its load status to initialized - */ - void init(); + Q_DECLARE_PRIVATE(SimpleLedgerView) }; #endif // SIMPLELEDGERVIEW_H diff --git a/kmymoney/views/viewenums.h b/kmymoney/views/viewenums.h index bdbfda9bd..aa843860c 100644 --- a/kmymoney/views/viewenums.h +++ b/kmymoney/views/viewenums.h @@ -1,42 +1,42 @@ /*************************************************************************** viewenums.h ------------------- copyright : (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 VIEWENUMS_H #define VIEWENUMS_H #include enum class View { Home = 0, Institutions, Accounts, Schedules, Categories, Tags, - Payees, Ledgers, Investments, Reports, Budget, Forecast, OnlineJobOutbox, None }; + Payees, Ledgers, Investments, Reports, Budget, Forecast, OnlineJobOutbox, NewLedgers, None }; inline uint qHash(const View key, uint seed) { return ::qHash(static_cast(key), seed); } namespace eView { enum class Tag { All = 0, Referenced, // used tags Unused, // unused tags Opened, // not closed tags Closed // closed tags }; namespace Schedules { enum class Requester { Reconciliation }; } } #endif