File indexing completed on 2024-05-26 05:08:36
0001 /* 0002 SPDX-FileCopyrightText: 2014 Christian Dávid <christian-david@web.de> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef PAYEEIDENTIFIERDATA_H 0007 #define PAYEEIDENTIFIERDATA_H 0008 0009 #include "payeeidentifier/kmm_payeeidentifier_export.h" 0010 0011 #include <QtPlugin> 0012 #include <QSharedPointer> 0013 #include <QHash> 0014 #include <QMetaType> 0015 0016 class QXmlStreamReader; 0017 class QXmlStreamWriter; 0018 class payeeIdentifier; 0019 class payeeIdentifierLoader; 0020 0021 /** 0022 * @brief Define a unique identifier for an payeeIdentifier subclass 0023 * 0024 * Use this macro in your class's public section. 0025 * 0026 * This also defines the helper ::ptr, ::constPtr and className::ptr cloneSharedPtr() 0027 * 0028 * @param PIDID the payeeIdentifier id, e.g. "org.kmymoney.payeeIdentifier.swift". Must be 0029 * unique among all payeeIdentifiers as it is used internally to store data, to compare 0030 * types and for type casting (there must not be more than one class which uses that pidid). 0031 */ 0032 #define PAYEEIDENTIFIER_IID(className, iid) \ 0033 /** @brief Returns the payeeIdentifier Iid */ \ 0034 static const QString& staticPayeeIdentifierIid() { \ 0035 static const QString _pidid = QLatin1String( iid ); \ 0036 return _pidid; \ 0037 } \ 0038 /** @brief Returns the payeeIdentifier Id */ \ 0039 QString payeeIdentifierId() const final override { \ 0040 return className::staticPayeeIdentifierIid(); \ 0041 } 0042 0043 /** 0044 * @brief "Something" that identifies a payee (or an account of a payee) 0045 * 0046 * The simplest form of this class is an identifier for an bank account (consisting of an account number 0047 * and a bank code). But also an e-mail address which is used by an online money-transfer service could be 0048 * such an identifier (that is the reason for the abstract name "payeeIdentifier"). 0049 * 0050 * But also the creditor identifier for debit-notes in sepa-countries can be a subclass. It does not 0051 * address an account but a company. 0052 * 0053 * Any payee (@ref MyMoneyPayee) can have several payeeIdentifiers. 0054 * 0055 * The online banking system uses payeeIdentifiers to determine if it is able so create a credit-transfer 0056 * to a given payee. During import the payeeIdentifiers are used to find a payee. 0057 * 0058 * You should use the shared pointer payeeIdentifier::ptr to handle payeeIdentifiers. To copy them used 0059 * cloneSharedPtr(). 0060 * 0061 * @internal First this is more complex than creating a superset of all possible identifiers. But there 0062 * are many of them. And using this method it is a lot easier to create the comparison operators and 0063 * things like isValid(). 0064 * 0065 * @section Inheriting 0066 * 0067 * To identify the type of an payeeIdentifier you must use the macro @ref PAYEEIDENTIFIER_IID() 0068 * in the public section of your subclass. 0069 */ 0070 class KMM_PAYEEIDENTIFIER_EXPORT payeeIdentifierData 0071 { 0072 public: 0073 virtual ~payeeIdentifierData() {} 0074 0075 /** 0076 * Use PAYEEIDENTIFIER_ID(className, PIDID) to reimplement this method. 0077 */ 0078 virtual QString payeeIdentifierId() const = 0; 0079 0080 /** 0081 * @brief Comparison operator 0082 */ 0083 virtual bool operator==(const payeeIdentifierData& other) const = 0; 0084 virtual bool operator!=(const payeeIdentifierData& other) const { 0085 return (!operator==(other)); 0086 } 0087 0088 /** 0089 * @brief Check if this payeeIdentifier contains correct data 0090 * 0091 * You should be able to handle invalid data. It is the task of the ui to prevent 0092 * invalid data. But during several procedures invalid data could be used (e.g. 0093 * during import). 0094 */ 0095 virtual bool isValid() const = 0; 0096 0097 /** 0098 * @brief Create a new payeeIdentifier form XML data 0099 * 0100 * @param element Note: there could be more data in that element than you created in writeXML() 0101 */ 0102 virtual payeeIdentifierData* createFromXml(QXmlStreamReader* reader) const = 0; 0103 0104 /** 0105 * @see MyMoneyObject::writeXML() 0106 * 0107 * @warning Do not set an attribute "type" or "id" to parent, it is used to store internal data and is 0108 * set automatically. 0109 */ 0110 virtual void writeXML(QXmlStreamWriter* writer) const = 0; 0111 0112 protected: 0113 /** 0114 * @brief Create deep copy 0115 */ 0116 virtual payeeIdentifierData* clone() const = 0; 0117 friend class payeeIdentifierLoader; 0118 friend class payeeIdentifier; 0119 }; 0120 0121 Q_DECLARE_INTERFACE(payeeIdentifierData, "org.kmymoney.payeeIdentifier") 0122 0123 #endif // PAYEEIDENTIFIERDATA_H