30#include <QDialogButtonBox>
39#include "moc_qgsprocessingparameterdefinitionwidget.cpp"
41using namespace Qt::StringLiterals;
45 , mWidgetContext( context )
51 mWidgetContext = context;
56 return mWidgetContext;
61 mContextGenerator = generator;
66 return QgsProcessingWidgetWrapperUtils::createExpressionContext( mContextGenerator, mWidgetContext,
nullptr,
nullptr );
79 QVBoxLayout *vlayout =
new QVBoxLayout();
81 QLabel *label =
new QLabel( tr(
"Description" ) );
82 vlayout->addWidget( label );
83 mDescriptionLineEdit =
new QLineEdit();
84 vlayout->addWidget( mDescriptionLineEdit );
88 mDescriptionLineEdit->setText( definition->
description() );
91 if ( mDefinitionWidget )
92 vlayout->addWidget( mDefinitionWidget );
94 vlayout->addSpacing( 20 );
95 mRequiredCheckBox =
new QCheckBox( tr(
"Mandatory" ) );
99 mRequiredCheckBox->setChecked(
true );
100 vlayout->addWidget( mRequiredCheckBox );
102 mAdvancedCheckBox =
new QCheckBox( tr(
"Advanced" ) );
106 mAdvancedCheckBox->setChecked(
false );
107 vlayout->addWidget( mAdvancedCheckBox );
109 vlayout->addStretch();
110 setLayout( vlayout );
115 std::unique_ptr<QgsProcessingParameterDefinition> param;
118 if ( !mRequiredCheckBox->isChecked() )
120 if ( mAdvancedCheckBox->isChecked() )
123 if ( mDefinitionWidget )
127 param.reset( mDefinitionWidget->createParameter( name, mDescriptionLineEdit->text(), flags ) );
135 param->setDescription( mDescriptionLineEdit->text() );
136 param->setFlags( flags );
140 return param.release();
145 if ( mDefinitionWidget )
147 mDefinitionWidget->registerProcessingContextGenerator( generator );
158 QVBoxLayout *vLayout =
new QVBoxLayout();
159 mTabWidget =
new QTabWidget();
160 vLayout->addWidget( mTabWidget );
162 QVBoxLayout *vLayout2 =
new QVBoxLayout();
164 vLayout2->addWidget( mWidget );
165 QWidget *w =
new QWidget();
166 w->setLayout( vLayout2 );
167 mTabWidget->addTab( w, tr(
"Properties" ) );
169 QVBoxLayout *commentLayout =
new QVBoxLayout();
170 mCommentEdit =
new QTextEdit();
171 mCommentEdit->setAcceptRichText(
false );
172 commentLayout->addWidget( mCommentEdit, 1 );
174 QHBoxLayout *hl =
new QHBoxLayout();
175 hl->setContentsMargins( 0, 0, 0, 0 );
176 hl->addWidget(
new QLabel( tr(
"Color" ) ) );
178 mCommentColorButton->setAllowOpacity(
true );
179 mCommentColorButton->setWindowTitle( tr(
"Comment Color" ) );
180 mCommentColorButton->setShowNull(
true, tr(
"Default" ) );
181 hl->addWidget( mCommentColorButton );
182 commentLayout->addLayout( hl );
184 QWidget *w2 =
new QWidget();
185 w2->setLayout( commentLayout );
186 mTabWidget->addTab( w2, tr(
"Comments" ) );
188 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
190 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsProcessingParameterDefinitionDialog::reject );
192 vLayout->addWidget( bbox );
193 setLayout( vLayout );
195 : tr(
"Parameter Definition" ) );
196 setObjectName( u
"QgsProcessingParameterDefinitionDialog"_s );
202 return mWidget->createParameter( name );
207 mCommentEdit->setPlainText(
comments );
212 return mCommentEdit->toPlainText();
217 if ( color.isValid() )
218 mCommentColorButton->setColor( color );
220 mCommentColorButton->setToNull();
225 return !mCommentColorButton->isNull() ? mCommentColorButton->color() : QColor();
230 mTabWidget->setCurrentIndex( 1 );
231 mCommentEdit->setFocus();
232 mCommentEdit->selectAll();
239 mWidget->registerProcessingContextGenerator( generator );
245 if ( mWidget->mDescriptionLineEdit->text().isEmpty() )
247 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