77#include <QButtonGroup>
85#include <QPlainTextEdit>
86#include <QRadioButton>
91#include "moc_qgsprocessingwidgetwrapperimpl.cpp"
93using namespace Qt::StringLiterals;
102QgsProcessingBooleanParameterDefinitionWidget::QgsProcessingBooleanParameterDefinitionWidget(
107 QVBoxLayout *vlayout =
new QVBoxLayout();
108 vlayout->setContentsMargins( 0, 0, 0, 0 );
110 mDefaultCheckBox =
new QCheckBox( tr(
"Checked" ) );
114 mDefaultCheckBox->setChecked(
false );
115 vlayout->addWidget( mDefaultCheckBox );
118 setLayout( vlayout );
123 auto param = std::make_unique<QgsProcessingParameterBoolean>( name, description, mDefaultCheckBox->isChecked() );
124 param->setFlags( flags );
125 return param.release();
133QWidget *QgsProcessingBooleanWidgetWrapper::createWidget()
139 QString description = parameterDefinition()->description();
141 description = QObject::tr(
"%1 [optional]" ).arg( description );
143 mCheckBox =
new QCheckBox( description );
144 mCheckBox->setToolTip( parameterDefinition()->toolTip() );
146 connect( mCheckBox, &QCheckBox::toggled,
this, [
this] { emit widgetValueHasChanged(
this ); } );
153 mComboBox =
new QComboBox();
154 mComboBox->addItem( tr(
"Yes" ),
true );
155 mComboBox->addItem( tr(
"No" ),
false );
156 mComboBox->setToolTip( parameterDefinition()->toolTip() );
158 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
166QLabel *QgsProcessingBooleanWidgetWrapper::createLabel()
175void QgsProcessingBooleanWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
182 mCheckBox->setChecked( v );
190 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
196QVariant QgsProcessingBooleanWidgetWrapper::widgetValue()
const
201 return mCheckBox->isChecked();
205 return mComboBox->currentData();
210QString QgsProcessingBooleanWidgetWrapper::parameterType()
const
217 return new QgsProcessingBooleanWidgetWrapper( parameter, type );
224 return new QgsProcessingBooleanParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
232QgsProcessingCrsParameterDefinitionWidget::QgsProcessingCrsParameterDefinitionWidget(
237 QVBoxLayout *vlayout =
new QVBoxLayout();
238 vlayout->setContentsMargins( 0, 0, 0, 0 );
240 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
245 mCrsSelector->setShowAccuracyWarnings(
true );
252 vlayout->addWidget( mCrsSelector );
253 setLayout( vlayout );
258 auto param = std::make_unique<QgsProcessingParameterCrs>( name, description, mCrsSelector->crs().authid() );
259 param->setFlags( flags );
260 return param.release();
267QWidget *QgsProcessingCrsWidgetWrapper::createWidget()
269 Q_ASSERT( mProjectionSelectionWidget ==
nullptr );
271 mProjectionSelectionWidget->setToolTip( parameterDefinition()->toolTip() );
285 return mProjectionSelectionWidget;
290 QWidget *w =
new QWidget();
291 w->setToolTip( parameterDefinition()->toolTip() );
293 QVBoxLayout *vl =
new QVBoxLayout();
294 vl->setContentsMargins( 0, 0, 0, 0 );
297 mUseProjectCrsCheckBox =
new QCheckBox( tr(
"Use project CRS" ) );
298 mUseProjectCrsCheckBox->setToolTip( tr(
"Always use the current project CRS when running the model" ) );
299 vl->addWidget( mUseProjectCrsCheckBox );
300 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, mProjectionSelectionWidget, &QgsProjectionSelectionWidget::setDisabled );
301 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled,
this, [
this] { emit widgetValueHasChanged(
this ); } );
303 vl->addWidget( mProjectionSelectionWidget );
311void QgsProcessingCrsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
313 if ( mUseProjectCrsCheckBox )
315 if ( value.toString().compare(
"ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
317 mUseProjectCrsCheckBox->setChecked(
true );
322 mUseProjectCrsCheckBox->setChecked(
false );
327 if ( mProjectionSelectionWidget )
328 mProjectionSelectionWidget->setCrs( v );
331QVariant QgsProcessingCrsWidgetWrapper::widgetValue()
const
333 if ( mUseProjectCrsCheckBox && mUseProjectCrsCheckBox->isChecked() )
334 return u
"ProjectCrs"_s;
335 else if ( mProjectionSelectionWidget )
336 return mProjectionSelectionWidget->crs().isValid() ? mProjectionSelectionWidget->crs() : QVariant();
341QString QgsProcessingCrsWidgetWrapper::modelerExpressionFormatString()
const
343 return tr(
"string as EPSG code, WKT or PROJ format, or a string identifying a map layer" );
346QString QgsProcessingCrsWidgetWrapper::parameterType()
const
353 return new QgsProcessingCrsWidgetWrapper( parameter, type );
360 return new QgsProcessingCrsParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
369QgsProcessingStringParameterDefinitionWidget::QgsProcessingStringParameterDefinitionWidget(
374 QVBoxLayout *vlayout =
new QVBoxLayout();
375 vlayout->setContentsMargins( 0, 0, 0, 0 );
377 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
379 mDefaultLineEdit =
new QLineEdit();
382 vlayout->addWidget( mDefaultLineEdit );
386 mMultiLineCheckBox =
new QCheckBox( tr(
"Multiline input" ) );
388 mMultiLineCheckBox->setChecked( stringParam->multiLine() );
389 vlayout->addWidget( mMultiLineCheckBox );
393 setLayout( vlayout );
398 auto param = std::make_unique<QgsProcessingParameterString>( name, description, mDefaultLineEdit->text(), mMultiLineCheckBox->isChecked() );
399 param->setFlags( flags );
400 return param.release();
408QWidget *QgsProcessingStringWidgetWrapper::createWidget()
410 const QVariantMap metadata = parameterDefinition()->metadata();
411 const QVariant valueHintsVariant = metadata.value( u
"widget_wrapper"_s ).toMap().value( u
"value_hints"_s );
413 if ( valueHintsVariant.isValid() )
415 const QVariantList valueList = valueHintsVariant.toList();
416 mComboBox =
new QComboBox();
417 mComboBox->setToolTip( parameterDefinition()->toolTip() );
421 mComboBox->addItem( QString() );
423 for (
const QVariant &entry : valueList )
425 mComboBox->addItem( entry.toString(), entry.toString() );
427 mComboBox->setCurrentIndex( 0 );
429 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
441 mPlainTextEdit =
new QPlainTextEdit();
442 mPlainTextEdit->setToolTip( parameterDefinition()->toolTip() );
444 connect( mPlainTextEdit, &QPlainTextEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
445 return mPlainTextEdit;
449 mLineEdit =
new QLineEdit();
450 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
452 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
459 mLineEdit =
new QLineEdit();
460 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
462 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
471void QgsProcessingStringWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
475 mLineEdit->setText( v );
476 if ( mPlainTextEdit )
477 mPlainTextEdit->setPlainText( v );
481 if ( !value.isValid() )
482 index = mComboBox->findData( QVariant() );
484 index = mComboBox->findData( v );
487 mComboBox->setCurrentIndex( index );
489 mComboBox->setCurrentIndex( 0 );
493QVariant QgsProcessingStringWidgetWrapper::widgetValue()
const
496 return mLineEdit->text();
497 else if ( mPlainTextEdit )
498 return mPlainTextEdit->toPlainText();
499 else if ( mComboBox )
500 return mComboBox->currentData();
505QString QgsProcessingStringWidgetWrapper::parameterType()
const
512 return new QgsProcessingStringWidgetWrapper( parameter, type );
519 return new QgsProcessingStringParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
531QWidget *QgsProcessingAuthConfigWidgetWrapper::createWidget()
540 mAuthConfigSelect->setToolTip( parameterDefinition()->toolTip() );
543 return mAuthConfigSelect;
549void QgsProcessingAuthConfigWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
552 if ( mAuthConfigSelect )
553 mAuthConfigSelect->setConfigId( v );
556QVariant QgsProcessingAuthConfigWidgetWrapper::widgetValue()
const
558 if ( mAuthConfigSelect )
559 return mAuthConfigSelect->configId();
564QString QgsProcessingAuthConfigWidgetWrapper::parameterType()
const
571 return new QgsProcessingAuthConfigWidgetWrapper( parameter, type );
578QgsProcessingNumberParameterDefinitionWidget::QgsProcessingNumberParameterDefinitionWidget(
583 QVBoxLayout *vlayout =
new QVBoxLayout();
584 vlayout->setContentsMargins( 0, 0, 0, 0 );
586 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
588 mTypeComboBox =
new QComboBox();
591 vlayout->addWidget( mTypeComboBox );
593 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
594 mMinLineEdit =
new QLineEdit();
595 vlayout->addWidget( mMinLineEdit );
597 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
598 mMaxLineEdit =
new QLineEdit();
599 vlayout->addWidget( mMaxLineEdit );
601 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
602 mDefaultLineEdit =
new QLineEdit();
603 vlayout->addWidget( mDefaultLineEdit );
607 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( numberParam->dataType() ) ) );
609 if ( !
qgsDoubleNear( numberParam->maximum(), std::numeric_limits<double>::max() ) )
611 mMaxLineEdit->setText( QLocale().toString( numberParam->maximum() ) );
615 mMaxLineEdit->clear();
618 if ( !
qgsDoubleNear( numberParam->minimum(), std::numeric_limits<double>::lowest() ) )
620 mMinLineEdit->setText( QLocale().toString( numberParam->minimum() ) );
624 mMinLineEdit->clear();
627 mDefaultLineEdit->setText( numberParam->defaultValueForGui().toString() );
635 setLayout( vlayout );
644 auto param = std::make_unique<QgsProcessingParameterNumber>( name, description, dataType, ok ? val : QVariant() );
646 if ( !mMinLineEdit->text().trimmed().isEmpty() )
651 param->setMinimum( val );
655 if ( !mMaxLineEdit->text().trimmed().isEmpty() )
660 param->setMaximum( val );
664 param->setFlags( flags );
665 return param.release();
672QWidget *QgsProcessingNumericWidgetWrapper::createWidget()
675 const QVariantMap metadata = numberDef->
metadata();
676 const int decimals = metadata.value( u
"widget_wrapper"_s ).toMap().value( u
"decimals"_s, 6 ).toInt();
684 QAbstractSpinBox *spinBox =
nullptr;
689 mDoubleSpinBox->setExpressionsEnabled(
true );
690 mDoubleSpinBox->setDecimals( decimals );
695 double singleStep = calculateStep( numberDef->
minimum(), numberDef->
maximum() );
696 singleStep = std::max( singleStep, std::pow( 10, -decimals ) );
697 mDoubleSpinBox->setSingleStep( singleStep );
700 spinBox = mDoubleSpinBox;
705 mSpinBox->setExpressionsEnabled(
true );
709 spinBox->setToolTip( parameterDefinition()->toolTip() );
711 double max = 999999999;
716 double min = -999999999;
721 if ( mDoubleSpinBox )
723 mDoubleSpinBox->setMinimum( min );
724 mDoubleSpinBox->setMaximum( max );
728 mSpinBox->setMinimum(
static_cast<int>( min ) );
729 mSpinBox->setMaximum(
static_cast<int>( max ) );
734 mAllowingNull =
true;
735 if ( mDoubleSpinBox )
737 mDoubleSpinBox->setShowClearButton(
true );
738 const double min = mDoubleSpinBox->minimum() - mDoubleSpinBox->singleStep();
739 mDoubleSpinBox->setMinimum( min );
740 mDoubleSpinBox->setValue( min );
744 mSpinBox->setShowClearButton(
true );
745 const int min = mSpinBox->minimum() - 1;
746 mSpinBox->setMinimum( min );
747 mSpinBox->setValue( min );
749 spinBox->setSpecialValueText( tr(
"Not set" ) );
757 if ( mDoubleSpinBox )
761 mDoubleSpinBox->setClearValue( defaultVal );
767 mSpinBox->setClearValue( intVal );
773 if ( mDoubleSpinBox )
774 mDoubleSpinBox->setClearValue( numberDef->
minimum() );
776 mSpinBox->setClearValue(
static_cast<int>( numberDef->
minimum() ) );
781 if ( mDoubleSpinBox )
783 mDoubleSpinBox->setValue( 0 );
784 mDoubleSpinBox->setClearValue( 0 );
788 mSpinBox->setValue( 0 );
789 mSpinBox->setClearValue( 0 );
794 if ( mDoubleSpinBox )
795 connect( mDoubleSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
797 connect( mSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
805void QgsProcessingNumericWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
807 if ( mDoubleSpinBox )
809 if ( mAllowingNull && !value.isValid() )
810 mDoubleSpinBox->clear();
814 mDoubleSpinBox->setValue( v );
819 if ( mAllowingNull && !value.isValid() )
824 mSpinBox->setValue( v );
829QVariant QgsProcessingNumericWidgetWrapper::widgetValue()
const
831 if ( mDoubleSpinBox )
833 if ( mAllowingNull &&
qgsDoubleNear( mDoubleSpinBox->value(), mDoubleSpinBox->minimum() ) )
836 return mDoubleSpinBox->value();
840 if ( mAllowingNull && mSpinBox->value() == mSpinBox->minimum() )
843 return mSpinBox->value();
849double QgsProcessingNumericWidgetWrapper::calculateStep(
const double minimum,
const double maximum )
851 const double valueRange = maximum - minimum;
852 if ( valueRange <= 1.0 )
854 const double step = valueRange / 10.0;
856 return qgsRound( step, -std::floor( std::log( step ) ) );
864QString QgsProcessingNumericWidgetWrapper::parameterType()
const
871 return new QgsProcessingNumericWidgetWrapper( parameter, type );
878 return new QgsProcessingNumberParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
885QgsProcessingDistanceParameterDefinitionWidget::QgsProcessingDistanceParameterDefinitionWidget(
890 QVBoxLayout *vlayout =
new QVBoxLayout();
891 vlayout->setContentsMargins( 0, 0, 0, 0 );
893 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
895 mParentLayerComboBox =
new QComboBox();
897 QString initialParent;
899 initialParent = distParam->parentParameterName();
901 if (
auto *lModel = widgetContext.
model() )
904 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
905 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
909 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
910 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
912 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
917 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
918 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
920 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
925 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
926 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
928 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
933 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
934 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
936 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
942 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
945 mParentLayerComboBox->addItem( initialParent, initialParent );
946 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
949 vlayout->addWidget( mParentLayerComboBox );
952 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
953 mMinLineEdit =
new QLineEdit();
954 vlayout->addWidget( mMinLineEdit );
956 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
957 mMaxLineEdit =
new QLineEdit();
958 vlayout->addWidget( mMaxLineEdit );
960 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
961 mDefaultLineEdit =
new QLineEdit();
962 vlayout->addWidget( mDefaultLineEdit );
966 mMinLineEdit->setText( QLocale().toString( distParam->minimum() ) );
967 mMaxLineEdit->setText( QLocale().toString( distParam->maximum() ) );
968 mDefaultLineEdit->setText( distParam->defaultValueForGui().toString() );
974 setLayout( vlayout );
982 auto param = std::make_unique<QgsProcessingParameterDistance>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
987 param->setMinimum( val );
993 param->setMaximum( val );
996 param->setFlags( flags );
997 return param.release();
1001 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1004QString QgsProcessingDistanceWidgetWrapper::parameterType()
const
1011 return new QgsProcessingDistanceWidgetWrapper( parameter, type );
1014QWidget *QgsProcessingDistanceWidgetWrapper::createWidget()
1018 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1023 mLabel =
new QLabel();
1024 mUnitsCombo =
new QComboBox();
1036 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1037 QHBoxLayout *layout =
new QHBoxLayout();
1038 layout->addWidget( spin, 1 );
1039 layout->insertSpacing( 1, labelMargin / 2 );
1040 layout->insertWidget( 2, mLabel );
1041 layout->insertWidget( 3, mUnitsCombo );
1046 mWarningLabel =
new QWidget();
1047 QHBoxLayout *warningLayout =
new QHBoxLayout();
1048 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1049 QLabel *warning =
new QLabel();
1051 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1052 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1053 warning->setToolTip( tr(
"Distance is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1054 warningLayout->insertSpacing( 0, labelMargin / 2 );
1055 warningLayout->insertWidget( 1, warning );
1056 mWarningLabel->setLayout( warningLayout );
1057 layout->insertWidget( 4, mWarningLabel );
1059 QWidget *w =
new QWidget();
1060 layout->setContentsMargins( 0, 0, 0, 0 );
1061 w->setLayout( layout );
1075void QgsProcessingDistanceWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1077 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1084 if ( wrapper->parameterDefinition()->name() ==
static_cast<const QgsProcessingParameterDistance *
>( parameterDefinition() )->parentParameterName() )
1086 setUnitParameterValue( wrapper->parameterValue(), wrapper );
1106 std::unique_ptr<QgsProcessingContext> tmpContext;
1107 if ( mProcessingContextGenerator )
1108 context = mProcessingContextGenerator->processingContext();
1112 tmpContext = std::make_unique<QgsProcessingContext>();
1113 context = tmpContext.get();
1120 units = crs.mapUnits();
1131 mUnitsCombo->hide();
1139 if ( mBaseUnit != units )
1141 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( units ) ) );
1144 mUnitsCombo->show();
1151QVariant QgsProcessingDistanceWidgetWrapper::widgetValue()
const
1153 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1154 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1169 return new QgsProcessingDistanceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1177QgsProcessingAreaParameterDefinitionWidget::QgsProcessingAreaParameterDefinitionWidget(
1182 QVBoxLayout *vlayout =
new QVBoxLayout();
1183 vlayout->setContentsMargins( 0, 0, 0, 0 );
1185 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
1187 mParentLayerComboBox =
new QComboBox();
1189 QString initialParent;
1191 initialParent = areaParam->parentParameterName();
1193 if (
auto *lModel = widgetContext.
model() )
1196 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
1197 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
1201 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1202 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1204 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1209 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1210 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1212 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1217 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1218 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1220 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1225 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1226 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1228 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1234 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
1237 mParentLayerComboBox->addItem( initialParent, initialParent );
1238 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1243 vlayout->addWidget( mParentLayerComboBox );
1245 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1246 mMinLineEdit =
new QLineEdit();
1247 vlayout->addWidget( mMinLineEdit );
1249 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1250 mMaxLineEdit =
new QLineEdit();
1251 vlayout->addWidget( mMaxLineEdit );
1253 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1254 mDefaultLineEdit =
new QLineEdit();
1255 vlayout->addWidget( mDefaultLineEdit );
1259 mMinLineEdit->setText( QLocale().toString( areaParam->minimum() ) );
1260 mMaxLineEdit->setText( QLocale().toString( areaParam->maximum() ) );
1261 mDefaultLineEdit->setText( areaParam->defaultValueForGui().toString() );
1268 setLayout( vlayout );
1276 auto param = std::make_unique<QgsProcessingParameterArea>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1281 param->setMinimum( val );
1287 param->setMaximum( val );
1290 param->setFlags( flags );
1291 return param.release();
1300 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1303QString QgsProcessingAreaWidgetWrapper::parameterType()
const
1310 return new QgsProcessingAreaWidgetWrapper( parameter, type );
1313QWidget *QgsProcessingAreaWidgetWrapper::createWidget()
1317 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1322 mLabel =
new QLabel();
1323 mUnitsCombo =
new QComboBox();
1338 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1339 QHBoxLayout *layout =
new QHBoxLayout();
1340 layout->addWidget( spin, 1 );
1341 layout->insertSpacing( 1, labelMargin / 2 );
1342 layout->insertWidget( 2, mLabel );
1343 layout->insertWidget( 3, mUnitsCombo );
1348 mWarningLabel =
new QWidget();
1349 QHBoxLayout *warningLayout =
new QHBoxLayout();
1350 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1351 QLabel *warning =
new QLabel();
1353 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1354 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1355 warning->setToolTip( tr(
"Area is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1356 warningLayout->insertSpacing( 0, labelMargin / 2 );
1357 warningLayout->insertWidget( 1, warning );
1358 mWarningLabel->setLayout( warningLayout );
1359 layout->insertWidget( 4, mWarningLabel );
1361 QWidget *w =
new QWidget();
1362 layout->setContentsMargins( 0, 0, 0, 0 );
1363 w->setLayout( layout );
1377void QgsProcessingAreaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1379 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1408 std::unique_ptr<QgsProcessingContext> tmpContext;
1409 if ( mProcessingContextGenerator )
1410 context = mProcessingContextGenerator->processingContext();
1414 tmpContext = std::make_unique<QgsProcessingContext>();
1415 context = tmpContext.get();
1422 units = QgsUnitTypes::distanceToAreaUnit( crs.mapUnits() );
1428void QgsProcessingAreaWidgetWrapper::setUnits(
Qgis::AreaUnit units )
1433 mUnitsCombo->hide();
1438 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QVariant::fromValue( units ) ) );
1439 mUnitsCombo->show();
1446QVariant QgsProcessingAreaWidgetWrapper::widgetValue()
const
1448 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1449 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1464 return new QgsProcessingAreaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1472QgsProcessingVolumeParameterDefinitionWidget::QgsProcessingVolumeParameterDefinitionWidget(
1477 QVBoxLayout *vlayout =
new QVBoxLayout();
1478 vlayout->setContentsMargins( 0, 0, 0, 0 );
1480 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
1482 mParentLayerComboBox =
new QComboBox();
1484 QString initialParent;
1486 initialParent = volumeParam->parentParameterName();
1488 if (
auto *lModel = widgetContext.
model() )
1491 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
1492 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
1496 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1497 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1499 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1504 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1505 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1507 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1512 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1513 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1515 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1520 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1521 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1523 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1529 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
1532 mParentLayerComboBox->addItem( initialParent, initialParent );
1533 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1536 vlayout->addWidget( mParentLayerComboBox );
1538 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1539 mMinLineEdit =
new QLineEdit();
1540 vlayout->addWidget( mMinLineEdit );
1542 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1543 mMaxLineEdit =
new QLineEdit();
1544 vlayout->addWidget( mMaxLineEdit );
1546 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1547 mDefaultLineEdit =
new QLineEdit();
1548 vlayout->addWidget( mDefaultLineEdit );
1552 mMinLineEdit->setText( QLocale().toString( volumeParam->minimum() ) );
1553 mMaxLineEdit->setText( QLocale().toString( volumeParam->maximum() ) );
1554 mDefaultLineEdit->setText( volumeParam->defaultValueForGui().toString() );
1562 setLayout( vlayout );
1570 auto param = std::make_unique<QgsProcessingParameterVolume>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1575 param->setMinimum( val );
1581 param->setMaximum( val );
1584 param->setFlags( flags );
1585 return param.release();
1594 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1597QString QgsProcessingVolumeWidgetWrapper::parameterType()
const
1604 return new QgsProcessingVolumeWidgetWrapper( parameter, type );
1607QWidget *QgsProcessingVolumeWidgetWrapper::createWidget()
1611 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1616 mLabel =
new QLabel();
1617 mUnitsCombo =
new QComboBox();
1630 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1631 QHBoxLayout *layout =
new QHBoxLayout();
1632 layout->addWidget( spin, 1 );
1633 layout->insertSpacing( 1, labelMargin / 2 );
1634 layout->insertWidget( 2, mLabel );
1635 layout->insertWidget( 3, mUnitsCombo );
1640 mWarningLabel =
new QWidget();
1641 QHBoxLayout *warningLayout =
new QHBoxLayout();
1642 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1643 QLabel *warning =
new QLabel();
1645 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1646 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1647 warning->setToolTip( tr(
"Volume is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1648 warningLayout->insertSpacing( 0, labelMargin / 2 );
1649 warningLayout->insertWidget( 1, warning );
1650 mWarningLabel->setLayout( warningLayout );
1651 layout->insertWidget( 4, mWarningLabel );
1653 QWidget *w =
new QWidget();
1654 layout->setContentsMargins( 0, 0, 0, 0 );
1655 w->setLayout( layout );
1669void QgsProcessingVolumeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1671 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1700 std::unique_ptr<QgsProcessingContext> tmpContext;
1701 if ( mProcessingContextGenerator )
1702 context = mProcessingContextGenerator->processingContext();
1706 tmpContext = std::make_unique<QgsProcessingContext>();
1707 context = tmpContext.get();
1714 units = QgsUnitTypes::distanceToVolumeUnit( crs.mapUnits() );
1725 mUnitsCombo->hide();
1730 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QVariant::fromValue( units ) ) );
1731 mUnitsCombo->show();
1738QVariant QgsProcessingVolumeWidgetWrapper::widgetValue()
const
1740 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1741 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1756 return new QgsProcessingVolumeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1764QgsProcessingDurationParameterDefinitionWidget::QgsProcessingDurationParameterDefinitionWidget(
1769 QVBoxLayout *vlayout =
new QVBoxLayout();
1770 vlayout->setContentsMargins( 0, 0, 0, 0 );
1772 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1773 mMinLineEdit =
new QLineEdit();
1774 vlayout->addWidget( mMinLineEdit );
1776 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1777 mMaxLineEdit =
new QLineEdit();
1778 vlayout->addWidget( mMaxLineEdit );
1780 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1781 mDefaultLineEdit =
new QLineEdit();
1782 vlayout->addWidget( mDefaultLineEdit );
1784 vlayout->addWidget(
new QLabel( tr(
"Default unit type" ) ) );
1786 mUnitsCombo =
new QComboBox();
1796 vlayout->addWidget( mUnitsCombo );
1802 mMinLineEdit->setText( QLocale().toString( durationParam->minimum() ) );
1803 mMaxLineEdit->setText( QLocale().toString( durationParam->maximum() ) );
1804 mDefaultLineEdit->setText( durationParam->defaultValueForGui().toString() );
1805 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( durationParam->defaultUnit() ) ) );
1811 setLayout( vlayout );
1819 auto param = std::make_unique<QgsProcessingParameterDuration>( name, description, ok ? val : QVariant() );
1824 param->setMinimum( val );
1830 param->setMaximum( val );
1833 param->setDefaultUnit(
static_cast<Qgis::TemporalUnit>( mUnitsCombo->currentData().toInt() ) );
1835 param->setFlags( flags );
1836 return param.release();
1840 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1843QString QgsProcessingDurationWidgetWrapper::parameterType()
const
1850 return new QgsProcessingDurationWidgetWrapper( parameter, type );
1853QWidget *QgsProcessingDurationWidgetWrapper::createWidget()
1857 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1862 mUnitsCombo =
new QComboBox();
1874 QHBoxLayout *layout =
new QHBoxLayout();
1875 layout->addWidget( spin, 1 );
1876 layout->insertWidget( 1, mUnitsCombo );
1878 QWidget *w =
new QWidget();
1879 layout->setContentsMargins( 0, 0, 0, 0 );
1880 w->setLayout( layout );
1882 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( durationDef->
defaultUnit() ) ) );
1883 mUnitsCombo->show();
1895QLabel *QgsProcessingDurationWidgetWrapper::createLabel()
1907QVariant QgsProcessingDurationWidgetWrapper::widgetValue()
const
1909 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1910 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo )
1921void QgsProcessingDurationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1927 QgsProcessingNumericWidgetWrapper::setWidgetValue( val, context );
1931 QgsProcessingNumericWidgetWrapper::setWidgetValue( value, context );
1939 return new QgsProcessingDurationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1946QgsProcessingScaleParameterDefinitionWidget::QgsProcessingScaleParameterDefinitionWidget(
1951 QVBoxLayout *vlayout =
new QVBoxLayout();
1952 vlayout->setContentsMargins( 0, 0, 0, 0 );
1954 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1956 mDefaultLineEdit =
new QLineEdit();
1960 mDefaultLineEdit->setText( scaleParam->defaultValueForGui().toString() );
1963 vlayout->addWidget( mDefaultLineEdit );
1966 setLayout( vlayout );
1972 double val = mDefaultLineEdit->text().toDouble( &ok );
1973 auto param = std::make_unique<QgsProcessingParameterScale>( name, description, ok ? val : QVariant() );
1974 param->setFlags( flags );
1975 return param.release();
1979 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1982QString QgsProcessingScaleWidgetWrapper::parameterType()
const
1989 return new QgsProcessingScaleWidgetWrapper( parameter, type );
1992QWidget *QgsProcessingScaleWidgetWrapper::createWidget()
2004 mScaleWidget->setAllowNull(
true );
2006 mScaleWidget->setMapCanvas( widgetContext().mapCanvas() );
2007 mScaleWidget->setShowCurrentScaleButton(
true );
2009 mScaleWidget->setToolTip( parameterDefinition()->toolTip() );
2011 return mScaleWidget;
2020 mScaleWidget->setMapCanvas( context.
mapCanvas() );
2025QVariant QgsProcessingScaleWidgetWrapper::widgetValue()
const
2027 return mScaleWidget && !mScaleWidget->isNull() ? QVariant( mScaleWidget->scale() ) : QVariant();
2030void QgsProcessingScaleWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2034 if ( mScaleWidget->allowNull() && !value.isValid() )
2035 mScaleWidget->setNull();
2039 mScaleWidget->setScale( v );
2048 return new QgsProcessingScaleParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2056QgsProcessingRangeParameterDefinitionWidget::QgsProcessingRangeParameterDefinitionWidget(
2061 QVBoxLayout *vlayout =
new QVBoxLayout();
2062 vlayout->setContentsMargins( 0, 0, 0, 0 );
2064 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
2066 mTypeComboBox =
new QComboBox();
2069 vlayout->addWidget( mTypeComboBox );
2071 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
2072 mMinLineEdit =
new QLineEdit();
2073 vlayout->addWidget( mMinLineEdit );
2075 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
2076 mMaxLineEdit =
new QLineEdit();
2077 vlayout->addWidget( mMaxLineEdit );
2081 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( rangeParam->dataType() ) ) );
2083 mMinLineEdit->setText( QLocale().toString( range.at( 0 ) ) );
2084 mMaxLineEdit->setText( QLocale().toString( range.at( 1 ) ) );
2091 setLayout( vlayout );
2096 QString defaultValue;
2097 if ( mMinLineEdit->text().isEmpty() )
2099 defaultValue = u
"None"_s;
2107 defaultValue = u
"None"_s;
2111 if ( mMaxLineEdit->text().isEmpty() )
2113 defaultValue +=
",None"_L1;
2119 defaultValue += u
",%1"_s.arg( ok ? QString::number( val ) :
"None"_L1 );
2123 auto param = std::make_unique<QgsProcessingParameterRange>( name, description, dataType, defaultValue );
2124 param->setFlags( flags );
2125 return param.release();
2133QWidget *QgsProcessingRangeWidgetWrapper::createWidget()
2142 QHBoxLayout *layout =
new QHBoxLayout();
2147 mMinSpinBox->setExpressionsEnabled(
true );
2148 mMinSpinBox->setShowClearButton(
false );
2149 mMaxSpinBox->setExpressionsEnabled(
true );
2150 mMaxSpinBox->setShowClearButton(
false );
2152 QLabel *minLabel =
new QLabel( tr(
"Min" ) );
2153 layout->addWidget( minLabel );
2154 layout->addWidget( mMinSpinBox, 1 );
2156 QLabel *maxLabel =
new QLabel( tr(
"Max" ) );
2157 layout->addWidget( maxLabel );
2158 layout->addWidget( mMaxSpinBox, 1 );
2160 QWidget *w =
new QWidget();
2161 layout->setContentsMargins( 0, 0, 0, 0 );
2162 w->setLayout( layout );
2166 mMinSpinBox->setDecimals( 6 );
2167 mMaxSpinBox->setDecimals( 6 );
2171 mMinSpinBox->setDecimals( 0 );
2172 mMaxSpinBox->setDecimals( 0 );
2175 mMinSpinBox->setMinimum( -99999999.999999 );
2176 mMaxSpinBox->setMinimum( -99999999.999999 );
2177 mMinSpinBox->setMaximum( 99999999.999999 );
2178 mMaxSpinBox->setMaximum( 99999999.999999 );
2182 mAllowingNull =
true;
2184 const double min = mMinSpinBox->minimum() - 1;
2185 mMinSpinBox->setMinimum( min );
2186 mMaxSpinBox->setMinimum( min );
2187 mMinSpinBox->setValue( min );
2188 mMaxSpinBox->setValue( min );
2190 mMinSpinBox->setShowClearButton(
true );
2191 mMaxSpinBox->setShowClearButton(
true );
2192 mMinSpinBox->setSpecialValueText( tr(
"Not set" ) );
2193 mMaxSpinBox->setSpecialValueText( tr(
"Not set" ) );
2196 w->setToolTip( parameterDefinition()->toolTip() );
2198 connect( mMinSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this](
const double v ) {
2199 mBlockChangedSignal++;
2200 if ( !mAllowingNull && v > mMaxSpinBox->value() )
2201 mMaxSpinBox->setValue( v );
2202 mBlockChangedSignal--;
2204 if ( !mBlockChangedSignal )
2205 emit widgetValueHasChanged(
this );
2207 connect( mMaxSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this](
const double v ) {
2208 mBlockChangedSignal++;
2209 if ( !mAllowingNull && v < mMinSpinBox->value() )
2210 mMinSpinBox->setValue( v );
2211 mBlockChangedSignal--;
2213 if ( !mBlockChangedSignal )
2214 emit widgetValueHasChanged(
this );
2223void QgsProcessingRangeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2226 if ( mAllowingNull && v.empty() )
2228 mMinSpinBox->clear();
2229 mMaxSpinBox->clear();
2236 if ( mAllowingNull )
2238 mBlockChangedSignal++;
2239 if ( std::isnan( v.at( 0 ) ) )
2240 mMinSpinBox->clear();
2242 mMinSpinBox->setValue( v.at( 0 ) );
2244 if ( v.count() >= 2 )
2246 if ( std::isnan( v.at( 1 ) ) )
2247 mMaxSpinBox->clear();
2249 mMaxSpinBox->setValue( v.at( 1 ) );
2251 mBlockChangedSignal--;
2255 mBlockChangedSignal++;
2256 mMinSpinBox->setValue( v.at( 0 ) );
2257 if ( v.count() >= 2 )
2258 mMaxSpinBox->setValue( v.at( 1 ) );
2259 mBlockChangedSignal--;
2263 if ( !mBlockChangedSignal )
2264 emit widgetValueHasChanged(
this );
2267QVariant QgsProcessingRangeWidgetWrapper::widgetValue()
const
2269 if ( mAllowingNull )
2272 if (
qgsDoubleNear( mMinSpinBox->value(), mMinSpinBox->minimum() ) )
2275 value = QString::number( mMinSpinBox->value() );
2277 if (
qgsDoubleNear( mMaxSpinBox->value(), mMaxSpinBox->minimum() ) )
2278 value +=
",None"_L1;
2280 value += u
",%1"_s.arg( mMaxSpinBox->value() );
2285 return u
"%1,%2"_s.arg( mMinSpinBox->value() ).arg( mMaxSpinBox->value() );
2288QString QgsProcessingRangeWidgetWrapper::modelerExpressionFormatString()
const
2290 return tr(
"string as two comma delimited floats, e.g. '1,10'" );
2293QString QgsProcessingRangeWidgetWrapper::parameterType()
const
2300 return new QgsProcessingRangeWidgetWrapper( parameter, type );
2307 return new QgsProcessingRangeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2315QgsProcessingMatrixParameterDefinitionWidget::QgsProcessingMatrixParameterDefinitionWidget(
2320 QVBoxLayout *vlayout =
new QVBoxLayout();
2321 vlayout->setContentsMargins( 0, 0, 0, 0 );
2323 mMatrixWidget =
new QgsProcessingMatrixModelerWidget();
2326 mMatrixWidget->setValue( matrixParam->headers(), matrixParam->defaultValueForGui() );
2327 mMatrixWidget->setFixedRows( matrixParam->hasFixedNumberRows() );
2329 vlayout->addWidget( mMatrixWidget );
2333 setLayout( vlayout );
2338 auto param = std::make_unique<QgsProcessingParameterMatrix>( name, description, 1, mMatrixWidget->fixedRows(), mMatrixWidget->headers(), mMatrixWidget->value() );
2339 param->setFlags( flags );
2340 return param.release();
2348QWidget *QgsProcessingMatrixWidgetWrapper::createWidget()
2350 mMatrixWidget =
new QgsProcessingMatrixParameterPanel(
nullptr,
dynamic_cast<const QgsProcessingParameterMatrix *
>( parameterDefinition() ) );
2351 mMatrixWidget->setToolTip( parameterDefinition()->toolTip() );
2353 connect( mMatrixWidget, &QgsProcessingMatrixParameterPanel::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
2361 return mMatrixWidget;
2367void QgsProcessingMatrixWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2370 if ( mMatrixWidget )
2371 mMatrixWidget->setValue( v );
2374QVariant QgsProcessingMatrixWidgetWrapper::widgetValue()
const
2376 if ( mMatrixWidget )
2377 return mMatrixWidget->value().isEmpty() ? QVariant() : mMatrixWidget->value();
2382QString QgsProcessingMatrixWidgetWrapper::modelerExpressionFormatString()
const
2384 return tr(
"comma delimited string of values, or an array of values" );
2387QString QgsProcessingMatrixWidgetWrapper::parameterType()
const
2394 return new QgsProcessingMatrixWidgetWrapper( parameter, type );
2401 return new QgsProcessingMatrixParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2410QgsProcessingFileParameterDefinitionWidget::QgsProcessingFileParameterDefinitionWidget(
2415 QVBoxLayout *vlayout =
new QVBoxLayout();
2416 vlayout->setContentsMargins( 0, 0, 0, 0 );
2418 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
2420 mTypeComboBox =
new QComboBox();
2424 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( fileParam->behavior() ) ) );
2426 mTypeComboBox->setCurrentIndex( 0 );
2427 vlayout->addWidget( mTypeComboBox );
2431 vlayout->addWidget(
new QLabel( tr(
"File filter" ) ) );
2433 mFilterComboBox =
new QComboBox();
2434 mFilterComboBox->setEditable(
true );
2436 mFilterComboBox->addItem( tr(
"All Files (*.*)" ) );
2437 mFilterComboBox->addItem( tr(
"CSV Files (*.csv)" ) );
2438 mFilterComboBox->addItem( tr(
"HTML Files (*.html *.htm)" ) );
2439 mFilterComboBox->addItem( tr(
"Text Files (*.txt)" ) );
2441 mFilterComboBox->setCurrentText( fileParam->fileFilter() );
2443 mFilterComboBox->setCurrentIndex( 0 );
2444 vlayout->addWidget( mFilterComboBox );
2448 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2451 mDefaultFileWidget->lineEdit()->setShowClearButton(
true );
2455 mDefaultFileWidget->setFilePath( fileParam->defaultValueForGui().toString() );
2459 vlayout->addWidget( mDefaultFileWidget );
2462 connect( mTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this] {
2470 setLayout( vlayout );
2475 auto param = std::make_unique<QgsProcessingParameterFile>( name, description );
2478 param->setFileFilter( mFilterComboBox->currentText() );
2479 if ( !mDefaultFileWidget->filePath().isEmpty() )
2480 param->setDefaultValue( mDefaultFileWidget->filePath() );
2481 param->setFlags( flags );
2482 return param.release();
2490QWidget *QgsProcessingFileWidgetWrapper::createWidget()
2503 mFileWidget->setToolTip( parameterDefinition()->toolTip() );
2504 mFileWidget->setDialogTitle( parameterDefinition()->description() );
2506 mFileWidget->setDefaultRoot(
QgsSettings().value( u
"/Processing/LastInputPath"_s, QDir::homePath() ).toString() );
2513 mFileWidget->setFilter( fileParam->
fileFilter() );
2514 else if ( !fileParam->
extension().isEmpty() )
2515 mFileWidget->setFilter( tr(
"%1 files" ).arg( fileParam->
extension().toUpper() ) + u
" (*."_s + fileParam->
extension().toLower() +
')' );
2524 QgsSettings().
setValue( u
"/Processing/LastInputPath"_s, QFileInfo( path ).canonicalPath() );
2525 emit widgetValueHasChanged(
this );
2533void QgsProcessingFileWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2537 mFileWidget->setFilePath( v );
2540QVariant QgsProcessingFileWidgetWrapper::widgetValue()
const
2543 return mFileWidget->filePath();
2548QString QgsProcessingFileWidgetWrapper::modelerExpressionFormatString()
const
2550 return tr(
"string representing a path to a file or folder" );
2553QString QgsProcessingFileWidgetWrapper::parameterType()
const
2560 return new QgsProcessingFileWidgetWrapper( parameter, type );
2567 return new QgsProcessingFileParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2575QgsProcessingExpressionParameterDefinitionWidget::QgsProcessingExpressionParameterDefinitionWidget(
2580 QVBoxLayout *vlayout =
new QVBoxLayout();
2581 vlayout->setContentsMargins( 0, 0, 0, 0 );
2582 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2585 mDefaultQgisLineEdit->registerExpressionContextGenerator(
this );
2587 mDefaultPointCloudLineEdit =
new QgsProcessingPointCloudExpressionLineEdit();
2588 mDefaultRasterCalculatorLineEdit =
new QgsProcessingRasterCalculatorExpressionLineEdit();
2590 QStackedWidget *stackedWidget =
new QStackedWidget();
2591 stackedWidget->addWidget( mDefaultQgisLineEdit );
2592 stackedWidget->addWidget( mDefaultPointCloudLineEdit );
2593 stackedWidget->addWidget( mDefaultRasterCalculatorLineEdit );
2594 vlayout->addWidget( stackedWidget );
2603 mDefaultQgisLineEdit->setExpression( expr );
2604 mDefaultPointCloudLineEdit->setExpression( expr );
2607 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
2609 mParentLayerComboBox =
new QComboBox();
2610 vlayout->addWidget( mParentLayerComboBox );
2612 vlayout->addWidget(
new QLabel( tr(
"Expression type" ) ) );
2613 mExpressionTypeComboBox =
new QComboBox();
2618 connect( mExpressionTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [
this, stackedWidget, definition, widgetContext](
int ) {
2619 mParentLayerComboBox->clear();
2620 mParentLayerComboBox->addItem( tr(
"None" ), QVariant() );
2622 stackedWidget->setCurrentIndex( mExpressionTypeComboBox->currentIndex() > 0 ? mExpressionTypeComboBox->currentIndex() : 0 );
2624 QString initialParent;
2626 initialParent = expParam->parentLayerParameterName();
2630 if ( QgsProcessingModelAlgorithm *model = widgetContext.
model() )
2633 const QMap<QString, QgsProcessingModelParameter> components = model->parameterComponents();
2634 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
2641 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2642 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2644 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2649 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2650 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2652 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2659 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2660 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2662 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2673 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2674 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2676 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2684 if ( mParentLayerComboBox->count() == 1 && !initialParent.isEmpty() )
2687 mParentLayerComboBox->addItem( initialParent, initialParent );
2688 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2692 mExpressionTypeComboBox->setCurrentIndex( -1 );
2694 mExpressionTypeComboBox->setCurrentIndex( mExpressionTypeComboBox->findData(
static_cast<int>( expParam->expressionType() ) ) );
2696 mExpressionTypeComboBox->setCurrentIndex( 0 );
2698 vlayout->addWidget( mExpressionTypeComboBox );
2703 setLayout( vlayout );
2710 switch ( expressionType )
2713 expression = mDefaultQgisLineEdit->expression();
2716 expression = mDefaultPointCloudLineEdit->expression();
2719 expression = mDefaultRasterCalculatorLineEdit->expression();
2722 auto param = std::make_unique<QgsProcessingParameterExpression>( name, description, expression, mParentLayerComboBox->currentData().toString(),
false, expressionType );
2723 param->setFlags( flags );
2724 return param.release();
2731QWidget *QgsProcessingExpressionWidgetWrapper::createWidget()
2746 mExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2747 mExpLineEdit->setExpressionDialogTitle( parameterDefinition()->description() );
2748 mExpLineEdit->registerExpressionContextGenerator(
this );
2750 return mExpLineEdit;
2756 mPointCloudExpLineEdit =
new QgsProcessingPointCloudExpressionLineEdit();
2757 mPointCloudExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2758 connect( mPointCloudExpLineEdit, &QgsProcessingPointCloudExpressionLineEdit::expressionChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
2759 return mPointCloudExpLineEdit;
2764 mRasterCalculatorExpLineEdit =
new QgsProcessingRasterCalculatorExpressionLineEdit();
2765 mRasterCalculatorExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2768 mRasterCalculatorExpLineEdit->setLayers( QVariantList() <<
"A" <<
"B" <<
"C" <<
"D" <<
"E" <<
"F" <<
"G" );
2770 connect( mRasterCalculatorExpLineEdit, &QgsProcessingRasterCalculatorExpressionLineEdit::expressionChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
2771 return mRasterCalculatorExpLineEdit;
2775 if ( expParam->
metadata().value( u
"inlineEditor"_s ).toBool() )
2778 mExpBuilderWidget->setToolTip( parameterDefinition()->toolTip() );
2779 mExpBuilderWidget->init( createExpressionContext() );
2781 Q_UNUSED( changed );
2782 emit widgetValueHasChanged(
this );
2784 return mExpBuilderWidget;
2789 mFieldExpWidget->setToolTip( parameterDefinition()->toolTip() );
2790 mFieldExpWidget->setExpressionDialogTitle( parameterDefinition()->description() );
2791 mFieldExpWidget->registerExpressionContextGenerator(
this );
2793 mFieldExpWidget->setAllowEmptyFieldName(
true );
2796 emit widgetValueHasChanged(
this );
2798 return mFieldExpWidget;
2806void QgsProcessingExpressionWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
2818 setParentLayerWrapperValue( wrapper );
2834 if ( mExpBuilderWidget )
2837 mExpBuilderWidget->setExpressionContext( createExpressionContext() );
2845 std::unique_ptr<QgsProcessingContext> tmpContext;
2846 if ( mProcessingContextGenerator )
2847 context = mProcessingContextGenerator->processingContext();
2851 tmpContext = std::make_unique<QgsProcessingContext>();
2852 context = tmpContext.get();
2865 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2875 if ( mFieldExpWidget )
2876 mFieldExpWidget->setLayer(
nullptr );
2877 else if ( mExpBuilderWidget )
2878 mExpBuilderWidget->setLayer(
nullptr );
2879 else if ( mExpLineEdit )
2880 mExpLineEdit->setLayer(
nullptr );
2886 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
2889 mParentLayer = std::move( ownedLayer );
2897 if ( mFieldExpWidget )
2898 mFieldExpWidget->setLayer( layer );
2899 if ( mExpBuilderWidget )
2900 mExpBuilderWidget->setLayer( layer );
2901 else if ( mExpLineEdit )
2902 mExpLineEdit->setLayer( layer );
2911 if ( mPointCloudExpLineEdit )
2912 mPointCloudExpLineEdit->setLayer(
nullptr );
2918 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
2921 mParentLayer = std::move( ownedLayer );
2929 if ( mPointCloudExpLineEdit )
2930 mPointCloudExpLineEdit->setLayer( layer );
2937 if ( layers.isEmpty() )
2939 if ( mRasterCalculatorExpLineEdit )
2941 mRasterCalculatorExpLineEdit->setLayers( val.userType() == QMetaType::Type::QVariantList ? val.toList() : QVariantList() << val );
2946 if ( mRasterCalculatorExpLineEdit )
2948 QVariantList layersList;
2951 layersList << layer->
name();
2953 mRasterCalculatorExpLineEdit->setLayers( layersList );
2961void QgsProcessingExpressionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2964 if ( mFieldExpWidget )
2965 mFieldExpWidget->setExpression( v );
2966 else if ( mExpBuilderWidget )
2967 mExpBuilderWidget->setExpressionText( v );
2968 else if ( mExpLineEdit )
2969 mExpLineEdit->setExpression( v );
2970 else if ( mPointCloudExpLineEdit )
2971 mPointCloudExpLineEdit->setExpression( v );
2972 else if ( mRasterCalculatorExpLineEdit )
2973 mRasterCalculatorExpLineEdit->setExpression( v );
2976QVariant QgsProcessingExpressionWidgetWrapper::widgetValue()
const
2978 if ( mFieldExpWidget )
2979 return mFieldExpWidget->expression();
2980 if ( mExpBuilderWidget )
2981 return mExpBuilderWidget->expressionText();
2982 else if ( mExpLineEdit )
2983 return mExpLineEdit->expression();
2984 else if ( mPointCloudExpLineEdit )
2985 return mPointCloudExpLineEdit->expression();
2986 else if ( mRasterCalculatorExpLineEdit )
2987 return mRasterCalculatorExpLineEdit->expression();
2992QString QgsProcessingExpressionWidgetWrapper::modelerExpressionFormatString()
const
2994 return tr(
"string representation of an expression" );
2997const QgsVectorLayer *QgsProcessingExpressionWidgetWrapper::linkedVectorLayer()
const
2999 if ( mFieldExpWidget && mFieldExpWidget->layer() )
3000 return mFieldExpWidget->layer();
3002 if ( mExpBuilderWidget && mExpBuilderWidget->layer() )
3003 return mExpBuilderWidget->layer();
3008QString QgsProcessingExpressionWidgetWrapper::parameterType()
const
3015 return new QgsProcessingExpressionWidgetWrapper( parameter, type );
3022 return new QgsProcessingExpressionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3034 QHBoxLayout *hl =
new QHBoxLayout();
3035 hl->setContentsMargins( 0, 0, 0, 0 );
3037 mLineEdit =
new QLineEdit();
3038 mLineEdit->setEnabled(
false );
3039 hl->addWidget( mLineEdit, 1 );
3041 mToolButton =
new QToolButton();
3042 mToolButton->setText( QString( QChar( 0x2026 ) ) );
3043 hl->addWidget( mToolButton );
3049 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
3052 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingEnumPanelWidget::showDialog );
3055void QgsProcessingEnumPanelWidget::setValue(
const QVariant &value )
3057 if ( value.isValid() )
3059 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
3061 if ( mParam->usesStaticStrings() && mValue.count() == 1 && mValue.at( 0 ).toString().isEmpty() )
3067 updateSummaryText();
3071void QgsProcessingEnumPanelWidget::showDialog()
3073 QVariantList availableOptions;
3076 availableOptions.reserve( mParam->options().size() );
3078 if ( mParam->usesStaticStrings() )
3080 for ( QString o : mParam->options() )
3082 availableOptions << o;
3087 for (
int i = 0; i < mParam->options().count(); ++i )
3088 availableOptions << i;
3092 const QStringList options = mParam ? mParam->options() : QStringList();
3096 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
3097 widget->setPanelTitle( mParam->description() );
3099 if ( mParam->usesStaticStrings() )
3101 widget->setValueFormatter( [options](
const QVariant &v ) -> QString {
3102 const QString i = v.toString();
3103 return options.contains( i ) ? i : QString();
3108 widget->setValueFormatter( [options](
const QVariant &v ) -> QString {
3109 const int i = v.toInt();
3110 return options.size() > i ? options.at( i ) : QString();
3114 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
3120 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
3122 dlg.setValueFormatter( [options](
const QVariant &v ) -> QString {
3123 const int i = v.toInt();
3124 return options.size() > i ? options.at( i ) : QString();
3128 setValue( dlg.selectedOptions() );
3133void QgsProcessingEnumPanelWidget::updateSummaryText()
3138 if ( mValue.empty() )
3140 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
3145 values.reserve( mValue.size() );
3146 if ( mParam->usesStaticStrings() )
3148 for (
const QVariant &val : std::as_const( mValue ) )
3150 values << val.toString();
3155 const QStringList options = mParam->options();
3156 for (
const QVariant &val : std::as_const( mValue ) )
3158 const int i = val.toInt();
3159 values << ( options.size() > i ? options.at( i ) : QString() );
3163 const QString concatenated = values.join( tr(
"," ) );
3164 if ( concatenated.length() < 100 )
3165 mLineEdit->setText( concatenated );
3167 mLineEdit->setText( tr(
"%n option(s) selected",
nullptr, mValue.count() ) );
3175QgsProcessingEnumCheckboxPanelWidget::QgsProcessingEnumCheckboxPanelWidget( QWidget *parent,
const QgsProcessingParameterEnum *param,
int columns )
3178 , mButtonGroup( new QButtonGroup( this ) )
3179 , mColumns( columns )
3181 mButtonGroup->setExclusive( !mParam->allowMultiple() );
3183 QGridLayout *l =
new QGridLayout();
3184 l->setContentsMargins( 0, 0, 0, 0 );
3186 int rows =
static_cast<int>( std::ceil( mParam->options().count() /
static_cast<double>( mColumns ) ) );
3187 for (
int i = 0; i < mParam->options().count(); ++i )
3189 QAbstractButton *button =
nullptr;
3190 if ( mParam->allowMultiple() )
3191 button =
new QCheckBox( mParam->options().at( i ) );
3193 button =
new QRadioButton( mParam->options().at( i ) );
3195 connect( button, &QAbstractButton::toggled,
this, [
this] {
3196 if ( !mBlockChangedSignal )
3200 mButtons.insert( i, button );
3202 mButtonGroup->addButton( button, i );
3203 l->addWidget( button, i % rows, i / rows );
3205 l->addItem(
new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, mColumns );
3208 if ( mParam->allowMultiple() )
3210 setContextMenuPolicy( Qt::CustomContextMenu );
3211 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsProcessingEnumCheckboxPanelWidget::showPopupMenu );
3215QVariant QgsProcessingEnumCheckboxPanelWidget::value()
const
3217 if ( mParam->allowMultiple() )
3220 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3222 if ( it.value()->isChecked() )
3223 value.append( mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key() );
3229 if ( mParam->usesStaticStrings() )
3230 return mButtonGroup->checkedId() >= 0 ? mParam->options().at( mButtonGroup->checkedId() ) : QVariant();
3232 return mButtonGroup->checkedId() >= 0 ? mButtonGroup->checkedId() : QVariant();
3236void QgsProcessingEnumCheckboxPanelWidget::setValue(
const QVariant &value )
3238 mBlockChangedSignal =
true;
3239 if ( mParam->allowMultiple() )
3241 QVariantList selected;
3242 if ( value.isValid() )
3243 selected = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
3244 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3246 QVariant v = mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key();
3247 it.value()->setChecked( selected.contains( v ) );
3253 if ( v.userType() == QMetaType::Type::QVariantList )
3254 v = v.toList().value( 0 );
3256 v = mParam->usesStaticStrings() ?
static_cast< int >( mParam->options().indexOf( v.toString() ) ) : v;
3257 if ( mButtons.contains( v ) )
3258 mButtons.value( v )->setChecked(
true );
3260 mBlockChangedSignal =
false;
3264void QgsProcessingEnumCheckboxPanelWidget::showPopupMenu()
3267 QAction *selectAllAction =
new QAction( tr(
"Select All" ), &popupMenu );
3268 connect( selectAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::selectAll );
3269 QAction *clearAllAction =
new QAction( tr(
"Clear Selection" ), &popupMenu );
3270 connect( clearAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::deselectAll );
3271 popupMenu.addAction( selectAllAction );
3272 popupMenu.addAction( clearAllAction );
3273 popupMenu.exec( QCursor::pos() );
3276void QgsProcessingEnumCheckboxPanelWidget::selectAll()
3278 mBlockChangedSignal =
true;
3279 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3280 it.value()->setChecked(
true );
3281 mBlockChangedSignal =
false;
3285void QgsProcessingEnumCheckboxPanelWidget::deselectAll()
3287 mBlockChangedSignal =
true;
3288 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3289 it.value()->setChecked(
false );
3290 mBlockChangedSignal =
false;
3299QgsProcessingEnumParameterDefinitionWidget::QgsProcessingEnumParameterDefinitionWidget(
3304 QVBoxLayout *vlayout =
new QVBoxLayout();
3305 vlayout->setContentsMargins( 0, 0, 0, 0 );
3307 mEnumWidget =
new QgsProcessingEnumModelerWidget();
3310 mEnumWidget->setAllowMultiple( enumParam->allowMultiple() );
3311 mEnumWidget->setOptions( enumParam->options() );
3312 mEnumWidget->setDefaultOptions( enumParam->defaultValueForGui() );
3314 vlayout->addWidget( mEnumWidget );
3318 setLayout( vlayout );
3323 auto param = std::make_unique<QgsProcessingParameterEnum>( name, description, mEnumWidget->options(), mEnumWidget->allowMultiple(), mEnumWidget->defaultOptions() );
3325 return param.release();
3333QWidget *QgsProcessingEnumWidgetWrapper::createWidget()
3344 if ( expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"useCheckBoxes"_s,
false ).toBool() )
3346 const int columns = expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"columns"_s, 2 ).toInt();
3347 mCheckboxPanel =
new QgsProcessingEnumCheckboxPanelWidget(
nullptr, expParam, columns );
3348 mCheckboxPanel->setToolTip( parameterDefinition()->toolTip() );
3349 connect( mCheckboxPanel, &QgsProcessingEnumCheckboxPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
3350 return mCheckboxPanel;
3359 mPanel =
new QgsProcessingEnumPanelWidget(
nullptr, expParam );
3360 mPanel->setToolTip( parameterDefinition()->toolTip() );
3361 connect( mPanel, &QgsProcessingEnumPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
3366 mComboBox =
new QComboBox();
3369 mComboBox->addItem( tr(
"[Not selected]" ), QVariant() );
3370 const QStringList options = expParam->
options();
3371 const QVariantList iconList = expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"icons"_s ).toList();
3372 for (
int i = 0; i < options.count(); ++i )
3374 const QIcon icon = iconList.value( i ).value<QIcon>();
3377 mComboBox->addItem( icon, options.at( i ), options.at( i ) );
3379 mComboBox->addItem( icon, options.at( i ), i );
3382 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3383 mComboBox->setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon );
3384 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
3392void QgsProcessingEnumWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3396 if ( !value.isValid() )
3397 mComboBox->setCurrentIndex( mComboBox->findData( QVariant() ) );
3403 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
3408 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
3412 else if ( mPanel || mCheckboxPanel )
3415 if ( value.isValid() )
3420 opts.reserve( v.size() );
3421 for ( QString i : v )
3427 opts.reserve( v.size() );
3433 mPanel->setValue( opts );
3434 else if ( mCheckboxPanel )
3435 mCheckboxPanel->setValue( opts );
3439QVariant QgsProcessingEnumWidgetWrapper::widgetValue()
const
3442 return mComboBox->currentData();
3444 return mPanel->value();
3445 else if ( mCheckboxPanel )
3446 return mCheckboxPanel->value();
3451QString QgsProcessingEnumWidgetWrapper::modelerExpressionFormatString()
const
3453 return tr(
"selected option index (starting from 0), array of indices, or comma separated string of options (e.g. '1,3')" );
3456QString QgsProcessingEnumWidgetWrapper::parameterType()
const
3463 return new QgsProcessingEnumWidgetWrapper( parameter, type );
3470 return new QgsProcessingEnumParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3481QWidget *QgsProcessingLayoutWidgetWrapper::createWidget()
3493 mComboBox =
new QgsLayoutComboBox(
nullptr, widgetContext().project() ? widgetContext().project()->layoutManager() :
nullptr );
3495 mComboBox->setAllowEmptyLayout(
true );
3498 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3505 mPlainComboBox =
new QComboBox();
3506 mPlainComboBox->setEditable(
true );
3507 mPlainComboBox->setToolTip( tr(
"Name of an existing print layout" ) );
3508 if ( widgetContext().project() )
3512 mPlainComboBox->addItem( layout->name() );
3515 connect( mPlainComboBox, &QComboBox::currentTextChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
3516 return mPlainComboBox;
3522void QgsProcessingLayoutWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3526 if ( !value.isValid() )
3527 mComboBox->setCurrentLayout(
nullptr );
3531 mComboBox->setCurrentLayout( l );
3533 mComboBox->setCurrentLayout(
nullptr );
3536 else if ( mPlainComboBox )
3539 mPlainComboBox->setCurrentText( v );
3543QVariant QgsProcessingLayoutWidgetWrapper::widgetValue()
const
3548 return l ? l->
name() : QVariant();
3550 else if ( mPlainComboBox )
3551 return mPlainComboBox->currentText().isEmpty() ? QVariant() : mPlainComboBox->currentText();
3559 if ( mPlainComboBox && context.
project() )
3563 mPlainComboBox->addItem( layout->name() );
3567QString QgsProcessingLayoutWidgetWrapper::modelerExpressionFormatString()
const
3569 return tr(
"string representing the name of an existing print layout" );
3572QString QgsProcessingLayoutWidgetWrapper::parameterType()
const
3579 return new QgsProcessingLayoutWidgetWrapper( parameter, type );
3588QgsProcessingLayoutItemParameterDefinitionWidget::QgsProcessingLayoutItemParameterDefinitionWidget(
3593 QVBoxLayout *vlayout =
new QVBoxLayout();
3594 vlayout->setContentsMargins( 0, 0, 0, 0 );
3596 vlayout->addWidget(
new QLabel( tr(
"Parent layout" ) ) );
3598 mParentLayoutComboBox =
new QComboBox();
3599 QString initialParent;
3601 initialParent = itemParam->parentLayoutParameterName();
3603 if (
auto *lModel = widgetContext.
model() )
3606 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3607 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3611 mParentLayoutComboBox->addItem( definition->
description(), definition->
name() );
3612 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
3614 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3620 if ( mParentLayoutComboBox->count() == 0 && !initialParent.isEmpty() )
3623 mParentLayoutComboBox->addItem( initialParent, initialParent );
3624 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3627 vlayout->addWidget( mParentLayoutComboBox );
3631 setLayout( vlayout );
3635 auto param = std::make_unique<QgsProcessingParameterLayoutItem>( name, description, QVariant(), mParentLayoutComboBox->currentData().toString() );
3637 return param.release();
3645QWidget *QgsProcessingLayoutItemWidgetWrapper::createWidget()
3659 mComboBox->setAllowEmptyItem(
true );
3660 if ( layoutParam->
itemType() >= 0 )
3663 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3670 mLineEdit =
new QLineEdit();
3671 mLineEdit->setToolTip( tr(
"UUID or ID of an existing print layout item" ) );
3672 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
3679void QgsProcessingLayoutItemWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3704void QgsProcessingLayoutItemWidgetWrapper::setLayoutParameterValue(
const QVariant &value )
3710 std::unique_ptr<QgsProcessingContext> tmpContext;
3711 if ( mProcessingContextGenerator )
3712 context = mProcessingContextGenerator->processingContext();
3716 tmpContext = std::make_unique<QgsProcessingContext>();
3717 context = tmpContext.get();
3721 setLayout( layout );
3724void QgsProcessingLayoutItemWidgetWrapper::setLayout(
QgsPrintLayout *layout )
3727 mComboBox->setCurrentLayout( layout );
3730void QgsProcessingLayoutItemWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3734 if ( !value.isValid() )
3735 mComboBox->setItem(
nullptr );
3739 mComboBox->setItem( item );
3742 else if ( mLineEdit )
3745 mLineEdit->setText( v );
3749QVariant QgsProcessingLayoutItemWidgetWrapper::widgetValue()
const
3754 return i ? i->
uuid() : QVariant();
3756 else if ( mLineEdit )
3757 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3763QString QgsProcessingLayoutItemWidgetWrapper::modelerExpressionFormatString()
const
3765 return tr(
"string representing the UUID or ID of an existing print layout item" );
3768QString QgsProcessingLayoutItemWidgetWrapper::parameterType()
const
3775 return new QgsProcessingLayoutItemWidgetWrapper( parameter, type );
3782 return new QgsProcessingLayoutItemParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3789QgsProcessingPointMapTool::QgsProcessingPointMapTool(
QgsMapCanvas *canvas )
3793 mSnapIndicator = std::make_unique<QgsSnapIndicator>( canvas );
3796QgsProcessingPointMapTool::~QgsProcessingPointMapTool() =
default;
3798void QgsProcessingPointMapTool::deactivate()
3812 if ( e->button() == Qt::LeftButton )
3815 emit clicked( point );
3820void QgsProcessingPointMapTool::keyPressEvent( QKeyEvent *e )
3822 if ( e->key() == Qt::Key_Escape )
3835QgsProcessingPointPanel::QgsProcessingPointPanel( QWidget *parent )
3838 QHBoxLayout *l =
new QHBoxLayout();
3839 l->setContentsMargins( 0, 0, 0, 0 );
3841 mLineEdit->setShowClearButton(
false );
3842 l->addWidget( mLineEdit, 1 );
3843 mButton =
new QToolButton();
3844 mButton->setText( QString( QChar( 0x2026 ) ) );
3845 l->addWidget( mButton );
3848 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::changed );
3849 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::textChanged );
3850 connect( mButton, &QToolButton::clicked,
this, &QgsProcessingPointPanel::selectOnCanvas );
3851 mButton->setVisible(
false );
3854QgsProcessingPointPanel::~QgsProcessingPointPanel()
3856 if ( mCanvas && mPrevTool && mCanvas->mapTool() == mTool.get() )
3858 mCanvas->setMapTool( mPrevTool.get() );
3862void QgsProcessingPointPanel::setMapCanvas(
QgsMapCanvas *canvas )
3865 if ( mAllowSelectOnCanvas )
3867 mButton->setVisible(
true );
3870 mTool = std::make_unique<QgsProcessingPointMapTool>( mCanvas );
3871 connect( mTool.get(), &QgsProcessingPointMapTool::clicked,
this, &QgsProcessingPointPanel::updatePoint );
3872 connect( mTool.get(), &QgsProcessingPointMapTool::complete,
this, &QgsProcessingPointPanel::pointPicked );
3876void QgsProcessingPointPanel::setAllowNull(
bool allowNull )
3878 mLineEdit->setShowClearButton( allowNull );
3881void QgsProcessingPointPanel::setShowPointOnCanvas(
bool show )
3883 if ( mShowPointOnCanvas == show )
3886 mShowPointOnCanvas = show;
3887 if ( mShowPointOnCanvas )
3893 mMapPointRubberBand.reset();
3897void QgsProcessingPointPanel::setAllowSelectOnCanvas(
bool allow )
3899 mAllowSelectOnCanvas = allow;
3900 mButton->setVisible( mAllowSelectOnCanvas &&
static_cast<bool>( mTool ) );
3903QVariant QgsProcessingPointPanel::value()
const
3905 return mLineEdit->showClearButton() && mLineEdit->text().trimmed().isEmpty() ? QVariant() : QVariant( mLineEdit->text() );
3908void QgsProcessingPointPanel::clear()
3916 QString newText = u
"%1,%2"_s.arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) );
3919 if ( mCrs.isValid() )
3921 newText += u
" [%1]"_s.arg( mCrs.authid() );
3923 mLineEdit->setText( newText );
3927void QgsProcessingPointPanel::showEvent( QShowEvent * )
3932 if ( QWidget *parentWindow = window() )
3934 setAllowSelectOnCanvas( !parentWindow->isModal() );
3940void QgsProcessingPointPanel::selectOnCanvas()
3945 mPrevTool = mCanvas->mapTool();
3946 mCanvas->setMapTool( mTool.get() );
3948 emit toggleDialogVisibility(
false );
3951void QgsProcessingPointPanel::updatePoint(
const QgsPointXY &point )
3953 setValue( point, mCanvas->mapSettings().destinationCrs() );
3956void QgsProcessingPointPanel::pointPicked()
3961 mCanvas->setMapTool( mPrevTool );
3963 emit toggleDialogVisibility(
true );
3966void QgsProcessingPointPanel::textChanged(
const QString &text )
3968 const thread_local QRegularExpression rx( u
"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
3970 const QRegularExpressionMatch match = rx.match( text );
3971 if ( match.hasMatch() )
3974 const double x = match.captured( 1 ).toDouble( &xOk );
3976 const double y = match.captured( 2 ).toDouble( &yOk );
3983 if ( pointCrs.isValid() )
4001void QgsProcessingPointPanel::updateRubberBand()
4003 if ( !mShowPointOnCanvas || !mCanvas )
4006 if ( mPoint.isEmpty() )
4008 mMapPointRubberBand.reset();
4012 if ( !mMapPointRubberBand )
4015 mMapPointRubberBand->setZValue( 1000 );
4018 const double scaleFactor = mCanvas->fontMetrics().xHeight() * .4;
4019 mMapPointRubberBand->setWidth( scaleFactor );
4020 mMapPointRubberBand->setIconSize( scaleFactor * 5 );
4022 mMapPointRubberBand->setSecondaryStrokeColor( QColor( 255, 255, 255, 100 ) );
4023 mMapPointRubberBand->setColor( QColor( 200, 0, 200 ) );
4034QgsProcessingPointParameterDefinitionWidget::QgsProcessingPointParameterDefinitionWidget(
4039 QVBoxLayout *vlayout =
new QVBoxLayout();
4040 vlayout->setContentsMargins( 0, 0, 0, 0 );
4042 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4044 mDefaultLineEdit =
new QLineEdit();
4045 mDefaultLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
4046 mDefaultLineEdit->setPlaceholderText( tr(
"Point as 'x,y'" ) );
4050 mDefaultLineEdit->setText( u
"%1,%2"_s.arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) ) );
4053 vlayout->addWidget( mDefaultLineEdit );
4057 setLayout( vlayout );
4062 auto param = std::make_unique<QgsProcessingParameterPoint>( name, description, mDefaultLineEdit->text() );
4064 return param.release();
4071QWidget *QgsProcessingPointWidgetWrapper::createWidget()
4082 mPanel =
new QgsProcessingPointPanel(
nullptr );
4083 if ( widgetContext().mapCanvas() )
4084 mPanel->setMapCanvas( widgetContext().mapCanvas() );
4087 mPanel->setAllowNull(
true );
4090 mPanel->setShowPointOnCanvas(
true );
4092 mPanel->setToolTip( parameterDefinition()->toolTip() );
4094 connect( mPanel, &QgsProcessingPointPanel::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
4097 setDialog( mDialog );
4103 mLineEdit =
new QLineEdit();
4104 mLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
4105 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
4116 mPanel->setMapCanvas( context.
mapCanvas() );
4119void QgsProcessingPointWidgetWrapper::setDialog( QWidget *dialog )
4124 connect( mPanel, &QgsProcessingPointPanel::toggleDialogVisibility, mDialog, [
this](
bool visible ) {
4126 mDialog->showMinimized();
4129 mDialog->showNormal();
4131 mDialog->activateWindow();
4138void QgsProcessingPointWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4142 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) )
4148 mPanel->setValue( p, crs );
4151 else if ( mLineEdit )
4154 mLineEdit->setText( v );
4158QVariant QgsProcessingPointWidgetWrapper::widgetValue()
const
4162 return mPanel->value();
4164 else if ( mLineEdit )
4165 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
4170QString QgsProcessingPointWidgetWrapper::modelerExpressionFormatString()
const
4172 return tr(
"string of the format 'x,y' or a geometry value (centroid is used)" );
4175QString QgsProcessingPointWidgetWrapper::parameterType()
const
4182 return new QgsProcessingPointWidgetWrapper( parameter, type );
4189 return new QgsProcessingPointParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4198QgsProcessingGeometryParameterDefinitionWidget::QgsProcessingGeometryParameterDefinitionWidget(
4203 QVBoxLayout *vlayout =
new QVBoxLayout();
4204 vlayout->setContentsMargins( 0, 0, 0, 0 );
4206 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4218 vlayout->addWidget( mGeometryWidget );
4222 setLayout( vlayout );
4228 auto param = std::make_unique<QgsProcessingParameterGeometry>( name, description, geometry.
isEmpty() ? QVariant() : geometry.
asWkt() );
4230 return param.release();
4237QWidget *QgsProcessingGeometryWidgetWrapper::createWidget()
4246 mGeometryWidget->setToolTip( parameterDefinition()->toolTip() );
4248 return mGeometryWidget;
4254void QgsProcessingGeometryWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4256 if ( mGeometryWidget )
4265 mGeometryWidget->clearGeometry();
4270QVariant QgsProcessingGeometryWidgetWrapper::widgetValue()
const
4272 if ( mGeometryWidget )
4275 return geometry.
isEmpty() ? QVariant() : geometry.asWkt();
4283QString QgsProcessingGeometryWidgetWrapper::modelerExpressionFormatString()
const
4285 return tr(
"string in the Well-Known-Text format or a geometry value" );
4288QString QgsProcessingGeometryWidgetWrapper::parameterType()
const
4295 return new QgsProcessingGeometryWidgetWrapper( parameter, type );
4302 return new QgsProcessingGeometryParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4311QgsProcessingColorParameterDefinitionWidget::QgsProcessingColorParameterDefinitionWidget(
4316 QVBoxLayout *vlayout =
new QVBoxLayout();
4317 vlayout->setContentsMargins( 0, 0, 0, 0 );
4319 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4322 mDefaultColorButton->setShowNull(
true );
4323 mAllowOpacity =
new QCheckBox( tr(
"Allow opacity control" ) );
4329 mDefaultColorButton->setToNull();
4331 mDefaultColorButton->setColor(
c );
4332 mAllowOpacity->setChecked( colorParam->opacityEnabled() );
4336 mDefaultColorButton->setToNull();
4337 mAllowOpacity->setChecked(
true );
4343 vlayout->addWidget( mDefaultColorButton );
4344 vlayout->addWidget( mAllowOpacity );
4345 setLayout( vlayout );
4350 auto param = std::make_unique<QgsProcessingParameterColor>( name, description, mDefaultColorButton->color(), mAllowOpacity->isChecked() );
4352 return param.release();
4359QWidget *QgsProcessingColorWidgetWrapper::createWidget()
4372 mColorButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
4375 mColorButton->setShowNull(
true );
4378 mColorButton->setToolTip( parameterDefinition()->toolTip() );
4379 mColorButton->setColorDialogTitle( parameterDefinition()->description() );
4387 return mColorButton;
4393void QgsProcessingColorWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4397 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) || ( value.userType() == QMetaType::Type::QColor && !value.value<QColor>().isValid() ) )
4398 mColorButton->setToNull();
4402 if ( !
c.isValid() && mColorButton->showNull() )
4403 mColorButton->setToNull();
4405 mColorButton->setColor(
c );
4410QVariant QgsProcessingColorWidgetWrapper::widgetValue()
const
4413 return mColorButton->isNull() ? QVariant() : mColorButton->color();
4418QString QgsProcessingColorWidgetWrapper::modelerExpressionFormatString()
const
4420 return tr(
"color style string, e.g. #ff0000 or 255,0,0" );
4423QString QgsProcessingColorWidgetWrapper::parameterType()
const
4430 return new QgsProcessingColorWidgetWrapper( parameter, type );
4437 return new QgsProcessingColorParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4445QgsProcessingCoordinateOperationParameterDefinitionWidget::QgsProcessingCoordinateOperationParameterDefinitionWidget(
4450 QVBoxLayout *vlayout =
new QVBoxLayout();
4451 vlayout->setContentsMargins( 0, 0, 0, 0 );
4453 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4455 mDefaultLineEdit =
new QLineEdit();
4458 vlayout->addWidget( mDefaultLineEdit );
4462 mSourceParamComboBox =
new QComboBox();
4463 mDestParamComboBox =
new QComboBox();
4464 QString initialSource;
4465 QString initialDest;
4470 initialSource = itemParam->sourceCrsParameterName();
4471 initialDest = itemParam->destinationCrsParameterName();
4476 mSourceParamComboBox->addItem( QString(), QString() );
4477 mDestParamComboBox->addItem( QString(), QString() );
4478 if (
auto *lModel = widgetContext.
model() )
4481 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4482 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4484 if ( definition && it->parameterName() == definition->
name() )
4488 mSourceParamComboBox->addItem( it->parameterName(), it->parameterName() );
4489 mDestParamComboBox->addItem( it->parameterName(), it->parameterName() );
4490 if ( !initialSource.isEmpty() && initialSource == it->parameterName() )
4492 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
4494 if ( !initialDest.isEmpty() && initialDest == it->parameterName() )
4496 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
4501 if ( mSourceParamComboBox->count() == 1 && !initialSource.isEmpty() )
4504 mSourceParamComboBox->addItem( initialSource, initialSource );
4505 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
4507 if ( mDestParamComboBox->count() == 1 && !initialDest.isEmpty() )
4510 mDestParamComboBox->addItem( initialDest, initialDest );
4511 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
4514 vlayout->addWidget(
new QLabel( tr(
"Source CRS parameter" ) ) );
4515 vlayout->addWidget( mSourceParamComboBox );
4516 vlayout->addWidget(
new QLabel( tr(
"Destination CRS parameter" ) ) );
4517 vlayout->addWidget( mDestParamComboBox );
4524 mStaticSourceWidget->setCrs( sourceCrs );
4527 mStaticDestWidget->setCrs( destCrs );
4529 vlayout->addWidget(
new QLabel( tr(
"Static source CRS" ) ) );
4530 vlayout->addWidget( mStaticSourceWidget );
4531 vlayout->addWidget(
new QLabel( tr(
"Static destination CRS" ) ) );
4532 vlayout->addWidget( mStaticDestWidget );
4537 setLayout( vlayout );
4542 auto param = std::make_unique<QgsProcessingParameterCoordinateOperation>(
4545 mDefaultLineEdit->text(),
4546 mSourceParamComboBox->currentText(),
4547 mDestParamComboBox->currentText(),
4548 mStaticSourceWidget->crs().isValid() ? QVariant::fromValue( mStaticSourceWidget->crs() ) : QVariant(),
4549 mStaticDestWidget->crs().isValid() ? QVariant::fromValue( mStaticDestWidget->crs() ) : QVariant()
4552 return param.release();
4559QWidget *QgsProcessingCoordinateOperationWidgetWrapper::createWidget()
4573 mOperationWidget->setShowMakeDefault(
false );
4574 mOperationWidget->setShowFallbackOption(
false );
4575 mOperationWidget->setToolTip( parameterDefinition()->toolTip() );
4576 mOperationWidget->setSourceCrs( mSourceCrs );
4577 mOperationWidget->setDestinationCrs( mDestCrs );
4578 mOperationWidget->setMapCanvas( mCanvas );
4583 mOperationWidget->setSelectedOperation( deets );
4588 return mOperationWidget;
4594 mLineEdit =
new QLineEdit();
4595 QHBoxLayout *layout =
new QHBoxLayout();
4596 layout->addWidget( mLineEdit, 1 );
4597 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
4599 QToolButton *button =
new QToolButton();
4600 button->setText( QString( QChar( 0x2026 ) ) );
4601 connect( button, &QToolButton::clicked,
this, [
this, button] {
4602 QgsDatumTransformDialog dlg( mSourceCrs, mDestCrs,
false,
false,
false, qMakePair( -1, -1 ), button, Qt::WindowFlags(), mLineEdit->text(), mCanvas );
4605 mLineEdit->setText( dlg.selectedDatumTransform().proj );
4606 emit widgetValueHasChanged(
this );
4609 layout->addWidget( button );
4611 QWidget *w =
new QWidget();
4612 layout->setContentsMargins( 0, 0, 0, 0 );
4613 w->setLayout( layout );
4620void QgsProcessingCoordinateOperationWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
4652 if ( mOperationWidget )
4653 mOperationWidget->setMapCanvas( context.
mapCanvas() );
4656void QgsProcessingCoordinateOperationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
4658 if ( mOperationWidget )
4660 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString ) )
4663 deets.
proj = value.toString();
4664 mOperationWidget->setSelectedOperation( deets );
4669 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString ) )
4671 mLineEdit->setText( value.toString() );
4676QVariant QgsProcessingCoordinateOperationWidgetWrapper::widgetValue()
const
4678 if ( mOperationWidget )
4679 return mOperationWidget->selectedOperation().proj;
4680 else if ( mLineEdit )
4681 return mLineEdit->text();
4686QString QgsProcessingCoordinateOperationWidgetWrapper::modelerExpressionFormatString()
const
4688 return tr(
"Proj coordinate operation string, e.g. '+proj=pipeline +step +inv...'" );
4691void QgsProcessingCoordinateOperationWidgetWrapper::setSourceCrsParameterValue(
const QVariant &value )
4694 std::unique_ptr<QgsProcessingContext> tmpContext;
4695 if ( mProcessingContextGenerator )
4696 context = mProcessingContextGenerator->processingContext();
4700 tmpContext = std::make_unique<QgsProcessingContext>();
4701 context = tmpContext.get();
4705 if ( mOperationWidget )
4707 mOperationWidget->setSourceCrs( mSourceCrs );
4708 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4712void QgsProcessingCoordinateOperationWidgetWrapper::setDestinationCrsParameterValue(
const QVariant &value )
4715 std::unique_ptr<QgsProcessingContext> tmpContext;
4716 if ( mProcessingContextGenerator )
4717 context = mProcessingContextGenerator->processingContext();
4721 tmpContext = std::make_unique<QgsProcessingContext>();
4722 context = tmpContext.get();
4726 if ( mOperationWidget )
4728 mOperationWidget->setDestinationCrs( mDestCrs );
4729 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4733QString QgsProcessingCoordinateOperationWidgetWrapper::parameterType()
const
4740 return new QgsProcessingCoordinateOperationWidgetWrapper( parameter, type );
4747 return new QgsProcessingCoordinateOperationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4759 QHBoxLayout *hl =
new QHBoxLayout();
4760 hl->setContentsMargins( 0, 0, 0, 0 );
4762 mLineEdit =
new QLineEdit();
4763 mLineEdit->setEnabled(
false );
4764 hl->addWidget( mLineEdit, 1 );
4766 mToolButton =
new QToolButton();
4767 mToolButton->setText( QString( QChar( 0x2026 ) ) );
4768 hl->addWidget( mToolButton );
4774 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4777 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingFieldPanelWidget::showDialog );
4780void QgsProcessingFieldPanelWidget::setFields(
const QgsFields &fields )
4786 QVariantList availableFields;
4787 for (
const QgsField &field : std::as_const( mFields ) )
4789 availableFields << field.name();
4791 QList<QVariant>::iterator it = std::remove_if( mValue.begin(), mValue.end(), [&availableFields](
const QVariant &value ) { return !availableFields.contains( value ); } );
4792 mValue.erase( it, mValue.end() );
4794 updateSummaryText();
4798void QgsProcessingFieldPanelWidget::setValue(
const QVariant &value )
4800 if ( value.isValid() )
4801 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
4805 updateSummaryText();
4809void QgsProcessingFieldPanelWidget::showDialog()
4811 QVariantList availableOptions;
4812 availableOptions.reserve( mFields.size() );
4813 for (
const QgsField &field : std::as_const( mFields ) )
4815 availableOptions << field.name();
4821 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
4822 widget->setPanelTitle( mParam->description() );
4824 widget->setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
4826 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
4832 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
4834 dlg.setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
4837 setValue( dlg.selectedOptions() );
4842void QgsProcessingFieldPanelWidget::updateSummaryText()
4847 if ( mValue.empty() )
4849 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4854 values.reserve( mValue.size() );
4855 for (
const QVariant &val : std::as_const( mValue ) )
4857 values << val.toString();
4860 const QString concatenated = values.join( tr(
"," ) );
4861 if ( concatenated.length() < 100 )
4862 mLineEdit->setText( concatenated );
4864 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, mValue.count() ) );
4873QgsProcessingFieldParameterDefinitionWidget::QgsProcessingFieldParameterDefinitionWidget(
4878 QVBoxLayout *vlayout =
new QVBoxLayout();
4879 vlayout->setContentsMargins( 0, 0, 0, 0 );
4881 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
4882 mParentLayerComboBox =
new QComboBox();
4884 QString initialParent;
4886 initialParent = fieldParam->parentLayerParameterName();
4888 if (
auto *lModel = widgetContext.
model() )
4891 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4892 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4896 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4897 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4899 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4904 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4905 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4907 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4914 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4915 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4917 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4924 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
4927 mParentLayerComboBox->addItem( initialParent, initialParent );
4928 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4931 vlayout->addWidget( mParentLayerComboBox );
4934 vlayout->addWidget(
new QLabel( tr(
"Allowed data type" ) ) );
4935 mDataTypeComboBox =
new QComboBox();
4943 mDataTypeComboBox->setCurrentIndex( mDataTypeComboBox->findData(
static_cast<int>( fieldParam->dataType() ) ) );
4945 vlayout->addWidget( mDataTypeComboBox );
4948 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple fields" ) );
4950 mAllowMultipleCheckBox->setChecked( fieldParam->allowMultiple() );
4952 vlayout->addWidget( mAllowMultipleCheckBox );
4957 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all fields by default" ) );
4958 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
4960 mDefaultToAllCheckBox->setChecked( fieldParam->defaultToAllFields() );
4962 vlayout->addWidget( mDefaultToAllCheckBox );
4965 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [
this] { mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() ); } );
4967 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4969 mDefaultLineEdit =
new QLineEdit();
4970 mDefaultLineEdit->setToolTip( tr(
"Default field name, or ; separated list of field names for multiple field parameters" ) );
4974 mDefaultLineEdit->setText( fields.join(
';' ) );
4976 vlayout->addWidget( mDefaultLineEdit );
4980 setLayout( vlayout );
4987 QVariant defaultValue;
4988 if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
4990 defaultValue = mDefaultLineEdit->text();
4992 auto param = std::make_unique<
4993 QgsProcessingParameterField>( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), dataType, mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
4995 return param.release();
5002QWidget *QgsProcessingFieldWidgetWrapper::createWidget()
5015 mPanel =
new QgsProcessingFieldPanelWidget(
nullptr, fieldParam );
5016 mPanel->setToolTip( parameterDefinition()->toolTip() );
5017 connect( mPanel, &QgsProcessingFieldPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
5036 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5044 mLineEdit =
new QLineEdit();
5045 mLineEdit->setToolTip( QObject::tr(
"Name of field (separate field names with ; for multiple field parameters)" ) );
5046 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
5053void QgsProcessingFieldWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5065 setParentLayerWrapperValue( wrapper );
5082 std::unique_ptr<QgsProcessingContext> tmpContext;
5083 if ( mProcessingContextGenerator )
5084 context = mProcessingContextGenerator->processingContext();
5088 tmpContext = std::make_unique<QgsProcessingContext>();
5089 context = tmpContext.get();
5094 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
5104 bool valueSet =
false;
5108 if ( layers.count() > 1 )
5110 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layers.at( 0 ) );
5112 const QList<QgsMapLayer *> remainingLayers = layers.mid( 1 );
5118 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
5119 if ( !vlayer || !vlayer->
isValid() )
5125 for (
int fieldIdx = fields.
count() - 1; fieldIdx >= 0; fieldIdx-- )
5128 fields.
remove( fieldIdx );
5133 mComboBox->setFields( fields );
5135 mPanel->setFields( filterFields( fields ) );
5141 if ( !valueSet && !layers.isEmpty() && layers.at( 0 )->isValid() )
5143 QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( layers.at( 0 ) );
5147 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
5150 mParentLayer.reset( qobject_cast<QgsVectorLayer *>( ownedLayer.release() ) );
5151 layer = mParentLayer.get();
5159 mComboBox->setLayer( layer );
5161 mPanel->setFields( filterFields( layer->
fields() ) );
5171 const QgsFields fields = source->fields();
5173 mComboBox->setFields( fields );
5175 mPanel->setFields( filterFields( fields ) );
5184 mComboBox->setLayer(
nullptr );
5188 if ( value.isValid() && widgetContext().messageBar() )
5200 val.reserve( mPanel->fields().size() );
5201 for (
const QgsField &field : mPanel->fields() )
5202 val << field.name();
5203 setWidgetValue( val, *context );
5206 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5209void QgsProcessingFieldWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5213 if ( !value.isValid() )
5214 mComboBox->setField( QString() );
5218 mComboBox->setField( v );
5224 if ( value.isValid() )
5227 opts.reserve( v.size() );
5228 for (
const QString &i : v )
5232 mPanel->setValue( opts );
5234 else if ( mLineEdit )
5240 mLineEdit->setText( v.join(
';' ) );
5249QVariant QgsProcessingFieldWidgetWrapper::widgetValue()
const
5252 return mComboBox->currentField();
5254 return mPanel->value();
5255 else if ( mLineEdit )
5260 return mLineEdit->text().split(
';' );
5263 return mLineEdit->text();
5269QString QgsProcessingFieldWidgetWrapper::modelerExpressionFormatString()
const
5271 return tr(
"selected field names as an array of names, or semicolon separated string of options (e.g. 'fid;place_name')" );
5274const QgsVectorLayer *QgsProcessingFieldWidgetWrapper::linkedVectorLayer()
const
5276 if ( mComboBox && mComboBox->layer() )
5277 return mComboBox->layer();
5282QgsFields QgsProcessingFieldWidgetWrapper::filterFields(
const QgsFields &fields )
const
5295 if ( f.isNumeric() )
5300 if ( f.type() == QMetaType::Type::QString )
5305 if ( f.type() == QMetaType::Type::QDate || f.type() == QMetaType::Type::QTime || f.type() == QMetaType::Type::QDateTime )
5310 if ( f.type() == QMetaType::Type::QByteArray )
5315 if ( f.type() == QMetaType::Type::Bool )
5324QString QgsProcessingFieldWidgetWrapper::parameterType()
const
5331 return new QgsProcessingFieldWidgetWrapper( parameter, type );
5338 return new QgsProcessingFieldParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5346QgsProcessingMapThemeParameterDefinitionWidget::QgsProcessingMapThemeParameterDefinitionWidget(
5351 QVBoxLayout *vlayout =
new QVBoxLayout();
5352 vlayout->setContentsMargins( 0, 0, 0, 0 );
5354 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5356 mDefaultComboBox =
new QComboBox();
5357 mDefaultComboBox->addItem( QString(), QVariant( -1 ) );
5360 for (
const QString &theme : mapThemes )
5364 mDefaultComboBox->setEditable(
true );
5368 if ( themeParam->defaultValueForGui().isValid() )
5371 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
5374 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
5376 vlayout->addWidget( mDefaultComboBox );
5380 setLayout( vlayout );
5385 QVariant defaultVal;
5386 if ( mDefaultComboBox->currentText().isEmpty() )
5387 defaultVal = QVariant();
5389 defaultVal = mDefaultComboBox->currentText();
5390 auto param = std::make_unique<QgsProcessingParameterMapTheme>( name, description, defaultVal );
5392 return param.release();
5400QWidget *QgsProcessingMapThemeWidgetWrapper::createWidget()
5406 mComboBox =
new QComboBox();
5409 mComboBox->addItem( tr(
"[Not selected]" ), QVariant( -1 ) );
5412 for (
const QString &theme : mapThemes )
5424 mComboBox->setEditable(
true );
5428 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5429 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
5434void QgsProcessingMapThemeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5438 if ( !value.isValid() )
5439 mComboBox->setCurrentIndex( mComboBox->findData( QVariant( -1 ) ) );
5442 if ( mComboBox->isEditable() && mComboBox->findData( v ) == -1 )
5444 const QString prev = mComboBox->currentText();
5445 mComboBox->setCurrentText( v );
5447 emit widgetValueHasChanged(
this );
5450 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
5454QVariant QgsProcessingMapThemeWidgetWrapper::widgetValue()
const
5457 return mComboBox->currentData().toInt() == -1 ? QVariant()
5458 : !mComboBox->currentData().isValid() && mComboBox->isEditable() ? mComboBox->currentText().isEmpty() ? QVariant() : QVariant( mComboBox->currentText() )
5459 : mComboBox->currentData();
5464QString QgsProcessingMapThemeWidgetWrapper::modelerExpressionFormatString()
const
5466 return tr(
"map theme as a string value (e.g. 'base maps')" );
5469QString QgsProcessingMapThemeWidgetWrapper::parameterType()
const
5476 return new QgsProcessingMapThemeWidgetWrapper( parameter, type );
5483 return new QgsProcessingMapThemeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5492QgsProcessingDateTimeParameterDefinitionWidget::QgsProcessingDateTimeParameterDefinitionWidget(
5497 QVBoxLayout *vlayout =
new QVBoxLayout();
5498 vlayout->setContentsMargins( 0, 0, 0, 0 );
5500 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
5502 mTypeComboBox =
new QComboBox();
5507 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( datetimeParam->dataType() ) ) );
5509 mTypeComboBox->setCurrentIndex( 0 );
5510 vlayout->addWidget( mTypeComboBox );
5514 setLayout( vlayout );
5519 auto param = std::make_unique<QgsProcessingParameterDateTime>( name, description );
5522 return param.release();
5530QWidget *QgsProcessingDateTimeWidgetWrapper::createWidget()
5533 if ( !dateTimeParam )
5537 switch ( dateTimeParam->
dataType() )
5541 widget = mDateTimeEdit;
5566 widget->setToolTip( parameterDefinition()->toolTip() );
5568 if ( mDateTimeEdit )
5572 else if ( mDateEdit )
5576 else if ( mTimeEdit )
5588 return new QgsProcessingDateTimeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5591void QgsProcessingDateTimeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5593 if ( mDateTimeEdit )
5597 else if ( mDateEdit )
5601 else if ( mTimeEdit )
5607QVariant QgsProcessingDateTimeWidgetWrapper::widgetValue()
const
5609 if ( mDateTimeEdit )
5610 return !mDateTimeEdit->dateTime().isNull() && mDateTimeEdit->dateTime().isValid() ? QVariant( mDateTimeEdit->dateTime() ) : QVariant();
5611 else if ( mDateEdit )
5612 return !mDateEdit->date().isNull() && mDateEdit->date().isValid() ? QVariant( mDateEdit->date() ) : QVariant();
5613 else if ( mTimeEdit )
5614 return !mTimeEdit->time().isNull() && mTimeEdit->time().isValid() ? QVariant( mTimeEdit->time() ) : QVariant();
5619QString QgsProcessingDateTimeWidgetWrapper::modelerExpressionFormatString()
const
5622 if ( dateTimeParam )
5624 switch ( dateTimeParam->
dataType() )
5627 return tr(
"datetime value, or a ISO string representation of a datetime" );
5630 return tr(
"date value, or a ISO string representation of a date" );
5633 return tr(
"time value, or a ISO string representation of a time" );
5639QString QgsProcessingDateTimeWidgetWrapper::parameterType()
const
5646 return new QgsProcessingDateTimeWidgetWrapper( parameter, type );
5654QgsProcessingProviderConnectionParameterDefinitionWidget::QgsProcessingProviderConnectionParameterDefinitionWidget(
5661 QVBoxLayout *vlayout =
new QVBoxLayout();
5662 vlayout->setContentsMargins( 0, 0, 0, 0 );
5664 vlayout->addWidget(
new QLabel( tr(
"Provider" ) ) );
5665 mProviderComboBox =
new QComboBox();
5666 mProviderComboBox->addItem( QObject::tr(
"Postgres" ), u
"postgres"_s );
5667 mProviderComboBox->addItem( QObject::tr(
"GeoPackage" ), u
"ogr"_s );
5668 mProviderComboBox->addItem( QObject::tr(
"Spatialite" ), u
"spatialite"_s );
5670 vlayout->addWidget( mProviderComboBox );
5672 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5674 mDefaultEdit =
new QLineEdit();
5675 vlayout->addWidget( mDefaultEdit );
5676 setLayout( vlayout );
5678 if ( connectionParam )
5680 mProviderComboBox->setCurrentIndex( mProviderComboBox->findData( connectionParam->
providerId() ) );
5690 QVariant defaultVal;
5691 if ( mDefaultEdit->text().isEmpty() )
5692 defaultVal = QVariant();
5694 defaultVal = mDefaultEdit->text();
5695 auto param = std::make_unique<QgsProcessingParameterProviderConnection>( name, description, mProviderComboBox->currentData().toString(), defaultVal );
5697 return param.release();
5705QWidget *QgsProcessingProviderConnectionWidgetWrapper::createWidget()
5708 if ( !connectionParam )
5713 mProviderComboBox->setAllowEmptyConnection(
true );
5721 mProviderComboBox->setEditable(
true );
5725 mProviderComboBox->setToolTip( parameterDefinition()->toolTip() );
5726 connect( mProviderComboBox, &QgsProviderConnectionComboBox::currentTextChanged,
this, [
this](
const QString & ) {
5727 if ( mBlockSignals )
5730 emit widgetValueHasChanged(
this );
5733 return mProviderComboBox;
5740 return new QgsProcessingProviderConnectionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5743void QgsProcessingProviderConnectionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5747 if ( !value.isValid() )
5748 mProviderComboBox->setCurrentIndex( -1 );
5751 if ( mProviderComboBox->isEditable() )
5753 const QString prev = mProviderComboBox->currentText();
5755 mProviderComboBox->setConnection( v );
5756 mProviderComboBox->setCurrentText( v );
5760 emit widgetValueHasChanged(
this );
5763 mProviderComboBox->setConnection( v );
5767QVariant QgsProcessingProviderConnectionWidgetWrapper::widgetValue()
const
5769 if ( mProviderComboBox )
5770 if ( mProviderComboBox->isEditable() )
5771 return mProviderComboBox->currentText().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentText() );
5773 return mProviderComboBox->currentConnection().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentConnection() );
5778QString QgsProcessingProviderConnectionWidgetWrapper::modelerExpressionFormatString()
const
5780 return tr(
"connection name as a string value" );
5783QString QgsProcessingProviderConnectionWidgetWrapper::parameterType()
const
5790 return new QgsProcessingProviderConnectionWidgetWrapper( parameter, type );
5798QgsProcessingDatabaseSchemaParameterDefinitionWidget::QgsProcessingDatabaseSchemaParameterDefinitionWidget(
5805 QVBoxLayout *vlayout =
new QVBoxLayout();
5806 vlayout->setContentsMargins( 0, 0, 0, 0 );
5808 mConnectionParamComboBox =
new QComboBox();
5809 QString initialConnection;
5815 if (
auto *lModel = widgetContext.
model() )
5818 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
5819 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
5821 if ( definition && it->parameterName() == definition->
name() )
5827 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
5828 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5830 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5835 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
5838 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
5839 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5842 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
5843 vlayout->addWidget( mConnectionParamComboBox );
5847 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5849 mDefaultEdit =
new QLineEdit();
5850 vlayout->addWidget( mDefaultEdit );
5851 setLayout( vlayout );
5862 QVariant defaultVal;
5863 if ( mDefaultEdit->text().isEmpty() )
5864 defaultVal = QVariant();
5866 defaultVal = mDefaultEdit->text();
5867 auto param = std::make_unique<QgsProcessingParameterDatabaseSchema>( name, description, mConnectionParamComboBox->currentData().toString(), defaultVal );
5869 return param.release();
5877QWidget *QgsProcessingDatabaseSchemaWidgetWrapper::createWidget()
5885 mSchemaComboBox->setAllowEmptySchema(
true );
5893 mSchemaComboBox->comboBox()->setEditable(
true );
5897 mSchemaComboBox->setToolTip( parameterDefinition()->toolTip() );
5898 connect( mSchemaComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [
this](
const QString & ) {
5899 if ( mBlockSignals )
5902 emit widgetValueHasChanged( this );
5905 return mSchemaComboBox;
5912 return new QgsProcessingDatabaseSchemaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5919 std::unique_ptr<QgsProcessingContext> tmpContext;
5920 if ( mProcessingContextGenerator )
5921 context = mProcessingContextGenerator->processingContext();
5925 tmpContext = std::make_unique<QgsProcessingContext>();
5926 context = tmpContext.get();
5932 if ( mSchemaComboBox )
5933 mSchemaComboBox->setConnectionName( connection, qgis::down_cast<const QgsProcessingParameterProviderConnection *>( parentWrapper->
parameterDefinition() )->providerId() );
5937 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5940void QgsProcessingDatabaseSchemaWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5944 if ( !value.isValid() )
5945 mSchemaComboBox->comboBox()->setCurrentIndex( -1 );
5948 if ( mSchemaComboBox->comboBox()->isEditable() )
5950 const QString prev = mSchemaComboBox->comboBox()->currentText();
5952 mSchemaComboBox->setSchema( v );
5953 mSchemaComboBox->comboBox()->setCurrentText( v );
5957 emit widgetValueHasChanged(
this );
5960 mSchemaComboBox->setSchema( v );
5964QVariant QgsProcessingDatabaseSchemaWidgetWrapper::widgetValue()
const
5966 if ( mSchemaComboBox )
5967 if ( mSchemaComboBox->comboBox()->isEditable() )
5968 return mSchemaComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->comboBox()->currentText() );
5970 return mSchemaComboBox->currentSchema().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->currentSchema() );
5975QString QgsProcessingDatabaseSchemaWidgetWrapper::modelerExpressionFormatString()
const
5977 return tr(
"database schema name as a string value" );
5980QString QgsProcessingDatabaseSchemaWidgetWrapper::parameterType()
const
5987 return new QgsProcessingDatabaseSchemaWidgetWrapper( parameter, type );
5990void QgsProcessingDatabaseSchemaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6002 setParentConnectionWrapperValue( wrapper );
6020QgsProcessingDatabaseTableParameterDefinitionWidget::QgsProcessingDatabaseTableParameterDefinitionWidget(
6027 QVBoxLayout *vlayout =
new QVBoxLayout();
6028 vlayout->setContentsMargins( 0, 0, 0, 0 );
6030 mConnectionParamComboBox =
new QComboBox();
6031 mSchemaParamComboBox =
new QComboBox();
6032 QString initialConnection;
6033 QString initialSchema;
6040 if (
auto *lModel = widgetContext.
model() )
6043 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6044 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6046 if ( definition && it->parameterName() == definition->
name() )
6051 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
6052 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
6054 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
6059 mSchemaParamComboBox->addItem( it->parameterName(), it->parameterName() );
6060 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
6062 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
6068 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
6071 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
6072 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
6075 if ( mSchemaParamComboBox->count() == 0 && !initialSchema.isEmpty() )
6078 mSchemaParamComboBox->addItem( initialSchema, initialSchema );
6079 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
6082 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
6083 vlayout->addWidget( mConnectionParamComboBox );
6085 vlayout->addWidget(
new QLabel( tr(
"Database schema parameter" ) ) );
6086 vlayout->addWidget( mSchemaParamComboBox );
6091 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6093 mDefaultEdit =
new QLineEdit();
6094 vlayout->addWidget( mDefaultEdit );
6095 setLayout( vlayout );
6106 QVariant defaultVal;
6107 if ( mDefaultEdit->text().isEmpty() )
6108 defaultVal = QVariant();
6110 defaultVal = mDefaultEdit->text();
6111 auto param = std::make_unique<QgsProcessingParameterDatabaseTable>( name, description, mConnectionParamComboBox->currentData().toString(), mSchemaParamComboBox->currentData().toString(), defaultVal );
6113 return param.release();
6121QWidget *QgsProcessingDatabaseTableWidgetWrapper::createWidget()
6129 mTableComboBox->setAllowEmptyTable(
true );
6132 mTableComboBox->comboBox()->setEditable(
true );
6134 mTableComboBox->setToolTip( parameterDefinition()->toolTip() );
6135 connect( mTableComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [
this](
const QString & ) {
6136 if ( mBlockSignals )
6139 emit widgetValueHasChanged( this );
6142 return mTableComboBox;
6149 return new QgsProcessingDatabaseTableParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6156 std::unique_ptr<QgsProcessingContext> tmpContext;
6157 if ( mProcessingContextGenerator )
6158 context = mProcessingContextGenerator->processingContext();
6162 tmpContext = std::make_unique<QgsProcessingContext>();
6163 context = tmpContext.get();
6168 mProvider = qgis::down_cast<const QgsProcessingParameterProviderConnection *>( parentWrapper->
parameterDefinition() )->providerId();
6169 if ( mTableComboBox && !mSchema.isEmpty() )
6171 mTableComboBox->setSchema( mSchema );
6172 mTableComboBox->setConnectionName( mConnection, mProvider );
6176 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6184 std::unique_ptr<QgsProcessingContext> tmpContext;
6185 if ( mProcessingContextGenerator )
6186 context = mProcessingContextGenerator->processingContext();
6190 tmpContext = std::make_unique<QgsProcessingContext>();
6191 context = tmpContext.get();
6197 if ( mTableComboBox && !mSchema.isEmpty() && !mConnection.isEmpty() )
6199 mTableComboBox->setSchema( mSchema );
6200 mTableComboBox->setConnectionName( mConnection, mProvider );
6202 const QgsProcessingParameterDatabaseTable *tableParam = static_cast<const QgsProcessingParameterDatabaseTable *>( parameterDefinition() );
6203 if ( tableParam->defaultValueForGui().isValid() )
6204 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6208void QgsProcessingDatabaseTableWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6212 if ( !value.isValid() )
6213 mTableComboBox->comboBox()->setCurrentIndex( -1 );
6216 if ( mTableComboBox->comboBox()->isEditable() )
6218 const QString prev = mTableComboBox->comboBox()->currentText();
6220 mTableComboBox->setTable( v );
6221 mTableComboBox->comboBox()->setCurrentText( v );
6225 emit widgetValueHasChanged(
this );
6228 mTableComboBox->setTable( v );
6232QVariant QgsProcessingDatabaseTableWidgetWrapper::widgetValue()
const
6234 if ( mTableComboBox )
6235 if ( mTableComboBox->comboBox()->isEditable() )
6236 return mTableComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mTableComboBox->comboBox()->currentText() );
6238 return mTableComboBox->currentTable().isEmpty() ? QVariant() : QVariant( mTableComboBox->currentTable() );
6243QString QgsProcessingDatabaseTableWidgetWrapper::modelerExpressionFormatString()
const
6245 return tr(
"database table name as a string value" );
6248QString QgsProcessingDatabaseTableWidgetWrapper::parameterType()
const
6255 return new QgsProcessingDatabaseTableWidgetWrapper( parameter, type );
6258void QgsProcessingDatabaseTableWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6270 setParentConnectionWrapperValue( wrapper );
6275 setParentSchemaWrapperValue( wrapper );
6292QgsProcessingExtentParameterDefinitionWidget::QgsProcessingExtentParameterDefinitionWidget(
6297 QVBoxLayout *vlayout =
new QVBoxLayout();
6298 vlayout->setContentsMargins( 0, 0, 0, 0 );
6300 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6303 mDefaultWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
6306 if ( extentParam->defaultValueForGui().isValid() )
6310 mDefaultWidget->setCurrentExtent( rect, crs );
6311 mDefaultWidget->setOutputExtentFromCurrent();
6315 mDefaultWidget->clear();
6321 vlayout->addWidget( mDefaultWidget );
6322 setLayout( vlayout );
6327 const QString defaultVal = mDefaultWidget->isValid() ? u
"%1,%2,%3,%4%5"_s.arg(
6328 QString::number( mDefaultWidget->outputExtent().xMinimum(),
'f', 9 ),
6329 QString::number( mDefaultWidget->outputExtent().xMaximum(),
'f', 9 ),
6330 QString::number( mDefaultWidget->outputExtent().yMinimum(),
'f', 9 ),
6331 QString::number( mDefaultWidget->outputExtent().yMaximum(),
'f', 9 ),
6332 mDefaultWidget->outputCrs().isValid() ? u
" [%1]"_s.arg( mDefaultWidget->outputCrs().authid() ) : QString()
6335 auto param = std::make_unique<QgsProcessingParameterExtent>( name, description, !defaultVal.isEmpty() ? QVariant( defaultVal ) : QVariant() );
6337 return param.release();
6345QWidget *QgsProcessingExtentWidgetWrapper::createWidget()
6358 if ( widgetContext().mapCanvas() )
6359 mExtentWidget->setMapCanvas( widgetContext().mapCanvas() );
6362 mExtentWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
6364 mExtentWidget->setToolTip( parameterDefinition()->toolTip() );
6369 setDialog( mDialog );
6371 return mExtentWidget;
6381 mExtentWidget->setMapCanvas( context.
mapCanvas() );
6384void QgsProcessingExtentWidgetWrapper::setDialog( QWidget *dialog )
6391 mDialog->showMinimized();
6394 mDialog->showNormal();
6396 mDialog->activateWindow();
6403void QgsProcessingExtentWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6405 if ( mExtentWidget )
6407 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) )
6408 mExtentWidget->clear();
6413 mExtentWidget->setCurrentExtent( r, crs );
6414 mExtentWidget->setOutputExtentFromUser( r, crs );
6419QVariant QgsProcessingExtentWidgetWrapper::widgetValue()
const
6421 if ( mExtentWidget )
6423 const QString val = mExtentWidget->isValid() ? u
"%1,%2,%3,%4%5"_s.arg(
6424 QString::number( mExtentWidget->outputExtent().xMinimum(),
'f', 9 ),
6425 QString::number( mExtentWidget->outputExtent().xMaximum(),
'f', 9 ),
6426 QString::number( mExtentWidget->outputExtent().yMinimum(),
'f', 9 ),
6427 QString::number( mExtentWidget->outputExtent().yMaximum(),
'f', 9 ),
6428 mExtentWidget->outputCrs().isValid() ? u
" [%1]"_s.arg( mExtentWidget->outputCrs().authid() ) : QString()
6432 return val.isEmpty() ? QVariant() : QVariant( val );
6438QString QgsProcessingExtentWidgetWrapper::modelerExpressionFormatString()
const
6440 return tr(
"string of the format 'x min,x max,y min,y max' or a geometry value (bounding box is used)" );
6443QString QgsProcessingExtentWidgetWrapper::parameterType()
const
6450 return new QgsProcessingExtentWidgetWrapper( parameter, type );
6457 return new QgsProcessingExtentParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6465QgsProcessingMapLayerParameterDefinitionWidget::QgsProcessingMapLayerParameterDefinitionWidget(
6470 QVBoxLayout *vlayout =
new QVBoxLayout();
6471 vlayout->setContentsMargins( 0, 0, 0, 0 );
6473 vlayout->addWidget(
new QLabel( tr(
"Layer type" ) ) );
6489 for (
int i : layerParam->dataTypes() )
6491 mLayerTypeComboBox->setItemCheckState( mLayerTypeComboBox->findData( i ), Qt::Checked );
6495 vlayout->addWidget( mLayerTypeComboBox );
6499 setLayout( vlayout );
6504 QList<int> dataTypes;
6505 for (
const QVariant &v : mLayerTypeComboBox->checkedItemsData() )
6506 dataTypes << v.toInt();
6508 auto param = std::make_unique<QgsProcessingParameterMapLayer>( name, description );
6509 param->setDataTypes( dataTypes );
6511 return param.release();
6518QWidget *QgsProcessingMapLayerWidgetWrapper::createWidget()
6520 mComboBox =
new QgsProcessingMapLayerComboBox( parameterDefinition(), type() );
6528 mComboBox->setEditable(
true );
6532 mComboBox->setToolTip( parameterDefinition()->toolTip() );
6534 connect( mComboBox, &QgsProcessingMapLayerComboBox::valueChanged,
this, [
this]() {
6535 if ( mBlockSignals )
6538 emit widgetValueHasChanged(
this );
6541 setWidgetContext( widgetContext() );
6550 mComboBox->setWidgetContext( context );
6555 if ( !parameterDefinition()->defaultValueForGui().isValid() )
6561void QgsProcessingMapLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6564 mComboBox->setValue( value, context );
6567QVariant QgsProcessingMapLayerWidgetWrapper::widgetValue()
const
6569 return mComboBox ? mComboBox->value() : QVariant();
6572QString QgsProcessingMapLayerWidgetWrapper::modelerExpressionFormatString()
const
6574 return tr(
"path to a map layer" );
6591QString QgsProcessingMapLayerWidgetWrapper::parameterType()
const
6598 return new QgsProcessingMapLayerWidgetWrapper( parameter, type );
6605 return new QgsProcessingMapLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6614 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6617QString QgsProcessingRasterLayerWidgetWrapper::modelerExpressionFormatString()
const
6619 return tr(
"path to a raster layer" );
6622QString QgsProcessingRasterLayerWidgetWrapper::parameterType()
const
6629 return new QgsProcessingRasterLayerWidgetWrapper( parameter, type );
6636 Q_UNUSED( context );
6637 Q_UNUSED( widgetContext );
6638 Q_UNUSED( definition );
6649QgsProcessingVectorLayerParameterDefinitionWidget::QgsProcessingVectorLayerParameterDefinitionWidget(
6654 QVBoxLayout *vlayout =
new QVBoxLayout();
6655 vlayout->setContentsMargins( 0, 0, 0, 0 );
6657 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6667 for (
int i : vectorParam->dataTypes() )
6669 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6673 vlayout->addWidget( mGeometryTypeComboBox );
6677 setLayout( vlayout );
6682 QList<int> dataTypes;
6683 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6684 dataTypes << v.toInt();
6686 auto param = std::make_unique<QgsProcessingParameterVectorLayer>( name, description, dataTypes );
6688 return param.release();
6693 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6696QString QgsProcessingVectorLayerWidgetWrapper::modelerExpressionFormatString()
const
6698 return tr(
"path to a vector layer" );
6701QString QgsProcessingVectorLayerWidgetWrapper::parameterType()
const
6708 return new QgsProcessingVectorLayerWidgetWrapper( parameter, type );
6715 return new QgsProcessingVectorLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6723QgsProcessingFeatureSourceParameterDefinitionWidget::QgsProcessingFeatureSourceParameterDefinitionWidget(
6728 QVBoxLayout *vlayout =
new QVBoxLayout();
6729 vlayout->setContentsMargins( 0, 0, 0, 0 );
6731 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6741 for (
int i : sourceParam->dataTypes() )
6743 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6751 vlayout->addWidget( mGeometryTypeComboBox );
6754 setLayout( vlayout );
6759 QList<int> dataTypes;
6760 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6761 dataTypes << v.toInt();
6763 auto param = std::make_unique<QgsProcessingParameterFeatureSource>( name, description, dataTypes );
6765 return param.release();
6769 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6772QString QgsProcessingFeatureSourceWidgetWrapper::modelerExpressionFormatString()
const
6774 return tr(
"path to a vector layer" );
6777QString QgsProcessingFeatureSourceWidgetWrapper::parameterType()
const
6784 return new QgsProcessingFeatureSourceWidgetWrapper( parameter, type );
6791 return new QgsProcessingFeatureSourceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6799 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6802QString QgsProcessingMeshLayerWidgetWrapper::modelerExpressionFormatString()
const
6804 return tr(
"path to a mesh layer" );
6807QString QgsProcessingMeshLayerWidgetWrapper::parameterType()
const
6814 return new QgsProcessingMeshLayerWidgetWrapper( parameter, type );
6821 Q_UNUSED( context );
6822 Q_UNUSED( widgetContext );
6823 Q_UNUSED( definition );
6834QgsProcessingRasterBandPanelWidget::QgsProcessingRasterBandPanelWidget( QWidget *parent,
const QgsProcessingParameterBand *param )
6838 QHBoxLayout *hl =
new QHBoxLayout();
6839 hl->setContentsMargins( 0, 0, 0, 0 );
6841 mLineEdit =
new QLineEdit();
6842 mLineEdit->setEnabled(
false );
6843 hl->addWidget( mLineEdit, 1 );
6845 mToolButton =
new QToolButton();
6846 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6847 hl->addWidget( mToolButton );
6853 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, 0 ) );
6856 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingRasterBandPanelWidget::showDialog );
6859void QgsProcessingRasterBandPanelWidget::setBands(
const QList<int> &bands )
6864void QgsProcessingRasterBandPanelWidget::setBandNames(
const QHash<int, QString> &names )
6869void QgsProcessingRasterBandPanelWidget::setValue(
const QVariant &value )
6871 if ( value.isValid() )
6872 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
6876 updateSummaryText();
6880void QgsProcessingRasterBandPanelWidget::showDialog()
6882 QVariantList availableOptions;
6883 availableOptions.reserve( mBands.size() );
6884 for (
int band : std::as_const( mBands ) )
6886 availableOptions << band;
6892 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
6893 widget->setPanelTitle( mParam->description() );
6895 widget->setValueFormatter( [
this](
const QVariant &v ) -> QString {
6896 int band = v.toInt();
6897 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6900 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
6906 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
6908 dlg.setValueFormatter( [
this](
const QVariant &v ) -> QString {
6909 int band = v.toInt();
6910 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6914 setValue( dlg.selectedOptions() );
6919void QgsProcessingRasterBandPanelWidget::updateSummaryText()
6922 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, mValue.count() ) );
6930QgsProcessingBandParameterDefinitionWidget::QgsProcessingBandParameterDefinitionWidget(
6935 QVBoxLayout *vlayout =
new QVBoxLayout();
6936 vlayout->setContentsMargins( 0, 0, 0, 0 );
6938 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6940 mDefaultLineEdit =
new QLineEdit();
6941 mDefaultLineEdit->setToolTip( tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6946 for (
int b : bands )
6948 defVal << QString::number( b );
6951 mDefaultLineEdit->setText( defVal.join(
';' ) );
6953 vlayout->addWidget( mDefaultLineEdit );
6956 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
6957 mParentLayerComboBox =
new QComboBox();
6959 QString initialParent;
6961 initialParent = bandParam->parentLayerParameterName();
6963 if (
auto *lModel = widgetContext.
model() )
6966 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6967 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6971 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
6972 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
6974 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6980 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
6983 mParentLayerComboBox->addItem( initialParent, initialParent );
6984 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6988 vlayout->addWidget( mParentLayerComboBox );
6990 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Allow multiple" ) );
6992 mAllowMultipleCheckBox->setChecked( bandParam->allowMultiple() );
6995 vlayout->addWidget( mAllowMultipleCheckBox );
6996 setLayout( vlayout );
7002 = std::make_unique<QgsProcessingParameterBand>( name, description, mDefaultLineEdit->text().split(
';' ), mParentLayerComboBox->currentData().toString(),
false, mAllowMultipleCheckBox->isChecked() );
7004 return param.release();
7011QWidget *QgsProcessingBandWidgetWrapper::createWidget()
7024 mPanel =
new QgsProcessingRasterBandPanelWidget(
nullptr, bandParam );
7025 mPanel->setToolTip( parameterDefinition()->toolTip() );
7026 connect( mPanel, &QgsProcessingRasterBandPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7034 mComboBox->setToolTip( parameterDefinition()->toolTip() );
7042 mLineEdit =
new QLineEdit();
7043 mLineEdit->setToolTip( QObject::tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
7044 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7051void QgsProcessingBandWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
7063 setParentLayerWrapperValue( wrapper );
7080 std::unique_ptr<QgsProcessingContext> tmpContext;
7081 if ( mProcessingContextGenerator )
7082 context = mProcessingContextGenerator->processingContext();
7086 tmpContext = std::make_unique<QgsProcessingContext>();
7087 context = tmpContext.get();
7093 if ( layer && layer->
isValid() )
7097 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
7100 mParentLayer.reset( qobject_cast<QgsRasterLayer *>( ownedLayer.release() ) );
7101 layer = mParentLayer.get();
7109 mComboBox->setLayer( layer );
7113 if ( provider && layer->
isValid() )
7118 QHash<int, QString> bandNames;
7119 for (
int i = 1; i <= nBands; ++i )
7124 mPanel->setBands( bands );
7125 mPanel->setBandNames( bandNames );
7132 mComboBox->setLayer(
nullptr );
7134 mPanel->setBands( QList<int>() );
7136 if ( value.isValid() && widgetContext().messageBar() )
7143 if ( parameterDefinition()->defaultValueForGui().isValid() )
7144 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
7147void QgsProcessingBandWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7151 if ( !value.isValid() )
7152 mComboBox->setBand( -1 );
7156 mComboBox->setBand( v );
7162 if ( value.isValid() )
7165 opts.reserve( v.size() );
7170 mPanel->setValue( value.isValid() ? opts : QVariant() );
7172 else if ( mLineEdit )
7179 opts.reserve( v.size() );
7181 opts << QString::number( i );
7182 mLineEdit->setText( value.isValid() && !opts.empty() ? opts.join(
';' ) : QString() );
7186 if ( value.isValid() )
7194QVariant QgsProcessingBandWidgetWrapper::widgetValue()
const
7197 return mComboBox->currentBand() == -1 ? QVariant() : mComboBox->currentBand();
7199 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
7200 else if ( mLineEdit )
7205 const QStringList parts = mLineEdit->text().split(
';', Qt::SkipEmptyParts );
7207 res.reserve( parts.count() );
7208 for (
const QString &s : parts )
7211 int band = s.toInt( &ok );
7215 return res.
isEmpty() ? QVariant() : res;
7219 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
7226QString QgsProcessingBandWidgetWrapper::modelerExpressionFormatString()
const
7228 return tr(
"selected band numbers as an array of numbers, or semicolon separated string of options (e.g. '1;3')" );
7231QString QgsProcessingBandWidgetWrapper::parameterType()
const
7238 return new QgsProcessingBandWidgetWrapper( parameter, type );
7245 return new QgsProcessingBandParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
7256 setAcceptDrops(
true );
7259void QgsProcessingMultipleLayerLineEdit::dragEnterEvent( QDragEnterEvent *event )
7261 const QStringList uris = QgsProcessingMultipleInputPanelWidget::compatibleUrisFromMimeData( mParam, event->mimeData(), {} );
7262 if ( !uris.isEmpty() )
7264 event->setDropAction( Qt::CopyAction );
7266 setHighlighted(
true );
7274void QgsProcessingMultipleLayerLineEdit::dragLeaveEvent( QDragLeaveEvent *event )
7276 QgsHighlightableLineEdit::dragLeaveEvent( event );
7278 setHighlighted(
false );
7281void QgsProcessingMultipleLayerLineEdit::dropEvent( QDropEvent *event )
7283 const QStringList uris = QgsProcessingMultipleInputPanelWidget::compatibleUrisFromMimeData( mParam, event->mimeData(), {} );
7284 if ( !uris.isEmpty() )
7286 event->setDropAction( Qt::CopyAction );
7288 QVariantList uriList;
7289 uriList.reserve( uris.size() );
7290 for (
const QString &uri : uris )
7291 uriList.append( QVariant( uri ) );
7292 emit layersDropped( uriList );
7295 setHighlighted(
false );
7306 QHBoxLayout *hl =
new QHBoxLayout();
7307 hl->setContentsMargins( 0, 0, 0, 0 );
7309 mLineEdit =
new QgsProcessingMultipleLayerLineEdit(
nullptr, param );
7310 mLineEdit->setEnabled(
true );
7311 mLineEdit->setReadOnly(
true );
7313 hl->addWidget( mLineEdit, 1 );
7314 connect( mLineEdit, &QgsProcessingMultipleLayerLineEdit::layersDropped,
this, &QgsProcessingMultipleLayerPanelWidget::setValue );
7316 mToolButton =
new QToolButton();
7317 mToolButton->setText( QString( QChar( 0x2026 ) ) );
7318 hl->addWidget( mToolButton );
7324 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, 0 ) );
7327 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingMultipleLayerPanelWidget::showDialog );
7330void QgsProcessingMultipleLayerPanelWidget::setValue(
const QVariant &value )
7332 if ( value.isValid() )
7333 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
7337 updateSummaryText();
7341void QgsProcessingMultipleLayerPanelWidget::setProject(
QgsProject *project )
7347 if ( mValue.removeAll( layerId ) )
7349 updateSummaryText();
7356void QgsProcessingMultipleLayerPanelWidget::setModel( QgsProcessingModelAlgorithm *model,
const QString &modelChildAlgorithmID )
7362 switch ( mParam->layerType() )
7370 mModelSources = model->availableSourcesForChild(
7371 modelChildAlgorithmID,
7380 mModelSources = model->availableSourcesForChild(
7381 modelChildAlgorithmID,
7390 mModelSources = model->availableSourcesForChild(
7391 modelChildAlgorithmID,
7400 mModelSources = model->availableSourcesForChild(
7401 modelChildAlgorithmID,
7410 mModelSources = model->availableSourcesForChild(
7411 modelChildAlgorithmID,
7420 mModelSources = model->availableSourcesForChild(
7421 modelChildAlgorithmID,
7430 mModelSources = model->availableSourcesForChild(
7431 modelChildAlgorithmID,
7440 mModelSources = model->availableSourcesForChild(
7441 modelChildAlgorithmID,
7455 mModelSources = model->availableSourcesForChild(
7456 modelChildAlgorithmID,
7469 mModelSources = model->availableSourcesForChild(
7470 modelChildAlgorithmID,
7484 mModelSources = model->availableSourcesForChild(
7485 modelChildAlgorithmID,
7499 mModelSources = model->availableSourcesForChild(
7500 modelChildAlgorithmID,
7514 mModelSources = model->availableSourcesForChild(
7515 modelChildAlgorithmID,
7536void QgsProcessingMultipleLayerPanelWidget::showDialog()
7541 QgsProcessingMultipleInputPanelWidget *widget =
new QgsProcessingMultipleInputPanelWidget( mParam, mValue, mModelSources, mModel,
nullptr );
7542 widget->setPanelTitle( mParam->description() );
7543 widget->setProject( mProject );
7544 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
7550 QgsProcessingMultipleInputDialog dlg( mParam, mValue, mModelSources, mModel,
this, Qt::WindowFlags() );
7551 dlg.setProject( mProject );
7554 setValue( dlg.selectedOptions() );
7559void QgsProcessingMultipleLayerPanelWidget::updateSummaryText()
7562 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, mValue.count() ) );
7569QgsProcessingMultipleLayerParameterDefinitionWidget::QgsProcessingMultipleLayerParameterDefinitionWidget(
7574 QVBoxLayout *vlayout =
new QVBoxLayout();
7575 vlayout->setContentsMargins( 0, 0, 0, 0 );
7577 vlayout->addWidget(
new QLabel( tr(
"Allowed layer type" ) ) );
7578 mLayerTypeComboBox =
new QComboBox();
7592 mLayerTypeComboBox->setCurrentIndex( mLayerTypeComboBox->findData(
static_cast<int>( layersParam->layerType() ) ) );
7594 vlayout->addWidget( mLayerTypeComboBox );
7597 setLayout( vlayout );
7602 auto param = std::make_unique<QgsProcessingParameterMultipleLayers>( name, description,
static_cast<Qgis::ProcessingSourceType>( mLayerTypeComboBox->currentData().toInt() ) );
7604 return param.release();
7611QWidget *QgsProcessingMultipleLayerWidgetWrapper::createWidget()
7615 mPanel =
new QgsProcessingMultipleLayerPanelWidget(
nullptr, layerParam );
7616 mPanel->setToolTip( parameterDefinition()->toolTip() );
7617 mPanel->setProject( widgetContext().project() );
7619 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7620 connect( mPanel, &QgsProcessingMultipleLayerPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7629 mPanel->setProject( context.
project() );
7631 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7635void QgsProcessingMultipleLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7640 if ( value.isValid() )
7643 opts.reserve( v.size() );
7645 opts << l->source();
7648 for (
const QVariant &v : value.toList() )
7650 if ( v.userType() == qMetaTypeId<QgsProcessingModelChildParameterSource>() )
7652 const QgsProcessingModelChildParameterSource source = v.value<QgsProcessingModelChildParameterSource>();
7653 opts << QVariant::fromValue( source );
7658 mPanel->setValue( value.isValid() ? opts : QVariant() );
7662QVariant QgsProcessingMultipleLayerWidgetWrapper::widgetValue()
const
7665 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
7670QString QgsProcessingMultipleLayerWidgetWrapper::modelerExpressionFormatString()
const
7672 return tr(
"an array of layer paths, or semicolon separated string of layer paths" );
7675QString QgsProcessingMultipleLayerWidgetWrapper::parameterType()
const
7682 return new QgsProcessingMultipleLayerWidgetWrapper( parameter, type );
7689 return new QgsProcessingMultipleLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
7698 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
7701QString QgsProcessingPointCloudLayerWidgetWrapper::modelerExpressionFormatString()
const
7703 return tr(
"path to a point cloud layer" );
7706QString QgsProcessingPointCloudLayerWidgetWrapper::parameterType()
const
7713 return new QgsProcessingPointCloudLayerWidgetWrapper( parameter, type );
7720 Q_UNUSED( context );
7721 Q_UNUSED( widgetContext );
7722 Q_UNUSED( definition );
7737QString QgsProcessingAnnotationLayerWidgetWrapper::modelerExpressionFormatString()
const
7739 return tr(
"name of an annotation layer, or \"main\" for the main annotation layer" );
7742QString QgsProcessingAnnotationLayerWidgetWrapper::parameterType()
const
7749 return new QgsProcessingAnnotationLayerWidgetWrapper( parameter, type );
7756 Q_UNUSED( context );
7757 Q_UNUSED( widgetContext );
7758 Q_UNUSED( definition );
7769 if ( mWidgetContext.project() )
7770 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7774QWidget *QgsProcessingAnnotationLayerWidgetWrapper::createWidget()
7785 mComboBox->setEditable(
true );
7789 mComboBox->setToolTip( parameterDefinition()->toolTip() );
7791 if ( mWidgetContext.project() )
7792 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7795 mComboBox->setAllowEmptyLayer(
true );
7798 if ( mBlockSignals )
7801 emit widgetValueHasChanged(
this );
7804 setWidgetContext( widgetContext() );
7808void QgsProcessingAnnotationLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7814 mComboBox->setLayer(
nullptr );
7818 QVariant val = value;
7819 if ( val.userType() == qMetaTypeId<QgsProperty>() )
7831 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( val.value<QObject *>() );
7832 if ( !layer && val.userType() == QMetaType::Type::QString )
7839 mComboBox->setLayer( layer );
7844QVariant QgsProcessingAnnotationLayerWidgetWrapper::widgetValue()
const
7846 return mComboBox && mComboBox->currentLayer()
7847 ? ( mWidgetContext.project() ? ( mComboBox->currentLayer() == mWidgetContext.project()->mainAnnotationLayer() ? u
"main"_s : mComboBox->currentLayer()->id() )
7848 : mComboBox->currentLayer()->id() )
7861 QHBoxLayout *hl =
new QHBoxLayout();
7862 hl->setContentsMargins( 0, 0, 0, 0 );
7864 mLineEdit =
new QLineEdit();
7865 mLineEdit->setEnabled(
false );
7866 hl->addWidget( mLineEdit, 1 );
7868 mToolButton =
new QToolButton();
7869 mToolButton->setText( QString( QChar( 0x2026 ) ) );
7870 hl->addWidget( mToolButton );
7876 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, 0 ) );
7879 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingPointCloudAttributePanelWidget::showDialog );
7884 mAttributes = attributes;
7887void QgsProcessingPointCloudAttributePanelWidget::setValue(
const QVariant &value )
7889 if ( value.isValid() )
7890 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
7894 updateSummaryText();
7898void QgsProcessingPointCloudAttributePanelWidget::showDialog()
7900 QVariantList availableOptions;
7901 availableOptions.reserve( mAttributes.count() );
7902 const QVector<QgsPointCloudAttribute> attributes = mAttributes.attributes();
7905 availableOptions << attr.name();
7911 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
7912 widget->setPanelTitle( mParam->description() );
7914 widget->setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
7916 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
7922 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
7924 dlg.setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
7927 setValue( dlg.selectedOptions() );
7932void QgsProcessingPointCloudAttributePanelWidget::updateSummaryText()
7937 if ( mValue.empty() )
7939 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, 0 ) );
7944 values.reserve( mValue.size() );
7945 for (
const QVariant &val : std::as_const( mValue ) )
7947 values << val.toString();
7950 const QString concatenated = values.join( tr(
"," ) );
7951 if ( concatenated.length() < 100 )
7952 mLineEdit->setText( concatenated );
7954 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, mValue.count() ) );
7963QgsProcessingPointCloudAttributeParameterDefinitionWidget::QgsProcessingPointCloudAttributeParameterDefinitionWidget(
7968 QVBoxLayout *vlayout =
new QVBoxLayout();
7969 vlayout->setContentsMargins( 0, 0, 0, 0 );
7971 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
7972 mParentLayerComboBox =
new QComboBox();
7974 QString initialParent;
7976 initialParent = attrParam->parentLayerParameterName();
7978 if (
auto *lModel = widgetContext.
model() )
7981 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
7982 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
7986 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
7987 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
7989 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
7995 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
7998 mParentLayerComboBox->addItem( initialParent, initialParent );
7999 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
8002 vlayout->addWidget( mParentLayerComboBox );
8006 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple attributes" ) );
8008 mAllowMultipleCheckBox->setChecked( attrParam->allowMultiple() );
8010 vlayout->addWidget( mAllowMultipleCheckBox );
8013 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all attributes by default" ) );
8014 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
8016 mDefaultToAllCheckBox->setChecked( attrParam->defaultToAllAttributes() );
8020 vlayout->addWidget( mDefaultToAllCheckBox );
8022 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [
this] { mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() ); } );
8024 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
8026 mDefaultLineEdit =
new QLineEdit();
8027 mDefaultLineEdit->setToolTip( tr(
"Default attribute name, or ; separated list of attribute names for multiple attribute parameters" ) );
8031 mDefaultLineEdit->setText( attributes.join(
';' ) );
8033 vlayout->addWidget( mDefaultLineEdit );
8037 setLayout( vlayout );
8042 QVariant defaultValue;
8043 if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
8045 defaultValue = mDefaultLineEdit->text();
8047 auto param = std::make_unique<
8048 QgsProcessingParameterPointCloudAttribute>( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
8050 return param.release();
8057QWidget *QgsProcessingPointCloudAttributeWidgetWrapper::createWidget()
8070 mPanel =
new QgsProcessingPointCloudAttributePanelWidget(
nullptr, attrParam );
8071 mPanel->setToolTip( parameterDefinition()->toolTip() );
8072 connect( mPanel, &QgsProcessingPointCloudAttributePanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
8079 mComboBox->setToolTip( parameterDefinition()->toolTip() );
8087 mLineEdit =
new QLineEdit();
8088 mLineEdit->setToolTip( QObject::tr(
"Name of attribute (separate attribute names with ; for multiple attribute parameters)" ) );
8089 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
8096void QgsProcessingPointCloudAttributeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
8108 setParentLayerWrapperValue( wrapper );
8125 std::unique_ptr<QgsProcessingContext> tmpContext;
8126 if ( mProcessingContextGenerator )
8127 context = mProcessingContextGenerator->processingContext();
8131 tmpContext = std::make_unique<QgsProcessingContext>();
8132 context = tmpContext.get();
8138 if ( layer && layer->
isValid() )
8142 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
8145 mParentLayer.reset( qobject_cast<QgsPointCloudLayer *>( ownedLayer.release() ) );
8146 layer = mParentLayer.get();
8154 mComboBox->setLayer( layer );
8157 mPanel->setAttributes( layer->
attributes() );
8164 mComboBox->setLayer(
nullptr );
8169 if ( value.isValid() && widgetContext().messageBar() )
8180 val.reserve( mPanel->attributes().attributes().size() );
8183 setWidgetValue( val, *context );
8186 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
8189void QgsProcessingPointCloudAttributeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
8193 if ( !value.isValid() )
8194 mComboBox->setAttribute( QString() );
8198 mComboBox->setAttribute( v );
8204 if ( value.isValid() )
8207 opts.reserve( v.size() );
8208 for (
const QString &i : v )
8212 mPanel->setValue( opts );
8214 else if ( mLineEdit )
8220 mLineEdit->setText( v.join(
';' ) );
8229QVariant QgsProcessingPointCloudAttributeWidgetWrapper::widgetValue()
const
8232 return mComboBox->currentAttribute();
8234 return mPanel->value();
8235 else if ( mLineEdit )
8240 return mLineEdit->text().split(
';' );
8243 return mLineEdit->text();
8249QString QgsProcessingPointCloudAttributeWidgetWrapper::modelerExpressionFormatString()
const
8251 return tr(
"selected attribute names as an array of names, or semicolon separated string of options (e.g. 'X;Intensity')" );
8254QString QgsProcessingPointCloudAttributeWidgetWrapper::parameterType()
const
8261 return new QgsProcessingPointCloudAttributeWidgetWrapper( parameter, type );
8268 return new QgsProcessingPointCloudAttributeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
8280QWidget *QgsProcessingOutputWidgetWrapper::createWidget()
8288 mOutputWidget =
new QgsProcessingLayerOutputDestinationWidget( destParam,
false );
8289 if ( mProcessingContextGenerator )
8290 mOutputWidget->setContext( mProcessingContextGenerator->processingContext() );
8291 if ( mParametersGenerator )
8292 mOutputWidget->registerProcessingParametersGenerator( mParametersGenerator );
8293 mOutputWidget->setToolTip( parameterDefinition()->toolTip() );
8295 connect( mOutputWidget, &QgsProcessingLayerOutputDestinationWidget::destinationChanged,
this, [
this]() {
8296 if ( mBlockSignals )
8299 emit widgetValueHasChanged(
this );
8304 mOutputWidget->addOpenAfterRunningOption();
8306 return mOutputWidget;
8316void QgsProcessingOutputWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
8318 if ( mOutputWidget )
8319 mOutputWidget->setValue( value );
8322QVariant QgsProcessingOutputWidgetWrapper::widgetValue()
const
8324 if ( mOutputWidget )
8325 return mOutputWidget->value();
8330QVariantMap QgsProcessingOutputWidgetWrapper::customProperties()
const
8333 if ( mOutputWidget )
8334 res.insert( u
"OPEN_AFTER_RUNNING"_s, mOutputWidget->openAfterRunning() );
8343 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8346QString QgsProcessingFeatureSinkWidgetWrapper::parameterType()
const
8353 return new QgsProcessingFeatureSinkWidgetWrapper( parameter, type );
8356QString QgsProcessingFeatureSinkWidgetWrapper::modelerExpressionFormatString()
const
8358 return tr(
"path to layer destination" );
8366 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8369QString QgsProcessingVectorDestinationWidgetWrapper::parameterType()
const
8376 return new QgsProcessingVectorDestinationWidgetWrapper( parameter, type );
8379QString QgsProcessingVectorDestinationWidgetWrapper::modelerExpressionFormatString()
const
8381 return tr(
"path to layer destination" );
8389 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8392QString QgsProcessingRasterDestinationWidgetWrapper::parameterType()
const
8399 return new QgsProcessingRasterDestinationWidgetWrapper( parameter, type );
8402QString QgsProcessingRasterDestinationWidgetWrapper::modelerExpressionFormatString()
const
8404 return tr(
"path to layer destination" );
8412 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8415QString QgsProcessingPointCloudDestinationWidgetWrapper::parameterType()
const
8422 return new QgsProcessingPointCloudDestinationWidgetWrapper( parameter, type );
8425QString QgsProcessingPointCloudDestinationWidgetWrapper::modelerExpressionFormatString()
const
8427 return tr(
"path to layer destination" );
8435 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8438QString QgsProcessingFileDestinationWidgetWrapper::parameterType()
const
8445 return new QgsProcessingFileDestinationWidgetWrapper( parameter, type );
8449QString QgsProcessingFileDestinationWidgetWrapper::modelerExpressionFormatString()
const
8451 return tr(
"path to file destination" );
8459 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8462QString QgsProcessingFolderDestinationWidgetWrapper::parameterType()
const
8469 return new QgsProcessingFolderDestinationWidgetWrapper( parameter, type );
8473QString QgsProcessingFolderDestinationWidgetWrapper::modelerExpressionFormatString()
const
8475 return tr(
"path to folder destination" );
8483 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8486QString QgsProcessingVectorTileDestinationWidgetWrapper::parameterType()
const
8493 return new QgsProcessingPointCloudDestinationWidgetWrapper( parameter, type );
8496QString QgsProcessingVectorTileDestinationWidgetWrapper::modelerExpressionFormatString()
const
8498 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).