Skip to content

Commit

Permalink
Use flags for parameter type extra info
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn authored and nyalldawson committed Mar 6, 2018
1 parent e3dabac commit c3a8436
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
10 changes: 9 additions & 1 deletion python/core/processing/qgsprocessingparametertype.sip.in
Expand Up @@ -23,6 +23,14 @@ Makes metadata of processing parameters available.
%End
public:

enum ParameterFlag
{
ExposeToModeler
};
typedef QFlags<QgsProcessingParameterType::ParameterFlag> ParameterFlags;



virtual QgsProcessingParameterDefinition *create( const QString &name ) const = 0 /Factory/;
%Docstring
Creates a new parameter of this type.
Expand All @@ -48,7 +56,7 @@ This will be used in comboboxes and list widgets.
A static id for this type which will be used for storing this parameter type.
%End

virtual bool exposeToModeler() const;
virtual ParameterFlags flags() const;
%Docstring
Determines if this parameter is available in the modeler.
The default implementation returns true.
Expand Down
4 changes: 1 addition & 3 deletions python/plugins/processing/modeler/ModelerDialog.py
Expand Up @@ -620,14 +620,12 @@ def _filterItem(self, item, text):
return False

def fillInputsTree(self):
from processing.core.Processing import Processing

icon = QIcon(os.path.join(pluginPath, 'images', 'input.svg'))
parametersItem = QTreeWidgetItem()
parametersItem.setText(0, self.tr('Parameters'))
sortedParams = sorted(QgsApplication.instance().processingRegistry().parameterTypes(), key=lambda pt: pt.name())
for param in sortedParams:
if param.exposeToModeller():
if param.flags() & QgsProcessingParameterType.ExposeToModeler:
paramItem = QTreeWidgetItem()
paramItem.setText(0, param.name())
paramItem.setData(0, Qt.UserRole, param.id())
Expand Down
4 changes: 2 additions & 2 deletions src/core/processing/qgsprocessingparametertype.cpp
Expand Up @@ -17,9 +17,9 @@

#include "qgsprocessingparametertype.h"

bool QgsProcessingParameterType::exposeToModeler() const
QgsProcessingParameterType::ParameterFlags QgsProcessingParameterType::flags() const
{
return true;
return QgsProcessingParameterType::ExposeToModeler;
}

QVariantMap QgsProcessingParameterType::metadata() const
Expand Down
13 changes: 12 additions & 1 deletion src/core/processing/qgsprocessingparametertype.h
Expand Up @@ -34,6 +34,17 @@ class CORE_EXPORT QgsProcessingParameterType
{
public:

/**
* Each parameter type can offer a number of additional flags to finetune its behavior
* and capabilities.
*/
enum ParameterFlag
{
ExposeToModeler = 1 //!< Is this parameter available in the modeler. Is set to on by default.
};
Q_DECLARE_FLAGS( ParameterFlags, ParameterFlag )


/**
* Creates a new parameter of this type.
*/
Expand Down Expand Up @@ -66,7 +77,7 @@ class CORE_EXPORT QgsProcessingParameterType
* Determines if this parameter is available in the modeler.
* The default implementation returns true.
*/
virtual bool exposeToModeler() const;
virtual ParameterFlags flags() const;

/**
* Metadata for this parameter type. Can be used for example to define custom widgets.
Expand Down

0 comments on commit c3a8436

Please sign in to comment.