File indexing completed on 2024-05-12 16:42:38

0001 /*
0002     SPDX-FileCopyrightText: 2000-2001 Michael Edwardes <mte@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2002-2019 Thomas Baumgart <tbaumgart@kde.org>
0004     SPDX-FileCopyrightText: 2003 Kevin Tambascio <ktambascio@users.sourceforge.net>
0005     SPDX-FileCopyrightText: 2006 Ace Jones <acejones@users.sourceforge.net>
0006     SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #ifndef MYMONEYPAYEE_H
0011 #define MYMONEYPAYEE_H
0012 
0013 // ----------------------------------------------------------------------------
0014 // QT Includes
0015 
0016 #include <QMetaType>
0017 
0018 // ----------------------------------------------------------------------------
0019 // Project Includes
0020 
0021 #include "kmm_mymoney_export.h"
0022 #include "mymoneyobject.h"
0023 #include "mymoneypayeeidentifiercontainer.h"
0024 
0025 class QString;
0026 class QStringList;
0027 
0028 namespace eMyMoney {
0029 namespace Payee {
0030 enum class MatchType;
0031 }
0032 }
0033 
0034 /**
0035   * This class represents a payee or receiver within the MyMoney engine.
0036   * Since it is not payee-specific, it is also used as a generic address
0037   * book entry.
0038   *
0039   * @author Thomas Baumgart
0040   */
0041 class MyMoneyPayeePrivate;
0042 class KMM_MYMONEY_EXPORT MyMoneyPayee : public MyMoneyObject, public MyMoneyPayeeIdentifierContainer
0043 {
0044     Q_DECLARE_PRIVATE(MyMoneyPayee)
0045 
0046     KMM_MYMONEY_UNIT_TESTABLE
0047 
0048 public:
0049     MyMoneyPayee();
0050     explicit MyMoneyPayee(const QString &id);
0051 
0052     MyMoneyPayee(const QString& id,
0053                  const MyMoneyPayee& other);
0054 
0055     MyMoneyPayee(const MyMoneyPayee & other);
0056     MyMoneyPayee(MyMoneyPayee && other);
0057     MyMoneyPayee & operator=(MyMoneyPayee other);
0058     friend void swap(MyMoneyPayee& first, MyMoneyPayee& second);
0059 
0060     ~MyMoneyPayee() override;
0061 
0062     QString name() const;
0063     void setName(const QString& val);
0064 
0065     QString address() const;
0066     void setAddress(const QString& val);
0067 
0068     QString city() const;
0069     void setCity(const QString& val);
0070 
0071     QString state() const;
0072     void setState(const QString& val);
0073 
0074     QString postcode() const;
0075     void setPostcode(const QString& val);
0076 
0077     QString telephone() const;
0078     void setTelephone(const QString& val);
0079 
0080     QString email() const;
0081     void setEmail(const QString& val);
0082 
0083     QString notes() const;
0084     void setNotes(const QString& val);
0085 
0086     QString reference() const;
0087     void setReference(const QString& ref);
0088 
0089     bool isMatchingEnabled() const;
0090     bool isUsingMatchKey() const;
0091     bool isMatchKeyIgnoreCase() const;
0092     QString matchKey() const;
0093 
0094     /**
0095      * Get all match data in one call
0096      *
0097      * @param ignorecase Bool which will be replaced to indicate whether the match is
0098      * case-sensitive (false) or case-insensitive (true)
0099      * @param keys List of strings which will be replaced by the match key to use for this payee
0100      *
0101      * @return the matching type (see payeeMatchType for details)
0102      */
0103     eMyMoney::Payee::MatchType matchData(bool& ignorecase, QStringList& keys) const;
0104 
0105     /**
0106      * Set all match data in one call
0107      *
0108      * @param type matching type (see payeeMatchType for details)
0109      * @param ignorecase Whether case should be ignored for the key/name match
0110      * @param keys A list of keys themselves, if applicable
0111      */
0112     void setMatchData(eMyMoney::Payee::MatchType type, bool ignorecase, const QStringList& keys);
0113 
0114     /**
0115      * Get all match data in one call (overloaded version for database module)
0116      *
0117      * @param ignorecase Bool which will be replaced to indicate whether the match is
0118      * case-sensitive (false) or case-insensitive (true)
0119      * @param keyString A list of keys in single-string format, if applicable
0120      *
0121      * @return the matching type (see payeeMatchType for details)
0122      */
0123     eMyMoney::Payee::MatchType matchData(bool& ignorecase, QString& keyString) const;
0124 
0125     /**
0126      * Set all match data in one call (overloaded version for database module)
0127      *
0128      * @param type matching type (see payeeMatchType for details)
0129      * @param ignorecase Whether case should be ignored for the key/name match
0130      * @param keys A list of keys in single-string format, if applicable
0131      */
0132     void setMatchData(eMyMoney::Payee::MatchType type, bool ignorecase, const QString& keys);
0133 
0134     QString defaultAccountId() const;
0135 
0136     void setDefaultAccountId(const QString& id = QString());
0137 
0138     // Equality operator
0139     bool operator == (const MyMoneyPayee &) const;
0140 //  bool operator == (const MyMoneyPayee& lhs, const QString& rhs) const;
0141     bool operator <(const MyMoneyPayee& right) const;
0142 
0143     /**
0144       * This method checks if a reference to the given object exists. It returns,
0145       * a @p true if the object is referencing the one requested by the
0146       * parameter @p id. If it does not, this method returns @p false.
0147       *
0148       * @param id id of the object to be checked for references
0149       * @retval true This object references object with id @p id.
0150       * @retval false This object does not reference the object with id @p id.
0151       */
0152     bool hasReferenceTo(const QString& id) const override;
0153 
0154     static MyMoneyPayee null;
0155 };
0156 
0157 inline void swap(MyMoneyPayee& first, MyMoneyPayee& second) // krazy:exclude=inline
0158 {
0159     using std::swap;
0160     swap(first.d_ptr, second.d_ptr);
0161     swap(first.m_payeeIdentifiers, second.m_payeeIdentifiers);
0162 }
0163 
0164 inline MyMoneyPayee::MyMoneyPayee(MyMoneyPayee && other) : MyMoneyPayee() // krazy:exclude=inline
0165 {
0166     swap(*this, other);
0167 }
0168 
0169 inline MyMoneyPayee & MyMoneyPayee::operator=(MyMoneyPayee other) // krazy:exclude=inline
0170 {
0171     swap(*this, other);
0172     return *this;
0173 }
0174 
0175 /**
0176   * Make it possible to hold @ref MyMoneyPayee objects inside @ref QVariant objects.
0177   */
0178 Q_DECLARE_METATYPE(MyMoneyPayee)
0179 
0180 #endif