31#include <QDialogButtonBox>
41 , mWidgetContext( context )
48 mWidgetContext = context;
53 return mWidgetContext;
58 mContextGenerator = generator;
63 return QgsProcessingGuiUtils::createExpressionContext( mContextGenerator, mWidgetContext,
nullptr,
nullptr );
80 QVBoxLayout *vlayout =
new QVBoxLayout();
82 QLabel *label =
new QLabel( tr(
"Description" ) );
83 vlayout->addWidget( label );
84 mDescriptionLineEdit =
new QLineEdit();
85 vlayout->addWidget( mDescriptionLineEdit );
89 mDescriptionLineEdit->setText( definition->
description() );
92 if ( mDefinitionWidget )
93 vlayout->addWidget( mDefinitionWidget );
95 vlayout->addSpacing( 20 );
96 mRequiredCheckBox =
new QCheckBox( tr(
"Mandatory" ) );
100 mRequiredCheckBox->setChecked(
true );
101 vlayout->addWidget( mRequiredCheckBox );
103 mAdvancedCheckBox =
new QCheckBox( tr(
"Advanced" ) );
107 mAdvancedCheckBox->setChecked(
false );
108 vlayout->addWidget( mAdvancedCheckBox );
110 vlayout->addStretch();
111 setLayout( vlayout );
116 std::unique_ptr< QgsProcessingParameterDefinition > param;
117 QgsProcessingParameterDefinition::Flags flags = QgsProcessingParameterDefinition::Flags();
119 if ( !mRequiredCheckBox->isChecked() )
121 if ( mAdvancedCheckBox->isChecked() )
124 if ( mDefinitionWidget )
128 param.reset( mDefinitionWidget->
createParameter( name, mDescriptionLineEdit->text(), flags ) );
136 param->setDescription( mDescriptionLineEdit->text() );
137 param->setFlags( flags );
141 return param.release();
146 if ( mDefinitionWidget )
164 QVBoxLayout *vLayout =
new QVBoxLayout();
165 mTabWidget =
new QTabWidget();
166 vLayout->addWidget( mTabWidget );
168 QVBoxLayout *vLayout2 =
new QVBoxLayout();
170 vLayout2->addWidget( mWidget );
171 QWidget *w =
new QWidget();
172 w->setLayout( vLayout2 );
173 mTabWidget->addTab( w, tr(
"Properties" ) );
175 QVBoxLayout *commentLayout =
new QVBoxLayout();
176 mCommentEdit =
new QTextEdit();
177 mCommentEdit->setAcceptRichText(
false );
178 commentLayout->addWidget( mCommentEdit, 1 );
180 QHBoxLayout *hl =
new QHBoxLayout();
181 hl->setContentsMargins( 0, 0, 0, 0 );
182 hl->addWidget(
new QLabel( tr(
"Color" ) ) );
185 mCommentColorButton->setWindowTitle( tr(
"Comment Color" ) );
186 mCommentColorButton->
setShowNull(
true, tr(
"Default" ) );
187 hl->addWidget( mCommentColorButton );
188 commentLayout->addLayout( hl );
190 QWidget *w2 =
new QWidget();
191 w2->setLayout( commentLayout );
192 mTabWidget->addTab( w2, tr(
"Comments" ) );
194 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
196 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsProcessingParameterDefinitionDialog::reject );
198 vLayout->addWidget( bbox );
199 setLayout( vLayout );
200 setWindowTitle( definition ? tr(
"%1 Parameter Definition" ).arg( definition->
description() )
202 tr(
"Parameter Definition" ) );
203 setObjectName( QStringLiteral(
"QgsProcessingParameterDefinitionDialog" ) );
214 mCommentEdit->setPlainText(
comments );
219 return mCommentEdit->toPlainText();
224 if ( color.isValid() )
225 mCommentColorButton->
setColor( color );
232 return !mCommentColorButton->
isNull() ? mCommentColorButton->
color() : QColor();
237 mTabWidget->setCurrentIndex( 1 );
238 mCommentEdit->setFocus();
239 mCommentEdit->selectAll();
252 if ( mWidget->mDescriptionLineEdit->text().isEmpty() )
254 QMessageBox::warning(
this, tr(
"Unable to define parameter" ),
255 tr(
"Invalid parameter name" ) );
static QgsProcessingRegistry * processingRegistry()
Returns the application's processing registry, used for managing processing providers,...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
static QgsProcessingGuiRegistry * processingGuiRegistry()
Returns the global processing gui registry, used for registering the GUI behavior of processing algor...
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Abstract base class for processing algorithms.
An interface for objects which can create Processing contexts.
Contains information about the context in which a processing algorithm is executed.
QgsProcessingAbstractParameterDefinitionWidget * createParameterDefinitionWidget(const QString &type, QgsProcessingContext &context, const QgsProcessingParameterWidgetContext &widgetContext, const QgsProcessingParameterDefinition *definition=nullptr, const QgsProcessingAlgorithm *algorithm=nullptr)
Creates a new parameter definition widget allowing for configuration of an instance of a specific par...
void registerProcessingContextGenerator(QgsProcessingContextGenerator *generator)
Registers a Processing context generator class that will be used to retrieve a Processing context for...
void setComments(const QString &comments)
Sets the comments for the parameter.
void switchToCommentTab()
Switches the dialog to the comments tab.
QgsProcessingParameterDefinitionDialog(const QString &type, QgsProcessingContext &context, const QgsProcessingParameterWidgetContext &widgetContext, const QgsProcessingParameterDefinition *definition=nullptr, const QgsProcessingAlgorithm *algorithm=nullptr, QWidget *parent=nullptr)
Constructor for QgsProcessingParameterDefinitionDialog, for a parameter of the specified type.
void setCommentColor(const QColor &color)
Sets the color for the comments for the parameter.
QgsProcessingParameterDefinition * createParameter(const QString &name=QString()) const
Returns a new instance of a parameter definition, using the current settings defined in the dialog.
QString comments() const
Returns the comments for the parameter.
QColor commentColor() const
Returns the color for the comments for the parameter.
Base class for the definition of processing parameters.
QString description() const
Returns the description for the parameter.
@ FlagAdvanced
Parameter is an advanced parameter which should be hidden from users by default.
@ FlagOptional
Parameter is optional.
Flags flags() const
Returns any flags associated with the parameter.
Contains settings which reflect the context in which a Processing parameter widget is shown,...
QgsProcessingParameterType * parameterType(const QString &id) const
Returns the parameter type registered for id.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call