File indexing completed on 2024-04-28 16:30:32

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 SKGREPORT_H
0007 #define SKGREPORT_H
0008 /** @file
0009  * A report class for document
0010  *
0011  * @author Stephane MANKOWSKI
0012  */
0013 #include <qobject.h>
0014 #include <qvariant.h>
0015 
0016 #include "skgbasemodeler_export.h"
0017 #include "skgerror.h"
0018 
0019 class SKGDocument;
0020 /**
0021  * A report class for document
0022  */
0023 class SKGBASEMODELER_EXPORT SKGReport : public QObject
0024 {
0025     Q_OBJECT
0026     /**
0027      * The period
0028      */
0029     Q_PROPERTY(QString period READ getPeriod WRITE setPeriod NOTIFY changed)
0030 
0031     /**
0032      * The month (for compatibility in templates)
0033      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0034      */
0035     Q_PROPERTY(QString month READ getPeriod NOTIFY changed)
0036 
0037     /**
0038      * The previous object
0039      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0040      */
0041     Q_PROPERTY(SKGReport* previous READ getPrevious NOTIFY changed)
0042 
0043     /**
0044      * The previous period
0045      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0046      */
0047     Q_PROPERTY(QString previous_period READ getPreviousPeriod NOTIFY changed)
0048 
0049     /**
0050      * The previous month (for compatibility in templates)
0051      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0052      */
0053     Q_PROPERTY(QString previous_month READ getPreviousPeriod NOTIFY changed)
0054 
0055     /**
0056      * The zoom factor
0057      */
0058     Q_PROPERTY(double point_size READ getPointSize WRITE setPointSize NOTIFY changed)
0059 
0060     /**
0061      * The tips of the day
0062      */
0063     Q_PROPERTY(QStringList tips_of_day READ getTipsOfDay WRITE setTipsOfDay NOTIFY changed)
0064 
0065     /**
0066      * The tip of the day
0067      */
0068     Q_PROPERTY(QString tip_of_day READ getTipOfDay NOTIFY changed)
0069 
0070 public:
0071     /**
0072      * Default Constructor
0073      */
0074     explicit SKGReport(SKGDocument* iDocument);
0075 
0076     /**
0077      * Default Destructor
0078      */
0079     ~SKGReport() override;
0080 
0081     /**
0082      * Get the parent document
0083      * @return the parent document of the report
0084      */
0085     virtual SKGDocument* getDocument() const;
0086 
0087     /**
0088      * Set the current period
0089      * @param iPeriod the period
0090      */
0091     Q_INVOKABLE virtual void setPeriod(const QString& iPeriod);
0092 
0093     /**
0094      * Get the current period
0095      * @return the current period
0096      */
0097     Q_INVOKABLE virtual QString getPeriod();
0098 
0099     /**
0100      * Set the SQL filter
0101      * @param iFilter the filter
0102      */
0103     Q_INVOKABLE virtual void setSqlFilter(const QString& iFilter);
0104 
0105     /**
0106      * Get the SQL filter
0107      * @return the SQL filter
0108      */
0109     Q_INVOKABLE virtual QString getSqlFilter();
0110 
0111     /**
0112      * Get the previous period
0113      * @return the previous period
0114      */
0115     Q_INVOKABLE virtual QString getPreviousPeriod();
0116 
0117     /**
0118      * Get the previous report
0119      * @return the previous report (MUST NOT BE REMOVED)
0120      */
0121     Q_INVOKABLE virtual SKGReport* getPrevious();
0122 
0123     /**
0124      * Set the font point size
0125      * @param iPointSize font point size
0126      */
0127     Q_INVOKABLE virtual void setPointSize(int iPointSize);
0128 
0129     /**
0130      * Get the font point
0131      * @return the font point
0132      */
0133     Q_INVOKABLE virtual int getPointSize() const;
0134 
0135     /**
0136      * Set the tips of the day
0137      * @param iTipsOfDays the tips of the day
0138      */
0139     Q_INVOKABLE virtual void setTipsOfDay(const QStringList& iTipsOfDays);
0140 
0141     /**
0142      * Get the tip of the day
0143      * @return the tip of the day
0144      */
0145     Q_INVOKABLE virtual QString getTipOfDay() const;
0146 
0147     /**
0148      * Get the tips of the day
0149      * @return the tips of the day
0150      */
0151     Q_INVOKABLE virtual QStringList getTipsOfDay() const;
0152 
0153     /**
0154      * Clean the cache
0155      * @param iEmitSignal to emit modification signal
0156      */
0157     Q_INVOKABLE virtual void cleanCache(bool iEmitSignal = true);
0158 
0159     /**
0160      * The context properties
0161      */
0162     Q_INVOKABLE virtual QVariantHash getContextProperty();
0163 
0164     /**
0165      * To add a parameter for a computation
0166      * @param iName the name of the parameter
0167      * @param ivalue the value of the parameter
0168      */
0169     Q_INVOKABLE virtual void addParameter(const QString& iName, const QVariant& ivalue);
0170 
0171     /**
0172      * Get report
0173      * @param iReport the report
0174      * @param iFile the template file name
0175      * @param oHtml the html report
0176      * @return an object managing the error
0177      *   @see SKGError
0178      */
0179     static SKGError getReportFromTemplate(SKGReport* iReport, const QString& iFile, QString& oHtml);
0180 
0181 Q_SIGNALS:
0182     /**
0183      * Emitted when the report changed
0184      */
0185     void changed();
0186 
0187 protected:
0188     /**
0189      * Enrich the grantlee mapping
0190      * @param iMapping the mapping
0191      */
0192     Q_INVOKABLE virtual void addItemsInMapping(QVariantHash& iMapping);
0193 
0194     SKGDocument* m_document;
0195     SKGReport* m_previous;
0196     QHash<QString, QVariant> m_cache;
0197     QHash<QString, QVariant> m_parameters;
0198     int m_pointSize;
0199     QStringList m_tipsOfTheDay;
0200 
0201 private:
0202     Q_DISABLE_COPY(SKGReport)
0203 };
0204 
0205 /**
0206  * Declare the class
0207  */
0208 Q_DECLARE_TYPEINFO(SKGReport, Q_MOVABLE_TYPE);
0209 #endif  // SKGREPORT_H