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() );
92 if ( mDefinitionWidget )
95 vlayout->addWidget( mDefinitionWidget );
98 vlayout->addSpacing( 20 );
99 mRequiredCheckBox =
new QCheckBox( tr(
"Mandatory" ) );
103 mRequiredCheckBox->setChecked(
true );
106 vlayout->addWidget( mRequiredCheckBox );
108 mAdvancedCheckBox =
new QCheckBox( tr(
"Advanced" ) );
112 mAdvancedCheckBox->setChecked(
false );
114 vlayout->addWidget( mAdvancedCheckBox );
116 vlayout->addStretch();
117 setLayout( vlayout );
122 std::unique_ptr<QgsProcessingParameterDefinition> param;
125 if ( !mRequiredCheckBox->isChecked() )
127 if ( mAdvancedCheckBox->isChecked() )
130 if ( mDefinitionWidget )
134 param.reset( mDefinitionWidget->createParameter( name, mDescriptionLineEdit->text(), flags ) );
142 param->setDescription( mDescriptionLineEdit->text() );
143 param->setFlags( flags );
147 return param.release();
152 if ( mDefinitionWidget )
154 mDefinitionWidget->registerProcessingContextGenerator( generator );
166 QVBoxLayout *vLayout =
new QVBoxLayout();
167 vLayout->setContentsMargins( 0, 0, 0, 0 );
168 mTabWidget =
new QTabWidget();
169 vLayout->addWidget( mTabWidget );
171 QVBoxLayout *vLayout2 =
new QVBoxLayout();
176 vLayout2->addWidget( mWidget );
177 QWidget *w =
new QWidget();
178 w->setLayout( vLayout2 );
179 mTabWidget->addTab( w, tr(
"Properties" ) );
181 QVBoxLayout *commentLayout =
new QVBoxLayout();
182 mCommentEdit =
new QTextEdit();
183 mCommentEdit->setAcceptRichText(
false );
184 commentLayout->addWidget( mCommentEdit, 1 );
188 QHBoxLayout *hl =
new QHBoxLayout();
189 hl->setContentsMargins( 0, 0, 0, 0 );
190 hl->addWidget(
new QLabel( tr(
"Color" ) ) );
192 mCommentColorButton->setAllowOpacity(
true );
193 mCommentColorButton->setWindowTitle( tr(
"Comment Color" ) );
194 mCommentColorButton->setShowNull(
true, tr(
"Default" ) );
195 hl->addWidget( mCommentColorButton );
196 commentLayout->addLayout( hl );
200 QWidget *w2 =
new QWidget();
201 w2->setLayout( commentLayout );
202 mTabWidget->addTab( w2, tr(
"Comments" ) );
204 setLayout( vLayout );
206 : tr(
"Parameter Definition" ) );
211 return mWidget->createParameter( name );
216 mCommentEdit->setPlainText(
comments );
221 return mCommentEdit->toPlainText();
226 if ( color.isValid() )
227 mCommentColorButton->setColor( color );
229 mCommentColorButton->setToNull();
234 return !mCommentColorButton->isNull() ? mCommentColorButton->color() : QColor();
239 mTabWidget->setCurrentIndex( 1 );
240 mCommentEdit->setFocus();
241 mCommentEdit->selectAll();
248 mWidget->registerProcessingContextGenerator( generator );
253void QgsProcessingParameterDefinitionPanelWidget::accept()
255 if ( mWidget->mDescriptionLineEdit->text().isEmpty() )
257 QMessageBox::warning(
this, tr(
"Unable to define parameter" ), tr(
"Invalid parameter name" ) );
271 QVBoxLayout *vLayout =
new QVBoxLayout();
273 vLayout->addWidget( mWidget );
277 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
279 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsProcessingParameterDefinitionDialog::reject );
281 vLayout->addWidget( bbox );
282 setLayout( vLayout );
284 : tr(
"Parameter Definition" ) );
285 setObjectName( u
"QgsProcessingParameterDefinitionDialog"_s );
291 return mWidget->createParameter( name );
301 return mWidget->comments();
306 mWidget->setCommentColor( color );
311 return mWidget->commentColor();
316 mWidget->switchToCommentTab();
321 mWidget->registerProcessingContextGenerator( generator );
326 if ( mWidget->mWidget->mDescriptionLineEdit->text().isEmpty() )
328 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