Skip to content
Permalink
Browse files

Use text encoded versions of points and extents in history panel

Fixes generation of unit tests with point/extent parameters
  • Loading branch information
nyalldawson committed Sep 24, 2017
1 parent fb08b0a commit 83a8a8d730c380c634070e5f7a8fa6fa99148c0c
@@ -79,10 +79,14 @@ def __init__(self, dialog, param):
if param.defaultValue() is not None:
context = createContext()
rect = QgsProcessingParameters.parameterAsExtent(param, {param.name(): param.defaultValue()}, context)
crs = QgsProcessingParameters.parameterAsExtentCrs(param, {param.name(): param.defaultValue()}, context)
if not rect.isNull():
try:
s = '{},{},{},{}'.format(
rect.xMinimum(), rect.xMaximum(), rect.yMinimum(), rect.yMaximum())
if crs.isValid():
s += ' [' + crs.authid() + ']'
self.crs = crs
self.leText.setText(s)
except:
pass
@@ -133,10 +137,6 @@ def useLayerExtent(self):
self.tr('Use extent from'), extents, False)
if ok:
self.setValueFromRect(QgsReferencedRectangle(extentsDict[item]["extent"], QgsCoordinateReferenceSystem(extentsDict[item]["authid"])))
if extentsDict[item]["authid"] != iface.mapCanvas().mapSettings().destinationCrs().authid():
iface.messageBar().pushMessage(self.tr("Warning"),
self.tr("The projection of the chosen layer is not the same as canvas projection! The selected extent might not be what was intended."),
QgsMessageBar.WARNING, 8)

def selectOnCanvas(self):
canvas = iface.mapCanvas()
@@ -151,11 +151,14 @@ def setValueFromRect(self, r):
s = '{},{},{},{}'.format(
r.xMinimum(), r.xMaximum(), r.yMinimum(), r.yMaximum())

self.leText.setText(s)
try:
self.crs = r.crs()
except:
self.crs = QgsProject.instance().crs()
if self.crs.isValid():
s += ' [' + self.crs.authid() + ']'

self.leText.setText(s)
self.tool.reset()
canvas = iface.mapCanvas()
canvas.setMapTool(self.prevMapTool)
@@ -165,13 +168,7 @@ def setValueFromRect(self, r):

def getValue(self):
if str(self.leText.text()).strip() != '':
try:
parts = self.leText.text().split(',')
parts = [float(p) for p in parts]
r = QgsReferencedRectangle(QgsRectangle(parts[0], parts[2], parts[1], parts[3]), self.crs)
return r
except:
return str(self.leText.text())
return str(self.leText.text())
else:
return None

@@ -82,6 +82,8 @@ def selectOnCanvas(self):
def updatePoint(self, point, button):
s = '{},{}'.format(point.x(), point.y())
self.crs = QgsProject.instance().crs()
if self.crs.isValid():
s += ' [' + self.crs.authid() + ']'
self.leText.setText(s)

def pointPicked(self):
@@ -93,15 +95,7 @@ def pointPicked(self):

def getValue(self):
if str(self.leText.text()).strip() != '':
try:
parts = self.leText.text().split(',')
parts = [float(p) for p in parts]
r = QgsReferencedPointXY(QgsPointXY(parts[0], parts[1]),
self.crs)
return r

except:
return str(self.leText.text())
return str(self.leText.text())
else:
return None

0 comments on commit 83a8a8d

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