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 SKGREPORTPLUGINWIDGET_H
7 #define SKGREPORTPLUGINWIDGET_H
8 /** @file
9 * This file is Skrooge plugin for bank management.
10 *
11 * @author Stephane MANKOWSKI / Guillaume DE BURE
12 */
13 #include <qdom.h>
14 #include <qstringlist.h>
15 #include <qtimer.h>
16 
17 #include "skgtabpage.h"
18 #include "ui_skgreportpluginwidget_base.h"
19 
20 class SKGDocumentBank;
21 
22 /**
23  * This file is Skrooge plugin to generate report
24  */
25 class SKGReportPluginWidget : public SKGTabPage
26 {
27     Q_OBJECT
28 
29 public:
30     /**
31      * Default Constructor
32      * @param iParent the parent widget
33      * @param iDocument the document
34      * @param iMinimmumMode the panel will be displayed with minimum widgets
35      */
36     explicit SKGReportPluginWidget(QWidget* iParent, SKGDocumentBank* iDocument, bool iMinimmumMode = false);
37 
38     /**
39      * Default Destructor
40      */
41     ~SKGReportPluginWidget() override;
42 
43     /**
44      * Get the current state
45      * MUST BE OVERWRITTEN
46      * @return a string containing all information needed to set the same state.
47      * Could be an XML stream
48      */
49     QString getState() override;
50 
51     /**
52      * Set the current state
53      * MUST BE OVERWRITTEN
54      * @param iState must be interpreted to set the state of the widget
55      */
56     void setState(const QString& iState) override;
57 
58     /**
59      * Get attribute name to save the default state
60      * MUST BE OVERWRITTEN
61      * @return attribute name to save the default state.
62      */
63     QString getDefaultStateAttribute() override;
64 
65     /**
66      * Get the zoomable widget.
67      * The default implementation returns the main widget.
68      * @return the zoomable widget.
69      */
70     QWidget* zoomableWidget() override;
71 
72     /**
73      * Get the printable widgets.
74      * The default implementation returns the main widget.
75      * @return the printable widgets.
76      */
77     QList<QWidget*> printableWidgets() override;
78 
79 public Q_SLOTS:
80     /**
81      * Refresh the panel
82      */
83     void refresh();
84 
85     /**
86     * data are modified
87     * @param iTableName table name
88     * @param iIdTransaction the id of the transaction for direct modifications of the table (update of modify objects is enough)
89     *or 0 in case of modifications by impact (full table must be refreshed)
90     */
91     virtual void dataModified(const QString& iTableName = QString(), int iIdTransaction = 0);
92 
93 private Q_SLOTS:
94     void pageChanged();
95     void onDoubleClick(int row, int column);
96     void onOpen();
97     void onOpenReport();
98     void onSelectionChanged();
99     void onOneLevelMore();
100     void onOneLevelLess();
101     void onAddLine();
102     void onRemoveLine();
103     void onBtnModeClicked(int mode);
104 
105     void setSettings();
106 
107 private:
108     Q_DISABLE_COPY(SKGReportPluginWidget)
109 
110     QString getConsolidatedWhereClause(QString* oWhereClausForPreviousData = nullptr, QString*  oWhereClausForForecastData = nullptr);
111     void getWhereClauseAndTitleForItem(int row, int column, QString& oWc, QString& oTitle);
112     void getWhereClauseAndTitleForSelection(QString& oWc, QString& oTitle);
113     QString getWhereClauseForProperty(const QString& iProperty) const;
114 
115     Ui::skgreportplugin_base ui{};
116     QString m_previousParametersUsed;
117     QStringList m_attsForColumns;
118     QStringList m_attsForLines;
119     QStringList m_attsForLinesAdded;
120     QAction* m_openReportAction;
121     QAction* m_openAction;
122     QTimer m_timer;
123     int m_mode;
124     int m_nbLevelLines;
125     int m_nbLevelColumns;
126     bool m_refreshNeeded;
127 };
128 
129 #endif  // SKGREPORTPLUGINWIDGET_H
130