74#include <QPlainTextEdit>
75#include <QRadioButton>
76#include <QButtonGroup>
90 QVBoxLayout *vlayout =
new QVBoxLayout();
91 vlayout->setContentsMargins( 0, 0, 0, 0 );
93 mDefaultCheckBox =
new QCheckBox( tr(
"Checked" ) );
97 mDefaultCheckBox->setChecked(
false );
98 vlayout->addWidget( mDefaultCheckBox );
102QgsProcessingParameterDefinition *QgsProcessingBooleanParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
104 auto param = std::make_unique< QgsProcessingParameterBoolean >( name, description, mDefaultCheckBox->isChecked() );
105 param->setFlags( flags );
106 return param.release();
116QWidget *QgsProcessingBooleanWidgetWrapper::createWidget()
122 QString description = parameterDefinition()->description();
124 description = QObject::tr(
"%1 [optional]" ).arg( description );
126 mCheckBox =
new QCheckBox( description );
127 mCheckBox->setToolTip( parameterDefinition()->toolTip() );
129 connect( mCheckBox, &QCheckBox::toggled,
this, [ = ]
131 emit widgetValueHasChanged(
this );
139 mComboBox =
new QComboBox();
140 mComboBox->addItem( tr(
"Yes" ),
true );
141 mComboBox->addItem( tr(
"No" ),
false );
142 mComboBox->setToolTip( parameterDefinition()->toolTip() );
144 connect( mComboBox, qOverload< int>( &QComboBox::currentIndexChanged ),
this, [ = ]
146 emit widgetValueHasChanged(
this );
155QLabel *QgsProcessingBooleanWidgetWrapper::createLabel()
164void QgsProcessingBooleanWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
171 mCheckBox->setChecked( v );
179 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
185QVariant QgsProcessingBooleanWidgetWrapper::widgetValue()
const
190 return mCheckBox->isChecked();
194 return mComboBox->currentData();
199QStringList QgsProcessingBooleanWidgetWrapper::compatibleParameterTypes()
const
221QStringList QgsProcessingBooleanWidgetWrapper::compatibleOutputTypes()
const
232QString QgsProcessingBooleanWidgetWrapper::parameterType()
const
239 return new QgsProcessingBooleanWidgetWrapper( parameter, type );
244 return new QgsProcessingBooleanParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
255 QVBoxLayout *vlayout =
new QVBoxLayout();
256 vlayout->setContentsMargins( 0, 0, 0, 0 );
258 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
263 mCrsSelector->setShowAccuracyWarnings(
true );
270 vlayout->addWidget( mCrsSelector );
271 setLayout( vlayout );
274QgsProcessingParameterDefinition *QgsProcessingCrsParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
276 auto param = std::make_unique< QgsProcessingParameterCrs >( name, description, mCrsSelector->crs().authid() );
277 param->setFlags( flags );
278 return param.release();
287QWidget *QgsProcessingCrsWidgetWrapper::createWidget()
289 Q_ASSERT( mProjectionSelectionWidget ==
nullptr );
291 mProjectionSelectionWidget->setToolTip( parameterDefinition()->toolTip() );
300 emit widgetValueHasChanged(
this );
308 return mProjectionSelectionWidget;
313 QWidget *w =
new QWidget();
314 w->setToolTip( parameterDefinition()->toolTip() );
316 QVBoxLayout *vl =
new QVBoxLayout();
317 vl->setContentsMargins( 0, 0, 0, 0 );
320 mUseProjectCrsCheckBox =
new QCheckBox( tr(
"Use project CRS" ) );
321 mUseProjectCrsCheckBox->setToolTip( tr(
"Always use the current project CRS when running the model" ) );
322 vl->addWidget( mUseProjectCrsCheckBox );
323 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, mProjectionSelectionWidget, &QgsProjectionSelectionWidget::setDisabled );
324 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled,
this, [ = ]
326 emit widgetValueHasChanged(
this );
329 vl->addWidget( mProjectionSelectionWidget );
337void QgsProcessingCrsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
339 if ( mUseProjectCrsCheckBox )
341 if ( value.toString().compare( QLatin1String(
"ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
343 mUseProjectCrsCheckBox->setChecked(
true );
348 mUseProjectCrsCheckBox->setChecked(
false );
353 if ( mProjectionSelectionWidget )
354 mProjectionSelectionWidget->setCrs( v );
357QVariant QgsProcessingCrsWidgetWrapper::widgetValue()
const
359 if ( mUseProjectCrsCheckBox && mUseProjectCrsCheckBox->isChecked() )
360 return QStringLiteral(
"ProjectCrs" );
361 else if ( mProjectionSelectionWidget )
362 return mProjectionSelectionWidget->crs().isValid() ? mProjectionSelectionWidget->crs() : QVariant();
367QStringList QgsProcessingCrsWidgetWrapper::compatibleParameterTypes()
const
381QStringList QgsProcessingCrsWidgetWrapper::compatibleOutputTypes()
const
389QString QgsProcessingCrsWidgetWrapper::modelerExpressionFormatString()
const
391 return tr(
"string as EPSG code, WKT or PROJ format, or a string identifying a map layer" );
394QString QgsProcessingCrsWidgetWrapper::parameterType()
const
401 return new QgsProcessingCrsWidgetWrapper( parameter, type );
406 return new QgsProcessingCrsParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
419 QVBoxLayout *vlayout =
new QVBoxLayout();
420 vlayout->setContentsMargins( 0, 0, 0, 0 );
422 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
424 mDefaultLineEdit =
new QLineEdit();
427 vlayout->addWidget( mDefaultLineEdit );
429 mMultiLineCheckBox =
new QCheckBox( tr(
"Multiline input" ) );
431 mMultiLineCheckBox->setChecked( stringParam->multiLine() );
432 vlayout->addWidget( mMultiLineCheckBox );
434 setLayout( vlayout );
437QgsProcessingParameterDefinition *QgsProcessingStringParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
439 auto param = std::make_unique< QgsProcessingParameterString >( name, description, mDefaultLineEdit->text(), mMultiLineCheckBox->isChecked() );
440 param->setFlags( flags );
441 return param.release();
452QWidget *QgsProcessingStringWidgetWrapper::createWidget()
454 const QVariantMap metadata = parameterDefinition()->metadata();
455 const QVariant valueHintsVariant = metadata.value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"value_hints" ) );
457 if ( valueHintsVariant.isValid() )
459 const QVariantList valueList = valueHintsVariant.toList();
460 mComboBox =
new QComboBox();
461 mComboBox->setToolTip( parameterDefinition()->toolTip() );
465 mComboBox->addItem( QString() );
467 for (
const QVariant &entry : valueList )
469 mComboBox->addItem( entry.toString(), entry.toString() );
471 mComboBox->setCurrentIndex( 0 );
473 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
475 emit widgetValueHasChanged(
this );
488 mPlainTextEdit =
new QPlainTextEdit();
489 mPlainTextEdit->setToolTip( parameterDefinition()->toolTip() );
491 connect( mPlainTextEdit, &QPlainTextEdit::textChanged,
this, [ = ]
493 emit widgetValueHasChanged(
this );
495 return mPlainTextEdit;
499 mLineEdit =
new QLineEdit();
500 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
502 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
504 emit widgetValueHasChanged(
this );
512 mLineEdit =
new QLineEdit();
513 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
515 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
517 emit widgetValueHasChanged(
this );
527void QgsProcessingStringWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
531 mLineEdit->setText( v );
532 if ( mPlainTextEdit )
533 mPlainTextEdit->setPlainText( v );
537 if ( !value.isValid() )
538 index = mComboBox->findData( QVariant() );
540 index = mComboBox->findData( v );
543 mComboBox->setCurrentIndex( index );
545 mComboBox->setCurrentIndex( 0 );
549QVariant QgsProcessingStringWidgetWrapper::widgetValue()
const
552 return mLineEdit->text();
553 else if ( mPlainTextEdit )
554 return mPlainTextEdit->toPlainText();
555 else if ( mComboBox )
556 return mComboBox->currentData();
561QStringList QgsProcessingStringWidgetWrapper::compatibleParameterTypes()
const
577QStringList QgsProcessingStringWidgetWrapper::compatibleOutputTypes()
const
585QString QgsProcessingStringWidgetWrapper::parameterType()
const
592 return new QgsProcessingStringWidgetWrapper( parameter, type );
597 return new QgsProcessingStringParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
612QWidget *QgsProcessingAuthConfigWidgetWrapper::createWidget()
621 mAuthConfigSelect->setToolTip( parameterDefinition()->toolTip() );
625 emit widgetValueHasChanged(
this );
627 return mAuthConfigSelect;
633void QgsProcessingAuthConfigWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
636 if ( mAuthConfigSelect )
637 mAuthConfigSelect->setConfigId( v );
640QVariant QgsProcessingAuthConfigWidgetWrapper::widgetValue()
const
642 if ( mAuthConfigSelect )
643 return mAuthConfigSelect->configId();
648QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleParameterTypes()
const
656QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleOutputTypes()
const
661QString QgsProcessingAuthConfigWidgetWrapper::parameterType()
const
668 return new QgsProcessingAuthConfigWidgetWrapper( parameter, type );
678 QVBoxLayout *vlayout =
new QVBoxLayout();
679 vlayout->setContentsMargins( 0, 0, 0, 0 );
681 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
683 mTypeComboBox =
new QComboBox();
686 vlayout->addWidget( mTypeComboBox );
688 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
689 mMinLineEdit =
new QLineEdit();
690 vlayout->addWidget( mMinLineEdit );
692 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
693 mMaxLineEdit =
new QLineEdit();
694 vlayout->addWidget( mMaxLineEdit );
696 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
697 mDefaultLineEdit =
new QLineEdit();
698 vlayout->addWidget( mDefaultLineEdit );
702 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( numberParam->dataType() ) );
704 if ( !
qgsDoubleNear( numberParam->maximum(), std::numeric_limits<double>::max() ) )
706 mMaxLineEdit->setText( QLocale().toString( numberParam->maximum() ) );
710 mMaxLineEdit->clear();
713 if ( !
qgsDoubleNear( numberParam->minimum(), std::numeric_limits<double>::lowest() ) )
715 mMinLineEdit->setText( QLocale().toString( numberParam->minimum() ) );
719 mMinLineEdit->clear();
722 mDefaultLineEdit->setText( numberParam->defaultValueForGui().toString() );
725 setLayout( vlayout );
728QgsProcessingParameterDefinition *QgsProcessingNumberParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
734 auto param = std::make_unique< QgsProcessingParameterNumber >( name, description, dataType, ok ? val : QVariant() );
736 if ( !mMinLineEdit->text().trimmed().isEmpty() )
741 param->setMinimum( val );
745 if ( !mMaxLineEdit->text().trimmed().isEmpty() )
750 param->setMaximum( val );
754 param->setFlags( flags );
755 return param.release();
764QWidget *QgsProcessingNumericWidgetWrapper::createWidget()
767 const QVariantMap metadata = numberDef->
metadata();
768 const int decimals = metadata.value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"decimals" ), 6 ).toInt();
776 QAbstractSpinBox *spinBox =
nullptr;
781 mDoubleSpinBox->setExpressionsEnabled(
true );
782 mDoubleSpinBox->setDecimals( decimals );
788 double singleStep = calculateStep( numberDef->
minimum(), numberDef->
maximum() );
789 singleStep = std::max( singleStep, std::pow( 10, -decimals ) );
790 mDoubleSpinBox->setSingleStep( singleStep );
793 spinBox = mDoubleSpinBox;
798 mSpinBox->setExpressionsEnabled(
true );
802 spinBox->setToolTip( parameterDefinition()->toolTip() );
804 double max = 999999999;
809 double min = -999999999;
814 if ( mDoubleSpinBox )
816 mDoubleSpinBox->setMinimum( min );
817 mDoubleSpinBox->setMaximum( max );
821 mSpinBox->setMinimum(
static_cast< int >( min ) );
822 mSpinBox->setMaximum(
static_cast< int >( max ) );
827 mAllowingNull =
true;
828 if ( mDoubleSpinBox )
830 mDoubleSpinBox->setShowClearButton(
true );
831 const double min = mDoubleSpinBox->minimum() - mDoubleSpinBox->singleStep();
832 mDoubleSpinBox->setMinimum( min );
833 mDoubleSpinBox->setValue( min );
837 mSpinBox->setShowClearButton(
true );
838 const int min = mSpinBox->minimum() - 1;
839 mSpinBox->setMinimum( min );
840 mSpinBox->setValue( min );
842 spinBox->setSpecialValueText( tr(
"Not set" ) );
850 if ( mDoubleSpinBox )
854 mDoubleSpinBox->setClearValue( defaultVal );
860 mSpinBox->setClearValue( intVal );
866 if ( mDoubleSpinBox )
867 mDoubleSpinBox->setClearValue( numberDef->
minimum() );
869 mSpinBox->setClearValue(
static_cast< int >( numberDef->
minimum() ) );
874 if ( mDoubleSpinBox )
876 mDoubleSpinBox->setValue( 0 );
877 mDoubleSpinBox->setClearValue( 0 );
881 mSpinBox->setValue( 0 );
882 mSpinBox->setClearValue( 0 );
887 if ( mDoubleSpinBox )
888 connect( mDoubleSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [ = ] { emit widgetValueHasChanged(
this ); } );
890 connect( mSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, [ = ] { emit widgetValueHasChanged(
this ); } );
898void QgsProcessingNumericWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
900 if ( mDoubleSpinBox )
902 if ( mAllowingNull && !value.isValid() )
903 mDoubleSpinBox->clear();
907 mDoubleSpinBox->setValue( v );
912 if ( mAllowingNull && !value.isValid() )
917 mSpinBox->setValue( v );
922QVariant QgsProcessingNumericWidgetWrapper::widgetValue()
const
924 if ( mDoubleSpinBox )
926 if ( mAllowingNull &&
qgsDoubleNear( mDoubleSpinBox->value(), mDoubleSpinBox->minimum() ) )
929 return mDoubleSpinBox->value();
933 if ( mAllowingNull && mSpinBox->value() == mSpinBox->minimum() )
936 return mSpinBox->value();
942QStringList QgsProcessingNumericWidgetWrapper::compatibleParameterTypes()
const
952QStringList QgsProcessingNumericWidgetWrapper::compatibleOutputTypes()
const
958double QgsProcessingNumericWidgetWrapper::calculateStep(
const double minimum,
const double maximum )
960 const double valueRange = maximum - minimum;
961 if ( valueRange <= 1.0 )
963 const double step = valueRange / 10.0;
965 return qgsRound( step, -std::floor( std::log( step ) ) );
973QString QgsProcessingNumericWidgetWrapper::parameterType()
const
980 return new QgsProcessingNumericWidgetWrapper( parameter, type );
985 return new QgsProcessingNumberParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
995 QVBoxLayout *vlayout =
new QVBoxLayout();
996 vlayout->setContentsMargins( 0, 0, 0, 0 );
998 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
1000 mParentLayerComboBox =
new QComboBox();
1002 QString initialParent;
1004 initialParent = distParam->parentParameterName();
1006 if (
auto *lModel = widgetContext.
model() )
1009 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
1010 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
1014 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1015 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1017 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1022 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1023 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1025 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1030 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1031 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1033 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1038 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1039 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1041 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1047 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
1050 mParentLayerComboBox->addItem( initialParent, initialParent );
1051 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1054 vlayout->addWidget( mParentLayerComboBox );
1056 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1057 mMinLineEdit =
new QLineEdit();
1058 vlayout->addWidget( mMinLineEdit );
1060 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1061 mMaxLineEdit =
new QLineEdit();
1062 vlayout->addWidget( mMaxLineEdit );
1064 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1065 mDefaultLineEdit =
new QLineEdit();
1066 vlayout->addWidget( mDefaultLineEdit );
1070 mMinLineEdit->setText( QLocale().toString( distParam->minimum() ) );
1071 mMaxLineEdit->setText( QLocale().toString( distParam->maximum() ) );
1072 mDefaultLineEdit->setText( distParam->defaultValueForGui().toString() );
1075 setLayout( vlayout );
1078QgsProcessingParameterDefinition *QgsProcessingDistanceParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1083 auto param = std::make_unique< QgsProcessingParameterDistance >( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1088 param->setMinimum( val );
1094 param->setMaximum( val );
1097 param->setFlags( flags );
1098 return param.release();
1102 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1107QString QgsProcessingDistanceWidgetWrapper::parameterType()
const
1114 return new QgsProcessingDistanceWidgetWrapper( parameter, type );
1117QWidget *QgsProcessingDistanceWidgetWrapper::createWidget()
1121 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1126 mLabel =
new QLabel();
1127 mUnitsCombo =
new QComboBox();
1135 const int labelMargin =
static_cast< int >( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1136 QHBoxLayout *layout =
new QHBoxLayout();
1137 layout->addWidget( spin, 1 );
1138 layout->insertSpacing( 1, labelMargin / 2 );
1139 layout->insertWidget( 2, mLabel );
1140 layout->insertWidget( 3, mUnitsCombo );
1145 mWarningLabel =
new QWidget();
1146 QHBoxLayout *warningLayout =
new QHBoxLayout();
1147 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1148 QLabel *warning =
new QLabel();
1150 const int size =
static_cast< int >( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1151 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1152 warning->setToolTip( tr(
"Distance is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1153 warningLayout->insertSpacing( 0, labelMargin / 2 );
1154 warningLayout->insertWidget( 1, warning );
1155 mWarningLabel->setLayout( warningLayout );
1156 layout->insertWidget( 4, mWarningLabel );
1158 QWidget *w =
new QWidget();
1159 layout->setContentsMargins( 0, 0, 0, 0 );
1160 w->setLayout( layout );
1175void QgsProcessingDistanceWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1177 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1184 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterDistance *
>( parameterDefinition() )->parentParameterName() )
1186 setUnitParameterValue( wrapper->parameterValue() );
1189 setUnitParameterValue( wrapper->parameterValue() );
1203void QgsProcessingDistanceWidgetWrapper::setUnitParameterValue(
const QVariant &value )
1209 std::unique_ptr< QgsProcessingContext > tmpContext;
1210 if ( mProcessingContextGenerator )
1211 context = mProcessingContextGenerator->processingContext();
1215 tmpContext = std::make_unique< QgsProcessingContext >();
1216 context = tmpContext.get();
1233 mUnitsCombo->hide();
1238 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( units ) );
1239 mUnitsCombo->show();
1246QVariant QgsProcessingDistanceWidgetWrapper::widgetValue()
const
1248 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1249 if ( val.type() == QVariant::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1262 return new QgsProcessingDistanceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1273 QVBoxLayout *vlayout =
new QVBoxLayout();
1274 vlayout->setContentsMargins( 0, 0, 0, 0 );
1276 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1277 mMinLineEdit =
new QLineEdit();
1278 vlayout->addWidget( mMinLineEdit );
1280 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1281 mMaxLineEdit =
new QLineEdit();
1282 vlayout->addWidget( mMaxLineEdit );
1284 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1285 mDefaultLineEdit =
new QLineEdit();
1286 vlayout->addWidget( mDefaultLineEdit );
1288 vlayout->addWidget(
new QLabel( tr(
"Default unit type" ) ) );
1290 mUnitsCombo =
new QComboBox();
1300 vlayout->addWidget( mUnitsCombo );
1304 mMinLineEdit->setText( QLocale().toString( durationParam->minimum() ) );
1305 mMaxLineEdit->setText( QLocale().toString( durationParam->maximum() ) );
1306 mDefaultLineEdit->setText( durationParam->defaultValueForGui().toString() );
1307 mUnitsCombo->setCurrentIndex( durationParam->defaultUnit() );
1310 setLayout( vlayout );
1313QgsProcessingParameterDefinition *QgsProcessingDurationParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1318 auto param = std::make_unique< QgsProcessingParameterDuration >( name, description, ok ? val : QVariant() );
1323 param->setMinimum( val );
1329 param->setMaximum( val );
1334 param->setFlags( flags );
1335 return param.release();
1339 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1344QString QgsProcessingDurationWidgetWrapper::parameterType()
const
1351 return new QgsProcessingDurationWidgetWrapper( parameter, type );
1354QWidget *QgsProcessingDurationWidgetWrapper::createWidget()
1358 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1363 mUnitsCombo =
new QComboBox();
1375 QHBoxLayout *layout =
new QHBoxLayout();
1376 layout->addWidget( spin, 1 );
1377 layout->insertWidget( 1, mUnitsCombo );
1379 QWidget *w =
new QWidget();
1380 layout->setContentsMargins( 0, 0, 0, 0 );
1381 w->setLayout( layout );
1383 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( durationDef->
defaultUnit() ) );
1384 mUnitsCombo->show();
1397QLabel *QgsProcessingDurationWidgetWrapper::createLabel()
1409QVariant QgsProcessingDurationWidgetWrapper::widgetValue()
const
1411 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1412 if ( val.type() == QVariant::Double && mUnitsCombo )
1423void QgsProcessingDurationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1429 QgsProcessingNumericWidgetWrapper::setWidgetValue( val, context );
1433 QgsProcessingNumericWidgetWrapper::setWidgetValue( value, context );
1439 return new QgsProcessingDurationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1449 QVBoxLayout *vlayout =
new QVBoxLayout();
1450 vlayout->setContentsMargins( 0, 0, 0, 0 );
1452 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1454 mDefaultLineEdit =
new QLineEdit();
1458 mDefaultLineEdit->setText( scaleParam->defaultValueForGui().toString() );
1461 vlayout->addWidget( mDefaultLineEdit );
1463 setLayout( vlayout );
1466QgsProcessingParameterDefinition *QgsProcessingScaleParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1469 double val = mDefaultLineEdit->text().toDouble( &ok );
1470 auto param = std::make_unique< QgsProcessingParameterScale >( name, description, ok ? val : QVariant() );
1472 return param.release();
1476 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1481QString QgsProcessingScaleWidgetWrapper::parameterType()
const
1488 return new QgsProcessingScaleWidgetWrapper( parameter, type );
1491QWidget *QgsProcessingScaleWidgetWrapper::createWidget()
1503 mScaleWidget->setAllowNull(
true );
1505 mScaleWidget->setMapCanvas( widgetContext().mapCanvas() );
1506 mScaleWidget->setShowCurrentScaleButton(
true );
1508 mScaleWidget->setToolTip( parameterDefinition()->toolTip() );
1511 emit widgetValueHasChanged(
this );
1513 return mScaleWidget;
1522 mScaleWidget->setMapCanvas( context.
mapCanvas() );
1527QVariant QgsProcessingScaleWidgetWrapper::widgetValue()
const
1529 return mScaleWidget && !mScaleWidget->isNull() ? QVariant( mScaleWidget->scale() ) : QVariant();
1532void QgsProcessingScaleWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1536 if ( mScaleWidget->allowNull() && !value.isValid() )
1537 mScaleWidget->setNull();
1541 mScaleWidget->setScale( v );
1548 return new QgsProcessingScaleParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1559 QVBoxLayout *vlayout =
new QVBoxLayout();
1560 vlayout->setContentsMargins( 0, 0, 0, 0 );
1562 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
1564 mTypeComboBox =
new QComboBox();
1567 vlayout->addWidget( mTypeComboBox );
1569 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1570 mMinLineEdit =
new QLineEdit();
1571 vlayout->addWidget( mMinLineEdit );
1573 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1574 mMaxLineEdit =
new QLineEdit();
1575 vlayout->addWidget( mMaxLineEdit );
1579 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( rangeParam->dataType() ) );
1581 mMinLineEdit->setText( QLocale().toString( range.at( 0 ) ) );
1582 mMaxLineEdit->setText( QLocale().toString( range.at( 1 ) ) );
1585 setLayout( vlayout );
1588QgsProcessingParameterDefinition *QgsProcessingRangeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1590 QString defaultValue;
1591 if ( mMinLineEdit->text().isEmpty() )
1593 defaultValue = QStringLiteral(
"None" );
1601 defaultValue = QStringLiteral(
"None" );
1605 if ( mMaxLineEdit->text().isEmpty() )
1607 defaultValue += QLatin1String(
",None" );
1613 defaultValue += QStringLiteral(
",%1" ).arg( ok ? QString::number( val ) : QLatin1String(
"None" ) );
1617 auto param = std::make_unique< QgsProcessingParameterRange >( name, description, dataType, defaultValue );
1618 param->setFlags( flags );
1619 return param.release();
1629QWidget *QgsProcessingRangeWidgetWrapper::createWidget()
1638 QHBoxLayout *layout =
new QHBoxLayout();
1643 mMinSpinBox->setExpressionsEnabled(
true );
1644 mMinSpinBox->setShowClearButton(
false );
1645 mMaxSpinBox->setExpressionsEnabled(
true );
1646 mMaxSpinBox->setShowClearButton(
false );
1648 QLabel *minLabel =
new QLabel( tr(
"Min" ) );
1649 layout->addWidget( minLabel );
1650 layout->addWidget( mMinSpinBox, 1 );
1652 QLabel *maxLabel =
new QLabel( tr(
"Max" ) );
1653 layout->addWidget( maxLabel );
1654 layout->addWidget( mMaxSpinBox, 1 );
1656 QWidget *w =
new QWidget();
1657 layout->setContentsMargins( 0, 0, 0, 0 );
1658 w->setLayout( layout );
1662 mMinSpinBox->setDecimals( 6 );
1663 mMaxSpinBox->setDecimals( 6 );
1667 mMinSpinBox->setDecimals( 0 );
1668 mMaxSpinBox->setDecimals( 0 );
1671 mMinSpinBox->setMinimum( -99999999.999999 );
1672 mMaxSpinBox->setMinimum( -99999999.999999 );
1673 mMinSpinBox->setMaximum( 99999999.999999 );
1674 mMaxSpinBox->setMaximum( 99999999.999999 );
1678 mAllowingNull =
true;
1680 const double min = mMinSpinBox->minimum() - 1;
1681 mMinSpinBox->setMinimum( min );
1682 mMaxSpinBox->setMinimum( min );
1683 mMinSpinBox->setValue( min );
1684 mMaxSpinBox->setValue( min );
1686 mMinSpinBox->setShowClearButton(
true );
1687 mMaxSpinBox->setShowClearButton(
true );
1688 mMinSpinBox->setSpecialValueText( tr(
"Not set" ) );
1689 mMaxSpinBox->setSpecialValueText( tr(
"Not set" ) );
1692 w->setToolTip( parameterDefinition()->toolTip() );
1694 connect( mMinSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
const double v )
1696 mBlockChangedSignal++;
1697 if ( !mAllowingNull && v > mMaxSpinBox->value() )
1698 mMaxSpinBox->setValue( v );
1699 mBlockChangedSignal--;
1701 if ( !mBlockChangedSignal )
1702 emit widgetValueHasChanged(
this );
1704 connect( mMaxSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
const double v )
1706 mBlockChangedSignal++;
1707 if ( !mAllowingNull && v < mMinSpinBox->value() )
1708 mMinSpinBox->setValue( v );
1709 mBlockChangedSignal--;
1711 if ( !mBlockChangedSignal )
1712 emit widgetValueHasChanged(
this );
1721void QgsProcessingRangeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1724 if ( mAllowingNull && v.empty() )
1726 mMinSpinBox->clear();
1727 mMaxSpinBox->clear();
1734 if ( mAllowingNull )
1736 mBlockChangedSignal++;
1737 if ( std::isnan( v.at( 0 ) ) )
1738 mMinSpinBox->clear();
1740 mMinSpinBox->setValue( v.at( 0 ) );
1742 if ( v.count() >= 2 )
1744 if ( std::isnan( v.at( 1 ) ) )
1745 mMaxSpinBox->clear();
1747 mMaxSpinBox->setValue( v.at( 1 ) );
1749 mBlockChangedSignal--;
1753 mBlockChangedSignal++;
1754 mMinSpinBox->setValue( v.at( 0 ) );
1755 if ( v.count() >= 2 )
1756 mMaxSpinBox->setValue( v.at( 1 ) );
1757 mBlockChangedSignal--;
1761 if ( !mBlockChangedSignal )
1762 emit widgetValueHasChanged(
this );
1765QVariant QgsProcessingRangeWidgetWrapper::widgetValue()
const
1767 if ( mAllowingNull )
1770 if (
qgsDoubleNear( mMinSpinBox->value(), mMinSpinBox->minimum() ) )
1771 value = QStringLiteral(
"None" );
1773 value = QString::number( mMinSpinBox->value() );
1775 if (
qgsDoubleNear( mMaxSpinBox->value(), mMaxSpinBox->minimum() ) )
1776 value += QLatin1String(
",None" );
1778 value += QStringLiteral(
",%1" ).arg( mMaxSpinBox->value() );
1783 return QStringLiteral(
"%1,%2" ).arg( mMinSpinBox->value() ).arg( mMaxSpinBox->value() );
1786QStringList QgsProcessingRangeWidgetWrapper::compatibleParameterTypes()
const
1788 return QStringList()
1793QStringList QgsProcessingRangeWidgetWrapper::compatibleOutputTypes()
const
1798QString QgsProcessingRangeWidgetWrapper::modelerExpressionFormatString()
const
1800 return tr(
"string as two comma delimited floats, e.g. '1,10'" );
1803QString QgsProcessingRangeWidgetWrapper::parameterType()
const
1810 return new QgsProcessingRangeWidgetWrapper( parameter, type );
1815 return new QgsProcessingRangeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1826 QVBoxLayout *vlayout =
new QVBoxLayout();
1827 vlayout->setContentsMargins( 0, 0, 0, 0 );
1829 mMatrixWidget =
new QgsProcessingMatrixModelerWidget();
1832 mMatrixWidget->setValue( matrixParam->headers(), matrixParam->defaultValueForGui() );
1833 mMatrixWidget->setFixedRows( matrixParam->hasFixedNumberRows() );
1835 vlayout->addWidget( mMatrixWidget );
1836 setLayout( vlayout );
1839QgsProcessingParameterDefinition *QgsProcessingMatrixParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1841 auto param = std::make_unique< QgsProcessingParameterMatrix >( name, description, 1, mMatrixWidget->fixedRows(), mMatrixWidget->headers(), mMatrixWidget->value() );
1842 param->setFlags( flags );
1843 return param.release();
1853QWidget *QgsProcessingMatrixWidgetWrapper::createWidget()
1855 mMatrixWidget =
new QgsProcessingMatrixParameterPanel(
nullptr,
dynamic_cast< const QgsProcessingParameterMatrix *
>( parameterDefinition() ) );
1856 mMatrixWidget->setToolTip( parameterDefinition()->toolTip() );
1858 connect( mMatrixWidget, &QgsProcessingMatrixParameterPanel::changed,
this, [ = ]
1860 emit widgetValueHasChanged(
this );
1869 return mMatrixWidget;
1875void QgsProcessingMatrixWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1878 if ( mMatrixWidget )
1879 mMatrixWidget->setValue( v );
1882QVariant QgsProcessingMatrixWidgetWrapper::widgetValue()
const
1884 if ( mMatrixWidget )
1885 return mMatrixWidget->value().isEmpty() ? QVariant() : mMatrixWidget->value();
1890QStringList QgsProcessingMatrixWidgetWrapper::compatibleParameterTypes()
const
1892 return QStringList()
1896QStringList QgsProcessingMatrixWidgetWrapper::compatibleOutputTypes()
const
1898 return QStringList();
1901QString QgsProcessingMatrixWidgetWrapper::modelerExpressionFormatString()
const
1903 return tr(
"comma delimited string of values, or an array of values" );
1906QString QgsProcessingMatrixWidgetWrapper::parameterType()
const
1913 return new QgsProcessingMatrixWidgetWrapper( parameter, type );
1918 return new QgsProcessingMatrixParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1930 QVBoxLayout *vlayout =
new QVBoxLayout();
1931 vlayout->setContentsMargins( 0, 0, 0, 0 );
1933 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
1935 mTypeComboBox =
new QComboBox();
1939 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( fileParam->behavior() ) );
1941 mTypeComboBox->setCurrentIndex( 0 );
1942 vlayout->addWidget( mTypeComboBox );
1944 vlayout->addWidget(
new QLabel( tr(
"File filter" ) ) );
1946 mFilterComboBox =
new QComboBox();
1947 mFilterComboBox->setEditable(
true );
1949 mFilterComboBox->addItem( tr(
"All Files (*.*)" ) );
1950 mFilterComboBox->addItem( tr(
"CSV Files (*.csv)" ) );
1951 mFilterComboBox->addItem( tr(
"HTML Files (*.html *.htm)" ) );
1952 mFilterComboBox->addItem( tr(
"Text Files (*.txt)" ) );
1954 mFilterComboBox->setCurrentText( fileParam->fileFilter() );
1956 mFilterComboBox->setCurrentIndex( 0 );
1957 vlayout->addWidget( mFilterComboBox );
1959 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1962 mDefaultFileWidget->lineEdit()->setShowClearButton(
true );
1966 mDefaultFileWidget->setFilePath( fileParam->defaultValueForGui().toString() );
1970 vlayout->addWidget( mDefaultFileWidget );
1972 connect( mTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ]
1981 setLayout( vlayout );
1984QgsProcessingParameterDefinition *QgsProcessingFileParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1986 auto param = std::make_unique< QgsProcessingParameterFile >( name, description );
1989 param->setFileFilter( mFilterComboBox->currentText() );
1990 if ( !mDefaultFileWidget->filePath().isEmpty() )
1991 param->setDefaultValue( mDefaultFileWidget->filePath() );
1992 param->setFlags( flags );
1993 return param.release();
2003QWidget *QgsProcessingFileWidgetWrapper::createWidget()
2013 mFileWidget->setToolTip( parameterDefinition()->toolTip() );
2014 mFileWidget->setDialogTitle( parameterDefinition()->description() );
2016 mFileWidget->setDefaultRoot(
QgsSettings().value( QStringLiteral(
"/Processing/LastInputPath" ), QDir::homePath() ).toString() );
2023 mFileWidget->setFilter( fileParam->
fileFilter() );
2024 else if ( !fileParam->
extension().isEmpty() )
2025 mFileWidget->setFilter( tr(
"%1 files" ).arg( fileParam->
extension().toUpper() ) + QStringLiteral(
" (*." ) + fileParam->
extension().toLower() +
')' );
2035 QgsSettings().
setValue( QStringLiteral(
"/Processing/LastInputPath" ), QFileInfo( path ).canonicalPath() );
2036 emit widgetValueHasChanged(
this );
2044void QgsProcessingFileWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2048 mFileWidget->setFilePath( v );
2051QVariant QgsProcessingFileWidgetWrapper::widgetValue()
const
2054 return mFileWidget->filePath();
2059QStringList QgsProcessingFileWidgetWrapper::compatibleParameterTypes()
const
2061 return QStringList()
2066QStringList QgsProcessingFileWidgetWrapper::compatibleOutputTypes()
const
2076QString QgsProcessingFileWidgetWrapper::modelerExpressionFormatString()
const
2078 return tr(
"string representing a path to a file or folder" );
2081QString QgsProcessingFileWidgetWrapper::parameterType()
const
2088 return new QgsProcessingFileWidgetWrapper( parameter, type );
2093 return new QgsProcessingFileParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2105 QVBoxLayout *vlayout =
new QVBoxLayout();
2106 vlayout->setContentsMargins( 0, 0, 0, 0 );
2107 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2110 mDefaultLineEdit->registerExpressionContextGenerator(
this );
2114 vlayout->addWidget( mDefaultLineEdit );
2116 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
2118 mParentLayerComboBox =
new QComboBox();
2119 mParentLayerComboBox->addItem( tr(
"None" ), QVariant() );
2121 QString initialParent;
2123 initialParent = expParam->parentLayerParameterName();
2125 if ( QgsProcessingModelAlgorithm *model = widgetContext.
model() )
2128 const QMap<QString, QgsProcessingModelParameter> components = model->parameterComponents();
2129 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
2133 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
2134 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2136 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2141 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
2142 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2144 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2150 if ( mParentLayerComboBox->count() == 1 && !initialParent.isEmpty() )
2153 mParentLayerComboBox->addItem( initialParent, initialParent );
2154 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2157 vlayout->addWidget( mParentLayerComboBox );
2158 setLayout( vlayout );
2161QgsProcessingParameterDefinition *QgsProcessingExpressionParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
2163 auto param = std::make_unique< QgsProcessingParameterExpression >( name, description, mDefaultLineEdit->expression(), mParentLayerComboBox->currentData().toString() );
2164 param->setFlags( flags );
2165 return param.release();
2174QWidget *QgsProcessingExpressionWidgetWrapper::createWidget()
2186 mExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2187 mExpLineEdit->setExpressionDialogTitle( parameterDefinition()->description() );
2188 mExpLineEdit->registerExpressionContextGenerator(
this );
2191 emit widgetValueHasChanged(
this );
2193 return mExpLineEdit;
2197 if ( expParam->
metadata().value( QStringLiteral(
"inlineEditor" ) ).toBool() )
2200 mExpBuilderWidget->setToolTip( parameterDefinition()->toolTip() );
2201 mExpBuilderWidget->init( createExpressionContext() );
2204 Q_UNUSED( changed );
2205 emit widgetValueHasChanged(
this );
2207 return mExpBuilderWidget;
2212 mFieldExpWidget->setToolTip( parameterDefinition()->toolTip() );
2213 mFieldExpWidget->setExpressionDialogTitle( parameterDefinition()->description() );
2214 mFieldExpWidget->registerExpressionContextGenerator(
this );
2216 mFieldExpWidget->setAllowEmptyFieldName(
true );
2220 emit widgetValueHasChanged(
this );
2222 return mFieldExpWidget;
2230void QgsProcessingExpressionWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
2240 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterExpression *
>( parameterDefinition() )->parentLayerParameterName() )
2242 setParentLayerWrapperValue( wrapper );
2245 setParentLayerWrapperValue( wrapper );
2261 if ( mExpBuilderWidget )
2264 mExpBuilderWidget->setExpressionContext( createExpressionContext() );
2272 std::unique_ptr< QgsProcessingContext > tmpContext;
2273 if ( mProcessingContextGenerator )
2274 context = mProcessingContextGenerator->processingContext();
2278 tmpContext = std::make_unique< QgsProcessingContext >();
2279 context = tmpContext.get();
2283 if ( val.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
2293 if ( mFieldExpWidget )
2294 mFieldExpWidget->setLayer(
nullptr );
2295 else if ( mExpBuilderWidget )
2296 mExpBuilderWidget->setLayer(
nullptr );
2297 else if ( mExpLineEdit )
2298 mExpLineEdit->setLayer(
nullptr );
2304 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
2307 mParentLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
2308 layer = mParentLayer.get();
2315 if ( mFieldExpWidget )
2316 mFieldExpWidget->setLayer( layer );
2317 if ( mExpBuilderWidget )
2318 mExpBuilderWidget->setLayer( layer );
2319 else if ( mExpLineEdit )
2320 mExpLineEdit->setLayer( layer );
2323void QgsProcessingExpressionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2326 if ( mFieldExpWidget )
2327 mFieldExpWidget->setExpression( v );
2328 else if ( mExpBuilderWidget )
2329 mExpBuilderWidget->setExpressionText( v );
2330 else if ( mExpLineEdit )
2331 mExpLineEdit->setExpression( v );
2334QVariant QgsProcessingExpressionWidgetWrapper::widgetValue()
const
2336 if ( mFieldExpWidget )
2337 return mFieldExpWidget->expression();
2338 if ( mExpBuilderWidget )
2339 return mExpBuilderWidget->expressionText();
2340 else if ( mExpLineEdit )
2341 return mExpLineEdit->expression();
2346QStringList QgsProcessingExpressionWidgetWrapper::compatibleParameterTypes()
const
2348 return QStringList()
2357QStringList QgsProcessingExpressionWidgetWrapper::compatibleOutputTypes()
const
2359 return QStringList()
2364QString QgsProcessingExpressionWidgetWrapper::modelerExpressionFormatString()
const
2366 return tr(
"string representation of an expression" );
2369const QgsVectorLayer *QgsProcessingExpressionWidgetWrapper::linkedVectorLayer()
const
2371 if ( mFieldExpWidget && mFieldExpWidget->layer() )
2372 return mFieldExpWidget->layer();
2374 if ( mExpBuilderWidget && mExpBuilderWidget->layer() )
2375 return mExpBuilderWidget->layer();
2380QString QgsProcessingExpressionWidgetWrapper::parameterType()
const
2387 return new QgsProcessingExpressionWidgetWrapper( parameter, type );
2392 return new QgsProcessingExpressionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2405 QHBoxLayout *hl =
new QHBoxLayout();
2406 hl->setContentsMargins( 0, 0, 0, 0 );
2408 mLineEdit =
new QLineEdit();
2409 mLineEdit->setEnabled(
false );
2410 hl->addWidget( mLineEdit, 1 );
2412 mToolButton =
new QToolButton();
2413 mToolButton->setText( QString( QChar( 0x2026 ) ) );
2414 hl->addWidget( mToolButton );
2420 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
2423 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingEnumPanelWidget::showDialog );
2426void QgsProcessingEnumPanelWidget::setValue(
const QVariant &value )
2428 if ( value.isValid() )
2430 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
2432 if ( mParam->usesStaticStrings() && mValue.count() == 1 && mValue.at( 0 ).toString().isEmpty() )
2438 updateSummaryText();
2442void QgsProcessingEnumPanelWidget::showDialog()
2444 QVariantList availableOptions;
2447 availableOptions.reserve( mParam->options().size() );
2449 if ( mParam->usesStaticStrings() )
2451 for ( QString o : mParam->options() )
2453 availableOptions << o;
2458 for (
int i = 0; i < mParam->options().count(); ++i )
2459 availableOptions << i;
2463 const QStringList options = mParam ? mParam->options() : QStringList();
2467 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
2468 widget->setPanelTitle( mParam->description() );
2470 if ( mParam->usesStaticStrings() )
2472 widget->setValueFormatter( [options](
const QVariant & v ) -> QString
2474 const QString i = v.toString();
2475 return options.contains( i ) ? i : QString();
2480 widget->setValueFormatter( [options](
const QVariant & v ) -> QString
2482 const int i = v.toInt();
2483 return options.size() > i ? options.at( i ) : QString();
2487 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
2489 setValue( widget->selectedOptions() );
2496 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
2498 dlg.setValueFormatter( [options](
const QVariant & v ) -> QString
2500 const int i = v.toInt();
2501 return options.size() > i ? options.at( i ) : QString();
2505 setValue( dlg.selectedOptions() );
2510void QgsProcessingEnumPanelWidget::updateSummaryText()
2515 if ( mValue.empty() )
2517 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
2522 values.reserve( mValue.size() );
2523 if ( mParam->usesStaticStrings() )
2525 for (
const QVariant &val : std::as_const( mValue ) )
2527 values << val.toString();
2532 const QStringList options = mParam->options();
2533 for (
const QVariant &val : std::as_const( mValue ) )
2535 const int i = val.toInt();
2536 values << ( options.size() > i ? options.at( i ) : QString() );
2540 const QString concatenated = values.join( tr(
"," ) );
2541 if ( concatenated.length() < 100 )
2542 mLineEdit->setText( concatenated );
2544 mLineEdit->setText( tr(
"%n option(s) selected",
nullptr, mValue.count() ) );
2552QgsProcessingEnumCheckboxPanelWidget::QgsProcessingEnumCheckboxPanelWidget( QWidget *parent,
const QgsProcessingParameterEnum *param,
int columns )
2555 , mButtonGroup( new QButtonGroup( this ) )
2556 , mColumns( columns )
2558 mButtonGroup->setExclusive( !mParam->allowMultiple() );
2560 QGridLayout *l =
new QGridLayout();
2561 l->setContentsMargins( 0, 0, 0, 0 );
2563 int rows =
static_cast< int >( std::ceil( mParam->options().count() /
static_cast< double >( mColumns ) ) );
2564 for (
int i = 0; i < mParam->options().count(); ++i )
2566 QAbstractButton *button =
nullptr;
2567 if ( mParam->allowMultiple() )
2568 button =
new QCheckBox( mParam->options().at( i ) );
2570 button =
new QRadioButton( mParam->options().at( i ) );
2572 connect( button, &QAbstractButton::toggled,
this, [ = ]
2574 if ( !mBlockChangedSignal )
2578 mButtons.insert( i, button );
2580 mButtonGroup->addButton( button, i );
2581 l->addWidget( button, i % rows, i / rows );
2583 l->addItem(
new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, mColumns );
2586 if ( mParam->allowMultiple() )
2588 setContextMenuPolicy( Qt::CustomContextMenu );
2589 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsProcessingEnumCheckboxPanelWidget::showPopupMenu );
2593QVariant QgsProcessingEnumCheckboxPanelWidget::value()
const
2595 if ( mParam->allowMultiple() )
2598 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2600 if ( it.value()->isChecked() )
2601 value.append( mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key() );
2607 if ( mParam->usesStaticStrings() )
2608 return mButtonGroup->checkedId() >= 0 ? mParam->options().at( mButtonGroup->checkedId() ) : QVariant();
2610 return mButtonGroup->checkedId() >= 0 ? mButtonGroup->checkedId() : QVariant();
2614void QgsProcessingEnumCheckboxPanelWidget::setValue(
const QVariant &value )
2616 mBlockChangedSignal =
true;
2617 if ( mParam->allowMultiple() )
2619 QVariantList selected;
2620 if ( value.isValid() )
2621 selected = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
2622 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2624 QVariant v = mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key();
2625 it.value()->setChecked( selected.contains( v ) );
2631 if ( v.type() == QVariant::List )
2632 v = v.toList().value( 0 );
2634 v = mParam->usesStaticStrings() ? mParam->options().indexOf( v.toString() ) : v;
2635 if ( mButtons.contains( v ) )
2636 mButtons.value( v )->setChecked(
true );
2638 mBlockChangedSignal =
false;
2642void QgsProcessingEnumCheckboxPanelWidget::showPopupMenu()
2645 QAction *selectAllAction =
new QAction( tr(
"Select All" ), &popupMenu );
2646 connect( selectAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::selectAll );
2647 QAction *clearAllAction =
new QAction( tr(
"Clear Selection" ), &popupMenu );
2648 connect( clearAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::deselectAll );
2649 popupMenu.addAction( selectAllAction );
2650 popupMenu.addAction( clearAllAction );
2651 popupMenu.exec( QCursor::pos() );
2654void QgsProcessingEnumCheckboxPanelWidget::selectAll()
2656 mBlockChangedSignal =
true;
2657 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2658 it.value()->setChecked(
true );
2659 mBlockChangedSignal =
false;
2663void QgsProcessingEnumCheckboxPanelWidget::deselectAll()
2665 mBlockChangedSignal =
true;
2666 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2667 it.value()->setChecked(
false );
2668 mBlockChangedSignal =
false;
2680 QVBoxLayout *vlayout =
new QVBoxLayout();
2681 vlayout->setContentsMargins( 0, 0, 0, 0 );
2683 mEnumWidget =
new QgsProcessingEnumModelerWidget();
2686 mEnumWidget->setAllowMultiple( enumParam->allowMultiple() );
2687 mEnumWidget->setOptions( enumParam->options() );
2688 mEnumWidget->setDefaultOptions( enumParam->defaultValueForGui() );
2690 vlayout->addWidget( mEnumWidget );
2691 setLayout( vlayout );
2694QgsProcessingParameterDefinition *QgsProcessingEnumParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
2696 auto param = std::make_unique< QgsProcessingParameterEnum >( name, description, mEnumWidget->options(), mEnumWidget->allowMultiple(), mEnumWidget->defaultOptions() );
2698 return param.release();
2708QWidget *QgsProcessingEnumWidgetWrapper::createWidget()
2716 if ( expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"useCheckBoxes" ),
false ).toBool() )
2718 const int columns = expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"columns" ), 2 ).toInt();
2719 mCheckboxPanel =
new QgsProcessingEnumCheckboxPanelWidget(
nullptr, expParam, columns );
2720 mCheckboxPanel->setToolTip( parameterDefinition()->toolTip() );
2721 connect( mCheckboxPanel, &QgsProcessingEnumCheckboxPanelWidget::changed,
this, [ = ]
2723 emit widgetValueHasChanged(
this );
2725 return mCheckboxPanel;
2734 mPanel =
new QgsProcessingEnumPanelWidget(
nullptr, expParam );
2735 mPanel->setToolTip( parameterDefinition()->toolTip() );
2736 connect( mPanel, &QgsProcessingEnumPanelWidget::changed,
this, [ = ]
2738 emit widgetValueHasChanged(
this );
2744 mComboBox =
new QComboBox();
2747 mComboBox->addItem( tr(
"[Not selected]" ), QVariant() );
2748 const QStringList options = expParam->
options();
2749 const QVariantList iconList = expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"icons" ) ).toList();
2750 for (
int i = 0; i < options.count(); ++i )
2752 const QIcon icon = iconList.value( i ).value< QIcon >();
2755 mComboBox->addItem( icon, options.at( i ), options.at( i ) );
2757 mComboBox->addItem( icon, options.at( i ), i );
2760 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2761 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
2763 emit widgetValueHasChanged(
this );
2772void QgsProcessingEnumWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2776 if ( !value.isValid() )
2777 mComboBox->setCurrentIndex( mComboBox->findData( QVariant() ) );
2784 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
2789 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
2793 else if ( mPanel || mCheckboxPanel )
2796 if ( value.isValid() )
2802 opts.reserve( v.size() );
2803 for ( QString i : v )
2809 opts.reserve( v.size() );
2815 mPanel->setValue( opts );
2816 else if ( mCheckboxPanel )
2817 mCheckboxPanel->setValue( opts );
2821QVariant QgsProcessingEnumWidgetWrapper::widgetValue()
const
2824 return mComboBox->currentData();
2826 return mPanel->value();
2827 else if ( mCheckboxPanel )
2828 return mCheckboxPanel->value();
2833QStringList QgsProcessingEnumWidgetWrapper::compatibleParameterTypes()
const
2835 return QStringList()
2841QStringList QgsProcessingEnumWidgetWrapper::compatibleOutputTypes()
const
2843 return QStringList()
2848QString QgsProcessingEnumWidgetWrapper::modelerExpressionFormatString()
const
2850 return tr(
"selected option index (starting from 0), array of indices, or comma separated string of options (e.g. '1,3')" );
2853QString QgsProcessingEnumWidgetWrapper::parameterType()
const
2860 return new QgsProcessingEnumWidgetWrapper( parameter, type );
2865 return new QgsProcessingEnumParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2878QWidget *QgsProcessingLayoutWidgetWrapper::createWidget()
2887 mComboBox =
new QgsLayoutComboBox(
nullptr, widgetContext().project() ? widgetContext().project()->layoutManager() : nullptr );
2892 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2895 emit widgetValueHasChanged(
this );
2902 mPlainComboBox =
new QComboBox();
2903 mPlainComboBox->setEditable(
true );
2904 mPlainComboBox->setToolTip( tr(
"Name of an existing print layout" ) );
2905 if ( widgetContext().project() )
2909 mPlainComboBox->addItem( layout->name() );
2912 connect( mPlainComboBox, &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
2914 emit widgetValueHasChanged(
this );
2916 return mPlainComboBox;
2922void QgsProcessingLayoutWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2926 if ( !value.isValid() )
2927 mComboBox->setCurrentLayout(
nullptr );
2931 mComboBox->setCurrentLayout( l );
2933 mComboBox->setCurrentLayout(
nullptr );
2936 else if ( mPlainComboBox )
2939 mPlainComboBox->setCurrentText( v );
2943QVariant QgsProcessingLayoutWidgetWrapper::widgetValue()
const
2948 return l ? l->
name() : QVariant();
2950 else if ( mPlainComboBox )
2951 return mPlainComboBox->currentText().isEmpty() ? QVariant() : mPlainComboBox->currentText();
2959 if ( mPlainComboBox && context.
project() )
2963 mPlainComboBox->addItem( layout->name() );
2967QStringList QgsProcessingLayoutWidgetWrapper::compatibleParameterTypes()
const
2969 return QStringList()
2974QStringList QgsProcessingLayoutWidgetWrapper::compatibleOutputTypes()
const
2976 return QStringList()
2980QString QgsProcessingLayoutWidgetWrapper::modelerExpressionFormatString()
const
2982 return tr(
"string representing the name of an existing print layout" );
2985QString QgsProcessingLayoutWidgetWrapper::parameterType()
const
2992 return new QgsProcessingLayoutWidgetWrapper( parameter, type );
3006 QVBoxLayout *vlayout =
new QVBoxLayout();
3007 vlayout->setContentsMargins( 0, 0, 0, 0 );
3009 vlayout->addWidget(
new QLabel( tr(
"Parent layout" ) ) );
3011 mParentLayoutComboBox =
new QComboBox();
3012 QString initialParent;
3014 initialParent = itemParam->parentLayoutParameterName();
3016 if (
auto *lModel = widgetContext.
model() )
3019 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3020 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3024 mParentLayoutComboBox-> addItem( definition->
description(), definition->
name() );
3025 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
3027 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3033 if ( mParentLayoutComboBox->count() == 0 && !initialParent.isEmpty() )
3036 mParentLayoutComboBox->addItem( initialParent, initialParent );
3037 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3040 vlayout->addWidget( mParentLayoutComboBox );
3041 setLayout( vlayout );
3043QgsProcessingParameterDefinition *QgsProcessingLayoutItemParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3045 auto param = std::make_unique< QgsProcessingParameterLayoutItem >( name, description, QVariant(), mParentLayoutComboBox->currentData().toString() );
3047 return param.release();
3057QWidget *QgsProcessingLayoutItemWidgetWrapper::createWidget()
3068 mComboBox->setAllowEmptyItem(
true );
3069 if ( layoutParam->
itemType() >= 0 )
3072 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3075 emit widgetValueHasChanged(
this );
3082 mLineEdit =
new QLineEdit();
3083 mLineEdit->setToolTip( tr(
"UUID or ID of an existing print layout item" ) );
3084 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
3086 emit widgetValueHasChanged(
this );
3094void QgsProcessingLayoutItemWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3104 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterLayoutItem *
>( parameterDefinition() )->parentLayoutParameterName() )
3106 setLayoutParameterValue( wrapper->parameterValue() );
3109 setLayoutParameterValue( wrapper->parameterValue() );
3122void QgsProcessingLayoutItemWidgetWrapper::setLayoutParameterValue(
const QVariant &value )
3128 std::unique_ptr< QgsProcessingContext > tmpContext;
3129 if ( mProcessingContextGenerator )
3130 context = mProcessingContextGenerator->processingContext();
3134 tmpContext = std::make_unique< QgsProcessingContext >();
3135 context = tmpContext.get();
3139 setLayout( layout );
3142void QgsProcessingLayoutItemWidgetWrapper::setLayout(
QgsPrintLayout *layout )
3145 mComboBox->setCurrentLayout( layout );
3148void QgsProcessingLayoutItemWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3152 if ( !value.isValid() )
3153 mComboBox->setItem(
nullptr );
3157 mComboBox->setItem( item );
3160 else if ( mLineEdit )
3163 mLineEdit->setText( v );
3167QVariant QgsProcessingLayoutItemWidgetWrapper::widgetValue()
const
3172 return i ? i->
uuid() : QVariant();
3174 else if ( mLineEdit )
3175 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3180QStringList QgsProcessingLayoutItemWidgetWrapper::compatibleParameterTypes()
const
3182 return QStringList()
3187QStringList QgsProcessingLayoutItemWidgetWrapper::compatibleOutputTypes()
const
3189 return QStringList()
3193QString QgsProcessingLayoutItemWidgetWrapper::modelerExpressionFormatString()
const
3195 return tr(
"string representing the UUID or ID of an existing print layout item" );
3198QString QgsProcessingLayoutItemWidgetWrapper::parameterType()
const
3205 return new QgsProcessingLayoutItemWidgetWrapper( parameter, type );
3210 return new QgsProcessingLayoutItemParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3217QgsProcessingPointMapTool::QgsProcessingPointMapTool(
QgsMapCanvas *canvas )
3224QgsProcessingPointMapTool::~QgsProcessingPointMapTool() =
default;
3226void QgsProcessingPointMapTool::deactivate()
3240 if ( e->button() == Qt::LeftButton )
3243 emit clicked( point );
3248void QgsProcessingPointMapTool::keyPressEvent( QKeyEvent *e )
3250 if ( e->key() == Qt::Key_Escape )
3265QgsProcessingPointPanel::QgsProcessingPointPanel( QWidget *parent )
3268 QHBoxLayout *l =
new QHBoxLayout();
3269 l->setContentsMargins( 0, 0, 0, 0 );
3271 mLineEdit->setShowClearButton(
false );
3272 l->addWidget( mLineEdit, 1 );
3273 mButton =
new QToolButton();
3274 mButton->setText( QString( QChar( 0x2026 ) ) );
3275 l->addWidget( mButton );
3278 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::changed );
3279 connect( mButton, &QToolButton::clicked,
this, &QgsProcessingPointPanel::selectOnCanvas );
3280 mButton->setVisible(
false );
3283void QgsProcessingPointPanel::setMapCanvas(
QgsMapCanvas *canvas )
3286 mButton->setVisible(
true );
3289 mTool = std::make_unique< QgsProcessingPointMapTool >( mCanvas );
3290 connect( mTool.get(), &QgsProcessingPointMapTool::clicked,
this, &QgsProcessingPointPanel::updatePoint );
3291 connect( mTool.get(), &QgsProcessingPointMapTool::complete,
this, &QgsProcessingPointPanel::pointPicked );
3294void QgsProcessingPointPanel::setAllowNull(
bool allowNull )
3296 mLineEdit->setShowClearButton( allowNull );
3299QVariant QgsProcessingPointPanel::value()
const
3301 return mLineEdit->showClearButton() && mLineEdit->text().trimmed().isEmpty() ? QVariant() : QVariant( mLineEdit->text() );
3304void QgsProcessingPointPanel::clear()
3311 QString newText = QStringLiteral(
"%1,%2" )
3312 .arg( QString::number( point.
x(),
'f' ),
3313 QString::number( point.
y(),
'f' ) );
3316 if ( mCrs.isValid() )
3318 newText += QStringLiteral(
" [%1]" ).arg( mCrs.authid() );
3320 mLineEdit->setText( newText );
3323void QgsProcessingPointPanel::selectOnCanvas()
3328 mPrevTool = mCanvas->mapTool();
3329 mCanvas->setMapTool( mTool.get() );
3331 emit toggleDialogVisibility(
false );
3334void QgsProcessingPointPanel::updatePoint(
const QgsPointXY &point )
3336 setValue( point, mCanvas->mapSettings().destinationCrs() );
3339void QgsProcessingPointPanel::pointPicked()
3344 mCanvas->setMapTool( mPrevTool );
3346 emit toggleDialogVisibility(
true );
3358 QVBoxLayout *vlayout =
new QVBoxLayout();
3359 vlayout->setContentsMargins( 0, 0, 0, 0 );
3361 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3363 mDefaultLineEdit =
new QLineEdit();
3364 mDefaultLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
3365 mDefaultLineEdit->setPlaceholderText( tr(
"Point as 'x,y'" ) );
3369 mDefaultLineEdit->setText( QStringLiteral(
"%1,%2" ).arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) ) );
3372 vlayout->addWidget( mDefaultLineEdit );
3373 setLayout( vlayout );
3376QgsProcessingParameterDefinition *QgsProcessingPointParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3378 auto param = std::make_unique< QgsProcessingParameterPoint >( name, description, mDefaultLineEdit->text() );
3380 return param.release();
3389QWidget *QgsProcessingPointWidgetWrapper::createWidget()
3397 mPanel =
new QgsProcessingPointPanel(
nullptr );
3398 if ( widgetContext().mapCanvas() )
3399 mPanel->setMapCanvas( widgetContext().mapCanvas() );
3402 mPanel->setAllowNull(
true );
3404 mPanel->setToolTip( parameterDefinition()->toolTip() );
3406 connect( mPanel, &QgsProcessingPointPanel::changed,
this, [ = ]
3408 emit widgetValueHasChanged(
this );
3412 setDialog( mDialog );
3418 mLineEdit =
new QLineEdit();
3419 mLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
3420 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
3422 emit widgetValueHasChanged(
this );
3434 mPanel->setMapCanvas( context.
mapCanvas() );
3437void QgsProcessingPointWidgetWrapper::setDialog( QDialog *dialog )
3442 connect( mPanel, &QgsProcessingPointPanel::toggleDialogVisibility, mDialog, [ = ](
bool visible )
3445 mDialog->showMinimized();
3448 mDialog->showNormal();
3450 mDialog->activateWindow();
3457void QgsProcessingPointWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3461 if ( !value.isValid() || ( value.type() == QVariant::String && value.toString().isEmpty() ) )
3467 mPanel->setValue( p,
crs );
3470 else if ( mLineEdit )
3473 mLineEdit->setText( v );
3477QVariant QgsProcessingPointWidgetWrapper::widgetValue()
const
3481 return mPanel->value();
3483 else if ( mLineEdit )
3484 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3489QStringList QgsProcessingPointWidgetWrapper::compatibleParameterTypes()
const
3491 return QStringList()
3496QStringList QgsProcessingPointWidgetWrapper::compatibleOutputTypes()
const
3498 return QStringList()
3502QString QgsProcessingPointWidgetWrapper::modelerExpressionFormatString()
const
3504 return tr(
"string of the format 'x,y' or a geometry value (centroid is used)" );
3507QString QgsProcessingPointWidgetWrapper::parameterType()
const
3514 return new QgsProcessingPointWidgetWrapper( parameter, type );
3519 return new QgsProcessingPointParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3531 QVBoxLayout *vlayout =
new QVBoxLayout();
3532 vlayout->setContentsMargins( 0, 0, 0, 0 );
3534 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3536 mDefaultLineEdit =
new QLineEdit();
3537 mDefaultLineEdit->setToolTip( tr(
"Geometry as WKT" ) );
3538 mDefaultLineEdit->setPlaceholderText( tr(
"Geometry as WKT" ) );
3543 mDefaultLineEdit->setText( g.
asWkt() );
3546 vlayout->addWidget( mDefaultLineEdit );
3547 setLayout( vlayout );
3550QgsProcessingParameterDefinition *QgsProcessingGeometryParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3552 auto param = std::make_unique< QgsProcessingParameterGeometry >( name, description, mDefaultLineEdit->text() );
3554 return param.release();
3563QWidget *QgsProcessingGeometryWidgetWrapper::createWidget()
3571 mLineEdit =
new QLineEdit();
3572 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
3573 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
3575 emit widgetValueHasChanged(
this );
3583void QgsProcessingGeometryWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3589 mLineEdit->setText( g.
asWkt() );
3595QVariant QgsProcessingGeometryWidgetWrapper::widgetValue()
const
3598 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3603QStringList QgsProcessingGeometryWidgetWrapper::compatibleParameterTypes()
const
3605 return QStringList()
3612QStringList QgsProcessingGeometryWidgetWrapper::compatibleOutputTypes()
const
3614 return QStringList()
3618QString QgsProcessingGeometryWidgetWrapper::modelerExpressionFormatString()
const
3620 return tr(
"string in the Well-Known-Text format or a geometry value" );
3623QString QgsProcessingGeometryWidgetWrapper::parameterType()
const
3630 return new QgsProcessingGeometryWidgetWrapper( parameter, type );
3635 return new QgsProcessingGeometryParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3647 QVBoxLayout *vlayout =
new QVBoxLayout();
3648 vlayout->setContentsMargins( 0, 0, 0, 0 );
3650 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3653 mDefaultColorButton->setShowNull(
true );
3654 mAllowOpacity =
new QCheckBox( tr(
"Allow opacity control" ) );
3660 mDefaultColorButton->setToNull();
3662 mDefaultColorButton->setColor(
c );
3663 mAllowOpacity->setChecked( colorParam->opacityEnabled() );
3667 mDefaultColorButton->setToNull();
3668 mAllowOpacity->setChecked(
true );
3671 vlayout->addWidget( mDefaultColorButton );
3672 vlayout->addWidget( mAllowOpacity );
3673 setLayout( vlayout );
3676QgsProcessingParameterDefinition *QgsProcessingColorParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3678 auto param = std::make_unique< QgsProcessingParameterColor >( name, description, mDefaultColorButton->color(), mAllowOpacity->isChecked() );
3680 return param.release();
3689QWidget *QgsProcessingColorWidgetWrapper::createWidget()
3699 mColorButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
3702 mColorButton->setShowNull(
true );
3705 mColorButton->setToolTip( parameterDefinition()->toolTip() );
3706 mColorButton->setColorDialogTitle( parameterDefinition()->description() );
3714 emit widgetValueHasChanged(
this );
3717 return mColorButton;
3723void QgsProcessingColorWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3727 if ( !value.isValid() ||
3728 ( value.type() == QVariant::String && value.toString().isEmpty() )
3729 || ( value.type() == QVariant::Color && !value.value< QColor >().isValid() ) )
3730 mColorButton->setToNull();
3734 if ( !
c.isValid() && mColorButton->showNull() )
3735 mColorButton->setToNull();
3737 mColorButton->setColor(
c );
3742QVariant QgsProcessingColorWidgetWrapper::widgetValue()
const
3745 return mColorButton->isNull() ? QVariant() : mColorButton->color();
3750QStringList QgsProcessingColorWidgetWrapper::compatibleParameterTypes()
const
3752 return QStringList()
3757QStringList QgsProcessingColorWidgetWrapper::compatibleOutputTypes()
const
3759 return QStringList()
3763QString QgsProcessingColorWidgetWrapper::modelerExpressionFormatString()
const
3765 return tr(
"color style string, e.g. #ff0000 or 255,0,0" );
3768QString QgsProcessingColorWidgetWrapper::parameterType()
const
3775 return new QgsProcessingColorWidgetWrapper( parameter, type );
3780 return new QgsProcessingColorParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3791 QVBoxLayout *vlayout =
new QVBoxLayout();
3792 vlayout->setContentsMargins( 0, 0, 0, 0 );
3794 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3796 mDefaultLineEdit =
new QLineEdit();
3799 vlayout->addWidget( mDefaultLineEdit );
3801 mSourceParamComboBox =
new QComboBox();
3802 mDestParamComboBox =
new QComboBox();
3803 QString initialSource;
3804 QString initialDest;
3809 initialSource = itemParam->sourceCrsParameterName();
3810 initialDest = itemParam->destinationCrsParameterName();
3815 mSourceParamComboBox->addItem( QString(), QString() );
3816 mDestParamComboBox->addItem( QString(), QString() );
3817 if (
auto *lModel = widgetContext.
model() )
3820 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3821 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3823 if ( definition && it->parameterName() == definition->
name() )
3827 mSourceParamComboBox->addItem( it->parameterName(), it->parameterName() );
3828 mDestParamComboBox->addItem( it->parameterName(), it->parameterName() );
3829 if ( !initialSource.isEmpty() && initialSource == it->parameterName() )
3831 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
3833 if ( !initialDest.isEmpty() && initialDest == it->parameterName() )
3835 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
3840 if ( mSourceParamComboBox->count() == 1 && !initialSource.isEmpty() )
3843 mSourceParamComboBox->addItem( initialSource, initialSource );
3844 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
3846 if ( mDestParamComboBox->count() == 1 && !initialDest.isEmpty() )
3849 mDestParamComboBox->addItem( initialDest, initialDest );
3850 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
3853 vlayout->addWidget(
new QLabel( tr(
"Source CRS parameter" ) ) );
3854 vlayout->addWidget( mSourceParamComboBox );
3855 vlayout->addWidget(
new QLabel( tr(
"Destination CRS parameter" ) ) );
3856 vlayout->addWidget( mDestParamComboBox );
3860 mStaticSourceWidget->setCrs( sourceCrs );
3863 mStaticDestWidget->setCrs( destCrs );
3865 vlayout->addWidget(
new QLabel( tr(
"Static source CRS" ) ) );
3866 vlayout->addWidget( mStaticSourceWidget );
3867 vlayout->addWidget(
new QLabel( tr(
"Static destination CRS" ) ) );
3868 vlayout->addWidget( mStaticDestWidget );
3870 setLayout( vlayout );
3873QgsProcessingParameterDefinition *QgsProcessingCoordinateOperationParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3875 auto param = std::make_unique< QgsProcessingParameterCoordinateOperation >( name, description, mDefaultLineEdit->text(),
3876 mSourceParamComboBox->currentText(),
3877 mDestParamComboBox->currentText(),
3878 mStaticSourceWidget->crs().isValid() ? QVariant::fromValue( mStaticSourceWidget->crs() ) : QVariant(),
3879 mStaticDestWidget->
crs().isValid() ? QVariant::fromValue( mStaticDestWidget->
crs() ) : QVariant() );
3881 return param.release();
3890QWidget *QgsProcessingCoordinateOperationWidgetWrapper::createWidget()
3901 mOperationWidget->setShowMakeDefault(
false );
3902 mOperationWidget->setShowFallbackOption(
false );
3903 mOperationWidget->setToolTip( parameterDefinition()->toolTip() );
3904 mOperationWidget->setSourceCrs( mSourceCrs );
3905 mOperationWidget->setDestinationCrs( mDestCrs );
3906 mOperationWidget->setMapCanvas( mCanvas );
3911 mOperationWidget->setSelectedOperation( deets );
3916 emit widgetValueHasChanged(
this );
3919 return mOperationWidget;
3925 mLineEdit =
new QLineEdit();
3926 QHBoxLayout *layout =
new QHBoxLayout();
3927 layout->addWidget( mLineEdit, 1 );
3928 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
3930 emit widgetValueHasChanged(
this );
3933 QToolButton *button =
new QToolButton();
3934 button->setText( QString( QChar( 0x2026 ) ) );
3935 connect( button, &QToolButton::clicked,
this, [ = ]
3937 QgsDatumTransformDialog dlg( mSourceCrs, mDestCrs,
false,
false,
false, qMakePair( -1, -1 ), button, Qt::WindowFlags(), mLineEdit->text(), mCanvas );
3940 mLineEdit->setText( dlg.selectedDatumTransform().proj );
3941 emit widgetValueHasChanged(
this );
3944 layout->addWidget( button );
3946 QWidget *w =
new QWidget();
3947 layout->setContentsMargins( 0, 0, 0, 0 );
3948 w->setLayout( layout );
3956void QgsProcessingCoordinateOperationWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3968 setSourceCrsParameterValue( wrapper->parameterValue() );
3971 setSourceCrsParameterValue( wrapper->parameterValue() );
3976 setDestinationCrsParameterValue( wrapper->parameterValue() );
3979 setDestinationCrsParameterValue( wrapper->parameterValue() );
3994 if ( mOperationWidget )
3995 mOperationWidget->setMapCanvas( context.
mapCanvas() );
3998void QgsProcessingCoordinateOperationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
4000 if ( mOperationWidget )
4002 if ( !value.isValid() ||
4003 ( value.type() == QVariant::String ) )
4006 deets.
proj = value.toString();
4007 mOperationWidget->setSelectedOperation( deets );
4012 if ( !value.isValid() ||
4013 ( value.type() == QVariant::String ) )
4015 mLineEdit->setText( value.toString() );
4020QVariant QgsProcessingCoordinateOperationWidgetWrapper::widgetValue()
const
4022 if ( mOperationWidget )
4023 return mOperationWidget->selectedOperation().proj;
4024 else if ( mLineEdit )
4025 return mLineEdit->text();
4030QStringList QgsProcessingCoordinateOperationWidgetWrapper::compatibleParameterTypes()
const
4032 return QStringList()
4037QStringList QgsProcessingCoordinateOperationWidgetWrapper::compatibleOutputTypes()
const
4039 return QStringList()
4043QString QgsProcessingCoordinateOperationWidgetWrapper::modelerExpressionFormatString()
const
4045 return tr(
"Proj coordinate operation string, e.g. '+proj=pipeline +step +inv...'" );
4048void QgsProcessingCoordinateOperationWidgetWrapper::setSourceCrsParameterValue(
const QVariant &value )
4051 std::unique_ptr< QgsProcessingContext > tmpContext;
4052 if ( mProcessingContextGenerator )
4053 context = mProcessingContextGenerator->processingContext();
4057 tmpContext = std::make_unique< QgsProcessingContext >();
4058 context = tmpContext.get();
4062 if ( mOperationWidget )
4064 mOperationWidget->setSourceCrs( mSourceCrs );
4065 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4069void QgsProcessingCoordinateOperationWidgetWrapper::setDestinationCrsParameterValue(
const QVariant &value )
4072 std::unique_ptr< QgsProcessingContext > tmpContext;
4073 if ( mProcessingContextGenerator )
4074 context = mProcessingContextGenerator->processingContext();
4078 tmpContext = std::make_unique< QgsProcessingContext >();
4079 context = tmpContext.get();
4083 if ( mOperationWidget )
4085 mOperationWidget->setDestinationCrs( mDestCrs );
4086 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4090QString QgsProcessingCoordinateOperationWidgetWrapper::parameterType()
const
4097 return new QgsProcessingCoordinateOperationWidgetWrapper( parameter, type );
4102 return new QgsProcessingCoordinateOperationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4115 QHBoxLayout *hl =
new QHBoxLayout();
4116 hl->setContentsMargins( 0, 0, 0, 0 );
4118 mLineEdit =
new QLineEdit();
4119 mLineEdit->setEnabled(
false );
4120 hl->addWidget( mLineEdit, 1 );
4122 mToolButton =
new QToolButton();
4123 mToolButton->setText( QString( QChar( 0x2026 ) ) );
4124 hl->addWidget( mToolButton );
4130 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4133 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingFieldPanelWidget::showDialog );
4136void QgsProcessingFieldPanelWidget::setFields(
const QgsFields &fields )
4141void QgsProcessingFieldPanelWidget::setValue(
const QVariant &value )
4143 if ( value.isValid() )
4144 mValue = value.type() == QVariant::List ? value.
toList() : QVariantList() << value;
4148 updateSummaryText();
4152void QgsProcessingFieldPanelWidget::showDialog()
4154 QVariantList availableOptions;
4155 QStringList fieldNames;
4156 availableOptions.reserve( mFields.size() );
4165 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
4166 widget->setPanelTitle( mParam->description() );
4168 widget->setValueFormatter( [](
const QVariant & v ) -> QString
4170 return v.toString();
4173 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
4175 setValue( widget->selectedOptions() );
4182 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
4184 dlg.setValueFormatter( [](
const QVariant & v ) -> QString
4186 return v.toString();
4190 setValue( dlg.selectedOptions() );
4195void QgsProcessingFieldPanelWidget::updateSummaryText()
4200 if ( mValue.empty() )
4202 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4207 values.reserve( mValue.size() );
4208 for (
const QVariant &val : std::as_const( mValue ) )
4210 values << val.toString();
4213 const QString concatenated = values.join( tr(
"," ) );
4214 if ( concatenated.length() < 100 )
4215 mLineEdit->setText( concatenated );
4217 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, mValue.count() ) );
4229 QVBoxLayout *vlayout =
new QVBoxLayout();
4230 vlayout->setContentsMargins( 0, 0, 0, 0 );
4232 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
4233 mParentLayerComboBox =
new QComboBox();
4235 QString initialParent;
4237 initialParent = fieldParam->parentLayerParameterName();
4239 if (
auto *lModel = widgetContext.
model() )
4242 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4243 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4247 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
4248 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4250 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4255 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
4256 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4258 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4265 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
4266 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4268 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4275 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
4278 mParentLayerComboBox->addItem( initialParent, initialParent );
4279 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4282 vlayout->addWidget( mParentLayerComboBox );
4284 vlayout->addWidget(
new QLabel( tr(
"Allowed data type" ) ) );
4285 mDataTypeComboBox =
new QComboBox();
4291 mDataTypeComboBox->setCurrentIndex( mDataTypeComboBox->findData( fieldParam->dataType() ) );
4293 vlayout->addWidget( mDataTypeComboBox );
4295 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple fields" ) );
4297 mAllowMultipleCheckBox->setChecked( fieldParam->allowMultiple() );
4299 vlayout->addWidget( mAllowMultipleCheckBox );
4301 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all fields by default" ) );
4302 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
4304 mDefaultToAllCheckBox->setChecked( fieldParam->defaultToAllFields() );
4306 vlayout->addWidget( mDefaultToAllCheckBox );
4308 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [ = ]
4310 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
4313 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4315 mDefaultLineEdit =
new QLineEdit();
4316 mDefaultLineEdit->setToolTip( tr(
"Default field name, or ; separated list of field names for multiple field parameters" ) );
4320 mDefaultLineEdit->setText( fields.join(
';' ) );
4322 vlayout->addWidget( mDefaultLineEdit );
4324 setLayout( vlayout );
4327QgsProcessingParameterDefinition *QgsProcessingFieldParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4331 QVariant defaultValue;
4332 if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
4334 defaultValue = mDefaultLineEdit->text();
4336 auto param = std::make_unique< QgsProcessingParameterField >( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), dataType, mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
4338 return param.release();
4347QWidget *QgsProcessingFieldWidgetWrapper::createWidget()
4357 mPanel =
new QgsProcessingFieldPanelWidget(
nullptr, fieldParam );
4358 mPanel->setToolTip( parameterDefinition()->toolTip() );
4359 connect( mPanel, &QgsProcessingFieldPanelWidget::changed,
this, [ = ]
4361 emit widgetValueHasChanged(
this );
4377 mComboBox->setToolTip( parameterDefinition()->toolTip() );
4380 emit widgetValueHasChanged(
this );
4388 mLineEdit =
new QLineEdit();
4389 mLineEdit->setToolTip( QObject::tr(
"Name of field (separate field names with ; for multiple field parameters)" ) );
4390 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
4392 emit widgetValueHasChanged(
this );
4401void QgsProcessingFieldWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
4411 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterField *
>( parameterDefinition() )->parentLayerParameterName() )
4413 setParentLayerWrapperValue( wrapper );
4416 setParentLayerWrapperValue( wrapper );
4433 std::unique_ptr< QgsProcessingContext > tmpContext;
4434 if ( mProcessingContextGenerator )
4435 context = mProcessingContextGenerator->processingContext();
4439 tmpContext = std::make_unique< QgsProcessingContext >();
4440 context = tmpContext.get();
4445 if ( value.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
4455 bool valueSet =
false;
4459 if ( layers.count() > 1 )
4461 QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( layers.at( 0 ) );
4463 const QList< QgsMapLayer * > remainingLayers = layers.mid( 1 );
4469 QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( layer );
4470 if ( !vlayer || !vlayer->
isValid() )
4476 for (
int fieldIdx = fields.
count() - 1; fieldIdx >= 0; fieldIdx-- )
4479 fields.
remove( fieldIdx );
4484 mComboBox->setFields( fields );
4486 mPanel->setFields( filterFields( fields ) );
4492 if ( !valueSet && !layers.isEmpty() && layers.at( 0 )->isValid() )
4494 QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( layers.at( 0 ) );
4498 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
4501 mParentLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
4502 layer = mParentLayer.get();
4510 mComboBox->setLayer( layer );
4512 mPanel->setFields( filterFields( layer->
fields() ) );
4522 const QgsFields fields = source->fields();
4524 mComboBox->setFields( fields );
4526 mPanel->setFields( filterFields( fields ) );
4535 mComboBox->setLayer(
nullptr );
4539 if ( value.isValid() && widgetContext().messageBar() )
4542 widgetContext().
messageBar()->
pushMessage( QString(), QObject::tr(
"Could not load selected layer/table. Dependent field could not be populated" ),
4552 val.reserve( mPanel->fields().size() );
4554 val <<
field.name();
4555 setWidgetValue( val, *context );
4558 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
4561void QgsProcessingFieldWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4565 if ( !value.isValid() )
4566 mComboBox->setField( QString() );
4570 mComboBox->setField( v );
4576 if ( value.isValid() )
4579 opts.reserve( v.size() );
4580 for (
const QString &i : v )
4584 mPanel->setValue( opts );
4586 else if ( mLineEdit )
4592 mLineEdit->setText( v.join(
';' ) );
4601QVariant QgsProcessingFieldWidgetWrapper::widgetValue()
const
4604 return mComboBox->currentField();
4606 return mPanel->value();
4607 else if ( mLineEdit )
4612 return mLineEdit->text().split(
';' );
4615 return mLineEdit->text();
4621QStringList QgsProcessingFieldWidgetWrapper::compatibleParameterTypes()
const
4623 return QStringList()
4628QStringList QgsProcessingFieldWidgetWrapper::compatibleOutputTypes()
const
4630 return QStringList()
4634QString QgsProcessingFieldWidgetWrapper::modelerExpressionFormatString()
const
4636 return tr(
"selected field names as an array of names, or semicolon separated string of options (e.g. 'fid;place_name')" );
4639const QgsVectorLayer *QgsProcessingFieldWidgetWrapper::linkedVectorLayer()
const
4641 if ( mComboBox && mComboBox->layer() )
4642 return mComboBox->layer();
4647QgsFields QgsProcessingFieldWidgetWrapper::filterFields(
const QgsFields &fields )
const
4660 if ( f.isNumeric() )
4665 if ( f.type() == QVariant::String )
4670 if ( f.type() == QVariant::Date || f.type() == QVariant::Time || f.type() == QVariant::DateTime )
4679QString QgsProcessingFieldWidgetWrapper::parameterType()
const
4686 return new QgsProcessingFieldWidgetWrapper( parameter, type );
4691 return new QgsProcessingFieldParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4702 QVBoxLayout *vlayout =
new QVBoxLayout();
4703 vlayout->setContentsMargins( 0, 0, 0, 0 );
4705 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4707 mDefaultComboBox =
new QComboBox();
4708 mDefaultComboBox->addItem( QString(), QVariant( -1 ) );
4711 for (
const QString &theme : mapThemes )
4715 mDefaultComboBox->setEditable(
true );
4719 if ( themeParam->defaultValueForGui().isValid() )
4722 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
4725 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
4727 vlayout->addWidget( mDefaultComboBox );
4729 setLayout( vlayout );
4732QgsProcessingParameterDefinition *QgsProcessingMapThemeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4734 QVariant defaultVal;
4735 if ( mDefaultComboBox->currentText().isEmpty() )
4736 defaultVal = QVariant();
4738 defaultVal = mDefaultComboBox->currentText();
4739 auto param = std::make_unique< QgsProcessingParameterMapTheme>( name, description, defaultVal );
4741 return param.release();
4751QWidget *QgsProcessingMapThemeWidgetWrapper::createWidget()
4755 mComboBox =
new QComboBox();
4758 mComboBox->addItem( tr(
"[Not selected]" ), QVariant( -1 ) );
4761 for (
const QString &theme : mapThemes )
4773 mComboBox->setEditable(
true );
4777 mComboBox->setToolTip( parameterDefinition()->toolTip() );
4778 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
4780 emit widgetValueHasChanged(
this );
4786void QgsProcessingMapThemeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4790 if ( !value.isValid() )
4791 mComboBox->setCurrentIndex( mComboBox->findData( QVariant( -1 ) ) );
4794 if ( mComboBox->isEditable() && mComboBox->findData( v ) == -1 )
4796 const QString prev = mComboBox->currentText();
4797 mComboBox->setCurrentText( v );
4799 emit widgetValueHasChanged(
this );
4802 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
4806QVariant QgsProcessingMapThemeWidgetWrapper::widgetValue()
const
4809 return mComboBox->currentData().toInt() == -1 ? QVariant() :
4810 !mComboBox->currentData().isValid() && mComboBox->isEditable() ? mComboBox->currentText().isEmpty() ? QVariant() : QVariant( mComboBox->currentText() )
4811 : mComboBox->currentData();
4816QStringList QgsProcessingMapThemeWidgetWrapper::compatibleParameterTypes()
const
4818 return QStringList()
4823QStringList QgsProcessingMapThemeWidgetWrapper::compatibleOutputTypes()
const
4825 return QStringList()
4829QString QgsProcessingMapThemeWidgetWrapper::modelerExpressionFormatString()
const
4831 return tr(
"map theme as a string value (e.g. 'base maps')" );
4834QString QgsProcessingMapThemeWidgetWrapper::parameterType()
const
4841 return new QgsProcessingMapThemeWidgetWrapper( parameter, type );
4846 return new QgsProcessingMapThemeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4859 QVBoxLayout *vlayout =
new QVBoxLayout();
4860 vlayout->setContentsMargins( 0, 0, 0, 0 );
4862 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
4864 mTypeComboBox =
new QComboBox();
4869 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( datetimeParam->dataType() ) );
4871 mTypeComboBox->setCurrentIndex( 0 );
4872 vlayout->addWidget( mTypeComboBox );
4874 setLayout( vlayout );
4877QgsProcessingParameterDefinition *QgsProcessingDateTimeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4879 auto param = std::make_unique< QgsProcessingParameterDateTime >( name, description );
4882 return param.release();
4892QWidget *QgsProcessingDateTimeWidgetWrapper::createWidget()
4897 switch ( dateTimeParam->
dataType() )
4901 widget = mDateTimeEdit;
4924 widget->setToolTip( parameterDefinition()->toolTip() );
4926 if ( mDateTimeEdit )
4930 emit widgetValueHasChanged(
this );
4933 else if ( mDateEdit )
4937 emit widgetValueHasChanged(
this );
4940 else if ( mTimeEdit )
4944 emit widgetValueHasChanged(
this );
4953 return new QgsProcessingDateTimeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4956void QgsProcessingDateTimeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4958 if ( mDateTimeEdit )
4962 else if ( mDateEdit )
4966 else if ( mTimeEdit )
4972QVariant QgsProcessingDateTimeWidgetWrapper::widgetValue()
const
4974 if ( mDateTimeEdit )
4975 return !mDateTimeEdit->dateTime().isNull() && mDateTimeEdit->dateTime().isValid() ? QVariant( mDateTimeEdit->dateTime() ) : QVariant();
4976 else if ( mDateEdit )
4977 return !mDateEdit->date().isNull() && mDateEdit->date().isValid() ? QVariant( mDateEdit->date() ) : QVariant();
4978 else if ( mTimeEdit )
4979 return !mTimeEdit->time().isNull() && mTimeEdit->time().isValid() ? QVariant( mTimeEdit->time() ) : QVariant();
4984QStringList QgsProcessingDateTimeWidgetWrapper::compatibleParameterTypes()
const
4986 return QStringList()
4991QStringList QgsProcessingDateTimeWidgetWrapper::compatibleOutputTypes()
const
4993 return QStringList()
4997QString QgsProcessingDateTimeWidgetWrapper::modelerExpressionFormatString()
const
5000 if ( dateTimeParam )
5002 switch ( dateTimeParam->
dataType() )
5005 return tr(
"datetime value, or a ISO string representation of a datetime" );
5008 return tr(
"date value, or a ISO string representation of a date" );
5011 return tr(
"time value, or a ISO string representation of a time" );
5017QString QgsProcessingDateTimeWidgetWrapper::parameterType()
const
5024 return new QgsProcessingDateTimeWidgetWrapper( parameter, type );
5038 QVBoxLayout *vlayout =
new QVBoxLayout();
5039 vlayout->setContentsMargins( 0, 0, 0, 0 );
5041 vlayout->addWidget(
new QLabel( tr(
"Provider" ) ) );
5042 mProviderComboBox =
new QComboBox();
5043 mProviderComboBox->addItem( QObject::tr(
"Postgres" ), QStringLiteral(
"postgres" ) );
5044 mProviderComboBox->addItem( QObject::tr(
"GeoPackage" ), QStringLiteral(
"ogr" ) );
5045 mProviderComboBox->addItem( QObject::tr(
"Spatialite" ), QStringLiteral(
"spatialite" ) );
5047 vlayout->addWidget( mProviderComboBox );
5049 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5051 mDefaultEdit =
new QLineEdit();
5052 vlayout->addWidget( mDefaultEdit );
5053 setLayout( vlayout );
5055 if ( connectionParam )
5057 mProviderComboBox->setCurrentIndex( mProviderComboBox->findData( connectionParam->
providerId() ) );
5062QgsProcessingParameterDefinition *QgsProcessingProviderConnectionParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5064 QVariant defaultVal;
5065 if ( mDefaultEdit->text().isEmpty() )
5066 defaultVal = QVariant();
5068 defaultVal = mDefaultEdit->text();
5069 auto param = std::make_unique< QgsProcessingParameterProviderConnection>( name, description, mProviderComboBox->currentData().toString(), defaultVal );
5071 return param.release();
5081QWidget *QgsProcessingProviderConnectionWidgetWrapper::createWidget()
5087 mProviderComboBox->setAllowEmptyConnection(
true );
5095 mProviderComboBox->setEditable(
true );
5099 mProviderComboBox->setToolTip( parameterDefinition()->toolTip() );
5100 connect( mProviderComboBox, &QgsProviderConnectionComboBox::currentTextChanged,
this, [ = ](
const QString & )
5102 if ( mBlockSignals )
5105 emit widgetValueHasChanged(
this );
5108 return mProviderComboBox;
5113 return new QgsProcessingProviderConnectionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5116void QgsProcessingProviderConnectionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5120 if ( !value.isValid() )
5121 mProviderComboBox->setCurrentIndex( -1 );
5124 if ( mProviderComboBox->isEditable() )
5126 const QString prev = mProviderComboBox->currentText();
5128 mProviderComboBox->setConnection( v );
5129 mProviderComboBox->setCurrentText( v );
5133 emit widgetValueHasChanged(
this );
5136 mProviderComboBox->setConnection( v );
5140QVariant QgsProcessingProviderConnectionWidgetWrapper::widgetValue()
const
5142 if ( mProviderComboBox )
5143 if ( mProviderComboBox->isEditable() )
5144 return mProviderComboBox->currentText().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentText() );
5146 return mProviderComboBox->currentConnection().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentConnection() );
5151QStringList QgsProcessingProviderConnectionWidgetWrapper::compatibleParameterTypes()
const
5153 return QStringList()
5159QStringList QgsProcessingProviderConnectionWidgetWrapper::compatibleOutputTypes()
const
5161 return QStringList()
5165QString QgsProcessingProviderConnectionWidgetWrapper::modelerExpressionFormatString()
const
5167 return tr(
"connection name as a string value" );
5170QString QgsProcessingProviderConnectionWidgetWrapper::parameterType()
const
5177 return new QgsProcessingProviderConnectionWidgetWrapper( parameter, type );
5192 QVBoxLayout *vlayout =
new QVBoxLayout();
5193 vlayout->setContentsMargins( 0, 0, 0, 0 );
5195 mConnectionParamComboBox =
new QComboBox();
5196 QString initialConnection;
5202 if (
auto *lModel = widgetContext.
model() )
5205 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
5206 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
5208 if ( definition && it->parameterName() == definition->
name() )
5214 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
5215 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5217 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5222 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
5225 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
5226 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5229 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
5230 vlayout->addWidget( mConnectionParamComboBox );
5232 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5234 mDefaultEdit =
new QLineEdit();
5235 vlayout->addWidget( mDefaultEdit );
5236 setLayout( vlayout );
5244QgsProcessingParameterDefinition *QgsProcessingDatabaseSchemaParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5246 QVariant defaultVal;
5247 if ( mDefaultEdit->text().isEmpty() )
5248 defaultVal = QVariant();
5250 defaultVal = mDefaultEdit->text();
5251 auto param = std::make_unique< QgsProcessingParameterDatabaseSchema>( name, description, mConnectionParamComboBox->currentData().toString(), defaultVal );
5253 return param.release();
5263QWidget *QgsProcessingDatabaseSchemaWidgetWrapper::createWidget()
5269 mSchemaComboBox->setAllowEmptySchema(
true );
5277 mSchemaComboBox->comboBox()->setEditable(
true );
5281 mSchemaComboBox->setToolTip( parameterDefinition()->toolTip() );
5282 connect( mSchemaComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
5284 if ( mBlockSignals )
5287 emit widgetValueHasChanged( this );
5290 return mSchemaComboBox;
5295 return new QgsProcessingDatabaseSchemaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5302 std::unique_ptr< QgsProcessingContext > tmpContext;
5303 if ( mProcessingContextGenerator )
5304 context = mProcessingContextGenerator->processingContext();
5308 tmpContext = std::make_unique< QgsProcessingContext >();
5309 context = tmpContext.get();
5315 if ( mSchemaComboBox )
5316 mSchemaComboBox->setConnectionName( connection, qgis::down_cast< const QgsProcessingParameterProviderConnection * >( parentWrapper->
parameterDefinition() )->providerId() );
5320 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5323void QgsProcessingDatabaseSchemaWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5327 if ( !value.isValid() )
5328 mSchemaComboBox->comboBox()->setCurrentIndex( -1 );
5331 if ( mSchemaComboBox->comboBox()->isEditable() )
5333 const QString prev = mSchemaComboBox->comboBox()->currentText();
5335 mSchemaComboBox->setSchema( v );
5336 mSchemaComboBox->comboBox()->setCurrentText( v );
5340 emit widgetValueHasChanged(
this );
5343 mSchemaComboBox->setSchema( v );
5347QVariant QgsProcessingDatabaseSchemaWidgetWrapper::widgetValue()
const
5349 if ( mSchemaComboBox )
5350 if ( mSchemaComboBox->comboBox()->isEditable() )
5351 return mSchemaComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->comboBox()->currentText() );
5353 return mSchemaComboBox->currentSchema().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->currentSchema() );
5358QStringList QgsProcessingDatabaseSchemaWidgetWrapper::compatibleParameterTypes()
const
5360 return QStringList()
5366QStringList QgsProcessingDatabaseSchemaWidgetWrapper::compatibleOutputTypes()
const
5368 return QStringList()
5372QString QgsProcessingDatabaseSchemaWidgetWrapper::modelerExpressionFormatString()
const
5374 return tr(
"database schema name as a string value" );
5377QString QgsProcessingDatabaseSchemaWidgetWrapper::parameterType()
const
5384 return new QgsProcessingDatabaseSchemaWidgetWrapper( parameter, type );
5387void QgsProcessingDatabaseSchemaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5399 setParentConnectionWrapperValue( wrapper );
5402 setParentConnectionWrapperValue( wrapper );
5426 QVBoxLayout *vlayout =
new QVBoxLayout();
5427 vlayout->setContentsMargins( 0, 0, 0, 0 );
5429 mConnectionParamComboBox =
new QComboBox();
5430 mSchemaParamComboBox =
new QComboBox();
5431 QString initialConnection;
5432 QString initialSchema;
5439 if (
auto *lModel = widgetContext.
model() )
5442 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
5443 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
5445 if ( definition && it->parameterName() == definition->
name() )
5450 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
5451 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5453 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5458 mSchemaParamComboBox->addItem( it->parameterName(), it->parameterName() );
5459 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5461 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
5467 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
5470 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
5471 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5474 if ( mSchemaParamComboBox->count() == 0 && !initialSchema.isEmpty() )
5477 mSchemaParamComboBox->addItem( initialSchema, initialSchema );
5478 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
5481 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
5482 vlayout->addWidget( mConnectionParamComboBox );
5484 vlayout->addWidget(
new QLabel( tr(
"Database schema parameter" ) ) );
5485 vlayout->addWidget( mSchemaParamComboBox );
5487 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5489 mDefaultEdit =
new QLineEdit();
5490 vlayout->addWidget( mDefaultEdit );
5491 setLayout( vlayout );
5499QgsProcessingParameterDefinition *QgsProcessingDatabaseTableParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5501 QVariant defaultVal;
5502 if ( mDefaultEdit->text().isEmpty() )
5503 defaultVal = QVariant();
5505 defaultVal = mDefaultEdit->text();
5506 auto param = std::make_unique< QgsProcessingParameterDatabaseTable>( name, description,
5507 mConnectionParamComboBox->currentData().toString(),
5508 mSchemaParamComboBox->currentData().toString(),
5511 return param.release();
5521QWidget *QgsProcessingDatabaseTableWidgetWrapper::createWidget()
5527 mTableComboBox->setAllowEmptyTable(
true );
5530 mTableComboBox->comboBox()->setEditable(
true );
5532 mTableComboBox->setToolTip( parameterDefinition()->toolTip() );
5533 connect( mTableComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
5535 if ( mBlockSignals )
5538 emit widgetValueHasChanged( this );
5541 return mTableComboBox;
5546 return new QgsProcessingDatabaseTableParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5553 std::unique_ptr< QgsProcessingContext > tmpContext;
5554 if ( mProcessingContextGenerator )
5555 context = mProcessingContextGenerator->processingContext();
5559 tmpContext = std::make_unique< QgsProcessingContext >();
5560 context = tmpContext.get();
5565 mProvider = qgis::down_cast< const QgsProcessingParameterProviderConnection * >( parentWrapper->
parameterDefinition() )->providerId();
5566 if ( mTableComboBox && !mSchema.isEmpty() )
5568 mTableComboBox->setSchema( mSchema );
5569 mTableComboBox->setConnectionName( mConnection, mProvider );
5573 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5581 std::unique_ptr< QgsProcessingContext > tmpContext;
5582 if ( mProcessingContextGenerator )
5583 context = mProcessingContextGenerator->processingContext();
5587 tmpContext = std::make_unique< QgsProcessingContext >();
5588 context = tmpContext.get();
5594 if ( mTableComboBox && !mSchema.isEmpty() && !mConnection.isEmpty() )
5596 mTableComboBox->setSchema( mSchema );
5597 mTableComboBox->setConnectionName( mConnection, mProvider );
5601 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5606void QgsProcessingDatabaseTableWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5610 if ( !value.isValid() )
5611 mTableComboBox->comboBox()->setCurrentIndex( -1 );
5614 if ( mTableComboBox->comboBox()->isEditable() )
5616 const QString prev = mTableComboBox->comboBox()->currentText();
5618 mTableComboBox->setTable( v );
5619 mTableComboBox->comboBox()->setCurrentText( v );
5623 emit widgetValueHasChanged(
this );
5626 mTableComboBox->setTable( v );
5630QVariant QgsProcessingDatabaseTableWidgetWrapper::widgetValue()
const
5632 if ( mTableComboBox )
5633 if ( mTableComboBox->comboBox()->isEditable() )
5634 return mTableComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mTableComboBox->comboBox()->currentText() );
5636 return mTableComboBox->currentTable().isEmpty() ? QVariant() : QVariant( mTableComboBox->currentTable() );
5641QStringList QgsProcessingDatabaseTableWidgetWrapper::compatibleParameterTypes()
const
5643 return QStringList()
5649QStringList QgsProcessingDatabaseTableWidgetWrapper::compatibleOutputTypes()
const
5651 return QStringList()
5655QString QgsProcessingDatabaseTableWidgetWrapper::modelerExpressionFormatString()
const
5657 return tr(
"database table name as a string value" );
5660QString QgsProcessingDatabaseTableWidgetWrapper::parameterType()
const
5667 return new QgsProcessingDatabaseTableWidgetWrapper( parameter, type );
5670void QgsProcessingDatabaseTableWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5682 setParentConnectionWrapperValue( wrapper );
5685 setParentConnectionWrapperValue( wrapper );
5690 setParentSchemaWrapperValue( wrapper );
5693 setParentSchemaWrapperValue( wrapper );
5713 QVBoxLayout *vlayout =
new QVBoxLayout();
5714 vlayout->setContentsMargins( 0, 0, 0, 0 );
5716 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5719 mDefaultWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
5722 if ( extentParam->defaultValueForGui().isValid() )
5726 mDefaultWidget->setCurrentExtent( rect,
crs );
5727 mDefaultWidget->setOutputExtentFromCurrent();
5731 mDefaultWidget->clear();
5735 vlayout->addWidget( mDefaultWidget );
5736 setLayout( vlayout );
5739QgsProcessingParameterDefinition *QgsProcessingExtentParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5741 const QString defaultVal = mDefaultWidget->isValid() ? QStringLiteral(
"%1,%2,%3,%4%5" ).arg(
5742 QString::number( mDefaultWidget->outputExtent().xMinimum(),
'f', 9 ),
5743 QString::number( mDefaultWidget->outputExtent().xMaximum(),
'f', 9 ),
5744 QString::number( mDefaultWidget->outputExtent().yMinimum(),
'f', 9 ),
5745 QString::number( mDefaultWidget->outputExtent().yMaximum(),
'f', 9 ),
5746 mDefaultWidget->outputCrs().isValid() ? QStringLiteral(
" [%1]" ).arg( mDefaultWidget->outputCrs().authid() ) : QString()
5748 auto param = std::make_unique< QgsProcessingParameterExtent >( name, description, !defaultVal.isEmpty() ? QVariant( defaultVal ) : QVariant() );
5750 return param.release();
5761QWidget *QgsProcessingExtentWidgetWrapper::createWidget()
5771 if ( widgetContext().mapCanvas() )
5772 mExtentWidget->setMapCanvas( widgetContext().mapCanvas() );
5775 mExtentWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
5777 mExtentWidget->setToolTip( parameterDefinition()->toolTip() );
5781 emit widgetValueHasChanged(
this );
5785 setDialog( mDialog );
5787 return mExtentWidget;
5797 mExtentWidget->setMapCanvas( context.
mapCanvas() );
5800void QgsProcessingExtentWidgetWrapper::setDialog( QDialog *dialog )
5808 mDialog->showMinimized();
5811 mDialog->showNormal();
5813 mDialog->activateWindow();
5820void QgsProcessingExtentWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5822 if ( mExtentWidget )
5824 if ( !value.isValid() || ( value.type() == QVariant::String && value.toString().isEmpty() ) )
5825 mExtentWidget->clear();
5830 mExtentWidget->setCurrentExtent( r,
crs );
5831 mExtentWidget->setOutputExtentFromUser( r,
crs );
5836QVariant QgsProcessingExtentWidgetWrapper::widgetValue()
const
5838 if ( mExtentWidget )
5840 const QString val = mExtentWidget->isValid() ? QStringLiteral(
"%1,%2,%3,%4%5" ).arg(
5841 QString::number( mExtentWidget->outputExtent().xMinimum(),
'f', 9 ),
5842 QString::number( mExtentWidget->outputExtent().xMaximum(),
'f', 9 ),
5843 QString::number( mExtentWidget->outputExtent().yMinimum(),
'f', 9 ),
5844 QString::number( mExtentWidget->outputExtent().yMaximum(),
'f', 9 ),
5845 mExtentWidget->outputCrs().isValid() ? QStringLiteral(
" [%1]" ).arg( mExtentWidget->outputCrs().authid() ) : QString()
5848 return val.isEmpty() ? QVariant() : QVariant( val );
5854QStringList QgsProcessingExtentWidgetWrapper::compatibleParameterTypes()
const
5856 return QStringList()
5868QStringList QgsProcessingExtentWidgetWrapper::compatibleOutputTypes()
const
5870 return QStringList()
5877QString QgsProcessingExtentWidgetWrapper::modelerExpressionFormatString()
const
5879 return tr(
"string of the format 'x min,x max,y min,y max' or a geometry value (bounding box is used)" );
5882QString QgsProcessingExtentWidgetWrapper::parameterType()
const
5889 return new QgsProcessingExtentWidgetWrapper( parameter, type );
5894 return new QgsProcessingExtentParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5906 QVBoxLayout *vlayout =
new QVBoxLayout();
5907 vlayout->setContentsMargins( 0, 0, 0, 0 );
5909 vlayout->addWidget(
new QLabel( tr(
"Layer type" ) ) );
5924 for (
int i : layerParam->dataTypes() )
5926 mLayerTypeComboBox->setItemCheckState( mLayerTypeComboBox->findData( i ), Qt::Checked );
5930 vlayout->addWidget( mLayerTypeComboBox );
5932 setLayout( vlayout );
5935QgsProcessingParameterDefinition *QgsProcessingMapLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5937 QList< int > dataTypes;
5938 for (
const QVariant &v : mLayerTypeComboBox->checkedItemsData() )
5939 dataTypes << v.toInt();
5941 auto param = std::make_unique< QgsProcessingParameterMapLayer >( name, description );
5942 param->setDataTypes( dataTypes );
5944 return param.release();
5953QWidget *QgsProcessingMapLayerWidgetWrapper::createWidget()
5955 mComboBox =
new QgsProcessingMapLayerComboBox( parameterDefinition(), type() );
5963 mComboBox->setEditable(
true );
5967 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5969 connect( mComboBox, &QgsProcessingMapLayerComboBox::valueChanged,
this, [ = ]()
5971 if ( mBlockSignals )
5974 emit widgetValueHasChanged(
this );
5977 setWidgetContext( widgetContext() );
5986 mComboBox->setWidgetContext( context );
5991 if ( !parameterDefinition()->defaultValueForGui().isValid() )
5997void QgsProcessingMapLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6000 mComboBox->setValue( value, context );
6003QVariant QgsProcessingMapLayerWidgetWrapper::widgetValue()
const
6005 return mComboBox ? mComboBox->value() : QVariant();
6008QStringList QgsProcessingMapLayerWidgetWrapper::compatibleParameterTypes()
const
6010 return QStringList()
6021QStringList QgsProcessingMapLayerWidgetWrapper::compatibleOutputTypes()
const
6023 return QStringList()
6031QString QgsProcessingMapLayerWidgetWrapper::modelerExpressionFormatString()
const
6033 return tr(
"path to a map layer" );
6038 return QgsProcessingModelChildParameterSource::ModelParameter;
6041QString QgsProcessingMapLayerWidgetWrapper::parameterType()
const
6048 return new QgsProcessingMapLayerWidgetWrapper( parameter, type );
6053 return new QgsProcessingMapLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6062 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6067QStringList QgsProcessingRasterLayerWidgetWrapper::compatibleParameterTypes()
const
6069 return QStringList()
6076QStringList QgsProcessingRasterLayerWidgetWrapper::compatibleOutputTypes()
const
6078 return QStringList()
6086QString QgsProcessingRasterLayerWidgetWrapper::modelerExpressionFormatString()
const
6088 return tr(
"path to a raster layer" );
6091QString QgsProcessingRasterLayerWidgetWrapper::parameterType()
const
6098 return new QgsProcessingRasterLayerWidgetWrapper( parameter, type );
6103 Q_UNUSED( context );
6104 Q_UNUSED( widgetContext );
6105 Q_UNUSED( definition );
6119 QVBoxLayout *vlayout =
new QVBoxLayout();
6120 vlayout->setContentsMargins( 0, 0, 0, 0 );
6122 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6132 for (
int i : vectorParam->dataTypes() )
6134 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6138 vlayout->addWidget( mGeometryTypeComboBox );
6140 setLayout( vlayout );
6143QgsProcessingParameterDefinition *QgsProcessingVectorLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6145 QList< int > dataTypes;
6146 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6147 dataTypes << v.toInt();
6149 auto param = std::make_unique< QgsProcessingParameterVectorLayer >( name, description, dataTypes );
6151 return param.release();
6156 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6161QStringList QgsProcessingVectorLayerWidgetWrapper::compatibleParameterTypes()
const
6163 return QStringList()
6170QStringList QgsProcessingVectorLayerWidgetWrapper::compatibleOutputTypes()
const
6172 return QStringList()
6180QString QgsProcessingVectorLayerWidgetWrapper::modelerExpressionFormatString()
const
6182 return tr(
"path to a vector layer" );
6188 return param->dataTypes();
6190 return QList< int >();
6193QString QgsProcessingVectorLayerWidgetWrapper::parameterType()
const
6200 return new QgsProcessingVectorLayerWidgetWrapper( parameter, type );
6205 return new QgsProcessingVectorLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6217 QVBoxLayout *vlayout =
new QVBoxLayout();
6218 vlayout->setContentsMargins( 0, 0, 0, 0 );
6220 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6230 for (
int i : sourceParam->dataTypes() )
6232 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6240 vlayout->addWidget( mGeometryTypeComboBox );
6242 setLayout( vlayout );
6245QgsProcessingParameterDefinition *QgsProcessingFeatureSourceParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6247 QList< int > dataTypes;
6248 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6249 dataTypes << v.toInt();
6251 auto param = std::make_unique< QgsProcessingParameterFeatureSource >( name, description, dataTypes );
6253 return param.release();
6257 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6262QStringList QgsProcessingFeatureSourceWidgetWrapper::compatibleParameterTypes()
const
6264 return QStringList()
6272QStringList QgsProcessingFeatureSourceWidgetWrapper::compatibleOutputTypes()
const
6274 return QStringList()
6282QString QgsProcessingFeatureSourceWidgetWrapper::modelerExpressionFormatString()
const
6284 return tr(
"path to a vector layer" );
6290 return param->dataTypes();
6292 return QList< int >();
6295QString QgsProcessingFeatureSourceWidgetWrapper::parameterType()
const
6302 return new QgsProcessingFeatureSourceWidgetWrapper( parameter, type );
6307 return new QgsProcessingFeatureSourceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6315 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6320QStringList QgsProcessingMeshLayerWidgetWrapper::compatibleParameterTypes()
const
6322 return QStringList()
6329QStringList QgsProcessingMeshLayerWidgetWrapper::compatibleOutputTypes()
const
6331 return QStringList()
6339QString QgsProcessingMeshLayerWidgetWrapper::modelerExpressionFormatString()
const
6341 return tr(
"path to a mesh layer" );
6344QString QgsProcessingMeshLayerWidgetWrapper::parameterType()
const
6351 return new QgsProcessingMeshLayerWidgetWrapper( parameter, type );
6356 Q_UNUSED( context );
6357 Q_UNUSED( widgetContext );
6358 Q_UNUSED( definition );
6370QgsProcessingRasterBandPanelWidget::QgsProcessingRasterBandPanelWidget( QWidget *parent,
const QgsProcessingParameterBand *param )
6374 QHBoxLayout *hl =
new QHBoxLayout();
6375 hl->setContentsMargins( 0, 0, 0, 0 );
6377 mLineEdit =
new QLineEdit();
6378 mLineEdit->setEnabled(
false );
6379 hl->addWidget( mLineEdit, 1 );
6381 mToolButton =
new QToolButton();
6382 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6383 hl->addWidget( mToolButton );
6389 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, 0 ) );
6392 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingRasterBandPanelWidget::showDialog );
6395void QgsProcessingRasterBandPanelWidget::setBands(
const QList< int > &bands )
6400void QgsProcessingRasterBandPanelWidget::setBandNames(
const QHash<int, QString> &names )
6405void QgsProcessingRasterBandPanelWidget::setValue(
const QVariant &value )
6407 if ( value.isValid() )
6408 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
6412 updateSummaryText();
6416void QgsProcessingRasterBandPanelWidget::showDialog()
6418 QVariantList availableOptions;
6419 QStringList fieldNames;
6420 availableOptions.reserve( mBands.size() );
6421 for (
int band : std::as_const( mBands ) )
6423 availableOptions << band;
6429 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
6430 widget->setPanelTitle( mParam->description() );
6432 widget->setValueFormatter( [
this](
const QVariant & v ) -> QString
6434 int band = v.toInt();
6435 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6438 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
6440 setValue( widget->selectedOptions() );
6447 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
6449 dlg.setValueFormatter( [
this](
const QVariant & v ) -> QString
6451 int band = v.toInt();
6452 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6456 setValue( dlg.selectedOptions() );
6461void QgsProcessingRasterBandPanelWidget::updateSummaryText()
6464 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, mValue.count() ) );
6476 QVBoxLayout *vlayout =
new QVBoxLayout();
6477 vlayout->setContentsMargins( 0, 0, 0, 0 );
6479 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6481 mDefaultLineEdit =
new QLineEdit();
6482 mDefaultLineEdit->setToolTip( tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6487 for (
int b : bands )
6489 defVal << QString::number( b );
6492 mDefaultLineEdit->setText( defVal.join(
';' ) );
6494 vlayout->addWidget( mDefaultLineEdit );
6496 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
6497 mParentLayerComboBox =
new QComboBox();
6499 QString initialParent;
6501 initialParent = bandParam->parentLayerParameterName();
6503 if (
auto *lModel = widgetContext.
model() )
6506 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6507 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6511 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
6512 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
6514 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6520 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
6523 mParentLayerComboBox->addItem( initialParent, initialParent );
6524 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6527 vlayout->addWidget( mParentLayerComboBox );
6529 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Allow multiple" ) );
6531 mAllowMultipleCheckBox->setChecked( bandParam->allowMultiple() );
6533 vlayout->addWidget( mAllowMultipleCheckBox );
6534 setLayout( vlayout );
6537QgsProcessingParameterDefinition *QgsProcessingBandParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6539 auto param = std::make_unique< QgsProcessingParameterBand >( name, description, mDefaultLineEdit->text().split(
';' ), mParentLayerComboBox->currentData().toString(),
false, mAllowMultipleCheckBox->isChecked() );
6541 return param.release();
6550QWidget *QgsProcessingBandWidgetWrapper::createWidget()
6560 mPanel =
new QgsProcessingRasterBandPanelWidget(
nullptr, bandParam );
6561 mPanel->setToolTip( parameterDefinition()->toolTip() );
6562 connect( mPanel, &QgsProcessingRasterBandPanelWidget::changed,
this, [ = ]
6564 emit widgetValueHasChanged(
this );
6573 mComboBox->setToolTip( parameterDefinition()->toolTip() );
6576 emit widgetValueHasChanged(
this );
6584 mLineEdit =
new QLineEdit();
6585 mLineEdit->setToolTip( QObject::tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6586 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
6588 emit widgetValueHasChanged(
this );
6597void QgsProcessingBandWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6607 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterBand *
>( parameterDefinition() )->parentLayerParameterName() )
6609 setParentLayerWrapperValue( wrapper );
6612 setParentLayerWrapperValue( wrapper );
6629 std::unique_ptr< QgsProcessingContext > tmpContext;
6630 if ( mProcessingContextGenerator )
6631 context = mProcessingContextGenerator->processingContext();
6635 tmpContext = std::make_unique< QgsProcessingContext >();
6636 context = tmpContext.get();
6642 if ( layer && layer->
isValid() )
6646 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
6649 mParentLayer.reset( qobject_cast< QgsRasterLayer * >( ownedLayer.release() ) );
6650 layer = mParentLayer.get();
6658 mComboBox->setLayer( layer );
6662 if ( provider && layer->
isValid() )
6667 QHash< int, QString > bandNames;
6668 for (
int i = 1; i <= nBands; ++i )
6673 mPanel->setBands( bands );
6674 mPanel->setBandNames( bandNames );
6681 mComboBox->setLayer(
nullptr );
6683 mPanel->setBands( QList< int >() );
6685 if ( value.isValid() && widgetContext().messageBar() )
6688 widgetContext().
messageBar()->
pushMessage( QString(), QObject::tr(
"Could not load selected layer/table. Dependent bands could not be populated" ),
6693 if ( parameterDefinition()->defaultValueForGui().isValid() )
6694 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6697void QgsProcessingBandWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6701 if ( !value.isValid() )
6702 mComboBox->setBand( -1 );
6706 mComboBox->setBand( v );
6712 if ( value.isValid() )
6715 opts.reserve( v.size() );
6720 mPanel->setValue( value.isValid() ? opts : QVariant() );
6722 else if ( mLineEdit )
6729 opts.reserve( v.size() );
6731 opts << QString::number( i );
6732 mLineEdit->setText( value.isValid() && !opts.empty() ? opts.join(
';' ) : QString() );
6736 if ( value.isValid() )
6744QVariant QgsProcessingBandWidgetWrapper::widgetValue()
const
6747 return mComboBox->currentBand() == -1 ? QVariant() : mComboBox->currentBand();
6749 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
6750 else if ( mLineEdit )
6755#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
6756 const QStringList parts = mLineEdit->text().split(
';', QString::SkipEmptyParts );
6758 const QStringList parts = mLineEdit->text().split(
';', Qt::SkipEmptyParts );
6761 res.reserve( parts.count() );
6762 for (
const QString &s : parts )
6765 int band = s.toInt( &ok );
6769 return res.
isEmpty() ? QVariant() : res;
6773 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
6780QStringList QgsProcessingBandWidgetWrapper::compatibleParameterTypes()
const
6782 return QStringList()
6787QStringList QgsProcessingBandWidgetWrapper::compatibleOutputTypes()
const
6789 return QStringList()
6793QString QgsProcessingBandWidgetWrapper::modelerExpressionFormatString()
const
6795 return tr(
"selected band numbers as an array of numbers, or semicolon separated string of options (e.g. '1;3')" );
6798QString QgsProcessingBandWidgetWrapper::parameterType()
const
6805 return new QgsProcessingBandWidgetWrapper( parameter, type );
6810 return new QgsProcessingBandParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6823 QHBoxLayout *hl =
new QHBoxLayout();
6824 hl->setContentsMargins( 0, 0, 0, 0 );
6826 mLineEdit =
new QLineEdit();
6827 mLineEdit->setEnabled(
false );
6828 hl->addWidget( mLineEdit, 1 );
6830 mToolButton =
new QToolButton();
6831 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6832 hl->addWidget( mToolButton );
6838 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, 0 ) );
6841 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingMultipleLayerPanelWidget::showDialog );
6844void QgsProcessingMultipleLayerPanelWidget::setValue(
const QVariant &value )
6846 if ( value.isValid() )
6847 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
6851 updateSummaryText();
6855void QgsProcessingMultipleLayerPanelWidget::setProject(
QgsProject *project )
6862 if ( mValue.removeAll( layerId ) )
6864 updateSummaryText();
6871void QgsProcessingMultipleLayerPanelWidget::setModel( QgsProcessingModelAlgorithm *model,
const QString &modelChildAlgorithmID )
6877 switch ( mParam->layerType() )
7026void QgsProcessingMultipleLayerPanelWidget::showDialog()
7031 QgsProcessingMultipleInputPanelWidget *widget =
new QgsProcessingMultipleInputPanelWidget( mParam, mValue, mModelSources, mModel );
7032 widget->setPanelTitle( mParam->description() );
7033 widget->setProject( mProject );
7034 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
7036 setValue( widget->selectedOptions() );
7043 QgsProcessingMultipleInputDialog dlg( mParam, mValue, mModelSources, mModel,
this, Qt::WindowFlags() );
7044 dlg.setProject( mProject );
7047 setValue( dlg.selectedOptions() );
7052void QgsProcessingMultipleLayerPanelWidget::updateSummaryText()
7055 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, mValue.count() ) );
7065 QVBoxLayout *vlayout =
new QVBoxLayout();
7066 vlayout->setContentsMargins( 0, 0, 0, 0 );
7068 vlayout->addWidget(
new QLabel( tr(
"Allowed layer type" ) ) );
7069 mLayerTypeComboBox =
new QComboBox();
7083 mLayerTypeComboBox->setCurrentIndex( mLayerTypeComboBox->findData( layersParam->layerType() ) );
7085 vlayout->addWidget( mLayerTypeComboBox );
7086 setLayout( vlayout );
7089QgsProcessingParameterDefinition *QgsProcessingMultipleLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
7091 auto param = std::make_unique< QgsProcessingParameterMultipleLayers >( name, description,
static_cast< QgsProcessing::SourceType >( mLayerTypeComboBox->currentData().toInt() ) );
7093 return param.release();
7102QWidget *QgsProcessingMultipleLayerWidgetWrapper::createWidget()
7106 mPanel =
new QgsProcessingMultipleLayerPanelWidget(
nullptr, layerParam );
7107 mPanel->setToolTip( parameterDefinition()->toolTip() );
7108 mPanel->setProject( widgetContext().project() );
7110 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7111 connect( mPanel, &QgsProcessingMultipleLayerPanelWidget::changed,
this, [ = ]
7113 emit widgetValueHasChanged(
this );
7123 mPanel->setProject( context.
project() );
7125 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7129void QgsProcessingMultipleLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7134 if ( value.isValid() )
7137 opts.reserve( v.size() );
7139 opts << l->source();
7142 for (
const QVariant &v : value.toList() )
7144 if ( v.userType() == QMetaType::type(
"QgsProcessingModelChildParameterSource" ) )
7146 const QgsProcessingModelChildParameterSource source = v.value< QgsProcessingModelChildParameterSource >();
7147 opts << QVariant::fromValue( source );
7152 mPanel->setValue( value.isValid() ? opts : QVariant() );
7156QVariant QgsProcessingMultipleLayerWidgetWrapper::widgetValue()
const
7159 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
7164QStringList QgsProcessingMultipleLayerWidgetWrapper::compatibleParameterTypes()
const
7166 return QStringList()
7177QStringList QgsProcessingMultipleLayerWidgetWrapper::compatibleOutputTypes()
const
7179 return QStringList()
7188QString QgsProcessingMultipleLayerWidgetWrapper::modelerExpressionFormatString()
const
7190 return tr(
"an array of layer paths, or semicolon separated string of layer paths" );
7193QString QgsProcessingMultipleLayerWidgetWrapper::parameterType()
const
7200 return new QgsProcessingMultipleLayerWidgetWrapper( parameter, type );
7205 return new QgsProcessingMultipleLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
7214 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
7219QStringList QgsProcessingPointCloudLayerWidgetWrapper::compatibleParameterTypes()
const
7221 return QStringList()
7228QStringList QgsProcessingPointCloudLayerWidgetWrapper::compatibleOutputTypes()
const
7230 return QStringList()
7238QString QgsProcessingPointCloudLayerWidgetWrapper::modelerExpressionFormatString()
const
7240 return tr(
"path to a point cloud layer" );
7243QString QgsProcessingPointCloudLayerWidgetWrapper::parameterType()
const
7250 return new QgsProcessingPointCloudLayerWidgetWrapper( parameter, type );
7255 Q_UNUSED( context );
7256 Q_UNUSED( widgetContext );
7257 Q_UNUSED( definition );
7274QStringList QgsProcessingAnnotationLayerWidgetWrapper::compatibleParameterTypes()
const
7276 return QStringList()
7283QStringList QgsProcessingAnnotationLayerWidgetWrapper::compatibleOutputTypes()
const
7285 return QStringList()
7290QString QgsProcessingAnnotationLayerWidgetWrapper::modelerExpressionFormatString()
const
7292 return tr(
"name of an annotation layer, or \"main\" for the main annotation layer" );
7295QString QgsProcessingAnnotationLayerWidgetWrapper::parameterType()
const
7302 return new QgsProcessingAnnotationLayerWidgetWrapper( parameter, type );
7307 Q_UNUSED( context );
7308 Q_UNUSED( widgetContext );
7309 Q_UNUSED( definition );
7320 if ( mWidgetContext.project() )
7321 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7325QWidget *QgsProcessingAnnotationLayerWidgetWrapper::createWidget()
7336 mComboBox->setEditable(
true );
7340 mComboBox->setToolTip( parameterDefinition()->toolTip() );
7342 if ( mWidgetContext.project() )
7343 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7346 mComboBox->setAllowEmptyLayer(
true );
7350 if ( mBlockSignals )
7353 emit widgetValueHasChanged(
this );
7356 setWidgetContext( widgetContext() );
7360void QgsProcessingAnnotationLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7366 mComboBox->setLayer(
nullptr );
7370 QVariant val = value;
7371 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
7383 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( val.value< QObject * >() );
7384 if ( !layer && val.type() == QVariant::String )
7391 mComboBox->setLayer( layer );
7396QVariant QgsProcessingAnnotationLayerWidgetWrapper::widgetValue()
const
7398 return mComboBox && mComboBox->currentLayer() ?
7399 ( mWidgetContext.project() ? ( mComboBox->currentLayer() == mWidgetContext.project()->mainAnnotationLayer() ? QStringLiteral(
"main" ) : mComboBox->currentLayer()->id() ) : mComboBox->currentLayer()->id() )
7415QWidget *QgsProcessingOutputWidgetWrapper::createWidget()
7423 mOutputWidget =
new QgsProcessingLayerOutputDestinationWidget( destParam,
false );
7424 if ( mProcessingContextGenerator )
7425 mOutputWidget->setContext( mProcessingContextGenerator->processingContext() );
7426 if ( mParametersGenerator )
7427 mOutputWidget->registerProcessingParametersGenerator( mParametersGenerator );
7428 mOutputWidget->setToolTip( parameterDefinition()->toolTip() );
7430 connect( mOutputWidget, &QgsProcessingLayerOutputDestinationWidget::destinationChanged,
this, [ = ]()
7432 if ( mBlockSignals )
7435 emit widgetValueHasChanged(
this );
7443 mOutputWidget->addOpenAfterRunningOption();
7445 return mOutputWidget;
7455void QgsProcessingOutputWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
7457 if ( mOutputWidget )
7458 mOutputWidget->setValue( value );
7461QVariant QgsProcessingOutputWidgetWrapper::widgetValue()
const
7463 if ( mOutputWidget )
7464 return mOutputWidget->value();
7469QVariantMap QgsProcessingOutputWidgetWrapper::customProperties()
const
7472 if ( mOutputWidget )
7473 res.insert( QStringLiteral(
"OPEN_AFTER_RUNNING" ), mOutputWidget->openAfterRunning() );
7477QStringList QgsProcessingOutputWidgetWrapper::compatibleParameterTypes()
const
7479 return QStringList()
7488QStringList QgsProcessingOutputWidgetWrapper::compatibleOutputTypes()
const
7490 return QStringList()
7501 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7506QString QgsProcessingFeatureSinkWidgetWrapper::parameterType()
const
7513 return new QgsProcessingFeatureSinkWidgetWrapper( parameter, type );
7516QString QgsProcessingFeatureSinkWidgetWrapper::modelerExpressionFormatString()
const
7518 return tr(
"path to layer destination" );
7526 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7531QString QgsProcessingVectorDestinationWidgetWrapper::parameterType()
const
7538 return new QgsProcessingVectorDestinationWidgetWrapper( parameter, type );
7541QString QgsProcessingVectorDestinationWidgetWrapper::modelerExpressionFormatString()
const
7543 return tr(
"path to layer destination" );
7551 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7556QString QgsProcessingRasterDestinationWidgetWrapper::parameterType()
const
7563 return new QgsProcessingRasterDestinationWidgetWrapper( parameter, type );
7566QString QgsProcessingRasterDestinationWidgetWrapper::modelerExpressionFormatString()
const
7568 return tr(
"path to layer destination" );
7576 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7581QString QgsProcessingPointCloudDestinationWidgetWrapper::parameterType()
const
7588 return new QgsProcessingPointCloudDestinationWidgetWrapper( parameter, type );
7591QString QgsProcessingPointCloudDestinationWidgetWrapper::modelerExpressionFormatString()
const
7593 return tr(
"path to layer destination" );
7601 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7606QString QgsProcessingFileDestinationWidgetWrapper::parameterType()
const
7613 return new QgsProcessingFileDestinationWidgetWrapper( parameter, type );
7616QString QgsProcessingFileDestinationWidgetWrapper::modelerExpressionFormatString()
const
7618 return tr(
"path to file destination" );
7626 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7631QString QgsProcessingFolderDestinationWidgetWrapper::parameterType()
const
7638 return new QgsProcessingFolderDestinationWidgetWrapper( parameter, type );
7641QString QgsProcessingFolderDestinationWidgetWrapper::modelerExpressionFormatString()
const
7643 return tr(
"path to folder destination" );
@ Info
Information message.
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.
@ CapturePoint
Select and capture a point or a feature.
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.
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.
void setAllowEmptyLayout(bool allowEmpty)
Sets whether an optional empty layout ("not set") option is present in the combobox.
The QgsLayoutItemComboBox class is a combo box which displays items of a matching type from a layout.
void itemChanged(QgsLayoutItem *item)
Emitted whenever the currently selected item changes.
Base class for graphical items within a QgsLayout.
virtual QString uuid() const
Returns the item identification string.
@ FilterPrintLayouts
Includes print layouts.
QList< QgsPrintLayout * > printLayouts() const
Returns a list of all print layouts contained in the manager.
Map canvas is a class for displaying all GIS data types on a canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
The QgsMapLayerComboBox class is a combo box which displays the list of layers.
void layerChanged(QgsMapLayer *layer)
Emitted whenever the currently selected layer changes.
@ AnnotationLayer
QgsAnnotationLayer.
Base class for all map layer types.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
QgsPointLocator::Match mapPointMatch() const
Returns the matching data from the most recently snapped point.
QgsPointXY snapPoint()
snapPoint will snap the points using the map canvas snapping utils configuration
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
Interface for master layout type objects, such as print layouts and reports.
virtual QString name() const =0
Returns the layout's name.
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::MessageLevel::Info, int duration=-1)
A convenience method for pushing a message with the specified text to the bar.
bool clearWidgets()
Removes all items from the bar.
A class to represent a 2D point.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Abstract base class for processing algorithms.
An interface for objects which can create Processing contexts.
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
QgsMapLayer * takeResultLayer(const QString &id)
Takes the result map layer with matching id from the context and transfers ownership of it back to th...
Base class for all parameter definitions which represent file or layer destinations,...
Encapsulates settings relating to a feature source input to a processing algorithm.
QgsProperty source
Source definition.
WidgetType
Types of dialogs which Processing widgets can be created for.
@ Standard
Standard algorithm dialog.
@ Batch
Batch processing dialog.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A raster band parameter for Processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
bool allowMultiple() const
Returns whether multiple band selections are permitted.
A boolean parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A color parameter for processing algorithms.
bool opacityEnabled() const
Returns true if the parameter allows opacity control.
static QString typeName()
Returns the type name for the parameter class.
A coordinate operation parameter for processing algorithms, for selection between available coordinat...
static QString typeName()
Returns the type name for the parameter class.
QVariant sourceCrs() const
Returns the static source CRS, or an invalid value if this is not set.
QVariant destinationCrs() const
Returns the static destination CRS, or an invalid value if this is not set.
A coordinate reference system parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A database schema parameter for processing algorithms, allowing users to select from existing schemas...
static QString typeName()
Returns the type name for the parameter class.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
A database table name parameter for processing algorithms, allowing users to select from existing dat...
static QString typeName()
Returns the type name for the parameter class.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
QString parentSchemaParameterName() const
Returns the name of the parent schema parameter, or an empty string if this is not set.
bool allowNewTableNames() const
Returns true if the parameter allows users to enter names for a new (non-existing) tables.
A datetime (or pure date or time) parameter for processing algorithms.
@ DateTime
Datetime values.
static QString typeName()
Returns the type name for the parameter class.
Type dataType() const
Returns the acceptable data type for the parameter.
Base class for the definition of processing parameters.
QVariantMap metadata() const
Returns the parameter's freeform metadata.
QString description() const
Returns the description for the parameter.
QVariant defaultValueForGui() const
Returns the default value to use for the parameter in a GUI.
@ FlagOptional
Parameter is optional.
virtual QString type() const =0
Unique parameter type name.
Flags flags() const
Returns any flags associated with the parameter.
QString name() const
Returns the name of the parameter.
void setFlags(Flags flags)
Sets the flags associated with the parameter.
A double numeric parameter for distance values.
static QString typeName()
Returns the type name for the parameter class.
QgsUnitTypes::DistanceUnit defaultUnit() const
Returns the default distance unit for the parameter.
A double numeric parameter for duration values.
QgsUnitTypes::TemporalUnit defaultUnit() const
Returns the default duration unit for the parameter.
static QString typeName()
Returns the type name for the parameter class.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
bool allowMultiple() const
Returns true if the parameter allows multiple selected values.
QStringList options() const
Returns the list of acceptable options for the parameter.
bool usesStaticStrings() const
Returns true if the parameter uses static (non-translated) string values for its enumeration choice l...
static QString typeName()
Returns the type name for the parameter class.
An expression parameter for processing algorithms.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
static QString typeName()
Returns the type name for the parameter class.
A rectangular map extent parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
An input feature source (such as vector layers) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A vector layer or feature source field parameter for processing algorithms.
void setDataType(DataType type)
Sets the acceptable data type for the field.
bool allowMultiple() const
Returns whether multiple field selections are permitted.
bool defaultToAllFields() const
Returns whether a parameter which allows multiple selections (see allowMultiple()) should automatical...
static QString typeName()
Returns the type name for the parameter class.
DataType
Field data types.
@ DateTime
Accepts datetime fields.
@ Numeric
Accepts numeric fields.
@ String
Accepts string fields.
DataType dataType() const
Returns the acceptable data type for the field.
static QString typeName()
Returns the type name for the parameter class.
An input file or folder parameter for processing algorithms.
QString extension() const
Returns any specified file extension for the parameter.
static QString typeName()
Returns the type name for the parameter class.
Behavior
Parameter behavior.
@ Folder
Parameter is a folder.
@ File
Parameter is a single file.
Behavior behavior() const
Returns the parameter behavior (e.g.
QString fileFilter() const
Returns the file filter string for file destinations compatible with this parameter.
static QString typeName()
Returns the type name for the parameter class.
A geometry parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A print layout item parameter, allowing users to select a particular item from a print layout.
static QString typeName()
Returns the type name for the parameter class.
int itemType() const
Returns the acceptable item type, or -1 if any item type is allowed.
A print layout parameter, allowing users to select a print layout.
static QString typeName()
Returns the type name for the parameter class.
A map layer parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A map theme parameter for processing algorithms, allowing users to select an existing map theme from ...
static QString typeName()
Returns the type name for the parameter class.
A table (matrix) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A parameter for processing algorithms which accepts multiple map layers.
static QString typeName()
Returns the type name for the parameter class.
A numeric parameter for processing algorithms.
double minimum() const
Returns the minimum value acceptable by the parameter.
@ Double
Double/float values.
double maximum() const
Returns the maximum value acceptable by the parameter.
Type dataType() const
Returns the acceptable data type for the parameter.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A point parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A data provider connection parameter for processing algorithms, allowing users to select from availab...
static QString typeName()
Returns the type name for the parameter class.
QString providerId() const
Returns the ID of the provider associated with the connections.
A numeric range parameter for processing algorithms.
QgsProcessingParameterNumber::Type dataType() const
Returns the acceptable data type for the range.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A raster layer parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A double numeric parameter for map scale values.
static QString typeName()
Returns the type name for the parameter class.
A string parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
bool multiLine() const
Returns true if the parameter allows multiline strings.
static QString typeName()
Returns the type name for the parameter class.
A vector layer (with or without geometry) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
Contains settings which reflect the context in which a Processing parameter widget is shown,...
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QgsProject * project() const
Returns the project associated with the widget.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
QgsProcessingModelAlgorithm * model() const
Returns the model which the parameter widget is associated with.
QgsMapLayer * activeLayer() const
Returns the current active layer.
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of map layers.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
static QTime parameterAsTime(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static time value.
static QgsRectangle parameterAsExtent(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent.
static QString parameterAsEnumString(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static enum string.
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
static QList< int > parameterAsInts(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of integer values.
static QString parameterAsConnectionName(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a connection name string.
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
static QgsLayoutItem * parameterAsLayoutItem(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsPrintLayout *layout)
Evaluates the parameter with matching definition to a print layout item, taken from the specified lay...
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QColor parameterAsColor(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the color associated with an point parameter value, or an invalid color if the parameter was ...
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
static int parameterAsInt(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static integer value.
static QString parameterAsDatabaseTableName(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database table name.
static QString parameterAsSchema(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database schema name.
static QgsGeometry parameterAsGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a geometry.
static QString parameterAsExpression(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to an expression.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
static QgsRasterLayer * parameterAsRasterLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a raster layer.
static QList< int > parameterAsEnums(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of enum values.
static QStringList parameterAsEnumStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of static enum strings.
static QStringList parameterAsFields(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of fields.
static QgsCoordinateReferenceSystem parameterAsExtentCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
static QDateTime parameterAsDateTime(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static datetime value.
static QDate parameterAsDate(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static date value.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
@ Annotation
Annotation layer type, since QGIS 3.22.
static QgsCoordinateReferenceSystem variantToCrs(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a coordinate reference system.
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, QgsProcessingUtils::LayerHint typeHint=QgsProcessingUtils::LayerHint::UnknownType)
Interprets a string as a map layer within the supplied context.
SourceType
Data source types enum.
@ TypePlugin
Plugin layers.
@ TypeVectorLine
Vector line layers.
@ TypeMapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer)
@ TypeVectorPolygon
Vector polygon layers.
@ TypeFile
Files (i.e. non map layer sources, such as text files)
@ TypeAnnotation
Annotation layers.
@ TypePointCloud
Point cloud layers.
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ TypeRaster
Raster layers.
@ TypeVectorPoint
Vector point layers.
@ TypeVectorAnyGeometry
Any vector layer with geometry.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsMapThemeCollection * mapThemeCollection
const QgsLayoutManager * layoutManager() const
Returns the project's layout manager, which manages print layouts, atlases and reports within the pro...
void layerRemoved(const QString &layerId)
Emitted after a layer was removed from the registry.
A store for object properties.
@ StaticProperty
Static property (QgsStaticProperty)
Type propertyType() const
Returns the property type.
The QgsProviderConnectionComboBox class is a combo box which displays the list of connections registe...
A combobox widget which displays the bands present in a raster layer.
void bandChanged(int band)
Emitted when the currently selected band changes.
static QString displayBandName(QgsRasterDataProvider *provider, int band)
Returns a user-friendly band name for the specified band.
Base class for raster data providers.
virtual int bandCount() const =0
Gets number of bands.
Represents a raster layer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
A rectangle specified with double values.
This class is a composition of two QSettings instances:
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Class that shows snapping marker on map canvas for the current snapping match.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
The QgsTimeEdit class is a QTimeEdit widget with the capability of setting/reading null date/times.
void timeValueChanged(const QTime &time)
Signal emitted whenever the time changes.
DistanceUnit
Units of distance.
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
@ DistanceKilometers
Kilometers.
@ DistanceMiles
Terrestrial miles.
@ DistanceUnknownUnit
Unknown distance unit.
@ DistanceYards
Imperial yards.
@ DistanceFeet
Imperial feet.
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
static Q_INVOKABLE QgsUnitTypes::DistanceUnitType unitType(QgsUnitTypes::DistanceUnit unit)
Returns the type for a distance unit.
@ Standard
Unit is a standard measurement unit.
TemporalUnit
Temporal units.
@ TemporalMilliseconds
Milliseconds.
@ TemporalDecades
Decades.
@ TemporalCenturies
Centuries.
@ TemporalSeconds
Seconds.
@ TemporalMinutes
Minutes.
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
@ VectorLayer
Vector layer.
@ RasterLayer
Raster layer.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
const QgsCoordinateReferenceSystem & crs