diff --git a/kmymoney/converter/mymoneystatementreader.cpp b/kmymoney/converter/mymoneystatementreader.cpp --- a/kmymoney/converter/mymoneystatementreader.cpp +++ b/kmymoney/converter/mymoneystatementreader.cpp @@ -697,20 +697,17 @@ // (2b) the name of the security matches the name of the security of the transaction. // search through each subordinate account - bool found = false; - QStringList accounts = thisaccount.accountList(); - QStringList::const_iterator it_account = accounts.constBegin(); + auto found = false; QString currencyid; - while (!found && it_account != accounts.constEnd()) { - currencyid = file->account(*it_account).currencyId(); - MyMoneySecurity security = file->security(currencyid); + foreach (const auto sAccount, thisaccount.accountList()) { + currencyid = file->account(sAccount).currencyId(); + auto security = file->security(currencyid); if (matchNotEmpty(statementTransactionUnderImport.m_strSymbol, security.tradingSymbol()) || matchNotEmpty(statementTransactionUnderImport.m_strSecurity, security.name())) { - thisaccount = file->account(*it_account); + thisaccount = file->account(sAccount); found = true; + break; } - - ++it_account; } // If there was no stock account under the m_acccount investment account, 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 @@ -439,13 +439,12 @@ // account are also selected if (!KMyMoneyGlobalSettings::expertMode()) { QStringList missing; - QStringList::const_iterator it_a, it_b; - for (it_a = list.constBegin(); it_a != list.constEnd(); ++it_a) { - MyMoneyAccount acc = MyMoneyFile::instance()->account(*it_a); + foreach (const auto selection, list) { + auto acc = MyMoneyFile::instance()->account(selection); if (acc.accountType() == eMyMoney::Account::Type::Investment) { - for (it_b = acc.accountList().constBegin(); it_b != acc.accountList().constEnd(); ++it_b) { - if (!list.contains(*it_b)) { - missing.append(*it_b); + foreach (const auto sAccount, acc.accountList()) { + if (!list.contains(sAccount)) { + missing.append(sAccount); } } } diff --git a/kmymoney/kmymoney.cpp b/kmymoney/kmymoney.cpp --- a/kmymoney/kmymoney.cpp +++ b/kmymoney/kmymoney.cpp @@ -3818,10 +3818,8 @@ return KMyMoneyUtils::AccountBalanceNonZero; // all children must be already closed - QStringList::const_iterator it_a; - for (it_a = acc.accountList().constBegin(); it_a != acc.accountList().constEnd(); ++it_a) { - MyMoneyAccount a = MyMoneyFile::instance()->account(*it_a); - if (!a.isClosed()) { + foreach (const auto sAccount, acc.accountList()) { + if (!MyMoneyFile::instance()->account(sAccount).isClosed()) { return KMyMoneyUtils::AccountChildrenOpen; } } @@ -5684,11 +5682,10 @@ // Now check the target investment account to see if it // contains a stock with this id QString newStockAccountId; - QStringList accountList = toInvAcc.accountList(); - for (QStringList::const_iterator it_a = accountList.constBegin(); it_a != accountList.constEnd(); ++it_a) { - if (MyMoneyFile::instance()->account((*it_a)).currencyId() == + foreach (const auto sAccount, toInvAcc.accountList()) { + if (MyMoneyFile::instance()->account(sAccount).currencyId() == stockSecurityId) { - newStockAccountId = (*it_a); + newStockAccountId = sAccount; break; } } diff --git a/kmymoney/models/accountsmodel.cpp b/kmymoney/models/accountsmodel.cpp --- a/kmymoney/models/accountsmodel.cpp +++ b/kmymoney/models/accountsmodel.cpp @@ -645,8 +645,7 @@ } // adding accounts (specific bank/investment accounts) belonging to given accounts category - const auto accountsStr = account.accountList(); - foreach (const auto accStr, accountsStr) { + foreach (const auto accStr, account.accountList()) { const auto acc = d->m_file->account(accStr); auto item = new QStandardItem(acc.name()); @@ -1153,9 +1152,10 @@ // load the investment sub-accounts if there are any - there could be sub-accounts if this is an add operation // that was triggered in slotObjectModified on an already existing account which went trough a hierarchy change - if (!account->accountList().isEmpty()) { + const auto sAccounts = account->accountList(); + if (!sAccounts.isEmpty()) { QList subAccounts; - d->m_file->accountList(subAccounts, account->accountList()); + d->m_file->accountList(subAccounts, sAccounts); foreach (const auto subAccount, subAccounts) { if (subAccount.isInvest()) { modelUtils->loadInstitution(this, subAccount); diff --git a/kmymoney/models/equitiesmodel.cpp b/kmymoney/models/equitiesmodel.cpp --- a/kmymoney/models/equitiesmodel.cpp +++ b/kmymoney/models/equitiesmodel.cpp @@ -56,8 +56,7 @@ itInvAcc->setColumnCount(m_columns.count()); setAccountData(node, itInvAcc->row(), invAcc, m_columns); - const auto strStkAccList = invAcc.accountList(); // only stock or bond accounts are expected here - foreach (const auto strStkAcc, strStkAccList) { + foreach (const auto strStkAcc, invAcc.accountList()) { // only stock or bond accounts are expected here auto stkAcc = m_file->account(strStkAcc); auto itStkAcc = new QStandardItem(strStkAcc); itStkAcc->setEditable(false); diff --git a/kmymoney/mymoney/mymoneyaccount.h b/kmymoney/mymoney/mymoneyaccount.h --- a/kmymoney/mymoney/mymoneyaccount.h +++ b/kmymoney/mymoney/mymoneyaccount.h @@ -284,7 +284,7 @@ * subordinate accounts * @return QStringList account ids */ - const QStringList& accountList() const; + QStringList accountList() const; /** * This method returns the number of entries in the m_accountList diff --git a/kmymoney/mymoney/mymoneyaccount.cpp b/kmymoney/mymoney/mymoneyaccount.cpp --- a/kmymoney/mymoney/mymoneyaccount.cpp +++ b/kmymoney/mymoney/mymoneyaccount.cpp @@ -278,7 +278,7 @@ d->m_parentAccount = parent; } -const QStringList& MyMoneyAccount::accountList() const +QStringList MyMoneyAccount::accountList() const { Q_D(const MyMoneyAccount); return d->m_accountList; diff --git a/kmymoney/mymoney/mymoneyfile.cpp b/kmymoney/mymoney/mymoneyfile.cpp --- a/kmymoney/mymoney/mymoneyfile.cpp +++ b/kmymoney/mymoney/mymoneyfile.cpp @@ -709,9 +709,8 @@ { static MyMoneyAccount nullAccount; - QList::const_iterator it_a; - for (it_a = acc.accountList().constBegin(); it_a != acc.accountList().constEnd(); ++it_a) { - const auto sacc = account(*it_a); + foreach (const auto sAccount, acc.accountList()) { + const auto sacc = account(sAccount); if (sacc.name() == name) return sacc; } @@ -854,8 +853,8 @@ } // process all accounts in the list and test if they have transactions assigned - for (QStringList::ConstIterator it = account_list.constBegin(); it != account_list.constEnd(); ++it) { - MyMoneyAccount a = d->m_storage->account(*it); + foreach (const auto sAccount, account_list) { + auto a = d->m_storage->account(sAccount); //qDebug() << "Deleting account '"<< a.name() << "'"; // first remove all sub-accounts @@ -865,7 +864,7 @@ // then remove account itself, but we first have to get // rid of the account list that is still stored in // the MyMoneyAccount object. Easiest way is to get a fresh copy. - a = d->m_storage->account(*it); + a = d->m_storage->account(sAccount); } // make sure to remove the item from the cache @@ -879,10 +878,10 @@ if (level > 100) throw MYMONEYEXCEPTION("Too deep recursion in [MyMoneyFile::hasOnlyUnusedAccounts]!"); // process all accounts in the list and test if they have transactions assigned - for (QStringList::ConstIterator it = account_list.constBegin(); it != account_list.constEnd(); ++it) { - if (transactionCount(*it) != 0) + foreach (const auto sAccount, account_list) { + if (transactionCount(sAccount) != 0) return false; // the current account has a transaction assigned - if (!hasOnlyUnusedAccounts(account(*it).accountList(), level + 1)) + if (!hasOnlyUnusedAccounts(account(sAccount).accountList(), level + 1)) return false; // some sub-account has a transaction assigned } return true; // all subaccounts unused @@ -1824,11 +1823,8 @@ level = category.section(AccountSeperator, 0, 0); remainder = category.section(AccountSeperator, 1); - QStringList list = base.accountList(); - QStringList::ConstIterator it_a; - - for (it_a = list.constBegin(); it_a != list.constEnd(); ++it_a) { - nextBase = account(*it_a); + foreach (const auto sAccount, base.accountList()) { + nextBase = account(sAccount); if (nextBase.name() == level) { if (remainder.isEmpty()) { return nextBase.id(); @@ -3214,11 +3210,9 @@ bool MyMoneyFile::hasAccount(const QString& id, const QString& name) const { auto acc = d->m_cache.account(id); - QStringList list = acc.accountList(); - QStringList::ConstIterator it; - bool rc = false; - for (it = list.constBegin(); rc == false && it != list.constEnd(); ++it) { - MyMoneyAccount a = d->m_cache.account(*it); + auto rc = false; + foreach (const auto sAccount, acc.accountList()) { + auto a = d->m_cache.account(sAccount); if (a.name() == name) rc = true; } diff --git a/kmymoney/mymoney/storage/mymoneyseqaccessmgr.cpp b/kmymoney/mymoney/storage/mymoneyseqaccessmgr.cpp --- a/kmymoney/mymoney/storage/mymoneyseqaccessmgr.cpp +++ b/kmymoney/mymoney/storage/mymoneyseqaccessmgr.cpp @@ -651,10 +651,9 @@ if (!account.institutionId().isEmpty()) institution(account.institutionId()); - QList::ConstIterator it_a; - for (it_a = account.accountList().constBegin(); it_a != account.accountList().constEnd(); ++it_a) { - this->account(*it_a); - } + foreach (const auto sAccount, account.accountList()) + this->account(sAccount); + // update information in account list m_accountList.modify(account.id(), account); @@ -1084,16 +1083,10 @@ const MyMoneyMoney MyMoneySeqAccessMgr::totalBalance(const QString& id, const QDate& date) const { - QStringList accounts; - QStringList::ConstIterator it_a; - MyMoneyMoney result(balance(id, date)); - accounts = account(id).accountList(); - - for (it_a = accounts.constBegin(); it_a != accounts.constEnd(); ++it_a) { - result += totalBalance(*it_a, date); - } + foreach (const auto sAccount, account(id).accountList()) + result += totalBalance(sAccount, date); return result; } diff --git a/kmymoney/plugins/csvexport/csvexportdlg.cpp b/kmymoney/plugins/csvexport/csvexportdlg.cpp --- a/kmymoney/plugins/csvexport/csvexportdlg.cpp +++ b/kmymoney/plugins/csvexport/csvexportdlg.cpp @@ -166,10 +166,8 @@ MyMoneyAccount accnt; if (account.accountType() == eMyMoney::Account::Type::Investment) { // If this is Investment account, we need child account. - QStringList listAccounts = account.accountList(); - QStringList::Iterator itAccounts; - for (itAccounts = listAccounts.begin(); itAccounts != listAccounts.end(); ++itAccounts) { - accnt = file->account((*itAccounts)); + foreach (const auto sAccount, account.accountList()) { + accnt = file->account(sAccount); MyMoneyTransactionFilter filter(accnt.id()); listTrans = file->transactionList(filter); if (!listTrans.isEmpty()) { diff --git a/kmymoney/plugins/csvexport/csvwriter.cpp b/kmymoney/plugins/csvexport/csvwriter.cpp --- a/kmymoney/plugins/csvexport/csvwriter.cpp +++ b/kmymoney/plugins/csvexport/csvwriter.cpp @@ -169,13 +169,9 @@ s << (acc.accountGroup() == eMyMoney::Account::Type::Expense ? QLatin1Char('E') : QLatin1Char('I')); s << endl; - QStringList list = acc.accountList(); - QStringList::Iterator it_catList; - name += m_separator; - for (it_catList = list.begin(); it_catList != list.end(); ++it_catList) { - writeCategoryEntry(s, *it_catList, name); - } + foreach (const auto sAccount, acc.accountList()) + writeCategoryEntry(s, sAccount, name); } @@ -277,11 +273,9 @@ void CsvWriter::extractInvestmentEntries(const QString& accountId, const QDate& startDate, const QDate& endDate) { MyMoneyFile* file = MyMoneyFile::instance(); - QList accList = file->account(accountId).accountList(); - QList::ConstIterator itAcc; - for (itAcc = accList.constBegin(); itAcc != accList.constEnd(); ++itAcc) { - MyMoneyTransactionFilter filter((*itAcc)); + foreach (const auto sAccount, file->account(accountId).accountList()) { + MyMoneyTransactionFilter filter(sAccount); filter.setDateFilter(startDate, endDate); QList list = file->transactionList(filter); QList::ConstIterator itList; diff --git a/kmymoney/reports/listtable.cpp b/kmymoney/reports/listtable.cpp --- a/kmymoney/reports/listtable.cpp +++ b/kmymoney/reports/listtable.cpp @@ -496,14 +496,12 @@ } } - QStringList::const_iterator it_a; - for (it_a = accountIdList.constBegin(); it_a != accountIdList.constEnd(); ++it_a) { - MyMoneyAccount acc = file->account(*it_a); + foreach (const auto sAccount, accountIdList) { + auto acc = file->account(sAccount); if (acc.accountType() == eMyMoney::Account::Type::Investment) { - QStringList::const_iterator it_b; - for (it_b = acc.accountList().constBegin(); it_b != acc.accountList().constEnd(); ++it_b) { - if (!accountIdList.contains(*it_b)) { - subAccountsList.append(*it_b); + foreach (const auto sSubAccount, acc.accountList()) { + if (!accountIdList.contains(sSubAccount)) { + subAccountsList.append(sSubAccount); } } } diff --git a/kmymoney/reports/objectinfotable.cpp b/kmymoney/reports/objectinfotable.cpp --- a/kmymoney/reports/objectinfotable.cpp +++ b/kmymoney/reports/objectinfotable.cpp @@ -349,11 +349,9 @@ { MyMoneyFile* file = MyMoneyFile::instance(); MyMoneyMoney value = file->balance(acc.id()); - QStringList accList = acc.accountList(); - QStringList::const_iterator it_a = accList.constBegin(); - for (; it_a != acc.accountList().constEnd(); ++it_a) { - MyMoneyAccount stock = file->account(*it_a); + foreach (const auto sAccount, acc.accountList()) { + auto stock = file->account(sAccount); try { MyMoneyMoney val; MyMoneyMoney balance = file->balance(stock.id()); diff --git a/kmymoney/reports/pivottable.cpp b/kmymoney/reports/pivottable.cpp --- a/kmymoney/reports/pivottable.cpp +++ b/kmymoney/reports/pivottable.cpp @@ -2299,13 +2299,12 @@ QStringList accountList; if (m_config.accounts(accountList)) { if (!KMyMoneyGlobalSettings::expertMode()) { - QStringList::const_iterator it_a, it_b; - for (it_a = accountList.constBegin(); it_a != accountList.constEnd(); ++it_a) { - MyMoneyAccount acc = MyMoneyFile::instance()->account(*it_a); + foreach (const auto sAccount, accountList) { + auto acc = MyMoneyFile::instance()->account(sAccount); if (acc.accountType() == eMyMoney::Account::Type::Investment) { - for (it_b = acc.accountList().constBegin(); it_b != acc.accountList().constEnd(); ++it_b) { - if (!accountList.contains(*it_b)) { - m_config.addAccount(*it_b); + foreach (const auto sSubAccount, acc.accountList()) { + if (!accountList.contains(sSubAccount)) { + m_config.addAccount(sSubAccount); } } } diff --git a/kmymoney/views/kforecastview.cpp b/kmymoney/views/kforecastview.cpp --- a/kmymoney/views/kforecastview.cpp +++ b/kmymoney/views/kforecastview.cpp @@ -734,15 +734,10 @@ if (forecast.isForecastAccount(acc)) return true; - QStringList accounts = acc.accountList(); - - if (accounts.size() > 0) { - QStringList::ConstIterator it_acc; - for (it_acc = accounts.constBegin(); it_acc != accounts.constEnd(); ++it_acc) { - MyMoneyAccount account = file->account(*it_acc); - if (includeAccount(forecast, account)) - return true; - } + foreach (const auto sAccount, acc.accountList()) { + auto account = file->account(sAccount); + if (includeAccount(forecast, account)) + return true; } return false; } @@ -766,19 +761,17 @@ void KForecastView::loadAccounts(MyMoneyForecast& forecast, const MyMoneyAccount& account, QTreeWidgetItem* parentItem, int forecastType) { QMap nameIdx; - QStringList accList; MyMoneyFile* file = MyMoneyFile::instance(); QTreeWidgetItem *forecastItem = 0; //Get all accounts of the right type to calculate forecast - accList = account.accountList(); + const auto accList = account.accountList(); - if (accList.size() == 0) + if (accList.isEmpty()) return; - QStringList::ConstIterator accList_t; - for (accList_t = accList.constBegin(); accList_t != accList.constEnd(); ++accList_t) { - MyMoneyAccount subAccount = file->account(*accList_t); + foreach (const auto sAccount, accList) { + auto subAccount = file->account(sAccount); //only add the account if it is a forecast account or the parent of a forecast account if (includeAccount(forecast, subAccount)) { nameIdx[subAccount.id()] = subAccount.id(); diff --git a/kmymoney/widgets/kmymoneyaccountselector.cpp b/kmymoney/widgets/kmymoneyaccountselector.cpp --- a/kmymoney/widgets/kmymoneyaccountselector.cpp +++ b/kmymoney/widgets/kmymoneyaccountselector.cpp @@ -571,15 +571,9 @@ if (d->m_typeList.contains(acc.accountType())) return true; - QStringList accounts = acc.accountList(); - - if (accounts.size() > 0) { - QStringList::ConstIterator it_acc; - for (it_acc = accounts.constBegin(); it_acc != accounts.constEnd(); ++it_acc) { - MyMoneyAccount account = d->m_file->account(*it_acc); - if (includeAccount(account)) - return true; - } - } + foreach (const auto sAccount, acc.accountList()) + if (includeAccount(d->m_file->account(sAccount))) + return true; + return false; }