74#include <QPlainTextEdit>
75#include <QRadioButton>
76#include <QButtonGroup>
90 QVBoxLayout *vlayout =
new QVBoxLayout();
91 vlayout->setContentsMargins( 0, 0, 0, 0 );
93 mDefaultCheckBox =
new QCheckBox( tr(
"Checked" ) );
97 mDefaultCheckBox->setChecked(
false );
98 vlayout->addWidget( mDefaultCheckBox );
102QgsProcessingParameterDefinition *QgsProcessingBooleanParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
104 auto param = std::make_unique< QgsProcessingParameterBoolean >( name, description, mDefaultCheckBox->isChecked() );
105 param->setFlags( flags );
106 return param.release();
116QWidget *QgsProcessingBooleanWidgetWrapper::createWidget()
122 QString description = parameterDefinition()->description();
124 description = QObject::tr(
"%1 [optional]" ).arg( description );
126 mCheckBox =
new QCheckBox( description );
127 mCheckBox->setToolTip( parameterDefinition()->toolTip() );
129 connect( mCheckBox, &QCheckBox::toggled,
this, [ = ]
131 emit widgetValueHasChanged(
this );
139 mComboBox =
new QComboBox();
140 mComboBox->addItem( tr(
"Yes" ),
true );
141 mComboBox->addItem( tr(
"No" ),
false );
142 mComboBox->setToolTip( parameterDefinition()->toolTip() );
144 connect( mComboBox, qOverload< int>( &QComboBox::currentIndexChanged ),
this, [ = ]
146 emit widgetValueHasChanged(
this );
155QLabel *QgsProcessingBooleanWidgetWrapper::createLabel()
164void QgsProcessingBooleanWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
171 mCheckBox->setChecked( v );
179 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
185QVariant QgsProcessingBooleanWidgetWrapper::widgetValue()
const
190 return mCheckBox->isChecked();
194 return mComboBox->currentData();
199QStringList QgsProcessingBooleanWidgetWrapper::compatibleParameterTypes()
const
221QStringList QgsProcessingBooleanWidgetWrapper::compatibleOutputTypes()
const
232QString QgsProcessingBooleanWidgetWrapper::parameterType()
const
239 return new QgsProcessingBooleanWidgetWrapper( parameter, type );
244 return new QgsProcessingBooleanParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
255 QVBoxLayout *vlayout =
new QVBoxLayout();
256 vlayout->setContentsMargins( 0, 0, 0, 0 );
258 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
263 mCrsSelector->setShowAccuracyWarnings(
true );
270 vlayout->addWidget( mCrsSelector );
271 setLayout( vlayout );
274QgsProcessingParameterDefinition *QgsProcessingCrsParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
276 auto param = std::make_unique< QgsProcessingParameterCrs >( name, description, mCrsSelector->crs().authid() );
277 param->setFlags( flags );
278 return param.release();
287QWidget *QgsProcessingCrsWidgetWrapper::createWidget()
289 Q_ASSERT( mProjectionSelectionWidget ==
nullptr );
291 mProjectionSelectionWidget->setToolTip( parameterDefinition()->toolTip() );
300 emit widgetValueHasChanged(
this );
308 return mProjectionSelectionWidget;
313 QWidget *w =
new QWidget();
314 w->setToolTip( parameterDefinition()->toolTip() );
316 QVBoxLayout *vl =
new QVBoxLayout();
317 vl->setContentsMargins( 0, 0, 0, 0 );
320 mUseProjectCrsCheckBox =
new QCheckBox( tr(
"Use project CRS" ) );
321 mUseProjectCrsCheckBox->setToolTip( tr(
"Always use the current project CRS when running the model" ) );
322 vl->addWidget( mUseProjectCrsCheckBox );
323 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, mProjectionSelectionWidget, &QgsProjectionSelectionWidget::setDisabled );
324 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled,
this, [ = ]
326 emit widgetValueHasChanged(
this );
329 vl->addWidget( mProjectionSelectionWidget );
337void QgsProcessingCrsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
339 if ( mUseProjectCrsCheckBox )
341 if ( value.toString().compare( QLatin1String(
"ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
343 mUseProjectCrsCheckBox->setChecked(
true );
348 mUseProjectCrsCheckBox->setChecked(
false );
353 if ( mProjectionSelectionWidget )
354 mProjectionSelectionWidget->setCrs( v );
357QVariant QgsProcessingCrsWidgetWrapper::widgetValue()
const
359 if ( mUseProjectCrsCheckBox && mUseProjectCrsCheckBox->isChecked() )
360 return QStringLiteral(
"ProjectCrs" );
361 else if ( mProjectionSelectionWidget )
362 return mProjectionSelectionWidget->crs().isValid() ? mProjectionSelectionWidget->crs() : QVariant();
367QStringList QgsProcessingCrsWidgetWrapper::compatibleParameterTypes()
const
381QStringList QgsProcessingCrsWidgetWrapper::compatibleOutputTypes()
const
389QString QgsProcessingCrsWidgetWrapper::modelerExpressionFormatString()
const
391 return tr(
"string as EPSG code, WKT or PROJ format, or a string identifying a map layer" );
394QString QgsProcessingCrsWidgetWrapper::parameterType()
const
401 return new QgsProcessingCrsWidgetWrapper( parameter, type );
406 return new QgsProcessingCrsParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
419 QVBoxLayout *vlayout =
new QVBoxLayout();
420 vlayout->setContentsMargins( 0, 0, 0, 0 );
422 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
424 mDefaultLineEdit =
new QLineEdit();
427 vlayout->addWidget( mDefaultLineEdit );
429 mMultiLineCheckBox =
new QCheckBox( tr(
"Multiline input" ) );
431 mMultiLineCheckBox->setChecked( stringParam->multiLine() );
432 vlayout->addWidget( mMultiLineCheckBox );
434 setLayout( vlayout );
437QgsProcessingParameterDefinition *QgsProcessingStringParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
439 auto param = std::make_unique< QgsProcessingParameterString >( name, description, mDefaultLineEdit->text(), mMultiLineCheckBox->isChecked() );
440 param->setFlags( flags );
441 return param.release();
452QWidget *QgsProcessingStringWidgetWrapper::createWidget()
454 const QVariantMap metadata = parameterDefinition()->metadata();
455 const QVariant valueHintsVariant = metadata.value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"value_hints" ) );
457 if ( valueHintsVariant.isValid() )
459 const QVariantList valueList = valueHintsVariant.toList();
460 mComboBox =
new QComboBox();
461 mComboBox->setToolTip( parameterDefinition()->toolTip() );
465 mComboBox->addItem( QString() );
467 for (
const QVariant &entry : valueList )
469 mComboBox->addItem( entry.toString(), entry.toString() );
471 mComboBox->setCurrentIndex( 0 );
473 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
475 emit widgetValueHasChanged(
this );
488 mPlainTextEdit =
new QPlainTextEdit();
489 mPlainTextEdit->setToolTip( parameterDefinition()->toolTip() );
491 connect( mPlainTextEdit, &QPlainTextEdit::textChanged,
this, [ = ]
493 emit widgetValueHasChanged(
this );
495 return mPlainTextEdit;
499 mLineEdit =
new QLineEdit();
500 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
502 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
504 emit widgetValueHasChanged(
this );
512 mLineEdit =
new QLineEdit();
513 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
515 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
517 emit widgetValueHasChanged(
this );
527void QgsProcessingStringWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
531 mLineEdit->setText( v );
532 if ( mPlainTextEdit )
533 mPlainTextEdit->setPlainText( v );
537 if ( !value.isValid() )
538 index = mComboBox->findData( QVariant() );
540 index = mComboBox->findData( v );
543 mComboBox->setCurrentIndex( index );
545 mComboBox->setCurrentIndex( 0 );
549QVariant QgsProcessingStringWidgetWrapper::widgetValue()
const
552 return mLineEdit->text();
553 else if ( mPlainTextEdit )
554 return mPlainTextEdit->toPlainText();
555 else if ( mComboBox )
556 return mComboBox->currentData();
561QStringList QgsProcessingStringWidgetWrapper::compatibleParameterTypes()
const
577QStringList QgsProcessingStringWidgetWrapper::compatibleOutputTypes()
const
585QString QgsProcessingStringWidgetWrapper::parameterType()
const
592 return new QgsProcessingStringWidgetWrapper( parameter, type );
597 return new QgsProcessingStringParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
612QWidget *QgsProcessingAuthConfigWidgetWrapper::createWidget()
621 mAuthConfigSelect->setToolTip( parameterDefinition()->toolTip() );
625 emit widgetValueHasChanged(
this );
627 return mAuthConfigSelect;
633void QgsProcessingAuthConfigWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
636 if ( mAuthConfigSelect )
637 mAuthConfigSelect->setConfigId( v );
640QVariant QgsProcessingAuthConfigWidgetWrapper::widgetValue()
const
642 if ( mAuthConfigSelect )
643 return mAuthConfigSelect->configId();
648QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleParameterTypes()
const
656QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleOutputTypes()
const
661QString QgsProcessingAuthConfigWidgetWrapper::parameterType()
const
668 return new QgsProcessingAuthConfigWidgetWrapper( parameter, type );
678 QVBoxLayout *vlayout =
new QVBoxLayout();
679 vlayout->setContentsMargins( 0, 0, 0, 0 );
681 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
683 mTypeComboBox =
new QComboBox();
686 vlayout->addWidget( mTypeComboBox );
688 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
689 mMinLineEdit =
new QLineEdit();
690 vlayout->addWidget( mMinLineEdit );
692 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
693 mMaxLineEdit =
new QLineEdit();
694 vlayout->addWidget( mMaxLineEdit );
696 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
697 mDefaultLineEdit =
new QLineEdit();
698 vlayout->addWidget( mDefaultLineEdit );
702 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( numberParam->dataType() ) );
704 if ( !
qgsDoubleNear( numberParam->maximum(), std::numeric_limits<double>::max() ) )
706 mMaxLineEdit->setText( QLocale().toString( numberParam->maximum() ) );
710 mMaxLineEdit->clear();
713 if ( !
qgsDoubleNear( numberParam->minimum(), std::numeric_limits<double>::lowest() ) )
715 mMinLineEdit->setText( QLocale().toString( numberParam->minimum() ) );
719 mMinLineEdit->clear();
722 mDefaultLineEdit->setText( numberParam->defaultValueForGui().toString() );
725 setLayout( vlayout );
728QgsProcessingParameterDefinition *QgsProcessingNumberParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
734 auto param = std::make_unique< QgsProcessingParameterNumber >( name, description, dataType, ok ? val : QVariant() );
736 if ( !mMinLineEdit->text().trimmed().isEmpty() )
741 param->setMinimum( val );
745 if ( !mMaxLineEdit->text().trimmed().isEmpty() )
750 param->setMaximum( val );
754 param->setFlags( flags );
755 return param.release();
764QWidget *QgsProcessingNumericWidgetWrapper::createWidget()
767 const QVariantMap metadata = numberDef->
metadata();
768 const int decimals = metadata.value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"decimals" ), 6 ).toInt();
776 QAbstractSpinBox *spinBox =
nullptr;
781 mDoubleSpinBox->setExpressionsEnabled(
true );
782 mDoubleSpinBox->setDecimals( decimals );
788 double singleStep = calculateStep( numberDef->
minimum(), numberDef->
maximum() );
789 singleStep = std::max( singleStep, std::pow( 10, -decimals ) );
790 mDoubleSpinBox->setSingleStep( singleStep );
793 spinBox = mDoubleSpinBox;
798 mSpinBox->setExpressionsEnabled(
true );
802 spinBox->setToolTip( parameterDefinition()->toolTip() );
804 double max = 999999999;
809 double min = -999999999;
814 if ( mDoubleSpinBox )
816 mDoubleSpinBox->setMinimum( min );
817 mDoubleSpinBox->setMaximum( max );
821 mSpinBox->setMinimum(
static_cast< int >( min ) );
822 mSpinBox->setMaximum(
static_cast< int >( max ) );
827 mAllowingNull =
true;
828 if ( mDoubleSpinBox )
830 mDoubleSpinBox->setShowClearButton(
true );
831 const double min = mDoubleSpinBox->minimum() - mDoubleSpinBox->singleStep();
832 mDoubleSpinBox->setMinimum( min );
833 mDoubleSpinBox->setValue( min );
837 mSpinBox->setShowClearButton(
true );
838 const int min = mSpinBox->minimum() - 1;
839 mSpinBox->setMinimum( min );
840 mSpinBox->setValue( min );
842 spinBox->setSpecialValueText( tr(
"Not set" ) );
850 if ( mDoubleSpinBox )
854 mDoubleSpinBox->setClearValue( defaultVal );
860 mSpinBox->setClearValue( intVal );
866 if ( mDoubleSpinBox )
867 mDoubleSpinBox->setClearValue( numberDef->
minimum() );
869 mSpinBox->setClearValue(
static_cast< int >( numberDef->
minimum() ) );
874 if ( mDoubleSpinBox )
876 mDoubleSpinBox->setValue( 0 );
877 mDoubleSpinBox->setClearValue( 0 );
881 mSpinBox->setValue( 0 );
882 mSpinBox->setClearValue( 0 );
887 if ( mDoubleSpinBox )
888 connect( mDoubleSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [ = ] { emit widgetValueHasChanged(
this ); } );
890 connect( mSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, [ = ] { emit widgetValueHasChanged(
this ); } );
898void QgsProcessingNumericWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
900 if ( mDoubleSpinBox )
902 if ( mAllowingNull && !value.isValid() )
903 mDoubleSpinBox->clear();
907 mDoubleSpinBox->setValue( v );
912 if ( mAllowingNull && !value.isValid() )
917 mSpinBox->setValue( v );
922QVariant QgsProcessingNumericWidgetWrapper::widgetValue()
const
924 if ( mDoubleSpinBox )
926 if ( mAllowingNull &&
qgsDoubleNear( mDoubleSpinBox->value(), mDoubleSpinBox->minimum() ) )
929 return mDoubleSpinBox->value();
933 if ( mAllowingNull && mSpinBox->value() == mSpinBox->minimum() )
936 return mSpinBox->value();
942QStringList QgsProcessingNumericWidgetWrapper::compatibleParameterTypes()
const
952QStringList QgsProcessingNumericWidgetWrapper::compatibleOutputTypes()
const
958double QgsProcessingNumericWidgetWrapper::calculateStep(
const double minimum,
const double maximum )
960 const double valueRange = maximum - minimum;
961 if ( valueRange <= 1.0 )
963 const double step = valueRange / 10.0;
965 return qgsRound( step, -std::floor( std::log( step ) ) );
973QString QgsProcessingNumericWidgetWrapper::parameterType()
const
980 return new QgsProcessingNumericWidgetWrapper( parameter, type );
985 return new QgsProcessingNumberParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
995 QVBoxLayout *vlayout =
new QVBoxLayout();
996 vlayout->setContentsMargins( 0, 0, 0, 0 );
998 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
1000 mParentLayerComboBox =
new QComboBox();
1002 QString initialParent;
1004 initialParent = distParam->parentParameterName();
1006 if (
auto *lModel = widgetContext.
model() )
1009 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
1010 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
1014 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1015 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1017 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1022 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1023 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1025 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1030 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1031 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1033 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1038 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
1039 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1041 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1047 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
1050 mParentLayerComboBox->addItem( initialParent, initialParent );
1051 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1054 vlayout->addWidget( mParentLayerComboBox );
1056 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1057 mMinLineEdit =
new QLineEdit();
1058 vlayout->addWidget( mMinLineEdit );
1060 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1061 mMaxLineEdit =
new QLineEdit();
1062 vlayout->addWidget( mMaxLineEdit );
1064 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1065 mDefaultLineEdit =
new QLineEdit();
1066 vlayout->addWidget( mDefaultLineEdit );
1070 mMinLineEdit->setText( QLocale().toString( distParam->minimum() ) );
1071 mMaxLineEdit->setText( QLocale().toString( distParam->maximum() ) );
1072 mDefaultLineEdit->setText( distParam->defaultValueForGui().toString() );
1075 setLayout( vlayout );
1078QgsProcessingParameterDefinition *QgsProcessingDistanceParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1083 auto param = std::make_unique< QgsProcessingParameterDistance >( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1088 param->setMinimum( val );
1094 param->setMaximum( val );
1097 param->setFlags( flags );
1098 return param.release();
1102 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1107QString QgsProcessingDistanceWidgetWrapper::parameterType()
const
1114 return new QgsProcessingDistanceWidgetWrapper( parameter, type );
1117QWidget *QgsProcessingDistanceWidgetWrapper::createWidget()
1121 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1126 mLabel =
new QLabel();
1127 mUnitsCombo =
new QComboBox();
1129 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::DistanceUnit::Meters ),
static_cast< int >( Qgis::DistanceUnit::Meters ) );
1130 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::DistanceUnit::Kilometers ),
static_cast< int >( Qgis::DistanceUnit::Kilometers ) );
1131 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::DistanceUnit::Feet ),
static_cast< int >( Qgis::DistanceUnit::Feet ) );
1132 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::DistanceUnit::Miles ),
static_cast< int >( Qgis::DistanceUnit::Miles ) );
1133 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::DistanceUnit::Yards ),
static_cast< int >( Qgis::DistanceUnit::Yards ) );
1135 const int labelMargin =
static_cast< int >( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1136 QHBoxLayout *layout =
new QHBoxLayout();
1137 layout->addWidget( spin, 1 );
1138 layout->insertSpacing( 1, labelMargin / 2 );
1139 layout->insertWidget( 2, mLabel );
1140 layout->insertWidget( 3, mUnitsCombo );
1145 mWarningLabel =
new QWidget();
1146 QHBoxLayout *warningLayout =
new QHBoxLayout();
1147 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1148 QLabel *warning =
new QLabel();
1150 const int size =
static_cast< int >( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1151 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1152 warning->setToolTip( tr(
"Distance is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1153 warningLayout->insertSpacing( 0, labelMargin / 2 );
1154 warningLayout->insertWidget( 1, warning );
1155 mWarningLabel->setLayout( warningLayout );
1156 layout->insertWidget( 4, mWarningLabel );
1158 QWidget *w =
new QWidget();
1159 layout->setContentsMargins( 0, 0, 0, 0 );
1160 w->setLayout( layout );
1175void QgsProcessingDistanceWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1177 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1184 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterDistance *
>( parameterDefinition() )->parentParameterName() )
1186 setUnitParameterValue( wrapper->parameterValue() );
1189 setUnitParameterValue( wrapper->parameterValue() );
1203void QgsProcessingDistanceWidgetWrapper::setUnitParameterValue(
const QVariant &value )
1209 std::unique_ptr< QgsProcessingContext > tmpContext;
1210 if ( mProcessingContextGenerator )
1211 context = mProcessingContextGenerator->processingContext();
1215 tmpContext = std::make_unique< QgsProcessingContext >();
1216 context = tmpContext.get();
1233 mUnitsCombo->hide();
1238 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast< int >( units ) ) );
1239 mUnitsCombo->show();
1242 mWarningLabel->setVisible( units == Qgis::DistanceUnit::Degrees );
1246QVariant QgsProcessingDistanceWidgetWrapper::widgetValue()
const
1248 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1249 if ( val.type() == QVariant::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1262 return new QgsProcessingDistanceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1273 QVBoxLayout *vlayout =
new QVBoxLayout();
1274 vlayout->setContentsMargins( 0, 0, 0, 0 );
1276 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1277 mMinLineEdit =
new QLineEdit();
1278 vlayout->addWidget( mMinLineEdit );
1280 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1281 mMaxLineEdit =
new QLineEdit();
1282 vlayout->addWidget( mMaxLineEdit );
1284 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1285 mDefaultLineEdit =
new QLineEdit();
1286 vlayout->addWidget( mDefaultLineEdit );
1288 vlayout->addWidget(
new QLabel( tr(
"Default unit type" ) ) );
1290 mUnitsCombo =
new QComboBox();
1291 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::TemporalUnit::Milliseconds ),
static_cast< int >( Qgis::TemporalUnit::Milliseconds ) );
1292 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::TemporalUnit::Seconds ),
static_cast< int >( Qgis::TemporalUnit::Seconds ) );
1293 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::TemporalUnit::Minutes ),
static_cast< int >( Qgis::TemporalUnit::Minutes ) );
1294 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::TemporalUnit::Hours ),
static_cast< int >( Qgis::TemporalUnit::Hours ) );
1295 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::TemporalUnit::Days ),
static_cast< int >( Qgis::TemporalUnit::Days ) );
1296 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::TemporalUnit::Weeks ),
static_cast< int >( Qgis::TemporalUnit::Weeks ) );
1297 mUnitsCombo->addItem( tr(
"years (365.25 days)" ),
static_cast< int >( Qgis::TemporalUnit::Years ) );
1298 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::TemporalUnit::Decades ),
static_cast< int >( Qgis::TemporalUnit::Decades ) );
1299 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::TemporalUnit::Centuries ),
static_cast< int >( Qgis::TemporalUnit::Centuries ) );
1300 vlayout->addWidget( mUnitsCombo );
1304 mMinLineEdit->setText( QLocale().toString( durationParam->minimum() ) );
1305 mMaxLineEdit->setText( QLocale().toString( durationParam->maximum() ) );
1306 mDefaultLineEdit->setText( durationParam->defaultValueForGui().toString() );
1307 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast <int >( durationParam->defaultUnit() ) ) );
1310 setLayout( vlayout );
1313QgsProcessingParameterDefinition *QgsProcessingDurationParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1318 auto param = std::make_unique< QgsProcessingParameterDuration >( name, description, ok ? val : QVariant() );
1323 param->setMinimum( val );
1329 param->setMaximum( val );
1332 param->setDefaultUnit(
static_cast<Qgis::TemporalUnit >( mUnitsCombo->currentData().toInt() ) );
1334 param->setFlags( flags );
1335 return param.release();
1339 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1344QString QgsProcessingDurationWidgetWrapper::parameterType()
const
1351 return new QgsProcessingDurationWidgetWrapper( parameter, type );
1354QWidget *QgsProcessingDurationWidgetWrapper::createWidget()
1358 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1363 mUnitsCombo =
new QComboBox();
1365 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::TemporalUnit::Milliseconds ),
static_cast< int >( Qgis::TemporalUnit::Milliseconds ) );
1366 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::TemporalUnit::Seconds ),
static_cast< int >( Qgis::TemporalUnit::Seconds ) );
1367 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::TemporalUnit::Minutes ),
static_cast< int >( Qgis::TemporalUnit::Minutes ) );
1368 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::TemporalUnit::Hours ),
static_cast< int >( Qgis::TemporalUnit::Hours ) );
1369 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::TemporalUnit::Days ),
static_cast< int >( Qgis::TemporalUnit::Days ) );
1370 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::TemporalUnit::Weeks ),
static_cast< int >( Qgis::TemporalUnit::Weeks ) );
1371 mUnitsCombo->addItem( tr(
"years (365.25 days)" ),
static_cast< int >( Qgis::TemporalUnit::Years ) );
1372 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::TemporalUnit::Decades ),
static_cast< int >( Qgis::TemporalUnit::Decades ) );
1373 mUnitsCombo->addItem(
QgsUnitTypes::toString( Qgis::TemporalUnit::Centuries ),
static_cast< int >( Qgis::TemporalUnit::Centuries ) );
1375 QHBoxLayout *layout =
new QHBoxLayout();
1376 layout->addWidget( spin, 1 );
1377 layout->insertWidget( 1, mUnitsCombo );
1379 QWidget *w =
new QWidget();
1380 layout->setContentsMargins( 0, 0, 0, 0 );
1381 w->setLayout( layout );
1383 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast< int >( durationDef->
defaultUnit() ) ) );
1384 mUnitsCombo->show();
1397QLabel *QgsProcessingDurationWidgetWrapper::createLabel()
1409QVariant QgsProcessingDurationWidgetWrapper::widgetValue()
const
1411 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1412 if ( val.type() == QVariant::Double && mUnitsCombo )
1423void QgsProcessingDurationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1429 QgsProcessingNumericWidgetWrapper::setWidgetValue( val, context );
1433 QgsProcessingNumericWidgetWrapper::setWidgetValue( value, context );
1439 return new QgsProcessingDurationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1449 QVBoxLayout *vlayout =
new QVBoxLayout();
1450 vlayout->setContentsMargins( 0, 0, 0, 0 );
1452 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1454 mDefaultLineEdit =
new QLineEdit();
1458 mDefaultLineEdit->setText( scaleParam->defaultValueForGui().toString() );
1461 vlayout->addWidget( mDefaultLineEdit );
1463 setLayout( vlayout );
1466QgsProcessingParameterDefinition *QgsProcessingScaleParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1469 double val = mDefaultLineEdit->text().toDouble( &ok );
1470 auto param = std::make_unique< QgsProcessingParameterScale >( name, description, ok ? val : QVariant() );
1471 param->setFlags( flags );
1472 return param.release();
1476 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1481QString QgsProcessingScaleWidgetWrapper::parameterType()
const
1488 return new QgsProcessingScaleWidgetWrapper( parameter, type );
1491QWidget *QgsProcessingScaleWidgetWrapper::createWidget()
1503 mScaleWidget->setAllowNull(
true );
1505 mScaleWidget->setMapCanvas( widgetContext().mapCanvas() );
1506 mScaleWidget->setShowCurrentScaleButton(
true );
1508 mScaleWidget->setToolTip( parameterDefinition()->toolTip() );
1511 emit widgetValueHasChanged(
this );
1513 return mScaleWidget;
1522 mScaleWidget->setMapCanvas( context.
mapCanvas() );
1527QVariant QgsProcessingScaleWidgetWrapper::widgetValue()
const
1529 return mScaleWidget && !mScaleWidget->isNull() ? QVariant( mScaleWidget->scale() ) : QVariant();
1532void QgsProcessingScaleWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1536 if ( mScaleWidget->allowNull() && !value.isValid() )
1537 mScaleWidget->setNull();
1541 mScaleWidget->setScale( v );
1548 return new QgsProcessingScaleParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1559 QVBoxLayout *vlayout =
new QVBoxLayout();
1560 vlayout->setContentsMargins( 0, 0, 0, 0 );
1562 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
1564 mTypeComboBox =
new QComboBox();
1567 vlayout->addWidget( mTypeComboBox );
1569 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1570 mMinLineEdit =
new QLineEdit();
1571 vlayout->addWidget( mMinLineEdit );
1573 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1574 mMaxLineEdit =
new QLineEdit();
1575 vlayout->addWidget( mMaxLineEdit );
1579 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( rangeParam->dataType() ) );
1581 mMinLineEdit->setText( QLocale().toString( range.at( 0 ) ) );
1582 mMaxLineEdit->setText( QLocale().toString( range.at( 1 ) ) );
1585 setLayout( vlayout );
1588QgsProcessingParameterDefinition *QgsProcessingRangeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1590 QString defaultValue;
1591 if ( mMinLineEdit->text().isEmpty() )
1593 defaultValue = QStringLiteral(
"None" );
1601 defaultValue = QStringLiteral(
"None" );
1605 if ( mMaxLineEdit->text().isEmpty() )
1607 defaultValue += QLatin1String(
",None" );
1613 defaultValue += QStringLiteral(
",%1" ).arg( ok ? QString::number( val ) : QLatin1String(
"None" ) );
1617 auto param = std::make_unique< QgsProcessingParameterRange >( name, description, dataType, defaultValue );
1618 param->setFlags( flags );
1619 return param.release();
1629QWidget *QgsProcessingRangeWidgetWrapper::createWidget()
1638 QHBoxLayout *layout =
new QHBoxLayout();
1643 mMinSpinBox->setExpressionsEnabled(
true );
1644 mMinSpinBox->setShowClearButton(
false );
1645 mMaxSpinBox->setExpressionsEnabled(
true );
1646 mMaxSpinBox->setShowClearButton(
false );
1648 QLabel *minLabel =
new QLabel( tr(
"Min" ) );
1649 layout->addWidget( minLabel );
1650 layout->addWidget( mMinSpinBox, 1 );
1652 QLabel *maxLabel =
new QLabel( tr(
"Max" ) );
1653 layout->addWidget( maxLabel );
1654 layout->addWidget( mMaxSpinBox, 1 );
1656 QWidget *w =
new QWidget();
1657 layout->setContentsMargins( 0, 0, 0, 0 );
1658 w->setLayout( layout );
1662 mMinSpinBox->setDecimals( 6 );
1663 mMaxSpinBox->setDecimals( 6 );
1667 mMinSpinBox->setDecimals( 0 );
1668 mMaxSpinBox->setDecimals( 0 );
1671 mMinSpinBox->setMinimum( -99999999.999999 );
1672 mMaxSpinBox->setMinimum( -99999999.999999 );
1673 mMinSpinBox->setMaximum( 99999999.999999 );
1674 mMaxSpinBox->setMaximum( 99999999.999999 );
1678 mAllowingNull =
true;
1680 const double min = mMinSpinBox->minimum() - 1;
1681 mMinSpinBox->setMinimum( min );
1682 mMaxSpinBox->setMinimum( min );
1683 mMinSpinBox->setValue( min );
1684 mMaxSpinBox->setValue( min );
1686 mMinSpinBox->setShowClearButton(
true );
1687 mMaxSpinBox->setShowClearButton(
true );
1688 mMinSpinBox->setSpecialValueText( tr(
"Not set" ) );
1689 mMaxSpinBox->setSpecialValueText( tr(
"Not set" ) );
1692 w->setToolTip( parameterDefinition()->toolTip() );
1694 connect( mMinSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
const double v )
1696 mBlockChangedSignal++;
1697 if ( !mAllowingNull && v > mMaxSpinBox->value() )
1698 mMaxSpinBox->setValue( v );
1699 mBlockChangedSignal--;
1701 if ( !mBlockChangedSignal )
1702 emit widgetValueHasChanged(
this );
1704 connect( mMaxSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
const double v )
1706 mBlockChangedSignal++;
1707 if ( !mAllowingNull && v < mMinSpinBox->value() )
1708 mMinSpinBox->setValue( v );
1709 mBlockChangedSignal--;
1711 if ( !mBlockChangedSignal )
1712 emit widgetValueHasChanged(
this );
1721void QgsProcessingRangeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1724 if ( mAllowingNull && v.empty() )
1726 mMinSpinBox->clear();
1727 mMaxSpinBox->clear();
1734 if ( mAllowingNull )
1736 mBlockChangedSignal++;
1737 if ( std::isnan( v.at( 0 ) ) )
1738 mMinSpinBox->clear();
1740 mMinSpinBox->setValue( v.at( 0 ) );
1742 if ( v.count() >= 2 )
1744 if ( std::isnan( v.at( 1 ) ) )
1745 mMaxSpinBox->clear();
1747 mMaxSpinBox->setValue( v.at( 1 ) );
1749 mBlockChangedSignal--;
1753 mBlockChangedSignal++;
1754 mMinSpinBox->setValue( v.at( 0 ) );
1755 if ( v.count() >= 2 )
1756 mMaxSpinBox->setValue( v.at( 1 ) );
1757 mBlockChangedSignal--;
1761 if ( !mBlockChangedSignal )
1762 emit widgetValueHasChanged(
this );
1765QVariant QgsProcessingRangeWidgetWrapper::widgetValue()
const
1767 if ( mAllowingNull )
1770 if (
qgsDoubleNear( mMinSpinBox->value(), mMinSpinBox->minimum() ) )
1771 value = QStringLiteral(
"None" );
1773 value = QString::number( mMinSpinBox->value() );
1775 if (
qgsDoubleNear( mMaxSpinBox->value(), mMaxSpinBox->minimum() ) )
1776 value += QLatin1String(
",None" );
1778 value += QStringLiteral(
",%1" ).arg( mMaxSpinBox->value() );
1783 return QStringLiteral(
"%1,%2" ).arg( mMinSpinBox->value() ).arg( mMaxSpinBox->value() );
1786QStringList QgsProcessingRangeWidgetWrapper::compatibleParameterTypes()
const
1788 return QStringList()
1793QStringList QgsProcessingRangeWidgetWrapper::compatibleOutputTypes()
const
1798QString QgsProcessingRangeWidgetWrapper::modelerExpressionFormatString()
const
1800 return tr(
"string as two comma delimited floats, e.g. '1,10'" );
1803QString QgsProcessingRangeWidgetWrapper::parameterType()
const
1810 return new QgsProcessingRangeWidgetWrapper( parameter, type );
1815 return new QgsProcessingRangeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1826 QVBoxLayout *vlayout =
new QVBoxLayout();
1827 vlayout->setContentsMargins( 0, 0, 0, 0 );
1829 mMatrixWidget =
new QgsProcessingMatrixModelerWidget();
1832 mMatrixWidget->setValue( matrixParam->headers(), matrixParam->defaultValueForGui() );
1833 mMatrixWidget->setFixedRows( matrixParam->hasFixedNumberRows() );
1835 vlayout->addWidget( mMatrixWidget );
1836 setLayout( vlayout );
1839QgsProcessingParameterDefinition *QgsProcessingMatrixParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1841 auto param = std::make_unique< QgsProcessingParameterMatrix >( name, description, 1, mMatrixWidget->fixedRows(), mMatrixWidget->headers(), mMatrixWidget->value() );
1842 param->setFlags( flags );
1843 return param.release();
1853QWidget *QgsProcessingMatrixWidgetWrapper::createWidget()
1855 mMatrixWidget =
new QgsProcessingMatrixParameterPanel(
nullptr,
dynamic_cast< const QgsProcessingParameterMatrix *
>( parameterDefinition() ) );
1856 mMatrixWidget->setToolTip( parameterDefinition()->toolTip() );
1858 connect( mMatrixWidget, &QgsProcessingMatrixParameterPanel::changed,
this, [ = ]
1860 emit widgetValueHasChanged(
this );
1869 return mMatrixWidget;
1875void QgsProcessingMatrixWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1878 if ( mMatrixWidget )
1879 mMatrixWidget->setValue( v );
1882QVariant QgsProcessingMatrixWidgetWrapper::widgetValue()
const
1884 if ( mMatrixWidget )
1885 return mMatrixWidget->value().isEmpty() ? QVariant() : mMatrixWidget->value();
1890QStringList QgsProcessingMatrixWidgetWrapper::compatibleParameterTypes()
const
1892 return QStringList()
1896QStringList QgsProcessingMatrixWidgetWrapper::compatibleOutputTypes()
const
1898 return QStringList();
1901QString QgsProcessingMatrixWidgetWrapper::modelerExpressionFormatString()
const
1903 return tr(
"comma delimited string of values, or an array of values" );
1906QString QgsProcessingMatrixWidgetWrapper::parameterType()
const
1913 return new QgsProcessingMatrixWidgetWrapper( parameter, type );
1918 return new QgsProcessingMatrixParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1930 QVBoxLayout *vlayout =
new QVBoxLayout();
1931 vlayout->setContentsMargins( 0, 0, 0, 0 );
1933 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
1935 mTypeComboBox =
new QComboBox();
1939 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( fileParam->behavior() ) );
1941 mTypeComboBox->setCurrentIndex( 0 );
1942 vlayout->addWidget( mTypeComboBox );
1944 vlayout->addWidget(
new QLabel( tr(
"File filter" ) ) );
1946 mFilterComboBox =
new QComboBox();
1947 mFilterComboBox->setEditable(
true );
1949 mFilterComboBox->addItem( tr(
"All Files (*.*)" ) );
1950 mFilterComboBox->addItem( tr(
"CSV Files (*.csv)" ) );
1951 mFilterComboBox->addItem( tr(
"HTML Files (*.html *.htm)" ) );
1952 mFilterComboBox->addItem( tr(
"Text Files (*.txt)" ) );
1954 mFilterComboBox->setCurrentText( fileParam->fileFilter() );
1956 mFilterComboBox->setCurrentIndex( 0 );
1957 vlayout->addWidget( mFilterComboBox );
1959 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1962 mDefaultFileWidget->lineEdit()->setShowClearButton(
true );
1966 mDefaultFileWidget->setFilePath( fileParam->defaultValueForGui().toString() );
1970 vlayout->addWidget( mDefaultFileWidget );
1972 connect( mTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ]
1981 setLayout( vlayout );
1984QgsProcessingParameterDefinition *QgsProcessingFileParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
1986 auto param = std::make_unique< QgsProcessingParameterFile >( name, description );
1989 param->setFileFilter( mFilterComboBox->currentText() );
1990 if ( !mDefaultFileWidget->filePath().isEmpty() )
1991 param->setDefaultValue( mDefaultFileWidget->filePath() );
1992 param->setFlags( flags );
1993 return param.release();
2003QWidget *QgsProcessingFileWidgetWrapper::createWidget()
2013 mFileWidget->setToolTip( parameterDefinition()->toolTip() );
2014 mFileWidget->setDialogTitle( parameterDefinition()->description() );
2016 mFileWidget->setDefaultRoot(
QgsSettings().value( QStringLiteral(
"/Processing/LastInputPath" ), QDir::homePath() ).toString() );
2023 mFileWidget->setFilter( fileParam->
fileFilter() );
2024 else if ( !fileParam->
extension().isEmpty() )
2025 mFileWidget->setFilter( tr(
"%1 files" ).arg( fileParam->
extension().toUpper() ) + QStringLiteral(
" (*." ) + fileParam->
extension().toLower() +
')' );
2035 QgsSettings().
setValue( QStringLiteral(
"/Processing/LastInputPath" ), QFileInfo( path ).canonicalPath() );
2036 emit widgetValueHasChanged(
this );
2044void QgsProcessingFileWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2048 mFileWidget->setFilePath( v );
2051QVariant QgsProcessingFileWidgetWrapper::widgetValue()
const
2054 return mFileWidget->filePath();
2059QStringList QgsProcessingFileWidgetWrapper::compatibleParameterTypes()
const
2061 return QStringList()
2066QStringList QgsProcessingFileWidgetWrapper::compatibleOutputTypes()
const
2076QString QgsProcessingFileWidgetWrapper::modelerExpressionFormatString()
const
2078 return tr(
"string representing a path to a file or folder" );
2081QString QgsProcessingFileWidgetWrapper::parameterType()
const
2088 return new QgsProcessingFileWidgetWrapper( parameter, type );
2093 return new QgsProcessingFileParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2105 QVBoxLayout *vlayout =
new QVBoxLayout();
2106 vlayout->setContentsMargins( 0, 0, 0, 0 );
2107 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2110 mDefaultLineEdit->registerExpressionContextGenerator(
this );
2114 vlayout->addWidget( mDefaultLineEdit );
2116 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
2118 mParentLayerComboBox =
new QComboBox();
2119 mParentLayerComboBox->addItem( tr(
"None" ), QVariant() );
2121 QString initialParent;
2123 initialParent = expParam->parentLayerParameterName();
2125 if ( QgsProcessingModelAlgorithm *model = widgetContext.
model() )
2128 const QMap<QString, QgsProcessingModelParameter> components = model->parameterComponents();
2129 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
2133 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
2134 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2136 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2141 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
2142 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2144 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2150 if ( mParentLayerComboBox->count() == 1 && !initialParent.isEmpty() )
2153 mParentLayerComboBox->addItem( initialParent, initialParent );
2154 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2157 vlayout->addWidget( mParentLayerComboBox );
2158 setLayout( vlayout );
2161QgsProcessingParameterDefinition *QgsProcessingExpressionParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
2163 auto param = std::make_unique< QgsProcessingParameterExpression >( name, description, mDefaultLineEdit->expression(), mParentLayerComboBox->currentData().toString() );
2164 param->setFlags( flags );
2165 return param.release();
2174QWidget *QgsProcessingExpressionWidgetWrapper::createWidget()
2186 mExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2187 mExpLineEdit->setExpressionDialogTitle( parameterDefinition()->description() );
2188 mExpLineEdit->registerExpressionContextGenerator(
this );
2191 emit widgetValueHasChanged(
this );
2193 return mExpLineEdit;
2197 if ( expParam->
metadata().value( QStringLiteral(
"inlineEditor" ) ).toBool() )
2200 mExpBuilderWidget->setToolTip( parameterDefinition()->toolTip() );
2201 mExpBuilderWidget->init( createExpressionContext() );
2204 Q_UNUSED( changed );
2205 emit widgetValueHasChanged(
this );
2207 return mExpBuilderWidget;
2212 mFieldExpWidget->setToolTip( parameterDefinition()->toolTip() );
2213 mFieldExpWidget->setExpressionDialogTitle( parameterDefinition()->description() );
2214 mFieldExpWidget->registerExpressionContextGenerator(
this );
2216 mFieldExpWidget->setAllowEmptyFieldName(
true );
2220 emit widgetValueHasChanged(
this );
2222 return mFieldExpWidget;
2230void QgsProcessingExpressionWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
2240 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterExpression *
>( parameterDefinition() )->parentLayerParameterName() )
2242 setParentLayerWrapperValue( wrapper );
2245 setParentLayerWrapperValue( wrapper );
2261 if ( mExpBuilderWidget )
2264 mExpBuilderWidget->setExpressionContext( createExpressionContext() );
2272 std::unique_ptr< QgsProcessingContext > tmpContext;
2273 if ( mProcessingContextGenerator )
2274 context = mProcessingContextGenerator->processingContext();
2278 tmpContext = std::make_unique< QgsProcessingContext >();
2279 context = tmpContext.get();
2283 if ( val.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
2293 if ( mFieldExpWidget )
2294 mFieldExpWidget->setLayer(
nullptr );
2295 else if ( mExpBuilderWidget )
2296 mExpBuilderWidget->setLayer(
nullptr );
2297 else if ( mExpLineEdit )
2298 mExpLineEdit->setLayer(
nullptr );
2304 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
2305 if ( ownedLayer && ownedLayer->type() == Qgis::LayerType::Vector )
2307 mParentLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
2308 layer = mParentLayer.get();
2315 if ( mFieldExpWidget )
2316 mFieldExpWidget->setLayer( layer );
2317 if ( mExpBuilderWidget )
2318 mExpBuilderWidget->setLayer( layer );
2319 else if ( mExpLineEdit )
2320 mExpLineEdit->setLayer( layer );
2323void QgsProcessingExpressionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2326 if ( mFieldExpWidget )
2327 mFieldExpWidget->setExpression( v );
2328 else if ( mExpBuilderWidget )
2329 mExpBuilderWidget->setExpressionText( v );
2330 else if ( mExpLineEdit )
2331 mExpLineEdit->setExpression( v );
2334QVariant QgsProcessingExpressionWidgetWrapper::widgetValue()
const
2336 if ( mFieldExpWidget )
2337 return mFieldExpWidget->expression();
2338 if ( mExpBuilderWidget )
2339 return mExpBuilderWidget->expressionText();
2340 else if ( mExpLineEdit )
2341 return mExpLineEdit->expression();
2346QStringList QgsProcessingExpressionWidgetWrapper::compatibleParameterTypes()
const
2348 return QStringList()
2357QStringList QgsProcessingExpressionWidgetWrapper::compatibleOutputTypes()
const
2359 return QStringList()
2364QString QgsProcessingExpressionWidgetWrapper::modelerExpressionFormatString()
const
2366 return tr(
"string representation of an expression" );
2369const QgsVectorLayer *QgsProcessingExpressionWidgetWrapper::linkedVectorLayer()
const
2371 if ( mFieldExpWidget && mFieldExpWidget->layer() )
2372 return mFieldExpWidget->layer();
2374 if ( mExpBuilderWidget && mExpBuilderWidget->layer() )
2375 return mExpBuilderWidget->layer();
2380QString QgsProcessingExpressionWidgetWrapper::parameterType()
const
2387 return new QgsProcessingExpressionWidgetWrapper( parameter, type );
2392 return new QgsProcessingExpressionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2405 QHBoxLayout *hl =
new QHBoxLayout();
2406 hl->setContentsMargins( 0, 0, 0, 0 );
2408 mLineEdit =
new QLineEdit();
2409 mLineEdit->setEnabled(
false );
2410 hl->addWidget( mLineEdit, 1 );
2412 mToolButton =
new QToolButton();
2413 mToolButton->setText( QString( QChar( 0x2026 ) ) );
2414 hl->addWidget( mToolButton );
2420 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
2423 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingEnumPanelWidget::showDialog );
2426void QgsProcessingEnumPanelWidget::setValue(
const QVariant &value )
2428 if ( value.isValid() )
2430 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
2432 if ( mParam->usesStaticStrings() && mValue.count() == 1 && mValue.at( 0 ).toString().isEmpty() )
2438 updateSummaryText();
2442void QgsProcessingEnumPanelWidget::showDialog()
2444 QVariantList availableOptions;
2447 availableOptions.reserve( mParam->options().size() );
2448 for (
int i = 0; i < mParam->options().count(); ++i )
2449 availableOptions << i;
2452 const QStringList options = mParam ? mParam->options() : QStringList();
2456 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
2457 widget->setPanelTitle( mParam->description() );
2459 if ( mParam->usesStaticStrings() )
2461 widget->setValueFormatter( [options](
const QVariant & v ) -> QString
2463 const QString i = v.toString();
2464 return options.contains( i ) ? i : QString();
2469 widget->setValueFormatter( [options](
const QVariant & v ) -> QString
2471 const int i = v.toInt();
2472 return options.size() > i ? options.at( i ) : QString();
2476 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
2478 setValue( widget->selectedOptions() );
2485 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
2487 dlg.setValueFormatter( [options](
const QVariant & v ) -> QString
2489 const int i = v.toInt();
2490 return options.size() > i ? options.at( i ) : QString();
2494 setValue( dlg.selectedOptions() );
2499void QgsProcessingEnumPanelWidget::updateSummaryText()
2504 if ( mValue.empty() )
2506 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
2511 values.reserve( mValue.size() );
2512 if ( mParam->usesStaticStrings() )
2514 for (
const QVariant &val : std::as_const( mValue ) )
2516 values << val.toString();
2521 const QStringList options = mParam->options();
2522 for (
const QVariant &val : std::as_const( mValue ) )
2524 const int i = val.toInt();
2525 values << ( options.size() > i ? options.at( i ) : QString() );
2529 const QString concatenated = values.join( tr(
"," ) );
2530 if ( concatenated.length() < 100 )
2531 mLineEdit->setText( concatenated );
2533 mLineEdit->setText( tr(
"%n option(s) selected",
nullptr, mValue.count() ) );
2541QgsProcessingEnumCheckboxPanelWidget::QgsProcessingEnumCheckboxPanelWidget( QWidget *parent,
const QgsProcessingParameterEnum *param,
int columns )
2544 , mButtonGroup( new QButtonGroup( this ) )
2545 , mColumns( columns )
2547 mButtonGroup->setExclusive( !mParam->allowMultiple() );
2549 QGridLayout *l =
new QGridLayout();
2550 l->setContentsMargins( 0, 0, 0, 0 );
2552 int rows =
static_cast< int >( std::ceil( mParam->options().count() /
static_cast< double >( mColumns ) ) );
2553 for (
int i = 0; i < mParam->options().count(); ++i )
2555 QAbstractButton *button =
nullptr;
2556 if ( mParam->allowMultiple() )
2557 button =
new QCheckBox( mParam->options().at( i ) );
2559 button =
new QRadioButton( mParam->options().at( i ) );
2561 connect( button, &QAbstractButton::toggled,
this, [ = ]
2563 if ( !mBlockChangedSignal )
2567 mButtons.insert( i, button );
2569 mButtonGroup->addButton( button, i );
2570 l->addWidget( button, i % rows, i / rows );
2572 l->addItem(
new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, mColumns );
2575 if ( mParam->allowMultiple() )
2577 setContextMenuPolicy( Qt::CustomContextMenu );
2578 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsProcessingEnumCheckboxPanelWidget::showPopupMenu );
2582QVariant QgsProcessingEnumCheckboxPanelWidget::value()
const
2584 if ( mParam->allowMultiple() )
2587 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2589 if ( it.value()->isChecked() )
2590 value.append( mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key() );
2596 if ( mParam->usesStaticStrings() )
2597 return mButtonGroup->checkedId() >= 0 ? mParam->options().at( mButtonGroup->checkedId() ) : QVariant();
2599 return mButtonGroup->checkedId() >= 0 ? mButtonGroup->checkedId() : QVariant();
2603void QgsProcessingEnumCheckboxPanelWidget::setValue(
const QVariant &value )
2605 mBlockChangedSignal =
true;
2606 if ( mParam->allowMultiple() )
2608 QVariantList selected;
2609 if ( value.isValid() )
2610 selected = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
2611 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2613 QVariant v = mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key();
2614 it.value()->setChecked( selected.contains( v ) );
2620 if ( v.type() == QVariant::List )
2621 v = v.toList().value( 0 );
2623 v = mParam->usesStaticStrings() ? mParam->options().indexOf( v.toString() ) : v;
2624 if ( mButtons.contains( v ) )
2625 mButtons.value( v )->setChecked(
true );
2627 mBlockChangedSignal =
false;
2631void QgsProcessingEnumCheckboxPanelWidget::showPopupMenu()
2634 QAction *selectAllAction =
new QAction( tr(
"Select All" ), &popupMenu );
2635 connect( selectAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::selectAll );
2636 QAction *clearAllAction =
new QAction( tr(
"Clear Selection" ), &popupMenu );
2637 connect( clearAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::deselectAll );
2638 popupMenu.addAction( selectAllAction );
2639 popupMenu.addAction( clearAllAction );
2640 popupMenu.exec( QCursor::pos() );
2643void QgsProcessingEnumCheckboxPanelWidget::selectAll()
2645 mBlockChangedSignal =
true;
2646 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2647 it.value()->setChecked(
true );
2648 mBlockChangedSignal =
false;
2652void QgsProcessingEnumCheckboxPanelWidget::deselectAll()
2654 mBlockChangedSignal =
true;
2655 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
2656 it.value()->setChecked(
false );
2657 mBlockChangedSignal =
false;
2669 QVBoxLayout *vlayout =
new QVBoxLayout();
2670 vlayout->setContentsMargins( 0, 0, 0, 0 );
2672 mEnumWidget =
new QgsProcessingEnumModelerWidget();
2675 mEnumWidget->setAllowMultiple( enumParam->allowMultiple() );
2676 mEnumWidget->setOptions( enumParam->options() );
2677 mEnumWidget->setDefaultOptions( enumParam->defaultValueForGui() );
2679 vlayout->addWidget( mEnumWidget );
2680 setLayout( vlayout );
2683QgsProcessingParameterDefinition *QgsProcessingEnumParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
2685 auto param = std::make_unique< QgsProcessingParameterEnum >( name, description, mEnumWidget->options(), mEnumWidget->allowMultiple(), mEnumWidget->defaultOptions() );
2687 return param.release();
2697QWidget *QgsProcessingEnumWidgetWrapper::createWidget()
2705 if ( expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"useCheckBoxes" ),
false ).toBool() )
2707 const int columns = expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"columns" ), 2 ).toInt();
2708 mCheckboxPanel =
new QgsProcessingEnumCheckboxPanelWidget(
nullptr, expParam, columns );
2709 mCheckboxPanel->setToolTip( parameterDefinition()->toolTip() );
2710 connect( mCheckboxPanel, &QgsProcessingEnumCheckboxPanelWidget::changed,
this, [ = ]
2712 emit widgetValueHasChanged(
this );
2714 return mCheckboxPanel;
2723 mPanel =
new QgsProcessingEnumPanelWidget(
nullptr, expParam );
2724 mPanel->setToolTip( parameterDefinition()->toolTip() );
2725 connect( mPanel, &QgsProcessingEnumPanelWidget::changed,
this, [ = ]
2727 emit widgetValueHasChanged(
this );
2733 mComboBox =
new QComboBox();
2736 mComboBox->addItem( tr(
"[Not selected]" ), QVariant() );
2737 const QStringList options = expParam->
options();
2738 const QVariantList iconList = expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"icons" ) ).toList();
2739 for (
int i = 0; i < options.count(); ++i )
2741 const QIcon icon = iconList.value( i ).value< QIcon >();
2744 mComboBox->addItem( icon, options.at( i ), options.at( i ) );
2746 mComboBox->addItem( icon, options.at( i ), i );
2749 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2750 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
2752 emit widgetValueHasChanged(
this );
2761void QgsProcessingEnumWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2765 if ( !value.isValid() )
2766 mComboBox->setCurrentIndex( mComboBox->findData( QVariant() ) );
2773 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
2778 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
2782 else if ( mPanel || mCheckboxPanel )
2785 if ( value.isValid() )
2791 opts.reserve( v.size() );
2792 for ( QString i : v )
2798 opts.reserve( v.size() );
2804 mPanel->setValue( opts );
2805 else if ( mCheckboxPanel )
2806 mCheckboxPanel->setValue( opts );
2810QVariant QgsProcessingEnumWidgetWrapper::widgetValue()
const
2813 return mComboBox->currentData();
2815 return mPanel->value();
2816 else if ( mCheckboxPanel )
2817 return mCheckboxPanel->value();
2822QStringList QgsProcessingEnumWidgetWrapper::compatibleParameterTypes()
const
2824 return QStringList()
2830QStringList QgsProcessingEnumWidgetWrapper::compatibleOutputTypes()
const
2832 return QStringList()
2837QString QgsProcessingEnumWidgetWrapper::modelerExpressionFormatString()
const
2839 return tr(
"selected option index (starting from 0), array of indices, or comma separated string of options (e.g. '1,3')" );
2842QString QgsProcessingEnumWidgetWrapper::parameterType()
const
2849 return new QgsProcessingEnumWidgetWrapper( parameter, type );
2854 return new QgsProcessingEnumParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2867QWidget *QgsProcessingLayoutWidgetWrapper::createWidget()
2876 mComboBox =
new QgsLayoutComboBox(
nullptr, widgetContext().project() ? widgetContext().project()->layoutManager() :
nullptr );
2878 mComboBox->setAllowEmptyLayout(
true );
2881 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2884 emit widgetValueHasChanged(
this );
2891 mPlainComboBox =
new QComboBox();
2892 mPlainComboBox->setEditable(
true );
2893 mPlainComboBox->setToolTip( tr(
"Name of an existing print layout" ) );
2894 if ( widgetContext().project() )
2898 mPlainComboBox->addItem( layout->name() );
2901 connect( mPlainComboBox, &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
2903 emit widgetValueHasChanged(
this );
2905 return mPlainComboBox;
2911void QgsProcessingLayoutWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2915 if ( !value.isValid() )
2916 mComboBox->setCurrentLayout(
nullptr );
2920 mComboBox->setCurrentLayout( l );
2922 mComboBox->setCurrentLayout(
nullptr );
2925 else if ( mPlainComboBox )
2928 mPlainComboBox->setCurrentText( v );
2932QVariant QgsProcessingLayoutWidgetWrapper::widgetValue()
const
2937 return l ? l->
name() : QVariant();
2939 else if ( mPlainComboBox )
2940 return mPlainComboBox->currentText().isEmpty() ? QVariant() : mPlainComboBox->currentText();
2948 if ( mPlainComboBox && context.
project() )
2952 mPlainComboBox->addItem( layout->name() );
2956QStringList QgsProcessingLayoutWidgetWrapper::compatibleParameterTypes()
const
2958 return QStringList()
2963QStringList QgsProcessingLayoutWidgetWrapper::compatibleOutputTypes()
const
2965 return QStringList()
2969QString QgsProcessingLayoutWidgetWrapper::modelerExpressionFormatString()
const
2971 return tr(
"string representing the name of an existing print layout" );
2974QString QgsProcessingLayoutWidgetWrapper::parameterType()
const
2981 return new QgsProcessingLayoutWidgetWrapper( parameter, type );
2995 QVBoxLayout *vlayout =
new QVBoxLayout();
2996 vlayout->setContentsMargins( 0, 0, 0, 0 );
2998 vlayout->addWidget(
new QLabel( tr(
"Parent layout" ) ) );
3000 mParentLayoutComboBox =
new QComboBox();
3001 QString initialParent;
3003 initialParent = itemParam->parentLayoutParameterName();
3005 if (
auto *lModel = widgetContext.
model() )
3008 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3009 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3013 mParentLayoutComboBox-> addItem( definition->
description(), definition->
name() );
3014 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
3016 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3022 if ( mParentLayoutComboBox->count() == 0 && !initialParent.isEmpty() )
3025 mParentLayoutComboBox->addItem( initialParent, initialParent );
3026 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3029 vlayout->addWidget( mParentLayoutComboBox );
3030 setLayout( vlayout );
3032QgsProcessingParameterDefinition *QgsProcessingLayoutItemParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3034 auto param = std::make_unique< QgsProcessingParameterLayoutItem >( name, description, QVariant(), mParentLayoutComboBox->currentData().toString() );
3036 return param.release();
3046QWidget *QgsProcessingLayoutItemWidgetWrapper::createWidget()
3057 mComboBox->setAllowEmptyItem(
true );
3058 if ( layoutParam->
itemType() >= 0 )
3061 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3064 emit widgetValueHasChanged(
this );
3071 mLineEdit =
new QLineEdit();
3072 mLineEdit->setToolTip( tr(
"UUID or ID of an existing print layout item" ) );
3073 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
3075 emit widgetValueHasChanged(
this );
3083void QgsProcessingLayoutItemWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3093 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterLayoutItem *
>( parameterDefinition() )->parentLayoutParameterName() )
3095 setLayoutParameterValue( wrapper->parameterValue() );
3098 setLayoutParameterValue( wrapper->parameterValue() );
3111void QgsProcessingLayoutItemWidgetWrapper::setLayoutParameterValue(
const QVariant &value )
3117 std::unique_ptr< QgsProcessingContext > tmpContext;
3118 if ( mProcessingContextGenerator )
3119 context = mProcessingContextGenerator->processingContext();
3123 tmpContext = std::make_unique< QgsProcessingContext >();
3124 context = tmpContext.get();
3128 setLayout( layout );
3131void QgsProcessingLayoutItemWidgetWrapper::setLayout(
QgsPrintLayout *layout )
3134 mComboBox->setCurrentLayout( layout );
3137void QgsProcessingLayoutItemWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3141 if ( !value.isValid() )
3142 mComboBox->setItem(
nullptr );
3146 mComboBox->setItem( item );
3149 else if ( mLineEdit )
3152 mLineEdit->setText( v );
3156QVariant QgsProcessingLayoutItemWidgetWrapper::widgetValue()
const
3161 return i ? i->
uuid() : QVariant();
3163 else if ( mLineEdit )
3164 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3169QStringList QgsProcessingLayoutItemWidgetWrapper::compatibleParameterTypes()
const
3171 return QStringList()
3176QStringList QgsProcessingLayoutItemWidgetWrapper::compatibleOutputTypes()
const
3178 return QStringList()
3182QString QgsProcessingLayoutItemWidgetWrapper::modelerExpressionFormatString()
const
3184 return tr(
"string representing the UUID or ID of an existing print layout item" );
3187QString QgsProcessingLayoutItemWidgetWrapper::parameterType()
const
3194 return new QgsProcessingLayoutItemWidgetWrapper( parameter, type );
3199 return new QgsProcessingLayoutItemParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3206QgsProcessingPointMapTool::QgsProcessingPointMapTool(
QgsMapCanvas *canvas )
3213QgsProcessingPointMapTool::~QgsProcessingPointMapTool() =
default;
3215void QgsProcessingPointMapTool::deactivate()
3229 if ( e->button() == Qt::LeftButton )
3232 emit clicked( point );
3237void QgsProcessingPointMapTool::keyPressEvent( QKeyEvent *e )
3239 if ( e->key() == Qt::Key_Escape )
3254QgsProcessingPointPanel::QgsProcessingPointPanel( QWidget *parent )
3257 QHBoxLayout *l =
new QHBoxLayout();
3258 l->setContentsMargins( 0, 0, 0, 0 );
3260 mLineEdit->setShowClearButton(
false );
3261 l->addWidget( mLineEdit, 1 );
3262 mButton =
new QToolButton();
3263 mButton->setText( QString( QChar( 0x2026 ) ) );
3264 l->addWidget( mButton );
3267 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::changed );
3268 connect( mButton, &QToolButton::clicked,
this, &QgsProcessingPointPanel::selectOnCanvas );
3269 mButton->setVisible(
false );
3272void QgsProcessingPointPanel::setMapCanvas(
QgsMapCanvas *canvas )
3275 mButton->setVisible(
true );
3278 mTool = std::make_unique< QgsProcessingPointMapTool >( mCanvas );
3279 connect( mTool.get(), &QgsProcessingPointMapTool::clicked,
this, &QgsProcessingPointPanel::updatePoint );
3280 connect( mTool.get(), &QgsProcessingPointMapTool::complete,
this, &QgsProcessingPointPanel::pointPicked );
3283void QgsProcessingPointPanel::setAllowNull(
bool allowNull )
3285 mLineEdit->setShowClearButton( allowNull );
3288QVariant QgsProcessingPointPanel::value()
const
3290 return mLineEdit->showClearButton() && mLineEdit->text().trimmed().isEmpty() ? QVariant() : QVariant( mLineEdit->text() );
3293void QgsProcessingPointPanel::clear()
3300 QString newText = QStringLiteral(
"%1,%2" )
3301 .arg( QString::number( point.
x(),
'f' ),
3302 QString::number( point.
y(),
'f' ) );
3305 if ( mCrs.isValid() )
3307 newText += QStringLiteral(
" [%1]" ).arg( mCrs.authid() );
3309 mLineEdit->setText( newText );
3312void QgsProcessingPointPanel::selectOnCanvas()
3317 mPrevTool = mCanvas->mapTool();
3318 mCanvas->setMapTool( mTool.get() );
3320 emit toggleDialogVisibility(
false );
3323void QgsProcessingPointPanel::updatePoint(
const QgsPointXY &point )
3325 setValue( point, mCanvas->mapSettings().destinationCrs() );
3328void QgsProcessingPointPanel::pointPicked()
3333 mCanvas->setMapTool( mPrevTool );
3335 emit toggleDialogVisibility(
true );
3347 QVBoxLayout *vlayout =
new QVBoxLayout();
3348 vlayout->setContentsMargins( 0, 0, 0, 0 );
3350 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3352 mDefaultLineEdit =
new QLineEdit();
3353 mDefaultLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
3354 mDefaultLineEdit->setPlaceholderText( tr(
"Point as 'x,y'" ) );
3358 mDefaultLineEdit->setText( QStringLiteral(
"%1,%2" ).arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) ) );
3361 vlayout->addWidget( mDefaultLineEdit );
3362 setLayout( vlayout );
3365QgsProcessingParameterDefinition *QgsProcessingPointParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3367 auto param = std::make_unique< QgsProcessingParameterPoint >( name, description, mDefaultLineEdit->text() );
3369 return param.release();
3378QWidget *QgsProcessingPointWidgetWrapper::createWidget()
3386 mPanel =
new QgsProcessingPointPanel(
nullptr );
3387 if ( widgetContext().mapCanvas() )
3388 mPanel->setMapCanvas( widgetContext().mapCanvas() );
3391 mPanel->setAllowNull(
true );
3393 mPanel->setToolTip( parameterDefinition()->toolTip() );
3395 connect( mPanel, &QgsProcessingPointPanel::changed,
this, [ = ]
3397 emit widgetValueHasChanged(
this );
3401 setDialog( mDialog );
3407 mLineEdit =
new QLineEdit();
3408 mLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
3409 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
3411 emit widgetValueHasChanged(
this );
3423 mPanel->setMapCanvas( context.
mapCanvas() );
3426void QgsProcessingPointWidgetWrapper::setDialog( QDialog *dialog )
3431 connect( mPanel, &QgsProcessingPointPanel::toggleDialogVisibility, mDialog, [ = ](
bool visible )
3434 mDialog->showMinimized();
3437 mDialog->showNormal();
3439 mDialog->activateWindow();
3446void QgsProcessingPointWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3450 if ( !value.isValid() || ( value.type() == QVariant::String && value.toString().isEmpty() ) )
3456 mPanel->setValue( p,
crs );
3459 else if ( mLineEdit )
3462 mLineEdit->setText( v );
3466QVariant QgsProcessingPointWidgetWrapper::widgetValue()
const
3470 return mPanel->value();
3472 else if ( mLineEdit )
3473 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3478QStringList QgsProcessingPointWidgetWrapper::compatibleParameterTypes()
const
3480 return QStringList()
3485QStringList QgsProcessingPointWidgetWrapper::compatibleOutputTypes()
const
3487 return QStringList()
3491QString QgsProcessingPointWidgetWrapper::modelerExpressionFormatString()
const
3493 return tr(
"string of the format 'x,y' or a geometry value (centroid is used)" );
3496QString QgsProcessingPointWidgetWrapper::parameterType()
const
3503 return new QgsProcessingPointWidgetWrapper( parameter, type );
3508 return new QgsProcessingPointParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3520 QVBoxLayout *vlayout =
new QVBoxLayout();
3521 vlayout->setContentsMargins( 0, 0, 0, 0 );
3523 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3525 mDefaultLineEdit =
new QLineEdit();
3526 mDefaultLineEdit->setToolTip( tr(
"Geometry as WKT" ) );
3527 mDefaultLineEdit->setPlaceholderText( tr(
"Geometry as WKT" ) );
3532 mDefaultLineEdit->setText( g.
asWkt() );
3535 vlayout->addWidget( mDefaultLineEdit );
3536 setLayout( vlayout );
3539QgsProcessingParameterDefinition *QgsProcessingGeometryParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3541 auto param = std::make_unique< QgsProcessingParameterGeometry >( name, description, mDefaultLineEdit->text() );
3543 return param.release();
3552QWidget *QgsProcessingGeometryWidgetWrapper::createWidget()
3560 mLineEdit =
new QLineEdit();
3561 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
3562 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
3564 emit widgetValueHasChanged(
this );
3572void QgsProcessingGeometryWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3578 mLineEdit->setText( g.
asWkt() );
3584QVariant QgsProcessingGeometryWidgetWrapper::widgetValue()
const
3587 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3592QStringList QgsProcessingGeometryWidgetWrapper::compatibleParameterTypes()
const
3594 return QStringList()
3601QStringList QgsProcessingGeometryWidgetWrapper::compatibleOutputTypes()
const
3603 return QStringList()
3607QString QgsProcessingGeometryWidgetWrapper::modelerExpressionFormatString()
const
3609 return tr(
"string in the Well-Known-Text format or a geometry value" );
3612QString QgsProcessingGeometryWidgetWrapper::parameterType()
const
3619 return new QgsProcessingGeometryWidgetWrapper( parameter, type );
3624 return new QgsProcessingGeometryParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3636 QVBoxLayout *vlayout =
new QVBoxLayout();
3637 vlayout->setContentsMargins( 0, 0, 0, 0 );
3639 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3642 mDefaultColorButton->setShowNull(
true );
3643 mAllowOpacity =
new QCheckBox( tr(
"Allow opacity control" ) );
3649 mDefaultColorButton->setToNull();
3651 mDefaultColorButton->setColor(
c );
3652 mAllowOpacity->setChecked( colorParam->opacityEnabled() );
3656 mDefaultColorButton->setToNull();
3657 mAllowOpacity->setChecked(
true );
3660 vlayout->addWidget( mDefaultColorButton );
3661 vlayout->addWidget( mAllowOpacity );
3662 setLayout( vlayout );
3665QgsProcessingParameterDefinition *QgsProcessingColorParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3667 auto param = std::make_unique< QgsProcessingParameterColor >( name, description, mDefaultColorButton->color(), mAllowOpacity->isChecked() );
3669 return param.release();
3678QWidget *QgsProcessingColorWidgetWrapper::createWidget()
3688 mColorButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
3691 mColorButton->setShowNull(
true );
3694 mColorButton->setToolTip( parameterDefinition()->toolTip() );
3695 mColorButton->setColorDialogTitle( parameterDefinition()->description() );
3703 emit widgetValueHasChanged(
this );
3706 return mColorButton;
3712void QgsProcessingColorWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3716 if ( !value.isValid() ||
3717 ( value.type() == QVariant::String && value.toString().isEmpty() )
3718 || ( value.type() == QVariant::Color && !value.value< QColor >().isValid() ) )
3719 mColorButton->setToNull();
3723 if ( !
c.isValid() && mColorButton->showNull() )
3724 mColorButton->setToNull();
3726 mColorButton->setColor(
c );
3731QVariant QgsProcessingColorWidgetWrapper::widgetValue()
const
3734 return mColorButton->isNull() ? QVariant() : mColorButton->color();
3739QStringList QgsProcessingColorWidgetWrapper::compatibleParameterTypes()
const
3741 return QStringList()
3746QStringList QgsProcessingColorWidgetWrapper::compatibleOutputTypes()
const
3748 return QStringList()
3752QString QgsProcessingColorWidgetWrapper::modelerExpressionFormatString()
const
3754 return tr(
"color style string, e.g. #ff0000 or 255,0,0" );
3757QString QgsProcessingColorWidgetWrapper::parameterType()
const
3764 return new QgsProcessingColorWidgetWrapper( parameter, type );
3769 return new QgsProcessingColorParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3780 QVBoxLayout *vlayout =
new QVBoxLayout();
3781 vlayout->setContentsMargins( 0, 0, 0, 0 );
3783 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
3785 mDefaultLineEdit =
new QLineEdit();
3788 vlayout->addWidget( mDefaultLineEdit );
3790 mSourceParamComboBox =
new QComboBox();
3791 mDestParamComboBox =
new QComboBox();
3792 QString initialSource;
3793 QString initialDest;
3798 initialSource = itemParam->sourceCrsParameterName();
3799 initialDest = itemParam->destinationCrsParameterName();
3804 mSourceParamComboBox->addItem( QString(), QString() );
3805 mDestParamComboBox->addItem( QString(), QString() );
3806 if (
auto *lModel = widgetContext.
model() )
3809 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3810 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3812 if ( definition && it->parameterName() == definition->
name() )
3816 mSourceParamComboBox->addItem( it->parameterName(), it->parameterName() );
3817 mDestParamComboBox->addItem( it->parameterName(), it->parameterName() );
3818 if ( !initialSource.isEmpty() && initialSource == it->parameterName() )
3820 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
3822 if ( !initialDest.isEmpty() && initialDest == it->parameterName() )
3824 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
3829 if ( mSourceParamComboBox->count() == 1 && !initialSource.isEmpty() )
3832 mSourceParamComboBox->addItem( initialSource, initialSource );
3833 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
3835 if ( mDestParamComboBox->count() == 1 && !initialDest.isEmpty() )
3838 mDestParamComboBox->addItem( initialDest, initialDest );
3839 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
3842 vlayout->addWidget(
new QLabel( tr(
"Source CRS parameter" ) ) );
3843 vlayout->addWidget( mSourceParamComboBox );
3844 vlayout->addWidget(
new QLabel( tr(
"Destination CRS parameter" ) ) );
3845 vlayout->addWidget( mDestParamComboBox );
3849 mStaticSourceWidget->setCrs( sourceCrs );
3852 mStaticDestWidget->setCrs( destCrs );
3854 vlayout->addWidget(
new QLabel( tr(
"Static source CRS" ) ) );
3855 vlayout->addWidget( mStaticSourceWidget );
3856 vlayout->addWidget(
new QLabel( tr(
"Static destination CRS" ) ) );
3857 vlayout->addWidget( mStaticDestWidget );
3859 setLayout( vlayout );
3862QgsProcessingParameterDefinition *QgsProcessingCoordinateOperationParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
3864 auto param = std::make_unique< QgsProcessingParameterCoordinateOperation >( name, description, mDefaultLineEdit->text(),
3865 mSourceParamComboBox->currentText(),
3866 mDestParamComboBox->currentText(),
3867 mStaticSourceWidget->crs().isValid() ? QVariant::fromValue( mStaticSourceWidget->crs() ) : QVariant(),
3868 mStaticDestWidget->crs().isValid() ? QVariant::fromValue( mStaticDestWidget->crs() ) : QVariant() );
3870 return param.release();
3879QWidget *QgsProcessingCoordinateOperationWidgetWrapper::createWidget()
3890 mOperationWidget->setShowMakeDefault(
false );
3891 mOperationWidget->setShowFallbackOption(
false );
3892 mOperationWidget->setToolTip( parameterDefinition()->toolTip() );
3893 mOperationWidget->setSourceCrs( mSourceCrs );
3894 mOperationWidget->setDestinationCrs( mDestCrs );
3895 mOperationWidget->setMapCanvas( mCanvas );
3900 mOperationWidget->setSelectedOperation( deets );
3905 emit widgetValueHasChanged(
this );
3908 return mOperationWidget;
3914 mLineEdit =
new QLineEdit();
3915 QHBoxLayout *layout =
new QHBoxLayout();
3916 layout->addWidget( mLineEdit, 1 );
3917 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
3919 emit widgetValueHasChanged(
this );
3922 QToolButton *button =
new QToolButton();
3923 button->setText( QString( QChar( 0x2026 ) ) );
3924 connect( button, &QToolButton::clicked,
this, [ = ]
3926 QgsDatumTransformDialog dlg( mSourceCrs, mDestCrs,
false,
false,
false, qMakePair( -1, -1 ), button, Qt::WindowFlags(), mLineEdit->text(), mCanvas );
3929 mLineEdit->setText( dlg.selectedDatumTransform().proj );
3930 emit widgetValueHasChanged(
this );
3933 layout->addWidget( button );
3935 QWidget *w =
new QWidget();
3936 layout->setContentsMargins( 0, 0, 0, 0 );
3937 w->setLayout( layout );
3945void QgsProcessingCoordinateOperationWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3957 setSourceCrsParameterValue( wrapper->parameterValue() );
3960 setSourceCrsParameterValue( wrapper->parameterValue() );
3965 setDestinationCrsParameterValue( wrapper->parameterValue() );
3968 setDestinationCrsParameterValue( wrapper->parameterValue() );
3983 if ( mOperationWidget )
3984 mOperationWidget->setMapCanvas( context.
mapCanvas() );
3987void QgsProcessingCoordinateOperationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
3989 if ( mOperationWidget )
3991 if ( !value.isValid() ||
3992 ( value.type() == QVariant::String ) )
3995 deets.
proj = value.toString();
3996 mOperationWidget->setSelectedOperation( deets );
4001 if ( !value.isValid() ||
4002 ( value.type() == QVariant::String ) )
4004 mLineEdit->setText( value.toString() );
4009QVariant QgsProcessingCoordinateOperationWidgetWrapper::widgetValue()
const
4011 if ( mOperationWidget )
4012 return mOperationWidget->selectedOperation().proj;
4013 else if ( mLineEdit )
4014 return mLineEdit->text();
4019QStringList QgsProcessingCoordinateOperationWidgetWrapper::compatibleParameterTypes()
const
4021 return QStringList()
4026QStringList QgsProcessingCoordinateOperationWidgetWrapper::compatibleOutputTypes()
const
4028 return QStringList()
4032QString QgsProcessingCoordinateOperationWidgetWrapper::modelerExpressionFormatString()
const
4034 return tr(
"Proj coordinate operation string, e.g. '+proj=pipeline +step +inv...'" );
4037void QgsProcessingCoordinateOperationWidgetWrapper::setSourceCrsParameterValue(
const QVariant &value )
4040 std::unique_ptr< QgsProcessingContext > tmpContext;
4041 if ( mProcessingContextGenerator )
4042 context = mProcessingContextGenerator->processingContext();
4046 tmpContext = std::make_unique< QgsProcessingContext >();
4047 context = tmpContext.get();
4051 if ( mOperationWidget )
4053 mOperationWidget->setSourceCrs( mSourceCrs );
4054 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4058void QgsProcessingCoordinateOperationWidgetWrapper::setDestinationCrsParameterValue(
const QVariant &value )
4061 std::unique_ptr< QgsProcessingContext > tmpContext;
4062 if ( mProcessingContextGenerator )
4063 context = mProcessingContextGenerator->processingContext();
4067 tmpContext = std::make_unique< QgsProcessingContext >();
4068 context = tmpContext.get();
4072 if ( mOperationWidget )
4074 mOperationWidget->setDestinationCrs( mDestCrs );
4075 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4079QString QgsProcessingCoordinateOperationWidgetWrapper::parameterType()
const
4086 return new QgsProcessingCoordinateOperationWidgetWrapper( parameter, type );
4091 return new QgsProcessingCoordinateOperationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4104 QHBoxLayout *hl =
new QHBoxLayout();
4105 hl->setContentsMargins( 0, 0, 0, 0 );
4107 mLineEdit =
new QLineEdit();
4108 mLineEdit->setEnabled(
false );
4109 hl->addWidget( mLineEdit, 1 );
4111 mToolButton =
new QToolButton();
4112 mToolButton->setText( QString( QChar( 0x2026 ) ) );
4113 hl->addWidget( mToolButton );
4119 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4122 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingFieldPanelWidget::showDialog );
4125void QgsProcessingFieldPanelWidget::setFields(
const QgsFields &fields )
4130void QgsProcessingFieldPanelWidget::setValue(
const QVariant &value )
4132 if ( value.isValid() )
4133 mValue = value.type() == QVariant::List ? value.
toList() : QVariantList() << value;
4137 updateSummaryText();
4141void QgsProcessingFieldPanelWidget::showDialog()
4143 QVariantList availableOptions;
4144 availableOptions.reserve( mFields.size() );
4153 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
4154 widget->setPanelTitle( mParam->description() );
4156 widget->setValueFormatter( [](
const QVariant & v ) -> QString
4158 return v.toString();
4161 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
4163 setValue( widget->selectedOptions() );
4170 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
4172 dlg.setValueFormatter( [](
const QVariant & v ) -> QString
4174 return v.toString();
4178 setValue( dlg.selectedOptions() );
4183void QgsProcessingFieldPanelWidget::updateSummaryText()
4188 if ( mValue.empty() )
4190 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4195 values.reserve( mValue.size() );
4196 for (
const QVariant &val : std::as_const( mValue ) )
4198 values << val.toString();
4201 const QString concatenated = values.join( tr(
"," ) );
4202 if ( concatenated.length() < 100 )
4203 mLineEdit->setText( concatenated );
4205 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, mValue.count() ) );
4217 QVBoxLayout *vlayout =
new QVBoxLayout();
4218 vlayout->setContentsMargins( 0, 0, 0, 0 );
4220 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
4221 mParentLayerComboBox =
new QComboBox();
4223 QString initialParent;
4225 initialParent = fieldParam->parentLayerParameterName();
4227 if (
auto *lModel = widgetContext.
model() )
4230 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4231 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4235 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
4236 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4238 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4243 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
4244 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4246 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4253 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
4254 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4256 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4263 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
4266 mParentLayerComboBox->addItem( initialParent, initialParent );
4267 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4270 vlayout->addWidget( mParentLayerComboBox );
4272 vlayout->addWidget(
new QLabel( tr(
"Allowed data type" ) ) );
4273 mDataTypeComboBox =
new QComboBox();
4279 mDataTypeComboBox->setCurrentIndex( mDataTypeComboBox->findData( fieldParam->dataType() ) );
4281 vlayout->addWidget( mDataTypeComboBox );
4283 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple fields" ) );
4285 mAllowMultipleCheckBox->setChecked( fieldParam->allowMultiple() );
4287 vlayout->addWidget( mAllowMultipleCheckBox );
4289 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all fields by default" ) );
4290 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
4292 mDefaultToAllCheckBox->setChecked( fieldParam->defaultToAllFields() );
4294 vlayout->addWidget( mDefaultToAllCheckBox );
4296 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [ = ]
4298 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
4301 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4303 mDefaultLineEdit =
new QLineEdit();
4304 mDefaultLineEdit->setToolTip( tr(
"Default field name, or ; separated list of field names for multiple field parameters" ) );
4308 mDefaultLineEdit->setText( fields.join(
';' ) );
4310 vlayout->addWidget( mDefaultLineEdit );
4312 setLayout( vlayout );
4315QgsProcessingParameterDefinition *QgsProcessingFieldParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4319 QVariant defaultValue;
4320 if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
4322 defaultValue = mDefaultLineEdit->text();
4324 auto param = std::make_unique< QgsProcessingParameterField >( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), dataType, mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
4326 return param.release();
4335QWidget *QgsProcessingFieldWidgetWrapper::createWidget()
4345 mPanel =
new QgsProcessingFieldPanelWidget(
nullptr, fieldParam );
4346 mPanel->setToolTip( parameterDefinition()->toolTip() );
4347 connect( mPanel, &QgsProcessingFieldPanelWidget::changed,
this, [ = ]
4349 emit widgetValueHasChanged(
this );
4365 mComboBox->setToolTip( parameterDefinition()->toolTip() );
4368 emit widgetValueHasChanged(
this );
4376 mLineEdit =
new QLineEdit();
4377 mLineEdit->setToolTip( QObject::tr(
"Name of field (separate field names with ; for multiple field parameters)" ) );
4378 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
4380 emit widgetValueHasChanged(
this );
4389void QgsProcessingFieldWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
4399 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterField *
>( parameterDefinition() )->parentLayerParameterName() )
4401 setParentLayerWrapperValue( wrapper );
4404 setParentLayerWrapperValue( wrapper );
4421 std::unique_ptr< QgsProcessingContext > tmpContext;
4422 if ( mProcessingContextGenerator )
4423 context = mProcessingContextGenerator->processingContext();
4427 tmpContext = std::make_unique< QgsProcessingContext >();
4428 context = tmpContext.get();
4433 if ( value.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
4443 bool valueSet =
false;
4447 if ( layers.count() > 1 )
4449 QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( layers.at( 0 ) );
4451 const QList< QgsMapLayer * > remainingLayers = layers.mid( 1 );
4457 QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( layer );
4458 if ( !vlayer || !vlayer->
isValid() )
4464 for (
int fieldIdx = fields.
count() - 1; fieldIdx >= 0; fieldIdx-- )
4467 fields.
remove( fieldIdx );
4472 mComboBox->setFields( fields );
4474 mPanel->setFields( filterFields( fields ) );
4480 if ( !valueSet && !layers.isEmpty() && layers.at( 0 )->isValid() )
4482 QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( layers.at( 0 ) );
4486 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
4487 if ( ownedLayer && ownedLayer->type() == Qgis::LayerType::Vector )
4489 mParentLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
4490 layer = mParentLayer.get();
4498 mComboBox->setLayer( layer );
4500 mPanel->setFields( filterFields( layer->
fields() ) );
4510 const QgsFields fields = source->fields();
4512 mComboBox->setFields( fields );
4514 mPanel->setFields( filterFields( fields ) );
4523 mComboBox->setLayer(
nullptr );
4527 if ( value.isValid() && widgetContext().messageBar() )
4530 widgetContext().
messageBar()->
pushMessage( QString(), QObject::tr(
"Could not load selected layer/table. Dependent field could not be populated" ),
4531 Qgis::MessageLevel::Info );
4540 val.reserve( mPanel->fields().size() );
4543 setWidgetValue( val, *context );
4546 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
4549void QgsProcessingFieldWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4553 if ( !value.isValid() )
4554 mComboBox->setField( QString() );
4558 mComboBox->setField( v );
4564 if ( value.isValid() )
4567 opts.reserve( v.size() );
4568 for (
const QString &i : v )
4572 mPanel->setValue( opts );
4574 else if ( mLineEdit )
4580 mLineEdit->setText( v.join(
';' ) );
4589QVariant QgsProcessingFieldWidgetWrapper::widgetValue()
const
4592 return mComboBox->currentField();
4594 return mPanel->value();
4595 else if ( mLineEdit )
4600 return mLineEdit->text().split(
';' );
4603 return mLineEdit->text();
4609QStringList QgsProcessingFieldWidgetWrapper::compatibleParameterTypes()
const
4611 return QStringList()
4616QStringList QgsProcessingFieldWidgetWrapper::compatibleOutputTypes()
const
4618 return QStringList()
4622QString QgsProcessingFieldWidgetWrapper::modelerExpressionFormatString()
const
4624 return tr(
"selected field names as an array of names, or semicolon separated string of options (e.g. 'fid;place_name')" );
4627const QgsVectorLayer *QgsProcessingFieldWidgetWrapper::linkedVectorLayer()
const
4629 if ( mComboBox && mComboBox->layer() )
4630 return mComboBox->layer();
4635QgsFields QgsProcessingFieldWidgetWrapper::filterFields(
const QgsFields &fields )
const
4648 if ( f.isNumeric() )
4653 if ( f.type() == QVariant::String )
4658 if ( f.type() == QVariant::Date || f.type() == QVariant::Time || f.type() == QVariant::DateTime )
4667QString QgsProcessingFieldWidgetWrapper::parameterType()
const
4674 return new QgsProcessingFieldWidgetWrapper( parameter, type );
4679 return new QgsProcessingFieldParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4690 QVBoxLayout *vlayout =
new QVBoxLayout();
4691 vlayout->setContentsMargins( 0, 0, 0, 0 );
4693 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4695 mDefaultComboBox =
new QComboBox();
4696 mDefaultComboBox->addItem( QString(), QVariant( -1 ) );
4699 for (
const QString &theme : mapThemes )
4703 mDefaultComboBox->setEditable(
true );
4707 if ( themeParam->defaultValueForGui().isValid() )
4710 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
4713 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
4715 vlayout->addWidget( mDefaultComboBox );
4717 setLayout( vlayout );
4720QgsProcessingParameterDefinition *QgsProcessingMapThemeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4722 QVariant defaultVal;
4723 if ( mDefaultComboBox->currentText().isEmpty() )
4724 defaultVal = QVariant();
4726 defaultVal = mDefaultComboBox->currentText();
4727 auto param = std::make_unique< QgsProcessingParameterMapTheme>( name, description, defaultVal );
4729 return param.release();
4739QWidget *QgsProcessingMapThemeWidgetWrapper::createWidget()
4743 mComboBox =
new QComboBox();
4746 mComboBox->addItem( tr(
"[Not selected]" ), QVariant( -1 ) );
4749 for (
const QString &theme : mapThemes )
4761 mComboBox->setEditable(
true );
4765 mComboBox->setToolTip( parameterDefinition()->toolTip() );
4766 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
4768 emit widgetValueHasChanged(
this );
4774void QgsProcessingMapThemeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4778 if ( !value.isValid() )
4779 mComboBox->setCurrentIndex( mComboBox->findData( QVariant( -1 ) ) );
4782 if ( mComboBox->isEditable() && mComboBox->findData( v ) == -1 )
4784 const QString prev = mComboBox->currentText();
4785 mComboBox->setCurrentText( v );
4787 emit widgetValueHasChanged(
this );
4790 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
4794QVariant QgsProcessingMapThemeWidgetWrapper::widgetValue()
const
4797 return mComboBox->currentData().toInt() == -1 ? QVariant() :
4798 !mComboBox->currentData().isValid() && mComboBox->isEditable() ? mComboBox->currentText().isEmpty() ? QVariant() : QVariant( mComboBox->currentText() )
4799 : mComboBox->currentData();
4804QStringList QgsProcessingMapThemeWidgetWrapper::compatibleParameterTypes()
const
4806 return QStringList()
4811QStringList QgsProcessingMapThemeWidgetWrapper::compatibleOutputTypes()
const
4813 return QStringList()
4817QString QgsProcessingMapThemeWidgetWrapper::modelerExpressionFormatString()
const
4819 return tr(
"map theme as a string value (e.g. 'base maps')" );
4822QString QgsProcessingMapThemeWidgetWrapper::parameterType()
const
4829 return new QgsProcessingMapThemeWidgetWrapper( parameter, type );
4834 return new QgsProcessingMapThemeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4847 QVBoxLayout *vlayout =
new QVBoxLayout();
4848 vlayout->setContentsMargins( 0, 0, 0, 0 );
4850 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
4852 mTypeComboBox =
new QComboBox();
4857 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( datetimeParam->dataType() ) );
4859 mTypeComboBox->setCurrentIndex( 0 );
4860 vlayout->addWidget( mTypeComboBox );
4862 setLayout( vlayout );
4865QgsProcessingParameterDefinition *QgsProcessingDateTimeParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
4867 auto param = std::make_unique< QgsProcessingParameterDateTime >( name, description );
4870 return param.release();
4880QWidget *QgsProcessingDateTimeWidgetWrapper::createWidget()
4885 switch ( dateTimeParam->
dataType() )
4889 widget = mDateTimeEdit;
4912 widget->setToolTip( parameterDefinition()->toolTip() );
4914 if ( mDateTimeEdit )
4918 emit widgetValueHasChanged(
this );
4921 else if ( mDateEdit )
4925 emit widgetValueHasChanged(
this );
4928 else if ( mTimeEdit )
4932 emit widgetValueHasChanged(
this );
4941 return new QgsProcessingDateTimeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4944void QgsProcessingDateTimeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4946 if ( mDateTimeEdit )
4950 else if ( mDateEdit )
4954 else if ( mTimeEdit )
4960QVariant QgsProcessingDateTimeWidgetWrapper::widgetValue()
const
4962 if ( mDateTimeEdit )
4963 return !mDateTimeEdit->dateTime().isNull() && mDateTimeEdit->dateTime().isValid() ? QVariant( mDateTimeEdit->dateTime() ) : QVariant();
4964 else if ( mDateEdit )
4965 return !mDateEdit->date().isNull() && mDateEdit->date().isValid() ? QVariant( mDateEdit->date() ) : QVariant();
4966 else if ( mTimeEdit )
4967 return !mTimeEdit->time().isNull() && mTimeEdit->time().isValid() ? QVariant( mTimeEdit->time() ) : QVariant();
4972QStringList QgsProcessingDateTimeWidgetWrapper::compatibleParameterTypes()
const
4974 return QStringList()
4979QStringList QgsProcessingDateTimeWidgetWrapper::compatibleOutputTypes()
const
4981 return QStringList()
4985QString QgsProcessingDateTimeWidgetWrapper::modelerExpressionFormatString()
const
4988 if ( dateTimeParam )
4990 switch ( dateTimeParam->
dataType() )
4993 return tr(
"datetime value, or a ISO string representation of a datetime" );
4996 return tr(
"date value, or a ISO string representation of a date" );
4999 return tr(
"time value, or a ISO string representation of a time" );
5005QString QgsProcessingDateTimeWidgetWrapper::parameterType()
const
5012 return new QgsProcessingDateTimeWidgetWrapper( parameter, type );
5026 QVBoxLayout *vlayout =
new QVBoxLayout();
5027 vlayout->setContentsMargins( 0, 0, 0, 0 );
5029 vlayout->addWidget(
new QLabel( tr(
"Provider" ) ) );
5030 mProviderComboBox =
new QComboBox();
5031 mProviderComboBox->addItem( QObject::tr(
"Postgres" ), QStringLiteral(
"postgres" ) );
5032 mProviderComboBox->addItem( QObject::tr(
"GeoPackage" ), QStringLiteral(
"ogr" ) );
5033 mProviderComboBox->addItem( QObject::tr(
"Spatialite" ), QStringLiteral(
"spatialite" ) );
5035 vlayout->addWidget( mProviderComboBox );
5037 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5039 mDefaultEdit =
new QLineEdit();
5040 vlayout->addWidget( mDefaultEdit );
5041 setLayout( vlayout );
5043 if ( connectionParam )
5045 mProviderComboBox->setCurrentIndex( mProviderComboBox->findData( connectionParam->
providerId() ) );
5050QgsProcessingParameterDefinition *QgsProcessingProviderConnectionParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5052 QVariant defaultVal;
5053 if ( mDefaultEdit->text().isEmpty() )
5054 defaultVal = QVariant();
5056 defaultVal = mDefaultEdit->text();
5057 auto param = std::make_unique< QgsProcessingParameterProviderConnection>( name, description, mProviderComboBox->currentData().toString(), defaultVal );
5059 return param.release();
5069QWidget *QgsProcessingProviderConnectionWidgetWrapper::createWidget()
5075 mProviderComboBox->setAllowEmptyConnection(
true );
5083 mProviderComboBox->setEditable(
true );
5087 mProviderComboBox->setToolTip( parameterDefinition()->toolTip() );
5088 connect( mProviderComboBox, &QgsProviderConnectionComboBox::currentTextChanged,
this, [ = ](
const QString & )
5090 if ( mBlockSignals )
5093 emit widgetValueHasChanged(
this );
5096 return mProviderComboBox;
5101 return new QgsProcessingProviderConnectionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5104void QgsProcessingProviderConnectionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5108 if ( !value.isValid() )
5109 mProviderComboBox->setCurrentIndex( -1 );
5112 if ( mProviderComboBox->isEditable() )
5114 const QString prev = mProviderComboBox->currentText();
5116 mProviderComboBox->setConnection( v );
5117 mProviderComboBox->setCurrentText( v );
5121 emit widgetValueHasChanged(
this );
5124 mProviderComboBox->setConnection( v );
5128QVariant QgsProcessingProviderConnectionWidgetWrapper::widgetValue()
const
5130 if ( mProviderComboBox )
5131 if ( mProviderComboBox->isEditable() )
5132 return mProviderComboBox->currentText().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentText() );
5134 return mProviderComboBox->currentConnection().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentConnection() );
5139QStringList QgsProcessingProviderConnectionWidgetWrapper::compatibleParameterTypes()
const
5141 return QStringList()
5147QStringList QgsProcessingProviderConnectionWidgetWrapper::compatibleOutputTypes()
const
5149 return QStringList()
5153QString QgsProcessingProviderConnectionWidgetWrapper::modelerExpressionFormatString()
const
5155 return tr(
"connection name as a string value" );
5158QString QgsProcessingProviderConnectionWidgetWrapper::parameterType()
const
5165 return new QgsProcessingProviderConnectionWidgetWrapper( parameter, type );
5180 QVBoxLayout *vlayout =
new QVBoxLayout();
5181 vlayout->setContentsMargins( 0, 0, 0, 0 );
5183 mConnectionParamComboBox =
new QComboBox();
5184 QString initialConnection;
5190 if (
auto *lModel = widgetContext.
model() )
5193 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
5194 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
5196 if ( definition && it->parameterName() == definition->
name() )
5202 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
5203 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5205 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5210 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
5213 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
5214 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5217 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
5218 vlayout->addWidget( mConnectionParamComboBox );
5220 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5222 mDefaultEdit =
new QLineEdit();
5223 vlayout->addWidget( mDefaultEdit );
5224 setLayout( vlayout );
5232QgsProcessingParameterDefinition *QgsProcessingDatabaseSchemaParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5234 QVariant defaultVal;
5235 if ( mDefaultEdit->text().isEmpty() )
5236 defaultVal = QVariant();
5238 defaultVal = mDefaultEdit->text();
5239 auto param = std::make_unique< QgsProcessingParameterDatabaseSchema>( name, description, mConnectionParamComboBox->currentData().toString(), defaultVal );
5241 return param.release();
5251QWidget *QgsProcessingDatabaseSchemaWidgetWrapper::createWidget()
5257 mSchemaComboBox->setAllowEmptySchema(
true );
5265 mSchemaComboBox->comboBox()->setEditable(
true );
5269 mSchemaComboBox->setToolTip( parameterDefinition()->toolTip() );
5270 connect( mSchemaComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
5272 if ( mBlockSignals )
5275 emit widgetValueHasChanged( this );
5278 return mSchemaComboBox;
5283 return new QgsProcessingDatabaseSchemaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5290 std::unique_ptr< QgsProcessingContext > tmpContext;
5291 if ( mProcessingContextGenerator )
5292 context = mProcessingContextGenerator->processingContext();
5296 tmpContext = std::make_unique< QgsProcessingContext >();
5297 context = tmpContext.get();
5303 if ( mSchemaComboBox )
5304 mSchemaComboBox->setConnectionName( connection, qgis::down_cast< const QgsProcessingParameterProviderConnection * >( parentWrapper->
parameterDefinition() )->providerId() );
5308 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5311void QgsProcessingDatabaseSchemaWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5315 if ( !value.isValid() )
5316 mSchemaComboBox->comboBox()->setCurrentIndex( -1 );
5319 if ( mSchemaComboBox->comboBox()->isEditable() )
5321 const QString prev = mSchemaComboBox->comboBox()->currentText();
5323 mSchemaComboBox->setSchema( v );
5324 mSchemaComboBox->comboBox()->setCurrentText( v );
5328 emit widgetValueHasChanged(
this );
5331 mSchemaComboBox->setSchema( v );
5335QVariant QgsProcessingDatabaseSchemaWidgetWrapper::widgetValue()
const
5337 if ( mSchemaComboBox )
5338 if ( mSchemaComboBox->comboBox()->isEditable() )
5339 return mSchemaComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->comboBox()->currentText() );
5341 return mSchemaComboBox->currentSchema().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->currentSchema() );
5346QStringList QgsProcessingDatabaseSchemaWidgetWrapper::compatibleParameterTypes()
const
5348 return QStringList()
5354QStringList QgsProcessingDatabaseSchemaWidgetWrapper::compatibleOutputTypes()
const
5356 return QStringList()
5360QString QgsProcessingDatabaseSchemaWidgetWrapper::modelerExpressionFormatString()
const
5362 return tr(
"database schema name as a string value" );
5365QString QgsProcessingDatabaseSchemaWidgetWrapper::parameterType()
const
5372 return new QgsProcessingDatabaseSchemaWidgetWrapper( parameter, type );
5375void QgsProcessingDatabaseSchemaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5387 setParentConnectionWrapperValue( wrapper );
5390 setParentConnectionWrapperValue( wrapper );
5414 QVBoxLayout *vlayout =
new QVBoxLayout();
5415 vlayout->setContentsMargins( 0, 0, 0, 0 );
5417 mConnectionParamComboBox =
new QComboBox();
5418 mSchemaParamComboBox =
new QComboBox();
5419 QString initialConnection;
5420 QString initialSchema;
5427 if (
auto *lModel = widgetContext.
model() )
5430 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
5431 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
5433 if ( definition && it->parameterName() == definition->
name() )
5438 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
5439 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5441 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5446 mSchemaParamComboBox->addItem( it->parameterName(), it->parameterName() );
5447 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5449 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
5455 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
5458 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
5459 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5462 if ( mSchemaParamComboBox->count() == 0 && !initialSchema.isEmpty() )
5465 mSchemaParamComboBox->addItem( initialSchema, initialSchema );
5466 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
5469 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
5470 vlayout->addWidget( mConnectionParamComboBox );
5472 vlayout->addWidget(
new QLabel( tr(
"Database schema parameter" ) ) );
5473 vlayout->addWidget( mSchemaParamComboBox );
5475 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5477 mDefaultEdit =
new QLineEdit();
5478 vlayout->addWidget( mDefaultEdit );
5479 setLayout( vlayout );
5487QgsProcessingParameterDefinition *QgsProcessingDatabaseTableParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5489 QVariant defaultVal;
5490 if ( mDefaultEdit->text().isEmpty() )
5491 defaultVal = QVariant();
5493 defaultVal = mDefaultEdit->text();
5494 auto param = std::make_unique< QgsProcessingParameterDatabaseTable>( name, description,
5495 mConnectionParamComboBox->currentData().toString(),
5496 mSchemaParamComboBox->currentData().toString(),
5499 return param.release();
5509QWidget *QgsProcessingDatabaseTableWidgetWrapper::createWidget()
5515 mTableComboBox->setAllowEmptyTable(
true );
5518 mTableComboBox->comboBox()->setEditable(
true );
5520 mTableComboBox->setToolTip( parameterDefinition()->toolTip() );
5521 connect( mTableComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [ = ](
const QString & )
5523 if ( mBlockSignals )
5526 emit widgetValueHasChanged( this );
5529 return mTableComboBox;
5534 return new QgsProcessingDatabaseTableParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5541 std::unique_ptr< QgsProcessingContext > tmpContext;
5542 if ( mProcessingContextGenerator )
5543 context = mProcessingContextGenerator->processingContext();
5547 tmpContext = std::make_unique< QgsProcessingContext >();
5548 context = tmpContext.get();
5553 mProvider = qgis::down_cast< const QgsProcessingParameterProviderConnection * >( parentWrapper->
parameterDefinition() )->providerId();
5554 if ( mTableComboBox && !mSchema.isEmpty() )
5556 mTableComboBox->setSchema( mSchema );
5557 mTableComboBox->setConnectionName( mConnection, mProvider );
5561 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5569 std::unique_ptr< QgsProcessingContext > tmpContext;
5570 if ( mProcessingContextGenerator )
5571 context = mProcessingContextGenerator->processingContext();
5575 tmpContext = std::make_unique< QgsProcessingContext >();
5576 context = tmpContext.get();
5582 if ( mTableComboBox && !mSchema.isEmpty() && !mConnection.isEmpty() )
5584 mTableComboBox->setSchema( mSchema );
5585 mTableComboBox->setConnectionName( mConnection, mProvider );
5589 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5594void QgsProcessingDatabaseTableWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5598 if ( !value.isValid() )
5599 mTableComboBox->comboBox()->setCurrentIndex( -1 );
5602 if ( mTableComboBox->comboBox()->isEditable() )
5604 const QString prev = mTableComboBox->comboBox()->currentText();
5606 mTableComboBox->setTable( v );
5607 mTableComboBox->comboBox()->setCurrentText( v );
5611 emit widgetValueHasChanged(
this );
5614 mTableComboBox->setTable( v );
5618QVariant QgsProcessingDatabaseTableWidgetWrapper::widgetValue()
const
5620 if ( mTableComboBox )
5621 if ( mTableComboBox->comboBox()->isEditable() )
5622 return mTableComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mTableComboBox->comboBox()->currentText() );
5624 return mTableComboBox->currentTable().isEmpty() ? QVariant() : QVariant( mTableComboBox->currentTable() );
5629QStringList QgsProcessingDatabaseTableWidgetWrapper::compatibleParameterTypes()
const
5631 return QStringList()
5637QStringList QgsProcessingDatabaseTableWidgetWrapper::compatibleOutputTypes()
const
5639 return QStringList()
5643QString QgsProcessingDatabaseTableWidgetWrapper::modelerExpressionFormatString()
const
5645 return tr(
"database table name as a string value" );
5648QString QgsProcessingDatabaseTableWidgetWrapper::parameterType()
const
5655 return new QgsProcessingDatabaseTableWidgetWrapper( parameter, type );
5658void QgsProcessingDatabaseTableWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5670 setParentConnectionWrapperValue( wrapper );
5673 setParentConnectionWrapperValue( wrapper );
5678 setParentSchemaWrapperValue( wrapper );
5681 setParentSchemaWrapperValue( wrapper );
5701 QVBoxLayout *vlayout =
new QVBoxLayout();
5702 vlayout->setContentsMargins( 0, 0, 0, 0 );
5704 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5707 mDefaultWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
5710 if ( extentParam->defaultValueForGui().isValid() )
5714 mDefaultWidget->setCurrentExtent( rect,
crs );
5715 mDefaultWidget->setOutputExtentFromCurrent();
5719 mDefaultWidget->clear();
5723 vlayout->addWidget( mDefaultWidget );
5724 setLayout( vlayout );
5727QgsProcessingParameterDefinition *QgsProcessingExtentParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5729 const QString defaultVal = mDefaultWidget->isValid() ? QStringLiteral(
"%1,%2,%3,%4%5" ).arg(
5730 QString::number( mDefaultWidget->outputExtent().xMinimum(),
'f', 9 ),
5731 QString::number( mDefaultWidget->outputExtent().xMaximum(),
'f', 9 ),
5732 QString::number( mDefaultWidget->outputExtent().yMinimum(),
'f', 9 ),
5733 QString::number( mDefaultWidget->outputExtent().yMaximum(),
'f', 9 ),
5734 mDefaultWidget->outputCrs().isValid() ? QStringLiteral(
" [%1]" ).arg( mDefaultWidget->outputCrs().authid() ) : QString()
5736 auto param = std::make_unique< QgsProcessingParameterExtent >( name, description, !defaultVal.isEmpty() ? QVariant( defaultVal ) : QVariant() );
5738 return param.release();
5749QWidget *QgsProcessingExtentWidgetWrapper::createWidget()
5759 if ( widgetContext().mapCanvas() )
5760 mExtentWidget->setMapCanvas( widgetContext().mapCanvas() );
5763 mExtentWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
5765 mExtentWidget->setToolTip( parameterDefinition()->toolTip() );
5769 emit widgetValueHasChanged(
this );
5773 setDialog( mDialog );
5775 return mExtentWidget;
5785 mExtentWidget->setMapCanvas( context.
mapCanvas() );
5788void QgsProcessingExtentWidgetWrapper::setDialog( QDialog *dialog )
5796 mDialog->showMinimized();
5799 mDialog->showNormal();
5801 mDialog->activateWindow();
5808void QgsProcessingExtentWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5810 if ( mExtentWidget )
5812 if ( !value.isValid() || ( value.type() == QVariant::String && value.toString().isEmpty() ) )
5813 mExtentWidget->clear();
5818 mExtentWidget->setCurrentExtent( r,
crs );
5819 mExtentWidget->setOutputExtentFromUser( r,
crs );
5824QVariant QgsProcessingExtentWidgetWrapper::widgetValue()
const
5826 if ( mExtentWidget )
5828 const QString val = mExtentWidget->isValid() ? QStringLiteral(
"%1,%2,%3,%4%5" ).arg(
5829 QString::number( mExtentWidget->outputExtent().xMinimum(),
'f', 9 ),
5830 QString::number( mExtentWidget->outputExtent().xMaximum(),
'f', 9 ),
5831 QString::number( mExtentWidget->outputExtent().yMinimum(),
'f', 9 ),
5832 QString::number( mExtentWidget->outputExtent().yMaximum(),
'f', 9 ),
5833 mExtentWidget->outputCrs().isValid() ? QStringLiteral(
" [%1]" ).arg( mExtentWidget->outputCrs().authid() ) : QString()
5836 return val.isEmpty() ? QVariant() : QVariant( val );
5842QStringList QgsProcessingExtentWidgetWrapper::compatibleParameterTypes()
const
5844 return QStringList()
5856QStringList QgsProcessingExtentWidgetWrapper::compatibleOutputTypes()
const
5858 return QStringList()
5865QString QgsProcessingExtentWidgetWrapper::modelerExpressionFormatString()
const
5867 return tr(
"string of the format 'x min,x max,y min,y max' or a geometry value (bounding box is used)" );
5870QString QgsProcessingExtentWidgetWrapper::parameterType()
const
5877 return new QgsProcessingExtentWidgetWrapper( parameter, type );
5882 return new QgsProcessingExtentParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5894 QVBoxLayout *vlayout =
new QVBoxLayout();
5895 vlayout->setContentsMargins( 0, 0, 0, 0 );
5897 vlayout->addWidget(
new QLabel( tr(
"Layer type" ) ) );
5912 for (
int i : layerParam->dataTypes() )
5914 mLayerTypeComboBox->setItemCheckState( mLayerTypeComboBox->findData( i ), Qt::Checked );
5918 vlayout->addWidget( mLayerTypeComboBox );
5920 setLayout( vlayout );
5923QgsProcessingParameterDefinition *QgsProcessingMapLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
5925 QList< int > dataTypes;
5926 for (
const QVariant &v : mLayerTypeComboBox->checkedItemsData() )
5927 dataTypes << v.toInt();
5929 auto param = std::make_unique< QgsProcessingParameterMapLayer >( name, description );
5930 param->setDataTypes( dataTypes );
5932 return param.release();
5941QWidget *QgsProcessingMapLayerWidgetWrapper::createWidget()
5943 mComboBox =
new QgsProcessingMapLayerComboBox( parameterDefinition(), type() );
5951 mComboBox->setEditable(
true );
5955 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5957 connect( mComboBox, &QgsProcessingMapLayerComboBox::valueChanged,
this, [ = ]()
5959 if ( mBlockSignals )
5962 emit widgetValueHasChanged(
this );
5965 setWidgetContext( widgetContext() );
5974 mComboBox->setWidgetContext( context );
5979 if ( !parameterDefinition()->defaultValueForGui().isValid() )
5985void QgsProcessingMapLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5988 mComboBox->setValue( value, context );
5991QVariant QgsProcessingMapLayerWidgetWrapper::widgetValue()
const
5993 return mComboBox ? mComboBox->value() : QVariant();
5996QStringList QgsProcessingMapLayerWidgetWrapper::compatibleParameterTypes()
const
5998 return QStringList()
6009QStringList QgsProcessingMapLayerWidgetWrapper::compatibleOutputTypes()
const
6011 return QStringList()
6019QString QgsProcessingMapLayerWidgetWrapper::modelerExpressionFormatString()
const
6021 return tr(
"path to a map layer" );
6026 return QgsProcessingModelChildParameterSource::ModelParameter;
6029QString QgsProcessingMapLayerWidgetWrapper::parameterType()
const
6036 return new QgsProcessingMapLayerWidgetWrapper( parameter, type );
6041 return new QgsProcessingMapLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6050 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6055QStringList QgsProcessingRasterLayerWidgetWrapper::compatibleParameterTypes()
const
6057 return QStringList()
6064QStringList QgsProcessingRasterLayerWidgetWrapper::compatibleOutputTypes()
const
6066 return QStringList()
6074QString QgsProcessingRasterLayerWidgetWrapper::modelerExpressionFormatString()
const
6076 return tr(
"path to a raster layer" );
6079QString QgsProcessingRasterLayerWidgetWrapper::parameterType()
const
6086 return new QgsProcessingRasterLayerWidgetWrapper( parameter, type );
6091 Q_UNUSED( context );
6092 Q_UNUSED( widgetContext );
6093 Q_UNUSED( definition );
6107 QVBoxLayout *vlayout =
new QVBoxLayout();
6108 vlayout->setContentsMargins( 0, 0, 0, 0 );
6110 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6120 for (
int i : vectorParam->dataTypes() )
6122 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6126 vlayout->addWidget( mGeometryTypeComboBox );
6128 setLayout( vlayout );
6131QgsProcessingParameterDefinition *QgsProcessingVectorLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6133 QList< int > dataTypes;
6134 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6135 dataTypes << v.toInt();
6137 auto param = std::make_unique< QgsProcessingParameterVectorLayer >( name, description, dataTypes );
6139 return param.release();
6144 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6149QStringList QgsProcessingVectorLayerWidgetWrapper::compatibleParameterTypes()
const
6151 return QStringList()
6158QStringList QgsProcessingVectorLayerWidgetWrapper::compatibleOutputTypes()
const
6160 return QStringList()
6168QString QgsProcessingVectorLayerWidgetWrapper::modelerExpressionFormatString()
const
6170 return tr(
"path to a vector layer" );
6176 return param->dataTypes();
6178 return QList< int >();
6181QString QgsProcessingVectorLayerWidgetWrapper::parameterType()
const
6188 return new QgsProcessingVectorLayerWidgetWrapper( parameter, type );
6193 return new QgsProcessingVectorLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6205 QVBoxLayout *vlayout =
new QVBoxLayout();
6206 vlayout->setContentsMargins( 0, 0, 0, 0 );
6208 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6218 for (
int i : sourceParam->dataTypes() )
6220 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6228 vlayout->addWidget( mGeometryTypeComboBox );
6230 setLayout( vlayout );
6233QgsProcessingParameterDefinition *QgsProcessingFeatureSourceParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6235 QList< int > dataTypes;
6236 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6237 dataTypes << v.toInt();
6239 auto param = std::make_unique< QgsProcessingParameterFeatureSource >( name, description, dataTypes );
6241 return param.release();
6245 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6250QStringList QgsProcessingFeatureSourceWidgetWrapper::compatibleParameterTypes()
const
6252 return QStringList()
6260QStringList QgsProcessingFeatureSourceWidgetWrapper::compatibleOutputTypes()
const
6262 return QStringList()
6270QString QgsProcessingFeatureSourceWidgetWrapper::modelerExpressionFormatString()
const
6272 return tr(
"path to a vector layer" );
6278 return param->dataTypes();
6280 return QList< int >();
6283QString QgsProcessingFeatureSourceWidgetWrapper::parameterType()
const
6290 return new QgsProcessingFeatureSourceWidgetWrapper( parameter, type );
6295 return new QgsProcessingFeatureSourceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6303 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6308QStringList QgsProcessingMeshLayerWidgetWrapper::compatibleParameterTypes()
const
6310 return QStringList()
6317QStringList QgsProcessingMeshLayerWidgetWrapper::compatibleOutputTypes()
const
6319 return QStringList()
6327QString QgsProcessingMeshLayerWidgetWrapper::modelerExpressionFormatString()
const
6329 return tr(
"path to a mesh layer" );
6332QString QgsProcessingMeshLayerWidgetWrapper::parameterType()
const
6339 return new QgsProcessingMeshLayerWidgetWrapper( parameter, type );
6344 Q_UNUSED( context );
6345 Q_UNUSED( widgetContext );
6346 Q_UNUSED( definition );
6358QgsProcessingRasterBandPanelWidget::QgsProcessingRasterBandPanelWidget( QWidget *parent,
const QgsProcessingParameterBand *param )
6362 QHBoxLayout *hl =
new QHBoxLayout();
6363 hl->setContentsMargins( 0, 0, 0, 0 );
6365 mLineEdit =
new QLineEdit();
6366 mLineEdit->setEnabled(
false );
6367 hl->addWidget( mLineEdit, 1 );
6369 mToolButton =
new QToolButton();
6370 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6371 hl->addWidget( mToolButton );
6377 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, 0 ) );
6380 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingRasterBandPanelWidget::showDialog );
6383void QgsProcessingRasterBandPanelWidget::setBands(
const QList< int > &bands )
6388void QgsProcessingRasterBandPanelWidget::setBandNames(
const QHash<int, QString> &names )
6393void QgsProcessingRasterBandPanelWidget::setValue(
const QVariant &value )
6395 if ( value.isValid() )
6396 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
6400 updateSummaryText();
6404void QgsProcessingRasterBandPanelWidget::showDialog()
6406 QVariantList availableOptions;
6407 availableOptions.reserve( mBands.size() );
6408 for (
int band : std::as_const( mBands ) )
6410 availableOptions << band;
6416 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
6417 widget->setPanelTitle( mParam->description() );
6419 widget->setValueFormatter( [
this](
const QVariant & v ) -> QString
6421 int band = v.toInt();
6422 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6425 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
6427 setValue( widget->selectedOptions() );
6434 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
6436 dlg.setValueFormatter( [
this](
const QVariant & v ) -> QString
6438 int band = v.toInt();
6439 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6443 setValue( dlg.selectedOptions() );
6448void QgsProcessingRasterBandPanelWidget::updateSummaryText()
6451 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, mValue.count() ) );
6463 QVBoxLayout *vlayout =
new QVBoxLayout();
6464 vlayout->setContentsMargins( 0, 0, 0, 0 );
6466 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6468 mDefaultLineEdit =
new QLineEdit();
6469 mDefaultLineEdit->setToolTip( tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6474 for (
int b : bands )
6476 defVal << QString::number( b );
6479 mDefaultLineEdit->setText( defVal.join(
';' ) );
6481 vlayout->addWidget( mDefaultLineEdit );
6483 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
6484 mParentLayerComboBox =
new QComboBox();
6486 QString initialParent;
6488 initialParent = bandParam->parentLayerParameterName();
6490 if (
auto *lModel = widgetContext.
model() )
6493 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6494 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6498 mParentLayerComboBox-> addItem( definition->
description(), definition->
name() );
6499 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
6501 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6507 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
6510 mParentLayerComboBox->addItem( initialParent, initialParent );
6511 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6514 vlayout->addWidget( mParentLayerComboBox );
6516 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Allow multiple" ) );
6518 mAllowMultipleCheckBox->setChecked( bandParam->allowMultiple() );
6520 vlayout->addWidget( mAllowMultipleCheckBox );
6521 setLayout( vlayout );
6524QgsProcessingParameterDefinition *QgsProcessingBandParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
6526 auto param = std::make_unique< QgsProcessingParameterBand >( name, description, mDefaultLineEdit->text().split(
';' ), mParentLayerComboBox->currentData().toString(),
false, mAllowMultipleCheckBox->isChecked() );
6528 return param.release();
6537QWidget *QgsProcessingBandWidgetWrapper::createWidget()
6547 mPanel =
new QgsProcessingRasterBandPanelWidget(
nullptr, bandParam );
6548 mPanel->setToolTip( parameterDefinition()->toolTip() );
6549 connect( mPanel, &QgsProcessingRasterBandPanelWidget::changed,
this, [ = ]
6551 emit widgetValueHasChanged(
this );
6560 mComboBox->setToolTip( parameterDefinition()->toolTip() );
6563 emit widgetValueHasChanged(
this );
6571 mLineEdit =
new QLineEdit();
6572 mLineEdit->setToolTip( QObject::tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6573 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
6575 emit widgetValueHasChanged(
this );
6584void QgsProcessingBandWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6594 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterBand *
>( parameterDefinition() )->parentLayerParameterName() )
6596 setParentLayerWrapperValue( wrapper );
6599 setParentLayerWrapperValue( wrapper );
6616 std::unique_ptr< QgsProcessingContext > tmpContext;
6617 if ( mProcessingContextGenerator )
6618 context = mProcessingContextGenerator->processingContext();
6622 tmpContext = std::make_unique< QgsProcessingContext >();
6623 context = tmpContext.get();
6629 if ( layer && layer->
isValid() )
6633 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
6634 if ( ownedLayer && ownedLayer->type() == Qgis::LayerType::Raster )
6636 mParentLayer.reset( qobject_cast< QgsRasterLayer * >( ownedLayer.release() ) );
6637 layer = mParentLayer.get();
6645 mComboBox->setLayer( layer );
6649 if ( provider && layer->
isValid() )
6654 QHash< int, QString > bandNames;
6655 for (
int i = 1; i <= nBands; ++i )
6660 mPanel->setBands( bands );
6661 mPanel->setBandNames( bandNames );
6668 mComboBox->setLayer(
nullptr );
6670 mPanel->setBands( QList< int >() );
6672 if ( value.isValid() && widgetContext().messageBar() )
6675 widgetContext().
messageBar()->
pushMessage( QString(), QObject::tr(
"Could not load selected layer/table. Dependent bands could not be populated" ),
6676 Qgis::MessageLevel::Info );
6680 if ( parameterDefinition()->defaultValueForGui().isValid() )
6681 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6684void QgsProcessingBandWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6688 if ( !value.isValid() )
6689 mComboBox->setBand( -1 );
6693 mComboBox->setBand( v );
6699 if ( value.isValid() )
6702 opts.reserve( v.size() );
6707 mPanel->setValue( value.isValid() ? opts : QVariant() );
6709 else if ( mLineEdit )
6716 opts.reserve( v.size() );
6718 opts << QString::number( i );
6719 mLineEdit->setText( value.isValid() && !opts.empty() ? opts.join(
';' ) : QString() );
6723 if ( value.isValid() )
6731QVariant QgsProcessingBandWidgetWrapper::widgetValue()
const
6734 return mComboBox->currentBand() == -1 ? QVariant() : mComboBox->currentBand();
6736 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
6737 else if ( mLineEdit )
6742#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
6743 const QStringList parts = mLineEdit->text().split(
';', QString::SkipEmptyParts );
6745 const QStringList parts = mLineEdit->text().split(
';', Qt::SkipEmptyParts );
6748 res.reserve( parts.count() );
6749 for (
const QString &s : parts )
6752 int band = s.toInt( &ok );
6756 return res.
isEmpty() ? QVariant() : res;
6760 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
6767QStringList QgsProcessingBandWidgetWrapper::compatibleParameterTypes()
const
6769 return QStringList()
6774QStringList QgsProcessingBandWidgetWrapper::compatibleOutputTypes()
const
6776 return QStringList()
6780QString QgsProcessingBandWidgetWrapper::modelerExpressionFormatString()
const
6782 return tr(
"selected band numbers as an array of numbers, or semicolon separated string of options (e.g. '1;3')" );
6785QString QgsProcessingBandWidgetWrapper::parameterType()
const
6792 return new QgsProcessingBandWidgetWrapper( parameter, type );
6797 return new QgsProcessingBandParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6810 QHBoxLayout *hl =
new QHBoxLayout();
6811 hl->setContentsMargins( 0, 0, 0, 0 );
6813 mLineEdit =
new QLineEdit();
6814 mLineEdit->setEnabled(
false );
6815 hl->addWidget( mLineEdit, 1 );
6817 mToolButton =
new QToolButton();
6818 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6819 hl->addWidget( mToolButton );
6825 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, 0 ) );
6828 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingMultipleLayerPanelWidget::showDialog );
6831void QgsProcessingMultipleLayerPanelWidget::setValue(
const QVariant &value )
6833 if ( value.isValid() )
6834 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
6838 updateSummaryText();
6842void QgsProcessingMultipleLayerPanelWidget::setProject(
QgsProject *project )
6849 if ( mValue.removeAll( layerId ) )
6851 updateSummaryText();
6858void QgsProcessingMultipleLayerPanelWidget::setModel( QgsProcessingModelAlgorithm *model,
const QString &modelChildAlgorithmID )
6864 switch ( mParam->layerType() )
7013void QgsProcessingMultipleLayerPanelWidget::showDialog()
7018 QgsProcessingMultipleInputPanelWidget *widget =
new QgsProcessingMultipleInputPanelWidget( mParam, mValue, mModelSources, mModel );
7019 widget->setPanelTitle( mParam->description() );
7020 widget->setProject( mProject );
7021 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
7023 setValue( widget->selectedOptions() );
7030 QgsProcessingMultipleInputDialog dlg( mParam, mValue, mModelSources, mModel,
this, Qt::WindowFlags() );
7031 dlg.setProject( mProject );
7034 setValue( dlg.selectedOptions() );
7039void QgsProcessingMultipleLayerPanelWidget::updateSummaryText()
7042 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, mValue.count() ) );
7052 QVBoxLayout *vlayout =
new QVBoxLayout();
7053 vlayout->setContentsMargins( 0, 0, 0, 0 );
7055 vlayout->addWidget(
new QLabel( tr(
"Allowed layer type" ) ) );
7056 mLayerTypeComboBox =
new QComboBox();
7070 mLayerTypeComboBox->setCurrentIndex( mLayerTypeComboBox->findData( layersParam->layerType() ) );
7072 vlayout->addWidget( mLayerTypeComboBox );
7073 setLayout( vlayout );
7076QgsProcessingParameterDefinition *QgsProcessingMultipleLayerParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const
7078 auto param = std::make_unique< QgsProcessingParameterMultipleLayers >( name, description,
static_cast< QgsProcessing::SourceType >( mLayerTypeComboBox->currentData().toInt() ) );
7080 return param.release();
7089QWidget *QgsProcessingMultipleLayerWidgetWrapper::createWidget()
7093 mPanel =
new QgsProcessingMultipleLayerPanelWidget(
nullptr, layerParam );
7094 mPanel->setToolTip( parameterDefinition()->toolTip() );
7095 mPanel->setProject( widgetContext().project() );
7097 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7098 connect( mPanel, &QgsProcessingMultipleLayerPanelWidget::changed,
this, [ = ]
7100 emit widgetValueHasChanged(
this );
7110 mPanel->setProject( context.
project() );
7112 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7116void QgsProcessingMultipleLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7121 if ( value.isValid() )
7124 opts.reserve( v.size() );
7126 opts << l->source();
7129 for (
const QVariant &v : value.toList() )
7131 if ( v.userType() == QMetaType::type(
"QgsProcessingModelChildParameterSource" ) )
7133 const QgsProcessingModelChildParameterSource source = v.value< QgsProcessingModelChildParameterSource >();
7134 opts << QVariant::fromValue( source );
7139 mPanel->setValue( value.isValid() ? opts : QVariant() );
7143QVariant QgsProcessingMultipleLayerWidgetWrapper::widgetValue()
const
7146 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
7151QStringList QgsProcessingMultipleLayerWidgetWrapper::compatibleParameterTypes()
const
7153 return QStringList()
7164QStringList QgsProcessingMultipleLayerWidgetWrapper::compatibleOutputTypes()
const
7166 return QStringList()
7175QString QgsProcessingMultipleLayerWidgetWrapper::modelerExpressionFormatString()
const
7177 return tr(
"an array of layer paths, or semicolon separated string of layer paths" );
7180QString QgsProcessingMultipleLayerWidgetWrapper::parameterType()
const
7187 return new QgsProcessingMultipleLayerWidgetWrapper( parameter, type );
7192 return new QgsProcessingMultipleLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
7201 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
7206QStringList QgsProcessingPointCloudLayerWidgetWrapper::compatibleParameterTypes()
const
7208 return QStringList()
7215QStringList QgsProcessingPointCloudLayerWidgetWrapper::compatibleOutputTypes()
const
7217 return QStringList()
7225QString QgsProcessingPointCloudLayerWidgetWrapper::modelerExpressionFormatString()
const
7227 return tr(
"path to a point cloud layer" );
7230QString QgsProcessingPointCloudLayerWidgetWrapper::parameterType()
const
7237 return new QgsProcessingPointCloudLayerWidgetWrapper( parameter, type );
7242 Q_UNUSED( context );
7243 Q_UNUSED( widgetContext );
7244 Q_UNUSED( definition );
7261QStringList QgsProcessingAnnotationLayerWidgetWrapper::compatibleParameterTypes()
const
7263 return QStringList()
7270QStringList QgsProcessingAnnotationLayerWidgetWrapper::compatibleOutputTypes()
const
7272 return QStringList()
7277QString QgsProcessingAnnotationLayerWidgetWrapper::modelerExpressionFormatString()
const
7279 return tr(
"name of an annotation layer, or \"main\" for the main annotation layer" );
7282QString QgsProcessingAnnotationLayerWidgetWrapper::parameterType()
const
7289 return new QgsProcessingAnnotationLayerWidgetWrapper( parameter, type );
7294 Q_UNUSED( context );
7295 Q_UNUSED( widgetContext );
7296 Q_UNUSED( definition );
7307 if ( mWidgetContext.project() )
7308 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7312QWidget *QgsProcessingAnnotationLayerWidgetWrapper::createWidget()
7323 mComboBox->setEditable(
true );
7327 mComboBox->setToolTip( parameterDefinition()->toolTip() );
7329 if ( mWidgetContext.project() )
7330 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7333 mComboBox->setAllowEmptyLayer(
true );
7337 if ( mBlockSignals )
7340 emit widgetValueHasChanged(
this );
7343 setWidgetContext( widgetContext() );
7347void QgsProcessingAnnotationLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7353 mComboBox->setLayer(
nullptr );
7357 QVariant val = value;
7358 if ( val.userType() == QMetaType::type(
"QgsProperty" ) )
7370 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( val.value< QObject * >() );
7371 if ( !layer && val.type() == QVariant::String )
7378 mComboBox->setLayer( layer );
7383QVariant QgsProcessingAnnotationLayerWidgetWrapper::widgetValue()
const
7385 return mComboBox && mComboBox->currentLayer() ?
7386 ( mWidgetContext.project() ? ( mComboBox->currentLayer() == mWidgetContext.project()->mainAnnotationLayer() ? QStringLiteral(
"main" ) : mComboBox->currentLayer()->id() ) : mComboBox->currentLayer()->id() )
7402QWidget *QgsProcessingOutputWidgetWrapper::createWidget()
7410 mOutputWidget =
new QgsProcessingLayerOutputDestinationWidget( destParam,
false );
7411 if ( mProcessingContextGenerator )
7412 mOutputWidget->setContext( mProcessingContextGenerator->processingContext() );
7413 if ( mParametersGenerator )
7414 mOutputWidget->registerProcessingParametersGenerator( mParametersGenerator );
7415 mOutputWidget->setToolTip( parameterDefinition()->toolTip() );
7417 connect( mOutputWidget, &QgsProcessingLayerOutputDestinationWidget::destinationChanged,
this, [ = ]()
7419 if ( mBlockSignals )
7422 emit widgetValueHasChanged(
this );
7430 mOutputWidget->addOpenAfterRunningOption();
7432 return mOutputWidget;
7442void QgsProcessingOutputWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
7444 if ( mOutputWidget )
7445 mOutputWidget->setValue( value );
7448QVariant QgsProcessingOutputWidgetWrapper::widgetValue()
const
7450 if ( mOutputWidget )
7451 return mOutputWidget->value();
7456QVariantMap QgsProcessingOutputWidgetWrapper::customProperties()
const
7459 if ( mOutputWidget )
7460 res.insert( QStringLiteral(
"OPEN_AFTER_RUNNING" ), mOutputWidget->openAfterRunning() );
7464QStringList QgsProcessingOutputWidgetWrapper::compatibleParameterTypes()
const
7466 return QStringList()
7475QStringList QgsProcessingOutputWidgetWrapper::compatibleOutputTypes()
const
7477 return QStringList()
7488 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7493QString QgsProcessingFeatureSinkWidgetWrapper::parameterType()
const
7500 return new QgsProcessingFeatureSinkWidgetWrapper( parameter, type );
7503QString QgsProcessingFeatureSinkWidgetWrapper::modelerExpressionFormatString()
const
7505 return tr(
"path to layer destination" );
7513 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7518QString QgsProcessingVectorDestinationWidgetWrapper::parameterType()
const
7525 return new QgsProcessingVectorDestinationWidgetWrapper( parameter, type );
7528QString QgsProcessingVectorDestinationWidgetWrapper::modelerExpressionFormatString()
const
7530 return tr(
"path to layer destination" );
7538 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7543QString QgsProcessingRasterDestinationWidgetWrapper::parameterType()
const
7550 return new QgsProcessingRasterDestinationWidgetWrapper( parameter, type );
7553QString QgsProcessingRasterDestinationWidgetWrapper::modelerExpressionFormatString()
const
7555 return tr(
"path to layer destination" );
7563 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7568QString QgsProcessingPointCloudDestinationWidgetWrapper::parameterType()
const
7575 return new QgsProcessingPointCloudDestinationWidgetWrapper( parameter, type );
7578QString QgsProcessingPointCloudDestinationWidgetWrapper::modelerExpressionFormatString()
const
7580 return tr(
"path to layer destination" );
7588 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7593QString QgsProcessingFileDestinationWidgetWrapper::parameterType()
const
7600 return new QgsProcessingFileDestinationWidgetWrapper( parameter, type );
7603QString QgsProcessingFileDestinationWidgetWrapper::modelerExpressionFormatString()
const
7605 return tr(
"path to file destination" );
7613 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
7618QString QgsProcessingFolderDestinationWidgetWrapper::parameterType()
const
7625 return new QgsProcessingFolderDestinationWidgetWrapper( parameter, type );
7628QString QgsProcessingFolderDestinationWidgetWrapper::modelerExpressionFormatString()
const
7630 return tr(
"path to folder destination" );
@ Standard
Unit is a standard measurement unit.
DistanceUnit
Units of distance.
TemporalUnit
Temporal units.
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Selector widget for authentication configs.
void selectedConfigIdChanged(const QString &authcfg)
Emitted when authentication config is changed or missing.
QComboBox subclass which allows selecting multiple items.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Q_GADGET Qgis::DistanceUnit mapUnits
The QgsDatabaseSchemaComboBox class is a combo box which displays the list of schemas for a specific ...
The QgsDatabaseTableComboBox class is a combo box which displays the list of tables for a specific da...
The QgsDateEdit class is a QDateEdit widget with the capability of setting/reading null dates.
void dateValueChanged(const QDate &date)
Signal emitted whenever the date changes.
The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times.
void setAllowNull(bool allowNull)
Determines if the widget allows setting null date/time.
void setNullRepresentation(const QString &null)
Sets the widget's null representation, which defaults to QgsApplication::nullRepresentation().
void valueChanged(const QDateTime &date)
Signal emitted whenever the value changes.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
static double toDouble(const QString &input, bool *ok)
Converts input string to double value.
The QgsExpressionLineEdit widget includes a line edit for entering expressions together with a button...
void expressionChanged(const QString &expression)
Emitted when the expression is changed.
The QgsFieldComboBox is a combo box which displays the list of fields of a given layer.
void fieldChanged(const QString &fieldName)
Emitted when the currently selected field changes.
@ DateTime
Datetime fieldss.
@ Date
Date or datetime fields.
@ Numeric
All numeric fields.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
QList< QgsField > toList() const
Utility function to return a list of QgsField instances.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false)
void remove(int fieldIdx)
Removes the field with the given index.
int count() const
Returns number of items.
bool isEmpty() const
Checks whether the container is empty.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
A geometry is the spatial representation of a feature.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
The QgsLayoutComboBox class is a combo box which displays available layouts from a QgsLayoutManager.
void layoutChanged(QgsMasterLayoutInterface *layout)
Emitted whenever the currently selected layout changes.
The QgsLayoutItemComboBox class is a combo box which displays items of a matching type from a layout.
void itemChanged(QgsLayoutItem *item)
Emitted whenever the currently selected item changes.
Base class for graphical items within a QgsLayout.
virtual QString uuid() const
Returns the item identification string.
@ FilterPrintLayouts
Includes print layouts.
QList< QgsPrintLayout * > printLayouts() const
Returns a list of all print layouts contained in the manager.
Map canvas is a class for displaying all GIS data types on a canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
The QgsMapLayerComboBox class is a combo box which displays the list of layers.
void layerChanged(QgsMapLayer *layer)
Emitted whenever the currently selected layer changes.
@ AnnotationLayer
QgsAnnotationLayer.
Base class for all map layer types.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
QgsPointLocator::Match mapPointMatch() const
Returns the matching data from the most recently snapped point.
QgsPointXY snapPoint()
snapPoint will snap the points using the map canvas snapping utils configuration
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
Interface for master layout type objects, such as print layouts and reports.
virtual QString name() const =0
Returns the layout's name.
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::MessageLevel::Info, int duration=-1)
A convenience method for pushing a message with the specified text to the bar.
bool clearWidgets()
Removes all items from the bar.
A class to represent a 2D point.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Abstract base class for processing algorithms.
An interface for objects which can create Processing contexts.
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
QgsMapLayer * takeResultLayer(const QString &id)
Takes the result map layer with matching id from the context and transfers ownership of it back to th...
Base class for all parameter definitions which represent file or layer destinations,...
Encapsulates settings relating to a feature source input to a processing algorithm.
QgsProperty source
Source definition.
WidgetType
Types of dialogs which Processing widgets can be created for.
@ Standard
Standard algorithm dialog.
@ Batch
Batch processing dialog.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A raster band parameter for Processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
bool allowMultiple() const
Returns whether multiple band selections are permitted.
A boolean parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A color parameter for processing algorithms.
bool opacityEnabled() const
Returns true if the parameter allows opacity control.
static QString typeName()
Returns the type name for the parameter class.
A coordinate operation parameter for processing algorithms, for selection between available coordinat...
static QString typeName()
Returns the type name for the parameter class.
QVariant sourceCrs() const
Returns the static source CRS, or an invalid value if this is not set.
QVariant destinationCrs() const
Returns the static destination CRS, or an invalid value if this is not set.
A coordinate reference system parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A database schema parameter for processing algorithms, allowing users to select from existing schemas...
static QString typeName()
Returns the type name for the parameter class.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
A database table name parameter for processing algorithms, allowing users to select from existing dat...
static QString typeName()
Returns the type name for the parameter class.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
QString parentSchemaParameterName() const
Returns the name of the parent schema parameter, or an empty string if this is not set.
bool allowNewTableNames() const
Returns true if the parameter allows users to enter names for a new (non-existing) tables.
A datetime (or pure date or time) parameter for processing algorithms.
@ DateTime
Datetime values.
static QString typeName()
Returns the type name for the parameter class.
Type dataType() const
Returns the acceptable data type for the parameter.
Base class for the definition of processing parameters.
QVariantMap metadata() const
Returns the parameter's freeform metadata.
QString description() const
Returns the description for the parameter.
QVariant defaultValueForGui() const
Returns the default value to use for the parameter in a GUI.
@ FlagOptional
Parameter is optional.
virtual QString type() const =0
Unique parameter type name.
Flags flags() const
Returns any flags associated with the parameter.
QString name() const
Returns the name of the parameter.
void setFlags(Flags flags)
Sets the flags associated with the parameter.
A double numeric parameter for distance values.
static QString typeName()
Returns the type name for the parameter class.
Qgis::DistanceUnit defaultUnit() const
Returns the default distance unit for the parameter.
A double numeric parameter for duration values.
Qgis::TemporalUnit defaultUnit() const
Returns the default duration unit for the parameter.
static QString typeName()
Returns the type name for the parameter class.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
bool allowMultiple() const
Returns true if the parameter allows multiple selected values.
QStringList options() const
Returns the list of acceptable options for the parameter.
bool usesStaticStrings() const
Returns true if the parameter uses static (non-translated) string values for its enumeration choice l...
static QString typeName()
Returns the type name for the parameter class.
An expression parameter for processing algorithms.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
static QString typeName()
Returns the type name for the parameter class.
A rectangular map extent parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
An input feature source (such as vector layers) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A vector layer or feature source field parameter for processing algorithms.
void setDataType(DataType type)
Sets the acceptable data type for the field.
bool allowMultiple() const
Returns whether multiple field selections are permitted.
bool defaultToAllFields() const
Returns whether a parameter which allows multiple selections (see allowMultiple()) should automatical...
static QString typeName()
Returns the type name for the parameter class.
DataType
Field data types.
@ DateTime
Accepts datetime fields.
@ Numeric
Accepts numeric fields.
@ String
Accepts string fields.
DataType dataType() const
Returns the acceptable data type for the field.
static QString typeName()
Returns the type name for the parameter class.
An input file or folder parameter for processing algorithms.
QString extension() const
Returns any specified file extension for the parameter.
static QString typeName()
Returns the type name for the parameter class.
Behavior
Parameter behavior.
@ Folder
Parameter is a folder.
@ File
Parameter is a single file.
Behavior behavior() const
Returns the parameter behavior (e.g.
QString fileFilter() const
Returns the file filter string for file destinations compatible with this parameter.
static QString typeName()
Returns the type name for the parameter class.
A geometry parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A print layout item parameter, allowing users to select a particular item from a print layout.
static QString typeName()
Returns the type name for the parameter class.
int itemType() const
Returns the acceptable item type, or -1 if any item type is allowed.
A print layout parameter, allowing users to select a print layout.
static QString typeName()
Returns the type name for the parameter class.
A map layer parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A map theme parameter for processing algorithms, allowing users to select an existing map theme from ...
static QString typeName()
Returns the type name for the parameter class.
A table (matrix) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A parameter for processing algorithms which accepts multiple map layers.
static QString typeName()
Returns the type name for the parameter class.
A numeric parameter for processing algorithms.
double minimum() const
Returns the minimum value acceptable by the parameter.
@ Double
Double/float values.
double maximum() const
Returns the maximum value acceptable by the parameter.
Type dataType() const
Returns the acceptable data type for the parameter.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A point parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A data provider connection parameter for processing algorithms, allowing users to select from availab...
static QString typeName()
Returns the type name for the parameter class.
QString providerId() const
Returns the ID of the provider associated with the connections.
A numeric range parameter for processing algorithms.
QgsProcessingParameterNumber::Type dataType() const
Returns the acceptable data type for the range.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A raster layer parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A double numeric parameter for map scale values.
static QString typeName()
Returns the type name for the parameter class.
A string parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
bool multiLine() const
Returns true if the parameter allows multiline strings.
static QString typeName()
Returns the type name for the parameter class.
A vector layer (with or without geometry) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
Contains settings which reflect the context in which a Processing parameter widget is shown,...
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QgsProject * project() const
Returns the project associated with the widget.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
QgsProcessingModelAlgorithm * model() const
Returns the model which the parameter widget is associated with.
QgsMapLayer * activeLayer() const
Returns the current active layer.
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of map layers.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
static QTime parameterAsTime(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static time value.
static QgsRectangle parameterAsExtent(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent.
static QString parameterAsEnumString(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static enum string.
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
static QList< int > parameterAsInts(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of integer values.
static QString parameterAsConnectionName(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a connection name string.
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
static QgsLayoutItem * parameterAsLayoutItem(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsPrintLayout *layout)
Evaluates the parameter with matching definition to a print layout item, taken from the specified lay...
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QColor parameterAsColor(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the color associated with an point parameter value, or an invalid color if the parameter was ...
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
static int parameterAsInt(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static integer value.
static QString parameterAsDatabaseTableName(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database table name.
static QString parameterAsSchema(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database schema name.
static QgsGeometry parameterAsGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a geometry.
static QString parameterAsExpression(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to an expression.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
static QgsRasterLayer * parameterAsRasterLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a raster layer.
static QList< int > parameterAsEnums(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of enum values.
static QStringList parameterAsEnumStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of static enum strings.
static QStringList parameterAsFields(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of fields.
static QgsCoordinateReferenceSystem parameterAsExtentCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
static QDateTime parameterAsDateTime(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static datetime value.
static QDate parameterAsDate(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static date value.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
@ Annotation
Annotation layer type, since QGIS 3.22.
static QgsCoordinateReferenceSystem variantToCrs(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a coordinate reference system.
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, QgsProcessingUtils::LayerHint typeHint=QgsProcessingUtils::LayerHint::UnknownType)
Interprets a string as a map layer within the supplied context.
SourceType
Data source types enum.
@ TypePlugin
Plugin layers.
@ TypeVectorLine
Vector line layers.
@ TypeMapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer)
@ TypeVectorPolygon
Vector polygon layers.
@ TypeFile
Files (i.e. non map layer sources, such as text files)
@ TypeAnnotation
Annotation layers.
@ TypePointCloud
Point cloud layers.
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ TypeRaster
Raster layers.
@ TypeVectorPoint
Vector point layers.
@ TypeVectorAnyGeometry
Any vector layer with geometry.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsMapThemeCollection * mapThemeCollection
const QgsLayoutManager * layoutManager() const
Returns the project's layout manager, which manages print layouts, atlases and reports within the pro...
void layerRemoved(const QString &layerId)
Emitted after a layer was removed from the registry.
A store for object properties.
@ StaticProperty
Static property (QgsStaticProperty)
Type propertyType() const
Returns the property type.
The QgsProviderConnectionComboBox class is a combo box which displays the list of connections registe...
A combobox widget which displays the bands present in a raster layer.
void bandChanged(int band)
Emitted when the currently selected band changes.
static QString displayBandName(QgsRasterDataProvider *provider, int band)
Returns a user-friendly band name for the specified band.
Base class for raster data providers.
virtual int bandCount() const =0
Gets number of bands.
Represents a raster layer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
A rectangle specified with double values.
This class is a composition of two QSettings instances:
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Class that shows snapping marker on map canvas for the current snapping match.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
The QgsTimeEdit class is a QTimeEdit widget with the capability of setting/reading null date/times.
void timeValueChanged(const QTime &time)
Signal emitted whenever the time changes.
static Q_INVOKABLE QString toString(Qgis::DistanceUnit unit)
Returns a translated string representing a distance unit.
static Q_INVOKABLE double fromUnitToUnitFactor(Qgis::DistanceUnit fromUnit, Qgis::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
static Q_INVOKABLE Qgis::DistanceUnitType unitType(Qgis::DistanceUnit unit)
Returns the type for a distance unit.
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
const QgsCoordinateReferenceSystem & crs