File indexing completed on 2024-05-19 05:08:35

0001 /*
0002     SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0003     SPDX-FileCopyrightText: 2020 Thomas Baumgart <tbaumgart@kde.org>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KMYMONEYVIEWBASE_H
0008 #define KMYMONEYVIEWBASE_H
0009 
0010 #include "kmm_widgets_export.h"
0011 
0012 // ----------------------------------------------------------------------------
0013 // QT Includes
0014 
0015 #include <QWidget>
0016 class QPoint;
0017 
0018 // ----------------------------------------------------------------------------
0019 // KDE Includes
0020 
0021 
0022 // ----------------------------------------------------------------------------
0023 // Project Includes
0024 
0025 #include "viewenums.h"
0026 
0027 #include "kmmyesno.h"
0028 
0029 class MyMoneyObject;
0030 class KPageWidgetItem;
0031 class SelectedObjects;
0032 namespace eMenu {
0033 enum class Action;
0034 enum class Menu;
0035 }
0036 namespace KMyMoneyPlugin {
0037 class OnlinePlugin;
0038 }
0039 
0040 /**
0041   * This class is an abstract base class that all specific views
0042   * should be based on.
0043   */
0044 class KMyMoneyViewBasePrivate;
0045 class KMM_WIDGETS_EXPORT KMyMoneyViewBase : public QWidget
0046 {
0047     Q_OBJECT
0048 
0049 public:
0050     virtual ~KMyMoneyViewBase();
0051 
0052     /**
0053      * Execute the @a action using the @a selections. This base
0054      * class implementation os a no-op. If a view needs to act upon
0055      * the execution of @a action you need to override this
0056      * method in the derived class of the view.
0057      */
0058     virtual void executeAction(eMenu::Action action, const SelectedObjects& selections);
0059 
0060     virtual void executeCustomAction(eView::Action) {}
0061 
0062     /**
0063      * This method is called during a view change on the view
0064      * that is left. In case you override it, make sure to
0065      * call the base class method as well.
0066      */
0067     virtual void aboutToHide();
0068 
0069     /**
0070      * This method is called during a view change on the view
0071      * that is entered. In case you override it, make sure to
0072      * call the base class method as well. The base class
0073      * implementation takes care of saving the last selected
0074      * view and informs the application about the current
0075      * selected objects in this view by emitting the
0076      * requestSelectionChange() signal.
0077      *
0078      * @sa requestSelectionChange()
0079      */
0080     virtual void aboutToShow();
0081 
0082     virtual QHash<eMenu::Action, QAction*> sharedToolbarActions();
0083 
0084     /**
0085      * Returns @c true if the view has a closable tab/sub-view.
0086      * Default is to return @c false.
0087      */
0088     virtual bool hasClosableView() const;
0089 
0090     /**
0091      * Closes the current selected closable tab/sub-view in the view.
0092      * Default is to do nothing.
0093      */
0094     virtual void closeCurrentView();
0095 
0096 Q_SIGNALS:
0097     // these signals are send to application logic
0098     void requestSelectionChange(const SelectedObjects& selection);
0099     void requestCustomContextMenu(eMenu::Menu type, const QPoint& pos);
0100     void requestActionTrigger(eMenu::Action action);
0101 
0102     void viewStateChanged(bool enabled);
0103 
0104     void customActionRequested(View, eView::Action);
0105 
0106     void requestView(QWidget* viewWidget, const QString& accountId, const QString& journalEntryId);
0107 
0108 public Q_SLOTS:
0109     virtual void updateActions(const SelectedObjects& selections) {
0110         Q_UNUSED(selections)
0111     }
0112 
0113     virtual void slotSettingsChanged() {}
0114 
0115     /**
0116      * Inform the view about available online plugins. The default
0117      * does not do anything
0118      */
0119     virtual void setOnlinePlugins(QMap<QString, KMyMoneyPlugin::OnlinePlugin*>* plugins)
0120     {
0121         Q_UNUSED(plugins)
0122     }
0123 
0124     virtual void setDefaultFocus();
0125 
0126 protected:
0127     const QScopedPointer<KMyMoneyViewBasePrivate> d_ptr;
0128 
0129     // we do not allow to create objects of this class
0130     explicit KMyMoneyViewBase(QWidget* parent = nullptr);
0131     KMyMoneyViewBase(KMyMoneyViewBasePrivate &dd, QWidget *parent);
0132 
0133 private:
0134     Q_DECLARE_PRIVATE(KMyMoneyViewBase)
0135 };
0136 
0137 #endif