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

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 SKGOPERATIONPLUGINWIDGET_H
0007 #define SKGOPERATIONPLUGINWIDGET_H
0008 /** @file
0009 * This file is Skrooge plugin for bank management.
0010 *
0011 * @author Stephane MANKOWSKI / Guillaume DE BURE
0012 */
0013 #include "skgoperationobject.h"
0014 #include "skgsuboperationobject.h"
0015 #include "skgtabpage.h"
0016 #include "ui_skgoperationpluginwidget_base.h"
0017 #include <qdom.h>
0018 
0019 class SKGDocumentBank;
0020 class SKGObjectModel;
0021 class SKGSplitTableDelegate;
0022 class SKGTreeView;
0023 class QAction;
0024 
0025 /**
0026  * This file is Skrooge plugin for transaction management
0027  */
0028 class SKGOperationPluginWidget : public SKGTabPage
0029 {
0030     Q_OBJECT
0031 
0032 
0033 public:
0034     /**
0035      * Default Constructor
0036      * @param iParent the parent widget
0037      * @param iDocument the document
0038      */
0039     explicit SKGOperationPluginWidget(QWidget* iParent, SKGDocumentBank* iDocument);
0040 
0041     /**
0042      * Default Destructor
0043      */
0044     ~SKGOperationPluginWidget() override;
0045 
0046     /**
0047      * Get the table view
0048      * @return the table view
0049      */
0050     virtual SKGTreeView* getTableView();
0051 
0052     /**
0053      * Get the current state
0054      * MUST BE OVERWRITTEN
0055      * @return a string containing all information needed to set the same state.
0056      * Could be an XML stream
0057      */
0058     QString getState() override;
0059 
0060     /**
0061      * Set the current state
0062      * MUST BE OVERWRITTEN
0063      * @param iState must be interpreted to set the state of the widget
0064      */
0065     void setState(const QString& iState) override;
0066 
0067     /**
0068      * Get attribute name to save the default state
0069      * MUST BE OVERWRITTEN
0070      * @return attribute name to save the default state.
0071      */
0072     QString getDefaultStateAttribute() override;
0073 
0074     /**
0075      * Get the main widget
0076      * @return a widget
0077      */
0078     QWidget* mainWidget() override;
0079 
0080     /**
0081      * Set or not the template mode
0082      * @param iTemplate the template mode
0083      */
0084     virtual void setTemplateMode(bool iTemplate);
0085 
0086     /**
0087      * To know if this page contains an editor. MUST BE OVERWRITTEN
0088      * @return the editor state
0089      */
0090     bool isEditor() override;
0091 
0092     /**
0093      * To activate the editor by setting focus on right widget. MUST BE OVERWRITTEN
0094      */
0095     void activateEditor() override;
0096 
0097 protected:
0098     /**
0099      * Event filtering
0100      * @param iObject object
0101      * @param iEvent event
0102      * @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.
0103      */
0104     bool eventFilter(QObject* iObject, QEvent* iEvent) override;
0105 
0106 private Q_SLOTS:
0107     void dataModified(const QString& iTableName, int iIdTransaction, bool iLightTransaction = false);
0108     void onOperationCreatorModified();
0109     void onPayeeChanged();
0110     void onAddOperationClicked();
0111     void onUpdateOperationClicked();
0112     void onFilterChanged();
0113     void onAccountChanged();
0114     void onSelectionChanged();
0115     void onFocusChanged();
0116     void onFastEdition();
0117     void onDoubleClick();
0118     void onQuantityChanged();
0119     // cppcheck-suppress passedByValue
0120     void onDateChanged(QDate iDate);
0121     void onSubopCellChanged(int row, int column);
0122     void onRemoveSubOperation(int iRow);
0123     void onRefreshInformationZone();
0124     void onRefreshInformationZoneDelayed();
0125     void onRotateAccountTools();
0126     void onValidateMarkedOperations();
0127     void onBtnModeClicked(int mode);
0128     void onAutoPoint();
0129     void onAddFakeOperation();
0130     void onFreeze();
0131     void refreshSubOperationAmount();
0132     void cleanEditor();
0133     void displayReconciliationInfo();
0134     void displayBalance();
0135     void fillTargetAccount();
0136 
0137 private:
0138     Q_DISABLE_COPY(SKGOperationPluginWidget)
0139 
0140     SKGError getSelectedOperation(SKGOperationObject& operation);
0141 
0142     bool isWidgetEditionEnabled(QWidget* iWidget);
0143     void setWidgetEditionEnabled(QWidget* iWidget, bool iEnabled);
0144     void setAllWidgetsEnabled();
0145 
0146     bool isTemplateMode();
0147     void displaySubOperations();
0148     // cppcheck-suppress passedByValue
0149     void displaySubOperations(const SKGOperationObject& iOperation, bool iKeepId = true, QDate iSubOperationsDate = QDate());
0150     double getRemainingQuantity();
0151     // cppcheck-suppress passedByValue
0152     void addSubOperationLine(int row, QDate date, const QString& category, const QString& tracker, const QString& comment, double quantity, const QString& formula, int id = 0);
0153     SKGError updateSelection(const SKGObjectBase::SKGListSKGObjectBase& iSelection, bool iForceCreation = false);
0154     void fillNumber();
0155     QString getAttributeOfSelection(const QString& iAttribute);
0156     QString currentAccount();
0157 
0158     Ui::skgoperationplugin_base ui{};
0159     SKGObjectModel* m_objectModel;
0160     QString m_operationWhereClause;
0161     QString m_previousValue;
0162     QDomDocument m_lastState;
0163 
0164     QAction* m_fastEditionAction;
0165 
0166     QString m_lastFastEditionWhereClause;
0167     int m_lastFastEditionOperationFound;
0168     bool m_showClosedAccounts;
0169 
0170     bool m_numberFieldIsNotUptodate;
0171     int m_modeInfoZone;
0172     QKeySequence m_deleteShortcut;
0173 
0174     SKGSplitTableDelegate* m_tableDelegate;
0175     QTimer m_timer;
0176 
0177     QStringList m_attributesForSplit;
0178     QDate m_previousDate;
0179 };
0180 
0181 #endif  // SKGOPERATIONPLUGINWIDGET_H