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

0001 /*
0002     SPDX-FileCopyrightText: 2005-2017 Thomas Baumgart <tbaumgart@kde.org>
0003     SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef MYMONEYSECURITY_H
0008 #define MYMONEYSECURITY_H
0009 
0010 #include "kmm_mymoney_export.h"
0011 
0012 // ----------------------------------------------------------------------------
0013 // QT Includes
0014 
0015 #include <QMetaType>
0016 
0017 // ----------------------------------------------------------------------------
0018 // KDE Includes
0019 
0020 // ----------------------------------------------------------------------------
0021 // Project Includes
0022 
0023 #include <alkimia/alkvalue.h>
0024 #include "mymoneyobject.h"
0025 #include "mymoneykeyvaluecontainer.h"
0026 
0027 class QString;
0028 
0029 namespace eMyMoney {
0030 namespace Security {
0031 enum class Type;
0032 }
0033 }
0034 
0035 /**
0036   * Class that holds all the required information about a security that the user
0037   * has entered information about. A security can be a stock, a mutual fund, a bond
0038   * or a currency.
0039   *
0040   * @author Kevin Tambascio
0041   * @author Thomas Baumgart
0042   * @author Łukasz Wojniłowicz
0043   */
0044 
0045 class MyMoneySecurityPrivate;
0046 class KMM_MYMONEY_EXPORT MyMoneySecurity : public MyMoneyObject, public MyMoneyKeyValueContainer
0047 {
0048     Q_DECLARE_PRIVATE_D(MyMoneyObject::d_ptr, MyMoneySecurity)
0049 
0050     KMM_MYMONEY_UNIT_TESTABLE
0051 
0052 public:
0053     MyMoneySecurity();
0054     explicit MyMoneySecurity(const QString &id);
0055 
0056     explicit MyMoneySecurity(const QString& id,
0057                              const QString& name,
0058                              const QString& symbol = QString(),
0059                              const int smallestCashFraction = 100,
0060                              const int smallestAccountFraction = 0,
0061                              const int pricePrecision = 4);
0062 
0063     MyMoneySecurity(const QString& id,
0064                     const MyMoneySecurity& other);
0065 
0066     MyMoneySecurity(const MyMoneySecurity & other);
0067     MyMoneySecurity(MyMoneySecurity && other);
0068     MyMoneySecurity & operator=(MyMoneySecurity other);
0069     friend void swap(MyMoneySecurity& first, MyMoneySecurity& second);
0070 
0071     ~MyMoneySecurity();
0072 
0073     bool operator < (const MyMoneySecurity&) const;
0074 
0075     /**
0076       * This operator tests for equality of two MyMoneySecurity objects
0077       */
0078     bool operator == (const MyMoneySecurity&) const;
0079 
0080     /**
0081       * This operator tests for inequality of this MyMoneySecurity object
0082       * and the one passed by @p r
0083       *
0084       * @param r the right side of the comparison
0085       */
0086     bool operator != (const MyMoneySecurity& r) const;
0087 
0088     QString name() const;
0089     void setName(const QString& str);
0090 
0091     QString tradingSymbol() const;
0092     void setTradingSymbol(const QString& str);
0093 
0094     eMyMoney::Security::Type securityType() const;
0095     void setSecurityType(const eMyMoney::Security::Type s);
0096 
0097     bool isCurrency() const;
0098 
0099     AlkValue::RoundingMethod roundingMethod() const;
0100     void setRoundingMethod(const AlkValue::RoundingMethod rnd);
0101 
0102     QString tradingMarket() const;
0103     void setTradingMarket(const QString& str);
0104 
0105     QString tradingCurrency() const;
0106     void setTradingCurrency(const QString& str);
0107 
0108     int smallestAccountFraction() const;
0109     void setSmallestAccountFraction(const int sf);
0110 
0111     int smallestCashFraction() const;
0112     void setSmallestCashFraction(const int cf);
0113 
0114     int pricePrecision() const;
0115     void setPricePrecision(const int pp);
0116 
0117     /**
0118      * This method checks if a reference to the given object exists. It returns,
0119      * a @p true if the object is referencing the one requested by the
0120      * parameter @p id. If it does not, this method returns @p false.
0121      *
0122      * @param id id of the object to be checked for references
0123      * @retval true This object references object with id @p id.
0124      * @retval false This object does not reference the object with id @p id.
0125      */
0126     bool hasReferenceTo(const QString& id) const override;
0127 
0128     /**
0129      * This method is used to convert the internal representation of
0130      * an security type into a human readable format
0131      *
0132      * @param securityType enumerated representation of the security type.
0133      *                     For possible values, see MyMoneySecurity::eSECURITYTYPE
0134      *
0135      * @return QString representing the human readable form
0136      */
0137     static QString securityTypeToString(const eMyMoney::Security::Type securityType);
0138 
0139     /**
0140      * This method is used to convert the internal representation of
0141      * an rounding method into a human readable format
0142      *
0143      * @param roundingMethod enumerated representation of the rouding method.
0144      *                     For possible values, see AlkValue::RoundingMethod
0145      *
0146      * @return QString representing the human readable form
0147      */
0148     static QString roundingMethodToString(const AlkValue::RoundingMethod roundingMethod);
0149 };
0150 
0151 inline void swap(MyMoneySecurity& first, MyMoneySecurity& second) // krazy:exclude=inline
0152 {
0153     using std::swap;
0154     swap(first.MyMoneyObject::d_ptr, second.MyMoneyObject::d_ptr);
0155     swap(first.MyMoneyKeyValueContainer::d_ptr, second.MyMoneyKeyValueContainer::d_ptr);
0156 }
0157 
0158 inline MyMoneySecurity::MyMoneySecurity(MyMoneySecurity && other) : MyMoneySecurity() // krazy:exclude=inline
0159 {
0160     swap(*this, other);
0161 }
0162 
0163 inline MyMoneySecurity & MyMoneySecurity::operator=(MyMoneySecurity other) // krazy:exclude=inline
0164 {
0165     swap(*this, other);
0166     return *this;
0167 }
0168 
0169 
0170 /**
0171   * Make it possible to hold @ref MyMoneySecurity objects inside @ref QVariant objects.
0172   */
0173 Q_DECLARE_METATYPE(MyMoneySecurity)
0174 
0175 #endif