File indexing completed on 2024-05-26 05:10:37

0001 /***************************************************************************
0002  * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr
0003  * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  ***************************************************************************/
0006 #ifndef SKGBUDGETPLUGINWIDGET_H
0007 #define SKGBUDGETPLUGINWIDGET_H
0008 /** @file
0009  * A skrooge plugin to manage budgets
0010  *
0011  * @author Stephane MANKOWSKI
0012  */
0013 #include "skgtabpage.h"
0014 #include "ui_skgbudgetpluginwidget_base.h"
0015 #include <qtimer.h>
0016 
0017 class SKGObjectModel;
0018 class SKGBudgetObject;
0019 class SKGBudgetRuleObject;
0020 
0021 /**
0022  * A skrooge plugin to manage budgets
0023  */
0024 class SKGBudgetPluginWidget : public SKGTabPage
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029     /**
0030      * Default Constructor
0031      * @param iParent the parent widget
0032      * @param iDocument the document
0033      */
0034     explicit SKGBudgetPluginWidget(QWidget* iParent, SKGDocument* iDocument);
0035 
0036     /**
0037      * Default Destructor
0038      */
0039     ~SKGBudgetPluginWidget() override;
0040 
0041     /**
0042      * Get the current state
0043      * MUST BE OVERWRITTEN
0044      * @return a string containing all information needed to set the same state.
0045      * Could be an XML stream
0046      */
0047     QString getState() override;
0048 
0049     /**
0050      * Set the current state
0051      * MUST BE OVERWRITTEN
0052      * @param iState must be interpreted to set the state of the widget
0053      */
0054     void setState(const QString& iState) override;
0055 
0056     /**
0057      * Get attribute name to save the default state
0058      * MUST BE OVERWRITTEN
0059      * @return attribute name to save the default state.
0060      */
0061     QString getDefaultStateAttribute() override;
0062 
0063     /**
0064      * Get the main widget
0065      * @return a widget
0066      */
0067     QWidget* mainWidget() override;
0068 
0069     /**
0070      * To know if this page contains an editor. MUST BE OVERWRITTEN
0071      * @return the editor state
0072      */
0073     bool isEditor() override;
0074 
0075     /**
0076      * To activate the editor by setting focus on right widget. MUST BE OVERWRITTEN
0077      */
0078     void activateEditor() override;
0079 
0080 public Q_SLOTS:
0081     /**
0082     * Refresh the content.
0083      */
0084     virtual void refresh();
0085 
0086 protected:
0087     /**
0088      * Event filtering
0089      * @param iObject object
0090      * @param iEvent event
0091      * @return In your reimplementation of this function, if you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.
0092      */
0093     bool eventFilter(QObject* iObject, QEvent* iEvent) override;
0094 
0095 private Q_SLOTS:
0096     void dataModified(const QString& iTableName, int iIdTransaction, bool iLightTransaction = false);
0097     void onCreatorModified();
0098     void onAddClicked();
0099     void onUpdateClicked();
0100     void onSelectionChanged();
0101     void onBtnModeClicked(int mode);
0102     void onTop();
0103     void onUp();
0104     void onDown();
0105     void onBottom();
0106 
0107     void refreshInfoZone();
0108 private:
0109     Q_DISABLE_COPY(SKGBudgetPluginWidget)
0110 
0111     Ui::skgbudgetplugin_base ui{};
0112 
0113     SKGError updateBudget(SKGBudgetObject& iBudget, int iMonth = -1);
0114     SKGError updateBudgetRule(SKGBudgetRuleObject& iRule);
0115 
0116     SKGObjectModel* m_objectModel;
0117     QString m_viewBudget;
0118     QString m_viewRule;
0119 
0120     QTimer m_timer;
0121 };
0122 
0123 #endif  // SKGBUDGETPLUGINWIDGET_H