20#include "moc_qgsprocessingparameterdefinitionwidget.cpp"
32#include <QDialogButtonBox>
42 , mWidgetContext( context )
49 mWidgetContext = context;
54 return mWidgetContext;
59 mContextGenerator = generator;
64 return QgsProcessingGuiUtils::createExpressionContext( mContextGenerator, mWidgetContext,
nullptr,
nullptr );
81 QVBoxLayout *vlayout =
new QVBoxLayout();
83 QLabel *label =
new QLabel( tr(
"Description" ) );
84 vlayout->addWidget( label );
85 mDescriptionLineEdit =
new QLineEdit();
86 vlayout->addWidget( mDescriptionLineEdit );
90 mDescriptionLineEdit->setText( definition->
description() );
93 if ( mDefinitionWidget )
94 vlayout->addWidget( mDefinitionWidget );
96 vlayout->addSpacing( 20 );
97 mRequiredCheckBox =
new QCheckBox( tr(
"Mandatory" ) );
101 mRequiredCheckBox->setChecked(
true );
102 vlayout->addWidget( mRequiredCheckBox );
104 mAdvancedCheckBox =
new QCheckBox( tr(
"Advanced" ) );
108 mAdvancedCheckBox->setChecked(
false );
109 vlayout->addWidget( mAdvancedCheckBox );
111 vlayout->addStretch();
112 setLayout( vlayout );
117 std::unique_ptr< QgsProcessingParameterDefinition > param;
120 if ( !mRequiredCheckBox->isChecked() )
122 if ( mAdvancedCheckBox->isChecked() )
125 if ( mDefinitionWidget )
129 param.reset( mDefinitionWidget->
createParameter( name, mDescriptionLineEdit->text(), flags ) );
138 param->setFlags( flags );
142 return param.release();
147 if ( mDefinitionWidget )
165 QVBoxLayout *vLayout =
new QVBoxLayout();
166 mTabWidget =
new QTabWidget();
167 vLayout->addWidget( mTabWidget );
169 QVBoxLayout *vLayout2 =
new QVBoxLayout();
171 vLayout2->addWidget( mWidget );
172 QWidget *w =
new QWidget();
173 w->setLayout( vLayout2 );
174 mTabWidget->addTab( w, tr(
"Properties" ) );
176 QVBoxLayout *commentLayout =
new QVBoxLayout();
177 mCommentEdit =
new QTextEdit();
178 mCommentEdit->setAcceptRichText(
false );
179 commentLayout->addWidget( mCommentEdit, 1 );
181 QHBoxLayout *hl =
new QHBoxLayout();
182 hl->setContentsMargins( 0, 0, 0, 0 );
183 hl->addWidget(
new QLabel( tr(
"Color" ) ) );
186 mCommentColorButton->setWindowTitle( tr(
"Comment Color" ) );
187 mCommentColorButton->
setShowNull(
true, tr(
"Default" ) );
188 hl->addWidget( mCommentColorButton );
189 commentLayout->addLayout( hl );
191 QWidget *w2 =
new QWidget();
192 w2->setLayout( commentLayout );
193 mTabWidget->addTab( w2, tr(
"Comments" ) );
195 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
197 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsProcessingParameterDefinitionDialog::reject );
199 vLayout->addWidget( bbox );
200 setLayout( vLayout );
201 setWindowTitle( definition ? tr(
"%1 Parameter Definition" ).arg( definition->
description() )
203 tr(
"Parameter Definition" ) );
204 setObjectName( QStringLiteral(
"QgsProcessingParameterDefinitionDialog" ) );
215 mCommentEdit->setPlainText(
comments );
220 return mCommentEdit->toPlainText();
225 if ( color.isValid() )
226 mCommentColorButton->
setColor( color );
233 return !mCommentColorButton->
isNull() ? mCommentColorButton->
color() : QColor();
238 mTabWidget->setCurrentIndex( 1 );
239 mCommentEdit->setFocus();
240 mCommentEdit->selectAll();
253 if ( mWidget->mDescriptionLineEdit->text().isEmpty() )
255 QMessageBox::warning(
this, tr(
"Unable to define parameter" ),
256 tr(
"Invalid parameter name" ) );
QFlags< ProcessingParameterFlag > ProcessingParameterFlags
Flags which dictate the behavior of Processing parameters.
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
@ Optional
Parameter is optional.
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.
void setDescription(const QString &description)
Sets the description for the parameter.
Qgis::ProcessingParameterFlags 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