Skip to content

Commit

Permalink
[processing] allow to use ParameterPoint in Graphical Modeler
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Feb 29, 2016
1 parent dd68c33 commit 317639f
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 10 deletions.
13 changes: 12 additions & 1 deletion python/plugins/processing/modeler/ModelerAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@
from processing.modeler.WrongModelException import WrongModelException
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.modeler.ModelerUtils import ModelerUtils
from processing.core.parameters import getParameterFromString, ParameterRaster, ParameterVector, ParameterTable, ParameterTableField, ParameterBoolean, ParameterString, ParameterNumber, ParameterExtent, ParameterDataObject, ParameterMultipleInput
from processing.core.parameters import (getParameterFromString,
ParameterRaster,
ParameterVector,
ParameterTable,
ParameterTableField,
ParameterBoolean,
ParameterString,
ParameterNumber,
ParameterExtent,
ParameterDataObject,
ParameterMultipleInput,
ParameterPoint)
from processing.tools import dataobjects
from processing.gui.Help2Html import getHtmlFromDescriptionsDict

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,28 @@
import math

from PyQt4.QtCore import Qt
from PyQt4.QtGui import QDialog, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QComboBox, QCheckBox, QDialogButtonBox, QMessageBox
from PyQt4.QtGui import (QDialog,
QVBoxLayout,
QHBoxLayout,
QLabel,
QLineEdit,
QComboBox,
QCheckBox,
QDialogButtonBox,
QMessageBox)

from processing.core.parameters import Parameter, ParameterBoolean, ParameterRaster, ParameterTable, ParameterVector, ParameterMultipleInput, ParameterNumber, ParameterString, ParameterTableField, ParameterExtent, ParameterFile
from processing.core.parameters import (Parameter,
ParameterBoolean,
ParameterRaster,
ParameterTable,
ParameterVector,
ParameterMultipleInput,
ParameterNumber,
ParameterString,
ParameterTableField,
ParameterExtent,
ParameterFile,
ParameterPoint)


class ModelerParameterDefinitionDialog(QDialog):
Expand All @@ -45,6 +64,7 @@ class ModelerParameterDefinitionDialog(QDialog):
PARAMETER_TABLE_FIELD = 'Table field'
PARAMETER_EXTENT = 'Extent'
PARAMETER_FILE = 'File'
PARAMETER_POINT = 'Point'

# To add
PARAMETER_MULTIPLE = 'Multiple input'
Expand All @@ -60,6 +80,7 @@ class ModelerParameterDefinitionDialog(QDialog):
PARAMETER_TABLE,
PARAMETER_TABLE_FIELD,
PARAMETER_VECTOR,
PARAMETER_POINT
]

def __init__(self, alg, paramType=None, param=None):
Expand Down Expand Up @@ -188,6 +209,14 @@ def setupUi(self):
1 if self.param.isFolder else 0)
self.horizontalLayout3.addWidget(self.fileFolderCombo)
self.verticalLayout.addLayout(self.horizontalLayout3)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_POINT or \
isinstance(self.param, ParameterPoint):
self.horizontalLayout3.addWidget(QLabel(self.tr('Default value')))
self.defaultTextBox = QLineEdit()
if self.param is not None:
self.defaultTextBox.setText(self.param.default)
self.horizontalLayout3.addWidget(self.defaultTextBox)
self.verticalLayout.addLayout(self.horizontalLayout3)

self.horizontalLayout2.addWidget(QLabel(self.tr('Required')))
self.yesNoCombo = QComboBox()
Expand Down Expand Up @@ -292,6 +321,10 @@ def okPressed(self):
isinstance(self.param, ParameterFile):
isFolder = self.fileFolderCombo.currentIndex() == 1
self.param = ParameterFile(name, description, isFolder=isFolder)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_POINT or \
isinstance(self.param, ParameterPoint):
self.param = ParameterPoint(name, description,
unicode(self.defaultTextBox.text()))
self.param.optional = self.yesNoCombo.currentIndex() == 1
self.close()

Expand Down
89 changes: 82 additions & 7 deletions python/plugins/processing/modeler/ModelerParametersDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,60 @@
__revision__ = '$Format:%H$'

from PyQt4.QtCore import Qt, QUrl, QMetaObject
from PyQt4.QtGui import QDialog, QDialogButtonBox, QLabel, QLineEdit, QFrame, QPushButton, QSizePolicy, QVBoxLayout, QHBoxLayout, QTabWidget, QWidget, QScrollArea, QComboBox, QTableWidgetItem, QMessageBox
from PyQt4.QtGui import (QDialog,
QDialogButtonBox,
QLabel,
QLineEdit,
QFrame,
QPushButton,
QSizePolicy,
QVBoxLayout,
QHBoxLayout,
QTabWidget,
QWidget,
QScrollArea,
QComboBox,
QTableWidgetItem,
QMessageBox)
from PyQt4.QtWebKit import QWebView

