1 /*
2 * Copyright 2005-2017 Thomas Baumgart <tbaumgart@kde.org>
3 * Copyright 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef MYMONEYSECURITY_H
20 #define MYMONEYSECURITY_H
21
22 #include "kmm_mymoney_export.h"
23
24 // ----------------------------------------------------------------------------
25 // QT Includes
26
27 #include <QMetaType>
28
29 // ----------------------------------------------------------------------------
30 // KDE Includes
31
32 // ----------------------------------------------------------------------------
33 // Project Includes
34
35 #include <alkimia/alkvalue.h>
36 #include "mymoneyobject.h"
37 #include "mymoneykeyvaluecontainer.h"
38
39 class QString;
40
41 namespace eMyMoney { namespace Security { enum class Type; } }
42
43 /**
44 * Class that holds all the required information about a security that the user
45 * has entered information about. A security can be a stock, a mutual fund, a bond
46 * or a currency.
47 *
48 * @author Kevin Tambascio
49 * @author Thomas Baumgart
50 * @author Łukasz Wojniłowicz
51 */
52
53 class MyMoneySecurityPrivate;
54 class KMM_MYMONEY_EXPORT MyMoneySecurity : public MyMoneyObject, public MyMoneyKeyValueContainer
55 {
56 Q_DECLARE_PRIVATE_D(MyMoneyObject::d_ptr, MyMoneySecurity)
57
58 KMM_MYMONEY_UNIT_TESTABLE
59
60 public:
61 MyMoneySecurity();
62 explicit MyMoneySecurity(const QString &id);
63
64 explicit MyMoneySecurity(const QString& id,
65 const QString& name,
66 const QString& symbol = QString(),
67 const int smallestCashFraction = 100,
68 const int smallestAccountFraction = 0,
69 const int pricePrecision = 4);
70
71 MyMoneySecurity(const QString& id,
72 const MyMoneySecurity& other);
73
74 MyMoneySecurity(const MyMoneySecurity & other);
75 MyMoneySecurity(MyMoneySecurity && other);
76 MyMoneySecurity & operator=(MyMoneySecurity other);
77 friend void swap(MyMoneySecurity& first, MyMoneySecurity& second);
78
79 ~MyMoneySecurity();
80
81 bool operator < (const MyMoneySecurity&) const;
82
83 /**
84 * This operator tests for equality of two MyMoneySecurity objects
85 */
86 bool operator == (const MyMoneySecurity&) const;
87
88 /**
89 * This operator tests for inequality of this MyMoneySecurity object
90 * and the one passed by @p r
91 *
92 * @param r the right side of the comparison
93 */
94 bool operator != (const MyMoneySecurity& r) const;
95
96 QString name() const;
97 void setName(const QString& str);
98
99 QString tradingSymbol() const;
100 void setTradingSymbol(const QString& str);
101
102 eMyMoney::Security::Type securityType() const;
103 void setSecurityType(const eMyMoney::Security::Type s);
104
105 bool isCurrency() const;
106
107 AlkValue::RoundingMethod roundingMethod() const;
108 void setRoundingMethod(const AlkValue::RoundingMethod rnd);
109
110 QString tradingMarket() const;
111 void setTradingMarket(const QString& str);
112
113 QString tradingCurrency() const;
114 void setTradingCurrency(const QString& str);
115
116 int smallestAccountFraction() const;
117 void setSmallestAccountFraction(const int sf);
118
119 int smallestCashFraction() const;
120 void setSmallestCashFraction(const int cf);
121
122 int pricePrecision() const;
123 void setPricePrecision(const int pp);
124
125 /**
126 * This method checks if a reference to the given object exists. It returns,
127 * a @p true if the object is referencing the one requested by the
128 * parameter @p id. If it does not, this method returns @p false.
129 *
130 * @param id id of the object to be checked for references
131 * @retval true This object references object with id @p id.
132 * @retval false This object does not reference the object with id @p id.
133 */
134 bool hasReferenceTo(const QString& id) const override;
135
136 /**
137 * This method is used to convert the internal representation of
138 * an security type into a human readable format
139 *
140 * @param securityType enumerated representation of the security type.
141 * For possible values, see MyMoneySecurity::eSECURITYTYPE
142 *
143 * @return QString representing the human readable form
144 */
145 static QString securityTypeToString(const eMyMoney::Security::Type securityType);
146
147 /**
148 * This method is used to convert the internal representation of
149 * an rounding method into a human readable format
150 *
151 * @param roundingMethod enumerated representation of the rouding method.
152 * For possible values, see AlkValue::RoundingMethod
153 *
154 * @return QString representing the human readable form
155 */
156 static QString roundingMethodToString(const AlkValue::RoundingMethod roundingMethod);
157 };
158
swap(MyMoneySecurity & first,MyMoneySecurity & second)159 inline void swap(MyMoneySecurity& first, MyMoneySecurity& second) // krazy:exclude=inline
160 {
161 using std::swap;
162 swap(first.MyMoneyObject::d_ptr, second.MyMoneyObject::d_ptr);
163 swap(first.MyMoneyKeyValueContainer::d_ptr, second.MyMoneyKeyValueContainer::d_ptr);
164 }
165
MyMoneySecurity(MyMoneySecurity && other)166 inline MyMoneySecurity::MyMoneySecurity(MyMoneySecurity && other) : MyMoneySecurity() // krazy:exclude=inline
167 {
168 swap(*this, other);
169 }
170
171 inline MyMoneySecurity & MyMoneySecurity::operator=(MyMoneySecurity other) // krazy:exclude=inline
172 {
173 swap(*this, other);
174 return *this;
175 }
176
177
178 /**
179 * Make it possible to hold @ref MyMoneySecurity objects inside @ref QVariant objects.
180 */
181 Q_DECLARE_METATYPE(MyMoneySecurity)
182
183 #endif
184