diff options
author | Aleksey Lysenko <lysenkoalexmail@gmail.com> | 2021-06-16 12:38:18 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-16 12:38:18 +0300 |
commit | 4715f63580f64d7baaba072f6c69632ccaa8a187 (patch) | |
tree | 201f42256d996e8aad25a70e929821d85e85011c /src/gui/accountmanager.cpp | |
parent | 09b538f4887d77685983dcb71d1ef6c1075a1b49 (diff) |
Remove possible qt containers detach (#8727)
* Replaced obsolete foreach-loops with for-loops
* Added a copy of queries into SqlDatabase::close
* Used const reference to avoid unneeded copying
* Fixed Qt containers possible detach within for-loop
* Removed unneeded copies before for-loops
Diffstat (limited to 'src/gui/accountmanager.cpp')
-rw-r--r-- | src/gui/accountmanager.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index ac9e6ce5a..af522f8cd 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -84,13 +84,14 @@ bool AccountManager::restore() } // If there are no accounts, check the old format. - if (settings->childGroups().isEmpty() + const auto &childGroups = settings->childGroups(); + if (childGroups.isEmpty() && !settings->contains(QLatin1String(versionC))) { restoreFromLegacySettings(); return true; } - foreach (const auto &accountId, settings->childGroups()) { + for (const auto &accountId : childGroups) { settings->beginGroup(accountId); if (!skipSettingsKeys.contains(settings->group())) { if (auto acc = loadAccountHelper(*settings)) { @@ -118,7 +119,8 @@ void AccountManager::backwardMigrationSettingsKeys(QStringList *deleteKeys, QStr auto settings = ConfigFile::settingsWithGroup(QLatin1String(accountsC)); const int accountsVersion = settings->value(QLatin1String(versionC)).toInt(); if (accountsVersion <= maxAccountsVersion) { - foreach (const auto &accountId, settings->childGroups()) { + const auto &childGroups = settings->childGroups(); + for (const auto &accountId : childGroups) { settings->beginGroup(accountId); const int accountVersion = settings->value(QLatin1String(versionC), 1).toInt(); if (accountVersion > maxAccountVersion) { @@ -192,7 +194,7 @@ void AccountManager::save(bool saveCredentials) { auto settings = ConfigFile::settingsWithGroup(QLatin1String(accountsC)); settings->setValue(QLatin1String(versionC), maxAccountsVersion); - foreach (const auto &acc, _accounts) { + for (const auto &acc : qAsConst(_accounts)) { settings->beginGroup(acc->account()->id()); saveAccountHelper(acc->account().data(), *settings, saveCredentials); acc->writeToSettings(*settings); @@ -339,7 +341,7 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) AccountStatePtr AccountManager::account(const QString &name) { - for (const auto &acc : _accounts) { + for (const auto &acc : qAsConst(_accounts)) { if (acc->account()->displayName() == name) { return acc; } @@ -395,16 +397,16 @@ AccountPtr AccountManager::createAccount() void AccountManager::shutdown() { - auto accountsCopy = _accounts; + const auto accountsCopy = _accounts; _accounts.clear(); - foreach (const auto &acc, accountsCopy) { + for (const auto &acc : accountsCopy) { emit accountRemoved(acc.data()); } } bool AccountManager::isAccountIdAvailable(const QString &id) const { - foreach (const auto &acc, _accounts) { + for (const auto &acc : _accounts) { if (acc->account()->id() == id) { return false; } |