QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
26 #include <QVBoxLayout>
31 #include <QDialogButtonBox>
32 #include <QMessageBox>
59 QVBoxLayout *vlayout =
new QVBoxLayout();
61 QLabel *label =
new QLabel( tr(
"Description" ) );
62 vlayout->addWidget( label );
63 mDescriptionLineEdit =
new QLineEdit();
64 vlayout->addWidget( mDescriptionLineEdit );
68 mDescriptionLineEdit->setText( definition->
description() );
71 if ( mDefinitionWidget )
72 vlayout->addWidget( mDefinitionWidget );
74 vlayout->addSpacing( 20 );
75 mRequiredCheckBox =
new QCheckBox( tr(
"Mandatory" ) );
79 mRequiredCheckBox->setChecked(
true );
80 vlayout->addWidget( mRequiredCheckBox );
82 mAdvancedCheckBox =
new QCheckBox( tr(
"Advanced" ) );
86 mAdvancedCheckBox->setChecked(
false );
87 vlayout->addWidget( mAdvancedCheckBox );
89 vlayout->addStretch();
95 std::unique_ptr< QgsProcessingParameterDefinition > param;
96 QgsProcessingParameterDefinition::Flags flags = QgsProcessingParameterDefinition::Flags();
98 if ( !mRequiredCheckBox->isChecked() )
100 if ( mAdvancedCheckBox->isChecked() )
103 if ( mDefinitionWidget )
107 param.reset( mDefinitionWidget->
createParameter( name, mDescriptionLineEdit->text(), flags ) );
115 param->setDescription( mDescriptionLineEdit->text() );
116 param->setFlags( flags );
120 return param.release();
135 QVBoxLayout *vLayout =
new QVBoxLayout();
136 mTabWidget =
new QTabWidget();
137 vLayout->addWidget( mTabWidget );
139 QVBoxLayout *vLayout2 =
new QVBoxLayout();
141 vLayout2->addWidget( mWidget );
142 QWidget *w =
new QWidget();
143 w->setLayout( vLayout2 );
144 mTabWidget->addTab( w, tr(
"Properties" ) );
146 QVBoxLayout *commentLayout =
new QVBoxLayout();
147 mCommentEdit =
new QTextEdit();
148 mCommentEdit->setAcceptRichText(
false );
149 commentLayout->addWidget( mCommentEdit, 1 );
151 QHBoxLayout *hl =
new QHBoxLayout();
152 hl->setContentsMargins( 0, 0, 0, 0 );
153 hl->addWidget(
new QLabel( tr(
"Color" ) ) );
156 mCommentColorButton->setWindowTitle( tr(
"Comment Color" ) );
157 mCommentColorButton->
setShowNull(
true, tr(
"Default" ) );
158 hl->addWidget( mCommentColorButton );
159 commentLayout->addLayout( hl );
161 QWidget *w2 =
new QWidget();
162 w2->setLayout( commentLayout );
163 mTabWidget->addTab( w2, tr(
"Comments" ) );
165 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
167 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsProcessingParameterDefinitionDialog::reject );
169 vLayout->addWidget( bbox );
170 setLayout( vLayout );
171 setWindowTitle( definition ? tr(
"%1 Parameter Definition" ).arg( definition->
description() )
173 tr(
"Parameter Definition" ) );
174 setObjectName( QStringLiteral(
"QgsProcessingParameterDefinitionDialog" ) );
185 mCommentEdit->setPlainText(
comments );
190 return mCommentEdit->toPlainText();
195 if ( color.isValid() )
196 mCommentColorButton->
setColor( color );
203 return !mCommentColorButton->
isNull() ? mCommentColorButton->
color() : QColor();
208 mTabWidget->setCurrentIndex( 1 );
209 mCommentEdit->setFocus();
210 mCommentEdit->selectAll();
215 if ( mWidget->mDescriptionLineEdit->text().isEmpty() )
217 QMessageBox::warning(
this, tr(
"Unable to define parameter" ),
218 tr(
"Invalid parameter name" ) );
static QgsProcessingRegistry * processingRegistry()
Returns the application's processing registry, used for managing processing providers,...
QgsProcessingParameterDefinition * createParameter(const QString &name=QString()) const
Returns a new instance of a parameter definition, using the current settings defined in the dialog.
QString description() const
Returns the description for the parameter.
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
Flags flags() const
Returns any flags associated with the parameter.
@ FlagAdvanced
Parameter is an advanced parameter which should be hidden from users by default.
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...
QString comments() const
Returns the comments for the parameter.
static QgsProcessingGuiRegistry * processingGuiRegistry()
Returns the global processing gui registry, used for registering the GUI behavior of processing algor...
QgsProcessingParameterType * parameterType(const QString &id) const
Returns the parameter type registered for id.
static QgsGui * instance()
Returns a pointer to the singleton instance.
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 setCommentColor(const QColor &color)
Sets the color for the comments for the parameter.
void setComments(const QString &comments)
Sets the comments for the parameter.
QColor commentColor() const
Returns the color for the comments for the parameter.
@ FlagOptional
Parameter is optional.
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 switchToCommentTab()
Switches the dialog to the comments tab.