ソースを参照

wxGUI/dbmgr: highlight selected features in mapdisplay by default (could be disabled from preferences)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@59109 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 11 年 前
コミット
83e376fbba

+ 2 - 1
gui/wxpython/core/settings.py

@@ -214,7 +214,8 @@ class Settings:
             'atm' : {
                 'highlight' : {
                     'color' : (255, 255, 0, 255),
-                    'width' : 2
+                    'width' : 2,
+                    'auto'  : True,
                     },
                 'leftDbClick' : {
                     'selection' : 1 # draw selected

+ 32 - 10
gui/wxpython/dbmgr/base.py

@@ -15,7 +15,9 @@ List of classes:
  - base::LayerListCtrl
  - base::LayerBook
 
-(C) 2007-2009, 2011-2012 by the GRASS Development Team
+@todo Implement giface class
+
+(C) 2007-2014 by the GRASS Development Team
 
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -354,6 +356,14 @@ class VirtualAttributeList(wx.ListCtrl,
 
         return cats
 
+    def GetItems(self):
+        """!Return list of items (category numbers)"""
+        cats = []
+        for item in range(self.GetItemCount()):
+            cats.append(self.GetItemText(item))
+        
+        return cats
+
     def GetColumnText(self, index, col):
         """!Return column text"""
         item = self.GetItem(index, col)
@@ -1557,14 +1567,19 @@ class DbMgrBrowsePage(DbMgrNotebookBase):
         
         event.Skip()
 
-    def _drawSelected(self, zoom):
+    def _drawSelected(self, zoom, selectedOnly=True):
         """!Highlight selected features"""
         if not self.map or not self.mapdisplay:
             return
         
         tlist = self.FindWindowById(self.layerPage[self.selLayer]['data'])
-        cats = map(int, tlist.GetSelectedItems())
-
+        if selectedOnly:
+            fn = tlist.GetSelectedItems
+        else:
+            fn = tlist.GetItems
+        
+        cats = map(int, fn())
+        
         digitToolbar = None
         if 'vdigit' in self.mapdisplay.toolbars:
             digitToolbar = self.mapdisplay.toolbars['vdigit']
@@ -1578,12 +1593,12 @@ class DbMgrBrowsePage(DbMgrNotebookBase):
                                               update = True)
         else:
             # add map layer with higlighted vector features
-            self.AddQueryMapLayer() # -> self.qlayer
+            self.AddQueryMapLayer(selectedOnly) # -> self.qlayer
 
             # set opacity based on queried layer
             if self.parent and self.mapdisplay.tree and \
                     self.dbMgrData['treeItem']:
-                maptree = self.mapdisplay.tree
+                maptree = self.mapdisplay.tree # TODO: giface
                 opacity = maptree.GetLayerInfo(self.dbMgrData['treeItem'], key = 'maplayer').GetOpacity()
                 self.qlayer.SetOpacity(opacity)
             if zoom:
@@ -1633,15 +1648,18 @@ class DbMgrBrowsePage(DbMgrNotebookBase):
         else:
             self.mapdisplay.MapWindow.UpdateMap(render = False, renderVector = True)
         
-    def AddQueryMapLayer(self):
+    def AddQueryMapLayer(self, selectedOnly = True):
         """!Redraw a map
 
         Return True if map has been redrawn, False if no map is given
         """
         tlist = self.FindWindowById(self.layerPage[self.selLayer]['data'])
-        cats = { 
-            self.selLayer : tlist.GetSelectedItems()
-            }
+        if selectedOnly:
+            fn = tlist.GetSelectedItems
+        else:
+            fn = tlist.GetItems
+
+        cats = { self.selLayer : fn() }
         
         if self.mapdisplay.Map.GetLayerIndex(self.qlayer) < 0:
             self.qlayer = None
@@ -1827,6 +1845,10 @@ class DbMgrBrowsePage(DbMgrNotebookBase):
         self.log.write(_("Number of loaded records: %d") % \
                            self.FindWindowById(self.layerPage[self.selLayer]['data']).GetItemCount())
 
+        # update map display if needed
+        if UserSettings.Get(group = 'atm', key = 'highlight', subkey = 'auto'):
+            self._drawSelected(zoom=False, selectedOnly=False) # TODO: replace by signals
+
     def OnBuilder(self,event):
         """!SQL Builder button pressed -> show the SQLBuilder dialog"""
         if not self.builder:

+ 11 - 2
gui/wxpython/gui_core/preferences.py

@@ -15,7 +15,7 @@ Classes:
  - preferences::MapsetAccess
  - preferences::CheckListMapset
 
-(C) 2007-2012 by the GRASS Development Team
+(C) 2007-2014 by the GRASS Development Team
 
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -1060,12 +1060,13 @@ class PreferencesDialog(PreferencesBaseDialog):
         # highlighting
         #
         highlightBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
-                                    label = " %s " % _("Highlighting"))
+                                    label = " %s " % _("Highlight selected features"))
         highlightSizer = wx.StaticBoxSizer(highlightBox, wx.VERTICAL)
 
         flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
         flexSizer.AddGrowableCol(0)
         
+        # color
         label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Color:"))
         hlColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
                                     colour = self.settings.Get(group = 'atm', key = 'highlight', subkey = 'color'),
@@ -1076,6 +1077,7 @@ class PreferencesDialog(PreferencesBaseDialog):
         flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
         flexSizer.Add(hlColor, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
 
+        # width
         label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Line width (in pixels):"))
         hlWidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (50, -1),
                               initial = self.settings.Get(group = 'atm', key = 'highlight',subkey = 'width'),
@@ -1085,6 +1087,13 @@ class PreferencesDialog(PreferencesBaseDialog):
         flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
         flexSizer.Add(hlWidth, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
 
+        # auto
+        autoHighlight = wx.CheckBox(parent = panel, id = wx.ID_ANY, label = _("Automatically hightlight selected features in map display"))
+        autoHighlight.SetValue(self.settings.Get(group = 'atm', key = 'highlight', subkey = 'auto'))
+        self.winId['atm:highlight:auto'] = autoHighlight.GetId()
+        
+        flexSizer.Add(autoHighlight, proportion = 1)
+        
         highlightSizer.Add(item = flexSizer,
                            proportion = 0,
                            flag = wx.ALL | wx.EXPAND,