QGIS API Documentation 4.3.0-Master (d57cc4a041c)
Loading...
Searching...
No Matches
qgsmodelchildalgorithmwidgets.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmodelchildalgorithmwidgets.cpp
3 ------------------------------------------
4 begin : August 2026
5 copyright : (C) 2026 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18
20
22#include "qgscolorbutton.h"
23#include "qgsgui.h"
24#include "qgshelp.h"
25#include "qgsmessagebar.h"
35#include "qgsscrollarea.h"
36
37#include <QDesktopServices>
38#include <QLabel>
39#include <QLineEdit>
40#include <QString>
41#include <QVBoxLayout>
42
43#include "moc_qgsmodelchildalgorithmwidgets.cpp"
44
45using namespace Qt::StringLiterals;
46
47//
48// QgsProcessingModelerParametersPanelWidget
49//
50
52 const QgsProcessingAlgorithm *childAlgorithm, QgsProcessingModelAlgorithm *model, QgsProcessingContext &context, const QString &childId, const QVariantMap &configuration, QWidget *parent, QWidget *dialog
53)
54 : QgsPanelWidget( parent )
55 , mAlgorithm( childAlgorithm ? childAlgorithm->create() : nullptr )
56 , mModel( model )
57 , mChildId( childId )
58 , mConfiguration( configuration )
59 , mContext( context )
60 , mDialog( dialog )
61{
62 setupUi();
63
65}
66
68
70{
71 return mAlgorithm.get();
72}
73
74void QgsProcessingModelerParametersPanelWidget::setupUi()
75{
76 auto mainLayout = new QVBoxLayout();
77 mainLayout->setContentsMargins( 0, 0, 0, 0 );
78
79 auto verticalLayout = new QVBoxLayout();
80
81 mMessageBar = new QgsMessageBar();
82 mMessageBar->setSizePolicy( QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Fixed );
83 verticalLayout->addWidget( mMessageBar );
84
85 auto hLayout = new QHBoxLayout();
86 hLayout->setContentsMargins( 0, 0, 0, 0 );
87 hLayout->addWidget( new QLabel( tr( "Description" ) ) );
88 mDescriptionBox = new QLineEdit();
89 mDescriptionBox->setObjectName( u"mDescriptionBox"_s );
90 if ( mAlgorithm )
91 {
92 mDescriptionBox->setText( mAlgorithm->displayName() );
93 }
94 hLayout->addWidget( mDescriptionBox );
95 connect( mDescriptionBox, &QLineEdit::textChanged, this, &QgsProcessingModelerParametersPanelWidget::emitChangedSignal );
96
97 verticalLayout->addLayout( hLayout );
98
99 auto line = new QFrame();
100 line->setFrameShape( QFrame::Shape::HLine );
101 line->setFrameShadow( QFrame::Shadow::Sunken );
102 verticalLayout->addWidget( line );
103
104 if ( mAlgorithm )
105 {
106 mAlgorithmItem = QgsGui::processingGuiRegistry()->algorithmConfigurationWidget( mAlgorithm.get() );
107 if ( mAlgorithmItem )
108 {
109 mAlgorithmItem->registerProcessingContextGenerator( this );
110 if ( !mConfiguration.isEmpty() )
111 mAlgorithmItem->setConfiguration( mConfiguration );
112
113 verticalLayout->addWidget( mAlgorithmItem );
114 }
115 }
116
117 if ( mAlgorithm )
118 {
119 const QList<const QgsProcessingParameterDefinition *> parameters = mAlgorithm->parameterDefinitions();
120 // only create advanced group when there are SOME advanced parameters:
121 bool hasAdvancedParameters = false;
122 for ( const QgsProcessingParameterDefinition *parameter : parameters )
123 {
124 if ( parameter->flags() & Qgis::ProcessingParameterFlag::Advanced )
125 {
126 hasAdvancedParameters = true;
127 break;
128 }
129 }
130 QgsCollapsibleGroupBox *advancedGroup = nullptr;
131 QVBoxLayout *advancedGroupLayout = nullptr;
132 if ( hasAdvancedParameters )
133 {
134 advancedGroup = new QgsCollapsibleGroupBox( tr( "Advanced Parameters" ) );
135 advancedGroupLayout = new QVBoxLayout();
136 advancedGroup->setLayout( advancedGroupLayout );
137 verticalLayout->addWidget( advancedGroup );
138 }
139
140 for ( const QgsProcessingParameterDefinition *parameter : parameters )
141 {
142 if ( parameter->isDestination() || ( parameter->flags() & Qgis::ProcessingParameterFlag::Hidden ) )
143 continue;
144
145 // note: ownership of widget is transferred to parent layout below
146 QgsProcessingModelerParameterWidget *widget = QgsGui::processingGuiRegistry()->createModelerParameterWidget( mModel, mChildId, parameter, mContext );
147 if ( !widget )
148 continue;
149
150 widget->setDialog( mDialog );
152 connect( widget, &QgsProcessingModelerParameterWidget::changed, this, &QgsProcessingModelerParametersPanelWidget::emitChangedSignal );
153 mWrappers.insert( parameter->name(), widget );
154
155 QLabel *label = widget->createLabel();
156 // advanced parameters get inserted to a different layout:
157 if ( advancedGroupLayout && parameter->flags() & Qgis::ProcessingParameterFlag::Advanced )
158 {
159 if ( label )
160 advancedGroupLayout->addWidget( label );
161 advancedGroupLayout->addWidget( widget );
162 }
163 else
164 {
165 if ( label )
166 verticalLayout->insertWidget( verticalLayout->count() - 1, label );
167 verticalLayout->insertWidget( verticalLayout->count() - 1, widget );
168 }
169 }
170
171 const QList< const QgsProcessingParameterDefinition * > destinationsParameters = mAlgorithm->destinationParameterDefinitions();
172 for ( const QgsProcessingParameterDefinition *output : destinationsParameters )
173 {
174 if ( output->flags() & Qgis::ProcessingParameterFlag::Hidden )
175 continue;
176
177 // note: ownership of widget is transferred to parent layout below
178 QgsProcessingModelerParameterWidget *widget = QgsGui::processingGuiRegistry()->createModelerParameterWidget( mModel, mChildId, output, mContext );
179 if ( !widget )
180 continue;
181
182 widget->setDialog( mDialog );
184 connect( widget, &QgsProcessingModelerParameterWidget::changed, this, &QgsProcessingModelerParametersPanelWidget::emitChangedSignal );
185
186 mWrappers.insert( output->name(), widget );
187
188 if ( QLabel *label = widget->createLabel() )
189 verticalLayout->addWidget( label );
190
191 verticalLayout->addWidget( widget );
192 }
193 }
194
195 const QFontMetrics fm( font() );
196 auto spacer = new QSpacerItem( 20, fm.height() );
197 verticalLayout->addItem( spacer );
198
199 auto dependenciesLabel = new QLabel( tr( "Dependencies" ) );
200 mDependenciesPanel = new QgsModelChildDependenciesWidget( this, mModel, mChildId );
201 verticalLayout->addWidget( dependenciesLabel );
202 verticalLayout->addWidget( mDependenciesPanel );
203 connect( mDependenciesPanel, &QgsModelChildDependenciesWidget::changed, this, &QgsProcessingModelerParametersPanelWidget::emitChangedSignal );
204 verticalLayout->addStretch( 1 );
205
206 auto scrollAreaContainer = new QVBoxLayout();
207 scrollAreaContainer->setSpacing( 2 );
208 scrollAreaContainer->setContentsMargins( 0, 0, 0, 0 );
209
210 auto paramPanel = new QWidget();
211 paramPanel->setLayout( verticalLayout );
212
213 auto scrollArea = new QgsScrollArea();
214 scrollArea->setWidget( paramPanel );
215 scrollArea->setWidgetResizable( true );
216 scrollArea->setFrameStyle( QFrame::Shape::NoFrame );
217
218 scrollAreaContainer->addWidget( scrollArea );
219
220 auto scrollAreaContainerWidget = new QWidget();
221 scrollAreaContainerWidget->setLayout( scrollAreaContainer );
222 mainLayout->addWidget( scrollAreaContainerWidget );
223 setLayout( mainLayout );
224}
225
226void QgsProcessingModelerParametersPanelWidget::emitChangedSignal()
227{
228 if ( !mBlockChangesSignal )
229 emit widgetChanged();
230}
231
233{
234 if ( mChildId.isEmpty() || !mModel->childAlgorithms().contains( mChildId ) )
235 return;
236
237 const QgsProcessingModelChildAlgorithm childAlgorithm = mModel->childAlgorithm( mChildId );
238 const QgsProcessingAlgorithm *sourceAlgorithm = mAlgorithm.get();
239 std::unique_ptr< QgsProcessingAlgorithm > tempAlgorithm;
240 if ( mAlgorithmItem )
241 {
242 // for algorithms with a custom config widget, we need to iterate over parameters defined
243 // when that algorithm is created respecting the custom config widget.
244
245 // WARNING: we CANNOT overwrite mAlgorithm here, as all the existing wrappers have already
246 // been created with references to that algorithm instance!
247 tempAlgorithm.reset( childAlgorithm.algorithm()->create( mAlgorithmItem->configuration() ) );
248 sourceAlgorithm = tempAlgorithm.get();
249 }
250
251 if ( !sourceAlgorithm )
252 return;
253
254 const QList< const QgsProcessingParameterDefinition * > parameters = sourceAlgorithm->parameterDefinitions();
255 const QList< const QgsProcessingParameterDefinition * > destinationParameters = sourceAlgorithm->destinationParameterDefinitions();
256
257 mBlockChangesSignal++;
258
259 mDescriptionBox->setText( childAlgorithm.description() );
260
261 for ( const QgsProcessingParameterDefinition *param : parameters )
262 {
263 if ( param->isDestination() || ( param->flags() & Qgis::ProcessingParameterFlag::Hidden ) )
264 continue;
265
266 QList< QgsProcessingModelChildParameterSource > valueList;
267 std::optional< QgsProcessingModelChildParameterSource > singleValue;
268 if ( childAlgorithm.parameterSources().contains( param->name() ) )
269 {
270 valueList = childAlgorithm.parameterSources().value( param->name() );
271 if ( valueList.size() == 1 )
272 {
273 singleValue = valueList.at( 0 );
274 valueList.clear();
275 }
276 }
277
278 if ( valueList.isEmpty() && !singleValue.has_value() )
279 {
280 singleValue = QgsProcessingModelChildParameterSource::fromStaticValue( param->defaultValue() );
281 }
282
283 if ( mWrappers.contains( param->name() ) )
284 {
285 if ( !valueList.isEmpty() )
286 {
287 mWrappers.value( param->name() )->setWidgetValue( valueList );
288 }
289 else if ( singleValue.has_value() )
290 {
291 mWrappers.value( param->name() )->setWidgetValue( singleValue.value() );
292 }
293 }
294 }
295
296 for ( const QgsProcessingParameterDefinition *output : destinationParameters )
297 {
298 if ( output->flags() & Qgis::ProcessingParameterFlag::Hidden )
299 continue;
300
301 QString modelOutputName;
302 const QMap< QString, QgsProcessingModelOutput > outputs = childAlgorithm.modelOutputs();
303 for ( auto it = outputs.constBegin(); it != outputs.constEnd(); ++it )
304 {
305 if ( it.value().childId() == mChildId && it.value().childOutputName() == output->name() )
306 {
307 // this destination parameter is linked to a model output
308 modelOutputName = it.value().name();
309 mPreviousOutputDefinitions.insert( output->name(), it.value() );
310 break;
311 }
312 }
313
314 QList< QgsProcessingModelChildParameterSource > valueList;
315 std::optional< QgsProcessingModelChildParameterSource > singleValue;
316 if ( modelOutputName.isEmpty() && childAlgorithm.parameterSources().contains( output->name() ) )
317 {
318 valueList = childAlgorithm.parameterSources().value( output->name() );
319 if ( valueList.size() == 1 )
320 {
321 singleValue = valueList.at( 0 );
322 valueList.clear();
323 }
324 }
325
326 if ( mWrappers.contains( output->name() ) )
327 {
328 QgsProcessingModelerParameterWidget *wrapper = mWrappers.value( output->name() );
329 if ( !modelOutputName.isEmpty() )
330 {
331 wrapper->setToModelOutput( modelOutputName );
332 }
333 else if ( !valueList.empty() )
334 {
335 wrapper->setWidgetValue( valueList );
336 }
337 else if ( singleValue.has_value() )
338 {
339 wrapper->setWidgetValue( singleValue.value() );
340 }
341 else if ( output->defaultValue().isValid() )
342 {
343 wrapper->setWidgetValue( QgsProcessingModelChildParameterSource::fromStaticValue( output->defaultValue() ) );
344 }
345 }
346 }
347
348 mDependenciesPanel->setValue( childAlgorithm.dependencies() );
349
350 mBlockChangesSignal--;
351}
352
353std::unique_ptr< QgsProcessingModelChildAlgorithm > QgsProcessingModelerParametersPanelWidget::createAlgorithm()
354{
355 if ( !mAlgorithm )
356 return nullptr;
357
358 auto newChildAlgorithm = std::make_unique< QgsProcessingModelChildAlgorithm >( mAlgorithm->id() );
359 if ( mChildId.isEmpty() )
360 newChildAlgorithm->generateChildId( *mModel );
361 else
362 newChildAlgorithm->setChildId( mChildId );
363
364 newChildAlgorithm->setDescription( mDescriptionBox->text() );
365 if ( mAlgorithmItem )
366 {
367 newChildAlgorithm->setConfiguration( mAlgorithmItem->configuration() );
368 mAlgorithm.reset( newChildAlgorithm->algorithm()->create( mAlgorithmItem->configuration() ) );
369 }
370
371 const QList<const QgsProcessingParameterDefinition * > parameterDefinitions = mAlgorithm->parameterDefinitions();
372 for ( const QgsProcessingParameterDefinition *parameter : parameterDefinitions )
373 {
374 if ( parameter->isDestination() || ( parameter->flags() & Qgis::ProcessingParameterFlag::Hidden ) )
375 continue;
376
377 if ( !mWrappers.contains( parameter->name() ) )
378 continue;
379
380 const QgsProcessingModelerParameterWidget *wrapper = mWrappers.value( parameter->name() );
381 QVariant value = wrapper->value();
382
383 QList< QgsProcessingModelChildParameterSource > sources;
384 if ( value.userType() == qMetaTypeId< QgsProcessingModelChildParameterSource >() )
385 {
386 sources.append( value.value< QgsProcessingModelChildParameterSource >() );
387 }
388 else if ( value.userType() == QMetaType::Type::QVariantList )
389 {
390 const QVariantList list = value.toList();
391 for ( const QVariant &subValue : list )
392 {
393 if ( subValue.userType() == qMetaTypeId< QgsProcessingModelChildParameterSource >() )
394 sources.append( subValue.value< QgsProcessingModelChildParameterSource >() );
395 else
396 sources.append( QgsProcessingModelChildParameterSource::fromStaticValue( subValue ) );
397 }
398 }
399 else
400 {
401 sources.append( QgsProcessingModelChildParameterSource::fromStaticValue( value ) );
402 }
403
404 bool valid = true;
405 for ( const QgsProcessingModelChildParameterSource &subValue : std::as_const( sources ) )
406 {
407 if ( subValue.source() == Qgis::ProcessingModelChildParameterSource::StaticValue && !parameter->checkValueIsAcceptable( subValue.staticValue() ) )
408 {
409 valid = false;
410 break;
411 }
412 }
413
414 if ( valid )
415 newChildAlgorithm->addParameterSources( parameter->name(), sources );
416 }
417
418 QMap< QString, QgsProcessingModelOutput > outputs;
419 const QList< const QgsProcessingParameterDefinition * > destinationParameters = mAlgorithm->destinationParameterDefinitions();
420 for ( const QgsProcessingParameterDefinition *output : destinationParameters )
421 {
422 if ( !( output->flags() & Qgis::ProcessingParameterFlag::Hidden ) )
423 {
424 if ( mWrappers.contains( output->name() ) )
425 {
426 QgsProcessingModelerParameterWidget *wrapper = mWrappers.value( output->name() );
427 if ( wrapper->isModelOutput() )
428 {
429 const QString name = wrapper->modelOutputName();
430 if ( !name.isEmpty() )
431 {
432 // if there was a previous output definition already for this output, we start with it,
433 // otherwise we'll lose any existing output comments, coloring, position, etc
434 QgsProcessingModelOutput modelOutput = mPreviousOutputDefinitions.value( output->name(), QgsProcessingModelOutput( name, name ) );
435 modelOutput.setDescription( name );
436 modelOutput.setChildId( newChildAlgorithm->childId() );
437 modelOutput.setChildOutputName( output->name() );
438 outputs.insert( name, modelOutput );
439 }
440 }
441 else
442 {
443 const QVariant val = wrapper->value();
444 QList< QgsProcessingModelChildParameterSource > sources;
445 if ( val.userType() == qMetaTypeId< QgsProcessingModelChildParameterSource >() )
446 {
447 sources.append( val.value< QgsProcessingModelChildParameterSource >() );
448 }
449 else if ( val.userType() == QMetaType::Type::QVariantList )
450 {
451 const QVariantList list = val.toList();
452 for ( const QVariant &subValue : list )
453 {
454 if ( subValue.userType() == qMetaTypeId< QgsProcessingModelChildParameterSource >() )
455 sources.append( subValue.value< QgsProcessingModelChildParameterSource >() );
456 else
457 sources.append( QgsProcessingModelChildParameterSource::fromStaticValue( subValue ) );
458 }
459 }
460
461 newChildAlgorithm->addParameterSources( output->name(), sources );
462 }
463 }
464 }
465
466 if ( output->flags() & Qgis::ProcessingParameterFlag::IsModelOutput )
467 {
468 if ( !outputs.contains( output->name() ) )
469 {
470 QgsProcessingModelOutput modelOutput( output->name(), output->name() );
471 modelOutput.setChildId( newChildAlgorithm->childId() );
472 modelOutput.setChildOutputName( output->name() );
473 outputs.insert( output->name(), modelOutput );
474 }
475 }
476 }
477
478 newChildAlgorithm->setModelOutputs( outputs );
479 newChildAlgorithm->setDependencies( mDependenciesPanel->value() );
480
481 return newChildAlgorithm;
482}
483
488
490{
491 if ( mAlgorithmItem )
492 {
493 mAlgorithmItem->setWidgetContext( context );
494 }
495 for ( auto it = mWrappers.constBegin(); it != mWrappers.constEnd(); ++it )
496 {
497 it.value()->setWidgetContext( context );
498 }
499}
500
501
502//
503// QgsProcessingModelerParametersWidget
504//
505
507 const QgsProcessingAlgorithm *childAlgorithm, QgsProcessingModelAlgorithm *model, QgsProcessingContext &context, const QString &childId, const QVariantMap &configuration, QWidget *parent, QWidget *dialog
508)
510{
511 mParametersPanel = new QgsProcessingModelerParametersPanelWidget( childAlgorithm, model, context, childId, configuration, this, dialog );
513
514 setupUi();
515}
516
518
520{
521 return mParametersPanel->algorithm();
522}
523
525{
526 mTabWidget->setCurrentIndex( 1 );
527 mCommentEdit->setFocus();
528 mCommentEdit->selectAll();
529}
530
532{
533 mParametersPanel->setWidgetContext( context );
534}
535
536void QgsProcessingModelerParametersWidget::setupUi()
537{
538 auto mainLayout = new QVBoxLayout();
539 mainLayout->setContentsMargins( 0, 0, 0, 0 );
540
541 mTabWidget = new QTabWidget();
542 mainLayout->addWidget( mTabWidget );
543
544 mPanelWidgetStack = new QgsPanelWidgetStack();
545 mParametersPanel->setDockMode( true );
546 mPanelWidgetStack->setMainPanel( mParametersPanel );
547
548 mTabWidget->addTab( mPanelWidgetStack, tr( "Properties" ) );
549
550 auto commentLayout = new QVBoxLayout();
551 mCommentEdit = new QTextEdit();
552 mCommentEdit->setAcceptRichText( false );
553 commentLayout->addWidget( mCommentEdit, 1 );
554 connect( mCommentEdit, &QTextEdit::textChanged, this, &QgsProcessingModelerParametersWidget::widgetChanged );
555
556 auto hl = new QHBoxLayout();
557 hl->setContentsMargins( 0, 0, 0, 0 );
558 hl->addWidget( new QLabel( tr( "Color" ) ) );
559
560 mCommentColorButton = new QgsColorButton();
561 mCommentColorButton->setAllowOpacity( true );
562 mCommentColorButton->setWindowTitle( tr( "Comment Color" ) );
563 mCommentColorButton->setShowNull( true, tr( "Default" ) );
564 hl->addWidget( mCommentColorButton );
565 commentLayout->addLayout( hl );
567
568 auto commentWidget = new QWidget();
569 commentWidget->setLayout( commentLayout );
570 mTabWidget->addTab( commentWidget, tr( "Comments" ) );
571
572 setLayout( mainLayout );
573}
574
576{
577 mCommentEdit->setPlainText( text );
578}
579
581{
582 return mCommentEdit->toPlainText();
583}
584
586{
587 if ( color.isValid() )
588 mCommentColorButton->setColor( color );
589 else
590 mCommentColorButton->setToNull();
591}
592
594{
595 return !mCommentColorButton->isNull() ? mCommentColorButton->color() : QColor();
596}
597
599{
600 mParametersPanel->setStateFromChildAlgorithm();
601}
602
603std::unique_ptr< QgsProcessingModelChildAlgorithm > QgsProcessingModelerParametersWidget::createAlgorithm()
604{
605 std::unique_ptr< QgsProcessingModelChildAlgorithm > alg = mParametersPanel->createAlgorithm();
606 if ( alg )
607 {
608 alg->comment()->setDescription( comments() );
609 alg->comment()->setColor( commentColor() );
610 }
611 return alg;
612}
613
614//
615// QgsProcessingModelerParametersDialog
616//
617
619 const QgsProcessingAlgorithm *childAlgorithm, QgsProcessingModelAlgorithm *model, QgsProcessingContext &context, const QString &childId, const QVariantMap &configuration, QWidget *parent
620)
621 : QDialog( parent )
622{
623 setObjectName( u"QgsProcessingModelerParametersDialog"_s );
624
625 setStyleSheet( QgsGui::applicationStyleSheet() );
626 connect( QgsGui::instance(), &QgsGui::applicationStyleSheetChanged, this, &QgsProcessingModelerParametersDialog::setStyleSheet );
627
628 mWidget = new QgsProcessingModelerParametersWidget( childAlgorithm, model, context, childId, configuration, this, this );
629
630 setWindowTitle( childAlgorithm ? ( childAlgorithm->group().isEmpty() ? childAlgorithm->displayName() : u"%1 - %2"_s.arg( childAlgorithm->group(), childAlgorithm->displayName() ) ) : QString() );
631
633
634 mButtonBox = new QDialogButtonBox();
635 mButtonBox->setOrientation( Qt::Orientation::Horizontal );
636 mButtonBox->setStandardButtons( QDialogButtonBox::StandardButton::Cancel | QDialogButtonBox::StandardButton::Ok | QDialogButtonBox::StandardButton::Help );
637
638 connect( mButtonBox, &QDialogButtonBox::accepted, this, &QgsProcessingModelerParametersDialog::okPressed );
639 connect( mButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
640 connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsProcessingModelerParametersDialog::openHelp );
641
642 auto mainLayout = new QVBoxLayout();
643 mainLayout->addWidget( mWidget, 1 );
644 mainLayout->addWidget( mButtonBox );
645 setLayout( mainLayout );
646}
647
649
651{
652 return mWidget->algorithm();
653}
654
656{
657 mWidget->setComments( text );
658}
659
661{
662 return mWidget->comments();
663}
664
666{
667 mWidget->setCommentColor( color );
668}
669
671{
672 return mWidget->commentColor();
673}
674
676{
677 mWidget->switchToCommentTab();
678}
679
681{
682 mWidget->setWidgetContext( context );
683}
684
686{
687 mWidget->setStateFromChildAlgorithm();
688}
689
690std::unique_ptr< QgsProcessingModelChildAlgorithm > QgsProcessingModelerParametersDialog::createAlgorithm()
691{
692 return mWidget->createAlgorithm();
693}
694
695void QgsProcessingModelerParametersDialog::okPressed()
696{
697 if ( createAlgorithm() )
698 accept();
699}
700
701void QgsProcessingModelerParametersDialog::openHelp()
702{
703 if ( !algorithm() )
704 return;
705
706 QString algHelp = algorithm()->helpUrl();
707 if ( algHelp.isEmpty() && algorithm()->provider() )
708 {
709 algHelp = QgsHelp::helpUrl( u"processing_algs/%1/%2.html#%3"_s
710 .arg( algorithm()->provider()->helpId(), algorithm()->groupId(), u"%1%2"_s.arg( algorithm()->provider()->helpId(), QString( algorithm()->name() ).replace( '_', '-' ) ) ) )
711 .toString();
712 }
713
714 if ( !algHelp.isEmpty() )
715 QDesktopServices::openUrl( QUrl( algHelp ) );
716}
@ StaticValue
Parameter value is a static value.
Definition qgis.h:4069
@ Hidden
Parameter is hidden and should not be shown to users.
Definition qgis.h:3983
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
Definition qgis.h:3982
@ IsModelOutput
Destination parameter is final output. The parameter name will be used.
Definition qgis.h:3985
A cross platform button subclass for selecting colors.
void colorChanged(const QColor &color)
Emitted whenever a new color is set for the button.
void setShowNull(bool showNull, const QString &nullString=QString())
Sets whether a set to null (clear) option is shown in the button's drop-down menu.
void setAllowOpacity(bool allowOpacity)
Sets whether opacity modification (transparency) is permitted for the color.
static QgsProcessingGuiRegistry * processingGuiRegistry()
Returns the global processing gui registry, used for registering the GUI behavior of processing algor...
Definition qgsgui.cpp:170
void applicationStyleSheetChanged(const QString &styleSheet)
Emitted whenever the application style sheet is changed.
static QString applicationStyleSheet()
Returns the application style sheet.
Definition qgsgui.cpp:399
static QgsGui * instance()
Returns a pointer to the singleton instance.
Definition qgsgui.cpp:94
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...
Definition qgsgui.cpp:225
static QUrl helpUrl(const QString &key)
Returns URI of the help topic for the given key.
Definition qgshelp.cpp:46
A bar for displaying non-blocking messages to the user.
A stack widget to manage multiple overlapping stacked panels.
void setMainPanel(QgsPanelWidget *panel SIP_TRANSFER)
Sets the main panel widget for the stack and selects it for the user.
QgsPanelWidget(QWidget *parent=nullptr)
Base class for any widget that can be shown as an inline panel.
void widgetChanged()
Emitted when the widget state changes.
virtual void setDockMode(bool dockMode)
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs.
Abstract base class for processing algorithms.
virtual QString group() const
Returns the name of the group this algorithm belongs to.
virtual QString helpUrl() const
Returns a url pointing to the algorithm's help page.
QgsProcessingParameterDefinitions parameterDefinitions() const
Returns an ordered list of parameter definitions utilized by the algorithm.
virtual QString displayName() const =0
Returns the translated algorithm name, which should be used for any user-visible display of the algor...
QgsProcessingParameterDefinitions destinationParameterDefinitions() const
Returns a list of destination parameters definitions utilized by the algorithm.
Contains information about the context in which a processing algorithm is executed.
QgsProcessingAlgorithmConfigurationWidget * algorithmConfigurationWidget(const QgsProcessingAlgorithm *algorithm) const
Gets the configuration widget for an algorithm.
QgsProcessingModelerParameterWidget * createModelerParameterWidget(QgsProcessingModelAlgorithm *model, const QString &childId, const QgsProcessingParameterDefinition *parameter, QgsProcessingContext &context)
Creates a new modeler parameter widget for the given parameter.
QgsProcessingModelConfigWidget(QWidget *parent=nullptr)
Constructor for QgsProcessingModelConfigWidget().
A widget for customising the value of Processing algorithm parameters inside a Processing model.
void setDialog(QWidget *dialog)
Sets the parent dialog (or widget) in which the widget is shown.
bool isModelOutput() const
Returns true if the widget is set to the model output mode.
QString modelOutputName() const
Returns the model output name, if isModelOutput() is true.
QLabel * createLabel()
Creates a label for use identifying the associated parameter.
virtual void setWidgetValue(const QgsProcessingModelChildParameterSource &value)
Sets the current value for the parameter.
virtual QVariant value() const
Returns the current value of the parameter.
void changed()
Emitted whenever the definition of the parameter is changed in the widget.
void registerProcessingContextGenerator(QgsProcessingContextGenerator *generator)
Registers a Processing context generator class that will be used to retrieve a Processing context for...
void setToModelOutput(const QString &value)
Sets the widget to a model output, for destination parameters only.
void setCommentColor(const QColor &color)
Sets the algorithm's comment color.
QgsProcessingModelerParametersDialog(const QgsProcessingAlgorithm *childAlgorithm, QgsProcessingModelAlgorithm *model, QgsProcessingContext &context, const QString &childId=QString(), const QVariantMap &configuration=QVariantMap(), QWidget *parent=nullptr)
Constructor for QgsProcessingModelerParametersDialog.
QString comments() const
Returns the algorithm's comments.
std::unique_ptr< QgsProcessingModelChildAlgorithm > createAlgorithm()
Creates the child algorithm instance, populated with the current dialog parameter values and comments...
void setStateFromChildAlgorithm()
Sets widget state from the existing child algorithm definition in the model.
void setWidgetContext(const QgsProcessingParameterWidgetContext &context)
Sets the context in which the dialog is shown, e.g., the parent model algorithm, a linked map canvas,...
void setComments(const QString &comments)
Sets the algorithm's comments.
const QgsProcessingAlgorithm * algorithm() const
Returns the algorithm associated with the dialog.
void switchToCommentTab()
Focuses the dialog on the comment editing tab.
QColor commentColor() const
Returns the algorithm's comment color.
A panel widget displaying the configuration for a child algorithm in a Processing model.
std::unique_ptr< QgsProcessingModelChildAlgorithm > createAlgorithm()
Creates the child algorithm instance populated with current widget values.
void setStateFromChildAlgorithm()
Sets widget state from the existing child algorithm definition in the model.
const QgsProcessingAlgorithm * algorithm() const
Returns the algorithm associated with the widget.
QgsProcessingContext * processingContext() const override
This method needs to be reimplemented in all classes which implement this interface and return a Proc...
QgsProcessingModelerParametersPanelWidget(const QgsProcessingAlgorithm *childAlgorithm, QgsProcessingModelAlgorithm *model, QgsProcessingContext &context, const QString &childId=QString(), const QVariantMap &configuration=QVariantMap(), QWidget *parent=nullptr, QWidget *dialog=nullptr)
Constructor for QgsProcessingModelerParametersPanelWidget.
void setWidgetContext(const QgsProcessingParameterWidgetContext &context)
Sets the context in which the panel is shown, e.g., the parent model algorithm, a linked map canvas,...
A panel config widget combining parameter settings and comments for a child algorithm in a Processing...
void setCommentColor(const QColor &color)
Sets the comment's color.
void setWidgetContext(const QgsProcessingParameterWidgetContext &context)
Sets the context in which the panel is shown, e.g., the parent model algorithm, a linked map canvas,...
void setComments(const QString &text)
Sets the comment text.
QString comments() const
Returns the comment text.
const QgsProcessingAlgorithm * algorithm() const
Returns the algorithm associated with the widget.
std::unique_ptr< QgsProcessingModelChildAlgorithm > createAlgorithm()
Creates the child algorithm instance, populated with the current widget parameter values and comments...
void switchToCommentTab()
Focuses the widget on the comment editing tab.
QColor commentColor() const
Returns the comment's color.
void setStateFromChildAlgorithm()
Sets widget state from the existing child algorithm definition in the model.
QgsProcessingModelerParametersWidget(const QgsProcessingAlgorithm *childAlgorithm, QgsProcessingModelAlgorithm *model, QgsProcessingContext &context, const QString &childId=QString(), const QVariantMap &configuration=QVariantMap(), QWidget *parent=nullptr, QWidget *dialog=nullptr)
Constructor for QgsProcessingModelerParametersWidget.
Base class for the definition of processing parameters.
Contains settings which reflect the context in which a Processing parameter widget is shown.