76#include <QButtonGroup>
84#include <QPlainTextEdit>
85#include <QRadioButton>
90#include "moc_qgsprocessingwidgetwrapperimpl.cpp"
92using namespace Qt::StringLiterals;
101QgsProcessingBooleanParameterDefinitionWidget::QgsProcessingBooleanParameterDefinitionWidget(
106 QVBoxLayout *vlayout =
new QVBoxLayout();
107 vlayout->setContentsMargins( 0, 0, 0, 0 );
109 mDefaultCheckBox =
new QCheckBox( tr(
"Checked" ) );
113 mDefaultCheckBox->setChecked(
false );
114 vlayout->addWidget( mDefaultCheckBox );
117 setLayout( vlayout );
122 auto param = std::make_unique<QgsProcessingParameterBoolean>( name, description, mDefaultCheckBox->isChecked() );
123 param->setFlags( flags );
124 return param.release();
132QWidget *QgsProcessingBooleanWidgetWrapper::createWidget()
138 QString description = parameterDefinition()->description();
140 description = QObject::tr(
"%1 [optional]" ).arg( description );
142 mCheckBox =
new QCheckBox( description );
143 mCheckBox->setToolTip( parameterDefinition()->toolTip() );
145 connect( mCheckBox, &QCheckBox::toggled,
this, [
this] { emit widgetValueHasChanged(
this ); } );
152 mComboBox =
new QComboBox();
153 mComboBox->addItem( tr(
"Yes" ),
true );
154 mComboBox->addItem( tr(
"No" ),
false );
155 mComboBox->setToolTip( parameterDefinition()->toolTip() );
157 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
165QLabel *QgsProcessingBooleanWidgetWrapper::createLabel()
174void QgsProcessingBooleanWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
181 mCheckBox->setChecked( v );
189 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
195QVariant QgsProcessingBooleanWidgetWrapper::widgetValue()
const
200 return mCheckBox->isChecked();
204 return mComboBox->currentData();
209QString QgsProcessingBooleanWidgetWrapper::parameterType()
const
216 return new QgsProcessingBooleanWidgetWrapper( parameter, type );
223 return new QgsProcessingBooleanParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
231QgsProcessingCrsParameterDefinitionWidget::QgsProcessingCrsParameterDefinitionWidget(
236 QVBoxLayout *vlayout =
new QVBoxLayout();
237 vlayout->setContentsMargins( 0, 0, 0, 0 );
239 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
244 mCrsSelector->setShowAccuracyWarnings(
true );
251 vlayout->addWidget( mCrsSelector );
252 setLayout( vlayout );
257 auto param = std::make_unique<QgsProcessingParameterCrs>( name, description, mCrsSelector->crs().authid() );
258 param->setFlags( flags );
259 return param.release();
266QWidget *QgsProcessingCrsWidgetWrapper::createWidget()
268 Q_ASSERT( mProjectionSelectionWidget ==
nullptr );
270 mProjectionSelectionWidget->setToolTip( parameterDefinition()->toolTip() );
284 return mProjectionSelectionWidget;
289 QWidget *w =
new QWidget();
290 w->setToolTip( parameterDefinition()->toolTip() );
292 QVBoxLayout *vl =
new QVBoxLayout();
293 vl->setContentsMargins( 0, 0, 0, 0 );
296 mUseProjectCrsCheckBox =
new QCheckBox( tr(
"Use project CRS" ) );
297 mUseProjectCrsCheckBox->setToolTip( tr(
"Always use the current project CRS when running the model" ) );
298 vl->addWidget( mUseProjectCrsCheckBox );
299 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, mProjectionSelectionWidget, &QgsProjectionSelectionWidget::setDisabled );
300 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled,
this, [
this] { emit widgetValueHasChanged(
this ); } );
302 vl->addWidget( mProjectionSelectionWidget );
310void QgsProcessingCrsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
312 if ( mUseProjectCrsCheckBox )
314 if ( value.toString().compare(
"ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
316 mUseProjectCrsCheckBox->setChecked(
true );
321 mUseProjectCrsCheckBox->setChecked(
false );
326 if ( mProjectionSelectionWidget )
327 mProjectionSelectionWidget->setCrs( v );
330QVariant QgsProcessingCrsWidgetWrapper::widgetValue()
const
332 if ( mUseProjectCrsCheckBox && mUseProjectCrsCheckBox->isChecked() )
333 return u
"ProjectCrs"_s;
334 else if ( mProjectionSelectionWidget )
335 return mProjectionSelectionWidget->crs().isValid() ? mProjectionSelectionWidget->crs() : QVariant();
340QString QgsProcessingCrsWidgetWrapper::modelerExpressionFormatString()
const
342 return tr(
"string as EPSG code, WKT or PROJ format, or a string identifying a map layer" );
345QString QgsProcessingCrsWidgetWrapper::parameterType()
const
352 return new QgsProcessingCrsWidgetWrapper( parameter, type );
359 return new QgsProcessingCrsParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
368QgsProcessingStringParameterDefinitionWidget::QgsProcessingStringParameterDefinitionWidget(
373 QVBoxLayout *vlayout =
new QVBoxLayout();
374 vlayout->setContentsMargins( 0, 0, 0, 0 );
376 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
378 mDefaultLineEdit =
new QLineEdit();
381 vlayout->addWidget( mDefaultLineEdit );
385 mMultiLineCheckBox =
new QCheckBox( tr(
"Multiline input" ) );
387 mMultiLineCheckBox->setChecked( stringParam->multiLine() );
388 vlayout->addWidget( mMultiLineCheckBox );
392 setLayout( vlayout );
397 auto param = std::make_unique<QgsProcessingParameterString>( name, description, mDefaultLineEdit->text(), mMultiLineCheckBox->isChecked() );
398 param->setFlags( flags );
399 return param.release();
407QWidget *QgsProcessingStringWidgetWrapper::createWidget()
409 const QVariantMap metadata = parameterDefinition()->metadata();
410 const QVariant valueHintsVariant = metadata.value( u
"widget_wrapper"_s ).toMap().value( u
"value_hints"_s );
412 if ( valueHintsVariant.isValid() )
414 const QVariantList valueList = valueHintsVariant.toList();
415 mComboBox =
new QComboBox();
416 mComboBox->setToolTip( parameterDefinition()->toolTip() );
420 mComboBox->addItem( QString() );
422 for (
const QVariant &entry : valueList )
424 mComboBox->addItem( entry.toString(), entry.toString() );
426 mComboBox->setCurrentIndex( 0 );
428 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
440 mPlainTextEdit =
new QPlainTextEdit();
441 mPlainTextEdit->setToolTip( parameterDefinition()->toolTip() );
443 connect( mPlainTextEdit, &QPlainTextEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
444 return mPlainTextEdit;
448 mLineEdit =
new QLineEdit();
449 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
451 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
458 mLineEdit =
new QLineEdit();
459 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
461 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
470void QgsProcessingStringWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
474 mLineEdit->setText( v );
475 if ( mPlainTextEdit )
476 mPlainTextEdit->setPlainText( v );
480 if ( !value.isValid() )
481 index = mComboBox->findData( QVariant() );
483 index = mComboBox->findData( v );
486 mComboBox->setCurrentIndex( index );
488 mComboBox->setCurrentIndex( 0 );
492QVariant QgsProcessingStringWidgetWrapper::widgetValue()
const
495 return mLineEdit->text();
496 else if ( mPlainTextEdit )
497 return mPlainTextEdit->toPlainText();
498 else if ( mComboBox )
499 return mComboBox->currentData();
504QString QgsProcessingStringWidgetWrapper::parameterType()
const
511 return new QgsProcessingStringWidgetWrapper( parameter, type );
518 return new QgsProcessingStringParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
530QWidget *QgsProcessingAuthConfigWidgetWrapper::createWidget()
539 mAuthConfigSelect->setToolTip( parameterDefinition()->toolTip() );
542 return mAuthConfigSelect;
548void QgsProcessingAuthConfigWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
551 if ( mAuthConfigSelect )
552 mAuthConfigSelect->setConfigId( v );
555QVariant QgsProcessingAuthConfigWidgetWrapper::widgetValue()
const
557 if ( mAuthConfigSelect )
558 return mAuthConfigSelect->configId();
563QString QgsProcessingAuthConfigWidgetWrapper::parameterType()
const
570 return new QgsProcessingAuthConfigWidgetWrapper( parameter, type );
577QgsProcessingNumberParameterDefinitionWidget::QgsProcessingNumberParameterDefinitionWidget(
582 QVBoxLayout *vlayout =
new QVBoxLayout();
583 vlayout->setContentsMargins( 0, 0, 0, 0 );
585 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
587 mTypeComboBox =
new QComboBox();
590 vlayout->addWidget( mTypeComboBox );
592 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
593 mMinLineEdit =
new QLineEdit();
594 vlayout->addWidget( mMinLineEdit );
596 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
597 mMaxLineEdit =
new QLineEdit();
598 vlayout->addWidget( mMaxLineEdit );
600 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
601 mDefaultLineEdit =
new QLineEdit();
602 vlayout->addWidget( mDefaultLineEdit );
606 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( numberParam->dataType() ) ) );
608 if ( !
qgsDoubleNear( numberParam->maximum(), std::numeric_limits<double>::max() ) )
610 mMaxLineEdit->setText( QLocale().toString( numberParam->maximum() ) );
614 mMaxLineEdit->clear();
617 if ( !
qgsDoubleNear( numberParam->minimum(), std::numeric_limits<double>::lowest() ) )
619 mMinLineEdit->setText( QLocale().toString( numberParam->minimum() ) );
623 mMinLineEdit->clear();
626 mDefaultLineEdit->setText( numberParam->defaultValueForGui().toString() );
634 setLayout( vlayout );
643 auto param = std::make_unique<QgsProcessingParameterNumber>( name, description, dataType, ok ? val : QVariant() );
645 if ( !mMinLineEdit->text().trimmed().isEmpty() )
650 param->setMinimum( val );
654 if ( !mMaxLineEdit->text().trimmed().isEmpty() )
659 param->setMaximum( val );
663 param->setFlags( flags );
664 return param.release();
671QWidget *QgsProcessingNumericWidgetWrapper::createWidget()
674 const QVariantMap metadata = numberDef->
metadata();
675 const int decimals = metadata.value( u
"widget_wrapper"_s ).toMap().value( u
"decimals"_s, 6 ).toInt();
683 QAbstractSpinBox *spinBox =
nullptr;
688 mDoubleSpinBox->setExpressionsEnabled(
true );
689 mDoubleSpinBox->setDecimals( decimals );
694 double singleStep = calculateStep( numberDef->
minimum(), numberDef->
maximum() );
695 singleStep = std::max( singleStep, std::pow( 10, -decimals ) );
696 mDoubleSpinBox->setSingleStep( singleStep );
699 spinBox = mDoubleSpinBox;
704 mSpinBox->setExpressionsEnabled(
true );
708 spinBox->setToolTip( parameterDefinition()->toolTip() );
710 double max = 999999999;
715 double min = -999999999;
720 if ( mDoubleSpinBox )
722 mDoubleSpinBox->setMinimum( min );
723 mDoubleSpinBox->setMaximum( max );
727 mSpinBox->setMinimum(
static_cast<int>( min ) );
728 mSpinBox->setMaximum(
static_cast<int>( max ) );
733 mAllowingNull =
true;
734 if ( mDoubleSpinBox )
736 mDoubleSpinBox->setShowClearButton(
true );
737 const double min = mDoubleSpinBox->minimum() - mDoubleSpinBox->singleStep();
738 mDoubleSpinBox->setMinimum( min );
739 mDoubleSpinBox->setValue( min );
743 mSpinBox->setShowClearButton(
true );
744 const int min = mSpinBox->minimum() - 1;
745 mSpinBox->setMinimum( min );
746 mSpinBox->setValue( min );
748 spinBox->setSpecialValueText( tr(
"Not set" ) );
756 if ( mDoubleSpinBox )
760 mDoubleSpinBox->setClearValue( defaultVal );
766 mSpinBox->setClearValue( intVal );
772 if ( mDoubleSpinBox )
773 mDoubleSpinBox->setClearValue( numberDef->
minimum() );
775 mSpinBox->setClearValue(
static_cast<int>( numberDef->
minimum() ) );
780 if ( mDoubleSpinBox )
782 mDoubleSpinBox->setValue( 0 );
783 mDoubleSpinBox->setClearValue( 0 );
787 mSpinBox->setValue( 0 );
788 mSpinBox->setClearValue( 0 );
793 if ( mDoubleSpinBox )
794 connect( mDoubleSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
796 connect( mSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
804void QgsProcessingNumericWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
806 if ( mDoubleSpinBox )
808 if ( mAllowingNull && !value.isValid() )
809 mDoubleSpinBox->clear();
813 mDoubleSpinBox->setValue( v );
818 if ( mAllowingNull && !value.isValid() )
823 mSpinBox->setValue( v );
828QVariant QgsProcessingNumericWidgetWrapper::widgetValue()
const
830 if ( mDoubleSpinBox )
832 if ( mAllowingNull &&
qgsDoubleNear( mDoubleSpinBox->value(), mDoubleSpinBox->minimum() ) )
835 return mDoubleSpinBox->value();
839 if ( mAllowingNull && mSpinBox->value() == mSpinBox->minimum() )
842 return mSpinBox->value();
848double QgsProcessingNumericWidgetWrapper::calculateStep(
const double minimum,
const double maximum )
850 const double valueRange = maximum - minimum;
851 if ( valueRange <= 1.0 )
853 const double step = valueRange / 10.0;
855 return qgsRound( step, -std::floor( std::log( step ) ) );
863QString QgsProcessingNumericWidgetWrapper::parameterType()
const
870 return new QgsProcessingNumericWidgetWrapper( parameter, type );
877 return new QgsProcessingNumberParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
884QgsProcessingDistanceParameterDefinitionWidget::QgsProcessingDistanceParameterDefinitionWidget(
889 QVBoxLayout *vlayout =
new QVBoxLayout();
890 vlayout->setContentsMargins( 0, 0, 0, 0 );
892 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
894 mParentLayerComboBox =
new QComboBox();
896 QString initialParent;
898 initialParent = distParam->parentParameterName();
900 if (
auto *lModel = widgetContext.
model() )
903 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
904 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
908 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
909 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
911 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
916 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
917 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
919 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
924 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
925 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
927 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
932 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
933 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
935 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
941 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
944 mParentLayerComboBox->addItem( initialParent, initialParent );
945 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
948 vlayout->addWidget( mParentLayerComboBox );
951 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
952 mMinLineEdit =
new QLineEdit();
953 vlayout->addWidget( mMinLineEdit );
955 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
956 mMaxLineEdit =
new QLineEdit();
957 vlayout->addWidget( mMaxLineEdit );
959 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
960 mDefaultLineEdit =
new QLineEdit();
961 vlayout->addWidget( mDefaultLineEdit );
965 mMinLineEdit->setText( QLocale().toString( distParam->minimum() ) );
966 mMaxLineEdit->setText( QLocale().toString( distParam->maximum() ) );
967 mDefaultLineEdit->setText( distParam->defaultValueForGui().toString() );
973 setLayout( vlayout );
981 auto param = std::make_unique<QgsProcessingParameterDistance>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
986 param->setMinimum( val );
992 param->setMaximum( val );
995 param->setFlags( flags );
996 return param.release();
1000 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1003QString QgsProcessingDistanceWidgetWrapper::parameterType()
const
1010 return new QgsProcessingDistanceWidgetWrapper( parameter, type );
1013QWidget *QgsProcessingDistanceWidgetWrapper::createWidget()
1017 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1022 mLabel =
new QLabel();
1023 mUnitsCombo =
new QComboBox();
1035 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1036 QHBoxLayout *layout =
new QHBoxLayout();
1037 layout->addWidget( spin, 1 );
1038 layout->insertSpacing( 1, labelMargin / 2 );
1039 layout->insertWidget( 2, mLabel );
1040 layout->insertWidget( 3, mUnitsCombo );
1045 mWarningLabel =
new QWidget();
1046 QHBoxLayout *warningLayout =
new QHBoxLayout();
1047 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1048 QLabel *warning =
new QLabel();
1050 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1051 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1052 warning->setToolTip( tr(
"Distance is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1053 warningLayout->insertSpacing( 0, labelMargin / 2 );
1054 warningLayout->insertWidget( 1, warning );
1055 mWarningLabel->setLayout( warningLayout );
1056 layout->insertWidget( 4, mWarningLabel );
1058 QWidget *w =
new QWidget();
1059 layout->setContentsMargins( 0, 0, 0, 0 );
1060 w->setLayout( layout );
1074void QgsProcessingDistanceWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1076 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1083 if ( wrapper->parameterDefinition()->name() ==
static_cast<const QgsProcessingParameterDistance *
>( parameterDefinition() )->parentParameterName() )
1085 setUnitParameterValue( wrapper->parameterValue(), wrapper );
1105 std::unique_ptr<QgsProcessingContext> tmpContext;
1106 if ( mProcessingContextGenerator )
1107 context = mProcessingContextGenerator->processingContext();
1111 tmpContext = std::make_unique<QgsProcessingContext>();
1112 context = tmpContext.get();
1119 units = crs.mapUnits();
1130 mUnitsCombo->hide();
1138 if ( mBaseUnit != units )
1140 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( units ) ) );
1143 mUnitsCombo->show();
1150QVariant QgsProcessingDistanceWidgetWrapper::widgetValue()
const
1152 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1153 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1168 return new QgsProcessingDistanceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1176QgsProcessingAreaParameterDefinitionWidget::QgsProcessingAreaParameterDefinitionWidget(
1181 QVBoxLayout *vlayout =
new QVBoxLayout();
1182 vlayout->setContentsMargins( 0, 0, 0, 0 );
1184 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
1186 mParentLayerComboBox =
new QComboBox();
1188 QString initialParent;
1190 initialParent = areaParam->parentParameterName();
1192 if (
auto *lModel = widgetContext.
model() )
1195 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
1196 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
1200 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1201 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1203 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1208 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1209 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1211 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1216 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1217 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1219 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1224 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1225 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1227 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1233 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
1236 mParentLayerComboBox->addItem( initialParent, initialParent );
1237 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1242 vlayout->addWidget( mParentLayerComboBox );
1244 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1245 mMinLineEdit =
new QLineEdit();
1246 vlayout->addWidget( mMinLineEdit );
1248 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1249 mMaxLineEdit =
new QLineEdit();
1250 vlayout->addWidget( mMaxLineEdit );
1252 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1253 mDefaultLineEdit =
new QLineEdit();
1254 vlayout->addWidget( mDefaultLineEdit );
1258 mMinLineEdit->setText( QLocale().toString( areaParam->minimum() ) );
1259 mMaxLineEdit->setText( QLocale().toString( areaParam->maximum() ) );
1260 mDefaultLineEdit->setText( areaParam->defaultValueForGui().toString() );
1267 setLayout( vlayout );
1275 auto param = std::make_unique<QgsProcessingParameterArea>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1280 param->setMinimum( val );
1286 param->setMaximum( val );
1289 param->setFlags( flags );
1290 return param.release();
1299 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1302QString QgsProcessingAreaWidgetWrapper::parameterType()
const
1309 return new QgsProcessingAreaWidgetWrapper( parameter, type );
1312QWidget *QgsProcessingAreaWidgetWrapper::createWidget()
1316 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1321 mLabel =
new QLabel();
1322 mUnitsCombo =
new QComboBox();
1337 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1338 QHBoxLayout *layout =
new QHBoxLayout();
1339 layout->addWidget( spin, 1 );
1340 layout->insertSpacing( 1, labelMargin / 2 );
1341 layout->insertWidget( 2, mLabel );
1342 layout->insertWidget( 3, mUnitsCombo );
1347 mWarningLabel =
new QWidget();
1348 QHBoxLayout *warningLayout =
new QHBoxLayout();
1349 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1350 QLabel *warning =
new QLabel();
1352 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1353 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1354 warning->setToolTip( tr(
"Area is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1355 warningLayout->insertSpacing( 0, labelMargin / 2 );
1356 warningLayout->insertWidget( 1, warning );
1357 mWarningLabel->setLayout( warningLayout );
1358 layout->insertWidget( 4, mWarningLabel );
1360 QWidget *w =
new QWidget();
1361 layout->setContentsMargins( 0, 0, 0, 0 );
1362 w->setLayout( layout );
1376void QgsProcessingAreaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1378 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1407 std::unique_ptr<QgsProcessingContext> tmpContext;
1408 if ( mProcessingContextGenerator )
1409 context = mProcessingContextGenerator->processingContext();
1413 tmpContext = std::make_unique<QgsProcessingContext>();
1414 context = tmpContext.get();
1421 units = QgsUnitTypes::distanceToAreaUnit( crs.mapUnits() );
1427void QgsProcessingAreaWidgetWrapper::setUnits(
Qgis::AreaUnit units )
1432 mUnitsCombo->hide();
1437 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QVariant::fromValue( units ) ) );
1438 mUnitsCombo->show();
1445QVariant QgsProcessingAreaWidgetWrapper::widgetValue()
const
1447 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1448 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1463 return new QgsProcessingAreaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1471QgsProcessingVolumeParameterDefinitionWidget::QgsProcessingVolumeParameterDefinitionWidget(
1476 QVBoxLayout *vlayout =
new QVBoxLayout();
1477 vlayout->setContentsMargins( 0, 0, 0, 0 );
1479 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
1481 mParentLayerComboBox =
new QComboBox();
1483 QString initialParent;
1485 initialParent = volumeParam->parentParameterName();
1487 if (
auto *lModel = widgetContext.
model() )
1490 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
1491 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
1495 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1496 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1498 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1503 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1504 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1506 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1511 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1512 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1514 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1519 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1520 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1522 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1528 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
1531 mParentLayerComboBox->addItem( initialParent, initialParent );
1532 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1535 vlayout->addWidget( mParentLayerComboBox );
1537 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1538 mMinLineEdit =
new QLineEdit();
1539 vlayout->addWidget( mMinLineEdit );
1541 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1542 mMaxLineEdit =
new QLineEdit();
1543 vlayout->addWidget( mMaxLineEdit );
1545 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1546 mDefaultLineEdit =
new QLineEdit();
1547 vlayout->addWidget( mDefaultLineEdit );
1551 mMinLineEdit->setText( QLocale().toString( volumeParam->minimum() ) );
1552 mMaxLineEdit->setText( QLocale().toString( volumeParam->maximum() ) );
1553 mDefaultLineEdit->setText( volumeParam->defaultValueForGui().toString() );
1561 setLayout( vlayout );
1569 auto param = std::make_unique<QgsProcessingParameterVolume>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1574 param->setMinimum( val );
1580 param->setMaximum( val );
1583 param->setFlags( flags );
1584 return param.release();
1593 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1596QString QgsProcessingVolumeWidgetWrapper::parameterType()
const
1603 return new QgsProcessingVolumeWidgetWrapper( parameter, type );
1606QWidget *QgsProcessingVolumeWidgetWrapper::createWidget()
1610 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1615 mLabel =
new QLabel();
1616 mUnitsCombo =
new QComboBox();
1629 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1630 QHBoxLayout *layout =
new QHBoxLayout();
1631 layout->addWidget( spin, 1 );
1632 layout->insertSpacing( 1, labelMargin / 2 );
1633 layout->insertWidget( 2, mLabel );
1634 layout->insertWidget( 3, mUnitsCombo );
1639 mWarningLabel =
new QWidget();
1640 QHBoxLayout *warningLayout =
new QHBoxLayout();
1641 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1642 QLabel *warning =
new QLabel();
1644 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1645 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1646 warning->setToolTip( tr(
"Volume is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1647 warningLayout->insertSpacing( 0, labelMargin / 2 );
1648 warningLayout->insertWidget( 1, warning );
1649 mWarningLabel->setLayout( warningLayout );
1650 layout->insertWidget( 4, mWarningLabel );
1652 QWidget *w =
new QWidget();
1653 layout->setContentsMargins( 0, 0, 0, 0 );
1654 w->setLayout( layout );
1668void QgsProcessingVolumeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1670 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1699 std::unique_ptr<QgsProcessingContext> tmpContext;
1700 if ( mProcessingContextGenerator )
1701 context = mProcessingContextGenerator->processingContext();
1705 tmpContext = std::make_unique<QgsProcessingContext>();
1706 context = tmpContext.get();
1713 units = QgsUnitTypes::distanceToVolumeUnit( crs.mapUnits() );
1724 mUnitsCombo->hide();
1729 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QVariant::fromValue( units ) ) );
1730 mUnitsCombo->show();
1737QVariant QgsProcessingVolumeWidgetWrapper::widgetValue()
const
1739 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1740 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1755 return new QgsProcessingVolumeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1763QgsProcessingDurationParameterDefinitionWidget::QgsProcessingDurationParameterDefinitionWidget(
1768 QVBoxLayout *vlayout =
new QVBoxLayout();
1769 vlayout->setContentsMargins( 0, 0, 0, 0 );
1771 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1772 mMinLineEdit =
new QLineEdit();
1773 vlayout->addWidget( mMinLineEdit );
1775 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1776 mMaxLineEdit =
new QLineEdit();
1777 vlayout->addWidget( mMaxLineEdit );
1779 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1780 mDefaultLineEdit =
new QLineEdit();
1781 vlayout->addWidget( mDefaultLineEdit );
1783 vlayout->addWidget(
new QLabel( tr(
"Default unit type" ) ) );
1785 mUnitsCombo =
new QComboBox();
1795 vlayout->addWidget( mUnitsCombo );
1801 mMinLineEdit->setText( QLocale().toString( durationParam->minimum() ) );
1802 mMaxLineEdit->setText( QLocale().toString( durationParam->maximum() ) );
1803 mDefaultLineEdit->setText( durationParam->defaultValueForGui().toString() );
1804 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( durationParam->defaultUnit() ) ) );
1810 setLayout( vlayout );
1818 auto param = std::make_unique<QgsProcessingParameterDuration>( name, description, ok ? val : QVariant() );
1823 param->setMinimum( val );
1829 param->setMaximum( val );
1832 param->setDefaultUnit(
static_cast<Qgis::TemporalUnit>( mUnitsCombo->currentData().toInt() ) );
1834 param->setFlags( flags );
1835 return param.release();
1839 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1842QString QgsProcessingDurationWidgetWrapper::parameterType()
const
1849 return new QgsProcessingDurationWidgetWrapper( parameter, type );
1852QWidget *QgsProcessingDurationWidgetWrapper::createWidget()
1856 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1861 mUnitsCombo =
new QComboBox();
1873 QHBoxLayout *layout =
new QHBoxLayout();
1874 layout->addWidget( spin, 1 );
1875 layout->insertWidget( 1, mUnitsCombo );
1877 QWidget *w =
new QWidget();
1878 layout->setContentsMargins( 0, 0, 0, 0 );
1879 w->setLayout( layout );
1881 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( durationDef->
defaultUnit() ) ) );
1882 mUnitsCombo->show();
1894QLabel *QgsProcessingDurationWidgetWrapper::createLabel()
1906QVariant QgsProcessingDurationWidgetWrapper::widgetValue()
const
1908 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1909 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo )
1920void QgsProcessingDurationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1926 QgsProcessingNumericWidgetWrapper::setWidgetValue( val, context );
1930 QgsProcessingNumericWidgetWrapper::setWidgetValue( value, context );
1938 return new QgsProcessingDurationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1945QgsProcessingScaleParameterDefinitionWidget::QgsProcessingScaleParameterDefinitionWidget(
1950 QVBoxLayout *vlayout =
new QVBoxLayout();
1951 vlayout->setContentsMargins( 0, 0, 0, 0 );
1953 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1955 mDefaultLineEdit =
new QLineEdit();
1959 mDefaultLineEdit->setText( scaleParam->defaultValueForGui().toString() );
1962 vlayout->addWidget( mDefaultLineEdit );
1965 setLayout( vlayout );
1971 double val = mDefaultLineEdit->text().toDouble( &ok );
1972 auto param = std::make_unique<QgsProcessingParameterScale>( name, description, ok ? val : QVariant() );
1973 param->setFlags( flags );
1974 return param.release();
1978 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1981QString QgsProcessingScaleWidgetWrapper::parameterType()
const
1988 return new QgsProcessingScaleWidgetWrapper( parameter, type );
1991QWidget *QgsProcessingScaleWidgetWrapper::createWidget()
2003 mScaleWidget->setAllowNull(
true );
2005 mScaleWidget->setMapCanvas( widgetContext().mapCanvas() );
2006 mScaleWidget->setShowCurrentScaleButton(
true );
2008 mScaleWidget->setToolTip( parameterDefinition()->toolTip() );
2010 return mScaleWidget;
2019 mScaleWidget->setMapCanvas( context.
mapCanvas() );
2024QVariant QgsProcessingScaleWidgetWrapper::widgetValue()
const
2026 return mScaleWidget && !mScaleWidget->isNull() ? QVariant( mScaleWidget->scale() ) : QVariant();
2029void QgsProcessingScaleWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2033 if ( mScaleWidget->allowNull() && !value.isValid() )
2034 mScaleWidget->setNull();
2038 mScaleWidget->setScale( v );
2047 return new QgsProcessingScaleParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2055QgsProcessingRangeParameterDefinitionWidget::QgsProcessingRangeParameterDefinitionWidget(
2060 QVBoxLayout *vlayout =
new QVBoxLayout();
2061 vlayout->setContentsMargins( 0, 0, 0, 0 );
2063 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
2065 mTypeComboBox =
new QComboBox();
2068 vlayout->addWidget( mTypeComboBox );
2070 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
2071 mMinLineEdit =
new QLineEdit();
2072 vlayout->addWidget( mMinLineEdit );
2074 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
2075 mMaxLineEdit =
new QLineEdit();
2076 vlayout->addWidget( mMaxLineEdit );
2080 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( rangeParam->dataType() ) ) );
2082 mMinLineEdit->setText( QLocale().toString( range.at( 0 ) ) );
2083 mMaxLineEdit->setText( QLocale().toString( range.at( 1 ) ) );
2090 setLayout( vlayout );
2095 QString defaultValue;
2096 if ( mMinLineEdit->text().isEmpty() )
2098 defaultValue = u
"None"_s;
2106 defaultValue = u
"None"_s;
2110 if ( mMaxLineEdit->text().isEmpty() )
2112 defaultValue +=
",None"_L1;
2118 defaultValue += u
",%1"_s.arg( ok ? QString::number( val ) :
"None"_L1 );
2122 auto param = std::make_unique<QgsProcessingParameterRange>( name, description, dataType, defaultValue );
2123 param->setFlags( flags );
2124 return param.release();
2132QWidget *QgsProcessingRangeWidgetWrapper::createWidget()
2141 QHBoxLayout *layout =
new QHBoxLayout();
2146 mMinSpinBox->setExpressionsEnabled(
true );
2147 mMinSpinBox->setShowClearButton(
false );
2148 mMaxSpinBox->setExpressionsEnabled(
true );
2149 mMaxSpinBox->setShowClearButton(
false );
2151 QLabel *minLabel =
new QLabel( tr(
"Min" ) );
2152 layout->addWidget( minLabel );
2153 layout->addWidget( mMinSpinBox, 1 );
2155 QLabel *maxLabel =
new QLabel( tr(
"Max" ) );
2156 layout->addWidget( maxLabel );
2157 layout->addWidget( mMaxSpinBox, 1 );
2159 QWidget *w =
new QWidget();
2160 layout->setContentsMargins( 0, 0, 0, 0 );
2161 w->setLayout( layout );
2165 mMinSpinBox->setDecimals( 6 );
2166 mMaxSpinBox->setDecimals( 6 );
2170 mMinSpinBox->setDecimals( 0 );
2171 mMaxSpinBox->setDecimals( 0 );
2174 mMinSpinBox->setMinimum( -99999999.999999 );
2175 mMaxSpinBox->setMinimum( -99999999.999999 );
2176 mMinSpinBox->setMaximum( 99999999.999999 );
2177 mMaxSpinBox->setMaximum( 99999999.999999 );
2181 mAllowingNull =
true;
2183 const double min = mMinSpinBox->minimum() - 1;
2184 mMinSpinBox->setMinimum( min );
2185 mMaxSpinBox->setMinimum( min );
2186 mMinSpinBox->setValue( min );
2187 mMaxSpinBox->setValue( min );
2189 mMinSpinBox->setShowClearButton(
true );
2190 mMaxSpinBox->setShowClearButton(
true );
2191 mMinSpinBox->setSpecialValueText( tr(
"Not set" ) );
2192 mMaxSpinBox->setSpecialValueText( tr(
"Not set" ) );
2195 w->setToolTip( parameterDefinition()->toolTip() );
2197 connect( mMinSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this](
const double v ) {
2198 mBlockChangedSignal++;
2199 if ( !mAllowingNull && v > mMaxSpinBox->value() )
2200 mMaxSpinBox->setValue( v );
2201 mBlockChangedSignal--;
2203 if ( !mBlockChangedSignal )
2204 emit widgetValueHasChanged(
this );
2206 connect( mMaxSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this](
const double v ) {
2207 mBlockChangedSignal++;
2208 if ( !mAllowingNull && v < mMinSpinBox->value() )
2209 mMinSpinBox->setValue( v );
2210 mBlockChangedSignal--;
2212 if ( !mBlockChangedSignal )
2213 emit widgetValueHasChanged(
this );
2222void QgsProcessingRangeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2225 if ( mAllowingNull && v.empty() )
2227 mMinSpinBox->clear();
2228 mMaxSpinBox->clear();
2235 if ( mAllowingNull )
2237 mBlockChangedSignal++;
2238 if ( std::isnan( v.at( 0 ) ) )
2239 mMinSpinBox->clear();
2241 mMinSpinBox->setValue( v.at( 0 ) );
2243 if ( v.count() >= 2 )
2245 if ( std::isnan( v.at( 1 ) ) )
2246 mMaxSpinBox->clear();
2248 mMaxSpinBox->setValue( v.at( 1 ) );
2250 mBlockChangedSignal--;
2254 mBlockChangedSignal++;
2255 mMinSpinBox->setValue( v.at( 0 ) );
2256 if ( v.count() >= 2 )
2257 mMaxSpinBox->setValue( v.at( 1 ) );
2258 mBlockChangedSignal--;
2262 if ( !mBlockChangedSignal )
2263 emit widgetValueHasChanged(
this );
2266QVariant QgsProcessingRangeWidgetWrapper::widgetValue()
const
2268 if ( mAllowingNull )
2271 if (
qgsDoubleNear( mMinSpinBox->value(), mMinSpinBox->minimum() ) )
2274 value = QString::number( mMinSpinBox->value() );
2276 if (
qgsDoubleNear( mMaxSpinBox->value(), mMaxSpinBox->minimum() ) )
2277 value +=
",None"_L1;
2279 value += u
",%1"_s.arg( mMaxSpinBox->value() );
2284 return u
"%1,%2"_s.arg( mMinSpinBox->value() ).arg( mMaxSpinBox->value() );
2287QString QgsProcessingRangeWidgetWrapper::modelerExpressionFormatString()
const
2289 return tr(
"string as two comma delimited floats, e.g. '1,10'" );
2292QString QgsProcessingRangeWidgetWrapper::parameterType()
const
2299 return new QgsProcessingRangeWidgetWrapper( parameter, type );
2306 return new QgsProcessingRangeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2314QgsProcessingMatrixParameterDefinitionWidget::QgsProcessingMatrixParameterDefinitionWidget(
2319 QVBoxLayout *vlayout =
new QVBoxLayout();
2320 vlayout->setContentsMargins( 0, 0, 0, 0 );
2322 mMatrixWidget =
new QgsProcessingMatrixModelerWidget();
2325 mMatrixWidget->setValue( matrixParam->headers(), matrixParam->defaultValueForGui() );
2326 mMatrixWidget->setFixedRows( matrixParam->hasFixedNumberRows() );
2328 vlayout->addWidget( mMatrixWidget );
2332 setLayout( vlayout );
2337 auto param = std::make_unique<QgsProcessingParameterMatrix>( name, description, 1, mMatrixWidget->fixedRows(), mMatrixWidget->headers(), mMatrixWidget->value() );
2338 param->setFlags( flags );
2339 return param.release();
2347QWidget *QgsProcessingMatrixWidgetWrapper::createWidget()
2349 mMatrixWidget =
new QgsProcessingMatrixParameterPanel(
nullptr,
dynamic_cast<const QgsProcessingParameterMatrix *
>( parameterDefinition() ) );
2350 mMatrixWidget->setToolTip( parameterDefinition()->toolTip() );
2352 connect( mMatrixWidget, &QgsProcessingMatrixParameterPanel::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
2360 return mMatrixWidget;
2366void QgsProcessingMatrixWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2369 if ( mMatrixWidget )
2370 mMatrixWidget->setValue( v );
2373QVariant QgsProcessingMatrixWidgetWrapper::widgetValue()
const
2375 if ( mMatrixWidget )
2376 return mMatrixWidget->value().isEmpty() ? QVariant() : mMatrixWidget->value();
2381QString QgsProcessingMatrixWidgetWrapper::modelerExpressionFormatString()
const
2383 return tr(
"comma delimited string of values, or an array of values" );
2386QString QgsProcessingMatrixWidgetWrapper::parameterType()
const
2393 return new QgsProcessingMatrixWidgetWrapper( parameter, type );
2400 return new QgsProcessingMatrixParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2409QgsProcessingFileParameterDefinitionWidget::QgsProcessingFileParameterDefinitionWidget(
2414 QVBoxLayout *vlayout =
new QVBoxLayout();
2415 vlayout->setContentsMargins( 0, 0, 0, 0 );
2417 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
2419 mTypeComboBox =
new QComboBox();
2423 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( fileParam->behavior() ) ) );
2425 mTypeComboBox->setCurrentIndex( 0 );
2426 vlayout->addWidget( mTypeComboBox );
2430 vlayout->addWidget(
new QLabel( tr(
"File filter" ) ) );
2432 mFilterComboBox =
new QComboBox();
2433 mFilterComboBox->setEditable(
true );
2435 mFilterComboBox->addItem( tr(
"All Files (*.*)" ) );
2436 mFilterComboBox->addItem( tr(
"CSV Files (*.csv)" ) );
2437 mFilterComboBox->addItem( tr(
"HTML Files (*.html *.htm)" ) );
2438 mFilterComboBox->addItem( tr(
"Text Files (*.txt)" ) );
2440 mFilterComboBox->setCurrentText( fileParam->fileFilter() );
2442 mFilterComboBox->setCurrentIndex( 0 );
2443 vlayout->addWidget( mFilterComboBox );
2447 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2450 mDefaultFileWidget->lineEdit()->setShowClearButton(
true );
2454 mDefaultFileWidget->setFilePath( fileParam->defaultValueForGui().toString() );
2458 vlayout->addWidget( mDefaultFileWidget );
2461 connect( mTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this] {
2469 setLayout( vlayout );
2474 auto param = std::make_unique<QgsProcessingParameterFile>( name, description );
2477 param->setFileFilter( mFilterComboBox->currentText() );
2478 if ( !mDefaultFileWidget->filePath().isEmpty() )
2479 param->setDefaultValue( mDefaultFileWidget->filePath() );
2480 param->setFlags( flags );
2481 return param.release();
2489QWidget *QgsProcessingFileWidgetWrapper::createWidget()
2502 mFileWidget->setToolTip( parameterDefinition()->toolTip() );
2503 mFileWidget->setDialogTitle( parameterDefinition()->description() );
2505 mFileWidget->setDefaultRoot(
QgsSettings().value( u
"/Processing/LastInputPath"_s, QDir::homePath() ).toString() );
2512 mFileWidget->setFilter( fileParam->
fileFilter() );
2513 else if ( !fileParam->
extension().isEmpty() )
2514 mFileWidget->setFilter( tr(
"%1 files" ).arg( fileParam->
extension().toUpper() ) + u
" (*."_s + fileParam->
extension().toLower() +
')' );
2523 QgsSettings().
setValue( u
"/Processing/LastInputPath"_s, QFileInfo( path ).canonicalPath() );
2524 emit widgetValueHasChanged(
this );
2532void QgsProcessingFileWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2536 mFileWidget->setFilePath( v );
2539QVariant QgsProcessingFileWidgetWrapper::widgetValue()
const
2542 return mFileWidget->filePath();
2547QString QgsProcessingFileWidgetWrapper::modelerExpressionFormatString()
const
2549 return tr(
"string representing a path to a file or folder" );
2552QString QgsProcessingFileWidgetWrapper::parameterType()
const
2559 return new QgsProcessingFileWidgetWrapper( parameter, type );
2566 return new QgsProcessingFileParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2574QgsProcessingExpressionParameterDefinitionWidget::QgsProcessingExpressionParameterDefinitionWidget(
2579 QVBoxLayout *vlayout =
new QVBoxLayout();
2580 vlayout->setContentsMargins( 0, 0, 0, 0 );
2581 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2584 mDefaultQgisLineEdit->registerExpressionContextGenerator(
this );
2586 mDefaultPointCloudLineEdit =
new QgsProcessingPointCloudExpressionLineEdit();
2587 mDefaultRasterCalculatorLineEdit =
new QgsProcessingRasterCalculatorExpressionLineEdit();
2589 QStackedWidget *stackedWidget =
new QStackedWidget();
2590 stackedWidget->addWidget( mDefaultQgisLineEdit );
2591 stackedWidget->addWidget( mDefaultPointCloudLineEdit );
2592 stackedWidget->addWidget( mDefaultRasterCalculatorLineEdit );
2593 vlayout->addWidget( stackedWidget );
2602 mDefaultQgisLineEdit->setExpression( expr );
2603 mDefaultPointCloudLineEdit->setExpression( expr );
2606 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
2608 mParentLayerComboBox =
new QComboBox();
2609 vlayout->addWidget( mParentLayerComboBox );
2611 vlayout->addWidget(
new QLabel( tr(
"Expression type" ) ) );
2612 mExpressionTypeComboBox =
new QComboBox();
2617 connect( mExpressionTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [
this, stackedWidget, definition, widgetContext](
int ) {
2618 mParentLayerComboBox->clear();
2619 mParentLayerComboBox->addItem( tr(
"None" ), QVariant() );
2621 stackedWidget->setCurrentIndex( mExpressionTypeComboBox->currentIndex() > 0 ? mExpressionTypeComboBox->currentIndex() : 0 );
2623 QString initialParent;
2625 initialParent = expParam->parentLayerParameterName();
2629 if ( QgsProcessingModelAlgorithm *model = widgetContext.
model() )
2632 const QMap<QString, QgsProcessingModelParameter> components = model->parameterComponents();
2633 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
2640 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2641 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2643 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2648 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2649 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2651 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2658 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2659 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2661 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2672 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2673 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2675 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2683 if ( mParentLayerComboBox->count() == 1 && !initialParent.isEmpty() )
2686 mParentLayerComboBox->addItem( initialParent, initialParent );
2687 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2691 mExpressionTypeComboBox->setCurrentIndex( -1 );
2693 mExpressionTypeComboBox->setCurrentIndex( mExpressionTypeComboBox->findData(
static_cast<int>( expParam->expressionType() ) ) );
2695 mExpressionTypeComboBox->setCurrentIndex( 0 );
2697 vlayout->addWidget( mExpressionTypeComboBox );
2702 setLayout( vlayout );
2709 switch ( expressionType )
2712 expression = mDefaultQgisLineEdit->expression();
2715 expression = mDefaultPointCloudLineEdit->expression();
2718 expression = mDefaultRasterCalculatorLineEdit->expression();
2721 auto param = std::make_unique<QgsProcessingParameterExpression>( name, description, expression, mParentLayerComboBox->currentData().toString(),
false, expressionType );
2722 param->setFlags( flags );
2723 return param.release();
2730QWidget *QgsProcessingExpressionWidgetWrapper::createWidget()
2745 mExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2746 mExpLineEdit->setExpressionDialogTitle( parameterDefinition()->description() );
2747 mExpLineEdit->registerExpressionContextGenerator(
this );
2749 return mExpLineEdit;
2755 mPointCloudExpLineEdit =
new QgsProcessingPointCloudExpressionLineEdit();
2756 mPointCloudExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2757 connect( mPointCloudExpLineEdit, &QgsProcessingPointCloudExpressionLineEdit::expressionChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
2758 return mPointCloudExpLineEdit;
2763 mRasterCalculatorExpLineEdit =
new QgsProcessingRasterCalculatorExpressionLineEdit();
2764 mRasterCalculatorExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2767 mRasterCalculatorExpLineEdit->setLayers( QVariantList() <<
"A" <<
"B" <<
"C" <<
"D" <<
"E" <<
"F" <<
"G" );
2769 connect( mRasterCalculatorExpLineEdit, &QgsProcessingRasterCalculatorExpressionLineEdit::expressionChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
2770 return mRasterCalculatorExpLineEdit;
2774 if ( expParam->
metadata().value( u
"inlineEditor"_s ).toBool() )
2777 mExpBuilderWidget->setToolTip( parameterDefinition()->toolTip() );
2778 mExpBuilderWidget->init( createExpressionContext() );
2780 Q_UNUSED( changed );
2781 emit widgetValueHasChanged(
this );
2783 return mExpBuilderWidget;
2788 mFieldExpWidget->setToolTip( parameterDefinition()->toolTip() );
2789 mFieldExpWidget->setExpressionDialogTitle( parameterDefinition()->description() );
2790 mFieldExpWidget->registerExpressionContextGenerator(
this );
2792 mFieldExpWidget->setAllowEmptyFieldName(
true );
2795 emit widgetValueHasChanged(
this );
2797 return mFieldExpWidget;
2805void QgsProcessingExpressionWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
2817 setParentLayerWrapperValue( wrapper );
2833 if ( mExpBuilderWidget )
2836 mExpBuilderWidget->setExpressionContext( createExpressionContext() );
2844 std::unique_ptr<QgsProcessingContext> tmpContext;
2845 if ( mProcessingContextGenerator )
2846 context = mProcessingContextGenerator->processingContext();
2850 tmpContext = std::make_unique<QgsProcessingContext>();
2851 context = tmpContext.get();
2864 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2874 if ( mFieldExpWidget )
2875 mFieldExpWidget->setLayer(
nullptr );
2876 else if ( mExpBuilderWidget )
2877 mExpBuilderWidget->setLayer(
nullptr );
2878 else if ( mExpLineEdit )
2879 mExpLineEdit->setLayer(
nullptr );
2885 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
2888 mParentLayer = std::move( ownedLayer );
2896 if ( mFieldExpWidget )
2897 mFieldExpWidget->setLayer( layer );
2898 if ( mExpBuilderWidget )
2899 mExpBuilderWidget->setLayer( layer );
2900 else if ( mExpLineEdit )
2901 mExpLineEdit->setLayer( layer );
2910 if ( mPointCloudExpLineEdit )
2911 mPointCloudExpLineEdit->setLayer(
nullptr );
2917 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
2920 mParentLayer = std::move( ownedLayer );
2928 if ( mPointCloudExpLineEdit )
2929 mPointCloudExpLineEdit->setLayer( layer );
2936 if ( layers.isEmpty() )
2938 if ( mRasterCalculatorExpLineEdit )
2940 mRasterCalculatorExpLineEdit->setLayers( val.userType() == QMetaType::Type::QVariantList ? val.toList() : QVariantList() << val );
2945 if ( mRasterCalculatorExpLineEdit )
2947 QVariantList layersList;
2950 layersList << layer->
name();
2952 mRasterCalculatorExpLineEdit->setLayers( layersList );
2960void QgsProcessingExpressionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2963 if ( mFieldExpWidget )
2964 mFieldExpWidget->setExpression( v );
2965 else if ( mExpBuilderWidget )
2966 mExpBuilderWidget->setExpressionText( v );
2967 else if ( mExpLineEdit )
2968 mExpLineEdit->setExpression( v );
2969 else if ( mPointCloudExpLineEdit )
2970 mPointCloudExpLineEdit->setExpression( v );
2971 else if ( mRasterCalculatorExpLineEdit )
2972 mRasterCalculatorExpLineEdit->setExpression( v );
2975QVariant QgsProcessingExpressionWidgetWrapper::widgetValue()
const
2977 if ( mFieldExpWidget )
2978 return mFieldExpWidget->expression();
2979 if ( mExpBuilderWidget )
2980 return mExpBuilderWidget->expressionText();
2981 else if ( mExpLineEdit )
2982 return mExpLineEdit->expression();
2983 else if ( mPointCloudExpLineEdit )
2984 return mPointCloudExpLineEdit->expression();
2985 else if ( mRasterCalculatorExpLineEdit )
2986 return mRasterCalculatorExpLineEdit->expression();
2991QString QgsProcessingExpressionWidgetWrapper::modelerExpressionFormatString()
const
2993 return tr(
"string representation of an expression" );
2996const QgsVectorLayer *QgsProcessingExpressionWidgetWrapper::linkedVectorLayer()
const
2998 if ( mFieldExpWidget && mFieldExpWidget->layer() )
2999 return mFieldExpWidget->layer();
3001 if ( mExpBuilderWidget && mExpBuilderWidget->layer() )
3002 return mExpBuilderWidget->layer();
3007QString QgsProcessingExpressionWidgetWrapper::parameterType()
const
3014 return new QgsProcessingExpressionWidgetWrapper( parameter, type );
3021 return new QgsProcessingExpressionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3033 QHBoxLayout *hl =
new QHBoxLayout();
3034 hl->setContentsMargins( 0, 0, 0, 0 );
3036 mLineEdit =
new QLineEdit();
3037 mLineEdit->setEnabled(
false );
3038 hl->addWidget( mLineEdit, 1 );
3040 mToolButton =
new QToolButton();
3041 mToolButton->setText( QString( QChar( 0x2026 ) ) );
3042 hl->addWidget( mToolButton );
3048 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
3051 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingEnumPanelWidget::showDialog );
3054void QgsProcessingEnumPanelWidget::setValue(
const QVariant &value )
3056 if ( value.isValid() )
3058 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
3060 if ( mParam->usesStaticStrings() && mValue.count() == 1 && mValue.at( 0 ).toString().isEmpty() )
3066 updateSummaryText();
3070void QgsProcessingEnumPanelWidget::showDialog()
3072 QVariantList availableOptions;
3075 availableOptions.reserve( mParam->options().size() );
3077 if ( mParam->usesStaticStrings() )
3079 for ( QString o : mParam->options() )
3081 availableOptions << o;
3086 for (
int i = 0; i < mParam->options().count(); ++i )
3087 availableOptions << i;
3091 const QStringList options = mParam ? mParam->options() : QStringList();
3095 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
3096 widget->setPanelTitle( mParam->description() );
3098 if ( mParam->usesStaticStrings() )
3100 widget->setValueFormatter( [options](
const QVariant &v ) -> QString {
3101 const QString i = v.toString();
3102 return options.contains( i ) ? i : QString();
3107 widget->setValueFormatter( [options](
const QVariant &v ) -> QString {
3108 const int i = v.toInt();
3109 return options.size() > i ? options.at( i ) : QString();
3113 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
3119 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
3121 dlg.setValueFormatter( [options](
const QVariant &v ) -> QString {
3122 const int i = v.toInt();
3123 return options.size() > i ? options.at( i ) : QString();
3127 setValue( dlg.selectedOptions() );
3132void QgsProcessingEnumPanelWidget::updateSummaryText()
3137 if ( mValue.empty() )
3139 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
3144 values.reserve( mValue.size() );
3145 if ( mParam->usesStaticStrings() )
3147 for (
const QVariant &val : std::as_const( mValue ) )
3149 values << val.toString();
3154 const QStringList options = mParam->options();
3155 for (
const QVariant &val : std::as_const( mValue ) )
3157 const int i = val.toInt();
3158 values << ( options.size() > i ? options.at( i ) : QString() );
3162 const QString concatenated = values.join( tr(
"," ) );
3163 if ( concatenated.length() < 100 )
3164 mLineEdit->setText( concatenated );
3166 mLineEdit->setText( tr(
"%n option(s) selected",
nullptr, mValue.count() ) );
3174QgsProcessingEnumCheckboxPanelWidget::QgsProcessingEnumCheckboxPanelWidget( QWidget *parent,
const QgsProcessingParameterEnum *param,
int columns )
3177 , mButtonGroup( new QButtonGroup( this ) )
3178 , mColumns( columns )
3180 mButtonGroup->setExclusive( !mParam->allowMultiple() );
3182 QGridLayout *l =
new QGridLayout();
3183 l->setContentsMargins( 0, 0, 0, 0 );
3185 int rows =
static_cast<int>( std::ceil( mParam->options().count() /
static_cast<double>( mColumns ) ) );
3186 for (
int i = 0; i < mParam->options().count(); ++i )
3188 QAbstractButton *button =
nullptr;
3189 if ( mParam->allowMultiple() )
3190 button =
new QCheckBox( mParam->options().at( i ) );
3192 button =
new QRadioButton( mParam->options().at( i ) );
3194 connect( button, &QAbstractButton::toggled,
this, [
this] {
3195 if ( !mBlockChangedSignal )
3199 mButtons.insert( i, button );
3201 mButtonGroup->addButton( button, i );
3202 l->addWidget( button, i % rows, i / rows );
3204 l->addItem(
new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, mColumns );
3207 if ( mParam->allowMultiple() )
3209 setContextMenuPolicy( Qt::CustomContextMenu );
3210 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsProcessingEnumCheckboxPanelWidget::showPopupMenu );
3214QVariant QgsProcessingEnumCheckboxPanelWidget::value()
const
3216 if ( mParam->allowMultiple() )
3219 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3221 if ( it.value()->isChecked() )
3222 value.append( mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key() );
3228 if ( mParam->usesStaticStrings() )
3229 return mButtonGroup->checkedId() >= 0 ? mParam->options().at( mButtonGroup->checkedId() ) : QVariant();
3231 return mButtonGroup->checkedId() >= 0 ? mButtonGroup->checkedId() : QVariant();
3235void QgsProcessingEnumCheckboxPanelWidget::setValue(
const QVariant &value )
3237 mBlockChangedSignal =
true;
3238 if ( mParam->allowMultiple() )
3240 QVariantList selected;
3241 if ( value.isValid() )
3242 selected = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
3243 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3245 QVariant v = mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key();
3246 it.value()->setChecked( selected.contains( v ) );
3252 if ( v.userType() == QMetaType::Type::QVariantList )
3253 v = v.toList().value( 0 );
3255 v = mParam->usesStaticStrings() ?
static_cast< int >( mParam->options().indexOf( v.toString() ) ) : v;
3256 if ( mButtons.contains( v ) )
3257 mButtons.value( v )->setChecked(
true );
3259 mBlockChangedSignal =
false;
3263void QgsProcessingEnumCheckboxPanelWidget::showPopupMenu()
3266 QAction *selectAllAction =
new QAction( tr(
"Select All" ), &popupMenu );
3267 connect( selectAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::selectAll );
3268 QAction *clearAllAction =
new QAction( tr(
"Clear Selection" ), &popupMenu );
3269 connect( clearAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::deselectAll );
3270 popupMenu.addAction( selectAllAction );
3271 popupMenu.addAction( clearAllAction );
3272 popupMenu.exec( QCursor::pos() );
3275void QgsProcessingEnumCheckboxPanelWidget::selectAll()
3277 mBlockChangedSignal =
true;
3278 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3279 it.value()->setChecked(
true );
3280 mBlockChangedSignal =
false;
3284void QgsProcessingEnumCheckboxPanelWidget::deselectAll()
3286 mBlockChangedSignal =
true;
3287 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3288 it.value()->setChecked(
false );
3289 mBlockChangedSignal =
false;
3298QgsProcessingEnumParameterDefinitionWidget::QgsProcessingEnumParameterDefinitionWidget(
3303 QVBoxLayout *vlayout =
new QVBoxLayout();
3304 vlayout->setContentsMargins( 0, 0, 0, 0 );
3306 mEnumWidget =
new QgsProcessingEnumModelerWidget();
3309 mEnumWidget->setAllowMultiple( enumParam->allowMultiple() );
3310 mEnumWidget->setOptions( enumParam->options() );
3311 mEnumWidget->setDefaultOptions( enumParam->defaultValueForGui() );
3313 vlayout->addWidget( mEnumWidget );
3317 setLayout( vlayout );
3322 auto param = std::make_unique<QgsProcessingParameterEnum>( name, description, mEnumWidget->options(), mEnumWidget->allowMultiple(), mEnumWidget->defaultOptions() );
3324 return param.release();
3332QWidget *QgsProcessingEnumWidgetWrapper::createWidget()
3343 if ( expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"useCheckBoxes"_s,
false ).toBool() )
3345 const int columns = expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"columns"_s, 2 ).toInt();
3346 mCheckboxPanel =
new QgsProcessingEnumCheckboxPanelWidget(
nullptr, expParam, columns );
3347 mCheckboxPanel->setToolTip( parameterDefinition()->toolTip() );
3348 connect( mCheckboxPanel, &QgsProcessingEnumCheckboxPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
3349 return mCheckboxPanel;
3358 mPanel =
new QgsProcessingEnumPanelWidget(
nullptr, expParam );
3359 mPanel->setToolTip( parameterDefinition()->toolTip() );
3360 connect( mPanel, &QgsProcessingEnumPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
3365 mComboBox =
new QComboBox();
3368 mComboBox->addItem( tr(
"[Not selected]" ), QVariant() );
3369 const QStringList options = expParam->
options();
3370 const QVariantList iconList = expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"icons"_s ).toList();
3371 for (
int i = 0; i < options.count(); ++i )
3373 const QIcon icon = iconList.value( i ).value<QIcon>();
3376 mComboBox->addItem( icon, options.at( i ), options.at( i ) );
3378 mComboBox->addItem( icon, options.at( i ), i );
3381 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3382 mComboBox->setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon );
3383 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
3391void QgsProcessingEnumWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3395 if ( !value.isValid() )
3396 mComboBox->setCurrentIndex( mComboBox->findData( QVariant() ) );
3402 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
3407 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
3411 else if ( mPanel || mCheckboxPanel )
3414 if ( value.isValid() )
3419 opts.reserve( v.size() );
3420 for ( QString i : v )
3426 opts.reserve( v.size() );
3432 mPanel->setValue( opts );
3433 else if ( mCheckboxPanel )
3434 mCheckboxPanel->setValue( opts );
3438QVariant QgsProcessingEnumWidgetWrapper::widgetValue()
const
3441 return mComboBox->currentData();
3443 return mPanel->value();
3444 else if ( mCheckboxPanel )
3445 return mCheckboxPanel->value();
3450QString QgsProcessingEnumWidgetWrapper::modelerExpressionFormatString()
const
3452 return tr(
"selected option index (starting from 0), array of indices, or comma separated string of options (e.g. '1,3')" );
3455QString QgsProcessingEnumWidgetWrapper::parameterType()
const
3462 return new QgsProcessingEnumWidgetWrapper( parameter, type );
3469 return new QgsProcessingEnumParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3480QWidget *QgsProcessingLayoutWidgetWrapper::createWidget()
3492 mComboBox =
new QgsLayoutComboBox(
nullptr, widgetContext().project() ? widgetContext().project()->layoutManager() :
nullptr );
3494 mComboBox->setAllowEmptyLayout(
true );
3497 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3504 mPlainComboBox =
new QComboBox();
3505 mPlainComboBox->setEditable(
true );
3506 mPlainComboBox->setToolTip( tr(
"Name of an existing print layout" ) );
3507 if ( widgetContext().project() )
3511 mPlainComboBox->addItem( layout->name() );
3514 connect( mPlainComboBox, &QComboBox::currentTextChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
3515 return mPlainComboBox;
3521void QgsProcessingLayoutWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3525 if ( !value.isValid() )
3526 mComboBox->setCurrentLayout(
nullptr );
3530 mComboBox->setCurrentLayout( l );
3532 mComboBox->setCurrentLayout(
nullptr );
3535 else if ( mPlainComboBox )
3538 mPlainComboBox->setCurrentText( v );
3542QVariant QgsProcessingLayoutWidgetWrapper::widgetValue()
const
3547 return l ? l->
name() : QVariant();
3549 else if ( mPlainComboBox )
3550 return mPlainComboBox->currentText().isEmpty() ? QVariant() : mPlainComboBox->currentText();
3558 if ( mPlainComboBox && context.
project() )
3562 mPlainComboBox->addItem( layout->name() );
3566QString QgsProcessingLayoutWidgetWrapper::modelerExpressionFormatString()
const
3568 return tr(
"string representing the name of an existing print layout" );
3571QString QgsProcessingLayoutWidgetWrapper::parameterType()
const
3578 return new QgsProcessingLayoutWidgetWrapper( parameter, type );
3587QgsProcessingLayoutItemParameterDefinitionWidget::QgsProcessingLayoutItemParameterDefinitionWidget(
3592 QVBoxLayout *vlayout =
new QVBoxLayout();
3593 vlayout->setContentsMargins( 0, 0, 0, 0 );
3595 vlayout->addWidget(
new QLabel( tr(
"Parent layout" ) ) );
3597 mParentLayoutComboBox =
new QComboBox();
3598 QString initialParent;
3600 initialParent = itemParam->parentLayoutParameterName();
3602 if (
auto *lModel = widgetContext.
model() )
3605 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3606 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3610 mParentLayoutComboBox->addItem( definition->
description(), definition->
name() );
3611 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
3613 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3619 if ( mParentLayoutComboBox->count() == 0 && !initialParent.isEmpty() )
3622 mParentLayoutComboBox->addItem( initialParent, initialParent );
3623 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3626 vlayout->addWidget( mParentLayoutComboBox );
3630 setLayout( vlayout );
3634 auto param = std::make_unique<QgsProcessingParameterLayoutItem>( name, description, QVariant(), mParentLayoutComboBox->currentData().toString() );
3636 return param.release();
3644QWidget *QgsProcessingLayoutItemWidgetWrapper::createWidget()
3658 mComboBox->setAllowEmptyItem(
true );
3659 if ( layoutParam->
itemType() >= 0 )
3662 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3669 mLineEdit =
new QLineEdit();
3670 mLineEdit->setToolTip( tr(
"UUID or ID of an existing print layout item" ) );
3671 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
3678void QgsProcessingLayoutItemWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3703void QgsProcessingLayoutItemWidgetWrapper::setLayoutParameterValue(
const QVariant &value )
3709 std::unique_ptr<QgsProcessingContext> tmpContext;
3710 if ( mProcessingContextGenerator )
3711 context = mProcessingContextGenerator->processingContext();
3715 tmpContext = std::make_unique<QgsProcessingContext>();
3716 context = tmpContext.get();
3720 setLayout( layout );
3723void QgsProcessingLayoutItemWidgetWrapper::setLayout(
QgsPrintLayout *layout )
3726 mComboBox->setCurrentLayout( layout );
3729void QgsProcessingLayoutItemWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3733 if ( !value.isValid() )
3734 mComboBox->setItem(
nullptr );
3738 mComboBox->setItem( item );
3741 else if ( mLineEdit )
3744 mLineEdit->setText( v );
3748QVariant QgsProcessingLayoutItemWidgetWrapper::widgetValue()
const
3753 return i ? i->
uuid() : QVariant();
3755 else if ( mLineEdit )
3756 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3762QString QgsProcessingLayoutItemWidgetWrapper::modelerExpressionFormatString()
const
3764 return tr(
"string representing the UUID or ID of an existing print layout item" );
3767QString QgsProcessingLayoutItemWidgetWrapper::parameterType()
const
3774 return new QgsProcessingLayoutItemWidgetWrapper( parameter, type );
3781 return new QgsProcessingLayoutItemParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3788QgsProcessingPointMapTool::QgsProcessingPointMapTool(
QgsMapCanvas *canvas )
3792 mSnapIndicator = std::make_unique<QgsSnapIndicator>( canvas );
3795QgsProcessingPointMapTool::~QgsProcessingPointMapTool() =
default;
3797void QgsProcessingPointMapTool::deactivate()
3811 if ( e->button() == Qt::LeftButton )
3814 emit clicked( point );
3819void QgsProcessingPointMapTool::keyPressEvent( QKeyEvent *e )
3821 if ( e->key() == Qt::Key_Escape )
3834QgsProcessingPointPanel::QgsProcessingPointPanel( QWidget *parent )
3837 QHBoxLayout *l =
new QHBoxLayout();
3838 l->setContentsMargins( 0, 0, 0, 0 );
3840 mLineEdit->setShowClearButton(
false );
3841 l->addWidget( mLineEdit, 1 );
3842 mButton =
new QToolButton();
3843 mButton->setText( QString( QChar( 0x2026 ) ) );
3844 l->addWidget( mButton );
3847 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::changed );
3848 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::textChanged );
3849 connect( mButton, &QToolButton::clicked,
this, &QgsProcessingPointPanel::selectOnCanvas );
3850 mButton->setVisible(
false );
3853void QgsProcessingPointPanel::setMapCanvas(
QgsMapCanvas *canvas )
3856 if ( mAllowSelectOnCanvas )
3858 mButton->setVisible(
true );
3861 mTool = std::make_unique<QgsProcessingPointMapTool>( mCanvas );
3862 connect( mTool.get(), &QgsProcessingPointMapTool::clicked,
this, &QgsProcessingPointPanel::updatePoint );
3863 connect( mTool.get(), &QgsProcessingPointMapTool::complete,
this, &QgsProcessingPointPanel::pointPicked );
3867void QgsProcessingPointPanel::setAllowNull(
bool allowNull )
3869 mLineEdit->setShowClearButton( allowNull );
3872void QgsProcessingPointPanel::setShowPointOnCanvas(
bool show )
3874 if ( mShowPointOnCanvas == show )
3877 mShowPointOnCanvas = show;
3878 if ( mShowPointOnCanvas )
3884 mMapPointRubberBand.reset();
3888void QgsProcessingPointPanel::setAllowSelectOnCanvas(
bool allow )
3890 mAllowSelectOnCanvas = allow;
3891 mButton->setVisible( mAllowSelectOnCanvas &&
static_cast<bool>( mTool ) );
3894QVariant QgsProcessingPointPanel::value()
const
3896 return mLineEdit->showClearButton() && mLineEdit->text().trimmed().isEmpty() ? QVariant() : QVariant( mLineEdit->text() );
3899void QgsProcessingPointPanel::clear()
3907 QString newText = u
"%1,%2"_s.arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) );
3910 if ( mCrs.isValid() )
3912 newText += u
" [%1]"_s.arg( mCrs.authid() );
3914 mLineEdit->setText( newText );
3918void QgsProcessingPointPanel::showEvent( QShowEvent * )
3923 if ( QWidget *parentWindow = window() )
3925 setAllowSelectOnCanvas( !parentWindow->isModal() );
3931void QgsProcessingPointPanel::selectOnCanvas()
3936 mPrevTool = mCanvas->mapTool();
3937 mCanvas->setMapTool( mTool.get() );
3939 emit toggleDialogVisibility(
false );
3942void QgsProcessingPointPanel::updatePoint(
const QgsPointXY &point )
3944 setValue( point, mCanvas->mapSettings().destinationCrs() );
3947void QgsProcessingPointPanel::pointPicked()
3952 mCanvas->setMapTool( mPrevTool );
3954 emit toggleDialogVisibility(
true );
3957void QgsProcessingPointPanel::textChanged(
const QString &text )
3959 const thread_local QRegularExpression rx( u
"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
3961 const QRegularExpressionMatch match = rx.match( text );
3962 if ( match.hasMatch() )
3965 const double x = match.captured( 1 ).toDouble( &xOk );
3967 const double y = match.captured( 2 ).toDouble( &yOk );
3974 if ( pointCrs.isValid() )
3992void QgsProcessingPointPanel::updateRubberBand()
3994 if ( !mShowPointOnCanvas || !mCanvas )
3997 if ( mPoint.isEmpty() )
3999 mMapPointRubberBand.reset();
4003 if ( !mMapPointRubberBand )
4006 mMapPointRubberBand->setZValue( 1000 );
4009 const double scaleFactor = mCanvas->fontMetrics().xHeight() * .4;
4010 mMapPointRubberBand->setWidth( scaleFactor );
4011 mMapPointRubberBand->setIconSize( scaleFactor * 5 );
4013 mMapPointRubberBand->setSecondaryStrokeColor( QColor( 255, 255, 255, 100 ) );
4014 mMapPointRubberBand->setColor( QColor( 200, 0, 200 ) );
4025QgsProcessingPointParameterDefinitionWidget::QgsProcessingPointParameterDefinitionWidget(
4030 QVBoxLayout *vlayout =
new QVBoxLayout();
4031 vlayout->setContentsMargins( 0, 0, 0, 0 );
4033 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4035 mDefaultLineEdit =
new QLineEdit();
4036 mDefaultLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
4037 mDefaultLineEdit->setPlaceholderText( tr(
"Point as 'x,y'" ) );
4041 mDefaultLineEdit->setText( u
"%1,%2"_s.arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) ) );
4044 vlayout->addWidget( mDefaultLineEdit );
4048 setLayout( vlayout );
4053 auto param = std::make_unique<QgsProcessingParameterPoint>( name, description, mDefaultLineEdit->text() );
4055 return param.release();
4062QWidget *QgsProcessingPointWidgetWrapper::createWidget()
4073 mPanel =
new QgsProcessingPointPanel(
nullptr );
4074 if ( widgetContext().mapCanvas() )
4075 mPanel->setMapCanvas( widgetContext().mapCanvas() );
4078 mPanel->setAllowNull(
true );
4081 mPanel->setShowPointOnCanvas(
true );
4083 mPanel->setToolTip( parameterDefinition()->toolTip() );
4085 connect( mPanel, &QgsProcessingPointPanel::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
4088 setDialog( mDialog );
4094 mLineEdit =
new QLineEdit();
4095 mLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
4096 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
4107 mPanel->setMapCanvas( context.
mapCanvas() );
4110void QgsProcessingPointWidgetWrapper::setDialog( QDialog *dialog )
4115 connect( mPanel, &QgsProcessingPointPanel::toggleDialogVisibility, mDialog, [
this](
bool visible ) {
4117 mDialog->showMinimized();
4120 mDialog->showNormal();
4122 mDialog->activateWindow();
4129void QgsProcessingPointWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4133 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) )
4139 mPanel->setValue( p, crs );
4142 else if ( mLineEdit )
4145 mLineEdit->setText( v );
4149QVariant QgsProcessingPointWidgetWrapper::widgetValue()
const
4153 return mPanel->value();
4155 else if ( mLineEdit )
4156 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
4161QString QgsProcessingPointWidgetWrapper::modelerExpressionFormatString()
const
4163 return tr(
"string of the format 'x,y' or a geometry value (centroid is used)" );
4166QString QgsProcessingPointWidgetWrapper::parameterType()
const
4173 return new QgsProcessingPointWidgetWrapper( parameter, type );
4180 return new QgsProcessingPointParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4189QgsProcessingGeometryParameterDefinitionWidget::QgsProcessingGeometryParameterDefinitionWidget(
4194 QVBoxLayout *vlayout =
new QVBoxLayout();
4195 vlayout->setContentsMargins( 0, 0, 0, 0 );
4197 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4209 vlayout->addWidget( mGeometryWidget );
4213 setLayout( vlayout );
4219 auto param = std::make_unique<QgsProcessingParameterGeometry>( name, description, geometry.
isEmpty() ? QVariant() : geometry.
asWkt() );
4221 return param.release();
4228QWidget *QgsProcessingGeometryWidgetWrapper::createWidget()
4237 mGeometryWidget->setToolTip( parameterDefinition()->toolTip() );
4239 return mGeometryWidget;
4245void QgsProcessingGeometryWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4247 if ( mGeometryWidget )
4256 mGeometryWidget->clearGeometry();
4261QVariant QgsProcessingGeometryWidgetWrapper::widgetValue()
const
4263 if ( mGeometryWidget )
4266 return geometry.
isEmpty() ? QVariant() : geometry.asWkt();
4274QString QgsProcessingGeometryWidgetWrapper::modelerExpressionFormatString()
const
4276 return tr(
"string in the Well-Known-Text format or a geometry value" );
4279QString QgsProcessingGeometryWidgetWrapper::parameterType()
const
4286 return new QgsProcessingGeometryWidgetWrapper( parameter, type );
4293 return new QgsProcessingGeometryParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4302QgsProcessingColorParameterDefinitionWidget::QgsProcessingColorParameterDefinitionWidget(
4307 QVBoxLayout *vlayout =
new QVBoxLayout();
4308 vlayout->setContentsMargins( 0, 0, 0, 0 );
4310 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4313 mDefaultColorButton->setShowNull(
true );
4314 mAllowOpacity =
new QCheckBox( tr(
"Allow opacity control" ) );
4320 mDefaultColorButton->setToNull();
4322 mDefaultColorButton->setColor(
c );
4323 mAllowOpacity->setChecked( colorParam->opacityEnabled() );
4327 mDefaultColorButton->setToNull();
4328 mAllowOpacity->setChecked(
true );
4334 vlayout->addWidget( mDefaultColorButton );
4335 vlayout->addWidget( mAllowOpacity );
4336 setLayout( vlayout );
4341 auto param = std::make_unique<QgsProcessingParameterColor>( name, description, mDefaultColorButton->color(), mAllowOpacity->isChecked() );
4343 return param.release();
4350QWidget *QgsProcessingColorWidgetWrapper::createWidget()
4363 mColorButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
4366 mColorButton->setShowNull(
true );
4369 mColorButton->setToolTip( parameterDefinition()->toolTip() );
4370 mColorButton->setColorDialogTitle( parameterDefinition()->description() );
4378 return mColorButton;
4384void QgsProcessingColorWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4388 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) || ( value.userType() == QMetaType::Type::QColor && !value.value<QColor>().isValid() ) )
4389 mColorButton->setToNull();
4393 if ( !
c.isValid() && mColorButton->showNull() )
4394 mColorButton->setToNull();
4396 mColorButton->setColor(
c );
4401QVariant QgsProcessingColorWidgetWrapper::widgetValue()
const
4404 return mColorButton->isNull() ? QVariant() : mColorButton->color();
4409QString QgsProcessingColorWidgetWrapper::modelerExpressionFormatString()
const
4411 return tr(
"color style string, e.g. #ff0000 or 255,0,0" );
4414QString QgsProcessingColorWidgetWrapper::parameterType()
const
4421 return new QgsProcessingColorWidgetWrapper( parameter, type );
4428 return new QgsProcessingColorParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4436QgsProcessingCoordinateOperationParameterDefinitionWidget::QgsProcessingCoordinateOperationParameterDefinitionWidget(
4441 QVBoxLayout *vlayout =
new QVBoxLayout();
4442 vlayout->setContentsMargins( 0, 0, 0, 0 );
4444 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4446 mDefaultLineEdit =
new QLineEdit();
4449 vlayout->addWidget( mDefaultLineEdit );
4453 mSourceParamComboBox =
new QComboBox();
4454 mDestParamComboBox =
new QComboBox();
4455 QString initialSource;
4456 QString initialDest;
4461 initialSource = itemParam->sourceCrsParameterName();
4462 initialDest = itemParam->destinationCrsParameterName();
4467 mSourceParamComboBox->addItem( QString(), QString() );
4468 mDestParamComboBox->addItem( QString(), QString() );
4469 if (
auto *lModel = widgetContext.
model() )
4472 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4473 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4475 if ( definition && it->parameterName() == definition->
name() )
4479 mSourceParamComboBox->addItem( it->parameterName(), it->parameterName() );
4480 mDestParamComboBox->addItem( it->parameterName(), it->parameterName() );
4481 if ( !initialSource.isEmpty() && initialSource == it->parameterName() )
4483 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
4485 if ( !initialDest.isEmpty() && initialDest == it->parameterName() )
4487 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
4492 if ( mSourceParamComboBox->count() == 1 && !initialSource.isEmpty() )
4495 mSourceParamComboBox->addItem( initialSource, initialSource );
4496 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
4498 if ( mDestParamComboBox->count() == 1 && !initialDest.isEmpty() )
4501 mDestParamComboBox->addItem( initialDest, initialDest );
4502 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
4505 vlayout->addWidget(
new QLabel( tr(
"Source CRS parameter" ) ) );
4506 vlayout->addWidget( mSourceParamComboBox );
4507 vlayout->addWidget(
new QLabel( tr(
"Destination CRS parameter" ) ) );
4508 vlayout->addWidget( mDestParamComboBox );
4515 mStaticSourceWidget->setCrs( sourceCrs );
4518 mStaticDestWidget->setCrs( destCrs );
4520 vlayout->addWidget(
new QLabel( tr(
"Static source CRS" ) ) );
4521 vlayout->addWidget( mStaticSourceWidget );
4522 vlayout->addWidget(
new QLabel( tr(
"Static destination CRS" ) ) );
4523 vlayout->addWidget( mStaticDestWidget );
4528 setLayout( vlayout );
4533 auto param = std::make_unique<QgsProcessingParameterCoordinateOperation>(
4536 mDefaultLineEdit->text(),
4537 mSourceParamComboBox->currentText(),
4538 mDestParamComboBox->currentText(),
4539 mStaticSourceWidget->crs().isValid() ? QVariant::fromValue( mStaticSourceWidget->crs() ) : QVariant(),
4540 mStaticDestWidget->crs().isValid() ? QVariant::fromValue( mStaticDestWidget->crs() ) : QVariant()
4543 return param.release();
4550QWidget *QgsProcessingCoordinateOperationWidgetWrapper::createWidget()
4564 mOperationWidget->setShowMakeDefault(
false );
4565 mOperationWidget->setShowFallbackOption(
false );
4566 mOperationWidget->setToolTip( parameterDefinition()->toolTip() );
4567 mOperationWidget->setSourceCrs( mSourceCrs );
4568 mOperationWidget->setDestinationCrs( mDestCrs );
4569 mOperationWidget->setMapCanvas( mCanvas );
4574 mOperationWidget->setSelectedOperation( deets );
4579 return mOperationWidget;
4585 mLineEdit =
new QLineEdit();
4586 QHBoxLayout *layout =
new QHBoxLayout();
4587 layout->addWidget( mLineEdit, 1 );
4588 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
4590 QToolButton *button =
new QToolButton();
4591 button->setText( QString( QChar( 0x2026 ) ) );
4592 connect( button, &QToolButton::clicked,
this, [
this, button] {
4593 QgsDatumTransformDialog dlg( mSourceCrs, mDestCrs,
false,
false,
false, qMakePair( -1, -1 ), button, Qt::WindowFlags(), mLineEdit->text(), mCanvas );
4596 mLineEdit->setText( dlg.selectedDatumTransform().proj );
4597 emit widgetValueHasChanged(
this );
4600 layout->addWidget( button );
4602 QWidget *w =
new QWidget();
4603 layout->setContentsMargins( 0, 0, 0, 0 );
4604 w->setLayout( layout );
4611void QgsProcessingCoordinateOperationWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
4643 if ( mOperationWidget )
4644 mOperationWidget->setMapCanvas( context.
mapCanvas() );
4647void QgsProcessingCoordinateOperationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
4649 if ( mOperationWidget )
4651 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString ) )
4654 deets.
proj = value.toString();
4655 mOperationWidget->setSelectedOperation( deets );
4660 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString ) )
4662 mLineEdit->setText( value.toString() );
4667QVariant QgsProcessingCoordinateOperationWidgetWrapper::widgetValue()
const
4669 if ( mOperationWidget )
4670 return mOperationWidget->selectedOperation().proj;
4671 else if ( mLineEdit )
4672 return mLineEdit->text();
4677QString QgsProcessingCoordinateOperationWidgetWrapper::modelerExpressionFormatString()
const
4679 return tr(
"Proj coordinate operation string, e.g. '+proj=pipeline +step +inv...'" );
4682void QgsProcessingCoordinateOperationWidgetWrapper::setSourceCrsParameterValue(
const QVariant &value )
4685 std::unique_ptr<QgsProcessingContext> tmpContext;
4686 if ( mProcessingContextGenerator )
4687 context = mProcessingContextGenerator->processingContext();
4691 tmpContext = std::make_unique<QgsProcessingContext>();
4692 context = tmpContext.get();
4696 if ( mOperationWidget )
4698 mOperationWidget->setSourceCrs( mSourceCrs );
4699 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4703void QgsProcessingCoordinateOperationWidgetWrapper::setDestinationCrsParameterValue(
const QVariant &value )
4706 std::unique_ptr<QgsProcessingContext> tmpContext;
4707 if ( mProcessingContextGenerator )
4708 context = mProcessingContextGenerator->processingContext();
4712 tmpContext = std::make_unique<QgsProcessingContext>();
4713 context = tmpContext.get();
4717 if ( mOperationWidget )
4719 mOperationWidget->setDestinationCrs( mDestCrs );
4720 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4724QString QgsProcessingCoordinateOperationWidgetWrapper::parameterType()
const
4731 return new QgsProcessingCoordinateOperationWidgetWrapper( parameter, type );
4738 return new QgsProcessingCoordinateOperationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4750 QHBoxLayout *hl =
new QHBoxLayout();
4751 hl->setContentsMargins( 0, 0, 0, 0 );
4753 mLineEdit =
new QLineEdit();
4754 mLineEdit->setEnabled(
false );
4755 hl->addWidget( mLineEdit, 1 );
4757 mToolButton =
new QToolButton();
4758 mToolButton->setText( QString( QChar( 0x2026 ) ) );
4759 hl->addWidget( mToolButton );
4765 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4768 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingFieldPanelWidget::showDialog );
4771void QgsProcessingFieldPanelWidget::setFields(
const QgsFields &fields )
4777 QVariantList availableFields;
4778 for (
const QgsField &field : std::as_const( mFields ) )
4780 availableFields << field.name();
4782 QList<QVariant>::iterator it = std::remove_if( mValue.begin(), mValue.end(), [&availableFields](
const QVariant &value ) { return !availableFields.contains( value ); } );
4783 mValue.erase( it, mValue.end() );
4785 updateSummaryText();
4789void QgsProcessingFieldPanelWidget::setValue(
const QVariant &value )
4791 if ( value.isValid() )
4792 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
4796 updateSummaryText();
4800void QgsProcessingFieldPanelWidget::showDialog()
4802 QVariantList availableOptions;
4803 availableOptions.reserve( mFields.size() );
4804 for (
const QgsField &field : std::as_const( mFields ) )
4806 availableOptions << field.name();
4812 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
4813 widget->setPanelTitle( mParam->description() );
4815 widget->setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
4817 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
4823 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
4825 dlg.setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
4828 setValue( dlg.selectedOptions() );
4833void QgsProcessingFieldPanelWidget::updateSummaryText()
4838 if ( mValue.empty() )
4840 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4845 values.reserve( mValue.size() );
4846 for (
const QVariant &val : std::as_const( mValue ) )
4848 values << val.toString();
4851 const QString concatenated = values.join( tr(
"," ) );
4852 if ( concatenated.length() < 100 )
4853 mLineEdit->setText( concatenated );
4855 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, mValue.count() ) );
4864QgsProcessingFieldParameterDefinitionWidget::QgsProcessingFieldParameterDefinitionWidget(
4869 QVBoxLayout *vlayout =
new QVBoxLayout();
4870 vlayout->setContentsMargins( 0, 0, 0, 0 );
4872 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
4873 mParentLayerComboBox =
new QComboBox();
4875 QString initialParent;
4877 initialParent = fieldParam->parentLayerParameterName();
4879 if (
auto *lModel = widgetContext.
model() )
4882 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4883 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4887 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4888 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4890 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4895 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4896 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4898 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 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
4918 mParentLayerComboBox->addItem( initialParent, initialParent );
4919 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4922 vlayout->addWidget( mParentLayerComboBox );
4925 vlayout->addWidget(
new QLabel( tr(
"Allowed data type" ) ) );
4926 mDataTypeComboBox =
new QComboBox();
4934 mDataTypeComboBox->setCurrentIndex( mDataTypeComboBox->findData(
static_cast<int>( fieldParam->dataType() ) ) );
4936 vlayout->addWidget( mDataTypeComboBox );
4939 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple fields" ) );
4941 mAllowMultipleCheckBox->setChecked( fieldParam->allowMultiple() );
4943 vlayout->addWidget( mAllowMultipleCheckBox );
4948 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all fields by default" ) );
4949 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
4951 mDefaultToAllCheckBox->setChecked( fieldParam->defaultToAllFields() );
4953 vlayout->addWidget( mDefaultToAllCheckBox );
4956 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [
this] { mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() ); } );
4958 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4960 mDefaultLineEdit =
new QLineEdit();
4961 mDefaultLineEdit->setToolTip( tr(
"Default field name, or ; separated list of field names for multiple field parameters" ) );
4965 mDefaultLineEdit->setText( fields.join(
';' ) );
4967 vlayout->addWidget( mDefaultLineEdit );
4971 setLayout( vlayout );
4978 QVariant defaultValue;
4979 if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
4981 defaultValue = mDefaultLineEdit->text();
4983 auto param = std::make_unique<
4984 QgsProcessingParameterField>( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), dataType, mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
4986 return param.release();
4993QWidget *QgsProcessingFieldWidgetWrapper::createWidget()
5006 mPanel =
new QgsProcessingFieldPanelWidget(
nullptr, fieldParam );
5007 mPanel->setToolTip( parameterDefinition()->toolTip() );
5008 connect( mPanel, &QgsProcessingFieldPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
5027 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5035 mLineEdit =
new QLineEdit();
5036 mLineEdit->setToolTip( QObject::tr(
"Name of field (separate field names with ; for multiple field parameters)" ) );
5037 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
5044void QgsProcessingFieldWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5056 setParentLayerWrapperValue( wrapper );
5073 std::unique_ptr<QgsProcessingContext> tmpContext;
5074 if ( mProcessingContextGenerator )
5075 context = mProcessingContextGenerator->processingContext();
5079 tmpContext = std::make_unique<QgsProcessingContext>();
5080 context = tmpContext.get();
5085 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
5095 bool valueSet =
false;
5099 if ( layers.count() > 1 )
5101 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layers.at( 0 ) );
5103 const QList<QgsMapLayer *> remainingLayers = layers.mid( 1 );
5109 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
5110 if ( !vlayer || !vlayer->
isValid() )
5116 for (
int fieldIdx = fields.
count() - 1; fieldIdx >= 0; fieldIdx-- )
5119 fields.
remove( fieldIdx );
5124 mComboBox->setFields( fields );
5126 mPanel->setFields( filterFields( fields ) );
5132 if ( !valueSet && !layers.isEmpty() && layers.at( 0 )->isValid() )
5134 QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( layers.at( 0 ) );
5138 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
5141 mParentLayer.reset( qobject_cast<QgsVectorLayer *>( ownedLayer.release() ) );
5142 layer = mParentLayer.get();
5150 mComboBox->setLayer( layer );
5152 mPanel->setFields( filterFields( layer->
fields() ) );
5162 const QgsFields fields = source->fields();
5164 mComboBox->setFields( fields );
5166 mPanel->setFields( filterFields( fields ) );
5175 mComboBox->setLayer(
nullptr );
5179 if ( value.isValid() && widgetContext().messageBar() )
5191 val.reserve( mPanel->fields().size() );
5192 for (
const QgsField &field : mPanel->fields() )
5193 val << field.name();
5194 setWidgetValue( val, *context );
5197 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5200void QgsProcessingFieldWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5204 if ( !value.isValid() )
5205 mComboBox->setField( QString() );
5209 mComboBox->setField( v );
5215 if ( value.isValid() )
5218 opts.reserve( v.size() );
5219 for (
const QString &i : v )
5223 mPanel->setValue( opts );
5225 else if ( mLineEdit )
5231 mLineEdit->setText( v.join(
';' ) );
5240QVariant QgsProcessingFieldWidgetWrapper::widgetValue()
const
5243 return mComboBox->currentField();
5245 return mPanel->value();
5246 else if ( mLineEdit )
5251 return mLineEdit->text().split(
';' );
5254 return mLineEdit->text();
5260QString QgsProcessingFieldWidgetWrapper::modelerExpressionFormatString()
const
5262 return tr(
"selected field names as an array of names, or semicolon separated string of options (e.g. 'fid;place_name')" );
5265const QgsVectorLayer *QgsProcessingFieldWidgetWrapper::linkedVectorLayer()
const
5267 if ( mComboBox && mComboBox->layer() )
5268 return mComboBox->layer();
5273QgsFields QgsProcessingFieldWidgetWrapper::filterFields(
const QgsFields &fields )
const
5286 if ( f.isNumeric() )
5291 if ( f.type() == QMetaType::Type::QString )
5296 if ( f.type() == QMetaType::Type::QDate || f.type() == QMetaType::Type::QTime || f.type() == QMetaType::Type::QDateTime )
5301 if ( f.type() == QMetaType::Type::QByteArray )
5306 if ( f.type() == QMetaType::Type::Bool )
5315QString QgsProcessingFieldWidgetWrapper::parameterType()
const
5322 return new QgsProcessingFieldWidgetWrapper( parameter, type );
5329 return new QgsProcessingFieldParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5337QgsProcessingMapThemeParameterDefinitionWidget::QgsProcessingMapThemeParameterDefinitionWidget(
5342 QVBoxLayout *vlayout =
new QVBoxLayout();
5343 vlayout->setContentsMargins( 0, 0, 0, 0 );
5345 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5347 mDefaultComboBox =
new QComboBox();
5348 mDefaultComboBox->addItem( QString(), QVariant( -1 ) );
5351 for (
const QString &theme : mapThemes )
5355 mDefaultComboBox->setEditable(
true );
5359 if ( themeParam->defaultValueForGui().isValid() )
5362 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
5365 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
5367 vlayout->addWidget( mDefaultComboBox );
5371 setLayout( vlayout );
5376 QVariant defaultVal;
5377 if ( mDefaultComboBox->currentText().isEmpty() )
5378 defaultVal = QVariant();
5380 defaultVal = mDefaultComboBox->currentText();
5381 auto param = std::make_unique<QgsProcessingParameterMapTheme>( name, description, defaultVal );
5383 return param.release();
5391QWidget *QgsProcessingMapThemeWidgetWrapper::createWidget()
5397 mComboBox =
new QComboBox();
5400 mComboBox->addItem( tr(
"[Not selected]" ), QVariant( -1 ) );
5403 for (
const QString &theme : mapThemes )
5415 mComboBox->setEditable(
true );
5419 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5420 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
5425void QgsProcessingMapThemeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5429 if ( !value.isValid() )
5430 mComboBox->setCurrentIndex( mComboBox->findData( QVariant( -1 ) ) );
5433 if ( mComboBox->isEditable() && mComboBox->findData( v ) == -1 )
5435 const QString prev = mComboBox->currentText();
5436 mComboBox->setCurrentText( v );
5438 emit widgetValueHasChanged(
this );
5441 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
5445QVariant QgsProcessingMapThemeWidgetWrapper::widgetValue()
const
5448 return mComboBox->currentData().toInt() == -1 ? QVariant()
5449 : !mComboBox->currentData().isValid() && mComboBox->isEditable() ? mComboBox->currentText().isEmpty() ? QVariant() : QVariant( mComboBox->currentText() )
5450 : mComboBox->currentData();
5455QString QgsProcessingMapThemeWidgetWrapper::modelerExpressionFormatString()
const
5457 return tr(
"map theme as a string value (e.g. 'base maps')" );
5460QString QgsProcessingMapThemeWidgetWrapper::parameterType()
const
5467 return new QgsProcessingMapThemeWidgetWrapper( parameter, type );
5474 return new QgsProcessingMapThemeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5483QgsProcessingDateTimeParameterDefinitionWidget::QgsProcessingDateTimeParameterDefinitionWidget(
5488 QVBoxLayout *vlayout =
new QVBoxLayout();
5489 vlayout->setContentsMargins( 0, 0, 0, 0 );
5491 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
5493 mTypeComboBox =
new QComboBox();
5498 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( datetimeParam->dataType() ) ) );
5500 mTypeComboBox->setCurrentIndex( 0 );
5501 vlayout->addWidget( mTypeComboBox );
5505 setLayout( vlayout );
5510 auto param = std::make_unique<QgsProcessingParameterDateTime>( name, description );
5513 return param.release();
5521QWidget *QgsProcessingDateTimeWidgetWrapper::createWidget()
5524 if ( !dateTimeParam )
5528 switch ( dateTimeParam->
dataType() )
5532 widget = mDateTimeEdit;
5557 widget->setToolTip( parameterDefinition()->toolTip() );
5559 if ( mDateTimeEdit )
5563 else if ( mDateEdit )
5567 else if ( mTimeEdit )
5579 return new QgsProcessingDateTimeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5582void QgsProcessingDateTimeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5584 if ( mDateTimeEdit )
5588 else if ( mDateEdit )
5592 else if ( mTimeEdit )
5598QVariant QgsProcessingDateTimeWidgetWrapper::widgetValue()
const
5600 if ( mDateTimeEdit )
5601 return !mDateTimeEdit->dateTime().isNull() && mDateTimeEdit->dateTime().isValid() ? QVariant( mDateTimeEdit->dateTime() ) : QVariant();
5602 else if ( mDateEdit )
5603 return !mDateEdit->date().isNull() && mDateEdit->date().isValid() ? QVariant( mDateEdit->date() ) : QVariant();
5604 else if ( mTimeEdit )
5605 return !mTimeEdit->time().isNull() && mTimeEdit->time().isValid() ? QVariant( mTimeEdit->time() ) : QVariant();
5610QString QgsProcessingDateTimeWidgetWrapper::modelerExpressionFormatString()
const
5613 if ( dateTimeParam )
5615 switch ( dateTimeParam->
dataType() )
5618 return tr(
"datetime value, or a ISO string representation of a datetime" );
5621 return tr(
"date value, or a ISO string representation of a date" );
5624 return tr(
"time value, or a ISO string representation of a time" );
5630QString QgsProcessingDateTimeWidgetWrapper::parameterType()
const
5637 return new QgsProcessingDateTimeWidgetWrapper( parameter, type );
5645QgsProcessingProviderConnectionParameterDefinitionWidget::QgsProcessingProviderConnectionParameterDefinitionWidget(
5652 QVBoxLayout *vlayout =
new QVBoxLayout();
5653 vlayout->setContentsMargins( 0, 0, 0, 0 );
5655 vlayout->addWidget(
new QLabel( tr(
"Provider" ) ) );
5656 mProviderComboBox =
new QComboBox();
5657 mProviderComboBox->addItem( QObject::tr(
"Postgres" ), u
"postgres"_s );
5658 mProviderComboBox->addItem( QObject::tr(
"GeoPackage" ), u
"ogr"_s );
5659 mProviderComboBox->addItem( QObject::tr(
"Spatialite" ), u
"spatialite"_s );
5661 vlayout->addWidget( mProviderComboBox );
5663 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5665 mDefaultEdit =
new QLineEdit();
5666 vlayout->addWidget( mDefaultEdit );
5667 setLayout( vlayout );
5669 if ( connectionParam )
5671 mProviderComboBox->setCurrentIndex( mProviderComboBox->findData( connectionParam->
providerId() ) );
5681 QVariant defaultVal;
5682 if ( mDefaultEdit->text().isEmpty() )
5683 defaultVal = QVariant();
5685 defaultVal = mDefaultEdit->text();
5686 auto param = std::make_unique<QgsProcessingParameterProviderConnection>( name, description, mProviderComboBox->currentData().toString(), defaultVal );
5688 return param.release();
5696QWidget *QgsProcessingProviderConnectionWidgetWrapper::createWidget()
5699 if ( !connectionParam )
5704 mProviderComboBox->setAllowEmptyConnection(
true );
5712 mProviderComboBox->setEditable(
true );
5716 mProviderComboBox->setToolTip( parameterDefinition()->toolTip() );
5717 connect( mProviderComboBox, &QgsProviderConnectionComboBox::currentTextChanged,
this, [
this](
const QString & ) {
5718 if ( mBlockSignals )
5721 emit widgetValueHasChanged(
this );
5724 return mProviderComboBox;
5731 return new QgsProcessingProviderConnectionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5734void QgsProcessingProviderConnectionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5738 if ( !value.isValid() )
5739 mProviderComboBox->setCurrentIndex( -1 );
5742 if ( mProviderComboBox->isEditable() )
5744 const QString prev = mProviderComboBox->currentText();
5746 mProviderComboBox->setConnection( v );
5747 mProviderComboBox->setCurrentText( v );
5751 emit widgetValueHasChanged(
this );
5754 mProviderComboBox->setConnection( v );
5758QVariant QgsProcessingProviderConnectionWidgetWrapper::widgetValue()
const
5760 if ( mProviderComboBox )
5761 if ( mProviderComboBox->isEditable() )
5762 return mProviderComboBox->currentText().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentText() );
5764 return mProviderComboBox->currentConnection().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentConnection() );
5769QString QgsProcessingProviderConnectionWidgetWrapper::modelerExpressionFormatString()
const
5771 return tr(
"connection name as a string value" );
5774QString QgsProcessingProviderConnectionWidgetWrapper::parameterType()
const
5781 return new QgsProcessingProviderConnectionWidgetWrapper( parameter, type );
5789QgsProcessingDatabaseSchemaParameterDefinitionWidget::QgsProcessingDatabaseSchemaParameterDefinitionWidget(
5796 QVBoxLayout *vlayout =
new QVBoxLayout();
5797 vlayout->setContentsMargins( 0, 0, 0, 0 );
5799 mConnectionParamComboBox =
new QComboBox();
5800 QString initialConnection;
5806 if (
auto *lModel = widgetContext.
model() )
5809 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
5810 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
5812 if ( definition && it->parameterName() == definition->
name() )
5818 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
5819 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5821 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5826 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
5829 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
5830 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5833 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
5834 vlayout->addWidget( mConnectionParamComboBox );
5838 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5840 mDefaultEdit =
new QLineEdit();
5841 vlayout->addWidget( mDefaultEdit );
5842 setLayout( vlayout );
5853 QVariant defaultVal;
5854 if ( mDefaultEdit->text().isEmpty() )
5855 defaultVal = QVariant();
5857 defaultVal = mDefaultEdit->text();
5858 auto param = std::make_unique<QgsProcessingParameterDatabaseSchema>( name, description, mConnectionParamComboBox->currentData().toString(), defaultVal );
5860 return param.release();
5868QWidget *QgsProcessingDatabaseSchemaWidgetWrapper::createWidget()
5876 mSchemaComboBox->setAllowEmptySchema(
true );
5884 mSchemaComboBox->comboBox()->setEditable(
true );
5888 mSchemaComboBox->setToolTip( parameterDefinition()->toolTip() );
5889 connect( mSchemaComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [
this](
const QString & ) {
5890 if ( mBlockSignals )
5893 emit widgetValueHasChanged( this );
5896 return mSchemaComboBox;
5903 return new QgsProcessingDatabaseSchemaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5910 std::unique_ptr<QgsProcessingContext> tmpContext;
5911 if ( mProcessingContextGenerator )
5912 context = mProcessingContextGenerator->processingContext();
5916 tmpContext = std::make_unique<QgsProcessingContext>();
5917 context = tmpContext.get();
5923 if ( mSchemaComboBox )
5924 mSchemaComboBox->setConnectionName( connection, qgis::down_cast<const QgsProcessingParameterProviderConnection *>( parentWrapper->
parameterDefinition() )->providerId() );
5928 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5931void QgsProcessingDatabaseSchemaWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5935 if ( !value.isValid() )
5936 mSchemaComboBox->comboBox()->setCurrentIndex( -1 );
5939 if ( mSchemaComboBox->comboBox()->isEditable() )
5941 const QString prev = mSchemaComboBox->comboBox()->currentText();
5943 mSchemaComboBox->setSchema( v );
5944 mSchemaComboBox->comboBox()->setCurrentText( v );
5948 emit widgetValueHasChanged(
this );
5951 mSchemaComboBox->setSchema( v );
5955QVariant QgsProcessingDatabaseSchemaWidgetWrapper::widgetValue()
const
5957 if ( mSchemaComboBox )
5958 if ( mSchemaComboBox->comboBox()->isEditable() )
5959 return mSchemaComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->comboBox()->currentText() );
5961 return mSchemaComboBox->currentSchema().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->currentSchema() );
5966QString QgsProcessingDatabaseSchemaWidgetWrapper::modelerExpressionFormatString()
const
5968 return tr(
"database schema name as a string value" );
5971QString QgsProcessingDatabaseSchemaWidgetWrapper::parameterType()
const
5978 return new QgsProcessingDatabaseSchemaWidgetWrapper( parameter, type );
5981void QgsProcessingDatabaseSchemaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5993 setParentConnectionWrapperValue( wrapper );
6011QgsProcessingDatabaseTableParameterDefinitionWidget::QgsProcessingDatabaseTableParameterDefinitionWidget(
6018 QVBoxLayout *vlayout =
new QVBoxLayout();
6019 vlayout->setContentsMargins( 0, 0, 0, 0 );
6021 mConnectionParamComboBox =
new QComboBox();
6022 mSchemaParamComboBox =
new QComboBox();
6023 QString initialConnection;
6024 QString initialSchema;
6031 if (
auto *lModel = widgetContext.
model() )
6034 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6035 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6037 if ( definition && it->parameterName() == definition->
name() )
6042 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
6043 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
6045 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
6050 mSchemaParamComboBox->addItem( it->parameterName(), it->parameterName() );
6051 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
6053 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
6059 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
6062 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
6063 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
6066 if ( mSchemaParamComboBox->count() == 0 && !initialSchema.isEmpty() )
6069 mSchemaParamComboBox->addItem( initialSchema, initialSchema );
6070 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
6073 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
6074 vlayout->addWidget( mConnectionParamComboBox );
6076 vlayout->addWidget(
new QLabel( tr(
"Database schema parameter" ) ) );
6077 vlayout->addWidget( mSchemaParamComboBox );
6082 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6084 mDefaultEdit =
new QLineEdit();
6085 vlayout->addWidget( mDefaultEdit );
6086 setLayout( vlayout );
6097 QVariant defaultVal;
6098 if ( mDefaultEdit->text().isEmpty() )
6099 defaultVal = QVariant();
6101 defaultVal = mDefaultEdit->text();
6102 auto param = std::make_unique<QgsProcessingParameterDatabaseTable>( name, description, mConnectionParamComboBox->currentData().toString(), mSchemaParamComboBox->currentData().toString(), defaultVal );
6104 return param.release();
6112QWidget *QgsProcessingDatabaseTableWidgetWrapper::createWidget()
6120 mTableComboBox->setAllowEmptyTable(
true );
6123 mTableComboBox->comboBox()->setEditable(
true );
6125 mTableComboBox->setToolTip( parameterDefinition()->toolTip() );
6126 connect( mTableComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [
this](
const QString & ) {
6127 if ( mBlockSignals )
6130 emit widgetValueHasChanged( this );
6133 return mTableComboBox;
6140 return new QgsProcessingDatabaseTableParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6147 std::unique_ptr<QgsProcessingContext> tmpContext;
6148 if ( mProcessingContextGenerator )
6149 context = mProcessingContextGenerator->processingContext();
6153 tmpContext = std::make_unique<QgsProcessingContext>();
6154 context = tmpContext.get();
6159 mProvider = qgis::down_cast<const QgsProcessingParameterProviderConnection *>( parentWrapper->
parameterDefinition() )->providerId();
6160 if ( mTableComboBox && !mSchema.isEmpty() )
6162 mTableComboBox->setSchema( mSchema );
6163 mTableComboBox->setConnectionName( mConnection, mProvider );
6167 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6175 std::unique_ptr<QgsProcessingContext> tmpContext;
6176 if ( mProcessingContextGenerator )
6177 context = mProcessingContextGenerator->processingContext();
6181 tmpContext = std::make_unique<QgsProcessingContext>();
6182 context = tmpContext.get();
6188 if ( mTableComboBox && !mSchema.isEmpty() && !mConnection.isEmpty() )
6190 mTableComboBox->setSchema( mSchema );
6191 mTableComboBox->setConnectionName( mConnection, mProvider );
6193 const QgsProcessingParameterDatabaseTable *tableParam = static_cast<const QgsProcessingParameterDatabaseTable *>( parameterDefinition() );
6194 if ( tableParam->defaultValueForGui().isValid() )
6195 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6199void QgsProcessingDatabaseTableWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6203 if ( !value.isValid() )
6204 mTableComboBox->comboBox()->setCurrentIndex( -1 );
6207 if ( mTableComboBox->comboBox()->isEditable() )
6209 const QString prev = mTableComboBox->comboBox()->currentText();
6211 mTableComboBox->setTable( v );
6212 mTableComboBox->comboBox()->setCurrentText( v );
6216 emit widgetValueHasChanged(
this );
6219 mTableComboBox->setTable( v );
6223QVariant QgsProcessingDatabaseTableWidgetWrapper::widgetValue()
const
6225 if ( mTableComboBox )
6226 if ( mTableComboBox->comboBox()->isEditable() )
6227 return mTableComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mTableComboBox->comboBox()->currentText() );
6229 return mTableComboBox->currentTable().isEmpty() ? QVariant() : QVariant( mTableComboBox->currentTable() );
6234QString QgsProcessingDatabaseTableWidgetWrapper::modelerExpressionFormatString()
const
6236 return tr(
"database table name as a string value" );
6239QString QgsProcessingDatabaseTableWidgetWrapper::parameterType()
const
6246 return new QgsProcessingDatabaseTableWidgetWrapper( parameter, type );
6249void QgsProcessingDatabaseTableWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6261 setParentConnectionWrapperValue( wrapper );
6266 setParentSchemaWrapperValue( wrapper );
6283QgsProcessingExtentParameterDefinitionWidget::QgsProcessingExtentParameterDefinitionWidget(
6288 QVBoxLayout *vlayout =
new QVBoxLayout();
6289 vlayout->setContentsMargins( 0, 0, 0, 0 );
6291 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6294 mDefaultWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
6297 if ( extentParam->defaultValueForGui().isValid() )
6301 mDefaultWidget->setCurrentExtent( rect, crs );
6302 mDefaultWidget->setOutputExtentFromCurrent();
6306 mDefaultWidget->clear();
6312 vlayout->addWidget( mDefaultWidget );
6313 setLayout( vlayout );
6318 const QString defaultVal = mDefaultWidget->isValid() ? u
"%1,%2,%3,%4%5"_s.arg(
6319 QString::number( mDefaultWidget->outputExtent().xMinimum(),
'f', 9 ),
6320 QString::number( mDefaultWidget->outputExtent().xMaximum(),
'f', 9 ),
6321 QString::number( mDefaultWidget->outputExtent().yMinimum(),
'f', 9 ),
6322 QString::number( mDefaultWidget->outputExtent().yMaximum(),
'f', 9 ),
6323 mDefaultWidget->outputCrs().isValid() ? u
" [%1]"_s.arg( mDefaultWidget->outputCrs().authid() ) : QString()
6326 auto param = std::make_unique<QgsProcessingParameterExtent>( name, description, !defaultVal.isEmpty() ? QVariant( defaultVal ) : QVariant() );
6328 return param.release();
6336QWidget *QgsProcessingExtentWidgetWrapper::createWidget()
6349 if ( widgetContext().mapCanvas() )
6350 mExtentWidget->setMapCanvas( widgetContext().mapCanvas() );
6353 mExtentWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
6355 mExtentWidget->setToolTip( parameterDefinition()->toolTip() );
6360 setDialog( mDialog );
6362 return mExtentWidget;
6372 mExtentWidget->setMapCanvas( context.
mapCanvas() );
6375void QgsProcessingExtentWidgetWrapper::setDialog( QDialog *dialog )
6382 mDialog->showMinimized();
6385 mDialog->showNormal();
6387 mDialog->activateWindow();
6394void QgsProcessingExtentWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6396 if ( mExtentWidget )
6398 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) )
6399 mExtentWidget->clear();
6404 mExtentWidget->setCurrentExtent( r, crs );
6405 mExtentWidget->setOutputExtentFromUser( r, crs );
6410QVariant QgsProcessingExtentWidgetWrapper::widgetValue()
const
6412 if ( mExtentWidget )
6414 const QString val = mExtentWidget->isValid() ? u
"%1,%2,%3,%4%5"_s.arg(
6415 QString::number( mExtentWidget->outputExtent().xMinimum(),
'f', 9 ),
6416 QString::number( mExtentWidget->outputExtent().xMaximum(),
'f', 9 ),
6417 QString::number( mExtentWidget->outputExtent().yMinimum(),
'f', 9 ),
6418 QString::number( mExtentWidget->outputExtent().yMaximum(),
'f', 9 ),
6419 mExtentWidget->outputCrs().isValid() ? u
" [%1]"_s.arg( mExtentWidget->outputCrs().authid() ) : QString()
6423 return val.isEmpty() ? QVariant() : QVariant( val );
6429QString QgsProcessingExtentWidgetWrapper::modelerExpressionFormatString()
const
6431 return tr(
"string of the format 'x min,x max,y min,y max' or a geometry value (bounding box is used)" );
6434QString QgsProcessingExtentWidgetWrapper::parameterType()
const
6441 return new QgsProcessingExtentWidgetWrapper( parameter, type );
6448 return new QgsProcessingExtentParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6456QgsProcessingMapLayerParameterDefinitionWidget::QgsProcessingMapLayerParameterDefinitionWidget(
6461 QVBoxLayout *vlayout =
new QVBoxLayout();
6462 vlayout->setContentsMargins( 0, 0, 0, 0 );
6464 vlayout->addWidget(
new QLabel( tr(
"Layer type" ) ) );
6480 for (
int i : layerParam->dataTypes() )
6482 mLayerTypeComboBox->setItemCheckState( mLayerTypeComboBox->findData( i ), Qt::Checked );
6486 vlayout->addWidget( mLayerTypeComboBox );
6490 setLayout( vlayout );
6495 QList<int> dataTypes;
6496 for (
const QVariant &v : mLayerTypeComboBox->checkedItemsData() )
6497 dataTypes << v.toInt();
6499 auto param = std::make_unique<QgsProcessingParameterMapLayer>( name, description );
6500 param->setDataTypes( dataTypes );
6502 return param.release();
6509QWidget *QgsProcessingMapLayerWidgetWrapper::createWidget()
6511 mComboBox =
new QgsProcessingMapLayerComboBox( parameterDefinition(), type() );
6519 mComboBox->setEditable(
true );
6523 mComboBox->setToolTip( parameterDefinition()->toolTip() );
6525 connect( mComboBox, &QgsProcessingMapLayerComboBox::valueChanged,
this, [
this]() {
6526 if ( mBlockSignals )
6529 emit widgetValueHasChanged(
this );
6532 setWidgetContext( widgetContext() );
6541 mComboBox->setWidgetContext( context );
6546 if ( !parameterDefinition()->defaultValueForGui().isValid() )
6552void QgsProcessingMapLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6555 mComboBox->setValue( value, context );
6558QVariant QgsProcessingMapLayerWidgetWrapper::widgetValue()
const
6560 return mComboBox ? mComboBox->value() : QVariant();
6563QString QgsProcessingMapLayerWidgetWrapper::modelerExpressionFormatString()
const
6565 return tr(
"path to a map layer" );
6582QString QgsProcessingMapLayerWidgetWrapper::parameterType()
const
6589 return new QgsProcessingMapLayerWidgetWrapper( parameter, type );
6596 return new QgsProcessingMapLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6605 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6608QString QgsProcessingRasterLayerWidgetWrapper::modelerExpressionFormatString()
const
6610 return tr(
"path to a raster layer" );
6613QString QgsProcessingRasterLayerWidgetWrapper::parameterType()
const
6620 return new QgsProcessingRasterLayerWidgetWrapper( parameter, type );
6627 Q_UNUSED( context );
6628 Q_UNUSED( widgetContext );
6629 Q_UNUSED( definition );
6640QgsProcessingVectorLayerParameterDefinitionWidget::QgsProcessingVectorLayerParameterDefinitionWidget(
6645 QVBoxLayout *vlayout =
new QVBoxLayout();
6646 vlayout->setContentsMargins( 0, 0, 0, 0 );
6648 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6658 for (
int i : vectorParam->dataTypes() )
6660 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6664 vlayout->addWidget( mGeometryTypeComboBox );
6668 setLayout( vlayout );
6673 QList<int> dataTypes;
6674 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6675 dataTypes << v.toInt();
6677 auto param = std::make_unique<QgsProcessingParameterVectorLayer>( name, description, dataTypes );
6679 return param.release();
6684 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6687QString QgsProcessingVectorLayerWidgetWrapper::modelerExpressionFormatString()
const
6689 return tr(
"path to a vector layer" );
6692QString QgsProcessingVectorLayerWidgetWrapper::parameterType()
const
6699 return new QgsProcessingVectorLayerWidgetWrapper( parameter, type );
6706 return new QgsProcessingVectorLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6714QgsProcessingFeatureSourceParameterDefinitionWidget::QgsProcessingFeatureSourceParameterDefinitionWidget(
6719 QVBoxLayout *vlayout =
new QVBoxLayout();
6720 vlayout->setContentsMargins( 0, 0, 0, 0 );
6722 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6732 for (
int i : sourceParam->dataTypes() )
6734 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6742 vlayout->addWidget( mGeometryTypeComboBox );
6745 setLayout( vlayout );
6750 QList<int> dataTypes;
6751 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6752 dataTypes << v.toInt();
6754 auto param = std::make_unique<QgsProcessingParameterFeatureSource>( name, description, dataTypes );
6756 return param.release();
6760 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6763QString QgsProcessingFeatureSourceWidgetWrapper::modelerExpressionFormatString()
const
6765 return tr(
"path to a vector layer" );
6768QString QgsProcessingFeatureSourceWidgetWrapper::parameterType()
const
6775 return new QgsProcessingFeatureSourceWidgetWrapper( parameter, type );
6782 return new QgsProcessingFeatureSourceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6790 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6793QString QgsProcessingMeshLayerWidgetWrapper::modelerExpressionFormatString()
const
6795 return tr(
"path to a mesh layer" );
6798QString QgsProcessingMeshLayerWidgetWrapper::parameterType()
const
6805 return new QgsProcessingMeshLayerWidgetWrapper( parameter, type );
6812 Q_UNUSED( context );
6813 Q_UNUSED( widgetContext );
6814 Q_UNUSED( definition );
6825QgsProcessingRasterBandPanelWidget::QgsProcessingRasterBandPanelWidget( QWidget *parent,
const QgsProcessingParameterBand *param )
6829 QHBoxLayout *hl =
new QHBoxLayout();
6830 hl->setContentsMargins( 0, 0, 0, 0 );
6832 mLineEdit =
new QLineEdit();
6833 mLineEdit->setEnabled(
false );
6834 hl->addWidget( mLineEdit, 1 );
6836 mToolButton =
new QToolButton();
6837 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6838 hl->addWidget( mToolButton );
6844 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, 0 ) );
6847 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingRasterBandPanelWidget::showDialog );
6850void QgsProcessingRasterBandPanelWidget::setBands(
const QList<int> &bands )
6855void QgsProcessingRasterBandPanelWidget::setBandNames(
const QHash<int, QString> &names )
6860void QgsProcessingRasterBandPanelWidget::setValue(
const QVariant &value )
6862 if ( value.isValid() )
6863 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
6867 updateSummaryText();
6871void QgsProcessingRasterBandPanelWidget::showDialog()
6873 QVariantList availableOptions;
6874 availableOptions.reserve( mBands.size() );
6875 for (
int band : std::as_const( mBands ) )
6877 availableOptions << band;
6883 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
6884 widget->setPanelTitle( mParam->description() );
6886 widget->setValueFormatter( [
this](
const QVariant &v ) -> QString {
6887 int band = v.toInt();
6888 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6891 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
6897 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
6899 dlg.setValueFormatter( [
this](
const QVariant &v ) -> QString {
6900 int band = v.toInt();
6901 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6905 setValue( dlg.selectedOptions() );
6910void QgsProcessingRasterBandPanelWidget::updateSummaryText()
6913 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, mValue.count() ) );
6921QgsProcessingBandParameterDefinitionWidget::QgsProcessingBandParameterDefinitionWidget(
6926 QVBoxLayout *vlayout =
new QVBoxLayout();
6927 vlayout->setContentsMargins( 0, 0, 0, 0 );
6929 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6931 mDefaultLineEdit =
new QLineEdit();
6932 mDefaultLineEdit->setToolTip( tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6937 for (
int b : bands )
6939 defVal << QString::number( b );
6942 mDefaultLineEdit->setText( defVal.join(
';' ) );
6944 vlayout->addWidget( mDefaultLineEdit );
6947 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
6948 mParentLayerComboBox =
new QComboBox();
6950 QString initialParent;
6952 initialParent = bandParam->parentLayerParameterName();
6954 if (
auto *lModel = widgetContext.
model() )
6957 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6958 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6962 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
6963 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
6965 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6971 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
6974 mParentLayerComboBox->addItem( initialParent, initialParent );
6975 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6979 vlayout->addWidget( mParentLayerComboBox );
6981 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Allow multiple" ) );
6983 mAllowMultipleCheckBox->setChecked( bandParam->allowMultiple() );
6986 vlayout->addWidget( mAllowMultipleCheckBox );
6987 setLayout( vlayout );
6993 = std::make_unique<QgsProcessingParameterBand>( name, description, mDefaultLineEdit->text().split(
';' ), mParentLayerComboBox->currentData().toString(),
false, mAllowMultipleCheckBox->isChecked() );
6995 return param.release();
7002QWidget *QgsProcessingBandWidgetWrapper::createWidget()
7015 mPanel =
new QgsProcessingRasterBandPanelWidget(
nullptr, bandParam );
7016 mPanel->setToolTip( parameterDefinition()->toolTip() );
7017 connect( mPanel, &QgsProcessingRasterBandPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7025 mComboBox->setToolTip( parameterDefinition()->toolTip() );
7033 mLineEdit =
new QLineEdit();
7034 mLineEdit->setToolTip( QObject::tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
7035 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7042void QgsProcessingBandWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
7054 setParentLayerWrapperValue( wrapper );
7071 std::unique_ptr<QgsProcessingContext> tmpContext;
7072 if ( mProcessingContextGenerator )
7073 context = mProcessingContextGenerator->processingContext();
7077 tmpContext = std::make_unique<QgsProcessingContext>();
7078 context = tmpContext.get();
7084 if ( layer && layer->
isValid() )
7088 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
7091 mParentLayer.reset( qobject_cast<QgsRasterLayer *>( ownedLayer.release() ) );
7092 layer = mParentLayer.get();
7100 mComboBox->setLayer( layer );
7104 if ( provider && layer->
isValid() )
7109 QHash<int, QString> bandNames;
7110 for (
int i = 1; i <= nBands; ++i )
7115 mPanel->setBands( bands );
7116 mPanel->setBandNames( bandNames );
7123 mComboBox->setLayer(
nullptr );
7125 mPanel->setBands( QList<int>() );
7127 if ( value.isValid() && widgetContext().messageBar() )
7134 if ( parameterDefinition()->defaultValueForGui().isValid() )
7135 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
7138void QgsProcessingBandWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7142 if ( !value.isValid() )
7143 mComboBox->setBand( -1 );
7147 mComboBox->setBand( v );
7153 if ( value.isValid() )
7156 opts.reserve( v.size() );
7161 mPanel->setValue( value.isValid() ? opts : QVariant() );
7163 else if ( mLineEdit )
7170 opts.reserve( v.size() );
7172 opts << QString::number( i );
7173 mLineEdit->setText( value.isValid() && !opts.empty() ? opts.join(
';' ) : QString() );
7177 if ( value.isValid() )
7185QVariant QgsProcessingBandWidgetWrapper::widgetValue()
const
7188 return mComboBox->currentBand() == -1 ? QVariant() : mComboBox->currentBand();
7190 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
7191 else if ( mLineEdit )
7196 const QStringList parts = mLineEdit->text().split(
';', Qt::SkipEmptyParts );
7198 res.reserve( parts.count() );
7199 for (
const QString &s : parts )
7202 int band = s.toInt( &ok );
7206 return res.
isEmpty() ? QVariant() : res;
7210 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
7217QString QgsProcessingBandWidgetWrapper::modelerExpressionFormatString()
const
7219 return tr(
"selected band numbers as an array of numbers, or semicolon separated string of options (e.g. '1;3')" );
7222QString QgsProcessingBandWidgetWrapper::parameterType()
const
7229 return new QgsProcessingBandWidgetWrapper( parameter, type );
7236 return new QgsProcessingBandParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
7247 setAcceptDrops(
true );
7250void QgsProcessingMultipleLayerLineEdit::dragEnterEvent( QDragEnterEvent *event )
7252 const QStringList uris = QgsProcessingMultipleInputPanelWidget::compatibleUrisFromMimeData( mParam, event->mimeData(), {} );
7253 if ( !uris.isEmpty() )
7255 event->setDropAction( Qt::CopyAction );
7257 setHighlighted(
true );
7265void QgsProcessingMultipleLayerLineEdit::dragLeaveEvent( QDragLeaveEvent *event )
7267 QgsHighlightableLineEdit::dragLeaveEvent( event );
7269 setHighlighted(
false );
7272void QgsProcessingMultipleLayerLineEdit::dropEvent( QDropEvent *event )
7274 const QStringList uris = QgsProcessingMultipleInputPanelWidget::compatibleUrisFromMimeData( mParam, event->mimeData(), {} );
7275 if ( !uris.isEmpty() )
7277 event->setDropAction( Qt::CopyAction );
7279 QVariantList uriList;
7280 uriList.reserve( uris.size() );
7281 for (
const QString &uri : uris )
7282 uriList.append( QVariant( uri ) );
7283 emit layersDropped( uriList );
7286 setHighlighted(
false );
7297 QHBoxLayout *hl =
new QHBoxLayout();
7298 hl->setContentsMargins( 0, 0, 0, 0 );
7300 mLineEdit =
new QgsProcessingMultipleLayerLineEdit(
nullptr, param );
7301 mLineEdit->setEnabled(
true );
7302 mLineEdit->setReadOnly(
true );
7304 hl->addWidget( mLineEdit, 1 );
7305 connect( mLineEdit, &QgsProcessingMultipleLayerLineEdit::layersDropped,
this, &QgsProcessingMultipleLayerPanelWidget::setValue );
7307 mToolButton =
new QToolButton();
7308 mToolButton->setText( QString( QChar( 0x2026 ) ) );
7309 hl->addWidget( mToolButton );
7315 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, 0 ) );
7318 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingMultipleLayerPanelWidget::showDialog );
7321void QgsProcessingMultipleLayerPanelWidget::setValue(
const QVariant &value )
7323 if ( value.isValid() )
7324 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
7328 updateSummaryText();
7332void QgsProcessingMultipleLayerPanelWidget::setProject(
QgsProject *project )
7338 if ( mValue.removeAll( layerId ) )
7340 updateSummaryText();
7347void QgsProcessingMultipleLayerPanelWidget::setModel( QgsProcessingModelAlgorithm *model,
const QString &modelChildAlgorithmID )
7353 switch ( mParam->layerType() )
7361 mModelSources = model->availableSourcesForChild(
7362 modelChildAlgorithmID,
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,
7446 mModelSources = model->availableSourcesForChild(
7447 modelChildAlgorithmID,
7460 mModelSources = model->availableSourcesForChild(
7461 modelChildAlgorithmID,
7475 mModelSources = model->availableSourcesForChild(
7476 modelChildAlgorithmID,
7490 mModelSources = model->availableSourcesForChild(
7491 modelChildAlgorithmID,
7505 mModelSources = model->availableSourcesForChild(
7506 modelChildAlgorithmID,
7527void QgsProcessingMultipleLayerPanelWidget::showDialog()
7532 QgsProcessingMultipleInputPanelWidget *widget =
new QgsProcessingMultipleInputPanelWidget( mParam, mValue, mModelSources, mModel,
nullptr );
7533 widget->setPanelTitle( mParam->description() );
7534 widget->setProject( mProject );
7535 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
7541 QgsProcessingMultipleInputDialog dlg( mParam, mValue, mModelSources, mModel,
this, Qt::WindowFlags() );
7542 dlg.setProject( mProject );
7545 setValue( dlg.selectedOptions() );
7550void QgsProcessingMultipleLayerPanelWidget::updateSummaryText()
7553 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, mValue.count() ) );
7560QgsProcessingMultipleLayerParameterDefinitionWidget::QgsProcessingMultipleLayerParameterDefinitionWidget(
7565 QVBoxLayout *vlayout =
new QVBoxLayout();
7566 vlayout->setContentsMargins( 0, 0, 0, 0 );
7568 vlayout->addWidget(
new QLabel( tr(
"Allowed layer type" ) ) );
7569 mLayerTypeComboBox =
new QComboBox();
7583 mLayerTypeComboBox->setCurrentIndex( mLayerTypeComboBox->findData(
static_cast<int>( layersParam->layerType() ) ) );
7585 vlayout->addWidget( mLayerTypeComboBox );
7588 setLayout( vlayout );
7593 auto param = std::make_unique<QgsProcessingParameterMultipleLayers>( name, description,
static_cast<Qgis::ProcessingSourceType>( mLayerTypeComboBox->currentData().toInt() ) );
7595 return param.release();
7602QWidget *QgsProcessingMultipleLayerWidgetWrapper::createWidget()
7606 mPanel =
new QgsProcessingMultipleLayerPanelWidget(
nullptr, layerParam );
7607 mPanel->setToolTip( parameterDefinition()->toolTip() );
7608 mPanel->setProject( widgetContext().project() );
7610 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7611 connect( mPanel, &QgsProcessingMultipleLayerPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7620 mPanel->setProject( context.
project() );
7622 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7626void QgsProcessingMultipleLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7631 if ( value.isValid() )
7634 opts.reserve( v.size() );
7636 opts << l->source();
7639 for (
const QVariant &v : value.toList() )
7641 if ( v.userType() == qMetaTypeId<QgsProcessingModelChildParameterSource>() )
7643 const QgsProcessingModelChildParameterSource source = v.value<QgsProcessingModelChildParameterSource>();
7644 opts << QVariant::fromValue( source );
7649 mPanel->setValue( value.isValid() ? opts : QVariant() );
7653QVariant QgsProcessingMultipleLayerWidgetWrapper::widgetValue()
const
7656 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
7661QString QgsProcessingMultipleLayerWidgetWrapper::modelerExpressionFormatString()
const
7663 return tr(
"an array of layer paths, or semicolon separated string of layer paths" );
7666QString QgsProcessingMultipleLayerWidgetWrapper::parameterType()
const
7673 return new QgsProcessingMultipleLayerWidgetWrapper( parameter, type );
7680 return new QgsProcessingMultipleLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
7689 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
7692QString QgsProcessingPointCloudLayerWidgetWrapper::modelerExpressionFormatString()
const
7694 return tr(
"path to a point cloud layer" );
7697QString QgsProcessingPointCloudLayerWidgetWrapper::parameterType()
const
7704 return new QgsProcessingPointCloudLayerWidgetWrapper( parameter, type );
7711 Q_UNUSED( context );
7712 Q_UNUSED( widgetContext );
7713 Q_UNUSED( definition );
7728QString QgsProcessingAnnotationLayerWidgetWrapper::modelerExpressionFormatString()
const
7730 return tr(
"name of an annotation layer, or \"main\" for the main annotation layer" );
7733QString QgsProcessingAnnotationLayerWidgetWrapper::parameterType()
const
7740 return new QgsProcessingAnnotationLayerWidgetWrapper( parameter, type );
7747 Q_UNUSED( context );
7748 Q_UNUSED( widgetContext );
7749 Q_UNUSED( definition );
7760 if ( mWidgetContext.project() )
7761 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7765QWidget *QgsProcessingAnnotationLayerWidgetWrapper::createWidget()
7776 mComboBox->setEditable(
true );
7780 mComboBox->setToolTip( parameterDefinition()->toolTip() );
7782 if ( mWidgetContext.project() )
7783 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7786 mComboBox->setAllowEmptyLayer(
true );
7789 if ( mBlockSignals )
7792 emit widgetValueHasChanged(
this );
7795 setWidgetContext( widgetContext() );
7799void QgsProcessingAnnotationLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7805 mComboBox->setLayer(
nullptr );
7809 QVariant val = value;
7810 if ( val.userType() == qMetaTypeId<QgsProperty>() )
7822 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( val.value<QObject *>() );
7823 if ( !layer && val.userType() == QMetaType::Type::QString )
7830 mComboBox->setLayer( layer );
7835QVariant QgsProcessingAnnotationLayerWidgetWrapper::widgetValue()
const
7837 return mComboBox && mComboBox->currentLayer()
7838 ? ( mWidgetContext.project() ? ( mComboBox->currentLayer() == mWidgetContext.project()->mainAnnotationLayer() ? u
"main"_s : mComboBox->currentLayer()->id() )
7839 : mComboBox->currentLayer()->id() )
7852 QHBoxLayout *hl =
new QHBoxLayout();
7853 hl->setContentsMargins( 0, 0, 0, 0 );
7855 mLineEdit =
new QLineEdit();
7856 mLineEdit->setEnabled(
false );
7857 hl->addWidget( mLineEdit, 1 );
7859 mToolButton =
new QToolButton();
7860 mToolButton->setText( QString( QChar( 0x2026 ) ) );
7861 hl->addWidget( mToolButton );
7867 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, 0 ) );
7870 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingPointCloudAttributePanelWidget::showDialog );
7875 mAttributes = attributes;
7878void QgsProcessingPointCloudAttributePanelWidget::setValue(
const QVariant &value )
7880 if ( value.isValid() )
7881 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
7885 updateSummaryText();
7889void QgsProcessingPointCloudAttributePanelWidget::showDialog()
7891 QVariantList availableOptions;
7892 availableOptions.reserve( mAttributes.count() );
7893 const QVector<QgsPointCloudAttribute> attributes = mAttributes.attributes();
7896 availableOptions << attr.name();
7902 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
7903 widget->setPanelTitle( mParam->description() );
7905 widget->setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
7907 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
7913 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
7915 dlg.setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
7918 setValue( dlg.selectedOptions() );
7923void QgsProcessingPointCloudAttributePanelWidget::updateSummaryText()
7928 if ( mValue.empty() )
7930 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, 0 ) );
7935 values.reserve( mValue.size() );
7936 for (
const QVariant &val : std::as_const( mValue ) )
7938 values << val.toString();
7941 const QString concatenated = values.join( tr(
"," ) );
7942 if ( concatenated.length() < 100 )
7943 mLineEdit->setText( concatenated );
7945 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, mValue.count() ) );
7954QgsProcessingPointCloudAttributeParameterDefinitionWidget::QgsProcessingPointCloudAttributeParameterDefinitionWidget(
7959 QVBoxLayout *vlayout =
new QVBoxLayout();
7960 vlayout->setContentsMargins( 0, 0, 0, 0 );
7962 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
7963 mParentLayerComboBox =
new QComboBox();
7965 QString initialParent;
7967 initialParent = attrParam->parentLayerParameterName();
7969 if (
auto *lModel = widgetContext.
model() )
7972 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
7973 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
7977 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
7978 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
7980 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
7986 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
7989 mParentLayerComboBox->addItem( initialParent, initialParent );
7990 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
7993 vlayout->addWidget( mParentLayerComboBox );
7997 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple attributes" ) );
7999 mAllowMultipleCheckBox->setChecked( attrParam->allowMultiple() );
8001 vlayout->addWidget( mAllowMultipleCheckBox );
8004 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all attributes by default" ) );
8005 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
8007 mDefaultToAllCheckBox->setChecked( attrParam->defaultToAllAttributes() );
8011 vlayout->addWidget( mDefaultToAllCheckBox );
8013 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [
this] { mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() ); } );
8015 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
8017 mDefaultLineEdit =
new QLineEdit();
8018 mDefaultLineEdit->setToolTip( tr(
"Default attribute name, or ; separated list of attribute names for multiple attribute parameters" ) );
8022 mDefaultLineEdit->setText( attributes.join(
';' ) );
8024 vlayout->addWidget( mDefaultLineEdit );
8028 setLayout( vlayout );
8033 QVariant defaultValue;
8034 if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
8036 defaultValue = mDefaultLineEdit->text();
8038 auto param = std::make_unique<
8039 QgsProcessingParameterPointCloudAttribute>( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
8041 return param.release();
8048QWidget *QgsProcessingPointCloudAttributeWidgetWrapper::createWidget()
8061 mPanel =
new QgsProcessingPointCloudAttributePanelWidget(
nullptr, attrParam );
8062 mPanel->setToolTip( parameterDefinition()->toolTip() );
8063 connect( mPanel, &QgsProcessingPointCloudAttributePanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
8070 mComboBox->setToolTip( parameterDefinition()->toolTip() );
8078 mLineEdit =
new QLineEdit();
8079 mLineEdit->setToolTip( QObject::tr(
"Name of attribute (separate attribute names with ; for multiple attribute parameters)" ) );
8080 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
8087void QgsProcessingPointCloudAttributeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
8099 setParentLayerWrapperValue( wrapper );
8116 std::unique_ptr<QgsProcessingContext> tmpContext;
8117 if ( mProcessingContextGenerator )
8118 context = mProcessingContextGenerator->processingContext();
8122 tmpContext = std::make_unique<QgsProcessingContext>();
8123 context = tmpContext.get();
8129 if ( layer && layer->
isValid() )
8133 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
8136 mParentLayer.reset( qobject_cast<QgsPointCloudLayer *>( ownedLayer.release() ) );
8137 layer = mParentLayer.get();
8145 mComboBox->setLayer( layer );
8148 mPanel->setAttributes( layer->
attributes() );
8155 mComboBox->setLayer(
nullptr );
8160 if ( value.isValid() && widgetContext().messageBar() )
8171 val.reserve( mPanel->attributes().attributes().size() );
8174 setWidgetValue( val, *context );
8177 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
8180void QgsProcessingPointCloudAttributeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
8184 if ( !value.isValid() )
8185 mComboBox->setAttribute( QString() );
8189 mComboBox->setAttribute( v );
8195 if ( value.isValid() )
8198 opts.reserve( v.size() );
8199 for (
const QString &i : v )
8203 mPanel->setValue( opts );
8205 else if ( mLineEdit )
8211 mLineEdit->setText( v.join(
';' ) );
8220QVariant QgsProcessingPointCloudAttributeWidgetWrapper::widgetValue()
const
8223 return mComboBox->currentAttribute();
8225 return mPanel->value();
8226 else if ( mLineEdit )
8231 return mLineEdit->text().split(
';' );
8234 return mLineEdit->text();
8240QString QgsProcessingPointCloudAttributeWidgetWrapper::modelerExpressionFormatString()
const
8242 return tr(
"selected attribute names as an array of names, or semicolon separated string of options (e.g. 'X;Intensity')" );
8245QString QgsProcessingPointCloudAttributeWidgetWrapper::parameterType()
const
8252 return new QgsProcessingPointCloudAttributeWidgetWrapper( parameter, type );
8259 return new QgsProcessingPointCloudAttributeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
8271QWidget *QgsProcessingOutputWidgetWrapper::createWidget()
8279 mOutputWidget =
new QgsProcessingLayerOutputDestinationWidget( destParam,
false );
8280 if ( mProcessingContextGenerator )
8281 mOutputWidget->setContext( mProcessingContextGenerator->processingContext() );
8282 if ( mParametersGenerator )
8283 mOutputWidget->registerProcessingParametersGenerator( mParametersGenerator );
8284 mOutputWidget->setToolTip( parameterDefinition()->toolTip() );
8286 connect( mOutputWidget, &QgsProcessingLayerOutputDestinationWidget::destinationChanged,
this, [
this]() {
8287 if ( mBlockSignals )
8290 emit widgetValueHasChanged(
this );
8295 mOutputWidget->addOpenAfterRunningOption();
8297 return mOutputWidget;
8307void QgsProcessingOutputWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
8309 if ( mOutputWidget )
8310 mOutputWidget->setValue( value );
8313QVariant QgsProcessingOutputWidgetWrapper::widgetValue()
const
8315 if ( mOutputWidget )
8316 return mOutputWidget->value();
8321QVariantMap QgsProcessingOutputWidgetWrapper::customProperties()
const
8324 if ( mOutputWidget )
8325 res.insert( u
"OPEN_AFTER_RUNNING"_s, mOutputWidget->openAfterRunning() );
8334 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8337QString QgsProcessingFeatureSinkWidgetWrapper::parameterType()
const
8344 return new QgsProcessingFeatureSinkWidgetWrapper( parameter, type );
8347QString QgsProcessingFeatureSinkWidgetWrapper::modelerExpressionFormatString()
const
8349 return tr(
"path to layer destination" );
8357 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8360QString QgsProcessingVectorDestinationWidgetWrapper::parameterType()
const
8367 return new QgsProcessingVectorDestinationWidgetWrapper( parameter, type );
8370QString QgsProcessingVectorDestinationWidgetWrapper::modelerExpressionFormatString()
const
8372 return tr(
"path to layer destination" );
8380 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8383QString QgsProcessingRasterDestinationWidgetWrapper::parameterType()
const
8390 return new QgsProcessingRasterDestinationWidgetWrapper( parameter, type );
8393QString QgsProcessingRasterDestinationWidgetWrapper::modelerExpressionFormatString()
const
8395 return tr(
"path to layer destination" );
8403 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8406QString QgsProcessingPointCloudDestinationWidgetWrapper::parameterType()
const
8413 return new QgsProcessingPointCloudDestinationWidgetWrapper( parameter, type );
8416QString QgsProcessingPointCloudDestinationWidgetWrapper::modelerExpressionFormatString()
const
8418 return tr(
"path to layer destination" );
8426 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8429QString QgsProcessingFileDestinationWidgetWrapper::parameterType()
const
8436 return new QgsProcessingFileDestinationWidgetWrapper( parameter, type );
8440QString QgsProcessingFileDestinationWidgetWrapper::modelerExpressionFormatString()
const
8442 return tr(
"path to file destination" );
8450 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8453QString QgsProcessingFolderDestinationWidgetWrapper::parameterType()
const
8460 return new QgsProcessingFolderDestinationWidgetWrapper( parameter, type );
8464QString QgsProcessingFolderDestinationWidgetWrapper::modelerExpressionFormatString()
const
8466 return tr(
"path to folder destination" );
8474 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8477QString QgsProcessingVectorTileDestinationWidgetWrapper::parameterType()
const
8484 return new QgsProcessingPointCloudDestinationWidgetWrapper( parameter, type );
8487QString QgsProcessingVectorTileDestinationWidgetWrapper::modelerExpressionFormatString()
const
8489 return tr(
"path to layer destination" );
@ 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 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.
Responsible for drawing transient features (e.g.
@ 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.
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).