20 #include "processing/models/qgsprocessingmodelalgorithm.h"
61 #include <QToolButton>
63 #include <QHBoxLayout>
64 #include <QVBoxLayout>
68 #include <QPlainTextEdit>
69 #include <QRadioButton>
70 #include <QButtonGroup>
72 #include <QFileDialog>
84 QVBoxLayout *vlayout =
new QVBoxLayout();
85 vlayout->setMargin( 0 );
86 vlayout->setContentsMargins( 0, 0, 0, 0 );
88 mDefaultCheckBox =
new QCheckBox( tr(
"Checked" ) );
92 mDefaultCheckBox->setChecked(
false );
93 vlayout->addWidget( mDefaultCheckBox );
97 QgsProcessingParameterDefinition *QgsProcessingBooleanParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
99 auto param = qgis::make_unique< QgsProcessingParameterBoolean >( name, description, mDefaultCheckBox->isChecked() );
100 param->setFlags( flags );
101 return param.release();
111 QWidget *QgsProcessingBooleanWidgetWrapper::createWidget()
117 QString description = parameterDefinition()->description();
119 description = QObject::tr(
"%1 [optional]" ).arg( description );
121 mCheckBox =
new QCheckBox( description );
122 mCheckBox->setToolTip( parameterDefinition()->toolTip() );
124 connect( mCheckBox, &QCheckBox::toggled,
this, [ = ]
126 emit widgetValueHasChanged(
this );
134 mComboBox =
new QComboBox();
135 mComboBox->addItem( tr(
"Yes" ),
true );
136 mComboBox->addItem( tr(
"No" ),
false );
137 mComboBox->setToolTip( parameterDefinition()->toolTip() );
139 connect( mComboBox, qgis::overload< int>::of( &QComboBox::currentIndexChanged ),
this, [ = ]
141 emit widgetValueHasChanged(
this );
150 QLabel *QgsProcessingBooleanWidgetWrapper::createLabel()
159 void QgsProcessingBooleanWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
166 mCheckBox->setChecked( v );
174 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
180 QVariant QgsProcessingBooleanWidgetWrapper::widgetValue()
const
185 return mCheckBox->isChecked();
189 return mComboBox->currentData();
194 QStringList QgsProcessingBooleanWidgetWrapper::compatibleParameterTypes()
const
213 QStringList QgsProcessingBooleanWidgetWrapper::compatibleOutputTypes()
const
224 QString QgsProcessingBooleanWidgetWrapper::parameterType()
const
231 return new QgsProcessingBooleanWidgetWrapper( parameter, type );
236 return new QgsProcessingBooleanParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
247 QVBoxLayout *vlayout =
new QVBoxLayout();
248 vlayout->setMargin( 0 );
249 vlayout->setContentsMargins( 0, 0, 0, 0 );
251 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
259 vlayout->addWidget( mCrsSelector );
260 setLayout( vlayout );
263 QgsProcessingParameterDefinition *QgsProcessingCrsParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
265 auto param = qgis::make_unique< QgsProcessingParameterCrs >( name, description, mCrsSelector->crs().authid() );
266 param->setFlags( flags );
267 return param.release();
276 QWidget *QgsProcessingCrsWidgetWrapper::createWidget()
278 Q_ASSERT( mProjectionSelectionWidget ==
nullptr );
280 mProjectionSelectionWidget->setToolTip( parameterDefinition()->toolTip() );
289 emit widgetValueHasChanged(
this );
297 return mProjectionSelectionWidget;
302 QWidget *w =
new QWidget();
303 w->setToolTip( parameterDefinition()->toolTip() );
305 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->setMargin( 0 );
409 vlayout->setContentsMargins( 0, 0, 0, 0 );
411 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
413 mDefaultLineEdit =
new QLineEdit();
416 vlayout->addWidget( mDefaultLineEdit );
418 mMultiLineCheckBox =
new QCheckBox( tr(
"Multiline input" ) );
420 mMultiLineCheckBox->setChecked( stringParam->multiLine() );
421 vlayout->addWidget( mMultiLineCheckBox );
423 setLayout( vlayout );
426 QgsProcessingParameterDefinition *QgsProcessingStringParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
428 auto param = qgis::make_unique< QgsProcessingParameterString >( name, description, mDefaultLineEdit->text(), mMultiLineCheckBox->isChecked() );
429 param->setFlags( flags );
430 return param.release();
441 QWidget *QgsProcessingStringWidgetWrapper::createWidget()
450 mPlainTextEdit =
new QPlainTextEdit();
451 mPlainTextEdit->setToolTip( parameterDefinition()->toolTip() );
453 connect( mPlainTextEdit, &QPlainTextEdit::textChanged,
this, [ = ]
455 emit widgetValueHasChanged(
this );
457 return mPlainTextEdit;
461 mLineEdit =
new QLineEdit();
462 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
464 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
466 emit widgetValueHasChanged(
this );
474 mLineEdit =
new QLineEdit();
475 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
477 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
479 emit widgetValueHasChanged(
this );
487 void QgsProcessingStringWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
491 mLineEdit->setText( v );
492 if ( mPlainTextEdit )
493 mPlainTextEdit->setPlainText( v );
496 QVariant QgsProcessingStringWidgetWrapper::widgetValue()
const
499 return mLineEdit->text();
500 else if ( mPlainTextEdit )
501 return mPlainTextEdit->toPlainText();
506 QStringList QgsProcessingStringWidgetWrapper::compatibleParameterTypes()
const
521 QStringList QgsProcessingStringWidgetWrapper::compatibleOutputTypes()
const
529 QString QgsProcessingStringWidgetWrapper::parameterType()
const
536 return new QgsProcessingStringWidgetWrapper( parameter, type );
541 return new QgsProcessingStringParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
556 QWidget *QgsProcessingAuthConfigWidgetWrapper::createWidget()
564 mAuthConfigSelect =
new QgsAuthConfigSelect();
565 mAuthConfigSelect->setToolTip( parameterDefinition()->toolTip() );
569 emit widgetValueHasChanged(
this );
571 return mAuthConfigSelect;
577 void QgsProcessingAuthConfigWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
580 if ( mAuthConfigSelect )
581 mAuthConfigSelect->setConfigId( v );
584 QVariant QgsProcessingAuthConfigWidgetWrapper::widgetValue()
const
586 if ( mAuthConfigSelect )
587 return mAuthConfigSelect->configId();
592 QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleParameterTypes()
const
600 QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleOutputTypes()
const
605 QString QgsProcessingAuthConfigWidgetWrapper::parameterType()
const
612 return new QgsProcessingAuthConfigWidgetWrapper( parameter, type );
622 QVBoxLayout *vlayout =
new QVBoxLayout();
623 vlayout->setMargin( 0 );
624 vlayout->setContentsMargins( 0, 0, 0, 0 );
626 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
628 mTypeComboBox =
new QComboBox();
631 vlayout->addWidget( mTypeComboBox );
633 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
634 mMinLineEdit =
new QLineEdit();
635 vlayout->addWidget( mMinLineEdit );
637 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
638 mMaxLineEdit =
new QLineEdit();
639 vlayout->addWidget( mMaxLineEdit );
641 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
642 mDefaultLineEdit =
new QLineEdit();
643 vlayout->addWidget( mDefaultLineEdit );
647 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( numberParam->dataType() ) );
648 mMinLineEdit->setText( QString::number( numberParam->minimum() ) );
649 mMaxLineEdit->setText( QString::number( numberParam->maximum() ) );
650 mDefaultLineEdit->setText( numberParam->defaultValue().toString() );
653 setLayout( vlayout );
656 QgsProcessingParameterDefinition *QgsProcessingNumberParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
659 double val = mDefaultLineEdit->text().toDouble( &ok );
662 auto param = qgis::make_unique< QgsProcessingParameterNumber >( name, description, dataType, ok ? val : QVariant() );
664 val = mMinLineEdit->text().toDouble( &ok );
667 param->setMinimum( val );
670 val = mMaxLineEdit->text().toDouble( &ok );
673 param->setMaximum( val );
676 param->setFlags( flags );
677 return param.release();
686 QWidget *QgsProcessingNumericWidgetWrapper::createWidget()
689 const QVariantMap metadata = numberDef->
metadata();
690 const int decimals = metadata.value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"decimals" ), 6 ).toInt();
698 QAbstractSpinBox *spinBox =
nullptr;
703 mDoubleSpinBox->setExpressionsEnabled(
true );
704 mDoubleSpinBox->setDecimals( decimals );
710 double singleStep = calculateStep( numberDef->
minimum(), numberDef->
maximum() );
711 singleStep = std::max( singleStep, std::pow( 10, -decimals ) );
712 mDoubleSpinBox->setSingleStep( singleStep );
715 spinBox = mDoubleSpinBox;
720 mSpinBox->setExpressionsEnabled(
true );
724 spinBox->setToolTip( parameterDefinition()->toolTip() );
726 double max = 999999999;
731 double min = -999999999;
736 if ( mDoubleSpinBox )
738 mDoubleSpinBox->setMinimum( min );
739 mDoubleSpinBox->setMaximum( max );
743 mSpinBox->setMinimum(
static_cast< int >( min ) );
744 mSpinBox->setMaximum(
static_cast< int >( max ) );
749 mAllowingNull =
true;
750 if ( mDoubleSpinBox )
752 mDoubleSpinBox->setShowClearButton(
true );
753 const double min = mDoubleSpinBox->minimum() - 1;
754 mDoubleSpinBox->setMinimum( min );
755 mDoubleSpinBox->setValue( min );
759 mSpinBox->setShowClearButton(
true );
760 const int min = mSpinBox->minimum() - 1;
761 mSpinBox->setMinimum( min );
762 mSpinBox->setValue( min );
764 spinBox->setSpecialValueText( tr(
"Not set" ) );
772 if ( mDoubleSpinBox )
774 double defaultVal = numberDef->
defaultValue().toDouble( &ok );
776 mDoubleSpinBox->setClearValue( defaultVal );
782 mSpinBox->setClearValue( intVal );
788 if ( mDoubleSpinBox )
789 mDoubleSpinBox->setClearValue( numberDef->
minimum() );
791 mSpinBox->setClearValue(
static_cast< int >( numberDef->
minimum() ) );
796 if ( mDoubleSpinBox )
798 mDoubleSpinBox->setValue( 0 );
799 mDoubleSpinBox->setClearValue( 0 );
803 mSpinBox->setValue( 0 );
804 mSpinBox->setClearValue( 0 );
809 if ( mDoubleSpinBox )
810 connect( mDoubleSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
this, [ = ] { emit widgetValueHasChanged(
this ); } );
812 connect( mSpinBox, qgis::overload<int>::of( &QgsSpinBox::valueChanged ),
this, [ = ] { emit widgetValueHasChanged(
this ); } );
820 void QgsProcessingNumericWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
822 if ( mDoubleSpinBox )
824 if ( mAllowingNull && !value.isValid() )
825 mDoubleSpinBox->clear();
829 mDoubleSpinBox->setValue( v );
834 if ( mAllowingNull && !value.isValid() )
839 mSpinBox->setValue( v );
844 QVariant QgsProcessingNumericWidgetWrapper::widgetValue()
const
846 if ( mDoubleSpinBox )
848 if ( mAllowingNull &&
qgsDoubleNear( mDoubleSpinBox->value(), mDoubleSpinBox->minimum() ) )
851 return mDoubleSpinBox->value();
855 if ( mAllowingNull && mSpinBox->value() == mSpinBox->minimum() )
858 return mSpinBox->value();
864 QStringList QgsProcessingNumericWidgetWrapper::compatibleParameterTypes()
const
873 QStringList QgsProcessingNumericWidgetWrapper::compatibleOutputTypes()
const
879 double QgsProcessingNumericWidgetWrapper::calculateStep(
const double minimum,
const double maximum )
881 const double valueRange = maximum - minimum;
882 if ( valueRange <= 1.0 )
884 const double step = valueRange / 10.0;
886 return qgsRound( step, -std::floor( std::log( step ) ) );
894 QString QgsProcessingNumericWidgetWrapper::parameterType()
const
901 return new QgsProcessingNumericWidgetWrapper( parameter, type );
906 return new QgsProcessingNumberParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
916 QVBoxLayout *vlayout =
new QVBoxLayout();
917 vlayout->setMargin( 0 );
918 vlayout->setContentsMargins( 0, 0, 0, 0 );
920 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
922 mParentLayerComboBox =
new QComboBox();
924 QString initialParent;
926 initialParent = distParam->parentParameterName();
928 if ( widgetContext.
model() )
931 const QMap<QString, QgsProcessingModelParameter> components = widgetContext.
model()->parameterComponents();
932 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
936 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
937 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
939 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
944 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
945 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
947 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
952 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
953 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
955 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
960 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
961 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
963 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
969 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
972 mParentLayerComboBox->addItem( initialParent, initialParent );
973 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
976 vlayout->addWidget( mParentLayerComboBox );
978 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
979 mMinLineEdit =
new QLineEdit();
980 vlayout->addWidget( mMinLineEdit );
982 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
983 mMaxLineEdit =
new QLineEdit();
984 vlayout->addWidget( mMaxLineEdit );
986 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
987 mDefaultLineEdit =
new QLineEdit();
988 vlayout->addWidget( mDefaultLineEdit );
992 mMinLineEdit->setText( QString::number( distParam->minimum() ) );
993 mMaxLineEdit->setText( QString::number( distParam->maximum() ) );
994 mDefaultLineEdit->setText( distParam->defaultValue().toString() );
997 setLayout( vlayout );
1000 QgsProcessingParameterDefinition *QgsProcessingDistanceParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1003 double val = mDefaultLineEdit->text().toDouble( &ok );
1005 auto param = qgis::make_unique< QgsProcessingParameterDistance >( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1007 val = mMinLineEdit->text().toDouble( &ok );
1010 param->setMinimum( val );
1013 val = mMaxLineEdit->text().toFloat( &ok );
1016 param->setMaximum( val );
1019 param->setFlags( flags );
1020 return param.release();
1024 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1029 QString QgsProcessingDistanceWidgetWrapper::parameterType()
const
1036 return new QgsProcessingDistanceWidgetWrapper( parameter, type );
1039 QWidget *QgsProcessingDistanceWidgetWrapper::createWidget()
1043 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1048 mLabel =
new QLabel();
1049 mUnitsCombo =
new QComboBox();
1057 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
1058 const int labelMargin =
static_cast< int >( std::round( mUnitsCombo->fontMetrics().width(
'X' ) ) );
1060 const int labelMargin =
static_cast< int >( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1062 QHBoxLayout *layout =
new QHBoxLayout();
1063 layout->addWidget( spin, 1 );
1064 layout->insertSpacing( 1, labelMargin / 2 );
1065 layout->insertWidget( 2, mLabel );
1066 layout->insertWidget( 3, mUnitsCombo );
1071 mWarningLabel =
new QWidget();
1072 QHBoxLayout *warningLayout =
new QHBoxLayout();
1073 warningLayout->setMargin( 0 );
1074 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1075 QLabel *warning =
new QLabel();
1077 const int size =
static_cast< int >( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1078 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1079 warning->setToolTip( tr(
"Distance is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1080 warningLayout->insertSpacing( 0, labelMargin / 2 );
1081 warningLayout->insertWidget( 1, warning );
1082 mWarningLabel->setLayout( warningLayout );
1083 layout->insertWidget( 4, mWarningLabel );
1085 QWidget *w =
new QWidget();
1086 layout->setMargin( 0 );
1087 layout->setContentsMargins( 0, 0, 0, 0 );
1088 w->setLayout( layout );
1103 void QgsProcessingDistanceWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1105 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1112 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterDistance *
>( parameterDefinition() )->parentParameterName() )
1114 setUnitParameterValue( wrapper->parameterValue() );
1117 setUnitParameterValue( wrapper->parameterValue() );
1131 void QgsProcessingDistanceWidgetWrapper::setUnitParameterValue(
const QVariant &value )
1137 std::unique_ptr< QgsProcessingContext > tmpContext;
1138 if ( mProcessingContextGenerator )
1139 context = mProcessingContextGenerator->processingContext();
1143 tmpContext = qgis::make_unique< QgsProcessingContext >();
1144 context = tmpContext.get();
1161 mUnitsCombo->hide();
1166 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( units ) );
1167 mUnitsCombo->show();
1174 QVariant QgsProcessingDistanceWidgetWrapper::widgetValue()
const
1176 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1177 if ( val.type() == QVariant::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1190 return new QgsProcessingDistanceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1200 QVBoxLayout *vlayout =
new QVBoxLayout();
1201 vlayout->setMargin( 0 );
1202 vlayout->setContentsMargins( 0, 0, 0, 0 );
1204 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1206 mDefaultLineEdit =
new QLineEdit();
1210 mDefaultLineEdit->setText( scaleParam->defaultValue().toString() );
1213 vlayout->addWidget( mDefaultLineEdit );
1215 setLayout( vlayout );
1218 QgsProcessingParameterDefinition *QgsProcessingScaleParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1221 double val = mDefaultLineEdit->text().toDouble( &ok );
1222 auto param = qgis::make_unique< QgsProcessingParameterScale >( name, description, ok ? val : QVariant() );
1223 param->setFlags( flags );
1224 return param.release();
1228 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1233 QString QgsProcessingScaleWidgetWrapper::parameterType()
const
1240 return new QgsProcessingScaleWidgetWrapper( parameter, type );
1243 QWidget *QgsProcessingScaleWidgetWrapper::createWidget()
1255 mScaleWidget->setAllowNull(
true );
1257 mScaleWidget->setMapCanvas( widgetContext().mapCanvas() );
1258 mScaleWidget->setShowCurrentScaleButton(
true );
1260 mScaleWidget->setToolTip( parameterDefinition()->toolTip() );
1263 emit widgetValueHasChanged(
this );
1265 return mScaleWidget;
1274 mScaleWidget->setMapCanvas( context.
mapCanvas() );
1279 QVariant QgsProcessingScaleWidgetWrapper::widgetValue()
const
1281 return mScaleWidget && !mScaleWidget->isNull() ? QVariant( mScaleWidget->scale() ) : QVariant();
1284 void QgsProcessingScaleWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1288 if ( mScaleWidget->allowNull() && !value.isValid() )
1289 mScaleWidget->setNull();
1293 mScaleWidget->setScale( v );
1300 return new QgsProcessingScaleParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1311 QVBoxLayout *vlayout =
new QVBoxLayout();
1312 vlayout->setMargin( 0 );
1313 vlayout->setContentsMargins( 0, 0, 0, 0 );
1315 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
1317 mTypeComboBox =
new QComboBox();
1320 vlayout->addWidget( mTypeComboBox );
1322 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1323 mMinLineEdit =
new QLineEdit();
1324 vlayout->addWidget( mMinLineEdit );
1326 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1327 mMaxLineEdit =
new QLineEdit();
1328 vlayout->addWidget( mMaxLineEdit );
1332 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( rangeParam->dataType() ) );
1334 mMinLineEdit->setText( QString::number( range.at( 0 ) ) );
1335 mMaxLineEdit->setText( QString::number( range.at( 1 ) ) );
1338 setLayout( vlayout );
1341 QgsProcessingParameterDefinition *QgsProcessingRangeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1343 QString defaultValue;
1344 if ( mMinLineEdit->text().isEmpty() )
1346 defaultValue = QStringLiteral(
"None" );
1350 defaultValue = mMinLineEdit->text();
1353 if ( mMaxLineEdit->text().isEmpty() )
1355 defaultValue += QStringLiteral(
",None" );
1359 defaultValue += QStringLiteral(
"," ) + mMaxLineEdit->text();
1363 auto param = qgis::make_unique< QgsProcessingParameterRange >( name, description, dataType, defaultValue );
1364 param->setFlags( flags );
1365 return param.release();
1375 QWidget *QgsProcessingRangeWidgetWrapper::createWidget()
1384 QHBoxLayout *layout =
new QHBoxLayout();
1389 mMinSpinBox->setExpressionsEnabled(
true );
1390 mMinSpinBox->setShowClearButton(
false );
1391 mMaxSpinBox->setExpressionsEnabled(
true );
1392 mMaxSpinBox->setShowClearButton(
false );
1394 QLabel *minLabel =
new QLabel( tr(
"Min" ) );
1395 layout->addWidget( minLabel );
1396 layout->addWidget( mMinSpinBox, 1 );
1398 QLabel *maxLabel =
new QLabel( tr(
"Max" ) );
1399 layout->addWidget( maxLabel );
1400 layout->addWidget( mMaxSpinBox, 1 );
1402 QWidget *w =
new QWidget();
1403 layout->setMargin( 0 );
1404 layout->setContentsMargins( 0, 0, 0, 0 );
1405 w->setLayout( layout );
1409 mMinSpinBox->setDecimals( 6 );
1410 mMaxSpinBox->setDecimals( 6 );
1414 mMinSpinBox->setDecimals( 0 );
1415 mMaxSpinBox->setDecimals( 0 );
1418 mMinSpinBox->setMinimum( -99999999.999999 );
1419 mMaxSpinBox->setMinimum( -99999999.999999 );
1420 mMinSpinBox->setMaximum( 99999999.999999 );
1421 mMaxSpinBox->setMaximum( 99999999.999999 );
1425 mAllowingNull =
true;
1427 const double min = mMinSpinBox->minimum() - 1;
1428 mMinSpinBox->setMinimum( min );
1429 mMaxSpinBox->setMinimum( min );
1430 mMinSpinBox->setValue( min );
1431 mMaxSpinBox->setValue( min );
1433 mMinSpinBox->setShowClearButton(
true );
1434 mMaxSpinBox->setShowClearButton(
true );
1435 mMinSpinBox->setSpecialValueText( tr(
"Not set" ) );
1436 mMaxSpinBox->setSpecialValueText( tr(
"Not set" ) );
1439 w->setToolTip( parameterDefinition()->toolTip() );
1441 connect( mMinSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
const double v )
1443 mBlockChangedSignal++;
1444 if ( !mAllowingNull && v > mMaxSpinBox->value() )
1445 mMaxSpinBox->setValue( v );
1446 mBlockChangedSignal--;
1448 if ( !mBlockChangedSignal )
1449 emit widgetValueHasChanged(
this );
1451 connect( mMaxSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
const double v )
1453 mBlockChangedSignal++;
1454 if ( !mAllowingNull && v < mMinSpinBox->value() )
1455 mMinSpinBox->setValue( v );
1456 mBlockChangedSignal--;
1458 if ( !mBlockChangedSignal )
1459 emit widgetValueHasChanged(
this );
1468 void QgsProcessingRangeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1471 if ( mAllowingNull && v.empty() )
1473 mMinSpinBox->clear();
1474 mMaxSpinBox->clear();
1481 if ( mAllowingNull )
1483 mBlockChangedSignal++;
1484 if ( std::isnan( v.at( 0 ) ) )
1485 mMinSpinBox->clear();
1487 mMinSpinBox->setValue( v.at( 0 ) );
1489 if ( v.count() >= 2 )
1491 if ( std::isnan( v.at( 1 ) ) )
1492 mMaxSpinBox->clear();
1494 mMaxSpinBox->setValue( v.at( 1 ) );
1496 mBlockChangedSignal--;
1500 mBlockChangedSignal++;
1501 mMinSpinBox->setValue( v.at( 0 ) );
1502 if ( v.count() >= 2 )
1503 mMaxSpinBox->setValue( v.at( 1 ) );
1504 mBlockChangedSignal--;
1508 if ( !mBlockChangedSignal )
1509 emit widgetValueHasChanged(
this );
1512 QVariant QgsProcessingRangeWidgetWrapper::widgetValue()
const
1514 if ( mAllowingNull )
1517 if (
qgsDoubleNear( mMinSpinBox->value(), mMinSpinBox->minimum() ) )
1518 value = QStringLiteral(
"None" );
1520 value = QStringLiteral(
"%1" ).arg( mMinSpinBox->value() );
1522 if (
qgsDoubleNear( mMaxSpinBox->value(), mMaxSpinBox->minimum() ) )
1523 value += QStringLiteral(
",None" );
1525 value += QStringLiteral(
",%1" ).arg( mMaxSpinBox->value() );
1530 return QStringLiteral(
"%1,%2" ).arg( mMinSpinBox->value() ).arg( mMaxSpinBox->value() );
1533 QStringList QgsProcessingRangeWidgetWrapper::compatibleParameterTypes()
const
1535 return QStringList()
1540 QStringList QgsProcessingRangeWidgetWrapper::compatibleOutputTypes()
const
1545 QString QgsProcessingRangeWidgetWrapper::modelerExpressionFormatString()
const
1547 return tr(
"string as two comma delimited floats, e.g. '1,10'" );
1550 QString QgsProcessingRangeWidgetWrapper::parameterType()
const
1557 return new QgsProcessingRangeWidgetWrapper( parameter, type );
1562 return new QgsProcessingRangeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1573 QVBoxLayout *vlayout =
new QVBoxLayout();
1574 vlayout->setMargin( 0 );
1575 vlayout->setContentsMargins( 0, 0, 0, 0 );
1577 mMatrixWidget =
new QgsProcessingMatrixModelerWidget();
1580 mMatrixWidget->setValue( matrixParam->headers(), matrixParam->defaultValue() );
1581 mMatrixWidget->setFixedRows( matrixParam->hasFixedNumberRows() );
1583 vlayout->addWidget( mMatrixWidget );
1584 setLayout( vlayout );
1587 QgsProcessingParameterDefinition *QgsProcessingMatrixParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1589 auto param = qgis::make_unique< QgsProcessingParameterMatrix >( name, description, 1, mMatrixWidget->fixedRows(), mMatrixWidget->headers(), mMatrixWidget->value() );
1590 param->setFlags( flags );
1591 return param.release();
1601 QWidget *QgsProcessingMatrixWidgetWrapper::createWidget()
1603 mMatrixWidget =
new QgsProcessingMatrixParameterPanel(
nullptr,
dynamic_cast< const QgsProcessingParameterMatrix *
>( parameterDefinition() ) );
1604 mMatrixWidget->setToolTip( parameterDefinition()->toolTip() );
1606 connect( mMatrixWidget, &QgsProcessingMatrixParameterPanel::changed,
this, [ = ]
1608 emit widgetValueHasChanged(
this );
1617 return mMatrixWidget;
1623 void QgsProcessingMatrixWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1626 if ( mMatrixWidget )
1627 mMatrixWidget->setValue( v );
1630 QVariant QgsProcessingMatrixWidgetWrapper::widgetValue()
const
1632 if ( mMatrixWidget )
1633 return mMatrixWidget->value().isEmpty() ? QVariant() : mMatrixWidget->value();
1638 QStringList QgsProcessingMatrixWidgetWrapper::compatibleParameterTypes()
const
1640 return QStringList()
1644 QStringList QgsProcessingMatrixWidgetWrapper::compatibleOutputTypes()
const
1646 return QStringList();
1649 QString QgsProcessingMatrixWidgetWrapper::modelerExpressionFormatString()
const
1651 return tr(
"comma delimited string of values, or an array of values" );
1654 QString QgsProcessingMatrixWidgetWrapper::parameterType()
const
1661 return new QgsProcessingMatrixWidgetWrapper( parameter, type );
1666 return new QgsProcessingMatrixParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1678 QVBoxLayout *vlayout =
new QVBoxLayout();
1679 vlayout->setMargin( 0 );
1680 vlayout->setContentsMargins( 0, 0, 0, 0 );
1682 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
1684 mTypeComboBox =
new QComboBox();
1688 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( fileParam->behavior() ) );
1690 mTypeComboBox->setCurrentIndex( 0 );
1691 vlayout->addWidget( mTypeComboBox );
1693 vlayout->addWidget(
new QLabel( tr(
"File filter" ) ) );
1695 mFilterComboBox =
new QComboBox();
1696 mFilterComboBox->setEditable(
true );
1698 mFilterComboBox->addItem( tr(
"All Files (*.*)" ) );
1699 mFilterComboBox->addItem( tr(
"CSV Files (*.csv)" ) );
1700 mFilterComboBox->addItem( tr(
"HTML Files (*.html *.htm)" ) );
1701 mFilterComboBox->addItem( tr(
"Text Files (*.txt)" ) );
1703 mFilterComboBox->setCurrentText( fileParam->fileFilter() );
1705 mFilterComboBox->setCurrentIndex( 0 );
1706 vlayout->addWidget( mFilterComboBox );
1708 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1711 mDefaultFileWidget->lineEdit()->setShowClearButton(
true );
1715 mDefaultFileWidget->setFilePath( fileParam->defaultValue().toString() );
1719 vlayout->addWidget( mDefaultFileWidget );
1721 connect( mTypeComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
this, [ = ]
1730 setLayout( vlayout );
1733 QgsProcessingParameterDefinition *QgsProcessingFileParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1735 auto param = qgis::make_unique< QgsProcessingParameterFile >( name, description );
1738 param->setFileFilter( mFilterComboBox->currentText() );
1739 if ( !mDefaultFileWidget->filePath().isEmpty() )
1740 param->setDefaultValue( mDefaultFileWidget->filePath() );
1741 param->setFlags( flags );
1742 return param.release();
1752 QWidget *QgsProcessingFileWidgetWrapper::createWidget()
1762 mFileWidget->setToolTip( parameterDefinition()->toolTip() );
1763 mFileWidget->setDialogTitle( parameterDefinition()->description() );
1765 mFileWidget->setDefaultRoot(
QgsSettings().value( QStringLiteral(
"/Processing/LastInputPath" ), QDir::homePath() ).toString() );
1772 mFileWidget->setFilter( fileParam->
fileFilter() );
1773 else if ( !fileParam->
extension().isEmpty() )
1774 mFileWidget->setFilter( tr(
"%1 files" ).arg( fileParam->
extension().toUpper() ) + QStringLiteral(
" (*." ) + fileParam->
extension().toLower() +
')' );
1784 QgsSettings().
setValue( QStringLiteral(
"/Processing/LastInputPath" ), QFileInfo( path ).canonicalPath() );
1785 emit widgetValueHasChanged(
this );
1793 void QgsProcessingFileWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1797 mFileWidget->setFilePath( v );
1800 QVariant QgsProcessingFileWidgetWrapper::widgetValue()
const
1803 return mFileWidget->filePath();
1808 QStringList QgsProcessingFileWidgetWrapper::compatibleParameterTypes()
const
1810 return QStringList()
1815 QStringList QgsProcessingFileWidgetWrapper::compatibleOutputTypes()
const
1825 QString QgsProcessingFileWidgetWrapper::modelerExpressionFormatString()
const
1827 return tr(
"string representing a path to a file or folder" );
1830 QString QgsProcessingFileWidgetWrapper::parameterType()
const
1837 return new QgsProcessingFileWidgetWrapper( parameter, type );
1842 return new QgsProcessingFileParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1854 QVBoxLayout *vlayout =
new QVBoxLayout();
1855 vlayout->setMargin( 0 );
1856 vlayout->setContentsMargins( 0, 0, 0, 0 );
1858 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1863 vlayout->addWidget( mDefaultLineEdit );
1865 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
1867 mParentLayerComboBox =
new QComboBox();
1868 mParentLayerComboBox->addItem( tr(
"None" ), QVariant() );
1870 QString initialParent;
1872 initialParent = expParam->parentLayerParameterName();
1874 if ( widgetContext.
model() )
1877 const QMap<QString, QgsProcessingModelParameter> components = widgetContext.
model()->parameterComponents();
1878 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
1882 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1883 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1885 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1890 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1891 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1893 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1899 if ( mParentLayerComboBox->count() == 1 && !initialParent.isEmpty() )
1902 mParentLayerComboBox->addItem( initialParent, initialParent );
1903 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1906 vlayout->addWidget( mParentLayerComboBox );
1907 setLayout( vlayout );
1910 QgsProcessingParameterDefinition *QgsProcessingExpressionParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1912 auto param = qgis::make_unique< QgsProcessingParameterExpression >( name, description, mDefaultLineEdit->expression(), mParentLayerComboBox->currentData().toString() );
1913 param->setFlags( flags );
1914 return param.release();
1923 QWidget *QgsProcessingExpressionWidgetWrapper::createWidget()
1935 mExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
1936 mExpLineEdit->setExpressionDialogTitle( parameterDefinition()->description() );
1937 mExpLineEdit->registerExpressionContextGenerator(
this );
1940 emit widgetValueHasChanged(
this );
1942 return mExpLineEdit;
1947 mFieldExpWidget->setToolTip( parameterDefinition()->toolTip() );
1948 mFieldExpWidget->setExpressionDialogTitle( parameterDefinition()->description() );
1949 mFieldExpWidget->registerExpressionContextGenerator(
this );
1952 emit widgetValueHasChanged(
this );
1954 return mFieldExpWidget;
1961 void QgsProcessingExpressionWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1971 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterExpression *
>( parameterDefinition() )->parentLayerParameterName() )
1973 setParentLayerWrapperValue( wrapper );
1976 setParentLayerWrapperValue( wrapper );
1993 std::unique_ptr< QgsProcessingContext > tmpContext;
1994 if ( mProcessingContextGenerator )
1995 context = mProcessingContextGenerator->processingContext();
1999 tmpContext = qgis::make_unique< QgsProcessingContext >();
2000 context = tmpContext.get();
2006 if ( mFieldExpWidget )
2007 mFieldExpWidget->setLayer(
nullptr );
2008 else if ( mExpLineEdit )
2009 mExpLineEdit->setLayer(
nullptr );
2015 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
2018 mParentLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
2019 layer = mParentLayer.get();
2026 if ( mFieldExpWidget )
2027 mFieldExpWidget->setLayer( layer );
2028 else if ( mExpLineEdit )
2029 mExpLineEdit->setLayer( layer );
2032 void QgsProcessingExpressionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2035 if ( mFieldExpWidget )
2036 mFieldExpWidget->setExpression( v );
2037 else if ( mExpLineEdit )
2038 mExpLineEdit->setExpression( v );
2041 QVariant QgsProcessingExpressionWidgetWrapper::widgetValue()
const
2043 if ( mFieldExpWidget )
2044 return mFieldExpWidget->expression();
2045 else if ( mExpLineEdit )
2046 return mExpLineEdit->expression();
2051 QStringList QgsProcessingExpressionWidgetWrapper::compatibleParameterTypes()
const
2053 return QStringList()
2062 QStringList QgsProcessingExpressionWidgetWrapper::compatibleOutputTypes()
const
2064 return QStringList()
2069 QString QgsProcessingExpressionWidgetWrapper::modelerExpressionFormatString()
const
2071 return tr(
"string representation of an expression" );
2074 const QgsVectorLayer *QgsProcessingExpressionWidgetWrapper::linkedVectorLayer()
const
2076 if ( mFieldExpWidget && mFieldExpWidget->layer() )
2077 return mFieldExpWidget->layer();
2082 QString QgsProcessingExpressionWidgetWrapper::parameterType()
const
2089 return new QgsProcessingExpressionWidgetWrapper( parameter, type );
2094 return new QgsProcessingExpressionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2107 QHBoxLayout *hl =
new QHBoxLayout();
2109 hl->setContentsMargins( 0, 0, 0, 0 );
2111 mLineEdit =
new QLineEdit();
2112 mLineEdit->setEnabled(
false );
2113 hl->addWidget( mLineEdit, 1 );
2115 mToolButton =
new QToolButton();
2116 mToolButton->setText( QString( QChar( 0x2026 ) ) );
2117 hl->addWidget( mToolButton );
2123 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
2126 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingEnumPanelWidget::showDialog );
2129 void QgsProcessingEnumPanelWidget::setValue(
const QVariant &value )
2131 if ( value.isValid() )
2132 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
2136 updateSummaryText();
2140 void QgsProcessingEnumPanelWidget::showDialog()
2142 QVariantList availableOptions;
2145 availableOptions.reserve( mParam->options().size() );
2146 for (
int i = 0; i < mParam->options().count(); ++i )
2147 availableOptions << i;
2150 const QStringList options = mParam ? mParam->options() : QStringList();
2154 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
2155 widget->setPanelTitle( mParam->description() );
2157 widget->setValueFormatter( [options](
const QVariant & v ) -> QString
2159 const int i = v.toInt();
2160 return options.size() > i ? options.at( i ) : QString();
2163 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
2165 setValue( widget->selectedOptions() );
2172 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this,
nullptr );
2174 dlg.setValueFormatter( [options](
const QVariant & v ) -> QString
2176 const int i = v.toInt();
2177 return options.size() > i ? options.at( i ) : QString();
2181 setValue( dlg.selectedOptions() );
2186 void QgsProcessingEnumPanelWidget::updateSummaryText()
2189 mLineEdit->setText( tr(
"%1 options selected" ).arg( mValue.count() ) );
2196 QgsProcessingEnumCheckboxPanelWidget::QgsProcessingEnumCheckboxPanelWidget( QWidget *parent,
const QgsProcessingParameterEnum *param,
int columns )
2199 , mButtonGroup( new QButtonGroup( this ) )
2200 , mColumns( columns )
2202 mButtonGroup->setExclusive( !mParam->allowMultiple() );
2204 QGridLayout *l =
new QGridLayout();
2205 l->setContentsMargins( 0, 0, 0, 0 );
2208 int rows =
static_cast< int >( std::ceil( mParam->options().count() /
static_cast< double >( mColumns ) ) );
2209 for (
int i = 0; i < mParam->options().count(); ++i )
2211 QAbstractButton *button =
nullptr;
2212 if ( mParam->allowMultiple() )
2213 button =
new QCheckBox( mParam->options().at( i ) );
2215 button =
new QRadioButton( mParam->options().at( i ) );
2217 connect( button, &QAbstractButton::toggled,
this, [ = ]
2219 if ( !mBlockChangedSignal )
2223 mButtons.insert( i, button );
2224 mButtonGroup->addButton( button, i );
2225 l->addWidget( button, i % rows, i / rows );
2227 l->addItem(
new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, mColumns );
2230 if ( mParam->allowMultiple() )
2232 setContextMenuPolicy( Qt::CustomContextMenu );
2233 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsProcessingEnumCheckboxPanelWidget::showPopupMenu );
2237 QVariant QgsProcessingEnumCheckboxPanelWidget::value()
const
2239 if ( mParam->allowMultiple() )
2242 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2244 if ( it.value()->isChecked() )
2245 value.append( it.key() );
2251 return mButtonGroup->checkedId() >= 0 ? mButtonGroup->checkedId() : QVariant();
2255 void QgsProcessingEnumCheckboxPanelWidget::setValue(
const QVariant &value )
2257 mBlockChangedSignal =
true;
2258 if ( mParam->allowMultiple() )
2260 QVariantList selected;
2261 if ( value.isValid() )
2262 selected = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
2263 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2265 it.value()->setChecked( selected.contains( it.key() ) );
2271 if ( v.type() == QVariant::List )
2272 v = v.toList().value( 0 );
2273 if ( mButtons.contains( v ) )
2274 mButtons.value( v )->setChecked(
true );
2276 mBlockChangedSignal =
false;
2280 void QgsProcessingEnumCheckboxPanelWidget::showPopupMenu()
2283 QAction *selectAllAction =
new QAction( tr(
"Select All" ), &popupMenu );
2284 connect( selectAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::selectAll );
2285 QAction *clearAllAction =
new QAction( tr(
"Clear Selection" ), &popupMenu );
2286 connect( clearAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::deselectAll );
2287 popupMenu.addAction( selectAllAction );
2288 popupMenu.addAction( clearAllAction );
2289 popupMenu.exec( QCursor::pos() );
2292 void QgsProcessingEnumCheckboxPanelWidget::selectAll()
2294 mBlockChangedSignal =
true;
2295 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2296 it.value()->setChecked(
true );
2297 mBlockChangedSignal =
false;
2301 void QgsProcessingEnumCheckboxPanelWidget::deselectAll()
2303 mBlockChangedSignal =
true;
2304 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2305 it.value()->setChecked(
false );
2306 mBlockChangedSignal =
false;
2318 QVBoxLayout *vlayout =
new QVBoxLayout();
2319 vlayout->setMargin( 0 );
2320 vlayout->setContentsMargins( 0, 0, 0, 0 );
2322 mEnumWidget =
new QgsProcessingEnumModelerWidget();
2325 mEnumWidget->setAllowMultiple( enumParam->allowMultiple() );
2326 mEnumWidget->setOptions( enumParam->options() );
2327 mEnumWidget->setDefaultOptions( enumParam->defaultValue() );
2329 vlayout->addWidget( mEnumWidget );
2330 setLayout( vlayout );
2333 QgsProcessingParameterDefinition *QgsProcessingEnumParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
2335 auto param = qgis::make_unique< QgsProcessingParameterEnum >( name, description, mEnumWidget->options(), mEnumWidget->allowMultiple(), mEnumWidget->defaultOptions() );
2337 return param.release();
2347 QWidget *QgsProcessingEnumWidgetWrapper::createWidget()
2355 if ( expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"useCheckBoxes" ),
false ).toBool() )
2357 const int columns = expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"columns" ), 2 ).toInt();
2358 mCheckboxPanel =
new QgsProcessingEnumCheckboxPanelWidget(
nullptr, expParam, columns );
2359 mCheckboxPanel->setToolTip( parameterDefinition()->toolTip() );
2360 connect( mCheckboxPanel, &QgsProcessingEnumCheckboxPanelWidget::changed,
this, [ = ]
2362 emit widgetValueHasChanged(
this );
2364 return mCheckboxPanel;
2373 mPanel =
new QgsProcessingEnumPanelWidget(
nullptr, expParam );
2374 mPanel->setToolTip( parameterDefinition()->toolTip() );
2375 connect( mPanel, &QgsProcessingEnumPanelWidget::changed,
this, [ = ]
2377 emit widgetValueHasChanged(
this );
2383 mComboBox =
new QComboBox();
2386 mComboBox->addItem( tr(
"[Not selected]" ), QVariant() );
2387 const QStringList options = expParam->
options();
2388 for (
int i = 0; i < options.count(); ++i )
2389 mComboBox->addItem( options.at( i ), i );
2391 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2392 connect( mComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
2394 emit widgetValueHasChanged(
this );
2403 void QgsProcessingEnumWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2407 if ( !value.isValid() )
2408 mComboBox->setCurrentIndex( mComboBox->findData( QVariant() ) );
2412 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
2415 else if ( mPanel || mCheckboxPanel )
2418 if ( value.isValid() )
2421 opts.reserve( v.size() );
2426 mPanel->setValue( opts );
2427 else if ( mCheckboxPanel )
2428 mCheckboxPanel->setValue( opts );
2432 QVariant QgsProcessingEnumWidgetWrapper::widgetValue()
const
2435 return mComboBox->currentData();
2437 return mPanel->value();
2438 else if ( mCheckboxPanel )
2439 return mCheckboxPanel->value();
2444 QStringList QgsProcessingEnumWidgetWrapper::compatibleParameterTypes()
const
2446 return QStringList()
2452 QStringList QgsProcessingEnumWidgetWrapper::compatibleOutputTypes()
const
2454 return QStringList()
2459 QString QgsProcessingEnumWidgetWrapper::modelerExpressionFormatString()
const
2461 return tr(
"selected option index (starting from 0), array of indices, or comma separated string of options (e.g. '1,3')" );
2464 QString QgsProcessingEnumWidgetWrapper::parameterType()
const
2471 return new QgsProcessingEnumWidgetWrapper( parameter, type );
2476 return new QgsProcessingEnumParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2489 QWidget *QgsProcessingLayoutWidgetWrapper::createWidget()
2498 mComboBox =
new QgsLayoutComboBox(
nullptr, widgetContext().project() ? widgetContext().project()->layoutManager() :
nullptr );
2500 mComboBox->setAllowEmptyLayout(
true );
2503 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2506 emit widgetValueHasChanged(
this );
2513 mLineEdit =
new QLineEdit();
2514 mLineEdit->setToolTip( tr(
"Name of an existing print layout" ) );
2515 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
2517 emit widgetValueHasChanged(
this );
2525 void QgsProcessingLayoutWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2529 if ( !value.isValid() )
2530 mComboBox->setCurrentLayout(
nullptr );
2534 mComboBox->setCurrentLayout( l );
2536 mComboBox->setCurrentLayout(
nullptr );
2539 else if ( mLineEdit )
2542 mLineEdit->setText( v );
2546 QVariant QgsProcessingLayoutWidgetWrapper::widgetValue()
const
2551 return l ? l->
name() : QVariant();
2553 else if ( mLineEdit )
2554 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
2559 QStringList QgsProcessingLayoutWidgetWrapper::compatibleParameterTypes()
const
2561 return QStringList()
2566 QStringList QgsProcessingLayoutWidgetWrapper::compatibleOutputTypes()
const
2568 return QStringList()
2572 QString QgsProcessingLayoutWidgetWrapper::modelerExpressionFormatString()
const
2574 return tr(
"string representing the name of an existing print layout" );
2577 QString QgsProcessingLayoutWidgetWrapper::parameterType()
const
2584 return new QgsProcessingLayoutWidgetWrapper( parameter, type );
2598 QVBoxLayout *vlayout =
new QVBoxLayout();
2599 vlayout->setMargin( 0 );
2600 vlayout->setContentsMargins( 0, 0, 0, 0 );
2602 vlayout->addWidget(
new QLabel( tr(
"Parent layout" ) ) );
2604 mParentLayoutComboBox =
new QComboBox();
2605 QString initialParent;
2607 initialParent = itemParam->parentLayoutParameterName();
2609 if ( widgetContext.
model() )
2612 const QMap<QString, QgsProcessingModelParameter> components = widgetContext.
model()->parameterComponents();
2613 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
2617 mParentLayoutComboBox-> addItem( definition->
description(), definition->
name() );
2618 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2620 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
2626 if ( mParentLayoutComboBox->count() == 0 && !initialParent.isEmpty() )
2629 mParentLayoutComboBox->addItem( initialParent, initialParent );
2630 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
2633 vlayout->addWidget( mParentLayoutComboBox );
2634 setLayout( vlayout );
2636 QgsProcessingParameterDefinition *QgsProcessingLayoutItemParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
2638 auto param = qgis::make_unique< QgsProcessingParameterLayoutItem >( name, description, QVariant(), mParentLayoutComboBox->currentData().toString() );
2640 return param.release();
2650 QWidget *QgsProcessingLayoutItemWidgetWrapper::createWidget()
2661 mComboBox->setAllowEmptyItem(
true );
2662 if ( layoutParam->
itemType() >= 0 )
2665 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2668 emit widgetValueHasChanged(
this );
2675 mLineEdit =
new QLineEdit();
2676 mLineEdit->setToolTip( tr(
"UUID or ID of an existing print layout item" ) );
2677 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
2679 emit widgetValueHasChanged(
this );
2687 void QgsProcessingLayoutItemWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
2697 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterLayoutItem *
>( parameterDefinition() )->parentLayoutParameterName() )
2699 setLayoutParameterValue( wrapper->parameterValue() );
2702 setLayoutParameterValue( wrapper->parameterValue() );
2715 void QgsProcessingLayoutItemWidgetWrapper::setLayoutParameterValue(
const QVariant &value )
2721 std::unique_ptr< QgsProcessingContext > tmpContext;
2722 if ( mProcessingContextGenerator )
2723 context = mProcessingContextGenerator->processingContext();
2727 tmpContext = qgis::make_unique< QgsProcessingContext >();
2728 context = tmpContext.get();
2732 setLayout( layout );
2735 void QgsProcessingLayoutItemWidgetWrapper::setLayout(
QgsPrintLayout *layout )
2738 mComboBox->setCurrentLayout( layout );
2741 void QgsProcessingLayoutItemWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2745 if ( !value.isValid() )
2746 mComboBox->setItem(
nullptr );
2750 mComboBox->setItem( item );
2753 else if ( mLineEdit )
2756 mLineEdit->setText( v );
2760 QVariant QgsProcessingLayoutItemWidgetWrapper::widgetValue()
const
2765 return i ? i->
uuid() : QVariant();
2767 else if ( mLineEdit )
2768 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
2773 QStringList QgsProcessingLayoutItemWidgetWrapper::compatibleParameterTypes()
const
2775 return QStringList()
2780 QStringList QgsProcessingLayoutItemWidgetWrapper::compatibleOutputTypes()
const
2782 return QStringList()
2786 QString QgsProcessingLayoutItemWidgetWrapper::modelerExpressionFormatString()
const
2788 return tr(
"string representing the UUID or ID of an existing print layout item" );
2791 QString QgsProcessingLayoutItemWidgetWrapper::parameterType()
const
2798 return new QgsProcessingLayoutItemWidgetWrapper( parameter, type );
2803 return new QgsProcessingLayoutItemParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2810 QgsProcessingPointMapTool::QgsProcessingPointMapTool(
QgsMapCanvas *canvas )
2817 QgsProcessingPointMapTool::~QgsProcessingPointMapTool() =
default;
2819 void QgsProcessingPointMapTool::deactivate()
2833 if ( e->button() == Qt::LeftButton )
2836 emit clicked( point );
2841 void QgsProcessingPointMapTool::keyPressEvent( QKeyEvent *e )
2843 if ( e->key() == Qt::Key_Escape )
2858 QgsProcessingPointPanel::QgsProcessingPointPanel( QWidget *parent )
2861 QHBoxLayout *l =
new QHBoxLayout();
2862 l->setContentsMargins( 0, 0, 0, 0 );
2865 mLineEdit->setShowClearButton(
false );
2866 l->addWidget( mLineEdit, 1 );
2867 mButton =
new QToolButton();
2868 mButton->setText( QString( QChar( 0x2026 ) ) );
2869 l->addWidget( mButton );
2872 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::changed );
2873 connect( mButton, &QToolButton::clicked,
this, &QgsProcessingPointPanel::selectOnCanvas );
2874 mButton->setVisible(
false );
2877 void QgsProcessingPointPanel::setMapCanvas(
QgsMapCanvas *canvas )
2880 mButton->setVisible(
true );
2883 mTool = qgis::make_unique< QgsProcessingPointMapTool >( mCanvas );
2884 connect( mTool.get(), &QgsProcessingPointMapTool::clicked,
this, &QgsProcessingPointPanel::updatePoint );
2885 connect( mTool.get(), &QgsProcessingPointMapTool::complete,
this, &QgsProcessingPointPanel::pointPicked );
2888 void QgsProcessingPointPanel::setAllowNull(
bool allowNull )
2890 mLineEdit->setShowClearButton( allowNull );
2893 QVariant QgsProcessingPointPanel::value()
const
2895 return mLineEdit->showClearButton() && mLineEdit->text().trimmed().isEmpty() ? QVariant() : QVariant( mLineEdit->text() );
2898 void QgsProcessingPointPanel::clear()
2905 QString newText = QStringLiteral(
"%1,%2" )
2906 .arg( QString::number( point.
x(),
'f' ),
2907 QString::number( point.
y(),
'f' ) );
2910 if ( mCrs.isValid() )
2912 newText += QStringLiteral(
" [%1]" ).arg( mCrs.authid() );
2914 mLineEdit->setText( newText );
2917 void QgsProcessingPointPanel::selectOnCanvas()
2922 mPrevTool = mCanvas->mapTool();
2923 mCanvas->setMapTool( mTool.get() );
2925 emit toggleDialogVisibility(
false );
2928 void QgsProcessingPointPanel::updatePoint(
const QgsPointXY &point )
2930 setValue( point, mCanvas->mapSettings().destinationCrs() );
2933 void QgsProcessingPointPanel::pointPicked()
2938 mCanvas->setMapTool( mPrevTool );
2940 emit toggleDialogVisibility(
true );
2952 QVBoxLayout *vlayout =
new QVBoxLayout();
2953 vlayout->setMargin( 0 );
2954 vlayout->setContentsMargins( 0, 0, 0, 0 );
2956 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2958 mDefaultLineEdit =
new QLineEdit();
2959 mDefaultLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
2960 mDefaultLineEdit->setPlaceholderText( tr(
"Point as 'x,y'" ) );
2964 mDefaultLineEdit->setText( QStringLiteral(
"%1,%2" ).arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) ) );
2967 vlayout->addWidget( mDefaultLineEdit );
2968 setLayout( vlayout );
2971 QgsProcessingParameterDefinition *QgsProcessingPointParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
2973 auto param = qgis::make_unique< QgsProcessingParameterPoint >( name, description, mDefaultLineEdit->text() );
2975 return param.release();
2984 QWidget *QgsProcessingPointWidgetWrapper::createWidget()
2992 mPanel =
new QgsProcessingPointPanel(
nullptr );
2993 if ( widgetContext().mapCanvas() )
2994 mPanel->setMapCanvas( widgetContext().mapCanvas() );
2997 mPanel->setAllowNull(
true );
2999 mPanel->setToolTip( parameterDefinition()->toolTip() );
3001 connect( mPanel, &QgsProcessingPointPanel::changed,
this, [ = ]
3003 emit widgetValueHasChanged(
this );
3007 setDialog( mDialog );
3013 mLineEdit =
new QLineEdit();
3014 mLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
3015 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
3017 emit widgetValueHasChanged(
this );
3029 mPanel->setMapCanvas( context.
mapCanvas() );
3032 void QgsProcessingPointWidgetWrapper::setDialog( QDialog *dialog )
3037 connect( mPanel, &QgsProcessingPointPanel::toggleDialogVisibility, mDialog, [ = ](
bool visible )
3040 mDialog->showMinimized();
3043 mDialog->showNormal();
3045 mDialog->activateWindow();
3052 void QgsProcessingPointWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3056 if ( !value.isValid() || ( value.type() == QVariant::String && value.toString().isEmpty() ) )
3062 mPanel->setValue( p,
crs );
3065 else if ( mLineEdit )
3068 mLineEdit->setText( v );
3072 QVariant QgsProcessingPointWidgetWrapper::widgetValue()
const
3076 return mPanel->value();
3078 else if ( mLineEdit )
3079 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3084 QStringList QgsProcessingPointWidgetWrapper::compatibleParameterTypes()
const
3086 return QStringList()
3091 QStringList QgsProcessingPointWidgetWrapper::compatibleOutputTypes()
const
3093 return QStringList()
3097 QString QgsProcessingPointWidgetWrapper::modelerExpressionFormatString()
const
3099 return tr(
"string of the format 'x,y' or a geometry value (centroid is used)" );
3102 QString QgsProcessingPointWidgetWrapper::parameterType()
const
3109 return new QgsProcessingPointWidgetWrapper( parameter, type );
3114 return new QgsProcessingPointParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3127 QVBoxLayout *vlayout =
new QVBoxLayout();
3128 vlayout->setMargin( 0 );
3129 vlayout->setContentsMargins( 0, 0, 0, 0 );
3131 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3134 mDefaultColorButton->setShowNull(
true );
3135 mAllowOpacity =
new QCheckBox( tr(
"Allow opacity control" ) );
3141 mDefaultColorButton->setToNull();
3143 mDefaultColorButton->setColor(
c );
3144 mAllowOpacity->setChecked( colorParam->opacityEnabled() );
3148 mDefaultColorButton->setToNull();
3149 mAllowOpacity->setChecked(
true );
3152 vlayout->addWidget( mDefaultColorButton );
3153 vlayout->addWidget( mAllowOpacity );
3154 setLayout( vlayout );
3157 QgsProcessingParameterDefinition *QgsProcessingColorParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3159 auto param = qgis::make_unique< QgsProcessingParameterColor >( name, description, mDefaultColorButton->color(), mAllowOpacity->isChecked() );
3161 return param.release();
3170 QWidget *QgsProcessingColorWidgetWrapper::createWidget()
3180 mColorButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
3183 mColorButton->setShowNull(
true );
3186 mColorButton->setToolTip( parameterDefinition()->toolTip() );
3187 mColorButton->setColorDialogTitle( parameterDefinition()->description() );
3188 if ( colorParam->
defaultValue().value< QColor >().isValid() )
3190 mColorButton->setDefaultColor( colorParam->
defaultValue().value< QColor >() );
3195 emit widgetValueHasChanged(
this );
3198 return mColorButton;
3204 void QgsProcessingColorWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3208 if ( !value.isValid() ||
3209 ( value.type() == QVariant::String && value.toString().isEmpty() )
3210 || ( value.type() == QVariant::Color && !value.value< QColor >().isValid() ) )
3211 mColorButton->setToNull();
3215 if ( !
c.isValid() && mColorButton->showNull() )
3216 mColorButton->setToNull();
3218 mColorButton->setColor(
c );
3223 QVariant QgsProcessingColorWidgetWrapper::widgetValue()
const
3226 return mColorButton->isNull() ? QVariant() : mColorButton->color();
3231 QStringList QgsProcessingColorWidgetWrapper::compatibleParameterTypes()
const
3233 return QStringList()
3238 QStringList QgsProcessingColorWidgetWrapper::compatibleOutputTypes()
const
3240 return QStringList()
3244 QString QgsProcessingColorWidgetWrapper::modelerExpressionFormatString()
const
3246 return tr(
"color style string, e.g. #ff0000 or 255,0,0" );
3249 QString QgsProcessingColorWidgetWrapper::parameterType()
const
3256 return new QgsProcessingColorWidgetWrapper( parameter, type );
3261 return new QgsProcessingColorParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3272 QVBoxLayout *vlayout =
new QVBoxLayout();
3273 vlayout->setMargin( 0 );
3274 vlayout->setContentsMargins( 0, 0, 0, 0 );
3276 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3278 mDefaultLineEdit =
new QLineEdit();
3281 vlayout->addWidget( mDefaultLineEdit );
3283 mSourceParamComboBox =
new QComboBox();
3284 mDestParamComboBox =
new QComboBox();
3285 QString initialSource;
3286 QString initialDest;
3291 initialSource = itemParam->sourceCrsParameterName();
3292 initialDest = itemParam->destinationCrsParameterName();
3297 mSourceParamComboBox->addItem( QString(), QString() );
3298 mDestParamComboBox->addItem( QString(), QString() );
3299 if ( widgetContext.
model() )
3302 const QMap<QString, QgsProcessingModelParameter> components = widgetContext.
model()->parameterComponents();
3303 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3305 if ( definition && it->parameterName() == definition->
name() )
3309 mSourceParamComboBox->addItem( it->parameterName(), it->parameterName() );
3310 mDestParamComboBox->addItem( it->parameterName(), it->parameterName() );
3311 if ( !initialSource.isEmpty() && initialSource == it->parameterName() )
3313 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
3315 if ( !initialDest.isEmpty() && initialDest == it->parameterName() )
3317 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
3322 if ( mSourceParamComboBox->count() == 1 && !initialSource.isEmpty() )
3325 mSourceParamComboBox->addItem( initialSource, initialSource );
3326 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
3328 if ( mDestParamComboBox->count() == 1 && !initialDest.isEmpty() )
3331 mDestParamComboBox->addItem( initialDest, initialDest );
3332 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
3335 vlayout->addWidget(
new QLabel( tr(
"Source CRS parameter" ) ) );
3336 vlayout->addWidget( mSourceParamComboBox );
3337 vlayout->addWidget(
new QLabel( tr(
"Destination CRS parameter" ) ) );
3338 vlayout->addWidget( mDestParamComboBox );
3342 mStaticSourceWidget->setCrs( sourceCrs );
3345 mStaticDestWidget->setCrs( destCrs );
3347 vlayout->addWidget(
new QLabel( tr(
"Static source CRS" ) ) );
3348 vlayout->addWidget( mStaticSourceWidget );
3349 vlayout->addWidget(
new QLabel( tr(
"Static destination CRS" ) ) );
3350 vlayout->addWidget( mStaticDestWidget );
3352 setLayout( vlayout );
3355 QgsProcessingParameterDefinition *QgsProcessingCoordinateOperationParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3357 auto param = qgis::make_unique< QgsProcessingParameterCoordinateOperation >( name, description, mDefaultLineEdit->text(),
3358 mSourceParamComboBox->currentText(),
3359 mDestParamComboBox->currentText(),
3360 mStaticSourceWidget->crs().isValid() ? QVariant::fromValue( mStaticSourceWidget->crs() ) : QVariant(),
3361 mStaticDestWidget->crs().isValid() ? QVariant::fromValue( mStaticDestWidget->crs() ) : QVariant() );
3363 return param.release();
3372 QWidget *QgsProcessingCoordinateOperationWidgetWrapper::createWidget()
3383 mOperationWidget->setShowMakeDefault(
false );
3384 mOperationWidget->setShowFallbackOption(
false );
3385 mOperationWidget->setToolTip( parameterDefinition()->toolTip() );
3386 mOperationWidget->setSourceCrs( mSourceCrs );
3387 mOperationWidget->setDestinationCrs( mDestCrs );
3388 mOperationWidget->setMapCanvas( mCanvas );
3389 if ( !coordParam->
defaultValue().toString().isEmpty() )
3393 mOperationWidget->setSelectedOperation( deets );
3398 emit widgetValueHasChanged(
this );
3401 return mOperationWidget;
3407 mLineEdit =
new QLineEdit();
3408 QHBoxLayout *layout =
new QHBoxLayout();
3409 layout->addWidget( mLineEdit, 1 );
3410 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
3412 emit widgetValueHasChanged(
this );
3415 QToolButton *button =
new QToolButton();
3416 button->setText( QString( QChar( 0x2026 ) ) );
3417 connect( button, &QToolButton::clicked,
this, [ = ]
3419 QgsDatumTransformDialog dlg( mSourceCrs, mDestCrs,
false,
false,
false, qMakePair( -1, -1 ), button,
nullptr, mLineEdit->text(), mCanvas );
3422 mLineEdit->setText( dlg.selectedDatumTransform().proj );
3423 emit widgetValueHasChanged(
this );
3426 layout->addWidget( button );
3428 QWidget *w =
new QWidget();
3429 layout->setMargin( 0 );
3430 layout->setContentsMargins( 0, 0, 0, 0 );
3431 w->setLayout( layout );
3439 void QgsProcessingCoordinateOperationWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3451 setSourceCrsParameterValue( wrapper->parameterValue() );
3454 setSourceCrsParameterValue( wrapper->parameterValue() );
3459 setDestinationCrsParameterValue( wrapper->parameterValue() );
3462 setDestinationCrsParameterValue( wrapper->parameterValue() );
3477 if ( mOperationWidget )
3478 mOperationWidget->setMapCanvas( context.
mapCanvas() );
3481 void QgsProcessingCoordinateOperationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
3483 if ( mOperationWidget )
3485 if ( !value.isValid() ||
3486 ( value.type() == QVariant::String ) )
3489 deets.
proj = value.toString();
3490 mOperationWidget->setSelectedOperation( deets );
3495 if ( !value.isValid() ||
3496 ( value.type() == QVariant::String ) )
3498 mLineEdit->setText( value.toString() );
3503 QVariant QgsProcessingCoordinateOperationWidgetWrapper::widgetValue()
const
3505 if ( mOperationWidget )
3506 return mOperationWidget->selectedOperation().proj;
3507 else if ( mLineEdit )
3508 return mLineEdit->text();
3513 QStringList QgsProcessingCoordinateOperationWidgetWrapper::compatibleParameterTypes()
const
3515 return QStringList()
3520 QStringList QgsProcessingCoordinateOperationWidgetWrapper::compatibleOutputTypes()
const
3522 return QStringList()
3526 QString QgsProcessingCoordinateOperationWidgetWrapper::modelerExpressionFormatString()
const
3528 return tr(
"Proj coordinate operation string, e.g. '+proj=pipeline +step +inv...'" );
3531 void QgsProcessingCoordinateOperationWidgetWrapper::setSourceCrsParameterValue(
const QVariant &value )
3534 std::unique_ptr< QgsProcessingContext > tmpContext;
3535 if ( mProcessingContextGenerator )
3536 context = mProcessingContextGenerator->processingContext();
3540 tmpContext = qgis::make_unique< QgsProcessingContext >();
3541 context = tmpContext.get();
3545 if ( mOperationWidget )
3547 mOperationWidget->setSourceCrs( mSourceCrs );
3548 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
3552 void QgsProcessingCoordinateOperationWidgetWrapper::setDestinationCrsParameterValue(
const QVariant &value )
3555 std::unique_ptr< QgsProcessingContext > tmpContext;
3556 if ( mProcessingContextGenerator )
3557 context = mProcessingContextGenerator->processingContext();
3561 tmpContext = qgis::make_unique< QgsProcessingContext >();
3562 context = tmpContext.get();
3566 if ( mOperationWidget )
3568 mOperationWidget->setDestinationCrs( mDestCrs );
3569 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
3573 QString QgsProcessingCoordinateOperationWidgetWrapper::parameterType()
const
3580 return new QgsProcessingCoordinateOperationWidgetWrapper( parameter, type );
3585 return new QgsProcessingCoordinateOperationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3598 QHBoxLayout *hl =
new QHBoxLayout();
3600 hl->setContentsMargins( 0, 0, 0, 0 );
3602 mLineEdit =
new QLineEdit();
3603 mLineEdit->setEnabled(
false );
3604 hl->addWidget( mLineEdit, 1 );
3606 mToolButton =
new QToolButton();
3607 mToolButton->setText( QString( QChar( 0x2026 ) ) );
3608 hl->addWidget( mToolButton );
3614 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
3617 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingFieldPanelWidget::showDialog );
3620 void QgsProcessingFieldPanelWidget::setFields(
const QgsFields &fields )
3625 void QgsProcessingFieldPanelWidget::setValue(
const QVariant &value )
3627 if ( value.isValid() )
3628 mValue = value.type() == QVariant::List ? value.
toList() : QVariantList() << value;
3632 updateSummaryText();
3636 void QgsProcessingFieldPanelWidget::showDialog()
3638 QVariantList availableOptions;
3639 QStringList fieldNames;
3640 availableOptions.reserve( mFields.size() );
3641 for (
const QgsField &field : qgis::as_const( mFields ) )
3643 availableOptions << field.name();
3649 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
3650 widget->setPanelTitle( mParam->description() );
3652 widget->setValueFormatter( [](
const QVariant & v ) -> QString
3654 return v.toString();
3657 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
3659 setValue( widget->selectedOptions() );
3666 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this,
nullptr );
3668 dlg.setValueFormatter( [](
const QVariant & v ) -> QString
3670 return v.toString();
3674 setValue( dlg.selectedOptions() );
3679 void QgsProcessingFieldPanelWidget::updateSummaryText()
3682 mLineEdit->setText( tr(
"%1 options selected" ).arg( mValue.count() ) );
3693 QVBoxLayout *vlayout =
new QVBoxLayout();
3694 vlayout->setMargin( 0 );
3695 vlayout->setContentsMargins( 0, 0, 0, 0 );
3697 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
3698 mParentLayerComboBox =
new QComboBox();
3700 QString initialParent;
3702 initialParent = fieldParam->parentLayerParameterName();
3704 if ( widgetContext.
model() )
3707 const QMap<QString, QgsProcessingModelParameter> components = widgetContext.
model()->parameterComponents();
3708 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3712 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
3713 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
3715 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
3720 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
3721 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
3723 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
3729 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
3732 mParentLayerComboBox->addItem( initialParent, initialParent );
3733 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
3736 vlayout->addWidget( mParentLayerComboBox );
3738 vlayout->addWidget(
new QLabel( tr(
"Allowed data type" ) ) );
3739 mDataTypeComboBox =
new QComboBox();
3745 mDataTypeComboBox->setCurrentIndex( mDataTypeComboBox->findData( fieldParam->dataType() ) );
3747 vlayout->addWidget( mDataTypeComboBox );
3749 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple fields" ) );
3751 mAllowMultipleCheckBox->setChecked( fieldParam->allowMultiple() );
3753 vlayout->addWidget( mAllowMultipleCheckBox );
3755 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all fields by default" ) );
3756 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
3758 mDefaultToAllCheckBox->setChecked( fieldParam->defaultToAllFields() );
3760 vlayout->addWidget( mDefaultToAllCheckBox );
3762 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [ = ]
3764 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
3767 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3769 mDefaultLineEdit =
new QLineEdit();
3770 mDefaultLineEdit->setToolTip( tr(
"Default field name, or ; separated list of field names for multiple field parameters" ) );
3774 mDefaultLineEdit->setText( fields.join(
';' ) );
3776 vlayout->addWidget( mDefaultLineEdit );
3778 setLayout( vlayout );
3781 QgsProcessingParameterDefinition *QgsProcessingFieldParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3784 auto param = qgis::make_unique< QgsProcessingParameterField >( name, description, mDefaultLineEdit->text(), mParentLayerComboBox->currentData().toString(), dataType, mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
3786 return param.release();
3795 QWidget *QgsProcessingFieldWidgetWrapper::createWidget()
3805 mPanel =
new QgsProcessingFieldPanelWidget(
nullptr, fieldParam );
3806 mPanel->setToolTip( parameterDefinition()->toolTip() );
3807 connect( mPanel, &QgsProcessingFieldPanelWidget::changed,
this, [ = ]
3809 emit widgetValueHasChanged(
this );
3825 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3828 emit widgetValueHasChanged(
this );
3836 mLineEdit =
new QLineEdit();
3837 mLineEdit->setToolTip( QObject::tr(
"Name of field (separate field names with ; for multiple field parameters)" ) );
3838 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
3840 emit widgetValueHasChanged(
this );
3849 void QgsProcessingFieldWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3859 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterField *
>( parameterDefinition() )->parentLayerParameterName() )
3861 setParentLayerWrapperValue( wrapper );
3864 setParentLayerWrapperValue( wrapper );
3881 std::unique_ptr< QgsProcessingContext > tmpContext;
3882 if ( mProcessingContextGenerator )
3883 context = mProcessingContextGenerator->processingContext();
3887 tmpContext = qgis::make_unique< QgsProcessingContext >();
3888 context = tmpContext.get();
3903 if ( layer && layer->
isValid() )
3907 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
3910 mParentLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
3911 layer = mParentLayer.get();
3919 mComboBox->setLayer( layer );
3921 mPanel->setFields( filterFields( layer->
fields() ) );
3928 const QgsFields fields = source->fields();
3930 mComboBox->setFields( fields );
3932 mPanel->setFields( filterFields( fields ) );
3937 mComboBox->setLayer(
nullptr );
3941 if ( value.isValid() && widgetContext().messageBar() )
3944 widgetContext().
messageBar()->
pushMessage( QString(), QObject::tr(
"Could not load selected layer/table. Dependent field could not be populated" ),
3955 val.reserve( mPanel->fields().size() );
3956 for (
const QgsField &field : mPanel->fields() )
3957 val << field.
name();
3958 setWidgetValue( val, *context );
3961 setWidgetValue( parameterDefinition()->defaultValue(), *context );
3964 void QgsProcessingFieldWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3968 if ( !value.isValid() )
3969 mComboBox->setField( QString() );
3973 mComboBox->setField( v );
3979 if ( value.isValid() )
3982 opts.reserve( v.size() );
3983 for (
const QString &i : v )
3987 mPanel->setValue( opts );
3989 else if ( mLineEdit )
3995 mLineEdit->setText( v.join(
';' ) );
4004 QVariant QgsProcessingFieldWidgetWrapper::widgetValue()
const
4007 return mComboBox->currentField();
4009 return mPanel->value();
4010 else if ( mLineEdit )
4015 return mLineEdit->text().split(
';' );
4018 return mLineEdit->text();
4024 QStringList QgsProcessingFieldWidgetWrapper::compatibleParameterTypes()
const
4026 return QStringList()
4031 QStringList QgsProcessingFieldWidgetWrapper::compatibleOutputTypes()
const
4033 return QStringList()
4037 QString QgsProcessingFieldWidgetWrapper::modelerExpressionFormatString()
const
4039 return tr(
"selected field names as an array of names, or semicolon separated string of options (e.g. 'fid;place_name')" );
4042 const QgsVectorLayer *QgsProcessingFieldWidgetWrapper::linkedVectorLayer()
const
4044 if ( mComboBox && mComboBox->layer() )
4045 return mComboBox->layer();
4050 QgsFields QgsProcessingFieldWidgetWrapper::filterFields(
const QgsFields &fields )
const
4063 if ( f.isNumeric() )
4068 if ( f.type() == QVariant::String )
4073 if ( f.type() == QVariant::Date || f.type() == QVariant::Time || f.type() == QVariant::DateTime )
4082 QString QgsProcessingFieldWidgetWrapper::parameterType()
const
4089 return new QgsProcessingFieldWidgetWrapper( parameter, type );
4094 return new QgsProcessingFieldParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4105 QVBoxLayout *vlayout =
new QVBoxLayout();
4106 vlayout->setMargin( 0 );
4107 vlayout->setContentsMargins( 0, 0, 0, 0 );
4109 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4111 mDefaultComboBox =
new QComboBox();
4112 mDefaultComboBox->addItem( QString(), QVariant( -1 ) );
4115 for (
const QString &theme : mapThemes )
4119 mDefaultComboBox->setEditable(
true );
4123 if ( themeParam->defaultValue().isValid() )
4126 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
4129 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
4131 vlayout->addWidget( mDefaultComboBox );
4133 setLayout( vlayout );
4136 QgsProcessingParameterDefinition *QgsProcessingMapThemeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4138 QVariant defaultVal;
4139 if ( mDefaultComboBox->currentText().isEmpty() )
4140 defaultVal = QVariant();
4142 defaultVal = mDefaultComboBox->currentText();
4143 auto param = qgis::make_unique< QgsProcessingParameterMapTheme>( name, description, defaultVal );
4145 return param.release();
4155 QWidget *QgsProcessingMapThemeWidgetWrapper::createWidget()
4159 mComboBox =
new QComboBox();
4162 mComboBox->addItem( tr(
"[Not selected]" ), QVariant( -1 ) );
4165 for (
const QString &theme : mapThemes )
4177 mComboBox->setEditable(
true );
4181 mComboBox->setToolTip( parameterDefinition()->toolTip() );
4182 connect( mComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
4184 emit widgetValueHasChanged(
this );
4190 void QgsProcessingMapThemeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4194 if ( !value.isValid() )
4195 mComboBox->setCurrentIndex( mComboBox->findData( QVariant( -1 ) ) );
4198 if ( mComboBox->isEditable() && mComboBox->findData( v ) == -1 )
4200 const QString prev = mComboBox->currentText();
4201 mComboBox->setCurrentText( v );
4203 emit widgetValueHasChanged(
this );
4206 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
4210 QVariant QgsProcessingMapThemeWidgetWrapper::widgetValue()
const
4213 return mComboBox->currentData().toInt() == -1 ? QVariant() :
4214 !mComboBox->currentData().isValid() && mComboBox->isEditable() ? mComboBox->currentText().isEmpty() ? QVariant() : QVariant( mComboBox->currentText() )
4215 : mComboBox->currentData();
4220 QStringList QgsProcessingMapThemeWidgetWrapper::compatibleParameterTypes()
const
4222 return QStringList()
4227 QStringList QgsProcessingMapThemeWidgetWrapper::compatibleOutputTypes()
const
4229 return QStringList()
4233 QString QgsProcessingMapThemeWidgetWrapper::modelerExpressionFormatString()
const
4235 return tr(
"map theme as a string value (e.g. 'base maps')" );
4238 QString QgsProcessingMapThemeWidgetWrapper::parameterType()
const
4245 return new QgsProcessingMapThemeWidgetWrapper( parameter, type );
4250 return new QgsProcessingMapThemeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4263 QVBoxLayout *vlayout =
new QVBoxLayout();
4264 vlayout->setMargin( 0 );
4265 vlayout->setContentsMargins( 0, 0, 0, 0 );
4267 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
4269 mTypeComboBox =
new QComboBox();
4274 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( datetimeParam->dataType() ) );
4276 mTypeComboBox->setCurrentIndex( 0 );
4277 vlayout->addWidget( mTypeComboBox );
4279 setLayout( vlayout );
4282 QgsProcessingParameterDefinition *QgsProcessingDateTimeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4284 auto param = qgis::make_unique< QgsProcessingParameterDateTime >( name, description );
4287 return param.release();
4297 QWidget *QgsProcessingDateTimeWidgetWrapper::createWidget()
4302 switch ( dateTimeParam->
dataType() )
4306 widget = mDateTimeEdit;
4329 widget->setToolTip( parameterDefinition()->toolTip() );
4331 if ( mDateTimeEdit )
4335 emit widgetValueHasChanged(
this );
4338 else if ( mDateEdit )
4342 emit widgetValueHasChanged(
this );
4345 else if ( mTimeEdit )
4349 emit widgetValueHasChanged(
this );
4358 return new QgsProcessingDateTimeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4361 void QgsProcessingDateTimeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4363 if ( mDateTimeEdit )
4367 else if ( mDateEdit )
4371 else if ( mTimeEdit )
4377 QVariant QgsProcessingDateTimeWidgetWrapper::widgetValue()
const
4379 if ( mDateTimeEdit )
4380 return !mDateTimeEdit->dateTime().isNull() && mDateTimeEdit->dateTime().isValid() ? QVariant( mDateTimeEdit->dateTime() ) : QVariant();
4381 else if ( mDateEdit )
4382 return !mDateEdit->date().isNull() && mDateEdit->date().isValid() ? QVariant( mDateEdit->date() ) : QVariant();
4383 else if ( mTimeEdit )
4384 return !mTimeEdit->time().isNull() && mTimeEdit->time().isValid() ? QVariant( mTimeEdit->time() ) : QVariant();
4389 QStringList QgsProcessingDateTimeWidgetWrapper::compatibleParameterTypes()
const
4391 return QStringList()
4396 QStringList QgsProcessingDateTimeWidgetWrapper::compatibleOutputTypes()
const
4398 return QStringList()
4402 QString QgsProcessingDateTimeWidgetWrapper::modelerExpressionFormatString()
const
4405 if ( dateTimeParam )
4407 switch ( dateTimeParam->
dataType() )
4410 return tr(
"datetime value, or a ISO string representation of a datetime" );
4413 return tr(
"date value, or a ISO string representation of a date" );
4416 return tr(
"time value, or a ISO string representation of a time" );
4422 QString QgsProcessingDateTimeWidgetWrapper::parameterType()
const
4429 return new QgsProcessingDateTimeWidgetWrapper( parameter, type );
4443 QVBoxLayout *vlayout =
new QVBoxLayout();
4444 vlayout->setMargin( 0 );
4445 vlayout->setContentsMargins( 0, 0, 0, 0 );
4447 vlayout->addWidget(
new QLabel( tr(
"Provider" ) ) );
4448 mProviderComboBox =
new QComboBox();
4449 mProviderComboBox->addItem( QObject::tr(
"Postgres" ), QStringLiteral(
"postgres" ) );
4450 mProviderComboBox->addItem( QObject::tr(
"GeoPackage" ), QStringLiteral(
"ogr" ) );
4451 mProviderComboBox->addItem( QObject::tr(
"Spatialite" ), QStringLiteral(
"spatialite" ) );
4453 vlayout->addWidget( mProviderComboBox );
4455 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4457 mDefaultEdit =
new QLineEdit();
4458 vlayout->addWidget( mDefaultEdit );
4459 setLayout( vlayout );
4461 if ( connectionParam )
4463 mProviderComboBox->setCurrentIndex( mProviderComboBox->findData( connectionParam->
providerId() ) );
4464 mDefaultEdit->setText( connectionParam->
defaultValue().toString() );
4468 QgsProcessingParameterDefinition *QgsProcessingProviderConnectionParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4470 QVariant defaultVal;
4471 if ( mDefaultEdit->text().isEmpty() )
4472 defaultVal = QVariant();
4474 defaultVal = mDefaultEdit->text();
4475 auto param = qgis::make_unique< QgsProcessingParameterProviderConnection>( name, description, mProviderComboBox->currentData().toString(), defaultVal );
4477 return param.release();
4487 QWidget *QgsProcessingProviderConnectionWidgetWrapper::createWidget()
4493 mProviderComboBox->setAllowEmptyConnection(
true );
4501 mProviderComboBox->setEditable(
true );
4505 mProviderComboBox->setToolTip( parameterDefinition()->toolTip() );
4506 connect( mProviderComboBox, &QgsProviderConnectionComboBox::currentTextChanged,
this, [ = ](
const QString & )
4508 if ( mBlockSignals )
4511 emit widgetValueHasChanged(
this );
4514 return mProviderComboBox;
4519 return new QgsProcessingProviderConnectionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4522 void QgsProcessingProviderConnectionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4526 if ( !value.isValid() )
4527 mProviderComboBox->setCurrentIndex( -1 );
4530 if ( mProviderComboBox->isEditable() )
4532 const QString prev = mProviderComboBox->currentText();
4534 mProviderComboBox->setConnection( v );
4535 mProviderComboBox->setCurrentText( v );
4539 emit widgetValueHasChanged(
this );
4542 mProviderComboBox->setConnection( v );
4546 QVariant QgsProcessingProviderConnectionWidgetWrapper::widgetValue()
const
4548 if ( mProviderComboBox )
4549 if ( mProviderComboBox->isEditable() )
4550 return mProviderComboBox->currentText().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentText() );
4552 return mProviderComboBox->currentConnection().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentConnection() );
4557 QStringList QgsProcessingProviderConnectionWidgetWrapper::compatibleParameterTypes()
const
4559 return QStringList()
4565 QStringList QgsProcessingProviderConnectionWidgetWrapper::compatibleOutputTypes()
const
4567 return QStringList()
4571 QString QgsProcessingProviderConnectionWidgetWrapper::modelerExpressionFormatString()
const
4573 return tr(
"connection name as a string value" );
4576 QString QgsProcessingProviderConnectionWidgetWrapper::parameterType()
const
4583 return new QgsProcessingProviderConnectionWidgetWrapper( parameter, type );
4598 QVBoxLayout *vlayout =
new QVBoxLayout();
4599 vlayout->setMargin( 0 );
4600 vlayout->setContentsMargins( 0, 0, 0, 0 );
4602 mConnectionParamComboBox =
new QComboBox();
4603 QString initialConnection;
4609 if ( widgetContext.
model() )
4612 const QMap<QString, QgsProcessingModelParameter> components = widgetContext.
model()->parameterComponents();
4613 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4615 if ( definition && it->parameterName() == definition->
name() )
4621 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
4622 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
4624 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
4629 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
4632 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
4633 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
4636 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
4637 vlayout->addWidget( mConnectionParamComboBox );
4639 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4641 mDefaultEdit =
new QLineEdit();
4642 vlayout->addWidget( mDefaultEdit );
4643 setLayout( vlayout );
4647 mDefaultEdit->setText( schemaParam->
defaultValue().toString() );
4651 QgsProcessingParameterDefinition *QgsProcessingDatabaseSchemaParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4653 QVariant defaultVal;
4654 if ( mDefaultEdit->text().isEmpty() )
4655 defaultVal = QVariant();
4657 defaultVal = mDefaultEdit->text();
4658 auto param = qgis::make_unique< QgsProcessingParameterDatabaseSchema>( name, description, mConnectionParamComboBox->currentData().toString(), defaultVal );
4660 return param.release();
4670 QWidget *QgsProcessingDatabaseSchemaWidgetWrapper::createWidget()
4676 mSchemaComboBox->setAllowEmptySchema(
true );
4684 mSchemaComboBox->comboBox()->setEditable(
true );
4688 mSchemaComboBox->setToolTip( parameterDefinition()->toolTip() );
4689 connect( mSchemaComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
4691 if ( mBlockSignals )
4694 emit widgetValueHasChanged( this );
4697 return mSchemaComboBox;
4702 return new QgsProcessingDatabaseSchemaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4709 std::unique_ptr< QgsProcessingContext > tmpContext;
4710 if ( mProcessingContextGenerator )
4711 context = mProcessingContextGenerator->processingContext();
4715 tmpContext = qgis::make_unique< QgsProcessingContext >();
4716 context = tmpContext.get();
4722 if ( mSchemaComboBox )
4727 setWidgetValue( parameterDefinition()->defaultValue(), *context );
4730 void QgsProcessingDatabaseSchemaWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4734 if ( !value.isValid() )
4735 mSchemaComboBox->comboBox()->setCurrentIndex( -1 );
4738 if ( mSchemaComboBox->comboBox()->isEditable() )
4740 const QString prev = mSchemaComboBox->comboBox()->currentText();
4742 mSchemaComboBox->setSchema( v );
4743 mSchemaComboBox->comboBox()->setCurrentText( v );
4747 emit widgetValueHasChanged(
this );
4750 mSchemaComboBox->setSchema( v );
4754 QVariant QgsProcessingDatabaseSchemaWidgetWrapper::widgetValue()
const
4756 if ( mSchemaComboBox )
4757 if ( mSchemaComboBox->comboBox()->isEditable() )
4758 return mSchemaComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->comboBox()->currentText() );
4760 return mSchemaComboBox->currentSchema().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->currentSchema() );
4765 QStringList QgsProcessingDatabaseSchemaWidgetWrapper::compatibleParameterTypes()
const
4767 return QStringList()
4773 QStringList QgsProcessingDatabaseSchemaWidgetWrapper::compatibleOutputTypes()
const
4775 return QStringList()
4779 QString QgsProcessingDatabaseSchemaWidgetWrapper::modelerExpressionFormatString()
const
4781 return tr(
"database schema name as a string value" );
4784 QString QgsProcessingDatabaseSchemaWidgetWrapper::parameterType()
const
4791 return new QgsProcessingDatabaseSchemaWidgetWrapper( parameter, type );
4794 void QgsProcessingDatabaseSchemaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
4806 setParentConnectionWrapperValue( wrapper );
4809 setParentConnectionWrapperValue( wrapper );
4833 QVBoxLayout *vlayout =
new QVBoxLayout();
4834 vlayout->setMargin( 0 );
4835 vlayout->setContentsMargins( 0, 0, 0, 0 );
4837 mConnectionParamComboBox =
new QComboBox();
4838 mSchemaParamComboBox =
new QComboBox();
4839 QString initialConnection;
4840 QString initialSchema;
4847 if ( widgetContext.
model() )
4850 const QMap<QString, QgsProcessingModelParameter> components = widgetContext.
model()->parameterComponents();
4851 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4853 if ( definition && it->parameterName() == definition->
name() )
4858 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
4859 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
4861 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
4866 mSchemaParamComboBox->addItem( it->parameterName(), it->parameterName() );
4867 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
4869 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
4875 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
4878 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
4879 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
4882 if ( mSchemaParamComboBox->count() == 0 && !initialSchema.isEmpty() )
4885 mSchemaParamComboBox->addItem( initialSchema, initialSchema );
4886 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
4889 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
4890 vlayout->addWidget( mConnectionParamComboBox );
4892 vlayout->addWidget(
new QLabel( tr(
"Database schema parameter" ) ) );
4893 vlayout->addWidget( mSchemaParamComboBox );
4895 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4897 mDefaultEdit =
new QLineEdit();
4898 vlayout->addWidget( mDefaultEdit );
4899 setLayout( vlayout );
4903 mDefaultEdit->setText( tableParam->
defaultValue().toString() );
4907 QgsProcessingParameterDefinition *QgsProcessingDatabaseTableParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4909 QVariant defaultVal;
4910 if ( mDefaultEdit->text().isEmpty() )
4911 defaultVal = QVariant();
4913 defaultVal = mDefaultEdit->text();
4914 auto param = qgis::make_unique< QgsProcessingParameterDatabaseTable>( name, description,
4915 mConnectionParamComboBox->currentData().toString(),
4916 mSchemaParamComboBox->currentData().toString(),
4919 return param.release();
4929 QWidget *QgsProcessingDatabaseTableWidgetWrapper::createWidget()
4935 mTableComboBox->setAllowEmptyTable(
true );
4938 mTableComboBox->comboBox()->setEditable(
true );
4940 mTableComboBox->setToolTip( parameterDefinition()->toolTip() );
4941 connect( mTableComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
4943 if ( mBlockSignals )
4946 emit widgetValueHasChanged( this );
4949 return mTableComboBox;
4954 return new QgsProcessingDatabaseTableParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4961 std::unique_ptr< QgsProcessingContext > tmpContext;
4962 if ( mProcessingContextGenerator )
4963 context = mProcessingContextGenerator->processingContext();
4967 tmpContext = qgis::make_unique< QgsProcessingContext >();
4968 context = tmpContext.get();
4974 if ( mTableComboBox && !mSchema.isEmpty() )
4976 mTableComboBox->setSchema( mSchema );
4977 mTableComboBox->setConnectionName( mConnection, mProvider );
4981 setWidgetValue( parameterDefinition()->defaultValue(), *context );
4989 std::unique_ptr< QgsProcessingContext > tmpContext;
4990 if ( mProcessingContextGenerator )
4991 context = mProcessingContextGenerator->processingContext();
4995 tmpContext = qgis::make_unique< QgsProcessingContext >();
4996 context = tmpContext.get();
5002 if ( mTableComboBox && !mSchema.isEmpty() && !mConnection.isEmpty() )
5004 mTableComboBox->setSchema( mSchema );
5005 mTableComboBox->setConnectionName( mConnection, mProvider );
5009 setWidgetValue( parameterDefinition()->defaultValue(), *context );
5014 void QgsProcessingDatabaseTableWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5018 if ( !value.isValid() )
5019 mTableComboBox->comboBox()->setCurrentIndex( -1 );
5022 if ( mTableComboBox->comboBox()->isEditable() )
5024 const QString prev = mTableComboBox->comboBox()->currentText();
5026 mTableComboBox->setTable( v );
5027 mTableComboBox->comboBox()->setCurrentText( v );
5031 emit widgetValueHasChanged(
this );
5034 mTableComboBox->setTable( v );
5038 QVariant QgsProcessingDatabaseTableWidgetWrapper::widgetValue()
const
5040 if ( mTableComboBox )
5041 if ( mTableComboBox->comboBox()->isEditable() )
5042 return mTableComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mTableComboBox->comboBox()->currentText() );
5044 return mTableComboBox->currentTable().isEmpty() ? QVariant() : QVariant( mTableComboBox->currentTable() );
5049 QStringList QgsProcessingDatabaseTableWidgetWrapper::compatibleParameterTypes()
const
5051 return QStringList()
5057 QStringList QgsProcessingDatabaseTableWidgetWrapper::compatibleOutputTypes()
const
5059 return QStringList()
5063 QString QgsProcessingDatabaseTableWidgetWrapper::modelerExpressionFormatString()
const
5065 return tr(
"database table name as a string value" );
5068 QString QgsProcessingDatabaseTableWidgetWrapper::parameterType()
const
5075 return new QgsProcessingDatabaseTableWidgetWrapper( parameter, type );
5078 void QgsProcessingDatabaseTableWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5090 setParentConnectionWrapperValue( wrapper );
5093 setParentConnectionWrapperValue( wrapper );
5098 setParentSchemaWrapperValue( wrapper );
5101 setParentSchemaWrapperValue( wrapper );
5121 QVBoxLayout *vlayout =
new QVBoxLayout();
5122 vlayout->setMargin( 0 );
5123 vlayout->setContentsMargins( 0, 0, 0, 0 );
5125 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5128 mDefaultWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
5131 if ( extentParam->defaultValue().isValid() )
5135 mDefaultWidget->setCurrentExtent( rect,
crs );
5136 mDefaultWidget->setOutputExtentFromCurrent();
5140 mDefaultWidget->clear();
5144 vlayout->addWidget( mDefaultWidget );
5145 setLayout( vlayout );
5148 QgsProcessingParameterDefinition *QgsProcessingExtentParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5150 const QString defaultVal = mDefaultWidget->isValid() ? QStringLiteral(
"%1,%2,%3,%4%5" ).arg(
5151 QString::number( mDefaultWidget->outputExtent().xMinimum(),
'f', 9 ),
5152 QString::number( mDefaultWidget->outputExtent().xMaximum(),
'f', 9 ),
5153 QString::number( mDefaultWidget->outputExtent().yMinimum(),
'f', 9 ),
5154 QString::number( mDefaultWidget->outputExtent().yMaximum(),
'f', 9 ),
5155 mDefaultWidget->outputCrs().isValid() ? QStringLiteral(
" [%1]" ).arg( mDefaultWidget->outputCrs().authid() ) : QString()
5157 auto param = qgis::make_unique< QgsProcessingParameterExtent >( name, description, !defaultVal.isEmpty() ? QVariant( defaultVal ) : QVariant() );
5159 return param.release();
5170 QWidget *QgsProcessingExtentWidgetWrapper::createWidget()
5180 if ( widgetContext().mapCanvas() )
5181 mExtentWidget->setMapCanvas( widgetContext().mapCanvas() );
5184 mExtentWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
5186 mExtentWidget->setToolTip( parameterDefinition()->toolTip() );
5190 emit widgetValueHasChanged(
this );
5194 setDialog( mDialog );
5196 return mExtentWidget;
5206 mExtentWidget->setMapCanvas( context.
mapCanvas() );
5209 void QgsProcessingExtentWidgetWrapper::setDialog( QDialog *dialog )
5217 mDialog->showMinimized();
5220 mDialog->showNormal();
5222 mDialog->activateWindow();
5229 void QgsProcessingExtentWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5231 if ( mExtentWidget )
5233 if ( !value.isValid() || ( value.type() == QVariant::String && value.toString().isEmpty() ) )
5234 mExtentWidget->clear();
5239 mExtentWidget->setCurrentExtent( r,
crs );
5240 mExtentWidget->setOutputExtentFromCurrent();
5245 QVariant QgsProcessingExtentWidgetWrapper::widgetValue()
const
5247 if ( mExtentWidget )
5249 const QString val = mExtentWidget->isValid() ? QStringLiteral(
"%1,%2,%3,%4%5" ).arg(
5250 QString::number( mExtentWidget->outputExtent().xMinimum(),
'f', 9 ),
5251 QString::number( mExtentWidget->outputExtent().xMaximum(),
'f', 9 ),
5252 QString::number( mExtentWidget->outputExtent().yMinimum(),
'f', 9 ),
5253 QString::number( mExtentWidget->outputExtent().yMaximum(),
'f', 9 ),
5254 mExtentWidget->outputCrs().isValid() ? QStringLiteral(
" [%1]" ).arg( mExtentWidget->outputCrs().authid() ) : QString()
5257 return val.isEmpty() ? QVariant() : QVariant( val );
5263 QStringList QgsProcessingExtentWidgetWrapper::compatibleParameterTypes()
const
5265 return QStringList()
5276 QStringList QgsProcessingExtentWidgetWrapper::compatibleOutputTypes()
const
5278 return QStringList()
5285 QString QgsProcessingExtentWidgetWrapper::modelerExpressionFormatString()
const
5287 return tr(
"string of the format 'x min,x max,y min,y max' or a geometry value (bounding box is used)" );
5290 QString QgsProcessingExtentWidgetWrapper::parameterType()
const
5297 return new QgsProcessingExtentWidgetWrapper( parameter, type );
5302 return new QgsProcessingExtentParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5314 QVBoxLayout *vlayout =
new QVBoxLayout();
5315 vlayout->setMargin( 0 );
5316 vlayout->setContentsMargins( 0, 0, 0, 0 );
5318 vlayout->addWidget(
new QLabel( tr(
"Layer type" ) ) );
5330 for (
int i : layerParam->dataTypes() )
5332 mLayerTypeComboBox->setItemCheckState( mLayerTypeComboBox->findData( i ), Qt::Checked );
5336 vlayout->addWidget( mLayerTypeComboBox );
5338 setLayout( vlayout );
5341 QgsProcessingParameterDefinition *QgsProcessingMapLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5343 QList< int > dataTypes;
5344 for (
const QVariant &v : mLayerTypeComboBox->checkedItemsData() )
5345 dataTypes << v.toInt();
5347 auto param = qgis::make_unique< QgsProcessingParameterMapLayer >( name, description );
5348 param->setDataTypes( dataTypes );
5350 return param.release();
5359 QWidget *QgsProcessingMapLayerWidgetWrapper::createWidget()
5361 mComboBox =
new QgsProcessingMapLayerComboBox( parameterDefinition(), type() );
5369 mComboBox->setEditable(
true );
5373 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5375 connect( mComboBox, &QgsProcessingMapLayerComboBox::valueChanged,
this, [ = ]()
5377 if ( mBlockSignals )
5380 emit widgetValueHasChanged(
this );
5383 setWidgetContext( widgetContext() );
5392 mComboBox->setWidgetContext( context );
5397 if ( !parameterDefinition()->defaultValue().isValid() )
5403 void QgsProcessingMapLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5406 mComboBox->setValue( value, context );
5409 QVariant QgsProcessingMapLayerWidgetWrapper::widgetValue()
const
5411 return mComboBox ? mComboBox->value() : QVariant();
5414 QStringList QgsProcessingMapLayerWidgetWrapper::compatibleParameterTypes()
const
5416 return QStringList()
5425 QStringList QgsProcessingMapLayerWidgetWrapper::compatibleOutputTypes()
const
5427 return QStringList()
5435 QString QgsProcessingMapLayerWidgetWrapper::modelerExpressionFormatString()
const
5437 return tr(
"path to a map layer" );
5440 QString QgsProcessingMapLayerWidgetWrapper::parameterType()
const
5447 return new QgsProcessingMapLayerWidgetWrapper( parameter, type );
5452 return new QgsProcessingMapLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5461 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
5466 QStringList QgsProcessingRasterLayerWidgetWrapper::compatibleParameterTypes()
const
5468 return QStringList()
5475 QStringList QgsProcessingRasterLayerWidgetWrapper::compatibleOutputTypes()
const
5477 return QStringList()
5485 QString QgsProcessingRasterLayerWidgetWrapper::modelerExpressionFormatString()
const
5487 return tr(
"path to a raster layer" );
5490 QString QgsProcessingRasterLayerWidgetWrapper::parameterType()
const
5497 return new QgsProcessingRasterLayerWidgetWrapper( parameter, type );
5502 Q_UNUSED( context );
5503 Q_UNUSED( widgetContext );
5504 Q_UNUSED( definition );
5518 QVBoxLayout *vlayout =
new QVBoxLayout();
5519 vlayout->setMargin( 0 );
5520 vlayout->setContentsMargins( 0, 0, 0, 0 );
5522 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
5532 for (
int i : vectorParam->dataTypes() )
5534 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
5538 vlayout->addWidget( mGeometryTypeComboBox );
5540 setLayout( vlayout );
5543 QgsProcessingParameterDefinition *QgsProcessingVectorLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5545 QList< int > dataTypes;
5546 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
5547 dataTypes << v.toInt();
5549 auto param = qgis::make_unique< QgsProcessingParameterVectorLayer >( name, description, dataTypes );
5551 return param.release();
5556 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
5561 QStringList QgsProcessingVectorLayerWidgetWrapper::compatibleParameterTypes()
const
5563 return QStringList()
5570 QStringList QgsProcessingVectorLayerWidgetWrapper::compatibleOutputTypes()
const
5572 return QStringList()
5580 QString QgsProcessingVectorLayerWidgetWrapper::modelerExpressionFormatString()
const
5582 return tr(
"path to a vector layer" );
5588 return param->dataTypes();
5590 return QList< int >();
5593 QString QgsProcessingVectorLayerWidgetWrapper::parameterType()
const
5600 return new QgsProcessingVectorLayerWidgetWrapper( parameter, type );
5605 return new QgsProcessingVectorLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5617 QVBoxLayout *vlayout =
new QVBoxLayout();
5618 vlayout->setMargin( 0 );
5619 vlayout->setContentsMargins( 0, 0, 0, 0 );
5621 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
5631 for (
int i : sourceParam->dataTypes() )
5633 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
5641 vlayout->addWidget( mGeometryTypeComboBox );
5643 setLayout( vlayout );
5646 QgsProcessingParameterDefinition *QgsProcessingFeatureSourceParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5648 QList< int > dataTypes;
5649 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
5650 dataTypes << v.toInt();
5652 auto param = qgis::make_unique< QgsProcessingParameterFeatureSource >( name, description, dataTypes );
5654 return param.release();
5658 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
5663 QStringList QgsProcessingFeatureSourceWidgetWrapper::compatibleParameterTypes()
const
5665 return QStringList()
5673 QStringList QgsProcessingFeatureSourceWidgetWrapper::compatibleOutputTypes()
const
5675 return QStringList()
5683 QString QgsProcessingFeatureSourceWidgetWrapper::modelerExpressionFormatString()
const
5685 return tr(
"path to a vector layer" );
5691 return param->dataTypes();
5693 return QList< int >();
5696 QString QgsProcessingFeatureSourceWidgetWrapper::parameterType()
const
5703 return new QgsProcessingFeatureSourceWidgetWrapper( parameter, type );
5708 return new QgsProcessingFeatureSourceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5716 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
5721 QStringList QgsProcessingMeshLayerWidgetWrapper::compatibleParameterTypes()
const
5723 return QStringList()
5730 QStringList QgsProcessingMeshLayerWidgetWrapper::compatibleOutputTypes()
const
5732 return QStringList()
5740 QString QgsProcessingMeshLayerWidgetWrapper::modelerExpressionFormatString()
const
5742 return tr(
"path to a mesh layer" );
5745 QString QgsProcessingMeshLayerWidgetWrapper::parameterType()
const
5752 return new QgsProcessingMeshLayerWidgetWrapper( parameter, type );
5757 Q_UNUSED( context );
5758 Q_UNUSED( widgetContext );
5759 Q_UNUSED( definition );
5771 QgsProcessingRasterBandPanelWidget::QgsProcessingRasterBandPanelWidget( QWidget *parent,
const QgsProcessingParameterBand *param )
5775 QHBoxLayout *hl =
new QHBoxLayout();
5777 hl->setContentsMargins( 0, 0, 0, 0 );
5779 mLineEdit =
new QLineEdit();
5780 mLineEdit->setEnabled(
false );
5781 hl->addWidget( mLineEdit, 1 );
5783 mToolButton =
new QToolButton();
5784 mToolButton->setText( QString( QChar( 0x2026 ) ) );
5785 hl->addWidget( mToolButton );
5791 mLineEdit->setText( tr(
"%1 bands selected" ).arg( 0 ) );
5794 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingRasterBandPanelWidget::showDialog );
5797 void QgsProcessingRasterBandPanelWidget::setBands(
const QList< int > &bands )
5802 void QgsProcessingRasterBandPanelWidget::setBandNames(
const QHash<int, QString> &names )
5807 void QgsProcessingRasterBandPanelWidget::setValue(
const QVariant &value )
5809 if ( value.isValid() )
5810 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
5814 updateSummaryText();
5818 void QgsProcessingRasterBandPanelWidget::showDialog()
5820 QVariantList availableOptions;
5821 QStringList fieldNames;
5822 availableOptions.reserve( mBands.size() );
5823 for (
int band : qgis::as_const( mBands ) )
5825 availableOptions << band;
5831 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
5832 widget->setPanelTitle( mParam->description() );
5834 widget->setValueFormatter( [
this](
const QVariant & v ) -> QString
5836 int band = v.toInt();
5837 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
5840 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
5842 setValue( widget->selectedOptions() );
5849 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this,
nullptr );
5851 dlg.setValueFormatter( [
this](
const QVariant & v ) -> QString
5853 int band = v.toInt();
5854 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
5858 setValue( dlg.selectedOptions() );
5863 void QgsProcessingRasterBandPanelWidget::updateSummaryText()
5866 mLineEdit->setText( tr(
"%1 bands selected" ).arg( mValue.count() ) );
5878 QVBoxLayout *vlayout =
new QVBoxLayout();
5879 vlayout->setMargin( 0 );
5880 vlayout->setContentsMargins( 0, 0, 0, 0 );
5882 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5884 mDefaultLineEdit =
new QLineEdit();
5885 mDefaultLineEdit->setToolTip( tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
5890 for (
int b : bands )
5892 defVal << QString::number( b );
5895 mDefaultLineEdit->setText( defVal.join(
';' ) );
5897 vlayout->addWidget( mDefaultLineEdit );
5899 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
5900 mParentLayerComboBox =
new QComboBox();
5902 QString initialParent;
5904 initialParent = bandParam->parentLayerParameterName();
5906 if ( widgetContext.
model() )
5909 const QMap<QString, QgsProcessingModelParameter> components = widgetContext.
model()->parameterComponents();
5910 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
5914 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
5915 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
5917 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
5923 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
5926 mParentLayerComboBox->addItem( initialParent, initialParent );
5927 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
5930 vlayout->addWidget( mParentLayerComboBox );
5932 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Allow multiple" ) );
5934 mAllowMultipleCheckBox->setChecked( bandParam->allowMultiple() );
5936 vlayout->addWidget( mAllowMultipleCheckBox );
5937 setLayout( vlayout );
5940 QgsProcessingParameterDefinition *QgsProcessingBandParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5942 auto param = qgis::make_unique< QgsProcessingParameterBand >( name, description, mDefaultLineEdit->text().split(
';' ), mParentLayerComboBox->currentData().toString(),
false, mAllowMultipleCheckBox->isChecked() );
5944 return param.release();
5953 QWidget *QgsProcessingBandWidgetWrapper::createWidget()
5963 mPanel =
new QgsProcessingRasterBandPanelWidget(
nullptr, bandParam );
5964 mPanel->setToolTip( parameterDefinition()->toolTip() );
5965 connect( mPanel, &QgsProcessingRasterBandPanelWidget::changed,
this, [ = ]
5967 emit widgetValueHasChanged(
this );
5976 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5979 emit widgetValueHasChanged(
this );
5987 mLineEdit =
new QLineEdit();
5988 mLineEdit->setToolTip( QObject::tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
5989 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
5991 emit widgetValueHasChanged(
this );
6000 void QgsProcessingBandWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6010 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterBand *
>( parameterDefinition() )->parentLayerParameterName() )
6012 setParentLayerWrapperValue( wrapper );
6015 setParentLayerWrapperValue( wrapper );
6032 std::unique_ptr< QgsProcessingContext > tmpContext;
6033 if ( mProcessingContextGenerator )
6034 context = mProcessingContextGenerator->processingContext();
6038 tmpContext = qgis::make_unique< QgsProcessingContext >();
6039 context = tmpContext.get();
6045 if ( layer && layer->
isValid() )
6049 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
6052 mParentLayer.reset( qobject_cast< QgsRasterLayer * >( ownedLayer.release() ) );
6053 layer = mParentLayer.get();
6061 mComboBox->setLayer( layer );
6065 if ( provider && layer->
isValid() )
6070 QHash< int, QString > bandNames;
6071 for (
int i = 1; i <= nBands; ++i )
6076 mPanel->setBands( bands );
6077 mPanel->setBandNames( bandNames );
6084 mComboBox->setLayer(
nullptr );
6086 mPanel->setBands( QList< int >() );
6088 if ( value.isValid() && widgetContext().messageBar() )
6091 widgetContext().
messageBar()->
pushMessage( QString(), QObject::tr(
"Could not load selected layer/table. Dependent bands could not be populated" ),
6096 if ( parameterDefinition()->defaultValue().isValid() )
6097 setWidgetValue( parameterDefinition()->defaultValue(), *context );
6100 void QgsProcessingBandWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6104 if ( !value.isValid() )
6105 mComboBox->setBand( -1 );
6109 mComboBox->setBand( v );
6115 if ( value.isValid() )
6118 opts.reserve( v.size() );
6123 mPanel->setValue( value.isValid() ? opts : QVariant() );
6125 else if ( mLineEdit )
6132 opts.reserve( v.size() );
6134 opts << QString::number( i );
6135 mLineEdit->setText( value.isValid() && !opts.empty() ? opts.join(
';' ) : QString() );
6139 if ( value.isValid() )
6147 QVariant QgsProcessingBandWidgetWrapper::widgetValue()
const
6150 return mComboBox->currentBand() == -1 ? QVariant() : mComboBox->currentBand();
6152 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
6153 else if ( mLineEdit )
6158 const QStringList parts = mLineEdit->text().split(
';', QString::SkipEmptyParts );
6160 res.reserve( parts.count() );
6161 for (
const QString &s : parts )
6164 int band = s.toInt( &ok );
6168 return res.
isEmpty() ? QVariant() : res;
6172 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
6179 QStringList QgsProcessingBandWidgetWrapper::compatibleParameterTypes()
const
6181 return QStringList()
6186 QStringList QgsProcessingBandWidgetWrapper::compatibleOutputTypes()
const
6188 return QStringList()
6192 QString QgsProcessingBandWidgetWrapper::modelerExpressionFormatString()
const
6194 return tr(
"selected band numbers as an array of numbers, or semicolon separated string of options (e.g. '1;3')" );
6197 QString QgsProcessingBandWidgetWrapper::parameterType()
const
6204 return new QgsProcessingBandWidgetWrapper( parameter, type );
6209 return new QgsProcessingBandParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6222 QHBoxLayout *hl =
new QHBoxLayout();
6224 hl->setContentsMargins( 0, 0, 0, 0 );
6226 mLineEdit =
new QLineEdit();
6227 mLineEdit->setEnabled(
false );
6228 hl->addWidget( mLineEdit, 1 );
6230 mToolButton =
new QToolButton();
6231 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6232 hl->addWidget( mToolButton );
6238 mLineEdit->setText( tr(
"%1 inputs selected" ).arg( 0 ) );
6241 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingMultipleLayerPanelWidget::showDialog );
6244 void QgsProcessingMultipleLayerPanelWidget::setValue(
const QVariant &value )
6246 if ( value.isValid() )
6247 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
6251 updateSummaryText();
6255 void QgsProcessingMultipleLayerPanelWidget::setProject(
QgsProject *project )
6260 void QgsProcessingMultipleLayerPanelWidget::setModel( QgsProcessingModelAlgorithm *model,
const QString &modelChildAlgorithmID )
6266 switch ( mParam->layerType() )
6376 void QgsProcessingMultipleLayerPanelWidget::showDialog()
6381 QgsProcessingMultipleInputPanelWidget *widget =
new QgsProcessingMultipleInputPanelWidget( mParam, mValue, mModelSources, mModel );
6382 widget->setPanelTitle( mParam->description() );
6383 widget->setProject( mProject );
6384 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
6386 setValue( widget->selectedOptions() );
6393 QgsProcessingMultipleInputDialog dlg( mParam, mValue, mModelSources, mModel,
this,
nullptr );
6394 dlg.setProject( mProject );
6397 setValue( dlg.selectedOptions() );
6402 void QgsProcessingMultipleLayerPanelWidget::updateSummaryText()
6405 mLineEdit->setText( tr(
"%1 inputs selected" ).arg( mValue.count() ) );
6415 QVBoxLayout *vlayout =
new QVBoxLayout();
6416 vlayout->setMargin( 0 );
6417 vlayout->setContentsMargins( 0, 0, 0, 0 );
6419 vlayout->addWidget(
new QLabel( tr(
"Allowed layer type" ) ) );
6420 mLayerTypeComboBox =
new QComboBox();
6431 mLayerTypeComboBox->setCurrentIndex( mLayerTypeComboBox->findData( layersParam->layerType() ) );
6433 vlayout->addWidget( mLayerTypeComboBox );
6434 setLayout( vlayout );
6437 QgsProcessingParameterDefinition *QgsProcessingMultipleLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6439 auto param = qgis::make_unique< QgsProcessingParameterMultipleLayers >( name, description,
static_cast< QgsProcessing::SourceType >( mLayerTypeComboBox->currentData().toInt() ) );
6441 return param.release();
6450 QWidget *QgsProcessingMultipleLayerWidgetWrapper::createWidget()
6454 mPanel =
new QgsProcessingMultipleLayerPanelWidget(
nullptr, layerParam );
6455 mPanel->setToolTip( parameterDefinition()->toolTip() );
6456 mPanel->setProject( widgetContext().project() );
6457 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
6458 connect( mPanel, &QgsProcessingMultipleLayerPanelWidget::changed,
this, [ = ]
6460 emit widgetValueHasChanged(
this );
6470 mPanel->setProject( context.
project() );
6471 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
6475 void QgsProcessingMultipleLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6480 if ( value.isValid() )
6483 opts.reserve( v.size() );
6485 opts << l->source();
6488 for (
const QVariant &v : value.toList() )
6490 if ( v.canConvert< QgsProcessingModelChildParameterSource >() )
6492 const QgsProcessingModelChildParameterSource source = v.value< QgsProcessingModelChildParameterSource >();
6493 opts << QVariant::fromValue( source );
6498 mPanel->setValue( value.isValid() ? opts : QVariant() );
6502 QVariant QgsProcessingMultipleLayerWidgetWrapper::widgetValue()
const
6505 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
6510 QStringList QgsProcessingMultipleLayerWidgetWrapper::compatibleParameterTypes()
const
6512 return QStringList()
6522 QStringList QgsProcessingMultipleLayerWidgetWrapper::compatibleOutputTypes()
const
6524 return QStringList()
6533 QString QgsProcessingMultipleLayerWidgetWrapper::modelerExpressionFormatString()
const
6535 return tr(
"an array of layer paths, or semicolon separated string of layer paths" );
6538 QString QgsProcessingMultipleLayerWidgetWrapper::parameterType()
const
6545 return new QgsProcessingMultipleLayerWidgetWrapper( parameter, type );
6550 return new QgsProcessingMultipleLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6564 QWidget *QgsProcessingOutputWidgetWrapper::createWidget()
6572 mOutputWidget =
new QgsProcessingLayerOutputDestinationWidget( destParam,
false );
6573 if ( mProcessingContextGenerator )
6574 mOutputWidget->setContext( mProcessingContextGenerator->processingContext() );
6575 if ( mParametersGenerator )
6576 mOutputWidget->registerProcessingParametersGenerator( mParametersGenerator );
6577 mOutputWidget->setToolTip( parameterDefinition()->toolTip() );
6579 connect( mOutputWidget, &QgsProcessingLayerOutputDestinationWidget::destinationChanged,
this, [ = ]()
6581 if ( mBlockSignals )
6584 emit widgetValueHasChanged(
this );
6591 mOutputWidget->addOpenAfterRunningOption();
6593 return mOutputWidget;
6603 void QgsProcessingOutputWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
6605 if ( mOutputWidget )
6606 mOutputWidget->setValue( value );
6609 QVariant QgsProcessingOutputWidgetWrapper::widgetValue()
const
6611 if ( mOutputWidget )
6612 return mOutputWidget->value();
6617 QVariantMap QgsProcessingOutputWidgetWrapper::customProperties()
const
6620 if ( mOutputWidget )
6621 res.insert( QStringLiteral(
"OPEN_AFTER_RUNNING" ), mOutputWidget->openAfterRunning() );
6625 QStringList QgsProcessingOutputWidgetWrapper::compatibleParameterTypes()
const
6627 return QStringList()
6636 QStringList QgsProcessingOutputWidgetWrapper::compatibleOutputTypes()
const
6638 return QStringList()
6649 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
6654 QString QgsProcessingFeatureSinkWidgetWrapper::parameterType()
const
6661 return new QgsProcessingFeatureSinkWidgetWrapper( parameter, type );
6664 QString QgsProcessingFeatureSinkWidgetWrapper::modelerExpressionFormatString()
const
6666 return tr(
"path to layer destination" );
6674 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
6679 QString QgsProcessingVectorDestinationWidgetWrapper::parameterType()
const
6686 return new QgsProcessingVectorDestinationWidgetWrapper( parameter, type );
6689 QString QgsProcessingVectorDestinationWidgetWrapper::modelerExpressionFormatString()
const
6691 return tr(
"path to layer destination" );
6699 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
6704 QString QgsProcessingRasterDestinationWidgetWrapper::parameterType()
const
6711 return new QgsProcessingRasterDestinationWidgetWrapper( parameter, type );
6714 QString QgsProcessingRasterDestinationWidgetWrapper::modelerExpressionFormatString()
const
6716 return tr(
"path to layer destination" );
6724 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
6729 QString QgsProcessingFileDestinationWidgetWrapper::parameterType()
const
6736 return new QgsProcessingFileDestinationWidgetWrapper( parameter, type );
6739 QString QgsProcessingFileDestinationWidgetWrapper::modelerExpressionFormatString()
const
6741 return tr(
"path to file destination" );
6749 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
6754 QString QgsProcessingFolderDestinationWidgetWrapper::parameterType()
const
6761 return new QgsProcessingFolderDestinationWidgetWrapper( parameter, type );
6764 QString QgsProcessingFolderDestinationWidgetWrapper::modelerExpressionFormatString()
const
6766 return tr(
"path to folder destination" );