Skip to content

Commit

Permalink
Port getCustomParametersDialog to QgsProcessingAlgorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 5, 2017
1 parent fb81176 commit 1e78855
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 11 deletions.
9 changes: 9 additions & 0 deletions python/core/processing/qgsprocessingalgorithm.sip
Expand Up @@ -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/ );
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/GdalAlgorithm.py
Expand Up @@ -55,7 +55,7 @@ def icon(self):
def svgIconPath(self):
return QgsApplication.iconPath("providerGdal.svg")

def getCustomParametersDialog(self):
def createCustomParametersWidget(self, parent):
return GdalAlgorithmDialog(self)

def processAlgorithm(self, context, feedback):
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/FieldsCalculator.py
Expand Up @@ -169,5 +169,5 @@ def checkParameterValuesBeforeExecuting(self):
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)
6 changes: 0 additions & 6 deletions python/plugins/processing/core/GeoAlgorithm.py
Expand Up @@ -106,12 +106,6 @@ def defineCharacteristics(self):
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
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/ProcessingToolbox.py
Expand Up @@ -266,7 +266,7 @@ def executeAlgorithm(self):
return

if alg.countVisibleParameters() > 0:
dlg = alg.getCustomParametersDialog()
dlg = alg.createCustomParametersWidget(self)
if not dlg:
dlg = AlgorithmDialog(alg)
canvas = iface.mapCanvas()
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/ScriptEditorDialog.py
Expand Up @@ -269,7 +269,7 @@ def runAlgorithm(self):
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)

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/menus.py
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions src/core/processing/qgsprocessingalgorithm.cpp
Expand Up @@ -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 )
Expand Down
9 changes: 9 additions & 0 deletions src/core/processing/qgsprocessingalgorithm.h
Expand Up @@ -29,6 +29,7 @@
class QgsProcessingProvider;
class QgsProcessingContext;
class QgsProcessingFeedback;
class QWidget;

/**
* \class QgsProcessingAlgorithm
Expand Down Expand Up @@ -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:

/**
Expand Down

0 comments on commit 1e78855

Please sign in to comment.