Skip to content
Permalink
Browse files

[processing] Make 'canvas extent' its own menu item in the extent

selection parameter button, instead of requiring opening the
'select layer/canvas extent' and choosing 'canvas extent'

It's only one extra click, but I don't think there's any reason
against saving this click!
  • Loading branch information
nyalldawson committed Oct 4, 2018
1 parent 2a974e3 commit 706b13a47bdeaebc7483ab5e49732e59b4bd91e7
Showing with 13 additions and 6 deletions.
  1. +13 −6 python/plugins/processing/gui/ExtentSelectionPanel.py
@@ -97,17 +97,23 @@ def __init__(self, dialog, param):

def selectExtent(self):
popupmenu = QMenu()
useCanvasExtentAction = QAction(
QCoreApplication.translate("ExtentSelectionPanel", 'Use Canvas Extent'),
self.btnSelect)
useLayerExtentAction = QAction(
QCoreApplication.translate("ExtentSelectionPanel", 'Use Layer/Canvas Extent…'),
QCoreApplication.translate("ExtentSelectionPanel", 'Use Layer Extent…'),
self.btnSelect)
selectOnCanvasAction = QAction(
self.tr('Select Extent on Canvas'), self.btnSelect)

popupmenu.addAction(useLayerExtentAction)
popupmenu.addAction(useCanvasExtentAction)
popupmenu.addAction(selectOnCanvasAction)
popupmenu.addSeparator()
popupmenu.addAction(useLayerExtentAction)

selectOnCanvasAction.triggered.connect(self.selectOnCanvas)
useLayerExtentAction.triggered.connect(self.useLayerExtent)
useCanvasExtentAction.triggered.connect(self.useCanvasExtent)

if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
useMincoveringExtentAction = QAction(
@@ -123,11 +129,8 @@ def useMinCoveringExtent(self):
self.leText.setText('')

def useLayerExtent(self):
CANVAS_KEY = 'Canvas Extent'
extentsDict = {}
extentsDict[CANVAS_KEY] = {"extent": iface.mapCanvas().extent(),
"authid": iface.mapCanvas().mapSettings().destinationCrs().authid()}
extents = [CANVAS_KEY]
extents = []
layers = QgsProcessingUtils.compatibleLayers(QgsProject.instance())
for layer in layers:
authid = layer.crs().authid()
@@ -143,6 +146,10 @@ def useLayerExtent(self):
if ok:
self.setValueFromRect(QgsReferencedRectangle(extentsDict[item]["extent"], QgsCoordinateReferenceSystem(extentsDict[item]["authid"])))

def useCanvasExtent(self):
self.setValueFromRect(QgsReferencedRectangle(iface.mapCanvas().extent(),
iface.mapCanvas().mapSettings().destinationCrs()))

def selectOnCanvas(self):
canvas = iface.mapCanvas()
canvas.setMapTool(self.tool)

0 comments on commit 706b13a

Please sign in to comment.
You can’t perform that action at this time.