Use flags for parameter type extra info

This commit is contained in:
Matthias Kuhn 2018-03-06 07:18:36 -05:00 committed by Nyall Dawson
parent e3dabac78a
commit c3a843619f
4 changed files with 24 additions and 7 deletions

View File

@ -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.
@ -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.

View File

@ -620,14 +620,12 @@ class ModelerDialog(BASE, WIDGET):
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())

View File

@ -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

View File

@ -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.
*/
@ -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.