Project/ProjectBaseBrowser.py

changeset 3601
236578b22511
parent 3600
7d17c492ab95
child 3603
cd14023a8ac1
diff -r 7d17c492ab95 -r 236578b22511 Project/ProjectBaseBrowser.py
--- a/Project/ProjectBaseBrowser.py	Wed May 21 19:45:39 2014 +0200
+++ b/Project/ProjectBaseBrowser.py	Thu May 22 18:23:29 2014 +0200
@@ -572,25 +572,36 @@
         
         @return list of expanded items names (list of string)
         """
-        # step 1: find the top most index
-        childIndex = self.currentIndex()
-        if not childIndex.isValid():
-            return []
+        expandedNames = []
         
-        while childIndex.isValid():
-            topIndex = childIndex
-            childIndex = self.indexAbove(childIndex)
-        
-        # step 2: get names of expanded items
-        expandedNames = []
-        childIndex = topIndex
+        childIndex = self.model().index(0, 0)
         while childIndex.isValid():
             if self.isExpanded(childIndex):
-                expandedNames.append(
-                    self.model().item(childIndex).name())
+                try:
+                    expandedNames.append(
+                        self.model().item(childIndex).name())
+                except AttributeError:
+                    # only items defining the name() method are returned
+                    pass
             childIndex = self.indexBelow(childIndex)
+        
         return expandedNames
         
+    def expandItemsByName(self, names):
+        """
+        Public method to expand items given their names.
+        
+        @param names list of item names to be expanded (list of string)
+        """
+        model = self.model()
+        for name in names:
+            childIndex = model.index(0, 0)
+            while childIndex.isValid():
+                if model.item(childIndex).name() == name:
+                    self.setExpanded(childIndex, True)
+                    break
+                childIndex = self.indexBelow(childIndex)
+        
     def _prepareRepopulateItem(self, name):
         """
         Protected slot to handle the prepareRepopulateItem signal.

eric ide

mercurial