20#include "moc_qgsprocessingparameterdefinitionwidget.cpp" 
   32#include <QDialogButtonBox> 
   39  , mWidgetContext( context )
 
 
   45  mWidgetContext = context;
 
 
   50  return mWidgetContext;
 
 
   55  mContextGenerator = generator;
 
 
   60  return QgsProcessingWidgetWrapperUtils::createExpressionContext( mContextGenerator, mWidgetContext, 
nullptr, 
nullptr );
 
 
   73  QVBoxLayout *vlayout = 
new QVBoxLayout();
 
   75  QLabel *label = 
new QLabel( tr( 
"Description" ) );
 
   76  vlayout->addWidget( label );
 
   77  mDescriptionLineEdit = 
new QLineEdit();
 
   78  vlayout->addWidget( mDescriptionLineEdit );
 
   82    mDescriptionLineEdit->setText( definition->
description() );
 
   85  if ( mDefinitionWidget )
 
   86    vlayout->addWidget( mDefinitionWidget );
 
   88  vlayout->addSpacing( 20 );
 
   89  mRequiredCheckBox = 
new QCheckBox( tr( 
"Mandatory" ) );
 
   93    mRequiredCheckBox->setChecked( 
true );
 
   94  vlayout->addWidget( mRequiredCheckBox );
 
   96  mAdvancedCheckBox = 
new QCheckBox( tr( 
"Advanced" ) );
 
  100    mAdvancedCheckBox->setChecked( 
false );
 
  101  vlayout->addWidget( mAdvancedCheckBox );
 
  103  vlayout->addStretch();
 
  104  setLayout( vlayout );
 
 
  109  std::unique_ptr<QgsProcessingParameterDefinition> param;
 
  112  if ( !mRequiredCheckBox->isChecked() )
 
  114  if ( mAdvancedCheckBox->isChecked() )
 
  117  if ( mDefinitionWidget )
 
  121    param.reset( mDefinitionWidget->
createParameter( name, mDescriptionLineEdit->text(), flags ) );
 
  130      param->setFlags( flags );
 
  134  return param.release();
 
 
  139  if ( mDefinitionWidget )
 
 
  152  QVBoxLayout *vLayout = 
new QVBoxLayout();
 
  153  mTabWidget = 
new QTabWidget();
 
  154  vLayout->addWidget( mTabWidget );
 
  156  QVBoxLayout *vLayout2 = 
new QVBoxLayout();
 
  158  vLayout2->addWidget( mWidget );
 
  159  QWidget *w = 
new QWidget();
 
  160  w->setLayout( vLayout2 );
 
  161  mTabWidget->addTab( w, tr( 
"Properties" ) );
 
  163  QVBoxLayout *commentLayout = 
new QVBoxLayout();
 
  164  mCommentEdit = 
new QTextEdit();
 
  165  mCommentEdit->setAcceptRichText( 
false );
 
  166  commentLayout->addWidget( mCommentEdit, 1 );
 
  168  QHBoxLayout *hl = 
new QHBoxLayout();
 
  169  hl->setContentsMargins( 0, 0, 0, 0 );
 
  170  hl->addWidget( 
new QLabel( tr( 
"Color" ) ) );
 
  173  mCommentColorButton->setWindowTitle( tr( 
"Comment Color" ) );
 
  174  mCommentColorButton->
setShowNull( 
true, tr( 
"Default" ) );
 
  175  hl->addWidget( mCommentColorButton );
 
  176  commentLayout->addLayout( hl );
 
  178  QWidget *w2 = 
new QWidget();
 
  179  w2->setLayout( commentLayout );
 
  180  mTabWidget->addTab( w2, tr( 
"Comments" ) );
 
  182  QDialogButtonBox *bbox = 
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
 
  184  connect( bbox, &QDialogButtonBox::rejected, 
this, &QgsProcessingParameterDefinitionDialog::reject );
 
  186  vLayout->addWidget( bbox );
 
  187  setLayout( vLayout );
 
  189                                                                                                                                                              : tr( 
"Parameter Definition" ) );
 
  190  setObjectName( QStringLiteral( 
"QgsProcessingParameterDefinitionDialog" ) );
 
 
  201  mCommentEdit->setPlainText( 
comments );
 
 
  206  return mCommentEdit->toPlainText();
 
 
  211  if ( color.isValid() )
 
  212    mCommentColorButton->
setColor( color );
 
 
  219  return !mCommentColorButton->
isNull() ? mCommentColorButton->
color() : QColor();
 
 
  224  mTabWidget->setCurrentIndex( 1 );
 
  225  mCommentEdit->setFocus();
 
  226  mCommentEdit->selectAll();
 
 
  239  if ( mWidget->mDescriptionLineEdit->text().isEmpty() )
 
  241    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.
 
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