Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/dialogs/investactivities.cpp
Context not available. | |||||
4 | begin : Fri Dec 15 2006 | 4 | begin : Fri Dec 15 2006 | ||
---|---|---|---|---|---|
5 | copyright : (C) 2006 by Thomas Baumgart | 5 | copyright : (C) 2006 by Thomas Baumgart | ||
6 | email : Thomas Baumgart <ipwizard@users.sourceforge.net> | 6 | email : Thomas Baumgart <ipwizard@users.sourceforge.net> | ||
7 | (C) 2017 by Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> | ||||
7 | ***************************************************************************/ | 8 | ***************************************************************************/ | ||
8 | 9 | | |||
9 | /*************************************************************************** | 10 | /*************************************************************************** | ||
Context not available. | |||||
31 | // ---------------------------------------------------------------------------- | 32 | // ---------------------------------------------------------------------------- | ||
32 | // Project Includes | 33 | // Project Includes | ||
33 | 34 | | |||
35 | #include "investtransactioneditor.h" | ||||
36 | #include "mymoneymoney.h" | ||||
34 | #include "kmymoneycategory.h" | 37 | #include "kmymoneycategory.h" | ||
35 | #include "kmymoneyedit.h" | 38 | #include "kmymoneyedit.h" | ||
36 | #include "kmymoneyaccountselector.h" | 39 | #include "kmymoneyaccountselector.h" | ||
37 | #include "kmymoneycompletion.h" | 40 | #include "kmymoneycompletion.h" | ||
38 | #include <kmymoneysettings.h> | 41 | #include <kmymoneysettings.h> | ||
39 | #include "mymoneyfile.h" | 42 | #include "mymoneyfile.h" | ||
43 | #include "mymoneysplit.h" | ||||
44 | #include "mymoneyaccount.h" | ||||
45 | #include "mymoneysecurity.h" | ||||
46 | #include "dialogenums.h" | ||||
47 | #include "mymoneyenums.h" | ||||
40 | 48 | | |||
41 | using namespace Invest; | 49 | using namespace Invest; | ||
42 | using namespace KMyMoneyRegister; | 50 | using namespace KMyMoneyRegister; | ||
43 | 51 | | |||
52 | class Invest::ActivityPrivate | ||||
53 | { | ||||
54 | Q_DISABLE_COPY(ActivityPrivate) | ||||
55 | | ||||
56 | public: | ||||
57 | ActivityPrivate() | ||||
58 | { | ||||
59 | } | ||||
60 | | ||||
61 | InvestTransactionEditor *m_parent; | ||||
62 | QMap<QString, MyMoneyMoney> m_priceInfo; | ||||
63 | bool m_memoChanged; | ||||
64 | QString m_memoText; | ||||
65 | }; | ||||
66 | | ||||
67 | | ||||
68 | Activity::Activity(InvestTransactionEditor* editor) : | ||||
69 | d_ptr(new ActivityPrivate) | ||||
70 | { | ||||
71 | Q_D(Activity); | ||||
72 | d->m_memoChanged = false; | ||||
73 | d->m_parent = editor; | ||||
74 | } | ||||
75 | | ||||
76 | Activity::~Activity() | ||||
77 | { | ||||
78 | Q_D(Activity); | ||||
79 | delete d; | ||||
80 | } | ||||
81 | | ||||
82 | bool& Activity::memoChanged() | ||||
83 | { | ||||
84 | Q_D(Activity); | ||||
85 | return d->m_memoChanged; | ||||
86 | } | ||||
87 | | ||||
88 | QString& Activity::memoText() | ||||
89 | { | ||||
90 | Q_D(Activity); | ||||
91 | return d->m_memoText; | ||||
92 | } | ||||
93 | | ||||
44 | bool Activity::isComplete(QString& reason) const | 94 | bool Activity::isComplete(QString& reason) const | ||
45 | { | 95 | { | ||
96 | Q_D(const Activity); | ||||
46 | Q_UNUSED(reason) | 97 | Q_UNUSED(reason) | ||
47 | 98 | | |||
48 | bool rc = false; | 99 | auto rc = false; | ||
49 | KMyMoneySecurity* security = dynamic_cast<KMyMoneySecurity*>(haveWidget("security")); | 100 | auto security = dynamic_cast<KMyMoneySecurity*>(haveWidget("security")); | ||
50 | if (!security->currentText().isEmpty()) { | 101 | if (!security->currentText().isEmpty()) { | ||
51 | rc = (security->selector()->contains(security->currentText()) || (isMultiSelection() && m_memoChanged)); | 102 | rc = (security->selector()->contains(security->currentText()) || (isMultiSelection() && d->m_memoChanged)); | ||
52 | } | 103 | } | ||
53 | return rc; | 104 | return rc; | ||
54 | } | 105 | } | ||
55 | 106 | | |||
107 | QWidget* Activity::haveWidget(const QString& name) const | ||||
108 | { | ||||
109 | Q_D(const Activity); | ||||
110 | return d->m_parent->haveWidget(name); | ||||
111 | } | ||||
112 | | ||||
56 | bool Activity::haveAssetAccount() const | 113 | bool Activity::haveAssetAccount() const | ||
57 | { | 114 | { | ||
58 | KMyMoneyCategory* cat = dynamic_cast<KMyMoneyCategory*>(haveWidget("asset-account")); | 115 | auto cat = dynamic_cast<KMyMoneyCategory*>(haveWidget("asset-account")); | ||
59 | 116 | | |||
60 | bool rc = true; | 117 | auto rc = true; | ||
61 | if (!isMultiSelection()) | 118 | if (!isMultiSelection()) | ||
62 | rc = !cat->currentText().isEmpty(); | 119 | rc = !cat->currentText().isEmpty(); | ||
63 | 120 | | |||
Context not available. | |||||
69 | 126 | | |||
70 | bool Activity::haveCategoryAndAmount(const QString& category, const QString& amount, bool optional) const | 127 | bool Activity::haveCategoryAndAmount(const QString& category, const QString& amount, bool optional) const | ||
71 | { | 128 | { | ||
72 | KMyMoneyCategory* cat = dynamic_cast<KMyMoneyCategory*>(haveWidget(category)); | 129 | Q_D(const Activity); | ||
130 | auto cat = dynamic_cast<KMyMoneyCategory*>(haveWidget(category)); | ||||
73 | 131 | | |||
74 | bool rc = true; | 132 | auto rc = true; | ||
75 | 133 | | |||
76 | if (!cat->currentText().isEmpty()) { | 134 | if (!cat->currentText().isEmpty()) { | ||
77 | rc = cat->selector()->contains(cat->currentText()) || cat->isSplitTransaction(); | 135 | rc = cat->selector()->contains(cat->currentText()) || cat->isSplitTransaction(); | ||
Context not available. | |||||
81 | QList<MyMoneySplit>::const_iterator splitEnd; | 139 | QList<MyMoneySplit>::const_iterator splitEnd; | ||
82 | 140 | | |||
83 | if (category == "fee-account") { | 141 | if (category == "fee-account") { | ||
84 | split = m_parent->feeSplits().cbegin(); | 142 | split = d->m_parent->feeSplits().cbegin(); | ||
85 | splitEnd = m_parent->feeSplits().cend(); | 143 | splitEnd = d->m_parent->feeSplits().cend(); | ||
86 | } else if (category == "interest-account") { | 144 | } else if (category == "interest-account") { | ||
87 | split = m_parent->interestSplits().cbegin(); | 145 | split = d->m_parent->interestSplits().cbegin(); | ||
88 | splitEnd = m_parent->interestSplits().cend(); | 146 | splitEnd = d->m_parent->interestSplits().cend(); | ||
89 | } | 147 | } | ||
90 | 148 | | |||
91 | for (; split != splitEnd; ++split) { | 149 | for (; split != splitEnd; ++split) { | ||
Context not available. | |||||
103 | return rc; | 161 | return rc; | ||
104 | } | 162 | } | ||
105 | 163 | | |||
164 | bool Activity::haveFees(bool optional) const | ||||
165 | { | ||||
166 | return haveCategoryAndAmount("fee-account", "fee-amount", optional); | ||||
167 | } | ||||
168 | | ||||
169 | bool Activity::haveInterest(bool optional) const | ||||
170 | { | ||||
171 | return haveCategoryAndAmount("interest-account", "interest-amount", optional); | ||||
172 | } | ||||
173 | | ||||
106 | bool Activity::haveShares() const | 174 | bool Activity::haveShares() const | ||
107 | { | 175 | { | ||
108 | kMyMoneyEdit* amount = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | 176 | kMyMoneyEdit* amount = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | ||
Context not available. | |||||
121 | return !amount->value().isZero(); | 189 | return !amount->value().isZero(); | ||
122 | } | 190 | } | ||
123 | 191 | | |||
192 | bool Activity::isMultiSelection() const | ||||
193 | { | ||||
194 | Q_D(const Activity); | ||||
195 | return d->m_parent->isMultiSelection(); | ||||
196 | } | ||||
197 | | ||||
124 | bool Activity::createCategorySplits(const MyMoneyTransaction& t, KMyMoneyCategory* cat, kMyMoneyEdit* amount, MyMoneyMoney factor, QList<MyMoneySplit>&splits, const QList<MyMoneySplit>& osplits) const | 198 | bool Activity::createCategorySplits(const MyMoneyTransaction& t, KMyMoneyCategory* cat, kMyMoneyEdit* amount, MyMoneyMoney factor, QList<MyMoneySplit>&splits, const QList<MyMoneySplit>& osplits) const | ||
125 | { | 199 | { | ||
126 | bool rc = true; | 200 | Q_D(const Activity); | ||
201 | auto rc = true; | ||||
127 | if (!isMultiSelection() || (isMultiSelection() && !cat->currentText().isEmpty())) { | 202 | if (!isMultiSelection() || (isMultiSelection() && !cat->currentText().isEmpty())) { | ||
128 | if (!cat->isSplitTransaction()) { | 203 | if (!cat->isSplitTransaction()) { | ||
129 | splits.clear(); | 204 | splits.clear(); | ||
Context not available. | |||||
134 | s1.setAccountId(categoryId); | 209 | s1.setAccountId(categoryId); | ||
135 | s1.setValue(amount->value() * factor); | 210 | s1.setValue(amount->value() * factor); | ||
136 | if (!s1.value().isZero()) { | 211 | if (!s1.value().isZero()) { | ||
137 | rc = m_parent->setupPrice(t, s1); | 212 | rc = d->m_parent->setupPrice(t, s1); | ||
138 | } | 213 | } | ||
139 | splits.append(s1); | 214 | splits.append(s1); | ||
140 | } | 215 | } | ||
Context not available. | |||||
147 | 222 | | |||
148 | void Activity::createAssetAccountSplit(MyMoneySplit& split, const MyMoneySplit& stockSplit) const | 223 | void Activity::createAssetAccountSplit(MyMoneySplit& split, const MyMoneySplit& stockSplit) const | ||
149 | { | 224 | { | ||
150 | KMyMoneyCategory* cat = dynamic_cast<KMyMoneyCategory*>(haveWidget("asset-account")); | 225 | auto cat = dynamic_cast<KMyMoneyCategory*>(haveWidget("asset-account")); | ||
151 | if (!isMultiSelection() || (isMultiSelection() && !cat->currentText().isEmpty())) { | 226 | if (!isMultiSelection() || (isMultiSelection() && !cat->currentText().isEmpty())) { | ||
152 | QString categoryId; | 227 | QString categoryId; | ||
153 | categoryId = cat->selectedItem(); | 228 | categoryId = cat->selectedItem(); | ||
Context not available. | |||||
172 | 247 | | |||
173 | void Activity::setLabelText(const QString& idx, const QString& txt) const | 248 | void Activity::setLabelText(const QString& idx, const QString& txt) const | ||
174 | { | 249 | { | ||
175 | QLabel* w = dynamic_cast<QLabel*>(haveWidget(idx)); | 250 | auto w = dynamic_cast<QLabel*>(haveWidget(idx)); | ||
176 | if (w) { | 251 | if (w) { | ||
177 | w->setText(txt); | 252 | w->setText(txt); | ||
178 | } else { | 253 | } else { | ||
Context not available. | |||||
185 | 260 | | |||
186 | void Activity::preloadAssetAccount() | 261 | void Activity::preloadAssetAccount() | ||
187 | { | 262 | { | ||
263 | Q_D(Activity); | ||||
188 | KMyMoneyCategory* cat; | 264 | KMyMoneyCategory* cat; | ||
189 | cat = dynamic_cast<KMyMoneyCategory*>(haveWidget("asset-account")); | 265 | cat = dynamic_cast<KMyMoneyCategory*>(haveWidget("asset-account")); | ||
190 | if (cat->isVisible()) { | 266 | if (cat->isVisible()) { | ||
191 | if (cat->currentText().isEmpty()) { | 267 | if (cat->currentText().isEmpty()) { | ||
192 | MyMoneyAccount acc = MyMoneyFile::instance()->accountByName(i18n("%1 (Brokerage)", m_parent->account().name())); | 268 | MyMoneyAccount acc = MyMoneyFile::instance()->accountByName(i18n("%1 (Brokerage)", d->m_parent->account().name())); | ||
193 | if (!acc.id().isEmpty()) { | 269 | if (!acc.id().isEmpty()) { | ||
194 | bool blocked = cat->signalsBlocked(); | 270 | bool blocked = cat->signalsBlocked(); | ||
195 | // block signals, so that the focus does not go crazy | 271 | // block signals, so that the focus does not go crazy | ||
Context not available. | |||||
205 | void Activity::setWidgetVisibility(const QStringList& widgetIds, bool visible) const | 281 | void Activity::setWidgetVisibility(const QStringList& widgetIds, bool visible) const | ||
206 | { | 282 | { | ||
207 | for (QStringList::const_iterator it_w = widgetIds.constBegin(); it_w != widgetIds.constEnd(); ++it_w) { | 283 | for (QStringList::const_iterator it_w = widgetIds.constBegin(); it_w != widgetIds.constEnd(); ++it_w) { | ||
208 | QWidget* w = haveWidget(*it_w); | 284 | auto w = haveWidget(*it_w); | ||
209 | if (w) { | 285 | if (w) { | ||
210 | if (visible) { | 286 | if (visible) { | ||
211 | w->show(); | 287 | w->show(); | ||
Context not available. | |||||
216 | } | 292 | } | ||
217 | } | 293 | } | ||
218 | 294 | | |||
295 | eDialogs::PriceMode Activity::priceMode() const | ||||
296 | { | ||||
297 | Q_D(const Activity); | ||||
298 | return d->m_parent->priceMode(); | ||||
299 | } | ||||
300 | | ||||
219 | QString Activity::priceLabel() const | 301 | QString Activity::priceLabel() const | ||
220 | { | 302 | { | ||
221 | QString label; | 303 | QString label; | ||
222 | if (priceMode() == InvestTransactionEditor::Price) { | 304 | if (priceMode() == eDialogs::PriceMode::Price) { | ||
223 | label = i18n("Price"); | 305 | label = i18n("Price"); | ||
224 | } else if (priceMode() == InvestTransactionEditor::PricePerShare) { | 306 | } else if (priceMode() == eDialogs::PriceMode::PricePerShare) { | ||
225 | label = i18n("Price/share"); | 307 | label = i18n("Price/share"); | ||
226 | } else if (priceMode() == InvestTransactionEditor::PricePerTransaction) { | 308 | } else if (priceMode() == eDialogs::PriceMode::PricePerTransaction) { | ||
227 | label = i18n("Transaction amount"); | 309 | label = i18n("Transaction amount"); | ||
228 | } | 310 | } | ||
229 | return label; | 311 | return label; | ||
230 | } | 312 | } | ||
231 | 313 | | |||
314 | Buy::Buy(InvestTransactionEditor* editor) : | ||||
315 | Activity(editor) | ||||
316 | { | ||||
317 | } | ||||
318 | | ||||
319 | Buy::~Buy() | ||||
320 | { | ||||
321 | } | ||||
322 | | ||||
323 | eMyMoney::Split::InvestmentTransactionType Buy::type() const | ||||
324 | { | ||||
325 | return eMyMoney::Split::InvestmentTransactionType::BuyShares; | ||||
326 | } | ||||
327 | | ||||
232 | void Buy::showWidgets() const | 328 | void Buy::showWidgets() const | ||
233 | { | 329 | { | ||
234 | static const QStringList visibleWidgetIds = QStringList() << "asset-account" << "shares" << "price" << "total" << "interest-account" << "fee-account"; | 330 | static const QStringList visibleWidgetIds = QStringList() << "asset-account" << "shares" << "price" << "total" << "interest-account" << "fee-account"; | ||
Context not available. | |||||
246 | 342 | | |||
247 | bool Buy::isComplete(QString& reason) const | 343 | bool Buy::isComplete(QString& reason) const | ||
248 | { | 344 | { | ||
249 | bool rc = Activity::isComplete(reason); | 345 | auto rc = Activity::isComplete(reason); | ||
250 | rc &= haveAssetAccount(); | 346 | rc &= haveAssetAccount(); | ||
251 | rc &= haveFees(true); | 347 | rc &= haveFees(true); | ||
252 | rc &= haveShares(); | 348 | rc &= haveShares(); | ||
Context not available. | |||||
257 | 353 | | |||
258 | bool Buy::createTransaction(MyMoneyTransaction& t, MyMoneySplit& s0, MyMoneySplit& assetAccountSplit, QList<MyMoneySplit>& feeSplits, QList<MyMoneySplit>& m_feeSplits, QList<MyMoneySplit>& interestSplits, QList<MyMoneySplit>& m_interestSplits, MyMoneySecurity& security, MyMoneySecurity& currency) | 354 | bool Buy::createTransaction(MyMoneyTransaction& t, MyMoneySplit& s0, MyMoneySplit& assetAccountSplit, QList<MyMoneySplit>& feeSplits, QList<MyMoneySplit>& m_feeSplits, QList<MyMoneySplit>& interestSplits, QList<MyMoneySplit>& m_interestSplits, MyMoneySecurity& security, MyMoneySecurity& currency) | ||
259 | { | 355 | { | ||
356 | Q_D(Activity); | ||||
260 | Q_UNUSED(m_interestSplits); | 357 | Q_UNUSED(m_interestSplits); | ||
261 | Q_UNUSED(security); | 358 | Q_UNUSED(security); | ||
262 | Q_UNUSED(currency); | 359 | Q_UNUSED(currency); | ||
Context not available. | |||||
265 | if (!isComplete(reason)) | 362 | if (!isComplete(reason)) | ||
266 | return false; | 363 | return false; | ||
267 | 364 | | |||
268 | kMyMoneyEdit* sharesEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | 365 | auto sharesEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | ||
269 | kMyMoneyEdit* priceEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("price")); | 366 | auto priceEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("price")); | ||
270 | 367 | | |||
271 | s0.setAction(eMyMoney::Split::InvestmentTransactionType::BuyShares); | 368 | s0.setAction(eMyMoney::Split::InvestmentTransactionType::BuyShares); | ||
272 | 369 | | |||
Context not available. | |||||
283 | } | 380 | } | ||
284 | if (!isMultiSelection() || (isMultiSelection() && !priceEdit->value().isZero())) { | 381 | if (!isMultiSelection() || (isMultiSelection() && !priceEdit->value().isZero())) { | ||
285 | price = priceEdit->value().abs(); | 382 | price = priceEdit->value().abs(); | ||
286 | if (priceMode() == InvestTransactionEditor::PricePerTransaction) { | 383 | if (priceMode() == eDialogs::PriceMode::PricePerTransaction) { | ||
287 | s0.setValue(price.reduce()); | 384 | s0.setValue(price.reduce()); | ||
288 | if (!s0.shares().isZero()) | 385 | if (!s0.shares().isZero()) | ||
289 | s0.setPrice((price / s0.shares()).reduce()); | 386 | s0.setPrice((price / s0.shares()).reduce()); | ||
Context not available. | |||||
305 | 402 | | |||
306 | assetAccountSplit.setValue(-total); | 403 | assetAccountSplit.setValue(-total); | ||
307 | 404 | | |||
308 | if (!m_parent->setupPrice(t, assetAccountSplit)) | 405 | if (!d->m_parent->setupPrice(t, assetAccountSplit)) | ||
309 | return false; | 406 | return false; | ||
310 | 407 | | |||
311 | return true; | 408 | return true; | ||
312 | } | 409 | } | ||
313 | 410 | | |||
411 | Sell::Sell(InvestTransactionEditor* editor) : | ||||
412 | Activity(editor) | ||||
413 | { | ||||
414 | } | ||||
415 | | ||||
416 | Sell::~Sell() | ||||
417 | { | ||||
418 | } | ||||
419 | | ||||
420 | eMyMoney::Split::InvestmentTransactionType Sell::type() const | ||||
421 | { | ||||
422 | return eMyMoney::Split::InvestmentTransactionType::SellShares; | ||||
423 | } | ||||
424 | | ||||
314 | void Sell::showWidgets() const | 425 | void Sell::showWidgets() const | ||
315 | { | 426 | { | ||
427 | Q_D(const Activity); | ||||
316 | static const QStringList visibleWidgetIds = QStringList() << "asset-account" << "interest-amount" << "shares" << "price" << "total" << "interest-account" << "fee-account"; | 428 | static const QStringList visibleWidgetIds = QStringList() << "asset-account" << "interest-amount" << "shares" << "price" << "total" << "interest-account" << "fee-account"; | ||
317 | setWidgetVisibility(visibleWidgetIds, true); | 429 | setWidgetVisibility(visibleWidgetIds, true); | ||
318 | 430 | | |||
319 | kMyMoneyEdit* shareEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | 431 | auto shareEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | ||
320 | shareEdit->setPrecision(MyMoneyMoney::denomToPrec(m_parent->security().smallestAccountFraction())); | 432 | shareEdit->setPrecision(MyMoneyMoney::denomToPrec(d->m_parent->security().smallestAccountFraction())); | ||
321 | 433 | | |||
322 | setLabelText("interest-amount-label", i18n("Interest")); | 434 | setLabelText("interest-amount-label", i18n("Interest")); | ||
323 | setLabelText("interest-label", i18n("Interest")); | 435 | setLabelText("interest-label", i18n("Interest")); | ||
Context not available. | |||||
331 | 443 | | |||
332 | bool Sell::isComplete(QString& reason) const | 444 | bool Sell::isComplete(QString& reason) const | ||
333 | { | 445 | { | ||
334 | bool rc = Activity::isComplete(reason); | 446 | auto rc = Activity::isComplete(reason); | ||
335 | rc &= haveAssetAccount(); | 447 | rc &= haveAssetAccount(); | ||
336 | rc &= haveFees(true); | 448 | rc &= haveFees(true); | ||
337 | rc &= haveInterest(true); | 449 | rc &= haveInterest(true); | ||
Context not available. | |||||
342 | 454 | | |||
343 | bool Sell::createTransaction(MyMoneyTransaction& t, MyMoneySplit& s0, MyMoneySplit& assetAccountSplit, QList<MyMoneySplit>& feeSplits, QList<MyMoneySplit>& m_feeSplits, QList<MyMoneySplit>& interestSplits, QList<MyMoneySplit>& m_interestSplits, MyMoneySecurity& security, MyMoneySecurity& currency) | 455 | bool Sell::createTransaction(MyMoneyTransaction& t, MyMoneySplit& s0, MyMoneySplit& assetAccountSplit, QList<MyMoneySplit>& feeSplits, QList<MyMoneySplit>& m_feeSplits, QList<MyMoneySplit>& interestSplits, QList<MyMoneySplit>& m_interestSplits, MyMoneySecurity& security, MyMoneySecurity& currency) | ||
344 | { | 456 | { | ||
457 | Q_D(Activity); | ||||
345 | Q_UNUSED(m_interestSplits); | 458 | Q_UNUSED(m_interestSplits); | ||
346 | Q_UNUSED(security); | 459 | Q_UNUSED(security); | ||
347 | Q_UNUSED(currency); | 460 | Q_UNUSED(currency); | ||
Context not available. | |||||
350 | if (!isComplete(reason)) | 463 | if (!isComplete(reason)) | ||
351 | return false; | 464 | return false; | ||
352 | 465 | | |||
353 | kMyMoneyEdit* sharesEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | 466 | auto sharesEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | ||
354 | kMyMoneyEdit* priceEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("price")); | 467 | auto priceEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("price")); | ||
355 | 468 | | |||
356 | s0.setAction(eMyMoney::Split::InvestmentTransactionType::BuyShares); | 469 | s0.setAction(eMyMoney::Split::InvestmentTransactionType::BuyShares); | ||
357 | 470 | | |||
Context not available. | |||||
368 | } | 481 | } | ||
369 | if (!isMultiSelection() || (isMultiSelection() && !priceEdit->value().isZero())) { | 482 | if (!isMultiSelection() || (isMultiSelection() && !priceEdit->value().isZero())) { | ||
370 | price = priceEdit->value().abs(); | 483 | price = priceEdit->value().abs(); | ||
371 | if (priceMode() == InvestTransactionEditor::PricePerTransaction) { | 484 | if (priceMode() == eDialogs::PriceMode::PricePerTransaction) { | ||
372 | price = -price; | 485 | price = -price; | ||
373 | s0.setValue(price.reduce()); | 486 | s0.setValue(price.reduce()); | ||
374 | if (!s0.shares().isZero()) | 487 | if (!s0.shares().isZero()) | ||
Context not available. | |||||
390 | MyMoneyMoney total = sumSplits(s0, feeSplits, interestSplits); | 503 | MyMoneyMoney total = sumSplits(s0, feeSplits, interestSplits); | ||
391 | assetAccountSplit.setValue(-total); | 504 | assetAccountSplit.setValue(-total); | ||
392 | 505 | | |||
393 | if (!m_parent->setupPrice(t, assetAccountSplit)) | 506 | if (!d->m_parent->setupPrice(t, assetAccountSplit)) | ||
394 | return false; | 507 | return false; | ||
395 | 508 | | |||
396 | return true; | 509 | return true; | ||
397 | } | 510 | } | ||
398 | 511 | | |||
512 | Div::Div(InvestTransactionEditor* editor) : | ||||
513 | Activity(editor) | ||||
514 | { | ||||
515 | } | ||||
516 | | ||||
517 | Div::~Div() | ||||
518 | { | ||||
519 | } | ||||
520 | | ||||
521 | eMyMoney::Split::InvestmentTransactionType Div::type() const | ||||
522 | { | ||||
523 | return eMyMoney::Split::InvestmentTransactionType::Dividend; | ||||
524 | } | ||||
525 | | ||||
399 | void Div::showWidgets() const | 526 | void Div::showWidgets() const | ||
400 | { | 527 | { | ||
401 | static const QStringList visibleWidgetIds = QStringList() << "asset-account" << "interest-amount" << "total" << "interest-account" << "fee-account"; | 528 | static const QStringList visibleWidgetIds = QStringList() << "asset-account" << "interest-amount" << "total" << "interest-account" << "fee-account"; | ||
Context not available. | |||||
414 | { | 541 | { | ||
415 | Q_UNUSED(reason) | 542 | Q_UNUSED(reason) | ||
416 | 543 | | |||
417 | bool rc = Activity::isComplete(reason); | 544 | auto rc = Activity::isComplete(reason); | ||
418 | rc &= haveAssetAccount(); | 545 | rc &= haveAssetAccount(); | ||
419 | rc &= haveCategoryAndAmount("interest-account", QString(), false); | 546 | rc &= haveCategoryAndAmount("interest-account", QString(), false); | ||
420 | rc &= haveInterest(false); | 547 | rc &= haveInterest(false); | ||
Context not available. | |||||
423 | 550 | | |||
424 | bool Div::createTransaction(MyMoneyTransaction& t, MyMoneySplit& s0, MyMoneySplit& assetAccountSplit, QList<MyMoneySplit>& feeSplits, QList<MyMoneySplit>& m_feeSplits, QList<MyMoneySplit>& interestSplits, QList<MyMoneySplit>& m_interestSplits, MyMoneySecurity& security, MyMoneySecurity& currency) | 551 | bool Div::createTransaction(MyMoneyTransaction& t, MyMoneySplit& s0, MyMoneySplit& assetAccountSplit, QList<MyMoneySplit>& feeSplits, QList<MyMoneySplit>& m_feeSplits, QList<MyMoneySplit>& interestSplits, QList<MyMoneySplit>& m_interestSplits, MyMoneySecurity& security, MyMoneySecurity& currency) | ||
425 | { | 552 | { | ||
553 | Q_D(Activity); | ||||
426 | Q_UNUSED(m_feeSplits); | 554 | Q_UNUSED(m_feeSplits); | ||
427 | Q_UNUSED(security); | 555 | Q_UNUSED(security); | ||
428 | Q_UNUSED(currency); | 556 | Q_UNUSED(currency); | ||
Context not available. | |||||
450 | MyMoneyMoney total = sumSplits(s0, feeSplits, interestSplits); | 578 | MyMoneyMoney total = sumSplits(s0, feeSplits, interestSplits); | ||
451 | assetAccountSplit.setValue(-total); | 579 | assetAccountSplit.setValue(-total); | ||
452 | 580 | | |||
453 | if (!m_parent->setupPrice(t, assetAccountSplit)) | 581 | if (!d->m_parent->setupPrice(t, assetAccountSplit)) | ||
454 | return false; | 582 | return false; | ||
455 | 583 | | |||
456 | return true; | 584 | return true; | ||
457 | } | 585 | } | ||
458 | 586 | | |||
587 | Reinvest::Reinvest(InvestTransactionEditor* editor) : | ||||
588 | Activity(editor) | ||||
589 | { | ||||
590 | } | ||||
591 | | ||||
592 | Reinvest::~Reinvest() | ||||
593 | { | ||||
594 | } | ||||
595 | | ||||
596 | eMyMoney::Split::InvestmentTransactionType Reinvest::type() const | ||||
597 | { | ||||
598 | return eMyMoney::Split::InvestmentTransactionType::ReinvestDividend; | ||||
599 | } | ||||
600 | | ||||
459 | void Reinvest::showWidgets() const | 601 | void Reinvest::showWidgets() const | ||
460 | { | 602 | { | ||
603 | Q_D(const Activity); | ||||
461 | static const QStringList visibleWidgetIds = QStringList() << "price" << "interest-account"; | 604 | static const QStringList visibleWidgetIds = QStringList() << "price" << "interest-account"; | ||
462 | setWidgetVisibility(visibleWidgetIds, true); | 605 | setWidgetVisibility(visibleWidgetIds, true); | ||
463 | 606 | | |||
464 | kMyMoneyEdit* shareEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | 607 | auto shareEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | ||
465 | shareEdit->show(); | 608 | shareEdit->show(); | ||
466 | shareEdit->setPrecision(MyMoneyMoney::denomToPrec(m_parent->security().smallestAccountFraction())); | 609 | shareEdit->setPrecision(MyMoneyMoney::denomToPrec(d->m_parent->security().smallestAccountFraction())); | ||
467 | 610 | | |||
468 | kMyMoneyEdit* intAmount = dynamic_cast<kMyMoneyEdit*>(haveWidget("interest-amount")); | 611 | kMyMoneyEdit* intAmount = dynamic_cast<kMyMoneyEdit*>(haveWidget("interest-amount")); | ||
469 | intAmount->hide(); | 612 | intAmount->hide(); | ||
Context not available. | |||||
479 | 622 | | |||
480 | bool Reinvest::isComplete(QString& reason) const | 623 | bool Reinvest::isComplete(QString& reason) const | ||
481 | { | 624 | { | ||
482 | bool rc = Activity::isComplete(reason); | 625 | auto rc = Activity::isComplete(reason); | ||
483 | rc &= haveCategoryAndAmount("interest-account", QString(), false); | 626 | rc &= haveCategoryAndAmount("interest-account", QString(), false); | ||
484 | rc &= haveShares(); | 627 | rc &= haveShares(); | ||
485 | rc &= havePrice(); | 628 | rc &= havePrice(); | ||
Context not available. | |||||
488 | 631 | | |||
489 | bool Reinvest::createTransaction(MyMoneyTransaction& t, MyMoneySplit& s0, MyMoneySplit& assetAccountSplit, QList<MyMoneySplit>& feeSplits, QList<MyMoneySplit>& m_feeSplits, QList<MyMoneySplit>& interestSplits, QList<MyMoneySplit>& m_interestSplits, MyMoneySecurity& security, MyMoneySecurity& currency) | 632 | bool Reinvest::createTransaction(MyMoneyTransaction& t, MyMoneySplit& s0, MyMoneySplit& assetAccountSplit, QList<MyMoneySplit>& feeSplits, QList<MyMoneySplit>& m_feeSplits, QList<MyMoneySplit>& interestSplits, QList<MyMoneySplit>& m_interestSplits, MyMoneySecurity& security, MyMoneySecurity& currency) | ||
490 | { | 633 | { | ||
634 | Q_D(Activity); | ||||
491 | Q_UNUSED(assetAccountSplit); | 635 | Q_UNUSED(assetAccountSplit); | ||
492 | Q_UNUSED(security); | 636 | Q_UNUSED(security); | ||
493 | Q_UNUSED(currency); | 637 | Q_UNUSED(currency); | ||
Context not available. | |||||
497 | if (!isComplete(reason)) | 641 | if (!isComplete(reason)) | ||
498 | return false; | 642 | return false; | ||
499 | 643 | | |||
500 | kMyMoneyEdit* sharesEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | 644 | auto sharesEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | ||
501 | kMyMoneyEdit* priceEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("price")); | 645 | auto priceEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("price")); | ||
502 | 646 | | |||
503 | s0.setAction(eMyMoney::Split::InvestmentTransactionType::ReinvestDividend); | 647 | s0.setAction(eMyMoney::Split::InvestmentTransactionType::ReinvestDividend); | ||
504 | 648 | | |||
Context not available. | |||||
515 | } | 659 | } | ||
516 | if (!isMultiSelection() || (isMultiSelection() && !priceEdit->value().isZero())) { | 660 | if (!isMultiSelection() || (isMultiSelection() && !priceEdit->value().isZero())) { | ||
517 | price = priceEdit->value().abs(); | 661 | price = priceEdit->value().abs(); | ||
518 | if (priceMode() == InvestTransactionEditor::PricePerTransaction) { | 662 | if (priceMode() == eDialogs::PriceMode::PricePerTransaction) { | ||
519 | s0.setValue(price.reduce()); | 663 | s0.setValue(price.reduce()); | ||
520 | if (!s0.shares().isZero()) | 664 | if (!s0.shares().isZero()) | ||
521 | s0.setPrice((price / s0.shares()).reduce()); | 665 | s0.setPrice((price / s0.shares()).reduce()); | ||
Context not available. | |||||
539 | 683 | | |||
540 | s1.setValue(-total); | 684 | s1.setValue(-total); | ||
541 | 685 | | |||
542 | if (!m_parent->setupPrice(t, s1)) | 686 | if (!d->m_parent->setupPrice(t, s1)) | ||
543 | return false; | 687 | return false; | ||
544 | 688 | | |||
545 | return true; | 689 | return true; | ||
546 | } | 690 | } | ||
547 | 691 | | |||
692 | Add::Add(InvestTransactionEditor* editor) : | ||||
693 | Activity(editor) | ||||
694 | { | ||||
695 | } | ||||
696 | | ||||
697 | Add::~Add() | ||||
698 | { | ||||
699 | } | ||||
700 | | ||||
701 | eMyMoney::Split::InvestmentTransactionType Add::type() const | ||||
702 | { | ||||
703 | return eMyMoney::Split::InvestmentTransactionType::AddShares; | ||||
704 | } | ||||
705 | | ||||
548 | void Add::showWidgets() const | 706 | void Add::showWidgets() const | ||
549 | { | 707 | { | ||
550 | kMyMoneyEdit* shareEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | 708 | Q_D(const Activity); | ||
709 | auto shareEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | ||||
551 | shareEdit->show(); | 710 | shareEdit->show(); | ||
552 | shareEdit->setPrecision(MyMoneyMoney::denomToPrec(m_parent->security().smallestAccountFraction())); | 711 | shareEdit->setPrecision(MyMoneyMoney::denomToPrec(d->m_parent->security().smallestAccountFraction())); | ||
553 | 712 | | |||
554 | setLabelText("shares-label", i18n("Shares")); | 713 | setLabelText("shares-label", i18n("Shares")); | ||
555 | } | 714 | } | ||
556 | 715 | | |||
557 | bool Add::isComplete(QString& reason) const | 716 | bool Add::isComplete(QString& reason) const | ||
558 | { | 717 | { | ||
559 | bool rc = Activity::isComplete(reason); | 718 | auto rc = Activity::isComplete(reason); | ||
560 | rc &= haveShares(); | 719 | rc &= haveShares(); | ||
561 | return rc; | 720 | return rc; | ||
562 | } | 721 | } | ||
Context not available. | |||||
574 | if (!isComplete(reason)) | 733 | if (!isComplete(reason)) | ||
575 | return false; | 734 | return false; | ||
576 | 735 | | |||
577 | kMyMoneyEdit* sharesEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | 736 | auto sharesEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | ||
578 | 737 | | |||
579 | s0.setAction(eMyMoney::Split::InvestmentTransactionType::AddShares); | 738 | s0.setAction(eMyMoney::Split::InvestmentTransactionType::AddShares); | ||
580 | s0.setShares(sharesEdit->value().abs()); | 739 | s0.setShares(sharesEdit->value().abs()); | ||
Context not available. | |||||
589 | return true; | 748 | return true; | ||
590 | } | 749 | } | ||
591 | 750 | | |||
751 | Remove::Remove(InvestTransactionEditor* editor) : | ||||
752 | Activity(editor) | ||||
753 | { | ||||
754 | } | ||||
755 | | ||||
756 | Remove::~Remove() | ||||
757 | { | ||||
758 | } | ||||
759 | | ||||
760 | eMyMoney::Split::InvestmentTransactionType Remove::type() const | ||||
761 | { | ||||
762 | return eMyMoney::Split::InvestmentTransactionType::RemoveShares; | ||||
763 | } | ||||
764 | | ||||
592 | void Remove::showWidgets() const | 765 | void Remove::showWidgets() const | ||
593 | { | 766 | { | ||
594 | kMyMoneyEdit* shareEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | 767 | Q_D(const Activity); | ||
768 | auto shareEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | ||||
595 | shareEdit->show(); | 769 | shareEdit->show(); | ||
596 | shareEdit->setPrecision(MyMoneyMoney::denomToPrec(m_parent->security().smallestAccountFraction())); | 770 | shareEdit->setPrecision(MyMoneyMoney::denomToPrec(d->m_parent->security().smallestAccountFraction())); | ||
597 | setLabelText("shares-label", i18n("Shares")); | 771 | setLabelText("shares-label", i18n("Shares")); | ||
598 | } | 772 | } | ||
599 | 773 | | |||
600 | bool Remove::isComplete(QString& reason) const | 774 | bool Remove::isComplete(QString& reason) const | ||
601 | { | 775 | { | ||
602 | bool rc = Activity::isComplete(reason); | 776 | auto rc = Activity::isComplete(reason); | ||
603 | rc &= haveShares(); | 777 | rc &= haveShares(); | ||
604 | return rc; | 778 | return rc; | ||
605 | } | 779 | } | ||
Context not available. | |||||
617 | if (!isComplete(reason)) | 791 | if (!isComplete(reason)) | ||
618 | return false; | 792 | return false; | ||
619 | 793 | | |||
620 | kMyMoneyEdit* sharesEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | 794 | auto sharesEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | ||
621 | 795 | | |||
622 | s0.setAction(eMyMoney::Split::InvestmentTransactionType::AddShares); | 796 | s0.setAction(eMyMoney::Split::InvestmentTransactionType::AddShares); | ||
623 | s0.setShares(-(sharesEdit->value().abs())); | 797 | s0.setShares(-(sharesEdit->value().abs())); | ||
Context not available. | |||||
632 | return true; | 806 | return true; | ||
633 | } | 807 | } | ||
634 | 808 | | |||
635 | void Split::showWidgets() const | 809 | Invest::Split::Split(InvestTransactionEditor* editor) : | ||
810 | Activity(editor) | ||||
811 | { | ||||
812 | } | ||||
813 | | ||||
814 | Invest::Split::~Split() | ||||
815 | { | ||||
816 | } | ||||
817 | | ||||
818 | eMyMoney::Split::InvestmentTransactionType Invest::Split::type() const | ||||
819 | { | ||||
820 | return eMyMoney::Split::InvestmentTransactionType::SplitShares; | ||||
821 | } | ||||
822 | | ||||
823 | void Invest::Split::showWidgets() const | ||||
636 | { | 824 | { | ||
637 | // TODO do we need a special split ratio widget? | 825 | // TODO do we need a special split ratio widget? | ||
638 | // TODO maybe yes, currently the precision is the one of the fraction and might differ from it | 826 | // TODO maybe yes, currently the precision is the one of the fraction and might differ from it | ||
639 | kMyMoneyEdit* shareEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | 827 | auto shareEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | ||
640 | shareEdit->show(); | 828 | shareEdit->show(); | ||
641 | shareEdit->setPrecision(-1); | 829 | shareEdit->setPrecision(-1); | ||
642 | setLabelText("shares-label", i18n("Ratio 1/")); | 830 | setLabelText("shares-label", i18n("Ratio 1/")); | ||
643 | } | 831 | } | ||
644 | 832 | | |||
645 | bool Split::isComplete(QString& reason) const | 833 | bool Invest::Split::isComplete(QString& reason) const | ||
646 | { | 834 | { | ||
647 | bool rc = Activity::isComplete(reason); | 835 | auto rc = Activity::isComplete(reason); | ||
648 | rc &= haveShares(); | 836 | rc &= haveShares(); | ||
649 | return rc; | 837 | return rc; | ||
650 | } | 838 | } | ||
651 | 839 | | |||
652 | bool Split::createTransaction(MyMoneyTransaction& t, MyMoneySplit& s0, MyMoneySplit& assetAccountSplit, QList<MyMoneySplit>& feeSplits, QList<MyMoneySplit>& m_feeSplits, QList<MyMoneySplit>& interestSplits, QList<MyMoneySplit>& m_interestSplits, MyMoneySecurity& security, MyMoneySecurity& currency) | 840 | bool Invest::Split::createTransaction(MyMoneyTransaction& t, MyMoneySplit& s0, MyMoneySplit& assetAccountSplit, QList<MyMoneySplit>& feeSplits, QList<MyMoneySplit>& m_feeSplits, QList<MyMoneySplit>& interestSplits, QList<MyMoneySplit>& m_interestSplits, MyMoneySecurity& security, MyMoneySecurity& currency) | ||
653 | { | 841 | { | ||
654 | Q_UNUSED(t); | 842 | Q_UNUSED(t); | ||
655 | Q_UNUSED(assetAccountSplit); | 843 | Q_UNUSED(assetAccountSplit); | ||
Context not available. | |||||
658 | Q_UNUSED(security); | 846 | Q_UNUSED(security); | ||
659 | Q_UNUSED(currency); | 847 | Q_UNUSED(currency); | ||
660 | 848 | | |||
661 | kMyMoneyEdit* sharesEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | 849 | auto sharesEdit = dynamic_cast<kMyMoneyEdit*>(haveWidget("shares")); | ||
662 | 850 | | |||
663 | KMyMoneyCategory* cat; | 851 | KMyMoneyCategory* cat; | ||
664 | cat = dynamic_cast<KMyMoneyCategory*>(haveWidget("interest-account")); | 852 | cat = dynamic_cast<KMyMoneyCategory*>(haveWidget("interest-account")); | ||
Context not available. | |||||
677 | return true; | 865 | return true; | ||
678 | } | 866 | } | ||
679 | 867 | | |||
868 | IntInc::IntInc(InvestTransactionEditor* editor) : | ||||
869 | Activity(editor) | ||||
870 | { | ||||
871 | } | ||||
872 | | ||||
873 | IntInc::~IntInc() | ||||
874 | { | ||||
875 | } | ||||
876 | | ||||
877 | eMyMoney::Split::InvestmentTransactionType IntInc::type() const | ||||
878 | { | ||||
879 | return eMyMoney::Split::InvestmentTransactionType::InterestIncome; | ||||
880 | } | ||||
881 | | ||||
680 | void IntInc::showWidgets() const | 882 | void IntInc::showWidgets() const | ||
681 | { | 883 | { | ||
682 | static const QStringList visibleWidgetIds = QStringList() << "asset-account" << "interest-amount" << "total" << "interest-account" << "fee-account"; | 884 | static const QStringList visibleWidgetIds = QStringList() << "asset-account" << "interest-amount" << "total" << "interest-account" << "fee-account"; | ||
Context not available. | |||||
695 | { | 897 | { | ||
696 | Q_UNUSED(reason) | 898 | Q_UNUSED(reason) | ||
697 | 899 | | |||
698 | bool rc = Activity::isComplete(reason); | 900 | auto rc = Activity::isComplete(reason); | ||
699 | rc &= haveAssetAccount(); | 901 | rc &= haveAssetAccount(); | ||
700 | rc &= haveCategoryAndAmount("interest-account", QString(), false); | 902 | rc &= haveCategoryAndAmount("interest-account", QString(), false); | ||
701 | rc &= haveInterest(false); | 903 | rc &= haveInterest(false); | ||
Context not available. | |||||
704 | 906 | | |||
705 | bool IntInc::createTransaction(MyMoneyTransaction& t, MyMoneySplit& s0, MyMoneySplit& assetAccountSplit, QList<MyMoneySplit>& feeSplits, QList<MyMoneySplit>& m_feeSplits, QList<MyMoneySplit>& interestSplits, QList<MyMoneySplit>& m_interestSplits, MyMoneySecurity& security, MyMoneySecurity& currency) | 907 | bool IntInc::createTransaction(MyMoneyTransaction& t, MyMoneySplit& s0, MyMoneySplit& assetAccountSplit, QList<MyMoneySplit>& feeSplits, QList<MyMoneySplit>& m_feeSplits, QList<MyMoneySplit>& interestSplits, QList<MyMoneySplit>& m_interestSplits, MyMoneySecurity& security, MyMoneySecurity& currency) | ||
706 | { | 908 | { | ||
909 | Q_D(Activity); | ||||
707 | Q_UNUSED(security); | 910 | Q_UNUSED(security); | ||
708 | Q_UNUSED(currency); | 911 | Q_UNUSED(currency); | ||
709 | 912 | | |||
Context not available. | |||||
729 | MyMoneyMoney total = sumSplits(s0, feeSplits, interestSplits); | 932 | MyMoneyMoney total = sumSplits(s0, feeSplits, interestSplits); | ||
730 | assetAccountSplit.setValue(-total); | 933 | assetAccountSplit.setValue(-total); | ||
731 | 934 | | |||
732 | if (!m_parent->setupPrice(t, assetAccountSplit)) | 935 | if (!d->m_parent->setupPrice(t, assetAccountSplit)) | ||
733 | return false; | 936 | return false; | ||
734 | 937 | | |||
735 | return true; | 938 | return true; | ||
Context not available. |