[GRASS-SVN] r62752 - in grass/trunk/gui/wxpython: lmgr nviz

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Nov 15 16:05:50 PST 2014


Author: annakrat
Date: 2014-11-15 16:05:50 -0800 (Sat, 15 Nov 2014)
New Revision: 62752

Modified:
   grass/trunk/gui/wxpython/lmgr/layertree.py
   grass/trunk/gui/wxpython/nviz/mapwindow.py
Log:
wxGUI/layertree: fix weird behavior when there is a lot of layers caused by wrong CustomTreeCtrl API usage, fixed also #2257 and partially groups drag and drop problem

Modified: grass/trunk/gui/wxpython/lmgr/layertree.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/layertree.py	2014-11-15 23:58:18 UTC (rev 62751)
+++ grass/trunk/gui/wxpython/lmgr/layertree.py	2014-11-16 00:05:50 UTC (rev 62752)
@@ -268,6 +268,23 @@
 
         return None
 
+    def GetNextItem(self, item):
+        """!Returns next item from tree (flattened expanded tree)"""
+        # this is a not empty group
+        if self.GetChildrenCount(item):
+                return self.GetFirstChild(item)[0]
+        # this is a layer outside group
+        if self.GetItemParent(item) == self.root:
+            return self.GetNextSibling(item)
+
+        # this is a layer inside group
+        sibling = self.GetNextSibling(item)
+        if sibling:
+            # this is a layer inside group
+            return sibling
+        # skip one up the hierarchy
+        return self.GetNextSibling(self.GetItemParent(item))
+
     def SetItemIcon(self, item, iconName=None):
         if not iconName:
             iconName = self.GetLayerInfo(item, key = 'maplayer').GetType()
@@ -1024,13 +1041,13 @@
         """
         if lname and not multiple:
             # check for duplicates
-            item = self.GetFirstVisibleItem()
+            item = self.GetFirstChild(self.root)[0]
             while item and item.IsOk():
                 if self.GetLayerInfo(item, key = 'type') == 'vector':
                     name = self.GetLayerInfo(item, key = 'maplayer').GetName()
                     if name == lname:
                         return
-                item = self.GetNextVisible(item)
+                item = self.GetNextItem(item)
         
         selectedLayer = self.GetSelectedLayer()
         # deselect active item
@@ -1150,7 +1167,7 @@
                 if self.GetLayerInfo(prevItem, key = 'maplayer'): 
                     prevMapLayer = self.GetLayerInfo(prevItem, key = 'maplayer')
                 
-                prevItem = self.GetNextSibling(prevItem) 
+                prevItem = self.GetNextItem(prevItem) 
                 
                 if prevMapLayer: 
                     pos = self.Map.GetLayerIndex(prevMapLayer)
@@ -1248,15 +1265,17 @@
         """
         self.lmgr.WorkspaceChanged()
         layer = event.GetItem()
-        
-        self.PropertiesDialog(layer)
-        
-        if self.GetLayerInfo(layer, key = 'type') == 'group':
+
+        if self.GetLayerInfo(layer, key='type') == 'group':
             if self.IsExpanded(layer):
                 self.Collapse(layer)
             else:
                 self.Expand(layer)
+            return
+
+        self.PropertiesDialog(layer)
         
+        
     def OnDeleteLayer(self, event):
         """Remove selected layer item from the layer tree"""
         self.lmgr.WorkspaceChanged()
@@ -1380,11 +1399,11 @@
         ctrl = event.GetEventObject().GetId()
         
         # find layer tree item by ctrl
-        layer = self.GetFirstVisibleItem()
+        layer = self.GetFirstChild(self.root)[0]
         while layer and layer.IsOk():
             if self.GetLayerInfo(layer, key = 'ctrl') == ctrl:
                 break
-            layer = self.GetNextVisible(layer)
+            layer = self.GetNextItem(layer)
         
         # change parameters for item in layers list in render.Map
         self.ChangeLayer(layer)
@@ -1508,8 +1527,7 @@
             if child:
                 while child:
                     self.RecreateItem(child, dropTarget, parent = newItem)
-                    self.Delete(child)
-                    child = self.GetNextChild(old, cookie)[0]
+                    child, cookie = self.GetNextChild(old, cookie)
         
         # delete layer at original position
         try:
@@ -1698,7 +1716,7 @@
         # make a list of visible layers
         layers = []
 
-        vislayer = self.GetFirstVisibleItem()
+        vislayer = self.GetFirstChild(self.root)[0]
 
         if not vislayer or self.GetPyData(vislayer) is None:
             return layers
@@ -1708,19 +1726,16 @@
             digitToolbar = self.mapdisplay.GetToolbar('vdigit')
             if digitToolbar:
                 vdigitLayer = digitToolbar.GetLayer()
-        
+
         itemList = ""
-        for item in range(self.GetCount()):
+        while vislayer:
             itemList += self.GetItemText(vislayer) + ','
             lType = self.GetLayerInfo(vislayer, key='type')
             mapLayer = self.GetLayerInfo(vislayer, key='maplayer')
             if lType and lType != 'group' and mapLayer is not vdigitLayer:
                 layers.append(mapLayer)
 
-            if not self.GetNextVisible(vislayer):
-                break
-            else:
-                vislayer = self.GetNextVisible(vislayer)
+            vislayer = self.GetNextItem(vislayer)
 
         Debug.msg(5, "LayerTree.GetVisibleLayers(): items=%s" %
                   (reversed(itemList)))
@@ -1798,7 +1813,7 @@
             if i == index:
                 return item
             
-            item = self.GetNextVisible(item)
+            item = self.GetNextItem(item)
             i += 1
         
         return None
@@ -1838,7 +1853,7 @@
             except KeyError:
                 return None
             
-            if value == itemLayer.GetName():
+            if itemLayer and value == itemLayer.GetName():
                 items.append(item)
             if self.GetLayerInfo(item, key = 'type') == 'group':
                 subItem = self.GetFirstChild(item)[0]

Modified: grass/trunk/gui/wxpython/nviz/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/nviz/mapwindow.py	2014-11-15 23:58:18 UTC (rev 62751)
+++ grass/trunk/gui/wxpython/nviz/mapwindow.py	2014-11-16 00:05:50 UTC (rev 62752)
@@ -1297,18 +1297,17 @@
         while item and item.IsOk():
             type = self.tree.GetLayerInfo(item, key = 'type')
             if type ==  'group':
-                subItem = self.tree.GetFirstChild(item)[0]
-                self._GetDataLayers(subItem, litems)
-                item = self.tree.GetNextSibling(item)
+                item = self.tree.GetNextItem(item)
+                continue
                 
             if not item.IsChecked() or \
                     type not in ('raster', 'vector', '3d-raster'):
-                item = self.tree.GetNextSibling(item)
+                item = self.tree.GetNextItem(item)
                 continue
             
             litems.append(item)
             
-            item = self.tree.GetNextSibling(item)
+            item = self.tree.GetNextItem(item)
         
     def LoadDataLayers(self):
         """Load raster/vector from current layer tree



More information about the grass-commit mailing list