[Pkg-owncloud-commits] [owncloud-client] 29/218: FolderStatusModel: add a function to get a QModelIndex from the path

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat Oct 17 14:30:36 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 9172a5fc4ce89893e3ade16912cbad4907951394
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Mon Aug 31 10:12:45 2015 +0200

    FolderStatusModel: add a function to get a QModelIndex from the path
    
    Will be usefull to solve #3704
---
 src/gui/folderstatusmodel.cpp | 39 +++++++++++++++++++++++++++++++++++++++
 src/gui/folderstatusmodel.h   |  7 ++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp
index 5435d61..d21d25e 100644
--- a/src/gui/folderstatusmodel.cpp
+++ b/src/gui/folderstatusmodel.cpp
@@ -330,6 +330,45 @@ FolderStatusModel::SubFolderInfo* FolderStatusModel::infoForIndex(const QModelIn
     }
 }
 
+QModelIndex FolderStatusModel::indexForPath(Folder *f, const QString& path) const
+{
+    int slashPos = path.lastIndexOf('/');
+    if (slashPos == -1) {
+        // first level folder
+        for (int i = 0; i < _folders.size(); ++i) {
+            if (_folders.at(i)._folder == f) {
+                for (int j = 0; j < _folders.at(i)._subs.size(); ++j) {
+                    if (_folders.at(i)._subs.at(j)._name == path) {
+                        return index(j, 0, index(i));
+                    }
+                }
+                return QModelIndex();
+            }
+        }
+        return QModelIndex();
+    }
+
+    auto parent = indexForPath(f, path.left(slashPos));
+    if (!parent.isValid())
+        return parent;
+
+    if (slashPos == path.size() - 1) {
+        // The slash is the last part, we found our index
+        return parent;
+    }
+
+    auto parentInfo = infoForIndex(parent);
+    if (!parentInfo) {
+        return QModelIndex();
+    }
+    for (int i = 0; i < parentInfo->_subs.size(); ++i) {
+        if (parentInfo->_subs.at(i)._name == path.mid(slashPos  + 1)) {
+            return index(i, 0, parent);
+        }
+    }
+
+    return QModelIndex();
+}
 
 QModelIndex FolderStatusModel::index(int row, int column, const QModelIndex& parent) const
 {
diff --git a/src/gui/folderstatusmodel.h b/src/gui/folderstatusmodel.h
index d849ee2..c19f0fe 100644
--- a/src/gui/folderstatusmodel.h
+++ b/src/gui/folderstatusmodel.h
@@ -49,7 +49,6 @@ public:
     void fetchMore(const QModelIndex& parent) Q_DECL_OVERRIDE;
     bool hasChildren(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
 
-
     struct SubFolderInfo {
         SubFolderInfo()
             : _folder(0), _size(0), _fetched(false), _fetching(false), _isUndecided(false),
@@ -87,6 +86,12 @@ public:
     // If the selective sync check boxes were changed
     bool isDirty() { return _dirty; }
 
+    /**
+     * return a QModelIndex for the given path within the given folder.
+     * Note: this method returns an invalid index if the path was not fetch from the server before
+     */
+    QModelIndex indexForPath(Folder *f, const QString &path) const;
+
 public slots:
     void slotUpdateFolderState(Folder *);
     void slotApplySelectiveSync();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list