Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/mymoney/mymoneysecurity.cpp
Show All 30 Lines | |||||
31 | 31 | | |||
32 | #include <KLocalizedString> | 32 | #include <KLocalizedString> | ||
33 | 33 | | |||
34 | // ---------------------------------------------------------------------------- | 34 | // ---------------------------------------------------------------------------- | ||
35 | // Project Includes | 35 | // Project Includes | ||
36 | 36 | | |||
37 | #include "mymoneyexception.h" | 37 | #include "mymoneyexception.h" | ||
38 | 38 | | |||
39 | MyMoneySecurity::MyMoneySecurity() | 39 | MyMoneySecurity::MyMoneySecurity() : | ||
40 | : m_securityType(SECURITY_NONE) | 40 | m_securityType(SECURITY_NONE), | ||
41 | , m_roundingMethod(AlkValue::RoundRound) | 41 | m_smallestCashFraction(DEFAULT_CASH_FRACTION), | ||
42 | , m_smallestAccountFraction(100) | 42 | m_smallestAccountFraction(DEFAULT_ACCOUNT_FRACTION), | ||
43 | , m_smallestCashFraction(100) | 43 | m_pricePrecision(DEFAULT_PRICE_PRECISION), | ||
44 | , m_partsPerUnit(100) | 44 | m_roundingMethod(AlkValue::RoundRound) | ||
45 | { | 45 | { | ||
46 | } | 46 | } | ||
47 | 47 | | |||
48 | MyMoneySecurity::MyMoneySecurity(const QString& id, const QString& name, const QString& symbol, const int partsPerUnit, const int smallestCashFraction, const int smallestAccountFraction) | 48 | MyMoneySecurity::MyMoneySecurity(const QString& id, const QString& name, const QString& symbol, | ||
49 | : MyMoneyObject(id) | 49 | const int smallestCashFraction, const int smallestAccountFraction, const int pricePrecision) : | ||
50 | , m_name(name) | 50 | MyMoneyObject(id), | ||
51 | , m_securityType(SECURITY_CURRENCY) | 51 | m_name(name), | ||
52 | , m_roundingMethod(AlkValue::RoundRound) | 52 | m_securityType(SECURITY_CURRENCY), | ||
53 | , m_smallestCashFraction(100) | 53 | m_smallestCashFraction(smallestCashFraction), | ||
54 | , m_partsPerUnit(100) | 54 | m_smallestAccountFraction(smallestAccountFraction), | ||
55 | m_pricePrecision(pricePrecision), | ||||
56 | m_roundingMethod(AlkValue::RoundRound) | ||||
55 | { | 57 | { | ||
56 | if (symbol.isEmpty()) | 58 | if (symbol.isEmpty()) | ||
57 | m_tradingSymbol = id; | 59 | m_tradingSymbol = id; | ||
58 | else | 60 | else | ||
59 | m_tradingSymbol = symbol; | 61 | m_tradingSymbol = symbol; | ||
60 | 62 | | |||
61 | m_partsPerUnit = partsPerUnit; | | |||
62 | m_smallestCashFraction = smallestCashFraction; | | |||
63 | if (smallestAccountFraction) | 63 | if (smallestAccountFraction) | ||
64 | m_smallestAccountFraction = smallestAccountFraction; | 64 | m_smallestAccountFraction = smallestAccountFraction; | ||
65 | else | 65 | else | ||
66 | m_smallestAccountFraction = smallestCashFraction; | 66 | m_smallestAccountFraction = smallestCashFraction; | ||
67 | } | 67 | } | ||
68 | 68 | | |||
69 | MyMoneySecurity::MyMoneySecurity(const QString& id, const MyMoneySecurity& equity) : | 69 | MyMoneySecurity::MyMoneySecurity(const QString& id, const MyMoneySecurity& equity) : | ||
70 | MyMoneyObject(id) | 70 | MyMoneyObject(id) | ||
Show All 10 Lines | 80 | if (("SECURITY" != node.tagName()) | |||
81 | && ("EQUITY" != node.tagName()) | 81 | && ("EQUITY" != node.tagName()) | ||
82 | && ("CURRENCY" != node.tagName())) | 82 | && ("CURRENCY" != node.tagName())) | ||
83 | throw MYMONEYEXCEPTION("Node was not SECURITY or CURRENCY"); | 83 | throw MYMONEYEXCEPTION("Node was not SECURITY or CURRENCY"); | ||
84 | 84 | | |||
85 | setName(QStringEmpty(node.attribute("name"))); | 85 | setName(QStringEmpty(node.attribute("name"))); | ||
86 | setTradingSymbol(QStringEmpty(node.attribute("symbol"))); | 86 | setTradingSymbol(QStringEmpty(node.attribute("symbol"))); | ||
87 | setSecurityType(static_cast<eSECURITYTYPE>(node.attribute("type").toInt())); | 87 | setSecurityType(static_cast<eSECURITYTYPE>(node.attribute("type").toInt())); | ||
88 | setRoundingMethod(static_cast<AlkValue::RoundingMethod>(node.attribute("rounding-method").toInt())); | 88 | setRoundingMethod(static_cast<AlkValue::RoundingMethod>(node.attribute("rounding-method").toInt())); | ||
89 | setSmallestAccountFraction(node.attribute("saf").toInt()); | 89 | int saf = node.attribute("saf").toUInt(); | ||
90 | int pp = node.attribute("pp").toUInt(); | ||||
91 | if (saf == 0) | ||||
92 | saf = 100; | ||||
93 | if (pp == 0 || pp > 10) | ||||
94 | pp = 4; | ||||
95 | setSmallestAccountFraction(saf); | ||||
96 | setPricePrecision(pp); | ||||
90 | 97 | | |||
91 | if (isCurrency()) { | 98 | if (isCurrency()) { | ||
92 | setPartsPerUnit(node.attribute("ppu").toInt()); | 99 | int scf = node.attribute("scf").toUInt(); | ||
93 | setSmallestCashFraction(node.attribute("scf").toInt()); | 100 | if (scf == 0) | ||
101 | scf = 100; | ||||
102 | setSmallestCashFraction(scf); | ||||
94 | } else { | 103 | } else { | ||
95 | setTradingCurrency(QStringEmpty(node.attribute("trading-currency"))); | 104 | setTradingCurrency(QStringEmpty(node.attribute("trading-currency"))); | ||
96 | setTradingMarket(QStringEmpty(node.attribute("trading-market"))); | 105 | setTradingMarket(QStringEmpty(node.attribute("trading-market"))); | ||
97 | } | 106 | } | ||
98 | } | 107 | } | ||
99 | 108 | | |||
100 | MyMoneySecurity::~MyMoneySecurity() | 109 | MyMoneySecurity::~MyMoneySecurity() | ||
101 | { | 110 | { | ||
102 | } | 111 | } | ||
103 | 112 | | |||
104 | bool MyMoneySecurity::operator == (const MyMoneySecurity& r) const | 113 | bool MyMoneySecurity::operator == (const MyMoneySecurity& r) const | ||
105 | { | 114 | { | ||
106 | return (m_id == r.m_id) | 115 | return (m_id == r.m_id) | ||
107 | && (m_name == r.m_name) | 116 | && (m_name == r.m_name) | ||
108 | && (m_tradingSymbol == r.m_tradingSymbol) | 117 | && (m_tradingSymbol == r.m_tradingSymbol) | ||
109 | && (m_tradingMarket == r.m_tradingMarket) | 118 | && (m_tradingMarket == r.m_tradingMarket) | ||
110 | && (m_roundingMethod == r.m_roundingMethod) | 119 | && (m_roundingMethod == r.m_roundingMethod) | ||
111 | && (m_tradingSymbol == r.m_tradingSymbol) | 120 | && (m_tradingSymbol == r.m_tradingSymbol) | ||
112 | && (m_tradingCurrency == r.m_tradingCurrency) | 121 | && (m_tradingCurrency == r.m_tradingCurrency) | ||
113 | && (m_securityType == r.m_securityType) | 122 | && (m_securityType == r.m_securityType) | ||
114 | && (m_smallestAccountFraction == r.m_smallestAccountFraction) | 123 | && (m_smallestAccountFraction == r.m_smallestAccountFraction) | ||
115 | && (m_smallestCashFraction == r.m_smallestCashFraction) | 124 | && (m_smallestCashFraction == r.m_smallestCashFraction) | ||
116 | && (m_partsPerUnit == r.m_partsPerUnit) | 125 | && (m_pricePrecision == r.m_pricePrecision) | ||
117 | && this->MyMoneyKeyValueContainer::operator == (r); | 126 | && this->MyMoneyKeyValueContainer::operator == (r); | ||
118 | | ||||
119 | } | 127 | } | ||
120 | 128 | | |||
121 | bool MyMoneySecurity::operator < (const MyMoneySecurity& right) const | 129 | bool MyMoneySecurity::operator < (const MyMoneySecurity& right) const | ||
122 | { | 130 | { | ||
123 | if (m_securityType == right.m_securityType) | 131 | if (m_securityType == right.m_securityType) | ||
124 | return m_name < right.m_name; | 132 | return m_name < right.m_name; | ||
125 | return m_securityType < right.m_securityType; | 133 | return m_securityType < right.m_securityType; | ||
126 | } | 134 | } | ||
Show All 14 Lines | 143 | { | |||
141 | 149 | | |||
142 | writeBaseXML(document, el); | 150 | writeBaseXML(document, el); | ||
143 | 151 | | |||
144 | el.setAttribute("name", m_name); | 152 | el.setAttribute("name", m_name); | ||
145 | el.setAttribute("symbol", m_tradingSymbol); | 153 | el.setAttribute("symbol", m_tradingSymbol); | ||
146 | el.setAttribute("type", static_cast<int>(m_securityType)); | 154 | el.setAttribute("type", static_cast<int>(m_securityType)); | ||
147 | el.setAttribute("rounding-method", static_cast<int>(m_roundingMethod)); | 155 | el.setAttribute("rounding-method", static_cast<int>(m_roundingMethod)); | ||
148 | el.setAttribute("saf", m_smallestAccountFraction); | 156 | el.setAttribute("saf", m_smallestAccountFraction); | ||
149 | if (isCurrency()) { | 157 | el.setAttribute("pp", m_pricePrecision); | ||
150 | el.setAttribute("ppu", m_partsPerUnit); | 158 | if (isCurrency()) | ||
151 | el.setAttribute("scf", m_smallestCashFraction); | 159 | el.setAttribute("scf", m_smallestCashFraction); | ||
152 | } else { | 160 | else { | ||
153 | el.setAttribute("trading-currency", m_tradingCurrency); | 161 | el.setAttribute("trading-currency", m_tradingCurrency); | ||
154 | el.setAttribute("trading-market", m_tradingMarket); | 162 | el.setAttribute("trading-market", m_tradingMarket); | ||
155 | } | 163 | } | ||
156 | 164 | | |||
157 | //Add in Key-Value Pairs for securities. | 165 | //Add in Key-Value Pairs for securities. | ||
158 | MyMoneyKeyValueContainer::writeXML(document, el); | 166 | MyMoneyKeyValueContainer::writeXML(document, el); | ||
159 | 167 | | |||
160 | parent.appendChild(el); | 168 | parent.appendChild(el); | ||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |