1 /***************************************************************************
2  * SPDX-FileCopyrightText: 2021 S. MANKOWSKI stephane@mankowski.fr
3  * SPDX-FileCopyrightText: 2021 G. DE BURE support@mankowski.fr
4  * SPDX-License-Identifier: GPL-3.0-or-later
5  ***************************************************************************/
6 #ifndef SKGOPERATIONPLUGINWIDGET_H
7 #define SKGOPERATIONPLUGINWIDGET_H
8 /** @file
9 * This file is Skrooge plugin for bank management.
10 *
11 * @author Stephane MANKOWSKI / Guillaume DE BURE
12 */
13 #include "skgoperationobject.h"
14 #include "skgsuboperationobject.h"
15 #include "skgtabpage.h"
16 #include "ui_skgoperationpluginwidget_base.h"
17 #include <qdom.h>
18 
19 class SKGDocumentBank;
20 class SKGObjectModel;
21 class SKGSplitTableDelegate;
22 class SKGTreeView;
23 class QAction;
24 
25 /**
26  * This file is Skrooge plugin for operation management
27  */
28 class SKGOperationPluginWidget : public SKGTabPage
29 {
30     Q_OBJECT
31 
32 
33 public:
34     /**
35      * Default Constructor
36      * @param iParent the parent widget
37      * @param iDocument the document
38      */
39     explicit SKGOperationPluginWidget(QWidget* iParent, SKGDocumentBank* iDocument);
40 
41     /**
42      * Default Destructor
43      */
44     ~SKGOperationPluginWidget() override;
45 
46     /**
47      * Get the table view
48      * @return the table view
49      */
50     virtual SKGTreeView* getTableView();
51 
52     /**
53      * Get the current state
54      * MUST BE OVERWRITTEN
55      * @return a string containing all information needed to set the same state.
56      * Could be an XML stream
57      */
58     QString getState() override;
59 
60     /**
61      * Set the current state
62      * MUST BE OVERWRITTEN
63      * @param iState must be interpreted to set the state of the widget
64      */
65     void setState(const QString& iState) override;
66 
67     /**
68      * Get attribute name to save the default state
69      * MUST BE OVERWRITTEN
70      * @return attribute name to save the default state.
71      */
72     QString getDefaultStateAttribute() override;
73 
74     /**
75      * Get the main widget
76      * @return a widget
77      */
78     QWidget* mainWidget() override;
79 
80     /**
81      * Set or not the template mode
82      * @param iTemplate the template mode
83      */
84     virtual void setTemplateMode(bool iTemplate);
85 
86     /**
87      * To know if this page contains an editor. MUST BE OVERWRITTEN
88      * @return the editor state
89      */
90     bool isEditor() override;
91 
92     /**
93      * To activate the editor by setting focus on right widget. MUST BE OVERWRITTEN
94      */
95     void activateEditor() override;
96 
97 protected:
98     /**
99      * Event filtering
100      * @param iObject object
101      * @param iEvent event
102      * @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.
103      */
104     bool eventFilter(QObject* iObject, QEvent* iEvent) override;
105 
106 private Q_SLOTS:
107     void dataModified(const QString& iTableName, int iIdTransaction, bool iLightTransaction = false);
108     void onOperationCreatorModified();
109     void onPayeeChanged();
110     void onAddOperationClicked();
111     void onUpdateOperationClicked();
112     void onFilterChanged();
113     void onAccountChanged();
114     void onSelectionChanged();
115     void onFocusChanged();
116     void onFastEdition();
117     void onDoubleClick();
118     void onQuantityChanged();
119     // cppcheck-suppress passedByValue
120     void onDateChanged(QDate iDate);
121     void onSubopCellChanged(int row, int column);
122     void onRemoveSubOperation(int iRow);
123     void onRefreshInformationZone();
124     void onRefreshInformationZoneDelayed();
125     void onRotateAccountTools();
126     void onValidatePointedOperations();
127     void onBtnModeClicked(int mode);
128     void onAutoPoint();
129     void onAddFakeOperation();
130     void onFreeze();
131     void refreshSubOperationAmount();
132     void cleanEditor();
133     void displayReconciliationInfo();
134     void displayBalance();
135     void fillTargetAccount();
136 
137 private:
138     Q_DISABLE_COPY(SKGOperationPluginWidget)
139 
140     SKGError getSelectedOperation(SKGOperationObject& operation);
141 
142     bool isWidgetEditionEnabled(QWidget* iWidget);
143     void setWidgetEditionEnabled(QWidget* iWidget, bool iEnabled);
144     void setAllWidgetsEnabled();
145 
146     bool isTemplateMode();
147     void displaySubOperations();
148     // cppcheck-suppress passedByValue
149     void displaySubOperations(const SKGOperationObject& iOperation, bool iKeepId = true, QDate iSubOperationsDate = QDate());
150     double getRemainingQuantity();
151     // cppcheck-suppress passedByValue
152     void addSubOperationLine(int row, QDate date, const QString& category, const QString& tracker, const QString& comment, double quantity, const QString& formula, int id = 0);
153     SKGError updateSelection(const SKGObjectBase::SKGListSKGObjectBase& iSelection, bool iForceCreation = false);
154     void fillNumber();
155     QString getAttributeOfSelection(const QString& iAttribute);
156     QString currentAccount();
157 
158     Ui::skgoperationplugin_base ui{};
159     SKGObjectModel* m_objectModel;
160     QString m_operationWhereClause;
161     QString m_previousValue;
162     QDomDocument m_lastState;
163 
164     QAction* m_fastEditionAction;
165 
166     QString m_lastFastEditionWhereClause;
167     int m_lastFastEditionOperationFound;
168     bool m_showClosedAccounts;
169 
170     bool m_numberFieldIsNotUptodate;
171     int m_modeInfoZone;
172     QKeySequence m_deleteShortcut;
173 
174     SKGSplitTableDelegate* m_tableDelegate;
175     QTimer m_timer;
176 
177     QStringList m_attributesForSplit;
178     QDate m_previousDate;
179 };
180 
181 #endif  // SKGOPERATIONPLUGINWIDGET_H
182