diff --git a/kmymoney/CMakeLists.txt b/kmymoney/CMakeLists.txt --- a/kmymoney/CMakeLists.txt +++ b/kmymoney/CMakeLists.txt @@ -151,6 +151,7 @@ KChart $<$:Qt5::Test> $<$:KF5::Holidays> + $<$:KF5::Activities> ) # own plist magic for mac os diff --git a/kmymoney/kmymoney.h b/kmymoney/kmymoney.h --- a/kmymoney/kmymoney.h +++ b/kmymoney/kmymoney.h @@ -94,11 +94,6 @@ Q_OBJECT private Q_SLOTS: - /** - * Keep track of objects that are destroyed by external events - */ - void slotObjectDestroyed(QObject* o); - /** * Add a context menu to the list used by KMessageBox::informationList to display the consistency check results. */ @@ -209,17 +204,6 @@ void slotShowNextView(); - /** - * Brings up a dialog to let the user search for specific transaction(s). It then - * opens a results window to display those transactions. - */ - void slotFindTransaction(); - - /** - * Destroys a possibly open the search dialog - */ - void slotCloseSearchDialog(); - /** * Calls the print logic for the current view */ diff --git a/kmymoney/kmymoney.cpp b/kmymoney/kmymoney.cpp --- a/kmymoney/kmymoney.cpp +++ b/kmymoney/kmymoney.cpp @@ -75,6 +75,9 @@ #include #include #endif +#ifdef KF5Activities_FOUND +#include +#endif // ---------------------------------------------------------------------------- // Project Includes @@ -90,7 +93,6 @@ #include "dialogs/kcurrencyeditdlg.h" #include "dialogs/kequitypriceupdatedlg.h" #include "dialogs/kmymoneyfileinfodlg.h" -#include "dialogs/kfindtransactiondlg.h" #include "dialogs/knewbankdlg.h" #include "wizards/newinvestmentwizard/knewinvestmentwizard.h" #include "dialogs/knewaccountdlg.h" @@ -211,8 +213,6 @@ public: Private(KMyMoneyApp *app) : q(app), - m_ft(0), - m_moveToAccountSelector(0), m_statementXMLindex(0), m_balanceWarning(0), m_backupState(backupStateE::BACKUP_IDLE), @@ -226,20 +226,20 @@ m_startDialog(false), m_progressBar(nullptr), m_statusLabel(nullptr), - m_searchDlg(nullptr), m_autoSaveEnabled(true), m_autoSaveTimer(nullptr), m_progressTimer(nullptr), m_autoSavePeriod(0), m_inAutoSaving(false), - m_transactionEditor(nullptr), - m_endingBalanceDlg(nullptr), m_saveEncrypted(nullptr), m_additionalKeyLabel(nullptr), m_additionalKeyButton(nullptr), m_recentFiles(nullptr), #ifdef KF5Holidays_FOUND - m_holidayRegion(0), + m_holidayRegion(nullptr), +#endif +#ifdef KF5Activities_FOUND + m_activityResourceInstance(nullptr), #endif m_applicationIsReady(true), m_webConnect(new WebConnect(app)) { @@ -265,8 +265,6 @@ */ KMyMoneyApp * const q; - MyMoneyFileTransaction* m_ft; - KMyMoneyAccountSelector* m_moveToAccountSelector; int m_statementXMLindex; KBalanceWarning* m_balanceWarning; @@ -327,21 +325,14 @@ // allows multiple imports to be launched trough web connect and to be executed sequentially QQueue m_importUrlsQueue; - KFindTransactionDlg* m_searchDlg; // This is Auto Saving related bool m_autoSaveEnabled; QTimer* m_autoSaveTimer; QTimer* m_progressTimer; int m_autoSavePeriod; bool m_inAutoSaving; - // pointer to the current transaction editor - TransactionEditor* m_transactionEditor; - - // Reconciliation dialog - KEndingBalanceDlg* m_endingBalanceDlg; - // Pointer to the combo box used for key selection during // File/Save as KComboBox* m_saveEncrypted; @@ -359,6 +350,11 @@ // used by the calendar interface for schedules KHolidays::HolidayRegion* m_holidayRegion; #endif + +#ifdef KF5Activities_FOUND + KActivities::ResourceInstance * m_activityResourceInstance; +#endif + QBitArray m_processingDays; QMap m_holidayMap; QStringList m_consistencyCheckResult; @@ -1664,15 +1660,28 @@ pMenus = initMenus(); d->newStorage(); - d->m_myMoneyView = new KMyMoneyView(this/*the global variable kmymoney is not yet assigned. So we pass it here*/); + d->m_myMoneyView = new KMyMoneyView; layout->addWidget(d->m_myMoneyView, 10); connect(d->m_myMoneyView, &KMyMoneyView::aboutToChangeView, this, &KMyMoneyApp::slotResetSelections); connect(d->m_myMoneyView, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), this, SLOT(slotUpdateActions())); connect(d->m_myMoneyView, &KMyMoneyView::statusMsg, this, &KMyMoneyApp::slotStatusMsg); connect(d->m_myMoneyView, &KMyMoneyView::statusProgress, this, &KMyMoneyApp::slotStatusProgressBar); + connect(this, &KMyMoneyApp::fileLoaded, d->m_myMoneyView, &KMyMoneyView::slotRefreshViews); + + // Initialize kactivities resource instance +#ifdef KF5Activities_FOUND + d->m_activityResourceInstance = new KActivities::ResourceInstance(window()->winId(), this); + connect(this, &KMyMoneyApp::fileLoaded, d->m_activityResourceInstance, &KActivities::ResourceInstance::setUri); +#endif + + const auto viewActions = d->m_myMoneyView->actionsToBeConnected(); + actionCollection()->addActions(viewActions.values()); + for (auto it = viewActions.cbegin(); it != viewActions.cend(); ++it) + pActions.insert(it.key(), it.value()); + /////////////////////////////////////////////////////////////////// // call inits to invoke all other construction parts readOptions(); @@ -1732,13 +1741,14 @@ // we need to unload all plugins before we destroy anything else KMyMoneyPlugin::pluginHandling(KMyMoneyPlugin::Action::Unload, d->m_plugins, this, guiFactory()); - delete d->m_searchDlg; - delete d->m_transactionEditor; - delete d->m_endingBalanceDlg; - delete d->m_moveToAccountSelector; #ifdef KF5Holidays_FOUND delete d->m_holidayRegion; #endif + +#ifdef KF5Activities_FOUND + delete d->m_activityResourceInstance; +#endif + delete d; } @@ -1755,13 +1765,6 @@ return url; } -void KMyMoneyApp::slotObjectDestroyed(QObject* o) -{ - if (o == d->m_moveToAccountSelector) { - d->m_moveToAccountSelector = 0; - } -} - void KMyMoneyApp::slotInstallConsistencyCheckContextMenu() { // this code relies on the implementation of KMessageBox::informationList to add a context menu to that list, @@ -1824,6 +1827,13 @@ { auto aC = actionCollection(); + /* Look-up table for all custom and standard actions. + It's required for: + 1) building QList with QActions to be added to ActionCollection + 2) adding custom features to QActions like e.g. keyboard shortcut + */ + QHash lutActions; + // ************* // Adding standard actions // ************* @@ -1834,16 +1844,9 @@ KStandardAction::saveAs(this, &KMyMoneyApp::slotFileSaveAs, aC); KStandardAction::close(this, &KMyMoneyApp::slotFileClose, aC); KStandardAction::quit(this, &KMyMoneyApp::slotFileQuit, aC); - KStandardAction::print(this, &KMyMoneyApp::slotPrintView, aC); + lutActions.insert(Action::Print, KStandardAction::print(this, &KMyMoneyApp::slotPrintView, aC)); KStandardAction::preferences(this, &KMyMoneyApp::slotSettings, aC); - /* Look-up table for all custom actions. - It's required for: - 1) building QList with QActions to be added to ActionCollection - 2) adding custom features to QActions like e.g. keyboard shortcut - */ - QHash lutActions; - // ************* // Adding all actions // ************* @@ -2016,10 +2019,6 @@ #endif {Action::FileInformation, &KMyMoneyApp::slotFileInfoDialog}, // ************* - // The Edit menu - // ************* - {Action::EditFindTransaction, &KMyMoneyApp::slotFindTransaction}, - // ************* // The View menu // ************* {Action::ViewTransactionDetail, &KMyMoneyApp::slotShowTransactionDetail}, @@ -3364,26 +3363,6 @@ KRun::runCommand(cmd, this); } -void KMyMoneyApp::slotFindTransaction() -{ - if (d->m_searchDlg == 0) { - d->m_searchDlg = new KFindTransactionDlg(this); - connect(d->m_searchDlg, SIGNAL(destroyed()), this, SLOT(slotCloseSearchDialog())); - connect(d->m_searchDlg, SIGNAL(transactionSelected(QString,QString)), - this, SIGNAL(transactionSelected(QString,QString))); - } - d->m_searchDlg->show(); - d->m_searchDlg->raise(); - d->m_searchDlg->activateWindow(); -} - -void KMyMoneyApp::slotCloseSearchDialog() -{ - if (d->m_searchDlg) - d->m_searchDlg->deleteLater(); - d->m_searchDlg = 0; -} - void KMyMoneyApp::createAccount(MyMoneyAccount& newAccount, MyMoneyAccount& parentAccount, MyMoneyAccount& brokerageAccount, MyMoneyMoney openingBal) { MyMoneyFile *file = MyMoneyFile::instance(); @@ -3480,7 +3459,7 @@ KMSTATUS(i18n("Running automatic reconciliation")); int progressBarIndex = 0; - kmymoney->slotStatusProgressBar(progressBarIndex, NR_OF_STEPS_LIMIT / PROGRESSBAR_STEPS); + q->slotStatusProgressBar(progressBarIndex, NR_OF_STEPS_LIMIT / PROGRESSBAR_STEPS); // optimize the most common case - all transactions should be cleared QListIterator > itTransactionSplitResult(result); @@ -3493,7 +3472,7 @@ result = transactions; return result; } - kmymoney->slotStatusProgressBar(progressBarIndex++, 0); + q->slotStatusProgressBar(progressBarIndex++, 0); // only one transaction is uncleared itTransactionSplitResult.toFront(); int index = 0; @@ -3505,7 +3484,7 @@ } index++; } - kmymoney->slotStatusProgressBar(progressBarIndex++, 0); + q->slotStatusProgressBar(progressBarIndex++, 0); // more than one transaction is uncleared - apply the algorithm result.clear(); @@ -3538,7 +3517,7 @@ sumToComponentsMap[transactionSplit.second.shares() + sum] = splitIds; int size = sumToComponentsMap.size(); if (size % PROGRESSBAR_STEPS == 0) { - kmymoney->slotStatusProgressBar(progressBarIndex++, 0); + q->slotStatusProgressBar(progressBarIndex++, 0); } if (size > NR_OF_STEPS_LIMIT) { return result; // it's taking too much resources abort the algorithm @@ -3561,7 +3540,7 @@ } } - kmymoney->slotStatusProgressBar(NR_OF_STEPS_LIMIT / PROGRESSBAR_STEPS, 0); + q->slotStatusProgressBar(NR_OF_STEPS_LIMIT / PROGRESSBAR_STEPS, 0); if (sumToComponentsMap.contains(amount)) { QListIterator > itTransactionSplit(transactions); while (itTransactionSplit.hasNext()) { @@ -3578,7 +3557,7 @@ qPrintable(MyMoneyUtils::formatMoney(amount, security)), sumToComponentsMap.size(), transactions.size()); #endif - kmymoney->slotStatusProgressBar(-1, -1); + q->slotStatusProgressBar(-1, -1); return result; } @@ -4102,8 +4081,8 @@ // Make sure we have an open file if (! d->m_fileOpen && - KMessageBox::warningContinueCancel(kmymoney, i18n("You must first select a KMyMoney file before you can import a statement.")) == KMessageBox::Continue) - kmymoney->slotFileOpen(); + KMessageBox::warningContinueCancel(this, i18n("You must first select a KMyMoney file before you can import a statement.")) == KMessageBox::Continue) + slotFileOpen(); // only continue if the user really did open a file. if (d->m_fileOpen) { diff --git a/kmymoney/menus/menuenums.h b/kmymoney/menus/menuenums.h --- a/kmymoney/menus/menuenums.h +++ b/kmymoney/menus/menuenums.h @@ -32,6 +32,7 @@ FileOpenDatabase, FileSaveAsDatabase, FileBackup, FileImportStatement, FileImportTemplate, FileExportTemplate, + Print, #ifdef KMM_DEBUG FileDump, #endif @@ -118,6 +119,14 @@ NewBudget, RenameBudget, DeleteBudget, CopyBudget, ChangeBudgetYear, BudgetForecast, // ************* + // The show actions + // ************* + ShowHomeView, ShowInstitutionsView, ShowAccountsView, + ShowSchedulesView, ShowCategoriesView, ShowTagsView, + ShowPayeesView, ShowLedgersView, ShowInvestmentsView, + ShowReportsView, ShowBudgetView, ShowForecastView, + ShowOnlineJobOutboxView, + // ************* // The misc actions // ************* #ifdef KMM_DEBUG diff --git a/kmymoney/views/CMakeLists.txt b/kmymoney/views/CMakeLists.txt --- a/kmymoney/views/CMakeLists.txt +++ b/kmymoney/views/CMakeLists.txt @@ -70,10 +70,6 @@ target_link_libraries(views PUBLIC KF5::WebKit) endif(ENABLE_WEBENGINE) -if(KF5Activities_FOUND) - target_link_libraries(views PRIVATE KF5::Activities) -endif() - # TODO: Remove this dependency. But it is needed as long as the payee editor uses these objects directly # This should be replaced by virtual methods in a pure abstract object. target_link_libraries( views PUBLIC diff --git a/kmymoney/views/kgloballedgerview.h b/kmymoney/views/kgloballedgerview.h --- a/kmymoney/views/kgloballedgerview.h +++ b/kmymoney/views/kgloballedgerview.h @@ -303,6 +303,18 @@ void slotFinishReconciliation(); void slotPostponeReconciliation(); void slotOpenAccount(); + + /** + * Brings up a dialog to let the user search for specific transaction(s). It then + * opens a results window to display those transactions. + */ + void slotFindTransaction(); + + /** + * Destroys a possibly open the search dialog + */ + void slotCloseSearchDialog(); + void slotStatusMsg(const QString& txt); void slotStatusProgress(int cnt, int base); void slotTransactionsSelected(const KMyMoneyRegister::SelectedTransactions& list); diff --git a/kmymoney/views/kgloballedgerview.cpp b/kmymoney/views/kgloballedgerview.cpp --- a/kmymoney/views/kgloballedgerview.cpp +++ b/kmymoney/views/kgloballedgerview.cpp @@ -98,7 +98,8 @@ {Action::StartReconciliation, &KGlobalLedgerView::slotStartReconciliation}, {Action::FinishReconciliation, &KGlobalLedgerView::slotFinishReconciliation}, {Action::PostponeReconciliation, &KGlobalLedgerView::slotPostponeReconciliation}, - {Action::OpenAccount, &KGlobalLedgerView::slotOpenAccount} + {Action::OpenAccount, &KGlobalLedgerView::slotOpenAccount}, + {Action::EditFindTransaction, &KGlobalLedgerView::slotFindTransaction}, }; for (auto a = actionConnections.cbegin(); a != actionConnections.cend(); ++a) @@ -2033,6 +2034,28 @@ slotLedgerSelected(d->m_currentAccount.id(), QString()); } +void KGlobalLedgerView::slotFindTransaction() +{ + Q_D(KGlobalLedgerView); + if (!d->m_searchDlg) { + d->m_searchDlg = new KFindTransactionDlg(this); + connect(d->m_searchDlg, &QObject::destroyed, this, &KGlobalLedgerView::slotCloseSearchDialog); + connect(d->m_searchDlg, &KFindTransactionDlg::transactionSelected, + this, &KGlobalLedgerView::slotLedgerSelected); + } + d->m_searchDlg->show(); + d->m_searchDlg->raise(); + d->m_searchDlg->activateWindow(); +} + +void KGlobalLedgerView::slotCloseSearchDialog() +{ + Q_D(KGlobalLedgerView); + if (d->m_searchDlg) + d->m_searchDlg->deleteLater(); + d->m_searchDlg = nullptr; +} + void KGlobalLedgerView::slotStatusMsg(const QString& txt) { emit selectByVariant(QVariantList {QVariant(txt)}, eView::Intent::ReportProgressMessage); diff --git a/kmymoney/views/kgloballedgerview_p.h b/kmymoney/views/kgloballedgerview_p.h --- a/kmymoney/views/kgloballedgerview_p.h +++ b/kmymoney/views/kgloballedgerview_p.h @@ -48,6 +48,7 @@ #include "kmymoneyviewbase_p.h" #include "kendingbalancedlg.h" +#include "kfindtransactiondlg.h" #include "kmymoneyaccountselector.h" #include "kmymoneyutils.h" #include "mymoneyexception.h" @@ -254,14 +255,16 @@ m_transactionEditor(nullptr), m_balanceWarning(nullptr), m_moveToAccountSelector(nullptr), - m_endingBalanceDlg(nullptr) + m_endingBalanceDlg(nullptr), + m_searchDlg(nullptr) { } ~KGlobalLedgerViewPrivate() { delete m_moveToAccountSelector; delete m_endingBalanceDlg; + delete m_searchDlg; } void init() @@ -1640,6 +1643,7 @@ // Reconciliation dialog KEndingBalanceDlg* m_endingBalanceDlg; + KFindTransactionDlg* m_searchDlg; }; #endif diff --git a/kmymoney/views/kmymoneyview.h b/kmymoney/views/kmymoneyview.h --- a/kmymoney/views/kmymoneyview.h +++ b/kmymoney/views/kmymoneyview.h @@ -121,16 +121,10 @@ 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 @@ -141,7 +135,7 @@ * The constructor for KMyMoneyView. Just creates all the tabs for the * different aspects of the MyMoneyFile. */ - explicit KMyMoneyView(KMyMoneyApp *kmymoney); + KMyMoneyView(); /** * Destructor @@ -192,6 +186,13 @@ void addView(KMyMoneyViewBase* view, const QString& name, View idView); void removeView(View idView); + /** + * @brief actionsToBeConnected are actions that need ActionCollection + * which is available in KMyMoneyApp + * @return QHash of action id and QAction itself + */ + QHash actionsToBeConnected(); + protected: /** * Overwritten because KMyMoney has it's custom header. diff --git a/kmymoney/views/kmymoneyview.cpp b/kmymoney/views/kmymoneyview.cpp --- a/kmymoney/views/kmymoneyview.cpp +++ b/kmymoney/views/kmymoneyview.cpp @@ -50,10 +50,6 @@ #include #include -#ifdef KF5Activities_FOUND -#include -#endif - // ---------------------------------------------------------------------------- // Project Includes @@ -79,7 +75,6 @@ #include "kscheduledview.h" #include "kgloballedgerview.h" #include "kinvestmentview.h" -#include "kmymoney.h" #include "models.h" #include "accountsmodel.h" #include "equitiesmodel.h" @@ -99,21 +94,18 @@ #include "mymoneyreport.h" #include "kmymoneyplugin.h" #include "mymoneyenums.h" +#include "menuenums.h" using namespace Icons; using namespace eMyMoney; typedef void(KMyMoneyView::*KMyMoneyViewFunc)(); -KMyMoneyView::KMyMoneyView(KMyMoneyApp *kmymoney) +KMyMoneyView::KMyMoneyView() : 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 @@ -140,8 +132,6 @@ // newStorage(); m_model = new KPageWidgetModel(this); // cannot be parentless, otherwise segfaults at exit - connect(kmymoney, &KMyMoneyApp::fileLoaded, this, &KMyMoneyView::slotRefreshViews); - viewBases[View::Home] = new KHomeView; viewBases[View::Institutions] = new KInstitutionsView; viewBases[View::Accounts] = new KAccountsView; @@ -192,10 +182,6 @@ connect(viewBases[view.id], &KMyMoneyViewBase::customActionRequested, this, &KMyMoneyView::slotCustomActionRequested); } - const auto& ledgersView = static_cast(viewBases[View::Ledgers]); - - connect(kmymoney, &KMyMoneyApp::transactionSelected, ledgersView, &KGlobalLedgerView::slotLedgerSelected); - connect(Models::instance()->accountsModel(), &AccountsModel::netWorthChanged, this, &KMyMoneyView::slotSelectByVariant); connect(Models::instance()->institutionsModel(), &AccountsModel::netWorthChanged, this, &KMyMoneyView::slotSelectByVariant); connect(Models::instance()->institutionsModel(), &AccountsModel::profitChanged, this, &KMyMoneyView::slotSelectByVariant); @@ -206,64 +192,11 @@ 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() @@ -509,7 +442,49 @@ m_model->removePage(viewFrames[idView]); viewFrames.remove(idView); viewBases.remove(idView); +} +QHash KMyMoneyView::actionsToBeConnected() +{ + using namespace eMenu; + // add fast switching of main views through Ctrl + NUM_X + struct pageInfo { + Action view; + KMyMoneyViewFunc callback; + QString text; + QKeySequence shortcut = QKeySequence(); + }; + + const QVector pageInfos { + {Action::ShowHomeView, &KMyMoneyView::slotShowHomePage, i18n("Show home page"), Qt::CTRL + Qt::Key_1}, + {Action::ShowInstitutionsView, &KMyMoneyView::slotShowInstitutionsPage, i18n("Show institutions page"), Qt::CTRL + Qt::Key_2}, + {Action::ShowAccountsView, &KMyMoneyView::slotShowAccountsPage, i18n("Show accounts page"), Qt::CTRL + Qt::Key_3}, + {Action::ShowSchedulesView, &KMyMoneyView::slotShowSchedulesPage, i18n("Show scheduled transactions page"), Qt::CTRL + Qt::Key_4}, + {Action::ShowCategoriesView, &KMyMoneyView::slotShowCategoriesPage, i18n("Show categories page"), Qt::CTRL + Qt::Key_5}, + {Action::ShowTagsView, &KMyMoneyView::slotShowTagsPage, i18n("Show tags page"), }, + {Action::ShowPayeesView, &KMyMoneyView::slotShowPayeesPage, i18n("Show payees page"), Qt::CTRL + Qt::Key_6}, + {Action::ShowLedgersView, &KMyMoneyView::slotShowLedgersPage, i18n("Show ledgers page"), Qt::CTRL + Qt::Key_7}, + {Action::ShowInvestmentsView, &KMyMoneyView::slotShowInvestmentsPage, i18n("Show investments page"), Qt::CTRL + Qt::Key_8}, + {Action::ShowReportsView, &KMyMoneyView::slotShowReportsPage, i18n("Show reports page"), Qt::CTRL + Qt::Key_9}, + {Action::ShowBudgetView, &KMyMoneyView::slotShowBudgetPage, i18n("Show budget page"), }, + {Action::ShowForecastView, &KMyMoneyView::slotShowForecastPage, i18n("Show forecast page"), }, + {Action::ShowOnlineJobOutboxView, &KMyMoneyView::slotShowOutboxPage, i18n("Show outbox page") } + }; + + QHash lutActions; + auto pageCount = 0; + for (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(QString::fromLatin1("ShowPage%1").arg(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()) + a->setShortcut(info.shortcut); + } + return lutActions; } bool KMyMoneyView::showPageHeader() const @@ -527,31 +502,13 @@ 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 (!viewFrames.contains(idView) || + currentPage() == viewFrames[idView]) + return; - if (!m_inConstructor) { - // fixup some actions that are dependant on the view - // this does not work during construction - kmymoney->slotUpdateActions(); - } + setCurrentPage(viewFrames[idView]); + pActions[eMenu::Action::Print]->setEnabled(canPrint()); + emit aboutToChangeView(); } bool KMyMoneyView::canPrint()