78#include <QButtonGroup>
86#include <QPlainTextEdit>
87#include <QRadioButton>
92#include "moc_qgsprocessingwidgetwrapperimpl.cpp"
94using namespace Qt::StringLiterals;
103QgsProcessingBooleanParameterDefinitionWidget::QgsProcessingBooleanParameterDefinitionWidget(
108 QVBoxLayout *vlayout =
new QVBoxLayout();
109 vlayout->setContentsMargins( 0, 0, 0, 0 );
111 mDefaultCheckBox =
new QCheckBox( tr(
"Checked" ) );
115 mDefaultCheckBox->setChecked(
false );
116 vlayout->addWidget( mDefaultCheckBox );
119 setLayout( vlayout );
124 auto param = std::make_unique<QgsProcessingParameterBoolean>( name, description, mDefaultCheckBox->isChecked() );
125 param->setFlags( flags );
126 return param.release();
134QWidget *QgsProcessingBooleanWidgetWrapper::createWidget()
140 QString description = parameterDefinition()->description();
142 description = QObject::tr(
"%1 [optional]" ).arg( description );
144 mCheckBox =
new QCheckBox( description );
145 mCheckBox->setToolTip( parameterDefinition()->toolTip() );
147 connect( mCheckBox, &QCheckBox::toggled,
this, [
this] { emit widgetValueHasChanged(
this ); } );
154 mComboBox =
new QComboBox();
155 mComboBox->addItem( tr(
"Yes" ),
true );
156 mComboBox->addItem( tr(
"No" ),
false );
157 mComboBox->setToolTip( parameterDefinition()->toolTip() );
159 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
167QLabel *QgsProcessingBooleanWidgetWrapper::createLabel()
176void QgsProcessingBooleanWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
183 mCheckBox->setChecked( v );
191 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
197QVariant QgsProcessingBooleanWidgetWrapper::widgetValue()
const
202 return mCheckBox->isChecked();
206 return mComboBox->currentData();
211QString QgsProcessingBooleanWidgetWrapper::parameterType()
const
218 return new QgsProcessingBooleanWidgetWrapper( parameter, type );
225 return new QgsProcessingBooleanParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
233QgsProcessingCrsParameterDefinitionWidget::QgsProcessingCrsParameterDefinitionWidget(
238 QVBoxLayout *vlayout =
new QVBoxLayout();
239 vlayout->setContentsMargins( 0, 0, 0, 0 );
241 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
246 mCrsSelector->setShowAccuracyWarnings(
true );
253 vlayout->addWidget( mCrsSelector );
254 setLayout( vlayout );
259 auto param = std::make_unique<QgsProcessingParameterCrs>( name, description, mCrsSelector->crs().authid() );
260 param->setFlags( flags );
261 return param.release();
268QWidget *QgsProcessingCrsWidgetWrapper::createWidget()
270 Q_ASSERT( mProjectionSelectionWidget ==
nullptr );
272 mProjectionSelectionWidget->setToolTip( parameterDefinition()->toolTip() );
286 return mProjectionSelectionWidget;
291 QWidget *w =
new QWidget();
292 w->setToolTip( parameterDefinition()->toolTip() );
294 QVBoxLayout *vl =
new QVBoxLayout();
295 vl->setContentsMargins( 0, 0, 0, 0 );
298 mUseProjectCrsCheckBox =
new QCheckBox( tr(
"Use project CRS" ) );
299 mUseProjectCrsCheckBox->setToolTip( tr(
"Always use the current project CRS when running the model" ) );
300 vl->addWidget( mUseProjectCrsCheckBox );
301 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, mProjectionSelectionWidget, &QgsProjectionSelectionWidget::setDisabled );
302 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled,
this, [
this] { emit widgetValueHasChanged(
this ); } );
304 vl->addWidget( mProjectionSelectionWidget );
312void QgsProcessingCrsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
314 if ( mUseProjectCrsCheckBox )
316 if ( value.toString().compare(
"ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
318 mUseProjectCrsCheckBox->setChecked(
true );
323 mUseProjectCrsCheckBox->setChecked(
false );
328 if ( mProjectionSelectionWidget )
329 mProjectionSelectionWidget->setCrs( v );
332QVariant QgsProcessingCrsWidgetWrapper::widgetValue()
const
334 if ( mUseProjectCrsCheckBox && mUseProjectCrsCheckBox->isChecked() )
335 return u
"ProjectCrs"_s;
336 else if ( mProjectionSelectionWidget )
337 return mProjectionSelectionWidget->crs().isValid() ? mProjectionSelectionWidget->crs() : QVariant();
342QString QgsProcessingCrsWidgetWrapper::modelerExpressionFormatString()
const
344 return tr(
"string as EPSG code, WKT or PROJ format, or a string identifying a map layer" );
347QString QgsProcessingCrsWidgetWrapper::parameterType()
const
354 return new QgsProcessingCrsWidgetWrapper( parameter, type );
361 return new QgsProcessingCrsParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
370QgsProcessingStringParameterDefinitionWidget::QgsProcessingStringParameterDefinitionWidget(
375 QVBoxLayout *vlayout =
new QVBoxLayout();
376 vlayout->setContentsMargins( 0, 0, 0, 0 );
378 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
380 mDefaultLineEdit =
new QLineEdit();
383 vlayout->addWidget( mDefaultLineEdit );
387 mMultiLineCheckBox =
new QCheckBox( tr(
"Multiline input" ) );
389 mMultiLineCheckBox->setChecked( stringParam->multiLine() );
390 vlayout->addWidget( mMultiLineCheckBox );
394 setLayout( vlayout );
399 auto param = std::make_unique<QgsProcessingParameterString>( name, description, mDefaultLineEdit->text(), mMultiLineCheckBox->isChecked() );
400 param->setFlags( flags );
401 return param.release();
409QWidget *QgsProcessingStringWidgetWrapper::createWidget()
411 const QVariantMap metadata = parameterDefinition()->metadata();
412 const QVariant valueHintsVariant = metadata.value( u
"widget_wrapper"_s ).toMap().value( u
"value_hints"_s );
414 if ( valueHintsVariant.isValid() )
416 const QVariantList valueList = valueHintsVariant.toList();
417 mComboBox =
new QComboBox();
418 mComboBox->setToolTip( parameterDefinition()->toolTip() );
422 mComboBox->addItem( QString() );
424 for (
const QVariant &entry : valueList )
426 mComboBox->addItem( entry.toString(), entry.toString() );
428 mComboBox->setCurrentIndex( 0 );
430 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
442 mPlainTextEdit =
new QPlainTextEdit();
443 mPlainTextEdit->setToolTip( parameterDefinition()->toolTip() );
445 connect( mPlainTextEdit, &QPlainTextEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
446 return mPlainTextEdit;
450 mLineEdit =
new QLineEdit();
451 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
453 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
460 mLineEdit =
new QLineEdit();
461 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
463 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
472void QgsProcessingStringWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
476 mLineEdit->setText( v );
477 if ( mPlainTextEdit )
478 mPlainTextEdit->setPlainText( v );
482 if ( !value.isValid() )
483 index = mComboBox->findData( QVariant() );
485 index = mComboBox->findData( v );
488 mComboBox->setCurrentIndex( index );
490 mComboBox->setCurrentIndex( 0 );
494QVariant QgsProcessingStringWidgetWrapper::widgetValue()
const
497 return mLineEdit->text();
498 else if ( mPlainTextEdit )
499 return mPlainTextEdit->toPlainText();
500 else if ( mComboBox )
501 return mComboBox->currentData();
506QString QgsProcessingStringWidgetWrapper::parameterType()
const
513 return new QgsProcessingStringWidgetWrapper( parameter, type );
520 return new QgsProcessingStringParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
532QWidget *QgsProcessingAuthConfigWidgetWrapper::createWidget()
541 mAuthConfigSelect->setToolTip( parameterDefinition()->toolTip() );
544 return mAuthConfigSelect;
550void QgsProcessingAuthConfigWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
553 if ( mAuthConfigSelect )
554 mAuthConfigSelect->setConfigId( v );
557QVariant QgsProcessingAuthConfigWidgetWrapper::widgetValue()
const
559 if ( mAuthConfigSelect )
560 return mAuthConfigSelect->configId();
565QString QgsProcessingAuthConfigWidgetWrapper::parameterType()
const
572 return new QgsProcessingAuthConfigWidgetWrapper( parameter, type );
579QgsProcessingNumberParameterDefinitionWidget::QgsProcessingNumberParameterDefinitionWidget(
584 QVBoxLayout *vlayout =
new QVBoxLayout();
585 vlayout->setContentsMargins( 0, 0, 0, 0 );
587 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
589 mTypeComboBox =
new QComboBox();
592 vlayout->addWidget( mTypeComboBox );
594 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
595 mMinLineEdit =
new QLineEdit();
596 vlayout->addWidget( mMinLineEdit );
598 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
599 mMaxLineEdit =
new QLineEdit();
600 vlayout->addWidget( mMaxLineEdit );
602 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
603 mDefaultLineEdit =
new QLineEdit();
604 vlayout->addWidget( mDefaultLineEdit );
608 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( numberParam->dataType() ) ) );
610 if ( !
qgsDoubleNear( numberParam->maximum(), std::numeric_limits<double>::max() ) )
612 mMaxLineEdit->setText( QLocale().toString( numberParam->maximum() ) );
616 mMaxLineEdit->clear();
619 if ( !
qgsDoubleNear( numberParam->minimum(), std::numeric_limits<double>::lowest() ) )
621 mMinLineEdit->setText( QLocale().toString( numberParam->minimum() ) );
625 mMinLineEdit->clear();
628 mDefaultLineEdit->setText( numberParam->defaultValueForGui().toString() );
636 setLayout( vlayout );
645 auto param = std::make_unique<QgsProcessingParameterNumber>( name, description, dataType, ok ? val : QVariant() );
647 if ( !mMinLineEdit->text().trimmed().isEmpty() )
652 param->setMinimum( val );
656 if ( !mMaxLineEdit->text().trimmed().isEmpty() )
661 param->setMaximum( val );
665 param->setFlags( flags );
666 return param.release();
673QWidget *QgsProcessingNumericWidgetWrapper::createWidget()
676 const QVariantMap metadata = numberDef->
metadata();
677 const int decimals = metadata.value( u
"widget_wrapper"_s ).toMap().value( u
"decimals"_s, 6 ).toInt();
685 QAbstractSpinBox *spinBox =
nullptr;
690 mDoubleSpinBox->setExpressionsEnabled(
true );
691 mDoubleSpinBox->setDecimals( decimals );
696 double singleStep = calculateStep( numberDef->
minimum(), numberDef->
maximum() );
697 singleStep = std::max( singleStep, std::pow( 10, -decimals ) );
698 mDoubleSpinBox->setSingleStep( singleStep );
701 spinBox = mDoubleSpinBox;
706 mSpinBox->setExpressionsEnabled(
true );
710 spinBox->setToolTip( parameterDefinition()->toolTip() );
712 double max = 999999999;
717 double min = -999999999;
722 if ( mDoubleSpinBox )
724 mDoubleSpinBox->setMinimum( min );
725 mDoubleSpinBox->setMaximum( max );
729 mSpinBox->setMinimum(
static_cast<int>( min ) );
730 mSpinBox->setMaximum(
static_cast<int>( max ) );
735 mAllowingNull =
true;
736 if ( mDoubleSpinBox )
738 mDoubleSpinBox->setShowClearButton(
true );
739 const double min = mDoubleSpinBox->minimum() - mDoubleSpinBox->singleStep();
740 mDoubleSpinBox->setMinimum( min );
741 mDoubleSpinBox->setValue( min );
745 mSpinBox->setShowClearButton(
true );
746 const int min = mSpinBox->minimum() - 1;
747 mSpinBox->setMinimum( min );
748 mSpinBox->setValue( min );
750 spinBox->setSpecialValueText( tr(
"Not set" ) );
758 if ( mDoubleSpinBox )
762 mDoubleSpinBox->setClearValue( defaultVal );
768 mSpinBox->setClearValue( intVal );
774 if ( mDoubleSpinBox )
775 mDoubleSpinBox->setClearValue( numberDef->
minimum() );
777 mSpinBox->setClearValue(
static_cast<int>( numberDef->
minimum() ) );
782 if ( mDoubleSpinBox )
784 mDoubleSpinBox->setValue( 0 );
785 mDoubleSpinBox->setClearValue( 0 );
789 mSpinBox->setValue( 0 );
790 mSpinBox->setClearValue( 0 );
795 if ( mDoubleSpinBox )
796 connect( mDoubleSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
798 connect( mSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
806void QgsProcessingNumericWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
808 if ( mDoubleSpinBox )
810 if ( mAllowingNull && !value.isValid() )
811 mDoubleSpinBox->clear();
815 mDoubleSpinBox->setValue( v );
820 if ( mAllowingNull && !value.isValid() )
825 mSpinBox->setValue( v );
830QVariant QgsProcessingNumericWidgetWrapper::widgetValue()
const
832 if ( mDoubleSpinBox )
834 if ( mAllowingNull &&
qgsDoubleNear( mDoubleSpinBox->value(), mDoubleSpinBox->minimum() ) )
837 return mDoubleSpinBox->value();
841 if ( mAllowingNull && mSpinBox->value() == mSpinBox->minimum() )
844 return mSpinBox->value();
850double QgsProcessingNumericWidgetWrapper::calculateStep(
const double minimum,
const double maximum )
852 const double valueRange = maximum - minimum;
853 if ( valueRange <= 1.0 )
855 const double step = valueRange / 10.0;
857 return qgsRound( step, -std::floor( std::log( step ) ) );
865QString QgsProcessingNumericWidgetWrapper::parameterType()
const
872 return new QgsProcessingNumericWidgetWrapper( parameter, type );
879 return new QgsProcessingNumberParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
886QgsProcessingDistanceParameterDefinitionWidget::QgsProcessingDistanceParameterDefinitionWidget(
891 QVBoxLayout *vlayout =
new QVBoxLayout();
892 vlayout->setContentsMargins( 0, 0, 0, 0 );
894 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
896 mParentLayerComboBox =
new QComboBox();
898 QString initialParent;
900 initialParent = distParam->parentParameterName();
902 if (
auto *lModel = widgetContext.
model() )
905 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
906 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
910 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
911 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
913 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
918 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
919 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
921 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
926 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
927 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
929 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
934 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
935 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
937 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
943 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
946 mParentLayerComboBox->addItem( initialParent, initialParent );
947 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
950 vlayout->addWidget( mParentLayerComboBox );
953 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
954 mMinLineEdit =
new QLineEdit();
955 vlayout->addWidget( mMinLineEdit );
957 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
958 mMaxLineEdit =
new QLineEdit();
959 vlayout->addWidget( mMaxLineEdit );
961 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
962 mDefaultLineEdit =
new QLineEdit();
963 vlayout->addWidget( mDefaultLineEdit );
967 mMinLineEdit->setText( QLocale().toString( distParam->minimum() ) );
968 mMaxLineEdit->setText( QLocale().toString( distParam->maximum() ) );
969 mDefaultLineEdit->setText( distParam->defaultValueForGui().toString() );
975 setLayout( vlayout );
983 auto param = std::make_unique<QgsProcessingParameterDistance>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
988 param->setMinimum( val );
994 param->setMaximum( val );
997 param->setFlags( flags );
998 return param.release();
1002 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1005QString QgsProcessingDistanceWidgetWrapper::parameterType()
const
1012 return new QgsProcessingDistanceWidgetWrapper( parameter, type );
1015QWidget *QgsProcessingDistanceWidgetWrapper::createWidget()
1019 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1024 mLabel =
new QLabel();
1025 mUnitsCombo =
new QComboBox();
1037 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1038 QHBoxLayout *layout =
new QHBoxLayout();
1039 layout->addWidget( spin, 1 );
1040 layout->insertSpacing( 1, labelMargin / 2 );
1041 layout->insertWidget( 2, mLabel );
1042 layout->insertWidget( 3, mUnitsCombo );
1047 mWarningLabel =
new QWidget();
1048 QHBoxLayout *warningLayout =
new QHBoxLayout();
1049 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1050 QLabel *warning =
new QLabel();
1052 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1053 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1054 warning->setToolTip( tr(
"Distance is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1055 warningLayout->insertSpacing( 0, labelMargin / 2 );
1056 warningLayout->insertWidget( 1, warning );
1057 mWarningLabel->setLayout( warningLayout );
1058 layout->insertWidget( 4, mWarningLabel );
1060 QWidget *w =
new QWidget();
1061 layout->setContentsMargins( 0, 0, 0, 0 );
1062 w->setLayout( layout );
1076void QgsProcessingDistanceWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1078 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1085 if ( wrapper->parameterDefinition()->name() ==
static_cast<const QgsProcessingParameterDistance *
>( parameterDefinition() )->parentParameterName() )
1087 setUnitParameterValue( wrapper->parameterValue(), wrapper );
1107 std::unique_ptr<QgsProcessingContext> tmpContext;
1108 if ( mProcessingContextGenerator )
1109 context = mProcessingContextGenerator->processingContext();
1113 tmpContext = std::make_unique<QgsProcessingContext>();
1114 context = tmpContext.get();
1121 units = crs.mapUnits();
1132 mUnitsCombo->hide();
1140 if ( mBaseUnit != units )
1142 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( units ) ) );
1145 mUnitsCombo->show();
1152QVariant QgsProcessingDistanceWidgetWrapper::widgetValue()
const
1154 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1155 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1170 return new QgsProcessingDistanceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1178QgsProcessingAreaParameterDefinitionWidget::QgsProcessingAreaParameterDefinitionWidget(
1183 QVBoxLayout *vlayout =
new QVBoxLayout();
1184 vlayout->setContentsMargins( 0, 0, 0, 0 );
1186 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
1188 mParentLayerComboBox =
new QComboBox();
1190 QString initialParent;
1192 initialParent = areaParam->parentParameterName();
1194 if (
auto *lModel = widgetContext.
model() )
1197 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
1198 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
1202 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1203 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1205 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1210 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1211 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1213 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1218 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1219 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1221 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1226 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1227 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1229 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1235 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
1238 mParentLayerComboBox->addItem( initialParent, initialParent );
1239 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1244 vlayout->addWidget( mParentLayerComboBox );
1246 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1247 mMinLineEdit =
new QLineEdit();
1248 vlayout->addWidget( mMinLineEdit );
1250 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1251 mMaxLineEdit =
new QLineEdit();
1252 vlayout->addWidget( mMaxLineEdit );
1254 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1255 mDefaultLineEdit =
new QLineEdit();
1256 vlayout->addWidget( mDefaultLineEdit );
1260 mMinLineEdit->setText( QLocale().toString( areaParam->minimum() ) );
1261 mMaxLineEdit->setText( QLocale().toString( areaParam->maximum() ) );
1262 mDefaultLineEdit->setText( areaParam->defaultValueForGui().toString() );
1269 setLayout( vlayout );
1277 auto param = std::make_unique<QgsProcessingParameterArea>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1282 param->setMinimum( val );
1288 param->setMaximum( val );
1291 param->setFlags( flags );
1292 return param.release();
1301 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1304QString QgsProcessingAreaWidgetWrapper::parameterType()
const
1311 return new QgsProcessingAreaWidgetWrapper( parameter, type );
1314QWidget *QgsProcessingAreaWidgetWrapper::createWidget()
1318 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1323 mLabel =
new QLabel();
1324 mUnitsCombo =
new QComboBox();
1339 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1340 QHBoxLayout *layout =
new QHBoxLayout();
1341 layout->addWidget( spin, 1 );
1342 layout->insertSpacing( 1, labelMargin / 2 );
1343 layout->insertWidget( 2, mLabel );
1344 layout->insertWidget( 3, mUnitsCombo );
1349 mWarningLabel =
new QWidget();
1350 QHBoxLayout *warningLayout =
new QHBoxLayout();
1351 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1352 QLabel *warning =
new QLabel();
1354 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1355 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1356 warning->setToolTip( tr(
"Area is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1357 warningLayout->insertSpacing( 0, labelMargin / 2 );
1358 warningLayout->insertWidget( 1, warning );
1359 mWarningLabel->setLayout( warningLayout );
1360 layout->insertWidget( 4, mWarningLabel );
1362 QWidget *w =
new QWidget();
1363 layout->setContentsMargins( 0, 0, 0, 0 );
1364 w->setLayout( layout );
1378void QgsProcessingAreaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1380 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1409 std::unique_ptr<QgsProcessingContext> tmpContext;
1410 if ( mProcessingContextGenerator )
1411 context = mProcessingContextGenerator->processingContext();
1415 tmpContext = std::make_unique<QgsProcessingContext>();
1416 context = tmpContext.get();
1423 units = QgsUnitTypes::distanceToAreaUnit( crs.mapUnits() );
1429void QgsProcessingAreaWidgetWrapper::setUnits(
Qgis::AreaUnit units )
1434 mUnitsCombo->hide();
1439 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QVariant::fromValue( units ) ) );
1440 mUnitsCombo->show();
1447QVariant QgsProcessingAreaWidgetWrapper::widgetValue()
const
1449 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1450 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1465 return new QgsProcessingAreaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1473QgsProcessingVolumeParameterDefinitionWidget::QgsProcessingVolumeParameterDefinitionWidget(
1478 QVBoxLayout *vlayout =
new QVBoxLayout();
1479 vlayout->setContentsMargins( 0, 0, 0, 0 );
1481 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
1483 mParentLayerComboBox =
new QComboBox();
1485 QString initialParent;
1487 initialParent = volumeParam->parentParameterName();
1489 if (
auto *lModel = widgetContext.
model() )
1492 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
1493 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
1497 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1498 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1500 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1505 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1506 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1508 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1513 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1514 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1516 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1521 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1522 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1524 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1530 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
1533 mParentLayerComboBox->addItem( initialParent, initialParent );
1534 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1537 vlayout->addWidget( mParentLayerComboBox );
1539 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1540 mMinLineEdit =
new QLineEdit();
1541 vlayout->addWidget( mMinLineEdit );
1543 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1544 mMaxLineEdit =
new QLineEdit();
1545 vlayout->addWidget( mMaxLineEdit );
1547 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1548 mDefaultLineEdit =
new QLineEdit();
1549 vlayout->addWidget( mDefaultLineEdit );
1553 mMinLineEdit->setText( QLocale().toString( volumeParam->minimum() ) );
1554 mMaxLineEdit->setText( QLocale().toString( volumeParam->maximum() ) );
1555 mDefaultLineEdit->setText( volumeParam->defaultValueForGui().toString() );
1563 setLayout( vlayout );
1571 auto param = std::make_unique<QgsProcessingParameterVolume>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1576 param->setMinimum( val );
1582 param->setMaximum( val );
1585 param->setFlags( flags );
1586 return param.release();
1595 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1598QString QgsProcessingVolumeWidgetWrapper::parameterType()
const
1605 return new QgsProcessingVolumeWidgetWrapper( parameter, type );
1608QWidget *QgsProcessingVolumeWidgetWrapper::createWidget()
1612 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1617 mLabel =
new QLabel();
1618 mUnitsCombo =
new QComboBox();
1631 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1632 QHBoxLayout *layout =
new QHBoxLayout();
1633 layout->addWidget( spin, 1 );
1634 layout->insertSpacing( 1, labelMargin / 2 );
1635 layout->insertWidget( 2, mLabel );
1636 layout->insertWidget( 3, mUnitsCombo );
1641 mWarningLabel =
new QWidget();
1642 QHBoxLayout *warningLayout =
new QHBoxLayout();
1643 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1644 QLabel *warning =
new QLabel();
1646 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1647 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1648 warning->setToolTip( tr(
"Volume is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1649 warningLayout->insertSpacing( 0, labelMargin / 2 );
1650 warningLayout->insertWidget( 1, warning );
1651 mWarningLabel->setLayout( warningLayout );
1652 layout->insertWidget( 4, mWarningLabel );
1654 QWidget *w =
new QWidget();
1655 layout->setContentsMargins( 0, 0, 0, 0 );
1656 w->setLayout( layout );
1670void QgsProcessingVolumeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1672 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1701 std::unique_ptr<QgsProcessingContext> tmpContext;
1702 if ( mProcessingContextGenerator )
1703 context = mProcessingContextGenerator->processingContext();
1707 tmpContext = std::make_unique<QgsProcessingContext>();
1708 context = tmpContext.get();
1715 units = QgsUnitTypes::distanceToVolumeUnit( crs.mapUnits() );
1726 mUnitsCombo->hide();
1731 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QVariant::fromValue( units ) ) );
1732 mUnitsCombo->show();
1739QVariant QgsProcessingVolumeWidgetWrapper::widgetValue()
const
1741 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1742 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1757 return new QgsProcessingVolumeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1765QgsProcessingDurationParameterDefinitionWidget::QgsProcessingDurationParameterDefinitionWidget(
1770 QVBoxLayout *vlayout =
new QVBoxLayout();
1771 vlayout->setContentsMargins( 0, 0, 0, 0 );
1773 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1774 mMinLineEdit =
new QLineEdit();
1775 vlayout->addWidget( mMinLineEdit );
1777 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1778 mMaxLineEdit =
new QLineEdit();
1779 vlayout->addWidget( mMaxLineEdit );
1781 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1782 mDefaultLineEdit =
new QLineEdit();
1783 vlayout->addWidget( mDefaultLineEdit );
1785 vlayout->addWidget(
new QLabel( tr(
"Default unit type" ) ) );
1787 mUnitsCombo =
new QComboBox();
1797 vlayout->addWidget( mUnitsCombo );
1803 mMinLineEdit->setText( QLocale().toString( durationParam->minimum() ) );
1804 mMaxLineEdit->setText( QLocale().toString( durationParam->maximum() ) );
1805 mDefaultLineEdit->setText( durationParam->defaultValueForGui().toString() );
1806 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( durationParam->defaultUnit() ) ) );
1812 setLayout( vlayout );
1820 auto param = std::make_unique<QgsProcessingParameterDuration>( name, description, ok ? val : QVariant() );
1825 param->setMinimum( val );
1831 param->setMaximum( val );
1834 param->setDefaultUnit(
static_cast<Qgis::TemporalUnit>( mUnitsCombo->currentData().toInt() ) );
1836 param->setFlags( flags );
1837 return param.release();
1841 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1844QString QgsProcessingDurationWidgetWrapper::parameterType()
const
1851 return new QgsProcessingDurationWidgetWrapper( parameter, type );
1854QWidget *QgsProcessingDurationWidgetWrapper::createWidget()
1858 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1863 mUnitsCombo =
new QComboBox();
1875 QHBoxLayout *layout =
new QHBoxLayout();
1876 layout->addWidget( spin, 1 );
1877 layout->insertWidget( 1, mUnitsCombo );
1879 QWidget *w =
new QWidget();
1880 layout->setContentsMargins( 0, 0, 0, 0 );
1881 w->setLayout( layout );
1883 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( durationDef->
defaultUnit() ) ) );
1884 mUnitsCombo->show();
1896QLabel *QgsProcessingDurationWidgetWrapper::createLabel()
1908QVariant QgsProcessingDurationWidgetWrapper::widgetValue()
const
1910 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1911 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo )
1922void QgsProcessingDurationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1928 QgsProcessingNumericWidgetWrapper::setWidgetValue( val, context );
1932 QgsProcessingNumericWidgetWrapper::setWidgetValue( value, context );
1940 return new QgsProcessingDurationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1947QgsProcessingScaleParameterDefinitionWidget::QgsProcessingScaleParameterDefinitionWidget(
1952 QVBoxLayout *vlayout =
new QVBoxLayout();
1953 vlayout->setContentsMargins( 0, 0, 0, 0 );
1955 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1957 mDefaultLineEdit =
new QLineEdit();
1961 mDefaultLineEdit->setText( scaleParam->defaultValueForGui().toString() );
1964 vlayout->addWidget( mDefaultLineEdit );
1967 setLayout( vlayout );
1973 double val = mDefaultLineEdit->text().toDouble( &ok );
1974 auto param = std::make_unique<QgsProcessingParameterScale>( name, description, ok ? val : QVariant() );
1975 param->setFlags( flags );
1976 return param.release();
1980 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1983QString QgsProcessingScaleWidgetWrapper::parameterType()
const
1990 return new QgsProcessingScaleWidgetWrapper( parameter, type );
1993QWidget *QgsProcessingScaleWidgetWrapper::createWidget()
2005 mScaleWidget->setAllowNull(
true );
2007 mScaleWidget->setMapCanvas( widgetContext().mapCanvas() );
2008 mScaleWidget->setShowCurrentScaleButton(
true );
2010 mScaleWidget->setToolTip( parameterDefinition()->toolTip() );
2012 return mScaleWidget;
2021 mScaleWidget->setMapCanvas( context.
mapCanvas() );
2026QVariant QgsProcessingScaleWidgetWrapper::widgetValue()
const
2028 return mScaleWidget && !mScaleWidget->isNull() ? QVariant( mScaleWidget->scale() ) : QVariant();
2031void QgsProcessingScaleWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2035 if ( mScaleWidget->allowNull() && !value.isValid() )
2036 mScaleWidget->setNull();
2040 mScaleWidget->setScale( v );
2049 return new QgsProcessingScaleParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2057QgsProcessingRangeParameterDefinitionWidget::QgsProcessingRangeParameterDefinitionWidget(
2062 QVBoxLayout *vlayout =
new QVBoxLayout();
2063 vlayout->setContentsMargins( 0, 0, 0, 0 );
2065 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
2067 mTypeComboBox =
new QComboBox();
2070 vlayout->addWidget( mTypeComboBox );
2072 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
2073 mMinLineEdit =
new QLineEdit();
2074 vlayout->addWidget( mMinLineEdit );
2076 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
2077 mMaxLineEdit =
new QLineEdit();
2078 vlayout->addWidget( mMaxLineEdit );
2082 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( rangeParam->dataType() ) ) );
2084 mMinLineEdit->setText( QLocale().toString( range.at( 0 ) ) );
2085 mMaxLineEdit->setText( QLocale().toString( range.at( 1 ) ) );
2092 setLayout( vlayout );
2097 QString defaultValue;
2098 if ( mMinLineEdit->text().isEmpty() )
2100 defaultValue = u
"None"_s;
2108 defaultValue = u
"None"_s;
2112 if ( mMaxLineEdit->text().isEmpty() )
2114 defaultValue +=
",None"_L1;
2120 defaultValue += u
",%1"_s.arg( ok ? QString::number( val ) :
"None"_L1 );
2124 auto param = std::make_unique<QgsProcessingParameterRange>( name, description, dataType, defaultValue );
2125 param->setFlags( flags );
2126 return param.release();
2134QWidget *QgsProcessingRangeWidgetWrapper::createWidget()
2143 QHBoxLayout *layout =
new QHBoxLayout();
2148 mMinSpinBox->setExpressionsEnabled(
true );
2149 mMinSpinBox->setShowClearButton(
false );
2150 mMaxSpinBox->setExpressionsEnabled(
true );
2151 mMaxSpinBox->setShowClearButton(
false );
2153 QLabel *minLabel =
new QLabel( tr(
"Min" ) );
2154 layout->addWidget( minLabel );
2155 layout->addWidget( mMinSpinBox, 1 );
2157 QLabel *maxLabel =
new QLabel( tr(
"Max" ) );
2158 layout->addWidget( maxLabel );
2159 layout->addWidget( mMaxSpinBox, 1 );
2161 QWidget *w =
new QWidget();
2162 layout->setContentsMargins( 0, 0, 0, 0 );
2163 w->setLayout( layout );
2167 mMinSpinBox->setDecimals( 6 );
2168 mMaxSpinBox->setDecimals( 6 );
2172 mMinSpinBox->setDecimals( 0 );
2173 mMaxSpinBox->setDecimals( 0 );
2176 mMinSpinBox->setMinimum( -99999999.999999 );
2177 mMaxSpinBox->setMinimum( -99999999.999999 );
2178 mMinSpinBox->setMaximum( 99999999.999999 );
2179 mMaxSpinBox->setMaximum( 99999999.999999 );
2183 mAllowingNull =
true;
2185 const double min = mMinSpinBox->minimum() - 1;
2186 mMinSpinBox->setMinimum( min );
2187 mMaxSpinBox->setMinimum( min );
2188 mMinSpinBox->setValue( min );
2189 mMaxSpinBox->setValue( min );
2191 mMinSpinBox->setShowClearButton(
true );
2192 mMaxSpinBox->setShowClearButton(
true );
2193 mMinSpinBox->setSpecialValueText( tr(
"Not set" ) );
2194 mMaxSpinBox->setSpecialValueText( tr(
"Not set" ) );
2197 w->setToolTip( parameterDefinition()->toolTip() );
2199 connect( mMinSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this](
const double v ) {
2200 mBlockChangedSignal++;
2201 if ( !mAllowingNull && v > mMaxSpinBox->value() )
2202 mMaxSpinBox->setValue( v );
2203 mBlockChangedSignal--;
2205 if ( !mBlockChangedSignal )
2206 emit widgetValueHasChanged(
this );
2208 connect( mMaxSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this](
const double v ) {
2209 mBlockChangedSignal++;
2210 if ( !mAllowingNull && v < mMinSpinBox->value() )
2211 mMinSpinBox->setValue( v );
2212 mBlockChangedSignal--;
2214 if ( !mBlockChangedSignal )
2215 emit widgetValueHasChanged(
this );
2224void QgsProcessingRangeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2227 if ( mAllowingNull && v.empty() )
2229 mMinSpinBox->clear();
2230 mMaxSpinBox->clear();
2237 if ( mAllowingNull )
2239 mBlockChangedSignal++;
2240 if ( std::isnan( v.at( 0 ) ) )
2241 mMinSpinBox->clear();
2243 mMinSpinBox->setValue( v.at( 0 ) );
2245 if ( v.count() >= 2 )
2247 if ( std::isnan( v.at( 1 ) ) )
2248 mMaxSpinBox->clear();
2250 mMaxSpinBox->setValue( v.at( 1 ) );
2252 mBlockChangedSignal--;
2256 mBlockChangedSignal++;
2257 mMinSpinBox->setValue( v.at( 0 ) );
2258 if ( v.count() >= 2 )
2259 mMaxSpinBox->setValue( v.at( 1 ) );
2260 mBlockChangedSignal--;
2264 if ( !mBlockChangedSignal )
2265 emit widgetValueHasChanged(
this );
2268QVariant QgsProcessingRangeWidgetWrapper::widgetValue()
const
2270 if ( mAllowingNull )
2273 if (
qgsDoubleNear( mMinSpinBox->value(), mMinSpinBox->minimum() ) )
2276 value = QString::number( mMinSpinBox->value() );
2278 if (
qgsDoubleNear( mMaxSpinBox->value(), mMaxSpinBox->minimum() ) )
2279 value +=
",None"_L1;
2281 value += u
",%1"_s.arg( mMaxSpinBox->value() );
2286 return u
"%1,%2"_s.arg( mMinSpinBox->value() ).arg( mMaxSpinBox->value() );
2289QString QgsProcessingRangeWidgetWrapper::modelerExpressionFormatString()
const
2291 return tr(
"string as two comma delimited floats, e.g. '1,10'" );
2294QString QgsProcessingRangeWidgetWrapper::parameterType()
const
2301 return new QgsProcessingRangeWidgetWrapper( parameter, type );
2308 return new QgsProcessingRangeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2316QgsProcessingMatrixParameterDefinitionWidget::QgsProcessingMatrixParameterDefinitionWidget(
2321 QVBoxLayout *vlayout =
new QVBoxLayout();
2322 vlayout->setContentsMargins( 0, 0, 0, 0 );
2324 mMatrixWidget =
new QgsProcessingMatrixModelerWidget();
2327 mMatrixWidget->setValue( matrixParam->headers(), matrixParam->defaultValueForGui() );
2328 mMatrixWidget->setFixedRows( matrixParam->hasFixedNumberRows() );
2330 vlayout->addWidget( mMatrixWidget );
2334 setLayout( vlayout );
2339 auto param = std::make_unique<QgsProcessingParameterMatrix>( name, description, 1, mMatrixWidget->fixedRows(), mMatrixWidget->headers(), mMatrixWidget->value() );
2340 param->setFlags( flags );
2341 return param.release();
2349QWidget *QgsProcessingMatrixWidgetWrapper::createWidget()
2351 mMatrixWidget =
new QgsProcessingMatrixParameterPanel(
nullptr,
dynamic_cast<const QgsProcessingParameterMatrix *
>( parameterDefinition() ) );
2352 mMatrixWidget->setToolTip( parameterDefinition()->toolTip() );
2354 connect( mMatrixWidget, &QgsProcessingMatrixParameterPanel::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
2362 return mMatrixWidget;
2368void QgsProcessingMatrixWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2371 if ( mMatrixWidget )
2372 mMatrixWidget->setValue( v );
2375QVariant QgsProcessingMatrixWidgetWrapper::widgetValue()
const
2377 if ( mMatrixWidget )
2378 return mMatrixWidget->value().isEmpty() ? QVariant() : mMatrixWidget->value();
2383QString QgsProcessingMatrixWidgetWrapper::modelerExpressionFormatString()
const
2385 return tr(
"comma delimited string of values, or an array of values" );
2388QString QgsProcessingMatrixWidgetWrapper::parameterType()
const
2395 return new QgsProcessingMatrixWidgetWrapper( parameter, type );
2402 return new QgsProcessingMatrixParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2411QgsProcessingFileParameterDefinitionWidget::QgsProcessingFileParameterDefinitionWidget(
2416 QVBoxLayout *vlayout =
new QVBoxLayout();
2417 vlayout->setContentsMargins( 0, 0, 0, 0 );
2419 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
2421 mTypeComboBox =
new QComboBox();
2425 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( fileParam->behavior() ) ) );
2427 mTypeComboBox->setCurrentIndex( 0 );
2428 vlayout->addWidget( mTypeComboBox );
2432 vlayout->addWidget(
new QLabel( tr(
"File filter" ) ) );
2434 mFilterComboBox =
new QComboBox();
2435 mFilterComboBox->setEditable(
true );
2437 mFilterComboBox->addItem( tr(
"All Files (*.*)" ) );
2438 mFilterComboBox->addItem( tr(
"CSV Files (*.csv)" ) );
2439 mFilterComboBox->addItem( tr(
"HTML Files (*.html *.htm)" ) );
2440 mFilterComboBox->addItem( tr(
"Text Files (*.txt)" ) );
2442 mFilterComboBox->setCurrentText( fileParam->fileFilter() );
2444 mFilterComboBox->setCurrentIndex( 0 );
2445 vlayout->addWidget( mFilterComboBox );
2449 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2452 mDefaultFileWidget->lineEdit()->setShowClearButton(
true );
2456 mDefaultFileWidget->setFilePath( fileParam->defaultValueForGui().toString() );
2460 vlayout->addWidget( mDefaultFileWidget );
2463 connect( mTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this] {
2471 setLayout( vlayout );
2476 auto param = std::make_unique<QgsProcessingParameterFile>( name, description );
2479 param->setFileFilter( mFilterComboBox->currentText() );
2480 if ( !mDefaultFileWidget->filePath().isEmpty() )
2481 param->setDefaultValue( mDefaultFileWidget->filePath() );
2482 param->setFlags( flags );
2483 return param.release();
2491QWidget *QgsProcessingFileWidgetWrapper::createWidget()
2504 mFileWidget->setToolTip( parameterDefinition()->toolTip() );
2505 mFileWidget->setDialogTitle( parameterDefinition()->description() );
2507 mFileWidget->setDefaultRoot(
QgsSettings().value( u
"/Processing/LastInputPath"_s, QDir::homePath() ).toString() );
2514 mFileWidget->setFilter( fileParam->
fileFilter() );
2515 else if ( !fileParam->
extension().isEmpty() )
2516 mFileWidget->setFilter( tr(
"%1 files" ).arg( fileParam->
extension().toUpper() ) + u
" (*."_s + fileParam->
extension().toLower() +
')' );
2525 QgsSettings().
setValue( u
"/Processing/LastInputPath"_s, QFileInfo( path ).canonicalPath() );
2526 emit widgetValueHasChanged(
this );
2534void QgsProcessingFileWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2538 mFileWidget->setFilePath( v );
2541QVariant QgsProcessingFileWidgetWrapper::widgetValue()
const
2544 return mFileWidget->filePath();
2549QString QgsProcessingFileWidgetWrapper::modelerExpressionFormatString()
const
2551 return tr(
"string representing a path to a file or folder" );
2554QString QgsProcessingFileWidgetWrapper::parameterType()
const
2561 return new QgsProcessingFileWidgetWrapper( parameter, type );
2568 return new QgsProcessingFileParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2576QgsProcessingExpressionParameterDefinitionWidget::QgsProcessingExpressionParameterDefinitionWidget(
2581 QVBoxLayout *vlayout =
new QVBoxLayout();
2582 vlayout->setContentsMargins( 0, 0, 0, 0 );
2583 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2586 mDefaultQgisLineEdit->registerExpressionContextGenerator(
this );
2588 mDefaultPointCloudLineEdit =
new QgsProcessingPointCloudExpressionLineEdit();
2589 mDefaultRasterCalculatorLineEdit =
new QgsProcessingRasterCalculatorExpressionLineEdit();
2591 QStackedWidget *stackedWidget =
new QStackedWidget();
2592 stackedWidget->addWidget( mDefaultQgisLineEdit );
2593 stackedWidget->addWidget( mDefaultPointCloudLineEdit );
2594 stackedWidget->addWidget( mDefaultRasterCalculatorLineEdit );
2595 vlayout->addWidget( stackedWidget );
2604 mDefaultQgisLineEdit->setExpression( expr );
2605 mDefaultPointCloudLineEdit->setExpression( expr );
2608 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
2610 mParentLayerComboBox =
new QComboBox();
2611 vlayout->addWidget( mParentLayerComboBox );
2613 vlayout->addWidget(
new QLabel( tr(
"Expression type" ) ) );
2614 mExpressionTypeComboBox =
new QComboBox();
2619 connect( mExpressionTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [
this, stackedWidget, definition, widgetContext](
int ) {
2620 mParentLayerComboBox->clear();
2621 mParentLayerComboBox->addItem( tr(
"None" ), QVariant() );
2623 stackedWidget->setCurrentIndex( mExpressionTypeComboBox->currentIndex() > 0 ? mExpressionTypeComboBox->currentIndex() : 0 );
2625 QString initialParent;
2627 initialParent = expParam->parentLayerParameterName();
2631 if ( QgsProcessingModelAlgorithm *model = widgetContext.
model() )
2634 const QMap<QString, QgsProcessingModelParameter> components = model->parameterComponents();
2635 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
2642 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2643 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2645 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2650 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2651 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2653 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2660 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2661 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2663 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2674 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2675 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2677 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2685 if ( mParentLayerComboBox->count() == 1 && !initialParent.isEmpty() )
2688 mParentLayerComboBox->addItem( initialParent, initialParent );
2689 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2693 mExpressionTypeComboBox->setCurrentIndex( -1 );
2695 mExpressionTypeComboBox->setCurrentIndex( mExpressionTypeComboBox->findData(
static_cast<int>( expParam->expressionType() ) ) );
2697 mExpressionTypeComboBox->setCurrentIndex( 0 );
2699 vlayout->addWidget( mExpressionTypeComboBox );
2704 setLayout( vlayout );
2711 switch ( expressionType )
2714 expression = mDefaultQgisLineEdit->expression();
2717 expression = mDefaultPointCloudLineEdit->expression();
2720 expression = mDefaultRasterCalculatorLineEdit->expression();
2723 auto param = std::make_unique<QgsProcessingParameterExpression>( name, description, expression, mParentLayerComboBox->currentData().toString(),
false, expressionType );
2724 param->setFlags( flags );
2725 return param.release();
2732QWidget *QgsProcessingExpressionWidgetWrapper::createWidget()
2747 mExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2748 mExpLineEdit->setExpressionDialogTitle( parameterDefinition()->description() );
2749 mExpLineEdit->registerExpressionContextGenerator(
this );
2751 return mExpLineEdit;
2757 mPointCloudExpLineEdit =
new QgsProcessingPointCloudExpressionLineEdit();
2758 mPointCloudExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2759 connect( mPointCloudExpLineEdit, &QgsProcessingPointCloudExpressionLineEdit::expressionChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
2760 return mPointCloudExpLineEdit;
2765 mRasterCalculatorExpLineEdit =
new QgsProcessingRasterCalculatorExpressionLineEdit();
2766 mRasterCalculatorExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2769 mRasterCalculatorExpLineEdit->setLayers( QVariantList() <<
"A" <<
"B" <<
"C" <<
"D" <<
"E" <<
"F" <<
"G" );
2771 connect( mRasterCalculatorExpLineEdit, &QgsProcessingRasterCalculatorExpressionLineEdit::expressionChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
2772 return mRasterCalculatorExpLineEdit;
2776 if ( expParam->
metadata().value( u
"inlineEditor"_s ).toBool() )
2779 mExpBuilderWidget->setToolTip( parameterDefinition()->toolTip() );
2780 mExpBuilderWidget->init( createExpressionContext() );
2782 Q_UNUSED( changed );
2783 emit widgetValueHasChanged(
this );
2785 return mExpBuilderWidget;
2790 mFieldExpWidget->setToolTip( parameterDefinition()->toolTip() );
2791 mFieldExpWidget->setExpressionDialogTitle( parameterDefinition()->description() );
2792 mFieldExpWidget->registerExpressionContextGenerator(
this );
2794 mFieldExpWidget->setAllowEmptyFieldName(
true );
2797 emit widgetValueHasChanged(
this );
2799 return mFieldExpWidget;
2807void QgsProcessingExpressionWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
2819 setParentLayerWrapperValue( wrapper );
2835 if ( mExpBuilderWidget )
2838 mExpBuilderWidget->setExpressionContext( createExpressionContext() );
2846 std::unique_ptr<QgsProcessingContext> tmpContext;
2847 if ( mProcessingContextGenerator )
2848 context = mProcessingContextGenerator->processingContext();
2852 tmpContext = std::make_unique<QgsProcessingContext>();
2853 context = tmpContext.get();
2866 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2876 if ( mFieldExpWidget )
2877 mFieldExpWidget->setLayer(
nullptr );
2878 else if ( mExpBuilderWidget )
2879 mExpBuilderWidget->setLayer(
nullptr );
2880 else if ( mExpLineEdit )
2881 mExpLineEdit->setLayer(
nullptr );
2887 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
2890 mParentLayer = std::move( ownedLayer );
2898 if ( mFieldExpWidget )
2899 mFieldExpWidget->setLayer( layer );
2900 if ( mExpBuilderWidget )
2901 mExpBuilderWidget->setLayer( layer );
2902 else if ( mExpLineEdit )
2903 mExpLineEdit->setLayer( layer );
2912 if ( mPointCloudExpLineEdit )
2913 mPointCloudExpLineEdit->setLayer(
nullptr );
2919 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
2922 mParentLayer = std::move( ownedLayer );
2930 if ( mPointCloudExpLineEdit )
2931 mPointCloudExpLineEdit->setLayer( layer );
2938 if ( layers.isEmpty() )
2940 if ( mRasterCalculatorExpLineEdit )
2942 mRasterCalculatorExpLineEdit->setLayers( val.userType() == QMetaType::Type::QVariantList ? val.toList() : QVariantList() << val );
2947 if ( mRasterCalculatorExpLineEdit )
2949 QVariantList layersList;
2952 layersList << layer->
name();
2954 mRasterCalculatorExpLineEdit->setLayers( layersList );
2962void QgsProcessingExpressionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2965 if ( mFieldExpWidget )
2966 mFieldExpWidget->setExpression( v );
2967 else if ( mExpBuilderWidget )
2968 mExpBuilderWidget->setExpressionText( v );
2969 else if ( mExpLineEdit )
2970 mExpLineEdit->setExpression( v );
2971 else if ( mPointCloudExpLineEdit )
2972 mPointCloudExpLineEdit->setExpression( v );
2973 else if ( mRasterCalculatorExpLineEdit )
2974 mRasterCalculatorExpLineEdit->setExpression( v );
2977QVariant QgsProcessingExpressionWidgetWrapper::widgetValue()
const
2979 if ( mFieldExpWidget )
2980 return mFieldExpWidget->expression();
2981 if ( mExpBuilderWidget )
2982 return mExpBuilderWidget->expressionText();
2983 else if ( mExpLineEdit )
2984 return mExpLineEdit->expression();
2985 else if ( mPointCloudExpLineEdit )
2986 return mPointCloudExpLineEdit->expression();
2987 else if ( mRasterCalculatorExpLineEdit )
2988 return mRasterCalculatorExpLineEdit->expression();
2993QString QgsProcessingExpressionWidgetWrapper::modelerExpressionFormatString()
const
2995 return tr(
"string representation of an expression" );
2998const QgsVectorLayer *QgsProcessingExpressionWidgetWrapper::linkedVectorLayer()
const
3000 if ( mFieldExpWidget && mFieldExpWidget->layer() )
3001 return mFieldExpWidget->layer();
3003 if ( mExpBuilderWidget && mExpBuilderWidget->layer() )
3004 return mExpBuilderWidget->layer();
3009QString QgsProcessingExpressionWidgetWrapper::parameterType()
const
3016 return new QgsProcessingExpressionWidgetWrapper( parameter, type );
3023 return new QgsProcessingExpressionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3035 QHBoxLayout *hl =
new QHBoxLayout();
3036 hl->setContentsMargins( 0, 0, 0, 0 );
3038 mLineEdit =
new QLineEdit();
3039 mLineEdit->setEnabled(
false );
3040 hl->addWidget( mLineEdit, 1 );
3042 mToolButton =
new QToolButton();
3043 mToolButton->setText( QString( QChar( 0x2026 ) ) );
3044 hl->addWidget( mToolButton );
3050 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
3053 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingEnumPanelWidget::showDialog );
3056void QgsProcessingEnumPanelWidget::setValue(
const QVariant &value )
3058 if ( value.isValid() )
3060 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
3062 if ( mParam->usesStaticStrings() && mValue.count() == 1 && mValue.at( 0 ).toString().isEmpty() )
3068 updateSummaryText();
3072void QgsProcessingEnumPanelWidget::showDialog()
3074 QVariantList availableOptions;
3077 availableOptions.reserve( mParam->options().size() );
3079 if ( mParam->usesStaticStrings() )
3081 for ( QString o : mParam->options() )
3083 availableOptions << o;
3088 for (
int i = 0; i < mParam->options().count(); ++i )
3089 availableOptions << i;
3093 const QStringList options = mParam ? mParam->options() : QStringList();
3097 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
3098 widget->setPanelTitle( mParam->description() );
3100 if ( mParam->usesStaticStrings() )
3102 widget->setValueFormatter( [options](
const QVariant &v ) -> QString {
3103 const QString i = v.toString();
3104 return options.contains( i ) ? i : QString();
3109 widget->setValueFormatter( [options](
const QVariant &v ) -> QString {
3110 const int i = v.toInt();
3111 return options.size() > i ? options.at( i ) : QString();
3115 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
3121 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
3123 dlg.setValueFormatter( [options](
const QVariant &v ) -> QString {
3124 const int i = v.toInt();
3125 return options.size() > i ? options.at( i ) : QString();
3129 setValue( dlg.selectedOptions() );
3134void QgsProcessingEnumPanelWidget::updateSummaryText()
3139 if ( mValue.empty() )
3141 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
3146 values.reserve( mValue.size() );
3147 if ( mParam->usesStaticStrings() )
3149 for (
const QVariant &val : std::as_const( mValue ) )
3151 values << val.toString();
3156 const QStringList options = mParam->options();
3157 for (
const QVariant &val : std::as_const( mValue ) )
3159 const int i = val.toInt();
3160 values << ( options.size() > i ? options.at( i ) : QString() );
3164 const QString concatenated = values.join( tr(
"," ) );
3165 if ( concatenated.length() < 100 )
3166 mLineEdit->setText( concatenated );
3168 mLineEdit->setText( tr(
"%n option(s) selected",
nullptr, mValue.count() ) );
3176QgsProcessingEnumCheckboxPanelWidget::QgsProcessingEnumCheckboxPanelWidget( QWidget *parent,
const QgsProcessingParameterEnum *param,
int columns )
3179 , mButtonGroup( new QButtonGroup( this ) )
3180 , mColumns( columns )
3182 mButtonGroup->setExclusive( !mParam->allowMultiple() );
3184 QGridLayout *l =
new QGridLayout();
3185 l->setContentsMargins( 0, 0, 0, 0 );
3187 int rows =
static_cast<int>( std::ceil( mParam->options().count() /
static_cast<double>( mColumns ) ) );
3188 for (
int i = 0; i < mParam->options().count(); ++i )
3190 QAbstractButton *button =
nullptr;
3191 if ( mParam->allowMultiple() )
3192 button =
new QCheckBox( mParam->options().at( i ) );
3194 button =
new QRadioButton( mParam->options().at( i ) );
3196 connect( button, &QAbstractButton::toggled,
this, [
this] {
3197 if ( !mBlockChangedSignal )
3201 mButtons.insert( i, button );
3203 mButtonGroup->addButton( button, i );
3204 l->addWidget( button, i % rows, i / rows );
3206 l->addItem(
new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, mColumns );
3209 if ( mParam->allowMultiple() )
3211 setContextMenuPolicy( Qt::CustomContextMenu );
3212 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsProcessingEnumCheckboxPanelWidget::showPopupMenu );
3216QVariant QgsProcessingEnumCheckboxPanelWidget::value()
const
3218 if ( mParam->allowMultiple() )
3221 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3223 if ( it.value()->isChecked() )
3224 value.append( mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key() );
3230 if ( mParam->usesStaticStrings() )
3231 return mButtonGroup->checkedId() >= 0 ? mParam->options().at( mButtonGroup->checkedId() ) : QVariant();
3233 return mButtonGroup->checkedId() >= 0 ? mButtonGroup->checkedId() : QVariant();
3237void QgsProcessingEnumCheckboxPanelWidget::setValue(
const QVariant &value )
3239 mBlockChangedSignal =
true;
3240 if ( mParam->allowMultiple() )
3242 QVariantList selected;
3243 if ( value.isValid() )
3244 selected = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
3245 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3247 QVariant v = mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key();
3248 it.value()->setChecked( selected.contains( v ) );
3254 if ( v.userType() == QMetaType::Type::QVariantList )
3255 v = v.toList().value( 0 );
3257 v = mParam->usesStaticStrings() ?
static_cast< int >( mParam->options().indexOf( v.toString() ) ) : v;
3258 if ( mButtons.contains( v ) )
3259 mButtons.value( v )->setChecked(
true );
3261 mBlockChangedSignal =
false;
3265void QgsProcessingEnumCheckboxPanelWidget::showPopupMenu()
3268 QAction *selectAllAction =
new QAction( tr(
"Select All" ), &popupMenu );
3269 connect( selectAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::selectAll );
3270 QAction *clearAllAction =
new QAction( tr(
"Clear Selection" ), &popupMenu );
3271 connect( clearAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::deselectAll );
3272 popupMenu.addAction( selectAllAction );
3273 popupMenu.addAction( clearAllAction );
3274 popupMenu.exec( QCursor::pos() );
3277void QgsProcessingEnumCheckboxPanelWidget::selectAll()
3279 mBlockChangedSignal =
true;
3280 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3281 it.value()->setChecked(
true );
3282 mBlockChangedSignal =
false;
3286void QgsProcessingEnumCheckboxPanelWidget::deselectAll()
3288 mBlockChangedSignal =
true;
3289 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3290 it.value()->setChecked(
false );
3291 mBlockChangedSignal =
false;
3300QgsProcessingEnumParameterDefinitionWidget::QgsProcessingEnumParameterDefinitionWidget(
3305 QVBoxLayout *vlayout =
new QVBoxLayout();
3306 vlayout->setContentsMargins( 0, 0, 0, 0 );
3308 mEnumWidget =
new QgsProcessingEnumModelerWidget();
3311 mEnumWidget->setAllowMultiple( enumParam->allowMultiple() );
3312 mEnumWidget->setOptions( enumParam->options() );
3313 mEnumWidget->setDefaultOptions( enumParam->defaultValueForGui() );
3315 vlayout->addWidget( mEnumWidget );
3319 setLayout( vlayout );
3324 auto param = std::make_unique<QgsProcessingParameterEnum>( name, description, mEnumWidget->options(), mEnumWidget->allowMultiple(), mEnumWidget->defaultOptions() );
3326 return param.release();
3334QWidget *QgsProcessingEnumWidgetWrapper::createWidget()
3345 if ( expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"useCheckBoxes"_s,
false ).toBool() )
3347 const int columns = expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"columns"_s, 2 ).toInt();
3348 mCheckboxPanel =
new QgsProcessingEnumCheckboxPanelWidget(
nullptr, expParam, columns );
3349 mCheckboxPanel->setToolTip( parameterDefinition()->toolTip() );
3350 connect( mCheckboxPanel, &QgsProcessingEnumCheckboxPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
3351 return mCheckboxPanel;
3360 mPanel =
new QgsProcessingEnumPanelWidget(
nullptr, expParam );
3361 mPanel->setToolTip( parameterDefinition()->toolTip() );
3362 connect( mPanel, &QgsProcessingEnumPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
3367 mComboBox =
new QComboBox();
3370 mComboBox->addItem( tr(
"[Not selected]" ), QVariant() );
3371 const QStringList options = expParam->
options();
3372 const QVariantList iconList = expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"icons"_s ).toList();
3373 for (
int i = 0; i < options.count(); ++i )
3375 const QIcon icon = iconList.value( i ).value<QIcon>();
3378 mComboBox->addItem( icon, options.at( i ), options.at( i ) );
3380 mComboBox->addItem( icon, options.at( i ), i );
3383 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3384 mComboBox->setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon );
3385 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
3393void QgsProcessingEnumWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3397 if ( !value.isValid() )
3398 mComboBox->setCurrentIndex( mComboBox->findData( QVariant() ) );
3404 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
3409 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
3413 else if ( mPanel || mCheckboxPanel )
3416 if ( value.isValid() )
3421 opts.reserve( v.size() );
3422 for ( QString i : v )
3428 opts.reserve( v.size() );
3434 mPanel->setValue( opts );
3435 else if ( mCheckboxPanel )
3436 mCheckboxPanel->setValue( opts );
3440QVariant QgsProcessingEnumWidgetWrapper::widgetValue()
const
3443 return mComboBox->currentData();
3445 return mPanel->value();
3446 else if ( mCheckboxPanel )
3447 return mCheckboxPanel->value();
3452QString QgsProcessingEnumWidgetWrapper::modelerExpressionFormatString()
const
3454 return tr(
"selected option index (starting from 0), array of indices, or comma separated string of options (e.g. '1,3')" );
3457QString QgsProcessingEnumWidgetWrapper::parameterType()
const
3464 return new QgsProcessingEnumWidgetWrapper( parameter, type );
3471 return new QgsProcessingEnumParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3482QWidget *QgsProcessingLayoutWidgetWrapper::createWidget()
3494 mComboBox =
new QgsLayoutComboBox(
nullptr, widgetContext().project() ? widgetContext().project()->layoutManager() :
nullptr );
3496 mComboBox->setAllowEmptyLayout(
true );
3499 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3506 mPlainComboBox =
new QComboBox();
3507 mPlainComboBox->setEditable(
true );
3508 mPlainComboBox->setToolTip( tr(
"Name of an existing print layout" ) );
3509 if ( widgetContext().project() )
3513 mPlainComboBox->addItem( layout->name() );
3516 connect( mPlainComboBox, &QComboBox::currentTextChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
3517 return mPlainComboBox;
3523void QgsProcessingLayoutWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3527 if ( !value.isValid() )
3528 mComboBox->setCurrentLayout(
nullptr );
3532 mComboBox->setCurrentLayout( l );
3534 mComboBox->setCurrentLayout(
nullptr );
3537 else if ( mPlainComboBox )
3540 mPlainComboBox->setCurrentText( v );
3544QVariant QgsProcessingLayoutWidgetWrapper::widgetValue()
const
3549 return l ? l->
name() : QVariant();
3551 else if ( mPlainComboBox )
3552 return mPlainComboBox->currentText().isEmpty() ? QVariant() : mPlainComboBox->currentText();
3560 if ( mPlainComboBox && context.
project() )
3564 mPlainComboBox->addItem( layout->name() );
3568QString QgsProcessingLayoutWidgetWrapper::modelerExpressionFormatString()
const
3570 return tr(
"string representing the name of an existing print layout" );
3573QString QgsProcessingLayoutWidgetWrapper::parameterType()
const
3580 return new QgsProcessingLayoutWidgetWrapper( parameter, type );
3589QgsProcessingLayoutItemParameterDefinitionWidget::QgsProcessingLayoutItemParameterDefinitionWidget(
3594 QVBoxLayout *vlayout =
new QVBoxLayout();
3595 vlayout->setContentsMargins( 0, 0, 0, 0 );
3597 vlayout->addWidget(
new QLabel( tr(
"Parent layout" ) ) );
3599 mParentLayoutComboBox =
new QComboBox();
3600 QString initialParent;
3602 initialParent = itemParam->parentLayoutParameterName();
3604 if (
auto *lModel = widgetContext.
model() )
3607 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3608 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3612 mParentLayoutComboBox->addItem( definition->
description(), definition->
name() );
3613 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
3615 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3621 if ( mParentLayoutComboBox->count() == 0 && !initialParent.isEmpty() )
3624 mParentLayoutComboBox->addItem( initialParent, initialParent );
3625 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3628 vlayout->addWidget( mParentLayoutComboBox );
3632 setLayout( vlayout );
3636 auto param = std::make_unique<QgsProcessingParameterLayoutItem>( name, description, QVariant(), mParentLayoutComboBox->currentData().toString() );
3638 return param.release();
3646QWidget *QgsProcessingLayoutItemWidgetWrapper::createWidget()
3660 mComboBox->setAllowEmptyItem(
true );
3661 if ( layoutParam->
itemType() >= 0 )
3664 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3671 mLineEdit =
new QLineEdit();
3672 mLineEdit->setToolTip( tr(
"UUID or ID of an existing print layout item" ) );
3673 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
3680void QgsProcessingLayoutItemWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3705void QgsProcessingLayoutItemWidgetWrapper::setLayoutParameterValue(
const QVariant &value )
3711 std::unique_ptr<QgsProcessingContext> tmpContext;
3712 if ( mProcessingContextGenerator )
3713 context = mProcessingContextGenerator->processingContext();
3717 tmpContext = std::make_unique<QgsProcessingContext>();
3718 context = tmpContext.get();
3722 setLayout( layout );
3725void QgsProcessingLayoutItemWidgetWrapper::setLayout(
QgsPrintLayout *layout )
3728 mComboBox->setCurrentLayout( layout );
3731void QgsProcessingLayoutItemWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3735 if ( !value.isValid() )
3736 mComboBox->setItem(
nullptr );
3740 mComboBox->setItem( item );
3743 else if ( mLineEdit )
3746 mLineEdit->setText( v );
3750QVariant QgsProcessingLayoutItemWidgetWrapper::widgetValue()
const
3755 return i ? i->
uuid() : QVariant();
3757 else if ( mLineEdit )
3758 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3764QString QgsProcessingLayoutItemWidgetWrapper::modelerExpressionFormatString()
const
3766 return tr(
"string representing the UUID or ID of an existing print layout item" );
3769QString QgsProcessingLayoutItemWidgetWrapper::parameterType()
const
3776 return new QgsProcessingLayoutItemWidgetWrapper( parameter, type );
3783 return new QgsProcessingLayoutItemParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3790QgsProcessingPointMapTool::QgsProcessingPointMapTool(
QgsMapCanvas *canvas )
3794 mSnapIndicator = std::make_unique<QgsSnapIndicator>( canvas );
3797QgsProcessingPointMapTool::~QgsProcessingPointMapTool() =
default;
3799void QgsProcessingPointMapTool::deactivate()
3813 if ( e->button() == Qt::LeftButton )
3816 emit clicked( point );
3821void QgsProcessingPointMapTool::keyPressEvent( QKeyEvent *e )
3823 if ( e->key() == Qt::Key_Escape )
3836QgsProcessingPointPanel::QgsProcessingPointPanel( QWidget *parent )
3839 QHBoxLayout *l =
new QHBoxLayout();
3840 l->setContentsMargins( 0, 0, 0, 0 );
3842 mLineEdit->setShowClearButton(
false );
3843 l->addWidget( mLineEdit, 1 );
3844 mButton =
new QToolButton();
3845 mButton->setText( QString( QChar( 0x2026 ) ) );
3846 l->addWidget( mButton );
3849 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::changed );
3850 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::textChanged );
3851 connect( mButton, &QToolButton::clicked,
this, &QgsProcessingPointPanel::selectOnCanvas );
3852 mButton->setVisible(
false );
3855QgsProcessingPointPanel::~QgsProcessingPointPanel()
3857 if ( mCanvas && mPrevTool && mCanvas->mapTool() == mTool.get() )
3859 mCanvas->setMapTool( mPrevTool.get() );
3863void QgsProcessingPointPanel::setMapCanvas(
QgsMapCanvas *canvas )
3866 if ( mAllowSelectOnCanvas )
3868 mButton->setVisible(
true );
3871 mTool = std::make_unique<QgsProcessingPointMapTool>( mCanvas );
3872 connect( mTool.get(), &QgsProcessingPointMapTool::clicked,
this, &QgsProcessingPointPanel::updatePoint );
3873 connect( mTool.get(), &QgsProcessingPointMapTool::complete,
this, &QgsProcessingPointPanel::pointPicked );
3877void QgsProcessingPointPanel::setAllowNull(
bool allowNull )
3879 mLineEdit->setShowClearButton( allowNull );
3882void QgsProcessingPointPanel::setShowPointOnCanvas(
bool show )
3884 if ( mShowPointOnCanvas == show )
3887 mShowPointOnCanvas = show;
3888 if ( mShowPointOnCanvas )
3894 mMapPointRubberBand.reset();
3898void QgsProcessingPointPanel::setAllowSelectOnCanvas(
bool allow )
3900 mAllowSelectOnCanvas = allow;
3901 mButton->setVisible( mAllowSelectOnCanvas &&
static_cast<bool>( mTool ) );
3904QVariant QgsProcessingPointPanel::value()
const
3906 return mLineEdit->showClearButton() && mLineEdit->text().trimmed().isEmpty() ? QVariant() : QVariant( mLineEdit->text() );
3909void QgsProcessingPointPanel::clear()
3917 QString newText = u
"%1,%2"_s.arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) );
3920 if ( mCrs.isValid() )
3922 newText += u
" [%1]"_s.arg( mCrs.authid() );
3924 mLineEdit->setText( newText );
3928void QgsProcessingPointPanel::showEvent( QShowEvent * )
3933 if ( QWidget *parentWindow = window() )
3935 setAllowSelectOnCanvas( !parentWindow->isModal() );
3941void QgsProcessingPointPanel::selectOnCanvas()
3946 mPrevTool = mCanvas->mapTool();
3947 mCanvas->setMapTool( mTool.get() );
3949 emit toggleDialogVisibility(
false );
3952void QgsProcessingPointPanel::updatePoint(
const QgsPointXY &point )
3954 setValue( point, mCanvas->mapSettings().destinationCrs() );
3957void QgsProcessingPointPanel::pointPicked()
3962 mCanvas->setMapTool( mPrevTool );
3964 emit toggleDialogVisibility(
true );
3967void QgsProcessingPointPanel::textChanged(
const QString &text )
3969 const thread_local QRegularExpression rx( u
"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
3971 const QRegularExpressionMatch match = rx.match( text );
3972 if ( match.hasMatch() )
3975 const double x = match.captured( 1 ).toDouble( &xOk );
3977 const double y = match.captured( 2 ).toDouble( &yOk );
3984 if ( pointCrs.isValid() )
4002void QgsProcessingPointPanel::updateRubberBand()
4004 if ( !mShowPointOnCanvas || !mCanvas )
4007 if ( mPoint.isEmpty() )
4009 mMapPointRubberBand.reset();
4013 if ( !mMapPointRubberBand )
4016 mMapPointRubberBand->setZValue( 1000 );
4019 const double scaleFactor = mCanvas->fontMetrics().xHeight() * .4;
4020 mMapPointRubberBand->setWidth( scaleFactor );
4021 mMapPointRubberBand->setIconSize( scaleFactor * 5 );
4023 mMapPointRubberBand->setSecondaryStrokeColor( QColor( 255, 255, 255, 100 ) );
4024 mMapPointRubberBand->setColor( QColor( 200, 0, 200 ) );
4035QgsProcessingPointParameterDefinitionWidget::QgsProcessingPointParameterDefinitionWidget(
4040 QVBoxLayout *vlayout =
new QVBoxLayout();
4041 vlayout->setContentsMargins( 0, 0, 0, 0 );
4043 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4045 mDefaultLineEdit =
new QLineEdit();
4046 mDefaultLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
4047 mDefaultLineEdit->setPlaceholderText( tr(
"Point as 'x,y'" ) );
4051 mDefaultLineEdit->setText( u
"%1,%2"_s.arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) ) );
4054 vlayout->addWidget( mDefaultLineEdit );
4058 setLayout( vlayout );
4063 auto param = std::make_unique<QgsProcessingParameterPoint>( name, description, mDefaultLineEdit->text() );
4065 return param.release();
4072QWidget *QgsProcessingPointWidgetWrapper::createWidget()
4083 mPanel =
new QgsProcessingPointPanel(
nullptr );
4084 if ( widgetContext().mapCanvas() )
4085 mPanel->setMapCanvas( widgetContext().mapCanvas() );
4088 mPanel->setAllowNull(
true );
4091 mPanel->setShowPointOnCanvas(
true );
4093 mPanel->setToolTip( parameterDefinition()->toolTip() );
4095 connect( mPanel, &QgsProcessingPointPanel::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
4098 setDialog( mDialog );
4104 mLineEdit =
new QLineEdit();
4105 mLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
4106 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
4117 mPanel->setMapCanvas( context.
mapCanvas() );
4120void QgsProcessingPointWidgetWrapper::setDialog( QWidget *dialog )
4125 connect( mPanel, &QgsProcessingPointPanel::toggleDialogVisibility, mDialog, [
this](
bool visible ) {
4127 mDialog->showMinimized();
4130 mDialog->showNormal();
4132 mDialog->activateWindow();
4139void QgsProcessingPointWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4143 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) )
4149 mPanel->setValue( p, crs );
4152 else if ( mLineEdit )
4155 mLineEdit->setText( v );
4159QVariant QgsProcessingPointWidgetWrapper::widgetValue()
const
4163 return mPanel->value();
4165 else if ( mLineEdit )
4166 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
4171QString QgsProcessingPointWidgetWrapper::modelerExpressionFormatString()
const
4173 return tr(
"string of the format 'x,y' or a geometry value (centroid is used)" );
4176QString QgsProcessingPointWidgetWrapper::parameterType()
const
4183 return new QgsProcessingPointWidgetWrapper( parameter, type );
4190 return new QgsProcessingPointParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4199QgsProcessingGeometryParameterDefinitionWidget::QgsProcessingGeometryParameterDefinitionWidget(
4204 QVBoxLayout *vlayout =
new QVBoxLayout();
4205 vlayout->setContentsMargins( 0, 0, 0, 0 );
4207 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4219 vlayout->addWidget( mGeometryWidget );
4223 setLayout( vlayout );
4229 auto param = std::make_unique<QgsProcessingParameterGeometry>( name, description, geometry.
isEmpty() ? QVariant() : geometry.
asWkt() );
4231 return param.release();
4238QWidget *QgsProcessingGeometryWidgetWrapper::createWidget()
4247 mGeometryWidget->setToolTip( parameterDefinition()->toolTip() );
4249 return mGeometryWidget;
4255void QgsProcessingGeometryWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4257 if ( mGeometryWidget )
4266 mGeometryWidget->clearGeometry();
4271QVariant QgsProcessingGeometryWidgetWrapper::widgetValue()
const
4273 if ( mGeometryWidget )
4276 return geometry.
isEmpty() ? QVariant() : geometry.asWkt();
4284QString QgsProcessingGeometryWidgetWrapper::modelerExpressionFormatString()
const
4286 return tr(
"string in the Well-Known-Text format or a geometry value" );
4289QString QgsProcessingGeometryWidgetWrapper::parameterType()
const
4296 return new QgsProcessingGeometryWidgetWrapper( parameter, type );
4303 return new QgsProcessingGeometryParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4312QgsProcessingColorParameterDefinitionWidget::QgsProcessingColorParameterDefinitionWidget(
4317 QVBoxLayout *vlayout =
new QVBoxLayout();
4318 vlayout->setContentsMargins( 0, 0, 0, 0 );
4320 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4323 mDefaultColorButton->setShowNull(
true );
4324 mAllowOpacity =
new QCheckBox( tr(
"Allow opacity control" ) );
4330 mDefaultColorButton->setToNull();
4332 mDefaultColorButton->setColor(
c );
4333 mAllowOpacity->setChecked( colorParam->opacityEnabled() );
4337 mDefaultColorButton->setToNull();
4338 mAllowOpacity->setChecked(
true );
4344 vlayout->addWidget( mDefaultColorButton );
4345 vlayout->addWidget( mAllowOpacity );
4346 setLayout( vlayout );
4351 auto param = std::make_unique<QgsProcessingParameterColor>( name, description, mDefaultColorButton->color(), mAllowOpacity->isChecked() );
4353 return param.release();
4360QWidget *QgsProcessingColorWidgetWrapper::createWidget()
4373 mColorButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
4376 mColorButton->setShowNull(
true );
4379 mColorButton->setToolTip( parameterDefinition()->toolTip() );
4380 mColorButton->setColorDialogTitle( parameterDefinition()->description() );
4388 return mColorButton;
4394void QgsProcessingColorWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4398 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) || ( value.userType() == QMetaType::Type::QColor && !value.value<QColor>().isValid() ) )
4399 mColorButton->setToNull();
4403 if ( !
c.isValid() && mColorButton->showNull() )
4404 mColorButton->setToNull();
4406 mColorButton->setColor(
c );
4411QVariant QgsProcessingColorWidgetWrapper::widgetValue()
const
4414 return mColorButton->isNull() ? QVariant() : mColorButton->color();
4419QString QgsProcessingColorWidgetWrapper::modelerExpressionFormatString()
const
4421 return tr(
"color style string, e.g. #ff0000 or 255,0,0" );
4424QString QgsProcessingColorWidgetWrapper::parameterType()
const
4431 return new QgsProcessingColorWidgetWrapper( parameter, type );
4438 return new QgsProcessingColorParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4446QgsProcessingCoordinateOperationParameterDefinitionWidget::QgsProcessingCoordinateOperationParameterDefinitionWidget(
4451 QVBoxLayout *vlayout =
new QVBoxLayout();
4452 vlayout->setContentsMargins( 0, 0, 0, 0 );
4454 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4456 mDefaultLineEdit =
new QLineEdit();
4459 vlayout->addWidget( mDefaultLineEdit );
4463 mSourceParamComboBox =
new QComboBox();
4464 mDestParamComboBox =
new QComboBox();
4465 QString initialSource;
4466 QString initialDest;
4471 initialSource = itemParam->sourceCrsParameterName();
4472 initialDest = itemParam->destinationCrsParameterName();
4477 mSourceParamComboBox->addItem( QString(), QString() );
4478 mDestParamComboBox->addItem( QString(), QString() );
4479 if (
auto *lModel = widgetContext.
model() )
4482 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4483 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4485 if ( definition && it->parameterName() == definition->
name() )
4489 mSourceParamComboBox->addItem( it->parameterName(), it->parameterName() );
4490 mDestParamComboBox->addItem( it->parameterName(), it->parameterName() );
4491 if ( !initialSource.isEmpty() && initialSource == it->parameterName() )
4493 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
4495 if ( !initialDest.isEmpty() && initialDest == it->parameterName() )
4497 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
4502 if ( mSourceParamComboBox->count() == 1 && !initialSource.isEmpty() )
4505 mSourceParamComboBox->addItem( initialSource, initialSource );
4506 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
4508 if ( mDestParamComboBox->count() == 1 && !initialDest.isEmpty() )
4511 mDestParamComboBox->addItem( initialDest, initialDest );
4512 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
4515 vlayout->addWidget(
new QLabel( tr(
"Source CRS parameter" ) ) );
4516 vlayout->addWidget( mSourceParamComboBox );
4517 vlayout->addWidget(
new QLabel( tr(
"Destination CRS parameter" ) ) );
4518 vlayout->addWidget( mDestParamComboBox );
4525 mStaticSourceWidget->setCrs( sourceCrs );
4528 mStaticDestWidget->setCrs( destCrs );
4530 vlayout->addWidget(
new QLabel( tr(
"Static source CRS" ) ) );
4531 vlayout->addWidget( mStaticSourceWidget );
4532 vlayout->addWidget(
new QLabel( tr(
"Static destination CRS" ) ) );
4533 vlayout->addWidget( mStaticDestWidget );
4538 setLayout( vlayout );
4543 auto param = std::make_unique<QgsProcessingParameterCoordinateOperation>(
4546 mDefaultLineEdit->text(),
4547 mSourceParamComboBox->currentText(),
4548 mDestParamComboBox->currentText(),
4549 mStaticSourceWidget->crs().isValid() ? QVariant::fromValue( mStaticSourceWidget->crs() ) : QVariant(),
4550 mStaticDestWidget->crs().isValid() ? QVariant::fromValue( mStaticDestWidget->crs() ) : QVariant()
4553 return param.release();
4560QWidget *QgsProcessingCoordinateOperationWidgetWrapper::createWidget()
4574 mOperationWidget->setShowMakeDefault(
false );
4575 mOperationWidget->setShowFallbackOption(
false );
4576 mOperationWidget->setToolTip( parameterDefinition()->toolTip() );
4577 mOperationWidget->setSourceCrs( mSourceCrs );
4578 mOperationWidget->setDestinationCrs( mDestCrs );
4579 mOperationWidget->setMapCanvas( mCanvas );
4584 mOperationWidget->setSelectedOperation( deets );
4589 return mOperationWidget;
4595 mLineEdit =
new QLineEdit();
4596 QHBoxLayout *layout =
new QHBoxLayout();
4597 layout->addWidget( mLineEdit, 1 );
4598 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
4600 QToolButton *button =
new QToolButton();
4601 button->setText( QString( QChar( 0x2026 ) ) );
4602 connect( button, &QToolButton::clicked,
this, [
this, button] {
4603 QgsDatumTransformDialog dlg( mSourceCrs, mDestCrs,
false,
false,
false, qMakePair( -1, -1 ), button, Qt::WindowFlags(), mLineEdit->text(), mCanvas );
4606 mLineEdit->setText( dlg.selectedDatumTransform().proj );
4607 emit widgetValueHasChanged(
this );
4610 layout->addWidget( button );
4612 QWidget *w =
new QWidget();
4613 layout->setContentsMargins( 0, 0, 0, 0 );
4614 w->setLayout( layout );
4621void QgsProcessingCoordinateOperationWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
4653 if ( mOperationWidget )
4654 mOperationWidget->setMapCanvas( context.
mapCanvas() );
4657void QgsProcessingCoordinateOperationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
4659 if ( mOperationWidget )
4661 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString ) )
4664 deets.
proj = value.toString();
4665 mOperationWidget->setSelectedOperation( deets );
4670 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString ) )
4672 mLineEdit->setText( value.toString() );
4677QVariant QgsProcessingCoordinateOperationWidgetWrapper::widgetValue()
const
4679 if ( mOperationWidget )
4680 return mOperationWidget->selectedOperation().proj;
4681 else if ( mLineEdit )
4682 return mLineEdit->text();
4687QString QgsProcessingCoordinateOperationWidgetWrapper::modelerExpressionFormatString()
const
4689 return tr(
"Proj coordinate operation string, e.g. '+proj=pipeline +step +inv...'" );
4692void QgsProcessingCoordinateOperationWidgetWrapper::setSourceCrsParameterValue(
const QVariant &value )
4695 std::unique_ptr<QgsProcessingContext> tmpContext;
4696 if ( mProcessingContextGenerator )
4697 context = mProcessingContextGenerator->processingContext();
4701 tmpContext = std::make_unique<QgsProcessingContext>();
4702 context = tmpContext.get();
4706 if ( mOperationWidget )
4708 mOperationWidget->setSourceCrs( mSourceCrs );
4709 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4713void QgsProcessingCoordinateOperationWidgetWrapper::setDestinationCrsParameterValue(
const QVariant &value )
4716 std::unique_ptr<QgsProcessingContext> tmpContext;
4717 if ( mProcessingContextGenerator )
4718 context = mProcessingContextGenerator->processingContext();
4722 tmpContext = std::make_unique<QgsProcessingContext>();
4723 context = tmpContext.get();
4727 if ( mOperationWidget )
4729 mOperationWidget->setDestinationCrs( mDestCrs );
4730 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4734QString QgsProcessingCoordinateOperationWidgetWrapper::parameterType()
const
4741 return new QgsProcessingCoordinateOperationWidgetWrapper( parameter, type );
4748 return new QgsProcessingCoordinateOperationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4760 QHBoxLayout *hl =
new QHBoxLayout();
4761 hl->setContentsMargins( 0, 0, 0, 0 );
4763 mLineEdit =
new QLineEdit();
4764 mLineEdit->setEnabled(
false );
4765 hl->addWidget( mLineEdit, 1 );
4767 mToolButton =
new QToolButton();
4768 mToolButton->setText( QString( QChar( 0x2026 ) ) );
4769 hl->addWidget( mToolButton );
4775 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4778 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingFieldPanelWidget::showDialog );
4781void QgsProcessingFieldPanelWidget::setFields(
const QgsFields &fields )
4787 QVariantList availableFields;
4788 for (
const QgsField &field : std::as_const( mFields ) )
4790 availableFields << field.name();
4792 QList<QVariant>::iterator it = std::remove_if( mValue.begin(), mValue.end(), [&availableFields](
const QVariant &value ) { return !availableFields.contains( value ); } );
4793 mValue.erase( it, mValue.end() );
4795 updateSummaryText();
4799void QgsProcessingFieldPanelWidget::setValue(
const QVariant &value )
4801 if ( value.isValid() )
4802 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
4806 updateSummaryText();
4810void QgsProcessingFieldPanelWidget::showDialog()
4812 QVariantList availableOptions;
4813 availableOptions.reserve( mFields.size() );
4814 for (
const QgsField &field : std::as_const( mFields ) )
4816 availableOptions << field.name();
4822 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
4823 widget->setPanelTitle( mParam->description() );
4825 widget->setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
4827 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
4833 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
4835 dlg.setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
4838 setValue( dlg.selectedOptions() );
4843void QgsProcessingFieldPanelWidget::updateSummaryText()
4848 if ( mValue.empty() )
4850 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4855 values.reserve( mValue.size() );
4856 for (
const QVariant &val : std::as_const( mValue ) )
4858 values << val.toString();
4861 const QString concatenated = values.join( tr(
"," ) );
4862 if ( concatenated.length() < 100 )
4863 mLineEdit->setText( concatenated );
4865 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, mValue.count() ) );
4874QgsProcessingFieldParameterDefinitionWidget::QgsProcessingFieldParameterDefinitionWidget(
4879 QVBoxLayout *vlayout =
new QVBoxLayout();
4880 vlayout->setContentsMargins( 0, 0, 0, 0 );
4882 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
4883 mParentLayerComboBox =
new QComboBox();
4885 QString initialParent;
4887 initialParent = fieldParam->parentLayerParameterName();
4889 if (
auto *lModel = widgetContext.
model() )
4892 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4893 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4897 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4898 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4900 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4905 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4906 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4908 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4915 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4916 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4918 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4925 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
4928 mParentLayerComboBox->addItem( initialParent, initialParent );
4929 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4932 vlayout->addWidget( mParentLayerComboBox );
4935 vlayout->addWidget(
new QLabel( tr(
"Allowed data type" ) ) );
4936 mDataTypeComboBox =
new QComboBox();
4944 mDataTypeComboBox->setCurrentIndex( mDataTypeComboBox->findData(
static_cast<int>( fieldParam->dataType() ) ) );
4946 vlayout->addWidget( mDataTypeComboBox );
4949 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple fields" ) );
4951 mAllowMultipleCheckBox->setChecked( fieldParam->allowMultiple() );
4953 vlayout->addWidget( mAllowMultipleCheckBox );
4958 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all fields by default" ) );
4959 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
4961 mDefaultToAllCheckBox->setChecked( fieldParam->defaultToAllFields() );
4963 vlayout->addWidget( mDefaultToAllCheckBox );
4966 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [
this] { mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() ); } );
4968 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4970 mDefaultLineEdit =
new QLineEdit();
4971 mDefaultLineEdit->setToolTip( tr(
"Default field name, or ; separated list of field names for multiple field parameters" ) );
4975 mDefaultLineEdit->setText( fields.join(
';' ) );
4977 vlayout->addWidget( mDefaultLineEdit );
4981 setLayout( vlayout );
4988 QVariant defaultValue;
4989 if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
4991 defaultValue = mDefaultLineEdit->text();
4993 auto param = std::make_unique<
4994 QgsProcessingParameterField>( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), dataType, mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
4996 return param.release();
5003QWidget *QgsProcessingFieldWidgetWrapper::createWidget()
5016 mPanel =
new QgsProcessingFieldPanelWidget(
nullptr, fieldParam );
5017 mPanel->setToolTip( parameterDefinition()->toolTip() );
5018 connect( mPanel, &QgsProcessingFieldPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
5037 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5045 mLineEdit =
new QLineEdit();
5046 mLineEdit->setToolTip( QObject::tr(
"Name of field (separate field names with ; for multiple field parameters)" ) );
5047 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
5054void QgsProcessingFieldWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5066 setParentLayerWrapperValue( wrapper );
5083 std::unique_ptr<QgsProcessingContext> tmpContext;
5084 if ( mProcessingContextGenerator )
5085 context = mProcessingContextGenerator->processingContext();
5089 tmpContext = std::make_unique<QgsProcessingContext>();
5090 context = tmpContext.get();
5095 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
5105 bool valueSet =
false;
5109 if ( layers.count() > 1 )
5111 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layers.at( 0 ) );
5113 const QList<QgsMapLayer *> remainingLayers = layers.mid( 1 );
5119 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
5120 if ( !vlayer || !vlayer->
isValid() )
5126 for (
int fieldIdx = fields.
count() - 1; fieldIdx >= 0; fieldIdx-- )
5129 fields.
remove( fieldIdx );
5134 mComboBox->setFields( fields );
5136 mPanel->setFields( filterFields( fields ) );
5142 if ( !valueSet && !layers.isEmpty() && layers.at( 0 )->isValid() )
5144 QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( layers.at( 0 ) );
5148 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
5151 mParentLayer.reset( qobject_cast<QgsVectorLayer *>( ownedLayer.release() ) );
5152 layer = mParentLayer.get();
5160 mComboBox->setLayer( layer );
5162 mPanel->setFields( filterFields( layer->
fields() ) );
5172 const QgsFields fields = source->fields();
5174 mComboBox->setFields( fields );
5176 mPanel->setFields( filterFields( fields ) );
5185 mComboBox->setLayer(
nullptr );
5189 if ( value.isValid() && widgetContext().messageBar() )
5201 val.reserve( mPanel->fields().size() );
5202 for (
const QgsField &field : mPanel->fields() )
5203 val << field.name();
5204 setWidgetValue( val, *context );
5207 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5210void QgsProcessingFieldWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5214 if ( !value.isValid() )
5215 mComboBox->setField( QString() );
5219 mComboBox->setField( v );
5225 if ( value.isValid() )
5228 opts.reserve( v.size() );
5229 for (
const QString &i : v )
5233 mPanel->setValue( opts );
5235 else if ( mLineEdit )
5241 mLineEdit->setText( v.join(
';' ) );
5250QVariant QgsProcessingFieldWidgetWrapper::widgetValue()
const
5253 return mComboBox->currentField();
5255 return mPanel->value();
5256 else if ( mLineEdit )
5261 return mLineEdit->text().split(
';' );
5264 return mLineEdit->text();
5270QString QgsProcessingFieldWidgetWrapper::modelerExpressionFormatString()
const
5272 return tr(
"selected field names as an array of names, or semicolon separated string of options (e.g. 'fid;place_name')" );
5275const QgsVectorLayer *QgsProcessingFieldWidgetWrapper::linkedVectorLayer()
const
5277 if ( mComboBox && mComboBox->layer() )
5278 return mComboBox->layer();
5283QgsFields QgsProcessingFieldWidgetWrapper::filterFields(
const QgsFields &fields )
const
5296 if ( f.isNumeric() )
5301 if ( f.type() == QMetaType::Type::QString )
5306 if ( f.type() == QMetaType::Type::QDate || f.type() == QMetaType::Type::QTime || f.type() == QMetaType::Type::QDateTime )
5311 if ( f.type() == QMetaType::Type::QByteArray )
5316 if ( f.type() == QMetaType::Type::Bool )
5325QString QgsProcessingFieldWidgetWrapper::parameterType()
const
5332 return new QgsProcessingFieldWidgetWrapper( parameter, type );
5339 return new QgsProcessingFieldParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5347QgsProcessingMapThemeParameterDefinitionWidget::QgsProcessingMapThemeParameterDefinitionWidget(
5352 QVBoxLayout *vlayout =
new QVBoxLayout();
5353 vlayout->setContentsMargins( 0, 0, 0, 0 );
5355 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5357 mDefaultComboBox =
new QComboBox();
5358 mDefaultComboBox->addItem( QString(), QVariant( -1 ) );
5361 for (
const QString &theme : mapThemes )
5365 mDefaultComboBox->setEditable(
true );
5369 if ( themeParam->defaultValueForGui().isValid() )
5372 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
5375 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
5377 vlayout->addWidget( mDefaultComboBox );
5381 setLayout( vlayout );
5386 QVariant defaultVal;
5387 if ( mDefaultComboBox->currentText().isEmpty() )
5388 defaultVal = QVariant();
5390 defaultVal = mDefaultComboBox->currentText();
5391 auto param = std::make_unique<QgsProcessingParameterMapTheme>( name, description, defaultVal );
5393 return param.release();
5401QWidget *QgsProcessingMapThemeWidgetWrapper::createWidget()
5407 mComboBox =
new QComboBox();
5410 mComboBox->addItem( tr(
"[Not selected]" ), QVariant( -1 ) );
5413 for (
const QString &theme : mapThemes )
5425 mComboBox->setEditable(
true );
5429 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5430 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
5435void QgsProcessingMapThemeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5439 if ( !value.isValid() )
5440 mComboBox->setCurrentIndex( mComboBox->findData( QVariant( -1 ) ) );
5443 if ( mComboBox->isEditable() && mComboBox->findData( v ) == -1 )
5445 const QString prev = mComboBox->currentText();
5446 mComboBox->setCurrentText( v );
5448 emit widgetValueHasChanged(
this );
5451 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
5455QVariant QgsProcessingMapThemeWidgetWrapper::widgetValue()
const
5458 return mComboBox->currentData().toInt() == -1 ? QVariant()
5459 : !mComboBox->currentData().isValid() && mComboBox->isEditable() ? mComboBox->currentText().isEmpty() ? QVariant() : QVariant( mComboBox->currentText() )
5460 : mComboBox->currentData();
5465QString QgsProcessingMapThemeWidgetWrapper::modelerExpressionFormatString()
const
5467 return tr(
"map theme as a string value (e.g. 'base maps')" );
5470QString QgsProcessingMapThemeWidgetWrapper::parameterType()
const
5477 return new QgsProcessingMapThemeWidgetWrapper( parameter, type );
5484 return new QgsProcessingMapThemeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5493QgsProcessingDateTimeParameterDefinitionWidget::QgsProcessingDateTimeParameterDefinitionWidget(
5498 QVBoxLayout *vlayout =
new QVBoxLayout();
5499 vlayout->setContentsMargins( 0, 0, 0, 0 );
5501 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
5503 mTypeComboBox =
new QComboBox();
5508 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( datetimeParam->dataType() ) ) );
5510 mTypeComboBox->setCurrentIndex( 0 );
5511 vlayout->addWidget( mTypeComboBox );
5515 setLayout( vlayout );
5520 auto param = std::make_unique<QgsProcessingParameterDateTime>( name, description );
5523 return param.release();
5531QWidget *QgsProcessingDateTimeWidgetWrapper::createWidget()
5534 if ( !dateTimeParam )
5538 switch ( dateTimeParam->
dataType() )
5542 widget = mDateTimeEdit;
5567 widget->setToolTip( parameterDefinition()->toolTip() );
5569 if ( mDateTimeEdit )
5573 else if ( mDateEdit )
5577 else if ( mTimeEdit )
5589 return new QgsProcessingDateTimeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5592void QgsProcessingDateTimeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5594 if ( mDateTimeEdit )
5598 else if ( mDateEdit )
5602 else if ( mTimeEdit )
5608QVariant QgsProcessingDateTimeWidgetWrapper::widgetValue()
const
5610 if ( mDateTimeEdit )
5611 return !mDateTimeEdit->dateTime().isNull() && mDateTimeEdit->dateTime().isValid() ? QVariant( mDateTimeEdit->dateTime() ) : QVariant();
5612 else if ( mDateEdit )
5613 return !mDateEdit->date().isNull() && mDateEdit->date().isValid() ? QVariant( mDateEdit->date() ) : QVariant();
5614 else if ( mTimeEdit )
5615 return !mTimeEdit->time().isNull() && mTimeEdit->time().isValid() ? QVariant( mTimeEdit->time() ) : QVariant();
5620QString QgsProcessingDateTimeWidgetWrapper::modelerExpressionFormatString()
const
5623 if ( dateTimeParam )
5625 switch ( dateTimeParam->
dataType() )
5628 return tr(
"datetime value, or a ISO string representation of a datetime" );
5631 return tr(
"date value, or a ISO string representation of a date" );
5634 return tr(
"time value, or a ISO string representation of a time" );
5640QString QgsProcessingDateTimeWidgetWrapper::parameterType()
const
5647 return new QgsProcessingDateTimeWidgetWrapper( parameter, type );
5655QgsProcessingProviderConnectionParameterDefinitionWidget::QgsProcessingProviderConnectionParameterDefinitionWidget(
5662 QVBoxLayout *vlayout =
new QVBoxLayout();
5663 vlayout->setContentsMargins( 0, 0, 0, 0 );
5665 vlayout->addWidget(
new QLabel( tr(
"Provider" ) ) );
5666 mProviderComboBox =
new QComboBox();
5667 mProviderComboBox->addItem( QObject::tr(
"Postgres" ), u
"postgres"_s );
5668 mProviderComboBox->addItem( QObject::tr(
"GeoPackage" ), u
"ogr"_s );
5669 mProviderComboBox->addItem( QObject::tr(
"Spatialite" ), u
"spatialite"_s );
5671 vlayout->addWidget( mProviderComboBox );
5673 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5675 mDefaultEdit =
new QLineEdit();
5676 vlayout->addWidget( mDefaultEdit );
5677 setLayout( vlayout );
5679 if ( connectionParam )
5681 mProviderComboBox->setCurrentIndex( mProviderComboBox->findData( connectionParam->
providerId() ) );
5691 QVariant defaultVal;
5692 if ( mDefaultEdit->text().isEmpty() )
5693 defaultVal = QVariant();
5695 defaultVal = mDefaultEdit->text();
5696 auto param = std::make_unique<QgsProcessingParameterProviderConnection>( name, description, mProviderComboBox->currentData().toString(), defaultVal );
5698 return param.release();
5706QWidget *QgsProcessingProviderConnectionWidgetWrapper::createWidget()
5709 if ( !connectionParam )
5714 mProviderComboBox->setAllowEmptyConnection(
true );
5722 mProviderComboBox->setEditable(
true );
5726 mProviderComboBox->setToolTip( parameterDefinition()->toolTip() );
5727 connect( mProviderComboBox, &QgsProviderConnectionComboBox::currentTextChanged,
this, [
this](
const QString & ) {
5728 if ( mBlockSignals )
5731 emit widgetValueHasChanged(
this );
5734 return mProviderComboBox;
5741 return new QgsProcessingProviderConnectionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5744void QgsProcessingProviderConnectionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5748 if ( !value.isValid() )
5749 mProviderComboBox->setCurrentIndex( -1 );
5752 if ( mProviderComboBox->isEditable() )
5754 const QString prev = mProviderComboBox->currentText();
5756 mProviderComboBox->setConnection( v );
5757 mProviderComboBox->setCurrentText( v );
5761 emit widgetValueHasChanged(
this );
5764 mProviderComboBox->setConnection( v );
5768QVariant QgsProcessingProviderConnectionWidgetWrapper::widgetValue()
const
5770 if ( mProviderComboBox )
5771 if ( mProviderComboBox->isEditable() )
5772 return mProviderComboBox->currentText().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentText() );
5774 return mProviderComboBox->currentConnection().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentConnection() );
5779QString QgsProcessingProviderConnectionWidgetWrapper::modelerExpressionFormatString()
const
5781 return tr(
"connection name as a string value" );
5784QString QgsProcessingProviderConnectionWidgetWrapper::parameterType()
const
5791 return new QgsProcessingProviderConnectionWidgetWrapper( parameter, type );
5799QgsProcessingDatabaseSchemaParameterDefinitionWidget::QgsProcessingDatabaseSchemaParameterDefinitionWidget(
5806 QVBoxLayout *vlayout =
new QVBoxLayout();
5807 vlayout->setContentsMargins( 0, 0, 0, 0 );
5809 mConnectionParamComboBox =
new QComboBox();
5810 QString initialConnection;
5816 if (
auto *lModel = widgetContext.
model() )
5819 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
5820 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
5822 if ( definition && it->parameterName() == definition->
name() )
5828 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
5829 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5831 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5836 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
5839 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
5840 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5843 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
5844 vlayout->addWidget( mConnectionParamComboBox );
5848 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5850 mDefaultEdit =
new QLineEdit();
5851 vlayout->addWidget( mDefaultEdit );
5852 setLayout( vlayout );
5863 QVariant defaultVal;
5864 if ( mDefaultEdit->text().isEmpty() )
5865 defaultVal = QVariant();
5867 defaultVal = mDefaultEdit->text();
5868 auto param = std::make_unique<QgsProcessingParameterDatabaseSchema>( name, description, mConnectionParamComboBox->currentData().toString(), defaultVal );
5870 return param.release();
5878QWidget *QgsProcessingDatabaseSchemaWidgetWrapper::createWidget()
5886 mSchemaComboBox->setAllowEmptySchema(
true );
5894 mSchemaComboBox->comboBox()->setEditable(
true );
5898 mSchemaComboBox->setToolTip( parameterDefinition()->toolTip() );
5899 connect( mSchemaComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [
this](
const QString & ) {
5900 if ( mBlockSignals )
5903 emit widgetValueHasChanged( this );
5906 return mSchemaComboBox;
5913 return new QgsProcessingDatabaseSchemaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5920 std::unique_ptr<QgsProcessingContext> tmpContext;
5921 if ( mProcessingContextGenerator )
5922 context = mProcessingContextGenerator->processingContext();
5926 tmpContext = std::make_unique<QgsProcessingContext>();
5927 context = tmpContext.get();
5933 if ( mSchemaComboBox )
5934 mSchemaComboBox->setConnectionName( connection, qgis::down_cast<const QgsProcessingParameterProviderConnection *>( parentWrapper->
parameterDefinition() )->providerId() );
5938 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5941void QgsProcessingDatabaseSchemaWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5945 if ( !value.isValid() )
5946 mSchemaComboBox->comboBox()->setCurrentIndex( -1 );
5949 if ( mSchemaComboBox->comboBox()->isEditable() )
5951 const QString prev = mSchemaComboBox->comboBox()->currentText();
5953 mSchemaComboBox->setSchema( v );
5954 mSchemaComboBox->comboBox()->setCurrentText( v );
5958 emit widgetValueHasChanged(
this );
5961 mSchemaComboBox->setSchema( v );
5965QVariant QgsProcessingDatabaseSchemaWidgetWrapper::widgetValue()
const
5967 if ( mSchemaComboBox )
5968 if ( mSchemaComboBox->comboBox()->isEditable() )
5969 return mSchemaComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->comboBox()->currentText() );
5971 return mSchemaComboBox->currentSchema().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->currentSchema() );
5976QString QgsProcessingDatabaseSchemaWidgetWrapper::modelerExpressionFormatString()
const
5978 return tr(
"database schema name as a string value" );
5981QString QgsProcessingDatabaseSchemaWidgetWrapper::parameterType()
const
5988 return new QgsProcessingDatabaseSchemaWidgetWrapper( parameter, type );
5991void QgsProcessingDatabaseSchemaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6003 setParentConnectionWrapperValue( wrapper );
6021QgsProcessingDatabaseTableParameterDefinitionWidget::QgsProcessingDatabaseTableParameterDefinitionWidget(
6028 QVBoxLayout *vlayout =
new QVBoxLayout();
6029 vlayout->setContentsMargins( 0, 0, 0, 0 );
6031 mConnectionParamComboBox =
new QComboBox();
6032 mSchemaParamComboBox =
new QComboBox();
6033 QString initialConnection;
6034 QString initialSchema;
6041 if (
auto *lModel = widgetContext.
model() )
6044 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6045 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6047 if ( definition && it->parameterName() == definition->
name() )
6052 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
6053 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
6055 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
6060 mSchemaParamComboBox->addItem( it->parameterName(), it->parameterName() );
6061 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
6063 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
6069 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
6072 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
6073 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
6076 if ( mSchemaParamComboBox->count() == 0 && !initialSchema.isEmpty() )
6079 mSchemaParamComboBox->addItem( initialSchema, initialSchema );
6080 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
6083 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
6084 vlayout->addWidget( mConnectionParamComboBox );
6086 vlayout->addWidget(
new QLabel( tr(
"Database schema parameter" ) ) );
6087 vlayout->addWidget( mSchemaParamComboBox );
6092 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6094 mDefaultEdit =
new QLineEdit();
6095 vlayout->addWidget( mDefaultEdit );
6096 setLayout( vlayout );
6107 QVariant defaultVal;
6108 if ( mDefaultEdit->text().isEmpty() )
6109 defaultVal = QVariant();
6111 defaultVal = mDefaultEdit->text();
6112 auto param = std::make_unique<QgsProcessingParameterDatabaseTable>( name, description, mConnectionParamComboBox->currentData().toString(), mSchemaParamComboBox->currentData().toString(), defaultVal );
6114 return param.release();
6122QWidget *QgsProcessingDatabaseTableWidgetWrapper::createWidget()
6130 mTableComboBox->setAllowEmptyTable(
true );
6133 mTableComboBox->comboBox()->setEditable(
true );
6135 mTableComboBox->setToolTip( parameterDefinition()->toolTip() );
6136 connect( mTableComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [
this](
const QString & ) {
6137 if ( mBlockSignals )
6140 emit widgetValueHasChanged( this );
6143 return mTableComboBox;
6150 return new QgsProcessingDatabaseTableParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6157 std::unique_ptr<QgsProcessingContext> tmpContext;
6158 if ( mProcessingContextGenerator )
6159 context = mProcessingContextGenerator->processingContext();
6163 tmpContext = std::make_unique<QgsProcessingContext>();
6164 context = tmpContext.get();
6169 mProvider = qgis::down_cast<const QgsProcessingParameterProviderConnection *>( parentWrapper->
parameterDefinition() )->providerId();
6170 if ( mTableComboBox && !mSchema.isEmpty() )
6172 mTableComboBox->setSchema( mSchema );
6173 mTableComboBox->setConnectionName( mConnection, mProvider );
6177 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6185 std::unique_ptr<QgsProcessingContext> tmpContext;
6186 if ( mProcessingContextGenerator )
6187 context = mProcessingContextGenerator->processingContext();
6191 tmpContext = std::make_unique<QgsProcessingContext>();
6192 context = tmpContext.get();
6198 if ( mTableComboBox && !mSchema.isEmpty() && !mConnection.isEmpty() )
6200 mTableComboBox->setSchema( mSchema );
6201 mTableComboBox->setConnectionName( mConnection, mProvider );
6203 const QgsProcessingParameterDatabaseTable *tableParam = static_cast<const QgsProcessingParameterDatabaseTable *>( parameterDefinition() );
6204 if ( tableParam->defaultValueForGui().isValid() )
6205 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6209void QgsProcessingDatabaseTableWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6213 if ( !value.isValid() )
6214 mTableComboBox->comboBox()->setCurrentIndex( -1 );
6217 if ( mTableComboBox->comboBox()->isEditable() )
6219 const QString prev = mTableComboBox->comboBox()->currentText();
6221 mTableComboBox->setTable( v );
6222 mTableComboBox->comboBox()->setCurrentText( v );
6226 emit widgetValueHasChanged(
this );
6229 mTableComboBox->setTable( v );
6233QVariant QgsProcessingDatabaseTableWidgetWrapper::widgetValue()
const
6235 if ( mTableComboBox )
6236 if ( mTableComboBox->comboBox()->isEditable() )
6237 return mTableComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mTableComboBox->comboBox()->currentText() );
6239 return mTableComboBox->currentTable().isEmpty() ? QVariant() : QVariant( mTableComboBox->currentTable() );
6244QString QgsProcessingDatabaseTableWidgetWrapper::modelerExpressionFormatString()
const
6246 return tr(
"database table name as a string value" );
6249QString QgsProcessingDatabaseTableWidgetWrapper::parameterType()
const
6256 return new QgsProcessingDatabaseTableWidgetWrapper( parameter, type );
6259void QgsProcessingDatabaseTableWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6271 setParentConnectionWrapperValue( wrapper );
6276 setParentSchemaWrapperValue( wrapper );
6293QgsProcessingExtentParameterDefinitionWidget::QgsProcessingExtentParameterDefinitionWidget(
6298 QVBoxLayout *vlayout =
new QVBoxLayout();
6299 vlayout->setContentsMargins( 0, 0, 0, 0 );
6301 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6304 mDefaultWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
6307 if ( extentParam->defaultValueForGui().isValid() )
6311 mDefaultWidget->setCurrentExtent( rect, crs );
6312 mDefaultWidget->setOutputExtentFromCurrent();
6316 mDefaultWidget->clear();
6322 vlayout->addWidget( mDefaultWidget );
6323 setLayout( vlayout );
6328 const QString defaultVal = mDefaultWidget->isValid() ? u
"%1,%2,%3,%4%5"_s.arg(
6329 QString::number( mDefaultWidget->outputExtent().xMinimum(),
'f', 9 ),
6330 QString::number( mDefaultWidget->outputExtent().xMaximum(),
'f', 9 ),
6331 QString::number( mDefaultWidget->outputExtent().yMinimum(),
'f', 9 ),
6332 QString::number( mDefaultWidget->outputExtent().yMaximum(),
'f', 9 ),
6333 mDefaultWidget->outputCrs().isValid() ? u
" [%1]"_s.arg( mDefaultWidget->outputCrs().authid() ) : QString()
6336 auto param = std::make_unique<QgsProcessingParameterExtent>( name, description, !defaultVal.isEmpty() ? QVariant( defaultVal ) : QVariant() );
6338 return param.release();
6346QWidget *QgsProcessingExtentWidgetWrapper::createWidget()
6359 if ( widgetContext().mapCanvas() )
6360 mExtentWidget->setMapCanvas( widgetContext().mapCanvas() );
6363 mExtentWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
6365 mExtentWidget->setToolTip( parameterDefinition()->toolTip() );
6370 setDialog( mDialog );
6372 return mExtentWidget;
6382 mExtentWidget->setMapCanvas( context.
mapCanvas() );
6385void QgsProcessingExtentWidgetWrapper::setDialog( QWidget *dialog )
6392 mDialog->showMinimized();
6395 mDialog->showNormal();
6397 mDialog->activateWindow();
6404void QgsProcessingExtentWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6406 if ( mExtentWidget )
6408 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) )
6409 mExtentWidget->clear();
6414 mExtentWidget->setCurrentExtent( r, crs );
6415 mExtentWidget->setOutputExtentFromUser( r, crs );
6420QVariant QgsProcessingExtentWidgetWrapper::widgetValue()
const
6422 if ( mExtentWidget )
6424 const QString val = mExtentWidget->isValid() ? u
"%1,%2,%3,%4%5"_s.arg(
6425 QString::number( mExtentWidget->outputExtent().xMinimum(),
'f', 9 ),
6426 QString::number( mExtentWidget->outputExtent().xMaximum(),
'f', 9 ),
6427 QString::number( mExtentWidget->outputExtent().yMinimum(),
'f', 9 ),
6428 QString::number( mExtentWidget->outputExtent().yMaximum(),
'f', 9 ),
6429 mExtentWidget->outputCrs().isValid() ? u
" [%1]"_s.arg( mExtentWidget->outputCrs().authid() ) : QString()
6433 return val.isEmpty() ? QVariant() : QVariant( val );
6439QString QgsProcessingExtentWidgetWrapper::modelerExpressionFormatString()
const
6441 return tr(
"string of the format 'x min,x max,y min,y max' or a geometry value (bounding box is used)" );
6444QString QgsProcessingExtentWidgetWrapper::parameterType()
const
6451 return new QgsProcessingExtentWidgetWrapper( parameter, type );
6458 return new QgsProcessingExtentParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6466QgsProcessingMapLayerParameterDefinitionWidget::QgsProcessingMapLayerParameterDefinitionWidget(
6471 QVBoxLayout *vlayout =
new QVBoxLayout();
6472 vlayout->setContentsMargins( 0, 0, 0, 0 );
6474 vlayout->addWidget(
new QLabel( tr(
"Layer type" ) ) );
6490 for (
int i : layerParam->dataTypes() )
6492 mLayerTypeComboBox->setItemCheckState( mLayerTypeComboBox->findData( i ), Qt::Checked );
6496 vlayout->addWidget( mLayerTypeComboBox );
6500 setLayout( vlayout );
6505 QList<int> dataTypes;
6506 for (
const QVariant &v : mLayerTypeComboBox->checkedItemsData() )
6507 dataTypes << v.toInt();
6509 auto param = std::make_unique<QgsProcessingParameterMapLayer>( name, description );
6510 param->setDataTypes( dataTypes );
6512 return param.release();
6519QWidget *QgsProcessingMapLayerWidgetWrapper::createWidget()
6521 mComboBox =
new QgsProcessingMapLayerComboBox( parameterDefinition(), type() );
6529 mComboBox->setEditable(
true );
6533 mComboBox->setToolTip( parameterDefinition()->toolTip() );
6535 connect( mComboBox, &QgsProcessingMapLayerComboBox::valueChanged,
this, [
this]() {
6536 if ( mBlockSignals )
6539 emit widgetValueHasChanged(
this );
6542 setWidgetContext( widgetContext() );
6551 mComboBox->setWidgetContext( context );
6556 if ( !parameterDefinition()->defaultValueForGui().isValid() )
6562void QgsProcessingMapLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6565 mComboBox->setValue( value, context );
6568QVariant QgsProcessingMapLayerWidgetWrapper::widgetValue()
const
6570 return mComboBox ? mComboBox->value() : QVariant();
6573QString QgsProcessingMapLayerWidgetWrapper::modelerExpressionFormatString()
const
6575 return tr(
"path to a map layer" );
6592QString QgsProcessingMapLayerWidgetWrapper::parameterType()
const
6599 return new QgsProcessingMapLayerWidgetWrapper( parameter, type );
6606 return new QgsProcessingMapLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6615 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6618QString QgsProcessingRasterLayerWidgetWrapper::modelerExpressionFormatString()
const
6620 return tr(
"path to a raster layer" );
6623QString QgsProcessingRasterLayerWidgetWrapper::parameterType()
const
6630 return new QgsProcessingRasterLayerWidgetWrapper( parameter, type );
6637 Q_UNUSED( context );
6638 Q_UNUSED( widgetContext );
6639 Q_UNUSED( definition );
6650QgsProcessingVectorLayerParameterDefinitionWidget::QgsProcessingVectorLayerParameterDefinitionWidget(
6655 QVBoxLayout *vlayout =
new QVBoxLayout();
6656 vlayout->setContentsMargins( 0, 0, 0, 0 );
6658 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6668 for (
int i : vectorParam->dataTypes() )
6670 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6674 vlayout->addWidget( mGeometryTypeComboBox );
6678 setLayout( vlayout );
6683 QList<int> dataTypes;
6684 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6685 dataTypes << v.toInt();
6687 auto param = std::make_unique<QgsProcessingParameterVectorLayer>( name, description, dataTypes );
6689 return param.release();
6694 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6697QString QgsProcessingVectorLayerWidgetWrapper::modelerExpressionFormatString()
const
6699 return tr(
"path to a vector layer" );
6702QString QgsProcessingVectorLayerWidgetWrapper::parameterType()
const
6709 return new QgsProcessingVectorLayerWidgetWrapper( parameter, type );
6716 return new QgsProcessingVectorLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6724QgsProcessingFeatureSourceParameterDefinitionWidget::QgsProcessingFeatureSourceParameterDefinitionWidget(
6729 QVBoxLayout *vlayout =
new QVBoxLayout();
6730 vlayout->setContentsMargins( 0, 0, 0, 0 );
6732 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6742 for (
int i : sourceParam->dataTypes() )
6744 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6752 vlayout->addWidget( mGeometryTypeComboBox );
6755 setLayout( vlayout );
6760 QList<int> dataTypes;
6761 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6762 dataTypes << v.toInt();
6764 auto param = std::make_unique<QgsProcessingParameterFeatureSource>( name, description, dataTypes );
6766 return param.release();
6770 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6773QString QgsProcessingFeatureSourceWidgetWrapper::modelerExpressionFormatString()
const
6775 return tr(
"path to a vector layer" );
6778QString QgsProcessingFeatureSourceWidgetWrapper::parameterType()
const
6785 return new QgsProcessingFeatureSourceWidgetWrapper( parameter, type );
6792 return new QgsProcessingFeatureSourceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6800 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6803QString QgsProcessingMeshLayerWidgetWrapper::modelerExpressionFormatString()
const
6805 return tr(
"path to a mesh layer" );
6808QString QgsProcessingMeshLayerWidgetWrapper::parameterType()
const
6815 return new QgsProcessingMeshLayerWidgetWrapper( parameter, type );
6822 Q_UNUSED( context );
6823 Q_UNUSED( widgetContext );
6824 Q_UNUSED( definition );
6835QgsProcessingRasterBandPanelWidget::QgsProcessingRasterBandPanelWidget( QWidget *parent,
const QgsProcessingParameterBand *param )
6839 QHBoxLayout *hl =
new QHBoxLayout();
6840 hl->setContentsMargins( 0, 0, 0, 0 );
6842 mLineEdit =
new QLineEdit();
6843 mLineEdit->setEnabled(
false );
6844 hl->addWidget( mLineEdit, 1 );
6846 mToolButton =
new QToolButton();
6847 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6848 hl->addWidget( mToolButton );
6854 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, 0 ) );
6857 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingRasterBandPanelWidget::showDialog );
6860void QgsProcessingRasterBandPanelWidget::setBands(
const QList<int> &bands )
6865void QgsProcessingRasterBandPanelWidget::setBandNames(
const QHash<int, QString> &names )
6870void QgsProcessingRasterBandPanelWidget::setValue(
const QVariant &value )
6872 if ( value.isValid() )
6873 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
6877 updateSummaryText();
6881void QgsProcessingRasterBandPanelWidget::showDialog()
6883 QVariantList availableOptions;
6884 availableOptions.reserve( mBands.size() );
6885 for (
int band : std::as_const( mBands ) )
6887 availableOptions << band;
6893 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
6894 widget->setPanelTitle( mParam->description() );
6896 widget->setValueFormatter( [
this](
const QVariant &v ) -> QString {
6897 int band = v.toInt();
6898 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6901 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
6907 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
6909 dlg.setValueFormatter( [
this](
const QVariant &v ) -> QString {
6910 int band = v.toInt();
6911 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6915 setValue( dlg.selectedOptions() );
6920void QgsProcessingRasterBandPanelWidget::updateSummaryText()
6923 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, mValue.count() ) );
6931QgsProcessingBandParameterDefinitionWidget::QgsProcessingBandParameterDefinitionWidget(
6936 QVBoxLayout *vlayout =
new QVBoxLayout();
6937 vlayout->setContentsMargins( 0, 0, 0, 0 );
6939 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6941 mDefaultLineEdit =
new QLineEdit();
6942 mDefaultLineEdit->setToolTip( tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6947 for (
int b : bands )
6949 defVal << QString::number( b );
6952 mDefaultLineEdit->setText( defVal.join(
';' ) );
6954 vlayout->addWidget( mDefaultLineEdit );
6957 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
6958 mParentLayerComboBox =
new QComboBox();
6960 QString initialParent;
6962 initialParent = bandParam->parentLayerParameterName();
6964 if (
auto *lModel = widgetContext.
model() )
6967 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6968 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6972 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
6973 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
6975 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6981 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
6984 mParentLayerComboBox->addItem( initialParent, initialParent );
6985 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6989 vlayout->addWidget( mParentLayerComboBox );
6991 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Allow multiple" ) );
6993 mAllowMultipleCheckBox->setChecked( bandParam->allowMultiple() );
6996 vlayout->addWidget( mAllowMultipleCheckBox );
6997 setLayout( vlayout );
7003 = std::make_unique<QgsProcessingParameterBand>( name, description, mDefaultLineEdit->text().split(
';' ), mParentLayerComboBox->currentData().toString(),
false, mAllowMultipleCheckBox->isChecked() );
7005 return param.release();
7012QWidget *QgsProcessingBandWidgetWrapper::createWidget()
7025 mPanel =
new QgsProcessingRasterBandPanelWidget(
nullptr, bandParam );
7026 mPanel->setToolTip( parameterDefinition()->toolTip() );
7027 connect( mPanel, &QgsProcessingRasterBandPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7035 mComboBox->setToolTip( parameterDefinition()->toolTip() );
7043 mLineEdit =
new QLineEdit();
7044 mLineEdit->setToolTip( QObject::tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
7045 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7052void QgsProcessingBandWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
7064 setParentLayerWrapperValue( wrapper );
7081 std::unique_ptr<QgsProcessingContext> tmpContext;
7082 if ( mProcessingContextGenerator )
7083 context = mProcessingContextGenerator->processingContext();
7087 tmpContext = std::make_unique<QgsProcessingContext>();
7088 context = tmpContext.get();
7094 if ( layer && layer->
isValid() )
7098 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
7101 mParentLayer.reset( qobject_cast<QgsRasterLayer *>( ownedLayer.release() ) );
7102 layer = mParentLayer.get();
7110 mComboBox->setLayer( layer );
7114 if ( provider && layer->
isValid() )
7119 QHash<int, QString> bandNames;
7120 for (
int i = 1; i <= nBands; ++i )
7125 mPanel->setBands( bands );
7126 mPanel->setBandNames( bandNames );
7133 mComboBox->setLayer(
nullptr );
7135 mPanel->setBands( QList<int>() );
7137 if ( value.isValid() && widgetContext().messageBar() )
7144 if ( parameterDefinition()->defaultValueForGui().isValid() )
7145 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
7148void QgsProcessingBandWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7152 if ( !value.isValid() )
7153 mComboBox->setBand( -1 );
7157 mComboBox->setBand( v );
7163 if ( value.isValid() )
7166 opts.reserve( v.size() );
7171 mPanel->setValue( value.isValid() ? opts : QVariant() );
7173 else if ( mLineEdit )
7180 opts.reserve( v.size() );
7182 opts << QString::number( i );
7183 mLineEdit->setText( value.isValid() && !opts.empty() ? opts.join(
';' ) : QString() );
7187 if ( value.isValid() )
7195QVariant QgsProcessingBandWidgetWrapper::widgetValue()
const
7198 return mComboBox->currentBand() == -1 ? QVariant() : mComboBox->currentBand();
7200 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
7201 else if ( mLineEdit )
7206 const QStringList parts = mLineEdit->text().split(
';', Qt::SkipEmptyParts );
7208 res.reserve( parts.count() );
7209 for (
const QString &s : parts )
7212 int band = s.toInt( &ok );
7216 return res.
isEmpty() ? QVariant() : res;
7220 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
7227QString QgsProcessingBandWidgetWrapper::modelerExpressionFormatString()
const
7229 return tr(
"selected band numbers as an array of numbers, or semicolon separated string of options (e.g. '1;3')" );
7232QString QgsProcessingBandWidgetWrapper::parameterType()
const
7239 return new QgsProcessingBandWidgetWrapper( parameter, type );
7246 return new QgsProcessingBandParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
7257 setAcceptDrops(
true );
7260void QgsProcessingMultipleLayerLineEdit::dragEnterEvent( QDragEnterEvent *event )
7262 const QStringList uris = QgsProcessingMultipleInputPanelWidget::compatibleUrisFromMimeData( mParam, event->mimeData(), {} );
7263 if ( !uris.isEmpty() )
7265 event->setDropAction( Qt::CopyAction );
7267 setHighlighted(
true );
7275void QgsProcessingMultipleLayerLineEdit::dragLeaveEvent( QDragLeaveEvent *event )
7277 QgsHighlightableLineEdit::dragLeaveEvent( event );
7279 setHighlighted(
false );
7282void QgsProcessingMultipleLayerLineEdit::dropEvent( QDropEvent *event )
7284 const QStringList uris = QgsProcessingMultipleInputPanelWidget::compatibleUrisFromMimeData( mParam, event->mimeData(), {} );
7285 if ( !uris.isEmpty() )
7287 event->setDropAction( Qt::CopyAction );
7289 QVariantList uriList;
7290 uriList.reserve( uris.size() );
7291 for (
const QString &uri : uris )
7292 uriList.append( QVariant( uri ) );
7293 emit layersDropped( uriList );
7296 setHighlighted(
false );
7307 QHBoxLayout *hl =
new QHBoxLayout();
7308 hl->setContentsMargins( 0, 0, 0, 0 );
7310 mLineEdit =
new QgsProcessingMultipleLayerLineEdit(
nullptr, param );
7311 mLineEdit->setEnabled(
true );
7312 mLineEdit->setReadOnly(
true );
7314 hl->addWidget( mLineEdit, 1 );
7315 connect( mLineEdit, &QgsProcessingMultipleLayerLineEdit::layersDropped,
this, &QgsProcessingMultipleLayerPanelWidget::setValue );
7317 mToolButton =
new QToolButton();
7318 mToolButton->setText( QString( QChar( 0x2026 ) ) );
7319 hl->addWidget( mToolButton );
7325 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, 0 ) );
7328 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingMultipleLayerPanelWidget::showDialog );
7331void QgsProcessingMultipleLayerPanelWidget::setValue(
const QVariant &value )
7333 if ( value.isValid() )
7334 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
7338 updateSummaryText();
7342void QgsProcessingMultipleLayerPanelWidget::setProject(
QgsProject *project )
7348 if ( mValue.removeAll( layerId ) )
7350 updateSummaryText();
7357void QgsProcessingMultipleLayerPanelWidget::setModel( QgsProcessingModelAlgorithm *model,
const QString &modelChildAlgorithmID )
7363 switch ( mParam->layerType() )
7371 mModelSources = model->availableSourcesForChild(
7372 modelChildAlgorithmID,
7381 mModelSources = model->availableSourcesForChild(
7382 modelChildAlgorithmID,
7391 mModelSources = model->availableSourcesForChild(
7392 modelChildAlgorithmID,
7401 mModelSources = model->availableSourcesForChild(
7402 modelChildAlgorithmID,
7411 mModelSources = model->availableSourcesForChild(
7412 modelChildAlgorithmID,
7421 mModelSources = model->availableSourcesForChild(
7422 modelChildAlgorithmID,
7431 mModelSources = model->availableSourcesForChild(
7432 modelChildAlgorithmID,
7441 mModelSources = model->availableSourcesForChild(
7442 modelChildAlgorithmID,
7456 mModelSources = model->availableSourcesForChild(
7457 modelChildAlgorithmID,
7470 mModelSources = model->availableSourcesForChild(
7471 modelChildAlgorithmID,
7485 mModelSources = model->availableSourcesForChild(
7486 modelChildAlgorithmID,
7500 mModelSources = model->availableSourcesForChild(
7501 modelChildAlgorithmID,
7515 mModelSources = model->availableSourcesForChild(
7516 modelChildAlgorithmID,
7537void QgsProcessingMultipleLayerPanelWidget::showDialog()
7542 QgsProcessingMultipleInputPanelWidget *widget =
new QgsProcessingMultipleInputPanelWidget( mParam, mValue, mModelSources, mModel,
nullptr );
7543 widget->setPanelTitle( mParam->description() );
7544 widget->setProject( mProject );
7545 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
7551 QgsProcessingMultipleInputDialog dlg( mParam, mValue, mModelSources, mModel,
this, Qt::WindowFlags() );
7552 dlg.setProject( mProject );
7555 setValue( dlg.selectedOptions() );
7560void QgsProcessingMultipleLayerPanelWidget::updateSummaryText()
7563 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, mValue.count() ) );
7570QgsProcessingMultipleLayerParameterDefinitionWidget::QgsProcessingMultipleLayerParameterDefinitionWidget(
7575 QVBoxLayout *vlayout =
new QVBoxLayout();
7576 vlayout->setContentsMargins( 0, 0, 0, 0 );
7578 vlayout->addWidget(
new QLabel( tr(
"Allowed layer type" ) ) );
7579 mLayerTypeComboBox =
new QComboBox();
7593 mLayerTypeComboBox->setCurrentIndex( mLayerTypeComboBox->findData(
static_cast<int>( layersParam->layerType() ) ) );
7595 vlayout->addWidget( mLayerTypeComboBox );
7598 setLayout( vlayout );
7603 auto param = std::make_unique<QgsProcessingParameterMultipleLayers>( name, description,
static_cast<Qgis::ProcessingSourceType>( mLayerTypeComboBox->currentData().toInt() ) );
7605 return param.release();
7612QWidget *QgsProcessingMultipleLayerWidgetWrapper::createWidget()
7616 mPanel =
new QgsProcessingMultipleLayerPanelWidget(
nullptr, layerParam );
7617 mPanel->setToolTip( parameterDefinition()->toolTip() );
7618 mPanel->setProject( widgetContext().project() );
7620 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7621 connect( mPanel, &QgsProcessingMultipleLayerPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7630 mPanel->setProject( context.
project() );
7632 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7636void QgsProcessingMultipleLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7641 if ( value.isValid() )
7644 opts.reserve( v.size() );
7646 opts << l->source();
7649 for (
const QVariant &v : value.toList() )
7651 if ( v.userType() == qMetaTypeId<QgsProcessingModelChildParameterSource>() )
7653 const QgsProcessingModelChildParameterSource source = v.value<QgsProcessingModelChildParameterSource>();
7654 opts << QVariant::fromValue( source );
7659 mPanel->setValue( value.isValid() ? opts : QVariant() );
7663QVariant QgsProcessingMultipleLayerWidgetWrapper::widgetValue()
const
7666 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
7671QString QgsProcessingMultipleLayerWidgetWrapper::modelerExpressionFormatString()
const
7673 return tr(
"an array of layer paths, or semicolon separated string of layer paths" );
7676QString QgsProcessingMultipleLayerWidgetWrapper::parameterType()
const
7683 return new QgsProcessingMultipleLayerWidgetWrapper( parameter, type );
7690 return new QgsProcessingMultipleLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
7699 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
7702QString QgsProcessingPointCloudLayerWidgetWrapper::modelerExpressionFormatString()
const
7704 return tr(
"path to a point cloud layer" );
7707QString QgsProcessingPointCloudLayerWidgetWrapper::parameterType()
const
7714 return new QgsProcessingPointCloudLayerWidgetWrapper( parameter, type );
7721 Q_UNUSED( context );
7722 Q_UNUSED( widgetContext );
7723 Q_UNUSED( definition );
7738QString QgsProcessingAnnotationLayerWidgetWrapper::modelerExpressionFormatString()
const
7740 return tr(
"name of an annotation layer, or \"main\" for the main annotation layer" );
7743QString QgsProcessingAnnotationLayerWidgetWrapper::parameterType()
const
7750 return new QgsProcessingAnnotationLayerWidgetWrapper( parameter, type );
7757 Q_UNUSED( context );
7758 Q_UNUSED( widgetContext );
7759 Q_UNUSED( definition );
7770 if ( mWidgetContext.project() )
7771 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7775QWidget *QgsProcessingAnnotationLayerWidgetWrapper::createWidget()
7786 mComboBox->setEditable(
true );
7790 mComboBox->setToolTip( parameterDefinition()->toolTip() );
7792 if ( mWidgetContext.project() )
7793 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7796 mComboBox->setAllowEmptyLayer(
true );
7799 if ( mBlockSignals )
7802 emit widgetValueHasChanged(
this );
7805 setWidgetContext( widgetContext() );
7809void QgsProcessingAnnotationLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7815 mComboBox->setLayer(
nullptr );
7819 QVariant val = value;
7820 if ( val.userType() == qMetaTypeId<QgsProperty>() )
7832 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( val.value<QObject *>() );
7833 if ( !layer && val.userType() == QMetaType::Type::QString )
7840 mComboBox->setLayer( layer );
7845QVariant QgsProcessingAnnotationLayerWidgetWrapper::widgetValue()
const
7847 return mComboBox && mComboBox->currentLayer()
7848 ? ( mWidgetContext.project() ? ( mComboBox->currentLayer() == mWidgetContext.project()->mainAnnotationLayer() ? u
"main"_s : mComboBox->currentLayer()->id() )
7849 : mComboBox->currentLayer()->id() )
7862 QHBoxLayout *hl =
new QHBoxLayout();
7863 hl->setContentsMargins( 0, 0, 0, 0 );
7865 mLineEdit =
new QLineEdit();
7866 mLineEdit->setEnabled(
false );
7867 hl->addWidget( mLineEdit, 1 );
7869 mToolButton =
new QToolButton();
7870 mToolButton->setText( QString( QChar( 0x2026 ) ) );
7871 hl->addWidget( mToolButton );
7877 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, 0 ) );
7880 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingPointCloudAttributePanelWidget::showDialog );
7885 mAttributes = attributes;
7888void QgsProcessingPointCloudAttributePanelWidget::setValue(
const QVariant &value )
7890 if ( value.isValid() )
7891 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
7895 updateSummaryText();
7899void QgsProcessingPointCloudAttributePanelWidget::showDialog()
7901 QVariantList availableOptions;
7902 availableOptions.reserve( mAttributes.count() );
7903 const QVector<QgsPointCloudAttribute> attributes = mAttributes.attributes();
7906 availableOptions << attr.name();
7912 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
7913 widget->setPanelTitle( mParam->description() );
7915 widget->setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
7917 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
7923 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
7925 dlg.setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
7928 setValue( dlg.selectedOptions() );
7933void QgsProcessingPointCloudAttributePanelWidget::updateSummaryText()
7938 if ( mValue.empty() )
7940 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, 0 ) );
7945 values.reserve( mValue.size() );
7946 for (
const QVariant &val : std::as_const( mValue ) )
7948 values << val.toString();
7951 const QString concatenated = values.join( tr(
"," ) );
7952 if ( concatenated.length() < 100 )
7953 mLineEdit->setText( concatenated );
7955 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, mValue.count() ) );
7964QgsProcessingPointCloudAttributeParameterDefinitionWidget::QgsProcessingPointCloudAttributeParameterDefinitionWidget(
7969 QVBoxLayout *vlayout =
new QVBoxLayout();
7970 vlayout->setContentsMargins( 0, 0, 0, 0 );
7972 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
7973 mParentLayerComboBox =
new QComboBox();
7975 QString initialParent;
7977 initialParent = attrParam->parentLayerParameterName();
7979 if (
auto *lModel = widgetContext.
model() )
7982 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
7983 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
7987 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
7988 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
7990 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
7996 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
7999 mParentLayerComboBox->addItem( initialParent, initialParent );
8000 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
8003 vlayout->addWidget( mParentLayerComboBox );
8007 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple attributes" ) );
8009 mAllowMultipleCheckBox->setChecked( attrParam->allowMultiple() );
8011 vlayout->addWidget( mAllowMultipleCheckBox );
8014 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all attributes by default" ) );
8015 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
8017 mDefaultToAllCheckBox->setChecked( attrParam->defaultToAllAttributes() );
8021 vlayout->addWidget( mDefaultToAllCheckBox );
8023 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [
this] { mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() ); } );
8025 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
8027 mDefaultLineEdit =
new QLineEdit();
8028 mDefaultLineEdit->setToolTip( tr(
"Default attribute name, or ; separated list of attribute names for multiple attribute parameters" ) );
8032 mDefaultLineEdit->setText( attributes.join(
';' ) );
8034 vlayout->addWidget( mDefaultLineEdit );
8038 setLayout( vlayout );
8043 QVariant defaultValue;
8044 if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
8046 defaultValue = mDefaultLineEdit->text();
8048 auto param = std::make_unique<
8049 QgsProcessingParameterPointCloudAttribute>( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
8051 return param.release();
8058QWidget *QgsProcessingPointCloudAttributeWidgetWrapper::createWidget()
8071 mPanel =
new QgsProcessingPointCloudAttributePanelWidget(
nullptr, attrParam );
8072 mPanel->setToolTip( parameterDefinition()->toolTip() );
8073 connect( mPanel, &QgsProcessingPointCloudAttributePanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
8080 mComboBox->setToolTip( parameterDefinition()->toolTip() );
8088 mLineEdit =
new QLineEdit();
8089 mLineEdit->setToolTip( QObject::tr(
"Name of attribute (separate attribute names with ; for multiple attribute parameters)" ) );
8090 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
8097void QgsProcessingPointCloudAttributeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
8109 setParentLayerWrapperValue( wrapper );
8126 std::unique_ptr<QgsProcessingContext> tmpContext;
8127 if ( mProcessingContextGenerator )
8128 context = mProcessingContextGenerator->processingContext();
8132 tmpContext = std::make_unique<QgsProcessingContext>();
8133 context = tmpContext.get();
8139 if ( layer && layer->
isValid() )
8143 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
8146 mParentLayer.reset( qobject_cast<QgsPointCloudLayer *>( ownedLayer.release() ) );
8147 layer = mParentLayer.get();
8155 mComboBox->setLayer( layer );
8158 mPanel->setAttributes( layer->
attributes() );
8165 mComboBox->setLayer(
nullptr );
8170 if ( value.isValid() && widgetContext().messageBar() )
8181 val.reserve( mPanel->attributes().attributes().size() );
8184 setWidgetValue( val, *context );
8187 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
8190void QgsProcessingPointCloudAttributeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
8194 if ( !value.isValid() )
8195 mComboBox->setAttribute( QString() );
8199 mComboBox->setAttribute( v );
8205 if ( value.isValid() )
8208 opts.reserve( v.size() );
8209 for (
const QString &i : v )
8213 mPanel->setValue( opts );
8215 else if ( mLineEdit )
8221 mLineEdit->setText( v.join(
';' ) );
8230QVariant QgsProcessingPointCloudAttributeWidgetWrapper::widgetValue()
const
8233 return mComboBox->currentAttribute();
8235 return mPanel->value();
8236 else if ( mLineEdit )
8241 return mLineEdit->text().split(
';' );
8244 return mLineEdit->text();
8250QString QgsProcessingPointCloudAttributeWidgetWrapper::modelerExpressionFormatString()
const
8252 return tr(
"selected attribute names as an array of names, or semicolon separated string of options (e.g. 'X;Intensity')" );
8255QString QgsProcessingPointCloudAttributeWidgetWrapper::parameterType()
const
8262 return new QgsProcessingPointCloudAttributeWidgetWrapper( parameter, type );
8269 return new QgsProcessingPointCloudAttributeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
8281QWidget *QgsProcessingOutputWidgetWrapper::createWidget()
8289 mOutputWidget =
new QgsProcessingLayerOutputDestinationWidget( destParam,
false );
8290 if ( mProcessingContextGenerator )
8291 mOutputWidget->setContext( mProcessingContextGenerator->processingContext() );
8292 if ( mParametersGenerator )
8293 mOutputWidget->registerProcessingParametersGenerator( mParametersGenerator );
8294 mOutputWidget->setToolTip( parameterDefinition()->toolTip() );
8296 connect( mOutputWidget, &QgsProcessingLayerOutputDestinationWidget::destinationChanged,
this, [
this]() {
8297 if ( mBlockSignals )
8300 emit widgetValueHasChanged(
this );
8305 mOutputWidget->addOpenAfterRunningOption();
8307 return mOutputWidget;
8317void QgsProcessingOutputWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
8319 if ( mOutputWidget )
8320 mOutputWidget->setValue( value );
8323QVariant QgsProcessingOutputWidgetWrapper::widgetValue()
const
8325 if ( mOutputWidget )
8326 return mOutputWidget->value();
8331QVariantMap QgsProcessingOutputWidgetWrapper::customProperties()
const
8334 if ( mOutputWidget )
8335 res.insert( u
"OPEN_AFTER_RUNNING"_s, mOutputWidget->openAfterRunning() );
8344 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8347QString QgsProcessingFeatureSinkWidgetWrapper::parameterType()
const
8354 return new QgsProcessingFeatureSinkWidgetWrapper( parameter, type );
8357QString QgsProcessingFeatureSinkWidgetWrapper::modelerExpressionFormatString()
const
8359 return tr(
"path to layer destination" );
8367 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8370QString QgsProcessingVectorDestinationWidgetWrapper::parameterType()
const
8377 return new QgsProcessingVectorDestinationWidgetWrapper( parameter, type );
8380QString QgsProcessingVectorDestinationWidgetWrapper::modelerExpressionFormatString()
const
8382 return tr(
"path to layer destination" );
8390 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8393QString QgsProcessingRasterDestinationWidgetWrapper::parameterType()
const
8400 return new QgsProcessingRasterDestinationWidgetWrapper( parameter, type );
8403QString QgsProcessingRasterDestinationWidgetWrapper::modelerExpressionFormatString()
const
8405 return tr(
"path to layer destination" );
8413 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8416QString QgsProcessingPointCloudDestinationWidgetWrapper::parameterType()
const
8423 return new QgsProcessingPointCloudDestinationWidgetWrapper( parameter, type );
8426QString QgsProcessingPointCloudDestinationWidgetWrapper::modelerExpressionFormatString()
const
8428 return tr(
"path to layer destination" );
8436 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8439QString QgsProcessingFileDestinationWidgetWrapper::parameterType()
const
8446 return new QgsProcessingFileDestinationWidgetWrapper( parameter, type );
8450QString QgsProcessingFileDestinationWidgetWrapper::modelerExpressionFormatString()
const
8452 return tr(
"path to file destination" );
8460 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8463QString QgsProcessingFolderDestinationWidgetWrapper::parameterType()
const
8470 return new QgsProcessingFolderDestinationWidgetWrapper( parameter, type );
8474QString QgsProcessingFolderDestinationWidgetWrapper::modelerExpressionFormatString()
const
8476 return tr(
"path to folder destination" );
8484 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8487QString QgsProcessingVectorTileDestinationWidgetWrapper::parameterType()
const
8494 return new QgsProcessingPointCloudDestinationWidgetWrapper( parameter, type );
8497QString QgsProcessingVectorTileDestinationWidgetWrapper::modelerExpressionFormatString()
const
8499 return tr(
"path to layer destination" );
8507QgsHeatmapPixelSizeWidget::QgsHeatmapPixelSizeWidget( QWidget *parent )
8512 mCellXSpinBox->setShowClearButton(
false );
8513 mCellYSpinBox->setShowClearButton(
false );
8514 mRowsSpinBox->setShowClearButton(
false );
8515 mColumnsSpinBox->setShowClearButton(
false );
8517 connect( mCellYSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), mCellXSpinBox, &QgsDoubleSpinBox::setValue );
8518 connect( mCellXSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsHeatmapPixelSizeWidget::pixelSizeChanged );
8519 connect( mRowsSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, &QgsHeatmapPixelSizeWidget::rowsChanged );
8520 connect( mColumnsSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, &QgsHeatmapPixelSizeWidget::columnsChanged );
8527 mLayerBounds = mLayer->
extent();
8531 recalculateBounds();
8539void QgsHeatmapPixelSizeWidget::setRadius(
double radius )
8542 recalculateBounds();
8545void QgsHeatmapPixelSizeWidget::setRadiusField(
const QString &radiusField )
8547 mRadiusField = radiusField;
8548 recalculateBounds();
8551void QgsHeatmapPixelSizeWidget::recalculateBounds()
8553 mRasterBounds = mLayerBounds;
8557 double maxRadius = mRadius;
8558 if ( !mRadiusField.isEmpty() )
8560 const int idx = mLayer->fields().lookupField( mRadiusField );
8562 maxRadius = mLayer->maximumValue( idx ).toDouble();
8565 mRasterBounds.setXMinimum( mRasterBounds.xMinimum() - maxRadius );
8566 mRasterBounds.setYMinimum( mRasterBounds.yMinimum() - maxRadius );
8567 mRasterBounds.setXMaximum( mRasterBounds.xMaximum() + maxRadius );
8568 mRasterBounds.setYMaximum( mRasterBounds.yMaximum() + maxRadius );
8573void QgsHeatmapPixelSizeWidget::pixelSizeChanged()
8575 const double prevValue = value();
8576 const double cellSize = mCellXSpinBox->value();
8577 if ( cellSize <= 0 || mRasterBounds.isNull() )
8579 emit valueChanged();
8585 const int rows = std::max(
static_cast<int>( std::round( mRasterBounds.height() / cellSize ) ) + 1, 1 );
8586 const int cols = std::max(
static_cast<int>( std::round( mRasterBounds.width() / cellSize ) ) + 1, 1 );
8593 emit valueChanged();
8597void QgsHeatmapPixelSizeWidget::rowsChanged()
8599 const int rows = mRowsSpinBox->value();
8600 if ( rows <= 0 || mRasterBounds.isNull() )
8603 const double cellSize = mRasterBounds.height() / rows;
8604 if ( cellSize == 0 )
8607 const int cols = std::max(
static_cast<int>( std::round( mRasterBounds.width() / cellSize ) ) + 1, 1 );
8613 emit valueChanged();
8616void QgsHeatmapPixelSizeWidget::columnsChanged()
8618 const int cols = mColumnsSpinBox->value();
8619 if ( cols < 2 || mRasterBounds.isNull() )
8622 const double cellSize = mRasterBounds.width() / ( cols - 1 );
8623 if ( cellSize == 0 )
8626 const int rows = std::max(
static_cast<int>( std::round( mRasterBounds.height() / cellSize ) ), 1 );
8632 emit valueChanged();
8635double QgsHeatmapPixelSizeWidget::value()
const
8637 return mCellXSpinBox->value();
8640void QgsHeatmapPixelSizeWidget::setValue(
double value )
8642 mCellXSpinBox->setValue( value );
8643 mCellYSpinBox->setValue( value );
8654QString QgsProcessingHeatmapPixelSizeWidgetWrapper::parameterType()
const
8661 return new QgsProcessingHeatmapPixelSizeWidgetWrapper( parameter, type );
8671QWidget *QgsProcessingHeatmapPixelSizeWidgetWrapper::createWidget()
8677 mWidget =
new QgsHeatmapPixelSizeWidget();
8678 connect( mWidget, &QgsHeatmapPixelSizeWidget::valueChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
8686 mFallbackSpinBox->setShowClearButton(
false );
8687 mFallbackSpinBox->setMinimum( 0.0 );
8688 mFallbackSpinBox->setMaximum( 99999999999.0 );
8689 mFallbackSpinBox->setDecimals( 6 );
8690 mFallbackSpinBox->setToolTip( tr(
"Resolution of each pixel in output raster, in layer units" ) );
8691 connect( mFallbackSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
8692 return mFallbackSpinBox;
8698void QgsProcessingHeatmapPixelSizeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
8707 if ( !param || !mWidget )
8714 setParentLayerWrapperValue( wrapper );
8743 std::unique_ptr<QgsProcessingContext> tmpContext;
8744 if ( mProcessingContextGenerator )
8745 context = mProcessingContextGenerator->processingContext();
8749 tmpContext = std::make_unique<QgsProcessingContext>();
8750 context = tmpContext.get();
8754 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
8764 mWidget->setLayer(
nullptr );
8770 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
8773 mParentLayer = std::move( ownedLayer );
8781 mWidget->setLayer( layer );
8784void QgsProcessingHeatmapPixelSizeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
8787 mWidget->setValue( value.toDouble() );
8788 else if ( mFallbackSpinBox )
8789 mFallbackSpinBox->setValue( value.toDouble() );
8792QVariant QgsProcessingHeatmapPixelSizeWidgetWrapper::widgetValue()
const
8795 return mWidget->value();
8796 else if ( mFallbackSpinBox )
8797 return mFallbackSpinBox->value();
8801const QgsVectorLayer *QgsProcessingHeatmapPixelSizeWidgetWrapper::linkedVectorLayer()
const
8803 if ( mWidget && mWidget->layer() )
8804 return mWidget->layer();
@ Standard
Unit is a standard measurement unit.
ProcessingSourceType
Processing data source types.
@ File
Files (i.e. non map layer sources, such as text files).
@ TiledScene
Tiled scene layers.
@ Annotation
Annotation layers.
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ VectorTile
Vector tile layers.
@ MapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer).
@ VectorAnyGeometry
Any vector layer with geometry.
@ VectorPoint
Vector point layers.
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
@ PointCloud
Point cloud layers.
ProcessingFileParameterBehavior
Flags which dictate the behavior of QgsProcessingParameterFile.
@ File
Parameter is a single file.
@ Folder
Parameter is a folder.
ExpressionType
Expression types.
@ RasterCalculator
Raster calculator expression.
@ Qgis
Native QGIS expression.
@ PointCloud
Point cloud expression.
ProcessingMode
Types of modes which Processing widgets can be created for.
@ Batch
Batch processing mode.
@ Standard
Standard (single-run) algorithm mode.
DistanceUnit
Units of distance.
@ Centimeters
Centimeters.
@ Millimeters
Millimeters.
@ Miles
Terrestrial miles.
@ Unknown
Unknown distance unit.
@ Degrees
Degrees, for planar geographic CRS distance measurements.
@ NauticalMiles
Nautical miles.
ProcessingFieldParameterDataType
Processing field parameter data types.
@ String
Accepts string fields.
@ Boolean
Accepts boolean fields, since QGIS 3.34.
@ Binary
Accepts binary fields, since QGIS 3.34.
@ Numeric
Accepts numeric fields.
@ DateTime
Accepts datetime fields.
@ SquareCentimeters
Square centimeters.
@ SquareInches
Square inches.
@ SquareNauticalMiles
Square nautical miles.
@ SquareMillimeters
Square millimeters.
@ SquareYards
Square yards.
@ SquareKilometers
Square kilometers.
@ SquareMeters
Square meters.
@ Unknown
Unknown areal unit.
@ SquareDegrees
Square degrees, for planar geographic CRS area measurements.
@ SquareMiles
Square miles.
@ Info
Information message.
@ AnnotationLayer
QgsAnnotationLayer.
TemporalUnit
Temporal units.
@ Milliseconds
Milliseconds.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
QFlags< ProcessingParameterFlag > ProcessingParameterFlags
Flags which dictate the behavior of Processing parameters.
VolumeUnit
Units of volume.
@ CubicMeters
Cubic meters.
@ CubicDegrees
Cubic degrees, for planar geographic CRS volume measurements.
@ CubicDecimeter
Cubic decimeters.
@ Unknown
Unknown volume unit.
@ CubicCentimeter
Cubic Centimeters.
ProcessingModelChildParameterSource
Processing model child parameter sources.
@ ModelParameter
Parameter value is taken from a parent model parameter.
@ StaticValue
Parameter value is a static value.
@ Optional
Parameter is optional.
ProcessingDateTimeParameterDataType
Processing date time parameter data types.
@ DateTime
Datetime values.
ProcessingNumberParameterType
Processing numeric parameter data types.
@ Double
Double/float values.
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
@ CapturePoint
Select and capture a point or a feature.
Selector widget for authentication configs.
void selectedConfigIdChanged(const QString &authcfg)
Emitted when authentication config is changed or missing.
QComboBox subclass which allows selecting multiple items.
void checkedItemsChanged(const QStringList &items)
Emitted whenever the checked items list changed.
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
A combo box which displays the list of schemas for a specific database connection.
A combobox which displays the list of tables for a specific database connection.
A QDateEdit widget with the capability of setting/reading null dates.
void dateValueChanged(const QDate &date)
Signal emitted whenever the date changes.
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.
A widget which includes a line edit for entering expressions together with a button to open the expre...
void expressionChanged(const QString &expression)
Emitted when the expression is changed.
A combobox which displays the list of fields of a given layer.
void fieldChanged(const QString &fieldName)
Emitted when the currently selected field changes.
@ DateTime
Datetime fields.
@ Date
Date or datetime fields.
@ Binary
Binary fields, since QGIS 3.34.
@ Boolean
Boolean fields, since QGIS 3.34.
@ Numeric
All numeric fields.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
void remove(int fieldIdx)
Removes the field with the given index.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Q_INVOKABLE 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.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
Q_INVOKABLE QString asWkt(int precision=17) const
Exports the geometry to WKT.
A QgsFilterLineEdit subclass with the ability to "highlight" the edges of the widget.
A combobox which displays available layouts from a QgsLayoutManager.
void layoutChanged(QgsMasterLayoutInterface *layout)
Emitted whenever the currently selected layout changes.
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.
A combobox which displays a dynamic list of layers from a QGIS project.
void layerChanged(QgsMapLayer *layer)
Emitted whenever the currently selected layer changes.
Base class for all map layer types.
A mouse event which is the result of a user interaction with 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 collection of point cloud attributes.
A combobox which displays the list of attributes of a given point cloud layer.
void attributeChanged(const QString &name)
Emitted when the currently selected attribute changes.
Attribute for point cloud data pair of name and size in bytes.
Represents a map layer supporting display of point clouds.
QgsPointCloudAttributeCollection attributes() const
Returns the attributes available from the layer.
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.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the parameter class.
A double numeric parameter for area values.
Qgis::AreaUnit defaultUnit() const
Returns the default area unit 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.
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.
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.
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.
static QString typeName()
Returns the type name for the parameter class.
Qgis::ProcessingDateTimeParameterDataType dataType() const
Returns the acceptable data type for the parameter.
Base class for the definition of processing parameters.
void setFlags(Qgis::ProcessingParameterFlags flags)
Sets the flags associated with the parameter.
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.
virtual QString type() const =0
Unique parameter type name.
QString name() const
Returns the name of the parameter.
Qgis::ProcessingParameterFlags flags() const
Returns any 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.
Qgis::ExpressionType expressionType() const
Returns the parameter's expression type.
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.
Qgis::ProcessingFieldParameterDataType dataType() const
Returns 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.
void setDataType(Qgis::ProcessingFieldParameterDataType type)
Sets 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.
QString fileFilter() const
Returns the file filter string for file destinations compatible with this parameter.
Qgis::ProcessingFileParameterBehavior behavior() const
Returns the parameter behavior (e.g.
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 parameter for the heatmap algorithm pixel size parameter.
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 maximum() const
Returns the maximum value acceptable by the parameter.
Qgis::ProcessingNumberParameterType dataType() const
Returns the acceptable data type for the parameter.
static QString typeName()
Returns the type name for the parameter class.
A point cloud layer attribute parameter for Processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
bool allowMultiple() const
Returns whether multiple field selections are permitted.
bool defaultToAllAttributes() const
Returns whether a parameter which allows multiple selections (see allowMultiple()) should automatical...
static QString typeName()
Returns the type name for the parameter class.
A point cloud layer parameter for processing algorithms.
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.
static QString typeName()
Returns the type name for the parameter class.
Qgis::ProcessingNumberParameterType dataType() const
Returns the acceptable data type for the range.
static QString typeName()
Returns the type name for the parameter class.
A raster layer parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A double numeric parameter for map scale values.
static QString typeName()
Returns the type name for the parameter class.
A string parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A vector layer (with or without geometry) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A double numeric parameter for volume values.
static QString typeName()
Returns the type name for the parameter class.
Qgis::VolumeUnit defaultUnit() const
Returns the default volume unit for the parameter.
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 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 QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a list of map layers.
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 QStringList parameterAsStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of strings (e.g.
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 QgsPointCloudLayer * parameterAsPointCloudLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a point cloud layer.
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 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.
Utility functions for use with processing classes.
@ 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, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Interprets a string as a map layer within the supplied context.
@ SkipIndexGeneration
Do not generate index when creating a layer. Makes sense only for point cloud layers.
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.
Qgis::PropertyType propertyType() const
Returns the property type.
A combo box which displays the list of connections registered for a given provider.
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.
A QgsGeometry with associated coordinate reference system.
@ ICON_X
A cross is used to highlight points (x).
Stores settings for use within QGIS.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
A spin box with a clear button that will set the value to the defined clear value.
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 dataset.
QgsRectangle extent() const final
Returns the extent of the 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).
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
constexpr QObjectUniquePtr< Tp > make_qobject_unique(Args &&...args)
Create an object owned by a QObjectUniquePtr.