diff --git a/kmymoney/converter/mymoneystatementreader.cpp b/kmymoney/converter/mymoneystatementreader.cpp --- a/kmymoney/converter/mymoneystatementreader.cpp +++ b/kmymoney/converter/mymoneystatementreader.cpp @@ -88,6 +88,8 @@ transactionsAdded(0), transactionsMatched(0), transactionsDuplicate(0), + m_skipCategoryMatching(true), + m_progressCallback(nullptr), scannedCategories(false) {} const QString& feeId(const MyMoneyAccount& invAcc); diff --git a/kmymoney/converter/tests/matchfinder-test.h b/kmymoney/converter/tests/matchfinder-test.h --- a/kmymoney/converter/tests/matchfinder-test.h +++ b/kmymoney/converter/tests/matchfinder-test.h @@ -103,6 +103,8 @@ void testScheduleMatch_overdue(); void testScheduleMismatch_dueDate(); void testScheduleMismatch_amount(); +public: + MatchFinderTest(); }; #endif // MATCHFINDERTEST_H diff --git a/kmymoney/converter/tests/matchfinder-test.cpp b/kmymoney/converter/tests/matchfinder-test.cpp --- a/kmymoney/converter/tests/matchfinder-test.cpp +++ b/kmymoney/converter/tests/matchfinder-test.cpp @@ -26,6 +26,12 @@ QTEST_GUILESS_MAIN(MatchFinderTest) +MatchFinderTest::MatchFinderTest() : + matchResult(TransactionMatchFinder::MatchResult::MatchNotFound) +{ + +} + void MatchFinderTest::init() { file = MyMoneyFile::instance(); diff --git a/kmymoney/converter/webpricequote.h b/kmymoney/converter/webpricequote.h --- a/kmymoney/converter/webpricequote.h +++ b/kmymoney/converter/webpricequote.h @@ -102,7 +102,7 @@ */ struct WebPriceQuoteSource { enum identifyBy {Symbol, IdentificationNumber, Name}; - WebPriceQuoteSource() : m_skipStripping(false) {} + WebPriceQuoteSource() : m_webIDBy(Symbol), m_skipStripping(false) {} explicit WebPriceQuoteSource(const QString& name); WebPriceQuoteSource(const QString& name, const QString& url, const QString& csvUrl, const QString& id, const identifyBy idBy, const QString& price, const QString& date, const QString& dateformat, bool skipStripping = false); ~WebPriceQuoteSource() {} diff --git a/kmymoney/dialogs/editpersonaldatadlg.cpp b/kmymoney/dialogs/editpersonaldatadlg.cpp --- a/kmymoney/dialogs/editpersonaldatadlg.cpp +++ b/kmymoney/dialogs/editpersonaldatadlg.cpp @@ -41,7 +41,8 @@ public: explicit EditPersonalDataDlgPrivate(EditPersonalDataDlg *qq) : q_ptr(qq), - ui(new Ui::EditPersonalDataDlg) + ui(new Ui::EditPersonalDataDlg), + m_contact(nullptr) { } diff --git a/kmymoney/dialogs/investactivities.cpp b/kmymoney/dialogs/investactivities.cpp --- a/kmymoney/dialogs/investactivities.cpp +++ b/kmymoney/dialogs/investactivities.cpp @@ -54,7 +54,9 @@ Q_DISABLE_COPY(ActivityPrivate) public: - ActivityPrivate() + ActivityPrivate() : + m_parent(nullptr), + m_memoChanged(false) { } @@ -98,7 +100,7 @@ auto rc = false; auto security = dynamic_cast(haveWidget("security")); - if (!security->currentText().isEmpty()) { + if (security && !security->currentText().isEmpty()) { rc = (security->selector()->contains(security->currentText()) || (isMultiSelection() && d->m_memoChanged)); } return rc; @@ -112,15 +114,17 @@ bool Activity::haveAssetAccount() const { + auto rc = true; auto cat = dynamic_cast(haveWidget("asset-account")); + if (!cat) + return rc; - auto rc = true; if (!isMultiSelection()) rc = !cat->currentText().isEmpty(); - if (rc && !cat->currentText().isEmpty()) { + if (rc && !cat->currentText().isEmpty()) rc = cat->selector()->contains(cat->currentText()); - } + return rc; } @@ -131,7 +135,7 @@ auto rc = true; - if (!cat->currentText().isEmpty()) { + if (cat && !cat->currentText().isEmpty()) { rc = cat->selector()->contains(cat->currentText()) || cat->isSplitTransaction(); if (rc && !amount.isEmpty() && !isMultiSelection()) { if (cat->isSplitTransaction()) { @@ -151,8 +155,8 @@ rc = false; } } else { - MyMoneyMoney value = dynamic_cast(haveWidget(amount))->value(); - rc = !value.isZero(); + if (auto valueWidget = dynamic_cast(haveWidget(amount))) + rc = !valueWidget->value().isZero(); } } } else if (!isMultiSelection() && !optional) { @@ -173,20 +177,24 @@ bool Activity::haveShares() const { - KMyMoneyEdit* amount = dynamic_cast(haveWidget("shares")); - if (isMultiSelection() && amount->value().isZero()) - return true; + if (auto amount = dynamic_cast(haveWidget("shares"))) { + if (isMultiSelection() && amount->value().isZero()) + return true; - return !amount->value().isZero(); + return !amount->value().isZero(); + } + return false; } bool Activity::havePrice() const { - KMyMoneyEdit* amount = dynamic_cast(haveWidget("price")); - if (isMultiSelection() && amount->value().isZero()) - return true; + if (auto amount = dynamic_cast(haveWidget("price"))) { + if (isMultiSelection() && amount->value().isZero()) + return true; - return !amount->value().isZero(); + return !amount->value().isZero(); + } + return false; } bool Activity::isMultiSelection() const @@ -223,9 +231,8 @@ void Activity::createAssetAccountSplit(MyMoneySplit& split, const MyMoneySplit& stockSplit) const { auto cat = dynamic_cast(haveWidget("asset-account")); - if (!isMultiSelection() || (isMultiSelection() && !cat->currentText().isEmpty())) { - QString categoryId; - categoryId = cat->selectedItem(); + if (!isMultiSelection() || (isMultiSelection() && cat && !cat->currentText().isEmpty())) { + auto categoryId = cat->selectedItem(); split.setAccountId(categoryId); } split.setMemo(stockSplit.memo()); @@ -259,9 +266,8 @@ void Activity::preloadAssetAccount() { Q_D(Activity); - KMyMoneyCategory* cat; - cat = dynamic_cast(haveWidget("asset-account")); - if (cat->isVisible()) { + auto cat = dynamic_cast(haveWidget("asset-account")); + if (cat && cat->isVisible()) { if (cat->currentText().isEmpty()) { MyMoneyAccount acc = MyMoneyFile::instance()->accountByName(i18n("%1 (Brokerage)", d->m_parent->account().name())); if (!acc.id().isEmpty()) { @@ -370,13 +376,13 @@ if (!s0.shares().isZero()) price = (s0.value() / s0.shares()).reduce(); - if (!isMultiSelection() || (isMultiSelection() && !sharesEdit->value().isZero())) { + if (!isMultiSelection() || (isMultiSelection() && sharesEdit && !sharesEdit->value().isZero())) { shares = sharesEdit->value().abs(); s0.setShares(shares); s0.setValue((shares * price).reduce()); s0.setPrice(price); } - if (!isMultiSelection() || (isMultiSelection() && !priceEdit->value().isZero())) { + if (!isMultiSelection() || (isMultiSelection() && priceEdit && !priceEdit->value().isZero())) { price = priceEdit->value().abs(); if (priceMode() == eDialogs::PriceMode::PricePerTransaction) { s0.setValue(price.reduce()); @@ -388,7 +394,10 @@ } } - if (!createCategorySplits(t, dynamic_cast(haveWidget("fee-account")), dynamic_cast(haveWidget("fee-amount")), MyMoneyMoney::ONE, feeSplits, m_feeSplits)) + auto feeAccountWidget = dynamic_cast(haveWidget("fee-account")); + auto feeAmountWidget = dynamic_cast(haveWidget("fee-amount")); + if (!feeAccountWidget || !feeAmountWidget || + !createCategorySplits(t, feeAccountWidget, feeAmountWidget, MyMoneyMoney::ONE, feeSplits, m_feeSplits)) return false; createAssetAccountSplit(assetAccountSplit, s0); @@ -426,8 +435,8 @@ static const QStringList visibleWidgetIds = QStringList() << "asset-account" << "interest-amount" << "shares" << "price" << "total" << "interest-account" << "fee-account"; setWidgetVisibility(visibleWidgetIds, true); - auto shareEdit = dynamic_cast(haveWidget("shares")); - shareEdit->setPrecision(MyMoneyMoney::denomToPrec(d->m_parent->security().smallestAccountFraction())); + if (auto shareEdit = dynamic_cast(haveWidget("shares"))) + shareEdit->setPrecision(MyMoneyMoney::denomToPrec(d->m_parent->security().smallestAccountFraction())); setLabelText("interest-amount-label", i18n("Interest")); setLabelText("interest-label", i18n("Interest")); @@ -471,13 +480,13 @@ if (!s0.shares().isZero()) price = (s0.value() / s0.shares()).reduce(); - if (!isMultiSelection() || (isMultiSelection() && !sharesEdit->value().isZero())) { + if (!isMultiSelection() || (isMultiSelection() && sharesEdit && !sharesEdit->value().isZero())) { shares = -sharesEdit->value().abs(); s0.setShares(shares); s0.setValue((shares * price).reduce()); s0.setPrice(price); } - if (!isMultiSelection() || (isMultiSelection() && !priceEdit->value().isZero())) { + if (!isMultiSelection() || (isMultiSelection() && priceEdit && !priceEdit->value().isZero())) { price = priceEdit->value().abs(); if (priceMode() == eDialogs::PriceMode::PricePerTransaction) { price = -price; @@ -490,10 +499,16 @@ } } - if (!createCategorySplits(t, dynamic_cast(haveWidget("fee-account")), dynamic_cast(haveWidget("fee-amount")), MyMoneyMoney::ONE, feeSplits, m_feeSplits)) + auto feeAccountWidget = dynamic_cast(haveWidget("fee-account")); + auto feeAmountWidget = dynamic_cast(haveWidget("fee-amount")); + if (!feeAccountWidget || !feeAmountWidget || + !createCategorySplits(t, feeAccountWidget, feeAmountWidget, MyMoneyMoney::ONE, feeSplits, m_feeSplits)) return false; - if (!createCategorySplits(t, dynamic_cast(haveWidget("interest-account")), dynamic_cast(haveWidget("interest-amount")), MyMoneyMoney::MINUS_ONE, interestSplits, m_interestSplits)) + auto interestAccountWidget = dynamic_cast(haveWidget("interest-account")); + auto interestAmountWidget = dynamic_cast(haveWidget("interest-amount")); + if (!interestAccountWidget || !interestAmountWidget || + !createCategorySplits(t, interestAccountWidget, interestAmountWidget, MyMoneyMoney::MINUS_ONE, interestSplits, m_interestSplits)) return false; createAssetAccountSplit(assetAccountSplit, s0); @@ -565,10 +580,16 @@ s0.setValue(shares); s0.setPrice(MyMoneyMoney::ONE); - if (!createCategorySplits(t, dynamic_cast(haveWidget("fee-account")), dynamic_cast(haveWidget("fee-amount")), MyMoneyMoney::ONE, feeSplits, m_feeSplits)) + auto feeAccountWidget = dynamic_cast(haveWidget("fee-account")); + auto feeAmountWidget = dynamic_cast(haveWidget("fee-amount")); + if (!feeAccountWidget || !feeAmountWidget || + !createCategorySplits(t, feeAccountWidget, feeAmountWidget, MyMoneyMoney::ONE, feeSplits, m_feeSplits)) return false; - if (!createCategorySplits(t, dynamic_cast(haveWidget("interest-account")), dynamic_cast(haveWidget("interest-amount")), MyMoneyMoney::MINUS_ONE, interestSplits, m_interestSplits)) + auto interestAccountWidget = dynamic_cast(haveWidget("interest-account")); + auto interestAmountWidget = dynamic_cast(haveWidget("interest-amount")); + if (!interestAccountWidget || !interestAmountWidget || + !createCategorySplits(t, interestAccountWidget, interestAmountWidget, MyMoneyMoney::MINUS_ONE, interestSplits, m_interestSplits)) return false; createAssetAccountSplit(assetAccountSplit, s0); @@ -602,14 +623,16 @@ static const QStringList visibleWidgetIds = QStringList() << "price" << "interest-account"; setWidgetVisibility(visibleWidgetIds, true); - auto shareEdit = dynamic_cast(haveWidget("shares")); - shareEdit->show(); - shareEdit->setPrecision(MyMoneyMoney::denomToPrec(d->m_parent->security().smallestAccountFraction())); + if (auto shareEdit = dynamic_cast(haveWidget("shares"))) { + shareEdit->show(); + shareEdit->setPrecision(MyMoneyMoney::denomToPrec(d->m_parent->security().smallestAccountFraction())); + } - KMyMoneyEdit* intAmount = dynamic_cast(haveWidget("interest-amount")); - intAmount->hide(); - setLabelText("interest-amount-label", QString()); - intAmount->setValue(MyMoneyMoney()); + if (auto intAmount = dynamic_cast(haveWidget("interest-amount"))) { + intAmount->hide(); + setLabelText("interest-amount-label", QString()); + intAmount->setValue(MyMoneyMoney()); + } setLabelText("interest-label", i18n("Interest")); setLabelText("shares-label", i18n("Shares")); @@ -649,13 +672,13 @@ if (!s0.shares().isZero()) price = (s0.value() / s0.shares()).reduce(); - if (!isMultiSelection() || (isMultiSelection() && !sharesEdit->value().isZero())) { + if (!isMultiSelection() || (isMultiSelection() && sharesEdit && !sharesEdit->value().isZero())) { shares = sharesEdit->value().abs(); s0.setShares(shares); s0.setValue((shares * price).reduce()); s0.setPrice(price); } - if (!isMultiSelection() || (isMultiSelection() && !priceEdit->value().isZero())) { + if (!isMultiSelection() || (isMultiSelection() && priceEdit && !priceEdit->value().isZero())) { price = priceEdit->value().abs(); if (priceMode() == eDialogs::PriceMode::PricePerTransaction) { s0.setValue(price.reduce()); @@ -667,7 +690,10 @@ } } - if (!createCategorySplits(t, dynamic_cast(haveWidget("interest-account")), dynamic_cast(haveWidget("interest-amount")), MyMoneyMoney::MINUS_ONE, interestSplits, m_interestSplits)) + auto interestAccountWidget = dynamic_cast(haveWidget("interest-account")); + auto interestAmountWidget = dynamic_cast(haveWidget("interest-amount")); + if (!interestAccountWidget || !interestAmountWidget || + !createCategorySplits(t, interestAccountWidget, interestAmountWidget, MyMoneyMoney::MINUS_ONE, interestSplits, m_interestSplits)) return false; if (interestSplits.count() != 1) { @@ -705,9 +731,10 @@ void Add::showWidgets() const { Q_D(const Activity); - auto shareEdit = dynamic_cast(haveWidget("shares")); - shareEdit->show(); - shareEdit->setPrecision(MyMoneyMoney::denomToPrec(d->m_parent->security().smallestAccountFraction())); + if (auto shareEdit = dynamic_cast(haveWidget("shares"))) { + shareEdit->show(); + shareEdit->setPrecision(MyMoneyMoney::denomToPrec(d->m_parent->security().smallestAccountFraction())); + } setLabelText("shares-label", i18n("Shares")); } @@ -735,7 +762,8 @@ auto sharesEdit = dynamic_cast(haveWidget("shares")); s0.setAction(eMyMoney::Split::InvestmentTransactionType::AddShares); - s0.setShares(sharesEdit->value().abs()); + if (sharesEdit) + s0.setShares(sharesEdit->value().abs()); s0.setValue(MyMoneyMoney()); s0.setPrice(MyMoneyMoney()); @@ -764,9 +792,10 @@ void Remove::showWidgets() const { Q_D(const Activity); - auto shareEdit = dynamic_cast(haveWidget("shares")); - shareEdit->show(); - shareEdit->setPrecision(MyMoneyMoney::denomToPrec(d->m_parent->security().smallestAccountFraction())); + if (auto shareEdit = dynamic_cast(haveWidget("shares"))) { + shareEdit->show(); + shareEdit->setPrecision(MyMoneyMoney::denomToPrec(d->m_parent->security().smallestAccountFraction())); + } setLabelText("shares-label", i18n("Shares")); } @@ -790,10 +819,9 @@ if (!isComplete(reason)) return false; - auto sharesEdit = dynamic_cast(haveWidget("shares")); - s0.setAction(eMyMoney::Split::InvestmentTransactionType::AddShares); - s0.setShares(-(sharesEdit->value().abs())); + if (auto sharesEdit = dynamic_cast(haveWidget("shares"))) + s0.setShares(-(sharesEdit->value().abs())); s0.setValue(MyMoneyMoney()); s0.setPrice(MyMoneyMoney()); @@ -823,9 +851,10 @@ { // TODO do we need a special split ratio widget? // TODO maybe yes, currently the precision is the one of the fraction and might differ from it - auto shareEdit = dynamic_cast(haveWidget("shares")); - shareEdit->show(); - shareEdit->setPrecision(-1); + if (auto shareEdit = dynamic_cast(haveWidget("shares"))) { + shareEdit->show(); + shareEdit->setPrecision(-1); + } setLabelText("shares-label", i18n("Ratio 1/")); } @@ -849,12 +878,15 @@ KMyMoneyCategory* cat; cat = dynamic_cast(haveWidget("interest-account")); - cat->parentWidget()->hide(); + if (cat) + cat->parentWidget()->hide(); cat = dynamic_cast(haveWidget("fee-account")); - cat->parentWidget()->hide(); + if (cat) + cat->parentWidget()->hide(); s0.setAction(eMyMoney::Split::InvestmentTransactionType::SplitShares); - s0.setShares(sharesEdit->value().abs()); + if (sharesEdit) + s0.setShares(sharesEdit->value().abs()); s0.setValue(MyMoneyMoney()); s0.setPrice(MyMoneyMoney()); @@ -921,9 +953,16 @@ s0.setValue(shares); s0.setPrice(MyMoneyMoney::ONE); - if (!createCategorySplits(t, dynamic_cast(haveWidget("fee-account")), dynamic_cast(haveWidget("fee-amount")), MyMoneyMoney::ONE, feeSplits, m_feeSplits)) + auto feeAccountWidget = dynamic_cast(haveWidget("fee-account")); + auto feeAmountWidget = dynamic_cast(haveWidget("fee-amount")); + if (!feeAccountWidget || !feeAmountWidget || + !createCategorySplits(t, feeAccountWidget, feeAmountWidget, MyMoneyMoney::ONE, feeSplits, m_feeSplits)) return false; - if (!createCategorySplits(t, dynamic_cast(haveWidget("interest-account")), dynamic_cast(haveWidget("interest-amount")), MyMoneyMoney::MINUS_ONE, interestSplits, m_interestSplits)) + + auto interestAccountWidget = dynamic_cast(haveWidget("interest-account")); + auto interestAmountWidget = dynamic_cast(haveWidget("interest-amount")); + if (!interestAccountWidget || !interestAmountWidget || + !createCategorySplits(t, interestAccountWidget, interestAmountWidget, MyMoneyMoney::MINUS_ONE, interestSplits, m_interestSplits)) return false; createAssetAccountSplit(assetAccountSplit, s0); diff --git a/kmymoney/dialogs/investtransactioneditor.cpp b/kmymoney/dialogs/investtransactioneditor.cpp --- a/kmymoney/dialogs/investtransactioneditor.cpp +++ b/kmymoney/dialogs/investtransactioneditor.cpp @@ -4,7 +4,7 @@ begin : Fri Dec 15 2006 copyright : (C) 2006 by Thomas Baumgart email : Thomas Baumgart - (C) 2017 by Łukasz Wojniłowicz + (C) 2017, 2018 by Łukasz Wojniłowicz ***************************************************************************/ /*************************************************************************** @@ -74,7 +74,8 @@ public: InvestTransactionEditorPrivate(InvestTransactionEditor* qq) : TransactionEditorPrivate(qq), - m_activity(0) + m_activity(0), + m_transactionType(eMyMoney::Split::InvestmentTransactionType::BuyShares) { m_phonyAccount = MyMoneyAccount("Phony-ID", MyMoneyAccount()); } @@ -87,7 +88,7 @@ void hideCategory(const QString& name) { Q_Q(InvestTransactionEditor); - if (KMyMoneyCategory* cat = dynamic_cast(q->haveWidget(name))) { + if (auto cat = dynamic_cast(q->haveWidget(name))) { cat->hide(); cat->splitButton()->hide(); } @@ -188,12 +189,16 @@ m_openEditSplits = true; // force focus change to update all data - KMyMoneyCategory* category = dynamic_cast(m_editWidgets[categoryWidgetName]); + auto category = dynamic_cast(m_editWidgets[categoryWidgetName]); + if (!category) + return rc; QWidget* w = category->splitButton(); if (w) w->setFocus(); - KMyMoneyEdit* amount = dynamic_cast(q->haveWidget(amountWidgetName)); + auto amount = dynamic_cast(q->haveWidget(amountWidgetName)); + if (!amount) + return rc; MyMoneyTransaction transaction; transaction.setCommodity(m_currency.id()); @@ -262,10 +267,13 @@ void updatePriceMode(const MyMoneySplit& split = MyMoneySplit()) { Q_Q(InvestTransactionEditor); - auto label = dynamic_cast(q->haveWidget("price-label")); - if (label) { + if (auto label = dynamic_cast(q->haveWidget("price-label"))) { auto sharesEdit = dynamic_cast(q->haveWidget("shares")); auto priceEdit = dynamic_cast(q->haveWidget("price")); + + if (!sharesEdit || !priceEdit) + return; + MyMoneyMoney price; if (!split.id().isEmpty()) price = split.price().reduce(); @@ -541,12 +549,16 @@ static const QSet transactionTypesWithoutFee = QSet() << eMyMoney::Split::InvestmentTransactionType::AddShares << eMyMoney::Split::InvestmentTransactionType::RemoveShares << eMyMoney::Split::InvestmentTransactionType::SplitShares; - KMyMoneyEdit* feeAmount = dynamic_cast(haveWidget("fee-amount")); + auto feeAmount = dynamic_cast(haveWidget("fee-amount")); + if (!feeAmount) + return; feeAmount->setHidden(txt.isEmpty()); - QLabel* l = dynamic_cast(haveWidget("fee-amount-label")); + auto l = dynamic_cast(haveWidget("fee-amount-label")); - KMyMoneyCategory* fee = dynamic_cast(haveWidget("fee-account")); - const bool hideFee = txt.isEmpty() || transactionTypesWithoutFee.contains(d->m_activity->type()); + auto fee = dynamic_cast(haveWidget("fee-account")); + if (!fee) + return; + const auto hideFee = txt.isEmpty() || transactionTypesWithoutFee.contains(d->m_activity->type()); // no fee expected so hide if (hideFee) { if (l) { @@ -576,10 +588,10 @@ QWidget* w = haveWidget("interest-amount"); w->setHidden(txt.isEmpty()); - QLabel* l = dynamic_cast(haveWidget("interest-amount-label")); + auto l = dynamic_cast(haveWidget("interest-amount-label")); - KMyMoneyCategory* interest = dynamic_cast(haveWidget("interest-account")); - const bool showInterest = !txt.isEmpty() && transactionTypesWithInterest.contains(d->m_activity->type()); + auto interest = dynamic_cast(haveWidget("interest-account")); + const auto showInterest = !txt.isEmpty() && transactionTypesWithInterest.contains(d->m_activity->type()); if (interest && showInterest) { interest->splitButton()->show(); w->show(); @@ -612,6 +624,9 @@ auto fees = dynamic_cast(haveWidget("fee-account")); auto security = dynamic_cast(haveWidget("security")); + if (!interest || !fees || !security) + return; + AccountSet aSet; QString id; @@ -652,6 +667,10 @@ auto interest = dynamic_cast(haveWidget("interest-account")); auto fees = dynamic_cast(haveWidget("fee-account")); + if (!postDate || !reconcile || !security || !activity || + !asset || !memo || !interest || !fees) + return; + // check if the current transaction has a reference to an equity account auto haveEquityAccount = false; foreach (const auto split, d->m_transaction.splits()) { @@ -725,6 +744,8 @@ // don't set the value if the number of shares is zero so that // we can see the hint value = dynamic_cast(haveWidget("shares")); + if (!value) + return; if (typeid(*(d->m_activity)) != typeid(Invest::Split(this))) value->setPrecision(MyMoneyMoney::denomToPrec(d->m_security.smallestAccountFraction())); else @@ -738,10 +759,14 @@ // fee amount value = dynamic_cast(haveWidget("fee-amount")); + if (!value) + return; value->setValue(d->subtotal(d->m_feeSplits)); // interest amount value = dynamic_cast(haveWidget("interest-amount")); + if (!value) + return; value->setValue(-d->subtotal(d->m_interestSplits)); // total @@ -776,6 +801,8 @@ QStringList::const_iterator it_f; for (it_f = fields.constBegin(); it_f != fields.constEnd(); ++it_f) { value = dynamic_cast(haveWidget((*it_f))); + if (!value) + return; value->setText(""); value->setAllowEmpty(); } @@ -814,10 +841,12 @@ if (!currencyKnown) { d->m_currency.setTradingSymbol("???"); } else { - if (typeid(*(d->m_activity)) != typeid(Invest::Split(this))) { - dynamic_cast(haveWidget("shares"))->setPrecision(MyMoneyMoney::denomToPrec(d->m_security.smallestAccountFraction())); - } else { - dynamic_cast(haveWidget("shares"))->setPrecision(-1); + auto sharesWidget = dynamic_cast(haveWidget("shares")); + if (sharesWidget) { + if (typeid(*(d->m_activity)) != typeid(Invest::Split(this))) + sharesWidget->setPrecision(MyMoneyMoney::denomToPrec(d->m_security.smallestAccountFraction())); + else + sharesWidget->setPrecision(-1); } } @@ -849,6 +878,10 @@ auto feesEdit = dynamic_cast(haveWidget("fee-amount")); auto interestEdit = dynamic_cast(haveWidget("interest-amount")); + if (!activityCombo || !sharesEdit || !priceEdit || + !feesEdit || !interestEdit) + return; + if (priceMode() == eDialogs::PriceMode::PricePerTransaction) amount = priceEdit->value().abs(); else @@ -885,7 +918,7 @@ void InvestTransactionEditor::slotUpdateTotalAmount() { Q_D(InvestTransactionEditor); - QLabel* total = dynamic_cast(haveWidget("total")); + auto total = dynamic_cast(haveWidget("total")); if (total && total->isVisible()) { MyMoneyMoney amount; @@ -941,14 +974,14 @@ d->m_activity->showWidgets(); d->m_activity->preloadAssetAccount(); - if (KMyMoneyCategory* cat = dynamic_cast(haveWidget("interest-account"))) { + if (auto cat = dynamic_cast(haveWidget("interest-account"))) { if (cat->parentWidget()->isVisible()) slotUpdateInterestVisibility(cat->currentText()); else cat->splitButton()->hide(); } - if (KMyMoneyCategory* cat = dynamic_cast(haveWidget("fee-account"))) { + if (auto cat = dynamic_cast(haveWidget("fee-account"))) { if (cat->parentWidget()->isVisible()) slotUpdateFeeVisibility(cat->currentText()); else @@ -960,9 +993,10 @@ { Q_D(const InvestTransactionEditor); eDialogs::PriceMode mode = static_cast(eDialogs::PriceMode::Price); - KMyMoneySecurity* sec = dynamic_cast(d->m_editWidgets["security"]); + auto sec = dynamic_cast(d->m_editWidgets["security"]); + QString accId; - if (!sec->currentText().isEmpty()) { + if (sec && !sec->currentText().isEmpty()) { accId = sec->selectedItem(); if (accId.isEmpty()) accId = d->m_account.id(); @@ -1064,8 +1098,8 @@ MyMoneySplit s0 = sorig; s0.clearId(); - KMyMoneySecurity* sec = dynamic_cast(d->m_editWidgets["security"]); - if (!isMultiSelection() || (isMultiSelection() && !sec->currentText().isEmpty())) { + auto sec = dynamic_cast(d->m_editWidgets["security"]); + if (!isMultiSelection() || (isMultiSelection() && sec && !sec->currentText().isEmpty())) { QString securityId = sec->selectedItem(); if (!securityId.isEmpty()) { s0.setAccountId(securityId); @@ -1099,8 +1133,8 @@ t.removeSplits(); - KMyMoneyDateInput* postDate = dynamic_cast(d->m_editWidgets["postdate"]); - if (postDate->date().isValid()) { + auto postDate = dynamic_cast(d->m_editWidgets["postdate"]); + if (postDate && postDate->date().isValid()) { t.setPostDate(postDate->date()); } @@ -1109,7 +1143,7 @@ // FIXME a better approach would be to have a 'dirty' flag with the widgets // which identifies if the originally loaded value has been modified // by the user - KTextEdit* memo = dynamic_cast(d->m_editWidgets["memo"]); + auto memo = dynamic_cast(d->m_editWidgets["memo"]); if (memo) { if (!isMultiSelection() || (isMultiSelection() && d->m_activity->memoChanged())) s0.setMemo(memo->toPlainText()); @@ -1147,13 +1181,13 @@ // if the activity is not set in the combo widget, we keep // the one which is used in the original transaction auto activityCombo = dynamic_cast(haveWidget("activity")); - if (activityCombo->activity() == eMyMoney::Split::InvestmentTransactionType::UnknownTransactionType) { + if (activityCombo && activityCombo->activity() == eMyMoney::Split::InvestmentTransactionType::UnknownTransactionType) { d->activityFactory(transactionType); } // if we mark the split reconciled here, we'll use today's date if no reconciliation date is given auto status = dynamic_cast(d->m_editWidgets["status"]); - if (status->state() != eMyMoney::Split::State::Unknown) + if (status && status->state() != eMyMoney::Split::State::Unknown) s0.setReconcileFlag(status->state()); if (s0.reconcileFlag() == eMyMoney::Split::State::Reconciled && !s0.reconcileDate().isValid()) diff --git a/kmymoney/dialogs/kaccountselectdlg.cpp b/kmymoney/dialogs/kaccountselectdlg.cpp --- a/kmymoney/dialogs/kaccountselectdlg.cpp +++ b/kmymoney/dialogs/kaccountselectdlg.cpp @@ -65,6 +65,8 @@ public: KAccountSelectDlgPrivate() : ui(new Ui::KAccountSelectDlg), + m_mode(0), + m_accountType(eDialogs::Category::none), m_aborted(false) { } diff --git a/kmymoney/dialogs/kcurrencyeditdlg.cpp b/kmymoney/dialogs/kcurrencyeditdlg.cpp --- a/kmymoney/dialogs/kcurrencyeditdlg.cpp +++ b/kmymoney/dialogs/kcurrencyeditdlg.cpp @@ -108,10 +108,13 @@ Q_DECLARE_PUBLIC(KCurrencyEditDlg) public: - explicit KCurrencyEditDlgPrivate(KCurrencyEditDlg *qq) - : q_ptr(qq) - , ui(new Ui::KCurrencyEditDlg) - , m_inLoading(false) + explicit KCurrencyEditDlgPrivate(KCurrencyEditDlg *qq) : + q_ptr(qq), + ui(new Ui::KCurrencyEditDlg), + m_availableCurrencyDlg(nullptr), + m_currencyEditorDlg(nullptr), + m_searchWidget(nullptr), + m_inLoading(false) { } diff --git a/kmymoney/dialogs/keditscheduledlg.cpp b/kmymoney/dialogs/keditscheduledlg.cpp --- a/kmymoney/dialogs/keditscheduledlg.cpp +++ b/kmymoney/dialogs/keditscheduledlg.cpp @@ -76,7 +76,10 @@ public: explicit KEditScheduleDlgPrivate(KEditScheduleDlg *qq) : q_ptr(qq), - ui(new Ui::KEditScheduleDlg) + ui(new Ui::KEditScheduleDlg), + m_item(nullptr), + m_editor(nullptr), + m_requiredFields(nullptr) { } @@ -315,8 +318,10 @@ // a possibly assigned check number if (d->m_schedule.paymentType() != Schedule::PaymentType::WriteChecque) { QWidget* w = editor->haveWidget("number"); - if (w) - dynamic_cast(w)->loadText(QString()); + if (w) { + if (auto numberWidget = dynamic_cast(w)) + numberWidget->loadText(QString()); + } } Q_ASSERT(!d->m_tabOrderWidgets.isEmpty()); @@ -361,8 +366,7 @@ } // connect the postdate modification signal to our update routine - KMyMoneyDateInput* dateEdit = dynamic_cast(editor->haveWidget("postdate")); - if (dateEdit) + if (auto dateEdit = dynamic_cast(editor->haveWidget("postdate"))) connect(dateEdit, &KMyMoneyDateInput::dateChanged, this, &KEditScheduleDlg::slotPostDateChanged); d->ui->m_nameEdit->setFocus(); @@ -373,10 +377,8 @@ d->m_requiredFields->add(editor->haveWidget("category")); // fix labels - QLabel* label = dynamic_cast(editor->haveWidget("date-label")); - if (label) { + if (auto label = dynamic_cast(editor->haveWidget("date-label"))) label->setText(i18n("Next due date")); - } d->m_editor = editor; slotSetPaymentMethod((int)d->m_schedule.paymentType()); @@ -434,8 +436,7 @@ d->m_schedule.setType(Schedule::Type::Bill); - KMyMoneyTransactionForm::TabBar* tabbar = dynamic_cast(d->m_editor->haveWidget("tabbar")); - if (tabbar) { + if (auto tabbar = dynamic_cast(d->m_editor->haveWidget("tabbar"))) { switch (static_cast(tabbar->currentIndex())) { case eWidgets::eRegister::Action::Deposit: d->m_schedule.setType(Schedule::Type::Deposit); @@ -625,8 +626,8 @@ { Q_D(KEditScheduleDlg); // Make sure the required fields are set - auto dateEdit = dynamic_cast(d->m_editor->haveWidget("postdate")); - d->m_schedule.setNextDueDate(dateEdit->date()); + if (auto dateEdit = dynamic_cast(d->m_editor->haveWidget("postdate"))) + d->m_schedule.setNextDueDate(dateEdit->date()); d->m_schedule.setOccurrencePeriod(static_cast(d->ui->m_frequencyEdit->currentItem())); d->m_schedule.setOccurrenceMultiplier(d->ui->m_frequencyNoEdit->value()); @@ -641,8 +642,8 @@ { Q_D(KEditScheduleDlg); // Make sure the required fields are set - auto dateEdit = dynamic_cast(d->m_editor->haveWidget("postdate")); - d->m_schedule.setNextDueDate(dateEdit->date()); + if (auto dateEdit = dynamic_cast(d->m_editor->haveWidget("postdate"))) + d->m_schedule.setNextDueDate(dateEdit->date()); d->m_schedule.setOccurrencePeriod(static_cast(d->ui->m_frequencyEdit->currentItem())); d->m_schedule.setOccurrenceMultiplier(d->ui->m_frequencyNoEdit->value()); @@ -669,16 +670,13 @@ void KEditScheduleDlg::slotSetPaymentMethod(int item) { Q_D(KEditScheduleDlg); - auto dateEdit = dynamic_cast(d->m_editor->haveWidget("number")); - if (dateEdit) { + if (auto dateEdit = dynamic_cast(d->m_editor->haveWidget("number"))) { dateEdit->setVisible(item == (int)Schedule::PaymentType::WriteChecque); // hiding the label does not work, because the label underneath will shine // through. So we either write the label or a blank - QLabel* label = dynamic_cast(d->m_editor->haveWidget("number-label")); - if (label) { + if (auto label = dynamic_cast(d->m_editor->haveWidget("number-label"))) label->setText((item == (int)Schedule::PaymentType::WriteChecque) ? i18n("Number") : " "); - } } } @@ -714,8 +712,8 @@ if (isEndSeries && (item != (int)Schedule::Occurrence::Once)) { // Changing the frequency changes the number // of remaining transactions - KMyMoneyDateInput* dateEdit = dynamic_cast(d->m_editor->haveWidget("postdate")); - d->m_schedule.setNextDueDate(dateEdit->date()); + if (auto dateEdit = dynamic_cast(d->m_editor->haveWidget("postdate"))) + d->m_schedule.setNextDueDate(dateEdit->date()); d->m_schedule.setOccurrenceMultiplier(d->ui->m_frequencyNoEdit->value()); d->m_schedule.setOccurrencePeriod(static_cast(item)); d->m_schedule.setEndDate(d->ui->m_FinalPaymentEdit->date()); @@ -730,8 +728,8 @@ auto oldOccurrenceMultiplier = d->m_schedule.occurrenceMultiplier(); if (multiplier != oldOccurrenceMultiplier) { if (d->ui->m_endOptionsFrame->isEnabled()) { - KMyMoneyDateInput* dateEdit = dynamic_cast(d->m_editor->haveWidget("postdate")); - d->m_schedule.setNextDueDate(dateEdit->date()); + if (auto dateEdit = dynamic_cast(d->m_editor->haveWidget("postdate"))) + d->m_schedule.setNextDueDate(dateEdit->date()); d->m_schedule.setOccurrenceMultiplier(multiplier); d->m_schedule.setOccurrencePeriod(static_cast(d->ui->m_frequencyEdit->currentItem())); d->m_schedule.setEndDate(d->ui->m_FinalPaymentEdit->date()); diff --git a/kmymoney/dialogs/kenterscheduledlg.cpp b/kmymoney/dialogs/kenterscheduledlg.cpp --- a/kmymoney/dialogs/kenterscheduledlg.cpp +++ b/kmymoney/dialogs/kenterscheduledlg.cpp @@ -74,7 +74,8 @@ KEnterScheduleDlgPrivate() : ui(new Ui::KEnterScheduleDlg), m_item(nullptr), - m_showWarningOnce(true) + m_showWarningOnce(true), + m_extendedReturnCode(eDialogs::ScheduleResultCode::Cancel) { } @@ -82,7 +83,7 @@ { delete ui; } - + Ui::KEnterScheduleDlg *ui; MyMoneySchedule m_schedule; KMyMoneyRegister::Transaction* m_item; @@ -294,14 +295,15 @@ num = KMyMoneyUtils::nextCheckNumber(d->m_schedule.account()); KMyMoneyUtils::updateLastNumberUsed(d->m_schedule.account(), num); d->m_schedule.account().setValue("lastNumberUsed", num); - if (w) { - dynamic_cast(w)->loadText(num); - } + if (w) + if (auto numberWidget = dynamic_cast(w)) + numberWidget->loadText(num); } else { // if it's not a check, then we need to clear // a possibly assigned check number if (w) - dynamic_cast(w)->loadText(QString()); + if (auto numberWidget = dynamic_cast(w)) + numberWidget->loadText(QString()); } Q_ASSERT(!d->m_tabOrderWidgets.isEmpty()); @@ -337,10 +339,8 @@ focusWidget->setFocus(); // Make sure, we use the adjusted date - KMyMoneyDateInput* dateEdit = dynamic_cast(editor->haveWidget("postdate")); - if (dateEdit) { + if (auto dateEdit = dynamic_cast(editor->haveWidget("postdate"))) dateEdit->setDate(d->m_schedule.adjustedNextDueDate()); - } } return editor; @@ -350,7 +350,7 @@ { Q_D(KEnterScheduleDlg); auto rc = false; - + auto w = qApp->focusWidget(); int currentWidgetIndex = d->m_tabOrderWidgets.indexOf(w); while (w && currentWidgetIndex == -1) { diff --git a/kmymoney/dialogs/kequitypriceupdateconfdlg.cpp b/kmymoney/dialogs/kequitypriceupdateconfdlg.cpp --- a/kmymoney/dialogs/kequitypriceupdateconfdlg.cpp +++ b/kmymoney/dialogs/kequitypriceupdateconfdlg.cpp @@ -27,7 +27,8 @@ public: EquityPriceUpdateConfDlgPrivate() : - ui(new Ui::EquityPriceUpdateConfDlg) + ui(new Ui::EquityPriceUpdateConfDlg), + m_updatingPricePolicy(eDialogs::UpdatePrice::All) { } diff --git a/kmymoney/dialogs/kequitypriceupdatedlg.cpp b/kmymoney/dialogs/kequitypriceupdatedlg.cpp --- a/kmymoney/dialogs/kequitypriceupdatedlg.cpp +++ b/kmymoney/dialogs/kequitypriceupdatedlg.cpp @@ -74,7 +74,9 @@ public: explicit KEquityPriceUpdateDlgPrivate(KEquityPriceUpdateDlg *qq) : q_ptr(qq), - ui(new Ui::KEquityPriceUpdateDlg) + ui(new Ui::KEquityPriceUpdateDlg), + m_fUpdateAll(false), + m_updatingPricePolicy(eDialogs::UpdatePrice::All) { } @@ -519,11 +521,13 @@ // Give the user some options int result; - if (_kmmID.contains(" ")) { + if (_kmmID.contains(" ")) result = KMessageBox::warningContinueCancel(this, i18n("Failed to retrieve an exchange rate for %1 from %2. It will be skipped this time.", _webID, item->text(SOURCE_COL)), i18n("Price Update Failed")); - } else { - result = KMessageBox::questionYesNoCancel(this, QString("%1").arg(i18n("Failed to retrieve a quote for %1 from %2. Press No to remove the online price source from this security permanently, Yes to continue updating this security during future price updates or Cancel to stop the current update operation.", _webID, item->text(SOURCE_COL))), i18n("Price Update Failed"), KStandardGuiItem::yes(), KStandardGuiItem::no()); - } + else if (!item) + return; + else + result = KMessageBox::questionYesNoCancel(this, QString::fromLatin1("%1").arg(i18n("Failed to retrieve a quote for %1 from %2. Press No to remove the online price source from this security permanently, Yes to continue updating this security during future price updates or Cancel to stop the current update operation.", _webID, item->text(SOURCE_COL))), i18n("Price Update Failed"), KStandardGuiItem::yes(), KStandardGuiItem::no()); + if (result == KMessageBox::No) { // Disable price updates for this security @@ -631,7 +635,7 @@ break; case eDialogs::UpdatePrice::Ask: { - int result = KMessageBox::questionYesNoCancel(this, + auto result = KMessageBox::questionYesNoCancel(this, i18n("For %1 on %2 price %3 already exists.
" "Do you want to replace it with %4?", storedPrice.from(), storedPrice.date().toString(Qt::ISODate), diff --git a/kmymoney/dialogs/kfindtransactiondlg_p.h b/kmymoney/dialogs/kfindtransactiondlg_p.h --- a/kmymoney/dialogs/kfindtransactiondlg_p.h +++ b/kmymoney/dialogs/kfindtransactiondlg_p.h @@ -70,7 +70,8 @@ explicit KFindTransactionDlgPrivate(KFindTransactionDlg *qq) : q_ptr(qq), - ui(new Ui::KFindTransactionDlg) + ui(new Ui::KFindTransactionDlg), + m_needReload(true) { } diff --git a/kmymoney/dialogs/kgpgkeyselectiondlg.cpp b/kmymoney/dialogs/kgpgkeyselectiondlg.cpp --- a/kmymoney/dialogs/kgpgkeyselectiondlg.cpp +++ b/kmymoney/dialogs/kgpgkeyselectiondlg.cpp @@ -46,6 +46,7 @@ ~KGpgKeySelectionDlgPrivate() { + delete ui; } Ui::KGpgKeySelectionDlg* ui; diff --git a/kmymoney/dialogs/kmymoneypricedlg.cpp b/kmymoney/dialogs/kmymoneypricedlg.cpp --- a/kmymoney/dialogs/kmymoneypricedlg.cpp +++ b/kmymoney/dialogs/kmymoneypricedlg.cpp @@ -85,6 +85,7 @@ explicit KMyMoneyPriceDlgPrivate(KMyMoneyPriceDlg *qq) : q_ptr(qq), ui(new Ui::KMyMoneyPriceDlg), + m_currentItem(nullptr), m_searchWidget(nullptr) { } diff --git a/kmymoney/dialogs/kmymoneysplittable.cpp b/kmymoney/dialogs/kmymoneysplittable.cpp --- a/kmymoney/dialogs/kmymoneysplittable.cpp +++ b/kmymoney/dialogs/kmymoneysplittable.cpp @@ -81,6 +81,9 @@ m_currentRow(0), m_maxRows(0), m_precision(2), + m_contextMenu(nullptr), + m_contextMenuDelete(nullptr), + m_contextMenuDuplicate(nullptr), m_editCategory(0), m_editMemo(0), m_editAmount(0) @@ -350,11 +353,12 @@ // a completion list. In this case, we close the completion list and // do not end editing of the transaction. if (o->inherits("KLineEdit")) { - KLineEdit* le = dynamic_cast(o); - KCompletionBox* box = le->completionBox(false); - if (box && box->isVisible()) { - terminate = false; - le->completionBox(false)->hide(); + if (auto le = dynamic_cast(o)) { + KCompletionBox* box = le->completionBox(false); + if (box && box->isVisible()) { + terminate = false; + le->completionBox(false)->hide(); + } } } diff --git a/kmymoney/dialogs/knewaccountdlg.cpp b/kmymoney/dialogs/knewaccountdlg.cpp --- a/kmymoney/dialogs/knewaccountdlg.cpp +++ b/kmymoney/dialogs/knewaccountdlg.cpp @@ -67,7 +67,10 @@ public: explicit KNewAccountDlgPrivate(KNewAccountDlg *qq) : q_ptr(qq), - ui(new Ui::KNewAccountDlg) + ui(new Ui::KNewAccountDlg), + m_filterProxyModel(nullptr), + m_categoryEditor(false), + m_isEditing(false) { } diff --git a/kmymoney/dialogs/knewequityentrydlg.cpp b/kmymoney/dialogs/knewequityentrydlg.cpp --- a/kmymoney/dialogs/knewequityentrydlg.cpp +++ b/kmymoney/dialogs/knewequityentrydlg.cpp @@ -42,11 +42,11 @@ class KNewEquityEntryDlgPrivate { Q_DISABLE_COPY(KNewEquityEntryDlgPrivate) - Q_DECLARE_PUBLIC(KNewEquityEntryDlg) public: KNewEquityEntryDlgPrivate() : - ui(new Ui::KNewEquityEntryDlg) + ui(new Ui::KNewEquityEntryDlg), + m_fraction(2) { } @@ -55,7 +55,6 @@ delete ui; } - KNewEquityEntryDlg *q_ptr; Ui::KNewEquityEntryDlg *ui; QString m_strSymbolName; QString m_strName; diff --git a/kmymoney/dialogs/kpayeereassigndlg.cpp b/kmymoney/dialogs/kpayeereassigndlg.cpp --- a/kmymoney/dialogs/kpayeereassigndlg.cpp +++ b/kmymoney/dialogs/kpayeereassigndlg.cpp @@ -51,7 +51,8 @@ public: KPayeeReassignDlgPrivate() : - ui(new Ui::KPayeeReassignDlg) + ui(new Ui::KPayeeReassignDlg), + m_type(KPayeeReassignDlg::OperationType::TypeMerge) { } diff --git a/kmymoney/dialogs/kreportconfigurationfilterdlg.cpp b/kmymoney/dialogs/kreportconfigurationfilterdlg.cpp --- a/kmymoney/dialogs/kreportconfigurationfilterdlg.cpp +++ b/kmymoney/dialogs/kreportconfigurationfilterdlg.cpp @@ -475,7 +475,7 @@ } else if (d->m_tabRowColQuery) { KComboBox *combo = d->m_tabRowColQuery->ui->m_comboOrganizeBy; switch (d->m_initialState.rowType()) { - case MyMoneyReport::eNoColumns: + case MyMoneyReport::eNoRows: case MyMoneyReport::eCategory: combo->setCurrentItem(i18n("Categories"), false); break; diff --git a/kmymoney/dialogs/kselecttransactionsdlg.cpp b/kmymoney/dialogs/kselecttransactionsdlg.cpp --- a/kmymoney/dialogs/kselecttransactionsdlg.cpp +++ b/kmymoney/dialogs/kselecttransactionsdlg.cpp @@ -159,8 +159,7 @@ QList list; list = d->ui->m_register->selectedItems(); if (list.count()) { - KMyMoneyRegister::Transaction* _t = dynamic_cast(list[0]); - if (_t) + if (auto _t = dynamic_cast(list[0])) t = _t->transaction(); } return t; @@ -176,14 +175,14 @@ { Q_D(KSelectTransactionsDlg); auto rc = false; - QKeyEvent* k; + QKeyEvent* k = nullptr; if (o == d->ui->m_register) { switch (e->type()) { case QEvent::KeyPress: k = dynamic_cast(e); - if ((k->modifiers() & Qt::KeyboardModifierMask) == 0 - || (k->modifiers() & Qt::KeypadModifier) != 0) { + if ((k && k->modifiers() & Qt::KeyboardModifierMask) == 0 + || (k && k->modifiers() & Qt::KeypadModifier) != 0) { switch (k->key()) { case Qt::Key_Return: case Qt::Key_Enter: diff --git a/kmymoney/dialogs/ksplittransactiondlg.cpp b/kmymoney/dialogs/ksplittransactiondlg.cpp --- a/kmymoney/dialogs/ksplittransactiondlg.cpp +++ b/kmymoney/dialogs/ksplittransactiondlg.cpp @@ -82,7 +82,11 @@ public: explicit KSplitTransactionDlgPrivate(KSplitTransactionDlg *qq) : q_ptr(qq), - ui(new Ui::KSplitTransactionDlg) + ui(new Ui::KSplitTransactionDlg), + m_buttonBox(nullptr), + m_precision(2), + m_amountValid(false), + m_isDeposit(false) { } diff --git a/kmymoney/dialogs/settings/ksettingsgeneral.cpp b/kmymoney/dialogs/settings/ksettingsgeneral.cpp --- a/kmymoney/dialogs/settings/ksettingsgeneral.cpp +++ b/kmymoney/dialogs/settings/ksettingsgeneral.cpp @@ -44,7 +44,8 @@ public: KSettingsGeneralPrivate() : - ui(new Ui::KSettingsGeneral) + ui(new Ui::KSettingsGeneral), + initialHideZeroBalanceEquities(false) { } diff --git a/kmymoney/dialogs/settings/ksettingsonlinequotes.cpp b/kmymoney/dialogs/settings/ksettingsonlinequotes.cpp --- a/kmymoney/dialogs/settings/ksettingsonlinequotes.cpp +++ b/kmymoney/dialogs/settings/ksettingsonlinequotes.cpp @@ -49,7 +49,8 @@ public: KSettingsOnlineQuotesPrivate() : - ui(new Ui::KSettingsOnlineQuotes) + ui(new Ui::KSettingsOnlineQuotes), + m_quoteInEditing(false) { } diff --git a/kmymoney/dialogs/splitadjustdialog.cpp b/kmymoney/dialogs/splitadjustdialog.cpp --- a/kmymoney/dialogs/splitadjustdialog.cpp +++ b/kmymoney/dialogs/splitadjustdialog.cpp @@ -26,9 +26,14 @@ class SplitAdjustDialog::Private { public: Private() - : ui(new Ui_SplitAdjustDialog) + : ui(new Ui_SplitAdjustDialog), + buttonGroup(nullptr) {} + ~Private() + { + delete ui; + } Ui_SplitAdjustDialog* ui; QButtonGroup* buttonGroup; }; @@ -58,8 +63,8 @@ { // now modify the text items of the dialog to contain the correct values QString q = i18n("The total amount of this transaction is %1 while " - "the sum of the splits is %2. The remaining %3 are " - "unassigned.", transactionSum, splitSum, diff); + "the sum of the splits is %2. The remaining %3 are " + "unassigned.", transactionSum, splitSum, diff); d->ui->explanation->setText(q); q = i18n("Change &total amount of transaction to %1.", splitSum); diff --git a/kmymoney/dialogs/stdtransactioneditor.cpp b/kmymoney/dialogs/stdtransactioneditor.cpp --- a/kmymoney/dialogs/stdtransactioneditor.cpp +++ b/kmymoney/dialogs/stdtransactioneditor.cpp @@ -4,7 +4,7 @@ begin : Wed Jun 07 2006 copyright : (C) 2006 by Thomas Baumgart email : Thomas Baumgart - (C) 2017 by Łukasz Wojniłowicz + (C) 2017, 2018 by Łukasz Wojniłowicz ***************************************************************************/ /*************************************************************************** @@ -266,7 +266,7 @@ label->setAlignment(Qt::AlignVCenter); // create a copy of tabbar above the form (if we are created for a form) - KMyMoneyTransactionForm::TransactionForm* form = dynamic_cast(d->m_regForm); + auto form = dynamic_cast(d->m_regForm); if (form) { auto tabbar = new KMyMoneyTransactionForm::TabBar; d->m_editWidgets["tabbar"] = tabbar; @@ -282,7 +282,8 @@ void StdTransactionEditor::setupCategoryWidget(QString& categoryId) { Q_D(StdTransactionEditor); - TransactionEditor::setupCategoryWidget(dynamic_cast(d->m_editWidgets["category"]), d->m_splits, categoryId, SLOT(slotEditSplits())); + if (auto categoryWidget = dynamic_cast(d->m_editWidgets["category"])) + TransactionEditor::setupCategoryWidget(categoryWidget, d->m_splits, categoryId, SLOT(slotEditSplits())); if (d->m_splits.count() == 1) d->m_shares = d->m_splits[0].shares(); @@ -307,8 +308,7 @@ AccountSet aSet; // load the account widget - KMyMoneyCategory* account = dynamic_cast(haveWidget("account")); - if (account) { + if (auto account = dynamic_cast(haveWidget("account"))) { aSet.addAccountGroup(eMyMoney::Account::Type::Asset); aSet.addAccountGroup(eMyMoney::Account::Type::Liability); aSet.removeAccountType(eMyMoney::Account::Type::AssetLoan); @@ -324,16 +324,20 @@ // load the payee widget auto payee = dynamic_cast(d->m_editWidgets["payee"]); - payee->loadPayees(MyMoneyFile::instance()->payeeList()); + if (payee) + payee->loadPayees(MyMoneyFile::instance()->payeeList()); // load the category widget auto category = dynamic_cast(d->m_editWidgets["category"]); - disconnect(category, &KMyMoneyCategory::focusIn, this, &StdTransactionEditor::slotEditSplits); + + if (category) + disconnect(category, &KMyMoneyCategory::focusIn, this, &StdTransactionEditor::slotEditSplits); // load the tag widget //auto tag = dynamic_cast(m_editWidgets["tag"]); auto tag = dynamic_cast(d->m_editWidgets["tag"]); - tag->loadTags(MyMoneyFile::instance()->tagList()); + if (tag) + tag->loadTags(MyMoneyFile::instance()->tagList()); // check if the current transaction has a reference to an equity account auto haveEquityAccount = false; @@ -357,7 +361,8 @@ aSet.removeAccountType(eMyMoney::Account::Type::Investment); aSet.removeAccountType(eMyMoney::Account::Type::Stock); aSet.removeAccountType(eMyMoney::Account::Type::MoneyMarket); - aSet.load(category->selector()); + if (category) + aSet.load(category->selector()); // if an account is specified then remove it from the widget so that the user // cannot create a transfer with from and to account being the same account @@ -365,21 +370,25 @@ category->selector()->removeItem(d->m_account.id()); // also show memo text if isMultiSelection() - dynamic_cast(d->m_editWidgets["memo"])->setText(d->m_split.memo()); + if (auto memoWidget = dynamic_cast(d->m_editWidgets["memo"])) + memoWidget->setText(d->m_split.memo()); // need to know if it changed d->m_memoText = d->m_split.memo(); d->m_memoChanged = false; if (!isMultiSelection()) { - if (d->m_transaction.postDate().isValid()) - dynamic_cast(d->m_editWidgets["postdate"])->setDate(d->m_transaction.postDate()); - else if (d->m_lastPostDate.isValid()) - dynamic_cast(d->m_editWidgets["postdate"])->setDate(d->m_lastPostDate); - else - dynamic_cast(d->m_editWidgets["postdate"])->setDate(QDate::currentDate()); + if (auto dateWidget = dynamic_cast(d->m_editWidgets["postdate"])) { + if (d->m_transaction.postDate().isValid()) + dateWidget->setDate(d->m_transaction.postDate()); + else if (d->m_lastPostDate.isValid()) + dateWidget->setDate(d->m_lastPostDate); + else + dateWidget->setDate(QDate::currentDate()); + } if ((w = haveWidget("number")) != 0) { - dynamic_cast(w)->loadText(d->m_split.number()); + if (auto lineEdit = dynamic_cast(w)) + lineEdit->loadText(d->m_split.number()); if (d->m_transaction.id().isEmpty() // new transaction && dynamic_cast(w)->text().isEmpty() // no number filled in && d->m_account.accountType() == eMyMoney::Account::Type::Checkings // checkings account @@ -389,17 +398,17 @@ assignNextNumber(); } } - dynamic_cast(d->m_editWidgets["status"])->setState(d->m_split.reconcileFlag()); + if (auto statusWidget = dynamic_cast(d->m_editWidgets["status"])) + statusWidget->setState(d->m_split.reconcileFlag()); QString payeeId = d->m_split.payeeId(); - if (!payeeId.isEmpty()) { + if (payee && !payeeId.isEmpty()) payee->setSelectedItem(payeeId); - } + QList t = d->m_split.tagIdList(); - if (!t.isEmpty()) { + if (tag && !t.isEmpty()) for (auto i = 0; i < t.size(); ++i) tag->addTagWidget(t[i]); - } d->m_splits.clear(); if (d->m_transaction.splitCount() < 2) { @@ -415,33 +424,39 @@ setupCategoryWidget(categoryId); if ((w = haveWidget("cashflow")) != 0) { - KMyMoneyCashFlowCombo* cashflow = dynamic_cast(w); - cashflow->setDirection(!d->m_split.value().isPositive() ? eRegister::CashFlowDirection::Payment : eRegister::CashFlowDirection::Deposit); // include isZero case + if (auto cashflow = dynamic_cast(w)) + cashflow->setDirection(!d->m_split.value().isPositive() ? eRegister::CashFlowDirection::Payment : eRegister::CashFlowDirection::Deposit); // include isZero case } if ((w = haveWidget("category-label")) != 0) { - QLabel *categoryLabel = dynamic_cast(w); - if (isTransfer(d->m_split.accountId(), categoryId)) { - if (d->m_split.value().isPositive()) - categoryLabel->setText(i18n("Transfer from")); - else - categoryLabel->setText(i18n("Transfer to")); + if (auto categoryLabel = dynamic_cast(w)) { + if (isTransfer(d->m_split.accountId(), categoryId)) { + if (d->m_split.value().isPositive()) + categoryLabel->setText(i18n("Transfer from")); + else + categoryLabel->setText(i18n("Transfer to")); + } } } MyMoneyMoney value = d->m_split.shares(); if (haveWidget("deposit")) { - if (d->m_split.shares().isNegative()) { - dynamic_cast(d->m_editWidgets["deposit"])->loadText(""); - dynamic_cast(d->m_editWidgets["payment"])->setValue(value.abs()); - } else { - dynamic_cast(d->m_editWidgets["deposit"])->setValue(value.abs()); - dynamic_cast(d->m_editWidgets["payment"])->loadText(""); + auto depositWidget = dynamic_cast(d->m_editWidgets["deposit"]); + auto paymentWidget = dynamic_cast(d->m_editWidgets["payment"]); + if (!depositWidget || !paymentWidget) { + if (d->m_split.shares().isNegative()) { + depositWidget->loadText(QString()); + paymentWidget->setValue(value.abs()); + } else { + depositWidget->setValue(value.abs()); + paymentWidget->loadText(QString()); + } } } if ((w = haveWidget("amount")) != 0) { - dynamic_cast(w)->setValue(value.abs()); + if (auto amountWidget = dynamic_cast(w)) + amountWidget->setValue(value.abs()); } slotUpdateCategory(categoryId); @@ -456,19 +471,21 @@ } } if (action != eRegister::Action::None) { - QLabel *categoryLabel = dynamic_cast(w); - if (action == eRegister::Action::Transfer) { - if (d->m_split.value().isPositive()) - categoryLabel->setText(i18n("Transfer from")); - else - categoryLabel->setText(i18n("Transfer to")); + if (auto categoryLabel = dynamic_cast(w)) { + if (action == eRegister::Action::Transfer) { + if (d->m_split.value().isPositive()) + categoryLabel->setText(i18n("Transfer from")); + else + categoryLabel->setText(i18n("Transfer to")); + } } if ((w = haveWidget("cashflow")) != 0) { - KMyMoneyCashFlowCombo* cashflow = dynamic_cast(w); - if (action == eRegister::Action::Deposit || (action == eRegister::Action::Transfer && d->m_split.value().isPositive())) - cashflow->setDirection(eRegister::CashFlowDirection::Deposit); - else - cashflow->setDirection(eRegister::CashFlowDirection::Payment); + if (auto cashflow = dynamic_cast(w)) { + if (action == eRegister::Action::Deposit || (action == eRegister::Action::Transfer && d->m_split.value().isPositive())) + cashflow->setDirection(eRegister::CashFlowDirection::Deposit); + else + cashflow->setDirection(eRegister::CashFlowDirection::Payment); + } } if (tabbar) { tabbar->setCurrentIndex((int)action); @@ -476,28 +493,34 @@ } } } else { - auto tabbar = dynamic_cast(haveWidget("tabbar")); - if (tabbar) { - if (!isTransfer(d->m_split.accountId(), categoryId)) { + if (auto tabbar = dynamic_cast(haveWidget("tabbar"))) { + if (!isTransfer(d->m_split.accountId(), categoryId)) tabbar->setCurrentIndex(d->m_split.value().isNegative() ? (int)eRegister::Action::Withdrawal : (int)eRegister::Action::Deposit); - } else { + else tabbar->setCurrentIndex((int)eRegister::Action::Transfer); - } } } } else { // isMultiSelection() - dynamic_cast(d->m_editWidgets["postdate"])->loadDate(QDate()); - dynamic_cast(d->m_editWidgets["status"])->setState(eMyMoney::Split::State::Unknown); + if (auto postDateWidget = dynamic_cast(d->m_editWidgets["postdate"])) + postDateWidget->loadDate(QDate()); + if (auto statusWidget = dynamic_cast(d->m_editWidgets["status"])) + statusWidget->setState(eMyMoney::Split::State::Unknown); if (haveWidget("deposit")) { - dynamic_cast(d->m_editWidgets["deposit"])->loadText(""); - dynamic_cast(d->m_editWidgets["deposit"])->setAllowEmpty(); - dynamic_cast(d->m_editWidgets["payment"])->loadText(""); - dynamic_cast(d->m_editWidgets["payment"])->setAllowEmpty(); + if (auto depositWidget = dynamic_cast(d->m_editWidgets["deposit"])) { + depositWidget->loadText(QString()); + depositWidget->setAllowEmpty(); + } + if (auto paymentWidget = dynamic_cast(d->m_editWidgets["payment"])) { + paymentWidget->loadText(QString()); + paymentWidget->setAllowEmpty(); + } } if ((w = haveWidget("amount")) != 0) { - dynamic_cast(w)->loadText(""); - dynamic_cast(w)->setAllowEmpty(); + if (auto amountWidget = dynamic_cast(w)) { + amountWidget->loadText(QString()); + amountWidget->setAllowEmpty(); + } } slotUpdateAction((int)action); @@ -532,46 +555,49 @@ { Q_D(StdTransactionEditor); // reload category widget - KMyMoneyCategory* category = dynamic_cast(d->m_editWidgets["category"]); - QString categoryId = category->selectedItem(); - - AccountSet aSet; - aSet.addAccountGroup(eMyMoney::Account::Type::Asset); - aSet.addAccountGroup(eMyMoney::Account::Type::Liability); - aSet.addAccountGroup(eMyMoney::Account::Type::Income); - aSet.addAccountGroup(eMyMoney::Account::Type::Expense); - if (KMyMoneySettings::expertMode()) - aSet.addAccountGroup(eMyMoney::Account::Type::Equity); - aSet.load(category->selector()); - - // if an account is specified then remove it from the widget so that the user - // cannot create a transfer with from and to account being the same account - if (!d->m_account.id().isEmpty()) - category->selector()->removeItem(d->m_account.id()); + if (auto category = dynamic_cast(d->m_editWidgets["category"])) { + QString categoryId = category->selectedItem(); - if (!categoryId.isEmpty()) - category->setSelectedItem(categoryId); + AccountSet aSet; + aSet.addAccountGroup(eMyMoney::Account::Type::Asset); + aSet.addAccountGroup(eMyMoney::Account::Type::Liability); + aSet.addAccountGroup(eMyMoney::Account::Type::Income); + aSet.addAccountGroup(eMyMoney::Account::Type::Expense); + if (KMyMoneySettings::expertMode()) + aSet.addAccountGroup(eMyMoney::Account::Type::Equity); + aSet.load(category->selector()); + + // if an account is specified then remove it from the widget so that the user + // cannot create a transfer with from and to account being the same account + if (!d->m_account.id().isEmpty()) + category->selector()->removeItem(d->m_account.id()); + + if (!categoryId.isEmpty()) + category->setSelectedItem(categoryId); + } // reload payee widget - KMyMoneyPayeeCombo* payee = dynamic_cast(d->m_editWidgets["payee"]); - QString payeeId = payee->selectedItem(); + if (auto payee = dynamic_cast(d->m_editWidgets["payee"])) { + QString payeeId = payee->selectedItem(); - payee->loadPayees(MyMoneyFile::instance()->payeeList()); + payee->loadPayees(MyMoneyFile::instance()->payeeList()); - if (!payeeId.isEmpty()) { - payee->setSelectedItem(payeeId); + if (!payeeId.isEmpty()) { + payee->setSelectedItem(payeeId); + } } // reload tag widget - KTagContainer* tag = dynamic_cast(d->m_editWidgets["tag"]); - QString tagId = tag->tagCombo()->selectedItem(); + if (auto tag = dynamic_cast(d->m_editWidgets["tag"])) { + QString tagId = tag->tagCombo()->selectedItem(); - tag->loadTags(MyMoneyFile::instance()->tagList()); + tag->loadTags(MyMoneyFile::instance()->tagList()); - if (!tagId.isEmpty()) { - tag->RemoveAllTagWidgets(); - tag->addTagWidget(tagId); + if (!tagId.isEmpty()) { + tag->RemoveAllTagWidgets(); + tag->addTagWidget(tagId); + } } } @@ -586,14 +612,15 @@ && d->m_splits.count() == 0 && KMyMoneySettings::autoFillTransaction() != 0) { // check if category is empty - KMyMoneyCategory* category = dynamic_cast(d->m_editWidgets["category"]); - QStringList list; - category->selectedItems(list); - if (!list.isEmpty()) - return; + if (auto category = dynamic_cast(d->m_editWidgets["category"])) { + QStringList list; + category->selectedItems(list); + if (!list.isEmpty()) + return; + } // check if memo is empty - KTextEdit* memo = dynamic_cast(d->m_editWidgets["memo"]); + auto memo = dynamic_cast(d->m_editWidgets["memo"]); if (memo && !memo->toPlainText().isEmpty()) return; @@ -619,8 +646,8 @@ // (ipwizard, 2008-04-07) // check if date has been altered by user - KMyMoneyDateInput* postDate = dynamic_cast(m_editWidgets["postdate"]); - if ((m_lastPostDate.isValid() && (postDate->date() != m_lastPostDate)) + auto postDate = dynamic_cast(m_editWidgets["postdate"]); + if (postDate && (m_lastPostDate.isValid() && (postDate->date() != m_lastPostDate)) || (!m_lastPostDate.isValid() && (postDate->date() != QDate::currentDate()))) return; #endif @@ -632,8 +659,8 @@ // If payee has associated default account (category), set that now. const MyMoneyPayee& payeeObj = MyMoneyFile::instance()->payee(payeeId); if (payeeObj.defaultAccountEnabled()) { - KMyMoneyCategory* category = dynamic_cast(d->m_editWidgets["category"]); - category->slotItemSelected(payeeObj.defaultAccountId()); + if (auto category = dynamic_cast(d->m_editWidgets["category"])) + category->slotItemSelected(payeeObj.defaultAccountId()); } } @@ -781,7 +808,7 @@ // to the transaction. // - KMyMoneyLineEdit* editNr = dynamic_cast(haveWidget("number")); + auto editNr = dynamic_cast(haveWidget("number")); if (editNr && !editNr->text().isEmpty()) { s.setNumber(editNr->text()); } else if (!s.number().isEmpty()) { @@ -816,9 +843,11 @@ } // now setup the widgets with the new data but keep the date - QDate date = dynamic_cast(d->m_editWidgets["postdate"])->date(); - loadEditWidgets(action); - dynamic_cast(d->m_editWidgets["postdate"])->setDate(date); + if (auto postdateWidget = dynamic_cast(d->m_editWidgets["postdate"])) { + auto date = postdateWidget->date(); + loadEditWidgets(action); + postdateWidget->setDate(date); + } } } @@ -834,8 +863,10 @@ Q_D(StdTransactionEditor); auto tabbar = dynamic_cast(haveWidget("tabbar")); if (tabbar) { - QLabel* categoryLabel = dynamic_cast(haveWidget("category-label")); - KMyMoneyCashFlowCombo* cashflow = dynamic_cast(d->m_editWidgets["cashflow"]); + auto categoryLabel = dynamic_cast(haveWidget("category-label")); + auto cashflow = dynamic_cast(d->m_editWidgets["cashflow"]); + if (!categoryLabel || !cashflow) + return; switch (action) { case (int)eRegister::Action::Deposit: categoryLabel->setText(i18n("Category")); @@ -863,9 +894,9 @@ void StdTransactionEditor::slotUpdateCashFlow(eRegister::CashFlowDirection dir) { - QLabel* categoryLabel = dynamic_cast(haveWidget("category-label")); - KMyMoneyCashFlowCombo* cashflow = dynamic_cast(haveWidget("cashflow")); - cashflow->setDirection(dir); + auto categoryLabel = dynamic_cast(haveWidget("category-label")); + if (auto cashflow = dynamic_cast(haveWidget("cashflow"))) + cashflow->setDirection(dir); // qDebug("Update cashflow to %d", dir); if (categoryLabel) { auto tabbar = dynamic_cast(haveWidget("tabbar")); @@ -890,13 +921,13 @@ void StdTransactionEditor::slotUpdateCategory(const QString& id) { Q_D(StdTransactionEditor); - QLabel *categoryLabel = dynamic_cast(haveWidget("category-label")); + auto categoryLabel = dynamic_cast(haveWidget("category-label")); // qDebug("Update category to %s", qPrintable(id)); if (categoryLabel) { auto tabbar = dynamic_cast(haveWidget("tabbar")); - KMyMoneyEdit* amount = dynamic_cast(d->m_editWidgets["amount"]); - MyMoneyMoney val = amount->value(); + auto amount = dynamic_cast(d->m_editWidgets["amount"]); + auto val = amount ? amount->value() : MyMoneyMoney(); if (categoryLabel->text() == i18n("Transfer from")) { val = -val; @@ -920,7 +951,7 @@ tabbar->setTabEnabled((int)eRegister::Action::Deposit, false); tabbar->setTabEnabled((int)eRegister::Action::Withdrawal, false); } - KMyMoneyCashFlowCombo* cashflow = dynamic_cast(d->m_editWidgets["cashflow"]); + auto cashflow = dynamic_cast(d->m_editWidgets["cashflow"]); if (val.isZero()) { if (cashflow && (cashflow->direction() == eRegister::CashFlowDirection::Deposit)) { categoryLabel->setText(i18n("Transfer from")); @@ -938,8 +969,8 @@ } updateAmount(val); } else { //id.isEmpty() - KMyMoneyCategory* category = dynamic_cast(d->m_editWidgets["category"]); - disableTransferTab = !category->currentText().isEmpty(); + if (auto category = dynamic_cast(d->m_editWidgets["category"])) + disableTransferTab = !category->currentText().isEmpty(); categoryLabel->setText(i18n("Category")); } if (tabbar) { @@ -963,11 +994,16 @@ Q_D(StdTransactionEditor); MyMoneyMoney val(txt); + auto depositWidget = dynamic_cast(d->m_editWidgets["deposit"]); + auto paymentWidget = dynamic_cast(d->m_editWidgets["payment"]); + if (!depositWidget || !paymentWidget) + return; + if (val.isNegative()) { - dynamic_cast(d->m_editWidgets["deposit"])->setValue(val.abs()); - dynamic_cast(d->m_editWidgets["payment"])->clearText(); + depositWidget->setValue(val.abs()); + paymentWidget->clearText(); } else { - dynamic_cast(d->m_editWidgets["deposit"])->clearText(); + depositWidget->clearText(); } updateVAT(); } @@ -976,11 +1012,17 @@ { Q_D(StdTransactionEditor); MyMoneyMoney val(txt); + + auto depositWidget = dynamic_cast(d->m_editWidgets["deposit"]); + auto paymentWidget = dynamic_cast(d->m_editWidgets["payment"]); + if (!depositWidget || !paymentWidget) + return; + if (val.isNegative()) { - dynamic_cast(d->m_editWidgets["payment"])->setValue(val.abs()); - dynamic_cast(d->m_editWidgets["deposit"])->clearText(); + paymentWidget->setValue(val.abs()); + depositWidget->clearText(); } else { - dynamic_cast(d->m_editWidgets["payment"])->clearText(); + paymentWidget->clearText(); } updateVAT(); } @@ -1000,29 +1042,31 @@ return; Q_D(StdTransactionEditor); - QLabel *categoryLabel = dynamic_cast(haveWidget("category-label")); + auto categoryLabel = dynamic_cast(haveWidget("category-label")); if (categoryLabel) { - KMyMoneyCashFlowCombo* cashflow = dynamic_cast(d->m_editWidgets["cashflow"]); - - if (!val.isPositive()) { // fixes BUG321317 - if (categoryLabel->text() != i18n("Category")) { - if (cashflow->direction() == eRegister::CashFlowDirection::Payment) { - categoryLabel->setText(i18n("Transfer to")); + if (auto cashflow = dynamic_cast(d->m_editWidgets["cashflow"])) { + if (!val.isPositive()) { // fixes BUG321317 + if (categoryLabel->text() != i18n("Category")) { + if (cashflow->direction() == eRegister::CashFlowDirection::Payment) { + categoryLabel->setText(i18n("Transfer to")); + } + } else { + slotUpdateCashFlow(cashflow->direction()); } + if (auto amountWidget = dynamic_cast(d->m_editWidgets["amount"])) + amountWidget->setValue(val.abs()); } else { - slotUpdateCashFlow(cashflow->direction()); - } - dynamic_cast(d->m_editWidgets["amount"])->setValue(val.abs()); - } else { - if (categoryLabel->text() != i18n("Category")) { - if (cashflow->direction() == eRegister::CashFlowDirection::Payment) { - categoryLabel->setText(i18n("Transfer to")); - } else { - categoryLabel->setText(i18n("Transfer from")); - cashflow->setDirection(eRegister::CashFlowDirection::Deposit); // editing with +ve shows 'from' not 'pay to' + if (categoryLabel->text() != i18n("Category")) { + if (cashflow->direction() == eRegister::CashFlowDirection::Payment) { + categoryLabel->setText(i18n("Transfer to")); + } else { + categoryLabel->setText(i18n("Transfer from")); + cashflow->setDirection(eRegister::CashFlowDirection::Deposit); // editing with +ve shows 'from' not 'pay to' + } } + if (auto amountWidget = dynamic_cast(d->m_editWidgets["amount"])) + amountWidget->setValue(val.abs()); } - dynamic_cast(d->m_editWidgets["amount"])->setValue(val.abs()); } } } @@ -1060,9 +1104,8 @@ if (d->m_splits.count() == 2) // not removed? return; - } else { + } else if (auto category = dynamic_cast(d->m_editWidgets["category"])) { // otherwise, we need a category - KMyMoneyCategory* category = dynamic_cast(d->m_editWidgets["category"]); if (category->selectedItem().isEmpty()) return; @@ -1165,7 +1208,7 @@ reason.clear(); QMap::const_iterator it_w; - KMyMoneyDateInput* postDate = dynamic_cast(d->m_editWidgets["postdate"]); + auto postDate = dynamic_cast(d->m_editWidgets["postdate"]); if (postDate) { QDate accountOpeningDate = d->m_account.openingDate(); for (QList::const_iterator it_s = d->m_splits.constBegin(); it_s != d->m_splits.constEnd(); ++it_s) { @@ -1175,7 +1218,7 @@ accountOpeningDate = acc.openingDate(); } // check the selected category in case m_splits hasn't been updated yet - KMyMoneyCategory* category = dynamic_cast(d->m_editWidgets["category"]); + auto category = dynamic_cast(d->m_editWidgets["category"]); if (category && !category->selectedItem().isEmpty()) { MyMoneyAccount cat = MyMoneyFile::instance()->account(category->selectedItem()); if (cat.openingDate() > accountOpeningDate) @@ -1193,13 +1236,13 @@ } for (it_w = d->m_editWidgets.begin(); it_w != d->m_editWidgets.end(); ++it_w) { - KMyMoneyPayeeCombo* payee = dynamic_cast(*it_w); - KTagContainer* tagContainer = dynamic_cast(*it_w); - KMyMoneyCategory* category = dynamic_cast(*it_w); - KMyMoneyEdit* amount = dynamic_cast(*it_w); - KMyMoneyReconcileCombo* reconcile = dynamic_cast(*it_w); - KMyMoneyCashFlowCombo* cashflow = dynamic_cast(*it_w); - KTextEdit* memo = dynamic_cast(*it_w); + auto payee = dynamic_cast(*it_w); + auto tagContainer = dynamic_cast(*it_w); + auto category = dynamic_cast(*it_w); + auto amount = dynamic_cast(*it_w); + auto reconcile = dynamic_cast(*it_w); + auto cashflow = dynamic_cast(*it_w); + auto memo = dynamic_cast(*it_w); if (payee && !(payee->currentText().isEmpty())) break; @@ -1212,17 +1255,16 @@ // the following widgets are only checked if we are editing multiple transactions if (isMultiSelection()) { - auto tabbar = dynamic_cast(haveWidget("tabbar")); - if (tabbar) { + if (auto tabbar = dynamic_cast(haveWidget("tabbar"))) tabbar->setEnabled(true); - } + if (reconcile && reconcile->state() != eMyMoney::Split::State::Unknown) break; if (cashflow && cashflow->direction() != eRegister::CashFlowDirection::Unknown) break; - if (postDate->date().isValid() && (postDate->date() >= d->m_account.openingDate())) + if (postDate && postDate->date().isValid() && (postDate->date() >= d->m_account.openingDate())) break; if (memo && d->m_memoChanged) @@ -1241,7 +1283,7 @@ MyMoneyAccount acc, parent; acc.setName(name); - KMyMoneyCashFlowCombo* cashflow = dynamic_cast(haveWidget("cashflow")); + auto cashflow = dynamic_cast(haveWidget("cashflow")); if (cashflow) { // form based input if (cashflow->direction() == eRegister::CashFlowDirection::Deposit) @@ -1251,11 +1293,12 @@ } else if (haveWidget("deposit")) { // register based input - KMyMoneyEdit* deposit = dynamic_cast(d->m_editWidgets["deposit"]); - if (deposit->value().isPositive()) - parent = MyMoneyFile::instance()->income(); - else - parent = MyMoneyFile::instance()->expense(); + if (auto deposit = dynamic_cast(d->m_editWidgets["deposit"])) { + if (deposit->value().isPositive()) + parent = MyMoneyFile::instance()->income(); + else + parent = MyMoneyFile::instance()->expense(); + } } else parent = MyMoneyFile::instance()->expense(); @@ -1284,17 +1327,16 @@ if (w) w->setFocus(); - KMyMoneyEdit* amount = dynamic_cast(haveWidget("amount")); - KMyMoneyEdit* deposit = dynamic_cast(haveWidget("deposit")); - KMyMoneyEdit* payment = dynamic_cast(haveWidget("payment")); + auto amount = dynamic_cast(haveWidget("amount")); + auto deposit = dynamic_cast(haveWidget("deposit")); + auto payment = dynamic_cast(haveWidget("payment")); KMyMoneyCashFlowCombo* cashflow = 0; eRegister::CashFlowDirection dir = eRegister::CashFlowDirection::Unknown; bool isValidAmount = false; if (amount) { isValidAmount = amount->lineedit()->text().length() != 0; - cashflow = dynamic_cast(haveWidget("cashflow")); - if (cashflow) + if ((cashflow = dynamic_cast(haveWidget("cashflow")))) dir = cashflow->direction(); } else { @@ -1379,27 +1421,30 @@ auto cashflow = dynamic_cast(haveWidget("cashflow")); if (cashflow) { // form based input - auto amount = dynamic_cast(d->m_editWidgets["amount"]); - // if both fields do not contain changes -> no need to update - if (cashflow->direction() != eRegister::CashFlowDirection::Unknown - && !amount->lineedit()->text().isEmpty()) - updateValue = true; - value = amount->value(); - if (cashflow->direction() == eRegister::CashFlowDirection::Payment) - value = -value; + if (auto amount = dynamic_cast(d->m_editWidgets["amount"])) { + // if both fields do not contain changes -> no need to update + if (cashflow->direction() != eRegister::CashFlowDirection::Unknown + && !amount->lineedit()->text().isEmpty()) + updateValue = true; + value = amount->value(); + if (cashflow->direction() == eRegister::CashFlowDirection::Payment) + value = -value; + } } else if (haveWidget("deposit")) { // register based input auto deposit = dynamic_cast(d->m_editWidgets["deposit"]); auto payment = dynamic_cast(d->m_editWidgets["payment"]); - // if both fields do not contain text -> no need to update - if (!(deposit->lineedit()->text().isEmpty() && payment->lineedit()->text().isEmpty())) - updateValue = true; + if (deposit || payment) { + // if both fields do not contain text -> no need to update + if (!(deposit->lineedit()->text().isEmpty() && payment->lineedit()->text().isEmpty())) + updateValue = true; - if (deposit->value().isPositive()) - value = deposit->value(); - else - value = -(payment->value()); + if (deposit->value().isPositive()) + value = deposit->value(); + else + value = -(payment->value()); + } } if (update) @@ -1433,8 +1478,8 @@ t.removeSplits(); t.setCommodity(d->m_account.currencyId()); - KMyMoneyDateInput* postDate = dynamic_cast(d->m_editWidgets["postdate"]); - if (postDate->date().isValid()) { + auto postDate = dynamic_cast(d->m_editWidgets["postdate"]); + if (postDate && postDate->date().isValid()) { t.setPostDate(postDate->date()); } @@ -1450,28 +1495,27 @@ // FIXME a better approach would be to have a 'dirty' flag with the widgets // which identifies if the originally loaded value has been modified // by the user - KTextEdit* memo = dynamic_cast(d->m_editWidgets["memo"]); + auto memo = dynamic_cast(d->m_editWidgets["memo"]); if (memo) { if (!isMultiSelection() || (isMultiSelection() && d->m_memoChanged)) s0.setMemo(memo->toPlainText()); } - KMyMoneyLineEdit* number = dynamic_cast(haveWidget("number")); - if (number) { + if (auto number = dynamic_cast(haveWidget("number"))) { if (!isMultiSelection() || (isMultiSelection() && !number->text().isEmpty())) s0.setNumber(number->text()); } - KMyMoneyPayeeCombo* payee = dynamic_cast(d->m_editWidgets["payee"]); + auto payee = dynamic_cast(d->m_editWidgets["payee"]); QString payeeId; - if (!isMultiSelection() || (isMultiSelection() && !payee->currentText().isEmpty())) { + if (!isMultiSelection() || (isMultiSelection() && payee && !payee->currentText().isEmpty())) { payeeId = payee->selectedItem(); s0.setPayeeId(payeeId); } //KMyMoneyTagCombo* tag = dynamic_cast(m_editWidgets["tag"]); - KTagContainer* tag = dynamic_cast(d->m_editWidgets["tag"]); - if (!isMultiSelection() || (isMultiSelection() && !tag->selectedTags().isEmpty())) { + auto tag = dynamic_cast(d->m_editWidgets["tag"]); + if (!isMultiSelection() || (isMultiSelection() && tag && !tag->selectedTags().isEmpty())) { s0.setTagIdList(tag->selectedTags()); } @@ -1487,8 +1531,8 @@ } // if we mark the split reconciled here, we'll use today's date if no reconciliation date is given - KMyMoneyReconcileCombo* status = dynamic_cast(d->m_editWidgets["status"]); - if (status->state() != eMyMoney::Split::State::Unknown) + auto status = dynamic_cast(d->m_editWidgets["status"]); + if (status && status->state() != eMyMoney::Split::State::Unknown) s0.setReconcileFlag(status->state()); if (s0.reconcileFlag() == eMyMoney::Split::State::Reconciled && !s0.reconcileDate().isValid()) @@ -1535,8 +1579,8 @@ } if (isMultiSelection() || splits.count() == 1) { - KMyMoneyCategory* category = dynamic_cast(d->m_editWidgets["category"]); - if (!isMultiSelection() || (isMultiSelection() && !category->currentText().isEmpty())) { + auto category = dynamic_cast(d->m_editWidgets["category"]); + if (!isMultiSelection() || (isMultiSelection() && category && !category->currentText().isEmpty())) { s1.setAccountId(category->selectedItem()); } @@ -1611,7 +1655,7 @@ { Q_D(StdTransactionEditor); TransactionEditor::slotUpdateAccount(id); - KMyMoneyCategory* category = dynamic_cast(d->m_editWidgets["category"]); + auto category = dynamic_cast(d->m_editWidgets["category"]); if (category && category->splitButton()) { category->splitButton()->setDisabled(id.isEmpty()); } diff --git a/kmymoney/dialogs/transactioneditor.cpp b/kmymoney/dialogs/transactioneditor.cpp --- a/kmymoney/dialogs/transactioneditor.cpp +++ b/kmymoney/dialogs/transactioneditor.cpp @@ -114,7 +114,7 @@ // After all, the editor is about to die //disconnect first tagCombo: - KTagContainer *w = dynamic_cast(haveWidget("tag")); + auto w = dynamic_cast(haveWidget("tag")); if (w && w->tagCombo()) { w->tagCombo()->disconnect(this); } @@ -153,7 +153,8 @@ for (it_w = widgets.constBegin(); it_w != widgets.constEnd(); ++it_w) { QWidget * w; if ((w = haveWidget(*it_w)) != 0) { - dynamic_cast(w)->setPrecision(prec); + if (auto precisionWidget = dynamic_cast(w)) + precisionWidget->setPrecision(prec); } } } @@ -268,12 +269,13 @@ // if the object is a widget, the event is a key press event and // the object is one of our edit widgets, then .... + auto numberWiget = dynamic_cast(o); if (o->isWidgetType() && (e->type() == QEvent::KeyPress) - && d->m_editWidgets.values().contains(dynamic_cast(o))) { - QKeyEvent* k = dynamic_cast(e); - if ((k->modifiers() & Qt::KeyboardModifierMask) == 0 - || (k->modifiers() & Qt::KeypadModifier) != 0) { + && numberWiget && d->m_editWidgets.values().contains(numberWiget)) { + auto k = dynamic_cast(e); + if ((k && k->modifiers() & Qt::KeyboardModifierMask) == 0 + || (k && k->modifiers() & Qt::KeypadModifier) != 0) { bool isFinal = false; QList::const_iterator it_w; switch (k->key()) { @@ -288,8 +290,8 @@ if (KMyMoneySettings::enterMovesBetweenFields()) { for (it_w = d->m_finalEditWidgets.constBegin(); !isFinal && it_w != d->m_finalEditWidgets.constEnd(); ++it_w) { if (*it_w == o) { - if (dynamic_cast(*it_w)) { - isFinal = !(dynamic_cast(*it_w)->value().isZero()); + if (auto widget = dynamic_cast(*it_w)) { + isFinal = !(widget->value().isZero()); } else isFinal = true; } @@ -306,7 +308,8 @@ QApplication::sendEvent(o, &evt); // in case of a category item and the split button is visible // send a second event so that we get passed the button. - if (dynamic_cast(o) && dynamic_cast(o)->splitButton()) + auto widget = dynamic_cast(o); + if (widget && widget->splitButton()) QApplication::sendEvent(o, &evt); } else { @@ -329,7 +332,6 @@ { Q_D(TransactionEditor); auto next = txt; - KMyMoneyLineEdit* number = dynamic_cast(haveWidget("number")); QString schedInfo; if (!d->m_scheduleInfo.isEmpty()) { schedInfo = i18n("
Processing schedule for %1.
", d->m_scheduleInfo); @@ -340,7 +342,7 @@ "
Do you want to replace it with the next available number?
", next, d->m_account.name()) + QString(""), i18n("Duplicate number")) == KMessageBox::Yes) { assignNextNumber(); next = KMyMoneyUtils::nextCheckNumber(d->m_account); - } else { + } else if (auto number = dynamic_cast(haveWidget("number"))) { number->setText(QString()); break; } @@ -526,7 +528,7 @@ { Q_D(TransactionEditor); if (canAssignNumber()) { - KMyMoneyLineEdit* number = dynamic_cast(haveWidget("number")); + auto number = dynamic_cast(haveWidget("number")); QString num = KMyMoneyUtils::nextCheckNumber(d->m_account); bool showMessage = true; int rc = KMessageBox::No; @@ -544,20 +546,23 @@ num = KMyMoneyUtils::nextCheckNumber(d->m_account); KMyMoneyUtils::updateLastNumberUsed(d->m_account, num); d->m_account.setValue("lastNumberUsed", num); - number->loadText(num); + if (number) + number->loadText(num); } else { num = QString(); break; } } - number->setText(num); + if (number) + number->setText(num); } } bool TransactionEditor::canAssignNumber() const { - auto number = dynamic_cast(haveWidget("number")); - return (number != 0); + if (dynamic_cast(haveWidget("number"))) + return true; + return false; } void TransactionEditor::setupCategoryWidget(KMyMoneyCategory* category, const QList& splits, QString& categoryId, const char* splitEditSlot, bool /* allowObjectCreation */) @@ -822,10 +827,9 @@ { Q_D(TransactionEditor); // force resizeing of the columns in the form - auto form = dynamic_cast(d->m_regForm); - if (form) { + + if (auto form = dynamic_cast(d->m_regForm)) QMetaObject::invokeMethod(form, "resize", Qt::QueuedConnection, QGenericReturnArgument(), Q_ARG(int, (int)eWidgets::eTransactionForm::Column::Value1)); - } } void TransactionEditor::slotNewPayee(const QString& newnameBase, QString& id) diff --git a/kmymoney/dialogs/transactioneditor_p.h b/kmymoney/dialogs/transactioneditor_p.h --- a/kmymoney/dialogs/transactioneditor_p.h +++ b/kmymoney/dialogs/transactioneditor_p.h @@ -59,7 +59,13 @@ public: explicit TransactionEditorPrivate(TransactionEditor *qq) : - q_ptr(qq) + q_ptr(qq), + m_paymentMethod(eMyMoney::Schedule::PaymentType::Any), + m_regForm(nullptr), + m_item(nullptr), + m_initialAction(eWidgets::eRegister::Action::None), + m_openEditSplits(false), + m_memoChanged(false) { } diff --git a/kmymoney/kmymoney.cpp b/kmymoney/kmymoney.cpp --- a/kmymoney/kmymoney.cpp +++ b/kmymoney/kmymoney.cpp @@ -220,23 +220,28 @@ m_moveToAccountSelector(0), m_statementXMLindex(0), m_balanceWarning(0), + m_backupState(backupStateE::BACKUP_IDLE), m_backupResult(0), m_backupMount(0), m_ignoreBackupExitCode(false), m_fileOpen(false), m_fmode(QFileDevice::ReadUser | QFileDevice::WriteUser), - m_myMoneyView(0), - m_progressBar(0), - m_searchDlg(0), - m_autoSaveTimer(0), - m_progressTimer(0), + m_myMoneyView(nullptr), + m_startDialog(false), + m_progressBar(nullptr), + m_statusLabel(nullptr), + m_searchDlg(nullptr), + m_autoSaveEnabled(true), + m_autoSaveTimer(nullptr), + m_progressTimer(nullptr), + m_autoSavePeriod(0), m_inAutoSaving(false), - m_transactionEditor(0), - m_endingBalanceDlg(0), - m_saveEncrypted(0), - m_additionalKeyLabel(0), - m_additionalKeyButton(0), - m_recentFiles(0), + m_transactionEditor(nullptr), + m_endingBalanceDlg(nullptr), + m_saveEncrypted(nullptr), + m_additionalKeyLabel(nullptr), + m_additionalKeyButton(nullptr), + m_recentFiles(nullptr), #ifdef KF5Holidays_FOUND m_holidayRegion(0), #endif @@ -2766,13 +2771,13 @@ void KMyMoneyApp::slotFileClose() { - bool okToSelect = true; +// bool okToSelect = true; // check if transaction editor is open and ask user what he wants to do // slotTransactionsCancelOrEnter(okToSelect); - if (!okToSelect) - return; +// if (!okToSelect) +// return; // no update status here, as we might delete the status too early. if (d->dirty()) { @@ -3677,8 +3682,7 @@ void KMyMoneyApp::showContextMenu(const QString& containerName) { QWidget* w = factory()->container(containerName, this); - QMenu *menu = dynamic_cast(w); - if (menu) + if (auto menu = dynamic_cast(w)) menu->exec(QCursor::pos()); else qDebug("menu '%s' not found: w = %p, menu = %p", qPrintable(containerName), w, menu); diff --git a/kmymoney/main.cpp b/kmymoney/main.cpp --- a/kmymoney/main.cpp +++ b/kmymoney/main.cpp @@ -161,7 +161,8 @@ // create the singletons before we start memory checking // to avoid false error reports - MyMoneyFile::instance(); + auto file = MyMoneyFile::instance(); + Q_UNUSED(file) KMyMoneyUtils::checkConstants(); diff --git a/kmymoney/models/accountsproxymodel.cpp b/kmymoney/models/accountsproxymodel.cpp --- a/kmymoney/models/accountsproxymodel.cpp +++ b/kmymoney/models/accountsproxymodel.cpp @@ -63,7 +63,9 @@ }; AccountsProxyModel::AccountsProxyModel(QObject *parent) - : KRecursiveFilterProxyModel(parent), d(new Private) + : KRecursiveFilterProxyModel(parent), + m_mdlColumns(nullptr), + d(new Private) { setDynamicSortFilter(true); setSortLocaleAware(true); diff --git a/kmymoney/models/onlinejobmessagesmodel.cpp b/kmymoney/models/onlinejobmessagesmodel.cpp --- a/kmymoney/models/onlinejobmessagesmodel.cpp +++ b/kmymoney/models/onlinejobmessagesmodel.cpp @@ -50,6 +50,7 @@ case eMyMoney::OnlineJob::MessageType::Information: return Icons::get(Icon::DialogInformation); case eMyMoney::OnlineJob::MessageType::Warning: return Icons::get(Icon::DialogWarning); case eMyMoney::OnlineJob::MessageType::Error: return Icons::get(Icon::DialogError); + break; } case Qt::ToolTipRole: switch (messages[index.row()].type()) { case eMyMoney::OnlineJob::MessageType::Debug: return i18n("Information to find issues."); @@ -57,6 +58,7 @@ case eMyMoney::OnlineJob::MessageType::Information: return i18n("Informative message without certain significance."); case eMyMoney::OnlineJob::MessageType::Warning: return i18n("Warning message."); case eMyMoney::OnlineJob::MessageType::Error: return i18n("Error"); + break; } default: return QVariant(); } diff --git a/kmymoney/models/securitiesmodel.cpp b/kmymoney/models/securitiesmodel.cpp --- a/kmymoney/models/securitiesmodel.cpp +++ b/kmymoney/models/securitiesmodel.cpp @@ -35,7 +35,10 @@ class SecuritiesModel::Private { public: - Private() : m_file(MyMoneyFile::instance()) + Private() : + m_file(MyMoneyFile::instance()), + m_ndCurrencies(nullptr), + m_ndSecurities(nullptr) { QVector columns { Column::Security, Column::Symbol, Column::Type, diff --git a/kmymoney/mymoney/mymoneyexception.cpp b/kmymoney/mymoney/mymoneyexception.cpp --- a/kmymoney/mymoney/mymoneyexception.cpp +++ b/kmymoney/mymoney/mymoneyexception.cpp @@ -37,7 +37,8 @@ class MyMoneyExceptionPrivate { public: - MyMoneyExceptionPrivate() + MyMoneyExceptionPrivate() : + m_line(0) { } diff --git a/kmymoney/mymoney/mymoneyfinancialcalculator_p.h b/kmymoney/mymoney/mymoneyfinancialcalculator_p.h --- a/kmymoney/mymoney/mymoneyfinancialcalculator_p.h +++ b/kmymoney/mymoney/mymoneyfinancialcalculator_p.h @@ -47,7 +47,18 @@ public: - MyMoneyFinancialCalculatorPrivate() + MyMoneyFinancialCalculatorPrivate() : + m_ir(0.0), + m_pv(0.0), + m_pmt(0.0), + m_fv(0.0), + m_npp(0.0), + m_CF(0), + m_PF(0), + m_prec(2), + m_bep(false), + m_disc(false), + m_mask(0) { } diff --git a/kmymoney/mymoney/mymoneyobject.h b/kmymoney/mymoney/mymoneyobject.h --- a/kmymoney/mymoney/mymoneyobject.h +++ b/kmymoney/mymoney/mymoneyobject.h @@ -51,7 +51,7 @@ /** * This is the constructor for the MyMoneyObject object */ - MyMoneyObject(); +// MyMoneyObject(); /** * This is the destructor for the MyMoneyObject object diff --git a/kmymoney/mymoney/mymoneyobject.cpp b/kmymoney/mymoney/mymoneyobject.cpp --- a/kmymoney/mymoney/mymoneyobject.cpp +++ b/kmymoney/mymoney/mymoneyobject.cpp @@ -3,7 +3,7 @@ ------------------- copyright : (C) 2005 by Thomas Baumagrt email : ipwizard@users.sourceforge.net - (C) 2017 by Łukasz Wojniłowicz + (C) 2017, 2018 by Łukasz Wojniłowicz ***************************************************************************/ /*************************************************************************** @@ -26,17 +26,17 @@ #include "mymoneyexception.h" -MyMoneyObject::MyMoneyObject(const QString& id) : - d_ptr(new MyMoneyObjectPrivate) -{ - Q_D(MyMoneyObject); - d->m_id = id; -} +//MyMoneyObject::MyMoneyObject(const QString& id) : +// d_ptr(new MyMoneyObjectPrivate) +//{ +// Q_D(MyMoneyObject); +// d->m_id = id; +//} -MyMoneyObject::MyMoneyObject() : - d_ptr(new MyMoneyObjectPrivate) -{ -} +//MyMoneyObject::MyMoneyObject() : +// d_ptr(new MyMoneyObjectPrivate) +//{ +//} MyMoneyObject::MyMoneyObject(MyMoneyObjectPrivate &dd) : d_ptr(&dd) diff --git a/kmymoney/mymoney/onlinejobadministration.cpp b/kmymoney/mymoney/onlinejobadministration.cpp --- a/kmymoney/mymoney/onlinejobadministration.cpp +++ b/kmymoney/mymoney/onlinejobadministration.cpp @@ -51,7 +51,8 @@ #include "tasks/onlinetask.h" onlineJobAdministration::onlineJobAdministration(QObject *parent) : - QObject(parent) + QObject(parent), + m_onlinePlugins(nullptr) { } diff --git a/kmymoney/mymoney/storage/mymoneymap.h b/kmymoney/mymoney/storage/mymoneymap.h --- a/kmymoney/mymoney/storage/mymoneymap.h +++ b/kmymoney/mymoney/storage/mymoneymap.h @@ -194,7 +194,7 @@ inline void map(QMap& that) const { //QMap* ptr = dynamic_cast* >(this); //that = *ptr; - that = *(dynamic_cast* >(const_cast* >(this))); + that = *(static_cast* >(const_cast* >(this))); } inline int count(void) const { diff --git a/kmymoney/mymoney/tests/mymoneyfile-test.h b/kmymoney/mymoney/tests/mymoneyfile-test.h --- a/kmymoney/mymoney/tests/mymoneyfile-test.h +++ b/kmymoney/mymoney/tests/mymoneyfile-test.h @@ -29,6 +29,9 @@ class MyMoneyFileTest : public QObject { Q_OBJECT +public: + MyMoneyFileTest(); + protected: MyMoneyFile *m; MyMoneyStorageMgr* storage; diff --git a/kmymoney/mymoney/tests/mymoneyfile-test.cpp b/kmymoney/mymoney/tests/mymoneyfile-test.cpp --- a/kmymoney/mymoney/tests/mymoneyfile-test.cpp +++ b/kmymoney/mymoney/tests/mymoneyfile-test.cpp @@ -46,6 +46,13 @@ QTEST_GUILESS_MAIN(MyMoneyFileTest) +MyMoneyFileTest::MyMoneyFileTest() : + m(nullptr), + storage(nullptr) +{ + +} + void MyMoneyFileTest::objectAdded(eMyMoney::File::Object type, const QString& id) { Q_UNUSED(type); @@ -2369,11 +2376,13 @@ void MyMoneyFileTest::testGetOnlineJob() { QSKIP("Need dummy task for this test", SkipAll); + #if 0 testAddOnlineJob(); const onlineJob requestedJob = m->getOnlineJob("O000001"); QVERIFY(!requestedJob.isNull()); QCOMPARE(requestedJob.id(), QString("O000001")); + #endif } void MyMoneyFileTest::testRemoveOnlineJob() diff --git a/kmymoney/mymoney/tests/mymoneyforecast-test.cpp b/kmymoney/mymoney/tests/mymoneyforecast-test.cpp --- a/kmymoney/mymoney/tests/mymoneyforecast-test.cpp +++ b/kmymoney/mymoney/tests/mymoneyforecast-test.cpp @@ -41,7 +41,10 @@ QTEST_GUILESS_MAIN(MyMoneyForecastTest) -MyMoneyForecastTest::MyMoneyForecastTest() +MyMoneyForecastTest::MyMoneyForecastTest() : + m(nullptr), + storage(nullptr), + file(nullptr) { this->moT1 = MyMoneyMoney(57, 1); this->moT2 = MyMoneyMoney(63, 1); @@ -606,7 +609,8 @@ //test invalid arguments MyMoneyAccount nullAcc; try { - a.daysToZeroBalance(nullAcc); + auto days = a.daysToZeroBalance(nullAcc); + Q_UNUSED(days) } catch (const MyMoneyException &) { QFAIL("Unexpected exception"); } diff --git a/kmymoney/payeeidentifier/ibanandbic/bicmodel.cpp b/kmymoney/payeeidentifier/ibanandbic/bicmodel.cpp --- a/kmymoney/payeeidentifier/ibanandbic/bicmodel.cpp +++ b/kmymoney/payeeidentifier/ibanandbic/bicmodel.cpp @@ -62,8 +62,8 @@ if (services.isEmpty()) { // Set a valid query - query.exec("SELECT null;"); - setQuery(query); + if (query.exec("SELECT null;")) + setQuery(query); return; } diff --git a/kmymoney/plugins/checkprinting/checkprinting.cpp b/kmymoney/plugins/checkprinting/checkprinting.cpp --- a/kmymoney/plugins/checkprinting/checkprinting.cpp +++ b/kmymoney/plugins/checkprinting/checkprinting.cpp @@ -65,7 +65,8 @@ }; CheckPrinting::CheckPrinting(QObject *parent, const QVariantList &args) : - KMyMoneyPlugin::Plugin(parent, "checkprinting"/*must be the same as X-KDE-PluginInfo-Name*/) + KMyMoneyPlugin::Plugin(parent, "checkprinting"/*must be the same as X-KDE-PluginInfo-Name*/), + m_currentPrinter(nullptr) { Q_UNUSED(args); // Tell the host application to load my GUI component diff --git a/kmymoney/plugins/csv/import/bankingwizardpage.cpp b/kmymoney/plugins/csv/import/bankingwizardpage.cpp --- a/kmymoney/plugins/csv/import/bankingwizardpage.cpp +++ b/kmymoney/plugins/csv/import/bankingwizardpage.cpp @@ -359,12 +359,13 @@ QString strEType; switch (st.m_eType) { - case eMyMoney::Statement::Type::CreditCard: - strEType = QStringLiteral("CCard"); - case eMyMoney::Statement::Type::Savings: - case eMyMoney::Statement::Type::Checkings: - default: - strEType = QStringLiteral("Bank"); + case eMyMoney::Statement::Type::CreditCard: + strEType = QStringLiteral("CCard"); + break; + case eMyMoney::Statement::Type::Savings: + case eMyMoney::Statement::Type::Checkings: + default: + strEType = QStringLiteral("Bank"); } if (!st.m_strAccountName.isEmpty()) { diff --git a/kmymoney/plugins/csv/import/core/csvimportercore.h b/kmymoney/plugins/csv/import/core/csvimportercore.h --- a/kmymoney/plugins/csv/import/core/csvimportercore.h +++ b/kmymoney/plugins/csv/import/core/csvimportercore.h @@ -63,13 +63,24 @@ class KMM_CSVIMPORTERCORE_NO_EXPORT CSVProfile { protected: - CSVProfile() {} + CSVProfile() : + m_encodingMIBEnum(0), + m_startLine(0), + m_endLine(0), + m_trailerLines(0), + m_dateFormat(DateFormat::DayMonthYear), + m_fieldDelimiter(FieldDelimiter::Auto), + m_textDelimiter(TextDelimiter::DoubleQuote), + m_decimalSymbol(DecimalSymbol::Auto) + { + } + CSVProfile(const QString &profileName, int encodingMIBEnum, int startLine, int trailerLines, DateFormat dateFormat, FieldDelimiter fieldDelimiter, TextDelimiter textDelimiter, DecimalSymbol decimalSymbol, QMap &colTypeNum) : m_profileName(profileName), m_encodingMIBEnum(encodingMIBEnum), - m_startLine(startLine), m_trailerLines(trailerLines), + m_startLine(startLine), m_endLine(startLine), m_trailerLines(trailerLines), m_dateFormat(dateFormat), m_fieldDelimiter(fieldDelimiter), m_textDelimiter(textDelimiter), m_decimalSymbol(decimalSymbol), m_colTypeNum(colTypeNum) @@ -110,7 +121,7 @@ class KMM_CSVIMPORTERCORE_EXPORT BankingProfile : public CSVProfile { public: - explicit BankingProfile() : CSVProfile() {} + explicit BankingProfile() : CSVProfile(), m_oppositeSigns(false) {} BankingProfile(QString profileName, int encodingMIBEnum, int startLine, int trailerLines, DateFormat dateFormat, FieldDelimiter fieldDelimiter, TextDelimiter textDelimiter, DecimalSymbol decimalSymbol, @@ -135,7 +146,14 @@ class KMM_CSVIMPORTERCORE_EXPORT InvestmentProfile : public CSVProfile { public: - explicit InvestmentProfile() : CSVProfile() {} + explicit InvestmentProfile() : + CSVProfile(), + m_priceFraction(2), + m_dontAsk(0), + m_feeIsPercentage(false) + { + } + InvestmentProfile(QString profileName, int encodingMIBEnum, int startLine, int trailerLines, DateFormat dateFormat, FieldDelimiter fieldDelimiter, TextDelimiter textDelimiter, DecimalSymbol decimalSymbol, @@ -145,7 +163,12 @@ startLine, trailerLines, dateFormat, fieldDelimiter, textDelimiter, decimalSymbol, colTypeNum), - m_transactionNames(transactionNames), m_priceFraction(priceFraction), m_feeIsPercentage(false) {} + m_transactionNames(transactionNames), + m_priceFraction(priceFraction), + m_dontAsk(0), + m_feeIsPercentage(false) + { + } Profile type() const { return Profile::Investment; } bool readSettings(const KSharedConfigPtr &config); @@ -170,7 +193,14 @@ { public: explicit PricesProfile() : CSVProfile() {} - explicit PricesProfile(const Profile profileType) : CSVProfile(), m_profileType(profileType) {} + explicit PricesProfile(const Profile profileType) : + CSVProfile(), + m_dontAsk(0), + m_priceFraction(2), + m_profileType(profileType) + { + } + PricesProfile(QString profileName, int encodingMIBEnum, int startLine, int trailerLines, DateFormat dateFormat, FieldDelimiter fieldDelimiter, TextDelimiter textDelimiter, DecimalSymbol decimalSymbol, @@ -180,7 +210,11 @@ startLine, trailerLines, dateFormat, fieldDelimiter, textDelimiter, decimalSymbol, colTypeNum), - m_priceFraction(priceFraction), m_profileType(profileType) {} + m_dontAsk(0), + m_priceFraction(priceFraction), + m_profileType(profileType) + { + } Profile type() const { return m_profileType; } bool readSettings(const KSharedConfigPtr &config); diff --git a/kmymoney/plugins/csv/import/core/csvimportercore.cpp b/kmymoney/plugins/csv/import/core/csvimportercore.cpp --- a/kmymoney/plugins/csv/import/core/csvimportercore.cpp +++ b/kmymoney/plugins/csv/import/core/csvimportercore.cpp @@ -107,8 +107,9 @@ const QString CSVImporterCore::m_confPriorName = QStringLiteral("Prior"); const QString CSVImporterCore::m_confMiscName = QStringLiteral("Misc"); -CSVImporterCore::CSVImporterCore() - : m_profile(0) +CSVImporterCore::CSVImporterCore() : + m_profile(0), + m_isActionTypeValidated(false) { m_convertDate = new ConvertDate; m_file = new CSVFile; @@ -520,7 +521,7 @@ bool CSVImporterCore::calculateFee() { - InvestmentProfile *profile = dynamic_cast(m_profile); + auto profile = dynamic_cast(m_profile); if (!profile) return false; if ((profile->m_feeRate.isEmpty() || // check whether feeRate... @@ -1362,10 +1363,10 @@ if (m_autodetect.value(AutoAccountInvest)) detectAccount(st); - InvestmentProfile *profile = dynamic_cast(m_profile); + auto profile = dynamic_cast(m_profile); if ((m_profile->m_colTypeNum.value(Column::Fee, -1) == -1 || m_profile->m_colTypeNum.value(Column::Fee, -1) >= m_file->m_columnCount) && - !profile->m_feeRate.isEmpty()) // fee column has not been calculated so do it now + profile && !profile->m_feeRate.isEmpty()) // fee column has not been calculated so do it now calculateFee(); for (int row = m_profile->m_startLine; row <= m_profile->m_endLine; ++row) @@ -1391,9 +1392,9 @@ return true; st.m_eType = eMyMoney::Statement::Type::None; - PricesProfile *profile = dynamic_cast(m_profile); + auto*profile = dynamic_cast(m_profile); for (int row = m_profile->m_startLine; row <= m_profile->m_endLine; ++row) - if (!processPriceRow(st, profile, row)) { // parse fields + if (profile && !processPriceRow(st, profile, row)) { // parse fields st = MyMoneyStatement(); return false; } @@ -1620,7 +1621,9 @@ profilesGroup.config()->sync(); } -CSVFile::CSVFile() +CSVFile::CSVFile() : + m_columnCount(0), + m_rowCount(0) { m_parse = new Parse; m_model = new QStandardItemModel; diff --git a/kmymoney/plugins/csv/import/core/tests/parsedata-test.cpp b/kmymoney/plugins/csv/import/core/tests/parsedata-test.cpp --- a/kmymoney/plugins/csv/import/core/tests/parsedata-test.cpp +++ b/kmymoney/plugins/csv/import/core/tests/parsedata-test.cpp @@ -23,7 +23,8 @@ QTEST_GUILESS_MAIN(ParseDataTest); -ParseDataTest::ParseDataTest() +ParseDataTest::ParseDataTest() : + m_parse(nullptr) { } diff --git a/kmymoney/plugins/csv/import/core/tests/symbol-test.cpp b/kmymoney/plugins/csv/import/core/tests/symbol-test.cpp --- a/kmymoney/plugins/csv/import/core/tests/symbol-test.cpp +++ b/kmymoney/plugins/csv/import/core/tests/symbol-test.cpp @@ -25,7 +25,8 @@ Parse* m_parse; -SymbolTest::SymbolTest() +SymbolTest::SymbolTest() : + m_parse(nullptr) { } diff --git a/kmymoney/plugins/csv/import/csvwizard.cpp b/kmymoney/plugins/csv/import/csvwizard.cpp --- a/kmymoney/plugins/csv/import/csvwizard.cpp +++ b/kmymoney/plugins/csv/import/csvwizard.cpp @@ -61,6 +61,7 @@ CSVWizard::CSVWizard(CSVImporter *plugin, CSVImporterCore* importer) : ui(new Ui::CSVWizard), + m_skipSetup(false), m_plugin(plugin), m_imp(importer), m_wiz(new QWizard) @@ -446,6 +447,7 @@ //------------------------------------------------------------------------------------------------------- IntroPage::IntroPage(CSVWizard *dlg, CSVImporterCore *imp) : CSVWizardPage(dlg, imp), + m_profileType(Profile::Banking), ui(new Ui::IntroPage) { ui->setupUi(this); @@ -780,12 +782,6 @@ m_imp->m_profile->m_textDelimiter = static_cast(index); m_imp->m_file->setupParser(m_imp->m_profile); - - if (index == -1) { - ui->m_textDelimiter->blockSignals(true); - ui->m_textDelimiter->setCurrentIndex((int)m_imp->m_profile->m_textDelimiter); - ui->m_textDelimiter->blockSignals(false); - } emit completeChanged(); } @@ -927,7 +923,9 @@ FormatsPage::FormatsPage(CSVWizard *dlg, CSVImporterCore *imp) : CSVWizardPage(dlg, imp), - ui(new Ui::FormatsPage) + ui(new Ui::FormatsPage), + m_isDecimalSymbolOK(false), + m_isDateFormatOK(false) { ui->setupUi(this); connect(ui->m_dateFormat, SIGNAL(currentIndexChanged(int)), this, SLOT(dateFormatChanged(int))); diff --git a/kmymoney/plugins/csv/import/securitiesdlg.cpp b/kmymoney/plugins/csv/import/securitiesdlg.cpp --- a/kmymoney/plugins/csv/import/securitiesdlg.cpp +++ b/kmymoney/plugins/csv/import/securitiesdlg.cpp @@ -24,7 +24,9 @@ #include "ui_securitiesdlg.h" -SecuritiesDlg::SecuritiesDlg() : ui(new Ui::SecuritiesDlg) +SecuritiesDlg::SecuritiesDlg() : + ui(new Ui::SecuritiesDlg), + m_RowCount(0) { ui->setupUi(this); m_validRowCount = 0; diff --git a/kmymoney/plugins/forecast/kforecastview_p.h b/kmymoney/plugins/forecast/kforecastview_p.h --- a/kmymoney/plugins/forecast/kforecastview_p.h +++ b/kmymoney/plugins/forecast/kforecastview_p.h @@ -390,8 +390,6 @@ && (dropMinimum < dropZero || dropZero == -1)) { switch (dropMinimum) { - case -1: - break; case 0: msg = QString("").arg(KMyMoneySettings::schemeColor(SchemeColor::Negative).name()); msg += i18n("The balance of %1 is below the minimum balance %2 today.", acc.name(), MyMoneyUtils::formatMoney(minBalance, acc, currency)); diff --git a/kmymoney/plugins/gnc/import/mymoneygncreader.cpp b/kmymoney/plugins/gnc/import/mymoneygncreader.cpp --- a/kmymoney/plugins/gnc/import/mymoneygncreader.cpp +++ b/kmymoney/plugins/gnc/import/mymoneygncreader.cpp @@ -2434,7 +2434,7 @@ return (lastDate); } throw MYMONEYEXCEPTION(i18n("Internal error - invalid interval char in incrDate")); - QDate r = QDate(); return (r); // to keep compiler happy +// QDate r = QDate(); return (r); // to keep compiler happy } PASS } diff --git a/kmymoney/plugins/kbanking/gwenkdegui.cpp b/kmymoney/plugins/kbanking/gwenkdegui.cpp --- a/kmymoney/plugins/kbanking/gwenkdegui.cpp +++ b/kmymoney/plugins/kbanking/gwenkdegui.cpp @@ -51,7 +51,6 @@ QString infoText = QString::fromUtf8(text); QRegExp hhdRegExp = QRegExp("^(.*)\\$OBEGIN\\$(.*)\\$OEND\\$(.*)$", Qt::CaseInsensitive); hhdRegExp.setMinimal(true); - hhdRegExp.indexIn(infoText); QStringList captured = hhdRegExp.capturedTexts(); QString hhdCode = captured.at(2); infoText = captured.at(1) + captured.at(3); diff --git a/kmymoney/plugins/kbanking/kbanking.cpp b/kmymoney/plugins/kbanking/kbanking.cpp --- a/kmymoney/plugins/kbanking/kbanking.cpp +++ b/kmymoney/plugins/kbanking/kbanking.cpp @@ -1318,10 +1318,10 @@ if (!startTime) startTime = ti; - else { + /*else { dead code if (GWEN_Time_Diff(ti, startTime) < 0) startTime = ti; - } + }*/ if (!GWEN_Time_GetBrokenDownDate(ti, &day, &month, &year)) { kt.m_datePosted = QDate(year, month + 1, day); diff --git a/kmymoney/plugins/kbanking/tasksettings/credittransfersettingsbase.h b/kmymoney/plugins/kbanking/tasksettings/credittransfersettingsbase.h --- a/kmymoney/plugins/kbanking/tasksettings/credittransfersettingsbase.h +++ b/kmymoney/plugins/kbanking/tasksettings/credittransfersettingsbase.h @@ -39,6 +39,7 @@ _payeeNameMaxLines(0), _payeeNameLength(0), _payeeNameMinLength(0), + m_endToEndReferenceLength(0), _allowedChars(QString("")) {} // Limits getter diff --git a/kmymoney/plugins/ofx/import/ofximporter.cpp b/kmymoney/plugins/ofx/import/ofximporter.cpp --- a/kmymoney/plugins/ofx/import/ofximporter.cpp +++ b/kmymoney/plugins/ofx/import/ofximporter.cpp @@ -135,6 +135,7 @@ } } + delete option; delete widget; } diff --git a/kmymoney/plugins/onlinetasks/sepa/sepastorageplugin.cpp b/kmymoney/plugins/onlinetasks/sepa/sepastorageplugin.cpp --- a/kmymoney/plugins/onlinetasks/sepa/sepastorageplugin.cpp +++ b/kmymoney/plugins/onlinetasks/sepa/sepastorageplugin.cpp @@ -55,7 +55,8 @@ if (currentVersion == 0) { // If the database is recreated the table may be still there. So drop it if needed. No error handling needed // as this step is not necessary - only the creation is important. - query.exec("DROP TABLE IF EXISTS kmmSepaOrders;"); + if (!query.exec("DROP TABLE IF EXISTS kmmSepaOrders;")) + return false; if (!query.exec( "CREATE TABLE kmmSepaOrders (" diff --git a/kmymoney/plugins/qif/import/mymoneyqifreader.cpp b/kmymoney/plugins/qif/import/mymoneyqifreader.cpp --- a/kmymoney/plugins/qif/import/mymoneyqifreader.cpp +++ b/kmymoney/plugins/qif/import/mymoneyqifreader.cpp @@ -73,7 +73,10 @@ public: Private() : accountType(eMyMoney::Account::Type::Checkings), - mapCategories(true) {} + firstTransaction(true), + mapCategories(true), + transactionType(MyMoneyQifReader::QifEntryTypeE::EntryUnknown) + {} const QString accountTypeToQif(eMyMoney::Account::Type type) const; @@ -243,7 +246,13 @@ MyMoneyQifReader::MyMoneyQifReader() : - d(new Private) + d(new Private), + m_file(nullptr), + m_extractedLine(0), + m_autoCreatePayee(true), + m_pos(0), + m_linenumber(0), + m_ft(nullptr) { m_skipAccount = false; m_transactionsProcessed = @@ -428,8 +437,7 @@ qDebug() << "Source:" << m_url.toDisplayString() << "Destination:" << m_filename; KIO::FileCopyJob *job = KIO::file_copy(m_url, QUrl::fromUserInput(m_filename), -1, KIO::Overwrite); // KJobWidgets::setWindow(job, kmymoney); - job->exec(); - if (job->error()) { + if (job->exec() && job->error()) { KMessageBox::detailedError(0, i18n("Error while loading file '%1'.", m_url.toDisplayString()), job->errorString(), i18n("File access error")); @@ -946,7 +954,8 @@ if (name.isEmpty()) { name = i18n("QIF imported, no account name supplied"); } - d->isTransfer(name, m_qifProfile.accountDelimiter().left(1), m_qifProfile.accountDelimiter().mid(1, 1)); + auto b = d->isTransfer(name, m_qifProfile.accountDelimiter().left(1), m_qifProfile.accountDelimiter().mid(1, 1)); + Q_UNUSED(b) QStringList entry = m_qifEntry; // keep a temp copy m_qifEntry.clear(); // and construct a temp entry to create/search the account m_qifEntry << QString("N%1").arg(name); diff --git a/kmymoney/plugins/reconciliationreport/kreconciliationreportdlg.cpp b/kmymoney/plugins/reconciliationreport/kreconciliationreportdlg.cpp --- a/kmymoney/plugins/reconciliationreport/kreconciliationreportdlg.cpp +++ b/kmymoney/plugins/reconciliationreport/kreconciliationreportdlg.cpp @@ -35,7 +35,9 @@ #include #endif -KReportDlg::KReportDlg(QWidget* parent, const QString& summaryReportHTML, const QString& detailsReportHTML) : QDialog(parent) +KReportDlg::KReportDlg(QWidget* parent, const QString& summaryReportHTML, const QString& detailsReportHTML) : + QDialog(parent), + m_currentPrinter(nullptr) { setupUi(this); #ifdef ENABLE_WEBENGINE diff --git a/kmymoney/plugins/sql/kgeneratesqldlg.cpp b/kmymoney/plugins/sql/kgeneratesqldlg.cpp --- a/kmymoney/plugins/sql/kgeneratesqldlg.cpp +++ b/kmymoney/plugins/sql/kgeneratesqldlg.cpp @@ -64,7 +64,12 @@ public: explicit KGenerateSqlDlgPrivate(KGenerateSqlDlg *qq) : q_ptr(qq), - ui(new Ui::KGenerateSqlDlg) + ui(new Ui::KGenerateSqlDlg), + m_createTablesButton(nullptr), + m_saveSqlButton(nullptr), + m_sqliteSelected(false), + m_storage(nullptr), + m_mustDetachStorage(false) { } diff --git a/kmymoney/plugins/sql/mymoneystoragesql.cpp b/kmymoney/plugins/sql/mymoneystoragesql.cpp --- a/kmymoney/plugins/sql/mymoneystoragesql.cpp +++ b/kmymoney/plugins/sql/mymoneystoragesql.cpp @@ -1249,50 +1249,51 @@ const int matchKeysCol = record.indexOf("matchKeys"); const int identIdCol = record.indexOf("identId"); - query.next(); - while (query.isValid()) { - QString pid; - QString boolChar; - MyMoneyPayee payee; - uint type; - bool ignoreCase; - QString matchKeys; - pid = GETSTRING(idCol); - payee.setName(GETSTRING(nameCol)); - payee.setReference(GETSTRING(referenceCol)); - payee.setEmail(GETSTRING(emailCol)); - payee.setAddress(GETSTRING(addressStreetCol)); - payee.setCity(GETSTRING(addressCityCol)); - payee.setPostcode(GETSTRING(addressZipcodeCol)); - payee.setState(GETSTRING(addressStateCol)); - payee.setTelephone(GETSTRING(telephoneCol)); - payee.setNotes(GETSTRING(notesCol)); - payee.setDefaultAccountId(GETSTRING(defaultAccountIdCol)); - type = GETINT(matchDataCol); - ignoreCase = (GETSTRING(matchIgnoreCaseCol) == "Y"); - matchKeys = GETSTRING(matchKeysCol); - - payee.setMatchData(static_cast(type), ignoreCase, matchKeys); - - // Get payeeIdentifier ids - QStringList identifierIds; - do { - identifierIds.append(GETSTRING(identIdCol)); - } while (query.next() && GETSTRING(idCol) == pid); // as long as the payeeId is unchanged - - // Fetch and save payeeIdentifier - if (!identifierIds.isEmpty()) { - QList< ::payeeIdentifier > identifier = fetchPayeeIdentifiers(identifierIds).values(); - payee.resetPayeeIdentifiers(identifier); - } + if (query.next()) { + while (query.isValid()) { + QString pid; + QString boolChar; + MyMoneyPayee payee; + uint type; + bool ignoreCase; + QString matchKeys; + pid = GETSTRING(idCol); + payee.setName(GETSTRING(nameCol)); + payee.setReference(GETSTRING(referenceCol)); + payee.setEmail(GETSTRING(emailCol)); + payee.setAddress(GETSTRING(addressStreetCol)); + payee.setCity(GETSTRING(addressCityCol)); + payee.setPostcode(GETSTRING(addressZipcodeCol)); + payee.setState(GETSTRING(addressStateCol)); + payee.setTelephone(GETSTRING(telephoneCol)); + payee.setNotes(GETSTRING(notesCol)); + payee.setDefaultAccountId(GETSTRING(defaultAccountIdCol)); + type = GETINT(matchDataCol); + ignoreCase = (GETSTRING(matchIgnoreCaseCol) == "Y"); + matchKeys = GETSTRING(matchKeysCol); + + payee.setMatchData(static_cast(type), ignoreCase, matchKeys); + + // Get payeeIdentifier ids + QStringList identifierIds; + do { + identifierIds.append(GETSTRING(identIdCol)); + } while (query.next() && GETSTRING(idCol) == pid); // as long as the payeeId is unchanged + + // Fetch and save payeeIdentifier + if (!identifierIds.isEmpty()) { + QList< ::payeeIdentifier > identifier = fetchPayeeIdentifiers(identifierIds).values(); + payee.resetPayeeIdentifiers(identifier); + } - if (pid == "USER") - d->m_storage->setUser(payee); - else - pList[pid] = MyMoneyPayee(pid, payee); + if (pid == "USER") + d->m_storage->setUser(payee); + else + pList[pid] = MyMoneyPayee(pid, payee); - if (d->m_displayStatus) - d->signalProgress(++progress, 0); + if (d->m_displayStatus) + d->signalProgress(++progress, 0); + } } return pList; } @@ -1598,7 +1599,8 @@ while (sq.isValid() && it_acc != accListEnd && it_acc.value().id() == sq.value(1).toString()) { it_acc.value().addAccountId(sq.value(0).toString()); - sq.next(); + if (!sq.next()) + break; } sq.previous(); } @@ -1884,7 +1886,7 @@ QDate end = filter.toDate(); // not entirely sure if the following is correct, but at best, saves a lot of reads, at worst // it only causes us to read a few more transactions that strictly necessary (I think...) - if (start == d->m_startDate) start = QDate(); + if (start == MyMoneyStorageSqlPrivate::m_startDate) start = QDate(); bool txFilterActive = ((start != QDate()) || (end != QDate())); // and this for fields in the transaction table QString whereClause = ""; diff --git a/kmymoney/plugins/sql/mymoneystoragesql_p.h b/kmymoney/plugins/sql/mymoneystoragesql_p.h --- a/kmymoney/plugins/sql/mymoneystoragesql_p.h +++ b/kmymoney/plugins/sql/mymoneystoragesql_p.h @@ -120,10 +120,14 @@ ~MyMoneyDbTransaction() { if (std::uncaught_exception()) { - m_db.cancelCommitUnit(m_name); - } else { + m_db.cancelCommitUnit(m_name); + } else { + try{ m_db.endCommitUnit(m_name); + } catch(MyMoneyException&) { + m_db.cancelCommitUnit(m_name); } + } } private: MyMoneyStorageSql& m_db; @@ -187,8 +191,24 @@ explicit MyMoneyStorageSqlPrivate(MyMoneyStorageSql* qq) : q_ptr(qq), m_dbVersion(0), + m_storage(nullptr), m_loadAll(false), m_override(false), + m_institutions(0), + m_accounts(0), + m_payees(0), + m_tags(0), + m_transactions(0), + m_splits(0), + m_securities(0), + m_prices(0), + m_currencies(0), + m_schedules(0), + m_reports(0), + m_kvps(0), + m_budgets(0), + m_onlineJobs(0), + m_payeeIdentifier(0), m_hiIdInstitutions(0), m_hiIdPayees(0), m_hiIdTags(0), diff --git a/kmymoney/plugins/sql/payeeidentifier/ibanandbic/ibanbicstorageplugin.cpp b/kmymoney/plugins/sql/payeeidentifier/ibanandbic/ibanbicstorageplugin.cpp --- a/kmymoney/plugins/sql/payeeidentifier/ibanandbic/ibanbicstorageplugin.cpp +++ b/kmymoney/plugins/sql/payeeidentifier/ibanandbic/ibanbicstorageplugin.cpp @@ -63,7 +63,8 @@ if (currentVersion == 0) { // If the database is recreated the table may be still there. So drop it if needed. No error handling needed // as this step is not necessary - only the creation is important. - query.exec("DROP TABLE IF EXISTS kmmIbanBic;"); + if (!query.exec("DROP TABLE IF EXISTS kmmIbanBic;")) + return false; if (!query.exec( "CREATE TABLE kmmIbanBic (" diff --git a/kmymoney/plugins/sql/payeeidentifier/nationalaccount/nationalaccountstorageplugin.cpp b/kmymoney/plugins/sql/payeeidentifier/nationalaccount/nationalaccountstorageplugin.cpp --- a/kmymoney/plugins/sql/payeeidentifier/nationalaccount/nationalaccountstorageplugin.cpp +++ b/kmymoney/plugins/sql/payeeidentifier/nationalaccount/nationalaccountstorageplugin.cpp @@ -66,7 +66,8 @@ if (currentVersion == 0) { // If the database is recreated the table may be still there. So drop it if needed. No error handling needed // as this step is not necessary - only the creation is important. - query.exec("DROP TABLE IF EXISTS kmmNationalAccountNumber;"); + if (!query.exec("DROP TABLE IF EXISTS kmmNationalAccountNumber;")) + return false; if (!query.exec( "CREATE TABLE kmmNationalAccountNumber (" diff --git a/kmymoney/plugins/sql/tests/mymoneydatabasemgr-test.cpp b/kmymoney/plugins/sql/tests/mymoneydatabasemgr-test.cpp --- a/kmymoney/plugins/sql/tests/mymoneydatabasemgr-test.cpp +++ b/kmymoney/plugins/sql/tests/mymoneydatabasemgr-test.cpp @@ -47,12 +47,13 @@ QTEST_GUILESS_MAIN(MyMoneyStorageMgrTest) -MyMoneyStorageMgrTest::MyMoneyStorageMgrTest() - : m_dbAttached(false), - m_canOpen(true), - m_haveEmptyDataBase(false), - m_file(this), - m_emptyFile(this) +MyMoneyStorageMgrTest::MyMoneyStorageMgrTest() : + m(nullptr), + m_dbAttached(false), + m_canOpen(true), + m_haveEmptyDataBase(false), + m_file(this), + m_emptyFile(this) { // Open and close the temp file so that it exists m_file.open(); @@ -2438,7 +2439,7 @@ m->setDirty(); QSKIP("Test not fully implemented, yet.", SkipAll); - + #if 0 try { m->addOnlineJob(job); @@ -2459,6 +2460,7 @@ } catch (const MyMoneyException &) { QCOMPARE(m->dirty(), false); } + #endif } void MyMoneyStorageMgrTest::testModifyOnlineJob() @@ -2473,7 +2475,7 @@ m->setDirty(); QSKIP("Test not fully implemented, yet.", SkipAll); - + #if 0 // update online job try { MyMoneyFileTransaction ft; @@ -2497,6 +2499,7 @@ } catch (const MyMoneyException &) { QVERIFY(m->dirty() == false); } + #endif } void MyMoneyStorageMgrTest::testRemoveOnlineJob() @@ -2511,7 +2514,7 @@ m->setDirty(); QSKIP("Test not fully implemented, yet.", SkipAll); - + #if 0 try { MyMoneyFileTransaction ft; m->removeOnlineJob(job); @@ -2532,6 +2535,7 @@ } catch (const MyMoneyException &) { QVERIFY(m->dirty() == false); } + #endif } void MyMoneyStorageMgrTest::testHighestNumberFromIdString() diff --git a/kmymoney/reports/kreportchartview.cpp b/kmymoney/reports/kreportchartview.cpp --- a/kmymoney/reports/kreportchartview.cpp +++ b/kmymoney/reports/kreportchartview.cpp @@ -58,7 +58,8 @@ m_numColumns(0), m_skipZero(0), m_backgroundBrush(KColorScheme(QPalette::Current).background()), - m_foregroundBrush(KColorScheme(QPalette::Current).foreground()) + m_foregroundBrush(KColorScheme(QPalette::Current).foreground()), + m_precision(2) { // ******************************************************************** // Set KMyMoney's Chart Parameter Defaults diff --git a/kmymoney/reports/listtable.cpp b/kmymoney/reports/listtable.cpp --- a/kmymoney/reports/listtable.cpp +++ b/kmymoney/reports/listtable.cpp @@ -228,9 +228,9 @@ else result.append(QLatin1String("")); } - } else { + }/* else { dead code result.append(QLatin1String("")); - } + }*/ } else { result.append(QString::fromLatin1("").arg(row_odd ? QLatin1String("odd") : QLatin1String("even"))); } diff --git a/kmymoney/reports/tests/reportstestcommon.cpp b/kmymoney/reports/tests/reportstestcommon.cpp --- a/kmymoney/reports/tests/reportstestcommon.cpp +++ b/kmymoney/reports/tests/reportstestcommon.cpp @@ -478,8 +478,8 @@ MyMoneyMoney searchHTML(const QString& _html, const QString& _search) { + Q_UNUSED(_html) QRegExp re(QString("%1[<>/td]*([\\-.0-9,]*)").arg(_search)); - re.indexIn(_html); QString found = re.cap(1); found.remove(','); diff --git a/kmymoney/views/kbudgetview.cpp b/kmymoney/views/kbudgetview.cpp --- a/kmymoney/views/kbudgetview.cpp +++ b/kmymoney/views/kbudgetview.cpp @@ -323,7 +323,9 @@ if (!p) return; - KBudgetListItem *pBudget = dynamic_cast(p); + auto pBudget = dynamic_cast(p); + if (!pBudget) + return; if (col == 1) { pBudget->setText(1, QString().setNum(pBudget->budget().budgetStart().year())); return; diff --git a/kmymoney/views/kbudgetview_p.h b/kmymoney/views/kbudgetview_p.h --- a/kmymoney/views/kbudgetview_p.h +++ b/kmymoney/views/kbudgetview_p.h @@ -105,7 +105,10 @@ explicit KBudgetViewPrivate(KBudgetView *qq) : KMyMoneyAccountsViewBasePrivate(), q_ptr(qq), - ui(new Ui::KBudgetView) + ui(new Ui::KBudgetView), + m_budgetProxyModel(nullptr), + m_inSelection(false), + m_budgetInEditing(false) { } diff --git a/kmymoney/views/kgloballedgerview_p.h b/kmymoney/views/kgloballedgerview_p.h --- a/kmymoney/views/kgloballedgerview_p.h +++ b/kmymoney/views/kgloballedgerview_p.h @@ -230,11 +230,24 @@ q_ptr(qq), m_mousePressFilter(0), m_registerSearchLine(0), + m_precision(2), m_recursion(false), m_showDetails(false), + m_action(eWidgets::eRegister::Action::None), m_filterProxyModel(0), m_accountComboBox(0), m_balanceIsApproximated(false), + m_toolbarFrame(nullptr), + m_registerFrame(nullptr), + m_buttonFrame(nullptr), + m_formFrame(nullptr), + m_summaryFrame(nullptr), + m_register(nullptr), + m_buttonbar(nullptr), + m_leftSummaryLabel(nullptr), + m_centerSummaryLabel(nullptr), + m_rightSummaryLabel(nullptr), + m_form(nullptr), m_needLoad(true), m_newAccountLoaded(true), m_inEditMode(false), @@ -1098,20 +1111,20 @@ if (m_register->focusItem() == 0) return false; - bool rc = true; +// bool rc = true; if (list.warnLevel() == 3) { //Closed account somewhere - KMyMoneyRegister::SelectedTransactions::const_iterator it_t; - for (it_t = list.begin(); rc && it_t != list.end(); ++it_t) { - QList splitList = (*it_t).transaction().splits(); - QString id = splitList.first().accountId(); + auto it_t = list.first(); +// for (auto it_t = list.cbegin(); rc && it_t != list.cend(); ++it_t) { + auto splitList = it_t.transaction().splits(); + auto id = splitList.first().accountId(); acc = MyMoneyFile::instance()->account(id); if (!acc.isClosed()) { //wrong split, try other id = splitList.last().accountId(); acc = MyMoneyFile::instance()->account(id); } closedAccount = acc.name(); - break; - } +// break; +// } tooltip = i18n("Cannot process transactions in account %1, which is closed.", closedAccount); showTooltip(tooltip); return false; diff --git a/kmymoney/views/khomeview_p.h b/kmymoney/views/khomeview_p.h --- a/kmymoney/views/khomeview_p.h +++ b/kmymoney/views/khomeview_p.h @@ -128,7 +128,8 @@ m_view(nullptr), m_showAllSchedules(false), m_needLoad(true), - m_netWorthGraphLastValidSize(400, 300) + m_netWorthGraphLastValidSize(400, 300), + m_currentPrinter(nullptr) { } @@ -1125,8 +1126,6 @@ && (dropMinimum < dropZero || dropZero == -1)) { switch (dropMinimum) { - case -1: - break; case 0: msg = i18n("The balance of %1 is below the minimum balance %2 today.", (*it_account).name(), MyMoneyUtils::formatMoney(minBalance, *it_account, currency)); msg = showColoredAmount(msg, true); diff --git a/kmymoney/views/konlinejoboutbox.cpp b/kmymoney/views/konlinejoboutbox.cpp --- a/kmymoney/views/konlinejoboutbox.cpp +++ b/kmymoney/views/konlinejoboutbox.cpp @@ -60,7 +60,8 @@ KMyMoneyViewBasePrivate(), q_ptr(qq), ui(new Ui::KOnlineJobOutbox), - m_needLoad(true) + m_needLoad(true), + m_onlinePlugins(nullptr) { } diff --git a/kmymoney/views/kpayeesview.cpp b/kmymoney/views/kpayeesview.cpp --- a/kmymoney/views/kpayeesview.cpp +++ b/kmymoney/views/kpayeesview.cpp @@ -104,8 +104,9 @@ while (item) { //only walk through selectable items. eg. transactions and not group markers if (item->isSelectable()) { - KMyMoneyRegister::Transaction* t = dynamic_cast(item); - + auto t = dynamic_cast(item); + if (!t) + return; MyMoneySplit s = t->transaction().splitByPayee(d->m_payee.id()); const MyMoneyAccount& acc = file->account(s.accountId()); @@ -443,9 +444,7 @@ } if (d->m_payeeRows.count() <= d->m_payeeRow) { - KPayeeListItem* item = dynamic_cast(d->ui->m_payeesList->currentItem()); - - if (item) { // update ui if something is selected + if (auto item = dynamic_cast(d->ui->m_payeesList->currentItem())) { // update ui if something is selected d->m_payee = item->payee(); d->ui->addressEdit->setText(d->m_payee.address()); d->ui->postcodeEdit->setText(d->m_payee.postcode()); @@ -456,8 +455,7 @@ return; } - KPayeeListItem* item = dynamic_cast(d->ui->m_payeesList->item(d->m_payeeRows.at(d->m_payeeRow))); - if (item) + if (auto item = dynamic_cast(d->ui->m_payeesList->item(d->m_payeeRows.at(d->m_payeeRow)))) d->m_payee = item->payee(); ++d->m_payeeRow; @@ -583,8 +581,7 @@ QList selectedItems = d->ui->m_payeesList->selectedItems(); QList::const_iterator payeesIt = selectedItems.constBegin(); while (payeesIt != selectedItems.constEnd()) { - KPayeeListItem* item = dynamic_cast(*payeesIt); - if (item) + if (auto item = dynamic_cast(*payeesIt)) item->setSelected(false); ++payeesIt; } @@ -593,7 +590,7 @@ QListWidgetItem* it; for (int i = 0; i < d->ui->m_payeesList->count(); ++i) { it = d->ui->m_payeesList->item(i); - KPayeeListItem* item = dynamic_cast(it); + auto item = dynamic_cast(it); if (item && item->payee().id() == payeeId) { d->ui->m_payeesList->scrollToItem(it, QAbstractItemView::PositionAtCenter); @@ -606,8 +603,7 @@ KMyMoneyRegister::RegisterItem *item = 0; for (int i = 0; i < d->ui->m_register->rowCount(); ++i) { item = d->ui->m_register->itemAtRow(i); - KMyMoneyRegister::Transaction* t = dynamic_cast(item); - if (t) { + if (auto t = dynamic_cast(item)) { if (t->transaction().id() == transactionId && t->transaction().accountReferenced(accountId)) { d->ui->m_register->selectItem(item); d->ui->m_register->ensureItemVisible(item); @@ -627,8 +623,7 @@ void KPayeesView::slotShowPayeesMenu(const QPoint& /*p*/) { Q_D(KPayeesView); - auto item = dynamic_cast(d->ui->m_payeesList->currentItem()); - if (item) { + if (dynamic_cast(d->ui->m_payeesList->currentItem())) { slotSelectPayee(); pMenus[eMenu::Menu::Payee]->exec(QCursor::pos()); } diff --git a/kmymoney/views/kpayeesview_p.h b/kmymoney/views/kpayeesview_p.h --- a/kmymoney/views/kpayeesview_p.h +++ b/kmymoney/views/kpayeesview_p.h @@ -123,10 +123,14 @@ KMyMoneyViewBasePrivate(), q_ptr(qq), ui(new Ui::KPayeesView), + m_contact(nullptr), + m_payeeRow(0), m_needLoad(true), + m_searchWidget(nullptr), m_inSelection(false), m_allowEditing(true), - m_payeeFilterType(0) + m_payeeFilterType(0), + m_filterProxyModel(nullptr) { } diff --git a/kmymoney/views/kreportsview.cpp b/kmymoney/views/kreportsview.cpp --- a/kmymoney/views/kreportsview.cpp +++ b/kmymoney/views/kreportsview.cpp @@ -134,8 +134,7 @@ if (d->m_needsRefresh) refresh(); - KReportTab* tab = dynamic_cast(d->m_reportTabWidget->currentWidget()); - if (tab) + if (auto tab = dynamic_cast(d->m_reportTabWidget->currentWidget())) emit reportSelected(tab->report()); else emit reportSelected(MyMoneyReport()); @@ -214,24 +213,21 @@ void KReportsView::slotPrintView() { Q_D(KReportsView); - KReportTab* tab = dynamic_cast(d->m_reportTabWidget->currentWidget()); - if (tab) + if (auto tab = dynamic_cast(d->m_reportTabWidget->currentWidget())) tab->print(); } void KReportsView::slotCopyView() { Q_D(KReportsView); - KReportTab* tab = dynamic_cast(d->m_reportTabWidget->currentWidget()); - if (tab) + if (auto tab = dynamic_cast(d->m_reportTabWidget->currentWidget())) tab->copyToClipboard(); } void KReportsView::slotSaveView() { Q_D(KReportsView); - KReportTab* tab = dynamic_cast(d->m_reportTabWidget->currentWidget()); - if (tab) { + if (auto tab = dynamic_cast(d->m_reportTabWidget->currentWidget())) { QString filterList = i18nc("CSV (Filefilter)", "CSV files") + QLatin1String(" (*.csv);;") + i18nc("HTML (Filefilter)", "HTML files") + QLatin1String(" (*.html)"); QUrl newURL = QFileDialog::getSaveFileUrl(this, i18n("Export as"), QUrl::fromLocalFile(KRecentDirs::dir(":kmymoney-export")), filterList, &d->m_selectedExportFilter); if (!newURL.isEmpty()) { @@ -252,7 +248,7 @@ Q_D(KReportsView); QString cm = "KReportsView::slotConfigure"; - KReportTab* tab = dynamic_cast(d->m_reportTabWidget->currentWidget()); + auto tab = dynamic_cast(d->m_reportTabWidget->currentWidget()); if (!tab) // nothing to do return; @@ -321,7 +317,7 @@ Q_D(KReportsView); QString cm = "KReportsView::slotDuplicate"; - KReportTab* tab = dynamic_cast(d->m_reportTabWidget->currentWidget()); + auto tab = dynamic_cast(d->m_reportTabWidget->currentWidget()); if (!tab) { // nothing to do @@ -381,7 +377,7 @@ void KReportsView::slotDelete() { Q_D(KReportsView); - KReportTab* tab = dynamic_cast(d->m_reportTabWidget->currentWidget()); + auto tab = dynamic_cast(d->m_reportTabWidget->currentWidget()); if (!tab) { // nothing to do return; @@ -419,9 +415,9 @@ // Find the tab which contains the report int index = 1; while (index < d->m_reportTabWidget->count()) { - KReportTab* current = dynamic_cast(d->m_reportTabWidget->widget(index)); + auto current = dynamic_cast(d->m_reportTabWidget->widget(index)); - if (current->report().id() == id) { + if (current && current->report().id() == id) { page = current; break; } @@ -447,9 +443,9 @@ // Find the tab which contains the report indicated by this list item int index = 1; while (index < d->m_reportTabWidget->count()) { - KReportTab* current = dynamic_cast(d->m_reportTabWidget->widget(index)); + auto current = dynamic_cast(d->m_reportTabWidget->widget(index)); - if (current->report().name() == report.name()) { + if (current && current->report().name() == report.name()) { page = current; break; } @@ -470,8 +466,8 @@ void KReportsView::slotItemDoubleClicked(QTreeWidgetItem* item, int) { Q_D(KReportsView); - TocItem* tocItem = dynamic_cast(item); - if (!tocItem->isReport()) { + auto tocItem = dynamic_cast(item); + if (tocItem && !tocItem->isReport()) { // toggle the expanded-state for reportgroup-items item->setExpanded(item->isExpanded() ? false : true); @@ -488,21 +484,22 @@ // Find the tab which contains the report indicated by this list item int index = 1; while (index < d->m_reportTabWidget->count()) { - KReportTab* current = dynamic_cast(d->m_reportTabWidget->widget(index)); - - // If this report has an ID, we'll use the ID to match - if (! report.id().isEmpty()) { - if (current->report().id() == report.id()) { - page = current; - break; + auto current = dynamic_cast(d->m_reportTabWidget->widget(index)); + if (current) { + // If this report has an ID, we'll use the ID to match + if (! report.id().isEmpty()) { + if (current->report().id() == report.id()) { + page = current; + break; + } } - } - // Otherwise, use the name to match. THIS ASSUMES that no 2 default reports - // have the same name...but that would be pretty a boneheaded thing to do. - else { - if (current->report().name() == report.name()) { - page = current; - break; + // Otherwise, use the name to match. THIS ASSUMES that no 2 default reports + // have the same name...but that would be pretty a boneheaded thing to do. + else { + if (current->report().name() == report.name()) { + page = current; + break; + } } } @@ -519,9 +516,7 @@ void KReportsView::slotToggleChart() { Q_D(KReportsView); - KReportTab* tab = dynamic_cast(d->m_reportTabWidget->currentWidget()); - - if (tab) + if (auto tab = dynamic_cast(d->m_reportTabWidget->currentWidget())) tab->toggleChart(); } @@ -534,8 +529,7 @@ void KReportsView::slotClose(int index) { Q_D(KReportsView); - KReportTab* tab = dynamic_cast(d->m_reportTabWidget->widget(index)); - if (tab) { + if (auto tab = dynamic_cast(d->m_reportTabWidget->widget(index))) { d->m_reportTabWidget->removeTab(index); tab->setReadyToDelete(true); } @@ -546,8 +540,7 @@ Q_D(KReportsView); if(!d->m_needLoad) { while (true) { - KReportTab* tab = dynamic_cast(d->m_reportTabWidget->widget(1)); - if (tab) { + if (auto tab = dynamic_cast(d->m_reportTabWidget->widget(1))) { d->m_reportTabWidget->removeTab(1); tab->setReadyToDelete(true); } else @@ -566,9 +559,9 @@ return; } - TocItem* tocItem = dynamic_cast(item); + auto tocItem = dynamic_cast(item); - if (!tocItem->isReport()) { + if (tocItem && !tocItem->isReport()) { // currently there is no context menu for reportgroup items return; } @@ -585,11 +578,14 @@ this, SLOT(slotNewFromList())); // Only add this option if it's a custom report. Default reports cannot be deleted - TocItemReport* reportTocItem = dynamic_cast(tocItem); - MyMoneyReport& report = reportTocItem->getReport(); - if (! report.id().isEmpty()) { - contextmenu->addAction(i18n("&Delete"), - this, SLOT(slotDeleteFromList())); + auto reportTocItem = dynamic_cast(tocItem); + + if (reportTocItem) { + MyMoneyReport& report = reportTocItem->getReport(); + if (! report.id().isEmpty()) { + contextmenu->addAction(i18n("&Delete"), + this, SLOT(slotDeleteFromList())); + } } contextmenu->popup(d->m_tocTreeWidget->mapToGlobal(p)); @@ -598,18 +594,14 @@ void KReportsView::slotOpenFromList() { Q_D(KReportsView); - TocItem* tocItem = dynamic_cast(d->m_tocTreeWidget->currentItem()); - - if (tocItem) + if (auto tocItem = dynamic_cast(d->m_tocTreeWidget->currentItem())) slotItemDoubleClicked(tocItem, 0); } void KReportsView::slotConfigureFromList() { Q_D(KReportsView); - TocItem* tocItem = dynamic_cast(d->m_tocTreeWidget->currentItem()); - - if (tocItem) { + if (auto tocItem = dynamic_cast(d->m_tocTreeWidget->currentItem())) { slotItemDoubleClicked(tocItem, 0); slotConfigure(); } @@ -618,9 +610,7 @@ void KReportsView::slotNewFromList() { Q_D(KReportsView); - TocItem* tocItem = dynamic_cast(d->m_tocTreeWidget->currentItem()); - - if (tocItem) { + if (auto tocItem = dynamic_cast(d->m_tocTreeWidget->currentItem())) { slotItemDoubleClicked(tocItem, 0); slotDuplicate(); } @@ -629,27 +619,25 @@ void KReportsView::slotDeleteFromList() { Q_D(KReportsView); - TocItem* tocItem = dynamic_cast(d->m_tocTreeWidget->currentItem()); - - if (tocItem) { - TocItemReport* reportTocItem = dynamic_cast(tocItem); - - MyMoneyReport& report = reportTocItem->getReport(); - - // If this report does not have an ID, it's a default report and cannot be deleted - if (! report.id().isEmpty() && - KMessageBox::Continue == d->deleteReportDialog(report.name())) { - // check if report's tab is open; start from 1 because 0 is toc tab - for (int i = 1; i < d->m_reportTabWidget->count(); ++i) { - KReportTab* tab = dynamic_cast(d->m_reportTabWidget->widget(i)); - if (tab->report().id() == report.id()) { - slotClose(i); // if open, close it, so no crash when switching to it - break; + if (auto tocItem = dynamic_cast(d->m_tocTreeWidget->currentItem())) { + if (auto reportTocItem = dynamic_cast(tocItem)) { + MyMoneyReport& report = reportTocItem->getReport(); + + // If this report does not have an ID, it's a default report and cannot be deleted + if (! report.id().isEmpty() && + KMessageBox::Continue == d->deleteReportDialog(report.name())) { + // check if report's tab is open; start from 1 because 0 is toc tab + for (int i = 1; i < d->m_reportTabWidget->count(); ++i) { + auto tab = dynamic_cast(d->m_reportTabWidget->widget(i)); + if (tab && tab->report().id() == report.id()) { + slotClose(i); // if open, close it, so no crash when switching to it + break; + } } + MyMoneyFileTransaction ft; + MyMoneyFile::instance()->removeReport(report); + ft.commit(); } - MyMoneyFileTransaction ft; - MyMoneyFile::instance()->removeReport(report); - ft.commit(); } } } diff --git a/kmymoney/views/kreportsview_p.h b/kmymoney/views/kreportsview_p.h --- a/kmymoney/views/kreportsview_p.h +++ b/kmymoney/views/kreportsview_p.h @@ -199,11 +199,14 @@ m_chartView(new KReportChartView(this)), m_control(new ReportControl(this)), m_layout(new QVBoxLayout(this)), + m_currentPrinter(nullptr), m_report(report), m_deleteMe(false), m_chartEnabled(false), m_showingChart(report.isChartByDefault()), m_needReload(true), + m_isChartViewValid(false), + m_isTableViewValid(false), m_table(0) { m_layout->setSpacing(6); @@ -443,7 +446,12 @@ explicit KReportsViewPrivate(KReportsView *qq): q_ptr(qq), m_needLoad(true), - m_reportListView(0) + m_reportListView(nullptr), + m_reportTabWidget(nullptr), + m_listTab(nullptr), + m_listTabLayout(nullptr), + m_tocTreeWidget(nullptr), + m_columnsAlreadyAdjusted(false) { } @@ -719,12 +727,13 @@ int index = 1; while (index < m_reportTabWidget->count()) { // TODO: Find some way of detecting the file is closed and kill these tabs!! - KReportTab* tab = dynamic_cast(m_reportTabWidget->widget(index)); - if (tab->isReadyToDelete() /* || ! reports.count() */) { - delete tab; - --index; - } else { - tab->loadTab(); + if (auto tab = dynamic_cast(m_reportTabWidget->widget(index))) { + if (tab->isReadyToDelete() /* || ! reports.count() */) { + delete tab; + --index; + } else { + tab->loadTab(); + } } ++index; } diff --git a/kmymoney/views/kscheduledview.cpp b/kmymoney/views/kscheduledview.cpp --- a/kmymoney/views/kscheduledview.cpp +++ b/kmymoney/views/kscheduledview.cpp @@ -264,7 +264,7 @@ QStringList accountList = file->asset().accountList(); accountList.append(file->liability().accountList()); file->accountList(list, accountList, true); - qStableSort(list.begin(), list.end(), d->accountNameLessThan); + qStableSort(list.begin(), list.end(), KScheduledViewPrivate::accountNameLessThan); QList::ConstIterator it_a; for (it_a = list.constBegin(); it_a != list.constEnd(); ++it_a) { diff --git a/kmymoney/views/kscheduledview_p.h b/kmymoney/views/kscheduledview_p.h --- a/kmymoney/views/kscheduledview_p.h +++ b/kmymoney/views/kscheduledview_p.h @@ -86,6 +86,7 @@ KMyMoneyViewBasePrivate(), q_ptr(qq), ui(new Ui::KScheduledView), + m_kaccPopup(nullptr), m_openBills(true), m_openDeposits(true), m_openTransfers(true), @@ -664,7 +665,6 @@ bool m_openDeposits; bool m_openTransfers; bool m_openLoans; - bool m_needsRefresh; /** * This member holds the load state of page diff --git a/kmymoney/views/ktagsview_p.h b/kmymoney/views/ktagsview_p.h --- a/kmymoney/views/ktagsview_p.h +++ b/kmymoney/views/ktagsview_p.h @@ -95,6 +95,7 @@ q_ptr(qq), ui(new Ui::KTagsView), m_needLoad(true), + m_searchWidget(nullptr), m_inSelection(false), m_allowEditing(true), m_tagFilterType(0) diff --git a/kmymoney/widgets/amountedit.cpp b/kmymoney/widgets/amountedit.cpp --- a/kmymoney/widgets/amountedit.cpp +++ b/kmymoney/widgets/amountedit.cpp @@ -54,6 +54,10 @@ public: explicit AmountEditPrivate(AmountEdit* qq) : q_ptr(qq), + m_calculatorFrame(nullptr), + m_calculator(nullptr), + m_calculatorButton(nullptr), + m_prec(2), m_allowEmpty(false) { Q_Q(AmountEdit); diff --git a/kmymoney/widgets/budgetviewproxymodel.cpp b/kmymoney/widgets/budgetviewproxymodel.cpp --- a/kmymoney/widgets/budgetviewproxymodel.cpp +++ b/kmymoney/widgets/budgetviewproxymodel.cpp @@ -74,6 +74,7 @@ default: break; } + break; } case (int)Role::Balance: if (file->security(account.currencyId()) != file->baseCurrency()) diff --git a/kmymoney/widgets/groupmarker.cpp b/kmymoney/widgets/groupmarker.cpp --- a/kmymoney/widgets/groupmarker.cpp +++ b/kmymoney/widgets/groupmarker.cpp @@ -140,7 +140,7 @@ cellRect.setHeight(d->GroupMarkerPrivate::m_bg->height()); // now it's time to draw the background - painter->drawPixmap(cellRect, *d->GroupMarkerPrivate::m_bg); + painter->drawPixmap(cellRect, *KMyMoneyRegister::GroupMarkerPrivate::m_bg); // in case we need to show the date, we just paint it in col 1 if (d->m_showDate) { diff --git a/kmymoney/widgets/kbudgetvalues.cpp b/kmymoney/widgets/kbudgetvalues.cpp --- a/kmymoney/widgets/kbudgetvalues.cpp +++ b/kmymoney/widgets/kbudgetvalues.cpp @@ -53,8 +53,13 @@ public: KBudgetValuesPrivate() : - ui(new Ui::KBudgetValues) + ui(new Ui::KBudgetValues), + m_currentTab(nullptr) { + for (int i = 0; i < 12; ++i) { + m_label[i] = nullptr; + m_field[i] = nullptr; + } } ~KBudgetValuesPrivate() @@ -161,9 +166,9 @@ if (o->isWidgetType() && (e->type() == QEvent::KeyPress)) { - QKeyEvent* k = dynamic_cast(e); - if ((k->modifiers() & Qt::KeyboardModifierMask) == 0 - || (k->modifiers() & Qt::KeypadModifier) != 0) { + auto k = dynamic_cast(e); + if ((k && k->modifiers() & Qt::KeyboardModifierMask) == 0 + || (k && k->modifiers() & Qt::KeypadModifier) != 0) { QKeyEvent evt(e->type(), Qt::Key_Tab, k->modifiers(), QString(), k->isAutoRepeat(), k->count()); diff --git a/kmymoney/widgets/kmymoneyaccounttreeview.cpp b/kmymoney/widgets/kmymoneyaccounttreeview.cpp --- a/kmymoney/widgets/kmymoneyaccounttreeview.cpp +++ b/kmymoney/widgets/kmymoneyaccounttreeview.cpp @@ -55,6 +55,7 @@ public: explicit KMyMoneyAccountTreeViewPrivate(KMyMoneyAccountTreeView *qq) : q_ptr(qq), + m_model(nullptr), m_view(View::None) { } diff --git a/kmymoney/widgets/kmymoneycalculator.cpp b/kmymoney/widgets/kmymoneycalculator.cpp --- a/kmymoney/widgets/kmymoneycalculator.cpp +++ b/kmymoney/widgets/kmymoneycalculator.cpp @@ -46,7 +46,13 @@ Q_DISABLE_COPY(KMyMoneyCalculatorPrivate) public: - KMyMoneyCalculatorPrivate() + KMyMoneyCalculatorPrivate() : + op0(0.0), + op1(0.0), + op(0), + stackedOp(0), + display(nullptr), + m_clearOperandOnDigit(false) { } diff --git a/kmymoney/widgets/kmymoneycombo.cpp b/kmymoney/widgets/kmymoneycombo.cpp --- a/kmymoney/widgets/kmymoneycombo.cpp +++ b/kmymoney/widgets/kmymoneycombo.cpp @@ -56,7 +56,7 @@ { Q_D(KMyMoneyCombo); if (rw) { - d->m_edit = new KMyMoneyLineEdit(this, "combo edit"); + d->m_edit = new KMyMoneyLineEdit(this, true); setLineEdit(d->m_edit); } } @@ -67,7 +67,7 @@ { Q_D(KMyMoneyCombo); if (rw) { - d->m_edit = new KMyMoneyLineEdit(this, "combo edit"); + d->m_edit = new KMyMoneyLineEdit(this, true); setLineEdit(d->m_edit); } } @@ -118,7 +118,7 @@ // make sure we use our own line edit style if (y) { - d->m_edit = new KMyMoneyLineEdit(this, "combo edit"); + d->m_edit = new KMyMoneyLineEdit(this, true); setLineEdit(d->m_edit); d->m_edit->setPalette(palette()); } else { diff --git a/kmymoney/widgets/kmymoneycompletion_p.h b/kmymoney/widgets/kmymoneycompletion_p.h --- a/kmymoney/widgets/kmymoneycompletion_p.h +++ b/kmymoney/widgets/kmymoneycompletion_p.h @@ -44,7 +44,11 @@ Q_DISABLE_COPY(KMyMoneyCompletionPrivate) public: - KMyMoneyCompletionPrivate() + KMyMoneyCompletionPrivate() : + m_parent(nullptr), + m_widget(nullptr), + m_lv(nullptr), + m_selector(nullptr) { } diff --git a/kmymoney/widgets/kmymoneyedit.cpp b/kmymoney/widgets/kmymoneyedit.cpp --- a/kmymoney/widgets/kmymoneyedit.cpp +++ b/kmymoney/widgets/kmymoneyedit.cpp @@ -90,7 +90,14 @@ public: explicit KMyMoneyEditPrivate(KMyMoneyEdit *qq) : - q_ptr(qq) + q_ptr(qq), + m_calculator(nullptr), + m_calculatorFrame(nullptr), + m_edit(nullptr), + m_calcButton(nullptr), + m_resetButton(nullptr), + m_prec(2), + allowEmpty(true) { } diff --git a/kmymoney/widgets/kmymoneytextedithighlighter.h b/kmymoney/widgets/kmymoneytextedithighlighter.h --- a/kmymoney/widgets/kmymoneytextedithighlighter.h +++ b/kmymoney/widgets/kmymoneytextedithighlighter.h @@ -42,10 +42,6 @@ private: KMyMoneyTextEditHighlighterPrivate * const d_ptr; Q_DECLARE_PRIVATE(KMyMoneyTextEditHighlighter) - QString m_allowedChars; - int m_maxLines; - int m_maxLineLength; - int m_maxLength; }; #endif // KMYMONEYTEXTEDIT_H diff --git a/kmymoney/widgets/kmymoneytextedithighlighter.cpp b/kmymoney/widgets/kmymoneytextedithighlighter.cpp --- a/kmymoney/widgets/kmymoneytextedithighlighter.cpp +++ b/kmymoney/widgets/kmymoneytextedithighlighter.cpp @@ -55,30 +55,35 @@ void KMyMoneyTextEditHighlighter::setAllowedChars(const QString& chars) { - m_allowedChars = chars; + Q_D(KMyMoneyTextEditHighlighter); + d->m_allowedChars = chars; rehighlight(); } void KMyMoneyTextEditHighlighter::setMaxLength(const int& length) { - m_maxLength = length; + Q_D(KMyMoneyTextEditHighlighter); + d->m_maxLength = length; rehighlight(); } void KMyMoneyTextEditHighlighter::setMaxLines(const int& lines) { - m_maxLines = lines; + Q_D(KMyMoneyTextEditHighlighter); + d->m_maxLines = lines; rehighlight(); } void KMyMoneyTextEditHighlighter::setMaxLineLength(const int& length) { - m_maxLineLength = length; + Q_D(KMyMoneyTextEditHighlighter); + d->m_maxLineLength = length; rehighlight(); } void KMyMoneyTextEditHighlighter::highlightBlock(const QString& text) { + Q_D(KMyMoneyTextEditHighlighter); // Spell checker first Highlighter::highlightBlock(text); @@ -90,29 +95,29 @@ // Check used characters const int length = text.length(); for (auto i = 0; i < length; ++i) { - if (!m_allowedChars.contains(text.at(i))) { + if (!d->m_allowedChars.contains(text.at(i))) { setFormat(i, 1, invalidFormat); } } - if (m_maxLines != -1) { + if (d->m_maxLines != -1) { //! @todo Is using QTextBlock::blockNumber() as line number dangerous? - if (currentBlock().blockNumber() >= m_maxLines) { + if (currentBlock().blockNumber() >= d->m_maxLines) { setFormat(0, length, invalidFormat); return; } } - if (m_maxLength != -1) { + if (d->m_maxLength != -1) { const int blockPosition = currentBlock().position(); - if (m_maxLength < (length + blockPosition)) { - setFormat(m_maxLength, length - m_maxLength - blockPosition, invalidFormat); + if (d->m_maxLength < (length + blockPosition)) { + setFormat(d->m_maxLength, length - d->m_maxLength - blockPosition, invalidFormat); return; } } - if (m_maxLineLength != -1 && length >= m_maxLineLength) { - setFormat(m_maxLineLength, length - m_maxLineLength, invalidFormat); + if (d->m_maxLineLength != -1 && length >= d->m_maxLineLength) { + setFormat(d->m_maxLineLength, length - d->m_maxLineLength, invalidFormat); return; } } diff --git a/kmymoney/widgets/kmymoneyvalidationfeedback.cpp b/kmymoney/widgets/kmymoneyvalidationfeedback.cpp --- a/kmymoney/widgets/kmymoneyvalidationfeedback.cpp +++ b/kmymoney/widgets/kmymoneyvalidationfeedback.cpp @@ -33,7 +33,8 @@ public: KMyMoneyValidationFeedbackPrivate() : - ui(new Ui::KMyMoneyValidationFeedback) + ui(new Ui::KMyMoneyValidationFeedback), + type(ValidationFeedback::MessageType::None) { } diff --git a/kmymoney/widgets/ktagcontainer.cpp b/kmymoney/widgets/ktagcontainer.cpp --- a/kmymoney/widgets/ktagcontainer.cpp +++ b/kmymoney/widgets/ktagcontainer.cpp @@ -39,7 +39,8 @@ Q_DISABLE_COPY(KTagContainerPrivate) public: - KTagContainerPrivate() + KTagContainerPrivate() : + m_tagCombo(nullptr) { } diff --git a/kmymoney/widgets/register.cpp b/kmymoney/widgets/register.cpp --- a/kmymoney/widgets/register.cpp +++ b/kmymoney/widgets/register.cpp @@ -71,12 +71,13 @@ { public: RegisterPrivate() : - m_selectAnchor(0), - m_focusItem(0), - m_firstItem(0), - m_lastItem(0), - m_firstErroneous(0), - m_lastErroneous(0), + m_selectAnchor(nullptr), + m_focusItem(nullptr), + m_ensureVisibleItem(nullptr), + m_firstItem(nullptr), + m_lastItem(nullptr), + m_firstErroneous(nullptr), + m_lastErroneous(nullptr), m_rowHeightHint(0), m_ledgerLensForced(false), m_selectionMode(QTableWidget::MultiSelection), @@ -87,6 +88,7 @@ m_usedWithEditor(false), m_mouseButton(Qt::MouseButtons(Qt::NoButton)), m_modifiers(Qt::KeyboardModifiers(Qt::NoModifier)), + m_lastCol(eTransaction::Column::Account), m_detailsColumnType(eRegister::DetailColumn::PayeeFirst) { } @@ -191,8 +193,8 @@ bool Register::eventFilter(QObject* o, QEvent* e) { if (o == this && e->type() == QEvent::KeyPress) { - QKeyEvent* ke = dynamic_cast(e); - if (ke->key() == Qt::Key_Menu) { + auto ke = dynamic_cast(e); + if (ke && ke->key() == Qt::Key_Menu) { emit openContextMenu(); return true; } @@ -392,7 +394,7 @@ item = d->m_lastItem; bool showBalance = true; while (item) { - Transaction* t = dynamic_cast(item); + auto t = dynamic_cast(item); if (t) { t->setShowBalance(showBalance); if (!t->isVisible()) { @@ -591,13 +593,13 @@ { bool lastWasGroupMarker = false; KMyMoneyRegister::RegisterItem* p = lastItem(); - KMyMoneyRegister::Transaction* t = dynamic_cast(p); + auto t = dynamic_cast(p); if (t && t->transaction().id().isEmpty()) { lastWasGroupMarker = true; p = p->prevItem(); } while (p) { - KMyMoneyRegister::GroupMarker* m = dynamic_cast(p); + auto m = dynamic_cast(p); if (m) { // make adjacent group marker invisible except those that show statement information if (lastWasGroupMarker && (dynamic_cast(m) == 0)) { @@ -907,7 +909,7 @@ RegisterItem* const item = d->m_items[i]; if (!item) continue; - Transaction* t = dynamic_cast(item); + auto t = dynamic_cast(item); if (t) { int nw = 0; try { @@ -1010,7 +1012,7 @@ { Q_D(const Register); if (d->m_focusItem && d->m_focusItem->isSelected() && d->m_focusItem->isVisible()) { - Transaction* t = dynamic_cast(d->m_focusItem); + auto t = dynamic_cast(d->m_focusItem); if (t) { QString id; if (t->isScheduled()) @@ -1026,7 +1028,7 @@ if (item == d->m_focusItem) continue; if (item && item->isSelected() && item->isVisible()) { - Transaction* t = dynamic_cast(item); + auto t = dynamic_cast(item); if (t) { QString id; if (t->isScheduled()) @@ -1130,7 +1132,7 @@ // selectItem() might have changed the pointers, so we // need to reconstruct it here item = itemById(id); - Transaction* t = dynamic_cast(item); + auto t = dynamic_cast(item); if (t) { if (!id.isEmpty()) { if (t && col == (int)eTransaction::Column::ReconcileFlag && selectedItemsCount() == 1 && !t->isScheduled()) @@ -1155,7 +1157,7 @@ if (d->m_focusItem) { d->m_focusItem->setFocus(false); } - Transaction* item = dynamic_cast(focusItem); + auto item = dynamic_cast(focusItem); if (d->m_focusItem != focusItem && item) { emit focusChanged(item); } @@ -1380,16 +1382,17 @@ } // now delete the widgets - KMyMoneyRegister::Transaction* t = dynamic_cast(focusItem()); - for (int row = t->startRow(); row < t->startRow() + t->numRowsRegister(true); ++row) { - for (int col = 0; col < columnCount(); ++col) { - if (cellWidget(row, col)) { - cellWidget(row, col)->hide(); - setCellWidget(row, col, 0); + if (auto t = dynamic_cast(focusItem())) { + for (int row = t->startRow(); row < t->startRow() + t->numRowsRegister(true); ++row) { + for (int col = 0; col < columnCount(); ++col) { + if (cellWidget(row, col)) { + cellWidget(row, col)->hide(); + setCellWidget(row, col, 0); + } } + // make sure to reduce the possibly size to what it was before editing started + setRowHeight(row, t->rowHeightHint()); } - // make sure to reduce the possibly size to what it was before editing started - setRowHeight(row, t->rowHeightHint()); } } @@ -1552,7 +1555,7 @@ } // make sure to avoid selecting a possible empty transaction at the end - Transaction* t = dynamic_cast(item); + auto t = dynamic_cast(item); if (t && t->transaction().id().isEmpty()) { if (t->prevItem()) { item = t->prevItem(); @@ -1759,10 +1762,8 @@ case SortField::Payee: if (KMyMoneySettings::showFancyMarker()) { while (p) { - t = dynamic_cast(p); - if (t) { + if ((t = dynamic_cast(p))) list[t->sortPayee()] = 1; - } p = p->nextItem(); } for (it = list.constBegin(); it != list.constEnd(); ++it) { @@ -1778,10 +1779,8 @@ case SortField::Category: if (KMyMoneySettings::showFancyMarker()) { while (p) { - t = dynamic_cast(p); - if (t) { + if ((t = dynamic_cast(p))) list[t->sortCategory()] = 1; - } p = p->nextItem(); } for (it = list.constBegin(); it != list.constEnd(); ++it) { @@ -1797,10 +1796,8 @@ case SortField::Security: if (KMyMoneySettings::showFancyMarker()) { while (p) { - t = dynamic_cast(p); - if (t) { + if ((t = dynamic_cast(p))) list[t->sortSecurity()] = 1; - } p = p->nextItem(); } for (it = list.constBegin(); it != list.constEnd(); ++it) { @@ -1838,7 +1835,7 @@ p = lastItem(); while (p) { q = p; - KMyMoneyRegister::GroupMarker* m = dynamic_cast(p); + auto m = dynamic_cast(p); p = p->prevItem(); if (m) { m->markVisible(true); diff --git a/kmymoney/widgets/registeritem.cpp b/kmymoney/widgets/registeritem.cpp --- a/kmymoney/widgets/registeritem.cpp +++ b/kmymoney/widgets/registeritem.cpp @@ -89,38 +89,32 @@ QDate RegisterItem::sortPostDate() const { - Q_D(const RegisterItem); - return d->nullDate; + return KMyMoneyRegister::RegisterItemPrivate::nullDate; } QDate RegisterItem::sortEntryDate() const { - Q_D(const RegisterItem); - return d->nullDate; + return KMyMoneyRegister::RegisterItemPrivate::nullDate; } const QString& RegisterItem::sortPayee() const { - Q_D(const RegisterItem); - return d->nullString; + return KMyMoneyRegister::RegisterItemPrivate::nullString; } MyMoneyMoney RegisterItem::sortValue() const { - Q_D(const RegisterItem); - return d->nullValue; + return KMyMoneyRegister::RegisterItemPrivate::nullValue; } QString RegisterItem::sortNumber() const { - Q_D(const RegisterItem); - return d->nullString; + return KMyMoneyRegister::RegisterItemPrivate::nullString; } const QString& RegisterItem::sortEntryOrder() const { - Q_D(const RegisterItem); - return d->nullString; + return KMyMoneyRegister::RegisterItemPrivate::nullString; } eWidgets::eRegister::CashFlowDirection RegisterItem::sortType() const @@ -130,8 +124,7 @@ const QString& RegisterItem::sortCategory() const { - Q_D(const RegisterItem); - return d->nullString; + return KMyMoneyRegister::RegisterItemPrivate::nullString; } eMyMoney::Split::State RegisterItem::sortReconcileState() const @@ -141,8 +134,7 @@ const QString RegisterItem::sortSecurity() const { - Q_D(const RegisterItem); - return d->nullString; + return KMyMoneyRegister::RegisterItemPrivate::nullString; } void RegisterItem::setStartRow(int row) diff --git a/kmymoney/widgets/transaction.h b/kmymoney/widgets/transaction.h --- a/kmymoney/widgets/transaction.h +++ b/kmymoney/widgets/transaction.h @@ -203,7 +203,6 @@ virtual void setupPalette(const QPalette& palette, QMap& editWidgets); - TransactionPrivate *d_ptr; Transaction(TransactionPrivate &dd, Register* parent, const MyMoneyTransaction& transaction, const MyMoneySplit& split, int uniqueId); Transaction(TransactionPrivate &dd); //for copy-constructor of derived class diff --git a/kmymoney/widgets/transaction.cpp b/kmymoney/widgets/transaction.cpp --- a/kmymoney/widgets/transaction.cpp +++ b/kmymoney/widgets/transaction.cpp @@ -157,8 +157,7 @@ } Transaction::Transaction(TransactionPrivate &dd, Register* parent, const MyMoneyTransaction& transaction, const MyMoneySplit& split, int uniqueId) : - RegisterItem(dd, parent), - d_ptr(&dd) + RegisterItem(dd, parent) { Q_D(Transaction); d->m_form = nullptr; @@ -731,8 +730,8 @@ d->m_inEdit = true; // hide the original tabbar since the edit tabbar will be added - KMyMoneyTransactionForm::TransactionForm* form = dynamic_cast(d->m_form); - form->getTabBar()->setVisible(false); + if (auto form = dynamic_cast(d->m_form)) + form->getTabBar()->setVisible(false); // only update the number of lines displayed if we edit inside the register if (d->m_inRegisterEdit) @@ -748,8 +747,8 @@ { Q_D(Transaction); // show the original tabbar since the edit tabbar was removed - KMyMoneyTransactionForm::TransactionForm* form = dynamic_cast(d->m_form); - form->getTabBar()->setVisible(true); + if (auto form = dynamic_cast(d->m_form)) + form->getTabBar()->setVisible(true); // make sure we reset the row height of all the transaction's rows because it could have been changed during edit if (d->m_parent) { @@ -907,8 +906,7 @@ // about it so that they don't show the balance p = prevItem(); while (p) { - t = dynamic_cast(p); - if (t) { + if ((t = dynamic_cast(p))) { if (!t->d_func()->m_showBalance) break; t->d_func()->m_showBalance = false; @@ -929,8 +927,7 @@ d->m_showBalance = true; p = prevItem(); while (p && p->isVisible()) { - t = dynamic_cast(p); - if (t) { + if ((t = dynamic_cast(p))) { if (t->d_func()->m_showBalance) break; t->d_func()->m_showBalance = true; diff --git a/kmymoney/widgets/transaction_p.h b/kmymoney/widgets/transaction_p.h --- a/kmymoney/widgets/transaction_p.h +++ b/kmymoney/widgets/transaction_p.h @@ -48,7 +48,16 @@ class TransactionPrivate : public RegisterItemPrivate { public: - TransactionPrivate() + TransactionPrivate() : + m_form(nullptr), + m_formRowHeight(-1), + m_selected(false), + m_focus(false), + m_erroneous(false), + m_inEdit(false), + m_inRegisterEdit(false), + m_showBalance(true), + m_reducedIntensity(false) { } @@ -58,15 +67,6 @@ void init(int uniqueId) { - m_formRowHeight = -1; - m_selected = false; - m_focus = false; - m_erroneous = false; - m_inEdit = false; - m_inRegisterEdit = false; - m_showBalance = true; - m_reducedIntensity = false; - auto file = MyMoneyFile::instance(); // load the account diff --git a/kmymoney/wizards/kmymoneywizard_p.h b/kmymoney/wizards/kmymoneywizard_p.h --- a/kmymoney/wizards/kmymoneywizard_p.h +++ b/kmymoney/wizards/kmymoneywizard_p.h @@ -57,7 +57,19 @@ public: explicit KMyMoneyWizardPrivate(KMyMoneyWizard *qq) : q_ptr(qq), - m_step(0) + m_cancelButton(nullptr), + m_backButton(nullptr), + m_nextButton(nullptr), + m_finishButton(nullptr), + m_helpButton(nullptr), + m_wizardLayout(nullptr), + m_stepLayout(nullptr), + m_pageLayout(nullptr), + m_buttonLayout(nullptr), + m_stepFrame(nullptr), + m_stepLabel(nullptr), + m_step(0), + m_titleLabel(nullptr) { } diff --git a/kmymoney/wizards/kmymoneywizardpage_p.h b/kmymoney/wizards/kmymoneywizardpage_p.h --- a/kmymoney/wizards/kmymoneywizardpage_p.h +++ b/kmymoney/wizards/kmymoneywizardpage_p.h @@ -47,7 +47,9 @@ public: explicit KMyMoneyWizardPagePrivate(QObject* parent) : - QObject(parent) + QObject(parent), + m_widget(nullptr), + m_mandatoryGroup(nullptr) { } diff --git a/kmymoney/wizards/newaccountwizard/kaccounttypepage_p.h b/kmymoney/wizards/newaccountwizard/kaccounttypepage_p.h --- a/kmymoney/wizards/newaccountwizard/kaccounttypepage_p.h +++ b/kmymoney/wizards/newaccountwizard/kaccounttypepage_p.h @@ -43,7 +43,8 @@ public: explicit AccountTypePagePrivate(QObject* parent) : WizardPagePrivate(parent), - ui(new Ui::KAccountTypePage) + ui(new Ui::KAccountTypePage), + m_showPriceWarning(false) { } diff --git a/kmymoney/wizards/newaccountwizard/kgeneralloaninfopage_p.h b/kmymoney/wizards/newaccountwizard/kgeneralloaninfopage_p.h --- a/kmymoney/wizards/newaccountwizard/kgeneralloaninfopage_p.h +++ b/kmymoney/wizards/newaccountwizard/kgeneralloaninfopage_p.h @@ -43,7 +43,8 @@ public: explicit GeneralLoanInfoPagePrivate(QObject* parent) : WizardPagePrivate(parent), - ui(new Ui::KGeneralLoanInfoPage) + ui(new Ui::KGeneralLoanInfoPage), + m_firstTime(false) { } diff --git a/kmymoney/wizards/newaccountwizard/khierarchypage_p.h b/kmymoney/wizards/newaccountwizard/khierarchypage_p.h --- a/kmymoney/wizards/newaccountwizard/khierarchypage_p.h +++ b/kmymoney/wizards/newaccountwizard/khierarchypage_p.h @@ -45,7 +45,8 @@ public: explicit HierarchyPagePrivate(QObject* parent) : WizardPagePrivate(parent), - ui(new Ui::KHierarchyPage) + ui(new Ui::KHierarchyPage), + m_filterProxyModel(nullptr) { } diff --git a/kmymoney/wizards/newaccountwizard/kloandetailspage_p.h b/kmymoney/wizards/newaccountwizard/kloandetailspage_p.h --- a/kmymoney/wizards/newaccountwizard/kloandetailspage_p.h +++ b/kmymoney/wizards/newaccountwizard/kloandetailspage_p.h @@ -43,7 +43,8 @@ public: explicit LoanDetailsPagePrivate(QObject* parent) : WizardPagePrivate(parent), - ui(new Ui::KLoanDetailsPage) + ui(new Ui::KLoanDetailsPage), + m_needCalculate(false) { } diff --git a/kmymoney/wizards/newaccountwizard/knewaccountwizard_p.h b/kmymoney/wizards/newaccountwizard/knewaccountwizard_p.h --- a/kmymoney/wizards/newaccountwizard/knewaccountwizard_p.h +++ b/kmymoney/wizards/newaccountwizard/knewaccountwizard_p.h @@ -55,7 +55,18 @@ public: explicit WizardPrivate(Wizard *qq): - KMyMoneyWizardPrivate(qq) + KMyMoneyWizardPrivate(qq), + m_institutionPage(nullptr), + m_accountTypePage(nullptr), + m_brokeragepage(nullptr), + m_schedulePage(nullptr), + m_generalLoanInfoPage(nullptr), + m_loanDetailsPage(nullptr), + m_loanPaymentPage(nullptr), + m_loanSchedulePage(nullptr), + m_loanPayoutPage(nullptr), + m_hierarchyPage(nullptr), + m_accountSummaryPage(nullptr) { } diff --git a/kmymoney/wizards/newinvestmentwizard/knewinvestmentwizard.cpp b/kmymoney/wizards/newinvestmentwizard/knewinvestmentwizard.cpp --- a/kmymoney/wizards/newinvestmentwizard/knewinvestmentwizard.cpp +++ b/kmymoney/wizards/newinvestmentwizard/knewinvestmentwizard.cpp @@ -51,7 +51,8 @@ public: explicit KNewInvestmentWizardPrivate(KNewInvestmentWizard *qq) : q_ptr(qq), - ui(new Ui::KNewInvestmentWizard) + ui(new Ui::KNewInvestmentWizard), + m_createAccount(false) { } @@ -59,7 +60,7 @@ { delete ui; } - + void init1() { Q_Q(KNewInvestmentWizard); @@ -67,13 +68,13 @@ // make sure, the back button does not clear fields q->setOption(QWizard::IndependentPages, true); - + // enable the help button q->setOption(q->HaveHelpButton, true); q->connect(q, &KNewInvestmentWizard::helpRequested, q, &KNewInvestmentWizard::slotHelp); - + m_createAccount = true; - + // Update label in case of edit if (!m_account.id().isEmpty()) { ui->m_investmentTypePage->setIntroLabelText(i18n("This wizard allows you to modify the selected investment.")); @@ -81,10 +82,10 @@ if (!m_security.id().isEmpty()) { ui->m_investmentTypePage->setIntroLabelText(i18n("This wizard allows you to modify the selected security.")); } - + KMyMoneyUtils::updateWizardButtons(q); } - + void init2() { ui->m_investmentTypePage->init2(m_security); @@ -92,10 +93,10 @@ ui->m_onlineUpdatePage->init2(m_security); ui->m_onlineUpdatePage->slotCheckPage(m_security.value("kmm-online-source")); } - + KNewInvestmentWizard *q_ptr; Ui::KNewInvestmentWizard *ui; - + MyMoneyAccount m_account; MyMoneySecurity m_security; bool m_createAccount; diff --git a/kmymoney/wizards/newloanwizard/keditloanwizard.cpp b/kmymoney/wizards/newloanwizard/keditloanwizard.cpp --- a/kmymoney/wizards/newloanwizard/keditloanwizard.cpp +++ b/kmymoney/wizards/newloanwizard/keditloanwizard.cpp @@ -69,7 +69,9 @@ public: KEditLoanWizardPrivate(KEditLoanWizard *qq) : - KNewLoanWizardPrivate(qq) + KNewLoanWizardPrivate(qq), + m_lastSelection(0), + m_fullyRepayLoan(false) { } diff --git a/kmymoney/wizards/newuserwizard/kgeneralpage.cpp b/kmymoney/wizards/newuserwizard/kgeneralpage.cpp --- a/kmymoney/wizards/newuserwizard/kgeneralpage.cpp +++ b/kmymoney/wizards/newuserwizard/kgeneralpage.cpp @@ -52,7 +52,8 @@ public: GeneralPagePrivate(QObject* parent) : - WizardPagePrivate(parent) + WizardPagePrivate(parent), + m_contact(nullptr) { } diff --git a/kmymoney/wizards/newuserwizard/knewuserwizard_p.h b/kmymoney/wizards/newuserwizard/knewuserwizard_p.h --- a/kmymoney/wizards/newuserwizard/knewuserwizard_p.h +++ b/kmymoney/wizards/newuserwizard/knewuserwizard_p.h @@ -45,7 +45,13 @@ public: explicit WizardPrivate(Wizard *qq): KMyMoneyWizardPrivate(qq), - m_introPage(nullptr) + m_introPage(nullptr), + m_generalPage(nullptr), + m_currencyPage(nullptr), + m_accountPage(nullptr), + m_categoriesPage(nullptr), + m_preferencePage(nullptr), + m_filePage(nullptr) { } diff --git a/kmymoney/wizards/wizardpage_p.h b/kmymoney/wizards/wizardpage_p.h --- a/kmymoney/wizards/wizardpage_p.h +++ b/kmymoney/wizards/wizardpage_p.h @@ -36,7 +36,9 @@ { public: WizardPagePrivate(QObject* parent) : - KMyMoneyWizardPagePrivate(parent) + KMyMoneyWizardPagePrivate(parent), + m_wizard(nullptr), + m_wizardBase(nullptr) { }