File indexing completed on 2024-05-12 05:06:42

0001 /*
0002     SPDX-FileCopyrightText: 2002 Thomas Baumgart <thb@net-bembel.de>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef MYMONEYQIFPROFILE_H
0007 #define MYMONEYQIFPROFILE_H
0008 
0009 // ----------------------------------------------------------------------------
0010 // QT Includes
0011 
0012 #include <QMap>
0013 #include <QObject>
0014 #include <QString>
0015 class QDate;
0016 
0017 // ----------------------------------------------------------------------------
0018 // KDE Includes
0019 
0020 // ----------------------------------------------------------------------------
0021 // Project Includes
0022 
0023 #include "kmm_mymoney_export.h"
0024 
0025 class MyMoneyMoney;
0026 
0027 /**
0028  * @author Thomas Baumgart
0029  */
0030 
0031 class KMM_MYMONEY_EXPORT MyMoneyQifProfile : public QObject
0032 {
0033     Q_OBJECT
0034 
0035 public:
0036     MyMoneyQifProfile();
0037     explicit MyMoneyQifProfile(const QString& name);
0038     ~MyMoneyQifProfile();
0039 
0040     inline const QString& profileName() const
0041     {
0042         return m_profileName;
0043     }
0044     void setProfileName(const QString& name);
0045 
0046     void loadProfile(const QString& name);
0047     void saveProfile();
0048 
0049     QDate date(const QString& datein) const;
0050     QString date(const QDate& datein) const;
0051 
0052     MyMoneyMoney value(const QChar& def, const QString& valuein) const;
0053     QString value(const QChar& def, const MyMoneyMoney& valuein) const;
0054 
0055     inline const QString& outputDateFormat() const
0056     {
0057         return m_dateFormat;
0058     }
0059     QString inputDateFormat() const;
0060     inline const QString& apostropheFormat() const
0061     {
0062         return m_apostropheFormat;
0063     }
0064     QChar amountDecimal(const QChar& def) const;
0065     QChar amountThousands(const QChar& def) const;
0066     inline const QString& profileDescription() const
0067     {
0068         return m_profileDescription;
0069     }
0070     inline const QString& profileType() const
0071     {
0072         return m_profileType;
0073     }
0074     inline const QString& openingBalanceText() const
0075     {
0076         return m_openingBalanceText;
0077     }
0078     QString accountDelimiter() const;
0079     inline const QString& voidMark() const
0080     {
0081         return m_voidMark;
0082     }
0083     inline const QString& filterScriptImport() const
0084     {
0085         return m_filterScriptImport;
0086     }
0087     inline const QString& filterScriptExport() const
0088     {
0089         return m_filterScriptExport;
0090     }
0091     inline const QString& filterFileType() const
0092     {
0093         return m_filterFileType;
0094     }
0095     inline bool attemptMatchDuplicates() const
0096     {
0097         return m_attemptMatchDuplicates;
0098     }
0099 
0100     /**
0101      * This method scans all strings contained in @a lines and tries to figure
0102      * out the settings for m_decimal, m_thousands and m_dateFormat
0103      */
0104     void autoDetect(const QStringList& lines);
0105 
0106     /**
0107      * This method returns a list of possible date formats the user
0108      * can choose from. If autoDetect() has not been run, the @a list
0109      * contains all possible date formats, in the other case, the @a list
0110      * is adjusted to those that will match the data scanned.
0111      */
0112     void possibleDateFormats(QStringList& list) const;
0113 
0114     /**
0115      * This method presets the member variables with the default values.
0116      */
0117     void clear();
0118 
0119     /**
0120      * This method is used to determine, if a profile has been changed or not
0121      */
0122     inline bool isDirty() const
0123     {
0124         return m_isDirty;
0125     };
0126 
0127 public Q_SLOTS:
0128     void setProfileDescription(const QString& desc);
0129     void setProfileType(const QString& type);
0130     void setOutputDateFormat(const QString& dateFormat);
0131     void setInputDateFormat(const QString& dateFormat);
0132     void setApostropheFormat(const QString& apostropheFormat);
0133     void setAmountDecimal(const QChar& def, const QChar& chr);
0134     void setAmountThousands(const QChar& def, const QChar& chr);
0135     void setAccountDelimiter(const QString& delim);
0136     void setOpeningBalanceText(const QString& text);
0137     void setVoidMark(const QString& txt);
0138     void setFilterScriptImport(const QString& txt);
0139     void setFilterScriptExport(const QString& txt);
0140     void setFilterFileType(const QString& txt);
0141     void setAttemptMatchDuplicates(bool);
0142 
0143 private:
0144     const QString twoDigitYear(const QChar& delim, int yr) const;
0145     void scanNumeric(const QString& txt, QChar& decimal, QChar& thousands) const;
0146     void scanDate(const QString& txt) const;
0147 
0148 private:
0149     /// \internal d-pointer class.
0150     class Private;
0151     /// \internal d-pointer instance.
0152     Private* const d;
0153     bool m_isDirty;
0154     QString m_profileName; //< contains the name of the profile with "Profile-" prepended
0155     QString m_profileDescription;
0156     QString m_dateFormat;
0157     QString m_apostropheFormat;
0158     QString m_valueMode;
0159     QString m_profileType;
0160     QString m_openingBalanceText;
0161     QString m_voidMark;
0162     QString m_accountDelimiter;
0163     QString m_filterScriptImport;
0164     QString m_filterScriptExport;
0165     QString m_filterFileType; /*< The kind of input files the filter will expect, e.g. "*.qif" */
0166     QMap<QChar, QChar> m_decimal;
0167     QMap<QChar, QChar> m_thousands;
0168     bool m_attemptMatchDuplicates;
0169 };
0170 
0171 #endif