Skip to content

Commit

Permalink
[sextante] improved handling of ParameterCrs
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Feb 24, 2013
1 parent 7e1f58f commit 10999cf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
9 changes: 7 additions & 2 deletions python/plugins/sextante/gui/CrsSelectionPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class CrsSelectionPanel(QtGui.QWidget):

def __init__(self, default):
super(CrsSelectionPanel, self).__init__(None)
super(CrsSelectionPanel, self).__init__(None)
self.authid = default
self.horizontalLayout = QtGui.QHBoxLayout(self)
self.horizontalLayout.setSpacing(2)
Expand All @@ -44,6 +44,10 @@ def __init__(self, default):
self.horizontalLayout.addWidget(self.pushButton)
self.setLayout(self.horizontalLayout)
self.setText()

def setAuthid(self, authid):
self.authid = authid
self.setText()

def showSelectionDialog(self):
dialog = CrsSelectionDialog()
Expand All @@ -53,7 +57,8 @@ def showSelectionDialog(self):
self.setText()

def setText(self):
self.text.setText(str(self.authid))
if self.authid is not None:
self.text.setText(str(self.authid))

def getValue(self):
return self.authid
3 changes: 1 addition & 2 deletions python/plugins/sextante/modeler/ModelerAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ def openModel(self, filename):
elif line.startswith("VALUE:"):
valueLine = line[len("VALUE:"):]
tokens = valueLine.split("===")

self.paramValues[tokens[0]] = tokens[1].replace(ModelerAlgorithm.LINE_BREAK_STRING, '\n')
elif line.startswith("NAME:"):
self.name = line[len("NAME:"):]
Expand Down Expand Up @@ -221,7 +220,7 @@ def removeAlgorithm(self, index):
for paramValues in self.algParameters:
index += 1
newValues = []
for name, value in paramValues:
for name, value in paramValues[index]:
if value:
if value.alg > index:
newValues[name] = AlgorithmAndParameter(value.alg - 1, value.param, value.algName, value.paramName)
Expand Down
18 changes: 16 additions & 2 deletions python/plugins/sextante/modeler/ModelerParametersDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* *
***************************************************************************
"""
from sextante.modeler.MultilineTextPanel import MultilineTextPanel

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
Expand All @@ -26,6 +26,8 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui, QtWebKit
from sextante.modeler.MultilineTextPanel import MultilineTextPanel
from sextante.gui.CrsSelectionPanel import CrsSelectionPanel
from sextante.parameters.ParameterCrs import ParameterCrs
from sextante.outputs.OutputString import OutputString
from sextante.parameters.ParameterRaster import ParameterRaster
Expand Down Expand Up @@ -437,6 +439,8 @@ def getWidgetFromParameter(self, param):
for n in numbers:
item.addItem(n.name(), n)
item.setEditText(str(param.default))
elif isinstance(param, ParameterCrs):
item = CrsSelectionPanel(param.default)
elif isinstance(param, ParameterExtent):
item = QtGui.QComboBox()
item.setEditable(True)
Expand Down Expand Up @@ -548,7 +552,7 @@ def setPreviousValues(self):
self.setComboBoxValue(widget, value, param)
elif isinstance(param, ParameterCrs):
value = self.model.getValueFromAlgorithmAndParameter(value)
widget.setText(unicode(value))
widget.setAuthid(value)
elif isinstance(param, ParameterFixedTable):
pass
elif isinstance(param, ParameterMultipleInput):
Expand Down Expand Up @@ -766,6 +770,16 @@ def setParamValue(self, param, widget):
self.params[param.name] = value
self.values[name] = str(widget.getValue())
return True
elif isinstance(param, ParameterCrs):
authid = widget.getValue()
if authid is None:
self.params[param.name] = None
else:
name = self.getSafeNameForHarcodedParameter(param)
value = AlgorithmAndParameter(AlgorithmAndParameter.PARENT_MODEL_ALGORITHM, name)
self.params[param.name] = value
self.values[name] = authid
return True
elif isinstance(param, ParameterFixedTable):
name = self.getSafeNameForHarcodedParameter(param)
value = AlgorithmAndParameter(AlgorithmAndParameter.PARENT_MODEL_ALGORITHM, name)
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/sextante/parameters/ParameterCrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def setValue(self, value):
if value is None:
self.value = self.default
return True
#TODO: check it is a valid authid
self.value = str(value)
return True

Expand All @@ -48,7 +49,9 @@ def serialize(self):
"|" + str(self.default)

def deserialize(self, s):
tokens = s.split("|")
tokens = s.split("|")
if tokens[2]==str(None):
tokens[2] = None
return ParameterCrs(tokens[0], tokens[1], tokens[2])

def getAsScriptCode(self):
Expand Down

0 comments on commit 10999cf

Please sign in to comment.