from processing.modeler.ModelerAlgorithm import ValueFromInput, \
ValueFromOutput, Algorithm, ModelerOutput
from processing.gui.CrsSelectionPanel import CrsSelectionPanel
from processing.gui.MultipleInputPanel import MultipleInputPanel
from processing.gui.FixedTablePanel import FixedTablePanel
from processing.gui.RangePanel import RangePanel
from processing.gui.GeometryPredicateSelectionPanel import \
GeometryPredicateSelectionPanel
from processing.core.parameters import (ParameterExtent,
ParameterRaster,
ParameterVector,
ParameterBoolean,
ParameterTable,
ParameterFixedTable,
ParameterMultipleInput,
ParameterSelection,
ParameterRange,
ParameterNumber,
ParameterString,
ParameterCrs,
ParameterTableField,
ParameterFile,
ParameterPoint,
ParameterGeometryPredicate)
from processing.core.outputs import (OutputRaster,
OutputVector,
OutputTable,
OutputHTML,
OutputFile,
OutputDirectory,
OutputNumber,
OutputString,
OutputExtent)

from processing.modeler.ModelerAlgorithm import (ValueFromInput,
ValueFromOutput,
Algorithm,
ModelerOutput)
from processing.modeler.MultilineTextPanel import MultilineTextPanel
from processing.core.parameters import ParameterExtent, ParameterRaster, ParameterVector, ParameterBoolean, ParameterTable, ParameterFixedTable, ParameterMultipleInput, ParameterSelection, ParameterRange, ParameterNumber, ParameterString, ParameterCrs, ParameterTableField, ParameterFile, ParameterGeometryPredicate
from processing.core.outputs import OutputRaster, OutputVector, OutputTable, OutputHTML, OutputFile, OutputDirectory, OutputNumber, OutputString, OutputExtent


class ModelerParametersDialog(QDialog):
Expand Down Expand Up @@ -109,7 +149,9 @@ def setupUi(self):
continue
desc = param.description
if isinstance(param, ParameterExtent):
desc += '(xmin, xmax, ymin, ymax)'
desc += self.tr('(xmin, xmax, ymin, ymax)')
if isinstance(param, ParameterPoint):
desc += self.tr('(x, y)')
label = QLabel(desc)
self.labels[param.name] = label
widget = self.getWidgetFromParameter(param)
Expand Down Expand Up @@ -335,6 +377,13 @@ def getWidgetFromParameter(self, param):
item.addItem(self.resolveValueDescription(ex), ex)
if not self.canUseAutoExtent():
item.setEditText(unicode(param.default))
elif isinstance(param, ParameterPoint):
item = QComboBox()
item.setEditable(True)
points = self.getAvailableValuesOfType(ParameterPoint)
for p in points:
item.addItem(self.resolveValueDescription(p), p)
item.setEditText(unicode(param.default))
elif isinstance(param, ParameterFile):
item = QComboBox()
item.setEditable(True)
Expand Down Expand Up @@ -427,7 +476,8 @@ def setPreviousValues(self):
ParameterNumber,
ParameterBoolean,
ParameterExtent,
ParameterFile
ParameterFile,
ParameterPoint
)):
self.setComboBoxValue(widget, value, param)
elif isinstance(param, ParameterString):
Expand Down Expand Up @@ -594,6 +644,29 @@ def setParamExtentValue(self, alg, param, widget):
alg.params[param.name] = value
return True

def setParamPointValue(self, alg, param, widget):
idx = widget.findText(widget.currentText())
if idx < 0:
s = unicode(widget.currentText()).strip()
if s:
try:
tokens = s.split(',')
if len(tokens) != 2:
return False
for token in tokens:
float(token)
except:
return False
elif param.optional:
s = None
else:
return False
alg.params[param.name] = [s]
else:
value = widget.itemData(widget.currentIndex())
alg.params[param.name] = value
return True

def setParamValue(self, alg, param, widget):
if isinstance(param, (ParameterRaster, ParameterVector,
ParameterTable)):
Expand All @@ -611,6 +684,8 @@ def setParamValue(self, alg, param, widget):
return self.setParamNumberValue(alg, param, widget)
elif isinstance(param, ParameterExtent):
return self.setParamExtentValue(alg, param, widget)
elif isinstance(param, ParameterPoint):
return self.setParamPointValue(alg, param, widget)
elif isinstance(param, ParameterFile):
return self.setParamFileValue(alg, param, widget)
elif isinstance(param, ParameterSelection):
Expand Down

0 comments on commit 317639f

Please sign in to comment.