30#include <QDialogButtonBox>
39#include "moc_qgsprocessingparameterdefinitionwidget.cpp"
41using namespace Qt::StringLiterals;
47 , mWidgetContext( context )
52 mWidgetContext = context;
57 return mWidgetContext;
62 mContextGenerator = generator;
67 return QgsProcessingWidgetWrapperUtils::createExpressionContext( mContextGenerator, mWidgetContext,
nullptr,
nullptr );
87 QVBoxLayout *vlayout =
new QVBoxLayout();
89 QLabel *label =
new QLabel( tr(
"Description" ) );
90 vlayout->addWidget( label );
91 mDescriptionLineEdit =
new QLineEdit();
92 vlayout->addWidget( mDescriptionLineEdit );
96 mDescriptionLineEdit->setText( definition->
description() );
100 if ( mDefinitionWidget )
103 vlayout->addWidget( mDefinitionWidget );
106 vlayout->addSpacing( 20 );
107 mRequiredCheckBox =
new QCheckBox( tr(
"Mandatory" ) );
111 mRequiredCheckBox->setChecked(
true );
114 vlayout->addWidget( mRequiredCheckBox );
116 mAdvancedCheckBox =
new QCheckBox( tr(
"Advanced" ) );
120 mAdvancedCheckBox->setChecked(
false );
122 vlayout->addWidget( mAdvancedCheckBox );
124 vlayout->addStretch();
125 setLayout( vlayout );
130 std::unique_ptr<QgsProcessingParameterDefinition> param;
133 if ( !mRequiredCheckBox->isChecked() )
135 if ( mAdvancedCheckBox->isChecked() )
138 if ( mDefinitionWidget )
142 param.reset( mDefinitionWidget->createParameter( name, mDescriptionLineEdit->text(), flags ) );
150 param->setDescription( mDescriptionLineEdit->text() );
151 param->setFlags( flags );
155 return param.release();
160 if ( mDefinitionWidget )
162 mDefinitionWidget->registerProcessingContextGenerator( generator );
181 QVBoxLayout *vLayout =
new QVBoxLayout();
182 vLayout->setContentsMargins( 0, 0, 0, 0 );
183 mTabWidget =
new QTabWidget();
184 vLayout->addWidget( mTabWidget );
186 QVBoxLayout *vLayout2 =
new QVBoxLayout();
191 vLayout2->addWidget( mWidget );
192 QWidget *w =
new QWidget();
193 w->setLayout( vLayout2 );
194 mTabWidget->addTab( w, tr(
"Properties" ) );
196 QVBoxLayout *commentLayout =
new QVBoxLayout();
197 mCommentEdit =
new QTextEdit();
198 mCommentEdit->setAcceptRichText(
false );
199 commentLayout->addWidget( mCommentEdit, 1 );
203 QHBoxLayout *hl =
new QHBoxLayout();
204 hl->setContentsMargins( 0, 0, 0, 0 );
205 hl->addWidget(
new QLabel( tr(
"Color" ) ) );
207 mCommentColorButton->setAllowOpacity(
true );
208 mCommentColorButton->setWindowTitle( tr(
"Comment Color" ) );
209 mCommentColorButton->setShowNull(
true, tr(
"Default" ) );
210 hl->addWidget( mCommentColorButton );
211 commentLayout->addLayout( hl );
215 QWidget *w2 =
new QWidget();
216 w2->setLayout( commentLayout );
217 mTabWidget->addTab( w2, tr(
"Comments" ) );
219 setLayout( vLayout );
221 definition ? tr(
"%1 Parameter Definition" ).arg( definition->
description() )
223 : tr(
"Parameter Definition" )
229 return mWidget->createParameter( name );
234 mCommentEdit->setPlainText(
comments );
239 return mCommentEdit->toPlainText();
244 if ( color.isValid() )
245 mCommentColorButton->setColor( color );
247 mCommentColorButton->setToNull();
252 return !mCommentColorButton->isNull() ? mCommentColorButton->color() : QColor();
257 mTabWidget->setCurrentIndex( 1 );
258 mCommentEdit->setFocus();
259 mCommentEdit->selectAll();
266 mWidget->registerProcessingContextGenerator( generator );
271void QgsProcessingParameterDefinitionPanelWidget::accept()
273 if ( mWidget->mDescriptionLineEdit->text().isEmpty() )
275 QMessageBox::warning(
this, tr(
"Unable to define parameter" ), tr(
"Invalid parameter name" ) );
296 QVBoxLayout *vLayout =
new QVBoxLayout();
298 vLayout->addWidget( mWidget );
302 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
304 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsProcessingParameterDefinitionDialog::reject );
306 vLayout->addWidget( bbox );
307 setLayout( vLayout );
309 definition ? tr(
"%1 Parameter Definition" ).arg( definition->
description() )
311 : tr(
"Parameter Definition" )
313 setObjectName( u
"QgsProcessingParameterDefinitionDialog"_s );
319 return mWidget->createParameter( name );
329 return mWidget->comments();
334 mWidget->setCommentColor( color );
339 return mWidget->commentColor();
344 mWidget->switchToCommentTab();
349 mWidget->registerProcessingContextGenerator( generator );
354 if ( mWidget->mWidget->mDescriptionLineEdit->text().isEmpty() )
356 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