Modernise and replace foreach loops with for in loops in folderstatusmodel
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 26 Feb 2024 09:09:14 +0000 (17:09 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 5 Mar 2024 03:48:05 +0000 (11:48 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/folderstatusmodel.cpp

index 9eb505be36eea0dd3ba037f552a4714e25232af2..a3b3b49f2bcadc5dbd43b03e7e82b98aa190b5db 100644 (file)
@@ -74,20 +74,21 @@ void FolderStatusModel::setAccountState(const AccountState *accountState)
         this, &FolderStatusModel::slotFolderScheduleQueueChanged, Qt::UniqueConnection);
 
     auto folders = FolderMan::instance()->map();
-    foreach (auto f, folders) {
-        if (!accountState)
+    for (const auto &folder : folders) {
+        if (!accountState) {
             break;
-        if (f->accountState() != accountState)
+        } else if (folder->accountState() != accountState) {
             continue;
+        }
         SubFolderInfo info;
-        info._name = f->alias();
+        info._name = folder->alias();
         info._path = "/";
-        info._folder = f;
+        info._folder = folder;
         info._checked = Qt::PartiallyChecked;
         _folders << info;
 
-        connect(f, &Folder::progressInfo, this, &FolderStatusModel::slotSetProgress, Qt::UniqueConnection);
-        connect(f, &Folder::newBigFolderDiscovered, this, &FolderStatusModel::slotNewBigFolder, Qt::UniqueConnection);
+        connect(folder, &Folder::progressInfo, this, &FolderStatusModel::slotSetProgress, Qt::UniqueConnection);
+        connect(folder, &Folder::newBigFolderDiscovered, this, &FolderStatusModel::slotNewBigFolder, Qt::UniqueConnection);
     }
 
     // Sort by header text
@@ -331,7 +332,7 @@ bool FolderStatusModel::setData(const QModelIndex &index, const QVariant &value,
                 auto parentInfo = infoForIndex(parent);
                 if (parentInfo && parentInfo->_checked != Qt::Checked) {
                     bool hasUnchecked = false;
-                    foreach (const auto &sub, parentInfo->_subs) {
+                    for (const auto &sub : parentInfo->_subs) {
                         if (sub._checked != Qt::Checked) {
                             hasUnchecked = true;
                             break;
@@ -720,7 +721,7 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list)
     }
 
     std::set<QString> selectiveSyncUndecidedSet; // not QSet because it's not sorted
-    foreach (const QString &str, selectiveSyncUndecidedList) {
+    for (const auto &str : selectiveSyncUndecidedList) {
         if (str.startsWith(parentInfo->_path) || parentInfo->_path == QLatin1String("/")) {
             selectiveSyncUndecidedSet.insert(str);
         }
@@ -737,7 +738,7 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list)
 
     QVector<SubFolderInfo> newSubs;
     newSubs.reserve(sortedSubfolders.size());
-    foreach (const QString &path, sortedSubfolders) {
+    for (const auto &path : sortedSubfolders) {
         auto relativePath = path.mid(pathToRemove.size());
         if (parentInfo->_folder->isFileExcludedRelative(relativePath)) {
             continue;
@@ -785,7 +786,7 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list)
         } else if (parentInfo->_checked == Qt::Checked) {
             newInfo._checked = Qt::Checked;
         } else {
-            foreach (const QString &str, selectiveSyncBlackList) {
+            for (const auto &str : selectiveSyncBlackList) {
                 if (str == relativePath || str == QLatin1String("/")) {
                     newInfo._checked = Qt::Unchecked;
                     break;
@@ -819,7 +820,7 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list)
         endInsertRows();
     }
 
-    for (int undecidedIndex : qAsConst(undecidedIndexes)) {
+    for (const auto undecidedIndex : qAsConst(undecidedIndexes)) {
         emit suggestExpand(index(undecidedIndex, 0, idx));
     }
     /* Try to remove the the undecided lists the items that are not on the server. */
@@ -880,7 +881,7 @@ QStringList FolderStatusModel::createBlackList(const FolderStatusModel::SubFolde
     } else {
         // We did not load from the server so we reuse the one from the old black list
         const QString path = root._path;
-        foreach (const QString &it, oldBlackList) {
+        for (const auto &it : oldBlackList) {
             if (it.startsWith(path))
                 result += it;
         }
@@ -942,7 +943,7 @@ void FolderStatusModel::slotApplySelectiveSync()
             }
             //The part that changed should not be read from the DB on next sync because there might be new folders
             // (the ones that are no longer in the blacklist)
-            foreach (const auto &it, changes) {
+            for (const auto &it : changes) {
                 folder->journalDb()->schedulePathForRemoteDiscovery(it);
                 folder->schedulePathForLocalDiscovery(it);
             }
@@ -1020,7 +1021,7 @@ void FolderStatusModel::slotSetProgress(const ProgressInfo &progress)
     quint64 estimatedUpBw = 0;
     quint64 estimatedDownBw = 0;
     QString allFilenames;
-    foreach (const ProgressInfo::ProgressItem &citm, progress._currentItems) {
+    for (const auto &citm : progress._currentItems) {
         if (curItemProgress == -1 || (ProgressInfo::isSizeDependent(citm._item)
                                          && biggerItemSize < citm._item._size)) {
             curItemProgress = citm._progress.completed();
@@ -1211,7 +1212,7 @@ void FolderStatusModel::slotFolderSyncStateChange(Folder *f)
 void FolderStatusModel::slotFolderScheduleQueueChanged()
 {
     // Update messages on waiting folders.
-    foreach (Folder *f, FolderMan::instance()->map()) {
+    for (const auto f : FolderMan::instance()->map()) {
         slotFolderSyncStateChange(f);
     }
 }
@@ -1248,7 +1249,7 @@ void FolderStatusModel::slotSyncAllPendingBigFolders()
             qCWarning(lcFolderStatus) << "Could not read selective sync list from db.";
             return;
         }
-        foreach (const auto &undecidedFolder, undecidedList) {
+        for (const auto &undecidedFolder : undecidedList) {
             blackList.removeAll(undecidedFolder);
         }
         folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, blackList);
@@ -1271,7 +1272,7 @@ void FolderStatusModel::slotSyncAllPendingBigFolders()
         }
         // The part that changed should not be read from the DB on next sync because there might be new folders
         // (the ones that are no longer in the blacklist)
-        foreach (const auto &it, undecidedList) {
+        for (const auto &it : undecidedList) {
             folder->journalDb()->schedulePathForRemoteDiscovery(it);
             folder->schedulePathForLocalDiscovery(it);
         }