File indexing completed on 2024-05-19 05:07:24

0001 /*
0002     SPDX-FileCopyrightText: 2020 Thomas Baumgart <tbaumgart@kde.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef MYMONEYTEMPLATE_H
0007 #define MYMONEYTEMPLATE_H
0008 
0009 #include "kmm_mymoney_export.h"
0010 
0011 // ----------------------------------------------------------------------------
0012 // QT Includes
0013 
0014 class QDomNode;
0015 class QFile;
0016 class QUrl;
0017 #include <QString>
0018 #include <QMetaType>
0019 
0020 // ----------------------------------------------------------------------------
0021 // KDE Includes
0022 
0023 // ----------------------------------------------------------------------------
0024 // Project Includes
0025 
0026 #include "mymoneyobject.h"
0027 
0028 
0029 /**
0030   * @author Thomas Baumgart
0031   */
0032 
0033 struct KMM_MYMONEY_EXPORT MyMoneyTemplateLoadResult
0034 {
0035     QString   errorMsg;
0036     int       errorLine {-1};
0037     int       errorColumn {-1};
0038 
0039     void setErrorMsg(const QString& msg);
0040     bool isOK() const;
0041 };
0042 
0043 /**
0044   * This class represents an account template handler. It is capable
0045   * to read an XML formatted account template file and import it into
0046   * the current engine. Also, it can save the current account structure
0047   * of the engine to an XML formatted template file.
0048   */
0049 class MyMoneyTemplatePrivate;
0050 class KMM_MYMONEY_EXPORT MyMoneyTemplate : public MyMoneyObject
0051 {
0052     Q_DECLARE_PRIVATE_D(MyMoneyObject::d_ptr, MyMoneyTemplate)
0053 
0054 public:
0055     MyMoneyTemplate();
0056     explicit MyMoneyTemplate(const QString& id, const MyMoneyTemplate& other);
0057     MyMoneyTemplate(const MyMoneyTemplate & other);
0058     MyMoneyTemplate(MyMoneyTemplate && other);
0059     MyMoneyTemplate & operator=(MyMoneyTemplate other);
0060     friend void swap(MyMoneyTemplate& first, MyMoneyTemplate& second);
0061 
0062     ~MyMoneyTemplate() override;
0063 
0064     const QString& title() const;
0065     const QString& shortDescription() const;
0066     const QString& longDescription() const;
0067     const QString& locale() const;
0068     const QUrl& source() const;
0069 
0070     void setTitle(const QString &s);
0071     void setShortDescription(const QString &s);
0072     void setLongDescription(const QString &s);
0073     void setLocale(const QString& s);
0074     void setSource(const QUrl& s);
0075 
0076     MyMoneyTemplateLoadResult setAccountTree(QFile *file);
0077     const QDomNode& accountTree() const;
0078 
0079 protected:
0080 #if 0
0081     bool loadDescription();
0082     bool createAccounts(MyMoneyAccount& parent, QDomNode account);
0083     bool setFlags(MyMoneyAccount& acc, QDomNode flags);
0084     bool saveToLocalFile(QSaveFile* qfile);
0085     bool addAccountStructure(QDomElement& parent, const MyMoneyAccount& acc);
0086     bool hierarchy(QMap<QString, QTreeWidgetItem*>& list, const QString& parent, QDomNode account);
0087 #endif
0088 
0089 private:
0090 };
0091 
0092 inline void swap(MyMoneyTemplate& first, MyMoneyTemplate& second) // krazy:exclude=inline
0093 {
0094     using std::swap;
0095     swap(first.d_ptr, second.d_ptr);
0096 }
0097 
0098 inline MyMoneyTemplate::MyMoneyTemplate(MyMoneyTemplate && other) : MyMoneyTemplate() // krazy:exclude=inline
0099 {
0100     swap(*this, other);
0101 }
0102 
0103 inline MyMoneyTemplate & MyMoneyTemplate::operator=(MyMoneyTemplate other) // krazy:exclude=inline
0104 {
0105     swap(*this, other);
0106     return *this;
0107 }
0108 
0109 /**
0110  * Make it possible to hold @ref MyMoneyTemplate objects inside @ref QVariant objects.
0111  */
0112 Q_DECLARE_METATYPE(MyMoneyTemplate)
0113 
0114 
0115 #endif