30#include <QDialogButtonBox>
38#include "moc_qgsprocessingparameterdefinitionwidget.cpp"
42 , mWidgetContext( context )
48 mWidgetContext = context;
53 return mWidgetContext;
58 mContextGenerator = generator;
63 return QgsProcessingWidgetWrapperUtils::createExpressionContext( mContextGenerator, mWidgetContext,
nullptr,
nullptr );
76 QVBoxLayout *vlayout =
new QVBoxLayout();
78 QLabel *label =
new QLabel( tr(
"Description" ) );
79 vlayout->addWidget( label );
80 mDescriptionLineEdit =
new QLineEdit();
81 vlayout->addWidget( mDescriptionLineEdit );
85 mDescriptionLineEdit->setText( definition->
description() );
88 if ( mDefinitionWidget )
89 vlayout->addWidget( mDefinitionWidget );
91 vlayout->addSpacing( 20 );
92 mRequiredCheckBox =
new QCheckBox( tr(
"Mandatory" ) );
96 mRequiredCheckBox->setChecked(
true );
97 vlayout->addWidget( mRequiredCheckBox );
99 mAdvancedCheckBox =
new QCheckBox( tr(
"Advanced" ) );
103 mAdvancedCheckBox->setChecked(
false );
104 vlayout->addWidget( mAdvancedCheckBox );
106 vlayout->addStretch();
107 setLayout( vlayout );
112 std::unique_ptr<QgsProcessingParameterDefinition> param;
115 if ( !mRequiredCheckBox->isChecked() )
117 if ( mAdvancedCheckBox->isChecked() )
120 if ( mDefinitionWidget )
124 param.reset( mDefinitionWidget->createParameter( name, mDescriptionLineEdit->text(), flags ) );
132 param->setDescription( mDescriptionLineEdit->text() );
133 param->setFlags( flags );
137 return param.release();
142 if ( mDefinitionWidget )
144 mDefinitionWidget->registerProcessingContextGenerator( generator );
155 QVBoxLayout *vLayout =
new QVBoxLayout();
156 mTabWidget =
new QTabWidget();
157 vLayout->addWidget( mTabWidget );
159 QVBoxLayout *vLayout2 =
new QVBoxLayout();
161 vLayout2->addWidget( mWidget );
162 QWidget *w =
new QWidget();
163 w->setLayout( vLayout2 );
164 mTabWidget->addTab( w, tr(
"Properties" ) );
166 QVBoxLayout *commentLayout =
new QVBoxLayout();
167 mCommentEdit =
new QTextEdit();
168 mCommentEdit->setAcceptRichText(
false );
169 commentLayout->addWidget( mCommentEdit, 1 );
171 QHBoxLayout *hl =
new QHBoxLayout();
172 hl->setContentsMargins( 0, 0, 0, 0 );
173 hl->addWidget(
new QLabel( tr(
"Color" ) ) );
175 mCommentColorButton->setAllowOpacity(
true );
176 mCommentColorButton->setWindowTitle( tr(
"Comment Color" ) );
177 mCommentColorButton->setShowNull(
true, tr(
"Default" ) );
178 hl->addWidget( mCommentColorButton );
179 commentLayout->addLayout( hl );
181 QWidget *w2 =
new QWidget();
182 w2->setLayout( commentLayout );
183 mTabWidget->addTab( w2, tr(
"Comments" ) );
185 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
187 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsProcessingParameterDefinitionDialog::reject );
189 vLayout->addWidget( bbox );
190 setLayout( vLayout );
192 : tr(
"Parameter Definition" ) );
193 setObjectName( QStringLiteral(
"QgsProcessingParameterDefinitionDialog" ) );
199 return mWidget->createParameter( name );
204 mCommentEdit->setPlainText(
comments );
209 return mCommentEdit->toPlainText();
214 if ( color.isValid() )
215 mCommentColorButton->setColor( color );
217 mCommentColorButton->setToNull();
222 return !mCommentColorButton->isNull() ? mCommentColorButton->color() : QColor();
227 mTabWidget->setCurrentIndex( 1 );
228 mCommentEdit->setFocus();
229 mCommentEdit->selectAll();
236 mWidget->registerProcessingContextGenerator( generator );
242 if ( mWidget->mDescriptionLineEdit->text().isEmpty() )
244 QMessageBox::warning(
this, tr(
"Unable to define parameter" ), 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.
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.
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