67 #include <QToolButton>
69 #include <QHBoxLayout>
70 #include <QVBoxLayout>
74 #include <QPlainTextEdit>
75 #include <QRadioButton>
76 #include <QButtonGroup>
78 #include <QFileDialog>
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 );
102 QgsProcessingParameterDefinition *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();
116 QWidget *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 );
155 QLabel *QgsProcessingBooleanWidgetWrapper::createLabel()
164 void QgsProcessingBooleanWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
171 mCheckBox->setChecked( v );
179 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
185 QVariant QgsProcessingBooleanWidgetWrapper::widgetValue()
const
190 return mCheckBox->isChecked();
194 return mComboBox->currentData();
199 QStringList QgsProcessingBooleanWidgetWrapper::compatibleParameterTypes()
const
221 QStringList QgsProcessingBooleanWidgetWrapper::compatibleOutputTypes()
const
232 QString 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 );
274 QgsProcessingParameterDefinition *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();
287 QWidget *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 );
337 void 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 );
357 QVariant QgsProcessingCrsWidgetWrapper::widgetValue()
const
359 if ( mUseProjectCrsCheckBox && mUseProjectCrsCheckBox->isChecked() )
360 return QStringLiteral(
"ProjectCrs" );
361 else if ( mProjectionSelectionWidget )
362 return mProjectionSelectionWidget->crs().isValid() ? mProjectionSelectionWidget->crs() : QVariant();
367 QStringList QgsProcessingCrsWidgetWrapper::compatibleParameterTypes()
const
381 QStringList QgsProcessingCrsWidgetWrapper::compatibleOutputTypes()
const
389 QString QgsProcessingCrsWidgetWrapper::modelerExpressionFormatString()
const
391 return tr(
"string as EPSG code, WKT or PROJ format, or a string identifying a map layer" );
394 QString 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 );
437 QgsProcessingParameterDefinition *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();
452 QWidget *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 );
527 void 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 );
549 QVariant QgsProcessingStringWidgetWrapper::widgetValue()
const
552 return mLineEdit->text();
553 else if ( mPlainTextEdit )
554 return mPlainTextEdit->toPlainText();
555 else if ( mComboBox )
556 return mComboBox->currentData();
561 QStringList QgsProcessingStringWidgetWrapper::compatibleParameterTypes()
const
577 QStringList QgsProcessingStringWidgetWrapper::compatibleOutputTypes()
const
585 QString QgsProcessingStringWidgetWrapper::parameterType()
const
592 return new QgsProcessingStringWidgetWrapper( parameter, type );
597 return new QgsProcessingStringParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
612 QWidget *QgsProcessingAuthConfigWidgetWrapper::createWidget()
621 mAuthConfigSelect->setToolTip( parameterDefinition()->toolTip() );
625 emit widgetValueHasChanged(
this );
627 return mAuthConfigSelect;
633 void QgsProcessingAuthConfigWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
636 if ( mAuthConfigSelect )
637 mAuthConfigSelect->setConfigId( v );
640 QVariant QgsProcessingAuthConfigWidgetWrapper::widgetValue()
const
642 if ( mAuthConfigSelect )
643 return mAuthConfigSelect->configId();
648 QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleParameterTypes()
const
656 QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleOutputTypes()
const
661 QString 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 );
728 QgsProcessingParameterDefinition *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();
764 QWidget *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() - 1;
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 ); } );
898 void 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 );
922 QVariant 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();
942 QStringList QgsProcessingNumericWidgetWrapper::compatibleParameterTypes()
const
952 QStringList QgsProcessingNumericWidgetWrapper::compatibleOutputTypes()
const
958 double 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 ) ) );
973 QString 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 );
1078 QgsProcessingParameterDefinition *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 )
1107 QString QgsProcessingDistanceWidgetWrapper::parameterType()
const
1114 return new QgsProcessingDistanceWidgetWrapper( parameter, type );
1117 QWidget *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 );
1175 void 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() );
1203 void 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();
1246 QVariant 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 );
1313 QgsProcessingParameterDefinition *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 )
1344 QString QgsProcessingDurationWidgetWrapper::parameterType()
const
1351 return new QgsProcessingDurationWidgetWrapper( parameter, type );
1354 QWidget *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();
1397 QLabel *QgsProcessingDurationWidgetWrapper::createLabel()
1409 QVariant QgsProcessingDurationWidgetWrapper::widgetValue()
const
1411 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1412 if ( val.type() == QVariant::Double && mUnitsCombo )
1423 void 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 );
1466 QgsProcessingParameterDefinition *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 )
1481 QString QgsProcessingScaleWidgetWrapper::parameterType()
const
1488 return new QgsProcessingScaleWidgetWrapper( parameter, type );
1491 QWidget *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() );
1527 QVariant QgsProcessingScaleWidgetWrapper::widgetValue()
const
1529 return mScaleWidget && !mScaleWidget->isNull() ? QVariant( mScaleWidget->scale() ) : QVariant();
1532 void 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 );
1588 QgsProcessingParameterDefinition *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();
1629 QWidget *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 );
1721 void 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 );
1765 QVariant 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() );
1786 QStringList QgsProcessingRangeWidgetWrapper::compatibleParameterTypes()
const
1788 return QStringList()
1793 QStringList QgsProcessingRangeWidgetWrapper::compatibleOutputTypes()
const
1798 QString QgsProcessingRangeWidgetWrapper::modelerExpressionFormatString()
const
1800 return tr(
"string as two comma delimited floats, e.g. '1,10'" );
1803 QString 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 );
1839 QgsProcessingParameterDefinition *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();
1853 QWidget *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;
1875 void QgsProcessingMatrixWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1878 if ( mMatrixWidget )
1879 mMatrixWidget->setValue( v );
1882 QVariant QgsProcessingMatrixWidgetWrapper::widgetValue()
const
1884 if ( mMatrixWidget )
1885 return mMatrixWidget->value().isEmpty() ? QVariant() : mMatrixWidget->value();
1890 QStringList QgsProcessingMatrixWidgetWrapper::compatibleParameterTypes()
const
1892 return QStringList()
1896 QStringList QgsProcessingMatrixWidgetWrapper::compatibleOutputTypes()
const
1898 return QStringList();
1901 QString QgsProcessingMatrixWidgetWrapper::modelerExpressionFormatString()
const
1903 return tr(
"comma delimited string of values, or an array of values" );
1906 QString 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 );
1984 QgsProcessingParameterDefinition *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();
2003 QWidget *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 );
2044 void QgsProcessingFileWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2048 mFileWidget->setFilePath( v );
2051 QVariant QgsProcessingFileWidgetWrapper::widgetValue()
const
2054 return mFileWidget->filePath();
2059 QStringList QgsProcessingFileWidgetWrapper::compatibleParameterTypes()
const
2061 return QStringList()
2066 QStringList QgsProcessingFileWidgetWrapper::compatibleOutputTypes()
const
2076 QString QgsProcessingFileWidgetWrapper::modelerExpressionFormatString()
const
2078 return tr(
"string representing a path to a file or folder" );
2081 QString 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 );
2161 QgsProcessingParameterDefinition *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();
2174 QWidget *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;
2230 void 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();
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 );
2323 void 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 );
2334 QVariant 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();
2346 QStringList QgsProcessingExpressionWidgetWrapper::compatibleParameterTypes()
const
2348 return QStringList()
2357 QStringList QgsProcessingExpressionWidgetWrapper::compatibleOutputTypes()
const
2359 return QStringList()
2364 QString QgsProcessingExpressionWidgetWrapper::modelerExpressionFormatString()
const
2366 return tr(
"string representation of an expression" );
2369 const QgsVectorLayer *QgsProcessingExpressionWidgetWrapper::linkedVectorLayer()
const
2371 if ( mFieldExpWidget && mFieldExpWidget->layer() )
2372 return mFieldExpWidget->layer();
2374 if ( mExpBuilderWidget && mExpBuilderWidget->layer() )
2375 return mExpBuilderWidget->layer();
2380 QString 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 );
2426 void 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();
2442 void 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() );
2499 void QgsProcessingEnumPanelWidget::updateSummaryText()
2502 mLineEdit->setText( tr(
"%1 options selected" ).arg( mValue.count() ) );
2509 QgsProcessingEnumCheckboxPanelWidget::QgsProcessingEnumCheckboxPanelWidget( QWidget *parent,
const QgsProcessingParameterEnum *param,
int columns )
2512 , mButtonGroup( new QButtonGroup( this ) )
2513 , mColumns( columns )
2515 mButtonGroup->setExclusive( !mParam->allowMultiple() );
2517 QGridLayout *l =
new QGridLayout();
2518 l->setContentsMargins( 0, 0, 0, 0 );
2520 int rows =
static_cast< int >( std::ceil( mParam->options().count() /
static_cast< double >( mColumns ) ) );
2521 for (
int i = 0; i < mParam->options().count(); ++i )
2523 QAbstractButton *button =
nullptr;
2524 if ( mParam->allowMultiple() )
2525 button =
new QCheckBox( mParam->options().at( i ) );
2527 button =
new QRadioButton( mParam->options().at( i ) );
2529 connect( button, &QAbstractButton::toggled,
this, [ = ]
2531 if ( !mBlockChangedSignal )
2535 mButtons.insert( i, button );
2537 mButtonGroup->addButton( button, i );
2538 l->addWidget( button, i % rows, i / rows );
2540 l->addItem(
new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, mColumns );
2543 if ( mParam->allowMultiple() )
2545 setContextMenuPolicy( Qt::CustomContextMenu );
2546 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsProcessingEnumCheckboxPanelWidget::showPopupMenu );
2550 QVariant QgsProcessingEnumCheckboxPanelWidget::value()
const
2552 if ( mParam->allowMultiple() )
2555 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2557 if ( it.value()->isChecked() )
2558 value.append( mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key() );
2564 if ( mParam->usesStaticStrings() )
2565 return mButtonGroup->checkedId() >= 0 ? mParam->options().at( mButtonGroup->checkedId() ) : QVariant();
2567 return mButtonGroup->checkedId() >= 0 ? mButtonGroup->checkedId() : QVariant();
2571 void QgsProcessingEnumCheckboxPanelWidget::setValue(
const QVariant &value )
2573 mBlockChangedSignal =
true;
2574 if ( mParam->allowMultiple() )
2576 QVariantList selected;
2577 if ( value.isValid() )
2578 selected = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
2579 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2581 QVariant v = mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key();
2582 it.value()->setChecked( selected.contains( v ) );
2588 if ( v.type() == QVariant::List )
2589 v = v.toList().value( 0 );
2591 v = mParam->usesStaticStrings() ? mParam->options().indexOf( v.toString() ) : v;
2592 if ( mButtons.contains( v ) )
2593 mButtons.value( v )->setChecked(
true );
2595 mBlockChangedSignal =
false;
2599 void QgsProcessingEnumCheckboxPanelWidget::showPopupMenu()
2602 QAction *selectAllAction =
new QAction( tr(
"Select All" ), &popupMenu );
2603 connect( selectAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::selectAll );
2604 QAction *clearAllAction =
new QAction( tr(
"Clear Selection" ), &popupMenu );
2605 connect( clearAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::deselectAll );
2606 popupMenu.addAction( selectAllAction );
2607 popupMenu.addAction( clearAllAction );
2608 popupMenu.exec( QCursor::pos() );
2611 void QgsProcessingEnumCheckboxPanelWidget::selectAll()
2613 mBlockChangedSignal =
true;
2614 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2615 it.value()->setChecked(
true );
2616 mBlockChangedSignal =
false;
2620 void QgsProcessingEnumCheckboxPanelWidget::deselectAll()
2622 mBlockChangedSignal =
true;
2623 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2624 it.value()->setChecked(
false );
2625 mBlockChangedSignal =
false;
2637 QVBoxLayout *vlayout =
new QVBoxLayout();
2638 vlayout->setContentsMargins( 0, 0, 0, 0 );
2640 mEnumWidget =
new QgsProcessingEnumModelerWidget();
2643 mEnumWidget->setAllowMultiple( enumParam->allowMultiple() );
2644 mEnumWidget->setOptions( enumParam->options() );
2645 mEnumWidget->setDefaultOptions( enumParam->defaultValueForGui() );
2647 vlayout->addWidget( mEnumWidget );
2648 setLayout( vlayout );
2651 QgsProcessingParameterDefinition *QgsProcessingEnumParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
2653 auto param = std::make_unique< QgsProcessingParameterEnum >( name, description, mEnumWidget->options(), mEnumWidget->allowMultiple(), mEnumWidget->defaultOptions() );
2655 return param.release();
2665 QWidget *QgsProcessingEnumWidgetWrapper::createWidget()
2673 if ( expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"useCheckBoxes" ),
false ).toBool() )
2675 const int columns = expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"columns" ), 2 ).toInt();
2676 mCheckboxPanel =
new QgsProcessingEnumCheckboxPanelWidget(
nullptr, expParam, columns );
2677 mCheckboxPanel->setToolTip( parameterDefinition()->toolTip() );
2678 connect( mCheckboxPanel, &QgsProcessingEnumCheckboxPanelWidget::changed,
this, [ = ]
2680 emit widgetValueHasChanged(
this );
2682 return mCheckboxPanel;
2691 mPanel =
new QgsProcessingEnumPanelWidget(
nullptr, expParam );
2692 mPanel->setToolTip( parameterDefinition()->toolTip() );
2693 connect( mPanel, &QgsProcessingEnumPanelWidget::changed,
this, [ = ]
2695 emit widgetValueHasChanged(
this );
2701 mComboBox =
new QComboBox();
2704 mComboBox->addItem( tr(
"[Not selected]" ), QVariant() );
2705 const QStringList options = expParam->
options();
2706 for (
int i = 0; i < options.count(); ++i )
2709 mComboBox->addItem( options.at( i ), options.at( i ) );
2711 mComboBox->addItem( options.at( i ), i );
2714 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2715 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
2717 emit widgetValueHasChanged(
this );
2726 void QgsProcessingEnumWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2730 if ( !value.isValid() )
2731 mComboBox->setCurrentIndex( mComboBox->findData( QVariant() ) );
2738 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
2743 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
2747 else if ( mPanel || mCheckboxPanel )
2750 if ( value.isValid() )
2756 opts.reserve( v.size() );
2757 for ( QString i : v )
2763 opts.reserve( v.size() );
2769 mPanel->setValue( opts );
2770 else if ( mCheckboxPanel )
2771 mCheckboxPanel->setValue( opts );
2775 QVariant QgsProcessingEnumWidgetWrapper::widgetValue()
const
2778 return mComboBox->currentData();
2780 return mPanel->value();
2781 else if ( mCheckboxPanel )
2782 return mCheckboxPanel->value();
2787 QStringList QgsProcessingEnumWidgetWrapper::compatibleParameterTypes()
const
2789 return QStringList()
2795 QStringList QgsProcessingEnumWidgetWrapper::compatibleOutputTypes()
const
2797 return QStringList()
2802 QString QgsProcessingEnumWidgetWrapper::modelerExpressionFormatString()
const
2804 return tr(
"selected option index (starting from 0), array of indices, or comma separated string of options (e.g. '1,3')" );
2807 QString QgsProcessingEnumWidgetWrapper::parameterType()
const
2814 return new QgsProcessingEnumWidgetWrapper( parameter, type );
2819 return new QgsProcessingEnumParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2832 QWidget *QgsProcessingLayoutWidgetWrapper::createWidget()
2841 mComboBox =
new QgsLayoutComboBox(
nullptr, widgetContext().project() ? widgetContext().project()->layoutManager() :
nullptr );
2843 mComboBox->setAllowEmptyLayout(
true );
2846 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2849 emit widgetValueHasChanged(
this );
2856 mPlainComboBox =
new QComboBox();
2857 mPlainComboBox->setEditable(
true );
2858 mPlainComboBox->setToolTip( tr(
"Name of an existing print layout" ) );
2859 if ( widgetContext().project() )
2863 mPlainComboBox->addItem( layout->name() );
2866 connect( mPlainComboBox, &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
2868 emit widgetValueHasChanged(
this );
2870 return mPlainComboBox;
2876 void QgsProcessingLayoutWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2880 if ( !value.isValid() )
2881 mComboBox->setCurrentLayout(
nullptr );
2885 mComboBox->setCurrentLayout( l );
2887 mComboBox->setCurrentLayout(
nullptr );
2890 else if ( mPlainComboBox )
2893 mPlainComboBox->setCurrentText( v );
2897 QVariant QgsProcessingLayoutWidgetWrapper::widgetValue()
const
2902 return l ? l->
name() : QVariant();
2904 else if ( mPlainComboBox )
2905 return mPlainComboBox->currentText().isEmpty() ? QVariant() : mPlainComboBox->currentText();
2913 if ( mPlainComboBox && context.
project() )
2917 mPlainComboBox->addItem( layout->name() );
2921 QStringList QgsProcessingLayoutWidgetWrapper::compatibleParameterTypes()
const
2923 return QStringList()
2928 QStringList QgsProcessingLayoutWidgetWrapper::compatibleOutputTypes()
const
2930 return QStringList()
2934 QString QgsProcessingLayoutWidgetWrapper::modelerExpressionFormatString()
const
2936 return tr(
"string representing the name of an existing print layout" );
2939 QString QgsProcessingLayoutWidgetWrapper::parameterType()
const
2946 return new QgsProcessingLayoutWidgetWrapper( parameter, type );
2960 QVBoxLayout *vlayout =
new QVBoxLayout();
2961 vlayout->setContentsMargins( 0, 0, 0, 0 );
2963 vlayout->addWidget(
new QLabel( tr(
"Parent layout" ) ) );
2965 mParentLayoutComboBox =
new QComboBox();
2966 QString initialParent;
2968 initialParent = itemParam->parentLayoutParameterName();
2970 if (
auto *lModel = widgetContext.
model() )
2973 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
2974 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
2978 mParentLayoutComboBox-> addItem( definition->
description(), definition->
name() );
2979 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2981 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
2987 if ( mParentLayoutComboBox->count() == 0 && !initialParent.isEmpty() )
2990 mParentLayoutComboBox->addItem( initialParent, initialParent );
2991 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
2994 vlayout->addWidget( mParentLayoutComboBox );
2995 setLayout( vlayout );
2997 QgsProcessingParameterDefinition *QgsProcessingLayoutItemParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
2999 auto param = std::make_unique< QgsProcessingParameterLayoutItem >( name, description, QVariant(), mParentLayoutComboBox->currentData().toString() );
3001 return param.release();
3011 QWidget *QgsProcessingLayoutItemWidgetWrapper::createWidget()
3022 mComboBox->setAllowEmptyItem(
true );
3023 if ( layoutParam->
itemType() >= 0 )
3026 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3029 emit widgetValueHasChanged(
this );
3036 mLineEdit =
new QLineEdit();
3037 mLineEdit->setToolTip( tr(
"UUID or ID of an existing print layout item" ) );
3038 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
3040 emit widgetValueHasChanged(
this );
3048 void QgsProcessingLayoutItemWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3058 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterLayoutItem *
>( parameterDefinition() )->parentLayoutParameterName() )
3060 setLayoutParameterValue( wrapper->parameterValue() );
3063 setLayoutParameterValue( wrapper->parameterValue() );
3076 void QgsProcessingLayoutItemWidgetWrapper::setLayoutParameterValue(
const QVariant &value )
3082 std::unique_ptr< QgsProcessingContext > tmpContext;
3083 if ( mProcessingContextGenerator )
3084 context = mProcessingContextGenerator->processingContext();
3088 tmpContext = std::make_unique< QgsProcessingContext >();
3089 context = tmpContext.get();
3093 setLayout( layout );
3096 void QgsProcessingLayoutItemWidgetWrapper::setLayout(
QgsPrintLayout *layout )
3099 mComboBox->setCurrentLayout( layout );
3102 void QgsProcessingLayoutItemWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3106 if ( !value.isValid() )
3107 mComboBox->setItem(
nullptr );
3111 mComboBox->setItem( item );
3114 else if ( mLineEdit )
3117 mLineEdit->setText( v );
3121 QVariant QgsProcessingLayoutItemWidgetWrapper::widgetValue()
const
3126 return i ? i->
uuid() : QVariant();
3128 else if ( mLineEdit )
3129 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3134 QStringList QgsProcessingLayoutItemWidgetWrapper::compatibleParameterTypes()
const
3136 return QStringList()
3141 QStringList QgsProcessingLayoutItemWidgetWrapper::compatibleOutputTypes()
const
3143 return QStringList()
3147 QString QgsProcessingLayoutItemWidgetWrapper::modelerExpressionFormatString()
const
3149 return tr(
"string representing the UUID or ID of an existing print layout item" );
3152 QString QgsProcessingLayoutItemWidgetWrapper::parameterType()
const
3159 return new QgsProcessingLayoutItemWidgetWrapper( parameter, type );
3164 return new QgsProcessingLayoutItemParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3171 QgsProcessingPointMapTool::QgsProcessingPointMapTool(
QgsMapCanvas *canvas )
3178 QgsProcessingPointMapTool::~QgsProcessingPointMapTool() =
default;
3180 void QgsProcessingPointMapTool::deactivate()
3194 if ( e->button() == Qt::LeftButton )
3197 emit clicked( point );
3202 void QgsProcessingPointMapTool::keyPressEvent( QKeyEvent *e )
3204 if ( e->key() == Qt::Key_Escape )
3219 QgsProcessingPointPanel::QgsProcessingPointPanel( QWidget *parent )
3222 QHBoxLayout *l =
new QHBoxLayout();
3223 l->setContentsMargins( 0, 0, 0, 0 );
3225 mLineEdit->setShowClearButton(
false );
3226 l->addWidget( mLineEdit, 1 );
3227 mButton =
new QToolButton();
3228 mButton->setText( QString( QChar( 0x2026 ) ) );
3229 l->addWidget( mButton );
3232 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::changed );
3233 connect( mButton, &QToolButton::clicked,
this, &QgsProcessingPointPanel::selectOnCanvas );
3234 mButton->setVisible(
false );
3237 void QgsProcessingPointPanel::setMapCanvas(
QgsMapCanvas *canvas )
3240 mButton->setVisible(
true );
3243 mTool = std::make_unique< QgsProcessingPointMapTool >( mCanvas );
3244 connect( mTool.get(), &QgsProcessingPointMapTool::clicked,
this, &QgsProcessingPointPanel::updatePoint );
3245 connect( mTool.get(), &QgsProcessingPointMapTool::complete,
this, &QgsProcessingPointPanel::pointPicked );
3248 void QgsProcessingPointPanel::setAllowNull(
bool allowNull )
3250 mLineEdit->setShowClearButton( allowNull );
3253 QVariant QgsProcessingPointPanel::value()
const
3255 return mLineEdit->showClearButton() && mLineEdit->text().trimmed().isEmpty() ? QVariant() : QVariant( mLineEdit->text() );
3258 void QgsProcessingPointPanel::clear()
3265 QString newText = QStringLiteral(
"%1,%2" )
3266 .arg( QString::number( point.
x(),
'f' ),
3267 QString::number( point.
y(),
'f' ) );
3270 if ( mCrs.isValid() )
3272 newText += QStringLiteral(
" [%1]" ).arg( mCrs.authid() );
3274 mLineEdit->setText( newText );
3277 void QgsProcessingPointPanel::selectOnCanvas()
3282 mPrevTool = mCanvas->mapTool();
3283 mCanvas->setMapTool( mTool.get() );
3285 emit toggleDialogVisibility(
false );
3288 void QgsProcessingPointPanel::updatePoint(
const QgsPointXY &point )
3290 setValue( point, mCanvas->mapSettings().destinationCrs() );
3293 void QgsProcessingPointPanel::pointPicked()
3298 mCanvas->setMapTool( mPrevTool );
3300 emit toggleDialogVisibility(
true );
3312 QVBoxLayout *vlayout =
new QVBoxLayout();
3313 vlayout->setContentsMargins( 0, 0, 0, 0 );
3315 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3317 mDefaultLineEdit =
new QLineEdit();
3318 mDefaultLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
3319 mDefaultLineEdit->setPlaceholderText( tr(
"Point as 'x,y'" ) );
3323 mDefaultLineEdit->setText( QStringLiteral(
"%1,%2" ).arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) ) );
3326 vlayout->addWidget( mDefaultLineEdit );
3327 setLayout( vlayout );
3330 QgsProcessingParameterDefinition *QgsProcessingPointParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3332 auto param = std::make_unique< QgsProcessingParameterPoint >( name, description, mDefaultLineEdit->text() );
3334 return param.release();
3343 QWidget *QgsProcessingPointWidgetWrapper::createWidget()
3351 mPanel =
new QgsProcessingPointPanel(
nullptr );
3352 if ( widgetContext().mapCanvas() )
3353 mPanel->setMapCanvas( widgetContext().mapCanvas() );
3356 mPanel->setAllowNull(
true );
3358 mPanel->setToolTip( parameterDefinition()->toolTip() );
3360 connect( mPanel, &QgsProcessingPointPanel::changed,
this, [ = ]
3362 emit widgetValueHasChanged(
this );
3366 setDialog( mDialog );
3372 mLineEdit =
new QLineEdit();
3373 mLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
3374 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
3376 emit widgetValueHasChanged(
this );
3388 mPanel->setMapCanvas( context.
mapCanvas() );
3391 void QgsProcessingPointWidgetWrapper::setDialog( QDialog *dialog )
3396 connect( mPanel, &QgsProcessingPointPanel::toggleDialogVisibility, mDialog, [ = ](
bool visible )
3399 mDialog->showMinimized();
3402 mDialog->showNormal();
3404 mDialog->activateWindow();
3411 void QgsProcessingPointWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3415 if ( !value.isValid() || ( value.type() == QVariant::String && value.toString().isEmpty() ) )
3421 mPanel->setValue( p,
crs );
3424 else if ( mLineEdit )
3427 mLineEdit->setText( v );
3431 QVariant QgsProcessingPointWidgetWrapper::widgetValue()
const
3435 return mPanel->value();
3437 else if ( mLineEdit )
3438 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3443 QStringList QgsProcessingPointWidgetWrapper::compatibleParameterTypes()
const
3445 return QStringList()
3450 QStringList QgsProcessingPointWidgetWrapper::compatibleOutputTypes()
const
3452 return QStringList()
3456 QString QgsProcessingPointWidgetWrapper::modelerExpressionFormatString()
const
3458 return tr(
"string of the format 'x,y' or a geometry value (centroid is used)" );
3461 QString QgsProcessingPointWidgetWrapper::parameterType()
const
3468 return new QgsProcessingPointWidgetWrapper( parameter, type );
3473 return new QgsProcessingPointParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3485 QVBoxLayout *vlayout =
new QVBoxLayout();
3486 vlayout->setContentsMargins( 0, 0, 0, 0 );
3488 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3490 mDefaultLineEdit =
new QLineEdit();
3491 mDefaultLineEdit->setToolTip( tr(
"Geometry as WKT" ) );
3492 mDefaultLineEdit->setPlaceholderText( tr(
"Geometry as WKT" ) );
3497 mDefaultLineEdit->setText( g.
asWkt() );
3500 vlayout->addWidget( mDefaultLineEdit );
3501 setLayout( vlayout );
3504 QgsProcessingParameterDefinition *QgsProcessingGeometryParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3506 auto param = std::make_unique< QgsProcessingParameterGeometry >( name, description, mDefaultLineEdit->text() );
3508 return param.release();
3517 QWidget *QgsProcessingGeometryWidgetWrapper::createWidget()
3525 mLineEdit =
new QLineEdit();
3526 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
3527 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
3529 emit widgetValueHasChanged(
this );
3537 void QgsProcessingGeometryWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3543 mLineEdit->setText( g.
asWkt() );
3549 QVariant QgsProcessingGeometryWidgetWrapper::widgetValue()
const
3552 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3557 QStringList QgsProcessingGeometryWidgetWrapper::compatibleParameterTypes()
const
3559 return QStringList()
3566 QStringList QgsProcessingGeometryWidgetWrapper::compatibleOutputTypes()
const
3568 return QStringList()
3572 QString QgsProcessingGeometryWidgetWrapper::modelerExpressionFormatString()
const
3574 return tr(
"string in the Well-Known-Text format or a geometry value" );
3577 QString QgsProcessingGeometryWidgetWrapper::parameterType()
const
3584 return new QgsProcessingGeometryWidgetWrapper( parameter, type );
3589 return new QgsProcessingGeometryParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3601 QVBoxLayout *vlayout =
new QVBoxLayout();
3602 vlayout->setContentsMargins( 0, 0, 0, 0 );
3604 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3607 mDefaultColorButton->setShowNull(
true );
3608 mAllowOpacity =
new QCheckBox( tr(
"Allow opacity control" ) );
3614 mDefaultColorButton->setToNull();
3616 mDefaultColorButton->setColor(
c );
3617 mAllowOpacity->setChecked( colorParam->opacityEnabled() );
3621 mDefaultColorButton->setToNull();
3622 mAllowOpacity->setChecked(
true );
3625 vlayout->addWidget( mDefaultColorButton );
3626 vlayout->addWidget( mAllowOpacity );
3627 setLayout( vlayout );
3630 QgsProcessingParameterDefinition *QgsProcessingColorParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3632 auto param = std::make_unique< QgsProcessingParameterColor >( name, description, mDefaultColorButton->color(), mAllowOpacity->isChecked() );
3634 return param.release();
3643 QWidget *QgsProcessingColorWidgetWrapper::createWidget()
3653 mColorButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
3656 mColorButton->setShowNull(
true );
3659 mColorButton->setToolTip( parameterDefinition()->toolTip() );
3660 mColorButton->setColorDialogTitle( parameterDefinition()->description() );
3668 emit widgetValueHasChanged(
this );
3671 return mColorButton;
3677 void QgsProcessingColorWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3681 if ( !value.isValid() ||
3682 ( value.type() == QVariant::String && value.toString().isEmpty() )
3683 || ( value.type() == QVariant::Color && !value.value< QColor >().isValid() ) )
3684 mColorButton->setToNull();
3688 if ( !
c.isValid() && mColorButton->showNull() )
3689 mColorButton->setToNull();
3691 mColorButton->setColor(
c );
3696 QVariant QgsProcessingColorWidgetWrapper::widgetValue()
const
3699 return mColorButton->isNull() ? QVariant() : mColorButton->color();
3704 QStringList QgsProcessingColorWidgetWrapper::compatibleParameterTypes()
const
3706 return QStringList()
3711 QStringList QgsProcessingColorWidgetWrapper::compatibleOutputTypes()
const
3713 return QStringList()
3717 QString QgsProcessingColorWidgetWrapper::modelerExpressionFormatString()
const
3719 return tr(
"color style string, e.g. #ff0000 or 255,0,0" );
3722 QString QgsProcessingColorWidgetWrapper::parameterType()
const
3729 return new QgsProcessingColorWidgetWrapper( parameter, type );
3734 return new QgsProcessingColorParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3745 QVBoxLayout *vlayout =
new QVBoxLayout();
3746 vlayout->setContentsMargins( 0, 0, 0, 0 );
3748 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3750 mDefaultLineEdit =
new QLineEdit();
3753 vlayout->addWidget( mDefaultLineEdit );
3755 mSourceParamComboBox =
new QComboBox();
3756 mDestParamComboBox =
new QComboBox();
3757 QString initialSource;
3758 QString initialDest;
3763 initialSource = itemParam->sourceCrsParameterName();
3764 initialDest = itemParam->destinationCrsParameterName();
3769 mSourceParamComboBox->addItem( QString(), QString() );
3770 mDestParamComboBox->addItem( QString(), QString() );
3771 if (
auto *lModel = widgetContext.
model() )
3774 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3775 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3777 if ( definition && it->parameterName() == definition->
name() )
3781 mSourceParamComboBox->addItem( it->parameterName(), it->parameterName() );
3782 mDestParamComboBox->addItem( it->parameterName(), it->parameterName() );
3783 if ( !initialSource.isEmpty() && initialSource == it->parameterName() )
3785 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
3787 if ( !initialDest.isEmpty() && initialDest == it->parameterName() )
3789 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
3794 if ( mSourceParamComboBox->count() == 1 && !initialSource.isEmpty() )
3797 mSourceParamComboBox->addItem( initialSource, initialSource );
3798 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
3800 if ( mDestParamComboBox->count() == 1 && !initialDest.isEmpty() )
3803 mDestParamComboBox->addItem( initialDest, initialDest );
3804 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
3807 vlayout->addWidget(
new QLabel( tr(
"Source CRS parameter" ) ) );
3808 vlayout->addWidget( mSourceParamComboBox );
3809 vlayout->addWidget(
new QLabel( tr(
"Destination CRS parameter" ) ) );
3810 vlayout->addWidget( mDestParamComboBox );
3814 mStaticSourceWidget->setCrs( sourceCrs );
3817 mStaticDestWidget->setCrs( destCrs );
3819 vlayout->addWidget(
new QLabel( tr(
"Static source CRS" ) ) );
3820 vlayout->addWidget( mStaticSourceWidget );
3821 vlayout->addWidget(
new QLabel( tr(
"Static destination CRS" ) ) );
3822 vlayout->addWidget( mStaticDestWidget );
3824 setLayout( vlayout );
3827 QgsProcessingParameterDefinition *QgsProcessingCoordinateOperationParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3829 auto param = std::make_unique< QgsProcessingParameterCoordinateOperation >( name, description, mDefaultLineEdit->text(),
3830 mSourceParamComboBox->currentText(),
3831 mDestParamComboBox->currentText(),
3832 mStaticSourceWidget->crs().isValid() ? QVariant::fromValue( mStaticSourceWidget->crs() ) : QVariant(),
3833 mStaticDestWidget->crs().isValid() ? QVariant::fromValue( mStaticDestWidget->crs() ) : QVariant() );
3835 return param.release();
3844 QWidget *QgsProcessingCoordinateOperationWidgetWrapper::createWidget()
3855 mOperationWidget->setShowMakeDefault(
false );
3856 mOperationWidget->setShowFallbackOption(
false );
3857 mOperationWidget->setToolTip( parameterDefinition()->toolTip() );
3858 mOperationWidget->setSourceCrs( mSourceCrs );
3859 mOperationWidget->setDestinationCrs( mDestCrs );
3860 mOperationWidget->setMapCanvas( mCanvas );
3865 mOperationWidget->setSelectedOperation( deets );
3870 emit widgetValueHasChanged(
this );
3873 return mOperationWidget;
3879 mLineEdit =
new QLineEdit();
3880 QHBoxLayout *layout =
new QHBoxLayout();
3881 layout->addWidget( mLineEdit, 1 );
3882 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
3884 emit widgetValueHasChanged(
this );
3887 QToolButton *button =
new QToolButton();
3888 button->setText( QString( QChar( 0x2026 ) ) );
3889 connect( button, &QToolButton::clicked,
this, [ = ]
3891 QgsDatumTransformDialog dlg( mSourceCrs, mDestCrs,
false,
false,
false, qMakePair( -1, -1 ), button, Qt::WindowFlags(), mLineEdit->text(), mCanvas );
3894 mLineEdit->setText( dlg.selectedDatumTransform().proj );
3895 emit widgetValueHasChanged(
this );
3898 layout->addWidget( button );
3900 QWidget *w =
new QWidget();
3901 layout->setContentsMargins( 0, 0, 0, 0 );
3902 w->setLayout( layout );
3910 void QgsProcessingCoordinateOperationWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3922 setSourceCrsParameterValue( wrapper->parameterValue() );
3925 setSourceCrsParameterValue( wrapper->parameterValue() );
3930 setDestinationCrsParameterValue( wrapper->parameterValue() );
3933 setDestinationCrsParameterValue( wrapper->parameterValue() );
3948 if ( mOperationWidget )
3949 mOperationWidget->setMapCanvas( context.
mapCanvas() );
3952 void QgsProcessingCoordinateOperationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
3954 if ( mOperationWidget )
3956 if ( !value.isValid() ||
3957 ( value.type() == QVariant::String ) )
3960 deets.
proj = value.toString();
3961 mOperationWidget->setSelectedOperation( deets );
3966 if ( !value.isValid() ||
3967 ( value.type() == QVariant::String ) )
3969 mLineEdit->setText( value.toString() );
3974 QVariant QgsProcessingCoordinateOperationWidgetWrapper::widgetValue()
const
3976 if ( mOperationWidget )
3977 return mOperationWidget->selectedOperation().proj;
3978 else if ( mLineEdit )
3979 return mLineEdit->text();
3984 QStringList QgsProcessingCoordinateOperationWidgetWrapper::compatibleParameterTypes()
const
3986 return QStringList()
3991 QStringList QgsProcessingCoordinateOperationWidgetWrapper::compatibleOutputTypes()
const
3993 return QStringList()
3997 QString QgsProcessingCoordinateOperationWidgetWrapper::modelerExpressionFormatString()
const
3999 return tr(
"Proj coordinate operation string, e.g. '+proj=pipeline +step +inv...'" );
4002 void QgsProcessingCoordinateOperationWidgetWrapper::setSourceCrsParameterValue(
const QVariant &value )
4005 std::unique_ptr< QgsProcessingContext > tmpContext;
4006 if ( mProcessingContextGenerator )
4007 context = mProcessingContextGenerator->processingContext();
4011 tmpContext = std::make_unique< QgsProcessingContext >();
4012 context = tmpContext.get();
4016 if ( mOperationWidget )
4018 mOperationWidget->setSourceCrs( mSourceCrs );
4019 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4023 void QgsProcessingCoordinateOperationWidgetWrapper::setDestinationCrsParameterValue(
const QVariant &value )
4026 std::unique_ptr< QgsProcessingContext > tmpContext;
4027 if ( mProcessingContextGenerator )
4028 context = mProcessingContextGenerator->processingContext();
4032 tmpContext = std::make_unique< QgsProcessingContext >();
4033 context = tmpContext.get();
4037 if ( mOperationWidget )
4039 mOperationWidget->setDestinationCrs( mDestCrs );
4040 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4044 QString QgsProcessingCoordinateOperationWidgetWrapper::parameterType()
const
4051 return new QgsProcessingCoordinateOperationWidgetWrapper( parameter, type );
4056 return new QgsProcessingCoordinateOperationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4069 QHBoxLayout *hl =
new QHBoxLayout();
4070 hl->setContentsMargins( 0, 0, 0, 0 );
4072 mLineEdit =
new QLineEdit();
4073 mLineEdit->setEnabled(
false );
4074 hl->addWidget( mLineEdit, 1 );
4076 mToolButton =
new QToolButton();
4077 mToolButton->setText( QString( QChar( 0x2026 ) ) );
4078 hl->addWidget( mToolButton );
4084 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
4087 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingFieldPanelWidget::showDialog );
4090 void QgsProcessingFieldPanelWidget::setFields(
const QgsFields &fields )
4095 void QgsProcessingFieldPanelWidget::setValue(
const QVariant &value )
4097 if ( value.isValid() )
4098 mValue = value.type() == QVariant::List ? value.
toList() : QVariantList() << value;
4102 updateSummaryText();
4106 void QgsProcessingFieldPanelWidget::showDialog()
4108 QVariantList availableOptions;
4109 QStringList fieldNames;
4110 availableOptions.reserve( mFields.size() );
4119 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
4120 widget->setPanelTitle( mParam->description() );
4122 widget->setValueFormatter( [](
const QVariant & v ) -> QString
4124 return v.toString();
4127 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
4129 setValue( widget->selectedOptions() );
4136 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
4138 dlg.setValueFormatter( [](
const QVariant & v ) -> QString
4140 return v.toString();
4144 setValue( dlg.selectedOptions() );
4149 void QgsProcessingFieldPanelWidget::updateSummaryText()
4152 mLineEdit->setText( tr(
"%1 options selected" ).arg( mValue.count() ) );
4163 QVBoxLayout *vlayout =
new QVBoxLayout();
4164 vlayout->setContentsMargins( 0, 0, 0, 0 );
4166 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
4167 mParentLayerComboBox =
new QComboBox();
4169 QString initialParent;
4171 initialParent = fieldParam->parentLayerParameterName();
4173 if (
auto *lModel = widgetContext.
model() )
4176 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4177 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4181 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
4182 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4184 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4189 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
4190 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4192 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4199 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
4200 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4202 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4209 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
4212 mParentLayerComboBox->addItem( initialParent, initialParent );
4213 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4216 vlayout->addWidget( mParentLayerComboBox );
4218 vlayout->addWidget(
new QLabel( tr(
"Allowed data type" ) ) );
4219 mDataTypeComboBox =
new QComboBox();
4225 mDataTypeComboBox->setCurrentIndex( mDataTypeComboBox->findData( fieldParam->dataType() ) );
4227 vlayout->addWidget( mDataTypeComboBox );
4229 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple fields" ) );
4231 mAllowMultipleCheckBox->setChecked( fieldParam->allowMultiple() );
4233 vlayout->addWidget( mAllowMultipleCheckBox );
4235 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all fields by default" ) );
4236 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
4238 mDefaultToAllCheckBox->setChecked( fieldParam->defaultToAllFields() );
4240 vlayout->addWidget( mDefaultToAllCheckBox );
4242 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [ = ]
4244 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
4247 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4249 mDefaultLineEdit =
new QLineEdit();
4250 mDefaultLineEdit->setToolTip( tr(
"Default field name, or ; separated list of field names for multiple field parameters" ) );
4254 mDefaultLineEdit->setText( fields.join(
';' ) );
4256 vlayout->addWidget( mDefaultLineEdit );
4258 setLayout( vlayout );
4261 QgsProcessingParameterDefinition *QgsProcessingFieldParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4265 QVariant defaultValue;
4266 if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
4268 defaultValue = mDefaultLineEdit->text();
4270 auto param = std::make_unique< QgsProcessingParameterField >( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), dataType, mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
4272 return param.release();
4281 QWidget *QgsProcessingFieldWidgetWrapper::createWidget()
4291 mPanel =
new QgsProcessingFieldPanelWidget(
nullptr, fieldParam );
4292 mPanel->setToolTip( parameterDefinition()->toolTip() );
4293 connect( mPanel, &QgsProcessingFieldPanelWidget::changed,
this, [ = ]
4295 emit widgetValueHasChanged(
this );
4311 mComboBox->setToolTip( parameterDefinition()->toolTip() );
4314 emit widgetValueHasChanged(
this );
4322 mLineEdit =
new QLineEdit();
4323 mLineEdit->setToolTip( QObject::tr(
"Name of field (separate field names with ; for multiple field parameters)" ) );
4324 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
4326 emit widgetValueHasChanged(
this );
4335 void QgsProcessingFieldWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
4345 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterField *
>( parameterDefinition() )->parentLayerParameterName() )
4347 setParentLayerWrapperValue( wrapper );
4350 setParentLayerWrapperValue( wrapper );
4367 std::unique_ptr< QgsProcessingContext > tmpContext;
4368 if ( mProcessingContextGenerator )
4369 context = mProcessingContextGenerator->processingContext();
4373 tmpContext = std::make_unique< QgsProcessingContext >();
4374 context = tmpContext.get();
4389 bool valueSet =
false;
4393 if ( layers.count() > 1 )
4395 QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( layers.at( 0 ) );
4397 const QList< QgsMapLayer * > remainingLayers = layers.mid( 1 );
4403 QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( layer );
4404 if ( !vlayer || !vlayer->
isValid() )
4410 for (
int fieldIdx = fields.
count() - 1; fieldIdx >= 0; fieldIdx-- )
4413 fields.
remove( fieldIdx );
4418 mComboBox->setFields( fields );
4420 mPanel->setFields( filterFields( fields ) );
4426 if ( !valueSet && !layers.isEmpty() && layers.at( 0 )->isValid() )
4428 QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( layers.at( 0 ) );
4432 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
4435 mParentLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
4436 layer = mParentLayer.get();
4444 mComboBox->setLayer( layer );
4446 mPanel->setFields( filterFields( layer->
fields() ) );
4456 const QgsFields fields = source->fields();
4458 mComboBox->setFields( fields );
4460 mPanel->setFields( filterFields( fields ) );
4469 mComboBox->setLayer(
nullptr );
4473 if ( value.isValid() && widgetContext().messageBar() )
4476 widgetContext().
messageBar()->
pushMessage( QString(), QObject::tr(
"Could not load selected layer/table. Dependent field could not be populated" ),
4477 Qgis::MessageLevel::Info );
4486 val.reserve( mPanel->fields().size() );
4489 setWidgetValue( val, *context );
4492 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
4495 void QgsProcessingFieldWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4499 if ( !value.isValid() )
4500 mComboBox->setField( QString() );
4504 mComboBox->setField( v );
4510 if ( value.isValid() )
4513 opts.reserve( v.size() );
4514 for (
const QString &i : v )
4518 mPanel->setValue( opts );
4520 else if ( mLineEdit )
4526 mLineEdit->setText( v.join(
';' ) );
4535 QVariant QgsProcessingFieldWidgetWrapper::widgetValue()
const
4538 return mComboBox->currentField();
4540 return mPanel->value();
4541 else if ( mLineEdit )
4546 return mLineEdit->text().split(
';' );
4549 return mLineEdit->text();
4555 QStringList QgsProcessingFieldWidgetWrapper::compatibleParameterTypes()
const
4557 return QStringList()
4562 QStringList QgsProcessingFieldWidgetWrapper::compatibleOutputTypes()
const
4564 return QStringList()
4568 QString QgsProcessingFieldWidgetWrapper::modelerExpressionFormatString()
const
4570 return tr(
"selected field names as an array of names, or semicolon separated string of options (e.g. 'fid;place_name')" );
4573 const QgsVectorLayer *QgsProcessingFieldWidgetWrapper::linkedVectorLayer()
const
4575 if ( mComboBox && mComboBox->layer() )
4576 return mComboBox->layer();
4581 QgsFields QgsProcessingFieldWidgetWrapper::filterFields(
const QgsFields &fields )
const
4594 if ( f.isNumeric() )
4599 if ( f.type() == QVariant::String )
4604 if ( f.type() == QVariant::Date || f.type() == QVariant::Time || f.type() == QVariant::DateTime )
4613 QString QgsProcessingFieldWidgetWrapper::parameterType()
const
4620 return new QgsProcessingFieldWidgetWrapper( parameter, type );
4625 return new QgsProcessingFieldParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4636 QVBoxLayout *vlayout =
new QVBoxLayout();
4637 vlayout->setContentsMargins( 0, 0, 0, 0 );
4639 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4641 mDefaultComboBox =
new QComboBox();
4642 mDefaultComboBox->addItem( QString(), QVariant( -1 ) );
4645 for (
const QString &theme : mapThemes )
4649 mDefaultComboBox->setEditable(
true );
4653 if ( themeParam->defaultValueForGui().isValid() )
4656 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
4659 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
4661 vlayout->addWidget( mDefaultComboBox );
4663 setLayout( vlayout );
4666 QgsProcessingParameterDefinition *QgsProcessingMapThemeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4668 QVariant defaultVal;
4669 if ( mDefaultComboBox->currentText().isEmpty() )
4670 defaultVal = QVariant();
4672 defaultVal = mDefaultComboBox->currentText();
4673 auto param = std::make_unique< QgsProcessingParameterMapTheme>( name, description, defaultVal );
4675 return param.release();
4685 QWidget *QgsProcessingMapThemeWidgetWrapper::createWidget()
4689 mComboBox =
new QComboBox();
4692 mComboBox->addItem( tr(
"[Not selected]" ), QVariant( -1 ) );
4695 for (
const QString &theme : mapThemes )
4707 mComboBox->setEditable(
true );
4711 mComboBox->setToolTip( parameterDefinition()->toolTip() );
4712 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
4714 emit widgetValueHasChanged(
this );
4720 void QgsProcessingMapThemeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4724 if ( !value.isValid() )
4725 mComboBox->setCurrentIndex( mComboBox->findData( QVariant( -1 ) ) );
4728 if ( mComboBox->isEditable() && mComboBox->findData( v ) == -1 )
4730 const QString prev = mComboBox->currentText();
4731 mComboBox->setCurrentText( v );
4733 emit widgetValueHasChanged(
this );
4736 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
4740 QVariant QgsProcessingMapThemeWidgetWrapper::widgetValue()
const
4743 return mComboBox->currentData().toInt() == -1 ? QVariant() :
4744 !mComboBox->currentData().isValid() && mComboBox->isEditable() ? mComboBox->currentText().isEmpty() ? QVariant() : QVariant( mComboBox->currentText() )
4745 : mComboBox->currentData();
4750 QStringList QgsProcessingMapThemeWidgetWrapper::compatibleParameterTypes()
const
4752 return QStringList()
4757 QStringList QgsProcessingMapThemeWidgetWrapper::compatibleOutputTypes()
const
4759 return QStringList()
4763 QString QgsProcessingMapThemeWidgetWrapper::modelerExpressionFormatString()
const
4765 return tr(
"map theme as a string value (e.g. 'base maps')" );
4768 QString QgsProcessingMapThemeWidgetWrapper::parameterType()
const
4775 return new QgsProcessingMapThemeWidgetWrapper( parameter, type );
4780 return new QgsProcessingMapThemeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4793 QVBoxLayout *vlayout =
new QVBoxLayout();
4794 vlayout->setContentsMargins( 0, 0, 0, 0 );
4796 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
4798 mTypeComboBox =
new QComboBox();
4803 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( datetimeParam->dataType() ) );
4805 mTypeComboBox->setCurrentIndex( 0 );
4806 vlayout->addWidget( mTypeComboBox );
4808 setLayout( vlayout );
4811 QgsProcessingParameterDefinition *QgsProcessingDateTimeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4813 auto param = std::make_unique< QgsProcessingParameterDateTime >( name, description );
4816 return param.release();
4826 QWidget *QgsProcessingDateTimeWidgetWrapper::createWidget()
4831 switch ( dateTimeParam->
dataType() )
4835 widget = mDateTimeEdit;
4858 widget->setToolTip( parameterDefinition()->toolTip() );
4860 if ( mDateTimeEdit )
4864 emit widgetValueHasChanged(
this );
4867 else if ( mDateEdit )
4871 emit widgetValueHasChanged(
this );
4874 else if ( mTimeEdit )
4878 emit widgetValueHasChanged(
this );
4887 return new QgsProcessingDateTimeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4890 void QgsProcessingDateTimeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4892 if ( mDateTimeEdit )
4896 else if ( mDateEdit )
4900 else if ( mTimeEdit )
4906 QVariant QgsProcessingDateTimeWidgetWrapper::widgetValue()
const
4908 if ( mDateTimeEdit )
4909 return !mDateTimeEdit->dateTime().isNull() && mDateTimeEdit->dateTime().isValid() ? QVariant( mDateTimeEdit->dateTime() ) : QVariant();
4910 else if ( mDateEdit )
4911 return !mDateEdit->date().isNull() && mDateEdit->date().isValid() ? QVariant( mDateEdit->date() ) : QVariant();
4912 else if ( mTimeEdit )
4913 return !mTimeEdit->time().isNull() && mTimeEdit->time().isValid() ? QVariant( mTimeEdit->time() ) : QVariant();
4918 QStringList QgsProcessingDateTimeWidgetWrapper::compatibleParameterTypes()
const
4920 return QStringList()
4925 QStringList QgsProcessingDateTimeWidgetWrapper::compatibleOutputTypes()
const
4927 return QStringList()
4931 QString QgsProcessingDateTimeWidgetWrapper::modelerExpressionFormatString()
const
4934 if ( dateTimeParam )
4936 switch ( dateTimeParam->
dataType() )
4939 return tr(
"datetime value, or a ISO string representation of a datetime" );
4942 return tr(
"date value, or a ISO string representation of a date" );
4945 return tr(
"time value, or a ISO string representation of a time" );
4951 QString QgsProcessingDateTimeWidgetWrapper::parameterType()
const
4958 return new QgsProcessingDateTimeWidgetWrapper( parameter, type );
4972 QVBoxLayout *vlayout =
new QVBoxLayout();
4973 vlayout->setContentsMargins( 0, 0, 0, 0 );
4975 vlayout->addWidget(
new QLabel( tr(
"Provider" ) ) );
4976 mProviderComboBox =
new QComboBox();
4977 mProviderComboBox->addItem( QObject::tr(
"Postgres" ), QStringLiteral(
"postgres" ) );
4978 mProviderComboBox->addItem( QObject::tr(
"GeoPackage" ), QStringLiteral(
"ogr" ) );
4979 mProviderComboBox->addItem( QObject::tr(
"Spatialite" ), QStringLiteral(
"spatialite" ) );
4981 vlayout->addWidget( mProviderComboBox );
4983 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4985 mDefaultEdit =
new QLineEdit();
4986 vlayout->addWidget( mDefaultEdit );
4987 setLayout( vlayout );
4989 if ( connectionParam )
4991 mProviderComboBox->setCurrentIndex( mProviderComboBox->findData( connectionParam->
providerId() ) );
4996 QgsProcessingParameterDefinition *QgsProcessingProviderConnectionParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4998 QVariant defaultVal;
4999 if ( mDefaultEdit->text().isEmpty() )
5000 defaultVal = QVariant();
5002 defaultVal = mDefaultEdit->text();
5003 auto param = std::make_unique< QgsProcessingParameterProviderConnection>( name, description, mProviderComboBox->currentData().toString(), defaultVal );
5005 return param.release();
5015 QWidget *QgsProcessingProviderConnectionWidgetWrapper::createWidget()
5021 mProviderComboBox->setAllowEmptyConnection(
true );
5029 mProviderComboBox->setEditable(
true );
5033 mProviderComboBox->setToolTip( parameterDefinition()->toolTip() );
5034 connect( mProviderComboBox, &QgsProviderConnectionComboBox::currentTextChanged,
this, [ = ](
const QString & )
5036 if ( mBlockSignals )
5039 emit widgetValueHasChanged(
this );
5042 return mProviderComboBox;
5047 return new QgsProcessingProviderConnectionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5050 void QgsProcessingProviderConnectionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5054 if ( !value.isValid() )
5055 mProviderComboBox->setCurrentIndex( -1 );
5058 if ( mProviderComboBox->isEditable() )
5060 const QString prev = mProviderComboBox->currentText();
5062 mProviderComboBox->setConnection( v );
5063 mProviderComboBox->setCurrentText( v );
5067 emit widgetValueHasChanged(
this );
5070 mProviderComboBox->setConnection( v );
5074 QVariant QgsProcessingProviderConnectionWidgetWrapper::widgetValue()
const
5076 if ( mProviderComboBox )
5077 if ( mProviderComboBox->isEditable() )
5078 return mProviderComboBox->currentText().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentText() );
5080 return mProviderComboBox->currentConnection().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentConnection() );
5085 QStringList QgsProcessingProviderConnectionWidgetWrapper::compatibleParameterTypes()
const
5087 return QStringList()
5093 QStringList QgsProcessingProviderConnectionWidgetWrapper::compatibleOutputTypes()
const
5095 return QStringList()
5099 QString QgsProcessingProviderConnectionWidgetWrapper::modelerExpressionFormatString()
const
5101 return tr(
"connection name as a string value" );
5104 QString QgsProcessingProviderConnectionWidgetWrapper::parameterType()
const
5111 return new QgsProcessingProviderConnectionWidgetWrapper( parameter, type );
5126 QVBoxLayout *vlayout =
new QVBoxLayout();
5127 vlayout->setContentsMargins( 0, 0, 0, 0 );
5129 mConnectionParamComboBox =
new QComboBox();
5130 QString initialConnection;
5136 if (
auto *lModel = widgetContext.
model() )
5139 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
5140 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
5142 if ( definition && it->parameterName() == definition->
name() )
5148 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
5149 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5151 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5156 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
5159 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
5160 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5163 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
5164 vlayout->addWidget( mConnectionParamComboBox );
5166 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5168 mDefaultEdit =
new QLineEdit();
5169 vlayout->addWidget( mDefaultEdit );
5170 setLayout( vlayout );
5178 QgsProcessingParameterDefinition *QgsProcessingDatabaseSchemaParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5180 QVariant defaultVal;
5181 if ( mDefaultEdit->text().isEmpty() )
5182 defaultVal = QVariant();
5184 defaultVal = mDefaultEdit->text();
5185 auto param = std::make_unique< QgsProcessingParameterDatabaseSchema>( name, description, mConnectionParamComboBox->currentData().toString(), defaultVal );
5187 return param.release();
5197 QWidget *QgsProcessingDatabaseSchemaWidgetWrapper::createWidget()
5203 mSchemaComboBox->setAllowEmptySchema(
true );
5211 mSchemaComboBox->comboBox()->setEditable(
true );
5215 mSchemaComboBox->setToolTip( parameterDefinition()->toolTip() );
5216 connect( mSchemaComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
5218 if ( mBlockSignals )
5221 emit widgetValueHasChanged( this );
5224 return mSchemaComboBox;
5229 return new QgsProcessingDatabaseSchemaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5236 std::unique_ptr< QgsProcessingContext > tmpContext;
5237 if ( mProcessingContextGenerator )
5238 context = mProcessingContextGenerator->processingContext();
5242 tmpContext = std::make_unique< QgsProcessingContext >();
5243 context = tmpContext.get();
5249 if ( mSchemaComboBox )
5250 mSchemaComboBox->setConnectionName( connection, qgis::down_cast< const QgsProcessingParameterProviderConnection * >( parentWrapper->
parameterDefinition() )->providerId() );
5254 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5257 void QgsProcessingDatabaseSchemaWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5261 if ( !value.isValid() )
5262 mSchemaComboBox->comboBox()->setCurrentIndex( -1 );
5265 if ( mSchemaComboBox->comboBox()->isEditable() )
5267 const QString prev = mSchemaComboBox->comboBox()->currentText();
5269 mSchemaComboBox->setSchema( v );
5270 mSchemaComboBox->comboBox()->setCurrentText( v );
5274 emit widgetValueHasChanged(
this );
5277 mSchemaComboBox->setSchema( v );
5281 QVariant QgsProcessingDatabaseSchemaWidgetWrapper::widgetValue()
const
5283 if ( mSchemaComboBox )
5284 if ( mSchemaComboBox->comboBox()->isEditable() )
5285 return mSchemaComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->comboBox()->currentText() );
5287 return mSchemaComboBox->currentSchema().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->currentSchema() );
5292 QStringList QgsProcessingDatabaseSchemaWidgetWrapper::compatibleParameterTypes()
const
5294 return QStringList()
5300 QStringList QgsProcessingDatabaseSchemaWidgetWrapper::compatibleOutputTypes()
const
5302 return QStringList()
5306 QString QgsProcessingDatabaseSchemaWidgetWrapper::modelerExpressionFormatString()
const
5308 return tr(
"database schema name as a string value" );
5311 QString QgsProcessingDatabaseSchemaWidgetWrapper::parameterType()
const
5318 return new QgsProcessingDatabaseSchemaWidgetWrapper( parameter, type );
5321 void QgsProcessingDatabaseSchemaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5333 setParentConnectionWrapperValue( wrapper );
5336 setParentConnectionWrapperValue( wrapper );
5360 QVBoxLayout *vlayout =
new QVBoxLayout();
5361 vlayout->setContentsMargins( 0, 0, 0, 0 );
5363 mConnectionParamComboBox =
new QComboBox();
5364 mSchemaParamComboBox =
new QComboBox();
5365 QString initialConnection;
5366 QString initialSchema;
5373 if (
auto *lModel = widgetContext.
model() )
5376 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
5377 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
5379 if ( definition && it->parameterName() == definition->
name() )
5384 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
5385 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5387 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5392 mSchemaParamComboBox->addItem( it->parameterName(), it->parameterName() );
5393 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5395 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
5401 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
5404 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
5405 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5408 if ( mSchemaParamComboBox->count() == 0 && !initialSchema.isEmpty() )
5411 mSchemaParamComboBox->addItem( initialSchema, initialSchema );
5412 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
5415 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
5416 vlayout->addWidget( mConnectionParamComboBox );
5418 vlayout->addWidget(
new QLabel( tr(
"Database schema parameter" ) ) );
5419 vlayout->addWidget( mSchemaParamComboBox );
5421 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5423 mDefaultEdit =
new QLineEdit();
5424 vlayout->addWidget( mDefaultEdit );
5425 setLayout( vlayout );
5433 QgsProcessingParameterDefinition *QgsProcessingDatabaseTableParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5435 QVariant defaultVal;
5436 if ( mDefaultEdit->text().isEmpty() )
5437 defaultVal = QVariant();
5439 defaultVal = mDefaultEdit->text();
5440 auto param = std::make_unique< QgsProcessingParameterDatabaseTable>( name, description,
5441 mConnectionParamComboBox->currentData().toString(),
5442 mSchemaParamComboBox->currentData().toString(),
5445 return param.release();
5455 QWidget *QgsProcessingDatabaseTableWidgetWrapper::createWidget()
5461 mTableComboBox->setAllowEmptyTable(
true );
5464 mTableComboBox->comboBox()->setEditable(
true );
5466 mTableComboBox->setToolTip( parameterDefinition()->toolTip() );
5467 connect( mTableComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
5469 if ( mBlockSignals )
5472 emit widgetValueHasChanged( this );
5475 return mTableComboBox;
5480 return new QgsProcessingDatabaseTableParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5487 std::unique_ptr< QgsProcessingContext > tmpContext;
5488 if ( mProcessingContextGenerator )
5489 context = mProcessingContextGenerator->processingContext();
5493 tmpContext = std::make_unique< QgsProcessingContext >();
5494 context = tmpContext.get();
5499 mProvider = qgis::down_cast< const QgsProcessingParameterProviderConnection * >( parentWrapper->
parameterDefinition() )->providerId();
5500 if ( mTableComboBox && !mSchema.isEmpty() )
5502 mTableComboBox->setSchema( mSchema );
5503 mTableComboBox->setConnectionName( mConnection, mProvider );
5507 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5515 std::unique_ptr< QgsProcessingContext > tmpContext;
5516 if ( mProcessingContextGenerator )
5517 context = mProcessingContextGenerator->processingContext();
5521 tmpContext = std::make_unique< QgsProcessingContext >();
5522 context = tmpContext.get();
5528 if ( mTableComboBox && !mSchema.isEmpty() && !mConnection.isEmpty() )
5530 mTableComboBox->setSchema( mSchema );
5531 mTableComboBox->setConnectionName( mConnection, mProvider );
5535 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5540 void QgsProcessingDatabaseTableWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5544 if ( !value.isValid() )
5545 mTableComboBox->comboBox()->setCurrentIndex( -1 );
5548 if ( mTableComboBox->comboBox()->isEditable() )
5550 const QString prev = mTableComboBox->comboBox()->currentText();
5552 mTableComboBox->setTable( v );
5553 mTableComboBox->comboBox()->setCurrentText( v );
5557 emit widgetValueHasChanged(
this );
5560 mTableComboBox->setTable( v );
5564 QVariant QgsProcessingDatabaseTableWidgetWrapper::widgetValue()
const
5566 if ( mTableComboBox )
5567 if ( mTableComboBox->comboBox()->isEditable() )
5568 return mTableComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mTableComboBox->comboBox()->currentText() );
5570 return mTableComboBox->currentTable().isEmpty() ? QVariant() : QVariant( mTableComboBox->currentTable() );
5575 QStringList QgsProcessingDatabaseTableWidgetWrapper::compatibleParameterTypes()
const
5577 return QStringList()
5583 QStringList QgsProcessingDatabaseTableWidgetWrapper::compatibleOutputTypes()
const
5585 return QStringList()
5589 QString QgsProcessingDatabaseTableWidgetWrapper::modelerExpressionFormatString()
const
5591 return tr(
"database table name as a string value" );
5594 QString QgsProcessingDatabaseTableWidgetWrapper::parameterType()
const
5601 return new QgsProcessingDatabaseTableWidgetWrapper( parameter, type );
5604 void QgsProcessingDatabaseTableWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5616 setParentConnectionWrapperValue( wrapper );
5619 setParentConnectionWrapperValue( wrapper );
5624 setParentSchemaWrapperValue( wrapper );
5627 setParentSchemaWrapperValue( wrapper );
5647 QVBoxLayout *vlayout =
new QVBoxLayout();
5648 vlayout->setContentsMargins( 0, 0, 0, 0 );
5650 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5653 mDefaultWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
5656 if ( extentParam->defaultValueForGui().isValid() )
5660 mDefaultWidget->setCurrentExtent( rect,
crs );
5661 mDefaultWidget->setOutputExtentFromCurrent();
5665 mDefaultWidget->clear();
5669 vlayout->addWidget( mDefaultWidget );
5670 setLayout( vlayout );
5673 QgsProcessingParameterDefinition *QgsProcessingExtentParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5675 const QString defaultVal = mDefaultWidget->isValid() ? QStringLiteral(
"%1,%2,%3,%4%5" ).arg(
5676 QString::number( mDefaultWidget->outputExtent().xMinimum(),
'f', 9 ),
5677 QString::number( mDefaultWidget->outputExtent().xMaximum(),
'f', 9 ),
5678 QString::number( mDefaultWidget->outputExtent().yMinimum(),
'f', 9 ),
5679 QString::number( mDefaultWidget->outputExtent().yMaximum(),
'f', 9 ),
5680 mDefaultWidget->outputCrs().isValid() ? QStringLiteral(
" [%1]" ).arg( mDefaultWidget->outputCrs().authid() ) : QString()
5682 auto param = std::make_unique< QgsProcessingParameterExtent >( name, description, !defaultVal.isEmpty() ? QVariant( defaultVal ) : QVariant() );
5684 return param.release();
5695 QWidget *QgsProcessingExtentWidgetWrapper::createWidget()
5705 if ( widgetContext().mapCanvas() )
5706 mExtentWidget->setMapCanvas( widgetContext().mapCanvas() );
5709 mExtentWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
5711 mExtentWidget->setToolTip( parameterDefinition()->toolTip() );
5715 emit widgetValueHasChanged(
this );
5719 setDialog( mDialog );
5721 return mExtentWidget;
5731 mExtentWidget->setMapCanvas( context.
mapCanvas() );
5734 void QgsProcessingExtentWidgetWrapper::setDialog( QDialog *dialog )
5742 mDialog->showMinimized();
5745 mDialog->showNormal();
5747 mDialog->activateWindow();
5754 void QgsProcessingExtentWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5756 if ( mExtentWidget )
5758 if ( !value.isValid() || ( value.type() == QVariant::String && value.toString().isEmpty() ) )
5759 mExtentWidget->clear();
5764 mExtentWidget->setCurrentExtent( r,
crs );
5765 mExtentWidget->setOutputExtentFromUser( r,
crs );
5770 QVariant QgsProcessingExtentWidgetWrapper::widgetValue()
const
5772 if ( mExtentWidget )
5774 const QString val = mExtentWidget->isValid() ? QStringLiteral(
"%1,%2,%3,%4%5" ).arg(
5775 QString::number( mExtentWidget->outputExtent().xMinimum(),
'f', 9 ),
5776 QString::number( mExtentWidget->outputExtent().xMaximum(),
'f', 9 ),
5777 QString::number( mExtentWidget->outputExtent().yMinimum(),
'f', 9 ),
5778 QString::number( mExtentWidget->outputExtent().yMaximum(),
'f', 9 ),
5779 mExtentWidget->outputCrs().isValid() ? QStringLiteral(
" [%1]" ).arg( mExtentWidget->outputCrs().authid() ) : QString()
5782 return val.isEmpty() ? QVariant() : QVariant( val );
5788 QStringList QgsProcessingExtentWidgetWrapper::compatibleParameterTypes()
const
5790 return QStringList()
5802 QStringList QgsProcessingExtentWidgetWrapper::compatibleOutputTypes()
const
5804 return QStringList()
5811 QString QgsProcessingExtentWidgetWrapper::modelerExpressionFormatString()
const
5813 return tr(
"string of the format 'x min,x max,y min,y max' or a geometry value (bounding box is used)" );
5816 QString QgsProcessingExtentWidgetWrapper::parameterType()
const
5823 return new QgsProcessingExtentWidgetWrapper( parameter, type );
5828 return new QgsProcessingExtentParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5840 QVBoxLayout *vlayout =
new QVBoxLayout();
5841 vlayout->setContentsMargins( 0, 0, 0, 0 );
5843 vlayout->addWidget(
new QLabel( tr(
"Layer type" ) ) );
5858 for (
int i : layerParam->dataTypes() )
5860 mLayerTypeComboBox->setItemCheckState( mLayerTypeComboBox->findData( i ), Qt::Checked );
5864 vlayout->addWidget( mLayerTypeComboBox );
5866 setLayout( vlayout );
5869 QgsProcessingParameterDefinition *QgsProcessingMapLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5871 QList< int > dataTypes;
5872 for (
const QVariant &v : mLayerTypeComboBox->checkedItemsData() )
5873 dataTypes << v.toInt();
5875 auto param = std::make_unique< QgsProcessingParameterMapLayer >( name, description );
5876 param->setDataTypes( dataTypes );
5878 return param.release();
5887 QWidget *QgsProcessingMapLayerWidgetWrapper::createWidget()
5889 mComboBox =
new QgsProcessingMapLayerComboBox( parameterDefinition(), type() );
5897 mComboBox->setEditable(
true );
5901 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5903 connect( mComboBox, &QgsProcessingMapLayerComboBox::valueChanged,
this, [ = ]()
5905 if ( mBlockSignals )
5908 emit widgetValueHasChanged(
this );
5911 setWidgetContext( widgetContext() );
5920 mComboBox->setWidgetContext( context );
5925 if ( !parameterDefinition()->defaultValueForGui().isValid() )
5931 void QgsProcessingMapLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5934 mComboBox->setValue( value, context );
5937 QVariant QgsProcessingMapLayerWidgetWrapper::widgetValue()
const
5939 return mComboBox ? mComboBox->value() : QVariant();
5942 QStringList QgsProcessingMapLayerWidgetWrapper::compatibleParameterTypes()
const
5944 return QStringList()
5955 QStringList QgsProcessingMapLayerWidgetWrapper::compatibleOutputTypes()
const
5957 return QStringList()
5965 QString QgsProcessingMapLayerWidgetWrapper::modelerExpressionFormatString()
const
5967 return tr(
"path to a map layer" );
5970 QString QgsProcessingMapLayerWidgetWrapper::parameterType()
const
5977 return new QgsProcessingMapLayerWidgetWrapper( parameter, type );
5982 return new QgsProcessingMapLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5991 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
5996 QStringList QgsProcessingRasterLayerWidgetWrapper::compatibleParameterTypes()
const
5998 return QStringList()
6005 QStringList QgsProcessingRasterLayerWidgetWrapper::compatibleOutputTypes()
const
6007 return QStringList()
6015 QString QgsProcessingRasterLayerWidgetWrapper::modelerExpressionFormatString()
const
6017 return tr(
"path to a raster layer" );
6020 QString QgsProcessingRasterLayerWidgetWrapper::parameterType()
const
6027 return new QgsProcessingRasterLayerWidgetWrapper( parameter, type );
6032 Q_UNUSED( context );
6033 Q_UNUSED( widgetContext );
6034 Q_UNUSED( definition );
6048 QVBoxLayout *vlayout =
new QVBoxLayout();
6049 vlayout->setContentsMargins( 0, 0, 0, 0 );
6051 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6061 for (
int i : vectorParam->dataTypes() )
6063 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6067 vlayout->addWidget( mGeometryTypeComboBox );
6069 setLayout( vlayout );
6072 QgsProcessingParameterDefinition *QgsProcessingVectorLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6074 QList< int > dataTypes;
6075 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6076 dataTypes << v.toInt();
6078 auto param = std::make_unique< QgsProcessingParameterVectorLayer >( name, description, dataTypes );
6080 return param.release();
6085 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6090 QStringList QgsProcessingVectorLayerWidgetWrapper::compatibleParameterTypes()
const
6092 return QStringList()
6099 QStringList QgsProcessingVectorLayerWidgetWrapper::compatibleOutputTypes()
const
6101 return QStringList()
6109 QString QgsProcessingVectorLayerWidgetWrapper::modelerExpressionFormatString()
const
6111 return tr(
"path to a vector layer" );
6117 return param->dataTypes();
6119 return QList< int >();
6122 QString QgsProcessingVectorLayerWidgetWrapper::parameterType()
const
6129 return new QgsProcessingVectorLayerWidgetWrapper( parameter, type );
6134 return new QgsProcessingVectorLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6146 QVBoxLayout *vlayout =
new QVBoxLayout();
6147 vlayout->setContentsMargins( 0, 0, 0, 0 );
6149 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6159 for (
int i : sourceParam->dataTypes() )
6161 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6169 vlayout->addWidget( mGeometryTypeComboBox );
6171 setLayout( vlayout );
6174 QgsProcessingParameterDefinition *QgsProcessingFeatureSourceParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6176 QList< int > dataTypes;
6177 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6178 dataTypes << v.toInt();
6180 auto param = std::make_unique< QgsProcessingParameterFeatureSource >( name, description, dataTypes );
6182 return param.release();
6186 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6191 QStringList QgsProcessingFeatureSourceWidgetWrapper::compatibleParameterTypes()
const
6193 return QStringList()
6201 QStringList QgsProcessingFeatureSourceWidgetWrapper::compatibleOutputTypes()
const
6203 return QStringList()
6211 QString QgsProcessingFeatureSourceWidgetWrapper::modelerExpressionFormatString()
const
6213 return tr(
"path to a vector layer" );
6219 return param->dataTypes();
6221 return QList< int >();
6224 QString QgsProcessingFeatureSourceWidgetWrapper::parameterType()
const
6231 return new QgsProcessingFeatureSourceWidgetWrapper( parameter, type );
6236 return new QgsProcessingFeatureSourceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6244 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6249 QStringList QgsProcessingMeshLayerWidgetWrapper::compatibleParameterTypes()
const
6251 return QStringList()
6258 QStringList QgsProcessingMeshLayerWidgetWrapper::compatibleOutputTypes()
const
6260 return QStringList()
6268 QString QgsProcessingMeshLayerWidgetWrapper::modelerExpressionFormatString()
const
6270 return tr(
"path to a mesh layer" );
6273 QString QgsProcessingMeshLayerWidgetWrapper::parameterType()
const
6280 return new QgsProcessingMeshLayerWidgetWrapper( parameter, type );
6285 Q_UNUSED( context );
6286 Q_UNUSED( widgetContext );
6287 Q_UNUSED( definition );
6299 QgsProcessingRasterBandPanelWidget::QgsProcessingRasterBandPanelWidget( QWidget *parent,
const QgsProcessingParameterBand *param )
6303 QHBoxLayout *hl =
new QHBoxLayout();
6304 hl->setContentsMargins( 0, 0, 0, 0 );
6306 mLineEdit =
new QLineEdit();
6307 mLineEdit->setEnabled(
false );
6308 hl->addWidget( mLineEdit, 1 );
6310 mToolButton =
new QToolButton();
6311 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6312 hl->addWidget( mToolButton );
6318 mLineEdit->setText( tr(
"%1 bands selected" ).arg( 0 ) );
6321 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingRasterBandPanelWidget::showDialog );
6324 void QgsProcessingRasterBandPanelWidget::setBands(
const QList< int > &bands )
6329 void QgsProcessingRasterBandPanelWidget::setBandNames(
const QHash<int, QString> &names )
6334 void QgsProcessingRasterBandPanelWidget::setValue(
const QVariant &value )
6336 if ( value.isValid() )
6337 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
6341 updateSummaryText();
6345 void QgsProcessingRasterBandPanelWidget::showDialog()
6347 QVariantList availableOptions;
6348 QStringList fieldNames;
6349 availableOptions.reserve( mBands.size() );
6350 for (
int band : std::as_const( mBands ) )
6352 availableOptions << band;
6358 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
6359 widget->setPanelTitle( mParam->description() );
6361 widget->setValueFormatter( [
this](
const QVariant & v ) -> QString
6363 int band = v.toInt();
6364 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6367 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
6369 setValue( widget->selectedOptions() );
6376 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
6378 dlg.setValueFormatter( [
this](
const QVariant & v ) -> QString
6380 int band = v.toInt();
6381 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6385 setValue( dlg.selectedOptions() );
6390 void QgsProcessingRasterBandPanelWidget::updateSummaryText()
6393 mLineEdit->setText( tr(
"%1 bands selected" ).arg( mValue.count() ) );
6405 QVBoxLayout *vlayout =
new QVBoxLayout();
6406 vlayout->setContentsMargins( 0, 0, 0, 0 );
6408 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6410 mDefaultLineEdit =
new QLineEdit();
6411 mDefaultLineEdit->setToolTip( tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6416 for (
int b : bands )
6418 defVal << QString::number( b );
6421 mDefaultLineEdit->setText( defVal.join(
';' ) );
6423 vlayout->addWidget( mDefaultLineEdit );
6425 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
6426 mParentLayerComboBox =
new QComboBox();
6428 QString initialParent;
6430 initialParent = bandParam->parentLayerParameterName();
6432 if (
auto *lModel = widgetContext.
model() )
6435 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6436 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6440 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
6441 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
6443 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6449 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
6452 mParentLayerComboBox->addItem( initialParent, initialParent );
6453 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6456 vlayout->addWidget( mParentLayerComboBox );
6458 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Allow multiple" ) );
6460 mAllowMultipleCheckBox->setChecked( bandParam->allowMultiple() );
6462 vlayout->addWidget( mAllowMultipleCheckBox );
6463 setLayout( vlayout );
6466 QgsProcessingParameterDefinition *QgsProcessingBandParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6468 auto param = std::make_unique< QgsProcessingParameterBand >( name, description, mDefaultLineEdit->text().split(
';' ), mParentLayerComboBox->currentData().toString(),
false, mAllowMultipleCheckBox->isChecked() );
6470 return param.release();
6479 QWidget *QgsProcessingBandWidgetWrapper::createWidget()
6489 mPanel =
new QgsProcessingRasterBandPanelWidget(
nullptr, bandParam );
6490 mPanel->setToolTip( parameterDefinition()->toolTip() );
6491 connect( mPanel, &QgsProcessingRasterBandPanelWidget::changed,
this, [ = ]
6493 emit widgetValueHasChanged(
this );
6502 mComboBox->setToolTip( parameterDefinition()->toolTip() );
6505 emit widgetValueHasChanged(
this );
6513 mLineEdit =
new QLineEdit();
6514 mLineEdit->setToolTip( QObject::tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6515 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
6517 emit widgetValueHasChanged(
this );
6526 void QgsProcessingBandWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6536 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterBand *
>( parameterDefinition() )->parentLayerParameterName() )
6538 setParentLayerWrapperValue( wrapper );
6541 setParentLayerWrapperValue( wrapper );
6558 std::unique_ptr< QgsProcessingContext > tmpContext;
6559 if ( mProcessingContextGenerator )
6560 context = mProcessingContextGenerator->processingContext();
6564 tmpContext = std::make_unique< QgsProcessingContext >();
6565 context = tmpContext.get();
6571 if ( layer && layer->
isValid() )
6575 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
6578 mParentLayer.reset( qobject_cast< QgsRasterLayer * >( ownedLayer.release() ) );
6579 layer = mParentLayer.get();
6587 mComboBox->setLayer( layer );
6591 if ( provider && layer->
isValid() )
6596 QHash< int, QString > bandNames;
6597 for (
int i = 1; i <= nBands; ++i )
6602 mPanel->setBands( bands );
6603 mPanel->setBandNames( bandNames );
6610 mComboBox->setLayer(
nullptr );
6612 mPanel->setBands( QList< int >() );
6614 if ( value.isValid() && widgetContext().messageBar() )
6617 widgetContext().
messageBar()->
pushMessage( QString(), QObject::tr(
"Could not load selected layer/table. Dependent bands could not be populated" ),
6618 Qgis::MessageLevel::Info );
6622 if ( parameterDefinition()->defaultValueForGui().isValid() )
6623 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6626 void QgsProcessingBandWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6630 if ( !value.isValid() )
6631 mComboBox->setBand( -1 );
6635 mComboBox->setBand( v );
6641 if ( value.isValid() )
6644 opts.reserve( v.size() );
6649 mPanel->setValue( value.isValid() ? opts : QVariant() );
6651 else if ( mLineEdit )
6658 opts.reserve( v.size() );
6660 opts << QString::number( i );
6661 mLineEdit->setText( value.isValid() && !opts.empty() ? opts.join(
';' ) : QString() );
6665 if ( value.isValid() )
6673 QVariant QgsProcessingBandWidgetWrapper::widgetValue()
const
6676 return mComboBox->currentBand() == -1 ? QVariant() : mComboBox->currentBand();
6678 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
6679 else if ( mLineEdit )
6684 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
6685 const QStringList parts = mLineEdit->text().split(
';', QString::SkipEmptyParts );
6687 const QStringList parts = mLineEdit->text().split(
';', Qt::SkipEmptyParts );
6690 res.reserve( parts.count() );
6691 for (
const QString &s : parts )
6694 int band = s.toInt( &ok );
6698 return res.
isEmpty() ? QVariant() : res;
6702 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
6709 QStringList QgsProcessingBandWidgetWrapper::compatibleParameterTypes()
const
6711 return QStringList()
6716 QStringList QgsProcessingBandWidgetWrapper::compatibleOutputTypes()
const
6718 return QStringList()
6722 QString QgsProcessingBandWidgetWrapper::modelerExpressionFormatString()
const
6724 return tr(
"selected band numbers as an array of numbers, or semicolon separated string of options (e.g. '1;3')" );
6727 QString QgsProcessingBandWidgetWrapper::parameterType()
const
6734 return new QgsProcessingBandWidgetWrapper( parameter, type );
6739 return new QgsProcessingBandParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6752 QHBoxLayout *hl =
new QHBoxLayout();
6753 hl->setContentsMargins( 0, 0, 0, 0 );
6755 mLineEdit =
new QLineEdit();
6756 mLineEdit->setEnabled(
false );
6757 hl->addWidget( mLineEdit, 1 );
6759 mToolButton =
new QToolButton();
6760 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6761 hl->addWidget( mToolButton );
6767 mLineEdit->setText( tr(
"%1 inputs selected" ).arg( 0 ) );
6770 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingMultipleLayerPanelWidget::showDialog );
6773 void QgsProcessingMultipleLayerPanelWidget::setValue(
const QVariant &value )
6775 if ( value.isValid() )
6776 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
6780 updateSummaryText();
6784 void QgsProcessingMultipleLayerPanelWidget::setProject(
QgsProject *project )
6791 if ( mValue.removeAll( layerId ) )
6793 updateSummaryText();
6800 void QgsProcessingMultipleLayerPanelWidget::setModel( QgsProcessingModelAlgorithm *model,
const QString &modelChildAlgorithmID )
6806 switch ( mParam->layerType() )
6955 void QgsProcessingMultipleLayerPanelWidget::showDialog()
6960 QgsProcessingMultipleInputPanelWidget *widget =
new QgsProcessingMultipleInputPanelWidget( mParam, mValue, mModelSources, mModel );
6961 widget->setPanelTitle( mParam->description() );
6962 widget->setProject( mProject );
6963 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
6965 setValue( widget->selectedOptions() );
6972 QgsProcessingMultipleInputDialog dlg( mParam, mValue, mModelSources, mModel,
this, Qt::WindowFlags() );
6973 dlg.setProject( mProject );
6976 setValue( dlg.selectedOptions() );
6981 void QgsProcessingMultipleLayerPanelWidget::updateSummaryText()
6984 mLineEdit->setText( tr(
"%1 inputs selected" ).arg( mValue.count() ) );
6994 QVBoxLayout *vlayout =
new QVBoxLayout();
6995 vlayout->setContentsMargins( 0, 0, 0, 0 );
6997 vlayout->addWidget(
new QLabel( tr(
"Allowed layer type" ) ) );
6998 mLayerTypeComboBox =
new QComboBox();
7012 mLayerTypeComboBox->setCurrentIndex( mLayerTypeComboBox->findData( layersParam->layerType() ) );
7014 vlayout->addWidget( mLayerTypeComboBox );
7015 setLayout( vlayout );
7018 QgsProcessingParameterDefinition *QgsProcessingMultipleLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
7020 auto param = std::make_unique< QgsProcessingParameterMultipleLayers >( name, description,
static_cast< QgsProcessing::SourceType >( mLayerTypeComboBox->currentData().toInt() ) );
7022 return param.release();
7031 QWidget *QgsProcessingMultipleLayerWidgetWrapper::createWidget()
7035 mPanel =
new QgsProcessingMultipleLayerPanelWidget(
nullptr, layerParam );
7036 mPanel->setToolTip( parameterDefinition()->toolTip() );
7037 mPanel->setProject( widgetContext().project() );
7039 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7040 connect( mPanel, &QgsProcessingMultipleLayerPanelWidget::changed,
this, [ = ]
7042 emit widgetValueHasChanged(
this );
7052 mPanel->setProject( context.
project() );
7054 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7058 void QgsProcessingMultipleLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7063 if ( value.isValid() )
7066 opts.reserve( v.size() );
7068 opts << l->source();
7071 for (
const QVariant &v : value.toList() )
7073 if ( v.canConvert< QgsProcessingModelChildParameterSource >() )
7075 const QgsProcessingModelChildParameterSource source = v.value< QgsProcessingModelChildParameterSource >();
7076 opts << QVariant::fromValue( source );
7081 mPanel->setValue( value.isValid() ? opts : QVariant() );
7085 QVariant QgsProcessingMultipleLayerWidgetWrapper::widgetValue()
const
7088 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
7093 QStringList QgsProcessingMultipleLayerWidgetWrapper::compatibleParameterTypes()
const
7095 return QStringList()
7106 QStringList QgsProcessingMultipleLayerWidgetWrapper::compatibleOutputTypes()
const
7108 return QStringList()
7117 QString QgsProcessingMultipleLayerWidgetWrapper::modelerExpressionFormatString()
const
7119 return tr(
"an array of layer paths, or semicolon separated string of layer paths" );
7122 QString QgsProcessingMultipleLayerWidgetWrapper::parameterType()
const
7129 return new QgsProcessingMultipleLayerWidgetWrapper( parameter, type );
7134 return new QgsProcessingMultipleLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
7143 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
7148 QStringList QgsProcessingPointCloudLayerWidgetWrapper::compatibleParameterTypes()
const
7150 return QStringList()
7157 QStringList QgsProcessingPointCloudLayerWidgetWrapper::compatibleOutputTypes()
const
7159 return QStringList()
7167 QString QgsProcessingPointCloudLayerWidgetWrapper::modelerExpressionFormatString()
const
7169 return tr(
"path to a point cloud layer" );
7172 QString QgsProcessingPointCloudLayerWidgetWrapper::parameterType()
const
7179 return new QgsProcessingPointCloudLayerWidgetWrapper( parameter, type );
7184 Q_UNUSED( context );
7185 Q_UNUSED( widgetContext );
7186 Q_UNUSED( definition );
7203 QStringList QgsProcessingAnnotationLayerWidgetWrapper::compatibleParameterTypes()
const
7205 return QStringList()
7212 QStringList QgsProcessingAnnotationLayerWidgetWrapper::compatibleOutputTypes()
const
7214 return QStringList()
7219 QString QgsProcessingAnnotationLayerWidgetWrapper::modelerExpressionFormatString()
const
7221 return tr(
"name of an annotation layer, or \"main\" for the main annotation layer" );
7224 QString QgsProcessingAnnotationLayerWidgetWrapper::parameterType()
const
7231 return new QgsProcessingAnnotationLayerWidgetWrapper( parameter, type );
7236 Q_UNUSED( context );
7237 Q_UNUSED( widgetContext );
7238 Q_UNUSED( definition );
7249 if ( mWidgetContext.project() )
7250 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7254 QWidget *QgsProcessingAnnotationLayerWidgetWrapper::createWidget()
7265 mComboBox->setEditable(
true );
7269 mComboBox->setToolTip( parameterDefinition()->toolTip() );
7271 if ( mWidgetContext.project() )
7272 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7275 mComboBox->setAllowEmptyLayer(
true );
7279 if ( mBlockSignals )
7282 emit widgetValueHasChanged(
this );
7285 setWidgetContext( widgetContext() );
7289 void QgsProcessingAnnotationLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7295 mComboBox->setLayer(
nullptr );
7299 QVariant val = value;
7312 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( val.value< QObject * >() );
7313 if ( !layer && val.type() == QVariant::String )
7320 mComboBox->setLayer( layer );
7325 QVariant QgsProcessingAnnotationLayerWidgetWrapper::widgetValue()
const
7327 return mComboBox && mComboBox->currentLayer() ?
7328 ( mWidgetContext.project() ? ( mComboBox->currentLayer() == mWidgetContext.project()->mainAnnotationLayer() ? QStringLiteral(
"main" ) : mComboBox->currentLayer()->id() ) : mComboBox->currentLayer()->id() )
7344 QWidget *QgsProcessingOutputWidgetWrapper::createWidget()
7352 mOutputWidget =
new QgsProcessingLayerOutputDestinationWidget( destParam,
false );
7353 if ( mProcessingContextGenerator )
7354 mOutputWidget->setContext( mProcessingContextGenerator->processingContext() );
7355 if ( mParametersGenerator )
7356 mOutputWidget->registerProcessingParametersGenerator( mParametersGenerator );
7357 mOutputWidget->setToolTip( parameterDefinition()->toolTip() );
7359 connect( mOutputWidget, &QgsProcessingLayerOutputDestinationWidget::destinationChanged,
this, [ = ]()
7361 if ( mBlockSignals )
7364 emit widgetValueHasChanged(
this );
7371 mOutputWidget->addOpenAfterRunningOption();
7373 return mOutputWidget;
7383 void QgsProcessingOutputWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
7385 if ( mOutputWidget )
7386 mOutputWidget->setValue( value );
7389 QVariant QgsProcessingOutputWidgetWrapper::widgetValue()
const
7391 if ( mOutputWidget )
7392 return mOutputWidget->value();
7397 QVariantMap QgsProcessingOutputWidgetWrapper::customProperties()
const
7400 if ( mOutputWidget )
7401 res.insert( QStringLiteral(
"OPEN_AFTER_RUNNING" ), mOutputWidget->openAfterRunning() );
7405 QStringList QgsProcessingOutputWidgetWrapper::compatibleParameterTypes()
const
7407 return QStringList()
7416 QStringList QgsProcessingOutputWidgetWrapper::compatibleOutputTypes()
const
7418 return QStringList()
7429 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7434 QString QgsProcessingFeatureSinkWidgetWrapper::parameterType()
const
7441 return new QgsProcessingFeatureSinkWidgetWrapper( parameter, type );
7444 QString QgsProcessingFeatureSinkWidgetWrapper::modelerExpressionFormatString()
const
7446 return tr(
"path to layer destination" );
7454 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7459 QString QgsProcessingVectorDestinationWidgetWrapper::parameterType()
const
7466 return new QgsProcessingVectorDestinationWidgetWrapper( parameter, type );
7469 QString QgsProcessingVectorDestinationWidgetWrapper::modelerExpressionFormatString()
const
7471 return tr(
"path to layer destination" );
7479 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7484 QString QgsProcessingRasterDestinationWidgetWrapper::parameterType()
const
7491 return new QgsProcessingRasterDestinationWidgetWrapper( parameter, type );
7494 QString QgsProcessingRasterDestinationWidgetWrapper::modelerExpressionFormatString()
const
7496 return tr(
"path to layer destination" );
7504 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7509 QString QgsProcessingFileDestinationWidgetWrapper::parameterType()
const
7516 return new QgsProcessingFileDestinationWidgetWrapper( parameter, type );
7519 QString QgsProcessingFileDestinationWidgetWrapper::modelerExpressionFormatString()
const
7521 return tr(
"path to file destination" );
7529 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7534 QString QgsProcessingFolderDestinationWidgetWrapper::parameterType()
const
7541 return new QgsProcessingFolderDestinationWidgetWrapper( parameter, type );
7544 QString QgsProcessingFolderDestinationWidgetWrapper::modelerExpressionFormatString()
const
7546 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.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
QgsExpressionContext & expressionContext()
Returns the expression 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.
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.
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