Changeset View
Standalone View
kmymoney/mymoney/mymoneysecurity.h
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 44 | /** | |||
---|---|---|---|---|---|
49 | * @author Kevin Tambascio | 49 | * @author Kevin Tambascio | ||
50 | * @author Thomas Baumgart | 50 | * @author Thomas Baumgart | ||
51 | */ | 51 | */ | ||
52 | class KMM_MYMONEY_EXPORT MyMoneySecurity : public MyMoneyObject, public MyMoneyKeyValueContainer | 52 | class KMM_MYMONEY_EXPORT MyMoneySecurity : public MyMoneyObject, public MyMoneyKeyValueContainer | ||
53 | { | 53 | { | ||
54 | public: | 54 | public: | ||
55 | MyMoneySecurity(); | 55 | MyMoneySecurity(); | ||
56 | MyMoneySecurity(const QString& id, const MyMoneySecurity& equity); | 56 | MyMoneySecurity(const QString& id, const MyMoneySecurity& equity); | ||
57 | MyMoneySecurity(const QString& id, const QString& name, const QString& symbol = QString(), const int partsPerUnit = 100, const int smallestCashFraction = 100, const int smallestAccountFraction = 0); | 57 | MyMoneySecurity(const QString& id, const QString& name, const QString& symbol = QString(), | ||
58 | const int smallestCashFraction = DEFAULT_CASH_FRACTION, | ||||
59 | const int smallestAccountFraction = DEFAULT_ACCOUNT_FRACTION, | ||||
60 | const int pricePrecision = DEFAULT_PRICE_PRECISION); | ||||
58 | MyMoneySecurity(const QDomElement& node); | 61 | MyMoneySecurity(const QDomElement& node); | ||
59 | virtual ~MyMoneySecurity(); | 62 | virtual ~MyMoneySecurity(); | ||
tbaumgart: Either use
```
const int xxx = 4
```
or
```
#define xxx 4
```
but not both, please. | |||||
Yes, but I use DEFAULT_CASH_FRACTION also for MyMoneySecurity() in mymoneysecurity.cpp. I want them to be consistent and defined by single DEFAULT_CASH_FRACTION. wojnilowicz: Yes, but I use DEFAULT_CASH_FRACTION also for MyMoneySecurity() in mymoneysecurity.cpp. I want… | |||||
I think you can do it as follows: in the .h file you declare a private member static const int DEFAULT_ACCOUNT_FRACTION; in the .cpp file you define this variable as follows (outside any method) static const int MyMoneySecurity::DEFAULT_ACCOUNT_FRACTION = 4; and in the ctor you write smallestAccountFraction = DEFAULT_ACCOUNT_FRACTION; In case you need the constant outside the scope of MyMoneySecurity, make the member variable public. You can then use MyMoneySecurity::DEFAULT_ACCOUNT_FRACTION in other contexts. Note: I am not 100% sure that this will work, but have seen and used similar constructions in other code. In case you can't achieve what you want go for the #define way. tbaumgart: I think you can do it as follows:
in the .h file you declare a private member
static const… | |||||
I did it without #defines but a little bit simpler. wojnilowicz: I did it without #defines but a little bit simpler.
Now it looks like eSECURITYTYPE. | |||||
60 | 63 | | |||
61 | bool operator < (const MyMoneySecurity&) const; | 64 | bool operator < (const MyMoneySecurity&) const; | ||
62 | 65 | | |||
63 | /** | 66 | /** | ||
64 | * This operator tests for equality of two MyMoneySecurity objects | 67 | * This operator tests for equality of two MyMoneySecurity objects | ||
65 | */ | 68 | */ | ||
66 | bool operator == (const MyMoneySecurity&) const; | 69 | bool operator == (const MyMoneySecurity&) const; | ||
67 | 70 | | |||
Show All 14 Lines | 82 | typedef enum { | |||
82 | SECURITY_BOND, | 85 | SECURITY_BOND, | ||
83 | SECURITY_CURRENCY, | 86 | SECURITY_CURRENCY, | ||
84 | SECURITY_NONE | 87 | SECURITY_NONE | ||
85 | } eSECURITYTYPE; | 88 | } eSECURITYTYPE; | ||
86 | 89 | | |||
87 | const QString& name() const { | 90 | const QString& name() const { | ||
88 | return m_name; | 91 | return m_name; | ||
89 | } | 92 | } | ||
93 | | ||||
90 | void setName(const QString& str) { | 94 | void setName(const QString& str) { | ||
91 | m_name = str; | 95 | m_name = str; | ||
92 | } | 96 | } | ||
93 | 97 | | |||
94 | const QString& tradingSymbol() const { | 98 | const QString& tradingSymbol() const { | ||
95 | return m_tradingSymbol; | 99 | return m_tradingSymbol; | ||
96 | } | 100 | } | ||
101 | | ||||
97 | void setTradingSymbol(const QString& str) { | 102 | void setTradingSymbol(const QString& str) { | ||
98 | m_tradingSymbol = str; | 103 | m_tradingSymbol = str; | ||
99 | } | 104 | } | ||
100 | 105 | | |||
101 | eSECURITYTYPE securityType() const { | 106 | eSECURITYTYPE securityType() const { | ||
102 | return m_securityType; | 107 | return m_securityType; | ||
103 | } | 108 | } | ||
109 | | ||||
104 | void setSecurityType(const eSECURITYTYPE& s) { | 110 | void setSecurityType(const eSECURITYTYPE& s) { | ||
105 | m_securityType = s; | 111 | m_securityType = s; | ||
106 | } | 112 | } | ||
113 | | ||||
107 | bool isCurrency() const { | 114 | bool isCurrency() const { | ||
108 | return m_securityType == SECURITY_CURRENCY; | 115 | return m_securityType == SECURITY_CURRENCY; | ||
109 | }; | 116 | } | ||
110 | 117 | | |||
111 | AlkValue::RoundingMethod roundingMethod() const { | 118 | AlkValue::RoundingMethod roundingMethod() const { | ||
112 | return m_roundingMethod; | 119 | return m_roundingMethod; | ||
113 | } | 120 | } | ||
121 | | ||||
114 | void setRoundingMethod(const AlkValue::RoundingMethod& rnd) { | 122 | void setRoundingMethod(const AlkValue::RoundingMethod& rnd) { | ||
115 | m_roundingMethod = rnd; | 123 | m_roundingMethod = rnd; | ||
116 | } | 124 | } | ||
117 | 125 | | |||
118 | const QString& tradingMarket() const { | 126 | const QString& tradingMarket() const { | ||
119 | return m_tradingMarket; | 127 | return m_tradingMarket; | ||
120 | } | 128 | } | ||
129 | | ||||
121 | void setTradingMarket(const QString& str) { | 130 | void setTradingMarket(const QString& str) { | ||
122 | m_tradingMarket = str; | 131 | m_tradingMarket = str; | ||
123 | } | 132 | } | ||
124 | 133 | | |||
125 | const QString& tradingCurrency() const { | 134 | const QString& tradingCurrency() const { | ||
126 | return m_tradingCurrency; | 135 | return m_tradingCurrency; | ||
127 | }; | 136 | } | ||
137 | | ||||
128 | void setTradingCurrency(const QString& str) { | 138 | void setTradingCurrency(const QString& str) { | ||
129 | m_tradingCurrency = str; | 139 | m_tradingCurrency = str; | ||
130 | }; | 140 | } | ||
131 | 141 | | |||
132 | int smallestAccountFraction() const { | 142 | int smallestAccountFraction() const { | ||
133 | return m_smallestAccountFraction; | 143 | return m_smallestAccountFraction; | ||
134 | }; | 144 | } | ||
145 | | ||||
135 | void setSmallestAccountFraction(const int sf) { | 146 | void setSmallestAccountFraction(const int sf) { | ||
136 | m_smallestAccountFraction = sf; | 147 | m_smallestAccountFraction = sf; | ||
137 | }; | 148 | } | ||
138 | 149 | | |||
139 | int partsPerUnit() const { | | |||
140 | return m_partsPerUnit; | | |||
141 | }; | | |||
142 | int smallestCashFraction() const { | 150 | int smallestCashFraction() const { | ||
143 | return m_smallestCashFraction; | 151 | return m_smallestCashFraction; | ||
144 | }; | 152 | } | ||
145 | 153 | | |||
146 | void setPartsPerUnit(const int ppu) { | | |||
147 | m_partsPerUnit = ppu; | | |||
148 | }; | | |||
149 | void setSmallestCashFraction(const int sf) { | 154 | void setSmallestCashFraction(const int sf) { | ||
150 | m_smallestCashFraction = sf; | 155 | m_smallestCashFraction = sf; | ||
151 | }; | 156 | } | ||
157 | | ||||
158 | int pricePrecision() const { | ||||
159 | return m_pricePrecision; | ||||
160 | } | ||||
161 | | ||||
162 | void setPricePrecision(const int pp) { | ||||
163 | m_pricePrecision = pp; | ||||
164 | } | ||||
152 | 165 | | |||
153 | void writeXML(QDomDocument& document, QDomElement& parent) const; | 166 | void writeXML(QDomDocument& document, QDomElement& parent) const; | ||
154 | 167 | | |||
155 | /** | 168 | /** | ||
156 | * This method checks if a reference to the given object exists. It returns, | 169 | * This method checks if a reference to the given object exists. It returns, | ||
157 | * a @p true if the object is referencing the one requested by the | 170 | * a @p true if the object is referencing the one requested by the | ||
158 | * parameter @p id. If it does not, this method returns @p false. | 171 | * parameter @p id. If it does not, this method returns @p false. | ||
159 | * | 172 | * | ||
Show All 20 Lines | |||||
180 | * | 193 | * | ||
181 | * @param roundingMethod enumerated representation of the rouding method. | 194 | * @param roundingMethod enumerated representation of the rouding method. | ||
182 | * For possible values, see AlkValue::RoundingMethod | 195 | * For possible values, see AlkValue::RoundingMethod | ||
183 | * | 196 | * | ||
184 | * @return QString representing the human readable form | 197 | * @return QString representing the human readable form | ||
185 | */ | 198 | */ | ||
186 | static QString roundingMethodToString(const AlkValue::RoundingMethod roundingMethod); | 199 | static QString roundingMethodToString(const AlkValue::RoundingMethod roundingMethod); | ||
187 | 200 | | |||
188 | | ||||
189 | protected: | 201 | protected: | ||
190 | QString m_name; | 202 | QString m_name; | ||
191 | QString m_tradingSymbol; | 203 | QString m_tradingSymbol; | ||
192 | QString m_tradingMarket; | 204 | QString m_tradingMarket; | ||
193 | QString m_tradingCurrency; | 205 | QString m_tradingCurrency; | ||
194 | eSECURITYTYPE m_securityType; | 206 | eSECURITYTYPE m_securityType; | ||
195 | AlkValue::RoundingMethod m_roundingMethod; | | |||
196 | int m_smallestAccountFraction; | | |||
197 | int m_smallestCashFraction; | 207 | int m_smallestCashFraction; | ||
198 | int m_partsPerUnit; | 208 | int m_smallestAccountFraction; | ||
209 | int m_pricePrecision; | ||||
210 | AlkValue::RoundingMethod m_roundingMethod; | ||||
211 | | ||||
212 | private: | ||||
213 | enum DefaultValues { | ||||
214 | DEFAULT_CASH_FRACTION = 100, | ||||
215 | DEFAULT_ACCOUNT_FRACTION = 100, | ||||
216 | DEFAULT_PRICE_PRECISION = 4, | ||||
217 | }; | ||||
199 | }; | 218 | }; | ||
200 | 219 | | |||
201 | /** | 220 | /** | ||
202 | * Make it possible to hold @ref MyMoneySecurity objects inside @ref QVariant objects. | 221 | * Make it possible to hold @ref MyMoneySecurity objects inside @ref QVariant objects. | ||
203 | */ | 222 | */ | ||
204 | Q_DECLARE_METATYPE(MyMoneySecurity) | 223 | Q_DECLARE_METATYPE(MyMoneySecurity) | ||
205 | 224 | | |||
206 | 225 | | |||
207 | #endif | 226 | #endif |
Either use
or
but not both, please.