83#include <QButtonGroup>
88#include <QInputDialog>
93#include <QPlainTextEdit>
94#include <QRadioButton>
99#include "moc_qgsprocessingwidgetwrapperimpl.cpp"
101using namespace Qt::StringLiterals;
110QgsProcessingBooleanParameterDefinitionWidget::QgsProcessingBooleanParameterDefinitionWidget(
115 QVBoxLayout *vlayout =
new QVBoxLayout();
116 vlayout->setContentsMargins( 0, 0, 0, 0 );
118 mDefaultCheckBox =
new QCheckBox( tr(
"Checked" ) );
122 mDefaultCheckBox->setChecked(
false );
123 vlayout->addWidget( mDefaultCheckBox );
126 setLayout( vlayout );
131 auto param = std::make_unique<QgsProcessingParameterBoolean>( name, description, mDefaultCheckBox->isChecked() );
132 param->setFlags( flags );
133 return param.release();
141QWidget *QgsProcessingBooleanWidgetWrapper::createWidget()
147 QString description = parameterDefinition()->description();
149 description = QObject::tr(
"%1 [optional]" ).arg( description );
151 mCheckBox =
new QCheckBox( description );
152 mCheckBox->setToolTip( parameterDefinition()->toolTip() );
154 connect( mCheckBox, &QCheckBox::toggled,
this, [
this] { emit widgetValueHasChanged(
this ); } );
161 mComboBox =
new QComboBox();
162 mComboBox->addItem( tr(
"Yes" ),
true );
163 mComboBox->addItem( tr(
"No" ),
false );
164 mComboBox->setToolTip( parameterDefinition()->toolTip() );
166 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
174QLabel *QgsProcessingBooleanWidgetWrapper::createLabel()
183void QgsProcessingBooleanWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
190 mCheckBox->setChecked( v );
198 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
204QVariant QgsProcessingBooleanWidgetWrapper::widgetValue()
const
209 return mCheckBox->isChecked();
213 return mComboBox->currentData();
218QString QgsProcessingBooleanWidgetWrapper::parameterType()
const
225 return new QgsProcessingBooleanWidgetWrapper( parameter, type );
232 return new QgsProcessingBooleanParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
240QgsProcessingCrsParameterDefinitionWidget::QgsProcessingCrsParameterDefinitionWidget(
245 QVBoxLayout *vlayout =
new QVBoxLayout();
246 vlayout->setContentsMargins( 0, 0, 0, 0 );
248 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
253 mCrsSelector->setShowAccuracyWarnings(
true );
260 vlayout->addWidget( mCrsSelector );
261 setLayout( vlayout );
266 auto param = std::make_unique<QgsProcessingParameterCrs>( name, description, mCrsSelector->crs().authid() );
267 param->setFlags( flags );
268 return param.release();
275QWidget *QgsProcessingCrsWidgetWrapper::createWidget()
277 Q_ASSERT( mProjectionSelectionWidget ==
nullptr );
279 mProjectionSelectionWidget->setToolTip( parameterDefinition()->toolTip() );
293 return mProjectionSelectionWidget;
298 QWidget *w =
new QWidget();
299 w->setToolTip( parameterDefinition()->toolTip() );
301 QVBoxLayout *vl =
new QVBoxLayout();
302 vl->setContentsMargins( 0, 0, 0, 0 );
305 mUseProjectCrsCheckBox =
new QCheckBox( tr(
"Use project CRS" ) );
306 mUseProjectCrsCheckBox->setToolTip( tr(
"Always use the current project CRS when running the model" ) );
307 vl->addWidget( mUseProjectCrsCheckBox );
308 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, mProjectionSelectionWidget, &QgsProjectionSelectionWidget::setDisabled );
309 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled,
this, [
this] { emit widgetValueHasChanged(
this ); } );
311 vl->addWidget( mProjectionSelectionWidget );
319void QgsProcessingCrsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
321 if ( mUseProjectCrsCheckBox )
323 if ( value.toString().compare(
"ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
325 mUseProjectCrsCheckBox->setChecked(
true );
330 mUseProjectCrsCheckBox->setChecked(
false );
335 if ( mProjectionSelectionWidget )
336 mProjectionSelectionWidget->setCrs( v );
339QVariant QgsProcessingCrsWidgetWrapper::widgetValue()
const
341 if ( mUseProjectCrsCheckBox && mUseProjectCrsCheckBox->isChecked() )
342 return u
"ProjectCrs"_s;
343 else if ( mProjectionSelectionWidget )
344 return mProjectionSelectionWidget->crs().isValid() ? mProjectionSelectionWidget->crs() : QVariant();
349QString QgsProcessingCrsWidgetWrapper::modelerExpressionFormatString()
const
351 return tr(
"string as EPSG code, WKT or PROJ format, or a string identifying a map layer" );
354QString QgsProcessingCrsWidgetWrapper::parameterType()
const
361 return new QgsProcessingCrsWidgetWrapper( parameter, type );
368 return new QgsProcessingCrsParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
377QgsProcessingStringParameterDefinitionWidget::QgsProcessingStringParameterDefinitionWidget(
382 QVBoxLayout *vlayout =
new QVBoxLayout();
383 vlayout->setContentsMargins( 0, 0, 0, 0 );
385 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
387 mDefaultLineEdit =
new QLineEdit();
390 vlayout->addWidget( mDefaultLineEdit );
394 mMultiLineCheckBox =
new QCheckBox( tr(
"Multiline input" ) );
396 mMultiLineCheckBox->setChecked( stringParam->multiLine() );
397 vlayout->addWidget( mMultiLineCheckBox );
401 setLayout( vlayout );
406 auto param = std::make_unique<QgsProcessingParameterString>( name, description, mDefaultLineEdit->text(), mMultiLineCheckBox->isChecked() );
407 param->setFlags( flags );
408 return param.release();
416QWidget *QgsProcessingStringWidgetWrapper::createWidget()
418 const QVariantMap metadata = parameterDefinition()->metadata();
419 const QVariant valueHintsVariant = metadata.value( u
"widget_wrapper"_s ).toMap().value( u
"value_hints"_s );
421 if ( valueHintsVariant.isValid() )
423 const QVariantList valueList = valueHintsVariant.toList();
424 mComboBox =
new QComboBox();
425 mComboBox->setToolTip( parameterDefinition()->toolTip() );
429 mComboBox->addItem( QString() );
431 for (
const QVariant &entry : valueList )
433 mComboBox->addItem( entry.toString(), entry.toString() );
435 mComboBox->setCurrentIndex( 0 );
437 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
449 mPlainTextEdit =
new QPlainTextEdit();
450 mPlainTextEdit->setToolTip( parameterDefinition()->toolTip() );
452 connect( mPlainTextEdit, &QPlainTextEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
453 return mPlainTextEdit;
457 mLineEdit =
new QLineEdit();
458 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
460 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
467 mLineEdit =
new QLineEdit();
468 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
470 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
479void QgsProcessingStringWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
483 mLineEdit->setText( v );
484 if ( mPlainTextEdit )
485 mPlainTextEdit->setPlainText( v );
489 if ( !value.isValid() )
490 index = mComboBox->findData( QVariant() );
492 index = mComboBox->findData( v );
495 mComboBox->setCurrentIndex( index );
497 mComboBox->setCurrentIndex( 0 );
501QVariant QgsProcessingStringWidgetWrapper::widgetValue()
const
504 return mLineEdit->text();
505 else if ( mPlainTextEdit )
506 return mPlainTextEdit->toPlainText();
507 else if ( mComboBox )
508 return mComboBox->currentData();
513QString QgsProcessingStringWidgetWrapper::parameterType()
const
520 return new QgsProcessingStringWidgetWrapper( parameter, type );
527 return new QgsProcessingStringParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
539QWidget *QgsProcessingAuthConfigWidgetWrapper::createWidget()
548 mAuthConfigSelect->setToolTip( parameterDefinition()->toolTip() );
551 return mAuthConfigSelect;
557void QgsProcessingAuthConfigWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
560 if ( mAuthConfigSelect )
561 mAuthConfigSelect->setConfigId( v );
564QVariant QgsProcessingAuthConfigWidgetWrapper::widgetValue()
const
566 if ( mAuthConfigSelect )
567 return mAuthConfigSelect->configId();
572QString QgsProcessingAuthConfigWidgetWrapper::parameterType()
const
579 return new QgsProcessingAuthConfigWidgetWrapper( parameter, type );
586QgsProcessingNumberParameterDefinitionWidget::QgsProcessingNumberParameterDefinitionWidget(
591 QVBoxLayout *vlayout =
new QVBoxLayout();
592 vlayout->setContentsMargins( 0, 0, 0, 0 );
594 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
596 mTypeComboBox =
new QComboBox();
599 vlayout->addWidget( mTypeComboBox );
601 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
602 mMinLineEdit =
new QLineEdit();
603 vlayout->addWidget( mMinLineEdit );
605 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
606 mMaxLineEdit =
new QLineEdit();
607 vlayout->addWidget( mMaxLineEdit );
609 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
610 mDefaultLineEdit =
new QLineEdit();
611 vlayout->addWidget( mDefaultLineEdit );
615 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( numberParam->dataType() ) ) );
617 if ( !
qgsDoubleNear( numberParam->maximum(), std::numeric_limits<double>::max() ) )
619 mMaxLineEdit->setText( QLocale().toString( numberParam->maximum() ) );
623 mMaxLineEdit->clear();
626 if ( !
qgsDoubleNear( numberParam->minimum(), std::numeric_limits<double>::lowest() ) )
628 mMinLineEdit->setText( QLocale().toString( numberParam->minimum() ) );
632 mMinLineEdit->clear();
635 mDefaultLineEdit->setText( numberParam->defaultValueForGui().toString() );
643 setLayout( vlayout );
652 auto param = std::make_unique<QgsProcessingParameterNumber>( name, description, dataType, ok ? val : QVariant() );
654 if ( !mMinLineEdit->text().trimmed().isEmpty() )
659 param->setMinimum( val );
663 if ( !mMaxLineEdit->text().trimmed().isEmpty() )
668 param->setMaximum( val );
672 param->setFlags( flags );
673 return param.release();
680QWidget *QgsProcessingNumericWidgetWrapper::createWidget()
683 const QVariantMap metadata = numberDef->
metadata();
684 const int decimals = metadata.value( u
"widget_wrapper"_s ).toMap().value( u
"decimals"_s, 6 ).toInt();
692 QAbstractSpinBox *spinBox =
nullptr;
697 mDoubleSpinBox->setExpressionsEnabled(
true );
698 mDoubleSpinBox->setDecimals( decimals );
703 double singleStep = calculateStep( numberDef->
minimum(), numberDef->
maximum() );
704 singleStep = std::max( singleStep, std::pow( 10, -decimals ) );
705 mDoubleSpinBox->setSingleStep( singleStep );
708 spinBox = mDoubleSpinBox;
713 mSpinBox->setExpressionsEnabled(
true );
717 spinBox->setToolTip( parameterDefinition()->toolTip() );
719 double max = 999999999;
724 double min = -999999999;
729 if ( mDoubleSpinBox )
731 mDoubleSpinBox->setMinimum( min );
732 mDoubleSpinBox->setMaximum( max );
736 mSpinBox->setMinimum(
static_cast<int>( min ) );
737 mSpinBox->setMaximum(
static_cast<int>( max ) );
742 mAllowingNull =
true;
743 if ( mDoubleSpinBox )
745 mDoubleSpinBox->setShowClearButton(
true );
746 const double min = mDoubleSpinBox->minimum() - mDoubleSpinBox->singleStep();
747 mDoubleSpinBox->setMinimum( min );
748 mDoubleSpinBox->setValue( min );
752 mSpinBox->setShowClearButton(
true );
753 const int min = mSpinBox->minimum() - 1;
754 mSpinBox->setMinimum( min );
755 mSpinBox->setValue( min );
757 spinBox->setSpecialValueText( tr(
"Not set" ) );
765 if ( mDoubleSpinBox )
769 mDoubleSpinBox->setClearValue( defaultVal );
775 mSpinBox->setClearValue( intVal );
781 if ( mDoubleSpinBox )
782 mDoubleSpinBox->setClearValue( numberDef->
minimum() );
784 mSpinBox->setClearValue(
static_cast<int>( numberDef->
minimum() ) );
789 if ( mDoubleSpinBox )
791 mDoubleSpinBox->setValue( 0 );
792 mDoubleSpinBox->setClearValue( 0 );
796 mSpinBox->setValue( 0 );
797 mSpinBox->setClearValue( 0 );
802 if ( mDoubleSpinBox )
803 connect( mDoubleSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
805 connect( mSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
813void QgsProcessingNumericWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
815 if ( mDoubleSpinBox )
817 if ( mAllowingNull && !value.isValid() )
818 mDoubleSpinBox->clear();
822 mDoubleSpinBox->setValue( v );
827 if ( mAllowingNull && !value.isValid() )
832 mSpinBox->setValue( v );
837QVariant QgsProcessingNumericWidgetWrapper::widgetValue()
const
839 if ( mDoubleSpinBox )
841 if ( mAllowingNull &&
qgsDoubleNear( mDoubleSpinBox->value(), mDoubleSpinBox->minimum() ) )
844 return mDoubleSpinBox->value();
848 if ( mAllowingNull && mSpinBox->value() == mSpinBox->minimum() )
851 return mSpinBox->value();
857double QgsProcessingNumericWidgetWrapper::calculateStep(
const double minimum,
const double maximum )
859 const double valueRange = maximum - minimum;
860 if ( valueRange <= 1.0 )
862 const double step = valueRange / 10.0;
864 return qgsRound( step, -std::floor( std::log( step ) ) );
872QString QgsProcessingNumericWidgetWrapper::parameterType()
const
879 return new QgsProcessingNumericWidgetWrapper( parameter, type );
886 return new QgsProcessingNumberParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
893QgsProcessingDistanceParameterDefinitionWidget::QgsProcessingDistanceParameterDefinitionWidget(
898 QVBoxLayout *vlayout =
new QVBoxLayout();
899 vlayout->setContentsMargins( 0, 0, 0, 0 );
901 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
903 mParentLayerComboBox =
new QComboBox();
905 QString initialParent;
907 initialParent = distParam->parentParameterName();
909 if (
auto *lModel = widgetContext.
model() )
912 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
913 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
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 );
941 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
942 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
944 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
950 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
953 mParentLayerComboBox->addItem( initialParent, initialParent );
954 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
957 vlayout->addWidget( mParentLayerComboBox );
960 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
961 mMinLineEdit =
new QLineEdit();
962 vlayout->addWidget( mMinLineEdit );
964 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
965 mMaxLineEdit =
new QLineEdit();
966 vlayout->addWidget( mMaxLineEdit );
968 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
969 mDefaultLineEdit =
new QLineEdit();
970 vlayout->addWidget( mDefaultLineEdit );
974 mMinLineEdit->setText( QLocale().toString( distParam->minimum() ) );
975 mMaxLineEdit->setText( QLocale().toString( distParam->maximum() ) );
976 mDefaultLineEdit->setText( distParam->defaultValueForGui().toString() );
982 setLayout( vlayout );
990 auto param = std::make_unique<QgsProcessingParameterDistance>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
995 param->setMinimum( val );
1001 param->setMaximum( val );
1004 param->setFlags( flags );
1005 return param.release();
1009 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1012QString QgsProcessingDistanceWidgetWrapper::parameterType()
const
1019 return new QgsProcessingDistanceWidgetWrapper( parameter, type );
1022QWidget *QgsProcessingDistanceWidgetWrapper::createWidget()
1026 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1031 mLabel =
new QLabel();
1032 mUnitsCombo =
new QComboBox();
1044 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1045 QHBoxLayout *layout =
new QHBoxLayout();
1046 layout->addWidget( spin, 1 );
1047 layout->insertSpacing( 1, labelMargin / 2 );
1048 layout->insertWidget( 2, mLabel );
1049 layout->insertWidget( 3, mUnitsCombo );
1054 mWarningLabel =
new QWidget();
1055 QHBoxLayout *warningLayout =
new QHBoxLayout();
1056 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1057 QLabel *warning =
new QLabel();
1059 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1060 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1061 warning->setToolTip( tr(
"Distance is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1062 warningLayout->insertSpacing( 0, labelMargin / 2 );
1063 warningLayout->insertWidget( 1, warning );
1064 mWarningLabel->setLayout( warningLayout );
1065 layout->insertWidget( 4, mWarningLabel );
1067 QWidget *w =
new QWidget();
1068 layout->setContentsMargins( 0, 0, 0, 0 );
1069 w->setLayout( layout );
1083void QgsProcessingDistanceWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1085 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1092 if ( wrapper->parameterDefinition()->name() ==
static_cast<const QgsProcessingParameterDistance *
>( parameterDefinition() )->parentParameterName() )
1094 setUnitParameterValue( wrapper->parameterValue(), wrapper );
1114 std::unique_ptr<QgsProcessingContext> tmpContext;
1115 if ( mProcessingContextGenerator )
1116 context = mProcessingContextGenerator->processingContext();
1120 tmpContext = std::make_unique<QgsProcessingContext>();
1121 context = tmpContext.get();
1128 units = crs.mapUnits();
1139 mUnitsCombo->hide();
1147 if ( mBaseUnit != units )
1149 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( units ) ) );
1152 mUnitsCombo->show();
1159QVariant QgsProcessingDistanceWidgetWrapper::widgetValue()
const
1161 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1162 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1177 return new QgsProcessingDistanceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1185QgsProcessingAreaParameterDefinitionWidget::QgsProcessingAreaParameterDefinitionWidget(
1190 QVBoxLayout *vlayout =
new QVBoxLayout();
1191 vlayout->setContentsMargins( 0, 0, 0, 0 );
1193 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
1195 mParentLayerComboBox =
new QComboBox();
1197 QString initialParent;
1199 initialParent = areaParam->parentParameterName();
1201 if (
auto *lModel = widgetContext.
model() )
1204 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
1205 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
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 );
1233 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1234 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1236 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1242 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
1245 mParentLayerComboBox->addItem( initialParent, initialParent );
1246 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1251 vlayout->addWidget( mParentLayerComboBox );
1253 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1254 mMinLineEdit =
new QLineEdit();
1255 vlayout->addWidget( mMinLineEdit );
1257 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1258 mMaxLineEdit =
new QLineEdit();
1259 vlayout->addWidget( mMaxLineEdit );
1261 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1262 mDefaultLineEdit =
new QLineEdit();
1263 vlayout->addWidget( mDefaultLineEdit );
1267 mMinLineEdit->setText( QLocale().toString( areaParam->minimum() ) );
1268 mMaxLineEdit->setText( QLocale().toString( areaParam->maximum() ) );
1269 mDefaultLineEdit->setText( areaParam->defaultValueForGui().toString() );
1276 setLayout( vlayout );
1284 auto param = std::make_unique<QgsProcessingParameterArea>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1289 param->setMinimum( val );
1295 param->setMaximum( val );
1298 param->setFlags( flags );
1299 return param.release();
1308 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1311QString QgsProcessingAreaWidgetWrapper::parameterType()
const
1318 return new QgsProcessingAreaWidgetWrapper( parameter, type );
1321QWidget *QgsProcessingAreaWidgetWrapper::createWidget()
1325 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1330 mLabel =
new QLabel();
1331 mUnitsCombo =
new QComboBox();
1346 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1347 QHBoxLayout *layout =
new QHBoxLayout();
1348 layout->addWidget( spin, 1 );
1349 layout->insertSpacing( 1, labelMargin / 2 );
1350 layout->insertWidget( 2, mLabel );
1351 layout->insertWidget( 3, mUnitsCombo );
1356 mWarningLabel =
new QWidget();
1357 QHBoxLayout *warningLayout =
new QHBoxLayout();
1358 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1359 QLabel *warning =
new QLabel();
1361 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1362 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1363 warning->setToolTip( tr(
"Area is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1364 warningLayout->insertSpacing( 0, labelMargin / 2 );
1365 warningLayout->insertWidget( 1, warning );
1366 mWarningLabel->setLayout( warningLayout );
1367 layout->insertWidget( 4, mWarningLabel );
1369 QWidget *w =
new QWidget();
1370 layout->setContentsMargins( 0, 0, 0, 0 );
1371 w->setLayout( layout );
1385void QgsProcessingAreaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1387 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1416 std::unique_ptr<QgsProcessingContext> tmpContext;
1417 if ( mProcessingContextGenerator )
1418 context = mProcessingContextGenerator->processingContext();
1422 tmpContext = std::make_unique<QgsProcessingContext>();
1423 context = tmpContext.get();
1430 units = QgsUnitTypes::distanceToAreaUnit( crs.mapUnits() );
1436void QgsProcessingAreaWidgetWrapper::setUnits(
Qgis::AreaUnit units )
1441 mUnitsCombo->hide();
1446 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QVariant::fromValue( units ) ) );
1447 mUnitsCombo->show();
1454QVariant QgsProcessingAreaWidgetWrapper::widgetValue()
const
1456 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1457 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1472 return new QgsProcessingAreaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1480QgsProcessingVolumeParameterDefinitionWidget::QgsProcessingVolumeParameterDefinitionWidget(
1485 QVBoxLayout *vlayout =
new QVBoxLayout();
1486 vlayout->setContentsMargins( 0, 0, 0, 0 );
1488 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
1490 mParentLayerComboBox =
new QComboBox();
1492 QString initialParent;
1494 initialParent = volumeParam->parentParameterName();
1496 if (
auto *lModel = widgetContext.
model() )
1499 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
1500 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
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 );
1528 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1529 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1531 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1537 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
1540 mParentLayerComboBox->addItem( initialParent, initialParent );
1541 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1544 vlayout->addWidget( mParentLayerComboBox );
1546 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1547 mMinLineEdit =
new QLineEdit();
1548 vlayout->addWidget( mMinLineEdit );
1550 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1551 mMaxLineEdit =
new QLineEdit();
1552 vlayout->addWidget( mMaxLineEdit );
1554 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1555 mDefaultLineEdit =
new QLineEdit();
1556 vlayout->addWidget( mDefaultLineEdit );
1560 mMinLineEdit->setText( QLocale().toString( volumeParam->minimum() ) );
1561 mMaxLineEdit->setText( QLocale().toString( volumeParam->maximum() ) );
1562 mDefaultLineEdit->setText( volumeParam->defaultValueForGui().toString() );
1570 setLayout( vlayout );
1578 auto param = std::make_unique<QgsProcessingParameterVolume>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1583 param->setMinimum( val );
1589 param->setMaximum( val );
1592 param->setFlags( flags );
1593 return param.release();
1602 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1605QString QgsProcessingVolumeWidgetWrapper::parameterType()
const
1612 return new QgsProcessingVolumeWidgetWrapper( parameter, type );
1615QWidget *QgsProcessingVolumeWidgetWrapper::createWidget()
1619 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1624 mLabel =
new QLabel();
1625 mUnitsCombo =
new QComboBox();
1638 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1639 QHBoxLayout *layout =
new QHBoxLayout();
1640 layout->addWidget( spin, 1 );
1641 layout->insertSpacing( 1, labelMargin / 2 );
1642 layout->insertWidget( 2, mLabel );
1643 layout->insertWidget( 3, mUnitsCombo );
1648 mWarningLabel =
new QWidget();
1649 QHBoxLayout *warningLayout =
new QHBoxLayout();
1650 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1651 QLabel *warning =
new QLabel();
1653 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1654 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1655 warning->setToolTip( tr(
"Volume is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1656 warningLayout->insertSpacing( 0, labelMargin / 2 );
1657 warningLayout->insertWidget( 1, warning );
1658 mWarningLabel->setLayout( warningLayout );
1659 layout->insertWidget( 4, mWarningLabel );
1661 QWidget *w =
new QWidget();
1662 layout->setContentsMargins( 0, 0, 0, 0 );
1663 w->setLayout( layout );
1677void QgsProcessingVolumeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1679 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1708 std::unique_ptr<QgsProcessingContext> tmpContext;
1709 if ( mProcessingContextGenerator )
1710 context = mProcessingContextGenerator->processingContext();
1714 tmpContext = std::make_unique<QgsProcessingContext>();
1715 context = tmpContext.get();
1722 units = QgsUnitTypes::distanceToVolumeUnit( crs.mapUnits() );
1733 mUnitsCombo->hide();
1738 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QVariant::fromValue( units ) ) );
1739 mUnitsCombo->show();
1746QVariant QgsProcessingVolumeWidgetWrapper::widgetValue()
const
1748 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1749 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1764 return new QgsProcessingVolumeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1772QgsProcessingDurationParameterDefinitionWidget::QgsProcessingDurationParameterDefinitionWidget(
1777 QVBoxLayout *vlayout =
new QVBoxLayout();
1778 vlayout->setContentsMargins( 0, 0, 0, 0 );
1780 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1781 mMinLineEdit =
new QLineEdit();
1782 vlayout->addWidget( mMinLineEdit );
1784 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1785 mMaxLineEdit =
new QLineEdit();
1786 vlayout->addWidget( mMaxLineEdit );
1788 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1789 mDefaultLineEdit =
new QLineEdit();
1790 vlayout->addWidget( mDefaultLineEdit );
1792 vlayout->addWidget(
new QLabel( tr(
"Default unit type" ) ) );
1794 mUnitsCombo =
new QComboBox();
1804 vlayout->addWidget( mUnitsCombo );
1810 mMinLineEdit->setText( QLocale().toString( durationParam->minimum() ) );
1811 mMaxLineEdit->setText( QLocale().toString( durationParam->maximum() ) );
1812 mDefaultLineEdit->setText( durationParam->defaultValueForGui().toString() );
1813 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( durationParam->defaultUnit() ) ) );
1819 setLayout( vlayout );
1827 auto param = std::make_unique<QgsProcessingParameterDuration>( name, description, ok ? val : QVariant() );
1832 param->setMinimum( val );
1838 param->setMaximum( val );
1841 param->setDefaultUnit(
static_cast<Qgis::TemporalUnit>( mUnitsCombo->currentData().toInt() ) );
1843 param->setFlags( flags );
1844 return param.release();
1848 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1851QString QgsProcessingDurationWidgetWrapper::parameterType()
const
1858 return new QgsProcessingDurationWidgetWrapper( parameter, type );
1861QWidget *QgsProcessingDurationWidgetWrapper::createWidget()
1865 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1870 mUnitsCombo =
new QComboBox();
1882 QHBoxLayout *layout =
new QHBoxLayout();
1883 layout->addWidget( spin, 1 );
1884 layout->insertWidget( 1, mUnitsCombo );
1886 QWidget *w =
new QWidget();
1887 layout->setContentsMargins( 0, 0, 0, 0 );
1888 w->setLayout( layout );
1890 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( durationDef->
defaultUnit() ) ) );
1891 mUnitsCombo->show();
1903QLabel *QgsProcessingDurationWidgetWrapper::createLabel()
1915QVariant QgsProcessingDurationWidgetWrapper::widgetValue()
const
1917 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1918 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo )
1929void QgsProcessingDurationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1935 QgsProcessingNumericWidgetWrapper::setWidgetValue( val, context );
1939 QgsProcessingNumericWidgetWrapper::setWidgetValue( value, context );
1947 return new QgsProcessingDurationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1954QgsProcessingScaleParameterDefinitionWidget::QgsProcessingScaleParameterDefinitionWidget(
1959 QVBoxLayout *vlayout =
new QVBoxLayout();
1960 vlayout->setContentsMargins( 0, 0, 0, 0 );
1962 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1964 mDefaultLineEdit =
new QLineEdit();
1968 mDefaultLineEdit->setText( scaleParam->defaultValueForGui().toString() );
1971 vlayout->addWidget( mDefaultLineEdit );
1974 setLayout( vlayout );
1980 double val = mDefaultLineEdit->text().toDouble( &ok );
1981 auto param = std::make_unique<QgsProcessingParameterScale>( name, description, ok ? val : QVariant() );
1982 param->setFlags( flags );
1983 return param.release();
1987 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1990QString QgsProcessingScaleWidgetWrapper::parameterType()
const
1997 return new QgsProcessingScaleWidgetWrapper( parameter, type );
2000QWidget *QgsProcessingScaleWidgetWrapper::createWidget()
2012 mScaleWidget->setAllowNull(
true );
2014 mScaleWidget->setMapCanvas( widgetContext().mapCanvas() );
2015 mScaleWidget->setShowCurrentScaleButton(
true );
2017 mScaleWidget->setToolTip( parameterDefinition()->toolTip() );
2019 return mScaleWidget;
2028 mScaleWidget->setMapCanvas( context.
mapCanvas() );
2033QVariant QgsProcessingScaleWidgetWrapper::widgetValue()
const
2035 return mScaleWidget && !mScaleWidget->isNull() ? QVariant( mScaleWidget->scale() ) : QVariant();
2038void QgsProcessingScaleWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2042 if ( mScaleWidget->allowNull() && !value.isValid() )
2043 mScaleWidget->setNull();
2047 mScaleWidget->setScale( v );
2056 return new QgsProcessingScaleParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2064QgsProcessingRangeParameterDefinitionWidget::QgsProcessingRangeParameterDefinitionWidget(
2069 QVBoxLayout *vlayout =
new QVBoxLayout();
2070 vlayout->setContentsMargins( 0, 0, 0, 0 );
2072 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
2074 mTypeComboBox =
new QComboBox();
2077 vlayout->addWidget( mTypeComboBox );
2079 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
2080 mMinLineEdit =
new QLineEdit();
2081 vlayout->addWidget( mMinLineEdit );
2083 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
2084 mMaxLineEdit =
new QLineEdit();
2085 vlayout->addWidget( mMaxLineEdit );
2089 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( rangeParam->dataType() ) ) );
2091 mMinLineEdit->setText( QLocale().toString( range.at( 0 ) ) );
2092 mMaxLineEdit->setText( QLocale().toString( range.at( 1 ) ) );
2099 setLayout( vlayout );
2104 QString defaultValue;
2105 if ( mMinLineEdit->text().isEmpty() )
2107 defaultValue = u
"None"_s;
2115 defaultValue = u
"None"_s;
2119 if ( mMaxLineEdit->text().isEmpty() )
2121 defaultValue +=
",None"_L1;
2127 defaultValue += u
",%1"_s.arg( ok ? QString::number( val ) :
"None"_L1 );
2131 auto param = std::make_unique<QgsProcessingParameterRange>( name, description, dataType, defaultValue );
2132 param->setFlags( flags );
2133 return param.release();
2141QWidget *QgsProcessingRangeWidgetWrapper::createWidget()
2150 QHBoxLayout *layout =
new QHBoxLayout();
2155 mMinSpinBox->setExpressionsEnabled(
true );
2156 mMinSpinBox->setShowClearButton(
false );
2157 mMaxSpinBox->setExpressionsEnabled(
true );
2158 mMaxSpinBox->setShowClearButton(
false );
2160 QLabel *minLabel =
new QLabel( tr(
"Min" ) );
2161 layout->addWidget( minLabel );
2162 layout->addWidget( mMinSpinBox, 1 );
2164 QLabel *maxLabel =
new QLabel( tr(
"Max" ) );
2165 layout->addWidget( maxLabel );
2166 layout->addWidget( mMaxSpinBox, 1 );
2168 QWidget *w =
new QWidget();
2169 layout->setContentsMargins( 0, 0, 0, 0 );
2170 w->setLayout( layout );
2174 mMinSpinBox->setDecimals( 6 );
2175 mMaxSpinBox->setDecimals( 6 );
2179 mMinSpinBox->setDecimals( 0 );
2180 mMaxSpinBox->setDecimals( 0 );
2183 mMinSpinBox->setMinimum( -99999999.999999 );
2184 mMaxSpinBox->setMinimum( -99999999.999999 );
2185 mMinSpinBox->setMaximum( 99999999.999999 );
2186 mMaxSpinBox->setMaximum( 99999999.999999 );
2190 mAllowingNull =
true;
2192 const double min = mMinSpinBox->minimum() - 1;
2193 mMinSpinBox->setMinimum( min );
2194 mMaxSpinBox->setMinimum( min );
2195 mMinSpinBox->setValue( min );
2196 mMaxSpinBox->setValue( min );
2198 mMinSpinBox->setShowClearButton(
true );
2199 mMaxSpinBox->setShowClearButton(
true );
2200 mMinSpinBox->setSpecialValueText( tr(
"Not set" ) );
2201 mMaxSpinBox->setSpecialValueText( tr(
"Not set" ) );
2204 w->setToolTip( parameterDefinition()->toolTip() );
2206 connect( mMinSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this](
const double v ) {
2207 mBlockChangedSignal++;
2208 if ( !mAllowingNull && v > mMaxSpinBox->value() )
2209 mMaxSpinBox->setValue( v );
2210 mBlockChangedSignal--;
2212 if ( !mBlockChangedSignal )
2213 emit widgetValueHasChanged(
this );
2215 connect( mMaxSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this](
const double v ) {
2216 mBlockChangedSignal++;
2217 if ( !mAllowingNull && v < mMinSpinBox->value() )
2218 mMinSpinBox->setValue( v );
2219 mBlockChangedSignal--;
2221 if ( !mBlockChangedSignal )
2222 emit widgetValueHasChanged(
this );
2231void QgsProcessingRangeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2234 if ( mAllowingNull && v.empty() )
2236 mMinSpinBox->clear();
2237 mMaxSpinBox->clear();
2244 if ( mAllowingNull )
2246 mBlockChangedSignal++;
2247 if ( std::isnan( v.at( 0 ) ) )
2248 mMinSpinBox->clear();
2250 mMinSpinBox->setValue( v.at( 0 ) );
2252 if ( v.count() >= 2 )
2254 if ( std::isnan( v.at( 1 ) ) )
2255 mMaxSpinBox->clear();
2257 mMaxSpinBox->setValue( v.at( 1 ) );
2259 mBlockChangedSignal--;
2263 mBlockChangedSignal++;
2264 mMinSpinBox->setValue( v.at( 0 ) );
2265 if ( v.count() >= 2 )
2266 mMaxSpinBox->setValue( v.at( 1 ) );
2267 mBlockChangedSignal--;
2271 if ( !mBlockChangedSignal )
2272 emit widgetValueHasChanged(
this );
2275QVariant QgsProcessingRangeWidgetWrapper::widgetValue()
const
2277 if ( mAllowingNull )
2280 if (
qgsDoubleNear( mMinSpinBox->value(), mMinSpinBox->minimum() ) )
2283 value = QString::number( mMinSpinBox->value() );
2285 if (
qgsDoubleNear( mMaxSpinBox->value(), mMaxSpinBox->minimum() ) )
2286 value +=
",None"_L1;
2288 value += u
",%1"_s.arg( mMaxSpinBox->value() );
2293 return u
"%1,%2"_s.arg( mMinSpinBox->value() ).arg( mMaxSpinBox->value() );
2296QString QgsProcessingRangeWidgetWrapper::modelerExpressionFormatString()
const
2298 return tr(
"string as two comma delimited floats, e.g. '1,10'" );
2301QString QgsProcessingRangeWidgetWrapper::parameterType()
const
2308 return new QgsProcessingRangeWidgetWrapper( parameter, type );
2315 return new QgsProcessingRangeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2323QgsProcessingMatrixParameterDefinitionWidget::QgsProcessingMatrixParameterDefinitionWidget(
2328 QVBoxLayout *vlayout =
new QVBoxLayout();
2329 vlayout->setContentsMargins( 0, 0, 0, 0 );
2331 mMatrixWidget =
new QgsProcessingMatrixModelerWidget();
2334 mMatrixWidget->setValue( matrixParam->headers(), matrixParam->defaultValueForGui() );
2335 mMatrixWidget->setFixedRows( matrixParam->hasFixedNumberRows() );
2337 vlayout->addWidget( mMatrixWidget );
2341 setLayout( vlayout );
2346 auto param = std::make_unique<QgsProcessingParameterMatrix>( name, description, 1, mMatrixWidget->fixedRows(), mMatrixWidget->headers(), mMatrixWidget->value() );
2347 param->setFlags( flags );
2348 return param.release();
2356QWidget *QgsProcessingMatrixWidgetWrapper::createWidget()
2358 mMatrixWidget =
new QgsProcessingMatrixParameterPanel(
nullptr,
dynamic_cast<const QgsProcessingParameterMatrix *
>( parameterDefinition() ) );
2359 mMatrixWidget->setToolTip( parameterDefinition()->toolTip() );
2361 connect( mMatrixWidget, &QgsProcessingMatrixParameterPanel::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
2369 return mMatrixWidget;
2375void QgsProcessingMatrixWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2378 if ( mMatrixWidget )
2379 mMatrixWidget->setValue( v );
2382QVariant QgsProcessingMatrixWidgetWrapper::widgetValue()
const
2384 if ( mMatrixWidget )
2385 return mMatrixWidget->value().isEmpty() ? QVariant() : mMatrixWidget->value();
2390QString QgsProcessingMatrixWidgetWrapper::modelerExpressionFormatString()
const
2392 return tr(
"comma delimited string of values, or an array of values" );
2395QString QgsProcessingMatrixWidgetWrapper::parameterType()
const
2402 return new QgsProcessingMatrixWidgetWrapper( parameter, type );
2409 return new QgsProcessingMatrixParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2418QgsProcessingFileParameterDefinitionWidget::QgsProcessingFileParameterDefinitionWidget(
2423 QVBoxLayout *vlayout =
new QVBoxLayout();
2424 vlayout->setContentsMargins( 0, 0, 0, 0 );
2426 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
2428 mTypeComboBox =
new QComboBox();
2432 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( fileParam->behavior() ) ) );
2434 mTypeComboBox->setCurrentIndex( 0 );
2435 vlayout->addWidget( mTypeComboBox );
2439 vlayout->addWidget(
new QLabel( tr(
"File filter" ) ) );
2441 mFilterComboBox =
new QComboBox();
2442 mFilterComboBox->setEditable(
true );
2444 mFilterComboBox->addItem( tr(
"All Files (*.*)" ) );
2445 mFilterComboBox->addItem( tr(
"CSV Files (*.csv)" ) );
2446 mFilterComboBox->addItem( tr(
"HTML Files (*.html *.htm)" ) );
2447 mFilterComboBox->addItem( tr(
"Text Files (*.txt)" ) );
2449 mFilterComboBox->setCurrentText( fileParam->fileFilter() );
2451 mFilterComboBox->setCurrentIndex( 0 );
2452 vlayout->addWidget( mFilterComboBox );
2456 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2459 mDefaultFileWidget->lineEdit()->setShowClearButton(
true );
2463 mDefaultFileWidget->setFilePath( fileParam->defaultValueForGui().toString() );
2467 vlayout->addWidget( mDefaultFileWidget );
2470 connect( mTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this] {
2478 setLayout( vlayout );
2483 auto param = std::make_unique<QgsProcessingParameterFile>( name, description );
2486 param->setFileFilter( mFilterComboBox->currentText() );
2487 if ( !mDefaultFileWidget->filePath().isEmpty() )
2488 param->setDefaultValue( mDefaultFileWidget->filePath() );
2489 param->setFlags( flags );
2490 return param.release();
2498QWidget *QgsProcessingFileWidgetWrapper::createWidget()
2511 mFileWidget->setToolTip( parameterDefinition()->toolTip() );
2512 mFileWidget->setDialogTitle( parameterDefinition()->description() );
2514 mFileWidget->setDefaultRoot(
QgsSettings().value( u
"/Processing/LastInputPath"_s, QDir::homePath() ).toString() );
2521 mFileWidget->setFilter( fileParam->
fileFilter() );
2522 else if ( !fileParam->
extension().isEmpty() )
2523 mFileWidget->setFilter( tr(
"%1 files" ).arg( fileParam->
extension().toUpper() ) + u
" (*."_s + fileParam->
extension().toLower() +
')' );
2532 QgsSettings().
setValue( u
"/Processing/LastInputPath"_s, QFileInfo( path ).canonicalPath() );
2533 emit widgetValueHasChanged(
this );
2541void QgsProcessingFileWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2545 mFileWidget->setFilePath( v );
2548QVariant QgsProcessingFileWidgetWrapper::widgetValue()
const
2551 return mFileWidget->filePath();
2556QString QgsProcessingFileWidgetWrapper::modelerExpressionFormatString()
const
2558 return tr(
"string representing a path to a file or folder" );
2561QString QgsProcessingFileWidgetWrapper::parameterType()
const
2568 return new QgsProcessingFileWidgetWrapper( parameter, type );
2575 return new QgsProcessingFileParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2583QgsProcessingExpressionParameterDefinitionWidget::QgsProcessingExpressionParameterDefinitionWidget(
2588 QVBoxLayout *vlayout =
new QVBoxLayout();
2589 vlayout->setContentsMargins( 0, 0, 0, 0 );
2590 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2593 mDefaultQgisLineEdit->registerExpressionContextGenerator(
this );
2595 mDefaultPointCloudLineEdit =
new QgsProcessingPointCloudExpressionLineEdit();
2596 mDefaultRasterCalculatorLineEdit =
new QgsProcessingRasterCalculatorExpressionLineEdit();
2598 QStackedWidget *stackedWidget =
new QStackedWidget();
2599 stackedWidget->addWidget( mDefaultQgisLineEdit );
2600 stackedWidget->addWidget( mDefaultPointCloudLineEdit );
2601 stackedWidget->addWidget( mDefaultRasterCalculatorLineEdit );
2602 vlayout->addWidget( stackedWidget );
2611 mDefaultQgisLineEdit->setExpression( expr );
2612 mDefaultPointCloudLineEdit->setExpression( expr );
2615 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
2617 mParentLayerComboBox =
new QComboBox();
2618 vlayout->addWidget( mParentLayerComboBox );
2620 vlayout->addWidget(
new QLabel( tr(
"Expression type" ) ) );
2621 mExpressionTypeComboBox =
new QComboBox();
2626 connect( mExpressionTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [
this, stackedWidget, definition, widgetContext](
int ) {
2627 mParentLayerComboBox->clear();
2628 mParentLayerComboBox->addItem( tr(
"None" ), QVariant() );
2630 stackedWidget->setCurrentIndex( mExpressionTypeComboBox->currentIndex() > 0 ? mExpressionTypeComboBox->currentIndex() : 0 );
2632 QString initialParent;
2634 initialParent = expParam->parentLayerParameterName();
2638 if ( QgsProcessingModelAlgorithm *model = widgetContext.
model() )
2641 const QMap<QString, QgsProcessingModelParameter> components = model->parameterComponents();
2642 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
2649 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2650 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2652 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2657 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2658 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2660 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2667 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2668 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2670 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2681 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2682 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2684 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2692 if ( mParentLayerComboBox->count() == 1 && !initialParent.isEmpty() )
2695 mParentLayerComboBox->addItem( initialParent, initialParent );
2696 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2700 mExpressionTypeComboBox->setCurrentIndex( -1 );
2702 mExpressionTypeComboBox->setCurrentIndex( mExpressionTypeComboBox->findData(
static_cast<int>( expParam->expressionType() ) ) );
2704 mExpressionTypeComboBox->setCurrentIndex( 0 );
2706 vlayout->addWidget( mExpressionTypeComboBox );
2711 setLayout( vlayout );
2718 switch ( expressionType )
2721 expression = mDefaultQgisLineEdit->expression();
2724 expression = mDefaultPointCloudLineEdit->expression();
2727 expression = mDefaultRasterCalculatorLineEdit->expression();
2730 auto param = std::make_unique<QgsProcessingParameterExpression>( name, description, expression, mParentLayerComboBox->currentData().toString(),
false, expressionType );
2731 param->setFlags( flags );
2732 return param.release();
2739QWidget *QgsProcessingExpressionWidgetWrapper::createWidget()
2754 mExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2755 mExpLineEdit->setExpressionDialogTitle( parameterDefinition()->description() );
2756 mExpLineEdit->registerExpressionContextGenerator(
this );
2758 return mExpLineEdit;
2764 mPointCloudExpLineEdit =
new QgsProcessingPointCloudExpressionLineEdit();
2765 mPointCloudExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2766 connect( mPointCloudExpLineEdit, &QgsProcessingPointCloudExpressionLineEdit::expressionChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
2767 return mPointCloudExpLineEdit;
2772 mRasterCalculatorExpLineEdit =
new QgsProcessingRasterCalculatorExpressionLineEdit();
2773 mRasterCalculatorExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2776 mRasterCalculatorExpLineEdit->setLayers( QVariantList() <<
"A" <<
"B" <<
"C" <<
"D" <<
"E" <<
"F" <<
"G" );
2778 connect( mRasterCalculatorExpLineEdit, &QgsProcessingRasterCalculatorExpressionLineEdit::expressionChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
2779 return mRasterCalculatorExpLineEdit;
2783 if ( expParam->
metadata().value( u
"inlineEditor"_s ).toBool() )
2786 mExpBuilderWidget->setToolTip( parameterDefinition()->toolTip() );
2787 mExpBuilderWidget->init( createExpressionContext() );
2789 Q_UNUSED( changed );
2790 emit widgetValueHasChanged(
this );
2792 return mExpBuilderWidget;
2797 mFieldExpWidget->setToolTip( parameterDefinition()->toolTip() );
2798 mFieldExpWidget->setExpressionDialogTitle( parameterDefinition()->description() );
2799 mFieldExpWidget->registerExpressionContextGenerator(
this );
2801 mFieldExpWidget->setAllowEmptyFieldName(
true );
2804 emit widgetValueHasChanged(
this );
2806 return mFieldExpWidget;
2814void QgsProcessingExpressionWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
2826 setParentLayerWrapperValue( wrapper );
2842 if ( mExpBuilderWidget )
2845 mExpBuilderWidget->setExpressionContext( createExpressionContext() );
2853 std::unique_ptr<QgsProcessingContext> tmpContext;
2854 if ( mProcessingContextGenerator )
2855 context = mProcessingContextGenerator->processingContext();
2859 tmpContext = std::make_unique<QgsProcessingContext>();
2860 context = tmpContext.get();
2873 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2883 if ( mFieldExpWidget )
2884 mFieldExpWidget->setLayer(
nullptr );
2885 else if ( mExpBuilderWidget )
2886 mExpBuilderWidget->setLayer(
nullptr );
2887 else if ( mExpLineEdit )
2888 mExpLineEdit->setLayer(
nullptr );
2894 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
2897 mParentLayer = std::move( ownedLayer );
2905 if ( mFieldExpWidget )
2906 mFieldExpWidget->setLayer( layer );
2907 if ( mExpBuilderWidget )
2908 mExpBuilderWidget->setLayer( layer );
2909 else if ( mExpLineEdit )
2910 mExpLineEdit->setLayer( layer );
2919 if ( mPointCloudExpLineEdit )
2920 mPointCloudExpLineEdit->setLayer(
nullptr );
2926 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
2929 mParentLayer = std::move( ownedLayer );
2937 if ( mPointCloudExpLineEdit )
2938 mPointCloudExpLineEdit->setLayer( layer );
2945 if ( layers.isEmpty() )
2947 if ( mRasterCalculatorExpLineEdit )
2949 mRasterCalculatorExpLineEdit->setLayers( val.userType() == QMetaType::Type::QVariantList ? val.toList() : QVariantList() << val );
2954 if ( mRasterCalculatorExpLineEdit )
2956 QVariantList layersList;
2959 layersList << layer->
name();
2961 mRasterCalculatorExpLineEdit->setLayers( layersList );
2969void QgsProcessingExpressionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2972 if ( mFieldExpWidget )
2973 mFieldExpWidget->setExpression( v );
2974 else if ( mExpBuilderWidget )
2975 mExpBuilderWidget->setExpressionText( v );
2976 else if ( mExpLineEdit )
2977 mExpLineEdit->setExpression( v );
2978 else if ( mPointCloudExpLineEdit )
2979 mPointCloudExpLineEdit->setExpression( v );
2980 else if ( mRasterCalculatorExpLineEdit )
2981 mRasterCalculatorExpLineEdit->setExpression( v );
2984QVariant QgsProcessingExpressionWidgetWrapper::widgetValue()
const
2986 if ( mFieldExpWidget )
2987 return mFieldExpWidget->expression();
2988 if ( mExpBuilderWidget )
2989 return mExpBuilderWidget->expressionText();
2990 else if ( mExpLineEdit )
2991 return mExpLineEdit->expression();
2992 else if ( mPointCloudExpLineEdit )
2993 return mPointCloudExpLineEdit->expression();
2994 else if ( mRasterCalculatorExpLineEdit )
2995 return mRasterCalculatorExpLineEdit->expression();
3000QString QgsProcessingExpressionWidgetWrapper::modelerExpressionFormatString()
const
3002 return tr(
"string representation of an expression" );
3005const QgsVectorLayer *QgsProcessingExpressionWidgetWrapper::linkedVectorLayer()
const
3007 if ( mFieldExpWidget && mFieldExpWidget->layer() )
3008 return mFieldExpWidget->layer();
3010 if ( mExpBuilderWidget && mExpBuilderWidget->layer() )
3011 return mExpBuilderWidget->layer();
3016QString QgsProcessingExpressionWidgetWrapper::parameterType()
const
3023 return new QgsProcessingExpressionWidgetWrapper( parameter, type );
3030 return new QgsProcessingExpressionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3042 QHBoxLayout *hl =
new QHBoxLayout();
3043 hl->setContentsMargins( 0, 0, 0, 0 );
3045 mLineEdit =
new QLineEdit();
3046 mLineEdit->setEnabled(
false );
3047 hl->addWidget( mLineEdit, 1 );
3049 mToolButton =
new QToolButton();
3050 mToolButton->setText( QString( QChar( 0x2026 ) ) );
3051 hl->addWidget( mToolButton );
3057 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
3060 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingEnumPanelWidget::showDialog );
3063void QgsProcessingEnumPanelWidget::setValue(
const QVariant &value )
3065 if ( value.isValid() )
3067 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
3069 if ( mParam->usesStaticStrings() && mValue.count() == 1 && mValue.at( 0 ).toString().isEmpty() )
3075 updateSummaryText();
3079void QgsProcessingEnumPanelWidget::showDialog()
3081 QVariantList availableOptions;
3084 availableOptions.reserve( mParam->options().size() );
3086 if ( mParam->usesStaticStrings() )
3088 for ( QString o : mParam->options() )
3090 availableOptions << o;
3095 for (
int i = 0; i < mParam->options().count(); ++i )
3096 availableOptions << i;
3100 const QStringList options = mParam ? mParam->options() : QStringList();
3104 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
3105 widget->setPanelTitle( mParam->description() );
3107 if ( mParam->usesStaticStrings() )
3109 widget->setValueFormatter( [options](
const QVariant &v ) -> QString {
3110 const QString i = v.toString();
3111 return options.contains( i ) ? i : QString();
3116 widget->setValueFormatter( [options](
const QVariant &v ) -> QString {
3117 const int i = v.toInt();
3118 return options.size() > i ? options.at( i ) : QString();
3122 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
3128 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
3130 dlg.setValueFormatter( [options](
const QVariant &v ) -> QString {
3131 const int i = v.toInt();
3132 return options.size() > i ? options.at( i ) : QString();
3136 setValue( dlg.selectedOptions() );
3141void QgsProcessingEnumPanelWidget::updateSummaryText()
3146 if ( mValue.empty() )
3148 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
3153 values.reserve( mValue.size() );
3154 if ( mParam->usesStaticStrings() )
3156 for (
const QVariant &val : std::as_const( mValue ) )
3158 values << val.toString();
3163 const QStringList options = mParam->options();
3164 for (
const QVariant &val : std::as_const( mValue ) )
3166 const int i = val.toInt();
3167 values << ( options.size() > i ? options.at( i ) : QString() );
3171 const QString concatenated = values.join( tr(
"," ) );
3172 if ( concatenated.length() < 100 )
3173 mLineEdit->setText( concatenated );
3175 mLineEdit->setText( tr(
"%n option(s) selected",
nullptr, mValue.count() ) );
3183QgsProcessingEnumCheckboxPanelWidget::QgsProcessingEnumCheckboxPanelWidget( QWidget *parent,
const QgsProcessingParameterEnum *param,
int columns )
3186 , mButtonGroup( new QButtonGroup( this ) )
3187 , mColumns( columns )
3189 mButtonGroup->setExclusive( !mParam->allowMultiple() );
3191 QGridLayout *l =
new QGridLayout();
3192 l->setContentsMargins( 0, 0, 0, 0 );
3194 int rows =
static_cast<int>( std::ceil( mParam->options().count() /
static_cast<double>( mColumns ) ) );
3195 for (
int i = 0; i < mParam->options().count(); ++i )
3197 QAbstractButton *button =
nullptr;
3198 if ( mParam->allowMultiple() )
3199 button =
new QCheckBox( mParam->options().at( i ) );
3201 button =
new QRadioButton( mParam->options().at( i ) );
3203 connect( button, &QAbstractButton::toggled,
this, [
this] {
3204 if ( !mBlockChangedSignal )
3208 mButtons.insert( i, button );
3210 mButtonGroup->addButton( button, i );
3211 l->addWidget( button, i % rows, i / rows );
3213 l->addItem(
new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, mColumns );
3216 if ( mParam->allowMultiple() )
3218 setContextMenuPolicy( Qt::CustomContextMenu );
3219 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsProcessingEnumCheckboxPanelWidget::showPopupMenu );
3223QVariant QgsProcessingEnumCheckboxPanelWidget::value()
const
3225 if ( mParam->allowMultiple() )
3228 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3230 if ( it.value()->isChecked() )
3231 value.append( mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key() );
3237 if ( mParam->usesStaticStrings() )
3238 return mButtonGroup->checkedId() >= 0 ? mParam->options().at( mButtonGroup->checkedId() ) : QVariant();
3240 return mButtonGroup->checkedId() >= 0 ? mButtonGroup->checkedId() : QVariant();
3244void QgsProcessingEnumCheckboxPanelWidget::setValue(
const QVariant &value )
3246 mBlockChangedSignal =
true;
3247 if ( mParam->allowMultiple() )
3249 QVariantList selected;
3250 if ( value.isValid() )
3251 selected = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
3252 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3254 QVariant v = mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key();
3255 it.value()->setChecked( selected.contains( v ) );
3261 if ( v.userType() == QMetaType::Type::QVariantList )
3262 v = v.toList().value( 0 );
3264 v = mParam->usesStaticStrings() ?
static_cast< int >( mParam->options().indexOf( v.toString() ) ) : v;
3265 if ( mButtons.contains( v ) )
3266 mButtons.value( v )->setChecked(
true );
3268 mBlockChangedSignal =
false;
3272void QgsProcessingEnumCheckboxPanelWidget::showPopupMenu()
3275 QAction *selectAllAction =
new QAction( tr(
"Select All" ), &popupMenu );
3276 connect( selectAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::selectAll );
3277 QAction *clearAllAction =
new QAction( tr(
"Clear Selection" ), &popupMenu );
3278 connect( clearAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::deselectAll );
3279 popupMenu.addAction( selectAllAction );
3280 popupMenu.addAction( clearAllAction );
3281 popupMenu.exec( QCursor::pos() );
3284void QgsProcessingEnumCheckboxPanelWidget::selectAll()
3286 mBlockChangedSignal =
true;
3287 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3288 it.value()->setChecked(
true );
3289 mBlockChangedSignal =
false;
3293void QgsProcessingEnumCheckboxPanelWidget::deselectAll()
3295 mBlockChangedSignal =
true;
3296 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3297 it.value()->setChecked(
false );
3298 mBlockChangedSignal =
false;
3307QgsProcessingEnumParameterDefinitionWidget::QgsProcessingEnumParameterDefinitionWidget(
3312 QVBoxLayout *vlayout =
new QVBoxLayout();
3313 vlayout->setContentsMargins( 0, 0, 0, 0 );
3315 mEnumWidget =
new QgsProcessingEnumModelerWidget();
3318 mEnumWidget->setAllowMultiple( enumParam->allowMultiple() );
3319 mEnumWidget->setOptions( enumParam->options() );
3320 mEnumWidget->setDefaultOptions( enumParam->defaultValueForGui() );
3322 vlayout->addWidget( mEnumWidget );
3326 setLayout( vlayout );
3331 auto param = std::make_unique<QgsProcessingParameterEnum>( name, description, mEnumWidget->options(), mEnumWidget->allowMultiple(), mEnumWidget->defaultOptions() );
3333 return param.release();
3341QWidget *QgsProcessingEnumWidgetWrapper::createWidget()
3352 if ( expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"useCheckBoxes"_s,
false ).toBool() )
3354 const int columns = expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"columns"_s, 2 ).toInt();
3355 mCheckboxPanel =
new QgsProcessingEnumCheckboxPanelWidget(
nullptr, expParam, columns );
3356 mCheckboxPanel->setToolTip( parameterDefinition()->toolTip() );
3357 connect( mCheckboxPanel, &QgsProcessingEnumCheckboxPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
3358 return mCheckboxPanel;
3367 mPanel =
new QgsProcessingEnumPanelWidget(
nullptr, expParam );
3368 mPanel->setToolTip( parameterDefinition()->toolTip() );
3369 connect( mPanel, &QgsProcessingEnumPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
3374 mComboBox =
new QComboBox();
3377 mComboBox->addItem( tr(
"[Not selected]" ), QVariant() );
3378 const QStringList options = expParam->
options();
3379 const QVariantList iconList = expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"icons"_s ).toList();
3380 for (
int i = 0; i < options.count(); ++i )
3382 const QIcon icon = iconList.value( i ).value<QIcon>();
3385 mComboBox->addItem( icon, options.at( i ), options.at( i ) );
3387 mComboBox->addItem( icon, options.at( i ), i );
3390 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3391 mComboBox->setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon );
3392 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
3400void QgsProcessingEnumWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3404 if ( !value.isValid() )
3405 mComboBox->setCurrentIndex( mComboBox->findData( QVariant() ) );
3411 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
3416 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
3420 else if ( mPanel || mCheckboxPanel )
3423 if ( value.isValid() )
3428 opts.reserve( v.size() );
3429 for ( QString i : v )
3435 opts.reserve( v.size() );
3441 mPanel->setValue( opts );
3442 else if ( mCheckboxPanel )
3443 mCheckboxPanel->setValue( opts );
3447QVariant QgsProcessingEnumWidgetWrapper::widgetValue()
const
3450 return mComboBox->currentData();
3452 return mPanel->value();
3453 else if ( mCheckboxPanel )
3454 return mCheckboxPanel->value();
3459QString QgsProcessingEnumWidgetWrapper::modelerExpressionFormatString()
const
3461 return tr(
"selected option index (starting from 0), array of indices, or comma separated string of options (e.g. '1,3')" );
3464QString QgsProcessingEnumWidgetWrapper::parameterType()
const
3471 return new QgsProcessingEnumWidgetWrapper( parameter, type );
3478 return new QgsProcessingEnumParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3489QWidget *QgsProcessingLayoutWidgetWrapper::createWidget()
3501 mComboBox =
new QgsLayoutComboBox(
nullptr, widgetContext().project() ? widgetContext().project()->layoutManager() :
nullptr );
3503 mComboBox->setAllowEmptyLayout(
true );
3506 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3513 mPlainComboBox =
new QComboBox();
3514 mPlainComboBox->setEditable(
true );
3515 mPlainComboBox->setToolTip( tr(
"Name of an existing print layout" ) );
3516 if ( widgetContext().project() )
3520 mPlainComboBox->addItem( layout->name() );
3523 connect( mPlainComboBox, &QComboBox::currentTextChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
3524 return mPlainComboBox;
3530void QgsProcessingLayoutWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3534 if ( !value.isValid() )
3535 mComboBox->setCurrentLayout(
nullptr );
3539 mComboBox->setCurrentLayout( l );
3541 mComboBox->setCurrentLayout(
nullptr );
3544 else if ( mPlainComboBox )
3547 mPlainComboBox->setCurrentText( v );
3551QVariant QgsProcessingLayoutWidgetWrapper::widgetValue()
const
3556 return l ? l->
name() : QVariant();
3558 else if ( mPlainComboBox )
3559 return mPlainComboBox->currentText().isEmpty() ? QVariant() : mPlainComboBox->currentText();
3567 if ( mPlainComboBox && context.
project() )
3571 mPlainComboBox->addItem( layout->name() );
3575QString QgsProcessingLayoutWidgetWrapper::modelerExpressionFormatString()
const
3577 return tr(
"string representing the name of an existing print layout" );
3580QString QgsProcessingLayoutWidgetWrapper::parameterType()
const
3587 return new QgsProcessingLayoutWidgetWrapper( parameter, type );
3596QgsProcessingLayoutItemParameterDefinitionWidget::QgsProcessingLayoutItemParameterDefinitionWidget(
3601 QVBoxLayout *vlayout =
new QVBoxLayout();
3602 vlayout->setContentsMargins( 0, 0, 0, 0 );
3604 vlayout->addWidget(
new QLabel( tr(
"Parent layout" ) ) );
3606 mParentLayoutComboBox =
new QComboBox();
3607 QString initialParent;
3609 initialParent = itemParam->parentLayoutParameterName();
3611 if (
auto *lModel = widgetContext.
model() )
3614 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3615 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3619 mParentLayoutComboBox->addItem( definition->
description(), definition->
name() );
3620 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
3622 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3628 if ( mParentLayoutComboBox->count() == 0 && !initialParent.isEmpty() )
3631 mParentLayoutComboBox->addItem( initialParent, initialParent );
3632 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3635 vlayout->addWidget( mParentLayoutComboBox );
3639 setLayout( vlayout );
3643 auto param = std::make_unique<QgsProcessingParameterLayoutItem>( name, description, QVariant(), mParentLayoutComboBox->currentData().toString() );
3645 return param.release();
3653QWidget *QgsProcessingLayoutItemWidgetWrapper::createWidget()
3667 mComboBox->setAllowEmptyItem(
true );
3668 if ( layoutParam->
itemType() >= 0 )
3671 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3678 mLineEdit =
new QLineEdit();
3679 mLineEdit->setToolTip( tr(
"UUID or ID of an existing print layout item" ) );
3680 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
3687void QgsProcessingLayoutItemWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3712void QgsProcessingLayoutItemWidgetWrapper::setLayoutParameterValue(
const QVariant &value )
3718 std::unique_ptr<QgsProcessingContext> tmpContext;
3719 if ( mProcessingContextGenerator )
3720 context = mProcessingContextGenerator->processingContext();
3724 tmpContext = std::make_unique<QgsProcessingContext>();
3725 context = tmpContext.get();
3729 setLayout( layout );
3732void QgsProcessingLayoutItemWidgetWrapper::setLayout(
QgsPrintLayout *layout )
3735 mComboBox->setCurrentLayout( layout );
3738void QgsProcessingLayoutItemWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3742 if ( !value.isValid() )
3743 mComboBox->setItem(
nullptr );
3747 mComboBox->setItem( item );
3750 else if ( mLineEdit )
3753 mLineEdit->setText( v );
3757QVariant QgsProcessingLayoutItemWidgetWrapper::widgetValue()
const
3762 return i ? i->
uuid() : QVariant();
3764 else if ( mLineEdit )
3765 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3771QString QgsProcessingLayoutItemWidgetWrapper::modelerExpressionFormatString()
const
3773 return tr(
"string representing the UUID or ID of an existing print layout item" );
3776QString QgsProcessingLayoutItemWidgetWrapper::parameterType()
const
3783 return new QgsProcessingLayoutItemWidgetWrapper( parameter, type );
3790 return new QgsProcessingLayoutItemParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3797QgsProcessingPointMapTool::QgsProcessingPointMapTool(
QgsMapCanvas *canvas )
3801 mSnapIndicator = std::make_unique<QgsSnapIndicator>( canvas );
3804QgsProcessingPointMapTool::~QgsProcessingPointMapTool() =
default;
3806void QgsProcessingPointMapTool::deactivate()
3820 if ( e->button() == Qt::LeftButton )
3823 emit clicked( point );
3828void QgsProcessingPointMapTool::keyPressEvent( QKeyEvent *e )
3830 if ( e->key() == Qt::Key_Escape )
3843QgsProcessingPointPanel::QgsProcessingPointPanel( QWidget *parent )
3846 QHBoxLayout *l =
new QHBoxLayout();
3847 l->setContentsMargins( 0, 0, 0, 0 );
3849 mLineEdit->setShowClearButton(
false );
3850 l->addWidget( mLineEdit, 1 );
3851 mButton =
new QToolButton();
3852 mButton->setText( QString( QChar( 0x2026 ) ) );
3853 l->addWidget( mButton );
3856 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::changed );
3857 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::textChanged );
3858 connect( mButton, &QToolButton::clicked,
this, &QgsProcessingPointPanel::selectOnCanvas );
3859 mButton->setVisible(
false );
3862QgsProcessingPointPanel::~QgsProcessingPointPanel()
3864 if ( mCanvas && mPrevTool && mCanvas->mapTool() == mTool.get() )
3866 mCanvas->setMapTool( mPrevTool.get() );
3870void QgsProcessingPointPanel::setMapCanvas(
QgsMapCanvas *canvas )
3873 if ( mAllowSelectOnCanvas )
3875 mButton->setVisible(
true );
3878 mTool = std::make_unique<QgsProcessingPointMapTool>( mCanvas );
3879 connect( mTool.get(), &QgsProcessingPointMapTool::clicked,
this, &QgsProcessingPointPanel::updatePoint );
3880 connect( mTool.get(), &QgsProcessingPointMapTool::complete,
this, &QgsProcessingPointPanel::pointPicked );
3884void QgsProcessingPointPanel::setAllowNull(
bool allowNull )
3886 mLineEdit->setShowClearButton( allowNull );
3889void QgsProcessingPointPanel::setShowPointOnCanvas(
bool show )
3891 if ( mShowPointOnCanvas == show )
3894 mShowPointOnCanvas = show;
3895 if ( mShowPointOnCanvas )
3901 mMapPointRubberBand.reset();
3905void QgsProcessingPointPanel::setAllowSelectOnCanvas(
bool allow )
3907 mAllowSelectOnCanvas = allow;
3908 mButton->setVisible( mAllowSelectOnCanvas &&
static_cast<bool>( mTool ) );
3911QVariant QgsProcessingPointPanel::value()
const
3913 return mLineEdit->showClearButton() && mLineEdit->text().trimmed().isEmpty() ? QVariant() : QVariant( mLineEdit->text() );
3916void QgsProcessingPointPanel::clear()
3924 QString newText = u
"%1,%2"_s.arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) );
3927 if ( mCrs.isValid() )
3929 newText += u
" [%1]"_s.arg( mCrs.authid() );
3931 mLineEdit->setText( newText );
3935void QgsProcessingPointPanel::showEvent( QShowEvent * )
3940 if ( QWidget *parentWindow = window() )
3942 setAllowSelectOnCanvas( !parentWindow->isModal() );
3948void QgsProcessingPointPanel::selectOnCanvas()
3953 mPrevTool = mCanvas->mapTool();
3954 mCanvas->setMapTool( mTool.get() );
3956 emit toggleDialogVisibility(
false );
3959void QgsProcessingPointPanel::updatePoint(
const QgsPointXY &point )
3961 setValue( point, mCanvas->mapSettings().destinationCrs() );
3964void QgsProcessingPointPanel::pointPicked()
3969 mCanvas->setMapTool( mPrevTool );
3971 emit toggleDialogVisibility(
true );
3974void QgsProcessingPointPanel::textChanged(
const QString &text )
3976 const thread_local QRegularExpression rx( u
"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
3978 const QRegularExpressionMatch match = rx.match( text );
3979 if ( match.hasMatch() )
3982 const double x = match.captured( 1 ).toDouble( &xOk );
3984 const double y = match.captured( 2 ).toDouble( &yOk );
3991 if ( pointCrs.isValid() )
4009void QgsProcessingPointPanel::updateRubberBand()
4011 if ( !mShowPointOnCanvas || !mCanvas )
4014 if ( mPoint.isEmpty() )
4016 mMapPointRubberBand.reset();
4020 if ( !mMapPointRubberBand )
4023 mMapPointRubberBand->setZValue( 1000 );
4026 const double scaleFactor = mCanvas->fontMetrics().xHeight() * .4;
4027 mMapPointRubberBand->setWidth( scaleFactor );
4028 mMapPointRubberBand->setIconSize( scaleFactor * 5 );
4030 mMapPointRubberBand->setSecondaryStrokeColor( QColor( 255, 255, 255, 100 ) );
4031 mMapPointRubberBand->setColor( QColor( 200, 0, 200 ) );
4042QgsProcessingPointParameterDefinitionWidget::QgsProcessingPointParameterDefinitionWidget(
4047 QVBoxLayout *vlayout =
new QVBoxLayout();
4048 vlayout->setContentsMargins( 0, 0, 0, 0 );
4050 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4052 mDefaultLineEdit =
new QLineEdit();
4053 mDefaultLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
4054 mDefaultLineEdit->setPlaceholderText( tr(
"Point as 'x,y'" ) );
4058 mDefaultLineEdit->setText( u
"%1,%2"_s.arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) ) );
4061 vlayout->addWidget( mDefaultLineEdit );
4065 setLayout( vlayout );
4070 auto param = std::make_unique<QgsProcessingParameterPoint>( name, description, mDefaultLineEdit->text() );
4072 return param.release();
4079QWidget *QgsProcessingPointWidgetWrapper::createWidget()
4090 mPanel =
new QgsProcessingPointPanel(
nullptr );
4091 if ( widgetContext().mapCanvas() )
4092 mPanel->setMapCanvas( widgetContext().mapCanvas() );
4095 mPanel->setAllowNull(
true );
4098 mPanel->setShowPointOnCanvas(
true );
4100 mPanel->setToolTip( parameterDefinition()->toolTip() );
4102 connect( mPanel, &QgsProcessingPointPanel::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
4105 setDialog( mDialog );
4111 mLineEdit =
new QLineEdit();
4112 mLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
4113 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
4124 mPanel->setMapCanvas( context.
mapCanvas() );
4127void QgsProcessingPointWidgetWrapper::setDialog( QWidget *dialog )
4132 connect( mPanel, &QgsProcessingPointPanel::toggleDialogVisibility, mDialog, [
this](
bool visible ) {
4134 mDialog->showMinimized();
4137 mDialog->showNormal();
4139 mDialog->activateWindow();
4146void QgsProcessingPointWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4150 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) )
4156 mPanel->setValue( p, crs );
4159 else if ( mLineEdit )
4162 mLineEdit->setText( v );
4166QVariant QgsProcessingPointWidgetWrapper::widgetValue()
const
4170 return mPanel->value();
4172 else if ( mLineEdit )
4173 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
4178QString QgsProcessingPointWidgetWrapper::modelerExpressionFormatString()
const
4180 return tr(
"string of the format 'x,y' or a geometry value (centroid is used)" );
4183QString QgsProcessingPointWidgetWrapper::parameterType()
const
4190 return new QgsProcessingPointWidgetWrapper( parameter, type );
4197 return new QgsProcessingPointParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4206QgsProcessingGeometryParameterDefinitionWidget::QgsProcessingGeometryParameterDefinitionWidget(
4211 QVBoxLayout *vlayout =
new QVBoxLayout();
4212 vlayout->setContentsMargins( 0, 0, 0, 0 );
4214 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4226 vlayout->addWidget( mGeometryWidget );
4230 setLayout( vlayout );
4236 auto param = std::make_unique<QgsProcessingParameterGeometry>( name, description, geometry.
isEmpty() ? QVariant() : geometry.
asWkt() );
4238 return param.release();
4245QWidget *QgsProcessingGeometryWidgetWrapper::createWidget()
4254 mGeometryWidget->setToolTip( parameterDefinition()->toolTip() );
4256 return mGeometryWidget;
4262void QgsProcessingGeometryWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4264 if ( mGeometryWidget )
4273 mGeometryWidget->clearGeometry();
4278QVariant QgsProcessingGeometryWidgetWrapper::widgetValue()
const
4280 if ( mGeometryWidget )
4283 return geometry.
isEmpty() ? QVariant() : geometry.asWkt();
4291QString QgsProcessingGeometryWidgetWrapper::modelerExpressionFormatString()
const
4293 return tr(
"string in the Well-Known-Text format or a geometry value" );
4296QString QgsProcessingGeometryWidgetWrapper::parameterType()
const
4303 return new QgsProcessingGeometryWidgetWrapper( parameter, type );
4310 return new QgsProcessingGeometryParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4319QgsProcessingColorParameterDefinitionWidget::QgsProcessingColorParameterDefinitionWidget(
4324 QVBoxLayout *vlayout =
new QVBoxLayout();
4325 vlayout->setContentsMargins( 0, 0, 0, 0 );
4327 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4330 mDefaultColorButton->setShowNull(
true );
4331 mAllowOpacity =
new QCheckBox( tr(
"Allow opacity control" ) );
4337 mDefaultColorButton->setToNull();
4339 mDefaultColorButton->setColor(
c );
4340 mAllowOpacity->setChecked( colorParam->opacityEnabled() );
4344 mDefaultColorButton->setToNull();
4345 mAllowOpacity->setChecked(
true );
4351 vlayout->addWidget( mDefaultColorButton );
4352 vlayout->addWidget( mAllowOpacity );
4353 setLayout( vlayout );
4358 auto param = std::make_unique<QgsProcessingParameterColor>( name, description, mDefaultColorButton->color(), mAllowOpacity->isChecked() );
4360 return param.release();
4367QWidget *QgsProcessingColorWidgetWrapper::createWidget()
4380 mColorButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
4383 mColorButton->setShowNull(
true );
4386 mColorButton->setToolTip( parameterDefinition()->toolTip() );
4387 mColorButton->setColorDialogTitle( parameterDefinition()->description() );
4395 return mColorButton;
4401void QgsProcessingColorWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4405 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) || ( value.userType() == QMetaType::Type::QColor && !value.value<QColor>().isValid() ) )
4406 mColorButton->setToNull();
4410 if ( !
c.isValid() && mColorButton->showNull() )
4411 mColorButton->setToNull();
4413 mColorButton->setColor(
c );
4418QVariant QgsProcessingColorWidgetWrapper::widgetValue()
const
4421 return mColorButton->isNull() ? QVariant() : mColorButton->color();
4426QString QgsProcessingColorWidgetWrapper::modelerExpressionFormatString()
const
4428 return tr(
"color style string, e.g. #ff0000 or 255,0,0" );
4431QString QgsProcessingColorWidgetWrapper::parameterType()
const
4438 return new QgsProcessingColorWidgetWrapper( parameter, type );
4445 return new QgsProcessingColorParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4453QgsProcessingCoordinateOperationParameterDefinitionWidget::QgsProcessingCoordinateOperationParameterDefinitionWidget(
4458 QVBoxLayout *vlayout =
new QVBoxLayout();
4459 vlayout->setContentsMargins( 0, 0, 0, 0 );
4461 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4463 mDefaultLineEdit =
new QLineEdit();
4466 vlayout->addWidget( mDefaultLineEdit );
4470 mSourceParamComboBox =
new QComboBox();
4471 mDestParamComboBox =
new QComboBox();
4472 QString initialSource;
4473 QString initialDest;
4478 initialSource = itemParam->sourceCrsParameterName();
4479 initialDest = itemParam->destinationCrsParameterName();
4484 mSourceParamComboBox->addItem( QString(), QString() );
4485 mDestParamComboBox->addItem( QString(), QString() );
4486 if (
auto *lModel = widgetContext.
model() )
4489 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4490 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4492 if ( definition && it->parameterName() == definition->
name() )
4496 mSourceParamComboBox->addItem( it->parameterName(), it->parameterName() );
4497 mDestParamComboBox->addItem( it->parameterName(), it->parameterName() );
4498 if ( !initialSource.isEmpty() && initialSource == it->parameterName() )
4500 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
4502 if ( !initialDest.isEmpty() && initialDest == it->parameterName() )
4504 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
4509 if ( mSourceParamComboBox->count() == 1 && !initialSource.isEmpty() )
4512 mSourceParamComboBox->addItem( initialSource, initialSource );
4513 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
4515 if ( mDestParamComboBox->count() == 1 && !initialDest.isEmpty() )
4518 mDestParamComboBox->addItem( initialDest, initialDest );
4519 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
4522 vlayout->addWidget(
new QLabel( tr(
"Source CRS parameter" ) ) );
4523 vlayout->addWidget( mSourceParamComboBox );
4524 vlayout->addWidget(
new QLabel( tr(
"Destination CRS parameter" ) ) );
4525 vlayout->addWidget( mDestParamComboBox );
4532 mStaticSourceWidget->setCrs( sourceCrs );
4535 mStaticDestWidget->setCrs( destCrs );
4537 vlayout->addWidget(
new QLabel( tr(
"Static source CRS" ) ) );
4538 vlayout->addWidget( mStaticSourceWidget );
4539 vlayout->addWidget(
new QLabel( tr(
"Static destination CRS" ) ) );
4540 vlayout->addWidget( mStaticDestWidget );
4545 setLayout( vlayout );
4550 auto param = std::make_unique<QgsProcessingParameterCoordinateOperation>(
4553 mDefaultLineEdit->text(),
4554 mSourceParamComboBox->currentText(),
4555 mDestParamComboBox->currentText(),
4556 mStaticSourceWidget->crs().isValid() ? QVariant::fromValue( mStaticSourceWidget->crs() ) : QVariant(),
4557 mStaticDestWidget->crs().isValid() ? QVariant::fromValue( mStaticDestWidget->crs() ) : QVariant()
4560 return param.release();
4567QWidget *QgsProcessingCoordinateOperationWidgetWrapper::createWidget()
4581 mOperationWidget->setShowMakeDefault(
false );
4582 mOperationWidget->setShowFallbackOption(
false );
4583 mOperationWidget->setToolTip( parameterDefinition()->toolTip() );
4584 mOperationWidget->setSourceCrs( mSourceCrs );
4585 mOperationWidget->setDestinationCrs( mDestCrs );
4586 mOperationWidget->setMapCanvas( mCanvas );
4591 mOperationWidget->setSelectedOperation( deets );
4596 return mOperationWidget;
4602 mLineEdit =
new QLineEdit();
4603 QHBoxLayout *layout =
new QHBoxLayout();
4604 layout->addWidget( mLineEdit, 1 );
4605 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
4607 QToolButton *button =
new QToolButton();
4608 button->setText( QString( QChar( 0x2026 ) ) );
4609 connect( button, &QToolButton::clicked,
this, [
this, button] {
4610 QgsDatumTransformDialog dlg( mSourceCrs, mDestCrs,
false,
false,
false, qMakePair( -1, -1 ), button, Qt::WindowFlags(), mLineEdit->text(), mCanvas );
4613 mLineEdit->setText( dlg.selectedDatumTransform().proj );
4614 emit widgetValueHasChanged(
this );
4617 layout->addWidget( button );
4619 QWidget *w =
new QWidget();
4620 layout->setContentsMargins( 0, 0, 0, 0 );
4621 w->setLayout( layout );
4628void QgsProcessingCoordinateOperationWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
4660 if ( mOperationWidget )
4661 mOperationWidget->setMapCanvas( context.
mapCanvas() );
4664void QgsProcessingCoordinateOperationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
4666 if ( mOperationWidget )
4668 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString ) )
4671 deets.
proj = value.toString();
4672 mOperationWidget->setSelectedOperation( deets );
4677 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString ) )
4679 mLineEdit->setText( value.toString() );
4684QVariant QgsProcessingCoordinateOperationWidgetWrapper::widgetValue()
const
4686 if ( mOperationWidget )
4687 return mOperationWidget->selectedOperation().proj;
4688 else if ( mLineEdit )
4689 return mLineEdit->text();
4694QString QgsProcessingCoordinateOperationWidgetWrapper::modelerExpressionFormatString()
const
4696 return tr(
"Proj coordinate operation string, e.g. '+proj=pipeline +step +inv...'" );
4699void QgsProcessingCoordinateOperationWidgetWrapper::setSourceCrsParameterValue(
const QVariant &value )
4702 std::unique_ptr<QgsProcessingContext> tmpContext;
4703 if ( mProcessingContextGenerator )
4704 context = mProcessingContextGenerator->processingContext();
4708 tmpContext = std::make_unique<QgsProcessingContext>();
4709 context = tmpContext.get();
4713 if ( mOperationWidget )
4715 mOperationWidget->setSourceCrs( mSourceCrs );
4716 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4720void QgsProcessingCoordinateOperationWidgetWrapper::setDestinationCrsParameterValue(
const QVariant &value )
4723 std::unique_ptr<QgsProcessingContext> tmpContext;
4724 if ( mProcessingContextGenerator )
4725 context = mProcessingContextGenerator->processingContext();
4729 tmpContext = std::make_unique<QgsProcessingContext>();
4730 context = tmpContext.get();
4734 if ( mOperationWidget )
4736 mOperationWidget->setDestinationCrs( mDestCrs );
4737 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4741QString QgsProcessingCoordinateOperationWidgetWrapper::parameterType()
const
4748 return new QgsProcessingCoordinateOperationWidgetWrapper( parameter, type );
4755 return new QgsProcessingCoordinateOperationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4767 QHBoxLayout *hl =
new QHBoxLayout();
4768 hl->setContentsMargins( 0, 0, 0, 0 );
4770 mLineEdit =
new QLineEdit();
4771 mLineEdit->setEnabled(
false );
4772 hl->addWidget( mLineEdit, 1 );
4774 mToolButton =
new QToolButton();
4775 mToolButton->setText( QString( QChar( 0x2026 ) ) );
4776 hl->addWidget( mToolButton );
4782 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4785 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingFieldPanelWidget::showDialog );
4788void QgsProcessingFieldPanelWidget::setFields(
const QgsFields &fields )
4794 QVariantList availableFields;
4795 for (
const QgsField &field : std::as_const( mFields ) )
4797 availableFields << field.name();
4799 QList<QVariant>::iterator it = std::remove_if( mValue.begin(), mValue.end(), [&availableFields](
const QVariant &value ) { return !availableFields.contains( value ); } );
4800 mValue.erase( it, mValue.end() );
4802 updateSummaryText();
4806void QgsProcessingFieldPanelWidget::setValue(
const QVariant &value )
4808 if ( value.isValid() )
4809 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
4813 updateSummaryText();
4817void QgsProcessingFieldPanelWidget::showDialog()
4819 QVariantList availableOptions;
4820 availableOptions.reserve( mFields.size() );
4821 for (
const QgsField &field : std::as_const( mFields ) )
4823 availableOptions << field.name();
4829 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
4830 widget->setPanelTitle( mParam->description() );
4832 widget->setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
4834 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
4840 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
4842 dlg.setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
4845 setValue( dlg.selectedOptions() );
4850void QgsProcessingFieldPanelWidget::updateSummaryText()
4855 if ( mValue.empty() )
4857 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4862 values.reserve( mValue.size() );
4863 for (
const QVariant &val : std::as_const( mValue ) )
4865 values << val.toString();
4868 const QString concatenated = values.join( tr(
"," ) );
4869 if ( concatenated.length() < 100 )
4870 mLineEdit->setText( concatenated );
4872 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, mValue.count() ) );
4881QgsProcessingFieldParameterDefinitionWidget::QgsProcessingFieldParameterDefinitionWidget(
4886 QVBoxLayout *vlayout =
new QVBoxLayout();
4887 vlayout->setContentsMargins( 0, 0, 0, 0 );
4889 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
4890 mParentLayerComboBox =
new QComboBox();
4892 QString initialParent;
4894 initialParent = fieldParam->parentLayerParameterName();
4896 if (
auto *lModel = widgetContext.
model() )
4899 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4900 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4904 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4905 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4907 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4912 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4913 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4915 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4922 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4923 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4925 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4932 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
4935 mParentLayerComboBox->addItem( initialParent, initialParent );
4936 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4939 vlayout->addWidget( mParentLayerComboBox );
4942 vlayout->addWidget(
new QLabel( tr(
"Allowed data type" ) ) );
4943 mDataTypeComboBox =
new QComboBox();
4951 mDataTypeComboBox->setCurrentIndex( mDataTypeComboBox->findData(
static_cast<int>( fieldParam->dataType() ) ) );
4953 vlayout->addWidget( mDataTypeComboBox );
4956 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple fields" ) );
4958 mAllowMultipleCheckBox->setChecked( fieldParam->allowMultiple() );
4960 vlayout->addWidget( mAllowMultipleCheckBox );
4965 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all fields by default" ) );
4966 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
4968 mDefaultToAllCheckBox->setChecked( fieldParam->defaultToAllFields() );
4970 vlayout->addWidget( mDefaultToAllCheckBox );
4973 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [
this] { mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() ); } );
4975 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4977 mDefaultLineEdit =
new QLineEdit();
4978 mDefaultLineEdit->setToolTip( tr(
"Default field name, or ; separated list of field names for multiple field parameters" ) );
4982 mDefaultLineEdit->setText( fields.join(
';' ) );
4984 vlayout->addWidget( mDefaultLineEdit );
4988 setLayout( vlayout );
4995 QVariant defaultValue;
4996 if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
4998 defaultValue = mDefaultLineEdit->text();
5000 auto param = std::make_unique<
5001 QgsProcessingParameterField>( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), dataType, mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
5003 return param.release();
5010QWidget *QgsProcessingFieldWidgetWrapper::createWidget()
5023 mPanel =
new QgsProcessingFieldPanelWidget(
nullptr, fieldParam );
5024 mPanel->setToolTip( parameterDefinition()->toolTip() );
5025 connect( mPanel, &QgsProcessingFieldPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
5044 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5052 mLineEdit =
new QLineEdit();
5053 mLineEdit->setToolTip( QObject::tr(
"Name of field (separate field names with ; for multiple field parameters)" ) );
5054 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
5061void QgsProcessingFieldWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5073 setParentLayerWrapperValue( wrapper );
5090 std::unique_ptr<QgsProcessingContext> tmpContext;
5091 if ( mProcessingContextGenerator )
5092 context = mProcessingContextGenerator->processingContext();
5096 tmpContext = std::make_unique<QgsProcessingContext>();
5097 context = tmpContext.get();
5102 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
5112 bool valueSet =
false;
5116 if ( layers.count() > 1 )
5118 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layers.at( 0 ) );
5120 const QList<QgsMapLayer *> remainingLayers = layers.mid( 1 );
5126 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
5127 if ( !vlayer || !vlayer->
isValid() )
5133 for (
int fieldIdx = fields.
count() - 1; fieldIdx >= 0; fieldIdx-- )
5136 fields.
remove( fieldIdx );
5141 mComboBox->setFields( fields );
5143 mPanel->setFields( filterFields( fields ) );
5149 if ( !valueSet && !layers.isEmpty() && layers.at( 0 )->isValid() )
5151 QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( layers.at( 0 ) );
5155 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
5158 mParentLayer.reset( qobject_cast<QgsVectorLayer *>( ownedLayer.release() ) );
5159 layer = mParentLayer.get();
5167 mComboBox->setLayer( layer );
5169 mPanel->setFields( filterFields( layer->
fields() ) );
5179 const QgsFields fields = source->fields();
5181 mComboBox->setFields( fields );
5183 mPanel->setFields( filterFields( fields ) );
5192 mComboBox->setLayer(
nullptr );
5196 if ( value.isValid() && widgetContext().messageBar() )
5208 val.reserve( mPanel->fields().size() );
5209 for (
const QgsField &field : mPanel->fields() )
5210 val << field.name();
5211 setWidgetValue( val, *context );
5214 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5217void QgsProcessingFieldWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5221 if ( !value.isValid() )
5222 mComboBox->setField( QString() );
5226 mComboBox->setField( v );
5232 if ( value.isValid() )
5235 opts.reserve( v.size() );
5236 for (
const QString &i : v )
5240 mPanel->setValue( opts );
5242 else if ( mLineEdit )
5248 mLineEdit->setText( v.join(
';' ) );
5257QVariant QgsProcessingFieldWidgetWrapper::widgetValue()
const
5260 return mComboBox->currentField();
5262 return mPanel->value();
5263 else if ( mLineEdit )
5268 return mLineEdit->text().split(
';' );
5271 return mLineEdit->text();
5277QString QgsProcessingFieldWidgetWrapper::modelerExpressionFormatString()
const
5279 return tr(
"selected field names as an array of names, or semicolon separated string of options (e.g. 'fid;place_name')" );
5282const QgsVectorLayer *QgsProcessingFieldWidgetWrapper::linkedVectorLayer()
const
5284 if ( mComboBox && mComboBox->layer() )
5285 return mComboBox->layer();
5290QgsFields QgsProcessingFieldWidgetWrapper::filterFields(
const QgsFields &fields )
const
5303 if ( f.isNumeric() )
5308 if ( f.type() == QMetaType::Type::QString )
5313 if ( f.type() == QMetaType::Type::QDate || f.type() == QMetaType::Type::QTime || f.type() == QMetaType::Type::QDateTime )
5318 if ( f.type() == QMetaType::Type::QByteArray )
5323 if ( f.type() == QMetaType::Type::Bool )
5332QString QgsProcessingFieldWidgetWrapper::parameterType()
const
5339 return new QgsProcessingFieldWidgetWrapper( parameter, type );
5346 return new QgsProcessingFieldParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5354QgsProcessingMapThemeParameterDefinitionWidget::QgsProcessingMapThemeParameterDefinitionWidget(
5359 QVBoxLayout *vlayout =
new QVBoxLayout();
5360 vlayout->setContentsMargins( 0, 0, 0, 0 );
5362 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5364 mDefaultComboBox =
new QComboBox();
5365 mDefaultComboBox->addItem( QString(), QVariant( -1 ) );
5368 for (
const QString &theme : mapThemes )
5372 mDefaultComboBox->setEditable(
true );
5376 if ( themeParam->defaultValueForGui().isValid() )
5379 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
5382 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
5384 vlayout->addWidget( mDefaultComboBox );
5388 setLayout( vlayout );
5393 QVariant defaultVal;
5394 if ( mDefaultComboBox->currentText().isEmpty() )
5395 defaultVal = QVariant();
5397 defaultVal = mDefaultComboBox->currentText();
5398 auto param = std::make_unique<QgsProcessingParameterMapTheme>( name, description, defaultVal );
5400 return param.release();
5408QWidget *QgsProcessingMapThemeWidgetWrapper::createWidget()
5414 mComboBox =
new QComboBox();
5417 mComboBox->addItem( tr(
"[Not selected]" ), QVariant( -1 ) );
5420 for (
const QString &theme : mapThemes )
5432 mComboBox->setEditable(
true );
5436 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5437 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
5442void QgsProcessingMapThemeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5446 if ( !value.isValid() )
5447 mComboBox->setCurrentIndex( mComboBox->findData( QVariant( -1 ) ) );
5450 if ( mComboBox->isEditable() && mComboBox->findData( v ) == -1 )
5452 const QString prev = mComboBox->currentText();
5453 mComboBox->setCurrentText( v );
5455 emit widgetValueHasChanged(
this );
5458 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
5462QVariant QgsProcessingMapThemeWidgetWrapper::widgetValue()
const
5465 return mComboBox->currentData().toInt() == -1 ? QVariant()
5466 : !mComboBox->currentData().isValid() && mComboBox->isEditable() ? mComboBox->currentText().isEmpty() ? QVariant() : QVariant( mComboBox->currentText() )
5467 : mComboBox->currentData();
5472QString QgsProcessingMapThemeWidgetWrapper::modelerExpressionFormatString()
const
5474 return tr(
"map theme as a string value (e.g. 'base maps')" );
5477QString QgsProcessingMapThemeWidgetWrapper::parameterType()
const
5484 return new QgsProcessingMapThemeWidgetWrapper( parameter, type );
5491 return new QgsProcessingMapThemeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5500QgsProcessingDateTimeParameterDefinitionWidget::QgsProcessingDateTimeParameterDefinitionWidget(
5505 QVBoxLayout *vlayout =
new QVBoxLayout();
5506 vlayout->setContentsMargins( 0, 0, 0, 0 );
5508 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
5510 mTypeComboBox =
new QComboBox();
5515 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( datetimeParam->dataType() ) ) );
5517 mTypeComboBox->setCurrentIndex( 0 );
5518 vlayout->addWidget( mTypeComboBox );
5522 setLayout( vlayout );
5527 auto param = std::make_unique<QgsProcessingParameterDateTime>( name, description );
5530 return param.release();
5538QWidget *QgsProcessingDateTimeWidgetWrapper::createWidget()
5541 if ( !dateTimeParam )
5545 switch ( dateTimeParam->
dataType() )
5549 widget = mDateTimeEdit;
5574 widget->setToolTip( parameterDefinition()->toolTip() );
5576 if ( mDateTimeEdit )
5580 else if ( mDateEdit )
5584 else if ( mTimeEdit )
5596 return new QgsProcessingDateTimeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5599void QgsProcessingDateTimeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5601 if ( mDateTimeEdit )
5605 else if ( mDateEdit )
5609 else if ( mTimeEdit )
5615QVariant QgsProcessingDateTimeWidgetWrapper::widgetValue()
const
5617 if ( mDateTimeEdit )
5618 return !mDateTimeEdit->dateTime().isNull() && mDateTimeEdit->dateTime().isValid() ? QVariant( mDateTimeEdit->dateTime() ) : QVariant();
5619 else if ( mDateEdit )
5620 return !mDateEdit->date().isNull() && mDateEdit->date().isValid() ? QVariant( mDateEdit->date() ) : QVariant();
5621 else if ( mTimeEdit )
5622 return !mTimeEdit->time().isNull() && mTimeEdit->time().isValid() ? QVariant( mTimeEdit->time() ) : QVariant();
5627QString QgsProcessingDateTimeWidgetWrapper::modelerExpressionFormatString()
const
5630 if ( dateTimeParam )
5632 switch ( dateTimeParam->
dataType() )
5635 return tr(
"datetime value, or a ISO string representation of a datetime" );
5638 return tr(
"date value, or a ISO string representation of a date" );
5641 return tr(
"time value, or a ISO string representation of a time" );
5647QString QgsProcessingDateTimeWidgetWrapper::parameterType()
const
5654 return new QgsProcessingDateTimeWidgetWrapper( parameter, type );
5662QgsProcessingProviderConnectionParameterDefinitionWidget::QgsProcessingProviderConnectionParameterDefinitionWidget(
5669 QVBoxLayout *vlayout =
new QVBoxLayout();
5670 vlayout->setContentsMargins( 0, 0, 0, 0 );
5672 vlayout->addWidget(
new QLabel( tr(
"Provider" ) ) );
5673 mProviderComboBox =
new QComboBox();
5674 mProviderComboBox->addItem( QObject::tr(
"Postgres" ), u
"postgres"_s );
5675 mProviderComboBox->addItem( QObject::tr(
"GeoPackage" ), u
"ogr"_s );
5676 mProviderComboBox->addItem( QObject::tr(
"Spatialite" ), u
"spatialite"_s );
5678 vlayout->addWidget( mProviderComboBox );
5680 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5682 mDefaultEdit =
new QLineEdit();
5683 vlayout->addWidget( mDefaultEdit );
5684 setLayout( vlayout );
5686 if ( connectionParam )
5688 mProviderComboBox->setCurrentIndex( mProviderComboBox->findData( connectionParam->
providerId() ) );
5698 QVariant defaultVal;
5699 if ( mDefaultEdit->text().isEmpty() )
5700 defaultVal = QVariant();
5702 defaultVal = mDefaultEdit->text();
5703 auto param = std::make_unique<QgsProcessingParameterProviderConnection>( name, description, mProviderComboBox->currentData().toString(), defaultVal );
5705 return param.release();
5713QWidget *QgsProcessingProviderConnectionWidgetWrapper::createWidget()
5716 if ( !connectionParam )
5721 mProviderComboBox->setAllowEmptyConnection(
true );
5729 mProviderComboBox->setEditable(
true );
5733 mProviderComboBox->setToolTip( parameterDefinition()->toolTip() );
5734 connect( mProviderComboBox, &QgsProviderConnectionComboBox::currentTextChanged,
this, [
this](
const QString & ) {
5735 if ( mBlockSignals )
5738 emit widgetValueHasChanged(
this );
5741 return mProviderComboBox;
5748 return new QgsProcessingProviderConnectionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5751void QgsProcessingProviderConnectionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5755 if ( !value.isValid() )
5756 mProviderComboBox->setCurrentIndex( -1 );
5759 if ( mProviderComboBox->isEditable() )
5761 const QString prev = mProviderComboBox->currentText();
5763 mProviderComboBox->setConnection( v );
5764 mProviderComboBox->setCurrentText( v );
5768 emit widgetValueHasChanged(
this );
5771 mProviderComboBox->setConnection( v );
5775QVariant QgsProcessingProviderConnectionWidgetWrapper::widgetValue()
const
5777 if ( mProviderComboBox )
5778 if ( mProviderComboBox->isEditable() )
5779 return mProviderComboBox->currentText().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentText() );
5781 return mProviderComboBox->currentConnection().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentConnection() );
5786QString QgsProcessingProviderConnectionWidgetWrapper::modelerExpressionFormatString()
const
5788 return tr(
"connection name as a string value" );
5791QString QgsProcessingProviderConnectionWidgetWrapper::parameterType()
const
5798 return new QgsProcessingProviderConnectionWidgetWrapper( parameter, type );
5806QgsProcessingDatabaseSchemaParameterDefinitionWidget::QgsProcessingDatabaseSchemaParameterDefinitionWidget(
5813 QVBoxLayout *vlayout =
new QVBoxLayout();
5814 vlayout->setContentsMargins( 0, 0, 0, 0 );
5816 mConnectionParamComboBox =
new QComboBox();
5817 QString initialConnection;
5823 if (
auto *lModel = widgetContext.
model() )
5826 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
5827 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
5829 if ( definition && it->parameterName() == definition->
name() )
5835 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
5836 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5838 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5843 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
5846 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
5847 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5850 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
5851 vlayout->addWidget( mConnectionParamComboBox );
5855 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5857 mDefaultEdit =
new QLineEdit();
5858 vlayout->addWidget( mDefaultEdit );
5859 setLayout( vlayout );
5870 QVariant defaultVal;
5871 if ( mDefaultEdit->text().isEmpty() )
5872 defaultVal = QVariant();
5874 defaultVal = mDefaultEdit->text();
5875 auto param = std::make_unique<QgsProcessingParameterDatabaseSchema>( name, description, mConnectionParamComboBox->currentData().toString(), defaultVal );
5877 return param.release();
5885QWidget *QgsProcessingDatabaseSchemaWidgetWrapper::createWidget()
5893 mSchemaComboBox->setAllowEmptySchema(
true );
5901 mSchemaComboBox->comboBox()->setEditable(
true );
5905 mSchemaComboBox->setToolTip( parameterDefinition()->toolTip() );
5906 connect( mSchemaComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [
this](
const QString & ) {
5907 if ( mBlockSignals )
5910 emit widgetValueHasChanged( this );
5913 return mSchemaComboBox;
5920 return new QgsProcessingDatabaseSchemaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5927 std::unique_ptr<QgsProcessingContext> tmpContext;
5928 if ( mProcessingContextGenerator )
5929 context = mProcessingContextGenerator->processingContext();
5933 tmpContext = std::make_unique<QgsProcessingContext>();
5934 context = tmpContext.get();
5940 if ( mSchemaComboBox )
5941 mSchemaComboBox->setConnectionName( connection, qgis::down_cast<const QgsProcessingParameterProviderConnection *>( parentWrapper->
parameterDefinition() )->providerId() );
5945 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5948void QgsProcessingDatabaseSchemaWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5952 if ( !value.isValid() )
5953 mSchemaComboBox->comboBox()->setCurrentIndex( -1 );
5956 if ( mSchemaComboBox->comboBox()->isEditable() )
5958 const QString prev = mSchemaComboBox->comboBox()->currentText();
5960 mSchemaComboBox->setSchema( v );
5961 mSchemaComboBox->comboBox()->setCurrentText( v );
5965 emit widgetValueHasChanged(
this );
5968 mSchemaComboBox->setSchema( v );
5972QVariant QgsProcessingDatabaseSchemaWidgetWrapper::widgetValue()
const
5974 if ( mSchemaComboBox )
5975 if ( mSchemaComboBox->comboBox()->isEditable() )
5976 return mSchemaComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->comboBox()->currentText() );
5978 return mSchemaComboBox->currentSchema().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->currentSchema() );
5983QString QgsProcessingDatabaseSchemaWidgetWrapper::modelerExpressionFormatString()
const
5985 return tr(
"database schema name as a string value" );
5988QString QgsProcessingDatabaseSchemaWidgetWrapper::parameterType()
const
5995 return new QgsProcessingDatabaseSchemaWidgetWrapper( parameter, type );
5998void QgsProcessingDatabaseSchemaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6010 setParentConnectionWrapperValue( wrapper );
6028QgsProcessingDatabaseTableParameterDefinitionWidget::QgsProcessingDatabaseTableParameterDefinitionWidget(
6035 QVBoxLayout *vlayout =
new QVBoxLayout();
6036 vlayout->setContentsMargins( 0, 0, 0, 0 );
6038 mConnectionParamComboBox =
new QComboBox();
6039 mSchemaParamComboBox =
new QComboBox();
6040 QString initialConnection;
6041 QString initialSchema;
6048 if (
auto *lModel = widgetContext.
model() )
6051 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6052 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6054 if ( definition && it->parameterName() == definition->
name() )
6059 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
6060 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
6062 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
6067 mSchemaParamComboBox->addItem( it->parameterName(), it->parameterName() );
6068 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
6070 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
6076 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
6079 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
6080 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
6083 if ( mSchemaParamComboBox->count() == 0 && !initialSchema.isEmpty() )
6086 mSchemaParamComboBox->addItem( initialSchema, initialSchema );
6087 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
6090 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
6091 vlayout->addWidget( mConnectionParamComboBox );
6093 vlayout->addWidget(
new QLabel( tr(
"Database schema parameter" ) ) );
6094 vlayout->addWidget( mSchemaParamComboBox );
6099 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6101 mDefaultEdit =
new QLineEdit();
6102 vlayout->addWidget( mDefaultEdit );
6103 setLayout( vlayout );
6114 QVariant defaultVal;
6115 if ( mDefaultEdit->text().isEmpty() )
6116 defaultVal = QVariant();
6118 defaultVal = mDefaultEdit->text();
6119 auto param = std::make_unique<QgsProcessingParameterDatabaseTable>( name, description, mConnectionParamComboBox->currentData().toString(), mSchemaParamComboBox->currentData().toString(), defaultVal );
6121 return param.release();
6129QWidget *QgsProcessingDatabaseTableWidgetWrapper::createWidget()
6137 mTableComboBox->setAllowEmptyTable(
true );
6140 mTableComboBox->comboBox()->setEditable(
true );
6142 mTableComboBox->setToolTip( parameterDefinition()->toolTip() );
6143 connect( mTableComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [
this](
const QString & ) {
6144 if ( mBlockSignals )
6147 emit widgetValueHasChanged( this );
6150 return mTableComboBox;
6157 return new QgsProcessingDatabaseTableParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6164 std::unique_ptr<QgsProcessingContext> tmpContext;
6165 if ( mProcessingContextGenerator )
6166 context = mProcessingContextGenerator->processingContext();
6170 tmpContext = std::make_unique<QgsProcessingContext>();
6171 context = tmpContext.get();
6176 mProvider = qgis::down_cast<const QgsProcessingParameterProviderConnection *>( parentWrapper->
parameterDefinition() )->providerId();
6177 if ( mTableComboBox && !mSchema.isEmpty() )
6179 mTableComboBox->setSchema( mSchema );
6180 mTableComboBox->setConnectionName( mConnection, mProvider );
6184 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6192 std::unique_ptr<QgsProcessingContext> tmpContext;
6193 if ( mProcessingContextGenerator )
6194 context = mProcessingContextGenerator->processingContext();
6198 tmpContext = std::make_unique<QgsProcessingContext>();
6199 context = tmpContext.get();
6205 if ( mTableComboBox && !mSchema.isEmpty() && !mConnection.isEmpty() )
6207 mTableComboBox->setSchema( mSchema );
6208 mTableComboBox->setConnectionName( mConnection, mProvider );
6210 const QgsProcessingParameterDatabaseTable *tableParam = static_cast<const QgsProcessingParameterDatabaseTable *>( parameterDefinition() );
6211 if ( tableParam->defaultValueForGui().isValid() )
6212 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6216void QgsProcessingDatabaseTableWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6220 if ( !value.isValid() )
6221 mTableComboBox->comboBox()->setCurrentIndex( -1 );
6224 if ( mTableComboBox->comboBox()->isEditable() )
6226 const QString prev = mTableComboBox->comboBox()->currentText();
6228 mTableComboBox->setTable( v );
6229 mTableComboBox->comboBox()->setCurrentText( v );
6233 emit widgetValueHasChanged(
this );
6236 mTableComboBox->setTable( v );
6240QVariant QgsProcessingDatabaseTableWidgetWrapper::widgetValue()
const
6242 if ( mTableComboBox )
6243 if ( mTableComboBox->comboBox()->isEditable() )
6244 return mTableComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mTableComboBox->comboBox()->currentText() );
6246 return mTableComboBox->currentTable().isEmpty() ? QVariant() : QVariant( mTableComboBox->currentTable() );
6251QString QgsProcessingDatabaseTableWidgetWrapper::modelerExpressionFormatString()
const
6253 return tr(
"database table name as a string value" );
6256QString QgsProcessingDatabaseTableWidgetWrapper::parameterType()
const
6263 return new QgsProcessingDatabaseTableWidgetWrapper( parameter, type );
6266void QgsProcessingDatabaseTableWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6278 setParentConnectionWrapperValue( wrapper );
6283 setParentSchemaWrapperValue( wrapper );
6300QgsProcessingExtentParameterDefinitionWidget::QgsProcessingExtentParameterDefinitionWidget(
6305 QVBoxLayout *vlayout =
new QVBoxLayout();
6306 vlayout->setContentsMargins( 0, 0, 0, 0 );
6308 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6311 mDefaultWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
6314 if ( extentParam->defaultValueForGui().isValid() )
6318 mDefaultWidget->setCurrentExtent( rect, crs );
6319 mDefaultWidget->setOutputExtentFromCurrent();
6323 mDefaultWidget->clear();
6329 vlayout->addWidget( mDefaultWidget );
6330 setLayout( vlayout );
6335 const QString defaultVal = mDefaultWidget->isValid() ? u
"%1,%2,%3,%4%5"_s.arg(
6336 QString::number( mDefaultWidget->outputExtent().xMinimum(),
'f', 9 ),
6337 QString::number( mDefaultWidget->outputExtent().xMaximum(),
'f', 9 ),
6338 QString::number( mDefaultWidget->outputExtent().yMinimum(),
'f', 9 ),
6339 QString::number( mDefaultWidget->outputExtent().yMaximum(),
'f', 9 ),
6340 mDefaultWidget->outputCrs().isValid() ? u
" [%1]"_s.arg( mDefaultWidget->outputCrs().authid() ) : QString()
6343 auto param = std::make_unique<QgsProcessingParameterExtent>( name, description, !defaultVal.isEmpty() ? QVariant( defaultVal ) : QVariant() );
6345 return param.release();
6353QWidget *QgsProcessingExtentWidgetWrapper::createWidget()
6366 if ( widgetContext().mapCanvas() )
6367 mExtentWidget->setMapCanvas( widgetContext().mapCanvas() );
6370 mExtentWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
6372 mExtentWidget->setToolTip( parameterDefinition()->toolTip() );
6377 setDialog( mDialog );
6379 return mExtentWidget;
6389 mExtentWidget->setMapCanvas( context.
mapCanvas() );
6392void QgsProcessingExtentWidgetWrapper::setDialog( QWidget *dialog )
6399 mDialog->showMinimized();
6402 mDialog->showNormal();
6404 mDialog->activateWindow();
6411void QgsProcessingExtentWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6413 if ( mExtentWidget )
6415 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) )
6416 mExtentWidget->clear();
6421 mExtentWidget->setCurrentExtent( r, crs );
6422 mExtentWidget->setOutputExtentFromUser( r, crs );
6427QVariant QgsProcessingExtentWidgetWrapper::widgetValue()
const
6429 if ( mExtentWidget )
6431 const QString val = mExtentWidget->isValid() ? u
"%1,%2,%3,%4%5"_s.arg(
6432 QString::number( mExtentWidget->outputExtent().xMinimum(),
'f', 9 ),
6433 QString::number( mExtentWidget->outputExtent().xMaximum(),
'f', 9 ),
6434 QString::number( mExtentWidget->outputExtent().yMinimum(),
'f', 9 ),
6435 QString::number( mExtentWidget->outputExtent().yMaximum(),
'f', 9 ),
6436 mExtentWidget->outputCrs().isValid() ? u
" [%1]"_s.arg( mExtentWidget->outputCrs().authid() ) : QString()
6440 return val.isEmpty() ? QVariant() : QVariant( val );
6446QString QgsProcessingExtentWidgetWrapper::modelerExpressionFormatString()
const
6448 return tr(
"string of the format 'x min,x max,y min,y max' or a geometry value (bounding box is used)" );
6451QString QgsProcessingExtentWidgetWrapper::parameterType()
const
6458 return new QgsProcessingExtentWidgetWrapper( parameter, type );
6465 return new QgsProcessingExtentParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6473QgsProcessingMapLayerParameterDefinitionWidget::QgsProcessingMapLayerParameterDefinitionWidget(
6478 QVBoxLayout *vlayout =
new QVBoxLayout();
6479 vlayout->setContentsMargins( 0, 0, 0, 0 );
6481 vlayout->addWidget(
new QLabel( tr(
"Layer type" ) ) );
6497 for (
int i : layerParam->dataTypes() )
6499 mLayerTypeComboBox->setItemCheckState( mLayerTypeComboBox->findData( i ), Qt::Checked );
6503 vlayout->addWidget( mLayerTypeComboBox );
6507 setLayout( vlayout );
6512 QList<int> dataTypes;
6513 for (
const QVariant &v : mLayerTypeComboBox->checkedItemsData() )
6514 dataTypes << v.toInt();
6516 auto param = std::make_unique<QgsProcessingParameterMapLayer>( name, description );
6517 param->setDataTypes( dataTypes );
6519 return param.release();
6526QWidget *QgsProcessingMapLayerWidgetWrapper::createWidget()
6528 mComboBox =
new QgsProcessingMapLayerComboBox( parameterDefinition(), type() );
6536 mComboBox->setEditable(
true );
6540 mComboBox->setToolTip( parameterDefinition()->toolTip() );
6542 connect( mComboBox, &QgsProcessingMapLayerComboBox::valueChanged,
this, [
this]() {
6543 if ( mBlockSignals )
6546 emit widgetValueHasChanged(
this );
6549 setWidgetContext( widgetContext() );
6558 mComboBox->setWidgetContext( context );
6563 if ( !parameterDefinition()->defaultValueForGui().isValid() )
6569void QgsProcessingMapLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6572 mComboBox->setValue( value, context );
6575QVariant QgsProcessingMapLayerWidgetWrapper::widgetValue()
const
6577 return mComboBox ? mComboBox->value() : QVariant();
6580QString QgsProcessingMapLayerWidgetWrapper::modelerExpressionFormatString()
const
6582 return tr(
"path to a map layer" );
6599QString QgsProcessingMapLayerWidgetWrapper::parameterType()
const
6606 return new QgsProcessingMapLayerWidgetWrapper( parameter, type );
6613 return new QgsProcessingMapLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6622 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6625QString QgsProcessingRasterLayerWidgetWrapper::modelerExpressionFormatString()
const
6627 return tr(
"path to a raster layer" );
6630QString QgsProcessingRasterLayerWidgetWrapper::parameterType()
const
6637 return new QgsProcessingRasterLayerWidgetWrapper( parameter, type );
6644 Q_UNUSED( context );
6645 Q_UNUSED( widgetContext );
6646 Q_UNUSED( definition );
6657QgsProcessingVectorLayerParameterDefinitionWidget::QgsProcessingVectorLayerParameterDefinitionWidget(
6662 QVBoxLayout *vlayout =
new QVBoxLayout();
6663 vlayout->setContentsMargins( 0, 0, 0, 0 );
6665 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6675 for (
int i : vectorParam->dataTypes() )
6677 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6681 vlayout->addWidget( mGeometryTypeComboBox );
6685 setLayout( vlayout );
6690 QList<int> dataTypes;
6691 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6692 dataTypes << v.toInt();
6694 auto param = std::make_unique<QgsProcessingParameterVectorLayer>( name, description, dataTypes );
6696 return param.release();
6701 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6704QString QgsProcessingVectorLayerWidgetWrapper::modelerExpressionFormatString()
const
6706 return tr(
"path to a vector layer" );
6709QString QgsProcessingVectorLayerWidgetWrapper::parameterType()
const
6716 return new QgsProcessingVectorLayerWidgetWrapper( parameter, type );
6723 return new QgsProcessingVectorLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6731QgsProcessingFeatureSourceParameterDefinitionWidget::QgsProcessingFeatureSourceParameterDefinitionWidget(
6736 QVBoxLayout *vlayout =
new QVBoxLayout();
6737 vlayout->setContentsMargins( 0, 0, 0, 0 );
6739 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6749 for (
int i : sourceParam->dataTypes() )
6751 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6759 vlayout->addWidget( mGeometryTypeComboBox );
6762 setLayout( vlayout );
6767 QList<int> dataTypes;
6768 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6769 dataTypes << v.toInt();
6771 auto param = std::make_unique<QgsProcessingParameterFeatureSource>( name, description, dataTypes );
6773 return param.release();
6777 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6780QString QgsProcessingFeatureSourceWidgetWrapper::modelerExpressionFormatString()
const
6782 return tr(
"path to a vector layer" );
6785QString QgsProcessingFeatureSourceWidgetWrapper::parameterType()
const
6792 return new QgsProcessingFeatureSourceWidgetWrapper( parameter, type );
6799 return new QgsProcessingFeatureSourceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6807 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6810QString QgsProcessingMeshLayerWidgetWrapper::modelerExpressionFormatString()
const
6812 return tr(
"path to a mesh layer" );
6815QString QgsProcessingMeshLayerWidgetWrapper::parameterType()
const
6822 return new QgsProcessingMeshLayerWidgetWrapper( parameter, type );
6829 Q_UNUSED( context );
6830 Q_UNUSED( widgetContext );
6831 Q_UNUSED( definition );
6842QgsProcessingRasterBandPanelWidget::QgsProcessingRasterBandPanelWidget( QWidget *parent,
const QgsProcessingParameterBand *param )
6846 QHBoxLayout *hl =
new QHBoxLayout();
6847 hl->setContentsMargins( 0, 0, 0, 0 );
6849 mLineEdit =
new QLineEdit();
6850 mLineEdit->setEnabled(
false );
6851 hl->addWidget( mLineEdit, 1 );
6853 mToolButton =
new QToolButton();
6854 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6855 hl->addWidget( mToolButton );
6861 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, 0 ) );
6864 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingRasterBandPanelWidget::showDialog );
6867void QgsProcessingRasterBandPanelWidget::setBands(
const QList<int> &bands )
6872void QgsProcessingRasterBandPanelWidget::setBandNames(
const QHash<int, QString> &names )
6877void QgsProcessingRasterBandPanelWidget::setValue(
const QVariant &value )
6879 if ( value.isValid() )
6880 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
6884 updateSummaryText();
6888void QgsProcessingRasterBandPanelWidget::showDialog()
6890 QVariantList availableOptions;
6891 availableOptions.reserve( mBands.size() );
6892 for (
int band : std::as_const( mBands ) )
6894 availableOptions << band;
6900 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
6901 widget->setPanelTitle( mParam->description() );
6903 widget->setValueFormatter( [
this](
const QVariant &v ) -> QString {
6904 int band = v.toInt();
6905 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6908 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
6914 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
6916 dlg.setValueFormatter( [
this](
const QVariant &v ) -> QString {
6917 int band = v.toInt();
6918 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6922 setValue( dlg.selectedOptions() );
6927void QgsProcessingRasterBandPanelWidget::updateSummaryText()
6930 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, mValue.count() ) );
6938QgsProcessingBandParameterDefinitionWidget::QgsProcessingBandParameterDefinitionWidget(
6943 QVBoxLayout *vlayout =
new QVBoxLayout();
6944 vlayout->setContentsMargins( 0, 0, 0, 0 );
6946 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6948 mDefaultLineEdit =
new QLineEdit();
6949 mDefaultLineEdit->setToolTip( tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6954 for (
int b : bands )
6956 defVal << QString::number( b );
6959 mDefaultLineEdit->setText( defVal.join(
';' ) );
6961 vlayout->addWidget( mDefaultLineEdit );
6964 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
6965 mParentLayerComboBox =
new QComboBox();
6967 QString initialParent;
6969 initialParent = bandParam->parentLayerParameterName();
6971 if (
auto *lModel = widgetContext.
model() )
6974 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6975 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6979 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
6980 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
6982 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6988 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
6991 mParentLayerComboBox->addItem( initialParent, initialParent );
6992 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6996 vlayout->addWidget( mParentLayerComboBox );
6998 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Allow multiple" ) );
7000 mAllowMultipleCheckBox->setChecked( bandParam->allowMultiple() );
7003 vlayout->addWidget( mAllowMultipleCheckBox );
7004 setLayout( vlayout );
7010 = std::make_unique<QgsProcessingParameterBand>( name, description, mDefaultLineEdit->text().split(
';' ), mParentLayerComboBox->currentData().toString(),
false, mAllowMultipleCheckBox->isChecked() );
7012 return param.release();
7019QWidget *QgsProcessingBandWidgetWrapper::createWidget()
7032 mPanel =
new QgsProcessingRasterBandPanelWidget(
nullptr, bandParam );
7033 mPanel->setToolTip( parameterDefinition()->toolTip() );
7034 connect( mPanel, &QgsProcessingRasterBandPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7042 mComboBox->setToolTip( parameterDefinition()->toolTip() );
7050 mLineEdit =
new QLineEdit();
7051 mLineEdit->setToolTip( QObject::tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
7052 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7059void QgsProcessingBandWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
7071 setParentLayerWrapperValue( wrapper );
7088 std::unique_ptr<QgsProcessingContext> tmpContext;
7089 if ( mProcessingContextGenerator )
7090 context = mProcessingContextGenerator->processingContext();
7094 tmpContext = std::make_unique<QgsProcessingContext>();
7095 context = tmpContext.get();
7101 if ( layer && layer->
isValid() )
7105 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
7108 mParentLayer.reset( qobject_cast<QgsRasterLayer *>( ownedLayer.release() ) );
7109 layer = mParentLayer.get();
7117 mComboBox->setLayer( layer );
7121 if ( provider && layer->
isValid() )
7126 QHash<int, QString> bandNames;
7127 for (
int i = 1; i <= nBands; ++i )
7132 mPanel->setBands( bands );
7133 mPanel->setBandNames( bandNames );
7140 mComboBox->setLayer(
nullptr );
7142 mPanel->setBands( QList<int>() );
7144 if ( value.isValid() && widgetContext().messageBar() )
7151 if ( parameterDefinition()->defaultValueForGui().isValid() )
7152 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
7155void QgsProcessingBandWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7159 if ( !value.isValid() )
7160 mComboBox->setBand( -1 );
7164 mComboBox->setBand( v );
7170 if ( value.isValid() )
7173 opts.reserve( v.size() );
7178 mPanel->setValue( value.isValid() ? opts : QVariant() );
7180 else if ( mLineEdit )
7187 opts.reserve( v.size() );
7189 opts << QString::number( i );
7190 mLineEdit->setText( value.isValid() && !opts.empty() ? opts.join(
';' ) : QString() );
7194 if ( value.isValid() )
7202QVariant QgsProcessingBandWidgetWrapper::widgetValue()
const
7205 return mComboBox->currentBand() == -1 ? QVariant() : mComboBox->currentBand();
7207 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
7208 else if ( mLineEdit )
7213 const QStringList parts = mLineEdit->text().split(
';', Qt::SkipEmptyParts );
7215 res.reserve( parts.count() );
7216 for (
const QString &s : parts )
7219 int band = s.toInt( &ok );
7223 return res.
isEmpty() ? QVariant() : res;
7227 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
7234QString QgsProcessingBandWidgetWrapper::modelerExpressionFormatString()
const
7236 return tr(
"selected band numbers as an array of numbers, or semicolon separated string of options (e.g. '1;3')" );
7239QString QgsProcessingBandWidgetWrapper::parameterType()
const
7246 return new QgsProcessingBandWidgetWrapper( parameter, type );
7253 return new QgsProcessingBandParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
7264 setAcceptDrops(
true );
7267void QgsProcessingMultipleLayerLineEdit::dragEnterEvent( QDragEnterEvent *event )
7269 const QStringList uris = QgsProcessingMultipleInputPanelWidget::compatibleUrisFromMimeData( mParam, event->mimeData(), {} );
7270 if ( !uris.isEmpty() )
7272 event->setDropAction( Qt::CopyAction );
7274 setHighlighted(
true );
7282void QgsProcessingMultipleLayerLineEdit::dragLeaveEvent( QDragLeaveEvent *event )
7284 QgsHighlightableLineEdit::dragLeaveEvent( event );
7286 setHighlighted(
false );
7289void QgsProcessingMultipleLayerLineEdit::dropEvent( QDropEvent *event )
7291 const QStringList uris = QgsProcessingMultipleInputPanelWidget::compatibleUrisFromMimeData( mParam, event->mimeData(), {} );
7292 if ( !uris.isEmpty() )
7294 event->setDropAction( Qt::CopyAction );
7296 QVariantList uriList;
7297 uriList.reserve( uris.size() );
7298 for (
const QString &uri : uris )
7299 uriList.append( QVariant( uri ) );
7300 emit layersDropped( uriList );
7303 setHighlighted(
false );
7314 QHBoxLayout *hl =
new QHBoxLayout();
7315 hl->setContentsMargins( 0, 0, 0, 0 );
7317 mLineEdit =
new QgsProcessingMultipleLayerLineEdit(
nullptr, param );
7318 mLineEdit->setEnabled(
true );
7319 mLineEdit->setReadOnly(
true );
7321 hl->addWidget( mLineEdit, 1 );
7322 connect( mLineEdit, &QgsProcessingMultipleLayerLineEdit::layersDropped,
this, &QgsProcessingMultipleLayerPanelWidget::setValue );
7324 mToolButton =
new QToolButton();
7325 mToolButton->setText( QString( QChar( 0x2026 ) ) );
7326 hl->addWidget( mToolButton );
7332 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, 0 ) );
7335 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingMultipleLayerPanelWidget::showDialog );
7338void QgsProcessingMultipleLayerPanelWidget::setValue(
const QVariant &value )
7340 if ( value.isValid() )
7341 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
7345 updateSummaryText();
7349void QgsProcessingMultipleLayerPanelWidget::setProject(
QgsProject *project )
7355 if ( mValue.removeAll( layerId ) )
7357 updateSummaryText();
7364void QgsProcessingMultipleLayerPanelWidget::setModel( QgsProcessingModelAlgorithm *model,
const QString &modelChildAlgorithmID )
7370 switch ( mParam->layerType() )
7378 mModelSources = model->availableSourcesForChild(
7379 modelChildAlgorithmID,
7388 mModelSources = model->availableSourcesForChild(
7389 modelChildAlgorithmID,
7398 mModelSources = model->availableSourcesForChild(
7399 modelChildAlgorithmID,
7408 mModelSources = model->availableSourcesForChild(
7409 modelChildAlgorithmID,
7418 mModelSources = model->availableSourcesForChild(
7419 modelChildAlgorithmID,
7428 mModelSources = model->availableSourcesForChild(
7429 modelChildAlgorithmID,
7438 mModelSources = model->availableSourcesForChild(
7439 modelChildAlgorithmID,
7448 mModelSources = model->availableSourcesForChild(
7449 modelChildAlgorithmID,
7463 mModelSources = model->availableSourcesForChild(
7464 modelChildAlgorithmID,
7477 mModelSources = model->availableSourcesForChild(
7478 modelChildAlgorithmID,
7492 mModelSources = model->availableSourcesForChild(
7493 modelChildAlgorithmID,
7507 mModelSources = model->availableSourcesForChild(
7508 modelChildAlgorithmID,
7522 mModelSources = model->availableSourcesForChild(
7523 modelChildAlgorithmID,
7544void QgsProcessingMultipleLayerPanelWidget::showDialog()
7549 QgsProcessingMultipleInputPanelWidget *widget =
new QgsProcessingMultipleInputPanelWidget( mParam, mValue, mModelSources, mModel,
nullptr );
7550 widget->setPanelTitle( mParam->description() );
7551 widget->setProject( mProject );
7552 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
7558 QgsProcessingMultipleInputDialog dlg( mParam, mValue, mModelSources, mModel,
this, Qt::WindowFlags() );
7559 dlg.setProject( mProject );
7562 setValue( dlg.selectedOptions() );
7567void QgsProcessingMultipleLayerPanelWidget::updateSummaryText()
7570 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, mValue.count() ) );
7577QgsProcessingMultipleLayerParameterDefinitionWidget::QgsProcessingMultipleLayerParameterDefinitionWidget(
7582 QVBoxLayout *vlayout =
new QVBoxLayout();
7583 vlayout->setContentsMargins( 0, 0, 0, 0 );
7585 vlayout->addWidget(
new QLabel( tr(
"Allowed layer type" ) ) );
7586 mLayerTypeComboBox =
new QComboBox();
7600 mLayerTypeComboBox->setCurrentIndex( mLayerTypeComboBox->findData(
static_cast<int>( layersParam->layerType() ) ) );
7602 vlayout->addWidget( mLayerTypeComboBox );
7605 setLayout( vlayout );
7610 auto param = std::make_unique<QgsProcessingParameterMultipleLayers>( name, description,
static_cast<Qgis::ProcessingSourceType>( mLayerTypeComboBox->currentData().toInt() ) );
7612 return param.release();
7619QWidget *QgsProcessingMultipleLayerWidgetWrapper::createWidget()
7623 mPanel =
new QgsProcessingMultipleLayerPanelWidget(
nullptr, layerParam );
7624 mPanel->setToolTip( parameterDefinition()->toolTip() );
7625 mPanel->setProject( widgetContext().project() );
7627 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7628 connect( mPanel, &QgsProcessingMultipleLayerPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7637 mPanel->setProject( context.
project() );
7639 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7643void QgsProcessingMultipleLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7648 if ( value.isValid() )
7651 opts.reserve( v.size() );
7653 opts << l->source();
7656 for (
const QVariant &v : value.toList() )
7658 if ( v.userType() == qMetaTypeId<QgsProcessingModelChildParameterSource>() )
7660 const QgsProcessingModelChildParameterSource source = v.value<QgsProcessingModelChildParameterSource>();
7661 opts << QVariant::fromValue( source );
7666 mPanel->setValue( value.isValid() ? opts : QVariant() );
7670QVariant QgsProcessingMultipleLayerWidgetWrapper::widgetValue()
const
7673 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
7678QString QgsProcessingMultipleLayerWidgetWrapper::modelerExpressionFormatString()
const
7680 return tr(
"an array of layer paths, or semicolon separated string of layer paths" );
7683QString QgsProcessingMultipleLayerWidgetWrapper::parameterType()
const
7690 return new QgsProcessingMultipleLayerWidgetWrapper( parameter, type );
7697 return new QgsProcessingMultipleLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
7706 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
7709QString QgsProcessingPointCloudLayerWidgetWrapper::modelerExpressionFormatString()
const
7711 return tr(
"path to a point cloud layer" );
7714QString QgsProcessingPointCloudLayerWidgetWrapper::parameterType()
const
7721 return new QgsProcessingPointCloudLayerWidgetWrapper( parameter, type );
7728 Q_UNUSED( context );
7729 Q_UNUSED( widgetContext );
7730 Q_UNUSED( definition );
7745QString QgsProcessingAnnotationLayerWidgetWrapper::modelerExpressionFormatString()
const
7747 return tr(
"name of an annotation layer, or \"main\" for the main annotation layer" );
7750QString QgsProcessingAnnotationLayerWidgetWrapper::parameterType()
const
7757 return new QgsProcessingAnnotationLayerWidgetWrapper( parameter, type );
7764 Q_UNUSED( context );
7765 Q_UNUSED( widgetContext );
7766 Q_UNUSED( definition );
7777 if ( mWidgetContext.project() )
7778 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7782QWidget *QgsProcessingAnnotationLayerWidgetWrapper::createWidget()
7793 mComboBox->setEditable(
true );
7797 mComboBox->setToolTip( parameterDefinition()->toolTip() );
7799 if ( mWidgetContext.project() )
7800 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7803 mComboBox->setAllowEmptyLayer(
true );
7806 if ( mBlockSignals )
7809 emit widgetValueHasChanged(
this );
7812 setWidgetContext( widgetContext() );
7816void QgsProcessingAnnotationLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7822 mComboBox->setLayer(
nullptr );
7826 QVariant val = value;
7827 if ( val.userType() == qMetaTypeId<QgsProperty>() )
7839 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( val.value<QObject *>() );
7840 if ( !layer && val.userType() == QMetaType::Type::QString )
7847 mComboBox->setLayer( layer );
7852QVariant QgsProcessingAnnotationLayerWidgetWrapper::widgetValue()
const
7854 return mComboBox && mComboBox->currentLayer()
7855 ? ( mWidgetContext.project() ? ( mComboBox->currentLayer() == mWidgetContext.project()->mainAnnotationLayer() ? u
"main"_s : mComboBox->currentLayer()->id() )
7856 : mComboBox->currentLayer()->id() )
7869 QHBoxLayout *hl =
new QHBoxLayout();
7870 hl->setContentsMargins( 0, 0, 0, 0 );
7872 mLineEdit =
new QLineEdit();
7873 mLineEdit->setEnabled(
false );
7874 hl->addWidget( mLineEdit, 1 );
7876 mToolButton =
new QToolButton();
7877 mToolButton->setText( QString( QChar( 0x2026 ) ) );
7878 hl->addWidget( mToolButton );
7884 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, 0 ) );
7887 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingPointCloudAttributePanelWidget::showDialog );
7892 mAttributes = attributes;
7895void QgsProcessingPointCloudAttributePanelWidget::setValue(
const QVariant &value )
7897 if ( value.isValid() )
7898 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
7902 updateSummaryText();
7906void QgsProcessingPointCloudAttributePanelWidget::showDialog()
7908 QVariantList availableOptions;
7909 availableOptions.reserve( mAttributes.count() );
7910 const QVector<QgsPointCloudAttribute> attributes = mAttributes.attributes();
7913 availableOptions << attr.name();
7919 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
7920 widget->setPanelTitle( mParam->description() );
7922 widget->setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
7924 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
7930 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
7932 dlg.setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
7935 setValue( dlg.selectedOptions() );
7940void QgsProcessingPointCloudAttributePanelWidget::updateSummaryText()
7945 if ( mValue.empty() )
7947 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, 0 ) );
7952 values.reserve( mValue.size() );
7953 for (
const QVariant &val : std::as_const( mValue ) )
7955 values << val.toString();
7958 const QString concatenated = values.join( tr(
"," ) );
7959 if ( concatenated.length() < 100 )
7960 mLineEdit->setText( concatenated );
7962 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, mValue.count() ) );
7971QgsProcessingPointCloudAttributeParameterDefinitionWidget::QgsProcessingPointCloudAttributeParameterDefinitionWidget(
7976 QVBoxLayout *vlayout =
new QVBoxLayout();
7977 vlayout->setContentsMargins( 0, 0, 0, 0 );
7979 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
7980 mParentLayerComboBox =
new QComboBox();
7982 QString initialParent;
7984 initialParent = attrParam->parentLayerParameterName();
7986 if (
auto *lModel = widgetContext.
model() )
7989 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
7990 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
7994 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
7995 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
7997 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
8003 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
8006 mParentLayerComboBox->addItem( initialParent, initialParent );
8007 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
8010 vlayout->addWidget( mParentLayerComboBox );
8014 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple attributes" ) );
8016 mAllowMultipleCheckBox->setChecked( attrParam->allowMultiple() );
8018 vlayout->addWidget( mAllowMultipleCheckBox );
8021 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all attributes by default" ) );
8022 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
8024 mDefaultToAllCheckBox->setChecked( attrParam->defaultToAllAttributes() );
8028 vlayout->addWidget( mDefaultToAllCheckBox );
8030 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [
this] { mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() ); } );
8032 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
8034 mDefaultLineEdit =
new QLineEdit();
8035 mDefaultLineEdit->setToolTip( tr(
"Default attribute name, or ; separated list of attribute names for multiple attribute parameters" ) );
8039 mDefaultLineEdit->setText( attributes.join(
';' ) );
8041 vlayout->addWidget( mDefaultLineEdit );
8045 setLayout( vlayout );
8050 QVariant defaultValue;
8051 if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
8053 defaultValue = mDefaultLineEdit->text();
8055 auto param = std::make_unique<
8056 QgsProcessingParameterPointCloudAttribute>( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
8058 return param.release();
8065QWidget *QgsProcessingPointCloudAttributeWidgetWrapper::createWidget()
8078 mPanel =
new QgsProcessingPointCloudAttributePanelWidget(
nullptr, attrParam );
8079 mPanel->setToolTip( parameterDefinition()->toolTip() );
8080 connect( mPanel, &QgsProcessingPointCloudAttributePanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
8087 mComboBox->setToolTip( parameterDefinition()->toolTip() );
8095 mLineEdit =
new QLineEdit();
8096 mLineEdit->setToolTip( QObject::tr(
"Name of attribute (separate attribute names with ; for multiple attribute parameters)" ) );
8097 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
8104void QgsProcessingPointCloudAttributeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
8116 setParentLayerWrapperValue( wrapper );
8133 std::unique_ptr<QgsProcessingContext> tmpContext;
8134 if ( mProcessingContextGenerator )
8135 context = mProcessingContextGenerator->processingContext();
8139 tmpContext = std::make_unique<QgsProcessingContext>();
8140 context = tmpContext.get();
8146 if ( layer && layer->
isValid() )
8150 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
8153 mParentLayer.reset( qobject_cast<QgsPointCloudLayer *>( ownedLayer.release() ) );
8154 layer = mParentLayer.get();
8162 mComboBox->setLayer( layer );
8165 mPanel->setAttributes( layer->
attributes() );
8172 mComboBox->setLayer(
nullptr );
8177 if ( value.isValid() && widgetContext().messageBar() )
8188 val.reserve( mPanel->attributes().attributes().size() );
8191 setWidgetValue( val, *context );
8194 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
8197void QgsProcessingPointCloudAttributeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
8201 if ( !value.isValid() )
8202 mComboBox->setAttribute( QString() );
8206 mComboBox->setAttribute( v );
8212 if ( value.isValid() )
8215 opts.reserve( v.size() );
8216 for (
const QString &i : v )
8220 mPanel->setValue( opts );
8222 else if ( mLineEdit )
8228 mLineEdit->setText( v.join(
';' ) );
8237QVariant QgsProcessingPointCloudAttributeWidgetWrapper::widgetValue()
const
8240 return mComboBox->currentAttribute();
8242 return mPanel->value();
8243 else if ( mLineEdit )
8248 return mLineEdit->text().split(
';' );
8251 return mLineEdit->text();
8257QString QgsProcessingPointCloudAttributeWidgetWrapper::modelerExpressionFormatString()
const
8259 return tr(
"selected attribute names as an array of names, or semicolon separated string of options (e.g. 'X;Intensity')" );
8262QString QgsProcessingPointCloudAttributeWidgetWrapper::parameterType()
const
8269 return new QgsProcessingPointCloudAttributeWidgetWrapper( parameter, type );
8276 return new QgsProcessingPointCloudAttributeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
8283QgsProcessingDestinationParameterDefinitionWidget::QgsProcessingDestinationParameterDefinitionWidget(
8284 const QString &type,
8295 mType = definition->
type();
8296 mExistingDestinationParameter.reset( qgis::down_cast< QgsProcessingDestinationParameter * >( definition->
clone() ) );
8302 Q_ASSERT( parameterTypeMetadata );
8303 mExistingDestinationParameter.reset( qgis::down_cast< QgsProcessingDestinationParameter * >( parameterTypeMetadata->
create( u
"OUTPUT"_s ) ) );
8309 QVBoxLayout *vlayout =
new QVBoxLayout();
8310 vlayout->setContentsMargins( 0, 0, 0, 0 );
8312 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
8314 mDestinationWidget =
new QgsProcessingLayerOutputDestinationWidget( mExistingDestinationParameter.get(),
true );
8315 vlayout->addWidget( mDestinationWidget );
8319 setLayout( vlayout );
8325 std::unique_ptr< QgsProcessingParameterDefinition > param( mExistingDestinationParameter->clone() );
8331 return param.release();
8342QWidget *QgsProcessingOutputWidgetWrapper::createWidget()
8350 mOutputWidget =
new QgsProcessingLayerOutputDestinationWidget( destParam,
false );
8351 if ( mProcessingContextGenerator )
8352 mOutputWidget->setContext( mProcessingContextGenerator->processingContext() );
8353 if ( mParametersGenerator )
8354 mOutputWidget->registerProcessingParametersGenerator( mParametersGenerator );
8355 mOutputWidget->setToolTip( parameterDefinition()->toolTip() );
8357 connect( mOutputWidget, &QgsProcessingLayerOutputDestinationWidget::destinationChanged,
this, [
this]() {
8358 if ( mBlockSignals )
8361 emit widgetValueHasChanged(
this );
8366 mOutputWidget->addOpenAfterRunningOption();
8368 return mOutputWidget;
8378void QgsProcessingOutputWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
8380 if ( mOutputWidget )
8381 mOutputWidget->setValue( value );
8384QVariant QgsProcessingOutputWidgetWrapper::widgetValue()
const
8386 if ( mOutputWidget )
8387 return mOutputWidget->value();
8392QVariantMap QgsProcessingOutputWidgetWrapper::customProperties()
const
8395 if ( mOutputWidget )
8396 res.insert( u
"OPEN_AFTER_RUNNING"_s, mOutputWidget->openAfterRunning() );
8404 return new QgsProcessingDestinationParameterDefinitionWidget( parameterType(), context, widgetContext, qgis::down_cast< const QgsProcessingDestinationParameter * >( definition ),
algorithm );
8413 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8416QString QgsProcessingFeatureSinkWidgetWrapper::parameterType()
const
8423 return new QgsProcessingFeatureSinkWidgetWrapper( parameter, type );
8426QString QgsProcessingFeatureSinkWidgetWrapper::modelerExpressionFormatString()
const
8428 return tr(
"path to layer destination" );
8436 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8439QString QgsProcessingVectorDestinationWidgetWrapper::parameterType()
const
8446 return new QgsProcessingVectorDestinationWidgetWrapper( parameter, type );
8449QString QgsProcessingVectorDestinationWidgetWrapper::modelerExpressionFormatString()
const
8451 return tr(
"path to layer destination" );
8459 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8462QString QgsProcessingRasterDestinationWidgetWrapper::parameterType()
const
8469 return new QgsProcessingRasterDestinationWidgetWrapper( parameter, type );
8472QString QgsProcessingRasterDestinationWidgetWrapper::modelerExpressionFormatString()
const
8474 return tr(
"path to layer destination" );
8482 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8485QString QgsProcessingPointCloudDestinationWidgetWrapper::parameterType()
const
8492 return new QgsProcessingPointCloudDestinationWidgetWrapper( parameter, type );
8495QString QgsProcessingPointCloudDestinationWidgetWrapper::modelerExpressionFormatString()
const
8497 return tr(
"path to layer destination" );
8505 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8508QString QgsProcessingFileDestinationWidgetWrapper::parameterType()
const
8515 return new QgsProcessingFileDestinationWidgetWrapper( parameter, type );
8519QString QgsProcessingFileDestinationWidgetWrapper::modelerExpressionFormatString()
const
8521 return tr(
"path to file destination" );
8529 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8532QString QgsProcessingFolderDestinationWidgetWrapper::parameterType()
const
8539 return new QgsProcessingFolderDestinationWidgetWrapper( parameter, type );
8543QString QgsProcessingFolderDestinationWidgetWrapper::modelerExpressionFormatString()
const
8545 return tr(
"path to folder destination" );
8553 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8556QString QgsProcessingVectorTileDestinationWidgetWrapper::parameterType()
const
8563 return new QgsProcessingPointCloudDestinationWidgetWrapper( parameter, type );
8566QString QgsProcessingVectorTileDestinationWidgetWrapper::modelerExpressionFormatString()
const
8568 return tr(
"path to layer destination" );
8576QgsHeatmapPixelSizeWidget::QgsHeatmapPixelSizeWidget( QWidget *parent )
8581 mCellXSpinBox->setShowClearButton(
false );
8582 mCellYSpinBox->setShowClearButton(
false );
8583 mRowsSpinBox->setShowClearButton(
false );
8584 mColumnsSpinBox->setShowClearButton(
false );
8586 connect( mCellYSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), mCellXSpinBox, &QgsDoubleSpinBox::setValue );
8587 connect( mCellXSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsHeatmapPixelSizeWidget::pixelSizeChanged );
8588 connect( mRowsSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, &QgsHeatmapPixelSizeWidget::rowsChanged );
8589 connect( mColumnsSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, &QgsHeatmapPixelSizeWidget::columnsChanged );
8596 mLayerBounds = mLayer->
extent();
8600 recalculateBounds();
8608void QgsHeatmapPixelSizeWidget::setRadius(
double radius )
8611 recalculateBounds();
8614void QgsHeatmapPixelSizeWidget::setRadiusField(
const QString &radiusField )
8616 mRadiusField = radiusField;
8617 recalculateBounds();
8620void QgsHeatmapPixelSizeWidget::recalculateBounds()
8622 mRasterBounds = mLayerBounds;
8626 double maxRadius = mRadius;
8627 if ( !mRadiusField.isEmpty() )
8629 const int idx = mLayer->fields().lookupField( mRadiusField );
8631 maxRadius = mLayer->maximumValue( idx ).toDouble();
8634 mRasterBounds.setXMinimum( mRasterBounds.xMinimum() - maxRadius );
8635 mRasterBounds.setYMinimum( mRasterBounds.yMinimum() - maxRadius );
8636 mRasterBounds.setXMaximum( mRasterBounds.xMaximum() + maxRadius );
8637 mRasterBounds.setYMaximum( mRasterBounds.yMaximum() + maxRadius );
8642void QgsHeatmapPixelSizeWidget::pixelSizeChanged()
8644 const double prevValue = value();
8645 const double cellSize = mCellXSpinBox->value();
8646 if ( cellSize <= 0 || mRasterBounds.isNull() )
8648 emit valueChanged();
8654 const int rows = std::max(
static_cast<int>( std::round( mRasterBounds.height() / cellSize ) ) + 1, 1 );
8655 const int cols = std::max(
static_cast<int>( std::round( mRasterBounds.width() / cellSize ) ) + 1, 1 );
8662 emit valueChanged();
8666void QgsHeatmapPixelSizeWidget::rowsChanged()
8668 const int rows = mRowsSpinBox->value();
8669 if ( rows <= 0 || mRasterBounds.isNull() )
8672 const double cellSize = mRasterBounds.height() / rows;
8673 if ( cellSize == 0 )
8676 const int cols = std::max(
static_cast<int>( std::round( mRasterBounds.width() / cellSize ) ) + 1, 1 );
8682 emit valueChanged();
8685void QgsHeatmapPixelSizeWidget::columnsChanged()
8687 const int cols = mColumnsSpinBox->value();
8688 if ( cols < 2 || mRasterBounds.isNull() )
8691 const double cellSize = mRasterBounds.width() / ( cols - 1 );
8692 if ( cellSize == 0 )
8695 const int rows = std::max(
static_cast<int>( std::round( mRasterBounds.height() / cellSize ) ), 1 );
8701 emit valueChanged();
8704double QgsHeatmapPixelSizeWidget::value()
const
8706 return mCellXSpinBox->value();
8709void QgsHeatmapPixelSizeWidget::setValue(
double value )
8711 mCellXSpinBox->setValue( value );
8712 mCellYSpinBox->setValue( value );
8723QString QgsProcessingHeatmapPixelSizeWidgetWrapper::parameterType()
const
8730 return new QgsProcessingHeatmapPixelSizeWidgetWrapper( parameter, type );
8740QWidget *QgsProcessingHeatmapPixelSizeWidgetWrapper::createWidget()
8746 mWidget =
new QgsHeatmapPixelSizeWidget();
8747 connect( mWidget, &QgsHeatmapPixelSizeWidget::valueChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
8755 mFallbackSpinBox->setShowClearButton(
false );
8756 mFallbackSpinBox->setMinimum( 0.0 );
8757 mFallbackSpinBox->setMaximum( 99999999999.0 );
8758 mFallbackSpinBox->setDecimals( 6 );
8759 mFallbackSpinBox->setToolTip( tr(
"Resolution of each pixel in output raster, in layer units" ) );
8760 connect( mFallbackSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
8761 return mFallbackSpinBox;
8767void QgsProcessingHeatmapPixelSizeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
8776 if ( !param || !mWidget )
8783 setParentLayerWrapperValue( wrapper );
8812 std::unique_ptr<QgsProcessingContext> tmpContext;
8813 if ( mProcessingContextGenerator )
8814 context = mProcessingContextGenerator->processingContext();
8818 tmpContext = std::make_unique<QgsProcessingContext>();
8819 context = tmpContext.get();
8823 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
8833 mWidget->setLayer(
nullptr );
8839 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
8842 mParentLayer = std::move( ownedLayer );
8850 mWidget->setLayer( layer );
8853void QgsProcessingHeatmapPixelSizeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
8856 mWidget->setValue( value.toDouble() );
8857 else if ( mFallbackSpinBox )
8858 mFallbackSpinBox->setValue( value.toDouble() );
8861QVariant QgsProcessingHeatmapPixelSizeWidgetWrapper::widgetValue()
const
8864 return mWidget->value();
8865 else if ( mFallbackSpinBox )
8866 return mFallbackSpinBox->value();
8870const QgsVectorLayer *QgsProcessingHeatmapPixelSizeWidgetWrapper::linkedVectorLayer()
const
8872 if ( mWidget && mWidget->layer() )
8873 return mWidget->layer();
8894QgsReliefColorsWidget::QgsReliefColorsWidget( QWidget *parent )
8899 connect( mButtonAdd, &QToolButton::clicked,
this, &QgsReliefColorsWidget::addClicked );
8900 connect( mButtonRemove, &QToolButton::clicked,
this, &QgsReliefColorsWidget::removeClicked );
8901 connect( mButtonUp, &QToolButton::clicked,
this, &QgsReliefColorsWidget::upClicked );
8902 connect( mButtonDown, &QToolButton::clicked,
this, &QgsReliefColorsWidget::downClicked );
8903 connect( mButtonLoad, &QToolButton::clicked,
this, &QgsReliefColorsWidget::loadClicked );
8904 connect( mButtonSave, &QToolButton::clicked,
this, &QgsReliefColorsWidget::saveClicked );
8905 connect( mButtonAuto, &QToolButton::clicked,
this, &QgsReliefColorsWidget::autoCalculate );
8906 connect( mReliefColorsWidget, &QTreeWidget::itemDoubleClicked,
this, &QgsReliefColorsWidget::itemDoubleClicked );
8916 return mLayer.data();
8919void QgsReliefColorsWidget::addClicked()
8921 auto item =
new QTreeWidgetItem();
8922 item->setText( 0, u
"0.00"_s );
8923 item->setText( 1, u
"0.00"_s );
8924 item->setBackground( 2, QBrush( QColor( 127, 127, 127 ) ) );
8925 mReliefColorsWidget->addTopLevelItem( item );
8926 emit valueChanged();
8929void QgsReliefColorsWidget::removeClicked()
8931 const QList<QTreeWidgetItem *> selectedItems = mReliefColorsWidget->selectedItems();
8932 for ( QTreeWidgetItem *item : std::as_const( selectedItems ) )
8936 emit valueChanged();
8939void QgsReliefColorsWidget::downClicked()
8941 const QList<QTreeWidgetItem *> selectedItems = mReliefColorsWidget->selectedItems();
8942 for ( QTreeWidgetItem *item : std::as_const( selectedItems ) )
8944 const int currentIndex = mReliefColorsWidget->indexOfTopLevelItem( item );
8945 if ( currentIndex >= 0 && currentIndex < mReliefColorsWidget->topLevelItemCount() - 1 )
8947 mReliefColorsWidget->takeTopLevelItem( currentIndex );
8948 mReliefColorsWidget->insertTopLevelItem( currentIndex + 1, item );
8949 mReliefColorsWidget->setCurrentItem( item );
8952 emit valueChanged();
8955void QgsReliefColorsWidget::upClicked()
8957 const QList<QTreeWidgetItem *> selectedItems = mReliefColorsWidget->selectedItems();
8958 for ( QTreeWidgetItem *item : std::as_const( selectedItems ) )
8960 const int currentIndex = mReliefColorsWidget->indexOfTopLevelItem( item );
8961 if ( currentIndex > 0 )
8963 mReliefColorsWidget->takeTopLevelItem( currentIndex );
8964 mReliefColorsWidget->insertTopLevelItem( currentIndex - 1, item );
8965 mReliefColorsWidget->setCurrentItem( item );
8968 emit valueChanged();
8971void QgsReliefColorsWidget::loadClicked()
8973 const QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Import Colors from XML" ), QDir::homePath(), tr(
"XML files (*.xml *.XML)" ) );
8974 if ( fileName.isEmpty() )
8977 QFile file( fileName );
8978 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
8982 if ( !doc.setContent( &file ) )
8984 QMessageBox::critical(
this, tr(
"Import Colors from XML" ), tr(
"The XML file could not be loaded" ) );
8988 mReliefColorsWidget->clear();
8989 const QDomNodeList reliefColorList = doc.elementsByTagName( u
"ReliefColor"_s );
8990 for (
int i = 0; i < reliefColorList.length(); ++i )
8992 const QDomElement elem = reliefColorList.at( i ).toElement();
8993 auto item =
new QTreeWidgetItem();
8994 item->setText( 0, elem.attribute( u
"MinElevation"_s ) );
8995 item->setText( 1, elem.attribute( u
"MaxElevation"_s ) );
8996 item->setBackground( 2, QBrush( QColor( elem.attribute( u
"red"_s ).toInt(), elem.attribute( u
"green"_s ).toInt(), elem.attribute( u
"blue"_s ).toInt() ) ) );
8997 mReliefColorsWidget->addTopLevelItem( item );
8999 emit valueChanged();
9002void QgsReliefColorsWidget::saveClicked()
9004 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Export Colors as XML" ), QDir::homePath(), tr(
"XML files (*.xml *.XML)" ) );
9005 if ( fileName.isEmpty() )
9011 QDomElement colorsElem = doc.createElement( u
"ReliefColors"_s );
9012 doc.appendChild( colorsElem );
9014 const QList<QgsRasterReliefColor> currentColors = colors();
9017 QDomElement elem = doc.createElement( u
"ReliefColor"_s );
9020 elem.setAttribute( u
"red"_s, QString::number(
c.color.red() ) );
9021 elem.setAttribute( u
"green"_s, QString::number(
c.color.green() ) );
9022 elem.setAttribute( u
"blue"_s, QString::number(
c.color.blue() ) );
9023 colorsElem.appendChild( elem );
9026 QFile file( fileName );
9027 if ( file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
9029 QTextStream out( &file );
9030 out << doc.toString( 2 );
9034void QgsReliefColorsWidget::autoCalculate()
9036 if ( !mLayer || !mLayer->isValid() )
9040 setColors( autoColors );
9041 emit valueChanged();
9044void QgsReliefColorsWidget::itemDoubleClicked( QTreeWidgetItem *item,
int column )
9052 const double d = QInputDialog::getDouble(
this, tr(
"Enter lower elevation class bound" ), tr(
"Elevation" ), item->text( 0 ).toDouble(), -2147483647, 2147483647, 2, &ok );
9055 item->setText( 0, QString::number( d ) );
9056 emit valueChanged();
9059 else if ( column == 1 )
9061 const double d = QInputDialog::getDouble(
this, tr(
"Enter upper elevation class bound" ), tr(
"Elevation" ), item->text( 1 ).toDouble(), -2147483647, 2147483647, 2, &ok );
9064 item->setText( 1, QString::number( d ) );
9065 emit valueChanged();
9068 else if ( column == 2 )
9070 const QColor
c = QColorDialog::getColor( item->background( 2 ).color(),
this, tr(
"Select color for relief class" ) );
9073 item->setBackground( 2, QBrush(
c ) );
9074 emit valueChanged();
9079QList<QgsRasterReliefColor> QgsReliefColorsWidget::colors()
const
9081 QList<QgsRasterReliefColor> colors;
9082 for (
int i = 0; i < mReliefColorsWidget->topLevelItemCount(); ++i )
9084 if ( QTreeWidgetItem *item = mReliefColorsWidget->topLevelItem( i ) )
9086 colors.append(
QgsRasterReliefColor( item->background( 2 ).color(), item->text( 0 ).toDouble(), item->text( 1 ).toDouble() ) );
9092void QgsReliefColorsWidget::setColors(
const QList<QgsRasterReliefColor> &colors )
9094 mReliefColorsWidget->clear();
9097 auto item =
new QTreeWidgetItem();
9100 item->setBackground( 2, QBrush(
c.color ) );
9101 mReliefColorsWidget->addTopLevelItem( item );
9103 emit valueChanged();
9114QString QgsProcessingReliefColorsWidgetWrapper::parameterType()
const
9121 return new QgsProcessingReliefColorsWidgetWrapper( parameter, type );
9131QWidget *QgsProcessingReliefColorsWidgetWrapper::createWidget()
9137 mWidget =
new QgsReliefColorsWidget();
9138 connect( mWidget, &QgsReliefColorsWidget::valueChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
9145 mFallbackLineEdit =
new QLineEdit();
9146 mFallbackLineEdit->setPlaceholderText( tr(
"Relief colors definition" ) );
9147 connect( mFallbackLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
9148 return mFallbackLineEdit;
9154void QgsProcessingReliefColorsWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
9163 if ( !param || !mWidget )
9170 setParentLayerWrapperValue( wrapper );
9189 std::unique_ptr<QgsProcessingContext> tmpContext;
9190 if ( mProcessingContextGenerator )
9191 context = mProcessingContextGenerator->processingContext();
9195 tmpContext = std::make_unique<QgsProcessingContext>();
9196 context = tmpContext.get();
9201 if ( layer && layer->
isValid() )
9205 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
9208 mParentLayer.reset( qobject_cast<QgsRasterLayer *>( ownedLayer.release() ) );
9209 layer = mParentLayer.get();
9217 mWidget->setLayer( layer );
9222 mWidget->setLayer(
nullptr );
9226void QgsProcessingReliefColorsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
9230 if ( mWidget && param )
9232 mWidget->setColors( param->valueAsReliefColors( value, context ) );
9234 else if ( mFallbackLineEdit )
9235 mFallbackLineEdit->setText( value.toString() );
9238QVariant QgsProcessingReliefColorsWidgetWrapper::widgetValue()
const
9242 else if ( mFallbackLineEdit )
9243 return mFallbackLineEdit->text();
9247QString QgsProcessingReliefColorsWidgetWrapper::modelerExpressionFormatString()
const
9249 return tr(
"string of the format 'min,max,red,green,blue' for each relief color, joined by a ; delimiter" );
9257QgsExecuteSqlWidget::QgsExecuteSqlWidget( QWidget *parent )
9260 QVBoxLayout *mainLayout =
new QVBoxLayout(
this );
9261 mainLayout->setContentsMargins( 0, 0, 0, 0 );
9263 mTextEdit =
new QPlainTextEdit(
this );
9264 mainLayout->addWidget( mTextEdit, 1 );
9266 QHBoxLayout *bottomLayout =
new QHBoxLayout();
9267 bottomLayout->setContentsMargins( 0, 0, 0, 0 );
9270 bottomLayout->addWidget( mExpressionWidget, 1 );
9272 mInsertButton =
new QPushButton( tr(
"Insert" ),
this );
9273 bottomLayout->addWidget( mInsertButton );
9275 mainLayout->addLayout( bottomLayout );
9277 connect( mInsertButton, &QPushButton::clicked,
this, &QgsExecuteSqlWidget::insertExpression );
9278 connect( mTextEdit, &QPlainTextEdit::textChanged,
this, &QgsExecuteSqlWidget::changed );
9281void QgsExecuteSqlWidget::insertExpression()
9283 if ( !mExpressionWidget->currentText().isEmpty() )
9285 const QString formattedExpression = u
"[% %1 %]"_s.arg( mExpressionWidget->currentText() );
9286 mTextEdit->insertPlainText( formattedExpression );
9290void QgsExecuteSqlWidget::setValue(
const QString &text )
9292 if ( text == value() )
9295 mTextEdit->setPlainText( text );
9298QString QgsExecuteSqlWidget::value()
const
9300 return mTextEdit->toPlainText();
9311QString QgsProcessingExecuteSqlWidgetWrapper::parameterType()
const
9313 return u
"executesql"_s;
9318 return new QgsProcessingExecuteSqlWidgetWrapper( parameter, type );
9321QWidget *QgsProcessingExecuteSqlWidgetWrapper::createWidget()
9323 mExecuteSqlWidget =
new QgsExecuteSqlWidget();
9324 mExecuteSqlWidget->expressionWidget()->registerExpressionContextGenerator(
this );
9326 if ( parameterDefinition() )
9328 mExecuteSqlWidget->setToolTip( parameterDefinition()->toolTip() );
9331 connect( mExecuteSqlWidget, &QgsExecuteSqlWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
9333 return mExecuteSqlWidget;
9336void QgsProcessingExecuteSqlWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
9338 if ( !mExecuteSqlWidget )
9344 mExecuteSqlWidget->setValue( sqlText );
9347QVariant QgsProcessingExecuteSqlWidgetWrapper::widgetValue()
const
9349 if ( !mExecuteSqlWidget )
9354 return mExecuteSqlWidget->value();
9361QgsInterpolationSourceWidget::QgsInterpolationSourceWidget( QWidget *parent )
9369 connect( btnAdd, &QToolButton::clicked,
this, &QgsInterpolationSourceWidget::addLayer );
9370 connect( btnRemove, &QToolButton::clicked,
this, &QgsInterpolationSourceWidget::removeLayer );
9377 layerChanged( qobject_cast< QgsVectorLayer * >( cmbLayers->currentLayer() ) );
9380void QgsInterpolationSourceWidget::addLayer()
9382 QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( cmbLayers->currentLayer() );
9388 const QString attribute = chkUseZCoordinate->isChecked() ? u
"Z_COORD"_s : cmbFields->currentField();
9389 addLayerData( layer, attribute );
9393void QgsInterpolationSourceWidget::removeLayer()
9395 QTreeWidgetItem *item = layersTree->currentItem();
9404void QgsInterpolationSourceWidget::layerChanged(
QgsVectorLayer *layer )
9406 chkUseZCoordinate->setEnabled(
false );
9407 chkUseZCoordinate->setChecked(
false );
9409 if ( !layer || !layer->
isValid() )
9416 chkUseZCoordinate->setEnabled(
true );
9419 cmbFields->setLayer( layer );
9422void QgsInterpolationSourceWidget::addLayerData(
QgsVectorLayer *layer,
const QString &attribute )
9424 QTreeWidgetItem *item =
new QTreeWidgetItem();
9425 item->setText( 0, layer->
name() );
9426 item->setText( 1, attribute );
9427 item->setData( 0, Qt::UserRole, layer->
source() );
9428 layersTree->addTopLevelItem( item );
9430 QComboBox *comboBox =
new QComboBox();
9434 comboBox->setCurrentIndex( 0 );
9435 layersTree->setItemWidget( item, 2, comboBox );
9438void QgsInterpolationSourceWidget::setValue(
const QVariant &value,
QgsProcessingContext &context )
9440 layersTree->clear();
9441 const QStringList rows = value.toString().split(
"::|::"_L1, Qt::SkipEmptyParts );
9443 for (
const QString &row : rows )
9445 const QStringList tokens = row.split(
"::~::"_L1 );
9446 if ( tokens.size() < 4 )
9451 const QString layerSource = tokens.at( 0 );
9453 if ( !layer || !layer->
isValid() )
9457 const int fieldIndexInt = tokens.at( 2 ).toInt( &isInt );
9458 if ( isInt && fieldIndexInt == -1 )
9460 addLayerData( layer, u
"Z_COORD"_s );
9464 addLayerData( layer, layer->
fields().
at( fieldIndexInt ).
name() );
9468 addLayerData( layer, tokens.at( 2 ) );
9472 QComboBox *comboBox = qobject_cast<QComboBox *>( layersTree->itemWidget( layersTree->topLevelItem( itemIndex ), 2 ) );
9475 comboBox->setCurrentIndex( comboBox->findData( QVariant::fromValue( sourceType ) ) );
9482QVariant QgsInterpolationSourceWidget::value()
const
9485 for (
int index = 0; index < layersTree->topLevelItemCount(); ++index )
9487 QTreeWidgetItem *item = layersTree->topLevelItem( index );
9493 const QString layerSource = item->data( 0, Qt::UserRole ).toString();
9494 QString interpolationAttribute = item->text( 1 );
9497 if ( interpolationAttribute ==
"Z_COORD"_L1 )
9500 interpolationAttribute = u
"-1"_s;
9503 QComboBox *comboBox = qobject_cast<QComboBox *>( layersTree->itemWidget( item, 2 ) );
9504 const int inputType = comboBox ?
static_cast< int >( comboBox->currentData().value< Qgis::InterpolationSourceType >() ) : 0;
9506 result << u
"%1::~::%2::~::%3::~::%4"_s.arg( layerSource ).arg( valueSource ).arg( interpolationAttribute ).arg( inputType );
9509 if ( result.isEmpty() )
9512 return result.join(
"::|::"_L1 );
9524QString QgsProcessingInterpolationSourceWidgetWrapper::parameterType()
const
9531 return new QgsProcessingInterpolationSourceWidgetWrapper( parameter, type );
9541QWidget *QgsProcessingInterpolationSourceWidgetWrapper::createWidget()
9543 mWidget =
new QgsInterpolationSourceWidget();
9544 if ( parameterDefinition() )
9546 mWidget->setToolTip( parameterDefinition()->toolTip() );
9549 connect( mWidget, &QgsInterpolationSourceWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
9553void QgsProcessingInterpolationSourceWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
9557 mWidget->setValue( value, context );
9561QVariant QgsProcessingInterpolationSourceWidgetWrapper::widgetValue()
const
9563 return mWidget ? mWidget->value() : QVariant();
9571QgsInterpolationPixelSizeWidget::QgsInterpolationPixelSizeWidget( QWidget *parent )
9576 mCellXSpinBox->setShowClearButton(
false );
9577 mCellYSpinBox->setShowClearButton(
false );
9578 mRowsSpinBox->setShowClearButton(
false );
9579 mColumnsSpinBox->setShowClearButton(
false );
9581 connect( mCellYSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), mCellXSpinBox, &QgsDoubleSpinBox::setValue );
9582 connect( mCellXSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsInterpolationPixelSizeWidget::pixelSizeChanged );
9583 connect( mRowsSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, &QgsInterpolationPixelSizeWidget::rowsChanged );
9584 connect( mColumnsSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, &QgsInterpolationPixelSizeWidget::columnsChanged );
9587void QgsInterpolationPixelSizeWidget::setSourceData(
const QString &sourceData,
QgsProcessingContext &context )
9590 const QStringList rows = sourceData.split(
"::|::"_L1, Qt::SkipEmptyParts );
9591 for (
const QString &row : rows )
9593 const QStringList tokens = row.split(
"::~::"_L1 );
9594 if ( tokens.isEmpty() )
9602 mExtent.combineExtentWith( source->sourceExtent() );
9609void QgsInterpolationPixelSizeWidget::setExtent(
const QgsRectangle &extent )
9615void QgsInterpolationPixelSizeWidget::pixelSizeChanged()
9617 const double prevValue = value();
9618 const double cellSize = mCellXSpinBox->value();
9621 emit valueChanged();
9627 const int rows = std::max(
static_cast<int>( std::round( mExtent.height() / cellSize ) ) + 1, 1 );
9628 const int cols = std::max(
static_cast<int>( std::round( mExtent.width() / cellSize ) ) + 1, 1 );
9635 emit valueChanged();
9639void QgsInterpolationPixelSizeWidget::rowsChanged()
9641 const int rows = mRowsSpinBox->value();
9642 if ( rows <= 0 || mExtent.isNull() )
9645 const double cellSize = mExtent.height() / rows;
9649 const int cols = std::max(
static_cast<int>( std::round( mExtent.width() / cellSize ) ) + 1, 1 );
9655 emit valueChanged();
9658void QgsInterpolationPixelSizeWidget::columnsChanged()
9660 const int cols = mColumnsSpinBox->value();
9661 if ( cols < 2 || mExtent.isNull() )
9664 const double cellSize = mExtent.width() / ( cols - 1 );
9668 const int rows = std::max(
static_cast<int>( std::round( mExtent.height() / cellSize ) ), 1 );
9674 emit valueChanged();
9677double QgsInterpolationPixelSizeWidget::value()
const
9679 return mCellXSpinBox->value();
9682void QgsInterpolationPixelSizeWidget::setValue(
double value )
9684 mCellXSpinBox->setValue( value );
9685 mCellYSpinBox->setValue( value );
9697QString QgsProcessingInterpolationPixelSizeWidgetWrapper::parameterType()
const
9704 return new QgsProcessingInterpolationPixelSizeWidgetWrapper( parameter, type );
9714QWidget *QgsProcessingInterpolationPixelSizeWidgetWrapper::createWidget()
9720 mWidget =
new QgsInterpolationPixelSizeWidget();
9721 connect( mWidget, &QgsInterpolationPixelSizeWidget::valueChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
9729 mFallbackSpinBox->setShowClearButton(
false );
9730 mFallbackSpinBox->setMinimum( 0.0 );
9731 mFallbackSpinBox->setMaximum( 99999999999.0 );
9732 mFallbackSpinBox->setDecimals( 6 );
9733 mFallbackSpinBox->setToolTip( tr(
"Resolution of each pixel in output raster" ) );
9734 connect( mFallbackSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
9735 return mFallbackSpinBox;
9741void QgsProcessingInterpolationPixelSizeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
9750 if ( !param || !mWidget )
9757 sourceChanged( wrapper );
9762 extentChanged( wrapper );
9774void QgsProcessingInterpolationPixelSizeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
9777 mWidget->setValue( value.toDouble() );
9778 else if ( mFallbackSpinBox )
9779 mFallbackSpinBox->setValue( value.toDouble() );
9782QVariant QgsProcessingInterpolationPixelSizeWidgetWrapper::widgetValue()
const
9785 return mWidget->value();
9786 else if ( mFallbackSpinBox )
9787 return mFallbackSpinBox->value();
9796 std::unique_ptr<QgsProcessingContext> tmpContext;
9797 if ( mProcessingContextGenerator )
9798 context = mProcessingContextGenerator->processingContext();
9802 tmpContext = std::make_unique<QgsProcessingContext>();
9803 context = tmpContext.get();
9806 mWidget->setSourceData( wrapper->
parameterValue().toString(), *context );
9815 std::unique_ptr<QgsProcessingContext> tmpContext;
9816 if ( mProcessingContextGenerator )
9817 context = mProcessingContextGenerator->processingContext();
9821 tmpContext = std::make_unique<QgsProcessingContext>();
9822 context = tmpContext.get();
9827 mWidget->setExtent( extent );
@ 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.
InterpolationSourceType
Interpolation source types.
@ StructureLines
Structure lines.
@ Z
Use feature's geometry Z values for interpolation.
@ Attribute
Take value from feature's attribute.
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.
@ CrossX
A cross is used to highlight points (x).
@ 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 QgsProcessingRegistry * processingRegistry()
Returns the application's processing registry, used for managing processing providers,...
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.
static QString ensureFileNameHasExtension(const QString &fileName, const QStringList &extensions)
Ensures that a fileName ends with an extension from the provided list of extensions.
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.
QString source() const
Returns the source for the layer.
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 setDefaultValue(const QVariant &value)
Sets the default value for the parameter.
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.
void setDescription(const QString &description)
Sets the description for the parameter.
void setName(const QString &name)
Sets the name of the parameter.
virtual QgsProcessingParameterDefinition * clone() const =0
Creates a clone of the parameter definition.
virtual QString type() const =0
Unique parameter type name.
QString name() const
Returns the name of the parameter.
Qgis::ProcessingParameterFlags flags() const
Returns any flags associated with the parameter.
A double numeric parameter for distance values.
static QString typeName()
Returns the type name for the parameter class.
Qgis::DistanceUnit defaultUnit() const
Returns the default distance unit for the parameter.
A double numeric parameter for duration values.
Qgis::TemporalUnit defaultUnit() const
Returns the default duration unit for the parameter.
static QString typeName()
Returns the type name for the parameter class.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
bool allowMultiple() const
Returns true if the parameter allows multiple selected values.
QStringList options() const
Returns the list of acceptable options for the parameter.
bool usesStaticStrings() const
Returns true if the parameter uses static (non-translated) string values for its enumeration choice l...
static QString typeName()
Returns the type name for the parameter class.
An expression parameter for processing algorithms.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
static QString typeName()
Returns the type name for the parameter class.
Qgis::ExpressionType expressionType() const
Returns the parameter's expression type.
A rectangular map extent parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
An input feature source (such as vector layers) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A vector layer or feature source field parameter for processing algorithms.
Qgis::ProcessingFieldParameterDataType dataType() const
Returns the acceptable data type for the field.
bool allowMultiple() const
Returns whether multiple field selections are permitted.
bool defaultToAllFields() const
Returns whether a parameter which allows multiple selections (see allowMultiple()) should automatical...
static QString typeName()
Returns the type name for the parameter class.
void setDataType(Qgis::ProcessingFieldParameterDataType type)
Sets the acceptable data type for the field.
static QString typeName()
Returns the type name for the parameter class.
An input file or folder parameter for processing algorithms.
QString extension() const
Returns any specified file extension for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QString fileFilter() const
Returns the file filter string for file destinations compatible with this parameter.
Qgis::ProcessingFileParameterBehavior behavior() const
Returns the parameter behavior (e.g.
static QString typeName()
Returns the type name for the parameter class.
A geometry parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A parameter for the heatmap algorithm pixel size parameter.
static QString typeName()
Returns the type name for the parameter class.
A parameter for the interpolation algorithm pixel size parameter.
static QString typeName()
Returns the type name for the parameter class.
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 parameter for raster relief colors.
static QVariant colorsAsVariant(const QList< QgsRasterReliefColor > &colors)
Returns a list of raster relief colors encoded as a variant value.
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.
Makes metadata of processing parameters available.
virtual QgsProcessingParameterDefinition * create(const QString &name) const =0
Creates a new parameter of this type.
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.
QgsProcessingParameterType * parameterType(const QString &id) const
Returns the parameter type registered for id.
Utility functions for use with processing classes.
@ Annotation
Annotation layer type, since QGIS 3.22.
@ Vector
Vector layer type.
static QgsProcessingFeatureSource * variantToSource(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a new feature source.
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.
static QList< QgsRasterReliefColor > calculateOptimizedReliefClasses(QgsRasterDataProvider *provider, int band)
Calculates optimized relief class breaks according with the method of Buenzli (2011) using an iterati...
Represents a raster layer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Defines elevation range and color for raster relief coloring.
A rectangle specified with double values.
A QgsGeometry with associated coordinate reference system.
Stores settings for use within QGIS.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
A spin box with a clear button that will set the value to the defined clear value.
A QTimeEdit widget with the capability of setting/reading null date/times.
void timeValueChanged(const QTime &time)
Signal emitted whenever the time changes.
static Q_INVOKABLE QString toString(Qgis::DistanceUnit unit)
Returns a translated string representing a distance unit.
static Q_INVOKABLE double fromUnitToUnitFactor(Qgis::DistanceUnit fromUnit, Qgis::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
static Q_INVOKABLE Qgis::DistanceUnitType unitType(Qgis::DistanceUnit unit)
Returns the type for a distance unit.
Represents a vector layer which manages a vector based dataset.
QgsRectangle extent() const final
Returns the extent of the layer.
Q_INVOKABLE Qgis::WkbType wkbType() const final
Returns the WKBType or WKBUnknown in case of error.
static Q_INVOKABLE bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
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
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
bool qgsDoubleLessThanOrNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles to see if one is less than the other or very near to the other.
constexpr QObjectUniquePtr< Tp > make_qobject_unique(Args &&...args)
Create an object owned by a QObjectUniquePtr.