Port getCustomParametersDialog to QgsProcessingAlgorithm

This commit is contained in:
Nyall Dawson 2017-05-15 12:46:59 +10:00
parent fb811766f8
commit 1e788556f0
9 changed files with 28 additions and 11 deletions

View File

@ -184,6 +184,15 @@ class QgsProcessingAlgorithm
:rtype: QVariantMap
%End
virtual QWidget *createCustomParametersWidget( QWidget *parent = 0 ) const /Factory/;
%Docstring
If an algorithm subclass implements a custom parameters widget, a copy of this widget
should be constructed and returned by this method.
The base class implementation returns None, which indicates that an autogenerated
parameters widget should be used.
:rtype: QWidget
%End
protected:
bool addParameter( QgsProcessingParameterDefinition *parameterDefinition /Transfer/ );

View File

@ -55,7 +55,7 @@ class GdalAlgorithm(GeoAlgorithm):
def svgIconPath(self):
return QgsApplication.iconPath("providerGdal.svg")
def getCustomParametersDialog(self):
def createCustomParametersWidget(self, parent):
return GdalAlgorithmDialog(self)
def processAlgorithm(self, context, feedback):

View File

@ -169,5 +169,5 @@ class FieldsCalculator(GeoAlgorithm):
if newField and len(fieldName) == 0:
return self.tr('Field name is not set. Please enter a field name')
def getCustomParametersDialog(self):
def createCustomParametersWidget(self, parent):
return FieldsCalculatorDialog(self)

View File

@ -106,12 +106,6 @@ class GeoAlgorithm(QgsProcessingAlgorithm):
def getParametersPanel(self, parent):
return ParametersPanel(parent, self)
def getCustomParametersDialog(self):
"""If the algorithm has a custom parameters dialog, it should
be returned here, ready to be executed.
"""
return None
def getCustomModelerParametersDialog(self, modelAlg, algName=None):
"""If the algorithm has a custom parameters dialog when called
from the modeler, it should be returned here, ready to be

View File

@ -266,7 +266,7 @@ class ProcessingToolbox(BASE, WIDGET):
return
if alg.countVisibleParameters() > 0:
dlg = alg.getCustomParametersDialog()
dlg = alg.createCustomParametersWidget(self)
if not dlg:
dlg = AlgorithmDialog(alg)
canvas = iface.mapCanvas()

View File

@ -269,7 +269,7 @@ class ScriptEditorDialog(BASE, WIDGET):
if self.algType == self.SCRIPT_PYTHON:
alg = ScriptAlgorithm(None, self.editor.text())
dlg = alg.getCustomParametersDialog()
dlg = alg.createCustomParametersWidget(self)
if not dlg:
dlg = AlgorithmDialog(alg)

View File

@ -205,7 +205,7 @@ def _executeAlgorithm(alg):
context = dataobjects.createContext()
if (alg.countVisibleParameters()) > 0:
dlg = alg.getCustomParametersDialog()
dlg = alg.createCustomParametersWidget(None)
if not dlg:
dlg = AlgorithmDialog(alg)
canvas = iface.mapCanvas()

View File

@ -71,6 +71,11 @@ QVariantMap QgsProcessingAlgorithm::run( const QVariantMap &, QgsProcessingConte
return QVariantMap();
}
QWidget *QgsProcessingAlgorithm::createCustomParametersWidget( QWidget * ) const
{
return nullptr;
}
bool QgsProcessingAlgorithm::addParameter( QgsProcessingParameterDefinition *definition )
{
if ( !definition )

View File

@ -29,6 +29,7 @@
class QgsProcessingProvider;
class QgsProcessingContext;
class QgsProcessingFeedback;
class QWidget;
/**
* \class QgsProcessingAlgorithm
@ -189,6 +190,14 @@ class CORE_EXPORT QgsProcessingAlgorithm
virtual QVariantMap run( const QVariantMap &parameters,
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) const;
/**
* If an algorithm subclass implements a custom parameters widget, a copy of this widget
* should be constructed and returned by this method.
* The base class implementation returns nullptr, which indicates that an autogenerated
* parameters widget should be used.
*/
virtual QWidget *createCustomParametersWidget( QWidget *parent = nullptr ) const SIP_FACTORY;
protected:
/**