2012-10-04 19:33:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
ModelerParametersDialog.py
|
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
2016-09-21 18:24:26 +02:00
|
|
|
from builtins import str
|
2013-02-23 16:18:22 +01:00
|
|
|
|
2016-05-31 12:35:56 +02:00
|
|
|
|
2012-10-04 19:33:47 +02:00
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-04 19:33:47 +02:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-04 19:33:47 +02:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2016-04-22 10:38:48 +02:00
|
|
|
from qgis.PyQt.QtCore import Qt, QUrl, QMetaObject
|
2016-05-27 19:04:25 +03:00
|
|
|
from qgis.PyQt.QtWidgets import (QDialog, QDialogButtonBox, QLabel, QLineEdit,
|
|
|
|
QFrame, QPushButton, QSizePolicy, QVBoxLayout,
|
2017-03-20 10:18:18 +10:00
|
|
|
QHBoxLayout, QTabWidget, QWidget,
|
2017-03-04 19:41:23 +01:00
|
|
|
QTextBrowser)
|
2016-05-27 19:04:25 +03:00
|
|
|
from qgis.PyQt.QtNetwork import QNetworkRequest, QNetworkReply
|
|
|
|
|
2017-03-04 19:41:23 +01:00
|
|
|
from qgis.core import QgsNetworkAccessManager
|
2014-09-12 12:33:06 +03:00
|
|
|
|
2017-03-20 10:18:18 +10:00
|
|
|
from qgis.gui import (QgsMessageBar,
|
|
|
|
QgsScrollArea)
|
2016-05-31 12:35:56 +02:00
|
|
|
|
2016-09-08 09:57:18 +02:00
|
|
|
from processing.gui.wrappers import InvalidParameterValue
|
2013-10-01 20:52:22 +03:00
|
|
|
from processing.gui.MultipleInputPanel import MultipleInputPanel
|
2016-02-23 14:38:54 +02:00
|
|
|
from processing.core.outputs import (OutputRaster,
|
|
|
|
OutputVector,
|
|
|
|
OutputTable,
|
|
|
|
OutputHTML,
|
|
|
|
OutputFile,
|
2017-03-04 19:41:23 +01:00
|
|
|
OutputDirectory)
|
2016-09-12 06:17:23 +02:00
|
|
|
from processing.core.parameters import ParameterPoint, ParameterExtent
|
2016-02-23 14:38:54 +02:00
|
|
|
|
|
|
|
from processing.modeler.ModelerAlgorithm import (ValueFromInput,
|
|
|
|
ValueFromOutput,
|
|
|
|
Algorithm,
|
|
|
|
ModelerOutput)
|
2016-09-09 10:48:51 +02:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2014-09-12 12:33:06 +03:00
|
|
|
class ModelerParametersDialog(QDialog):
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
ENTER_NAME = '[Enter name if this is a final result]'
|
|
|
|
NOT_SELECTED = '[Not selected]'
|
|
|
|
USE_MIN_COVERING_EXTENT = '[Use min covering extent]'
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2014-06-08 00:21:12 +02:00
|
|
|
def __init__(self, alg, model, algName=None):
|
2014-09-12 12:33:06 +03:00
|
|
|
QDialog.__init__(self)
|
2012-09-15 18:25:25 +03:00
|
|
|
self.setModal(True)
|
2016-05-31 12:35:56 +02:00
|
|
|
# The algorithm to define in this dialog. It is an instance of GeoAlgorithm
|
2014-06-08 00:21:12 +02:00
|
|
|
self._alg = alg
|
2016-05-31 12:35:56 +02:00
|
|
|
# The resulting algorithm after the user clicks on OK. it is an instance of the container Algorithm class
|
2014-06-08 00:21:12 +02:00
|
|
|
self.alg = None
|
2016-05-31 12:35:56 +02:00
|
|
|
# The model this algorithm is going to be added to
|
2012-09-15 18:25:25 +03:00
|
|
|
self.model = model
|
2016-05-31 12:35:56 +02:00
|
|
|
# The name of the algorithm in the model, in case we are editing it and not defining it for the first time
|
2014-06-08 00:21:12 +02:00
|
|
|
self._algName = algName
|
2012-09-15 18:25:25 +03:00
|
|
|
self.setupUi()
|
|
|
|
self.params = None
|
|
|
|
|
|
|
|
def setupUi(self):
|
2012-10-12 19:14:39 +02:00
|
|
|
self.labels = {}
|
|
|
|
self.widgets = {}
|
|
|
|
self.checkBoxes = {}
|
|
|
|
self.showAdvanced = False
|
2016-09-07 14:30:20 +02:00
|
|
|
self.wrappers = {}
|
2012-09-15 18:25:25 +03:00
|
|
|
self.valueItems = {}
|
|
|
|
self.dependentItems = {}
|
|
|
|
self.resize(650, 450)
|
2014-09-12 12:33:06 +03:00
|
|
|
self.buttonBox = QDialogButtonBox()
|
|
|
|
self.buttonBox.setOrientation(Qt.Horizontal)
|
2017-03-04 19:41:23 +01:00
|
|
|
self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel |
|
|
|
|
QDialogButtonBox.Ok)
|
2014-06-08 00:21:12 +02:00
|
|
|
tooltips = self._alg.getParameterDescriptions()
|
2014-09-12 12:33:06 +03:00
|
|
|
self.setSizePolicy(QSizePolicy.Expanding,
|
|
|
|
QSizePolicy.Expanding)
|
|
|
|
self.verticalLayout = QVBoxLayout()
|
2012-10-12 19:14:39 +02:00
|
|
|
self.verticalLayout.setSpacing(5)
|
|
|
|
self.verticalLayout.setMargin(20)
|
2014-07-02 07:46:03 +02:00
|
|
|
|
2016-05-31 12:35:56 +02:00
|
|
|
self.bar = QgsMessageBar()
|
|
|
|
self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
|
|
|
|
self.verticalLayout.addWidget(self.bar)
|
|
|
|
|
2014-09-12 12:33:06 +03:00
|
|
|
hLayout = QHBoxLayout()
|
2014-06-08 00:21:12 +02:00
|
|
|
hLayout.setSpacing(5)
|
|
|
|
hLayout.setMargin(0)
|
2014-10-03 21:56:24 +03:00
|
|
|
descriptionLabel = QLabel(self.tr("Description"))
|
2014-09-12 12:33:06 +03:00
|
|
|
self.descriptionBox = QLineEdit()
|
2014-06-08 00:21:12 +02:00
|
|
|
self.descriptionBox.setText(self._alg.name)
|
|
|
|
hLayout.addWidget(descriptionLabel)
|
|
|
|
hLayout.addWidget(self.descriptionBox)
|
|
|
|
self.verticalLayout.addLayout(hLayout)
|
2014-09-12 12:33:06 +03:00
|
|
|
line = QFrame()
|
|
|
|
line.setFrameShape(QFrame.HLine)
|
|
|
|
line.setFrameShadow(QFrame.Sunken)
|
2014-06-08 00:21:12 +02:00
|
|
|
self.verticalLayout.addWidget(line)
|
2014-07-02 07:46:03 +02:00
|
|
|
|
2014-06-08 00:21:12 +02:00
|
|
|
for param in self._alg.parameters:
|
2012-10-12 19:14:39 +02:00
|
|
|
if param.isAdvanced:
|
2014-09-12 12:33:06 +03:00
|
|
|
self.advancedButton = QPushButton()
|
2014-10-03 21:56:24 +03:00
|
|
|
self.advancedButton.setText(self.tr('Show advanced parameters'))
|
2014-09-12 12:33:06 +03:00
|
|
|
self.advancedButton.clicked.connect(
|
|
|
|
self.showAdvancedParametersClicked)
|
2016-03-25 01:51:20 +03:00
|
|
|
advancedButtonHLayout = QHBoxLayout()
|
|
|
|
advancedButtonHLayout.addWidget(self.advancedButton)
|
|
|
|
advancedButtonHLayout.addStretch()
|
|
|
|
self.verticalLayout.addLayout(advancedButtonHLayout)
|
2012-10-12 19:14:39 +02:00
|
|
|
break
|
2014-06-08 00:21:12 +02:00
|
|
|
for param in self._alg.parameters:
|
2012-10-12 19:14:39 +02:00
|
|
|
if param.hidden:
|
|
|
|
continue
|
|
|
|
desc = param.description
|
|
|
|
if isinstance(param, ParameterExtent):
|
2016-02-23 14:38:54 +02:00
|
|
|
desc += self.tr('(xmin, xmax, ymin, ymax)')
|
|
|
|
if isinstance(param, ParameterPoint):
|
|
|
|
desc += self.tr('(x, y)')
|
2016-09-19 09:12:32 +02:00
|
|
|
if param.optional:
|
|
|
|
desc += self.tr(' [optional]')
|
2014-09-12 12:33:06 +03:00
|
|
|
label = QLabel(desc)
|
2012-10-12 19:14:39 +02:00
|
|
|
self.labels[param.name] = label
|
2016-09-03 02:25:30 +02:00
|
|
|
|
2016-09-07 14:30:20 +02:00
|
|
|
wrapper = param.wrapper(self)
|
|
|
|
self.wrappers[param.name] = wrapper
|
2016-09-03 02:25:30 +02:00
|
|
|
|
2016-08-23 14:48:11 +02:00
|
|
|
widget = wrapper.widget
|
2017-02-09 16:08:45 +01:00
|
|
|
if widget is not None:
|
2016-11-17 12:06:24 +01:00
|
|
|
self.valueItems[param.name] = widget
|
|
|
|
if param.name in list(tooltips.keys()):
|
|
|
|
tooltip = tooltips[param.name]
|
|
|
|
else:
|
|
|
|
tooltip = param.description
|
|
|
|
label.setToolTip(tooltip)
|
|
|
|
widget.setToolTip(tooltip)
|
|
|
|
if param.isAdvanced:
|
|
|
|
label.setVisible(self.showAdvanced)
|
|
|
|
widget.setVisible(self.showAdvanced)
|
|
|
|
self.widgets[param.name] = widget
|
2016-11-25 09:27:50 +02:00
|
|
|
|
2016-11-17 12:06:24 +01:00
|
|
|
self.verticalLayout.addWidget(label)
|
|
|
|
self.verticalLayout.addWidget(widget)
|
2012-10-12 19:14:39 +02:00
|
|
|
|
2014-06-08 00:21:12 +02:00
|
|
|
for output in self._alg.outputs:
|
2012-10-12 19:14:39 +02:00
|
|
|
if output.hidden:
|
|
|
|
continue
|
2013-10-01 20:52:22 +03:00
|
|
|
if isinstance(output, (OutputRaster, OutputVector, OutputTable,
|
2015-12-20 10:12:18 +01:00
|
|
|
OutputHTML, OutputFile, OutputDirectory)):
|
2017-03-04 19:41:23 +01:00
|
|
|
label = QLabel(output.description + '<' +
|
|
|
|
output.__class__.__name__ + '>')
|
2012-10-12 19:14:39 +02:00
|
|
|
item = QLineEdit()
|
|
|
|
if hasattr(item, 'setPlaceholderText'):
|
|
|
|
item.setPlaceholderText(ModelerParametersDialog.ENTER_NAME)
|
|
|
|
self.verticalLayout.addWidget(label)
|
|
|
|
self.verticalLayout.addWidget(item)
|
|
|
|
self.valueItems[output.name] = item
|
2013-02-07 01:09:39 +01:00
|
|
|
|
2014-09-12 12:33:06 +03:00
|
|
|
label = QLabel(' ')
|
2013-02-03 10:26:43 +01:00
|
|
|
self.verticalLayout.addWidget(label)
|
2014-10-03 21:56:24 +03:00
|
|
|
label = QLabel(self.tr('Parent algorithms'))
|
2013-02-07 01:09:39 +01:00
|
|
|
self.dependenciesPanel = self.getDependenciesPanel()
|
2013-02-03 10:26:43 +01:00
|
|
|
self.verticalLayout.addWidget(label)
|
|
|
|
self.verticalLayout.addWidget(self.dependenciesPanel)
|
2012-10-12 19:14:39 +02:00
|
|
|
self.verticalLayout.addStretch(1000)
|
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
self.setPreviousValues()
|
2014-06-08 00:21:12 +02:00
|
|
|
self.setWindowTitle(self._alg.name)
|
2014-09-12 12:33:06 +03:00
|
|
|
self.verticalLayout2 = QVBoxLayout()
|
2012-10-12 19:14:39 +02:00
|
|
|
self.verticalLayout2.setSpacing(2)
|
|
|
|
self.verticalLayout2.setMargin(0)
|
2014-09-12 12:33:06 +03:00
|
|
|
self.tabWidget = QTabWidget()
|
2012-12-10 00:12:07 +01:00
|
|
|
self.tabWidget.setMinimumWidth(300)
|
2014-09-12 12:33:06 +03:00
|
|
|
self.paramPanel = QWidget()
|
2012-10-12 19:14:39 +02:00
|
|
|
self.paramPanel.setLayout(self.verticalLayout)
|
2017-03-20 10:18:18 +10:00
|
|
|
self.scrollArea = QgsScrollArea()
|
2012-10-16 00:01:13 +02:00
|
|
|
self.scrollArea.setWidget(self.paramPanel)
|
|
|
|
self.scrollArea.setWidgetResizable(True)
|
2014-10-03 21:56:24 +03:00
|
|
|
self.tabWidget.addTab(self.scrollArea, self.tr('Parameters'))
|
2016-05-27 19:04:25 +03:00
|
|
|
|
|
|
|
self.txtHelp = QTextBrowser()
|
2014-04-19 22:04:24 +02:00
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
html = None
|
2016-05-27 19:04:25 +03:00
|
|
|
isText, algHelp = self._alg.help()
|
|
|
|
if algHelp is not None:
|
|
|
|
algHelp = algHelp if isText else QUrl(algHelp)
|
|
|
|
try:
|
|
|
|
if isText:
|
|
|
|
self.txtHelp.setHtml(algHelp)
|
|
|
|
else:
|
|
|
|
html = self.tr('<p>Downloading algorithm help... Please wait.</p>')
|
|
|
|
self.txtHelp.setHtml(html)
|
2016-09-19 09:12:32 +02:00
|
|
|
self.tabWidget.addTab(self.txtHelp, 'Help')
|
2016-05-27 19:04:25 +03:00
|
|
|
self.reply = QgsNetworkAccessManager.instance().get(QNetworkRequest(algHelp))
|
|
|
|
self.reply.finished.connect(self.requestFinished)
|
|
|
|
except:
|
2016-09-19 09:12:32 +02:00
|
|
|
pass
|
|
|
|
|
2012-10-12 19:14:39 +02:00
|
|
|
self.verticalLayout2.addWidget(self.tabWidget)
|
|
|
|
self.verticalLayout2.addWidget(self.buttonBox)
|
|
|
|
self.setLayout(self.verticalLayout2)
|
2014-09-12 12:33:06 +03:00
|
|
|
self.buttonBox.accepted.connect(self.okPressed)
|
|
|
|
self.buttonBox.rejected.connect(self.cancelPressed)
|
|
|
|
QMetaObject.connectSlotsByName(self)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2016-09-27 19:51:06 +02:00
|
|
|
for wrapper in list(self.wrappers.values()):
|
|
|
|
wrapper.postInitialize(list(self.wrappers.values()))
|
2016-09-18 12:56:24 +02:00
|
|
|
|
2016-05-27 19:04:25 +03:00
|
|
|
def requestFinished(self):
|
|
|
|
"""Change the webview HTML content"""
|
|
|
|
reply = self.sender()
|
|
|
|
if reply.error() != QNetworkReply.NoError:
|
|
|
|
html = self.tr('<h2>No help available for this algorithm</h2><p>{}</p>'.format(reply.errorString()))
|
|
|
|
else:
|
2016-09-21 18:24:26 +02:00
|
|
|
html = str(reply.readAll())
|
2016-05-27 19:04:25 +03:00
|
|
|
reply.deleteLater()
|
|
|
|
self.txtHelp.setHtml(html)
|
|
|
|
|
2017-01-23 09:24:31 +10:00
|
|
|
def getAvailableDependencies(self): # spellok
|
2014-06-08 00:21:12 +02:00
|
|
|
if self._algName is None:
|
2013-02-03 10:26:43 +01:00
|
|
|
dependent = []
|
|
|
|
else:
|
2014-06-08 00:21:12 +02:00
|
|
|
dependent = self.model.getDependentAlgorithms(self._algName)
|
2013-02-07 01:09:39 +01:00
|
|
|
opts = []
|
2016-09-21 18:24:26 +02:00
|
|
|
for alg in list(self.model.algs.values()):
|
2014-06-08 00:21:12 +02:00
|
|
|
if alg.name not in dependent:
|
2014-11-28 14:20:16 +01:00
|
|
|
opts.append(alg)
|
2013-02-03 10:26:43 +01:00
|
|
|
return opts
|
|
|
|
|
|
|
|
def getDependenciesPanel(self):
|
2017-01-23 09:24:31 +10:00
|
|
|
return MultipleInputPanel([alg.description for alg in self.getAvailableDependencies()]) # spellok
|
2013-02-07 01:09:39 +01:00
|
|
|
|
2012-10-17 22:03:40 +02:00
|
|
|
def showAdvancedParametersClicked(self):
|
|
|
|
self.showAdvanced = not self.showAdvanced
|
|
|
|
if self.showAdvanced:
|
2014-10-03 21:56:24 +03:00
|
|
|
self.advancedButton.setText(self.tr('Hide advanced parameters'))
|
2012-10-17 22:03:40 +02:00
|
|
|
else:
|
2014-10-03 21:56:24 +03:00
|
|
|
self.advancedButton.setText(self.tr('Show advanced parameters'))
|
2014-06-08 00:21:12 +02:00
|
|
|
for param in self._alg.parameters:
|
2012-10-17 22:03:40 +02:00
|
|
|
if param.isAdvanced:
|
|
|
|
self.labels[param.name].setVisible(self.showAdvanced)
|
|
|
|
self.widgets[param.name].setVisible(self.showAdvanced)
|
2012-12-10 00:12:07 +01:00
|
|
|
|
2016-08-08 15:37:33 +03:00
|
|
|
def getAvailableValuesOfType(self, paramType, outType=None, dataType=None):
|
2016-11-09 13:45:08 +10:00
|
|
|
# upgrade paramType to list
|
|
|
|
if type(paramType) is not list:
|
|
|
|
paramType = [paramType]
|
|
|
|
|
2014-06-08 00:21:12 +02:00
|
|
|
values = []
|
|
|
|
inputs = self.model.inputs
|
2016-09-21 18:24:26 +02:00
|
|
|
for i in list(inputs.values()):
|
2014-06-08 00:21:12 +02:00
|
|
|
param = i.param
|
2016-11-09 13:45:08 +10:00
|
|
|
for t in paramType:
|
|
|
|
if isinstance(param, t):
|
|
|
|
if dataType is not None:
|
|
|
|
if param.datatype in dataType:
|
|
|
|
values.append(ValueFromInput(param.name))
|
|
|
|
else:
|
2016-09-12 06:17:23 +02:00
|
|
|
values.append(ValueFromInput(param.name))
|
2016-11-09 13:45:08 +10:00
|
|
|
break
|
2014-06-08 00:21:12 +02:00
|
|
|
if outType is None:
|
|
|
|
return values
|
|
|
|
if self._algName is None:
|
2012-09-15 18:25:25 +03:00
|
|
|
dependent = []
|
|
|
|
else:
|
2014-06-08 00:21:12 +02:00
|
|
|
dependent = self.model.getDependentAlgorithms(self._algName)
|
2016-09-21 18:24:26 +02:00
|
|
|
for alg in list(self.model.algs.values()):
|
2014-06-08 00:21:12 +02:00
|
|
|
if alg.name not in dependent:
|
|
|
|
for out in alg.algorithm.outputs:
|
|
|
|
if isinstance(out, outType):
|
2016-08-08 16:45:40 +03:00
|
|
|
if dataType is not None and out.datatype in dataType:
|
2016-08-08 15:38:28 +03:00
|
|
|
values.append(ValueFromOutput(alg.name, out.name))
|
|
|
|
else:
|
|
|
|
values.append(ValueFromOutput(alg.name, out.name))
|
2014-06-08 00:21:12 +02:00
|
|
|
|
|
|
|
return values
|
2014-07-02 07:46:03 +02:00
|
|
|
|
2014-06-08 00:21:12 +02:00
|
|
|
def resolveValueDescription(self, value):
|
|
|
|
if isinstance(value, ValueFromInput):
|
|
|
|
return self.model.inputs[value.name].param.description
|
2012-09-15 18:25:25 +03:00
|
|
|
else:
|
2014-06-08 00:21:12 +02:00
|
|
|
alg = self.model.algs[value.alg]
|
2017-03-04 16:23:36 +01:00
|
|
|
return self.tr("'{0}' from algorithm '{1}'").format(alg.algorithm.getOutputFromName(value.output).description, alg.description)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2014-07-02 07:46:03 +02:00
|
|
|
def setPreviousValues(self):
|
|
|
|
if self._algName is not None:
|
2014-06-08 00:21:12 +02:00
|
|
|
alg = self.model.algs[self._algName]
|
|
|
|
self.descriptionBox.setText(alg.description)
|
|
|
|
for param in alg.algorithm.parameters:
|
|
|
|
if param.hidden:
|
|
|
|
continue
|
2015-03-25 17:46:30 +01:00
|
|
|
if param.name in alg.params:
|
|
|
|
value = alg.params[param.name]
|
|
|
|
else:
|
2016-04-27 10:10:18 +02:00
|
|
|
value = param.default
|
2016-09-12 06:17:23 +02:00
|
|
|
self.wrappers[param.name].setValue(value)
|
2016-09-27 19:51:06 +02:00
|
|
|
for name, out in list(alg.outputs.items()):
|
2016-09-12 06:17:23 +02:00
|
|
|
self.valueItems[name].setText(out.description)
|
2013-02-07 01:09:39 +01:00
|
|
|
|
2013-02-03 10:26:43 +01:00
|
|
|
selected = []
|
2017-01-23 09:24:31 +10:00
|
|
|
dependencies = self.getAvailableDependencies() # spellok
|
2014-06-08 00:21:12 +02:00
|
|
|
for idx, dependency in enumerate(dependencies):
|
2015-08-21 10:33:26 +02:00
|
|
|
if dependency.name in alg.dependencies:
|
2014-06-08 00:21:12 +02:00
|
|
|
selected.append(idx)
|
2013-02-07 01:09:39 +01:00
|
|
|
|
2013-02-03 10:26:43 +01:00
|
|
|
self.dependenciesPanel.setSelectedItems(selected)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2014-06-08 00:21:12 +02:00
|
|
|
def createAlgorithm(self):
|
|
|
|
alg = Algorithm(self._alg.commandLineName())
|
|
|
|
alg.setName(self.model)
|
2014-07-02 07:46:03 +02:00
|
|
|
alg.description = self.descriptionBox.text()
|
2014-06-08 00:21:12 +02:00
|
|
|
params = self._alg.parameters
|
|
|
|
outputs = self._alg.outputs
|
2012-09-15 18:25:25 +03:00
|
|
|
for param in params:
|
|
|
|
if param.hidden:
|
|
|
|
continue
|
2016-09-07 14:30:20 +02:00
|
|
|
if not self.setParamValue(alg, param, self.wrappers[param.name]):
|
2016-05-31 12:35:56 +02:00
|
|
|
self.bar.pushMessage("Error", "Wrong or missing value for parameter '%s'" % param.description,
|
|
|
|
level=QgsMessageBar.WARNING)
|
2014-06-08 00:21:12 +02:00
|
|
|
return None
|
2012-09-15 18:25:25 +03:00
|
|
|
for output in outputs:
|
2014-06-08 00:21:12 +02:00
|
|
|
if not output.hidden:
|
2016-09-21 18:24:26 +02:00
|
|
|
name = str(self.valueItems[output.name].text())
|
2014-06-08 00:21:12 +02:00
|
|
|
if name.strip() != '' and name != ModelerParametersDialog.ENTER_NAME:
|
2014-08-14 10:56:08 +02:00
|
|
|
alg.outputs[output.name] = ModelerOutput(name)
|
2013-02-07 01:09:39 +01:00
|
|
|
|
2013-02-03 10:26:43 +01:00
|
|
|
selectedOptions = self.dependenciesPanel.selectedoptions
|
2017-01-23 09:24:31 +10:00
|
|
|
availableDependencies = self.getAvailableDependencies() # spellok
|
2013-02-03 10:26:43 +01:00
|
|
|
for selected in selectedOptions:
|
2017-01-23 09:24:31 +10:00
|
|
|
alg.dependencies.append(availableDependencies[selected].name) # spellok
|
2013-02-07 01:09:39 +01:00
|
|
|
|
2016-11-17 12:06:24 +01:00
|
|
|
self._alg.processBeforeAddingToModeler(alg, self.model)
|
2014-06-08 00:21:12 +02:00
|
|
|
return alg
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2016-08-23 14:48:11 +02:00
|
|
|
def setParamValue(self, alg, param, wrapper):
|
2016-09-07 14:30:20 +02:00
|
|
|
try:
|
2016-11-17 12:06:24 +01:00
|
|
|
if wrapper.widget:
|
|
|
|
value = wrapper.value()
|
|
|
|
alg.params[param.name] = value
|
2012-09-15 18:25:25 +03:00
|
|
|
return True
|
2016-09-07 14:30:20 +02:00
|
|
|
except InvalidParameterValue:
|
|
|
|
return False
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def okPressed(self):
|
2014-06-08 00:21:12 +02:00
|
|
|
self.alg = self.createAlgorithm()
|
|
|
|
if self.alg is not None:
|
2012-09-15 18:25:25 +03:00
|
|
|
self.close()
|
2016-05-31 12:35:56 +02:00
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
def cancelPressed(self):
|
2014-06-08 00:21:12 +02:00
|
|
|
self.alg = None
|
2012-09-15 18:25:25 +03:00
|
|
|
self.close()
|