Skip to content

Commit

Permalink
Add CrsWidgetWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-morvan authored and volaya committed Oct 5, 2016
1 parent bb0938a commit 6158e9b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
8 changes: 6 additions & 2 deletions python/plugins/processing/core/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,16 @@ def getAsScriptCode(self):

class ParameterCrs(Parameter):

def __init__(self, name='', description='', default=None, optional=False):
default_metadata = {
'widget_wrapper': 'processing.gui.wrappers.CrsWidgetWrapper'
}

def __init__(self, name='', description='', default=None, optional=False, metadata={}):
'''The value is a string that uniquely identifies the
coordinate reference system. Typically it is the auth id of the CRS
(if the authority is EPSG) or proj4 string of the CRS (in case
of other authorities or user defined projections).'''
Parameter.__init__(self, name, description, default, optional)
Parameter.__init__(self, name, description, default, optional, metadata)

def setValue(self, value):
if value is None or value.strip() == '':
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/processing/gui/AlgorithmDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
from processing.core.parameters import ParameterString
from processing.core.parameters import ParameterNumber
from processing.core.parameters import ParameterFile
from processing.core.parameters import ParameterCrs
from processing.core.parameters import ParameterPoint
from processing.core.parameters import ParameterGeometryPredicate

Expand Down Expand Up @@ -172,7 +171,7 @@ def setParamValue(self, param, wrapper, alg=None):
else:
options = dataobjects.getVectorLayers([param.datatype], sorting=False)
return param.setValue([options[i] for i in widget.selectedoptions])
elif isinstance(param, (ParameterNumber, ParameterFile, ParameterCrs,
elif isinstance(param, (ParameterNumber, ParameterFile,
ParameterExtent, ParameterPoint)):
return param.setValue(widget.getValue())
elif isinstance(param, ParameterString):
Expand Down
6 changes: 4 additions & 2 deletions python/plugins/processing/gui/CrsSelectionPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@

class CrsSelectionPanel(BASE, WIDGET):

def __init__(self, default):
def __init__(self, default='EPSG:4326'):
super(CrsSelectionPanel, self).__init__(None)
self.setupUi(self)

self.leText.setEnabled(False)

self.btnSelect.clicked.connect(self.browseCRS)
self.crs = QgsCoordinateReferenceSystem(default).authid()

# TODO: Default should be removed
self.crs = default
self.updateText()

def setAuthId(self, authid):
Expand Down
2 changes: 0 additions & 2 deletions python/plugins/processing/gui/ParametersPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,6 @@ def getWidgetFromParameter(self, param):
item = ExtentSelectionPanel(self.parent, self.alg, param.default)
elif isinstance(param, ParameterPoint):
item = PointSelectionPanel(self.parent, param.default)
elif isinstance(param, ParameterCrs):
item = CrsSelectionPanel(param.default)
elif isinstance(param, ParameterString):
if param.multiline:
verticalLayout = QVBoxLayout()
Expand Down
19 changes: 19 additions & 0 deletions python/plugins/processing/gui/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@

from inspect import isclass

from qgis.core import QgsCoordinateReferenceSystem
from qgis.PyQt.QtWidgets import (
QCheckBox,
QComboBox,
)

from processing.gui.CrsSelectionPanel import CrsSelectionPanel

DIALOG_STANDARD = 'standard'
DIALOG_BATCH = 'batch'
DIALOG_MODELER = 'modeler'
Expand Down Expand Up @@ -115,3 +118,19 @@ def value(self):

if self.dialog in (DIALOG_BATCH, DIALOG_MODELER):
return self.widget.itemData(self.widget.currentIndex())


class CrsWidgetWrapper(WidgetWrapper):

def createWidget(self, extra_values=[]):
return CrsSelectionPanel()

def setValue(self, value):
if isinstance(value, basestring): # authId
self.widget.crs = value
else:
self.widget.crs = QgsCoordinateReferenceSystem(value).authid()
self.widget.updateText()

def value(self):
return self.widget.getValue()

0 comments on commit 6158e9b

Please sign in to comment.