74#include <QPlainTextEdit>
75#include <QRadioButton>
76#include <QButtonGroup>
90 QVBoxLayout *vlayout =
new QVBoxLayout();
91 vlayout->setContentsMargins( 0, 0, 0, 0 );
93 mDefaultCheckBox =
new QCheckBox( tr(
"Checked" ) );
97 mDefaultCheckBox->setChecked(
false );
98 vlayout->addWidget( mDefaultCheckBox );
102QgsProcessingParameterDefinition *QgsProcessingBooleanParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
104 auto param = std::make_unique< QgsProcessingParameterBoolean >( name, description, mDefaultCheckBox->isChecked() );
105 param->setFlags( flags );
106 return param.release();
116QWidget *QgsProcessingBooleanWidgetWrapper::createWidget()
122 QString description = parameterDefinition()->description();
124 description = QObject::tr(
"%1 [optional]" ).arg( description );
126 mCheckBox =
new QCheckBox( description );
127 mCheckBox->setToolTip( parameterDefinition()->toolTip() );
129 connect( mCheckBox, &QCheckBox::toggled,
this, [ = ]
131 emit widgetValueHasChanged(
this );
139 mComboBox =
new QComboBox();
140 mComboBox->addItem( tr(
"Yes" ),
true );
141 mComboBox->addItem( tr(
"No" ),
false );
142 mComboBox->setToolTip( parameterDefinition()->toolTip() );
144 connect( mComboBox, qOverload< int>( &QComboBox::currentIndexChanged ),
this, [ = ]
146 emit widgetValueHasChanged(
this );
155QLabel *QgsProcessingBooleanWidgetWrapper::createLabel()
164void QgsProcessingBooleanWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
171 mCheckBox->setChecked( v );
179 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
185QVariant QgsProcessingBooleanWidgetWrapper::widgetValue()
const
190 return mCheckBox->isChecked();
194 return mComboBox->currentData();
199QStringList QgsProcessingBooleanWidgetWrapper::compatibleParameterTypes()
const
221QStringList QgsProcessingBooleanWidgetWrapper::compatibleOutputTypes()
const
232QString QgsProcessingBooleanWidgetWrapper::parameterType()
const
239 return new QgsProcessingBooleanWidgetWrapper( parameter, type );
244 return new QgsProcessingBooleanParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
255 QVBoxLayout *vlayout =
new QVBoxLayout();
256 vlayout->setContentsMargins( 0, 0, 0, 0 );
258 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
263 mCrsSelector->setShowAccuracyWarnings(
true );
270 vlayout->addWidget( mCrsSelector );
271 setLayout( vlayout );
274QgsProcessingParameterDefinition *QgsProcessingCrsParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
276 auto param = std::make_unique< QgsProcessingParameterCrs >( name, description, mCrsSelector->crs().authid() );
277 param->setFlags( flags );
278 return param.release();
287QWidget *QgsProcessingCrsWidgetWrapper::createWidget()
289 Q_ASSERT( mProjectionSelectionWidget ==
nullptr );
291 mProjectionSelectionWidget->setToolTip( parameterDefinition()->toolTip() );
300 emit widgetValueHasChanged(
this );
308 return mProjectionSelectionWidget;
313 QWidget *w =
new QWidget();
314 w->setToolTip( parameterDefinition()->toolTip() );
316 QVBoxLayout *vl =
new QVBoxLayout();
317 vl->setContentsMargins( 0, 0, 0, 0 );
320 mUseProjectCrsCheckBox =
new QCheckBox( tr(
"Use project CRS" ) );
321 mUseProjectCrsCheckBox->setToolTip( tr(
"Always use the current project CRS when running the model" ) );
322 vl->addWidget( mUseProjectCrsCheckBox );
323 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, mProjectionSelectionWidget, &QgsProjectionSelectionWidget::setDisabled );
324 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled,
this, [ = ]
326 emit widgetValueHasChanged(
this );
329 vl->addWidget( mProjectionSelectionWidget );
337void QgsProcessingCrsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
339 if ( mUseProjectCrsCheckBox )
341 if ( value.toString().compare( QLatin1String(
"ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
343 mUseProjectCrsCheckBox->setChecked(
true );
348 mUseProjectCrsCheckBox->setChecked(
false );
353 if ( mProjectionSelectionWidget )
354 mProjectionSelectionWidget->setCrs( v );
357QVariant QgsProcessingCrsWidgetWrapper::widgetValue()
const
359 if ( mUseProjectCrsCheckBox && mUseProjectCrsCheckBox->isChecked() )
360 return QStringLiteral(
"ProjectCrs" );
361 else if ( mProjectionSelectionWidget )
362 return mProjectionSelectionWidget->crs().isValid() ? mProjectionSelectionWidget->crs() : QVariant();
367QStringList QgsProcessingCrsWidgetWrapper::compatibleParameterTypes()
const
381QStringList QgsProcessingCrsWidgetWrapper::compatibleOutputTypes()
const
389QString QgsProcessingCrsWidgetWrapper::modelerExpressionFormatString()
const
391 return tr(
"string as EPSG code, WKT or PROJ format, or a string identifying a map layer" );
394QString QgsProcessingCrsWidgetWrapper::parameterType()
const
401 return new QgsProcessingCrsWidgetWrapper( parameter, type );
406 return new QgsProcessingCrsParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
419 QVBoxLayout *vlayout =
new QVBoxLayout();
420 vlayout->setContentsMargins( 0, 0, 0, 0 );
422 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
424 mDefaultLineEdit =
new QLineEdit();
427 vlayout->addWidget( mDefaultLineEdit );
429 mMultiLineCheckBox =
new QCheckBox( tr(
"Multiline input" ) );
431 mMultiLineCheckBox->setChecked( stringParam->multiLine() );
432 vlayout->addWidget( mMultiLineCheckBox );
434 setLayout( vlayout );
437QgsProcessingParameterDefinition *QgsProcessingStringParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
439 auto param = std::make_unique< QgsProcessingParameterString >( name, description, mDefaultLineEdit->text(), mMultiLineCheckBox->isChecked() );
440 param->setFlags( flags );
441 return param.release();
452QWidget *QgsProcessingStringWidgetWrapper::createWidget()
454 const QVariantMap metadata = parameterDefinition()->metadata();
455 const QVariant valueHintsVariant = metadata.value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"value_hints" ) );
457 if ( valueHintsVariant.isValid() )
459 const QVariantList valueList = valueHintsVariant.toList();
460 mComboBox =
new QComboBox();
461 mComboBox->setToolTip( parameterDefinition()->toolTip() );
465 mComboBox->addItem( QString() );
467 for (
const QVariant &entry : valueList )
469 mComboBox->addItem( entry.toString(), entry.toString() );
471 mComboBox->setCurrentIndex( 0 );
473 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
475 emit widgetValueHasChanged(
this );
488 mPlainTextEdit =
new QPlainTextEdit();
489 mPlainTextEdit->setToolTip( parameterDefinition()->toolTip() );
491 connect( mPlainTextEdit, &QPlainTextEdit::textChanged,
this, [ = ]
493 emit widgetValueHasChanged(
this );
495 return mPlainTextEdit;
499 mLineEdit =
new QLineEdit();
500 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
502 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
504 emit widgetValueHasChanged(
this );
512 mLineEdit =
new QLineEdit();
513 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
515 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
517 emit widgetValueHasChanged(
this );
527void QgsProcessingStringWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
531 mLineEdit->setText( v );
532 if ( mPlainTextEdit )
533 mPlainTextEdit->setPlainText( v );
537 if ( !value.isValid() )
538 index = mComboBox->findData( QVariant() );
540 index = mComboBox->findData( v );
543 mComboBox->setCurrentIndex( index );
545 mComboBox->setCurrentIndex( 0 );
549QVariant QgsProcessingStringWidgetWrapper::widgetValue()
const
552 return mLineEdit->text();
553 else if ( mPlainTextEdit )
554 return mPlainTextEdit->toPlainText();
555 else if ( mComboBox )
556 return mComboBox->currentData();
561QStringList QgsProcessingStringWidgetWrapper::compatibleParameterTypes()
const
577QStringList QgsProcessingStringWidgetWrapper::compatibleOutputTypes()
const
585QString QgsProcessingStringWidgetWrapper::parameterType()
const
592 return new QgsProcessingStringWidgetWrapper( parameter, type );
597 return new QgsProcessingStringParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
612QWidget *QgsProcessingAuthConfigWidgetWrapper::createWidget()
621 mAuthConfigSelect->setToolTip( parameterDefinition()->toolTip() );
625 emit widgetValueHasChanged(
this );
627 return mAuthConfigSelect;
633void QgsProcessingAuthConfigWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
636 if ( mAuthConfigSelect )
637 mAuthConfigSelect->setConfigId( v );
640QVariant QgsProcessingAuthConfigWidgetWrapper::widgetValue()
const
642 if ( mAuthConfigSelect )
643 return mAuthConfigSelect->configId();
648QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleParameterTypes()
const
656QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleOutputTypes()
const
661QString QgsProcessingAuthConfigWidgetWrapper::parameterType()
const
668 return new QgsProcessingAuthConfigWidgetWrapper( parameter, type );
678 QVBoxLayout *vlayout =
new QVBoxLayout();
679 vlayout->setContentsMargins( 0, 0, 0, 0 );
681 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
683 mTypeComboBox =
new QComboBox();
686 vlayout->addWidget( mTypeComboBox );
688 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
689 mMinLineEdit =
new QLineEdit();
690 vlayout->addWidget( mMinLineEdit );
692 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
693 mMaxLineEdit =
new QLineEdit();
694 vlayout->addWidget( mMaxLineEdit );
696 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
697 mDefaultLineEdit =
new QLineEdit();
698 vlayout->addWidget( mDefaultLineEdit );
702 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( numberParam->dataType() ) );
704 if ( !
qgsDoubleNear( numberParam->maximum(), std::numeric_limits<double>::max() ) )
706 mMaxLineEdit->setText( QLocale().toString( numberParam->maximum() ) );
710 mMaxLineEdit->clear();
713 if ( !
qgsDoubleNear( numberParam->minimum(), std::numeric_limits<double>::lowest() ) )
715 mMinLineEdit->setText( QLocale().toString( numberParam->minimum() ) );
719 mMinLineEdit->clear();
722 mDefaultLineEdit->setText( numberParam->defaultValueForGui().toString() );
725 setLayout( vlayout );
728QgsProcessingParameterDefinition *QgsProcessingNumberParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
734 auto param = std::make_unique< QgsProcessingParameterNumber >( name, description, dataType, ok ? val : QVariant() );
736 if ( !mMinLineEdit->text().trimmed().isEmpty() )
741 param->setMinimum( val );
745 if ( !mMaxLineEdit->text().trimmed().isEmpty() )
750 param->setMaximum( val );
754 param->setFlags( flags );
755 return param.release();
764QWidget *QgsProcessingNumericWidgetWrapper::createWidget()
767 const QVariantMap metadata = numberDef->
metadata();
768 const int decimals = metadata.value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"decimals" ), 6 ).toInt();
776 QAbstractSpinBox *spinBox =
nullptr;
781 mDoubleSpinBox->setExpressionsEnabled(
true );
782 mDoubleSpinBox->setDecimals( decimals );
788 double singleStep = calculateStep( numberDef->
minimum(), numberDef->
maximum() );
789 singleStep = std::max( singleStep, std::pow( 10, -decimals ) );
790 mDoubleSpinBox->setSingleStep( singleStep );
793 spinBox = mDoubleSpinBox;
798 mSpinBox->setExpressionsEnabled(
true );
802 spinBox->setToolTip( parameterDefinition()->toolTip() );
804 double max = 999999999;
809 double min = -999999999;
814 if ( mDoubleSpinBox )
816 mDoubleSpinBox->setMinimum( min );
817 mDoubleSpinBox->setMaximum( max );
821 mSpinBox->setMinimum(
static_cast< int >( min ) );
822 mSpinBox->setMaximum(
static_cast< int >( max ) );
827 mAllowingNull =
true;
828 if ( mDoubleSpinBox )
830 mDoubleSpinBox->setShowClearButton(
true );
831 const double min = mDoubleSpinBox->minimum() - mDoubleSpinBox->singleStep();
832 mDoubleSpinBox->setMinimum( min );
833 mDoubleSpinBox->setValue( min );
837 mSpinBox->setShowClearButton(
true );
838 const int min = mSpinBox->minimum() - 1;
839 mSpinBox->setMinimum( min );
840 mSpinBox->setValue( min );
842 spinBox->setSpecialValueText( tr(
"Not set" ) );
850 if ( mDoubleSpinBox )
854 mDoubleSpinBox->setClearValue( defaultVal );
860 mSpinBox->setClearValue( intVal );
866 if ( mDoubleSpinBox )
867 mDoubleSpinBox->setClearValue( numberDef->
minimum() );
869 mSpinBox->setClearValue(
static_cast< int >( numberDef->
minimum() ) );
874 if ( mDoubleSpinBox )
876 mDoubleSpinBox->setValue( 0 );
877 mDoubleSpinBox->setClearValue( 0 );
881 mSpinBox->setValue( 0 );
882 mSpinBox->setClearValue( 0 );
887 if ( mDoubleSpinBox )
888 connect( mDoubleSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [ = ] { emit widgetValueHasChanged(
this ); } );
890 connect( mSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, [ = ] { emit widgetValueHasChanged(
this ); } );
898void QgsProcessingNumericWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
900 if ( mDoubleSpinBox )
902 if ( mAllowingNull && !value.isValid() )
903 mDoubleSpinBox->clear();
907 mDoubleSpinBox->setValue( v );
912 if ( mAllowingNull && !value.isValid() )
917 mSpinBox->setValue( v );
922QVariant QgsProcessingNumericWidgetWrapper::widgetValue()
const
924 if ( mDoubleSpinBox )
926 if ( mAllowingNull &&
qgsDoubleNear( mDoubleSpinBox->value(), mDoubleSpinBox->minimum() ) )
929 return mDoubleSpinBox->value();
933 if ( mAllowingNull && mSpinBox->value() == mSpinBox->minimum() )
936 return mSpinBox->value();
942QStringList QgsProcessingNumericWidgetWrapper::compatibleParameterTypes()
const
952QStringList QgsProcessingNumericWidgetWrapper::compatibleOutputTypes()
const
958double QgsProcessingNumericWidgetWrapper::calculateStep(
const double minimum,
const double maximum )
960 const double valueRange = maximum - minimum;
961 if ( valueRange <= 1.0 )
963 const double step = valueRange / 10.0;
965 return qgsRound( step, -std::floor( std::log( step ) ) );
973QString QgsProcessingNumericWidgetWrapper::parameterType()
const
980 return new QgsProcessingNumericWidgetWrapper( parameter, type );
985 return new QgsProcessingNumberParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
995 QVBoxLayout *vlayout =
new QVBoxLayout();
996 vlayout->setContentsMargins( 0, 0, 0, 0 );
998 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
1000 mParentLayerComboBox =
new QComboBox();
1002 QString initialParent;
1004 initialParent = distParam->parentParameterName();
1006 if (
auto *lModel = widgetContext.
model() )
1009 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
1010 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
1014 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1015 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1017 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1022 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1023 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1025 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1030 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1031 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1033 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1038 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1039 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1041 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1047 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
1050 mParentLayerComboBox->addItem( initialParent, initialParent );
1051 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1054 vlayout->addWidget( mParentLayerComboBox );
1056 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1057 mMinLineEdit =
new QLineEdit();
1058 vlayout->addWidget( mMinLineEdit );
1060 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1061 mMaxLineEdit =
new QLineEdit();
1062 vlayout->addWidget( mMaxLineEdit );
1064 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1065 mDefaultLineEdit =
new QLineEdit();
1066 vlayout->addWidget( mDefaultLineEdit );
1070 mMinLineEdit->setText( QLocale().toString( distParam->minimum() ) );
1071 mMaxLineEdit->setText( QLocale().toString( distParam->maximum() ) );
1072 mDefaultLineEdit->setText( distParam->defaultValueForGui().toString() );
1075 setLayout( vlayout );
1078QgsProcessingParameterDefinition *QgsProcessingDistanceParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1083 auto param = std::make_unique< QgsProcessingParameterDistance >( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1088 param->setMinimum( val );
1094 param->setMaximum( val );
1097 param->setFlags( flags );
1098 return param.release();
1102 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1107QString QgsProcessingDistanceWidgetWrapper::parameterType()
const
1114 return new QgsProcessingDistanceWidgetWrapper( parameter, type );
1117QWidget *QgsProcessingDistanceWidgetWrapper::createWidget()
1121 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1126 mLabel =
new QLabel();
1127 mUnitsCombo =
new QComboBox();
1135 const int labelMargin =
static_cast< int >( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1136 QHBoxLayout *layout =
new QHBoxLayout();
1137 layout->addWidget( spin, 1 );
1138 layout->insertSpacing( 1, labelMargin / 2 );
1139 layout->insertWidget( 2, mLabel );
1140 layout->insertWidget( 3, mUnitsCombo );
1145 mWarningLabel =
new QWidget();
1146 QHBoxLayout *warningLayout =
new QHBoxLayout();
1147 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1148 QLabel *warning =
new QLabel();
1150 const int size =
static_cast< int >( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1151 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1152 warning->setToolTip( tr(
"Distance is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1153 warningLayout->insertSpacing( 0, labelMargin / 2 );
1154 warningLayout->insertWidget( 1, warning );
1155 mWarningLabel->setLayout( warningLayout );
1156 layout->insertWidget( 4, mWarningLabel );
1158 QWidget *w =
new QWidget();
1159 layout->setContentsMargins( 0, 0, 0, 0 );
1160 w->setLayout( layout );
1175void QgsProcessingDistanceWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1177 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1184 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterDistance *
>( parameterDefinition() )->parentParameterName() )
1186 setUnitParameterValue( wrapper->parameterValue() );
1189 setUnitParameterValue( wrapper->parameterValue() );
1203void QgsProcessingDistanceWidgetWrapper::setUnitParameterValue(
const QVariant &value )
1209 std::unique_ptr< QgsProcessingContext > tmpContext;
1210 if ( mProcessingContextGenerator )
1211 context = mProcessingContextGenerator->processingContext();
1215 tmpContext = std::make_unique< QgsProcessingContext >();
1216 context = tmpContext.get();
1233 mUnitsCombo->hide();
1238 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( units ) );
1239 mUnitsCombo->show();
1246QVariant QgsProcessingDistanceWidgetWrapper::widgetValue()
const
1248 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1249 if ( val.type() == QVariant::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1262 return new QgsProcessingDistanceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1273 QVBoxLayout *vlayout =
new QVBoxLayout();
1274 vlayout->setContentsMargins( 0, 0, 0, 0 );
1276 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1277 mMinLineEdit =
new QLineEdit();
1278 vlayout->addWidget( mMinLineEdit );
1280 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1281 mMaxLineEdit =
new QLineEdit();
1282 vlayout->addWidget( mMaxLineEdit );
1284 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1285 mDefaultLineEdit =
new QLineEdit();
1286 vlayout->addWidget( mDefaultLineEdit );
1288 vlayout->addWidget(
new QLabel( tr(
"Default unit type" ) ) );
1290 mUnitsCombo =
new QComboBox();
1300 vlayout->addWidget( mUnitsCombo );
1304 mMinLineEdit->setText( QLocale().toString( durationParam->minimum() ) );
1305 mMaxLineEdit->setText( QLocale().toString( durationParam->maximum() ) );
1306 mDefaultLineEdit->setText( durationParam->defaultValueForGui().toString() );
1307 mUnitsCombo->setCurrentIndex( durationParam->defaultUnit() );
1310 setLayout( vlayout );
1313QgsProcessingParameterDefinition *QgsProcessingDurationParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1318 auto param = std::make_unique< QgsProcessingParameterDuration >( name, description, ok ? val : QVariant() );
1323 param->setMinimum( val );
1329 param->setMaximum( val );
1334 param->setFlags( flags );
1335 return param.release();
1339 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1344QString QgsProcessingDurationWidgetWrapper::parameterType()
const
1351 return new QgsProcessingDurationWidgetWrapper( parameter, type );
1354QWidget *QgsProcessingDurationWidgetWrapper::createWidget()
1358 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1363 mUnitsCombo =
new QComboBox();
1375 QHBoxLayout *layout =
new QHBoxLayout();
1376 layout->addWidget( spin, 1 );
1377 layout->insertWidget( 1, mUnitsCombo );
1379 QWidget *w =
new QWidget();
1380 layout->setContentsMargins( 0, 0, 0, 0 );
1381 w->setLayout( layout );
1383 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( durationDef->
defaultUnit() ) );
1384 mUnitsCombo->show();
1397QLabel *QgsProcessingDurationWidgetWrapper::createLabel()
1409QVariant QgsProcessingDurationWidgetWrapper::widgetValue()
const
1411 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1412 if ( val.type() == QVariant::Double && mUnitsCombo )
1423void QgsProcessingDurationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1429 QgsProcessingNumericWidgetWrapper::setWidgetValue( val, context );
1433 QgsProcessingNumericWidgetWrapper::setWidgetValue( value, context );
1439 return new QgsProcessingDurationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1449 QVBoxLayout *vlayout =
new QVBoxLayout();
1450 vlayout->setContentsMargins( 0, 0, 0, 0 );
1452 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1454 mDefaultLineEdit =
new QLineEdit();
1458 mDefaultLineEdit->setText( scaleParam->defaultValueForGui().toString() );
1461 vlayout->addWidget( mDefaultLineEdit );
1463 setLayout( vlayout );
1466QgsProcessingParameterDefinition *QgsProcessingScaleParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1469 double val = mDefaultLineEdit->text().toDouble( &ok );
1470 auto param = std::make_unique< QgsProcessingParameterScale >( name, description, ok ? val : QVariant() );
1471 param->setFlags( flags );
1472 return param.release();
1476 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1481QString QgsProcessingScaleWidgetWrapper::parameterType()
const
1488 return new QgsProcessingScaleWidgetWrapper( parameter, type );
1491QWidget *QgsProcessingScaleWidgetWrapper::createWidget()
1503 mScaleWidget->setAllowNull(
true );
1505 mScaleWidget->setMapCanvas( widgetContext().mapCanvas() );
1506 mScaleWidget->setShowCurrentScaleButton(
true );
1508 mScaleWidget->setToolTip( parameterDefinition()->toolTip() );
1511 emit widgetValueHasChanged(
this );
1513 return mScaleWidget;
1522 mScaleWidget->setMapCanvas( context.
mapCanvas() );
1527QVariant QgsProcessingScaleWidgetWrapper::widgetValue()
const
1529 return mScaleWidget && !mScaleWidget->isNull() ? QVariant( mScaleWidget->scale() ) : QVariant();
1532void QgsProcessingScaleWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1536 if ( mScaleWidget->allowNull() && !value.isValid() )
1537 mScaleWidget->setNull();
1541 mScaleWidget->setScale( v );
1548 return new QgsProcessingScaleParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1559 QVBoxLayout *vlayout =
new QVBoxLayout();
1560 vlayout->setContentsMargins( 0, 0, 0, 0 );
1562 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
1564 mTypeComboBox =
new QComboBox();
1567 vlayout->addWidget( mTypeComboBox );
1569 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1570 mMinLineEdit =
new QLineEdit();
1571 vlayout->addWidget( mMinLineEdit );
1573 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1574 mMaxLineEdit =
new QLineEdit();
1575 vlayout->addWidget( mMaxLineEdit );
1579 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( rangeParam->dataType() ) );
1581 mMinLineEdit->setText( QLocale().toString( range.at( 0 ) ) );
1582 mMaxLineEdit->setText( QLocale().toString( range.at( 1 ) ) );
1585 setLayout( vlayout );
1588QgsProcessingParameterDefinition *QgsProcessingRangeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1590 QString defaultValue;
1591 if ( mMinLineEdit->text().isEmpty() )
1593 defaultValue = QStringLiteral(
"None" );
1601 defaultValue = QStringLiteral(
"None" );
1605 if ( mMaxLineEdit->text().isEmpty() )
1607 defaultValue += QLatin1String(
",None" );
1613 defaultValue += QStringLiteral(
",%1" ).arg( ok ? QString::number( val ) : QLatin1String(
"None" ) );
1617 auto param = std::make_unique< QgsProcessingParameterRange >( name, description, dataType, defaultValue );
1618 param->setFlags( flags );
1619 return param.release();
1629QWidget *QgsProcessingRangeWidgetWrapper::createWidget()
1638 QHBoxLayout *layout =
new QHBoxLayout();
1643 mMinSpinBox->setExpressionsEnabled(
true );
1644 mMinSpinBox->setShowClearButton(
false );
1645 mMaxSpinBox->setExpressionsEnabled(
true );
1646 mMaxSpinBox->setShowClearButton(
false );
1648 QLabel *minLabel =
new QLabel( tr(
"Min" ) );
1649 layout->addWidget( minLabel );
1650 layout->addWidget( mMinSpinBox, 1 );
1652 QLabel *maxLabel =
new QLabel( tr(
"Max" ) );
1653 layout->addWidget( maxLabel );
1654 layout->addWidget( mMaxSpinBox, 1 );
1656 QWidget *w =
new QWidget();
1657 layout->setContentsMargins( 0, 0, 0, 0 );
1658 w->setLayout( layout );
1662 mMinSpinBox->setDecimals( 6 );
1663 mMaxSpinBox->setDecimals( 6 );
1667 mMinSpinBox->setDecimals( 0 );
1668 mMaxSpinBox->setDecimals( 0 );
1671 mMinSpinBox->setMinimum( -99999999.999999 );
1672 mMaxSpinBox->setMinimum( -99999999.999999 );
1673 mMinSpinBox->setMaximum( 99999999.999999 );
1674 mMaxSpinBox->setMaximum( 99999999.999999 );
1678 mAllowingNull =
true;
1680 const double min = mMinSpinBox->minimum() - 1;
1681 mMinSpinBox->setMinimum( min );
1682 mMaxSpinBox->setMinimum( min );
1683 mMinSpinBox->setValue( min );
1684 mMaxSpinBox->setValue( min );
1686 mMinSpinBox->setShowClearButton(
true );
1687 mMaxSpinBox->setShowClearButton(
true );
1688 mMinSpinBox->setSpecialValueText( tr(
"Not set" ) );
1689 mMaxSpinBox->setSpecialValueText( tr(
"Not set" ) );
1692 w->setToolTip( parameterDefinition()->toolTip() );
1694 connect( mMinSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
const double v )
1696 mBlockChangedSignal++;
1697 if ( !mAllowingNull && v > mMaxSpinBox->value() )
1698 mMaxSpinBox->setValue( v );
1699 mBlockChangedSignal--;
1701 if ( !mBlockChangedSignal )
1702 emit widgetValueHasChanged(
this );
1704 connect( mMaxSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
const double v )
1706 mBlockChangedSignal++;
1707 if ( !mAllowingNull && v < mMinSpinBox->value() )
1708 mMinSpinBox->setValue( v );
1709 mBlockChangedSignal--;
1711 if ( !mBlockChangedSignal )
1712 emit widgetValueHasChanged(
this );
1721void QgsProcessingRangeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1724 if ( mAllowingNull && v.empty() )
1726 mMinSpinBox->clear();
1727 mMaxSpinBox->clear();
1734 if ( mAllowingNull )
1736 mBlockChangedSignal++;
1737 if ( std::isnan( v.at( 0 ) ) )
1738 mMinSpinBox->clear();
1740 mMinSpinBox->setValue( v.at( 0 ) );
1742 if ( v.count() >= 2 )
1744 if ( std::isnan( v.at( 1 ) ) )
1745 mMaxSpinBox->clear();
1747 mMaxSpinBox->setValue( v.at( 1 ) );
1749 mBlockChangedSignal--;
1753 mBlockChangedSignal++;
1754 mMinSpinBox->setValue( v.at( 0 ) );
1755 if ( v.count() >= 2 )
1756 mMaxSpinBox->setValue( v.at( 1 ) );
1757 mBlockChangedSignal--;
1761 if ( !mBlockChangedSignal )
1762 emit widgetValueHasChanged(
this );
1765QVariant QgsProcessingRangeWidgetWrapper::widgetValue()
const
1767 if ( mAllowingNull )
1770 if (
qgsDoubleNear( mMinSpinBox->value(), mMinSpinBox->minimum() ) )
1771 value = QStringLiteral(
"None" );
1773 value = QString::number( mMinSpinBox->value() );
1775 if (
qgsDoubleNear( mMaxSpinBox->value(), mMaxSpinBox->minimum() ) )
1776 value += QLatin1String(
",None" );
1778 value += QStringLiteral(
",%1" ).arg( mMaxSpinBox->value() );
1783 return QStringLiteral(
"%1,%2" ).arg( mMinSpinBox->value() ).arg( mMaxSpinBox->value() );
1786QStringList QgsProcessingRangeWidgetWrapper::compatibleParameterTypes()
const
1788 return QStringList()
1793QStringList QgsProcessingRangeWidgetWrapper::compatibleOutputTypes()
const
1798QString QgsProcessingRangeWidgetWrapper::modelerExpressionFormatString()
const
1800 return tr(
"string as two comma delimited floats, e.g. '1,10'" );
1803QString QgsProcessingRangeWidgetWrapper::parameterType()
const
1810 return new QgsProcessingRangeWidgetWrapper( parameter, type );
1815 return new QgsProcessingRangeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1826 QVBoxLayout *vlayout =
new QVBoxLayout();
1827 vlayout->setContentsMargins( 0, 0, 0, 0 );
1829 mMatrixWidget =
new QgsProcessingMatrixModelerWidget();
1832 mMatrixWidget->setValue( matrixParam->headers(), matrixParam->defaultValueForGui() );
1833 mMatrixWidget->setFixedRows( matrixParam->hasFixedNumberRows() );
1835 vlayout->addWidget( mMatrixWidget );
1836 setLayout( vlayout );
1839QgsProcessingParameterDefinition *QgsProcessingMatrixParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1841 auto param = std::make_unique< QgsProcessingParameterMatrix >( name, description, 1, mMatrixWidget->fixedRows(), mMatrixWidget->headers(), mMatrixWidget->value() );
1842 param->setFlags( flags );
1843 return param.release();
1853QWidget *QgsProcessingMatrixWidgetWrapper::createWidget()
1855 mMatrixWidget =
new QgsProcessingMatrixParameterPanel(
nullptr,
dynamic_cast< const QgsProcessingParameterMatrix *
>( parameterDefinition() ) );
1856 mMatrixWidget->setToolTip( parameterDefinition()->toolTip() );
1858 connect( mMatrixWidget, &QgsProcessingMatrixParameterPanel::changed,
this, [ = ]
1860 emit widgetValueHasChanged(
this );
1869 return mMatrixWidget;
1875void QgsProcessingMatrixWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1878 if ( mMatrixWidget )
1879 mMatrixWidget->setValue( v );
1882QVariant QgsProcessingMatrixWidgetWrapper::widgetValue()
const
1884 if ( mMatrixWidget )
1885 return mMatrixWidget->value().isEmpty() ? QVariant() : mMatrixWidget->value();
1890QStringList QgsProcessingMatrixWidgetWrapper::compatibleParameterTypes()
const
1892 return QStringList()
1896QStringList QgsProcessingMatrixWidgetWrapper::compatibleOutputTypes()
const
1898 return QStringList();
1901QString QgsProcessingMatrixWidgetWrapper::modelerExpressionFormatString()
const
1903 return tr(
"comma delimited string of values, or an array of values" );
1906QString QgsProcessingMatrixWidgetWrapper::parameterType()
const
1913 return new QgsProcessingMatrixWidgetWrapper( parameter, type );
1918 return new QgsProcessingMatrixParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1930 QVBoxLayout *vlayout =
new QVBoxLayout();
1931 vlayout->setContentsMargins( 0, 0, 0, 0 );
1933 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
1935 mTypeComboBox =
new QComboBox();
1939 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( fileParam->behavior() ) );
1941 mTypeComboBox->setCurrentIndex( 0 );
1942 vlayout->addWidget( mTypeComboBox );
1944 vlayout->addWidget(
new QLabel( tr(
"File filter" ) ) );
1946 mFilterComboBox =
new QComboBox();
1947 mFilterComboBox->setEditable(
true );
1949 mFilterComboBox->addItem( tr(
"All Files (*.*)" ) );
1950 mFilterComboBox->addItem( tr(
"CSV Files (*.csv)" ) );
1951 mFilterComboBox->addItem( tr(
"HTML Files (*.html *.htm)" ) );
1952 mFilterComboBox->addItem( tr(
"Text Files (*.txt)" ) );
1954 mFilterComboBox->setCurrentText( fileParam->fileFilter() );
1956 mFilterComboBox->setCurrentIndex( 0 );
1957 vlayout->addWidget( mFilterComboBox );
1959 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1962 mDefaultFileWidget->lineEdit()->setShowClearButton(
true );
1966 mDefaultFileWidget->setFilePath( fileParam->defaultValueForGui().toString() );
1970 vlayout->addWidget( mDefaultFileWidget );
1972 connect( mTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ]
1981 setLayout( vlayout );
1984QgsProcessingParameterDefinition *QgsProcessingFileParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1986 auto param = std::make_unique< QgsProcessingParameterFile >( name, description );
1989 param->setFileFilter( mFilterComboBox->currentText() );
1990 if ( !mDefaultFileWidget->filePath().isEmpty() )
1991 param->setDefaultValue( mDefaultFileWidget->filePath() );
1992 param->setFlags( flags );
1993 return param.release();
2003QWidget *QgsProcessingFileWidgetWrapper::createWidget()
2013 mFileWidget->setToolTip( parameterDefinition()->toolTip() );
2014 mFileWidget->setDialogTitle( parameterDefinition()->description() );
2016 mFileWidget->setDefaultRoot(
QgsSettings().value( QStringLiteral(
"/Processing/LastInputPath" ), QDir::homePath() ).toString() );
2023 mFileWidget->setFilter( fileParam->
fileFilter() );
2024 else if ( !fileParam->
extension().isEmpty() )
2025 mFileWidget->setFilter( tr(
"%1 files" ).arg( fileParam->
extension().toUpper() ) + QStringLiteral(
" (*." ) + fileParam->
extension().toLower() +
')' );
2035 QgsSettings().
setValue( QStringLiteral(
"/Processing/LastInputPath" ), QFileInfo( path ).canonicalPath() );
2036 emit widgetValueHasChanged(
this );
2044void QgsProcessingFileWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2048 mFileWidget->setFilePath( v );
2051QVariant QgsProcessingFileWidgetWrapper::widgetValue()
const
2054 return mFileWidget->filePath();
2059QStringList QgsProcessingFileWidgetWrapper::compatibleParameterTypes()
const
2061 return QStringList()
2066QStringList QgsProcessingFileWidgetWrapper::compatibleOutputTypes()
const
2076QString QgsProcessingFileWidgetWrapper::modelerExpressionFormatString()
const
2078 return tr(
"string representing a path to a file or folder" );
2081QString QgsProcessingFileWidgetWrapper::parameterType()
const
2088 return new QgsProcessingFileWidgetWrapper( parameter, type );
2093 return new QgsProcessingFileParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2105 QVBoxLayout *vlayout =
new QVBoxLayout();
2106 vlayout->setContentsMargins( 0, 0, 0, 0 );
2107 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2110 mDefaultLineEdit->registerExpressionContextGenerator(
this );
2114 vlayout->addWidget( mDefaultLineEdit );
2116 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
2118 mParentLayerComboBox =
new QComboBox();
2119 mParentLayerComboBox->addItem( tr(
"None" ), QVariant() );
2121 QString initialParent;
2123 initialParent = expParam->parentLayerParameterName();
2125 if ( QgsProcessingModelAlgorithm *model = widgetContext.
model() )
2128 const QMap<QString, QgsProcessingModelParameter> components = model->parameterComponents();
2129 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
2133 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
2134 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2136 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2141 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
2142 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2144 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2150 if ( mParentLayerComboBox->count() == 1 && !initialParent.isEmpty() )
2153 mParentLayerComboBox->addItem( initialParent, initialParent );
2154 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2157 vlayout->addWidget( mParentLayerComboBox );
2158 setLayout( vlayout );
2161QgsProcessingParameterDefinition *QgsProcessingExpressionParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
2163 auto param = std::make_unique< QgsProcessingParameterExpression >( name, description, mDefaultLineEdit->expression(), mParentLayerComboBox->currentData().toString() );
2164 param->setFlags( flags );
2165 return param.release();
2174QWidget *QgsProcessingExpressionWidgetWrapper::createWidget()
2186 mExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2187 mExpLineEdit->setExpressionDialogTitle( parameterDefinition()->description() );
2188 mExpLineEdit->registerExpressionContextGenerator(
this );
2191 emit widgetValueHasChanged(
this );
2193 return mExpLineEdit;
2197 if ( expParam->
metadata().value( QStringLiteral(
"inlineEditor" ) ).toBool() )
2200 mExpBuilderWidget->setToolTip( parameterDefinition()->toolTip() );
2201 mExpBuilderWidget->init( createExpressionContext() );
2204 Q_UNUSED( changed );
2205 emit widgetValueHasChanged(
this );
2207 return mExpBuilderWidget;
2212 mFieldExpWidget->setToolTip( parameterDefinition()->toolTip() );
2213 mFieldExpWidget->setExpressionDialogTitle( parameterDefinition()->description() );
2214 mFieldExpWidget->registerExpressionContextGenerator(
this );
2216 mFieldExpWidget->setAllowEmptyFieldName(
true );
2220 emit widgetValueHasChanged(
this );
2222 return mFieldExpWidget;
2230void QgsProcessingExpressionWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
2240 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterExpression *
>( parameterDefinition() )->parentLayerParameterName() )
2242 setParentLayerWrapperValue( wrapper );
2245 setParentLayerWrapperValue( wrapper );
2261 if ( mExpBuilderWidget )
2264 mExpBuilderWidget->setExpressionContext( createExpressionContext() );
2272 std::unique_ptr< QgsProcessingContext > tmpContext;
2273 if ( mProcessingContextGenerator )
2274 context = mProcessingContextGenerator->processingContext();
2278 tmpContext = std::make_unique< QgsProcessingContext >();
2279 context = tmpContext.get();
2283 if ( val.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
2293 if ( mFieldExpWidget )
2294 mFieldExpWidget->setLayer(
nullptr );
2295 else if ( mExpBuilderWidget )
2296 mExpBuilderWidget->setLayer(
nullptr );
2297 else if ( mExpLineEdit )
2298 mExpLineEdit->setLayer(
nullptr );
2304 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
2307 mParentLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
2308 layer = mParentLayer.get();
2315 if ( mFieldExpWidget )
2316 mFieldExpWidget->setLayer( layer );
2317 if ( mExpBuilderWidget )
2318 mExpBuilderWidget->setLayer( layer );
2319 else if ( mExpLineEdit )
2320 mExpLineEdit->setLayer( layer );
2323void QgsProcessingExpressionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2326 if ( mFieldExpWidget )
2327 mFieldExpWidget->setExpression( v );
2328 else if ( mExpBuilderWidget )
2329 mExpBuilderWidget->setExpressionText( v );
2330 else if ( mExpLineEdit )
2331 mExpLineEdit->setExpression( v );
2334QVariant QgsProcessingExpressionWidgetWrapper::widgetValue()
const
2336 if ( mFieldExpWidget )
2337 return mFieldExpWidget->expression();
2338 if ( mExpBuilderWidget )
2339 return mExpBuilderWidget->expressionText();
2340 else if ( mExpLineEdit )
2341 return mExpLineEdit->expression();
2346QStringList QgsProcessingExpressionWidgetWrapper::compatibleParameterTypes()
const
2348 return QStringList()
2357QStringList QgsProcessingExpressionWidgetWrapper::compatibleOutputTypes()
const
2359 return QStringList()
2364QString QgsProcessingExpressionWidgetWrapper::modelerExpressionFormatString()
const
2366 return tr(
"string representation of an expression" );
2369const QgsVectorLayer *QgsProcessingExpressionWidgetWrapper::linkedVectorLayer()
const
2371 if ( mFieldExpWidget && mFieldExpWidget->layer() )
2372 return mFieldExpWidget->layer();
2374 if ( mExpBuilderWidget && mExpBuilderWidget->layer() )
2375 return mExpBuilderWidget->layer();
2380QString QgsProcessingExpressionWidgetWrapper::parameterType()
const
2387 return new QgsProcessingExpressionWidgetWrapper( parameter, type );
2392 return new QgsProcessingExpressionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2405 QHBoxLayout *hl =
new QHBoxLayout();
2406 hl->setContentsMargins( 0, 0, 0, 0 );
2408 mLineEdit =
new QLineEdit();
2409 mLineEdit->setEnabled(
false );
2410 hl->addWidget( mLineEdit, 1 );
2412 mToolButton =
new QToolButton();
2413 mToolButton->setText( QString( QChar( 0x2026 ) ) );
2414 hl->addWidget( mToolButton );
2420 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
2423 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingEnumPanelWidget::showDialog );
2426void QgsProcessingEnumPanelWidget::setValue(
const QVariant &value )
2428 if ( value.isValid() )
2430 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
2432 if ( mParam->usesStaticStrings() && mValue.count() == 1 && mValue.at( 0 ).toString().isEmpty() )
2438 updateSummaryText();
2442void QgsProcessingEnumPanelWidget::showDialog()
2444 QVariantList availableOptions;
2447 availableOptions.reserve( mParam->options().size() );
2448 for (
int i = 0; i < mParam->options().count(); ++i )
2449 availableOptions << i;
2452 const QStringList options = mParam ? mParam->options() : QStringList();
2456 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
2457 widget->setPanelTitle( mParam->description() );
2459 if ( mParam->usesStaticStrings() )
2461 widget->setValueFormatter( [options](
const QVariant & v ) -> QString
2463 const QString i = v.toString();
2464 return options.contains( i ) ? i : QString();
2469 widget->setValueFormatter( [options](
const QVariant & v ) -> QString
2471 const int i = v.toInt();
2472 return options.size() > i ? options.at( i ) : QString();
2476 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
2478 setValue( widget->selectedOptions() );
2485 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
2487 dlg.setValueFormatter( [options](
const QVariant & v ) -> QString
2489 const int i = v.toInt();
2490 return options.size() > i ? options.at( i ) : QString();
2494 setValue( dlg.selectedOptions() );
2499void QgsProcessingEnumPanelWidget::updateSummaryText()
2504 if ( mValue.empty() )
2506 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
2511 values.reserve( mValue.size() );
2512 if ( mParam->usesStaticStrings() )
2514 for (
const QVariant &val : std::as_const( mValue ) )
2516 values << val.toString();
2521 const QStringList options = mParam->options();
2522 for (
const QVariant &val : std::as_const( mValue ) )
2524 const int i = val.toInt();
2525 values << ( options.size() > i ? options.at( i ) : QString() );
2529 const QString concatenated = values.join( tr(
"," ) );
2530 if ( concatenated.length() < 100 )
2531 mLineEdit->setText( concatenated );
2533 mLineEdit->setText( tr(
"%n option(s) selected",
nullptr, mValue.count() ) );
2541QgsProcessingEnumCheckboxPanelWidget::QgsProcessingEnumCheckboxPanelWidget( QWidget *parent,
const QgsProcessingParameterEnum *param,
int columns )
2544 , mButtonGroup( new QButtonGroup( this ) )
2545 , mColumns( columns )
2547 mButtonGroup->setExclusive( !mParam->allowMultiple() );
2549 QGridLayout *l =
new QGridLayout();
2550 l->setContentsMargins( 0, 0, 0, 0 );
2552 int rows =
static_cast< int >( std::ceil( mParam->options().count() /
static_cast< double >( mColumns ) ) );
2553 for (
int i = 0; i < mParam->options().count(); ++i )
2555 QAbstractButton *button =
nullptr;
2556 if ( mParam->allowMultiple() )
2557 button =
new QCheckBox( mParam->options().at( i ) );
2559 button =
new QRadioButton( mParam->options().at( i ) );
2561 connect( button, &QAbstractButton::toggled,
this, [ = ]
2563 if ( !mBlockChangedSignal )
2567 mButtons.insert( i, button );
2569 mButtonGroup->addButton( button, i );
2570 l->addWidget( button, i % rows, i / rows );
2572 l->addItem(
new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, mColumns );
2575 if ( mParam->allowMultiple() )
2577 setContextMenuPolicy( Qt::CustomContextMenu );
2578 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsProcessingEnumCheckboxPanelWidget::showPopupMenu );
2582QVariant QgsProcessingEnumCheckboxPanelWidget::value()
const
2584 if ( mParam->allowMultiple() )
2587 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2589 if ( it.value()->isChecked() )
2590 value.append( mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key() );
2596 if ( mParam->usesStaticStrings() )
2597 return mButtonGroup->checkedId() >= 0 ? mParam->options().at( mButtonGroup->checkedId() ) : QVariant();
2599 return mButtonGroup->checkedId() >= 0 ? mButtonGroup->checkedId() : QVariant();
2603void QgsProcessingEnumCheckboxPanelWidget::setValue(
const QVariant &value )
2605 mBlockChangedSignal =
true;
2606 if ( mParam->allowMultiple() )
2608 QVariantList selected;
2609 if ( value.isValid() )
2610 selected = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
2611 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2613 QVariant v = mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key();
2614 it.value()->setChecked( selected.contains( v ) );
2620 if ( v.type() == QVariant::List )
2621 v = v.toList().value( 0 );
2623 v = mParam->usesStaticStrings() ? mParam->options().indexOf( v.toString() ) : v;
2624 if ( mButtons.contains( v ) )
2625 mButtons.value( v )->setChecked(
true );
2627 mBlockChangedSignal =
false;
2631void QgsProcessingEnumCheckboxPanelWidget::showPopupMenu()
2634 QAction *selectAllAction =
new QAction( tr(
"Select All" ), &popupMenu );
2635 connect( selectAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::selectAll );
2636 QAction *clearAllAction =
new QAction( tr(
"Clear Selection" ), &popupMenu );
2637 connect( clearAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::deselectAll );
2638 popupMenu.addAction( selectAllAction );
2639 popupMenu.addAction( clearAllAction );
2640 popupMenu.exec( QCursor::pos() );
2643void QgsProcessingEnumCheckboxPanelWidget::selectAll()
2645 mBlockChangedSignal =
true;
2646 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2647 it.value()->setChecked(
true );
2648 mBlockChangedSignal =
false;
2652void QgsProcessingEnumCheckboxPanelWidget::deselectAll()
2654 mBlockChangedSignal =
true;
2655 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2656 it.value()->setChecked(
false );
2657 mBlockChangedSignal =
false;
2669 QVBoxLayout *vlayout =
new QVBoxLayout();
2670 vlayout->setContentsMargins( 0, 0, 0, 0 );
2672 mEnumWidget =
new QgsProcessingEnumModelerWidget();
2675 mEnumWidget->setAllowMultiple( enumParam->allowMultiple() );
2676 mEnumWidget->setOptions( enumParam->options() );
2677 mEnumWidget->setDefaultOptions( enumParam->defaultValueForGui() );
2679 vlayout->addWidget( mEnumWidget );
2680 setLayout( vlayout );
2683QgsProcessingParameterDefinition *QgsProcessingEnumParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
2685 auto param = std::make_unique< QgsProcessingParameterEnum >( name, description, mEnumWidget->options(), mEnumWidget->allowMultiple(), mEnumWidget->defaultOptions() );
2687 return param.release();
2697QWidget *QgsProcessingEnumWidgetWrapper::createWidget()
2705 if ( expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"useCheckBoxes" ),
false ).toBool() )
2707 const int columns = expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"columns" ), 2 ).toInt();
2708 mCheckboxPanel =
new QgsProcessingEnumCheckboxPanelWidget(
nullptr, expParam, columns );
2709 mCheckboxPanel->setToolTip( parameterDefinition()->toolTip() );
2710 connect( mCheckboxPanel, &QgsProcessingEnumCheckboxPanelWidget::changed,
this, [ = ]
2712 emit widgetValueHasChanged(
this );
2714 return mCheckboxPanel;
2723 mPanel =
new QgsProcessingEnumPanelWidget(
nullptr, expParam );
2724 mPanel->setToolTip( parameterDefinition()->toolTip() );
2725 connect( mPanel, &QgsProcessingEnumPanelWidget::changed,
this, [ = ]
2727 emit widgetValueHasChanged(
this );
2733 mComboBox =
new QComboBox();
2736 mComboBox->addItem( tr(
"[Not selected]" ), QVariant() );
2737 const QStringList options = expParam->
options();
2738 const QVariantList iconList = expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"icons" ) ).toList();
2739 for (
int i = 0; i < options.count(); ++i )
2741 const QIcon icon = iconList.value( i ).value< QIcon >();
2744 mComboBox->addItem( icon, options.at( i ), options.at( i ) );
2746 mComboBox->addItem( icon, options.at( i ), i );
2749 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2750 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
2752 emit widgetValueHasChanged(
this );
2761void QgsProcessingEnumWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2765 if ( !value.isValid() )
2766 mComboBox->setCurrentIndex( mComboBox->findData( QVariant() ) );
2773 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
2778 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
2782 else if ( mPanel || mCheckboxPanel )
2785 if ( value.isValid() )
2791 opts.reserve( v.size() );
2792 for ( QString i : v )
2798 opts.reserve( v.size() );
2804 mPanel->setValue( opts );
2805 else if ( mCheckboxPanel )
2806 mCheckboxPanel->setValue( opts );
2810QVariant QgsProcessingEnumWidgetWrapper::widgetValue()
const
2813 return mComboBox->currentData();
2815 return mPanel->value();
2816 else if ( mCheckboxPanel )
2817 return mCheckboxPanel->value();
2822QStringList QgsProcessingEnumWidgetWrapper::compatibleParameterTypes()
const
2824 return QStringList()
2830QStringList QgsProcessingEnumWidgetWrapper::compatibleOutputTypes()
const
2832 return QStringList()
2837QString QgsProcessingEnumWidgetWrapper::modelerExpressionFormatString()
const
2839 return tr(
"selected option index (starting from 0), array of indices, or comma separated string of options (e.g. '1,3')" );
2842QString QgsProcessingEnumWidgetWrapper::parameterType()
const
2849 return new QgsProcessingEnumWidgetWrapper( parameter, type );
2854 return new QgsProcessingEnumParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2867QWidget *QgsProcessingLayoutWidgetWrapper::createWidget()
2876 mComboBox =
new QgsLayoutComboBox(
nullptr, widgetContext().project() ? widgetContext().project()->layoutManager() :
nullptr );
2878 mComboBox->setAllowEmptyLayout(
true );
2881 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2884 emit widgetValueHasChanged(
this );
2891 mPlainComboBox =
new QComboBox();
2892 mPlainComboBox->setEditable(
true );
2893 mPlainComboBox->setToolTip( tr(
"Name of an existing print layout" ) );
2894 if ( widgetContext().project() )
2898 mPlainComboBox->addItem( layout->name() );
2901 connect( mPlainComboBox, &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
2903 emit widgetValueHasChanged(
this );
2905 return mPlainComboBox;
2911void QgsProcessingLayoutWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2915 if ( !value.isValid() )
2916 mComboBox->setCurrentLayout(
nullptr );
2920 mComboBox->setCurrentLayout( l );
2922 mComboBox->setCurrentLayout(
nullptr );
2925 else if ( mPlainComboBox )
2928 mPlainComboBox->setCurrentText( v );
2932QVariant QgsProcessingLayoutWidgetWrapper::widgetValue()
const
2937 return l ? l->
name() : QVariant();
2939 else if ( mPlainComboBox )
2940 return mPlainComboBox->currentText().isEmpty() ? QVariant() : mPlainComboBox->currentText();
2948 if ( mPlainComboBox && context.
project() )
2952 mPlainComboBox->addItem( layout->name() );
2956QStringList QgsProcessingLayoutWidgetWrapper::compatibleParameterTypes()
const
2958 return QStringList()
2963QStringList QgsProcessingLayoutWidgetWrapper::compatibleOutputTypes()
const
2965 return QStringList()
2969QString QgsProcessingLayoutWidgetWrapper::modelerExpressionFormatString()
const
2971 return tr(
"string representing the name of an existing print layout" );
2974QString QgsProcessingLayoutWidgetWrapper::parameterType()
const
2981 return new QgsProcessingLayoutWidgetWrapper( parameter, type );
2995 QVBoxLayout *vlayout =
new QVBoxLayout();
2996 vlayout->setContentsMargins( 0, 0, 0, 0 );
2998 vlayout->addWidget(
new QLabel( tr(
"Parent layout" ) ) );
3000 mParentLayoutComboBox =
new QComboBox();
3001 QString initialParent;
3003 initialParent = itemParam->parentLayoutParameterName();
3005 if (
auto *lModel = widgetContext.
model() )
3008 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3009 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3013 mParentLayoutComboBox-> addItem( definition->
description(), definition->
name() );
3014 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
3016 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3022 if ( mParentLayoutComboBox->count() == 0 && !initialParent.isEmpty() )
3025 mParentLayoutComboBox->addItem( initialParent, initialParent );
3026 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3029 vlayout->addWidget( mParentLayoutComboBox );
3030 setLayout( vlayout );
3032QgsProcessingParameterDefinition *QgsProcessingLayoutItemParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3034 auto param = std::make_unique< QgsProcessingParameterLayoutItem >( name, description, QVariant(), mParentLayoutComboBox->currentData().toString() );
3036 return param.release();
3046QWidget *QgsProcessingLayoutItemWidgetWrapper::createWidget()
3057 mComboBox->setAllowEmptyItem(
true );
3058 if ( layoutParam->
itemType() >= 0 )
3061 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3064 emit widgetValueHasChanged(
this );
3071 mLineEdit =
new QLineEdit();
3072 mLineEdit->setToolTip( tr(
"UUID or ID of an existing print layout item" ) );
3073 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
3075 emit widgetValueHasChanged(
this );
3083void QgsProcessingLayoutItemWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3093 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterLayoutItem *
>( parameterDefinition() )->parentLayoutParameterName() )
3095 setLayoutParameterValue( wrapper->parameterValue() );
3098 setLayoutParameterValue( wrapper->parameterValue() );
3111void QgsProcessingLayoutItemWidgetWrapper::setLayoutParameterValue(
const QVariant &value )
3117 std::unique_ptr< QgsProcessingContext > tmpContext;
3118 if ( mProcessingContextGenerator )
3119 context = mProcessingContextGenerator->processingContext();
3123 tmpContext = std::make_unique< QgsProcessingContext >();
3124 context = tmpContext.get();
3128 setLayout( layout );
3131void QgsProcessingLayoutItemWidgetWrapper::setLayout(
QgsPrintLayout *layout )
3134 mComboBox->setCurrentLayout( layout );
3137void QgsProcessingLayoutItemWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3141 if ( !value.isValid() )
3142 mComboBox->setItem(
nullptr );
3146 mComboBox->setItem( item );
3149 else if ( mLineEdit )
3152 mLineEdit->setText( v );
3156QVariant QgsProcessingLayoutItemWidgetWrapper::widgetValue()
const
3161 return i ? i->
uuid() : QVariant();
3163 else if ( mLineEdit )
3164 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3169QStringList QgsProcessingLayoutItemWidgetWrapper::compatibleParameterTypes()
const
3171 return QStringList()
3176QStringList QgsProcessingLayoutItemWidgetWrapper::compatibleOutputTypes()
const
3178 return QStringList()
3182QString QgsProcessingLayoutItemWidgetWrapper::modelerExpressionFormatString()
const
3184 return tr(
"string representing the UUID or ID of an existing print layout item" );
3187QString QgsProcessingLayoutItemWidgetWrapper::parameterType()
const
3194 return new QgsProcessingLayoutItemWidgetWrapper( parameter, type );
3199 return new QgsProcessingLayoutItemParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3206QgsProcessingPointMapTool::QgsProcessingPointMapTool(
QgsMapCanvas *canvas )
3213QgsProcessingPointMapTool::~QgsProcessingPointMapTool() =
default;
3215void QgsProcessingPointMapTool::deactivate()
3229 if ( e->button() == Qt::LeftButton )
3232 emit clicked( point );
3237void QgsProcessingPointMapTool::keyPressEvent( QKeyEvent *e )
3239 if ( e->key() == Qt::Key_Escape )
3254QgsProcessingPointPanel::QgsProcessingPointPanel( QWidget *parent )
3257 QHBoxLayout *l =
new QHBoxLayout();
3258 l->setContentsMargins( 0, 0, 0, 0 );
3260 mLineEdit->setShowClearButton(
false );
3261 l->addWidget( mLineEdit, 1 );
3262 mButton =
new QToolButton();
3263 mButton->setText( QString( QChar( 0x2026 ) ) );
3264 l->addWidget( mButton );
3267 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::changed );
3268 connect( mButton, &QToolButton::clicked,
this, &QgsProcessingPointPanel::selectOnCanvas );
3269 mButton->setVisible(
false );
3272void QgsProcessingPointPanel::setMapCanvas(
QgsMapCanvas *canvas )
3275 mButton->setVisible(
true );
3278 mTool = std::make_unique< QgsProcessingPointMapTool >( mCanvas );
3279 connect( mTool.get(), &QgsProcessingPointMapTool::clicked,
this, &QgsProcessingPointPanel::updatePoint );
3280 connect( mTool.get(), &QgsProcessingPointMapTool::complete,
this, &QgsProcessingPointPanel::pointPicked );
3283void QgsProcessingPointPanel::setAllowNull(
bool allowNull )
3285 mLineEdit->setShowClearButton( allowNull );
3288QVariant QgsProcessingPointPanel::value()
const
3290 return mLineEdit->showClearButton() && mLineEdit->text().trimmed().isEmpty() ? QVariant() : QVariant( mLineEdit->text() );
3293void QgsProcessingPointPanel::clear()
3300 QString newText = QStringLiteral(
"%1,%2" )
3301 .arg( QString::number( point.
x(),
'f' ),
3302 QString::number( point.
y(),
'f' ) );
3305 if ( mCrs.isValid() )
3307 newText += QStringLiteral(
" [%1]" ).arg( mCrs.authid() );
3309 mLineEdit->setText( newText );
3312void QgsProcessingPointPanel::selectOnCanvas()
3317 mPrevTool = mCanvas->mapTool();
3318 mCanvas->setMapTool( mTool.get() );
3320 emit toggleDialogVisibility(
false );
3323void QgsProcessingPointPanel::updatePoint(
const QgsPointXY &point )
3325 setValue( point, mCanvas->mapSettings().destinationCrs() );
3328void QgsProcessingPointPanel::pointPicked()
3333 mCanvas->setMapTool( mPrevTool );
3335 emit toggleDialogVisibility(
true );
3347 QVBoxLayout *vlayout =
new QVBoxLayout();
3348 vlayout->setContentsMargins( 0, 0, 0, 0 );
3350 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3352 mDefaultLineEdit =
new QLineEdit();
3353 mDefaultLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
3354 mDefaultLineEdit->setPlaceholderText( tr(
"Point as 'x,y'" ) );
3358 mDefaultLineEdit->setText( QStringLiteral(
"%1,%2" ).arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) ) );
3361 vlayout->addWidget( mDefaultLineEdit );
3362 setLayout( vlayout );
3365QgsProcessingParameterDefinition *QgsProcessingPointParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3367 auto param = std::make_unique< QgsProcessingParameterPoint >( name, description, mDefaultLineEdit->text() );
3369 return param.release();
3378QWidget *QgsProcessingPointWidgetWrapper::createWidget()
3386 mPanel =
new QgsProcessingPointPanel(
nullptr );
3387 if ( widgetContext().mapCanvas() )
3388 mPanel->setMapCanvas( widgetContext().mapCanvas() );
3391 mPanel->setAllowNull(
true );
3393 mPanel->setToolTip( parameterDefinition()->toolTip() );
3395 connect( mPanel, &QgsProcessingPointPanel::changed,
this, [ = ]
3397 emit widgetValueHasChanged(
this );
3401 setDialog( mDialog );
3407 mLineEdit =
new QLineEdit();
3408 mLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
3409 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
3411 emit widgetValueHasChanged(
this );
3423 mPanel->setMapCanvas( context.
mapCanvas() );
3426void QgsProcessingPointWidgetWrapper::setDialog( QDialog *dialog )
3431 connect( mPanel, &QgsProcessingPointPanel::toggleDialogVisibility, mDialog, [ = ](
bool visible )
3434 mDialog->showMinimized();
3437 mDialog->showNormal();
3439 mDialog->activateWindow();
3446void QgsProcessingPointWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3450 if ( !value.isValid() || ( value.type() == QVariant::String && value.toString().isEmpty() ) )
3456 mPanel->setValue( p,
crs );
3459 else if ( mLineEdit )
3462 mLineEdit->setText( v );
3466QVariant QgsProcessingPointWidgetWrapper::widgetValue()
const
3470 return mPanel->value();
3472 else if ( mLineEdit )
3473 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3478QStringList QgsProcessingPointWidgetWrapper::compatibleParameterTypes()
const
3480 return QStringList()
3485QStringList QgsProcessingPointWidgetWrapper::compatibleOutputTypes()
const
3487 return QStringList()
3491QString QgsProcessingPointWidgetWrapper::modelerExpressionFormatString()
const
3493 return tr(
"string of the format 'x,y' or a geometry value (centroid is used)" );
3496QString QgsProcessingPointWidgetWrapper::parameterType()
const
3503 return new QgsProcessingPointWidgetWrapper( parameter, type );
3508 return new QgsProcessingPointParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3520 QVBoxLayout *vlayout =
new QVBoxLayout();
3521 vlayout->setContentsMargins( 0, 0, 0, 0 );
3523 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3525 mDefaultLineEdit =
new QLineEdit();
3526 mDefaultLineEdit->setToolTip( tr(
"Geometry as WKT" ) );
3527 mDefaultLineEdit->setPlaceholderText( tr(
"Geometry as WKT" ) );
3532 mDefaultLineEdit->setText( g.
asWkt() );
3535 vlayout->addWidget( mDefaultLineEdit );
3536 setLayout( vlayout );
3539QgsProcessingParameterDefinition *QgsProcessingGeometryParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3541 auto param = std::make_unique< QgsProcessingParameterGeometry >( name, description, mDefaultLineEdit->text() );
3543 return param.release();
3552QWidget *QgsProcessingGeometryWidgetWrapper::createWidget()
3560 mLineEdit =
new QLineEdit();
3561 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
3562 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
3564 emit widgetValueHasChanged(
this );
3572void QgsProcessingGeometryWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3578 mLineEdit->setText( g.
asWkt() );
3584QVariant QgsProcessingGeometryWidgetWrapper::widgetValue()
const
3587 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3592QStringList QgsProcessingGeometryWidgetWrapper::compatibleParameterTypes()
const
3594 return QStringList()
3601QStringList QgsProcessingGeometryWidgetWrapper::compatibleOutputTypes()
const
3603 return QStringList()
3607QString QgsProcessingGeometryWidgetWrapper::modelerExpressionFormatString()
const
3609 return tr(
"string in the Well-Known-Text format or a geometry value" );
3612QString QgsProcessingGeometryWidgetWrapper::parameterType()
const
3619 return new QgsProcessingGeometryWidgetWrapper( parameter, type );
3624 return new QgsProcessingGeometryParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3636 QVBoxLayout *vlayout =
new QVBoxLayout();
3637 vlayout->setContentsMargins( 0, 0, 0, 0 );
3639 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3642 mDefaultColorButton->setShowNull(
true );
3643 mAllowOpacity =
new QCheckBox( tr(
"Allow opacity control" ) );
3649 mDefaultColorButton->setToNull();
3651 mDefaultColorButton->setColor(
c );
3652 mAllowOpacity->setChecked( colorParam->opacityEnabled() );
3656 mDefaultColorButton->setToNull();
3657 mAllowOpacity->setChecked(
true );
3660 vlayout->addWidget( mDefaultColorButton );
3661 vlayout->addWidget( mAllowOpacity );
3662 setLayout( vlayout );
3665QgsProcessingParameterDefinition *QgsProcessingColorParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3667 auto param = std::make_unique< QgsProcessingParameterColor >( name, description, mDefaultColorButton->color(), mAllowOpacity->isChecked() );
3669 return param.release();
3678QWidget *QgsProcessingColorWidgetWrapper::createWidget()
3688 mColorButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
3691 mColorButton->setShowNull(
true );
3694 mColorButton->setToolTip( parameterDefinition()->toolTip() );
3695 mColorButton->setColorDialogTitle( parameterDefinition()->description() );
3703 emit widgetValueHasChanged(
this );
3706 return mColorButton;
3712void QgsProcessingColorWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3716 if ( !value.isValid() ||
3717 ( value.type() == QVariant::String && value.toString().isEmpty() )
3718 || ( value.type() == QVariant::Color && !value.value< QColor >().isValid() ) )
3719 mColorButton->setToNull();
3723 if ( !
c.isValid() && mColorButton->showNull() )
3724 mColorButton->setToNull();
3726 mColorButton->setColor(
c );
3731QVariant QgsProcessingColorWidgetWrapper::widgetValue()
const
3734 return mColorButton->isNull() ? QVariant() : mColorButton->color();
3739QStringList QgsProcessingColorWidgetWrapper::compatibleParameterTypes()
const
3741 return QStringList()
3746QStringList QgsProcessingColorWidgetWrapper::compatibleOutputTypes()
const
3748 return QStringList()
3752QString QgsProcessingColorWidgetWrapper::modelerExpressionFormatString()
const
3754 return tr(
"color style string, e.g. #ff0000 or 255,0,0" );
3757QString QgsProcessingColorWidgetWrapper::parameterType()
const
3764 return new QgsProcessingColorWidgetWrapper( parameter, type );
3769 return new QgsProcessingColorParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3780 QVBoxLayout *vlayout =
new QVBoxLayout();
3781 vlayout->setContentsMargins( 0, 0, 0, 0 );
3783 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3785 mDefaultLineEdit =
new QLineEdit();
3788 vlayout->addWidget( mDefaultLineEdit );
3790 mSourceParamComboBox =
new QComboBox();
3791 mDestParamComboBox =
new QComboBox();
3792 QString initialSource;
3793 QString initialDest;
3798 initialSource = itemParam->sourceCrsParameterName();
3799 initialDest = itemParam->destinationCrsParameterName();
3804 mSourceParamComboBox->addItem( QString(), QString() );
3805 mDestParamComboBox->addItem( QString(), QString() );
3806 if (
auto *lModel = widgetContext.
model() )
3809 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3810 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3812 if ( definition && it->parameterName() == definition->
name() )
3816 mSourceParamComboBox->addItem( it->parameterName(), it->parameterName() );
3817 mDestParamComboBox->addItem( it->parameterName(), it->parameterName() );
3818 if ( !initialSource.isEmpty() && initialSource == it->parameterName() )
3820 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
3822 if ( !initialDest.isEmpty() && initialDest == it->parameterName() )
3824 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
3829 if ( mSourceParamComboBox->count() == 1 && !initialSource.isEmpty() )
3832 mSourceParamComboBox->addItem( initialSource, initialSource );
3833 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
3835 if ( mDestParamComboBox->count() == 1 && !initialDest.isEmpty() )
3838 mDestParamComboBox->addItem( initialDest, initialDest );
3839 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
3842 vlayout->addWidget(
new QLabel( tr(
"Source CRS parameter" ) ) );
3843 vlayout->addWidget( mSourceParamComboBox );
3844 vlayout->addWidget(
new QLabel( tr(
"Destination CRS parameter" ) ) );
3845 vlayout->addWidget( mDestParamComboBox );
3849 mStaticSourceWidget->setCrs( sourceCrs );
3852 mStaticDestWidget->setCrs( destCrs );
3854 vlayout->addWidget(
new QLabel( tr(
"Static source CRS" ) ) );
3855 vlayout->addWidget( mStaticSourceWidget );
3856 vlayout->addWidget(
new QLabel( tr(
"Static destination CRS" ) ) );
3857 vlayout->addWidget( mStaticDestWidget );
3859 setLayout( vlayout );
3862QgsProcessingParameterDefinition *QgsProcessingCoordinateOperationParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3864 auto param = std::make_unique< QgsProcessingParameterCoordinateOperation >( name, description, mDefaultLineEdit->text(),
3865 mSourceParamComboBox->currentText(),
3866 mDestParamComboBox->currentText(),
3867 mStaticSourceWidget->crs().isValid() ? QVariant::fromValue( mStaticSourceWidget->crs() ) : QVariant(),
3868 mStaticDestWidget->crs().isValid() ? QVariant::fromValue( mStaticDestWidget->crs() ) : QVariant() );
3870 return param.release();
3879QWidget *QgsProcessingCoordinateOperationWidgetWrapper::createWidget()
3890 mOperationWidget->setShowMakeDefault(
false );
3891 mOperationWidget->setShowFallbackOption(
false );
3892 mOperationWidget->setToolTip( parameterDefinition()->toolTip() );
3893 mOperationWidget->setSourceCrs( mSourceCrs );
3894 mOperationWidget->setDestinationCrs( mDestCrs );
3895 mOperationWidget->setMapCanvas( mCanvas );
3900 mOperationWidget->setSelectedOperation( deets );
3905 emit widgetValueHasChanged(
this );
3908 return mOperationWidget;
3914 mLineEdit =
new QLineEdit();
3915 QHBoxLayout *layout =
new QHBoxLayout();
3916 layout->addWidget( mLineEdit, 1 );
3917 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
3919 emit widgetValueHasChanged(
this );
3922 QToolButton *button =
new QToolButton();
3923 button->setText( QString( QChar( 0x2026 ) ) );
3924 connect( button, &QToolButton::clicked,
this, [ = ]
3926 QgsDatumTransformDialog dlg( mSourceCrs, mDestCrs,
false,
false,
false, qMakePair( -1, -1 ), button, Qt::WindowFlags(), mLineEdit->text(), mCanvas );
3929 mLineEdit->setText( dlg.selectedDatumTransform().proj );
3930 emit widgetValueHasChanged(
this );
3933 layout->addWidget( button );
3935 QWidget *w =
new QWidget();
3936 layout->setContentsMargins( 0, 0, 0, 0 );
3937 w->setLayout( layout );
3945void QgsProcessingCoordinateOperationWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3957 setSourceCrsParameterValue( wrapper->parameterValue() );
3960 setSourceCrsParameterValue( wrapper->parameterValue() );
3965 setDestinationCrsParameterValue( wrapper->parameterValue() );
3968 setDestinationCrsParameterValue( wrapper->parameterValue() );
3983 if ( mOperationWidget )
3984 mOperationWidget->setMapCanvas( context.
mapCanvas() );
3987void QgsProcessingCoordinateOperationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
3989 if ( mOperationWidget )
3991 if ( !value.isValid() ||
3992 ( value.type() == QVariant::String ) )
3995 deets.
proj = value.toString();
3996 mOperationWidget->setSelectedOperation( deets );
4001 if ( !value.isValid() ||
4002 ( value.type() == QVariant::String ) )
4004 mLineEdit->setText( value.toString() );
4009QVariant QgsProcessingCoordinateOperationWidgetWrapper::widgetValue()
const
4011 if ( mOperationWidget )
4012 return mOperationWidget->selectedOperation().proj;
4013 else if ( mLineEdit )
4014 return mLineEdit->text();
4019QStringList QgsProcessingCoordinateOperationWidgetWrapper::compatibleParameterTypes()
const
4021 return QStringList()
4026QStringList QgsProcessingCoordinateOperationWidgetWrapper::compatibleOutputTypes()
const
4028 return QStringList()
4032QString QgsProcessingCoordinateOperationWidgetWrapper::modelerExpressionFormatString()
const
4034 return tr(
"Proj coordinate operation string, e.g. '+proj=pipeline +step +inv...'" );
4037void QgsProcessingCoordinateOperationWidgetWrapper::setSourceCrsParameterValue(
const QVariant &value )
4040 std::unique_ptr< QgsProcessingContext > tmpContext;
4041 if ( mProcessingContextGenerator )
4042 context = mProcessingContextGenerator->processingContext();
4046 tmpContext = std::make_unique< QgsProcessingContext >();
4047 context = tmpContext.get();
4051 if ( mOperationWidget )
4053 mOperationWidget->setSourceCrs( mSourceCrs );
4054 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4058void QgsProcessingCoordinateOperationWidgetWrapper::setDestinationCrsParameterValue(
const QVariant &value )
4061 std::unique_ptr< QgsProcessingContext > tmpContext;
4062 if ( mProcessingContextGenerator )
4063 context = mProcessingContextGenerator->processingContext();
4067 tmpContext = std::make_unique< QgsProcessingContext >();
4068 context = tmpContext.get();
4072 if ( mOperationWidget )
4074 mOperationWidget->setDestinationCrs( mDestCrs );
4075 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4079QString QgsProcessingCoordinateOperationWidgetWrapper::parameterType()
const
4086 return new QgsProcessingCoordinateOperationWidgetWrapper( parameter, type );
4091 return new QgsProcessingCoordinateOperationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4104 QHBoxLayout *hl =
new QHBoxLayout();
4105 hl->setContentsMargins( 0, 0, 0, 0 );
4107 mLineEdit =
new QLineEdit();
4108 mLineEdit->setEnabled(
false );
4109 hl->addWidget( mLineEdit, 1 );
4111 mToolButton =
new QToolButton();
4112 mToolButton->setText( QString( QChar( 0x2026 ) ) );
4113 hl->addWidget( mToolButton );
4119 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4122 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingFieldPanelWidget::showDialog );
4125void QgsProcessingFieldPanelWidget::setFields(
const QgsFields &fields )
4130void QgsProcessingFieldPanelWidget::setValue(
const QVariant &value )
4132 if ( value.isValid() )
4133 mValue = value.type() == QVariant::List ? value.
toList() : QVariantList() << value;
4137 updateSummaryText();
4141void QgsProcessingFieldPanelWidget::showDialog()
4143 QVariantList availableOptions;
4144 QStringList fieldNames;
4145 availableOptions.reserve( mFields.size() );
4154 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
4155 widget->setPanelTitle( mParam->description() );
4157 widget->setValueFormatter( [](
const QVariant & v ) -> QString
4159 return v.toString();
4162 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
4164 setValue( widget->selectedOptions() );
4171 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
4173 dlg.setValueFormatter( [](
const QVariant & v ) -> QString
4175 return v.toString();
4179 setValue( dlg.selectedOptions() );
4184void QgsProcessingFieldPanelWidget::updateSummaryText()
4189 if ( mValue.empty() )
4191 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4196 values.reserve( mValue.size() );
4197 for (
const QVariant &val : std::as_const( mValue ) )
4199 values << val.toString();
4202 const QString concatenated = values.join( tr(
"," ) );
4203 if ( concatenated.length() < 100 )
4204 mLineEdit->setText( concatenated );
4206 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, mValue.count() ) );
4218 QVBoxLayout *vlayout =
new QVBoxLayout();
4219 vlayout->setContentsMargins( 0, 0, 0, 0 );
4221 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
4222 mParentLayerComboBox =
new QComboBox();
4224 QString initialParent;
4226 initialParent = fieldParam->parentLayerParameterName();
4228 if (
auto *lModel = widgetContext.
model() )
4231 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4232 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4236 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
4237 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4239 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4244 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
4245 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4247 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4254 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
4255 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4257 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4264 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
4267 mParentLayerComboBox->addItem( initialParent, initialParent );
4268 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4271 vlayout->addWidget( mParentLayerComboBox );
4273 vlayout->addWidget(
new QLabel( tr(
"Allowed data type" ) ) );
4274 mDataTypeComboBox =
new QComboBox();
4280 mDataTypeComboBox->setCurrentIndex( mDataTypeComboBox->findData( fieldParam->dataType() ) );
4282 vlayout->addWidget( mDataTypeComboBox );
4284 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple fields" ) );
4286 mAllowMultipleCheckBox->setChecked( fieldParam->allowMultiple() );
4288 vlayout->addWidget( mAllowMultipleCheckBox );
4290 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all fields by default" ) );
4291 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
4293 mDefaultToAllCheckBox->setChecked( fieldParam->defaultToAllFields() );
4295 vlayout->addWidget( mDefaultToAllCheckBox );
4297 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [ = ]
4299 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
4302 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4304 mDefaultLineEdit =
new QLineEdit();
4305 mDefaultLineEdit->setToolTip( tr(
"Default field name, or ; separated list of field names for multiple field parameters" ) );
4309 mDefaultLineEdit->setText( fields.join(
';' ) );
4311 vlayout->addWidget( mDefaultLineEdit );
4313 setLayout( vlayout );
4316QgsProcessingParameterDefinition *QgsProcessingFieldParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4320 QVariant defaultValue;
4321 if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
4323 defaultValue = mDefaultLineEdit->text();
4325 auto param = std::make_unique< QgsProcessingParameterField >( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), dataType, mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
4327 return param.release();
4336QWidget *QgsProcessingFieldWidgetWrapper::createWidget()
4346 mPanel =
new QgsProcessingFieldPanelWidget(
nullptr, fieldParam );
4347 mPanel->setToolTip( parameterDefinition()->toolTip() );
4348 connect( mPanel, &QgsProcessingFieldPanelWidget::changed,
this, [ = ]
4350 emit widgetValueHasChanged(
this );
4366 mComboBox->setToolTip( parameterDefinition()->toolTip() );
4369 emit widgetValueHasChanged(
this );
4377 mLineEdit =
new QLineEdit();
4378 mLineEdit->setToolTip( QObject::tr(
"Name of field (separate field names with ; for multiple field parameters)" ) );
4379 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
4381 emit widgetValueHasChanged(
this );
4390void QgsProcessingFieldWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
4400 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterField *
>( parameterDefinition() )->parentLayerParameterName() )
4402 setParentLayerWrapperValue( wrapper );
4405 setParentLayerWrapperValue( wrapper );
4422 std::unique_ptr< QgsProcessingContext > tmpContext;
4423 if ( mProcessingContextGenerator )
4424 context = mProcessingContextGenerator->processingContext();
4428 tmpContext = std::make_unique< QgsProcessingContext >();
4429 context = tmpContext.get();
4434 if ( value.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
4444 bool valueSet =
false;
4448 if ( layers.count() > 1 )
4450 QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( layers.at( 0 ) );
4452 const QList< QgsMapLayer * > remainingLayers = layers.mid( 1 );
4458 QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( layer );
4459 if ( !vlayer || !vlayer->
isValid() )
4465 for (
int fieldIdx = fields.
count() - 1; fieldIdx >= 0; fieldIdx-- )
4468 fields.
remove( fieldIdx );
4473 mComboBox->setFields( fields );
4475 mPanel->setFields( filterFields( fields ) );
4481 if ( !valueSet && !layers.isEmpty() && layers.at( 0 )->isValid() )
4483 QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( layers.at( 0 ) );
4487 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
4490 mParentLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
4491 layer = mParentLayer.get();
4499 mComboBox->setLayer( layer );
4501 mPanel->setFields( filterFields( layer->
fields() ) );
4511 const QgsFields fields = source->fields();
4513 mComboBox->setFields( fields );
4515 mPanel->setFields( filterFields( fields ) );
4524 mComboBox->setLayer(
nullptr );
4528 if ( value.isValid() && widgetContext().messageBar() )
4531 widgetContext().
messageBar()->
pushMessage( QString(), QObject::tr(
"Could not load selected layer/table. Dependent field could not be populated" ),
4532 Qgis::MessageLevel::Info );
4541 val.reserve( mPanel->fields().size() );
4544 setWidgetValue( val, *context );
4547 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
4550void QgsProcessingFieldWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4554 if ( !value.isValid() )
4555 mComboBox->setField( QString() );
4559 mComboBox->setField( v );
4565 if ( value.isValid() )
4568 opts.reserve( v.size() );
4569 for (
const QString &i : v )
4573 mPanel->setValue( opts );
4575 else if ( mLineEdit )
4581 mLineEdit->setText( v.join(
';' ) );
4590QVariant QgsProcessingFieldWidgetWrapper::widgetValue()
const
4593 return mComboBox->currentField();
4595 return mPanel->value();
4596 else if ( mLineEdit )
4601 return mLineEdit->text().split(
';' );
4604 return mLineEdit->text();
4610QStringList QgsProcessingFieldWidgetWrapper::compatibleParameterTypes()
const
4612 return QStringList()
4617QStringList QgsProcessingFieldWidgetWrapper::compatibleOutputTypes()
const
4619 return QStringList()
4623QString QgsProcessingFieldWidgetWrapper::modelerExpressionFormatString()
const
4625 return tr(
"selected field names as an array of names, or semicolon separated string of options (e.g. 'fid;place_name')" );
4628const QgsVectorLayer *QgsProcessingFieldWidgetWrapper::linkedVectorLayer()
const
4630 if ( mComboBox && mComboBox->layer() )
4631 return mComboBox->layer();
4636QgsFields QgsProcessingFieldWidgetWrapper::filterFields(
const QgsFields &fields )
const
4649 if ( f.isNumeric() )
4654 if ( f.type() == QVariant::String )
4659 if ( f.type() == QVariant::Date || f.type() == QVariant::Time || f.type() == QVariant::DateTime )
4668QString QgsProcessingFieldWidgetWrapper::parameterType()
const
4675 return new QgsProcessingFieldWidgetWrapper( parameter, type );
4680 return new QgsProcessingFieldParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4691 QVBoxLayout *vlayout =
new QVBoxLayout();
4692 vlayout->setContentsMargins( 0, 0, 0, 0 );
4694 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4696 mDefaultComboBox =
new QComboBox();
4697 mDefaultComboBox->addItem( QString(), QVariant( -1 ) );
4700 for (
const QString &theme : mapThemes )
4704 mDefaultComboBox->setEditable(
true );
4708 if ( themeParam->defaultValueForGui().isValid() )
4711 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
4714 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
4716 vlayout->addWidget( mDefaultComboBox );
4718 setLayout( vlayout );
4721QgsProcessingParameterDefinition *QgsProcessingMapThemeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4723 QVariant defaultVal;
4724 if ( mDefaultComboBox->currentText().isEmpty() )
4725 defaultVal = QVariant();
4727 defaultVal = mDefaultComboBox->currentText();
4728 auto param = std::make_unique< QgsProcessingParameterMapTheme>( name, description, defaultVal );
4730 return param.release();
4740QWidget *QgsProcessingMapThemeWidgetWrapper::createWidget()
4744 mComboBox =
new QComboBox();
4747 mComboBox->addItem( tr(
"[Not selected]" ), QVariant( -1 ) );
4750 for (
const QString &theme : mapThemes )
4762 mComboBox->setEditable(
true );
4766 mComboBox->setToolTip( parameterDefinition()->toolTip() );
4767 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
4769 emit widgetValueHasChanged(
this );
4775void QgsProcessingMapThemeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4779 if ( !value.isValid() )
4780 mComboBox->setCurrentIndex( mComboBox->findData( QVariant( -1 ) ) );
4783 if ( mComboBox->isEditable() && mComboBox->findData( v ) == -1 )
4785 const QString prev = mComboBox->currentText();
4786 mComboBox->setCurrentText( v );
4788 emit widgetValueHasChanged(
this );
4791 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
4795QVariant QgsProcessingMapThemeWidgetWrapper::widgetValue()
const
4798 return mComboBox->currentData().toInt() == -1 ? QVariant() :
4799 !mComboBox->currentData().isValid() && mComboBox->isEditable() ? mComboBox->currentText().isEmpty() ? QVariant() : QVariant( mComboBox->currentText() )
4800 : mComboBox->currentData();
4805QStringList QgsProcessingMapThemeWidgetWrapper::compatibleParameterTypes()
const
4807 return QStringList()
4812QStringList QgsProcessingMapThemeWidgetWrapper::compatibleOutputTypes()
const
4814 return QStringList()
4818QString QgsProcessingMapThemeWidgetWrapper::modelerExpressionFormatString()
const
4820 return tr(
"map theme as a string value (e.g. 'base maps')" );
4823QString QgsProcessingMapThemeWidgetWrapper::parameterType()
const
4830 return new QgsProcessingMapThemeWidgetWrapper( parameter, type );
4835 return new QgsProcessingMapThemeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4848 QVBoxLayout *vlayout =
new QVBoxLayout();
4849 vlayout->setContentsMargins( 0, 0, 0, 0 );
4851 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
4853 mTypeComboBox =
new QComboBox();
4858 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( datetimeParam->dataType() ) );
4860 mTypeComboBox->setCurrentIndex( 0 );
4861 vlayout->addWidget( mTypeComboBox );
4863 setLayout( vlayout );
4866QgsProcessingParameterDefinition *QgsProcessingDateTimeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4868 auto param = std::make_unique< QgsProcessingParameterDateTime >( name, description );
4871 return param.release();
4881QWidget *QgsProcessingDateTimeWidgetWrapper::createWidget()
4886 switch ( dateTimeParam->
dataType() )
4890 widget = mDateTimeEdit;
4913 widget->setToolTip( parameterDefinition()->toolTip() );
4915 if ( mDateTimeEdit )
4919 emit widgetValueHasChanged(
this );
4922 else if ( mDateEdit )
4926 emit widgetValueHasChanged(
this );
4929 else if ( mTimeEdit )
4933 emit widgetValueHasChanged(
this );
4942 return new QgsProcessingDateTimeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4945void QgsProcessingDateTimeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4947 if ( mDateTimeEdit )
4951 else if ( mDateEdit )
4955 else if ( mTimeEdit )
4961QVariant QgsProcessingDateTimeWidgetWrapper::widgetValue()
const
4963 if ( mDateTimeEdit )
4964 return !mDateTimeEdit->dateTime().isNull() && mDateTimeEdit->dateTime().isValid() ? QVariant( mDateTimeEdit->dateTime() ) : QVariant();
4965 else if ( mDateEdit )
4966 return !mDateEdit->date().isNull() && mDateEdit->date().isValid() ? QVariant( mDateEdit->date() ) : QVariant();
4967 else if ( mTimeEdit )
4968 return !mTimeEdit->time().isNull() && mTimeEdit->time().isValid() ? QVariant( mTimeEdit->time() ) : QVariant();
4973QStringList QgsProcessingDateTimeWidgetWrapper::compatibleParameterTypes()
const
4975 return QStringList()
4980QStringList QgsProcessingDateTimeWidgetWrapper::compatibleOutputTypes()
const
4982 return QStringList()
4986QString QgsProcessingDateTimeWidgetWrapper::modelerExpressionFormatString()
const
4989 if ( dateTimeParam )
4991 switch ( dateTimeParam->
dataType() )
4994 return tr(
"datetime value, or a ISO string representation of a datetime" );
4997 return tr(
"date value, or a ISO string representation of a date" );
5000 return tr(
"time value, or a ISO string representation of a time" );
5006QString QgsProcessingDateTimeWidgetWrapper::parameterType()
const
5013 return new QgsProcessingDateTimeWidgetWrapper( parameter, type );
5027 QVBoxLayout *vlayout =
new QVBoxLayout();
5028 vlayout->setContentsMargins( 0, 0, 0, 0 );
5030 vlayout->addWidget(
new QLabel( tr(
"Provider" ) ) );
5031 mProviderComboBox =
new QComboBox();
5032 mProviderComboBox->addItem( QObject::tr(
"Postgres" ), QStringLiteral(
"postgres" ) );
5033 mProviderComboBox->addItem( QObject::tr(
"GeoPackage" ), QStringLiteral(
"ogr" ) );
5034 mProviderComboBox->addItem( QObject::tr(
"Spatialite" ), QStringLiteral(
"spatialite" ) );
5036 vlayout->addWidget( mProviderComboBox );
5038 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5040 mDefaultEdit =
new QLineEdit();
5041 vlayout->addWidget( mDefaultEdit );
5042 setLayout( vlayout );
5044 if ( connectionParam )
5046 mProviderComboBox->setCurrentIndex( mProviderComboBox->findData( connectionParam->
providerId() ) );
5051QgsProcessingParameterDefinition *QgsProcessingProviderConnectionParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5053 QVariant defaultVal;
5054 if ( mDefaultEdit->text().isEmpty() )
5055 defaultVal = QVariant();
5057 defaultVal = mDefaultEdit->text();
5058 auto param = std::make_unique< QgsProcessingParameterProviderConnection>( name, description, mProviderComboBox->currentData().toString(), defaultVal );
5060 return param.release();
5070QWidget *QgsProcessingProviderConnectionWidgetWrapper::createWidget()
5076 mProviderComboBox->setAllowEmptyConnection(
true );
5084 mProviderComboBox->setEditable(
true );
5088 mProviderComboBox->setToolTip( parameterDefinition()->toolTip() );
5089 connect( mProviderComboBox, &QgsProviderConnectionComboBox::currentTextChanged,
this, [ = ](
const QString & )
5091 if ( mBlockSignals )
5094 emit widgetValueHasChanged(
this );
5097 return mProviderComboBox;
5102 return new QgsProcessingProviderConnectionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5105void QgsProcessingProviderConnectionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5109 if ( !value.isValid() )
5110 mProviderComboBox->setCurrentIndex( -1 );
5113 if ( mProviderComboBox->isEditable() )
5115 const QString prev = mProviderComboBox->currentText();
5117 mProviderComboBox->setConnection( v );
5118 mProviderComboBox->setCurrentText( v );
5122 emit widgetValueHasChanged(
this );
5125 mProviderComboBox->setConnection( v );
5129QVariant QgsProcessingProviderConnectionWidgetWrapper::widgetValue()
const
5131 if ( mProviderComboBox )
5132 if ( mProviderComboBox->isEditable() )
5133 return mProviderComboBox->currentText().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentText() );
5135 return mProviderComboBox->currentConnection().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentConnection() );
5140QStringList QgsProcessingProviderConnectionWidgetWrapper::compatibleParameterTypes()
const
5142 return QStringList()
5148QStringList QgsProcessingProviderConnectionWidgetWrapper::compatibleOutputTypes()
const
5150 return QStringList()
5154QString QgsProcessingProviderConnectionWidgetWrapper::modelerExpressionFormatString()
const
5156 return tr(
"connection name as a string value" );
5159QString QgsProcessingProviderConnectionWidgetWrapper::parameterType()
const
5166 return new QgsProcessingProviderConnectionWidgetWrapper( parameter, type );
5181 QVBoxLayout *vlayout =
new QVBoxLayout();
5182 vlayout->setContentsMargins( 0, 0, 0, 0 );
5184 mConnectionParamComboBox =
new QComboBox();
5185 QString initialConnection;
5191 if (
auto *lModel = widgetContext.
model() )
5194 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
5195 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
5197 if ( definition && it->parameterName() == definition->
name() )
5203 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
5204 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5206 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5211 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
5214 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
5215 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5218 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
5219 vlayout->addWidget( mConnectionParamComboBox );
5221 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5223 mDefaultEdit =
new QLineEdit();
5224 vlayout->addWidget( mDefaultEdit );
5225 setLayout( vlayout );
5233QgsProcessingParameterDefinition *QgsProcessingDatabaseSchemaParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5235 QVariant defaultVal;
5236 if ( mDefaultEdit->text().isEmpty() )
5237 defaultVal = QVariant();
5239 defaultVal = mDefaultEdit->text();
5240 auto param = std::make_unique< QgsProcessingParameterDatabaseSchema>( name, description, mConnectionParamComboBox->currentData().toString(), defaultVal );
5242 return param.release();
5252QWidget *QgsProcessingDatabaseSchemaWidgetWrapper::createWidget()
5258 mSchemaComboBox->setAllowEmptySchema(
true );
5266 mSchemaComboBox->comboBox()->setEditable(
true );
5270 mSchemaComboBox->setToolTip( parameterDefinition()->toolTip() );
5271 connect( mSchemaComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
5273 if ( mBlockSignals )
5276 emit widgetValueHasChanged( this );
5279 return mSchemaComboBox;
5284 return new QgsProcessingDatabaseSchemaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5291 std::unique_ptr< QgsProcessingContext > tmpContext;
5292 if ( mProcessingContextGenerator )
5293 context = mProcessingContextGenerator->processingContext();
5297 tmpContext = std::make_unique< QgsProcessingContext >();
5298 context = tmpContext.get();
5304 if ( mSchemaComboBox )
5305 mSchemaComboBox->setConnectionName( connection, qgis::down_cast< const QgsProcessingParameterProviderConnection * >( parentWrapper->
parameterDefinition() )->providerId() );
5309 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5312void QgsProcessingDatabaseSchemaWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5316 if ( !value.isValid() )
5317 mSchemaComboBox->comboBox()->setCurrentIndex( -1 );
5320 if ( mSchemaComboBox->comboBox()->isEditable() )
5322 const QString prev = mSchemaComboBox->comboBox()->currentText();
5324 mSchemaComboBox->setSchema( v );
5325 mSchemaComboBox->comboBox()->setCurrentText( v );
5329 emit widgetValueHasChanged(
this );
5332 mSchemaComboBox->setSchema( v );
5336QVariant QgsProcessingDatabaseSchemaWidgetWrapper::widgetValue()
const
5338 if ( mSchemaComboBox )
5339 if ( mSchemaComboBox->comboBox()->isEditable() )
5340 return mSchemaComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->comboBox()->currentText() );
5342 return mSchemaComboBox->currentSchema().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->currentSchema() );
5347QStringList QgsProcessingDatabaseSchemaWidgetWrapper::compatibleParameterTypes()
const
5349 return QStringList()
5355QStringList QgsProcessingDatabaseSchemaWidgetWrapper::compatibleOutputTypes()
const
5357 return QStringList()
5361QString QgsProcessingDatabaseSchemaWidgetWrapper::modelerExpressionFormatString()
const
5363 return tr(
"database schema name as a string value" );
5366QString QgsProcessingDatabaseSchemaWidgetWrapper::parameterType()
const
5373 return new QgsProcessingDatabaseSchemaWidgetWrapper( parameter, type );
5376void QgsProcessingDatabaseSchemaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5388 setParentConnectionWrapperValue( wrapper );
5391 setParentConnectionWrapperValue( wrapper );
5415 QVBoxLayout *vlayout =
new QVBoxLayout();
5416 vlayout->setContentsMargins( 0, 0, 0, 0 );
5418 mConnectionParamComboBox =
new QComboBox();
5419 mSchemaParamComboBox =
new QComboBox();
5420 QString initialConnection;
5421 QString initialSchema;
5428 if (
auto *lModel = widgetContext.
model() )
5431 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
5432 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
5434 if ( definition && it->parameterName() == definition->
name() )
5439 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
5440 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5442 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5447 mSchemaParamComboBox->addItem( it->parameterName(), it->parameterName() );
5448 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5450 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
5456 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
5459 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
5460 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5463 if ( mSchemaParamComboBox->count() == 0 && !initialSchema.isEmpty() )
5466 mSchemaParamComboBox->addItem( initialSchema, initialSchema );
5467 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
5470 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
5471 vlayout->addWidget( mConnectionParamComboBox );
5473 vlayout->addWidget(
new QLabel( tr(
"Database schema parameter" ) ) );
5474 vlayout->addWidget( mSchemaParamComboBox );
5476 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5478 mDefaultEdit =
new QLineEdit();
5479 vlayout->addWidget( mDefaultEdit );
5480 setLayout( vlayout );
5488QgsProcessingParameterDefinition *QgsProcessingDatabaseTableParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5490 QVariant defaultVal;
5491 if ( mDefaultEdit->text().isEmpty() )
5492 defaultVal = QVariant();
5494 defaultVal = mDefaultEdit->text();
5495 auto param = std::make_unique< QgsProcessingParameterDatabaseTable>( name, description,
5496 mConnectionParamComboBox->currentData().toString(),
5497 mSchemaParamComboBox->currentData().toString(),
5500 return param.release();
5510QWidget *QgsProcessingDatabaseTableWidgetWrapper::createWidget()
5516 mTableComboBox->setAllowEmptyTable(
true );
5519 mTableComboBox->comboBox()->setEditable(
true );
5521 mTableComboBox->setToolTip( parameterDefinition()->toolTip() );
5522 connect( mTableComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
5524 if ( mBlockSignals )
5527 emit widgetValueHasChanged( this );
5530 return mTableComboBox;
5535 return new QgsProcessingDatabaseTableParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5542 std::unique_ptr< QgsProcessingContext > tmpContext;
5543 if ( mProcessingContextGenerator )
5544 context = mProcessingContextGenerator->processingContext();
5548 tmpContext = std::make_unique< QgsProcessingContext >();
5549 context = tmpContext.get();
5554 mProvider = qgis::down_cast< const QgsProcessingParameterProviderConnection * >( parentWrapper->
parameterDefinition() )->providerId();
5555 if ( mTableComboBox && !mSchema.isEmpty() )
5557 mTableComboBox->setSchema( mSchema );
5558 mTableComboBox->setConnectionName( mConnection, mProvider );
5562 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5570 std::unique_ptr< QgsProcessingContext > tmpContext;
5571 if ( mProcessingContextGenerator )
5572 context = mProcessingContextGenerator->processingContext();
5576 tmpContext = std::make_unique< QgsProcessingContext >();
5577 context = tmpContext.get();
5583 if ( mTableComboBox && !mSchema.isEmpty() && !mConnection.isEmpty() )
5585 mTableComboBox->setSchema( mSchema );
5586 mTableComboBox->setConnectionName( mConnection, mProvider );
5590 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5595void QgsProcessingDatabaseTableWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5599 if ( !value.isValid() )
5600 mTableComboBox->comboBox()->setCurrentIndex( -1 );
5603 if ( mTableComboBox->comboBox()->isEditable() )
5605 const QString prev = mTableComboBox->comboBox()->currentText();
5607 mTableComboBox->setTable( v );
5608 mTableComboBox->comboBox()->setCurrentText( v );
5612 emit widgetValueHasChanged(
this );
5615 mTableComboBox->setTable( v );
5619QVariant QgsProcessingDatabaseTableWidgetWrapper::widgetValue()
const
5621 if ( mTableComboBox )
5622 if ( mTableComboBox->comboBox()->isEditable() )
5623 return mTableComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mTableComboBox->comboBox()->currentText() );
5625 return mTableComboBox->currentTable().isEmpty() ? QVariant() : QVariant( mTableComboBox->currentTable() );
5630QStringList QgsProcessingDatabaseTableWidgetWrapper::compatibleParameterTypes()
const
5632 return QStringList()
5638QStringList QgsProcessingDatabaseTableWidgetWrapper::compatibleOutputTypes()
const
5640 return QStringList()
5644QString QgsProcessingDatabaseTableWidgetWrapper::modelerExpressionFormatString()
const
5646 return tr(
"database table name as a string value" );
5649QString QgsProcessingDatabaseTableWidgetWrapper::parameterType()
const
5656 return new QgsProcessingDatabaseTableWidgetWrapper( parameter, type );
5659void QgsProcessingDatabaseTableWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5671 setParentConnectionWrapperValue( wrapper );
5674 setParentConnectionWrapperValue( wrapper );
5679 setParentSchemaWrapperValue( wrapper );
5682 setParentSchemaWrapperValue( wrapper );
5702 QVBoxLayout *vlayout =
new QVBoxLayout();
5703 vlayout->setContentsMargins( 0, 0, 0, 0 );
5705 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5708 mDefaultWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
5711 if ( extentParam->defaultValueForGui().isValid() )
5715 mDefaultWidget->setCurrentExtent( rect,
crs );
5716 mDefaultWidget->setOutputExtentFromCurrent();
5720 mDefaultWidget->clear();
5724 vlayout->addWidget( mDefaultWidget );
5725 setLayout( vlayout );
5728QgsProcessingParameterDefinition *QgsProcessingExtentParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5730 const QString defaultVal = mDefaultWidget->isValid() ? QStringLiteral(
"%1,%2,%3,%4%5" ).arg(
5731 QString::number( mDefaultWidget->outputExtent().xMinimum(),
'f', 9 ),
5732 QString::number( mDefaultWidget->outputExtent().xMaximum(),
'f', 9 ),
5733 QString::number( mDefaultWidget->outputExtent().yMinimum(),
'f', 9 ),
5734 QString::number( mDefaultWidget->outputExtent().yMaximum(),
'f', 9 ),
5735 mDefaultWidget->outputCrs().isValid() ? QStringLiteral(
" [%1]" ).arg( mDefaultWidget->outputCrs().authid() ) : QString()
5737 auto param = std::make_unique< QgsProcessingParameterExtent >( name, description, !defaultVal.isEmpty() ? QVariant( defaultVal ) : QVariant() );
5739 return param.release();
5750QWidget *QgsProcessingExtentWidgetWrapper::createWidget()
5760 if ( widgetContext().mapCanvas() )
5761 mExtentWidget->setMapCanvas( widgetContext().mapCanvas() );
5764 mExtentWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
5766 mExtentWidget->setToolTip( parameterDefinition()->toolTip() );
5770 emit widgetValueHasChanged(
this );
5774 setDialog( mDialog );
5776 return mExtentWidget;
5786 mExtentWidget->setMapCanvas( context.
mapCanvas() );
5789void QgsProcessingExtentWidgetWrapper::setDialog( QDialog *dialog )
5797 mDialog->showMinimized();
5800 mDialog->showNormal();
5802 mDialog->activateWindow();
5809void QgsProcessingExtentWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5811 if ( mExtentWidget )
5813 if ( !value.isValid() || ( value.type() == QVariant::String && value.toString().isEmpty() ) )
5814 mExtentWidget->clear();
5819 mExtentWidget->setCurrentExtent( r,
crs );
5820 mExtentWidget->setOutputExtentFromUser( r,
crs );
5825QVariant QgsProcessingExtentWidgetWrapper::widgetValue()
const
5827 if ( mExtentWidget )
5829 const QString val = mExtentWidget->isValid() ? QStringLiteral(
"%1,%2,%3,%4%5" ).arg(
5830 QString::number( mExtentWidget->outputExtent().xMinimum(),
'f', 9 ),
5831 QString::number( mExtentWidget->outputExtent().xMaximum(),
'f', 9 ),
5832 QString::number( mExtentWidget->outputExtent().yMinimum(),
'f', 9 ),
5833 QString::number( mExtentWidget->outputExtent().yMaximum(),
'f', 9 ),
5834 mExtentWidget->outputCrs().isValid() ? QStringLiteral(
" [%1]" ).arg( mExtentWidget->outputCrs().authid() ) : QString()
5837 return val.isEmpty() ? QVariant() : QVariant( val );
5843QStringList QgsProcessingExtentWidgetWrapper::compatibleParameterTypes()
const
5845 return QStringList()
5857QStringList QgsProcessingExtentWidgetWrapper::compatibleOutputTypes()
const
5859 return QStringList()
5866QString QgsProcessingExtentWidgetWrapper::modelerExpressionFormatString()
const
5868 return tr(
"string of the format 'x min,x max,y min,y max' or a geometry value (bounding box is used)" );
5871QString QgsProcessingExtentWidgetWrapper::parameterType()
const
5878 return new QgsProcessingExtentWidgetWrapper( parameter, type );
5883 return new QgsProcessingExtentParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5895 QVBoxLayout *vlayout =
new QVBoxLayout();
5896 vlayout->setContentsMargins( 0, 0, 0, 0 );
5898 vlayout->addWidget(
new QLabel( tr(
"Layer type" ) ) );
5913 for (
int i : layerParam->dataTypes() )
5915 mLayerTypeComboBox->setItemCheckState( mLayerTypeComboBox->findData( i ), Qt::Checked );
5919 vlayout->addWidget( mLayerTypeComboBox );
5921 setLayout( vlayout );
5924QgsProcessingParameterDefinition *QgsProcessingMapLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5926 QList< int > dataTypes;
5927 for (
const QVariant &v : mLayerTypeComboBox->checkedItemsData() )
5928 dataTypes << v.toInt();
5930 auto param = std::make_unique< QgsProcessingParameterMapLayer >( name, description );
5931 param->setDataTypes( dataTypes );
5933 return param.release();
5942QWidget *QgsProcessingMapLayerWidgetWrapper::createWidget()
5944 mComboBox =
new QgsProcessingMapLayerComboBox( parameterDefinition(), type() );
5952 mComboBox->setEditable(
true );
5956 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5958 connect( mComboBox, &QgsProcessingMapLayerComboBox::valueChanged,
this, [ = ]()
5960 if ( mBlockSignals )
5963 emit widgetValueHasChanged(
this );
5966 setWidgetContext( widgetContext() );
5975 mComboBox->setWidgetContext( context );
5980 if ( !parameterDefinition()->defaultValueForGui().isValid() )
5986void QgsProcessingMapLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5989 mComboBox->setValue( value, context );
5992QVariant QgsProcessingMapLayerWidgetWrapper::widgetValue()
const
5994 return mComboBox ? mComboBox->value() : QVariant();
5997QStringList QgsProcessingMapLayerWidgetWrapper::compatibleParameterTypes()
const
5999 return QStringList()
6010QStringList QgsProcessingMapLayerWidgetWrapper::compatibleOutputTypes()
const
6012 return QStringList()
6020QString QgsProcessingMapLayerWidgetWrapper::modelerExpressionFormatString()
const
6022 return tr(
"path to a map layer" );
6027 return QgsProcessingModelChildParameterSource::ModelParameter;
6030QString QgsProcessingMapLayerWidgetWrapper::parameterType()
const
6037 return new QgsProcessingMapLayerWidgetWrapper( parameter, type );
6042 return new QgsProcessingMapLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6051 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6056QStringList QgsProcessingRasterLayerWidgetWrapper::compatibleParameterTypes()
const
6058 return QStringList()
6065QStringList QgsProcessingRasterLayerWidgetWrapper::compatibleOutputTypes()
const
6067 return QStringList()
6075QString QgsProcessingRasterLayerWidgetWrapper::modelerExpressionFormatString()
const
6077 return tr(
"path to a raster layer" );
6080QString QgsProcessingRasterLayerWidgetWrapper::parameterType()
const
6087 return new QgsProcessingRasterLayerWidgetWrapper( parameter, type );
6092 Q_UNUSED( context );
6093 Q_UNUSED( widgetContext );
6094 Q_UNUSED( definition );
6108 QVBoxLayout *vlayout =
new QVBoxLayout();
6109 vlayout->setContentsMargins( 0, 0, 0, 0 );
6111 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6121 for (
int i : vectorParam->dataTypes() )
6123 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6127 vlayout->addWidget( mGeometryTypeComboBox );
6129 setLayout( vlayout );
6132QgsProcessingParameterDefinition *QgsProcessingVectorLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6134 QList< int > dataTypes;
6135 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6136 dataTypes << v.toInt();
6138 auto param = std::make_unique< QgsProcessingParameterVectorLayer >( name, description, dataTypes );
6140 return param.release();
6145 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6150QStringList QgsProcessingVectorLayerWidgetWrapper::compatibleParameterTypes()
const
6152 return QStringList()
6159QStringList QgsProcessingVectorLayerWidgetWrapper::compatibleOutputTypes()
const
6161 return QStringList()
6169QString QgsProcessingVectorLayerWidgetWrapper::modelerExpressionFormatString()
const
6171 return tr(
"path to a vector layer" );
6177 return param->dataTypes();
6179 return QList< int >();
6182QString QgsProcessingVectorLayerWidgetWrapper::parameterType()
const
6189 return new QgsProcessingVectorLayerWidgetWrapper( parameter, type );
6194 return new QgsProcessingVectorLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6206 QVBoxLayout *vlayout =
new QVBoxLayout();
6207 vlayout->setContentsMargins( 0, 0, 0, 0 );
6209 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6219 for (
int i : sourceParam->dataTypes() )
6221 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6229 vlayout->addWidget( mGeometryTypeComboBox );
6231 setLayout( vlayout );
6234QgsProcessingParameterDefinition *QgsProcessingFeatureSourceParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6236 QList< int > dataTypes;
6237 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6238 dataTypes << v.toInt();
6240 auto param = std::make_unique< QgsProcessingParameterFeatureSource >( name, description, dataTypes );
6242 return param.release();
6246 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6251QStringList QgsProcessingFeatureSourceWidgetWrapper::compatibleParameterTypes()
const
6253 return QStringList()
6261QStringList QgsProcessingFeatureSourceWidgetWrapper::compatibleOutputTypes()
const
6263 return QStringList()
6271QString QgsProcessingFeatureSourceWidgetWrapper::modelerExpressionFormatString()
const
6273 return tr(
"path to a vector layer" );
6279 return param->dataTypes();
6281 return QList< int >();
6284QString QgsProcessingFeatureSourceWidgetWrapper::parameterType()
const
6291 return new QgsProcessingFeatureSourceWidgetWrapper( parameter, type );
6296 return new QgsProcessingFeatureSourceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6304 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6309QStringList QgsProcessingMeshLayerWidgetWrapper::compatibleParameterTypes()
const
6311 return QStringList()
6318QStringList QgsProcessingMeshLayerWidgetWrapper::compatibleOutputTypes()
const
6320 return QStringList()
6328QString QgsProcessingMeshLayerWidgetWrapper::modelerExpressionFormatString()
const
6330 return tr(
"path to a mesh layer" );
6333QString QgsProcessingMeshLayerWidgetWrapper::parameterType()
const
6340 return new QgsProcessingMeshLayerWidgetWrapper( parameter, type );
6345 Q_UNUSED( context );
6346 Q_UNUSED( widgetContext );
6347 Q_UNUSED( definition );
6359QgsProcessingRasterBandPanelWidget::QgsProcessingRasterBandPanelWidget( QWidget *parent,
const QgsProcessingParameterBand *param )
6363 QHBoxLayout *hl =
new QHBoxLayout();
6364 hl->setContentsMargins( 0, 0, 0, 0 );
6366 mLineEdit =
new QLineEdit();
6367 mLineEdit->setEnabled(
false );
6368 hl->addWidget( mLineEdit, 1 );
6370 mToolButton =
new QToolButton();
6371 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6372 hl->addWidget( mToolButton );
6378 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, 0 ) );
6381 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingRasterBandPanelWidget::showDialog );
6384void QgsProcessingRasterBandPanelWidget::setBands(
const QList< int > &bands )
6389void QgsProcessingRasterBandPanelWidget::setBandNames(
const QHash<int, QString> &names )
6394void QgsProcessingRasterBandPanelWidget::setValue(
const QVariant &value )
6396 if ( value.isValid() )
6397 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
6401 updateSummaryText();
6405void QgsProcessingRasterBandPanelWidget::showDialog()
6407 QVariantList availableOptions;
6408 QStringList fieldNames;
6409 availableOptions.reserve( mBands.size() );
6410 for (
int band : std::as_const( mBands ) )
6412 availableOptions << band;
6418 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
6419 widget->setPanelTitle( mParam->description() );
6421 widget->setValueFormatter( [
this](
const QVariant & v ) -> QString
6423 int band = v.toInt();
6424 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6427 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
6429 setValue( widget->selectedOptions() );
6436 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
6438 dlg.setValueFormatter( [
this](
const QVariant & v ) -> QString
6440 int band = v.toInt();
6441 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6445 setValue( dlg.selectedOptions() );
6450void QgsProcessingRasterBandPanelWidget::updateSummaryText()
6453 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, mValue.count() ) );
6465 QVBoxLayout *vlayout =
new QVBoxLayout();
6466 vlayout->setContentsMargins( 0, 0, 0, 0 );
6468 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6470 mDefaultLineEdit =
new QLineEdit();
6471 mDefaultLineEdit->setToolTip( tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6476 for (
int b : bands )
6478 defVal << QString::number( b );
6481 mDefaultLineEdit->setText( defVal.join(
';' ) );
6483 vlayout->addWidget( mDefaultLineEdit );
6485 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
6486 mParentLayerComboBox =
new QComboBox();
6488 QString initialParent;
6490 initialParent = bandParam->parentLayerParameterName();
6492 if (
auto *lModel = widgetContext.
model() )
6495 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6496 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6500 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
6501 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
6503 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6509 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
6512 mParentLayerComboBox->addItem( initialParent, initialParent );
6513 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6516 vlayout->addWidget( mParentLayerComboBox );
6518 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Allow multiple" ) );
6520 mAllowMultipleCheckBox->setChecked( bandParam->allowMultiple() );
6522 vlayout->addWidget( mAllowMultipleCheckBox );
6523 setLayout( vlayout );
6526QgsProcessingParameterDefinition *QgsProcessingBandParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6528 auto param = std::make_unique< QgsProcessingParameterBand >( name, description, mDefaultLineEdit->text().split(
';' ), mParentLayerComboBox->currentData().toString(),
false, mAllowMultipleCheckBox->isChecked() );
6530 return param.release();
6539QWidget *QgsProcessingBandWidgetWrapper::createWidget()
6549 mPanel =
new QgsProcessingRasterBandPanelWidget(
nullptr, bandParam );
6550 mPanel->setToolTip( parameterDefinition()->toolTip() );
6551 connect( mPanel, &QgsProcessingRasterBandPanelWidget::changed,
this, [ = ]
6553 emit widgetValueHasChanged(
this );
6562 mComboBox->setToolTip( parameterDefinition()->toolTip() );
6565 emit widgetValueHasChanged(
this );
6573 mLineEdit =
new QLineEdit();
6574 mLineEdit->setToolTip( QObject::tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6575 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
6577 emit widgetValueHasChanged(
this );
6586void QgsProcessingBandWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6596 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterBand *
>( parameterDefinition() )->parentLayerParameterName() )
6598 setParentLayerWrapperValue( wrapper );
6601 setParentLayerWrapperValue( wrapper );
6618 std::unique_ptr< QgsProcessingContext > tmpContext;
6619 if ( mProcessingContextGenerator )
6620 context = mProcessingContextGenerator->processingContext();
6624 tmpContext = std::make_unique< QgsProcessingContext >();
6625 context = tmpContext.get();
6631 if ( layer && layer->
isValid() )
6635 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
6638 mParentLayer.reset( qobject_cast< QgsRasterLayer * >( ownedLayer.release() ) );
6639 layer = mParentLayer.get();
6647 mComboBox->setLayer( layer );
6651 if ( provider && layer->
isValid() )
6656 QHash< int, QString > bandNames;
6657 for (
int i = 1; i <= nBands; ++i )
6662 mPanel->setBands( bands );
6663 mPanel->setBandNames( bandNames );
6670 mComboBox->setLayer(
nullptr );
6672 mPanel->setBands( QList< int >() );
6674 if ( value.isValid() && widgetContext().messageBar() )
6677 widgetContext().
messageBar()->
pushMessage( QString(), QObject::tr(
"Could not load selected layer/table. Dependent bands could not be populated" ),
6678 Qgis::MessageLevel::Info );
6682 if ( parameterDefinition()->defaultValueForGui().isValid() )
6683 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6686void QgsProcessingBandWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6690 if ( !value.isValid() )
6691 mComboBox->setBand( -1 );
6695 mComboBox->setBand( v );
6701 if ( value.isValid() )
6704 opts.reserve( v.size() );
6709 mPanel->setValue( value.isValid() ? opts : QVariant() );
6711 else if ( mLineEdit )
6718 opts.reserve( v.size() );
6720 opts << QString::number( i );
6721 mLineEdit->setText( value.isValid() && !opts.empty() ? opts.join(
';' ) : QString() );
6725 if ( value.isValid() )
6733QVariant QgsProcessingBandWidgetWrapper::widgetValue()
const
6736 return mComboBox->currentBand() == -1 ? QVariant() : mComboBox->currentBand();
6738 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
6739 else if ( mLineEdit )
6744#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
6745 const QStringList parts = mLineEdit->text().split(
';', QString::SkipEmptyParts );
6747 const QStringList parts = mLineEdit->text().split(
';', Qt::SkipEmptyParts );
6750 res.reserve( parts.count() );
6751 for (
const QString &s : parts )
6754 int band = s.toInt( &ok );
6758 return res.
isEmpty() ? QVariant() : res;
6762 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
6769QStringList QgsProcessingBandWidgetWrapper::compatibleParameterTypes()
const
6771 return QStringList()
6776QStringList QgsProcessingBandWidgetWrapper::compatibleOutputTypes()
const
6778 return QStringList()
6782QString QgsProcessingBandWidgetWrapper::modelerExpressionFormatString()
const
6784 return tr(
"selected band numbers as an array of numbers, or semicolon separated string of options (e.g. '1;3')" );
6787QString QgsProcessingBandWidgetWrapper::parameterType()
const
6794 return new QgsProcessingBandWidgetWrapper( parameter, type );
6799 return new QgsProcessingBandParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6812 QHBoxLayout *hl =
new QHBoxLayout();
6813 hl->setContentsMargins( 0, 0, 0, 0 );
6815 mLineEdit =
new QLineEdit();
6816 mLineEdit->setEnabled(
false );
6817 hl->addWidget( mLineEdit, 1 );
6819 mToolButton =
new QToolButton();
6820 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6821 hl->addWidget( mToolButton );
6827 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, 0 ) );
6830 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingMultipleLayerPanelWidget::showDialog );
6833void QgsProcessingMultipleLayerPanelWidget::setValue(
const QVariant &value )
6835 if ( value.isValid() )
6836 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
6840 updateSummaryText();
6844void QgsProcessingMultipleLayerPanelWidget::setProject(
QgsProject *project )
6851 if ( mValue.removeAll( layerId ) )
6853 updateSummaryText();
6860void QgsProcessingMultipleLayerPanelWidget::setModel( QgsProcessingModelAlgorithm *model,
const QString &modelChildAlgorithmID )
6866 switch ( mParam->layerType() )
7015void QgsProcessingMultipleLayerPanelWidget::showDialog()
7020 QgsProcessingMultipleInputPanelWidget *widget =
new QgsProcessingMultipleInputPanelWidget( mParam, mValue, mModelSources, mModel );
7021 widget->setPanelTitle( mParam->description() );
7022 widget->setProject( mProject );
7023 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
7025 setValue( widget->selectedOptions() );
7032 QgsProcessingMultipleInputDialog dlg( mParam, mValue, mModelSources, mModel,
this, Qt::WindowFlags() );
7033 dlg.setProject( mProject );
7036 setValue( dlg.selectedOptions() );
7041void QgsProcessingMultipleLayerPanelWidget::updateSummaryText()
7044 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, mValue.count() ) );
7054 QVBoxLayout *vlayout =
new QVBoxLayout();
7055 vlayout->setContentsMargins( 0, 0, 0, 0 );
7057 vlayout->addWidget(
new QLabel( tr(
"Allowed layer type" ) ) );
7058 mLayerTypeComboBox =
new QComboBox();
7072 mLayerTypeComboBox->setCurrentIndex( mLayerTypeComboBox->findData( layersParam->layerType() ) );
7074 vlayout->addWidget( mLayerTypeComboBox );
7075 setLayout( vlayout );
7078QgsProcessingParameterDefinition *QgsProcessingMultipleLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
7080 auto param = std::make_unique< QgsProcessingParameterMultipleLayers >( name, description,
static_cast< QgsProcessing::SourceType >( mLayerTypeComboBox->currentData().toInt() ) );
7082 return param.release();
7091QWidget *QgsProcessingMultipleLayerWidgetWrapper::createWidget()
7095 mPanel =
new QgsProcessingMultipleLayerPanelWidget(
nullptr, layerParam );
7096 mPanel->setToolTip( parameterDefinition()->toolTip() );
7097 mPanel->setProject( widgetContext().project() );
7099 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7100 connect( mPanel, &QgsProcessingMultipleLayerPanelWidget::changed,
this, [ = ]
7102 emit widgetValueHasChanged(
this );
7112 mPanel->setProject( context.
project() );
7114 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7118void QgsProcessingMultipleLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7123 if ( value.isValid() )
7126 opts.reserve( v.size() );
7128 opts << l->source();
7131 for (
const QVariant &v : value.toList() )
7133 if ( v.userType() == QMetaType::type(
"QgsProcessingModelChildParameterSource" ) )
7135 const QgsProcessingModelChildParameterSource source = v.value< QgsProcessingModelChildParameterSource >();
7136 opts << QVariant::fromValue( source );
7141 mPanel->setValue( value.isValid() ? opts : QVariant() );
7145QVariant QgsProcessingMultipleLayerWidgetWrapper::widgetValue()
const
7148 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
7153QStringList QgsProcessingMultipleLayerWidgetWrapper::compatibleParameterTypes()
const
7155 return QStringList()
7166QStringList QgsProcessingMultipleLayerWidgetWrapper::compatibleOutputTypes()
const
7168 return QStringList()
7177QString QgsProcessingMultipleLayerWidgetWrapper::modelerExpressionFormatString()
const
7179 return tr(
"an array of layer paths, or semicolon separated string of layer paths" );
7182QString QgsProcessingMultipleLayerWidgetWrapper::parameterType()
const
7189 return new QgsProcessingMultipleLayerWidgetWrapper( parameter, type );
7194 return new QgsProcessingMultipleLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
7203 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
7208QStringList QgsProcessingPointCloudLayerWidgetWrapper::compatibleParameterTypes()
const
7210 return QStringList()
7217QStringList QgsProcessingPointCloudLayerWidgetWrapper::compatibleOutputTypes()
const
7219 return QStringList()
7227QString QgsProcessingPointCloudLayerWidgetWrapper::modelerExpressionFormatString()
const
7229 return tr(
"path to a point cloud layer" );
7232QString QgsProcessingPointCloudLayerWidgetWrapper::parameterType()
const
7239 return new QgsProcessingPointCloudLayerWidgetWrapper( parameter, type );
7244 Q_UNUSED( context );
7245 Q_UNUSED( widgetContext );
7246 Q_UNUSED( definition );
7263QStringList QgsProcessingAnnotationLayerWidgetWrapper::compatibleParameterTypes()
const
7265 return QStringList()
7272QStringList QgsProcessingAnnotationLayerWidgetWrapper::compatibleOutputTypes()
const
7274 return QStringList()
7279QString QgsProcessingAnnotationLayerWidgetWrapper::modelerExpressionFormatString()
const
7281 return tr(
"name of an annotation layer, or \"main\" for the main annotation layer" );
7284QString QgsProcessingAnnotationLayerWidgetWrapper::parameterType()
const
7291 return new QgsProcessingAnnotationLayerWidgetWrapper( parameter, type );
7296 Q_UNUSED( context );
7297 Q_UNUSED( widgetContext );
7298 Q_UNUSED( definition );
7309 if ( mWidgetContext.project() )
7310 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7314QWidget *QgsProcessingAnnotationLayerWidgetWrapper::createWidget()
7325 mComboBox->setEditable(
true );
7329 mComboBox->setToolTip( parameterDefinition()->toolTip() );
7331 if ( mWidgetContext.project() )
7332 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7335 mComboBox->setAllowEmptyLayer(
true );
7339 if ( mBlockSignals )
7342 emit widgetValueHasChanged(
this );
7345 setWidgetContext( widgetContext() );
7349void QgsProcessingAnnotationLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7355 mComboBox->setLayer(
nullptr );
7359 QVariant val = value;
7360 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
7372 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( val.value< QObject * >() );
7373 if ( !layer && val.type() == QVariant::String )
7380 mComboBox->setLayer( layer );
7385QVariant QgsProcessingAnnotationLayerWidgetWrapper::widgetValue()
const
7387 return mComboBox && mComboBox->currentLayer() ?
7388 ( mWidgetContext.project() ? ( mComboBox->currentLayer() == mWidgetContext.project()->mainAnnotationLayer() ? QStringLiteral(
"main" ) : mComboBox->currentLayer()->id() ) : mComboBox->currentLayer()->id() )
7404QWidget *QgsProcessingOutputWidgetWrapper::createWidget()
7412 mOutputWidget =
new QgsProcessingLayerOutputDestinationWidget( destParam,
false );
7413 if ( mProcessingContextGenerator )
7414 mOutputWidget->setContext( mProcessingContextGenerator->processingContext() );
7415 if ( mParametersGenerator )
7416 mOutputWidget->registerProcessingParametersGenerator( mParametersGenerator );
7417 mOutputWidget->setToolTip( parameterDefinition()->toolTip() );
7419 connect( mOutputWidget, &QgsProcessingLayerOutputDestinationWidget::destinationChanged,
this, [ = ]()
7421 if ( mBlockSignals )
7424 emit widgetValueHasChanged(
this );
7432 mOutputWidget->addOpenAfterRunningOption();
7434 return mOutputWidget;
7444void QgsProcessingOutputWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
7446 if ( mOutputWidget )
7447 mOutputWidget->setValue( value );
7450QVariant QgsProcessingOutputWidgetWrapper::widgetValue()
const
7452 if ( mOutputWidget )
7453 return mOutputWidget->value();
7458QVariantMap QgsProcessingOutputWidgetWrapper::customProperties()
const
7461 if ( mOutputWidget )
7462 res.insert( QStringLiteral(
"OPEN_AFTER_RUNNING" ), mOutputWidget->openAfterRunning() );
7466QStringList QgsProcessingOutputWidgetWrapper::compatibleParameterTypes()
const
7468 return QStringList()
7477QStringList QgsProcessingOutputWidgetWrapper::compatibleOutputTypes()
const
7479 return QStringList()
7490 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7495QString QgsProcessingFeatureSinkWidgetWrapper::parameterType()
const
7502 return new QgsProcessingFeatureSinkWidgetWrapper( parameter, type );
7505QString QgsProcessingFeatureSinkWidgetWrapper::modelerExpressionFormatString()
const
7507 return tr(
"path to layer destination" );
7515 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7520QString QgsProcessingVectorDestinationWidgetWrapper::parameterType()
const
7527 return new QgsProcessingVectorDestinationWidgetWrapper( parameter, type );
7530QString QgsProcessingVectorDestinationWidgetWrapper::modelerExpressionFormatString()
const
7532 return tr(
"path to layer destination" );
7540 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7545QString QgsProcessingRasterDestinationWidgetWrapper::parameterType()
const
7552 return new QgsProcessingRasterDestinationWidgetWrapper( parameter, type );
7555QString QgsProcessingRasterDestinationWidgetWrapper::modelerExpressionFormatString()
const
7557 return tr(
"path to layer destination" );
7565 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7570QString QgsProcessingPointCloudDestinationWidgetWrapper::parameterType()
const
7577 return new QgsProcessingPointCloudDestinationWidgetWrapper( parameter, type );
7580QString QgsProcessingPointCloudDestinationWidgetWrapper::modelerExpressionFormatString()
const
7582 return tr(
"path to layer destination" );
7590 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7595QString QgsProcessingFileDestinationWidgetWrapper::parameterType()
const
7602 return new QgsProcessingFileDestinationWidgetWrapper( parameter, type );
7605QString QgsProcessingFileDestinationWidgetWrapper::modelerExpressionFormatString()
const
7607 return tr(
"path to file destination" );
7615 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7620QString QgsProcessingFolderDestinationWidgetWrapper::parameterType()
const
7627 return new QgsProcessingFolderDestinationWidgetWrapper( parameter, type );
7630QString QgsProcessingFolderDestinationWidgetWrapper::modelerExpressionFormatString()
const
7632 return tr(
"path to folder destination" );
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Selector widget for authentication configs.
void selectedConfigIdChanged(const QString &authcfg)
Emitted when authentication config is changed or missing.
QComboBox subclass which allows selecting multiple items.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Q_GADGET QgsUnitTypes::DistanceUnit mapUnits
The QgsDatabaseSchemaComboBox class is a combo box which displays the list of schemas for a specific ...
The QgsDatabaseTableComboBox class is a combo box which displays the list of tables for a specific da...
The QgsDateEdit class is a QDateEdit widget with the capability of setting/reading null dates.
void dateValueChanged(const QDate &date)
Signal emitted whenever the date changes.
The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times.
void setAllowNull(bool allowNull)
Determines if the widget allows setting null date/time.
void setNullRepresentation(const QString &null)
Sets the widget's null representation, which defaults to QgsApplication::nullRepresentation().
void valueChanged(const QDateTime &date)
Signal emitted whenever the value changes.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
static double toDouble(const QString &input, bool *ok)
Converts input string to double value.
The QgsExpressionLineEdit widget includes a line edit for entering expressions together with a button...
void expressionChanged(const QString &expression)
Emitted when the expression is changed.
The QgsFieldComboBox is a combo box which displays the list of fields of a given layer.
void fieldChanged(const QString &fieldName)
Emitted when the currently selected field changes.
@ DateTime
Datetime fieldss.
@ Date
Date or datetime fields.
@ Numeric
All numeric fields.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
QList< QgsField > toList() const
Utility function to return a list of QgsField instances.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false)
void remove(int fieldIdx)
Removes the field with the given index.
int count() const
Returns number of items.
bool isEmpty() const
Checks whether the container is empty.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
A geometry is the spatial representation of a feature.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
The QgsLayoutComboBox class is a combo box which displays available layouts from a QgsLayoutManager.
void layoutChanged(QgsMasterLayoutInterface *layout)
Emitted whenever the currently selected layout changes.
The QgsLayoutItemComboBox class is a combo box which displays items of a matching type from a layout.
void itemChanged(QgsLayoutItem *item)
Emitted whenever the currently selected item changes.
Base class for graphical items within a QgsLayout.
virtual QString uuid() const
Returns the item identification string.
@ FilterPrintLayouts
Includes print layouts.
QList< QgsPrintLayout * > printLayouts() const
Returns a list of all print layouts contained in the manager.
Map canvas is a class for displaying all GIS data types on a canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
The QgsMapLayerComboBox class is a combo box which displays the list of layers.
void layerChanged(QgsMapLayer *layer)
Emitted whenever the currently selected layer changes.
@ AnnotationLayer
QgsAnnotationLayer.
Base class for all map layer types.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
QgsPointLocator::Match mapPointMatch() const
Returns the matching data from the most recently snapped point.
QgsPointXY snapPoint()
snapPoint will snap the points using the map canvas snapping utils configuration
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
Interface for master layout type objects, such as print layouts and reports.
virtual QString name() const =0
Returns the layout's name.
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::MessageLevel::Info, int duration=-1)
A convenience method for pushing a message with the specified text to the bar.
bool clearWidgets()
Removes all items from the bar.
A class to represent a 2D point.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
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.
QgsExpressionContext & expressionContext()
Returns the expression context.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
QgsMapLayer * takeResultLayer(const QString &id)
Takes the result map layer with matching id from the context and transfers ownership of it back to th...
Base class for all parameter definitions which represent file or layer destinations,...
Encapsulates settings relating to a feature source input to a processing algorithm.
QgsProperty source
Source definition.
WidgetType
Types of dialogs which Processing widgets can be created for.
@ Standard
Standard algorithm dialog.
@ Batch
Batch processing dialog.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A raster band parameter for Processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
bool allowMultiple() const
Returns whether multiple band selections are permitted.
A boolean parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A color parameter for processing algorithms.
bool opacityEnabled() const
Returns true if the parameter allows opacity control.
static QString typeName()
Returns the type name for the parameter class.
A coordinate operation parameter for processing algorithms, for selection between available coordinat...
static QString typeName()
Returns the type name for the parameter class.
QVariant sourceCrs() const
Returns the static source CRS, or an invalid value if this is not set.
QVariant destinationCrs() const
Returns the static destination CRS, or an invalid value if this is not set.
A coordinate reference system parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A database schema parameter for processing algorithms, allowing users to select from existing schemas...
static QString typeName()
Returns the type name for the parameter class.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
A database table name parameter for processing algorithms, allowing users to select from existing dat...
static QString typeName()
Returns the type name for the parameter class.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
QString parentSchemaParameterName() const
Returns the name of the parent schema parameter, or an empty string if this is not set.
bool allowNewTableNames() const
Returns true if the parameter allows users to enter names for a new (non-existing) tables.
A datetime (or pure date or time) parameter for processing algorithms.
@ DateTime
Datetime values.
static QString typeName()
Returns the type name for the parameter class.
Type dataType() const
Returns the acceptable data type for the parameter.
Base class for the definition of processing parameters.
QVariantMap metadata() const
Returns the parameter's freeform metadata.
QString description() const
Returns the description for the parameter.
QVariant defaultValueForGui() const
Returns the default value to use for the parameter in a GUI.
@ FlagOptional
Parameter is optional.
virtual QString type() const =0
Unique parameter type name.
Flags flags() const
Returns any flags associated with the parameter.
QString name() const
Returns the name of the parameter.
void setFlags(Flags flags)
Sets the flags associated with the parameter.
A double numeric parameter for distance values.
static QString typeName()
Returns the type name for the parameter class.
QgsUnitTypes::DistanceUnit defaultUnit() const
Returns the default distance unit for the parameter.
A double numeric parameter for duration values.
QgsUnitTypes::TemporalUnit defaultUnit() const
Returns the default duration unit for the parameter.
static QString typeName()
Returns the type name for the parameter class.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
bool allowMultiple() const
Returns true if the parameter allows multiple selected values.
QStringList options() const
Returns the list of acceptable options for the parameter.
bool usesStaticStrings() const
Returns true if the parameter uses static (non-translated) string values for its enumeration choice l...
static QString typeName()
Returns the type name for the parameter class.
An expression parameter for processing algorithms.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
static QString typeName()
Returns the type name for the parameter class.
A rectangular map extent parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
An input feature source (such as vector layers) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A vector layer or feature source field parameter for processing algorithms.
void setDataType(DataType type)
Sets the acceptable data type for the field.
bool allowMultiple() const
Returns whether multiple field selections are permitted.
bool defaultToAllFields() const
Returns whether a parameter which allows multiple selections (see allowMultiple()) should automatical...
static QString typeName()
Returns the type name for the parameter class.
DataType
Field data types.
@ DateTime
Accepts datetime fields.
@ Numeric
Accepts numeric fields.
@ String
Accepts string fields.
DataType dataType() const
Returns the acceptable data type for the field.
static QString typeName()
Returns the type name for the parameter class.
An input file or folder parameter for processing algorithms.
QString extension() const
Returns any specified file extension for the parameter.
static QString typeName()
Returns the type name for the parameter class.
Behavior
Parameter behavior.
@ Folder
Parameter is a folder.
@ File
Parameter is a single file.
Behavior behavior() const
Returns the parameter behavior (e.g.
QString fileFilter() const
Returns the file filter string for file destinations compatible with this parameter.
static QString typeName()
Returns the type name for the parameter class.
A geometry parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A print layout item parameter, allowing users to select a particular item from a print layout.
static QString typeName()
Returns the type name for the parameter class.
int itemType() const
Returns the acceptable item type, or -1 if any item type is allowed.
A print layout parameter, allowing users to select a print layout.
static QString typeName()
Returns the type name for the parameter class.
A map layer parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A map theme parameter for processing algorithms, allowing users to select an existing map theme from ...
static QString typeName()
Returns the type name for the parameter class.
A table (matrix) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A parameter for processing algorithms which accepts multiple map layers.
static QString typeName()
Returns the type name for the parameter class.
A numeric parameter for processing algorithms.
double minimum() const
Returns the minimum value acceptable by the parameter.
@ Double
Double/float values.
double maximum() const
Returns the maximum value acceptable by the parameter.
Type dataType() const
Returns the acceptable data type for the parameter.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A point parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A data provider connection parameter for processing algorithms, allowing users to select from availab...
static QString typeName()
Returns the type name for the parameter class.
QString providerId() const
Returns the ID of the provider associated with the connections.
A numeric range parameter for processing algorithms.
QgsProcessingParameterNumber::Type dataType() const
Returns the acceptable data type for the range.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A raster layer parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A double numeric parameter for map scale values.
static QString typeName()
Returns the type name for the parameter class.
A string parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
bool multiLine() const
Returns true if the parameter allows multiline strings.
static QString typeName()
Returns the type name for the parameter class.
A vector layer (with or without geometry) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
Contains settings which reflect the context in which a Processing parameter widget is shown,...
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QgsProject * project() const
Returns the project associated with the widget.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
QgsProcessingModelAlgorithm * model() const
Returns the model which the parameter widget is associated with.
QgsMapLayer * activeLayer() const
Returns the current active layer.
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of map layers.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
static QTime parameterAsTime(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static time value.
static QgsRectangle parameterAsExtent(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent.
static QString parameterAsEnumString(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static enum string.
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
static QList< int > parameterAsInts(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of integer values.
static QString parameterAsConnectionName(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a connection name string.
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
static QgsLayoutItem * parameterAsLayoutItem(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsPrintLayout *layout)
Evaluates the parameter with matching definition to a print layout item, taken from the specified lay...
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QColor parameterAsColor(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the color associated with an point parameter value, or an invalid color if the parameter was ...
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
static int parameterAsInt(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static integer value.
static QString parameterAsDatabaseTableName(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database table name.
static QString parameterAsSchema(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database schema name.
static QgsGeometry parameterAsGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a geometry.
static QString parameterAsExpression(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to an expression.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
static QgsRasterLayer * parameterAsRasterLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a raster layer.
static QList< int > parameterAsEnums(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of enum values.
static QStringList parameterAsEnumStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of static enum strings.
static QStringList parameterAsFields(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of fields.
static QgsCoordinateReferenceSystem parameterAsExtentCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
static QDateTime parameterAsDateTime(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static datetime value.
static QDate parameterAsDate(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static date value.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
@ Annotation
Annotation layer type, since QGIS 3.22.
static QgsCoordinateReferenceSystem variantToCrs(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a coordinate reference system.
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, QgsProcessingUtils::LayerHint typeHint=QgsProcessingUtils::LayerHint::UnknownType)
Interprets a string as a map layer within the supplied context.
SourceType
Data source types enum.
@ TypePlugin
Plugin layers.
@ TypeVectorLine
Vector line layers.
@ TypeMapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer)
@ TypeVectorPolygon
Vector polygon layers.
@ TypeFile
Files (i.e. non map layer sources, such as text files)
@ TypeAnnotation
Annotation layers.
@ TypePointCloud
Point cloud layers.
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ TypeRaster
Raster layers.
@ TypeVectorPoint
Vector point layers.
@ TypeVectorAnyGeometry
Any vector layer with geometry.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsMapThemeCollection * mapThemeCollection
const QgsLayoutManager * layoutManager() const
Returns the project's layout manager, which manages print layouts, atlases and reports within the pro...
void layerRemoved(const QString &layerId)
Emitted after a layer was removed from the registry.
A store for object properties.
@ StaticProperty
Static property (QgsStaticProperty)
Type propertyType() const
Returns the property type.
The QgsProviderConnectionComboBox class is a combo box which displays the list of connections registe...
A combobox widget which displays the bands present in a raster layer.
void bandChanged(int band)
Emitted when the currently selected band changes.
static QString displayBandName(QgsRasterDataProvider *provider, int band)
Returns a user-friendly band name for the specified band.
Base class for raster data providers.
virtual int bandCount() const =0
Gets number of bands.
Represents a raster layer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
A rectangle specified with double values.
This class is a composition of two QSettings instances:
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Class that shows snapping marker on map canvas for the current snapping match.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
The QgsTimeEdit class is a QTimeEdit widget with the capability of setting/reading null date/times.
void timeValueChanged(const QTime &time)
Signal emitted whenever the time changes.
DistanceUnit
Units of distance.
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
@ DistanceKilometers
Kilometers.
@ DistanceMiles
Terrestrial miles.
@ DistanceUnknownUnit
Unknown distance unit.
@ DistanceYards
Imperial yards.
@ DistanceFeet
Imperial feet.
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
static Q_INVOKABLE QgsUnitTypes::DistanceUnitType unitType(QgsUnitTypes::DistanceUnit unit)
Returns the type for a distance unit.
@ Standard
Unit is a standard measurement unit.
TemporalUnit
Temporal units.
@ TemporalMilliseconds
Milliseconds.
@ TemporalDecades
Decades.
@ TemporalCenturies
Centuries.
@ TemporalSeconds
Seconds.
@ TemporalMinutes
Minutes.
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
@ VectorLayer
Vector layer.
@ RasterLayer
Raster layer.
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
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 c
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
const QgsCoordinateReferenceSystem & crs