Use const access where possible
authorHannah von Reth <hannah.vonreth@owncloud.com>
Wed, 22 Jul 2020 19:02:09 +0000 (21:02 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:59:17 +0000 (10:59 +0100)
src/gui/folderstatusmodel.cpp
src/gui/folderstatusmodel.h

index 8741a1f164e2e3d095a4fd8471e1fa0ec3271007..6c56ae39d989effa3e498d4f24c86d5e8524716c 100644 (file)
@@ -144,7 +144,7 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const
         return QVariant();
     }
     case SubFolder: {
-        const auto &x = static_cast<SubFolderInfo *>(index.internalPointer())->_subs[index.row()];
+        const auto &x = static_cast<SubFolderInfo *>(index.internalPointer())->_subs.at(index.row());
         switch (role) {
         case Qt::DisplayRole:
             //: Example text: "File.txt (23KB)"
@@ -315,7 +315,7 @@ bool FolderStatusModel::setData(const QModelIndex &index, const QVariant &value,
                 }
                 // also check all the children
                 for (int i = 0; i < info->_subs.count(); ++i) {
-                    if (info->_subs[i]._checked != Qt::Checked) {
+                    if (info->_subs.at(i)._checked != Qt::Checked) {
                         setData(this->index(i, 0, index), Qt::Checked, Qt::CheckStateRole);
                     }
                 }
@@ -330,7 +330,7 @@ bool FolderStatusModel::setData(const QModelIndex &index, const QVariant &value,
 
                 // Uncheck all the children
                 for (int i = 0; i < info->_subs.count(); ++i) {
-                    if (info->_subs[i]._checked != Qt::Unchecked) {
+                    if (info->_subs.at(i)._checked != Qt::Unchecked) {
                         setData(this->index(i, 0, index), Qt::Unchecked, Qt::CheckStateRole);
                     }
                 }
@@ -512,7 +512,7 @@ QModelIndex FolderStatusModel::parent(const QModelIndex &child) const
     const SubFolderInfo *info = &_folders[pathIdx.at(0)];
     while (i < pathIdx.count() - 1) {
         ASSERT(pathIdx.at(i) < info->_subs.count());
-        info = &info->_subs[pathIdx.at(i)];
+        info = &info->_subs.at(pathIdx.at(i));
         ++i;
     }
     return createIndex(pathIdx.at(i), 0, const_cast<SubFolderInfo *>(info));
@@ -789,15 +789,12 @@ void FolderStatusModel::slotLscolFinishedWithError(QNetworkReply *r)
     }
 }
 
-QStringList FolderStatusModel::createBlackList(FolderStatusModel::SubFolderInfo *root,
+QStringList FolderStatusModel::createBlackList(const FolderStatusModel::SubFolderInfo &root,
     const QStringList &oldBlackList) const
 {
-    if (!root)
-        return QStringList();
-
-    switch (root->_checked) {
+    switch (root._checked) {
     case Qt::Unchecked:
-        return QStringList(root->_path);
+        return QStringList(root._path);
     case Qt::Checked:
         return QStringList();
     case Qt::PartiallyChecked:
@@ -805,13 +802,13 @@ QStringList FolderStatusModel::createBlackList(FolderStatusModel::SubFolderInfo
     }
 
     QStringList result;
-    if (root->_fetched) {
-        for (int i = 0; i < root->_subs.count(); ++i) {
-            result += createBlackList(&root->_subs[i], oldBlackList);
+    if (root._fetched) {
+        for (int i = 0; i < root._subs.count(); ++i) {
+            result += createBlackList(root._subs.at(i), oldBlackList);
         }
     } else {
         // We did not load from the server so we re-use the one from the old black list
-        QString path = root->_path;
+        const QString path = root._path;
         foreach (const QString &it, oldBlackList) {
             if (it.startsWith(path))
                 result += it;
@@ -846,7 +843,7 @@ void FolderStatusModel::slotApplySelectiveSync()
             qCWarning(lcFolderStatus) << "Could not read selective sync list from db.";
             continue;
         }
-        QStringList blackList = createBlackList(&_folders[i], oldBlackList);
+        QStringList blackList = createBlackList(_folders.at(i), oldBlackList);
         folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, blackList);
 
         auto blackListSet = blackList.toSet();
index a4248a6f57793d10d46bf19aad4017eb84894e69..ecc13c2091077de98ef84ea7ffe7ddbdc4d1f10e 100644 (file)
@@ -138,7 +138,7 @@ private slots:
     void slotShowFetchProgress();
 
 private:
-    QStringList createBlackList(OCC::FolderStatusModel::SubFolderInfo *root,
+    QStringList createBlackList(const OCC::FolderStatusModel::SubFolderInfo &root,
         const QStringList &oldBlackList) const;
     const AccountState *_accountState = nullptr;
     bool _dirty = false; // If the selective sync checkboxes were changed