Skip to content

Commit

Permalink
#120 Now repainting joined layers
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinux committed May 19, 2015
1 parent 11d985f commit c01fce2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
11 changes: 11 additions & 0 deletions logging.py
Expand Up @@ -21,3 +21,14 @@ def log_after(*args, **kwargs):
error("Exception in function {}:{}".format(str(func),str(e)))
return
return log_after

def debug_on_exceptions(func):
""" Only used for debugging"""
def debug_after(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception,e:
from PyQt4.QtCore import pyqtRemoveInputHook
pyqtRemoveInputHook()
import pdb;pdb.set_trace()
return debug_after
19 changes: 18 additions & 1 deletion qgis_utils.py
@@ -1,11 +1,28 @@
from PyQt4.QtGui import QColor
from qgis._core import QgsMapLayerRegistry, QgsFields
from qgis.core import QgsRasterLayer
from logging import warn
from logging import warn, debug_on_exceptions

__author__ = 'carolinux'


def getAllJoinIdsOfLayer(layer):
return set(map(lambda x: x.joinLayerId, layer.vectorJoins()))

def getAllJoinedLayers(layerIds):
"""get the ids of the layers that are joined on the given layerIds"""
allJoined = set()
allLayers = QgsMapLayerRegistry.instance().mapLayers()
for (id, layer) in allLayers.iteritems():
if id in layerIds: # let's see what the given layers are joined on
allJoined|= getAllJoinIdsOfLayer(layer)
else: # let's see if the other layers join with the given layers
joinsOfCurrentLayer = getAllJoinIdsOfLayer(layer)
if len(joinsOfCurrentLayer & layerIds)>0:
allJoined.add(id)

return allJoined

def getLayerAttributes(layerId):
try:
layer=QgsMapLayerRegistry.instance().mapLayers()[layerId]
Expand Down
8 changes: 5 additions & 3 deletions timemanagercontrol.py
Expand Up @@ -174,6 +174,7 @@ def refreshGuiTimeExtents(self,timeExtents):

self.setPropagateGuiChanges(True)

@log_exceptions
def refreshGuiWithCurrentTime(self,currentTimePosition,sender=None):
"""update the gui when time has changed by refreshing/repainting the layers
and changing the time showing in dateTimeEditCurrentTime and horizontalTimeSlider"""
Expand All @@ -198,10 +199,11 @@ def refreshGuiWithCurrentTime(self,currentTimePosition,sender=None):
- self.guiControl.dock.horizontalTimeSlider.minimum()))
self.guiControl.dock.horizontalTimeSlider.setValue(sliderVal)
self.guiControl.repaintRasters()
#self.guiControl.repaintVectors()
self.guiControl.repaintJoined()
self.guiControl.repaintVectors()
self.guiControl.refreshMapCanvas()
except:
pass
except Exception,e:
error(e)
finally:
self.setPropagateGuiChanges(True)

Expand Down
6 changes: 6 additions & 0 deletions timemanagerguicontrol.py
Expand Up @@ -414,3 +414,9 @@ def repaintRasters(self):

def repaintVectors(self):
map(lambda x: x.layer.triggerRepaint(), self.model.getActiveVectors())

def repaintJoined(self):
layerIdsToRefresh = qgs.getAllJoinedLayers(set(map(lambda x:x.layer.id(),self.model.getActiveVectors())))
info("to refresh {}".format(layerIdsToRefresh))
layersToRefresh = map(lambda x: qgs.getLayerFromId(x), layerIdsToRefresh)
map(lambda x: x.triggerRepaint(), layersToRefresh)

0 comments on commit c01fce2

Please sign in to comment.