20 #include "processing/models/qgsprocessingmodelalgorithm.h"
62 #include <QToolButton>
64 #include <QHBoxLayout>
65 #include <QVBoxLayout>
69 #include <QPlainTextEdit>
70 #include <QRadioButton>
71 #include <QButtonGroup>
73 #include <QFileDialog>
85 QVBoxLayout *vlayout =
new QVBoxLayout();
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->setContentsMargins( 0, 0, 0, 0 );
250 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
258 vlayout->addWidget( mCrsSelector );
259 setLayout( vlayout );
262 QgsProcessingParameterDefinition *QgsProcessingCrsParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
264 auto param = qgis::make_unique< QgsProcessingParameterCrs >( name, description, mCrsSelector->crs().authid() );
265 param->setFlags( flags );
266 return param.release();
275 QWidget *QgsProcessingCrsWidgetWrapper::createWidget()
277 Q_ASSERT( mProjectionSelectionWidget ==
nullptr );
279 mProjectionSelectionWidget->setToolTip( parameterDefinition()->toolTip() );
288 emit widgetValueHasChanged(
this );
296 return mProjectionSelectionWidget;
301 QWidget *w =
new QWidget();
302 w->setToolTip( parameterDefinition()->toolTip() );
304 QVBoxLayout *vl =
new QVBoxLayout();
305 vl->setContentsMargins( 0, 0, 0, 0 );
308 mUseProjectCrsCheckBox =
new QCheckBox( tr(
"Use project CRS" ) );
309 mUseProjectCrsCheckBox->setToolTip( tr(
"Always use the current project CRS when running the model" ) );
310 vl->addWidget( mUseProjectCrsCheckBox );
311 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, mProjectionSelectionWidget, &QgsProjectionSelectionWidget::setDisabled );
312 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled,
this, [ = ]
314 emit widgetValueHasChanged(
this );
317 vl->addWidget( mProjectionSelectionWidget );
325 void QgsProcessingCrsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
327 if ( mUseProjectCrsCheckBox )
329 if ( value.toString().compare( QLatin1String(
"ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
331 mUseProjectCrsCheckBox->setChecked(
true );
336 mUseProjectCrsCheckBox->setChecked(
false );
341 if ( mProjectionSelectionWidget )
342 mProjectionSelectionWidget->setCrs( v );
345 QVariant QgsProcessingCrsWidgetWrapper::widgetValue()
const
347 if ( mUseProjectCrsCheckBox && mUseProjectCrsCheckBox->isChecked() )
348 return QStringLiteral(
"ProjectCrs" );
349 else if ( mProjectionSelectionWidget )
350 return mProjectionSelectionWidget->crs().isValid() ? mProjectionSelectionWidget->crs() : QVariant();
355 QStringList QgsProcessingCrsWidgetWrapper::compatibleParameterTypes()
const
367 QStringList QgsProcessingCrsWidgetWrapper::compatibleOutputTypes()
const
375 QString QgsProcessingCrsWidgetWrapper::modelerExpressionFormatString()
const
377 return tr(
"string as EPSG code, WKT or PROJ format, or a string identifying a map layer" );
380 QString QgsProcessingCrsWidgetWrapper::parameterType()
const
387 return new QgsProcessingCrsWidgetWrapper( parameter, type );
392 return new QgsProcessingCrsParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
405 QVBoxLayout *vlayout =
new QVBoxLayout();
406 vlayout->setContentsMargins( 0, 0, 0, 0 );
408 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
410 mDefaultLineEdit =
new QLineEdit();
413 vlayout->addWidget( mDefaultLineEdit );
415 mMultiLineCheckBox =
new QCheckBox( tr(
"Multiline input" ) );
417 mMultiLineCheckBox->setChecked( stringParam->multiLine() );
418 vlayout->addWidget( mMultiLineCheckBox );
420 setLayout( vlayout );
423 QgsProcessingParameterDefinition *QgsProcessingStringParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
425 auto param = qgis::make_unique< QgsProcessingParameterString >( name, description, mDefaultLineEdit->text(), mMultiLineCheckBox->isChecked() );
426 param->setFlags( flags );
427 return param.release();
438 QWidget *QgsProcessingStringWidgetWrapper::createWidget()
447 mPlainTextEdit =
new QPlainTextEdit();
448 mPlainTextEdit->setToolTip( parameterDefinition()->toolTip() );
450 connect( mPlainTextEdit, &QPlainTextEdit::textChanged,
this, [ = ]
452 emit widgetValueHasChanged(
this );
454 return mPlainTextEdit;
458 mLineEdit =
new QLineEdit();
459 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
461 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
463 emit widgetValueHasChanged(
this );
471 mLineEdit =
new QLineEdit();
472 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
474 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
476 emit widgetValueHasChanged(
this );
484 void QgsProcessingStringWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
488 mLineEdit->setText( v );
489 if ( mPlainTextEdit )
490 mPlainTextEdit->setPlainText( v );
493 QVariant QgsProcessingStringWidgetWrapper::widgetValue()
const
496 return mLineEdit->text();
497 else if ( mPlainTextEdit )
498 return mPlainTextEdit->toPlainText();
503 QStringList QgsProcessingStringWidgetWrapper::compatibleParameterTypes()
const
518 QStringList QgsProcessingStringWidgetWrapper::compatibleOutputTypes()
const
526 QString QgsProcessingStringWidgetWrapper::parameterType()
const
533 return new QgsProcessingStringWidgetWrapper( parameter, type );
538 return new QgsProcessingStringParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
553 QWidget *QgsProcessingAuthConfigWidgetWrapper::createWidget()
561 mAuthConfigSelect =
new QgsAuthConfigSelect();
562 mAuthConfigSelect->setToolTip( parameterDefinition()->toolTip() );
566 emit widgetValueHasChanged(
this );
568 return mAuthConfigSelect;
574 void QgsProcessingAuthConfigWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
577 if ( mAuthConfigSelect )
578 mAuthConfigSelect->setConfigId( v );
581 QVariant QgsProcessingAuthConfigWidgetWrapper::widgetValue()
const
583 if ( mAuthConfigSelect )
584 return mAuthConfigSelect->configId();
589 QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleParameterTypes()
const
597 QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleOutputTypes()
const
602 QString QgsProcessingAuthConfigWidgetWrapper::parameterType()
const
609 return new QgsProcessingAuthConfigWidgetWrapper( parameter, type );
619 QVBoxLayout *vlayout =
new QVBoxLayout();
620 vlayout->setContentsMargins( 0, 0, 0, 0 );
622 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
624 mTypeComboBox =
new QComboBox();
627 vlayout->addWidget( mTypeComboBox );
629 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
630 mMinLineEdit =
new QLineEdit();
631 vlayout->addWidget( mMinLineEdit );
633 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
634 mMaxLineEdit =
new QLineEdit();
635 vlayout->addWidget( mMaxLineEdit );
637 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
638 mDefaultLineEdit =
new QLineEdit();
639 vlayout->addWidget( mDefaultLineEdit );
643 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( numberParam->dataType() ) );
644 mMinLineEdit->setText( QString::number( numberParam->minimum() ) );
645 mMaxLineEdit->setText( QString::number( numberParam->maximum() ) );
646 mDefaultLineEdit->setText( numberParam->defaultValue().toString() );
649 setLayout( vlayout );
652 QgsProcessingParameterDefinition *QgsProcessingNumberParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
655 double val = mDefaultLineEdit->text().toDouble( &ok );
658 auto param = qgis::make_unique< QgsProcessingParameterNumber >( name, description, dataType, ok ? val : QVariant() );
660 val = mMinLineEdit->text().toDouble( &ok );
663 param->setMinimum( val );
666 val = mMaxLineEdit->text().toDouble( &ok );
669 param->setMaximum( val );
672 param->setFlags( flags );
673 return param.release();
682 QWidget *QgsProcessingNumericWidgetWrapper::createWidget()
685 const QVariantMap metadata = numberDef->
metadata();
686 const int decimals = metadata.value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"decimals" ), 6 ).toInt();
694 QAbstractSpinBox *spinBox =
nullptr;
699 mDoubleSpinBox->setExpressionsEnabled(
true );
700 mDoubleSpinBox->setDecimals( decimals );
706 double singleStep = calculateStep( numberDef->
minimum(), numberDef->
maximum() );
707 singleStep = std::max( singleStep, std::pow( 10, -decimals ) );
708 mDoubleSpinBox->setSingleStep( singleStep );
711 spinBox = mDoubleSpinBox;
716 mSpinBox->setExpressionsEnabled(
true );
720 spinBox->setToolTip( parameterDefinition()->toolTip() );
722 double max = 999999999;
727 double min = -999999999;
732 if ( mDoubleSpinBox )
734 mDoubleSpinBox->setMinimum( min );
735 mDoubleSpinBox->setMaximum( max );
739 mSpinBox->setMinimum(
static_cast< int >( min ) );
740 mSpinBox->setMaximum(
static_cast< int >( max ) );
745 mAllowingNull =
true;
746 if ( mDoubleSpinBox )
748 mDoubleSpinBox->setShowClearButton(
true );
749 const double min = mDoubleSpinBox->minimum() - 1;
750 mDoubleSpinBox->setMinimum( min );
751 mDoubleSpinBox->setValue( min );
755 mSpinBox->setShowClearButton(
true );
756 const int min = mSpinBox->minimum() - 1;
757 mSpinBox->setMinimum( min );
758 mSpinBox->setValue( min );
760 spinBox->setSpecialValueText( tr(
"Not set" ) );
768 if ( mDoubleSpinBox )
770 double defaultVal = numberDef->
defaultValue().toDouble( &ok );
772 mDoubleSpinBox->setClearValue( defaultVal );
778 mSpinBox->setClearValue( intVal );
784 if ( mDoubleSpinBox )
785 mDoubleSpinBox->setClearValue( numberDef->
minimum() );
787 mSpinBox->setClearValue(
static_cast< int >( numberDef->
minimum() ) );
792 if ( mDoubleSpinBox )
794 mDoubleSpinBox->setValue( 0 );
795 mDoubleSpinBox->setClearValue( 0 );
799 mSpinBox->setValue( 0 );
800 mSpinBox->setClearValue( 0 );
805 if ( mDoubleSpinBox )
806 connect( mDoubleSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
this, [ = ] { emit widgetValueHasChanged(
this ); } );
808 connect( mSpinBox, qgis::overload<int>::of( &QgsSpinBox::valueChanged ),
this, [ = ] { emit widgetValueHasChanged(
this ); } );
816 void QgsProcessingNumericWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
818 if ( mDoubleSpinBox )
820 if ( mAllowingNull && !value.isValid() )
821 mDoubleSpinBox->clear();
825 mDoubleSpinBox->setValue( v );
830 if ( mAllowingNull && !value.isValid() )
835 mSpinBox->setValue( v );
840 QVariant QgsProcessingNumericWidgetWrapper::widgetValue()
const
842 if ( mDoubleSpinBox )
844 if ( mAllowingNull &&
qgsDoubleNear( mDoubleSpinBox->value(), mDoubleSpinBox->minimum() ) )
847 return mDoubleSpinBox->value();
851 if ( mAllowingNull && mSpinBox->value() == mSpinBox->minimum() )
854 return mSpinBox->value();
860 QStringList QgsProcessingNumericWidgetWrapper::compatibleParameterTypes()
const
869 QStringList QgsProcessingNumericWidgetWrapper::compatibleOutputTypes()
const
875 double QgsProcessingNumericWidgetWrapper::calculateStep(
const double minimum,
const double maximum )
877 const double valueRange = maximum - minimum;
878 if ( valueRange <= 1.0 )
880 const double step = valueRange / 10.0;
882 return qgsRound( step, -std::floor( std::log( step ) ) );
890 QString QgsProcessingNumericWidgetWrapper::parameterType()
const
897 return new QgsProcessingNumericWidgetWrapper( parameter, type );
902 return new QgsProcessingNumberParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
912 QVBoxLayout *vlayout =
new QVBoxLayout();
913 vlayout->setContentsMargins( 0, 0, 0, 0 );
915 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
917 mParentLayerComboBox =
new QComboBox();
919 QString initialParent;
921 initialParent = distParam->parentParameterName();
926 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
927 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
931 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
932 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
934 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
939 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
940 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
942 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
947 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
948 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
950 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
955 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
956 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
958 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
964 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
967 mParentLayerComboBox->addItem( initialParent, initialParent );
968 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
971 vlayout->addWidget( mParentLayerComboBox );
973 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
974 mMinLineEdit =
new QLineEdit();
975 vlayout->addWidget( mMinLineEdit );
977 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
978 mMaxLineEdit =
new QLineEdit();
979 vlayout->addWidget( mMaxLineEdit );
981 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
982 mDefaultLineEdit =
new QLineEdit();
983 vlayout->addWidget( mDefaultLineEdit );
987 mMinLineEdit->setText( QString::number( distParam->minimum() ) );
988 mMaxLineEdit->setText( QString::number( distParam->maximum() ) );
989 mDefaultLineEdit->setText( distParam->defaultValue().toString() );
992 setLayout( vlayout );
995 QgsProcessingParameterDefinition *QgsProcessingDistanceParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
998 double val = mDefaultLineEdit->text().toDouble( &ok );
1000 auto param = qgis::make_unique< QgsProcessingParameterDistance >( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1002 val = mMinLineEdit->text().toDouble( &ok );
1005 param->setMinimum( val );
1008 val = mMaxLineEdit->text().toFloat( &ok );
1011 param->setMaximum( val );
1014 param->setFlags( flags );
1015 return param.release();
1019 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1024 QString QgsProcessingDistanceWidgetWrapper::parameterType()
const
1031 return new QgsProcessingDistanceWidgetWrapper( parameter, type );
1034 QWidget *QgsProcessingDistanceWidgetWrapper::createWidget()
1038 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1043 mLabel =
new QLabel();
1044 mUnitsCombo =
new QComboBox();
1052 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
1053 const int labelMargin =
static_cast< int >( std::round( mUnitsCombo->fontMetrics().width(
'X' ) ) );
1055 const int labelMargin =
static_cast< int >( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1057 QHBoxLayout *layout =
new QHBoxLayout();
1058 layout->addWidget( spin, 1 );
1059 layout->insertSpacing( 1, labelMargin / 2 );
1060 layout->insertWidget( 2, mLabel );
1061 layout->insertWidget( 3, mUnitsCombo );
1066 mWarningLabel =
new QWidget();
1067 QHBoxLayout *warningLayout =
new QHBoxLayout();
1068 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1069 QLabel *warning =
new QLabel();
1071 const int size =
static_cast< int >( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1072 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1073 warning->setToolTip( tr(
"Distance is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1074 warningLayout->insertSpacing( 0, labelMargin / 2 );
1075 warningLayout->insertWidget( 1, warning );
1076 mWarningLabel->setLayout( warningLayout );
1077 layout->insertWidget( 4, mWarningLabel );
1079 QWidget *w =
new QWidget();
1080 layout->setContentsMargins( 0, 0, 0, 0 );
1081 w->setLayout( layout );
1096 void QgsProcessingDistanceWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1098 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1105 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterDistance *
>( parameterDefinition() )->parentParameterName() )
1107 setUnitParameterValue( wrapper->parameterValue() );
1110 setUnitParameterValue( wrapper->parameterValue() );
1124 void QgsProcessingDistanceWidgetWrapper::setUnitParameterValue(
const QVariant &value )
1130 std::unique_ptr< QgsProcessingContext > tmpContext;
1131 if ( mProcessingContextGenerator )
1132 context = mProcessingContextGenerator->processingContext();
1136 tmpContext = qgis::make_unique< QgsProcessingContext >();
1137 context = tmpContext.get();
1154 mUnitsCombo->hide();
1159 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( units ) );
1160 mUnitsCombo->show();
1167 QVariant QgsProcessingDistanceWidgetWrapper::widgetValue()
const
1169 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1170 if ( val.type() == QVariant::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1183 return new QgsProcessingDistanceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1193 QVBoxLayout *vlayout =
new QVBoxLayout();
1194 vlayout->setContentsMargins( 0, 0, 0, 0 );
1196 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1198 mDefaultLineEdit =
new QLineEdit();
1202 mDefaultLineEdit->setText( scaleParam->defaultValue().toString() );
1205 vlayout->addWidget( mDefaultLineEdit );
1207 setLayout( vlayout );
1210 QgsProcessingParameterDefinition *QgsProcessingScaleParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1213 double val = mDefaultLineEdit->text().toDouble( &ok );
1214 auto param = qgis::make_unique< QgsProcessingParameterScale >( name, description, ok ? val : QVariant() );
1215 param->setFlags( flags );
1216 return param.release();
1220 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1225 QString QgsProcessingScaleWidgetWrapper::parameterType()
const
1232 return new QgsProcessingScaleWidgetWrapper( parameter, type );
1235 QWidget *QgsProcessingScaleWidgetWrapper::createWidget()
1247 mScaleWidget->setAllowNull(
true );
1249 mScaleWidget->setMapCanvas( widgetContext().mapCanvas() );
1250 mScaleWidget->setShowCurrentScaleButton(
true );
1252 mScaleWidget->setToolTip( parameterDefinition()->toolTip() );
1255 emit widgetValueHasChanged(
this );
1257 return mScaleWidget;
1266 mScaleWidget->setMapCanvas( context.
mapCanvas() );
1271 QVariant QgsProcessingScaleWidgetWrapper::widgetValue()
const
1273 return mScaleWidget && !mScaleWidget->isNull() ? QVariant( mScaleWidget->scale() ) : QVariant();
1276 void QgsProcessingScaleWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1280 if ( mScaleWidget->allowNull() && !value.isValid() )
1281 mScaleWidget->setNull();
1285 mScaleWidget->setScale( v );
1292 return new QgsProcessingScaleParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1303 QVBoxLayout *vlayout =
new QVBoxLayout();
1304 vlayout->setContentsMargins( 0, 0, 0, 0 );
1306 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
1308 mTypeComboBox =
new QComboBox();
1311 vlayout->addWidget( mTypeComboBox );
1313 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1314 mMinLineEdit =
new QLineEdit();
1315 vlayout->addWidget( mMinLineEdit );
1317 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1318 mMaxLineEdit =
new QLineEdit();
1319 vlayout->addWidget( mMaxLineEdit );
1323 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( rangeParam->dataType() ) );
1325 mMinLineEdit->setText( QString::number( range.at( 0 ) ) );
1326 mMaxLineEdit->setText( QString::number( range.at( 1 ) ) );
1329 setLayout( vlayout );
1332 QgsProcessingParameterDefinition *QgsProcessingRangeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1334 QString defaultValue;
1335 if ( mMinLineEdit->text().isEmpty() )
1337 defaultValue = QStringLiteral(
"None" );
1341 defaultValue = mMinLineEdit->text();
1344 if ( mMaxLineEdit->text().isEmpty() )
1346 defaultValue += QLatin1String(
",None" );
1350 defaultValue += QStringLiteral(
"," ) + mMaxLineEdit->text();
1354 auto param = qgis::make_unique< QgsProcessingParameterRange >( name, description, dataType, defaultValue );
1355 param->setFlags( flags );
1356 return param.release();
1366 QWidget *QgsProcessingRangeWidgetWrapper::createWidget()
1375 QHBoxLayout *layout =
new QHBoxLayout();
1380 mMinSpinBox->setExpressionsEnabled(
true );
1381 mMinSpinBox->setShowClearButton(
false );
1382 mMaxSpinBox->setExpressionsEnabled(
true );
1383 mMaxSpinBox->setShowClearButton(
false );
1385 QLabel *minLabel =
new QLabel( tr(
"Min" ) );
1386 layout->addWidget( minLabel );
1387 layout->addWidget( mMinSpinBox, 1 );
1389 QLabel *maxLabel =
new QLabel( tr(
"Max" ) );
1390 layout->addWidget( maxLabel );
1391 layout->addWidget( mMaxSpinBox, 1 );
1393 QWidget *w =
new QWidget();
1394 layout->setContentsMargins( 0, 0, 0, 0 );
1395 w->setLayout( layout );
1399 mMinSpinBox->setDecimals( 6 );
1400 mMaxSpinBox->setDecimals( 6 );
1404 mMinSpinBox->setDecimals( 0 );
1405 mMaxSpinBox->setDecimals( 0 );
1408 mMinSpinBox->setMinimum( -99999999.999999 );
1409 mMaxSpinBox->setMinimum( -99999999.999999 );
1410 mMinSpinBox->setMaximum( 99999999.999999 );
1411 mMaxSpinBox->setMaximum( 99999999.999999 );
1415 mAllowingNull =
true;
1417 const double min = mMinSpinBox->minimum() - 1;
1418 mMinSpinBox->setMinimum( min );
1419 mMaxSpinBox->setMinimum( min );
1420 mMinSpinBox->setValue( min );
1421 mMaxSpinBox->setValue( min );
1423 mMinSpinBox->setShowClearButton(
true );
1424 mMaxSpinBox->setShowClearButton(
true );
1425 mMinSpinBox->setSpecialValueText( tr(
"Not set" ) );
1426 mMaxSpinBox->setSpecialValueText( tr(
"Not set" ) );
1429 w->setToolTip( parameterDefinition()->toolTip() );
1431 connect( mMinSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
const double v )
1433 mBlockChangedSignal++;
1434 if ( !mAllowingNull && v > mMaxSpinBox->value() )
1435 mMaxSpinBox->setValue( v );
1436 mBlockChangedSignal--;
1438 if ( !mBlockChangedSignal )
1439 emit widgetValueHasChanged(
this );
1441 connect( mMaxSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
const double v )
1443 mBlockChangedSignal++;
1444 if ( !mAllowingNull && v < mMinSpinBox->value() )
1445 mMinSpinBox->setValue( v );
1446 mBlockChangedSignal--;
1448 if ( !mBlockChangedSignal )
1449 emit widgetValueHasChanged(
this );
1458 void QgsProcessingRangeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1461 if ( mAllowingNull && v.empty() )
1463 mMinSpinBox->clear();
1464 mMaxSpinBox->clear();
1471 if ( mAllowingNull )
1473 mBlockChangedSignal++;
1474 if ( std::isnan( v.at( 0 ) ) )
1475 mMinSpinBox->clear();
1477 mMinSpinBox->setValue( v.at( 0 ) );
1479 if ( v.count() >= 2 )
1481 if ( std::isnan( v.at( 1 ) ) )
1482 mMaxSpinBox->clear();
1484 mMaxSpinBox->setValue( v.at( 1 ) );
1486 mBlockChangedSignal--;
1490 mBlockChangedSignal++;
1491 mMinSpinBox->setValue( v.at( 0 ) );
1492 if ( v.count() >= 2 )
1493 mMaxSpinBox->setValue( v.at( 1 ) );
1494 mBlockChangedSignal--;
1498 if ( !mBlockChangedSignal )
1499 emit widgetValueHasChanged(
this );
1502 QVariant QgsProcessingRangeWidgetWrapper::widgetValue()
const
1504 if ( mAllowingNull )
1507 if (
qgsDoubleNear( mMinSpinBox->value(), mMinSpinBox->minimum() ) )
1508 value = QStringLiteral(
"None" );
1510 value = QString::number( mMinSpinBox->value() );
1512 if (
qgsDoubleNear( mMaxSpinBox->value(), mMaxSpinBox->minimum() ) )
1513 value += QLatin1String(
",None" );
1515 value += QStringLiteral(
",%1" ).arg( mMaxSpinBox->value() );
1520 return QStringLiteral(
"%1,%2" ).arg( mMinSpinBox->value() ).arg( mMaxSpinBox->value() );
1523 QStringList QgsProcessingRangeWidgetWrapper::compatibleParameterTypes()
const
1525 return QStringList()
1530 QStringList QgsProcessingRangeWidgetWrapper::compatibleOutputTypes()
const
1535 QString QgsProcessingRangeWidgetWrapper::modelerExpressionFormatString()
const
1537 return tr(
"string as two comma delimited floats, e.g. '1,10'" );
1540 QString QgsProcessingRangeWidgetWrapper::parameterType()
const
1547 return new QgsProcessingRangeWidgetWrapper( parameter, type );
1552 return new QgsProcessingRangeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1563 QVBoxLayout *vlayout =
new QVBoxLayout();
1564 vlayout->setContentsMargins( 0, 0, 0, 0 );
1566 mMatrixWidget =
new QgsProcessingMatrixModelerWidget();
1569 mMatrixWidget->setValue( matrixParam->headers(), matrixParam->defaultValue() );
1570 mMatrixWidget->setFixedRows( matrixParam->hasFixedNumberRows() );
1572 vlayout->addWidget( mMatrixWidget );
1573 setLayout( vlayout );
1576 QgsProcessingParameterDefinition *QgsProcessingMatrixParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1578 auto param = qgis::make_unique< QgsProcessingParameterMatrix >( name, description, 1, mMatrixWidget->fixedRows(), mMatrixWidget->headers(), mMatrixWidget->value() );
1579 param->setFlags( flags );
1580 return param.release();
1590 QWidget *QgsProcessingMatrixWidgetWrapper::createWidget()
1592 mMatrixWidget =
new QgsProcessingMatrixParameterPanel(
nullptr,
dynamic_cast< const QgsProcessingParameterMatrix *
>( parameterDefinition() ) );
1593 mMatrixWidget->setToolTip( parameterDefinition()->toolTip() );
1595 connect( mMatrixWidget, &QgsProcessingMatrixParameterPanel::changed,
this, [ = ]
1597 emit widgetValueHasChanged(
this );
1606 return mMatrixWidget;
1612 void QgsProcessingMatrixWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1615 if ( mMatrixWidget )
1616 mMatrixWidget->setValue( v );
1619 QVariant QgsProcessingMatrixWidgetWrapper::widgetValue()
const
1621 if ( mMatrixWidget )
1622 return mMatrixWidget->value().isEmpty() ? QVariant() : mMatrixWidget->value();
1627 QStringList QgsProcessingMatrixWidgetWrapper::compatibleParameterTypes()
const
1629 return QStringList()
1633 QStringList QgsProcessingMatrixWidgetWrapper::compatibleOutputTypes()
const
1635 return QStringList();
1638 QString QgsProcessingMatrixWidgetWrapper::modelerExpressionFormatString()
const
1640 return tr(
"comma delimited string of values, or an array of values" );
1643 QString QgsProcessingMatrixWidgetWrapper::parameterType()
const
1650 return new QgsProcessingMatrixWidgetWrapper( parameter, type );
1655 return new QgsProcessingMatrixParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1667 QVBoxLayout *vlayout =
new QVBoxLayout();
1668 vlayout->setContentsMargins( 0, 0, 0, 0 );
1670 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
1672 mTypeComboBox =
new QComboBox();
1676 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( fileParam->behavior() ) );
1678 mTypeComboBox->setCurrentIndex( 0 );
1679 vlayout->addWidget( mTypeComboBox );
1681 vlayout->addWidget(
new QLabel( tr(
"File filter" ) ) );
1683 mFilterComboBox =
new QComboBox();
1684 mFilterComboBox->setEditable(
true );
1686 mFilterComboBox->addItem( tr(
"All Files (*.*)" ) );
1687 mFilterComboBox->addItem( tr(
"CSV Files (*.csv)" ) );
1688 mFilterComboBox->addItem( tr(
"HTML Files (*.html *.htm)" ) );
1689 mFilterComboBox->addItem( tr(
"Text Files (*.txt)" ) );
1691 mFilterComboBox->setCurrentText( fileParam->fileFilter() );
1693 mFilterComboBox->setCurrentIndex( 0 );
1694 vlayout->addWidget( mFilterComboBox );
1696 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1699 mDefaultFileWidget->lineEdit()->setShowClearButton(
true );
1703 mDefaultFileWidget->setFilePath( fileParam->defaultValue().toString() );
1707 vlayout->addWidget( mDefaultFileWidget );
1709 connect( mTypeComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
this, [ = ]
1718 setLayout( vlayout );
1721 QgsProcessingParameterDefinition *QgsProcessingFileParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1723 auto param = qgis::make_unique< QgsProcessingParameterFile >( name, description );
1726 param->setFileFilter( mFilterComboBox->currentText() );
1727 if ( !mDefaultFileWidget->filePath().isEmpty() )
1728 param->setDefaultValue( mDefaultFileWidget->filePath() );
1729 param->setFlags( flags );
1730 return param.release();
1740 QWidget *QgsProcessingFileWidgetWrapper::createWidget()
1750 mFileWidget->setToolTip( parameterDefinition()->toolTip() );
1751 mFileWidget->setDialogTitle( parameterDefinition()->description() );
1753 mFileWidget->setDefaultRoot(
QgsSettings().value( QStringLiteral(
"/Processing/LastInputPath" ), QDir::homePath() ).toString() );
1760 mFileWidget->setFilter( fileParam->
fileFilter() );
1761 else if ( !fileParam->
extension().isEmpty() )
1762 mFileWidget->setFilter( tr(
"%1 files" ).arg( fileParam->
extension().toUpper() ) + QStringLiteral(
" (*." ) + fileParam->
extension().toLower() +
')' );
1772 QgsSettings().
setValue( QStringLiteral(
"/Processing/LastInputPath" ), QFileInfo( path ).canonicalPath() );
1773 emit widgetValueHasChanged(
this );
1781 void QgsProcessingFileWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1785 mFileWidget->setFilePath( v );
1788 QVariant QgsProcessingFileWidgetWrapper::widgetValue()
const
1791 return mFileWidget->filePath();
1796 QStringList QgsProcessingFileWidgetWrapper::compatibleParameterTypes()
const
1798 return QStringList()
1803 QStringList QgsProcessingFileWidgetWrapper::compatibleOutputTypes()
const
1813 QString QgsProcessingFileWidgetWrapper::modelerExpressionFormatString()
const
1815 return tr(
"string representing a path to a file or folder" );
1818 QString QgsProcessingFileWidgetWrapper::parameterType()
const
1825 return new QgsProcessingFileWidgetWrapper( parameter, type );
1830 return new QgsProcessingFileParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1842 QVBoxLayout *vlayout =
new QVBoxLayout();
1843 vlayout->setContentsMargins( 0, 0, 0, 0 );
1845 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1850 vlayout->addWidget( mDefaultLineEdit );
1852 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
1854 mParentLayerComboBox =
new QComboBox();
1855 mParentLayerComboBox->addItem( tr(
"None" ), QVariant() );
1857 QString initialParent;
1859 initialParent = expParam->parentLayerParameterName();
1864 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
1865 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
1869 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1870 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1872 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1877 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1878 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1880 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1886 if ( mParentLayerComboBox->count() == 1 && !initialParent.isEmpty() )
1889 mParentLayerComboBox->addItem( initialParent, initialParent );
1890 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1893 vlayout->addWidget( mParentLayerComboBox );
1894 setLayout( vlayout );
1897 QgsProcessingParameterDefinition *QgsProcessingExpressionParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1899 auto param = qgis::make_unique< QgsProcessingParameterExpression >( name, description, mDefaultLineEdit->expression(), mParentLayerComboBox->currentData().toString() );
1900 param->setFlags( flags );
1901 return param.release();
1910 QWidget *QgsProcessingExpressionWidgetWrapper::createWidget()
1922 mExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
1923 mExpLineEdit->setExpressionDialogTitle( parameterDefinition()->description() );
1924 mExpLineEdit->registerExpressionContextGenerator(
this );
1927 emit widgetValueHasChanged(
this );
1929 return mExpLineEdit;
1933 if ( expParam->
metadata().value( QStringLiteral(
"inlineEditor" ) ).toBool() )
1936 mExpBuilderWidget->setToolTip( parameterDefinition()->toolTip() );
1937 mExpBuilderWidget->init( createExpressionContext() );
1940 Q_UNUSED( changed );
1941 emit widgetValueHasChanged(
this );
1943 return mExpBuilderWidget;
1948 mFieldExpWidget->setToolTip( parameterDefinition()->toolTip() );
1949 mFieldExpWidget->setExpressionDialogTitle( parameterDefinition()->description() );
1950 mFieldExpWidget->registerExpressionContextGenerator(
this );
1953 emit widgetValueHasChanged(
this );
1955 return mFieldExpWidget;
1963 void QgsProcessingExpressionWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1973 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterExpression *
>( parameterDefinition() )->parentLayerParameterName() )
1975 setParentLayerWrapperValue( wrapper );
1978 setParentLayerWrapperValue( wrapper );
1995 std::unique_ptr< QgsProcessingContext > tmpContext;
1996 if ( mProcessingContextGenerator )
1997 context = mProcessingContextGenerator->processingContext();
2001 tmpContext = qgis::make_unique< QgsProcessingContext >();
2002 context = tmpContext.get();
2008 if ( mFieldExpWidget )
2009 mFieldExpWidget->setLayer(
nullptr );
2010 else if ( mExpBuilderWidget )
2011 mExpBuilderWidget->setLayer(
nullptr );
2012 else if ( mExpLineEdit )
2013 mExpLineEdit->setLayer(
nullptr );
2019 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
2022 mParentLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
2023 layer = mParentLayer.get();
2030 if ( mFieldExpWidget )
2031 mFieldExpWidget->setLayer( layer );
2032 if ( mExpBuilderWidget )
2033 mExpBuilderWidget->setLayer( layer );
2034 else if ( mExpLineEdit )
2035 mExpLineEdit->setLayer( layer );
2038 void QgsProcessingExpressionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2041 if ( mFieldExpWidget )
2042 mFieldExpWidget->setExpression( v );
2043 else if ( mExpBuilderWidget )
2044 mExpBuilderWidget->setExpressionText( v );
2045 else if ( mExpLineEdit )
2046 mExpLineEdit->setExpression( v );
2049 QVariant QgsProcessingExpressionWidgetWrapper::widgetValue()
const
2051 if ( mFieldExpWidget )
2052 return mFieldExpWidget->expression();
2053 if ( mExpBuilderWidget )
2054 return mExpBuilderWidget->expressionText();
2055 else if ( mExpLineEdit )
2056 return mExpLineEdit->expression();
2061 QStringList QgsProcessingExpressionWidgetWrapper::compatibleParameterTypes()
const
2063 return QStringList()
2072 QStringList QgsProcessingExpressionWidgetWrapper::compatibleOutputTypes()
const
2074 return QStringList()
2079 QString QgsProcessingExpressionWidgetWrapper::modelerExpressionFormatString()
const
2081 return tr(
"string representation of an expression" );
2084 const QgsVectorLayer *QgsProcessingExpressionWidgetWrapper::linkedVectorLayer()
const
2086 if ( mFieldExpWidget && mFieldExpWidget->layer() )
2087 return mFieldExpWidget->layer();
2089 if ( mExpBuilderWidget && mExpBuilderWidget->layer() )
2090 return mExpBuilderWidget->layer();
2095 QString QgsProcessingExpressionWidgetWrapper::parameterType()
const
2102 return new QgsProcessingExpressionWidgetWrapper( parameter, type );
2107 return new QgsProcessingExpressionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2120 QHBoxLayout *hl =
new QHBoxLayout();
2121 hl->setContentsMargins( 0, 0, 0, 0 );
2123 mLineEdit =
new QLineEdit();
2124 mLineEdit->setEnabled(
false );
2125 hl->addWidget( mLineEdit, 1 );
2127 mToolButton =
new QToolButton();
2128 mToolButton->setText( QString( QChar( 0x2026 ) ) );
2129 hl->addWidget( mToolButton );
2135 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
2138 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingEnumPanelWidget::showDialog );
2141 void QgsProcessingEnumPanelWidget::setValue(
const QVariant &value )
2143 if ( value.isValid() )
2144 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
2148 updateSummaryText();
2152 void QgsProcessingEnumPanelWidget::showDialog()
2154 QVariantList availableOptions;
2157 availableOptions.reserve( mParam->options().size() );
2158 for (
int i = 0; i < mParam->options().count(); ++i )
2159 availableOptions << i;
2162 const QStringList options = mParam ? mParam->options() : QStringList();
2166 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
2167 widget->setPanelTitle( mParam->description() );
2169 widget->setValueFormatter( [options](
const QVariant & v ) -> QString
2171 const int i = v.toInt();
2172 return options.size() > i ? options.at( i ) : QString();
2175 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
2177 setValue( widget->selectedOptions() );
2184 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
2186 dlg.setValueFormatter( [options](
const QVariant & v ) -> QString
2188 const int i = v.toInt();
2189 return options.size() > i ? options.at( i ) : QString();
2193 setValue( dlg.selectedOptions() );
2198 void QgsProcessingEnumPanelWidget::updateSummaryText()
2201 mLineEdit->setText( tr(
"%1 options selected" ).arg( mValue.count() ) );
2208 QgsProcessingEnumCheckboxPanelWidget::QgsProcessingEnumCheckboxPanelWidget( QWidget *parent,
const QgsProcessingParameterEnum *param,
int columns )
2211 , mButtonGroup( new QButtonGroup( this ) )
2212 , mColumns( columns )
2214 mButtonGroup->setExclusive( !mParam->allowMultiple() );
2216 QGridLayout *l =
new QGridLayout();
2217 l->setContentsMargins( 0, 0, 0, 0 );
2219 int rows =
static_cast< int >( std::ceil( mParam->options().count() /
static_cast< double >( mColumns ) ) );
2220 for (
int i = 0; i < mParam->options().count(); ++i )
2222 QAbstractButton *button =
nullptr;
2223 if ( mParam->allowMultiple() )
2224 button =
new QCheckBox( mParam->options().at( i ) );
2226 button =
new QRadioButton( mParam->options().at( i ) );
2228 connect( button, &QAbstractButton::toggled,
this, [ = ]
2230 if ( !mBlockChangedSignal )
2234 mButtons.insert( i, button );
2235 mButtonGroup->addButton( button, i );
2236 l->addWidget( button, i % rows, i / rows );
2238 l->addItem(
new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, mColumns );
2241 if ( mParam->allowMultiple() )
2243 setContextMenuPolicy( Qt::CustomContextMenu );
2244 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsProcessingEnumCheckboxPanelWidget::showPopupMenu );
2248 QVariant QgsProcessingEnumCheckboxPanelWidget::value()
const
2250 if ( mParam->allowMultiple() )
2253 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2255 if ( it.value()->isChecked() )
2256 value.append( it.key() );
2262 return mButtonGroup->checkedId() >= 0 ? mButtonGroup->checkedId() : QVariant();
2266 void QgsProcessingEnumCheckboxPanelWidget::setValue(
const QVariant &value )
2268 mBlockChangedSignal =
true;
2269 if ( mParam->allowMultiple() )
2271 QVariantList selected;
2272 if ( value.isValid() )
2273 selected = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
2274 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2276 it.value()->setChecked( selected.contains( it.key() ) );
2282 if ( v.type() == QVariant::List )
2283 v = v.toList().value( 0 );
2284 if ( mButtons.contains( v ) )
2285 mButtons.value( v )->setChecked(
true );
2287 mBlockChangedSignal =
false;
2291 void QgsProcessingEnumCheckboxPanelWidget::showPopupMenu()
2294 QAction *selectAllAction =
new QAction( tr(
"Select All" ), &popupMenu );
2295 connect( selectAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::selectAll );
2296 QAction *clearAllAction =
new QAction( tr(
"Clear Selection" ), &popupMenu );
2297 connect( clearAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::deselectAll );
2298 popupMenu.addAction( selectAllAction );
2299 popupMenu.addAction( clearAllAction );
2300 popupMenu.exec( QCursor::pos() );
2303 void QgsProcessingEnumCheckboxPanelWidget::selectAll()
2305 mBlockChangedSignal =
true;
2306 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2307 it.value()->setChecked(
true );
2308 mBlockChangedSignal =
false;
2312 void QgsProcessingEnumCheckboxPanelWidget::deselectAll()
2314 mBlockChangedSignal =
true;
2315 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2316 it.value()->setChecked(
false );
2317 mBlockChangedSignal =
false;
2329 QVBoxLayout *vlayout =
new QVBoxLayout();
2330 vlayout->setContentsMargins( 0, 0, 0, 0 );
2332 mEnumWidget =
new QgsProcessingEnumModelerWidget();
2335 mEnumWidget->setAllowMultiple( enumParam->allowMultiple() );
2336 mEnumWidget->setOptions( enumParam->options() );
2337 mEnumWidget->setDefaultOptions( enumParam->defaultValue() );
2339 vlayout->addWidget( mEnumWidget );
2340 setLayout( vlayout );
2343 QgsProcessingParameterDefinition *QgsProcessingEnumParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
2345 auto param = qgis::make_unique< QgsProcessingParameterEnum >( name, description, mEnumWidget->options(), mEnumWidget->allowMultiple(), mEnumWidget->defaultOptions() );
2347 return param.release();
2357 QWidget *QgsProcessingEnumWidgetWrapper::createWidget()
2365 if ( expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"useCheckBoxes" ),
false ).toBool() )
2367 const int columns = expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"columns" ), 2 ).toInt();
2368 mCheckboxPanel =
new QgsProcessingEnumCheckboxPanelWidget(
nullptr, expParam, columns );
2369 mCheckboxPanel->setToolTip( parameterDefinition()->toolTip() );
2370 connect( mCheckboxPanel, &QgsProcessingEnumCheckboxPanelWidget::changed,
this, [ = ]
2372 emit widgetValueHasChanged(
this );
2374 return mCheckboxPanel;
2383 mPanel =
new QgsProcessingEnumPanelWidget(
nullptr, expParam );
2384 mPanel->setToolTip( parameterDefinition()->toolTip() );
2385 connect( mPanel, &QgsProcessingEnumPanelWidget::changed,
this, [ = ]
2387 emit widgetValueHasChanged(
this );
2393 mComboBox =
new QComboBox();
2396 mComboBox->addItem( tr(
"[Not selected]" ), QVariant() );
2397 const QStringList options = expParam->
options();
2398 for (
int i = 0; i < options.count(); ++i )
2399 mComboBox->addItem( options.at( i ), i );
2401 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2402 connect( mComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
2404 emit widgetValueHasChanged(
this );
2413 void QgsProcessingEnumWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2417 if ( !value.isValid() )
2418 mComboBox->setCurrentIndex( mComboBox->findData( QVariant() ) );
2422 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
2425 else if ( mPanel || mCheckboxPanel )
2428 if ( value.isValid() )
2431 opts.reserve( v.size() );
2436 mPanel->setValue( opts );
2437 else if ( mCheckboxPanel )
2438 mCheckboxPanel->setValue( opts );
2442 QVariant QgsProcessingEnumWidgetWrapper::widgetValue()
const
2445 return mComboBox->currentData();
2447 return mPanel->value();
2448 else if ( mCheckboxPanel )
2449 return mCheckboxPanel->value();
2454 QStringList QgsProcessingEnumWidgetWrapper::compatibleParameterTypes()
const
2456 return QStringList()
2462 QStringList QgsProcessingEnumWidgetWrapper::compatibleOutputTypes()
const
2464 return QStringList()
2469 QString QgsProcessingEnumWidgetWrapper::modelerExpressionFormatString()
const
2471 return tr(
"selected option index (starting from 0), array of indices, or comma separated string of options (e.g. '1,3')" );
2474 QString QgsProcessingEnumWidgetWrapper::parameterType()
const
2481 return new QgsProcessingEnumWidgetWrapper( parameter, type );
2486 return new QgsProcessingEnumParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2499 QWidget *QgsProcessingLayoutWidgetWrapper::createWidget()
2508 mComboBox =
new QgsLayoutComboBox(
nullptr, widgetContext().project() ? widgetContext().project()->layoutManager() :
nullptr );
2510 mComboBox->setAllowEmptyLayout(
true );
2513 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2516 emit widgetValueHasChanged(
this );
2523 mPlainComboBox =
new QComboBox();
2524 mPlainComboBox->setEditable(
true );
2525 mPlainComboBox->setToolTip( tr(
"Name of an existing print layout" ) );
2526 if ( widgetContext().project() )
2530 mPlainComboBox->addItem( layout->name() );
2533 connect( mPlainComboBox, &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
2535 emit widgetValueHasChanged(
this );
2537 return mPlainComboBox;
2543 void QgsProcessingLayoutWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2547 if ( !value.isValid() )
2548 mComboBox->setCurrentLayout(
nullptr );
2552 mComboBox->setCurrentLayout( l );
2554 mComboBox->setCurrentLayout(
nullptr );
2557 else if ( mPlainComboBox )
2560 mPlainComboBox->setCurrentText( v );
2564 QVariant QgsProcessingLayoutWidgetWrapper::widgetValue()
const
2569 return l ? l->
name() : QVariant();
2571 else if ( mPlainComboBox )
2572 return mPlainComboBox->currentText().isEmpty() ? QVariant() : mPlainComboBox->currentText();
2580 if ( mPlainComboBox && context.
project() )
2584 mPlainComboBox->addItem( layout->name() );
2588 QStringList QgsProcessingLayoutWidgetWrapper::compatibleParameterTypes()
const
2590 return QStringList()
2595 QStringList QgsProcessingLayoutWidgetWrapper::compatibleOutputTypes()
const
2597 return QStringList()
2601 QString QgsProcessingLayoutWidgetWrapper::modelerExpressionFormatString()
const
2603 return tr(
"string representing the name of an existing print layout" );
2606 QString QgsProcessingLayoutWidgetWrapper::parameterType()
const
2613 return new QgsProcessingLayoutWidgetWrapper( parameter, type );
2627 QVBoxLayout *vlayout =
new QVBoxLayout();
2628 vlayout->setContentsMargins( 0, 0, 0, 0 );
2630 vlayout->addWidget(
new QLabel( tr(
"Parent layout" ) ) );
2632 mParentLayoutComboBox =
new QComboBox();
2633 QString initialParent;
2635 initialParent = itemParam->parentLayoutParameterName();
2640 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
2641 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
2645 mParentLayoutComboBox-> addItem( definition->
description(), definition->
name() );
2646 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2648 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
2654 if ( mParentLayoutComboBox->count() == 0 && !initialParent.isEmpty() )
2657 mParentLayoutComboBox->addItem( initialParent, initialParent );
2658 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
2661 vlayout->addWidget( mParentLayoutComboBox );
2662 setLayout( vlayout );
2664 QgsProcessingParameterDefinition *QgsProcessingLayoutItemParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
2666 auto param = qgis::make_unique< QgsProcessingParameterLayoutItem >( name, description, QVariant(), mParentLayoutComboBox->currentData().toString() );
2668 return param.release();
2678 QWidget *QgsProcessingLayoutItemWidgetWrapper::createWidget()
2689 mComboBox->setAllowEmptyItem(
true );
2690 if ( layoutParam->
itemType() >= 0 )
2693 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2696 emit widgetValueHasChanged(
this );
2703 mLineEdit =
new QLineEdit();
2704 mLineEdit->setToolTip( tr(
"UUID or ID of an existing print layout item" ) );
2705 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
2707 emit widgetValueHasChanged(
this );
2715 void QgsProcessingLayoutItemWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
2725 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterLayoutItem *
>( parameterDefinition() )->parentLayoutParameterName() )
2727 setLayoutParameterValue( wrapper->parameterValue() );
2730 setLayoutParameterValue( wrapper->parameterValue() );
2743 void QgsProcessingLayoutItemWidgetWrapper::setLayoutParameterValue(
const QVariant &value )
2749 std::unique_ptr< QgsProcessingContext > tmpContext;
2750 if ( mProcessingContextGenerator )
2751 context = mProcessingContextGenerator->processingContext();
2755 tmpContext = qgis::make_unique< QgsProcessingContext >();
2756 context = tmpContext.get();
2760 setLayout( layout );
2763 void QgsProcessingLayoutItemWidgetWrapper::setLayout(
QgsPrintLayout *layout )
2766 mComboBox->setCurrentLayout( layout );
2769 void QgsProcessingLayoutItemWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2773 if ( !value.isValid() )
2774 mComboBox->setItem(
nullptr );
2778 mComboBox->setItem( item );
2781 else if ( mLineEdit )
2784 mLineEdit->setText( v );
2788 QVariant QgsProcessingLayoutItemWidgetWrapper::widgetValue()
const
2793 return i ? i->
uuid() : QVariant();
2795 else if ( mLineEdit )
2796 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
2801 QStringList QgsProcessingLayoutItemWidgetWrapper::compatibleParameterTypes()
const
2803 return QStringList()
2808 QStringList QgsProcessingLayoutItemWidgetWrapper::compatibleOutputTypes()
const
2810 return QStringList()
2814 QString QgsProcessingLayoutItemWidgetWrapper::modelerExpressionFormatString()
const
2816 return tr(
"string representing the UUID or ID of an existing print layout item" );
2819 QString QgsProcessingLayoutItemWidgetWrapper::parameterType()
const
2826 return new QgsProcessingLayoutItemWidgetWrapper( parameter, type );
2831 return new QgsProcessingLayoutItemParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2838 QgsProcessingPointMapTool::QgsProcessingPointMapTool(
QgsMapCanvas *canvas )
2845 QgsProcessingPointMapTool::~QgsProcessingPointMapTool() =
default;
2847 void QgsProcessingPointMapTool::deactivate()
2861 if ( e->button() == Qt::LeftButton )
2864 emit clicked( point );
2869 void QgsProcessingPointMapTool::keyPressEvent( QKeyEvent *e )
2871 if ( e->key() == Qt::Key_Escape )
2886 QgsProcessingPointPanel::QgsProcessingPointPanel( QWidget *parent )
2889 QHBoxLayout *l =
new QHBoxLayout();
2890 l->setContentsMargins( 0, 0, 0, 0 );
2892 mLineEdit->setShowClearButton(
false );
2893 l->addWidget( mLineEdit, 1 );
2894 mButton =
new QToolButton();
2895 mButton->setText( QString( QChar( 0x2026 ) ) );
2896 l->addWidget( mButton );
2899 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::changed );
2900 connect( mButton, &QToolButton::clicked,
this, &QgsProcessingPointPanel::selectOnCanvas );
2901 mButton->setVisible(
false );
2904 void QgsProcessingPointPanel::setMapCanvas(
QgsMapCanvas *canvas )
2907 mButton->setVisible(
true );
2910 mTool = qgis::make_unique< QgsProcessingPointMapTool >( mCanvas );
2911 connect( mTool.get(), &QgsProcessingPointMapTool::clicked,
this, &QgsProcessingPointPanel::updatePoint );
2912 connect( mTool.get(), &QgsProcessingPointMapTool::complete,
this, &QgsProcessingPointPanel::pointPicked );
2915 void QgsProcessingPointPanel::setAllowNull(
bool allowNull )
2917 mLineEdit->setShowClearButton( allowNull );
2920 QVariant QgsProcessingPointPanel::value()
const
2922 return mLineEdit->showClearButton() && mLineEdit->text().trimmed().isEmpty() ? QVariant() : QVariant( mLineEdit->text() );
2925 void QgsProcessingPointPanel::clear()
2932 QString newText = QStringLiteral(
"%1,%2" )
2933 .arg( QString::number( point.
x(),
'f' ),
2934 QString::number( point.
y(),
'f' ) );
2937 if ( mCrs.isValid() )
2939 newText += QStringLiteral(
" [%1]" ).arg( mCrs.authid() );
2941 mLineEdit->setText( newText );
2944 void QgsProcessingPointPanel::selectOnCanvas()
2949 mPrevTool = mCanvas->mapTool();
2950 mCanvas->setMapTool( mTool.get() );
2952 emit toggleDialogVisibility(
false );
2955 void QgsProcessingPointPanel::updatePoint(
const QgsPointXY &point )
2957 setValue( point, mCanvas->mapSettings().destinationCrs() );
2960 void QgsProcessingPointPanel::pointPicked()
2965 mCanvas->setMapTool( mPrevTool );
2967 emit toggleDialogVisibility(
true );
2979 QVBoxLayout *vlayout =
new QVBoxLayout();
2980 vlayout->setContentsMargins( 0, 0, 0, 0 );
2982 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2984 mDefaultLineEdit =
new QLineEdit();
2985 mDefaultLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
2986 mDefaultLineEdit->setPlaceholderText( tr(
"Point as 'x,y'" ) );
2990 mDefaultLineEdit->setText( QStringLiteral(
"%1,%2" ).arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) ) );
2993 vlayout->addWidget( mDefaultLineEdit );
2994 setLayout( vlayout );
2997 QgsProcessingParameterDefinition *QgsProcessingPointParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
2999 auto param = qgis::make_unique< QgsProcessingParameterPoint >( name, description, mDefaultLineEdit->text() );
3001 return param.release();
3010 QWidget *QgsProcessingPointWidgetWrapper::createWidget()
3018 mPanel =
new QgsProcessingPointPanel(
nullptr );
3019 if ( widgetContext().mapCanvas() )
3020 mPanel->setMapCanvas( widgetContext().mapCanvas() );
3023 mPanel->setAllowNull(
true );
3025 mPanel->setToolTip( parameterDefinition()->toolTip() );
3027 connect( mPanel, &QgsProcessingPointPanel::changed,
this, [ = ]
3029 emit widgetValueHasChanged(
this );
3033 setDialog( mDialog );
3039 mLineEdit =
new QLineEdit();
3040 mLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
3041 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
3043 emit widgetValueHasChanged(
this );
3055 mPanel->setMapCanvas( context.
mapCanvas() );
3058 void QgsProcessingPointWidgetWrapper::setDialog( QDialog *dialog )
3063 connect( mPanel, &QgsProcessingPointPanel::toggleDialogVisibility, mDialog, [ = ](
bool visible )
3066 mDialog->showMinimized();
3069 mDialog->showNormal();
3071 mDialog->activateWindow();
3078 void QgsProcessingPointWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3082 if ( !value.isValid() || ( value.type() == QVariant::String && value.toString().isEmpty() ) )
3088 mPanel->setValue( p,
crs );
3091 else if ( mLineEdit )
3094 mLineEdit->setText( v );
3098 QVariant QgsProcessingPointWidgetWrapper::widgetValue()
const
3102 return mPanel->value();
3104 else if ( mLineEdit )
3105 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3110 QStringList QgsProcessingPointWidgetWrapper::compatibleParameterTypes()
const
3112 return QStringList()
3117 QStringList QgsProcessingPointWidgetWrapper::compatibleOutputTypes()
const
3119 return QStringList()
3123 QString QgsProcessingPointWidgetWrapper::modelerExpressionFormatString()
const
3125 return tr(
"string of the format 'x,y' or a geometry value (centroid is used)" );
3128 QString QgsProcessingPointWidgetWrapper::parameterType()
const
3135 return new QgsProcessingPointWidgetWrapper( parameter, type );
3140 return new QgsProcessingPointParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3152 QVBoxLayout *vlayout =
new QVBoxLayout();
3153 vlayout->setContentsMargins( 0, 0, 0, 0 );
3155 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3157 mDefaultLineEdit =
new QLineEdit();
3158 mDefaultLineEdit->setToolTip( tr(
"Geometry as WKT" ) );
3159 mDefaultLineEdit->setPlaceholderText( tr(
"Geometry as WKT" ) );
3164 mDefaultLineEdit->setText( g.
asWkt() );
3167 vlayout->addWidget( mDefaultLineEdit );
3168 setLayout( vlayout );
3171 QgsProcessingParameterDefinition *QgsProcessingGeometryParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3173 auto param = qgis::make_unique< QgsProcessingParameterGeometry >( name, description, mDefaultLineEdit->text() );
3175 return param.release();
3184 QWidget *QgsProcessingGeometryWidgetWrapper::createWidget()
3192 mLineEdit =
new QLineEdit();
3193 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
3194 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
3196 emit widgetValueHasChanged(
this );
3204 void QgsProcessingGeometryWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3210 mLineEdit->setText( g.
asWkt() );
3216 QVariant QgsProcessingGeometryWidgetWrapper::widgetValue()
const
3219 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3224 QStringList QgsProcessingGeometryWidgetWrapper::compatibleParameterTypes()
const
3226 return QStringList()
3233 QStringList QgsProcessingGeometryWidgetWrapper::compatibleOutputTypes()
const
3235 return QStringList()
3239 QString QgsProcessingGeometryWidgetWrapper::modelerExpressionFormatString()
const
3241 return tr(
"string in the Well-Known-Text format or a geometry value" );
3244 QString QgsProcessingGeometryWidgetWrapper::parameterType()
const
3251 return new QgsProcessingGeometryWidgetWrapper( parameter, type );
3256 return new QgsProcessingGeometryParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3268 QVBoxLayout *vlayout =
new QVBoxLayout();
3269 vlayout->setContentsMargins( 0, 0, 0, 0 );
3271 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3274 mDefaultColorButton->setShowNull(
true );
3275 mAllowOpacity =
new QCheckBox( tr(
"Allow opacity control" ) );
3281 mDefaultColorButton->setToNull();
3283 mDefaultColorButton->setColor(
c );
3284 mAllowOpacity->setChecked( colorParam->opacityEnabled() );
3288 mDefaultColorButton->setToNull();
3289 mAllowOpacity->setChecked(
true );
3292 vlayout->addWidget( mDefaultColorButton );
3293 vlayout->addWidget( mAllowOpacity );
3294 setLayout( vlayout );
3297 QgsProcessingParameterDefinition *QgsProcessingColorParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3299 auto param = qgis::make_unique< QgsProcessingParameterColor >( name, description, mDefaultColorButton->color(), mAllowOpacity->isChecked() );
3301 return param.release();
3310 QWidget *QgsProcessingColorWidgetWrapper::createWidget()
3320 mColorButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
3323 mColorButton->setShowNull(
true );
3326 mColorButton->setToolTip( parameterDefinition()->toolTip() );
3327 mColorButton->setColorDialogTitle( parameterDefinition()->description() );
3328 if ( colorParam->
defaultValue().value< QColor >().isValid() )
3330 mColorButton->setDefaultColor( colorParam->
defaultValue().value< QColor >() );
3335 emit widgetValueHasChanged(
this );
3338 return mColorButton;
3344 void QgsProcessingColorWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3348 if ( !value.isValid() ||
3349 ( value.type() == QVariant::String && value.toString().isEmpty() )
3350 || ( value.type() == QVariant::Color && !value.value< QColor >().isValid() ) )
3351 mColorButton->setToNull();
3355 if ( !
c.isValid() && mColorButton->showNull() )
3356 mColorButton->setToNull();
3358 mColorButton->setColor(
c );
3363 QVariant QgsProcessingColorWidgetWrapper::widgetValue()
const
3366 return mColorButton->isNull() ? QVariant() : mColorButton->color();
3371 QStringList QgsProcessingColorWidgetWrapper::compatibleParameterTypes()
const
3373 return QStringList()
3378 QStringList QgsProcessingColorWidgetWrapper::compatibleOutputTypes()
const
3380 return QStringList()
3384 QString QgsProcessingColorWidgetWrapper::modelerExpressionFormatString()
const
3386 return tr(
"color style string, e.g. #ff0000 or 255,0,0" );
3389 QString QgsProcessingColorWidgetWrapper::parameterType()
const
3396 return new QgsProcessingColorWidgetWrapper( parameter, type );
3401 return new QgsProcessingColorParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3412 QVBoxLayout *vlayout =
new QVBoxLayout();
3413 vlayout->setContentsMargins( 0, 0, 0, 0 );
3415 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3417 mDefaultLineEdit =
new QLineEdit();
3420 vlayout->addWidget( mDefaultLineEdit );
3422 mSourceParamComboBox =
new QComboBox();
3423 mDestParamComboBox =
new QComboBox();
3424 QString initialSource;
3425 QString initialDest;
3430 initialSource = itemParam->sourceCrsParameterName();
3431 initialDest = itemParam->destinationCrsParameterName();
3436 mSourceParamComboBox->addItem( QString(), QString() );
3437 mDestParamComboBox->addItem( QString(), QString() );
3441 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3442 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3444 if ( definition && it->parameterName() == definition->
name() )
3448 mSourceParamComboBox->addItem( it->parameterName(), it->parameterName() );
3449 mDestParamComboBox->addItem( it->parameterName(), it->parameterName() );
3450 if ( !initialSource.isEmpty() && initialSource == it->parameterName() )
3452 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
3454 if ( !initialDest.isEmpty() && initialDest == it->parameterName() )
3456 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
3461 if ( mSourceParamComboBox->count() == 1 && !initialSource.isEmpty() )
3464 mSourceParamComboBox->addItem( initialSource, initialSource );
3465 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
3467 if ( mDestParamComboBox->count() == 1 && !initialDest.isEmpty() )
3470 mDestParamComboBox->addItem( initialDest, initialDest );
3471 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
3474 vlayout->addWidget(
new QLabel( tr(
"Source CRS parameter" ) ) );
3475 vlayout->addWidget( mSourceParamComboBox );
3476 vlayout->addWidget(
new QLabel( tr(
"Destination CRS parameter" ) ) );
3477 vlayout->addWidget( mDestParamComboBox );
3481 mStaticSourceWidget->setCrs( sourceCrs );
3484 mStaticDestWidget->setCrs( destCrs );
3486 vlayout->addWidget(
new QLabel( tr(
"Static source CRS" ) ) );
3487 vlayout->addWidget( mStaticSourceWidget );
3488 vlayout->addWidget(
new QLabel( tr(
"Static destination CRS" ) ) );
3489 vlayout->addWidget( mStaticDestWidget );
3491 setLayout( vlayout );
3494 QgsProcessingParameterDefinition *QgsProcessingCoordinateOperationParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3496 auto param = qgis::make_unique< QgsProcessingParameterCoordinateOperation >( name, description, mDefaultLineEdit->text(),
3497 mSourceParamComboBox->currentText(),
3498 mDestParamComboBox->currentText(),
3499 mStaticSourceWidget->crs().isValid() ? QVariant::fromValue( mStaticSourceWidget->crs() ) : QVariant(),
3500 mStaticDestWidget->crs().isValid() ? QVariant::fromValue( mStaticDestWidget->crs() ) : QVariant() );
3502 return param.release();
3511 QWidget *QgsProcessingCoordinateOperationWidgetWrapper::createWidget()
3522 mOperationWidget->setShowMakeDefault(
false );
3523 mOperationWidget->setShowFallbackOption(
false );
3524 mOperationWidget->setToolTip( parameterDefinition()->toolTip() );
3525 mOperationWidget->setSourceCrs( mSourceCrs );
3526 mOperationWidget->setDestinationCrs( mDestCrs );
3527 mOperationWidget->setMapCanvas( mCanvas );
3528 if ( !coordParam->
defaultValue().toString().isEmpty() )
3532 mOperationWidget->setSelectedOperation( deets );
3537 emit widgetValueHasChanged(
this );
3540 return mOperationWidget;
3546 mLineEdit =
new QLineEdit();
3547 QHBoxLayout *layout =
new QHBoxLayout();
3548 layout->addWidget( mLineEdit, 1 );
3549 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
3551 emit widgetValueHasChanged(
this );
3554 QToolButton *button =
new QToolButton();
3555 button->setText( QString( QChar( 0x2026 ) ) );
3556 connect( button, &QToolButton::clicked,
this, [ = ]
3558 QgsDatumTransformDialog dlg( mSourceCrs, mDestCrs,
false,
false,
false, qMakePair( -1, -1 ), button, Qt::WindowFlags(), mLineEdit->text(), mCanvas );
3561 mLineEdit->setText( dlg.selectedDatumTransform().proj );
3562 emit widgetValueHasChanged(
this );
3565 layout->addWidget( button );
3567 QWidget *w =
new QWidget();
3568 layout->setContentsMargins( 0, 0, 0, 0 );
3569 w->setLayout( layout );
3577 void QgsProcessingCoordinateOperationWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3589 setSourceCrsParameterValue( wrapper->parameterValue() );
3592 setSourceCrsParameterValue( wrapper->parameterValue() );
3597 setDestinationCrsParameterValue( wrapper->parameterValue() );
3600 setDestinationCrsParameterValue( wrapper->parameterValue() );
3615 if ( mOperationWidget )
3616 mOperationWidget->setMapCanvas( context.
mapCanvas() );
3619 void QgsProcessingCoordinateOperationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
3621 if ( mOperationWidget )
3623 if ( !value.isValid() ||
3624 ( value.type() == QVariant::String ) )
3627 deets.
proj = value.toString();
3628 mOperationWidget->setSelectedOperation( deets );
3633 if ( !value.isValid() ||
3634 ( value.type() == QVariant::String ) )
3636 mLineEdit->setText( value.toString() );
3641 QVariant QgsProcessingCoordinateOperationWidgetWrapper::widgetValue()
const
3643 if ( mOperationWidget )
3644 return mOperationWidget->selectedOperation().proj;
3645 else if ( mLineEdit )
3646 return mLineEdit->text();
3651 QStringList QgsProcessingCoordinateOperationWidgetWrapper::compatibleParameterTypes()
const
3653 return QStringList()
3658 QStringList QgsProcessingCoordinateOperationWidgetWrapper::compatibleOutputTypes()
const
3660 return QStringList()
3664 QString QgsProcessingCoordinateOperationWidgetWrapper::modelerExpressionFormatString()
const
3666 return tr(
"Proj coordinate operation string, e.g. '+proj=pipeline +step +inv...'" );
3669 void QgsProcessingCoordinateOperationWidgetWrapper::setSourceCrsParameterValue(
const QVariant &value )
3672 std::unique_ptr< QgsProcessingContext > tmpContext;
3673 if ( mProcessingContextGenerator )
3674 context = mProcessingContextGenerator->processingContext();
3678 tmpContext = qgis::make_unique< QgsProcessingContext >();
3679 context = tmpContext.get();
3683 if ( mOperationWidget )
3685 mOperationWidget->setSourceCrs( mSourceCrs );
3686 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
3690 void QgsProcessingCoordinateOperationWidgetWrapper::setDestinationCrsParameterValue(
const QVariant &value )
3693 std::unique_ptr< QgsProcessingContext > tmpContext;
3694 if ( mProcessingContextGenerator )
3695 context = mProcessingContextGenerator->processingContext();
3699 tmpContext = qgis::make_unique< QgsProcessingContext >();
3700 context = tmpContext.get();
3704 if ( mOperationWidget )
3706 mOperationWidget->setDestinationCrs( mDestCrs );
3707 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
3711 QString QgsProcessingCoordinateOperationWidgetWrapper::parameterType()
const
3718 return new QgsProcessingCoordinateOperationWidgetWrapper( parameter, type );
3723 return new QgsProcessingCoordinateOperationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3736 QHBoxLayout *hl =
new QHBoxLayout();
3737 hl->setContentsMargins( 0, 0, 0, 0 );
3739 mLineEdit =
new QLineEdit();
3740 mLineEdit->setEnabled(
false );
3741 hl->addWidget( mLineEdit, 1 );
3743 mToolButton =
new QToolButton();
3744 mToolButton->setText( QString( QChar( 0x2026 ) ) );
3745 hl->addWidget( mToolButton );
3751 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
3754 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingFieldPanelWidget::showDialog );
3757 void QgsProcessingFieldPanelWidget::setFields(
const QgsFields &fields )
3762 void QgsProcessingFieldPanelWidget::setValue(
const QVariant &value )
3764 if ( value.isValid() )
3765 mValue = value.type() == QVariant::List ? value.
toList() : QVariantList() << value;
3769 updateSummaryText();
3773 void QgsProcessingFieldPanelWidget::showDialog()
3775 QVariantList availableOptions;
3776 QStringList fieldNames;
3777 availableOptions.reserve( mFields.size() );
3786 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
3787 widget->setPanelTitle( mParam->description() );
3789 widget->setValueFormatter( [](
const QVariant & v ) -> QString
3791 return v.toString();
3794 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
3796 setValue( widget->selectedOptions() );
3803 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
3805 dlg.setValueFormatter( [](
const QVariant & v ) -> QString
3807 return v.toString();
3811 setValue( dlg.selectedOptions() );
3816 void QgsProcessingFieldPanelWidget::updateSummaryText()
3819 mLineEdit->setText( tr(
"%1 options selected" ).arg( mValue.count() ) );
3830 QVBoxLayout *vlayout =
new QVBoxLayout();
3831 vlayout->setContentsMargins( 0, 0, 0, 0 );
3833 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
3834 mParentLayerComboBox =
new QComboBox();
3836 QString initialParent;
3838 initialParent = fieldParam->parentLayerParameterName();
3843 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3844 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3848 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
3849 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
3851 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
3856 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
3857 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
3859 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
3865 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
3868 mParentLayerComboBox->addItem( initialParent, initialParent );
3869 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
3872 vlayout->addWidget( mParentLayerComboBox );
3874 vlayout->addWidget(
new QLabel( tr(
"Allowed data type" ) ) );
3875 mDataTypeComboBox =
new QComboBox();
3881 mDataTypeComboBox->setCurrentIndex( mDataTypeComboBox->findData( fieldParam->dataType() ) );
3883 vlayout->addWidget( mDataTypeComboBox );
3885 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple fields" ) );
3887 mAllowMultipleCheckBox->setChecked( fieldParam->allowMultiple() );
3889 vlayout->addWidget( mAllowMultipleCheckBox );
3891 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all fields by default" ) );
3892 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
3894 mDefaultToAllCheckBox->setChecked( fieldParam->defaultToAllFields() );
3896 vlayout->addWidget( mDefaultToAllCheckBox );
3898 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [ = ]
3900 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
3903 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3905 mDefaultLineEdit =
new QLineEdit();
3906 mDefaultLineEdit->setToolTip( tr(
"Default field name, or ; separated list of field names for multiple field parameters" ) );
3910 mDefaultLineEdit->setText( fields.join(
';' ) );
3912 vlayout->addWidget( mDefaultLineEdit );
3914 setLayout( vlayout );
3917 QgsProcessingParameterDefinition *QgsProcessingFieldParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3920 auto param = qgis::make_unique< QgsProcessingParameterField >( name, description, mDefaultLineEdit->text(), mParentLayerComboBox->currentData().toString(), dataType, mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
3922 return param.release();
3931 QWidget *QgsProcessingFieldWidgetWrapper::createWidget()
3941 mPanel =
new QgsProcessingFieldPanelWidget(
nullptr, fieldParam );
3942 mPanel->setToolTip( parameterDefinition()->toolTip() );
3943 connect( mPanel, &QgsProcessingFieldPanelWidget::changed,
this, [ = ]
3945 emit widgetValueHasChanged(
this );
3961 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3964 emit widgetValueHasChanged(
this );
3972 mLineEdit =
new QLineEdit();
3973 mLineEdit->setToolTip( QObject::tr(
"Name of field (separate field names with ; for multiple field parameters)" ) );
3974 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
3976 emit widgetValueHasChanged(
this );
3985 void QgsProcessingFieldWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3995 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterField *
>( parameterDefinition() )->parentLayerParameterName() )
3997 setParentLayerWrapperValue( wrapper );
4000 setParentLayerWrapperValue( wrapper );
4017 std::unique_ptr< QgsProcessingContext > tmpContext;
4018 if ( mProcessingContextGenerator )
4019 context = mProcessingContextGenerator->processingContext();
4023 tmpContext = qgis::make_unique< QgsProcessingContext >();
4024 context = tmpContext.get();
4039 if ( layer && layer->
isValid() )
4043 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
4046 mParentLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
4047 layer = mParentLayer.get();
4055 mComboBox->setLayer( layer );
4057 mPanel->setFields( filterFields( layer->
fields() ) );
4064 const QgsFields fields = source->fields();
4066 mComboBox->setFields( fields );
4068 mPanel->setFields( filterFields( fields ) );
4073 mComboBox->setLayer(
nullptr );
4077 if ( value.isValid() && widgetContext().messageBar() )
4080 widgetContext().
messageBar()->
pushMessage( QString(), QObject::tr(
"Could not load selected layer/table. Dependent field could not be populated" ),
4091 val.reserve( mPanel->fields().size() );
4094 setWidgetValue( val, *context );
4097 setWidgetValue( parameterDefinition()->defaultValue(), *context );
4100 void QgsProcessingFieldWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4104 if ( !value.isValid() )
4105 mComboBox->setField( QString() );
4109 mComboBox->setField( v );
4115 if ( value.isValid() )
4118 opts.reserve( v.size() );
4119 for (
const QString &i : v )
4123 mPanel->setValue( opts );
4125 else if ( mLineEdit )
4131 mLineEdit->setText( v.join(
';' ) );
4140 QVariant QgsProcessingFieldWidgetWrapper::widgetValue()
const
4143 return mComboBox->currentField();
4145 return mPanel->value();
4146 else if ( mLineEdit )
4151 return mLineEdit->text().split(
';' );
4154 return mLineEdit->text();
4160 QStringList QgsProcessingFieldWidgetWrapper::compatibleParameterTypes()
const
4162 return QStringList()
4167 QStringList QgsProcessingFieldWidgetWrapper::compatibleOutputTypes()
const
4169 return QStringList()
4173 QString QgsProcessingFieldWidgetWrapper::modelerExpressionFormatString()
const
4175 return tr(
"selected field names as an array of names, or semicolon separated string of options (e.g. 'fid;place_name')" );
4178 const QgsVectorLayer *QgsProcessingFieldWidgetWrapper::linkedVectorLayer()
const
4180 if ( mComboBox && mComboBox->layer() )
4181 return mComboBox->layer();
4186 QgsFields QgsProcessingFieldWidgetWrapper::filterFields(
const QgsFields &fields )
const
4199 if ( f.isNumeric() )
4204 if ( f.type() == QVariant::String )
4209 if ( f.type() == QVariant::Date || f.type() == QVariant::Time || f.type() == QVariant::DateTime )
4218 QString QgsProcessingFieldWidgetWrapper::parameterType()
const
4225 return new QgsProcessingFieldWidgetWrapper( parameter, type );
4230 return new QgsProcessingFieldParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4241 QVBoxLayout *vlayout =
new QVBoxLayout();
4242 vlayout->setContentsMargins( 0, 0, 0, 0 );
4244 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4246 mDefaultComboBox =
new QComboBox();
4247 mDefaultComboBox->addItem( QString(), QVariant( -1 ) );
4250 for (
const QString &theme : mapThemes )
4254 mDefaultComboBox->setEditable(
true );
4258 if ( themeParam->defaultValue().isValid() )
4261 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
4264 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
4266 vlayout->addWidget( mDefaultComboBox );
4268 setLayout( vlayout );
4271 QgsProcessingParameterDefinition *QgsProcessingMapThemeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4273 QVariant defaultVal;
4274 if ( mDefaultComboBox->currentText().isEmpty() )
4275 defaultVal = QVariant();
4277 defaultVal = mDefaultComboBox->currentText();
4278 auto param = qgis::make_unique< QgsProcessingParameterMapTheme>( name, description, defaultVal );
4280 return param.release();
4290 QWidget *QgsProcessingMapThemeWidgetWrapper::createWidget()
4294 mComboBox =
new QComboBox();
4297 mComboBox->addItem( tr(
"[Not selected]" ), QVariant( -1 ) );
4300 for (
const QString &theme : mapThemes )
4312 mComboBox->setEditable(
true );
4316 mComboBox->setToolTip( parameterDefinition()->toolTip() );
4317 connect( mComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
4319 emit widgetValueHasChanged(
this );
4325 void QgsProcessingMapThemeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4329 if ( !value.isValid() )
4330 mComboBox->setCurrentIndex( mComboBox->findData( QVariant( -1 ) ) );
4333 if ( mComboBox->isEditable() && mComboBox->findData( v ) == -1 )
4335 const QString prev = mComboBox->currentText();
4336 mComboBox->setCurrentText( v );
4338 emit widgetValueHasChanged(
this );
4341 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
4345 QVariant QgsProcessingMapThemeWidgetWrapper::widgetValue()
const
4348 return mComboBox->currentData().toInt() == -1 ? QVariant() :
4349 !mComboBox->currentData().isValid() && mComboBox->isEditable() ? mComboBox->currentText().isEmpty() ? QVariant() : QVariant( mComboBox->currentText() )
4350 : mComboBox->currentData();
4355 QStringList QgsProcessingMapThemeWidgetWrapper::compatibleParameterTypes()
const
4357 return QStringList()
4362 QStringList QgsProcessingMapThemeWidgetWrapper::compatibleOutputTypes()
const
4364 return QStringList()
4368 QString QgsProcessingMapThemeWidgetWrapper::modelerExpressionFormatString()
const
4370 return tr(
"map theme as a string value (e.g. 'base maps')" );
4373 QString QgsProcessingMapThemeWidgetWrapper::parameterType()
const
4380 return new QgsProcessingMapThemeWidgetWrapper( parameter, type );
4385 return new QgsProcessingMapThemeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4398 QVBoxLayout *vlayout =
new QVBoxLayout();
4399 vlayout->setContentsMargins( 0, 0, 0, 0 );
4401 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
4403 mTypeComboBox =
new QComboBox();
4408 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( datetimeParam->dataType() ) );
4410 mTypeComboBox->setCurrentIndex( 0 );
4411 vlayout->addWidget( mTypeComboBox );
4413 setLayout( vlayout );
4416 QgsProcessingParameterDefinition *QgsProcessingDateTimeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4418 auto param = qgis::make_unique< QgsProcessingParameterDateTime >( name, description );
4421 return param.release();
4431 QWidget *QgsProcessingDateTimeWidgetWrapper::createWidget()
4436 switch ( dateTimeParam->
dataType() )
4440 widget = mDateTimeEdit;
4463 widget->setToolTip( parameterDefinition()->toolTip() );
4465 if ( mDateTimeEdit )
4469 emit widgetValueHasChanged(
this );
4472 else if ( mDateEdit )
4476 emit widgetValueHasChanged(
this );
4479 else if ( mTimeEdit )
4483 emit widgetValueHasChanged(
this );
4492 return new QgsProcessingDateTimeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4495 void QgsProcessingDateTimeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4497 if ( mDateTimeEdit )
4501 else if ( mDateEdit )
4505 else if ( mTimeEdit )
4511 QVariant QgsProcessingDateTimeWidgetWrapper::widgetValue()
const
4513 if ( mDateTimeEdit )
4514 return !mDateTimeEdit->dateTime().isNull() && mDateTimeEdit->dateTime().isValid() ? QVariant( mDateTimeEdit->dateTime() ) : QVariant();
4515 else if ( mDateEdit )
4516 return !mDateEdit->date().isNull() && mDateEdit->date().isValid() ? QVariant( mDateEdit->date() ) : QVariant();
4517 else if ( mTimeEdit )
4518 return !mTimeEdit->time().isNull() && mTimeEdit->time().isValid() ? QVariant( mTimeEdit->time() ) : QVariant();
4523 QStringList QgsProcessingDateTimeWidgetWrapper::compatibleParameterTypes()
const
4525 return QStringList()
4530 QStringList QgsProcessingDateTimeWidgetWrapper::compatibleOutputTypes()
const
4532 return QStringList()
4536 QString QgsProcessingDateTimeWidgetWrapper::modelerExpressionFormatString()
const
4539 if ( dateTimeParam )
4541 switch ( dateTimeParam->
dataType() )
4544 return tr(
"datetime value, or a ISO string representation of a datetime" );
4547 return tr(
"date value, or a ISO string representation of a date" );
4550 return tr(
"time value, or a ISO string representation of a time" );
4556 QString QgsProcessingDateTimeWidgetWrapper::parameterType()
const
4563 return new QgsProcessingDateTimeWidgetWrapper( parameter, type );
4577 QVBoxLayout *vlayout =
new QVBoxLayout();
4578 vlayout->setContentsMargins( 0, 0, 0, 0 );
4580 vlayout->addWidget(
new QLabel( tr(
"Provider" ) ) );
4581 mProviderComboBox =
new QComboBox();
4582 mProviderComboBox->addItem( QObject::tr(
"Postgres" ), QStringLiteral(
"postgres" ) );
4583 mProviderComboBox->addItem( QObject::tr(
"GeoPackage" ), QStringLiteral(
"ogr" ) );
4584 mProviderComboBox->addItem( QObject::tr(
"Spatialite" ), QStringLiteral(
"spatialite" ) );
4586 vlayout->addWidget( mProviderComboBox );
4588 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4590 mDefaultEdit =
new QLineEdit();
4591 vlayout->addWidget( mDefaultEdit );
4592 setLayout( vlayout );
4594 if ( connectionParam )
4596 mProviderComboBox->setCurrentIndex( mProviderComboBox->findData( connectionParam->
providerId() ) );
4597 mDefaultEdit->setText( connectionParam->
defaultValue().toString() );
4601 QgsProcessingParameterDefinition *QgsProcessingProviderConnectionParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4603 QVariant defaultVal;
4604 if ( mDefaultEdit->text().isEmpty() )
4605 defaultVal = QVariant();
4607 defaultVal = mDefaultEdit->text();
4608 auto param = qgis::make_unique< QgsProcessingParameterProviderConnection>( name, description, mProviderComboBox->currentData().toString(), defaultVal );
4610 return param.release();
4620 QWidget *QgsProcessingProviderConnectionWidgetWrapper::createWidget()
4626 mProviderComboBox->setAllowEmptyConnection(
true );
4634 mProviderComboBox->setEditable(
true );
4638 mProviderComboBox->setToolTip( parameterDefinition()->toolTip() );
4639 connect( mProviderComboBox, &QgsProviderConnectionComboBox::currentTextChanged,
this, [ = ](
const QString & )
4641 if ( mBlockSignals )
4644 emit widgetValueHasChanged(
this );
4647 return mProviderComboBox;
4652 return new QgsProcessingProviderConnectionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4655 void QgsProcessingProviderConnectionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4659 if ( !value.isValid() )
4660 mProviderComboBox->setCurrentIndex( -1 );
4663 if ( mProviderComboBox->isEditable() )
4665 const QString prev = mProviderComboBox->currentText();
4667 mProviderComboBox->setConnection( v );
4668 mProviderComboBox->setCurrentText( v );
4672 emit widgetValueHasChanged(
this );
4675 mProviderComboBox->setConnection( v );
4679 QVariant QgsProcessingProviderConnectionWidgetWrapper::widgetValue()
const
4681 if ( mProviderComboBox )
4682 if ( mProviderComboBox->isEditable() )
4683 return mProviderComboBox->currentText().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentText() );
4685 return mProviderComboBox->currentConnection().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentConnection() );
4690 QStringList QgsProcessingProviderConnectionWidgetWrapper::compatibleParameterTypes()
const
4692 return QStringList()
4698 QStringList QgsProcessingProviderConnectionWidgetWrapper::compatibleOutputTypes()
const
4700 return QStringList()
4704 QString QgsProcessingProviderConnectionWidgetWrapper::modelerExpressionFormatString()
const
4706 return tr(
"connection name as a string value" );
4709 QString QgsProcessingProviderConnectionWidgetWrapper::parameterType()
const
4716 return new QgsProcessingProviderConnectionWidgetWrapper( parameter, type );
4731 QVBoxLayout *vlayout =
new QVBoxLayout();
4732 vlayout->setContentsMargins( 0, 0, 0, 0 );
4734 mConnectionParamComboBox =
new QComboBox();
4735 QString initialConnection;
4744 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4745 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4747 if ( definition && it->parameterName() == definition->
name() )
4753 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
4754 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
4756 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
4761 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
4764 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
4765 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
4768 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
4769 vlayout->addWidget( mConnectionParamComboBox );
4771 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4773 mDefaultEdit =
new QLineEdit();
4774 vlayout->addWidget( mDefaultEdit );
4775 setLayout( vlayout );
4779 mDefaultEdit->setText( schemaParam->
defaultValue().toString() );
4783 QgsProcessingParameterDefinition *QgsProcessingDatabaseSchemaParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4785 QVariant defaultVal;
4786 if ( mDefaultEdit->text().isEmpty() )
4787 defaultVal = QVariant();
4789 defaultVal = mDefaultEdit->text();
4790 auto param = qgis::make_unique< QgsProcessingParameterDatabaseSchema>( name, description, mConnectionParamComboBox->currentData().toString(), defaultVal );
4792 return param.release();
4802 QWidget *QgsProcessingDatabaseSchemaWidgetWrapper::createWidget()
4808 mSchemaComboBox->setAllowEmptySchema(
true );
4816 mSchemaComboBox->comboBox()->setEditable(
true );
4820 mSchemaComboBox->setToolTip( parameterDefinition()->toolTip() );
4821 connect( mSchemaComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
4823 if ( mBlockSignals )
4826 emit widgetValueHasChanged( this );
4829 return mSchemaComboBox;
4834 return new QgsProcessingDatabaseSchemaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4841 std::unique_ptr< QgsProcessingContext > tmpContext;
4842 if ( mProcessingContextGenerator )
4843 context = mProcessingContextGenerator->processingContext();
4847 tmpContext = qgis::make_unique< QgsProcessingContext >();
4848 context = tmpContext.get();
4854 if ( mSchemaComboBox )
4859 setWidgetValue( parameterDefinition()->defaultValue(), *context );
4862 void QgsProcessingDatabaseSchemaWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4866 if ( !value.isValid() )
4867 mSchemaComboBox->comboBox()->setCurrentIndex( -1 );
4870 if ( mSchemaComboBox->comboBox()->isEditable() )
4872 const QString prev = mSchemaComboBox->comboBox()->currentText();
4874 mSchemaComboBox->setSchema( v );
4875 mSchemaComboBox->comboBox()->setCurrentText( v );
4879 emit widgetValueHasChanged(
this );
4882 mSchemaComboBox->setSchema( v );
4886 QVariant QgsProcessingDatabaseSchemaWidgetWrapper::widgetValue()
const
4888 if ( mSchemaComboBox )
4889 if ( mSchemaComboBox->comboBox()->isEditable() )
4890 return mSchemaComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->comboBox()->currentText() );
4892 return mSchemaComboBox->currentSchema().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->currentSchema() );
4897 QStringList QgsProcessingDatabaseSchemaWidgetWrapper::compatibleParameterTypes()
const
4899 return QStringList()
4905 QStringList QgsProcessingDatabaseSchemaWidgetWrapper::compatibleOutputTypes()
const
4907 return QStringList()
4911 QString QgsProcessingDatabaseSchemaWidgetWrapper::modelerExpressionFormatString()
const
4913 return tr(
"database schema name as a string value" );
4916 QString QgsProcessingDatabaseSchemaWidgetWrapper::parameterType()
const
4923 return new QgsProcessingDatabaseSchemaWidgetWrapper( parameter, type );
4926 void QgsProcessingDatabaseSchemaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
4938 setParentConnectionWrapperValue( wrapper );
4941 setParentConnectionWrapperValue( wrapper );
4965 QVBoxLayout *vlayout =
new QVBoxLayout();
4966 vlayout->setContentsMargins( 0, 0, 0, 0 );
4968 mConnectionParamComboBox =
new QComboBox();
4969 mSchemaParamComboBox =
new QComboBox();
4970 QString initialConnection;
4971 QString initialSchema;
4981 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4982 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4984 if ( definition && it->parameterName() == definition->
name() )
4989 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
4990 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
4992 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
4997 mSchemaParamComboBox->addItem( it->parameterName(), it->parameterName() );
4998 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5000 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
5006 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
5009 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
5010 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5013 if ( mSchemaParamComboBox->count() == 0 && !initialSchema.isEmpty() )
5016 mSchemaParamComboBox->addItem( initialSchema, initialSchema );
5017 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
5020 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
5021 vlayout->addWidget( mConnectionParamComboBox );
5023 vlayout->addWidget(
new QLabel( tr(
"Database schema parameter" ) ) );
5024 vlayout->addWidget( mSchemaParamComboBox );
5026 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5028 mDefaultEdit =
new QLineEdit();
5029 vlayout->addWidget( mDefaultEdit );
5030 setLayout( vlayout );
5034 mDefaultEdit->setText( tableParam->
defaultValue().toString() );
5038 QgsProcessingParameterDefinition *QgsProcessingDatabaseTableParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5040 QVariant defaultVal;
5041 if ( mDefaultEdit->text().isEmpty() )
5042 defaultVal = QVariant();
5044 defaultVal = mDefaultEdit->text();
5045 auto param = qgis::make_unique< QgsProcessingParameterDatabaseTable>( name, description,
5046 mConnectionParamComboBox->currentData().toString(),
5047 mSchemaParamComboBox->currentData().toString(),
5050 return param.release();
5060 QWidget *QgsProcessingDatabaseTableWidgetWrapper::createWidget()
5066 mTableComboBox->setAllowEmptyTable(
true );
5069 mTableComboBox->comboBox()->setEditable(
true );
5071 mTableComboBox->setToolTip( parameterDefinition()->toolTip() );
5072 connect( mTableComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
5074 if ( mBlockSignals )
5077 emit widgetValueHasChanged( this );
5080 return mTableComboBox;
5085 return new QgsProcessingDatabaseTableParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5092 std::unique_ptr< QgsProcessingContext > tmpContext;
5093 if ( mProcessingContextGenerator )
5094 context = mProcessingContextGenerator->processingContext();
5098 tmpContext = qgis::make_unique< QgsProcessingContext >();
5099 context = tmpContext.get();
5105 if ( mTableComboBox && !mSchema.isEmpty() )
5107 mTableComboBox->setSchema( mSchema );
5108 mTableComboBox->setConnectionName( mConnection, mProvider );
5112 setWidgetValue( parameterDefinition()->defaultValue(), *context );
5120 std::unique_ptr< QgsProcessingContext > tmpContext;
5121 if ( mProcessingContextGenerator )
5122 context = mProcessingContextGenerator->processingContext();
5126 tmpContext = qgis::make_unique< QgsProcessingContext >();
5127 context = tmpContext.get();
5133 if ( mTableComboBox && !mSchema.isEmpty() && !mConnection.isEmpty() )
5135 mTableComboBox->setSchema( mSchema );
5136 mTableComboBox->setConnectionName( mConnection, mProvider );
5140 setWidgetValue( parameterDefinition()->defaultValue(), *context );
5145 void QgsProcessingDatabaseTableWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5149 if ( !value.isValid() )
5150 mTableComboBox->comboBox()->setCurrentIndex( -1 );
5153 if ( mTableComboBox->comboBox()->isEditable() )
5155 const QString prev = mTableComboBox->comboBox()->currentText();
5157 mTableComboBox->setTable( v );
5158 mTableComboBox->comboBox()->setCurrentText( v );
5162 emit widgetValueHasChanged(
this );
5165 mTableComboBox->setTable( v );
5169 QVariant QgsProcessingDatabaseTableWidgetWrapper::widgetValue()
const
5171 if ( mTableComboBox )
5172 if ( mTableComboBox->comboBox()->isEditable() )
5173 return mTableComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mTableComboBox->comboBox()->currentText() );
5175 return mTableComboBox->currentTable().isEmpty() ? QVariant() : QVariant( mTableComboBox->currentTable() );
5180 QStringList QgsProcessingDatabaseTableWidgetWrapper::compatibleParameterTypes()
const
5182 return QStringList()
5188 QStringList QgsProcessingDatabaseTableWidgetWrapper::compatibleOutputTypes()
const
5190 return QStringList()
5194 QString QgsProcessingDatabaseTableWidgetWrapper::modelerExpressionFormatString()
const
5196 return tr(
"database table name as a string value" );
5199 QString QgsProcessingDatabaseTableWidgetWrapper::parameterType()
const
5206 return new QgsProcessingDatabaseTableWidgetWrapper( parameter, type );
5209 void QgsProcessingDatabaseTableWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5221 setParentConnectionWrapperValue( wrapper );
5224 setParentConnectionWrapperValue( wrapper );
5229 setParentSchemaWrapperValue( wrapper );
5232 setParentSchemaWrapperValue( wrapper );
5252 QVBoxLayout *vlayout =
new QVBoxLayout();
5253 vlayout->setContentsMargins( 0, 0, 0, 0 );
5255 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5258 mDefaultWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
5261 if ( extentParam->defaultValue().isValid() )
5265 mDefaultWidget->setCurrentExtent( rect,
crs );
5266 mDefaultWidget->setOutputExtentFromCurrent();
5270 mDefaultWidget->clear();
5274 vlayout->addWidget( mDefaultWidget );
5275 setLayout( vlayout );
5278 QgsProcessingParameterDefinition *QgsProcessingExtentParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5280 const QString defaultVal = mDefaultWidget->isValid() ? QStringLiteral(
"%1,%2,%3,%4%5" ).arg(
5281 QString::number( mDefaultWidget->outputExtent().xMinimum(),
'f', 9 ),
5282 QString::number( mDefaultWidget->outputExtent().xMaximum(),
'f', 9 ),
5283 QString::number( mDefaultWidget->outputExtent().yMinimum(),
'f', 9 ),
5284 QString::number( mDefaultWidget->outputExtent().yMaximum(),
'f', 9 ),
5285 mDefaultWidget->outputCrs().isValid() ? QStringLiteral(
" [%1]" ).arg( mDefaultWidget->outputCrs().authid() ) : QString()
5287 auto param = qgis::make_unique< QgsProcessingParameterExtent >( name, description, !defaultVal.isEmpty() ? QVariant( defaultVal ) : QVariant() );
5289 return param.release();
5300 QWidget *QgsProcessingExtentWidgetWrapper::createWidget()
5310 if ( widgetContext().mapCanvas() )
5311 mExtentWidget->setMapCanvas( widgetContext().mapCanvas() );
5314 mExtentWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
5316 mExtentWidget->setToolTip( parameterDefinition()->toolTip() );
5320 emit widgetValueHasChanged(
this );
5324 setDialog( mDialog );
5326 return mExtentWidget;
5336 mExtentWidget->setMapCanvas( context.
mapCanvas() );
5339 void QgsProcessingExtentWidgetWrapper::setDialog( QDialog *dialog )
5347 mDialog->showMinimized();
5350 mDialog->showNormal();
5352 mDialog->activateWindow();
5359 void QgsProcessingExtentWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5361 if ( mExtentWidget )
5363 if ( !value.isValid() || ( value.type() == QVariant::String && value.toString().isEmpty() ) )
5364 mExtentWidget->clear();
5369 mExtentWidget->setCurrentExtent( r,
crs );
5370 mExtentWidget->setOutputExtentFromUser( r,
crs );
5375 QVariant QgsProcessingExtentWidgetWrapper::widgetValue()
const
5377 if ( mExtentWidget )
5379 const QString val = mExtentWidget->isValid() ? QStringLiteral(
"%1,%2,%3,%4%5" ).arg(
5380 QString::number( mExtentWidget->outputExtent().xMinimum(),
'f', 9 ),
5381 QString::number( mExtentWidget->outputExtent().xMaximum(),
'f', 9 ),
5382 QString::number( mExtentWidget->outputExtent().yMinimum(),
'f', 9 ),
5383 QString::number( mExtentWidget->outputExtent().yMaximum(),
'f', 9 ),
5384 mExtentWidget->outputCrs().isValid() ? QStringLiteral(
" [%1]" ).arg( mExtentWidget->outputCrs().authid() ) : QString()
5387 return val.isEmpty() ? QVariant() : QVariant( val );
5393 QStringList QgsProcessingExtentWidgetWrapper::compatibleParameterTypes()
const
5395 return QStringList()
5406 QStringList QgsProcessingExtentWidgetWrapper::compatibleOutputTypes()
const
5408 return QStringList()
5415 QString QgsProcessingExtentWidgetWrapper::modelerExpressionFormatString()
const
5417 return tr(
"string of the format 'x min,x max,y min,y max' or a geometry value (bounding box is used)" );
5420 QString QgsProcessingExtentWidgetWrapper::parameterType()
const
5427 return new QgsProcessingExtentWidgetWrapper( parameter, type );
5432 return new QgsProcessingExtentParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5444 QVBoxLayout *vlayout =
new QVBoxLayout();
5445 vlayout->setContentsMargins( 0, 0, 0, 0 );
5447 vlayout->addWidget(
new QLabel( tr(
"Layer type" ) ) );
5459 for (
int i : layerParam->dataTypes() )
5461 mLayerTypeComboBox->setItemCheckState( mLayerTypeComboBox->findData( i ), Qt::Checked );
5465 vlayout->addWidget( mLayerTypeComboBox );
5467 setLayout( vlayout );
5470 QgsProcessingParameterDefinition *QgsProcessingMapLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5472 QList< int > dataTypes;
5473 for (
const QVariant &v : mLayerTypeComboBox->checkedItemsData() )
5474 dataTypes << v.toInt();
5476 auto param = qgis::make_unique< QgsProcessingParameterMapLayer >( name, description );
5477 param->setDataTypes( dataTypes );
5479 return param.release();
5488 QWidget *QgsProcessingMapLayerWidgetWrapper::createWidget()
5490 mComboBox =
new QgsProcessingMapLayerComboBox( parameterDefinition(), type() );
5498 mComboBox->setEditable(
true );
5502 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5504 connect( mComboBox, &QgsProcessingMapLayerComboBox::valueChanged,
this, [ = ]()
5506 if ( mBlockSignals )
5509 emit widgetValueHasChanged(
this );
5512 setWidgetContext( widgetContext() );
5521 mComboBox->setWidgetContext( context );
5526 if ( !parameterDefinition()->defaultValue().isValid() )
5532 void QgsProcessingMapLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5535 mComboBox->setValue( value, context );
5538 QVariant QgsProcessingMapLayerWidgetWrapper::widgetValue()
const
5540 return mComboBox ? mComboBox->value() : QVariant();
5543 QStringList QgsProcessingMapLayerWidgetWrapper::compatibleParameterTypes()
const
5545 return QStringList()
5554 QStringList QgsProcessingMapLayerWidgetWrapper::compatibleOutputTypes()
const
5556 return QStringList()
5564 QString QgsProcessingMapLayerWidgetWrapper::modelerExpressionFormatString()
const
5566 return tr(
"path to a map layer" );
5569 QString QgsProcessingMapLayerWidgetWrapper::parameterType()
const
5576 return new QgsProcessingMapLayerWidgetWrapper( parameter, type );
5581 return new QgsProcessingMapLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5590 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
5595 QStringList QgsProcessingRasterLayerWidgetWrapper::compatibleParameterTypes()
const
5597 return QStringList()
5604 QStringList QgsProcessingRasterLayerWidgetWrapper::compatibleOutputTypes()
const
5606 return QStringList()
5614 QString QgsProcessingRasterLayerWidgetWrapper::modelerExpressionFormatString()
const
5616 return tr(
"path to a raster layer" );
5619 QString QgsProcessingRasterLayerWidgetWrapper::parameterType()
const
5626 return new QgsProcessingRasterLayerWidgetWrapper( parameter, type );
5631 Q_UNUSED( context );
5632 Q_UNUSED( widgetContext );
5633 Q_UNUSED( definition );
5647 QVBoxLayout *vlayout =
new QVBoxLayout();
5648 vlayout->setContentsMargins( 0, 0, 0, 0 );
5650 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
5660 for (
int i : vectorParam->dataTypes() )
5662 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
5666 vlayout->addWidget( mGeometryTypeComboBox );
5668 setLayout( vlayout );
5671 QgsProcessingParameterDefinition *QgsProcessingVectorLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5673 QList< int > dataTypes;
5674 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
5675 dataTypes << v.toInt();
5677 auto param = qgis::make_unique< QgsProcessingParameterVectorLayer >( name, description, dataTypes );
5679 return param.release();
5684 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
5689 QStringList QgsProcessingVectorLayerWidgetWrapper::compatibleParameterTypes()
const
5691 return QStringList()
5698 QStringList QgsProcessingVectorLayerWidgetWrapper::compatibleOutputTypes()
const
5700 return QStringList()
5708 QString QgsProcessingVectorLayerWidgetWrapper::modelerExpressionFormatString()
const
5710 return tr(
"path to a vector layer" );
5716 return param->dataTypes();
5718 return QList< int >();
5721 QString QgsProcessingVectorLayerWidgetWrapper::parameterType()
const
5728 return new QgsProcessingVectorLayerWidgetWrapper( parameter, type );
5733 return new QgsProcessingVectorLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5745 QVBoxLayout *vlayout =
new QVBoxLayout();
5746 vlayout->setContentsMargins( 0, 0, 0, 0 );
5748 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
5758 for (
int i : sourceParam->dataTypes() )
5760 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
5768 vlayout->addWidget( mGeometryTypeComboBox );
5770 setLayout( vlayout );
5773 QgsProcessingParameterDefinition *QgsProcessingFeatureSourceParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5775 QList< int > dataTypes;
5776 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
5777 dataTypes << v.toInt();
5779 auto param = qgis::make_unique< QgsProcessingParameterFeatureSource >( name, description, dataTypes );
5781 return param.release();
5785 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
5790 QStringList QgsProcessingFeatureSourceWidgetWrapper::compatibleParameterTypes()
const
5792 return QStringList()
5800 QStringList QgsProcessingFeatureSourceWidgetWrapper::compatibleOutputTypes()
const
5802 return QStringList()
5810 QString QgsProcessingFeatureSourceWidgetWrapper::modelerExpressionFormatString()
const
5812 return tr(
"path to a vector layer" );
5818 return param->dataTypes();
5820 return QList< int >();
5823 QString QgsProcessingFeatureSourceWidgetWrapper::parameterType()
const
5830 return new QgsProcessingFeatureSourceWidgetWrapper( parameter, type );
5835 return new QgsProcessingFeatureSourceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5843 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
5848 QStringList QgsProcessingMeshLayerWidgetWrapper::compatibleParameterTypes()
const
5850 return QStringList()
5857 QStringList QgsProcessingMeshLayerWidgetWrapper::compatibleOutputTypes()
const
5859 return QStringList()
5867 QString QgsProcessingMeshLayerWidgetWrapper::modelerExpressionFormatString()
const
5869 return tr(
"path to a mesh layer" );
5872 QString QgsProcessingMeshLayerWidgetWrapper::parameterType()
const
5879 return new QgsProcessingMeshLayerWidgetWrapper( parameter, type );
5884 Q_UNUSED( context );
5885 Q_UNUSED( widgetContext );
5886 Q_UNUSED( definition );
5898 QgsProcessingRasterBandPanelWidget::QgsProcessingRasterBandPanelWidget( QWidget *parent,
const QgsProcessingParameterBand *param )
5902 QHBoxLayout *hl =
new QHBoxLayout();
5903 hl->setContentsMargins( 0, 0, 0, 0 );
5905 mLineEdit =
new QLineEdit();
5906 mLineEdit->setEnabled(
false );
5907 hl->addWidget( mLineEdit, 1 );
5909 mToolButton =
new QToolButton();
5910 mToolButton->setText( QString( QChar( 0x2026 ) ) );
5911 hl->addWidget( mToolButton );
5917 mLineEdit->setText( tr(
"%1 bands selected" ).arg( 0 ) );
5920 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingRasterBandPanelWidget::showDialog );
5923 void QgsProcessingRasterBandPanelWidget::setBands(
const QList< int > &bands )
5928 void QgsProcessingRasterBandPanelWidget::setBandNames(
const QHash<int, QString> &names )
5933 void QgsProcessingRasterBandPanelWidget::setValue(
const QVariant &value )
5935 if ( value.isValid() )
5936 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
5940 updateSummaryText();
5944 void QgsProcessingRasterBandPanelWidget::showDialog()
5946 QVariantList availableOptions;
5947 QStringList fieldNames;
5948 availableOptions.reserve( mBands.size() );
5949 for (
int band : qgis::as_const( mBands ) )
5951 availableOptions << band;
5957 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
5958 widget->setPanelTitle( mParam->description() );
5960 widget->setValueFormatter( [
this](
const QVariant & v ) -> QString
5962 int band = v.toInt();
5963 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
5966 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
5968 setValue( widget->selectedOptions() );
5975 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
5977 dlg.setValueFormatter( [
this](
const QVariant & v ) -> QString
5979 int band = v.toInt();
5980 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
5984 setValue( dlg.selectedOptions() );
5989 void QgsProcessingRasterBandPanelWidget::updateSummaryText()
5992 mLineEdit->setText( tr(
"%1 bands selected" ).arg( mValue.count() ) );
6004 QVBoxLayout *vlayout =
new QVBoxLayout();
6005 vlayout->setContentsMargins( 0, 0, 0, 0 );
6007 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6009 mDefaultLineEdit =
new QLineEdit();
6010 mDefaultLineEdit->setToolTip( tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6015 for (
int b : bands )
6017 defVal << QString::number( b );
6020 mDefaultLineEdit->setText( defVal.join(
';' ) );
6022 vlayout->addWidget( mDefaultLineEdit );
6024 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
6025 mParentLayerComboBox =
new QComboBox();
6027 QString initialParent;
6029 initialParent = bandParam->parentLayerParameterName();
6034 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6035 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6039 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
6040 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
6042 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6048 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
6051 mParentLayerComboBox->addItem( initialParent, initialParent );
6052 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6055 vlayout->addWidget( mParentLayerComboBox );
6057 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Allow multiple" ) );
6059 mAllowMultipleCheckBox->setChecked( bandParam->allowMultiple() );
6061 vlayout->addWidget( mAllowMultipleCheckBox );
6062 setLayout( vlayout );
6065 QgsProcessingParameterDefinition *QgsProcessingBandParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6067 auto param = qgis::make_unique< QgsProcessingParameterBand >( name, description, mDefaultLineEdit->text().split(
';' ), mParentLayerComboBox->currentData().toString(),
false, mAllowMultipleCheckBox->isChecked() );
6069 return param.release();
6078 QWidget *QgsProcessingBandWidgetWrapper::createWidget()
6088 mPanel =
new QgsProcessingRasterBandPanelWidget(
nullptr, bandParam );
6089 mPanel->setToolTip( parameterDefinition()->toolTip() );
6090 connect( mPanel, &QgsProcessingRasterBandPanelWidget::changed,
this, [ = ]
6092 emit widgetValueHasChanged(
this );
6101 mComboBox->setToolTip( parameterDefinition()->toolTip() );
6104 emit widgetValueHasChanged(
this );
6112 mLineEdit =
new QLineEdit();
6113 mLineEdit->setToolTip( QObject::tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6114 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
6116 emit widgetValueHasChanged(
this );
6125 void QgsProcessingBandWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6135 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterBand *
>( parameterDefinition() )->parentLayerParameterName() )
6137 setParentLayerWrapperValue( wrapper );
6140 setParentLayerWrapperValue( wrapper );
6157 std::unique_ptr< QgsProcessingContext > tmpContext;
6158 if ( mProcessingContextGenerator )
6159 context = mProcessingContextGenerator->processingContext();
6163 tmpContext = qgis::make_unique< QgsProcessingContext >();
6164 context = tmpContext.get();
6170 if ( layer && layer->
isValid() )
6174 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
6177 mParentLayer.reset( qobject_cast< QgsRasterLayer * >( ownedLayer.release() ) );
6178 layer = mParentLayer.get();
6186 mComboBox->setLayer( layer );
6190 if ( provider && layer->
isValid() )
6195 QHash< int, QString > bandNames;
6196 for (
int i = 1; i <= nBands; ++i )
6201 mPanel->setBands( bands );
6202 mPanel->setBandNames( bandNames );
6209 mComboBox->setLayer(
nullptr );
6211 mPanel->setBands( QList< int >() );
6213 if ( value.isValid() && widgetContext().messageBar() )
6216 widgetContext().
messageBar()->
pushMessage( QString(), QObject::tr(
"Could not load selected layer/table. Dependent bands could not be populated" ),
6221 if ( parameterDefinition()->defaultValue().isValid() )
6222 setWidgetValue( parameterDefinition()->defaultValue(), *context );
6225 void QgsProcessingBandWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6229 if ( !value.isValid() )
6230 mComboBox->setBand( -1 );
6234 mComboBox->setBand( v );
6240 if ( value.isValid() )
6243 opts.reserve( v.size() );
6248 mPanel->setValue( value.isValid() ? opts : QVariant() );
6250 else if ( mLineEdit )
6257 opts.reserve( v.size() );
6259 opts << QString::number( i );
6260 mLineEdit->setText( value.isValid() && !opts.empty() ? opts.join(
';' ) : QString() );
6264 if ( value.isValid() )
6272 QVariant QgsProcessingBandWidgetWrapper::widgetValue()
const
6275 return mComboBox->currentBand() == -1 ? QVariant() : mComboBox->currentBand();
6277 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
6278 else if ( mLineEdit )
6283 const QStringList parts = mLineEdit->text().split(
';', QString::SkipEmptyParts );
6285 res.reserve( parts.count() );
6286 for (
const QString &s : parts )
6289 int band = s.toInt( &ok );
6293 return res.
isEmpty() ? QVariant() : res;
6297 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
6304 QStringList QgsProcessingBandWidgetWrapper::compatibleParameterTypes()
const
6306 return QStringList()
6311 QStringList QgsProcessingBandWidgetWrapper::compatibleOutputTypes()
const
6313 return QStringList()
6317 QString QgsProcessingBandWidgetWrapper::modelerExpressionFormatString()
const
6319 return tr(
"selected band numbers as an array of numbers, or semicolon separated string of options (e.g. '1;3')" );
6322 QString QgsProcessingBandWidgetWrapper::parameterType()
const
6329 return new QgsProcessingBandWidgetWrapper( parameter, type );
6334 return new QgsProcessingBandParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6347 QHBoxLayout *hl =
new QHBoxLayout();
6348 hl->setContentsMargins( 0, 0, 0, 0 );
6350 mLineEdit =
new QLineEdit();
6351 mLineEdit->setEnabled(
false );
6352 hl->addWidget( mLineEdit, 1 );
6354 mToolButton =
new QToolButton();
6355 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6356 hl->addWidget( mToolButton );
6362 mLineEdit->setText( tr(
"%1 inputs selected" ).arg( 0 ) );
6365 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingMultipleLayerPanelWidget::showDialog );
6368 void QgsProcessingMultipleLayerPanelWidget::setValue(
const QVariant &value )
6370 if ( value.isValid() )
6371 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
6375 updateSummaryText();
6379 void QgsProcessingMultipleLayerPanelWidget::setProject(
QgsProject *project )
6384 void QgsProcessingMultipleLayerPanelWidget::setModel( QgsProcessingModelAlgorithm *model,
const QString &modelChildAlgorithmID )
6390 switch ( mParam->layerType() )
6508 void QgsProcessingMultipleLayerPanelWidget::showDialog()
6513 QgsProcessingMultipleInputPanelWidget *widget =
new QgsProcessingMultipleInputPanelWidget( mParam, mValue, mModelSources, mModel );
6514 widget->setPanelTitle( mParam->description() );
6515 widget->setProject( mProject );
6516 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
6518 setValue( widget->selectedOptions() );
6525 QgsProcessingMultipleInputDialog dlg( mParam, mValue, mModelSources, mModel,
this, Qt::WindowFlags() );
6526 dlg.setProject( mProject );
6529 setValue( dlg.selectedOptions() );
6534 void QgsProcessingMultipleLayerPanelWidget::updateSummaryText()
6537 mLineEdit->setText( tr(
"%1 inputs selected" ).arg( mValue.count() ) );
6547 QVBoxLayout *vlayout =
new QVBoxLayout();
6548 vlayout->setContentsMargins( 0, 0, 0, 0 );
6550 vlayout->addWidget(
new QLabel( tr(
"Allowed layer type" ) ) );
6551 mLayerTypeComboBox =
new QComboBox();
6562 mLayerTypeComboBox->setCurrentIndex( mLayerTypeComboBox->findData( layersParam->layerType() ) );
6564 vlayout->addWidget( mLayerTypeComboBox );
6565 setLayout( vlayout );
6568 QgsProcessingParameterDefinition *QgsProcessingMultipleLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6570 auto param = qgis::make_unique< QgsProcessingParameterMultipleLayers >( name, description,
static_cast< QgsProcessing::SourceType >( mLayerTypeComboBox->currentData().toInt() ) );
6572 return param.release();
6581 QWidget *QgsProcessingMultipleLayerWidgetWrapper::createWidget()
6585 mPanel =
new QgsProcessingMultipleLayerPanelWidget(
nullptr, layerParam );
6586 mPanel->setToolTip( parameterDefinition()->toolTip() );
6587 mPanel->setProject( widgetContext().project() );
6588 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
6589 connect( mPanel, &QgsProcessingMultipleLayerPanelWidget::changed,
this, [ = ]
6591 emit widgetValueHasChanged(
this );
6601 mPanel->setProject( context.
project() );
6602 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
6606 void QgsProcessingMultipleLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6611 if ( value.isValid() )
6614 opts.reserve( v.size() );
6616 opts << l->source();
6619 for (
const QVariant &v : value.toList() )
6621 if ( v.canConvert< QgsProcessingModelChildParameterSource >() )
6623 const QgsProcessingModelChildParameterSource source = v.value< QgsProcessingModelChildParameterSource >();
6624 opts << QVariant::fromValue( source );
6629 mPanel->setValue( value.isValid() ? opts : QVariant() );
6633 QVariant QgsProcessingMultipleLayerWidgetWrapper::widgetValue()
const
6636 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
6641 QStringList QgsProcessingMultipleLayerWidgetWrapper::compatibleParameterTypes()
const
6643 return QStringList()
6654 QStringList QgsProcessingMultipleLayerWidgetWrapper::compatibleOutputTypes()
const
6656 return QStringList()
6665 QString QgsProcessingMultipleLayerWidgetWrapper::modelerExpressionFormatString()
const
6667 return tr(
"an array of layer paths, or semicolon separated string of layer paths" );
6670 QString QgsProcessingMultipleLayerWidgetWrapper::parameterType()
const
6677 return new QgsProcessingMultipleLayerWidgetWrapper( parameter, type );
6682 return new QgsProcessingMultipleLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6696 QWidget *QgsProcessingOutputWidgetWrapper::createWidget()
6704 mOutputWidget =
new QgsProcessingLayerOutputDestinationWidget( destParam,
false );
6705 if ( mProcessingContextGenerator )
6706 mOutputWidget->setContext( mProcessingContextGenerator->processingContext() );
6707 if ( mParametersGenerator )
6708 mOutputWidget->registerProcessingParametersGenerator( mParametersGenerator );
6709 mOutputWidget->setToolTip( parameterDefinition()->toolTip() );
6711 connect( mOutputWidget, &QgsProcessingLayerOutputDestinationWidget::destinationChanged,
this, [ = ]()
6713 if ( mBlockSignals )
6716 emit widgetValueHasChanged(
this );
6723 mOutputWidget->addOpenAfterRunningOption();
6725 return mOutputWidget;
6735 void QgsProcessingOutputWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
6737 if ( mOutputWidget )
6738 mOutputWidget->setValue( value );
6741 QVariant QgsProcessingOutputWidgetWrapper::widgetValue()
const
6743 if ( mOutputWidget )
6744 return mOutputWidget->value();
6749 QVariantMap QgsProcessingOutputWidgetWrapper::customProperties()
const
6752 if ( mOutputWidget )
6753 res.insert( QStringLiteral(
"OPEN_AFTER_RUNNING" ), mOutputWidget->openAfterRunning() );
6757 QStringList QgsProcessingOutputWidgetWrapper::compatibleParameterTypes()
const
6759 return QStringList()
6768 QStringList QgsProcessingOutputWidgetWrapper::compatibleOutputTypes()
const
6770 return QStringList()
6781 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
6786 QString QgsProcessingFeatureSinkWidgetWrapper::parameterType()
const
6793 return new QgsProcessingFeatureSinkWidgetWrapper( parameter, type );
6796 QString QgsProcessingFeatureSinkWidgetWrapper::modelerExpressionFormatString()
const
6798 return tr(
"path to layer destination" );
6806 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
6811 QString QgsProcessingVectorDestinationWidgetWrapper::parameterType()
const
6818 return new QgsProcessingVectorDestinationWidgetWrapper( parameter, type );
6821 QString QgsProcessingVectorDestinationWidgetWrapper::modelerExpressionFormatString()
const
6823 return tr(
"path to layer destination" );
6831 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
6836 QString QgsProcessingRasterDestinationWidgetWrapper::parameterType()
const
6843 return new QgsProcessingRasterDestinationWidgetWrapper( parameter, type );
6846 QString QgsProcessingRasterDestinationWidgetWrapper::modelerExpressionFormatString()
const
6848 return tr(
"path to layer destination" );
6856 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
6861 QString QgsProcessingFileDestinationWidgetWrapper::parameterType()
const
6868 return new QgsProcessingFileDestinationWidgetWrapper( parameter, type );
6871 QString QgsProcessingFileDestinationWidgetWrapper::modelerExpressionFormatString()
const
6873 return tr(
"path to file destination" );
6881 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
6886 QString QgsProcessingFolderDestinationWidgetWrapper::parameterType()
const
6893 return new QgsProcessingFolderDestinationWidgetWrapper( parameter, type );
6896 QString QgsProcessingFolderDestinationWidgetWrapper::modelerExpressionFormatString()
const
6898 return tr(
"path to folder destination" );