20 #include "processing/models/qgsprocessingmodelalgorithm.h"
64 #include <QToolButton>
66 #include <QHBoxLayout>
67 #include <QVBoxLayout>
71 #include <QPlainTextEdit>
72 #include <QRadioButton>
73 #include <QButtonGroup>
75 #include <QFileDialog>
87 QVBoxLayout *vlayout =
new QVBoxLayout();
88 vlayout->setContentsMargins( 0, 0, 0, 0 );
90 mDefaultCheckBox =
new QCheckBox( tr(
"Checked" ) );
94 mDefaultCheckBox->setChecked(
false );
95 vlayout->addWidget( mDefaultCheckBox );
99 QgsProcessingParameterDefinition *QgsProcessingBooleanParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
101 auto param = qgis::make_unique< QgsProcessingParameterBoolean >( name, description, mDefaultCheckBox->isChecked() );
102 param->setFlags( flags );
103 return param.release();
113 QWidget *QgsProcessingBooleanWidgetWrapper::createWidget()
119 QString description = parameterDefinition()->description();
121 description = QObject::tr(
"%1 [optional]" ).arg( description );
123 mCheckBox =
new QCheckBox( description );
124 mCheckBox->setToolTip( parameterDefinition()->toolTip() );
126 connect( mCheckBox, &QCheckBox::toggled,
this, [ = ]
128 emit widgetValueHasChanged(
this );
136 mComboBox =
new QComboBox();
137 mComboBox->addItem( tr(
"Yes" ),
true );
138 mComboBox->addItem( tr(
"No" ),
false );
139 mComboBox->setToolTip( parameterDefinition()->toolTip() );
141 connect( mComboBox, qgis::overload< int>::of( &QComboBox::currentIndexChanged ),
this, [ = ]
143 emit widgetValueHasChanged(
this );
152 QLabel *QgsProcessingBooleanWidgetWrapper::createLabel()
161 void QgsProcessingBooleanWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
168 mCheckBox->setChecked( v );
176 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
182 QVariant QgsProcessingBooleanWidgetWrapper::widgetValue()
const
187 return mCheckBox->isChecked();
191 return mComboBox->currentData();
196 QStringList QgsProcessingBooleanWidgetWrapper::compatibleParameterTypes()
const
215 QStringList QgsProcessingBooleanWidgetWrapper::compatibleOutputTypes()
const
226 QString QgsProcessingBooleanWidgetWrapper::parameterType()
const
233 return new QgsProcessingBooleanWidgetWrapper( parameter, type );
238 return new QgsProcessingBooleanParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
249 QVBoxLayout *vlayout =
new QVBoxLayout();
250 vlayout->setContentsMargins( 0, 0, 0, 0 );
252 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
260 vlayout->addWidget( mCrsSelector );
261 setLayout( vlayout );
264 QgsProcessingParameterDefinition *QgsProcessingCrsParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
266 auto param = qgis::make_unique< QgsProcessingParameterCrs >( name, description, mCrsSelector->crs().authid() );
267 param->setFlags( flags );
268 return param.release();
277 QWidget *QgsProcessingCrsWidgetWrapper::createWidget()
279 Q_ASSERT( mProjectionSelectionWidget ==
nullptr );
281 mProjectionSelectionWidget->setToolTip( parameterDefinition()->toolTip() );
290 emit widgetValueHasChanged(
this );
298 return mProjectionSelectionWidget;
303 QWidget *w =
new QWidget();
304 w->setToolTip( parameterDefinition()->toolTip() );
306 QVBoxLayout *vl =
new QVBoxLayout();
307 vl->setContentsMargins( 0, 0, 0, 0 );
310 mUseProjectCrsCheckBox =
new QCheckBox( tr(
"Use project CRS" ) );
311 mUseProjectCrsCheckBox->setToolTip( tr(
"Always use the current project CRS when running the model" ) );
312 vl->addWidget( mUseProjectCrsCheckBox );
313 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, mProjectionSelectionWidget, &QgsProjectionSelectionWidget::setDisabled );
314 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled,
this, [ = ]
316 emit widgetValueHasChanged(
this );
319 vl->addWidget( mProjectionSelectionWidget );
327 void QgsProcessingCrsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
329 if ( mUseProjectCrsCheckBox )
331 if ( value.toString().compare( QLatin1String(
"ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
333 mUseProjectCrsCheckBox->setChecked(
true );
338 mUseProjectCrsCheckBox->setChecked(
false );
343 if ( mProjectionSelectionWidget )
344 mProjectionSelectionWidget->setCrs( v );
347 QVariant QgsProcessingCrsWidgetWrapper::widgetValue()
const
349 if ( mUseProjectCrsCheckBox && mUseProjectCrsCheckBox->isChecked() )
350 return QStringLiteral(
"ProjectCrs" );
351 else if ( mProjectionSelectionWidget )
352 return mProjectionSelectionWidget->crs().isValid() ? mProjectionSelectionWidget->crs() : QVariant();
357 QStringList QgsProcessingCrsWidgetWrapper::compatibleParameterTypes()
const
369 QStringList QgsProcessingCrsWidgetWrapper::compatibleOutputTypes()
const
377 QString QgsProcessingCrsWidgetWrapper::modelerExpressionFormatString()
const
379 return tr(
"string as EPSG code, WKT or PROJ format, or a string identifying a map layer" );
382 QString QgsProcessingCrsWidgetWrapper::parameterType()
const
389 return new QgsProcessingCrsWidgetWrapper( parameter, type );
394 return new QgsProcessingCrsParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
407 QVBoxLayout *vlayout =
new QVBoxLayout();
408 vlayout->setContentsMargins( 0, 0, 0, 0 );
410 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
412 mDefaultLineEdit =
new QLineEdit();
415 vlayout->addWidget( mDefaultLineEdit );
417 mMultiLineCheckBox =
new QCheckBox( tr(
"Multiline input" ) );
419 mMultiLineCheckBox->setChecked( stringParam->multiLine() );
420 vlayout->addWidget( mMultiLineCheckBox );
422 setLayout( vlayout );
425 QgsProcessingParameterDefinition *QgsProcessingStringParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
427 auto param = qgis::make_unique< QgsProcessingParameterString >( name, description, mDefaultLineEdit->text(), mMultiLineCheckBox->isChecked() );
428 param->setFlags( flags );
429 return param.release();
440 QWidget *QgsProcessingStringWidgetWrapper::createWidget()
449 mPlainTextEdit =
new QPlainTextEdit();
450 mPlainTextEdit->setToolTip( parameterDefinition()->toolTip() );
452 connect( mPlainTextEdit, &QPlainTextEdit::textChanged,
this, [ = ]
454 emit widgetValueHasChanged(
this );
456 return mPlainTextEdit;
460 mLineEdit =
new QLineEdit();
461 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
463 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
465 emit widgetValueHasChanged(
this );
473 mLineEdit =
new QLineEdit();
474 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
476 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
478 emit widgetValueHasChanged(
this );
486 void QgsProcessingStringWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
490 mLineEdit->setText( v );
491 if ( mPlainTextEdit )
492 mPlainTextEdit->setPlainText( v );
495 QVariant QgsProcessingStringWidgetWrapper::widgetValue()
const
498 return mLineEdit->text();
499 else if ( mPlainTextEdit )
500 return mPlainTextEdit->toPlainText();
505 QStringList QgsProcessingStringWidgetWrapper::compatibleParameterTypes()
const
520 QStringList QgsProcessingStringWidgetWrapper::compatibleOutputTypes()
const
528 QString QgsProcessingStringWidgetWrapper::parameterType()
const
535 return new QgsProcessingStringWidgetWrapper( parameter, type );
540 return new QgsProcessingStringParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
555 QWidget *QgsProcessingAuthConfigWidgetWrapper::createWidget()
564 mAuthConfigSelect->setToolTip( parameterDefinition()->toolTip() );
568 emit widgetValueHasChanged(
this );
570 return mAuthConfigSelect;
576 void QgsProcessingAuthConfigWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
579 if ( mAuthConfigSelect )
580 mAuthConfigSelect->setConfigId( v );
583 QVariant QgsProcessingAuthConfigWidgetWrapper::widgetValue()
const
585 if ( mAuthConfigSelect )
586 return mAuthConfigSelect->configId();
591 QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleParameterTypes()
const
599 QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleOutputTypes()
const
604 QString QgsProcessingAuthConfigWidgetWrapper::parameterType()
const
611 return new QgsProcessingAuthConfigWidgetWrapper( parameter, type );
621 QVBoxLayout *vlayout =
new QVBoxLayout();
622 vlayout->setContentsMargins( 0, 0, 0, 0 );
624 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
626 mTypeComboBox =
new QComboBox();
629 vlayout->addWidget( mTypeComboBox );
631 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
632 mMinLineEdit =
new QLineEdit();
633 vlayout->addWidget( mMinLineEdit );
635 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
636 mMaxLineEdit =
new QLineEdit();
637 vlayout->addWidget( mMaxLineEdit );
639 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
640 mDefaultLineEdit =
new QLineEdit();
641 vlayout->addWidget( mDefaultLineEdit );
645 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( numberParam->dataType() ) );
646 mMinLineEdit->setText( QString::number( numberParam->minimum() ) );
647 mMaxLineEdit->setText( QString::number( numberParam->maximum() ) );
648 mDefaultLineEdit->setText( numberParam->defaultValueForGui().toString() );
651 setLayout( vlayout );
654 QgsProcessingParameterDefinition *QgsProcessingNumberParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
657 double val = mDefaultLineEdit->text().toDouble( &ok );
660 auto param = qgis::make_unique< QgsProcessingParameterNumber >( name, description, dataType, ok ? val : QVariant() );
662 val = mMinLineEdit->text().toDouble( &ok );
665 param->setMinimum( val );
668 val = mMaxLineEdit->text().toDouble( &ok );
671 param->setMaximum( val );
674 param->setFlags( flags );
675 return param.release();
684 QWidget *QgsProcessingNumericWidgetWrapper::createWidget()
687 const QVariantMap metadata = numberDef->
metadata();
688 const int decimals = metadata.value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"decimals" ), 6 ).toInt();
696 QAbstractSpinBox *spinBox =
nullptr;
701 mDoubleSpinBox->setExpressionsEnabled(
true );
702 mDoubleSpinBox->setDecimals( decimals );
708 double singleStep = calculateStep( numberDef->
minimum(), numberDef->
maximum() );
709 singleStep = std::max( singleStep, std::pow( 10, -decimals ) );
710 mDoubleSpinBox->setSingleStep( singleStep );
713 spinBox = mDoubleSpinBox;
718 mSpinBox->setExpressionsEnabled(
true );
722 spinBox->setToolTip( parameterDefinition()->toolTip() );
724 double max = 999999999;
729 double min = -999999999;
734 if ( mDoubleSpinBox )
736 mDoubleSpinBox->setMinimum( min );
737 mDoubleSpinBox->setMaximum( max );
741 mSpinBox->setMinimum(
static_cast< int >( min ) );
742 mSpinBox->setMaximum(
static_cast< int >( max ) );
747 mAllowingNull =
true;
748 if ( mDoubleSpinBox )
750 mDoubleSpinBox->setShowClearButton(
true );
751 const double min = mDoubleSpinBox->minimum() - 1;
752 mDoubleSpinBox->setMinimum( min );
753 mDoubleSpinBox->setValue( min );
757 mSpinBox->setShowClearButton(
true );
758 const int min = mSpinBox->minimum() - 1;
759 mSpinBox->setMinimum( min );
760 mSpinBox->setValue( min );
762 spinBox->setSpecialValueText( tr(
"Not set" ) );
770 if ( mDoubleSpinBox )
774 mDoubleSpinBox->setClearValue( defaultVal );
780 mSpinBox->setClearValue( intVal );
786 if ( mDoubleSpinBox )
787 mDoubleSpinBox->setClearValue( numberDef->
minimum() );
789 mSpinBox->setClearValue(
static_cast< int >( numberDef->
minimum() ) );
794 if ( mDoubleSpinBox )
796 mDoubleSpinBox->setValue( 0 );
797 mDoubleSpinBox->setClearValue( 0 );
801 mSpinBox->setValue( 0 );
802 mSpinBox->setClearValue( 0 );
807 if ( mDoubleSpinBox )
808 connect( mDoubleSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
this, [ = ] { emit widgetValueHasChanged(
this ); } );
810 connect( mSpinBox, qgis::overload<int>::of( &QgsSpinBox::valueChanged ),
this, [ = ] { emit widgetValueHasChanged(
this ); } );
818 void QgsProcessingNumericWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
820 if ( mDoubleSpinBox )
822 if ( mAllowingNull && !value.isValid() )
823 mDoubleSpinBox->clear();
827 mDoubleSpinBox->setValue( v );
832 if ( mAllowingNull && !value.isValid() )
837 mSpinBox->setValue( v );
842 QVariant QgsProcessingNumericWidgetWrapper::widgetValue()
const
844 if ( mDoubleSpinBox )
846 if ( mAllowingNull &&
qgsDoubleNear( mDoubleSpinBox->value(), mDoubleSpinBox->minimum() ) )
849 return mDoubleSpinBox->value();
853 if ( mAllowingNull && mSpinBox->value() == mSpinBox->minimum() )
856 return mSpinBox->value();
862 QStringList QgsProcessingNumericWidgetWrapper::compatibleParameterTypes()
const
871 QStringList QgsProcessingNumericWidgetWrapper::compatibleOutputTypes()
const
877 double QgsProcessingNumericWidgetWrapper::calculateStep(
const double minimum,
const double maximum )
879 const double valueRange = maximum - minimum;
880 if ( valueRange <= 1.0 )
882 const double step = valueRange / 10.0;
884 return qgsRound( step, -std::floor( std::log( step ) ) );
892 QString QgsProcessingNumericWidgetWrapper::parameterType()
const
899 return new QgsProcessingNumericWidgetWrapper( parameter, type );
904 return new QgsProcessingNumberParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
914 QVBoxLayout *vlayout =
new QVBoxLayout();
915 vlayout->setContentsMargins( 0, 0, 0, 0 );
917 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
919 mParentLayerComboBox =
new QComboBox();
921 QString initialParent;
923 initialParent = distParam->parentParameterName();
925 if (
auto *lModel = widgetContext.
model() )
928 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
929 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
933 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
934 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
936 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
941 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
942 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
944 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
949 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
950 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
952 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
957 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
958 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
960 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
966 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
969 mParentLayerComboBox->addItem( initialParent, initialParent );
970 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
973 vlayout->addWidget( mParentLayerComboBox );
975 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
976 mMinLineEdit =
new QLineEdit();
977 vlayout->addWidget( mMinLineEdit );
979 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
980 mMaxLineEdit =
new QLineEdit();
981 vlayout->addWidget( mMaxLineEdit );
983 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
984 mDefaultLineEdit =
new QLineEdit();
985 vlayout->addWidget( mDefaultLineEdit );
989 mMinLineEdit->setText( QString::number( distParam->minimum() ) );
990 mMaxLineEdit->setText( QString::number( distParam->maximum() ) );
991 mDefaultLineEdit->setText( distParam->defaultValueForGui().toString() );
994 setLayout( vlayout );
997 QgsProcessingParameterDefinition *QgsProcessingDistanceParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1000 double val = mDefaultLineEdit->text().toDouble( &ok );
1002 auto param = qgis::make_unique< QgsProcessingParameterDistance >( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1004 val = mMinLineEdit->text().toDouble( &ok );
1007 param->setMinimum( val );
1010 val = mMaxLineEdit->text().toFloat( &ok );
1013 param->setMaximum( val );
1016 param->setFlags( flags );
1017 return param.release();
1021 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1026 QString QgsProcessingDistanceWidgetWrapper::parameterType()
const
1033 return new QgsProcessingDistanceWidgetWrapper( parameter, type );
1036 QWidget *QgsProcessingDistanceWidgetWrapper::createWidget()
1040 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1045 mLabel =
new QLabel();
1046 mUnitsCombo =
new QComboBox();
1054 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
1055 const int labelMargin =
static_cast< int >( std::round( mUnitsCombo->fontMetrics().width(
'X' ) ) );
1057 const int labelMargin =
static_cast< int >( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1059 QHBoxLayout *layout =
new QHBoxLayout();
1060 layout->addWidget( spin, 1 );
1061 layout->insertSpacing( 1, labelMargin / 2 );
1062 layout->insertWidget( 2, mLabel );
1063 layout->insertWidget( 3, mUnitsCombo );
1068 mWarningLabel =
new QWidget();
1069 QHBoxLayout *warningLayout =
new QHBoxLayout();
1070 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1071 QLabel *warning =
new QLabel();
1073 const int size =
static_cast< int >( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1074 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1075 warning->setToolTip( tr(
"Distance is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1076 warningLayout->insertSpacing( 0, labelMargin / 2 );
1077 warningLayout->insertWidget( 1, warning );
1078 mWarningLabel->setLayout( warningLayout );
1079 layout->insertWidget( 4, mWarningLabel );
1081 QWidget *w =
new QWidget();
1082 layout->setContentsMargins( 0, 0, 0, 0 );
1083 w->setLayout( layout );
1098 void QgsProcessingDistanceWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1100 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1107 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterDistance *
>( parameterDefinition() )->parentParameterName() )
1109 setUnitParameterValue( wrapper->parameterValue() );
1112 setUnitParameterValue( wrapper->parameterValue() );
1126 void QgsProcessingDistanceWidgetWrapper::setUnitParameterValue(
const QVariant &value )
1132 std::unique_ptr< QgsProcessingContext > tmpContext;
1133 if ( mProcessingContextGenerator )
1134 context = mProcessingContextGenerator->processingContext();
1138 tmpContext = qgis::make_unique< QgsProcessingContext >();
1139 context = tmpContext.get();
1156 mUnitsCombo->hide();
1161 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( units ) );
1162 mUnitsCombo->show();
1169 QVariant QgsProcessingDistanceWidgetWrapper::widgetValue()
const
1171 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1172 if ( val.type() == QVariant::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1185 return new QgsProcessingDistanceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1195 QVBoxLayout *vlayout =
new QVBoxLayout();
1196 vlayout->setContentsMargins( 0, 0, 0, 0 );
1198 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1200 mDefaultLineEdit =
new QLineEdit();
1204 mDefaultLineEdit->setText( scaleParam->defaultValueForGui().toString() );
1207 vlayout->addWidget( mDefaultLineEdit );
1209 setLayout( vlayout );
1212 QgsProcessingParameterDefinition *QgsProcessingScaleParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1215 double val = mDefaultLineEdit->text().toDouble( &ok );
1216 auto param = qgis::make_unique< QgsProcessingParameterScale >( name, description, ok ? val : QVariant() );
1217 param->setFlags( flags );
1218 return param.release();
1222 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1227 QString QgsProcessingScaleWidgetWrapper::parameterType()
const
1234 return new QgsProcessingScaleWidgetWrapper( parameter, type );
1237 QWidget *QgsProcessingScaleWidgetWrapper::createWidget()
1249 mScaleWidget->setAllowNull(
true );
1251 mScaleWidget->setMapCanvas( widgetContext().mapCanvas() );
1252 mScaleWidget->setShowCurrentScaleButton(
true );
1254 mScaleWidget->setToolTip( parameterDefinition()->toolTip() );
1257 emit widgetValueHasChanged(
this );
1259 return mScaleWidget;
1268 mScaleWidget->setMapCanvas( context.
mapCanvas() );
1273 QVariant QgsProcessingScaleWidgetWrapper::widgetValue()
const
1275 return mScaleWidget && !mScaleWidget->isNull() ? QVariant( mScaleWidget->scale() ) : QVariant();
1278 void QgsProcessingScaleWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1282 if ( mScaleWidget->allowNull() && !value.isValid() )
1283 mScaleWidget->setNull();
1287 mScaleWidget->setScale( v );
1294 return new QgsProcessingScaleParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1305 QVBoxLayout *vlayout =
new QVBoxLayout();
1306 vlayout->setContentsMargins( 0, 0, 0, 0 );
1308 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
1310 mTypeComboBox =
new QComboBox();
1313 vlayout->addWidget( mTypeComboBox );
1315 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1316 mMinLineEdit =
new QLineEdit();
1317 vlayout->addWidget( mMinLineEdit );
1319 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1320 mMaxLineEdit =
new QLineEdit();
1321 vlayout->addWidget( mMaxLineEdit );
1325 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( rangeParam->dataType() ) );
1327 mMinLineEdit->setText( QString::number( range.at( 0 ) ) );
1328 mMaxLineEdit->setText( QString::number( range.at( 1 ) ) );
1331 setLayout( vlayout );
1334 QgsProcessingParameterDefinition *QgsProcessingRangeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1336 QString defaultValue;
1337 if ( mMinLineEdit->text().isEmpty() )
1339 defaultValue = QStringLiteral(
"None" );
1343 defaultValue = mMinLineEdit->text();
1346 if ( mMaxLineEdit->text().isEmpty() )
1348 defaultValue += QLatin1String(
",None" );
1352 defaultValue += QStringLiteral(
"," ) + mMaxLineEdit->text();
1356 auto param = qgis::make_unique< QgsProcessingParameterRange >( name, description, dataType, defaultValue );
1357 param->setFlags( flags );
1358 return param.release();
1368 QWidget *QgsProcessingRangeWidgetWrapper::createWidget()
1377 QHBoxLayout *layout =
new QHBoxLayout();
1382 mMinSpinBox->setExpressionsEnabled(
true );
1383 mMinSpinBox->setShowClearButton(
false );
1384 mMaxSpinBox->setExpressionsEnabled(
true );
1385 mMaxSpinBox->setShowClearButton(
false );
1387 QLabel *minLabel =
new QLabel( tr(
"Min" ) );
1388 layout->addWidget( minLabel );
1389 layout->addWidget( mMinSpinBox, 1 );
1391 QLabel *maxLabel =
new QLabel( tr(
"Max" ) );
1392 layout->addWidget( maxLabel );
1393 layout->addWidget( mMaxSpinBox, 1 );
1395 QWidget *w =
new QWidget();
1396 layout->setContentsMargins( 0, 0, 0, 0 );
1397 w->setLayout( layout );
1401 mMinSpinBox->setDecimals( 6 );
1402 mMaxSpinBox->setDecimals( 6 );
1406 mMinSpinBox->setDecimals( 0 );
1407 mMaxSpinBox->setDecimals( 0 );
1410 mMinSpinBox->setMinimum( -99999999.999999 );
1411 mMaxSpinBox->setMinimum( -99999999.999999 );
1412 mMinSpinBox->setMaximum( 99999999.999999 );
1413 mMaxSpinBox->setMaximum( 99999999.999999 );
1417 mAllowingNull =
true;
1419 const double min = mMinSpinBox->minimum() - 1;
1420 mMinSpinBox->setMinimum( min );
1421 mMaxSpinBox->setMinimum( min );
1422 mMinSpinBox->setValue( min );
1423 mMaxSpinBox->setValue( min );
1425 mMinSpinBox->setShowClearButton(
true );
1426 mMaxSpinBox->setShowClearButton(
true );
1427 mMinSpinBox->setSpecialValueText( tr(
"Not set" ) );
1428 mMaxSpinBox->setSpecialValueText( tr(
"Not set" ) );
1431 w->setToolTip( parameterDefinition()->toolTip() );
1433 connect( mMinSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
const double v )
1435 mBlockChangedSignal++;
1436 if ( !mAllowingNull && v > mMaxSpinBox->value() )
1437 mMaxSpinBox->setValue( v );
1438 mBlockChangedSignal--;
1440 if ( !mBlockChangedSignal )
1441 emit widgetValueHasChanged(
this );
1443 connect( mMaxSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
const double v )
1445 mBlockChangedSignal++;
1446 if ( !mAllowingNull && v < mMinSpinBox->value() )
1447 mMinSpinBox->setValue( v );
1448 mBlockChangedSignal--;
1450 if ( !mBlockChangedSignal )
1451 emit widgetValueHasChanged(
this );
1460 void QgsProcessingRangeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1463 if ( mAllowingNull && v.empty() )
1465 mMinSpinBox->clear();
1466 mMaxSpinBox->clear();
1473 if ( mAllowingNull )
1475 mBlockChangedSignal++;
1476 if ( std::isnan( v.at( 0 ) ) )
1477 mMinSpinBox->clear();
1479 mMinSpinBox->setValue( v.at( 0 ) );
1481 if ( v.count() >= 2 )
1483 if ( std::isnan( v.at( 1 ) ) )
1484 mMaxSpinBox->clear();
1486 mMaxSpinBox->setValue( v.at( 1 ) );
1488 mBlockChangedSignal--;
1492 mBlockChangedSignal++;
1493 mMinSpinBox->setValue( v.at( 0 ) );
1494 if ( v.count() >= 2 )
1495 mMaxSpinBox->setValue( v.at( 1 ) );
1496 mBlockChangedSignal--;
1500 if ( !mBlockChangedSignal )
1501 emit widgetValueHasChanged(
this );
1504 QVariant QgsProcessingRangeWidgetWrapper::widgetValue()
const
1506 if ( mAllowingNull )
1509 if (
qgsDoubleNear( mMinSpinBox->value(), mMinSpinBox->minimum() ) )
1510 value = QStringLiteral(
"None" );
1512 value = QString::number( mMinSpinBox->value() );
1514 if (
qgsDoubleNear( mMaxSpinBox->value(), mMaxSpinBox->minimum() ) )
1515 value += QLatin1String(
",None" );
1517 value += QStringLiteral(
",%1" ).arg( mMaxSpinBox->value() );
1522 return QStringLiteral(
"%1,%2" ).arg( mMinSpinBox->value() ).arg( mMaxSpinBox->value() );
1525 QStringList QgsProcessingRangeWidgetWrapper::compatibleParameterTypes()
const
1527 return QStringList()
1532 QStringList QgsProcessingRangeWidgetWrapper::compatibleOutputTypes()
const
1537 QString QgsProcessingRangeWidgetWrapper::modelerExpressionFormatString()
const
1539 return tr(
"string as two comma delimited floats, e.g. '1,10'" );
1542 QString QgsProcessingRangeWidgetWrapper::parameterType()
const
1549 return new QgsProcessingRangeWidgetWrapper( parameter, type );
1554 return new QgsProcessingRangeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1565 QVBoxLayout *vlayout =
new QVBoxLayout();
1566 vlayout->setContentsMargins( 0, 0, 0, 0 );
1568 mMatrixWidget =
new QgsProcessingMatrixModelerWidget();
1571 mMatrixWidget->setValue( matrixParam->headers(), matrixParam->defaultValueForGui() );
1572 mMatrixWidget->setFixedRows( matrixParam->hasFixedNumberRows() );
1574 vlayout->addWidget( mMatrixWidget );
1575 setLayout( vlayout );
1578 QgsProcessingParameterDefinition *QgsProcessingMatrixParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1580 auto param = qgis::make_unique< QgsProcessingParameterMatrix >( name, description, 1, mMatrixWidget->fixedRows(), mMatrixWidget->headers(), mMatrixWidget->value() );
1581 param->setFlags( flags );
1582 return param.release();
1592 QWidget *QgsProcessingMatrixWidgetWrapper::createWidget()
1594 mMatrixWidget =
new QgsProcessingMatrixParameterPanel(
nullptr,
dynamic_cast< const QgsProcessingParameterMatrix *
>( parameterDefinition() ) );
1595 mMatrixWidget->setToolTip( parameterDefinition()->toolTip() );
1597 connect( mMatrixWidget, &QgsProcessingMatrixParameterPanel::changed,
this, [ = ]
1599 emit widgetValueHasChanged(
this );
1608 return mMatrixWidget;
1614 void QgsProcessingMatrixWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1617 if ( mMatrixWidget )
1618 mMatrixWidget->setValue( v );
1621 QVariant QgsProcessingMatrixWidgetWrapper::widgetValue()
const
1623 if ( mMatrixWidget )
1624 return mMatrixWidget->value().isEmpty() ? QVariant() : mMatrixWidget->value();
1629 QStringList QgsProcessingMatrixWidgetWrapper::compatibleParameterTypes()
const
1631 return QStringList()
1635 QStringList QgsProcessingMatrixWidgetWrapper::compatibleOutputTypes()
const
1637 return QStringList();
1640 QString QgsProcessingMatrixWidgetWrapper::modelerExpressionFormatString()
const
1642 return tr(
"comma delimited string of values, or an array of values" );
1645 QString QgsProcessingMatrixWidgetWrapper::parameterType()
const
1652 return new QgsProcessingMatrixWidgetWrapper( parameter, type );
1657 return new QgsProcessingMatrixParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1669 QVBoxLayout *vlayout =
new QVBoxLayout();
1670 vlayout->setContentsMargins( 0, 0, 0, 0 );
1672 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
1674 mTypeComboBox =
new QComboBox();
1678 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( fileParam->behavior() ) );
1680 mTypeComboBox->setCurrentIndex( 0 );
1681 vlayout->addWidget( mTypeComboBox );
1683 vlayout->addWidget(
new QLabel( tr(
"File filter" ) ) );
1685 mFilterComboBox =
new QComboBox();
1686 mFilterComboBox->setEditable(
true );
1688 mFilterComboBox->addItem( tr(
"All Files (*.*)" ) );
1689 mFilterComboBox->addItem( tr(
"CSV Files (*.csv)" ) );
1690 mFilterComboBox->addItem( tr(
"HTML Files (*.html *.htm)" ) );
1691 mFilterComboBox->addItem( tr(
"Text Files (*.txt)" ) );
1693 mFilterComboBox->setCurrentText( fileParam->fileFilter() );
1695 mFilterComboBox->setCurrentIndex( 0 );
1696 vlayout->addWidget( mFilterComboBox );
1698 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1701 mDefaultFileWidget->lineEdit()->setShowClearButton(
true );
1705 mDefaultFileWidget->setFilePath( fileParam->defaultValueForGui().toString() );
1709 vlayout->addWidget( mDefaultFileWidget );
1711 connect( mTypeComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
this, [ = ]
1720 setLayout( vlayout );
1723 QgsProcessingParameterDefinition *QgsProcessingFileParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1725 auto param = qgis::make_unique< QgsProcessingParameterFile >( name, description );
1728 param->setFileFilter( mFilterComboBox->currentText() );
1729 if ( !mDefaultFileWidget->filePath().isEmpty() )
1730 param->setDefaultValue( mDefaultFileWidget->filePath() );
1731 param->setFlags( flags );
1732 return param.release();
1742 QWidget *QgsProcessingFileWidgetWrapper::createWidget()
1752 mFileWidget->setToolTip( parameterDefinition()->toolTip() );
1753 mFileWidget->setDialogTitle( parameterDefinition()->description() );
1755 mFileWidget->setDefaultRoot(
QgsSettings().value( QStringLiteral(
"/Processing/LastInputPath" ), QDir::homePath() ).toString() );
1762 mFileWidget->setFilter( fileParam->
fileFilter() );
1763 else if ( !fileParam->
extension().isEmpty() )
1764 mFileWidget->setFilter( tr(
"%1 files" ).arg( fileParam->
extension().toUpper() ) + QStringLiteral(
" (*." ) + fileParam->
extension().toLower() +
')' );
1774 QgsSettings().
setValue( QStringLiteral(
"/Processing/LastInputPath" ), QFileInfo( path ).canonicalPath() );
1775 emit widgetValueHasChanged(
this );
1783 void QgsProcessingFileWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1787 mFileWidget->setFilePath( v );
1790 QVariant QgsProcessingFileWidgetWrapper::widgetValue()
const
1793 return mFileWidget->filePath();
1798 QStringList QgsProcessingFileWidgetWrapper::compatibleParameterTypes()
const
1800 return QStringList()
1805 QStringList QgsProcessingFileWidgetWrapper::compatibleOutputTypes()
const
1815 QString QgsProcessingFileWidgetWrapper::modelerExpressionFormatString()
const
1817 return tr(
"string representing a path to a file or folder" );
1820 QString QgsProcessingFileWidgetWrapper::parameterType()
const
1827 return new QgsProcessingFileWidgetWrapper( parameter, type );
1832 return new QgsProcessingFileParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1844 QVBoxLayout *vlayout =
new QVBoxLayout();
1845 vlayout->setContentsMargins( 0, 0, 0, 0 );
1846 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1849 mDefaultLineEdit->registerExpressionContextGenerator(
this );
1853 vlayout->addWidget( mDefaultLineEdit );
1855 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
1857 mParentLayerComboBox =
new QComboBox();
1858 mParentLayerComboBox->addItem( tr(
"None" ), QVariant() );
1860 QString initialParent;
1862 initialParent = expParam->parentLayerParameterName();
1864 if ( QgsProcessingModelAlgorithm *model = widgetContext.
model() )
1867 const QMap<QString, QgsProcessingModelParameter> components = model->parameterComponents();
1868 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
1872 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1873 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1875 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1880 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1881 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1883 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1889 if ( mParentLayerComboBox->count() == 1 && !initialParent.isEmpty() )
1892 mParentLayerComboBox->addItem( initialParent, initialParent );
1893 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1896 vlayout->addWidget( mParentLayerComboBox );
1897 setLayout( vlayout );
1900 QgsProcessingParameterDefinition *QgsProcessingExpressionParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1902 auto param = qgis::make_unique< QgsProcessingParameterExpression >( name, description, mDefaultLineEdit->expression(), mParentLayerComboBox->currentData().toString() );
1903 param->setFlags( flags );
1904 return param.release();
1913 QWidget *QgsProcessingExpressionWidgetWrapper::createWidget()
1925 mExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
1926 mExpLineEdit->setExpressionDialogTitle( parameterDefinition()->description() );
1927 mExpLineEdit->registerExpressionContextGenerator(
this );
1930 emit widgetValueHasChanged(
this );
1932 return mExpLineEdit;
1936 if ( expParam->
metadata().value( QStringLiteral(
"inlineEditor" ) ).toBool() )
1939 mExpBuilderWidget->setToolTip( parameterDefinition()->toolTip() );
1940 mExpBuilderWidget->init( createExpressionContext() );
1943 Q_UNUSED( changed );
1944 emit widgetValueHasChanged(
this );
1946 return mExpBuilderWidget;
1951 mFieldExpWidget->setToolTip( parameterDefinition()->toolTip() );
1952 mFieldExpWidget->setExpressionDialogTitle( parameterDefinition()->description() );
1953 mFieldExpWidget->registerExpressionContextGenerator(
this );
1955 mFieldExpWidget->setAllowEmptyFieldName(
true );
1959 emit widgetValueHasChanged(
this );
1961 return mFieldExpWidget;
1969 void QgsProcessingExpressionWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1979 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterExpression *
>( parameterDefinition() )->parentLayerParameterName() )
1981 setParentLayerWrapperValue( wrapper );
1984 setParentLayerWrapperValue( wrapper );
2001 std::unique_ptr< QgsProcessingContext > tmpContext;
2002 if ( mProcessingContextGenerator )
2003 context = mProcessingContextGenerator->processingContext();
2007 tmpContext = qgis::make_unique< QgsProcessingContext >();
2008 context = tmpContext.get();
2022 if ( mFieldExpWidget )
2023 mFieldExpWidget->setLayer(
nullptr );
2024 else if ( mExpBuilderWidget )
2025 mExpBuilderWidget->setLayer(
nullptr );
2026 else if ( mExpLineEdit )
2027 mExpLineEdit->setLayer(
nullptr );
2033 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
2036 mParentLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
2037 layer = mParentLayer.get();
2044 if ( mFieldExpWidget )
2045 mFieldExpWidget->setLayer( layer );
2046 if ( mExpBuilderWidget )
2047 mExpBuilderWidget->setLayer( layer );
2048 else if ( mExpLineEdit )
2049 mExpLineEdit->setLayer( layer );
2052 void QgsProcessingExpressionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2055 if ( mFieldExpWidget )
2056 mFieldExpWidget->setExpression( v );
2057 else if ( mExpBuilderWidget )
2058 mExpBuilderWidget->setExpressionText( v );
2059 else if ( mExpLineEdit )
2060 mExpLineEdit->setExpression( v );
2063 QVariant QgsProcessingExpressionWidgetWrapper::widgetValue()
const
2065 if ( mFieldExpWidget )
2066 return mFieldExpWidget->expression();
2067 if ( mExpBuilderWidget )
2068 return mExpBuilderWidget->expressionText();
2069 else if ( mExpLineEdit )
2070 return mExpLineEdit->expression();
2075 QStringList QgsProcessingExpressionWidgetWrapper::compatibleParameterTypes()
const
2077 return QStringList()
2086 QStringList QgsProcessingExpressionWidgetWrapper::compatibleOutputTypes()
const
2088 return QStringList()
2093 QString QgsProcessingExpressionWidgetWrapper::modelerExpressionFormatString()
const
2095 return tr(
"string representation of an expression" );
2098 const QgsVectorLayer *QgsProcessingExpressionWidgetWrapper::linkedVectorLayer()
const
2100 if ( mFieldExpWidget && mFieldExpWidget->layer() )
2101 return mFieldExpWidget->layer();
2103 if ( mExpBuilderWidget && mExpBuilderWidget->layer() )
2104 return mExpBuilderWidget->layer();
2109 QString QgsProcessingExpressionWidgetWrapper::parameterType()
const
2116 return new QgsProcessingExpressionWidgetWrapper( parameter, type );
2121 return new QgsProcessingExpressionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2134 QHBoxLayout *hl =
new QHBoxLayout();
2135 hl->setContentsMargins( 0, 0, 0, 0 );
2137 mLineEdit =
new QLineEdit();
2138 mLineEdit->setEnabled(
false );
2139 hl->addWidget( mLineEdit, 1 );
2141 mToolButton =
new QToolButton();
2142 mToolButton->setText( QString( QChar( 0x2026 ) ) );
2143 hl->addWidget( mToolButton );
2149 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
2152 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingEnumPanelWidget::showDialog );
2155 void QgsProcessingEnumPanelWidget::setValue(
const QVariant &value )
2157 if ( value.isValid() )
2159 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
2161 if ( mParam->usesStaticStrings() && mValue.count() == 1 && mValue.at( 0 ).toString().isEmpty() )
2167 updateSummaryText();
2171 void QgsProcessingEnumPanelWidget::showDialog()
2173 QVariantList availableOptions;
2176 availableOptions.reserve( mParam->options().size() );
2177 for (
int i = 0; i < mParam->options().count(); ++i )
2178 availableOptions << i;
2181 const QStringList options = mParam ? mParam->options() : QStringList();
2185 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
2186 widget->setPanelTitle( mParam->description() );
2188 if ( mParam->usesStaticStrings() )
2190 widget->setValueFormatter( [options](
const QVariant & v ) -> QString
2192 const QString i = v.toString();
2193 return options.contains( i ) ? i : QString();
2198 widget->setValueFormatter( [options](
const QVariant & v ) -> QString
2200 const int i = v.toInt();
2201 return options.size() > i ? options.at( i ) : QString();
2205 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
2207 setValue( widget->selectedOptions() );
2214 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
2216 dlg.setValueFormatter( [options](
const QVariant & v ) -> QString
2218 const int i = v.toInt();
2219 return options.size() > i ? options.at( i ) : QString();
2223 setValue( dlg.selectedOptions() );
2228 void QgsProcessingEnumPanelWidget::updateSummaryText()
2231 mLineEdit->setText( tr(
"%1 options selected" ).arg( mValue.count() ) );
2238 QgsProcessingEnumCheckboxPanelWidget::QgsProcessingEnumCheckboxPanelWidget( QWidget *parent,
const QgsProcessingParameterEnum *param,
int columns )
2241 , mButtonGroup( new QButtonGroup( this ) )
2242 , mColumns( columns )
2244 mButtonGroup->setExclusive( !mParam->allowMultiple() );
2246 QGridLayout *l =
new QGridLayout();
2247 l->setContentsMargins( 0, 0, 0, 0 );
2249 int rows =
static_cast< int >( std::ceil( mParam->options().count() /
static_cast< double >( mColumns ) ) );
2250 for (
int i = 0; i < mParam->options().count(); ++i )
2252 QAbstractButton *button =
nullptr;
2253 if ( mParam->allowMultiple() )
2254 button =
new QCheckBox( mParam->options().at( i ) );
2256 button =
new QRadioButton( mParam->options().at( i ) );
2258 connect( button, &QAbstractButton::toggled,
this, [ = ]
2260 if ( !mBlockChangedSignal )
2264 mButtons.insert( i, button );
2266 mButtonGroup->addButton( button, i );
2267 l->addWidget( button, i % rows, i / rows );
2269 l->addItem(
new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, mColumns );
2272 if ( mParam->allowMultiple() )
2274 setContextMenuPolicy( Qt::CustomContextMenu );
2275 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsProcessingEnumCheckboxPanelWidget::showPopupMenu );
2279 QVariant QgsProcessingEnumCheckboxPanelWidget::value()
const
2281 if ( mParam->allowMultiple() )
2284 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2286 if ( it.value()->isChecked() )
2287 value.append( mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key() );
2293 if ( mParam->usesStaticStrings() )
2294 return mButtonGroup->checkedId() >= 0 ? mParam->options().at( mButtonGroup->checkedId() ) : QVariant();
2296 return mButtonGroup->checkedId() >= 0 ? mButtonGroup->checkedId() : QVariant();
2300 void QgsProcessingEnumCheckboxPanelWidget::setValue(
const QVariant &value )
2302 mBlockChangedSignal =
true;
2303 if ( mParam->allowMultiple() )
2305 QVariantList selected;
2306 if ( value.isValid() )
2307 selected = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
2308 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2310 QVariant v = mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key();
2311 it.value()->setChecked( selected.contains( v ) );
2317 if ( v.type() == QVariant::List )
2318 v = v.toList().value( 0 );
2320 v = mParam->usesStaticStrings() ? mParam->options().indexOf( v.toString() ) : v;
2321 if ( mButtons.contains( v ) )
2322 mButtons.value( v )->setChecked(
true );
2324 mBlockChangedSignal =
false;
2328 void QgsProcessingEnumCheckboxPanelWidget::showPopupMenu()
2331 QAction *selectAllAction =
new QAction( tr(
"Select All" ), &popupMenu );
2332 connect( selectAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::selectAll );
2333 QAction *clearAllAction =
new QAction( tr(
"Clear Selection" ), &popupMenu );
2334 connect( clearAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::deselectAll );
2335 popupMenu.addAction( selectAllAction );
2336 popupMenu.addAction( clearAllAction );
2337 popupMenu.exec( QCursor::pos() );
2340 void QgsProcessingEnumCheckboxPanelWidget::selectAll()
2342 mBlockChangedSignal =
true;
2343 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2344 it.value()->setChecked(
true );
2345 mBlockChangedSignal =
false;
2349 void QgsProcessingEnumCheckboxPanelWidget::deselectAll()
2351 mBlockChangedSignal =
true;
2352 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2353 it.value()->setChecked(
false );
2354 mBlockChangedSignal =
false;
2366 QVBoxLayout *vlayout =
new QVBoxLayout();
2367 vlayout->setContentsMargins( 0, 0, 0, 0 );
2369 mEnumWidget =
new QgsProcessingEnumModelerWidget();
2372 mEnumWidget->setAllowMultiple( enumParam->allowMultiple() );
2373 mEnumWidget->setOptions( enumParam->options() );
2374 mEnumWidget->setDefaultOptions( enumParam->defaultValueForGui() );
2376 vlayout->addWidget( mEnumWidget );
2377 setLayout( vlayout );
2380 QgsProcessingParameterDefinition *QgsProcessingEnumParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
2382 auto param = qgis::make_unique< QgsProcessingParameterEnum >( name, description, mEnumWidget->options(), mEnumWidget->allowMultiple(), mEnumWidget->defaultOptions() );
2384 return param.release();
2394 QWidget *QgsProcessingEnumWidgetWrapper::createWidget()
2402 if ( expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"useCheckBoxes" ),
false ).toBool() )
2404 const int columns = expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"columns" ), 2 ).toInt();
2405 mCheckboxPanel =
new QgsProcessingEnumCheckboxPanelWidget(
nullptr, expParam, columns );
2406 mCheckboxPanel->setToolTip( parameterDefinition()->toolTip() );
2407 connect( mCheckboxPanel, &QgsProcessingEnumCheckboxPanelWidget::changed,
this, [ = ]
2409 emit widgetValueHasChanged(
this );
2411 return mCheckboxPanel;
2420 mPanel =
new QgsProcessingEnumPanelWidget(
nullptr, expParam );
2421 mPanel->setToolTip( parameterDefinition()->toolTip() );
2422 connect( mPanel, &QgsProcessingEnumPanelWidget::changed,
this, [ = ]
2424 emit widgetValueHasChanged(
this );
2430 mComboBox =
new QComboBox();
2433 mComboBox->addItem( tr(
"[Not selected]" ), QVariant() );
2434 const QStringList options = expParam->
options();
2435 for (
int i = 0; i < options.count(); ++i )
2438 mComboBox->addItem( options.at( i ), options.at( i ) );
2440 mComboBox->addItem( options.at( i ), i );
2443 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2444 connect( mComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
2446 emit widgetValueHasChanged(
this );
2455 void QgsProcessingEnumWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2459 if ( !value.isValid() )
2460 mComboBox->setCurrentIndex( mComboBox->findData( QVariant() ) );
2467 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
2472 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
2476 else if ( mPanel || mCheckboxPanel )
2479 if ( value.isValid() )
2485 opts.reserve( v.size() );
2486 for ( QString i : v )
2492 opts.reserve( v.size() );
2498 mPanel->setValue( opts );
2499 else if ( mCheckboxPanel )
2500 mCheckboxPanel->setValue( opts );
2504 QVariant QgsProcessingEnumWidgetWrapper::widgetValue()
const
2507 return mComboBox->currentData();
2509 return mPanel->value();
2510 else if ( mCheckboxPanel )
2511 return mCheckboxPanel->value();
2516 QStringList QgsProcessingEnumWidgetWrapper::compatibleParameterTypes()
const
2518 return QStringList()
2524 QStringList QgsProcessingEnumWidgetWrapper::compatibleOutputTypes()
const
2526 return QStringList()
2531 QString QgsProcessingEnumWidgetWrapper::modelerExpressionFormatString()
const
2533 return tr(
"selected option index (starting from 0), array of indices, or comma separated string of options (e.g. '1,3')" );
2536 QString QgsProcessingEnumWidgetWrapper::parameterType()
const
2543 return new QgsProcessingEnumWidgetWrapper( parameter, type );
2548 return new QgsProcessingEnumParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2561 QWidget *QgsProcessingLayoutWidgetWrapper::createWidget()
2570 mComboBox =
new QgsLayoutComboBox(
nullptr, widgetContext().project() ? widgetContext().project()->layoutManager() :
nullptr );
2572 mComboBox->setAllowEmptyLayout(
true );
2575 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2578 emit widgetValueHasChanged(
this );
2585 mPlainComboBox =
new QComboBox();
2586 mPlainComboBox->setEditable(
true );
2587 mPlainComboBox->setToolTip( tr(
"Name of an existing print layout" ) );
2588 if ( widgetContext().project() )
2592 mPlainComboBox->addItem( layout->name() );
2595 connect( mPlainComboBox, &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
2597 emit widgetValueHasChanged(
this );
2599 return mPlainComboBox;
2605 void QgsProcessingLayoutWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2609 if ( !value.isValid() )
2610 mComboBox->setCurrentLayout(
nullptr );
2614 mComboBox->setCurrentLayout( l );
2616 mComboBox->setCurrentLayout(
nullptr );
2619 else if ( mPlainComboBox )
2622 mPlainComboBox->setCurrentText( v );
2626 QVariant QgsProcessingLayoutWidgetWrapper::widgetValue()
const
2631 return l ? l->
name() : QVariant();
2633 else if ( mPlainComboBox )
2634 return mPlainComboBox->currentText().isEmpty() ? QVariant() : mPlainComboBox->currentText();
2642 if ( mPlainComboBox && context.
project() )
2646 mPlainComboBox->addItem( layout->name() );
2650 QStringList QgsProcessingLayoutWidgetWrapper::compatibleParameterTypes()
const
2652 return QStringList()
2657 QStringList QgsProcessingLayoutWidgetWrapper::compatibleOutputTypes()
const
2659 return QStringList()
2663 QString QgsProcessingLayoutWidgetWrapper::modelerExpressionFormatString()
const
2665 return tr(
"string representing the name of an existing print layout" );
2668 QString QgsProcessingLayoutWidgetWrapper::parameterType()
const
2675 return new QgsProcessingLayoutWidgetWrapper( parameter, type );
2689 QVBoxLayout *vlayout =
new QVBoxLayout();
2690 vlayout->setContentsMargins( 0, 0, 0, 0 );
2692 vlayout->addWidget(
new QLabel( tr(
"Parent layout" ) ) );
2694 mParentLayoutComboBox =
new QComboBox();
2695 QString initialParent;
2697 initialParent = itemParam->parentLayoutParameterName();
2699 if (
auto *lModel = widgetContext.
model() )
2702 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
2703 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
2707 mParentLayoutComboBox-> addItem( definition->
description(), definition->
name() );
2708 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2710 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
2716 if ( mParentLayoutComboBox->count() == 0 && !initialParent.isEmpty() )
2719 mParentLayoutComboBox->addItem( initialParent, initialParent );
2720 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
2723 vlayout->addWidget( mParentLayoutComboBox );
2724 setLayout( vlayout );
2726 QgsProcessingParameterDefinition *QgsProcessingLayoutItemParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
2728 auto param = qgis::make_unique< QgsProcessingParameterLayoutItem >( name, description, QVariant(), mParentLayoutComboBox->currentData().toString() );
2730 return param.release();
2740 QWidget *QgsProcessingLayoutItemWidgetWrapper::createWidget()
2751 mComboBox->setAllowEmptyItem(
true );
2752 if ( layoutParam->
itemType() >= 0 )
2755 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2758 emit widgetValueHasChanged(
this );
2765 mLineEdit =
new QLineEdit();
2766 mLineEdit->setToolTip( tr(
"UUID or ID of an existing print layout item" ) );
2767 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
2769 emit widgetValueHasChanged(
this );
2777 void QgsProcessingLayoutItemWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
2787 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterLayoutItem *
>( parameterDefinition() )->parentLayoutParameterName() )
2789 setLayoutParameterValue( wrapper->parameterValue() );
2792 setLayoutParameterValue( wrapper->parameterValue() );
2805 void QgsProcessingLayoutItemWidgetWrapper::setLayoutParameterValue(
const QVariant &value )
2811 std::unique_ptr< QgsProcessingContext > tmpContext;
2812 if ( mProcessingContextGenerator )
2813 context = mProcessingContextGenerator->processingContext();
2817 tmpContext = qgis::make_unique< QgsProcessingContext >();
2818 context = tmpContext.get();
2822 setLayout( layout );
2825 void QgsProcessingLayoutItemWidgetWrapper::setLayout(
QgsPrintLayout *layout )
2828 mComboBox->setCurrentLayout( layout );
2831 void QgsProcessingLayoutItemWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2835 if ( !value.isValid() )
2836 mComboBox->setItem(
nullptr );
2840 mComboBox->setItem( item );
2843 else if ( mLineEdit )
2846 mLineEdit->setText( v );
2850 QVariant QgsProcessingLayoutItemWidgetWrapper::widgetValue()
const
2855 return i ? i->
uuid() : QVariant();
2857 else if ( mLineEdit )
2858 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
2863 QStringList QgsProcessingLayoutItemWidgetWrapper::compatibleParameterTypes()
const
2865 return QStringList()
2870 QStringList QgsProcessingLayoutItemWidgetWrapper::compatibleOutputTypes()
const
2872 return QStringList()
2876 QString QgsProcessingLayoutItemWidgetWrapper::modelerExpressionFormatString()
const
2878 return tr(
"string representing the UUID or ID of an existing print layout item" );
2881 QString QgsProcessingLayoutItemWidgetWrapper::parameterType()
const
2888 return new QgsProcessingLayoutItemWidgetWrapper( parameter, type );
2893 return new QgsProcessingLayoutItemParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2900 QgsProcessingPointMapTool::QgsProcessingPointMapTool(
QgsMapCanvas *canvas )
2907 QgsProcessingPointMapTool::~QgsProcessingPointMapTool() =
default;
2909 void QgsProcessingPointMapTool::deactivate()
2923 if ( e->button() == Qt::LeftButton )
2926 emit clicked( point );
2931 void QgsProcessingPointMapTool::keyPressEvent( QKeyEvent *e )
2933 if ( e->key() == Qt::Key_Escape )
2948 QgsProcessingPointPanel::QgsProcessingPointPanel( QWidget *parent )
2951 QHBoxLayout *l =
new QHBoxLayout();
2952 l->setContentsMargins( 0, 0, 0, 0 );
2954 mLineEdit->setShowClearButton(
false );
2955 l->addWidget( mLineEdit, 1 );
2956 mButton =
new QToolButton();
2957 mButton->setText( QString( QChar( 0x2026 ) ) );
2958 l->addWidget( mButton );
2961 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::changed );
2962 connect( mButton, &QToolButton::clicked,
this, &QgsProcessingPointPanel::selectOnCanvas );
2963 mButton->setVisible(
false );
2966 void QgsProcessingPointPanel::setMapCanvas(
QgsMapCanvas *canvas )
2969 mButton->setVisible(
true );
2972 mTool = qgis::make_unique< QgsProcessingPointMapTool >( mCanvas );
2973 connect( mTool.get(), &QgsProcessingPointMapTool::clicked,
this, &QgsProcessingPointPanel::updatePoint );
2974 connect( mTool.get(), &QgsProcessingPointMapTool::complete,
this, &QgsProcessingPointPanel::pointPicked );
2977 void QgsProcessingPointPanel::setAllowNull(
bool allowNull )
2979 mLineEdit->setShowClearButton( allowNull );
2982 QVariant QgsProcessingPointPanel::value()
const
2984 return mLineEdit->showClearButton() && mLineEdit->text().trimmed().isEmpty() ? QVariant() : QVariant( mLineEdit->text() );
2987 void QgsProcessingPointPanel::clear()
2994 QString newText = QStringLiteral(
"%1,%2" )
2995 .arg( QString::number( point.
x(),
'f' ),
2996 QString::number( point.
y(),
'f' ) );
2999 if ( mCrs.isValid() )
3001 newText += QStringLiteral(
" [%1]" ).arg( mCrs.authid() );
3003 mLineEdit->setText( newText );
3006 void QgsProcessingPointPanel::selectOnCanvas()
3011 mPrevTool = mCanvas->mapTool();
3012 mCanvas->setMapTool( mTool.get() );
3014 emit toggleDialogVisibility(
false );
3017 void QgsProcessingPointPanel::updatePoint(
const QgsPointXY &point )
3019 setValue( point, mCanvas->mapSettings().destinationCrs() );
3022 void QgsProcessingPointPanel::pointPicked()
3027 mCanvas->setMapTool( mPrevTool );
3029 emit toggleDialogVisibility(
true );
3041 QVBoxLayout *vlayout =
new QVBoxLayout();
3042 vlayout->setContentsMargins( 0, 0, 0, 0 );
3044 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3046 mDefaultLineEdit =
new QLineEdit();
3047 mDefaultLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
3048 mDefaultLineEdit->setPlaceholderText( tr(
"Point as 'x,y'" ) );
3052 mDefaultLineEdit->setText( QStringLiteral(
"%1,%2" ).arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) ) );
3055 vlayout->addWidget( mDefaultLineEdit );
3056 setLayout( vlayout );
3059 QgsProcessingParameterDefinition *QgsProcessingPointParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3061 auto param = qgis::make_unique< QgsProcessingParameterPoint >( name, description, mDefaultLineEdit->text() );
3063 return param.release();
3072 QWidget *QgsProcessingPointWidgetWrapper::createWidget()
3080 mPanel =
new QgsProcessingPointPanel(
nullptr );
3081 if ( widgetContext().mapCanvas() )
3082 mPanel->setMapCanvas( widgetContext().mapCanvas() );
3085 mPanel->setAllowNull(
true );
3087 mPanel->setToolTip( parameterDefinition()->toolTip() );
3089 connect( mPanel, &QgsProcessingPointPanel::changed,
this, [ = ]
3091 emit widgetValueHasChanged(
this );
3095 setDialog( mDialog );
3101 mLineEdit =
new QLineEdit();
3102 mLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
3103 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
3105 emit widgetValueHasChanged(
this );
3117 mPanel->setMapCanvas( context.
mapCanvas() );
3120 void QgsProcessingPointWidgetWrapper::setDialog( QDialog *dialog )
3125 connect( mPanel, &QgsProcessingPointPanel::toggleDialogVisibility, mDialog, [ = ](
bool visible )
3128 mDialog->showMinimized();
3131 mDialog->showNormal();
3133 mDialog->activateWindow();
3140 void QgsProcessingPointWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3144 if ( !value.isValid() || ( value.type() == QVariant::String && value.toString().isEmpty() ) )
3150 mPanel->setValue( p,
crs );
3153 else if ( mLineEdit )
3156 mLineEdit->setText( v );
3160 QVariant QgsProcessingPointWidgetWrapper::widgetValue()
const
3164 return mPanel->value();
3166 else if ( mLineEdit )
3167 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3172 QStringList QgsProcessingPointWidgetWrapper::compatibleParameterTypes()
const
3174 return QStringList()
3179 QStringList QgsProcessingPointWidgetWrapper::compatibleOutputTypes()
const
3181 return QStringList()
3185 QString QgsProcessingPointWidgetWrapper::modelerExpressionFormatString()
const
3187 return tr(
"string of the format 'x,y' or a geometry value (centroid is used)" );
3190 QString QgsProcessingPointWidgetWrapper::parameterType()
const
3197 return new QgsProcessingPointWidgetWrapper( parameter, type );
3202 return new QgsProcessingPointParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3214 QVBoxLayout *vlayout =
new QVBoxLayout();
3215 vlayout->setContentsMargins( 0, 0, 0, 0 );
3217 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3219 mDefaultLineEdit =
new QLineEdit();
3220 mDefaultLineEdit->setToolTip( tr(
"Geometry as WKT" ) );
3221 mDefaultLineEdit->setPlaceholderText( tr(
"Geometry as WKT" ) );
3226 mDefaultLineEdit->setText( g.
asWkt() );
3229 vlayout->addWidget( mDefaultLineEdit );
3230 setLayout( vlayout );
3233 QgsProcessingParameterDefinition *QgsProcessingGeometryParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3235 auto param = qgis::make_unique< QgsProcessingParameterGeometry >( name, description, mDefaultLineEdit->text() );
3237 return param.release();
3246 QWidget *QgsProcessingGeometryWidgetWrapper::createWidget()
3254 mLineEdit =
new QLineEdit();
3255 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
3256 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
3258 emit widgetValueHasChanged(
this );
3266 void QgsProcessingGeometryWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3272 mLineEdit->setText( g.
asWkt() );
3278 QVariant QgsProcessingGeometryWidgetWrapper::widgetValue()
const
3281 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3286 QStringList QgsProcessingGeometryWidgetWrapper::compatibleParameterTypes()
const
3288 return QStringList()
3295 QStringList QgsProcessingGeometryWidgetWrapper::compatibleOutputTypes()
const
3297 return QStringList()
3301 QString QgsProcessingGeometryWidgetWrapper::modelerExpressionFormatString()
const
3303 return tr(
"string in the Well-Known-Text format or a geometry value" );
3306 QString QgsProcessingGeometryWidgetWrapper::parameterType()
const
3313 return new QgsProcessingGeometryWidgetWrapper( parameter, type );
3318 return new QgsProcessingGeometryParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3330 QVBoxLayout *vlayout =
new QVBoxLayout();
3331 vlayout->setContentsMargins( 0, 0, 0, 0 );
3333 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3336 mDefaultColorButton->setShowNull(
true );
3337 mAllowOpacity =
new QCheckBox( tr(
"Allow opacity control" ) );
3343 mDefaultColorButton->setToNull();
3345 mDefaultColorButton->setColor(
c );
3346 mAllowOpacity->setChecked( colorParam->opacityEnabled() );
3350 mDefaultColorButton->setToNull();
3351 mAllowOpacity->setChecked(
true );
3354 vlayout->addWidget( mDefaultColorButton );
3355 vlayout->addWidget( mAllowOpacity );
3356 setLayout( vlayout );
3359 QgsProcessingParameterDefinition *QgsProcessingColorParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3361 auto param = qgis::make_unique< QgsProcessingParameterColor >( name, description, mDefaultColorButton->color(), mAllowOpacity->isChecked() );
3363 return param.release();
3372 QWidget *QgsProcessingColorWidgetWrapper::createWidget()
3382 mColorButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
3385 mColorButton->setShowNull(
true );
3388 mColorButton->setToolTip( parameterDefinition()->toolTip() );
3389 mColorButton->setColorDialogTitle( parameterDefinition()->description() );
3397 emit widgetValueHasChanged(
this );
3400 return mColorButton;
3406 void QgsProcessingColorWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3410 if ( !value.isValid() ||
3411 ( value.type() == QVariant::String && value.toString().isEmpty() )
3412 || ( value.type() == QVariant::Color && !value.value< QColor >().isValid() ) )
3413 mColorButton->setToNull();
3417 if ( !
c.isValid() && mColorButton->showNull() )
3418 mColorButton->setToNull();
3420 mColorButton->setColor(
c );
3425 QVariant QgsProcessingColorWidgetWrapper::widgetValue()
const
3428 return mColorButton->isNull() ? QVariant() : mColorButton->color();
3433 QStringList QgsProcessingColorWidgetWrapper::compatibleParameterTypes()
const
3435 return QStringList()
3440 QStringList QgsProcessingColorWidgetWrapper::compatibleOutputTypes()
const
3442 return QStringList()
3446 QString QgsProcessingColorWidgetWrapper::modelerExpressionFormatString()
const
3448 return tr(
"color style string, e.g. #ff0000 or 255,0,0" );
3451 QString QgsProcessingColorWidgetWrapper::parameterType()
const
3458 return new QgsProcessingColorWidgetWrapper( parameter, type );
3463 return new QgsProcessingColorParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3474 QVBoxLayout *vlayout =
new QVBoxLayout();
3475 vlayout->setContentsMargins( 0, 0, 0, 0 );
3477 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3479 mDefaultLineEdit =
new QLineEdit();
3482 vlayout->addWidget( mDefaultLineEdit );
3484 mSourceParamComboBox =
new QComboBox();
3485 mDestParamComboBox =
new QComboBox();
3486 QString initialSource;
3487 QString initialDest;
3492 initialSource = itemParam->sourceCrsParameterName();
3493 initialDest = itemParam->destinationCrsParameterName();
3498 mSourceParamComboBox->addItem( QString(), QString() );
3499 mDestParamComboBox->addItem( QString(), QString() );
3500 if (
auto *lModel = widgetContext.
model() )
3503 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3504 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3506 if ( definition && it->parameterName() == definition->
name() )
3510 mSourceParamComboBox->addItem( it->parameterName(), it->parameterName() );
3511 mDestParamComboBox->addItem( it->parameterName(), it->parameterName() );
3512 if ( !initialSource.isEmpty() && initialSource == it->parameterName() )
3514 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
3516 if ( !initialDest.isEmpty() && initialDest == it->parameterName() )
3518 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
3523 if ( mSourceParamComboBox->count() == 1 && !initialSource.isEmpty() )
3526 mSourceParamComboBox->addItem( initialSource, initialSource );
3527 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
3529 if ( mDestParamComboBox->count() == 1 && !initialDest.isEmpty() )
3532 mDestParamComboBox->addItem( initialDest, initialDest );
3533 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
3536 vlayout->addWidget(
new QLabel( tr(
"Source CRS parameter" ) ) );
3537 vlayout->addWidget( mSourceParamComboBox );
3538 vlayout->addWidget(
new QLabel( tr(
"Destination CRS parameter" ) ) );
3539 vlayout->addWidget( mDestParamComboBox );
3543 mStaticSourceWidget->setCrs( sourceCrs );
3546 mStaticDestWidget->setCrs( destCrs );
3548 vlayout->addWidget(
new QLabel( tr(
"Static source CRS" ) ) );
3549 vlayout->addWidget( mStaticSourceWidget );
3550 vlayout->addWidget(
new QLabel( tr(
"Static destination CRS" ) ) );
3551 vlayout->addWidget( mStaticDestWidget );
3553 setLayout( vlayout );
3556 QgsProcessingParameterDefinition *QgsProcessingCoordinateOperationParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3558 auto param = qgis::make_unique< QgsProcessingParameterCoordinateOperation >( name, description, mDefaultLineEdit->text(),
3559 mSourceParamComboBox->currentText(),
3560 mDestParamComboBox->currentText(),
3561 mStaticSourceWidget->crs().isValid() ? QVariant::fromValue( mStaticSourceWidget->crs() ) : QVariant(),
3562 mStaticDestWidget->crs().isValid() ? QVariant::fromValue( mStaticDestWidget->crs() ) : QVariant() );
3564 return param.release();
3573 QWidget *QgsProcessingCoordinateOperationWidgetWrapper::createWidget()
3584 mOperationWidget->setShowMakeDefault(
false );
3585 mOperationWidget->setShowFallbackOption(
false );
3586 mOperationWidget->setToolTip( parameterDefinition()->toolTip() );
3587 mOperationWidget->setSourceCrs( mSourceCrs );
3588 mOperationWidget->setDestinationCrs( mDestCrs );
3589 mOperationWidget->setMapCanvas( mCanvas );
3594 mOperationWidget->setSelectedOperation( deets );
3599 emit widgetValueHasChanged(
this );
3602 return mOperationWidget;
3608 mLineEdit =
new QLineEdit();
3609 QHBoxLayout *layout =
new QHBoxLayout();
3610 layout->addWidget( mLineEdit, 1 );
3611 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
3613 emit widgetValueHasChanged(
this );
3616 QToolButton *button =
new QToolButton();
3617 button->setText( QString( QChar( 0x2026 ) ) );
3618 connect( button, &QToolButton::clicked,
this, [ = ]
3620 QgsDatumTransformDialog dlg( mSourceCrs, mDestCrs,
false,
false,
false, qMakePair( -1, -1 ), button, Qt::WindowFlags(), mLineEdit->text(), mCanvas );
3623 mLineEdit->setText( dlg.selectedDatumTransform().proj );
3624 emit widgetValueHasChanged(
this );
3627 layout->addWidget( button );
3629 QWidget *w =
new QWidget();
3630 layout->setContentsMargins( 0, 0, 0, 0 );
3631 w->setLayout( layout );
3639 void QgsProcessingCoordinateOperationWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3651 setSourceCrsParameterValue( wrapper->parameterValue() );
3654 setSourceCrsParameterValue( wrapper->parameterValue() );
3659 setDestinationCrsParameterValue( wrapper->parameterValue() );
3662 setDestinationCrsParameterValue( wrapper->parameterValue() );
3677 if ( mOperationWidget )
3678 mOperationWidget->setMapCanvas( context.
mapCanvas() );
3681 void QgsProcessingCoordinateOperationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
3683 if ( mOperationWidget )
3685 if ( !value.isValid() ||
3686 ( value.type() == QVariant::String ) )
3689 deets.
proj = value.toString();
3690 mOperationWidget->setSelectedOperation( deets );
3695 if ( !value.isValid() ||
3696 ( value.type() == QVariant::String ) )
3698 mLineEdit->setText( value.toString() );
3703 QVariant QgsProcessingCoordinateOperationWidgetWrapper::widgetValue()
const
3705 if ( mOperationWidget )
3706 return mOperationWidget->selectedOperation().proj;
3707 else if ( mLineEdit )
3708 return mLineEdit->text();
3713 QStringList QgsProcessingCoordinateOperationWidgetWrapper::compatibleParameterTypes()
const
3715 return QStringList()
3720 QStringList QgsProcessingCoordinateOperationWidgetWrapper::compatibleOutputTypes()
const
3722 return QStringList()
3726 QString QgsProcessingCoordinateOperationWidgetWrapper::modelerExpressionFormatString()
const
3728 return tr(
"Proj coordinate operation string, e.g. '+proj=pipeline +step +inv...'" );
3731 void QgsProcessingCoordinateOperationWidgetWrapper::setSourceCrsParameterValue(
const QVariant &value )
3734 std::unique_ptr< QgsProcessingContext > tmpContext;
3735 if ( mProcessingContextGenerator )
3736 context = mProcessingContextGenerator->processingContext();
3740 tmpContext = qgis::make_unique< QgsProcessingContext >();
3741 context = tmpContext.get();
3745 if ( mOperationWidget )
3747 mOperationWidget->setSourceCrs( mSourceCrs );
3748 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
3752 void QgsProcessingCoordinateOperationWidgetWrapper::setDestinationCrsParameterValue(
const QVariant &value )
3755 std::unique_ptr< QgsProcessingContext > tmpContext;
3756 if ( mProcessingContextGenerator )
3757 context = mProcessingContextGenerator->processingContext();
3761 tmpContext = qgis::make_unique< QgsProcessingContext >();
3762 context = tmpContext.get();
3766 if ( mOperationWidget )
3768 mOperationWidget->setDestinationCrs( mDestCrs );
3769 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
3773 QString QgsProcessingCoordinateOperationWidgetWrapper::parameterType()
const
3780 return new QgsProcessingCoordinateOperationWidgetWrapper( parameter, type );
3785 return new QgsProcessingCoordinateOperationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3798 QHBoxLayout *hl =
new QHBoxLayout();
3799 hl->setContentsMargins( 0, 0, 0, 0 );
3801 mLineEdit =
new QLineEdit();
3802 mLineEdit->setEnabled(
false );
3803 hl->addWidget( mLineEdit, 1 );
3805 mToolButton =
new QToolButton();
3806 mToolButton->setText( QString( QChar( 0x2026 ) ) );
3807 hl->addWidget( mToolButton );
3813 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
3816 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingFieldPanelWidget::showDialog );
3819 void QgsProcessingFieldPanelWidget::setFields(
const QgsFields &fields )
3824 void QgsProcessingFieldPanelWidget::setValue(
const QVariant &value )
3826 if ( value.isValid() )
3827 mValue = value.type() == QVariant::List ? value.
toList() : QVariantList() << value;
3831 updateSummaryText();
3835 void QgsProcessingFieldPanelWidget::showDialog()
3837 QVariantList availableOptions;
3838 QStringList fieldNames;
3839 availableOptions.reserve( mFields.size() );
3848 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
3849 widget->setPanelTitle( mParam->description() );
3851 widget->setValueFormatter( [](
const QVariant & v ) -> QString
3853 return v.toString();
3856 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
3858 setValue( widget->selectedOptions() );
3865 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
3867 dlg.setValueFormatter( [](
const QVariant & v ) -> QString
3869 return v.toString();
3873 setValue( dlg.selectedOptions() );
3878 void QgsProcessingFieldPanelWidget::updateSummaryText()
3881 mLineEdit->setText( tr(
"%1 options selected" ).arg( mValue.count() ) );
3892 QVBoxLayout *vlayout =
new QVBoxLayout();
3893 vlayout->setContentsMargins( 0, 0, 0, 0 );
3895 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
3896 mParentLayerComboBox =
new QComboBox();
3898 QString initialParent;
3900 initialParent = fieldParam->parentLayerParameterName();
3902 if (
auto *lModel = widgetContext.
model() )
3905 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3906 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3910 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
3911 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
3913 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
3918 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
3919 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
3921 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
3928 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
3929 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
3931 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
3938 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
3941 mParentLayerComboBox->addItem( initialParent, initialParent );
3942 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
3945 vlayout->addWidget( mParentLayerComboBox );
3947 vlayout->addWidget(
new QLabel( tr(
"Allowed data type" ) ) );
3948 mDataTypeComboBox =
new QComboBox();
3954 mDataTypeComboBox->setCurrentIndex( mDataTypeComboBox->findData( fieldParam->dataType() ) );
3956 vlayout->addWidget( mDataTypeComboBox );
3958 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple fields" ) );
3960 mAllowMultipleCheckBox->setChecked( fieldParam->allowMultiple() );
3962 vlayout->addWidget( mAllowMultipleCheckBox );
3964 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all fields by default" ) );
3965 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
3967 mDefaultToAllCheckBox->setChecked( fieldParam->defaultToAllFields() );
3969 vlayout->addWidget( mDefaultToAllCheckBox );
3971 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [ = ]
3973 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
3976 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3978 mDefaultLineEdit =
new QLineEdit();
3979 mDefaultLineEdit->setToolTip( tr(
"Default field name, or ; separated list of field names for multiple field parameters" ) );
3983 mDefaultLineEdit->setText( fields.join(
';' ) );
3985 vlayout->addWidget( mDefaultLineEdit );
3987 setLayout( vlayout );
3990 QgsProcessingParameterDefinition *QgsProcessingFieldParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3993 auto param = qgis::make_unique< QgsProcessingParameterField >( name, description, mDefaultLineEdit->text(), mParentLayerComboBox->currentData().toString(), dataType, mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
3995 return param.release();
4004 QWidget *QgsProcessingFieldWidgetWrapper::createWidget()
4014 mPanel =
new QgsProcessingFieldPanelWidget(
nullptr, fieldParam );
4015 mPanel->setToolTip( parameterDefinition()->toolTip() );
4016 connect( mPanel, &QgsProcessingFieldPanelWidget::changed,
this, [ = ]
4018 emit widgetValueHasChanged(
this );
4034 mComboBox->setToolTip( parameterDefinition()->toolTip() );
4037 emit widgetValueHasChanged(
this );
4045 mLineEdit =
new QLineEdit();
4046 mLineEdit->setToolTip( QObject::tr(
"Name of field (separate field names with ; for multiple field parameters)" ) );
4047 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
4049 emit widgetValueHasChanged(
this );
4058 void QgsProcessingFieldWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
4068 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterField *
>( parameterDefinition() )->parentLayerParameterName() )
4070 setParentLayerWrapperValue( wrapper );
4073 setParentLayerWrapperValue( wrapper );
4090 std::unique_ptr< QgsProcessingContext > tmpContext;
4091 if ( mProcessingContextGenerator )
4092 context = mProcessingContextGenerator->processingContext();
4096 tmpContext = qgis::make_unique< QgsProcessingContext >();
4097 context = tmpContext.get();
4112 bool valueSet =
false;
4116 if ( layers.count() > 1 )
4118 QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( layers.at( 0 ) );
4120 const QList< QgsMapLayer * > remainingLayers = layers.mid( 1 );
4126 QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( layer );
4127 if ( !vlayer || !vlayer->
isValid() )
4133 for (
int fieldIdx = fields.
count() - 1; fieldIdx >= 0; fieldIdx-- )
4136 fields.
remove( fieldIdx );
4141 mComboBox->setFields( fields );
4143 mPanel->setFields( filterFields( fields ) );
4149 if ( !valueSet && !layers.isEmpty() && layers.at( 0 )->isValid() )
4151 QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( layers.at( 0 ) );
4155 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
4158 mParentLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
4159 layer = mParentLayer.get();
4167 mComboBox->setLayer( layer );
4169 mPanel->setFields( filterFields( layer->
fields() ) );
4179 const QgsFields fields = source->fields();
4181 mComboBox->setFields( fields );
4183 mPanel->setFields( filterFields( fields ) );
4192 mComboBox->setLayer(
nullptr );
4196 if ( value.isValid() && widgetContext().messageBar() )
4199 widgetContext().
messageBar()->
pushMessage( QString(), QObject::tr(
"Could not load selected layer/table. Dependent field could not be populated" ),
4209 val.reserve( mPanel->fields().size() );
4212 setWidgetValue( val, *context );
4215 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
4218 void QgsProcessingFieldWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4222 if ( !value.isValid() )
4223 mComboBox->setField( QString() );
4227 mComboBox->setField( v );
4233 if ( value.isValid() )
4236 opts.reserve( v.size() );
4237 for (
const QString &i : v )
4241 mPanel->setValue( opts );
4243 else if ( mLineEdit )
4249 mLineEdit->setText( v.join(
';' ) );
4258 QVariant QgsProcessingFieldWidgetWrapper::widgetValue()
const
4261 return mComboBox->currentField();
4263 return mPanel->value();
4264 else if ( mLineEdit )
4269 return mLineEdit->text().split(
';' );
4272 return mLineEdit->text();
4278 QStringList QgsProcessingFieldWidgetWrapper::compatibleParameterTypes()
const
4280 return QStringList()
4285 QStringList QgsProcessingFieldWidgetWrapper::compatibleOutputTypes()
const
4287 return QStringList()
4291 QString QgsProcessingFieldWidgetWrapper::modelerExpressionFormatString()
const
4293 return tr(
"selected field names as an array of names, or semicolon separated string of options (e.g. 'fid;place_name')" );
4296 const QgsVectorLayer *QgsProcessingFieldWidgetWrapper::linkedVectorLayer()
const
4298 if ( mComboBox && mComboBox->layer() )
4299 return mComboBox->layer();
4304 QgsFields QgsProcessingFieldWidgetWrapper::filterFields(
const QgsFields &fields )
const
4317 if ( f.isNumeric() )
4322 if ( f.type() == QVariant::String )
4327 if ( f.type() == QVariant::Date || f.type() == QVariant::Time || f.type() == QVariant::DateTime )
4336 QString QgsProcessingFieldWidgetWrapper::parameterType()
const
4343 return new QgsProcessingFieldWidgetWrapper( parameter, type );
4348 return new QgsProcessingFieldParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4359 QVBoxLayout *vlayout =
new QVBoxLayout();
4360 vlayout->setContentsMargins( 0, 0, 0, 0 );
4362 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4364 mDefaultComboBox =
new QComboBox();
4365 mDefaultComboBox->addItem( QString(), QVariant( -1 ) );
4368 for (
const QString &theme : mapThemes )
4372 mDefaultComboBox->setEditable(
true );
4376 if ( themeParam->defaultValueForGui().isValid() )
4379 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
4382 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
4384 vlayout->addWidget( mDefaultComboBox );
4386 setLayout( vlayout );
4389 QgsProcessingParameterDefinition *QgsProcessingMapThemeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4391 QVariant defaultVal;
4392 if ( mDefaultComboBox->currentText().isEmpty() )
4393 defaultVal = QVariant();
4395 defaultVal = mDefaultComboBox->currentText();
4396 auto param = qgis::make_unique< QgsProcessingParameterMapTheme>( name, description, defaultVal );
4398 return param.release();
4408 QWidget *QgsProcessingMapThemeWidgetWrapper::createWidget()
4412 mComboBox =
new QComboBox();
4415 mComboBox->addItem( tr(
"[Not selected]" ), QVariant( -1 ) );
4418 for (
const QString &theme : mapThemes )
4430 mComboBox->setEditable(
true );
4434 mComboBox->setToolTip( parameterDefinition()->toolTip() );
4435 connect( mComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
4437 emit widgetValueHasChanged(
this );
4443 void QgsProcessingMapThemeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4447 if ( !value.isValid() )
4448 mComboBox->setCurrentIndex( mComboBox->findData( QVariant( -1 ) ) );
4451 if ( mComboBox->isEditable() && mComboBox->findData( v ) == -1 )
4453 const QString prev = mComboBox->currentText();
4454 mComboBox->setCurrentText( v );
4456 emit widgetValueHasChanged(
this );
4459 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
4463 QVariant QgsProcessingMapThemeWidgetWrapper::widgetValue()
const
4466 return mComboBox->currentData().toInt() == -1 ? QVariant() :
4467 !mComboBox->currentData().isValid() && mComboBox->isEditable() ? mComboBox->currentText().isEmpty() ? QVariant() : QVariant( mComboBox->currentText() )
4468 : mComboBox->currentData();
4473 QStringList QgsProcessingMapThemeWidgetWrapper::compatibleParameterTypes()
const
4475 return QStringList()
4480 QStringList QgsProcessingMapThemeWidgetWrapper::compatibleOutputTypes()
const
4482 return QStringList()
4486 QString QgsProcessingMapThemeWidgetWrapper::modelerExpressionFormatString()
const
4488 return tr(
"map theme as a string value (e.g. 'base maps')" );
4491 QString QgsProcessingMapThemeWidgetWrapper::parameterType()
const
4498 return new QgsProcessingMapThemeWidgetWrapper( parameter, type );
4503 return new QgsProcessingMapThemeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4516 QVBoxLayout *vlayout =
new QVBoxLayout();
4517 vlayout->setContentsMargins( 0, 0, 0, 0 );
4519 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
4521 mTypeComboBox =
new QComboBox();
4526 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( datetimeParam->dataType() ) );
4528 mTypeComboBox->setCurrentIndex( 0 );
4529 vlayout->addWidget( mTypeComboBox );
4531 setLayout( vlayout );
4534 QgsProcessingParameterDefinition *QgsProcessingDateTimeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4536 auto param = qgis::make_unique< QgsProcessingParameterDateTime >( name, description );
4539 return param.release();
4549 QWidget *QgsProcessingDateTimeWidgetWrapper::createWidget()
4554 switch ( dateTimeParam->
dataType() )
4558 widget = mDateTimeEdit;
4581 widget->setToolTip( parameterDefinition()->toolTip() );
4583 if ( mDateTimeEdit )
4587 emit widgetValueHasChanged(
this );
4590 else if ( mDateEdit )
4594 emit widgetValueHasChanged(
this );
4597 else if ( mTimeEdit )
4601 emit widgetValueHasChanged(
this );
4610 return new QgsProcessingDateTimeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4613 void QgsProcessingDateTimeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4615 if ( mDateTimeEdit )
4619 else if ( mDateEdit )
4623 else if ( mTimeEdit )
4629 QVariant QgsProcessingDateTimeWidgetWrapper::widgetValue()
const
4631 if ( mDateTimeEdit )
4632 return !mDateTimeEdit->dateTime().isNull() && mDateTimeEdit->dateTime().isValid() ? QVariant( mDateTimeEdit->dateTime() ) : QVariant();
4633 else if ( mDateEdit )
4634 return !mDateEdit->date().isNull() && mDateEdit->date().isValid() ? QVariant( mDateEdit->date() ) : QVariant();
4635 else if ( mTimeEdit )
4636 return !mTimeEdit->time().isNull() && mTimeEdit->time().isValid() ? QVariant( mTimeEdit->time() ) : QVariant();
4641 QStringList QgsProcessingDateTimeWidgetWrapper::compatibleParameterTypes()
const
4643 return QStringList()
4648 QStringList QgsProcessingDateTimeWidgetWrapper::compatibleOutputTypes()
const
4650 return QStringList()
4654 QString QgsProcessingDateTimeWidgetWrapper::modelerExpressionFormatString()
const
4657 if ( dateTimeParam )
4659 switch ( dateTimeParam->
dataType() )
4662 return tr(
"datetime value, or a ISO string representation of a datetime" );
4665 return tr(
"date value, or a ISO string representation of a date" );
4668 return tr(
"time value, or a ISO string representation of a time" );
4674 QString QgsProcessingDateTimeWidgetWrapper::parameterType()
const
4681 return new QgsProcessingDateTimeWidgetWrapper( parameter, type );
4695 QVBoxLayout *vlayout =
new QVBoxLayout();
4696 vlayout->setContentsMargins( 0, 0, 0, 0 );
4698 vlayout->addWidget(
new QLabel( tr(
"Provider" ) ) );
4699 mProviderComboBox =
new QComboBox();
4700 mProviderComboBox->addItem( QObject::tr(
"Postgres" ), QStringLiteral(
"postgres" ) );
4701 mProviderComboBox->addItem( QObject::tr(
"GeoPackage" ), QStringLiteral(
"ogr" ) );
4702 mProviderComboBox->addItem( QObject::tr(
"Spatialite" ), QStringLiteral(
"spatialite" ) );
4704 vlayout->addWidget( mProviderComboBox );
4706 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4708 mDefaultEdit =
new QLineEdit();
4709 vlayout->addWidget( mDefaultEdit );
4710 setLayout( vlayout );
4712 if ( connectionParam )
4714 mProviderComboBox->setCurrentIndex( mProviderComboBox->findData( connectionParam->
providerId() ) );
4719 QgsProcessingParameterDefinition *QgsProcessingProviderConnectionParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4721 QVariant defaultVal;
4722 if ( mDefaultEdit->text().isEmpty() )
4723 defaultVal = QVariant();
4725 defaultVal = mDefaultEdit->text();
4726 auto param = qgis::make_unique< QgsProcessingParameterProviderConnection>( name, description, mProviderComboBox->currentData().toString(), defaultVal );
4728 return param.release();
4738 QWidget *QgsProcessingProviderConnectionWidgetWrapper::createWidget()
4744 mProviderComboBox->setAllowEmptyConnection(
true );
4752 mProviderComboBox->setEditable(
true );
4756 mProviderComboBox->setToolTip( parameterDefinition()->toolTip() );
4757 connect( mProviderComboBox, &QgsProviderConnectionComboBox::currentTextChanged,
this, [ = ](
const QString & )
4759 if ( mBlockSignals )
4762 emit widgetValueHasChanged(
this );
4765 return mProviderComboBox;
4770 return new QgsProcessingProviderConnectionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4773 void QgsProcessingProviderConnectionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4777 if ( !value.isValid() )
4778 mProviderComboBox->setCurrentIndex( -1 );
4781 if ( mProviderComboBox->isEditable() )
4783 const QString prev = mProviderComboBox->currentText();
4785 mProviderComboBox->setConnection( v );
4786 mProviderComboBox->setCurrentText( v );
4790 emit widgetValueHasChanged(
this );
4793 mProviderComboBox->setConnection( v );
4797 QVariant QgsProcessingProviderConnectionWidgetWrapper::widgetValue()
const
4799 if ( mProviderComboBox )
4800 if ( mProviderComboBox->isEditable() )
4801 return mProviderComboBox->currentText().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentText() );
4803 return mProviderComboBox->currentConnection().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentConnection() );
4808 QStringList QgsProcessingProviderConnectionWidgetWrapper::compatibleParameterTypes()
const
4810 return QStringList()
4816 QStringList QgsProcessingProviderConnectionWidgetWrapper::compatibleOutputTypes()
const
4818 return QStringList()
4822 QString QgsProcessingProviderConnectionWidgetWrapper::modelerExpressionFormatString()
const
4824 return tr(
"connection name as a string value" );
4827 QString QgsProcessingProviderConnectionWidgetWrapper::parameterType()
const
4834 return new QgsProcessingProviderConnectionWidgetWrapper( parameter, type );
4849 QVBoxLayout *vlayout =
new QVBoxLayout();
4850 vlayout->setContentsMargins( 0, 0, 0, 0 );
4852 mConnectionParamComboBox =
new QComboBox();
4853 QString initialConnection;
4859 if (
auto *lModel = widgetContext.
model() )
4862 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4863 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4865 if ( definition && it->parameterName() == definition->
name() )
4871 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
4872 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
4874 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
4879 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
4882 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
4883 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
4886 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
4887 vlayout->addWidget( mConnectionParamComboBox );
4889 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4891 mDefaultEdit =
new QLineEdit();
4892 vlayout->addWidget( mDefaultEdit );
4893 setLayout( vlayout );
4901 QgsProcessingParameterDefinition *QgsProcessingDatabaseSchemaParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4903 QVariant defaultVal;
4904 if ( mDefaultEdit->text().isEmpty() )
4905 defaultVal = QVariant();
4907 defaultVal = mDefaultEdit->text();
4908 auto param = qgis::make_unique< QgsProcessingParameterDatabaseSchema>( name, description, mConnectionParamComboBox->currentData().toString(), defaultVal );
4910 return param.release();
4920 QWidget *QgsProcessingDatabaseSchemaWidgetWrapper::createWidget()
4926 mSchemaComboBox->setAllowEmptySchema(
true );
4934 mSchemaComboBox->comboBox()->setEditable(
true );
4938 mSchemaComboBox->setToolTip( parameterDefinition()->toolTip() );
4939 connect( mSchemaComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
4941 if ( mBlockSignals )
4944 emit widgetValueHasChanged( this );
4947 return mSchemaComboBox;
4952 return new QgsProcessingDatabaseSchemaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4959 std::unique_ptr< QgsProcessingContext > tmpContext;
4960 if ( mProcessingContextGenerator )
4961 context = mProcessingContextGenerator->processingContext();
4965 tmpContext = qgis::make_unique< QgsProcessingContext >();
4966 context = tmpContext.get();
4972 if ( mSchemaComboBox )
4977 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
4980 void QgsProcessingDatabaseSchemaWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4984 if ( !value.isValid() )
4985 mSchemaComboBox->comboBox()->setCurrentIndex( -1 );
4988 if ( mSchemaComboBox->comboBox()->isEditable() )
4990 const QString prev = mSchemaComboBox->comboBox()->currentText();
4992 mSchemaComboBox->setSchema( v );
4993 mSchemaComboBox->comboBox()->setCurrentText( v );
4997 emit widgetValueHasChanged(
this );
5000 mSchemaComboBox->setSchema( v );
5004 QVariant QgsProcessingDatabaseSchemaWidgetWrapper::widgetValue()
const
5006 if ( mSchemaComboBox )
5007 if ( mSchemaComboBox->comboBox()->isEditable() )
5008 return mSchemaComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->comboBox()->currentText() );
5010 return mSchemaComboBox->currentSchema().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->currentSchema() );
5015 QStringList QgsProcessingDatabaseSchemaWidgetWrapper::compatibleParameterTypes()
const
5017 return QStringList()
5023 QStringList QgsProcessingDatabaseSchemaWidgetWrapper::compatibleOutputTypes()
const
5025 return QStringList()
5029 QString QgsProcessingDatabaseSchemaWidgetWrapper::modelerExpressionFormatString()
const
5031 return tr(
"database schema name as a string value" );
5034 QString QgsProcessingDatabaseSchemaWidgetWrapper::parameterType()
const
5041 return new QgsProcessingDatabaseSchemaWidgetWrapper( parameter, type );
5044 void QgsProcessingDatabaseSchemaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5056 setParentConnectionWrapperValue( wrapper );
5059 setParentConnectionWrapperValue( wrapper );
5083 QVBoxLayout *vlayout =
new QVBoxLayout();
5084 vlayout->setContentsMargins( 0, 0, 0, 0 );
5086 mConnectionParamComboBox =
new QComboBox();
5087 mSchemaParamComboBox =
new QComboBox();
5088 QString initialConnection;
5089 QString initialSchema;
5096 if (
auto *lModel = widgetContext.
model() )
5099 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
5100 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
5102 if ( definition && it->parameterName() == definition->
name() )
5107 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
5108 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5110 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5115 mSchemaParamComboBox->addItem( it->parameterName(), it->parameterName() );
5116 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5118 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
5124 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
5127 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
5128 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5131 if ( mSchemaParamComboBox->count() == 0 && !initialSchema.isEmpty() )
5134 mSchemaParamComboBox->addItem( initialSchema, initialSchema );
5135 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
5138 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
5139 vlayout->addWidget( mConnectionParamComboBox );
5141 vlayout->addWidget(
new QLabel( tr(
"Database schema parameter" ) ) );
5142 vlayout->addWidget( mSchemaParamComboBox );
5144 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5146 mDefaultEdit =
new QLineEdit();
5147 vlayout->addWidget( mDefaultEdit );
5148 setLayout( vlayout );
5156 QgsProcessingParameterDefinition *QgsProcessingDatabaseTableParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5158 QVariant defaultVal;
5159 if ( mDefaultEdit->text().isEmpty() )
5160 defaultVal = QVariant();
5162 defaultVal = mDefaultEdit->text();
5163 auto param = qgis::make_unique< QgsProcessingParameterDatabaseTable>( name, description,
5164 mConnectionParamComboBox->currentData().toString(),
5165 mSchemaParamComboBox->currentData().toString(),
5168 return param.release();
5178 QWidget *QgsProcessingDatabaseTableWidgetWrapper::createWidget()
5184 mTableComboBox->setAllowEmptyTable(
true );
5187 mTableComboBox->comboBox()->setEditable(
true );
5189 mTableComboBox->setToolTip( parameterDefinition()->toolTip() );
5190 connect( mTableComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
5192 if ( mBlockSignals )
5195 emit widgetValueHasChanged( this );
5198 return mTableComboBox;
5203 return new QgsProcessingDatabaseTableParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5210 std::unique_ptr< QgsProcessingContext > tmpContext;
5211 if ( mProcessingContextGenerator )
5212 context = mProcessingContextGenerator->processingContext();
5216 tmpContext = qgis::make_unique< QgsProcessingContext >();
5217 context = tmpContext.get();
5223 if ( mTableComboBox && !mSchema.isEmpty() )
5225 mTableComboBox->setSchema( mSchema );
5226 mTableComboBox->setConnectionName( mConnection, mProvider );
5230 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5238 std::unique_ptr< QgsProcessingContext > tmpContext;
5239 if ( mProcessingContextGenerator )
5240 context = mProcessingContextGenerator->processingContext();
5244 tmpContext = qgis::make_unique< QgsProcessingContext >();
5245 context = tmpContext.get();
5251 if ( mTableComboBox && !mSchema.isEmpty() && !mConnection.isEmpty() )
5253 mTableComboBox->setSchema( mSchema );
5254 mTableComboBox->setConnectionName( mConnection, mProvider );
5258 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5263 void QgsProcessingDatabaseTableWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5267 if ( !value.isValid() )
5268 mTableComboBox->comboBox()->setCurrentIndex( -1 );
5271 if ( mTableComboBox->comboBox()->isEditable() )
5273 const QString prev = mTableComboBox->comboBox()->currentText();
5275 mTableComboBox->setTable( v );
5276 mTableComboBox->comboBox()->setCurrentText( v );
5280 emit widgetValueHasChanged(
this );
5283 mTableComboBox->setTable( v );
5287 QVariant QgsProcessingDatabaseTableWidgetWrapper::widgetValue()
const
5289 if ( mTableComboBox )
5290 if ( mTableComboBox->comboBox()->isEditable() )
5291 return mTableComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mTableComboBox->comboBox()->currentText() );
5293 return mTableComboBox->currentTable().isEmpty() ? QVariant() : QVariant( mTableComboBox->currentTable() );
5298 QStringList QgsProcessingDatabaseTableWidgetWrapper::compatibleParameterTypes()
const
5300 return QStringList()
5306 QStringList QgsProcessingDatabaseTableWidgetWrapper::compatibleOutputTypes()
const
5308 return QStringList()
5312 QString QgsProcessingDatabaseTableWidgetWrapper::modelerExpressionFormatString()
const
5314 return tr(
"database table name as a string value" );
5317 QString QgsProcessingDatabaseTableWidgetWrapper::parameterType()
const
5324 return new QgsProcessingDatabaseTableWidgetWrapper( parameter, type );
5327 void QgsProcessingDatabaseTableWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5339 setParentConnectionWrapperValue( wrapper );
5342 setParentConnectionWrapperValue( wrapper );
5347 setParentSchemaWrapperValue( wrapper );
5350 setParentSchemaWrapperValue( wrapper );
5370 QVBoxLayout *vlayout =
new QVBoxLayout();
5371 vlayout->setContentsMargins( 0, 0, 0, 0 );
5373 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5376 mDefaultWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
5379 if ( extentParam->defaultValueForGui().isValid() )
5383 mDefaultWidget->setCurrentExtent( rect,
crs );
5384 mDefaultWidget->setOutputExtentFromCurrent();
5388 mDefaultWidget->clear();
5392 vlayout->addWidget( mDefaultWidget );
5393 setLayout( vlayout );
5396 QgsProcessingParameterDefinition *QgsProcessingExtentParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5398 const QString defaultVal = mDefaultWidget->isValid() ? QStringLiteral(
"%1,%2,%3,%4%5" ).arg(
5399 QString::number( mDefaultWidget->outputExtent().xMinimum(),
'f', 9 ),
5400 QString::number( mDefaultWidget->outputExtent().xMaximum(),
'f', 9 ),
5401 QString::number( mDefaultWidget->outputExtent().yMinimum(),
'f', 9 ),
5402 QString::number( mDefaultWidget->outputExtent().yMaximum(),
'f', 9 ),
5403 mDefaultWidget->outputCrs().isValid() ? QStringLiteral(
" [%1]" ).arg( mDefaultWidget->outputCrs().authid() ) : QString()
5405 auto param = qgis::make_unique< QgsProcessingParameterExtent >( name, description, !defaultVal.isEmpty() ? QVariant( defaultVal ) : QVariant() );
5407 return param.release();
5418 QWidget *QgsProcessingExtentWidgetWrapper::createWidget()
5428 if ( widgetContext().mapCanvas() )
5429 mExtentWidget->setMapCanvas( widgetContext().mapCanvas() );
5432 mExtentWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
5434 mExtentWidget->setToolTip( parameterDefinition()->toolTip() );
5438 emit widgetValueHasChanged(
this );
5442 setDialog( mDialog );
5444 return mExtentWidget;
5454 mExtentWidget->setMapCanvas( context.
mapCanvas() );
5457 void QgsProcessingExtentWidgetWrapper::setDialog( QDialog *dialog )
5465 mDialog->showMinimized();
5468 mDialog->showNormal();
5470 mDialog->activateWindow();
5477 void QgsProcessingExtentWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5479 if ( mExtentWidget )
5481 if ( !value.isValid() || ( value.type() == QVariant::String && value.toString().isEmpty() ) )
5482 mExtentWidget->clear();
5487 mExtentWidget->setCurrentExtent( r,
crs );
5488 mExtentWidget->setOutputExtentFromUser( r,
crs );
5493 QVariant QgsProcessingExtentWidgetWrapper::widgetValue()
const
5495 if ( mExtentWidget )
5497 const QString val = mExtentWidget->isValid() ? QStringLiteral(
"%1,%2,%3,%4%5" ).arg(
5498 QString::number( mExtentWidget->outputExtent().xMinimum(),
'f', 9 ),
5499 QString::number( mExtentWidget->outputExtent().xMaximum(),
'f', 9 ),
5500 QString::number( mExtentWidget->outputExtent().yMinimum(),
'f', 9 ),
5501 QString::number( mExtentWidget->outputExtent().yMaximum(),
'f', 9 ),
5502 mExtentWidget->outputCrs().isValid() ? QStringLiteral(
" [%1]" ).arg( mExtentWidget->outputCrs().authid() ) : QString()
5505 return val.isEmpty() ? QVariant() : QVariant( val );
5511 QStringList QgsProcessingExtentWidgetWrapper::compatibleParameterTypes()
const
5513 return QStringList()
5524 QStringList QgsProcessingExtentWidgetWrapper::compatibleOutputTypes()
const
5526 return QStringList()
5533 QString QgsProcessingExtentWidgetWrapper::modelerExpressionFormatString()
const
5535 return tr(
"string of the format 'x min,x max,y min,y max' or a geometry value (bounding box is used)" );
5538 QString QgsProcessingExtentWidgetWrapper::parameterType()
const
5545 return new QgsProcessingExtentWidgetWrapper( parameter, type );
5550 return new QgsProcessingExtentParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5562 QVBoxLayout *vlayout =
new QVBoxLayout();
5563 vlayout->setContentsMargins( 0, 0, 0, 0 );
5565 vlayout->addWidget(
new QLabel( tr(
"Layer type" ) ) );
5577 for (
int i : layerParam->dataTypes() )
5579 mLayerTypeComboBox->setItemCheckState( mLayerTypeComboBox->findData( i ), Qt::Checked );
5583 vlayout->addWidget( mLayerTypeComboBox );
5585 setLayout( vlayout );
5588 QgsProcessingParameterDefinition *QgsProcessingMapLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5590 QList< int > dataTypes;
5591 for (
const QVariant &v : mLayerTypeComboBox->checkedItemsData() )
5592 dataTypes << v.toInt();
5594 auto param = qgis::make_unique< QgsProcessingParameterMapLayer >( name, description );
5595 param->setDataTypes( dataTypes );
5597 return param.release();
5606 QWidget *QgsProcessingMapLayerWidgetWrapper::createWidget()
5608 mComboBox =
new QgsProcessingMapLayerComboBox( parameterDefinition(), type() );
5616 mComboBox->setEditable(
true );
5620 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5622 connect( mComboBox, &QgsProcessingMapLayerComboBox::valueChanged,
this, [ = ]()
5624 if ( mBlockSignals )
5627 emit widgetValueHasChanged(
this );
5630 setWidgetContext( widgetContext() );
5639 mComboBox->setWidgetContext( context );
5644 if ( !parameterDefinition()->defaultValueForGui().isValid() )
5650 void QgsProcessingMapLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5653 mComboBox->setValue( value, context );
5656 QVariant QgsProcessingMapLayerWidgetWrapper::widgetValue()
const
5658 return mComboBox ? mComboBox->value() : QVariant();
5661 QStringList QgsProcessingMapLayerWidgetWrapper::compatibleParameterTypes()
const
5663 return QStringList()
5672 QStringList QgsProcessingMapLayerWidgetWrapper::compatibleOutputTypes()
const
5674 return QStringList()
5682 QString QgsProcessingMapLayerWidgetWrapper::modelerExpressionFormatString()
const
5684 return tr(
"path to a map layer" );
5687 QString QgsProcessingMapLayerWidgetWrapper::parameterType()
const
5694 return new QgsProcessingMapLayerWidgetWrapper( parameter, type );
5699 return new QgsProcessingMapLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5708 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
5713 QStringList QgsProcessingRasterLayerWidgetWrapper::compatibleParameterTypes()
const
5715 return QStringList()
5722 QStringList QgsProcessingRasterLayerWidgetWrapper::compatibleOutputTypes()
const
5724 return QStringList()
5732 QString QgsProcessingRasterLayerWidgetWrapper::modelerExpressionFormatString()
const
5734 return tr(
"path to a raster layer" );
5737 QString QgsProcessingRasterLayerWidgetWrapper::parameterType()
const
5744 return new QgsProcessingRasterLayerWidgetWrapper( parameter, type );
5749 Q_UNUSED( context );
5750 Q_UNUSED( widgetContext );
5751 Q_UNUSED( definition );
5765 QVBoxLayout *vlayout =
new QVBoxLayout();
5766 vlayout->setContentsMargins( 0, 0, 0, 0 );
5768 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
5778 for (
int i : vectorParam->dataTypes() )
5780 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
5784 vlayout->addWidget( mGeometryTypeComboBox );
5786 setLayout( vlayout );
5789 QgsProcessingParameterDefinition *QgsProcessingVectorLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5791 QList< int > dataTypes;
5792 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
5793 dataTypes << v.toInt();
5795 auto param = qgis::make_unique< QgsProcessingParameterVectorLayer >( name, description, dataTypes );
5797 return param.release();
5802 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
5807 QStringList QgsProcessingVectorLayerWidgetWrapper::compatibleParameterTypes()
const
5809 return QStringList()
5816 QStringList QgsProcessingVectorLayerWidgetWrapper::compatibleOutputTypes()
const
5818 return QStringList()
5826 QString QgsProcessingVectorLayerWidgetWrapper::modelerExpressionFormatString()
const
5828 return tr(
"path to a vector layer" );
5834 return param->dataTypes();
5836 return QList< int >();
5839 QString QgsProcessingVectorLayerWidgetWrapper::parameterType()
const
5846 return new QgsProcessingVectorLayerWidgetWrapper( parameter, type );
5851 return new QgsProcessingVectorLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5863 QVBoxLayout *vlayout =
new QVBoxLayout();
5864 vlayout->setContentsMargins( 0, 0, 0, 0 );
5866 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
5876 for (
int i : sourceParam->dataTypes() )
5878 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
5886 vlayout->addWidget( mGeometryTypeComboBox );
5888 setLayout( vlayout );
5891 QgsProcessingParameterDefinition *QgsProcessingFeatureSourceParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5893 QList< int > dataTypes;
5894 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
5895 dataTypes << v.toInt();
5897 auto param = qgis::make_unique< QgsProcessingParameterFeatureSource >( name, description, dataTypes );
5899 return param.release();
5903 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
5908 QStringList QgsProcessingFeatureSourceWidgetWrapper::compatibleParameterTypes()
const
5910 return QStringList()
5918 QStringList QgsProcessingFeatureSourceWidgetWrapper::compatibleOutputTypes()
const
5920 return QStringList()
5928 QString QgsProcessingFeatureSourceWidgetWrapper::modelerExpressionFormatString()
const
5930 return tr(
"path to a vector layer" );
5936 return param->dataTypes();
5938 return QList< int >();
5941 QString QgsProcessingFeatureSourceWidgetWrapper::parameterType()
const
5948 return new QgsProcessingFeatureSourceWidgetWrapper( parameter, type );
5953 return new QgsProcessingFeatureSourceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5961 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
5966 QStringList QgsProcessingMeshLayerWidgetWrapper::compatibleParameterTypes()
const
5968 return QStringList()
5975 QStringList QgsProcessingMeshLayerWidgetWrapper::compatibleOutputTypes()
const
5977 return QStringList()
5985 QString QgsProcessingMeshLayerWidgetWrapper::modelerExpressionFormatString()
const
5987 return tr(
"path to a mesh layer" );
5990 QString QgsProcessingMeshLayerWidgetWrapper::parameterType()
const
5997 return new QgsProcessingMeshLayerWidgetWrapper( parameter, type );
6002 Q_UNUSED( context );
6003 Q_UNUSED( widgetContext );
6004 Q_UNUSED( definition );
6016 QgsProcessingRasterBandPanelWidget::QgsProcessingRasterBandPanelWidget( QWidget *parent,
const QgsProcessingParameterBand *param )
6020 QHBoxLayout *hl =
new QHBoxLayout();
6021 hl->setContentsMargins( 0, 0, 0, 0 );
6023 mLineEdit =
new QLineEdit();
6024 mLineEdit->setEnabled(
false );
6025 hl->addWidget( mLineEdit, 1 );
6027 mToolButton =
new QToolButton();
6028 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6029 hl->addWidget( mToolButton );
6035 mLineEdit->setText( tr(
"%1 bands selected" ).arg( 0 ) );
6038 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingRasterBandPanelWidget::showDialog );
6041 void QgsProcessingRasterBandPanelWidget::setBands(
const QList< int > &bands )
6046 void QgsProcessingRasterBandPanelWidget::setBandNames(
const QHash<int, QString> &names )
6051 void QgsProcessingRasterBandPanelWidget::setValue(
const QVariant &value )
6053 if ( value.isValid() )
6054 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
6058 updateSummaryText();
6062 void QgsProcessingRasterBandPanelWidget::showDialog()
6064 QVariantList availableOptions;
6065 QStringList fieldNames;
6066 availableOptions.reserve( mBands.size() );
6067 for (
int band : qgis::as_const( mBands ) )
6069 availableOptions << band;
6075 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
6076 widget->setPanelTitle( mParam->description() );
6078 widget->setValueFormatter( [
this](
const QVariant & v ) -> QString
6080 int band = v.toInt();
6081 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6084 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
6086 setValue( widget->selectedOptions() );
6093 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
6095 dlg.setValueFormatter( [
this](
const QVariant & v ) -> QString
6097 int band = v.toInt();
6098 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6102 setValue( dlg.selectedOptions() );
6107 void QgsProcessingRasterBandPanelWidget::updateSummaryText()
6110 mLineEdit->setText( tr(
"%1 bands selected" ).arg( mValue.count() ) );
6122 QVBoxLayout *vlayout =
new QVBoxLayout();
6123 vlayout->setContentsMargins( 0, 0, 0, 0 );
6125 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6127 mDefaultLineEdit =
new QLineEdit();
6128 mDefaultLineEdit->setToolTip( tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6133 for (
int b : bands )
6135 defVal << QString::number( b );
6138 mDefaultLineEdit->setText( defVal.join(
';' ) );
6140 vlayout->addWidget( mDefaultLineEdit );
6142 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
6143 mParentLayerComboBox =
new QComboBox();
6145 QString initialParent;
6147 initialParent = bandParam->parentLayerParameterName();
6149 if (
auto *lModel = widgetContext.
model() )
6152 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6153 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6157 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
6158 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
6160 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6166 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
6169 mParentLayerComboBox->addItem( initialParent, initialParent );
6170 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6173 vlayout->addWidget( mParentLayerComboBox );
6175 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Allow multiple" ) );
6177 mAllowMultipleCheckBox->setChecked( bandParam->allowMultiple() );
6179 vlayout->addWidget( mAllowMultipleCheckBox );
6180 setLayout( vlayout );
6183 QgsProcessingParameterDefinition *QgsProcessingBandParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6185 auto param = qgis::make_unique< QgsProcessingParameterBand >( name, description, mDefaultLineEdit->text().split(
';' ), mParentLayerComboBox->currentData().toString(),
false, mAllowMultipleCheckBox->isChecked() );
6187 return param.release();
6196 QWidget *QgsProcessingBandWidgetWrapper::createWidget()
6206 mPanel =
new QgsProcessingRasterBandPanelWidget(
nullptr, bandParam );
6207 mPanel->setToolTip( parameterDefinition()->toolTip() );
6208 connect( mPanel, &QgsProcessingRasterBandPanelWidget::changed,
this, [ = ]
6210 emit widgetValueHasChanged(
this );
6219 mComboBox->setToolTip( parameterDefinition()->toolTip() );
6222 emit widgetValueHasChanged(
this );
6230 mLineEdit =
new QLineEdit();
6231 mLineEdit->setToolTip( QObject::tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6232 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
6234 emit widgetValueHasChanged(
this );
6243 void QgsProcessingBandWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6253 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterBand *
>( parameterDefinition() )->parentLayerParameterName() )
6255 setParentLayerWrapperValue( wrapper );
6258 setParentLayerWrapperValue( wrapper );
6275 std::unique_ptr< QgsProcessingContext > tmpContext;
6276 if ( mProcessingContextGenerator )
6277 context = mProcessingContextGenerator->processingContext();
6281 tmpContext = qgis::make_unique< QgsProcessingContext >();
6282 context = tmpContext.get();
6288 if ( layer && layer->
isValid() )
6292 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
6295 mParentLayer.reset( qobject_cast< QgsRasterLayer * >( ownedLayer.release() ) );
6296 layer = mParentLayer.get();
6304 mComboBox->setLayer( layer );
6308 if ( provider && layer->
isValid() )
6313 QHash< int, QString > bandNames;
6314 for (
int i = 1; i <= nBands; ++i )
6319 mPanel->setBands( bands );
6320 mPanel->setBandNames( bandNames );
6327 mComboBox->setLayer(
nullptr );
6329 mPanel->setBands( QList< int >() );
6331 if ( value.isValid() && widgetContext().messageBar() )
6334 widgetContext().
messageBar()->
pushMessage( QString(), QObject::tr(
"Could not load selected layer/table. Dependent bands could not be populated" ),
6339 if ( parameterDefinition()->defaultValueForGui().isValid() )
6340 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6343 void QgsProcessingBandWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6347 if ( !value.isValid() )
6348 mComboBox->setBand( -1 );
6352 mComboBox->setBand( v );
6358 if ( value.isValid() )
6361 opts.reserve( v.size() );
6366 mPanel->setValue( value.isValid() ? opts : QVariant() );
6368 else if ( mLineEdit )
6375 opts.reserve( v.size() );
6377 opts << QString::number( i );
6378 mLineEdit->setText( value.isValid() && !opts.empty() ? opts.join(
';' ) : QString() );
6382 if ( value.isValid() )
6390 QVariant QgsProcessingBandWidgetWrapper::widgetValue()
const
6393 return mComboBox->currentBand() == -1 ? QVariant() : mComboBox->currentBand();
6395 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
6396 else if ( mLineEdit )
6401 const QStringList parts = mLineEdit->text().split(
';', QString::SkipEmptyParts );
6403 res.reserve( parts.count() );
6404 for (
const QString &s : parts )
6407 int band = s.toInt( &ok );
6411 return res.
isEmpty() ? QVariant() : res;
6415 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
6422 QStringList QgsProcessingBandWidgetWrapper::compatibleParameterTypes()
const
6424 return QStringList()
6429 QStringList QgsProcessingBandWidgetWrapper::compatibleOutputTypes()
const
6431 return QStringList()
6435 QString QgsProcessingBandWidgetWrapper::modelerExpressionFormatString()
const
6437 return tr(
"selected band numbers as an array of numbers, or semicolon separated string of options (e.g. '1;3')" );
6440 QString QgsProcessingBandWidgetWrapper::parameterType()
const
6447 return new QgsProcessingBandWidgetWrapper( parameter, type );
6452 return new QgsProcessingBandParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6465 QHBoxLayout *hl =
new QHBoxLayout();
6466 hl->setContentsMargins( 0, 0, 0, 0 );
6468 mLineEdit =
new QLineEdit();
6469 mLineEdit->setEnabled(
false );
6470 hl->addWidget( mLineEdit, 1 );
6472 mToolButton =
new QToolButton();
6473 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6474 hl->addWidget( mToolButton );
6480 mLineEdit->setText( tr(
"%1 inputs selected" ).arg( 0 ) );
6483 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingMultipleLayerPanelWidget::showDialog );
6486 void QgsProcessingMultipleLayerPanelWidget::setValue(
const QVariant &value )
6488 if ( value.isValid() )
6489 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
6493 updateSummaryText();
6497 void QgsProcessingMultipleLayerPanelWidget::setProject(
QgsProject *project )
6502 if ( mValue.removeAll( layerId ) )
6504 updateSummaryText();
6510 void QgsProcessingMultipleLayerPanelWidget::setModel( QgsProcessingModelAlgorithm *model,
const QString &modelChildAlgorithmID )
6516 switch ( mParam->layerType() )
6634 void QgsProcessingMultipleLayerPanelWidget::showDialog()
6639 QgsProcessingMultipleInputPanelWidget *widget =
new QgsProcessingMultipleInputPanelWidget( mParam, mValue, mModelSources, mModel );
6640 widget->setPanelTitle( mParam->description() );
6641 widget->setProject( mProject );
6642 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
6644 setValue( widget->selectedOptions() );
6651 QgsProcessingMultipleInputDialog dlg( mParam, mValue, mModelSources, mModel,
this, Qt::WindowFlags() );
6652 dlg.setProject( mProject );
6655 setValue( dlg.selectedOptions() );
6660 void QgsProcessingMultipleLayerPanelWidget::updateSummaryText()
6663 mLineEdit->setText( tr(
"%1 inputs selected" ).arg( mValue.count() ) );
6673 QVBoxLayout *vlayout =
new QVBoxLayout();
6674 vlayout->setContentsMargins( 0, 0, 0, 0 );
6676 vlayout->addWidget(
new QLabel( tr(
"Allowed layer type" ) ) );
6677 mLayerTypeComboBox =
new QComboBox();
6688 mLayerTypeComboBox->setCurrentIndex( mLayerTypeComboBox->findData( layersParam->layerType() ) );
6690 vlayout->addWidget( mLayerTypeComboBox );
6691 setLayout( vlayout );
6694 QgsProcessingParameterDefinition *QgsProcessingMultipleLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6696 auto param = qgis::make_unique< QgsProcessingParameterMultipleLayers >( name, description,
static_cast< QgsProcessing::SourceType >( mLayerTypeComboBox->currentData().toInt() ) );
6698 return param.release();
6707 QWidget *QgsProcessingMultipleLayerWidgetWrapper::createWidget()
6711 mPanel =
new QgsProcessingMultipleLayerPanelWidget(
nullptr, layerParam );
6712 mPanel->setToolTip( parameterDefinition()->toolTip() );
6713 mPanel->setProject( widgetContext().project() );
6714 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
6715 connect( mPanel, &QgsProcessingMultipleLayerPanelWidget::changed,
this, [ = ]
6717 emit widgetValueHasChanged(
this );
6727 mPanel->setProject( context.
project() );
6728 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
6732 void QgsProcessingMultipleLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6737 if ( value.isValid() )
6740 opts.reserve( v.size() );
6742 opts << l->source();
6745 for (
const QVariant &v : value.toList() )
6747 if ( v.canConvert< QgsProcessingModelChildParameterSource >() )
6749 const QgsProcessingModelChildParameterSource source = v.value< QgsProcessingModelChildParameterSource >();
6750 opts << QVariant::fromValue( source );
6755 mPanel->setValue( value.isValid() ? opts : QVariant() );
6759 QVariant QgsProcessingMultipleLayerWidgetWrapper::widgetValue()
const
6762 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
6767 QStringList QgsProcessingMultipleLayerWidgetWrapper::compatibleParameterTypes()
const
6769 return QStringList()
6780 QStringList QgsProcessingMultipleLayerWidgetWrapper::compatibleOutputTypes()
const
6782 return QStringList()
6791 QString QgsProcessingMultipleLayerWidgetWrapper::modelerExpressionFormatString()
const
6793 return tr(
"an array of layer paths, or semicolon separated string of layer paths" );
6796 QString QgsProcessingMultipleLayerWidgetWrapper::parameterType()
const
6803 return new QgsProcessingMultipleLayerWidgetWrapper( parameter, type );
6808 return new QgsProcessingMultipleLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6822 QWidget *QgsProcessingOutputWidgetWrapper::createWidget()
6830 mOutputWidget =
new QgsProcessingLayerOutputDestinationWidget( destParam,
false );
6831 if ( mProcessingContextGenerator )
6832 mOutputWidget->setContext( mProcessingContextGenerator->processingContext() );
6833 if ( mParametersGenerator )
6834 mOutputWidget->registerProcessingParametersGenerator( mParametersGenerator );
6835 mOutputWidget->setToolTip( parameterDefinition()->toolTip() );
6837 connect( mOutputWidget, &QgsProcessingLayerOutputDestinationWidget::destinationChanged,
this, [ = ]()
6839 if ( mBlockSignals )
6842 emit widgetValueHasChanged(
this );
6849 mOutputWidget->addOpenAfterRunningOption();
6851 return mOutputWidget;
6861 void QgsProcessingOutputWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
6863 if ( mOutputWidget )
6864 mOutputWidget->setValue( value );
6867 QVariant QgsProcessingOutputWidgetWrapper::widgetValue()
const
6869 if ( mOutputWidget )
6870 return mOutputWidget->value();
6875 QVariantMap QgsProcessingOutputWidgetWrapper::customProperties()
const
6878 if ( mOutputWidget )
6879 res.insert( QStringLiteral(
"OPEN_AFTER_RUNNING" ), mOutputWidget->openAfterRunning() );
6883 QStringList QgsProcessingOutputWidgetWrapper::compatibleParameterTypes()
const
6885 return QStringList()
6894 QStringList QgsProcessingOutputWidgetWrapper::compatibleOutputTypes()
const
6896 return QStringList()
6907 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
6912 QString QgsProcessingFeatureSinkWidgetWrapper::parameterType()
const
6919 return new QgsProcessingFeatureSinkWidgetWrapper( parameter, type );
6922 QString QgsProcessingFeatureSinkWidgetWrapper::modelerExpressionFormatString()
const
6924 return tr(
"path to layer destination" );
6932 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
6937 QString QgsProcessingVectorDestinationWidgetWrapper::parameterType()
const
6944 return new QgsProcessingVectorDestinationWidgetWrapper( parameter, type );
6947 QString QgsProcessingVectorDestinationWidgetWrapper::modelerExpressionFormatString()
const
6949 return tr(
"path to layer destination" );
6957 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
6962 QString QgsProcessingRasterDestinationWidgetWrapper::parameterType()
const
6969 return new QgsProcessingRasterDestinationWidgetWrapper( parameter, type );
6972 QString QgsProcessingRasterDestinationWidgetWrapper::modelerExpressionFormatString()
const
6974 return tr(
"path to layer destination" );
6982 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
6987 QString QgsProcessingFileDestinationWidgetWrapper::parameterType()
const
6994 return new QgsProcessingFileDestinationWidgetWrapper( parameter, type );
6997 QString QgsProcessingFileDestinationWidgetWrapper::modelerExpressionFormatString()
const
6999 return tr(
"path to file destination" );
7007 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7012 QString QgsProcessingFolderDestinationWidgetWrapper::parameterType()
const
7019 return new QgsProcessingFolderDestinationWidgetWrapper( parameter, type );
7022 QString QgsProcessingFolderDestinationWidgetWrapper::modelerExpressionFormatString()
const
7024 return tr(
"path to folder destination" );
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
Selector widget for authentication configs.
void selectedConfigIdChanged(const QString &authcfg)
Emitted when authentication config is changed or missing.
QComboBox subclass which allows selecting multiple items.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Q_GADGET QgsUnitTypes::DistanceUnit mapUnits
The QgsDatabaseSchemaComboBox class is a combo box which displays the list of schemas for a specific ...
The QgsDatabaseTableComboBox class is a combo box which displays the list of tables for a specific da...
The QgsDateEdit class is a QDateEdit widget with the capability of setting/reading null dates.
void dateValueChanged(const QDate &date)
Signal emitted whenever the date changes.
The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times.
void setAllowNull(bool allowNull)
Determines if the widget allows setting null date/time.
void setNullRepresentation(const QString &null)
Sets the widget's null representation, which defaults to QgsApplication::nullRepresentation().
void valueChanged(const QDateTime &date)
Signal emitted whenever the value changes.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
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 a 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
Gets field at particular index (must be in range 0..N-1)
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
A geometry is the spatial representation of a feature.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
The QgsLayoutComboBox class is a combo box which displays available layouts from a QgsLayoutManager.
void layoutChanged(QgsMasterLayoutInterface *layout)
Emitted whenever the currently selected layout changes.
The QgsLayoutItemComboBox class is a combo box which displays items of a matching type from a layout.
void itemChanged(QgsLayoutItem *item)
Emitted whenever the currently selected item changes.
Base class for graphical items within a QgsLayout.
virtual QString uuid() const
Returns the item identification string.
@ FilterPrintLayouts
Includes print layouts.
QList< QgsPrintLayout * > printLayouts() const
Returns a list of all print layouts contained in the manager.
Map canvas is a class for displaying all GIS data types on a canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
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::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.
Contains information about the context in which a processing algorithm is executed.
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.
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.
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.
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.
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.
static QgsCoordinateReferenceSystem variantToCrs(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a coordinate reference system.
SourceType
Data source types enum.
@ TypeVectorLine
Vector line layers.
@ TypeMapLayer
Any map layer type (raster or vector or mesh)
@ TypeVectorPolygon
Vector polygon layers.
@ TypeFile
Files (i.e. non map layer sources, such as text files)
@ 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.
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.
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
const QgsCoordinateReferenceSystem & crs