82#include <QButtonGroup>
87#include <QInputDialog>
92#include <QPlainTextEdit>
93#include <QRadioButton>
98#include "moc_qgsprocessingwidgetwrapperimpl.cpp"
100using namespace Qt::StringLiterals;
109QgsProcessingBooleanParameterDefinitionWidget::QgsProcessingBooleanParameterDefinitionWidget(
114 QVBoxLayout *vlayout =
new QVBoxLayout();
115 vlayout->setContentsMargins( 0, 0, 0, 0 );
117 mDefaultCheckBox =
new QCheckBox( tr(
"Checked" ) );
121 mDefaultCheckBox->setChecked(
false );
122 vlayout->addWidget( mDefaultCheckBox );
125 setLayout( vlayout );
130 auto param = std::make_unique<QgsProcessingParameterBoolean>( name, description, mDefaultCheckBox->isChecked() );
131 param->setFlags( flags );
132 return param.release();
140QWidget *QgsProcessingBooleanWidgetWrapper::createWidget()
146 QString description = parameterDefinition()->description();
148 description = QObject::tr(
"%1 [optional]" ).arg( description );
150 mCheckBox =
new QCheckBox( description );
151 mCheckBox->setToolTip( parameterDefinition()->toolTip() );
153 connect( mCheckBox, &QCheckBox::toggled,
this, [
this] { emit widgetValueHasChanged(
this ); } );
160 mComboBox =
new QComboBox();
161 mComboBox->addItem( tr(
"Yes" ),
true );
162 mComboBox->addItem( tr(
"No" ),
false );
163 mComboBox->setToolTip( parameterDefinition()->toolTip() );
165 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
173QLabel *QgsProcessingBooleanWidgetWrapper::createLabel()
182void QgsProcessingBooleanWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
189 mCheckBox->setChecked( v );
197 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
203QVariant QgsProcessingBooleanWidgetWrapper::widgetValue()
const
208 return mCheckBox->isChecked();
212 return mComboBox->currentData();
217QString QgsProcessingBooleanWidgetWrapper::parameterType()
const
224 return new QgsProcessingBooleanWidgetWrapper( parameter, type );
231 return new QgsProcessingBooleanParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
239QgsProcessingCrsParameterDefinitionWidget::QgsProcessingCrsParameterDefinitionWidget(
244 QVBoxLayout *vlayout =
new QVBoxLayout();
245 vlayout->setContentsMargins( 0, 0, 0, 0 );
247 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
252 mCrsSelector->setShowAccuracyWarnings(
true );
259 vlayout->addWidget( mCrsSelector );
260 setLayout( vlayout );
265 auto param = std::make_unique<QgsProcessingParameterCrs>( name, description, mCrsSelector->crs().authid() );
266 param->setFlags( flags );
267 return param.release();
274QWidget *QgsProcessingCrsWidgetWrapper::createWidget()
276 Q_ASSERT( mProjectionSelectionWidget ==
nullptr );
278 mProjectionSelectionWidget->setToolTip( parameterDefinition()->toolTip() );
292 return mProjectionSelectionWidget;
297 QWidget *w =
new QWidget();
298 w->setToolTip( parameterDefinition()->toolTip() );
300 QVBoxLayout *vl =
new QVBoxLayout();
301 vl->setContentsMargins( 0, 0, 0, 0 );
304 mUseProjectCrsCheckBox =
new QCheckBox( tr(
"Use project CRS" ) );
305 mUseProjectCrsCheckBox->setToolTip( tr(
"Always use the current project CRS when running the model" ) );
306 vl->addWidget( mUseProjectCrsCheckBox );
307 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, mProjectionSelectionWidget, &QgsProjectionSelectionWidget::setDisabled );
308 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled,
this, [
this] { emit widgetValueHasChanged(
this ); } );
310 vl->addWidget( mProjectionSelectionWidget );
318void QgsProcessingCrsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
320 if ( mUseProjectCrsCheckBox )
322 if ( value.toString().compare(
"ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
324 mUseProjectCrsCheckBox->setChecked(
true );
329 mUseProjectCrsCheckBox->setChecked(
false );
334 if ( mProjectionSelectionWidget )
335 mProjectionSelectionWidget->setCrs( v );
338QVariant QgsProcessingCrsWidgetWrapper::widgetValue()
const
340 if ( mUseProjectCrsCheckBox && mUseProjectCrsCheckBox->isChecked() )
341 return u
"ProjectCrs"_s;
342 else if ( mProjectionSelectionWidget )
343 return mProjectionSelectionWidget->crs().isValid() ? mProjectionSelectionWidget->crs() : QVariant();
348QString QgsProcessingCrsWidgetWrapper::modelerExpressionFormatString()
const
350 return tr(
"string as EPSG code, WKT or PROJ format, or a string identifying a map layer" );
353QString QgsProcessingCrsWidgetWrapper::parameterType()
const
360 return new QgsProcessingCrsWidgetWrapper( parameter, type );
367 return new QgsProcessingCrsParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
376QgsProcessingStringParameterDefinitionWidget::QgsProcessingStringParameterDefinitionWidget(
381 QVBoxLayout *vlayout =
new QVBoxLayout();
382 vlayout->setContentsMargins( 0, 0, 0, 0 );
384 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
386 mDefaultLineEdit =
new QLineEdit();
389 vlayout->addWidget( mDefaultLineEdit );
393 mMultiLineCheckBox =
new QCheckBox( tr(
"Multiline input" ) );
395 mMultiLineCheckBox->setChecked( stringParam->multiLine() );
396 vlayout->addWidget( mMultiLineCheckBox );
400 setLayout( vlayout );
405 auto param = std::make_unique<QgsProcessingParameterString>( name, description, mDefaultLineEdit->text(), mMultiLineCheckBox->isChecked() );
406 param->setFlags( flags );
407 return param.release();
415QWidget *QgsProcessingStringWidgetWrapper::createWidget()
417 const QVariantMap metadata = parameterDefinition()->metadata();
418 const QVariant valueHintsVariant = metadata.value( u
"widget_wrapper"_s ).toMap().value( u
"value_hints"_s );
420 if ( valueHintsVariant.isValid() )
422 const QVariantList valueList = valueHintsVariant.toList();
423 mComboBox =
new QComboBox();
424 mComboBox->setToolTip( parameterDefinition()->toolTip() );
428 mComboBox->addItem( QString() );
430 for (
const QVariant &entry : valueList )
432 mComboBox->addItem( entry.toString(), entry.toString() );
434 mComboBox->setCurrentIndex( 0 );
436 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
448 mPlainTextEdit =
new QPlainTextEdit();
449 mPlainTextEdit->setToolTip( parameterDefinition()->toolTip() );
451 connect( mPlainTextEdit, &QPlainTextEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
452 return mPlainTextEdit;
456 mLineEdit =
new QLineEdit();
457 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
459 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
466 mLineEdit =
new QLineEdit();
467 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
469 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
478void QgsProcessingStringWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
482 mLineEdit->setText( v );
483 if ( mPlainTextEdit )
484 mPlainTextEdit->setPlainText( v );
488 if ( !value.isValid() )
489 index = mComboBox->findData( QVariant() );
491 index = mComboBox->findData( v );
494 mComboBox->setCurrentIndex( index );
496 mComboBox->setCurrentIndex( 0 );
500QVariant QgsProcessingStringWidgetWrapper::widgetValue()
const
503 return mLineEdit->text();
504 else if ( mPlainTextEdit )
505 return mPlainTextEdit->toPlainText();
506 else if ( mComboBox )
507 return mComboBox->currentData();
512QString QgsProcessingStringWidgetWrapper::parameterType()
const
519 return new QgsProcessingStringWidgetWrapper( parameter, type );
526 return new QgsProcessingStringParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
538QWidget *QgsProcessingAuthConfigWidgetWrapper::createWidget()
547 mAuthConfigSelect->setToolTip( parameterDefinition()->toolTip() );
550 return mAuthConfigSelect;
556void QgsProcessingAuthConfigWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
559 if ( mAuthConfigSelect )
560 mAuthConfigSelect->setConfigId( v );
563QVariant QgsProcessingAuthConfigWidgetWrapper::widgetValue()
const
565 if ( mAuthConfigSelect )
566 return mAuthConfigSelect->configId();
571QString QgsProcessingAuthConfigWidgetWrapper::parameterType()
const
578 return new QgsProcessingAuthConfigWidgetWrapper( parameter, type );
585QgsProcessingNumberParameterDefinitionWidget::QgsProcessingNumberParameterDefinitionWidget(
590 QVBoxLayout *vlayout =
new QVBoxLayout();
591 vlayout->setContentsMargins( 0, 0, 0, 0 );
593 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
595 mTypeComboBox =
new QComboBox();
598 vlayout->addWidget( mTypeComboBox );
600 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
601 mMinLineEdit =
new QLineEdit();
602 vlayout->addWidget( mMinLineEdit );
604 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
605 mMaxLineEdit =
new QLineEdit();
606 vlayout->addWidget( mMaxLineEdit );
608 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
609 mDefaultLineEdit =
new QLineEdit();
610 vlayout->addWidget( mDefaultLineEdit );
614 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( numberParam->dataType() ) ) );
616 if ( !
qgsDoubleNear( numberParam->maximum(), std::numeric_limits<double>::max() ) )
618 mMaxLineEdit->setText( QLocale().toString( numberParam->maximum() ) );
622 mMaxLineEdit->clear();
625 if ( !
qgsDoubleNear( numberParam->minimum(), std::numeric_limits<double>::lowest() ) )
627 mMinLineEdit->setText( QLocale().toString( numberParam->minimum() ) );
631 mMinLineEdit->clear();
634 mDefaultLineEdit->setText( numberParam->defaultValueForGui().toString() );
642 setLayout( vlayout );
651 auto param = std::make_unique<QgsProcessingParameterNumber>( name, description, dataType, ok ? val : QVariant() );
653 if ( !mMinLineEdit->text().trimmed().isEmpty() )
658 param->setMinimum( val );
662 if ( !mMaxLineEdit->text().trimmed().isEmpty() )
667 param->setMaximum( val );
671 param->setFlags( flags );
672 return param.release();
679QWidget *QgsProcessingNumericWidgetWrapper::createWidget()
682 const QVariantMap metadata = numberDef->
metadata();
683 const int decimals = metadata.value( u
"widget_wrapper"_s ).toMap().value( u
"decimals"_s, 6 ).toInt();
691 QAbstractSpinBox *spinBox =
nullptr;
696 mDoubleSpinBox->setExpressionsEnabled(
true );
697 mDoubleSpinBox->setDecimals( decimals );
702 double singleStep = calculateStep( numberDef->
minimum(), numberDef->
maximum() );
703 singleStep = std::max( singleStep, std::pow( 10, -decimals ) );
704 mDoubleSpinBox->setSingleStep( singleStep );
707 spinBox = mDoubleSpinBox;
712 mSpinBox->setExpressionsEnabled(
true );
716 spinBox->setToolTip( parameterDefinition()->toolTip() );
718 double max = 999999999;
723 double min = -999999999;
728 if ( mDoubleSpinBox )
730 mDoubleSpinBox->setMinimum( min );
731 mDoubleSpinBox->setMaximum( max );
735 mSpinBox->setMinimum(
static_cast<int>( min ) );
736 mSpinBox->setMaximum(
static_cast<int>( max ) );
741 mAllowingNull =
true;
742 if ( mDoubleSpinBox )
744 mDoubleSpinBox->setShowClearButton(
true );
745 const double min = mDoubleSpinBox->minimum() - mDoubleSpinBox->singleStep();
746 mDoubleSpinBox->setMinimum( min );
747 mDoubleSpinBox->setValue( min );
751 mSpinBox->setShowClearButton(
true );
752 const int min = mSpinBox->minimum() - 1;
753 mSpinBox->setMinimum( min );
754 mSpinBox->setValue( min );
756 spinBox->setSpecialValueText( tr(
"Not set" ) );
764 if ( mDoubleSpinBox )
768 mDoubleSpinBox->setClearValue( defaultVal );
774 mSpinBox->setClearValue( intVal );
780 if ( mDoubleSpinBox )
781 mDoubleSpinBox->setClearValue( numberDef->
minimum() );
783 mSpinBox->setClearValue(
static_cast<int>( numberDef->
minimum() ) );
788 if ( mDoubleSpinBox )
790 mDoubleSpinBox->setValue( 0 );
791 mDoubleSpinBox->setClearValue( 0 );
795 mSpinBox->setValue( 0 );
796 mSpinBox->setClearValue( 0 );
801 if ( mDoubleSpinBox )
802 connect( mDoubleSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
804 connect( mSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
812void QgsProcessingNumericWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
814 if ( mDoubleSpinBox )
816 if ( mAllowingNull && !value.isValid() )
817 mDoubleSpinBox->clear();
821 mDoubleSpinBox->setValue( v );
826 if ( mAllowingNull && !value.isValid() )
831 mSpinBox->setValue( v );
836QVariant QgsProcessingNumericWidgetWrapper::widgetValue()
const
838 if ( mDoubleSpinBox )
840 if ( mAllowingNull &&
qgsDoubleNear( mDoubleSpinBox->value(), mDoubleSpinBox->minimum() ) )
843 return mDoubleSpinBox->value();
847 if ( mAllowingNull && mSpinBox->value() == mSpinBox->minimum() )
850 return mSpinBox->value();
856double QgsProcessingNumericWidgetWrapper::calculateStep(
const double minimum,
const double maximum )
858 const double valueRange = maximum - minimum;
859 if ( valueRange <= 1.0 )
861 const double step = valueRange / 10.0;
863 return qgsRound( step, -std::floor( std::log( step ) ) );
871QString QgsProcessingNumericWidgetWrapper::parameterType()
const
878 return new QgsProcessingNumericWidgetWrapper( parameter, type );
885 return new QgsProcessingNumberParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
892QgsProcessingDistanceParameterDefinitionWidget::QgsProcessingDistanceParameterDefinitionWidget(
897 QVBoxLayout *vlayout =
new QVBoxLayout();
898 vlayout->setContentsMargins( 0, 0, 0, 0 );
900 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
902 mParentLayerComboBox =
new QComboBox();
904 QString initialParent;
906 initialParent = distParam->parentParameterName();
908 if (
auto *lModel = widgetContext.
model() )
911 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
912 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
916 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
917 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
919 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
924 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
925 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
927 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
932 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
933 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
935 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
940 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
941 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
943 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
949 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
952 mParentLayerComboBox->addItem( initialParent, initialParent );
953 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
956 vlayout->addWidget( mParentLayerComboBox );
959 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
960 mMinLineEdit =
new QLineEdit();
961 vlayout->addWidget( mMinLineEdit );
963 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
964 mMaxLineEdit =
new QLineEdit();
965 vlayout->addWidget( mMaxLineEdit );
967 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
968 mDefaultLineEdit =
new QLineEdit();
969 vlayout->addWidget( mDefaultLineEdit );
973 mMinLineEdit->setText( QLocale().toString( distParam->minimum() ) );
974 mMaxLineEdit->setText( QLocale().toString( distParam->maximum() ) );
975 mDefaultLineEdit->setText( distParam->defaultValueForGui().toString() );
981 setLayout( vlayout );
989 auto param = std::make_unique<QgsProcessingParameterDistance>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
994 param->setMinimum( val );
1000 param->setMaximum( val );
1003 param->setFlags( flags );
1004 return param.release();
1008 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1011QString QgsProcessingDistanceWidgetWrapper::parameterType()
const
1018 return new QgsProcessingDistanceWidgetWrapper( parameter, type );
1021QWidget *QgsProcessingDistanceWidgetWrapper::createWidget()
1025 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1030 mLabel =
new QLabel();
1031 mUnitsCombo =
new QComboBox();
1043 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1044 QHBoxLayout *layout =
new QHBoxLayout();
1045 layout->addWidget( spin, 1 );
1046 layout->insertSpacing( 1, labelMargin / 2 );
1047 layout->insertWidget( 2, mLabel );
1048 layout->insertWidget( 3, mUnitsCombo );
1053 mWarningLabel =
new QWidget();
1054 QHBoxLayout *warningLayout =
new QHBoxLayout();
1055 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1056 QLabel *warning =
new QLabel();
1058 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1059 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1060 warning->setToolTip( tr(
"Distance is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1061 warningLayout->insertSpacing( 0, labelMargin / 2 );
1062 warningLayout->insertWidget( 1, warning );
1063 mWarningLabel->setLayout( warningLayout );
1064 layout->insertWidget( 4, mWarningLabel );
1066 QWidget *w =
new QWidget();
1067 layout->setContentsMargins( 0, 0, 0, 0 );
1068 w->setLayout( layout );
1082void QgsProcessingDistanceWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1084 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1091 if ( wrapper->parameterDefinition()->name() ==
static_cast<const QgsProcessingParameterDistance *
>( parameterDefinition() )->parentParameterName() )
1093 setUnitParameterValue( wrapper->parameterValue(), wrapper );
1113 std::unique_ptr<QgsProcessingContext> tmpContext;
1114 if ( mProcessingContextGenerator )
1115 context = mProcessingContextGenerator->processingContext();
1119 tmpContext = std::make_unique<QgsProcessingContext>();
1120 context = tmpContext.get();
1127 units = crs.mapUnits();
1138 mUnitsCombo->hide();
1146 if ( mBaseUnit != units )
1148 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( units ) ) );
1151 mUnitsCombo->show();
1158QVariant QgsProcessingDistanceWidgetWrapper::widgetValue()
const
1160 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1161 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1176 return new QgsProcessingDistanceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1184QgsProcessingAreaParameterDefinitionWidget::QgsProcessingAreaParameterDefinitionWidget(
1189 QVBoxLayout *vlayout =
new QVBoxLayout();
1190 vlayout->setContentsMargins( 0, 0, 0, 0 );
1192 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
1194 mParentLayerComboBox =
new QComboBox();
1196 QString initialParent;
1198 initialParent = areaParam->parentParameterName();
1200 if (
auto *lModel = widgetContext.
model() )
1203 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
1204 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
1208 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1209 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1211 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1216 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1217 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1219 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1224 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1225 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1227 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1232 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1233 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1235 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1241 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
1244 mParentLayerComboBox->addItem( initialParent, initialParent );
1245 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1250 vlayout->addWidget( mParentLayerComboBox );
1252 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1253 mMinLineEdit =
new QLineEdit();
1254 vlayout->addWidget( mMinLineEdit );
1256 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1257 mMaxLineEdit =
new QLineEdit();
1258 vlayout->addWidget( mMaxLineEdit );
1260 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1261 mDefaultLineEdit =
new QLineEdit();
1262 vlayout->addWidget( mDefaultLineEdit );
1266 mMinLineEdit->setText( QLocale().toString( areaParam->minimum() ) );
1267 mMaxLineEdit->setText( QLocale().toString( areaParam->maximum() ) );
1268 mDefaultLineEdit->setText( areaParam->defaultValueForGui().toString() );
1275 setLayout( vlayout );
1283 auto param = std::make_unique<QgsProcessingParameterArea>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1288 param->setMinimum( val );
1294 param->setMaximum( val );
1297 param->setFlags( flags );
1298 return param.release();
1307 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1310QString QgsProcessingAreaWidgetWrapper::parameterType()
const
1317 return new QgsProcessingAreaWidgetWrapper( parameter, type );
1320QWidget *QgsProcessingAreaWidgetWrapper::createWidget()
1324 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1329 mLabel =
new QLabel();
1330 mUnitsCombo =
new QComboBox();
1345 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1346 QHBoxLayout *layout =
new QHBoxLayout();
1347 layout->addWidget( spin, 1 );
1348 layout->insertSpacing( 1, labelMargin / 2 );
1349 layout->insertWidget( 2, mLabel );
1350 layout->insertWidget( 3, mUnitsCombo );
1355 mWarningLabel =
new QWidget();
1356 QHBoxLayout *warningLayout =
new QHBoxLayout();
1357 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1358 QLabel *warning =
new QLabel();
1360 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1361 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1362 warning->setToolTip( tr(
"Area is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1363 warningLayout->insertSpacing( 0, labelMargin / 2 );
1364 warningLayout->insertWidget( 1, warning );
1365 mWarningLabel->setLayout( warningLayout );
1366 layout->insertWidget( 4, mWarningLabel );
1368 QWidget *w =
new QWidget();
1369 layout->setContentsMargins( 0, 0, 0, 0 );
1370 w->setLayout( layout );
1384void QgsProcessingAreaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1386 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1415 std::unique_ptr<QgsProcessingContext> tmpContext;
1416 if ( mProcessingContextGenerator )
1417 context = mProcessingContextGenerator->processingContext();
1421 tmpContext = std::make_unique<QgsProcessingContext>();
1422 context = tmpContext.get();
1429 units = QgsUnitTypes::distanceToAreaUnit( crs.mapUnits() );
1435void QgsProcessingAreaWidgetWrapper::setUnits(
Qgis::AreaUnit units )
1440 mUnitsCombo->hide();
1445 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QVariant::fromValue( units ) ) );
1446 mUnitsCombo->show();
1453QVariant QgsProcessingAreaWidgetWrapper::widgetValue()
const
1455 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1456 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1471 return new QgsProcessingAreaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1479QgsProcessingVolumeParameterDefinitionWidget::QgsProcessingVolumeParameterDefinitionWidget(
1484 QVBoxLayout *vlayout =
new QVBoxLayout();
1485 vlayout->setContentsMargins( 0, 0, 0, 0 );
1487 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
1489 mParentLayerComboBox =
new QComboBox();
1491 QString initialParent;
1493 initialParent = volumeParam->parentParameterName();
1495 if (
auto *lModel = widgetContext.
model() )
1498 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
1499 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
1503 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1504 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1506 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1511 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1512 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1514 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1519 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1520 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1522 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1527 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1528 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1530 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1536 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
1539 mParentLayerComboBox->addItem( initialParent, initialParent );
1540 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1543 vlayout->addWidget( mParentLayerComboBox );
1545 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1546 mMinLineEdit =
new QLineEdit();
1547 vlayout->addWidget( mMinLineEdit );
1549 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1550 mMaxLineEdit =
new QLineEdit();
1551 vlayout->addWidget( mMaxLineEdit );
1553 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1554 mDefaultLineEdit =
new QLineEdit();
1555 vlayout->addWidget( mDefaultLineEdit );
1559 mMinLineEdit->setText( QLocale().toString( volumeParam->minimum() ) );
1560 mMaxLineEdit->setText( QLocale().toString( volumeParam->maximum() ) );
1561 mDefaultLineEdit->setText( volumeParam->defaultValueForGui().toString() );
1569 setLayout( vlayout );
1577 auto param = std::make_unique<QgsProcessingParameterVolume>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1582 param->setMinimum( val );
1588 param->setMaximum( val );
1591 param->setFlags( flags );
1592 return param.release();
1601 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1604QString QgsProcessingVolumeWidgetWrapper::parameterType()
const
1611 return new QgsProcessingVolumeWidgetWrapper( parameter, type );
1614QWidget *QgsProcessingVolumeWidgetWrapper::createWidget()
1618 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1623 mLabel =
new QLabel();
1624 mUnitsCombo =
new QComboBox();
1637 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1638 QHBoxLayout *layout =
new QHBoxLayout();
1639 layout->addWidget( spin, 1 );
1640 layout->insertSpacing( 1, labelMargin / 2 );
1641 layout->insertWidget( 2, mLabel );
1642 layout->insertWidget( 3, mUnitsCombo );
1647 mWarningLabel =
new QWidget();
1648 QHBoxLayout *warningLayout =
new QHBoxLayout();
1649 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1650 QLabel *warning =
new QLabel();
1652 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1653 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1654 warning->setToolTip( tr(
"Volume is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1655 warningLayout->insertSpacing( 0, labelMargin / 2 );
1656 warningLayout->insertWidget( 1, warning );
1657 mWarningLabel->setLayout( warningLayout );
1658 layout->insertWidget( 4, mWarningLabel );
1660 QWidget *w =
new QWidget();
1661 layout->setContentsMargins( 0, 0, 0, 0 );
1662 w->setLayout( layout );
1676void QgsProcessingVolumeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1678 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1707 std::unique_ptr<QgsProcessingContext> tmpContext;
1708 if ( mProcessingContextGenerator )
1709 context = mProcessingContextGenerator->processingContext();
1713 tmpContext = std::make_unique<QgsProcessingContext>();
1714 context = tmpContext.get();
1721 units = QgsUnitTypes::distanceToVolumeUnit( crs.mapUnits() );
1732 mUnitsCombo->hide();
1737 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QVariant::fromValue( units ) ) );
1738 mUnitsCombo->show();
1745QVariant QgsProcessingVolumeWidgetWrapper::widgetValue()
const
1747 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1748 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1763 return new QgsProcessingVolumeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1771QgsProcessingDurationParameterDefinitionWidget::QgsProcessingDurationParameterDefinitionWidget(
1776 QVBoxLayout *vlayout =
new QVBoxLayout();
1777 vlayout->setContentsMargins( 0, 0, 0, 0 );
1779 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1780 mMinLineEdit =
new QLineEdit();
1781 vlayout->addWidget( mMinLineEdit );
1783 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1784 mMaxLineEdit =
new QLineEdit();
1785 vlayout->addWidget( mMaxLineEdit );
1787 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1788 mDefaultLineEdit =
new QLineEdit();
1789 vlayout->addWidget( mDefaultLineEdit );
1791 vlayout->addWidget(
new QLabel( tr(
"Default unit type" ) ) );
1793 mUnitsCombo =
new QComboBox();
1803 vlayout->addWidget( mUnitsCombo );
1809 mMinLineEdit->setText( QLocale().toString( durationParam->minimum() ) );
1810 mMaxLineEdit->setText( QLocale().toString( durationParam->maximum() ) );
1811 mDefaultLineEdit->setText( durationParam->defaultValueForGui().toString() );
1812 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( durationParam->defaultUnit() ) ) );
1818 setLayout( vlayout );
1826 auto param = std::make_unique<QgsProcessingParameterDuration>( name, description, ok ? val : QVariant() );
1831 param->setMinimum( val );
1837 param->setMaximum( val );
1840 param->setDefaultUnit(
static_cast<Qgis::TemporalUnit>( mUnitsCombo->currentData().toInt() ) );
1842 param->setFlags( flags );
1843 return param.release();
1847 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1850QString QgsProcessingDurationWidgetWrapper::parameterType()
const
1857 return new QgsProcessingDurationWidgetWrapper( parameter, type );
1860QWidget *QgsProcessingDurationWidgetWrapper::createWidget()
1864 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1869 mUnitsCombo =
new QComboBox();
1881 QHBoxLayout *layout =
new QHBoxLayout();
1882 layout->addWidget( spin, 1 );
1883 layout->insertWidget( 1, mUnitsCombo );
1885 QWidget *w =
new QWidget();
1886 layout->setContentsMargins( 0, 0, 0, 0 );
1887 w->setLayout( layout );
1889 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( durationDef->
defaultUnit() ) ) );
1890 mUnitsCombo->show();
1902QLabel *QgsProcessingDurationWidgetWrapper::createLabel()
1914QVariant QgsProcessingDurationWidgetWrapper::widgetValue()
const
1916 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1917 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo )
1928void QgsProcessingDurationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1934 QgsProcessingNumericWidgetWrapper::setWidgetValue( val, context );
1938 QgsProcessingNumericWidgetWrapper::setWidgetValue( value, context );
1946 return new QgsProcessingDurationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1953QgsProcessingScaleParameterDefinitionWidget::QgsProcessingScaleParameterDefinitionWidget(
1958 QVBoxLayout *vlayout =
new QVBoxLayout();
1959 vlayout->setContentsMargins( 0, 0, 0, 0 );
1961 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1963 mDefaultLineEdit =
new QLineEdit();
1967 mDefaultLineEdit->setText( scaleParam->defaultValueForGui().toString() );
1970 vlayout->addWidget( mDefaultLineEdit );
1973 setLayout( vlayout );
1979 double val = mDefaultLineEdit->text().toDouble( &ok );
1980 auto param = std::make_unique<QgsProcessingParameterScale>( name, description, ok ? val : QVariant() );
1981 param->setFlags( flags );
1982 return param.release();
1986 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1989QString QgsProcessingScaleWidgetWrapper::parameterType()
const
1996 return new QgsProcessingScaleWidgetWrapper( parameter, type );
1999QWidget *QgsProcessingScaleWidgetWrapper::createWidget()
2011 mScaleWidget->setAllowNull(
true );
2013 mScaleWidget->setMapCanvas( widgetContext().mapCanvas() );
2014 mScaleWidget->setShowCurrentScaleButton(
true );
2016 mScaleWidget->setToolTip( parameterDefinition()->toolTip() );
2018 return mScaleWidget;
2027 mScaleWidget->setMapCanvas( context.
mapCanvas() );
2032QVariant QgsProcessingScaleWidgetWrapper::widgetValue()
const
2034 return mScaleWidget && !mScaleWidget->isNull() ? QVariant( mScaleWidget->scale() ) : QVariant();
2037void QgsProcessingScaleWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2041 if ( mScaleWidget->allowNull() && !value.isValid() )
2042 mScaleWidget->setNull();
2046 mScaleWidget->setScale( v );
2055 return new QgsProcessingScaleParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2063QgsProcessingRangeParameterDefinitionWidget::QgsProcessingRangeParameterDefinitionWidget(
2068 QVBoxLayout *vlayout =
new QVBoxLayout();
2069 vlayout->setContentsMargins( 0, 0, 0, 0 );
2071 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
2073 mTypeComboBox =
new QComboBox();
2076 vlayout->addWidget( mTypeComboBox );
2078 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
2079 mMinLineEdit =
new QLineEdit();
2080 vlayout->addWidget( mMinLineEdit );
2082 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
2083 mMaxLineEdit =
new QLineEdit();
2084 vlayout->addWidget( mMaxLineEdit );
2088 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( rangeParam->dataType() ) ) );
2090 mMinLineEdit->setText( QLocale().toString( range.at( 0 ) ) );
2091 mMaxLineEdit->setText( QLocale().toString( range.at( 1 ) ) );
2098 setLayout( vlayout );
2103 QString defaultValue;
2104 if ( mMinLineEdit->text().isEmpty() )
2106 defaultValue = u
"None"_s;
2114 defaultValue = u
"None"_s;
2118 if ( mMaxLineEdit->text().isEmpty() )
2120 defaultValue +=
",None"_L1;
2126 defaultValue += u
",%1"_s.arg( ok ? QString::number( val ) :
"None"_L1 );
2130 auto param = std::make_unique<QgsProcessingParameterRange>( name, description, dataType, defaultValue );
2131 param->setFlags( flags );
2132 return param.release();
2140QWidget *QgsProcessingRangeWidgetWrapper::createWidget()
2149 QHBoxLayout *layout =
new QHBoxLayout();
2154 mMinSpinBox->setExpressionsEnabled(
true );
2155 mMinSpinBox->setShowClearButton(
false );
2156 mMaxSpinBox->setExpressionsEnabled(
true );
2157 mMaxSpinBox->setShowClearButton(
false );
2159 QLabel *minLabel =
new QLabel( tr(
"Min" ) );
2160 layout->addWidget( minLabel );
2161 layout->addWidget( mMinSpinBox, 1 );
2163 QLabel *maxLabel =
new QLabel( tr(
"Max" ) );
2164 layout->addWidget( maxLabel );
2165 layout->addWidget( mMaxSpinBox, 1 );
2167 QWidget *w =
new QWidget();
2168 layout->setContentsMargins( 0, 0, 0, 0 );
2169 w->setLayout( layout );
2173 mMinSpinBox->setDecimals( 6 );
2174 mMaxSpinBox->setDecimals( 6 );
2178 mMinSpinBox->setDecimals( 0 );
2179 mMaxSpinBox->setDecimals( 0 );
2182 mMinSpinBox->setMinimum( -99999999.999999 );
2183 mMaxSpinBox->setMinimum( -99999999.999999 );
2184 mMinSpinBox->setMaximum( 99999999.999999 );
2185 mMaxSpinBox->setMaximum( 99999999.999999 );
2189 mAllowingNull =
true;
2191 const double min = mMinSpinBox->minimum() - 1;
2192 mMinSpinBox->setMinimum( min );
2193 mMaxSpinBox->setMinimum( min );
2194 mMinSpinBox->setValue( min );
2195 mMaxSpinBox->setValue( min );
2197 mMinSpinBox->setShowClearButton(
true );
2198 mMaxSpinBox->setShowClearButton(
true );
2199 mMinSpinBox->setSpecialValueText( tr(
"Not set" ) );
2200 mMaxSpinBox->setSpecialValueText( tr(
"Not set" ) );
2203 w->setToolTip( parameterDefinition()->toolTip() );
2205 connect( mMinSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this](
const double v ) {
2206 mBlockChangedSignal++;
2207 if ( !mAllowingNull && v > mMaxSpinBox->value() )
2208 mMaxSpinBox->setValue( v );
2209 mBlockChangedSignal--;
2211 if ( !mBlockChangedSignal )
2212 emit widgetValueHasChanged(
this );
2214 connect( mMaxSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this](
const double v ) {
2215 mBlockChangedSignal++;
2216 if ( !mAllowingNull && v < mMinSpinBox->value() )
2217 mMinSpinBox->setValue( v );
2218 mBlockChangedSignal--;
2220 if ( !mBlockChangedSignal )
2221 emit widgetValueHasChanged(
this );
2230void QgsProcessingRangeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2233 if ( mAllowingNull && v.empty() )
2235 mMinSpinBox->clear();
2236 mMaxSpinBox->clear();
2243 if ( mAllowingNull )
2245 mBlockChangedSignal++;
2246 if ( std::isnan( v.at( 0 ) ) )
2247 mMinSpinBox->clear();
2249 mMinSpinBox->setValue( v.at( 0 ) );
2251 if ( v.count() >= 2 )
2253 if ( std::isnan( v.at( 1 ) ) )
2254 mMaxSpinBox->clear();
2256 mMaxSpinBox->setValue( v.at( 1 ) );
2258 mBlockChangedSignal--;
2262 mBlockChangedSignal++;
2263 mMinSpinBox->setValue( v.at( 0 ) );
2264 if ( v.count() >= 2 )
2265 mMaxSpinBox->setValue( v.at( 1 ) );
2266 mBlockChangedSignal--;
2270 if ( !mBlockChangedSignal )
2271 emit widgetValueHasChanged(
this );
2274QVariant QgsProcessingRangeWidgetWrapper::widgetValue()
const
2276 if ( mAllowingNull )
2279 if (
qgsDoubleNear( mMinSpinBox->value(), mMinSpinBox->minimum() ) )
2282 value = QString::number( mMinSpinBox->value() );
2284 if (
qgsDoubleNear( mMaxSpinBox->value(), mMaxSpinBox->minimum() ) )
2285 value +=
",None"_L1;
2287 value += u
",%1"_s.arg( mMaxSpinBox->value() );
2292 return u
"%1,%2"_s.arg( mMinSpinBox->value() ).arg( mMaxSpinBox->value() );
2295QString QgsProcessingRangeWidgetWrapper::modelerExpressionFormatString()
const
2297 return tr(
"string as two comma delimited floats, e.g. '1,10'" );
2300QString QgsProcessingRangeWidgetWrapper::parameterType()
const
2307 return new QgsProcessingRangeWidgetWrapper( parameter, type );
2314 return new QgsProcessingRangeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2322QgsProcessingMatrixParameterDefinitionWidget::QgsProcessingMatrixParameterDefinitionWidget(
2327 QVBoxLayout *vlayout =
new QVBoxLayout();
2328 vlayout->setContentsMargins( 0, 0, 0, 0 );
2330 mMatrixWidget =
new QgsProcessingMatrixModelerWidget();
2333 mMatrixWidget->setValue( matrixParam->headers(), matrixParam->defaultValueForGui() );
2334 mMatrixWidget->setFixedRows( matrixParam->hasFixedNumberRows() );
2336 vlayout->addWidget( mMatrixWidget );
2340 setLayout( vlayout );
2345 auto param = std::make_unique<QgsProcessingParameterMatrix>( name, description, 1, mMatrixWidget->fixedRows(), mMatrixWidget->headers(), mMatrixWidget->value() );
2346 param->setFlags( flags );
2347 return param.release();
2355QWidget *QgsProcessingMatrixWidgetWrapper::createWidget()
2357 mMatrixWidget =
new QgsProcessingMatrixParameterPanel(
nullptr,
dynamic_cast<const QgsProcessingParameterMatrix *
>( parameterDefinition() ) );
2358 mMatrixWidget->setToolTip( parameterDefinition()->toolTip() );
2360 connect( mMatrixWidget, &QgsProcessingMatrixParameterPanel::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
2368 return mMatrixWidget;
2374void QgsProcessingMatrixWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2377 if ( mMatrixWidget )
2378 mMatrixWidget->setValue( v );
2381QVariant QgsProcessingMatrixWidgetWrapper::widgetValue()
const
2383 if ( mMatrixWidget )
2384 return mMatrixWidget->value().isEmpty() ? QVariant() : mMatrixWidget->value();
2389QString QgsProcessingMatrixWidgetWrapper::modelerExpressionFormatString()
const
2391 return tr(
"comma delimited string of values, or an array of values" );
2394QString QgsProcessingMatrixWidgetWrapper::parameterType()
const
2401 return new QgsProcessingMatrixWidgetWrapper( parameter, type );
2408 return new QgsProcessingMatrixParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2417QgsProcessingFileParameterDefinitionWidget::QgsProcessingFileParameterDefinitionWidget(
2422 QVBoxLayout *vlayout =
new QVBoxLayout();
2423 vlayout->setContentsMargins( 0, 0, 0, 0 );
2425 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
2427 mTypeComboBox =
new QComboBox();
2431 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( fileParam->behavior() ) ) );
2433 mTypeComboBox->setCurrentIndex( 0 );
2434 vlayout->addWidget( mTypeComboBox );
2438 vlayout->addWidget(
new QLabel( tr(
"File filter" ) ) );
2440 mFilterComboBox =
new QComboBox();
2441 mFilterComboBox->setEditable(
true );
2443 mFilterComboBox->addItem( tr(
"All Files (*.*)" ) );
2444 mFilterComboBox->addItem( tr(
"CSV Files (*.csv)" ) );
2445 mFilterComboBox->addItem( tr(
"HTML Files (*.html *.htm)" ) );
2446 mFilterComboBox->addItem( tr(
"Text Files (*.txt)" ) );
2448 mFilterComboBox->setCurrentText( fileParam->fileFilter() );
2450 mFilterComboBox->setCurrentIndex( 0 );
2451 vlayout->addWidget( mFilterComboBox );
2455 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2458 mDefaultFileWidget->lineEdit()->setShowClearButton(
true );
2462 mDefaultFileWidget->setFilePath( fileParam->defaultValueForGui().toString() );
2466 vlayout->addWidget( mDefaultFileWidget );
2469 connect( mTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this] {
2477 setLayout( vlayout );
2482 auto param = std::make_unique<QgsProcessingParameterFile>( name, description );
2485 param->setFileFilter( mFilterComboBox->currentText() );
2486 if ( !mDefaultFileWidget->filePath().isEmpty() )
2487 param->setDefaultValue( mDefaultFileWidget->filePath() );
2488 param->setFlags( flags );
2489 return param.release();
2497QWidget *QgsProcessingFileWidgetWrapper::createWidget()
2510 mFileWidget->setToolTip( parameterDefinition()->toolTip() );
2511 mFileWidget->setDialogTitle( parameterDefinition()->description() );
2513 mFileWidget->setDefaultRoot(
QgsSettings().value( u
"/Processing/LastInputPath"_s, QDir::homePath() ).toString() );
2520 mFileWidget->setFilter( fileParam->
fileFilter() );
2521 else if ( !fileParam->
extension().isEmpty() )
2522 mFileWidget->setFilter( tr(
"%1 files" ).arg( fileParam->
extension().toUpper() ) + u
" (*."_s + fileParam->
extension().toLower() +
')' );
2531 QgsSettings().
setValue( u
"/Processing/LastInputPath"_s, QFileInfo( path ).canonicalPath() );
2532 emit widgetValueHasChanged(
this );
2540void QgsProcessingFileWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2544 mFileWidget->setFilePath( v );
2547QVariant QgsProcessingFileWidgetWrapper::widgetValue()
const
2550 return mFileWidget->filePath();
2555QString QgsProcessingFileWidgetWrapper::modelerExpressionFormatString()
const
2557 return tr(
"string representing a path to a file or folder" );
2560QString QgsProcessingFileWidgetWrapper::parameterType()
const
2567 return new QgsProcessingFileWidgetWrapper( parameter, type );
2574 return new QgsProcessingFileParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2582QgsProcessingExpressionParameterDefinitionWidget::QgsProcessingExpressionParameterDefinitionWidget(
2587 QVBoxLayout *vlayout =
new QVBoxLayout();
2588 vlayout->setContentsMargins( 0, 0, 0, 0 );
2589 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2592 mDefaultQgisLineEdit->registerExpressionContextGenerator(
this );
2594 mDefaultPointCloudLineEdit =
new QgsProcessingPointCloudExpressionLineEdit();
2595 mDefaultRasterCalculatorLineEdit =
new QgsProcessingRasterCalculatorExpressionLineEdit();
2597 QStackedWidget *stackedWidget =
new QStackedWidget();
2598 stackedWidget->addWidget( mDefaultQgisLineEdit );
2599 stackedWidget->addWidget( mDefaultPointCloudLineEdit );
2600 stackedWidget->addWidget( mDefaultRasterCalculatorLineEdit );
2601 vlayout->addWidget( stackedWidget );
2610 mDefaultQgisLineEdit->setExpression( expr );
2611 mDefaultPointCloudLineEdit->setExpression( expr );
2614 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
2616 mParentLayerComboBox =
new QComboBox();
2617 vlayout->addWidget( mParentLayerComboBox );
2619 vlayout->addWidget(
new QLabel( tr(
"Expression type" ) ) );
2620 mExpressionTypeComboBox =
new QComboBox();
2625 connect( mExpressionTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [
this, stackedWidget, definition, widgetContext](
int ) {
2626 mParentLayerComboBox->clear();
2627 mParentLayerComboBox->addItem( tr(
"None" ), QVariant() );
2629 stackedWidget->setCurrentIndex( mExpressionTypeComboBox->currentIndex() > 0 ? mExpressionTypeComboBox->currentIndex() : 0 );
2631 QString initialParent;
2633 initialParent = expParam->parentLayerParameterName();
2637 if ( QgsProcessingModelAlgorithm *model = widgetContext.
model() )
2640 const QMap<QString, QgsProcessingModelParameter> components = model->parameterComponents();
2641 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
2648 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2649 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2651 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2656 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2657 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2659 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2666 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2667 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2669 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2680 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2681 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2683 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2691 if ( mParentLayerComboBox->count() == 1 && !initialParent.isEmpty() )
2694 mParentLayerComboBox->addItem( initialParent, initialParent );
2695 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2699 mExpressionTypeComboBox->setCurrentIndex( -1 );
2701 mExpressionTypeComboBox->setCurrentIndex( mExpressionTypeComboBox->findData(
static_cast<int>( expParam->expressionType() ) ) );
2703 mExpressionTypeComboBox->setCurrentIndex( 0 );
2705 vlayout->addWidget( mExpressionTypeComboBox );
2710 setLayout( vlayout );
2717 switch ( expressionType )
2720 expression = mDefaultQgisLineEdit->expression();
2723 expression = mDefaultPointCloudLineEdit->expression();
2726 expression = mDefaultRasterCalculatorLineEdit->expression();
2729 auto param = std::make_unique<QgsProcessingParameterExpression>( name, description, expression, mParentLayerComboBox->currentData().toString(),
false, expressionType );
2730 param->setFlags( flags );
2731 return param.release();
2738QWidget *QgsProcessingExpressionWidgetWrapper::createWidget()
2753 mExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2754 mExpLineEdit->setExpressionDialogTitle( parameterDefinition()->description() );
2755 mExpLineEdit->registerExpressionContextGenerator(
this );
2757 return mExpLineEdit;
2763 mPointCloudExpLineEdit =
new QgsProcessingPointCloudExpressionLineEdit();
2764 mPointCloudExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2765 connect( mPointCloudExpLineEdit, &QgsProcessingPointCloudExpressionLineEdit::expressionChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
2766 return mPointCloudExpLineEdit;
2771 mRasterCalculatorExpLineEdit =
new QgsProcessingRasterCalculatorExpressionLineEdit();
2772 mRasterCalculatorExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2775 mRasterCalculatorExpLineEdit->setLayers( QVariantList() <<
"A" <<
"B" <<
"C" <<
"D" <<
"E" <<
"F" <<
"G" );
2777 connect( mRasterCalculatorExpLineEdit, &QgsProcessingRasterCalculatorExpressionLineEdit::expressionChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
2778 return mRasterCalculatorExpLineEdit;
2782 if ( expParam->
metadata().value( u
"inlineEditor"_s ).toBool() )
2785 mExpBuilderWidget->setToolTip( parameterDefinition()->toolTip() );
2786 mExpBuilderWidget->init( createExpressionContext() );
2788 Q_UNUSED( changed );
2789 emit widgetValueHasChanged(
this );
2791 return mExpBuilderWidget;
2796 mFieldExpWidget->setToolTip( parameterDefinition()->toolTip() );
2797 mFieldExpWidget->setExpressionDialogTitle( parameterDefinition()->description() );
2798 mFieldExpWidget->registerExpressionContextGenerator(
this );
2800 mFieldExpWidget->setAllowEmptyFieldName(
true );
2803 emit widgetValueHasChanged(
this );
2805 return mFieldExpWidget;
2813void QgsProcessingExpressionWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
2825 setParentLayerWrapperValue( wrapper );
2841 if ( mExpBuilderWidget )
2844 mExpBuilderWidget->setExpressionContext( createExpressionContext() );
2852 std::unique_ptr<QgsProcessingContext> tmpContext;
2853 if ( mProcessingContextGenerator )
2854 context = mProcessingContextGenerator->processingContext();
2858 tmpContext = std::make_unique<QgsProcessingContext>();
2859 context = tmpContext.get();
2872 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2882 if ( mFieldExpWidget )
2883 mFieldExpWidget->setLayer(
nullptr );
2884 else if ( mExpBuilderWidget )
2885 mExpBuilderWidget->setLayer(
nullptr );
2886 else if ( mExpLineEdit )
2887 mExpLineEdit->setLayer(
nullptr );
2893 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
2896 mParentLayer = std::move( ownedLayer );
2904 if ( mFieldExpWidget )
2905 mFieldExpWidget->setLayer( layer );
2906 if ( mExpBuilderWidget )
2907 mExpBuilderWidget->setLayer( layer );
2908 else if ( mExpLineEdit )
2909 mExpLineEdit->setLayer( layer );
2918 if ( mPointCloudExpLineEdit )
2919 mPointCloudExpLineEdit->setLayer(
nullptr );
2925 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
2928 mParentLayer = std::move( ownedLayer );
2936 if ( mPointCloudExpLineEdit )
2937 mPointCloudExpLineEdit->setLayer( layer );
2944 if ( layers.isEmpty() )
2946 if ( mRasterCalculatorExpLineEdit )
2948 mRasterCalculatorExpLineEdit->setLayers( val.userType() == QMetaType::Type::QVariantList ? val.toList() : QVariantList() << val );
2953 if ( mRasterCalculatorExpLineEdit )
2955 QVariantList layersList;
2958 layersList << layer->
name();
2960 mRasterCalculatorExpLineEdit->setLayers( layersList );
2968void QgsProcessingExpressionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2971 if ( mFieldExpWidget )
2972 mFieldExpWidget->setExpression( v );
2973 else if ( mExpBuilderWidget )
2974 mExpBuilderWidget->setExpressionText( v );
2975 else if ( mExpLineEdit )
2976 mExpLineEdit->setExpression( v );
2977 else if ( mPointCloudExpLineEdit )
2978 mPointCloudExpLineEdit->setExpression( v );
2979 else if ( mRasterCalculatorExpLineEdit )
2980 mRasterCalculatorExpLineEdit->setExpression( v );
2983QVariant QgsProcessingExpressionWidgetWrapper::widgetValue()
const
2985 if ( mFieldExpWidget )
2986 return mFieldExpWidget->expression();
2987 if ( mExpBuilderWidget )
2988 return mExpBuilderWidget->expressionText();
2989 else if ( mExpLineEdit )
2990 return mExpLineEdit->expression();
2991 else if ( mPointCloudExpLineEdit )
2992 return mPointCloudExpLineEdit->expression();
2993 else if ( mRasterCalculatorExpLineEdit )
2994 return mRasterCalculatorExpLineEdit->expression();
2999QString QgsProcessingExpressionWidgetWrapper::modelerExpressionFormatString()
const
3001 return tr(
"string representation of an expression" );
3004const QgsVectorLayer *QgsProcessingExpressionWidgetWrapper::linkedVectorLayer()
const
3006 if ( mFieldExpWidget && mFieldExpWidget->layer() )
3007 return mFieldExpWidget->layer();
3009 if ( mExpBuilderWidget && mExpBuilderWidget->layer() )
3010 return mExpBuilderWidget->layer();
3015QString QgsProcessingExpressionWidgetWrapper::parameterType()
const
3022 return new QgsProcessingExpressionWidgetWrapper( parameter, type );
3029 return new QgsProcessingExpressionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3041 QHBoxLayout *hl =
new QHBoxLayout();
3042 hl->setContentsMargins( 0, 0, 0, 0 );
3044 mLineEdit =
new QLineEdit();
3045 mLineEdit->setEnabled(
false );
3046 hl->addWidget( mLineEdit, 1 );
3048 mToolButton =
new QToolButton();
3049 mToolButton->setText( QString( QChar( 0x2026 ) ) );
3050 hl->addWidget( mToolButton );
3056 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
3059 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingEnumPanelWidget::showDialog );
3062void QgsProcessingEnumPanelWidget::setValue(
const QVariant &value )
3064 if ( value.isValid() )
3066 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
3068 if ( mParam->usesStaticStrings() && mValue.count() == 1 && mValue.at( 0 ).toString().isEmpty() )
3074 updateSummaryText();
3078void QgsProcessingEnumPanelWidget::showDialog()
3080 QVariantList availableOptions;
3083 availableOptions.reserve( mParam->options().size() );
3085 if ( mParam->usesStaticStrings() )
3087 for ( QString o : mParam->options() )
3089 availableOptions << o;
3094 for (
int i = 0; i < mParam->options().count(); ++i )
3095 availableOptions << i;
3099 const QStringList options = mParam ? mParam->options() : QStringList();
3103 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
3104 widget->setPanelTitle( mParam->description() );
3106 if ( mParam->usesStaticStrings() )
3108 widget->setValueFormatter( [options](
const QVariant &v ) -> QString {
3109 const QString i = v.toString();
3110 return options.contains( i ) ? i : QString();
3115 widget->setValueFormatter( [options](
const QVariant &v ) -> QString {
3116 const int i = v.toInt();
3117 return options.size() > i ? options.at( i ) : QString();
3121 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
3127 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
3129 dlg.setValueFormatter( [options](
const QVariant &v ) -> QString {
3130 const int i = v.toInt();
3131 return options.size() > i ? options.at( i ) : QString();
3135 setValue( dlg.selectedOptions() );
3140void QgsProcessingEnumPanelWidget::updateSummaryText()
3145 if ( mValue.empty() )
3147 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
3152 values.reserve( mValue.size() );
3153 if ( mParam->usesStaticStrings() )
3155 for (
const QVariant &val : std::as_const( mValue ) )
3157 values << val.toString();
3162 const QStringList options = mParam->options();
3163 for (
const QVariant &val : std::as_const( mValue ) )
3165 const int i = val.toInt();
3166 values << ( options.size() > i ? options.at( i ) : QString() );
3170 const QString concatenated = values.join( tr(
"," ) );
3171 if ( concatenated.length() < 100 )
3172 mLineEdit->setText( concatenated );
3174 mLineEdit->setText( tr(
"%n option(s) selected",
nullptr, mValue.count() ) );
3182QgsProcessingEnumCheckboxPanelWidget::QgsProcessingEnumCheckboxPanelWidget( QWidget *parent,
const QgsProcessingParameterEnum *param,
int columns )
3185 , mButtonGroup( new QButtonGroup( this ) )
3186 , mColumns( columns )
3188 mButtonGroup->setExclusive( !mParam->allowMultiple() );
3190 QGridLayout *l =
new QGridLayout();
3191 l->setContentsMargins( 0, 0, 0, 0 );
3193 int rows =
static_cast<int>( std::ceil( mParam->options().count() /
static_cast<double>( mColumns ) ) );
3194 for (
int i = 0; i < mParam->options().count(); ++i )
3196 QAbstractButton *button =
nullptr;
3197 if ( mParam->allowMultiple() )
3198 button =
new QCheckBox( mParam->options().at( i ) );
3200 button =
new QRadioButton( mParam->options().at( i ) );
3202 connect( button, &QAbstractButton::toggled,
this, [
this] {
3203 if ( !mBlockChangedSignal )
3207 mButtons.insert( i, button );
3209 mButtonGroup->addButton( button, i );
3210 l->addWidget( button, i % rows, i / rows );
3212 l->addItem(
new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, mColumns );
3215 if ( mParam->allowMultiple() )
3217 setContextMenuPolicy( Qt::CustomContextMenu );
3218 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsProcessingEnumCheckboxPanelWidget::showPopupMenu );
3222QVariant QgsProcessingEnumCheckboxPanelWidget::value()
const
3224 if ( mParam->allowMultiple() )
3227 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3229 if ( it.value()->isChecked() )
3230 value.append( mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key() );
3236 if ( mParam->usesStaticStrings() )
3237 return mButtonGroup->checkedId() >= 0 ? mParam->options().at( mButtonGroup->checkedId() ) : QVariant();
3239 return mButtonGroup->checkedId() >= 0 ? mButtonGroup->checkedId() : QVariant();
3243void QgsProcessingEnumCheckboxPanelWidget::setValue(
const QVariant &value )
3245 mBlockChangedSignal =
true;
3246 if ( mParam->allowMultiple() )
3248 QVariantList selected;
3249 if ( value.isValid() )
3250 selected = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
3251 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3253 QVariant v = mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key();
3254 it.value()->setChecked( selected.contains( v ) );
3260 if ( v.userType() == QMetaType::Type::QVariantList )
3261 v = v.toList().value( 0 );
3263 v = mParam->usesStaticStrings() ?
static_cast< int >( mParam->options().indexOf( v.toString() ) ) : v;
3264 if ( mButtons.contains( v ) )
3265 mButtons.value( v )->setChecked(
true );
3267 mBlockChangedSignal =
false;
3271void QgsProcessingEnumCheckboxPanelWidget::showPopupMenu()
3274 QAction *selectAllAction =
new QAction( tr(
"Select All" ), &popupMenu );
3275 connect( selectAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::selectAll );
3276 QAction *clearAllAction =
new QAction( tr(
"Clear Selection" ), &popupMenu );
3277 connect( clearAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::deselectAll );
3278 popupMenu.addAction( selectAllAction );
3279 popupMenu.addAction( clearAllAction );
3280 popupMenu.exec( QCursor::pos() );
3283void QgsProcessingEnumCheckboxPanelWidget::selectAll()
3285 mBlockChangedSignal =
true;
3286 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3287 it.value()->setChecked(
true );
3288 mBlockChangedSignal =
false;
3292void QgsProcessingEnumCheckboxPanelWidget::deselectAll()
3294 mBlockChangedSignal =
true;
3295 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3296 it.value()->setChecked(
false );
3297 mBlockChangedSignal =
false;
3306QgsProcessingEnumParameterDefinitionWidget::QgsProcessingEnumParameterDefinitionWidget(
3311 QVBoxLayout *vlayout =
new QVBoxLayout();
3312 vlayout->setContentsMargins( 0, 0, 0, 0 );
3314 mEnumWidget =
new QgsProcessingEnumModelerWidget();
3317 mEnumWidget->setAllowMultiple( enumParam->allowMultiple() );
3318 mEnumWidget->setOptions( enumParam->options() );
3319 mEnumWidget->setDefaultOptions( enumParam->defaultValueForGui() );
3321 vlayout->addWidget( mEnumWidget );
3325 setLayout( vlayout );
3330 auto param = std::make_unique<QgsProcessingParameterEnum>( name, description, mEnumWidget->options(), mEnumWidget->allowMultiple(), mEnumWidget->defaultOptions() );
3332 return param.release();
3340QWidget *QgsProcessingEnumWidgetWrapper::createWidget()
3351 if ( expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"useCheckBoxes"_s,
false ).toBool() )
3353 const int columns = expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"columns"_s, 2 ).toInt();
3354 mCheckboxPanel =
new QgsProcessingEnumCheckboxPanelWidget(
nullptr, expParam, columns );
3355 mCheckboxPanel->setToolTip( parameterDefinition()->toolTip() );
3356 connect( mCheckboxPanel, &QgsProcessingEnumCheckboxPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
3357 return mCheckboxPanel;
3366 mPanel =
new QgsProcessingEnumPanelWidget(
nullptr, expParam );
3367 mPanel->setToolTip( parameterDefinition()->toolTip() );
3368 connect( mPanel, &QgsProcessingEnumPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
3373 mComboBox =
new QComboBox();
3376 mComboBox->addItem( tr(
"[Not selected]" ), QVariant() );
3377 const QStringList options = expParam->
options();
3378 const QVariantList iconList = expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"icons"_s ).toList();
3379 for (
int i = 0; i < options.count(); ++i )
3381 const QIcon icon = iconList.value( i ).value<QIcon>();
3384 mComboBox->addItem( icon, options.at( i ), options.at( i ) );
3386 mComboBox->addItem( icon, options.at( i ), i );
3389 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3390 mComboBox->setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon );
3391 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
3399void QgsProcessingEnumWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3403 if ( !value.isValid() )
3404 mComboBox->setCurrentIndex( mComboBox->findData( QVariant() ) );
3410 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
3415 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
3419 else if ( mPanel || mCheckboxPanel )
3422 if ( value.isValid() )
3427 opts.reserve( v.size() );
3428 for ( QString i : v )
3434 opts.reserve( v.size() );
3440 mPanel->setValue( opts );
3441 else if ( mCheckboxPanel )
3442 mCheckboxPanel->setValue( opts );
3446QVariant QgsProcessingEnumWidgetWrapper::widgetValue()
const
3449 return mComboBox->currentData();
3451 return mPanel->value();
3452 else if ( mCheckboxPanel )
3453 return mCheckboxPanel->value();
3458QString QgsProcessingEnumWidgetWrapper::modelerExpressionFormatString()
const
3460 return tr(
"selected option index (starting from 0), array of indices, or comma separated string of options (e.g. '1,3')" );
3463QString QgsProcessingEnumWidgetWrapper::parameterType()
const
3470 return new QgsProcessingEnumWidgetWrapper( parameter, type );
3477 return new QgsProcessingEnumParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3488QWidget *QgsProcessingLayoutWidgetWrapper::createWidget()
3500 mComboBox =
new QgsLayoutComboBox(
nullptr, widgetContext().project() ? widgetContext().project()->layoutManager() :
nullptr );
3502 mComboBox->setAllowEmptyLayout(
true );
3505 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3512 mPlainComboBox =
new QComboBox();
3513 mPlainComboBox->setEditable(
true );
3514 mPlainComboBox->setToolTip( tr(
"Name of an existing print layout" ) );
3515 if ( widgetContext().project() )
3519 mPlainComboBox->addItem( layout->name() );
3522 connect( mPlainComboBox, &QComboBox::currentTextChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
3523 return mPlainComboBox;
3529void QgsProcessingLayoutWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3533 if ( !value.isValid() )
3534 mComboBox->setCurrentLayout(
nullptr );
3538 mComboBox->setCurrentLayout( l );
3540 mComboBox->setCurrentLayout(
nullptr );
3543 else if ( mPlainComboBox )
3546 mPlainComboBox->setCurrentText( v );
3550QVariant QgsProcessingLayoutWidgetWrapper::widgetValue()
const
3555 return l ? l->
name() : QVariant();
3557 else if ( mPlainComboBox )
3558 return mPlainComboBox->currentText().isEmpty() ? QVariant() : mPlainComboBox->currentText();
3566 if ( mPlainComboBox && context.
project() )
3570 mPlainComboBox->addItem( layout->name() );
3574QString QgsProcessingLayoutWidgetWrapper::modelerExpressionFormatString()
const
3576 return tr(
"string representing the name of an existing print layout" );
3579QString QgsProcessingLayoutWidgetWrapper::parameterType()
const
3586 return new QgsProcessingLayoutWidgetWrapper( parameter, type );
3595QgsProcessingLayoutItemParameterDefinitionWidget::QgsProcessingLayoutItemParameterDefinitionWidget(
3600 QVBoxLayout *vlayout =
new QVBoxLayout();
3601 vlayout->setContentsMargins( 0, 0, 0, 0 );
3603 vlayout->addWidget(
new QLabel( tr(
"Parent layout" ) ) );
3605 mParentLayoutComboBox =
new QComboBox();
3606 QString initialParent;
3608 initialParent = itemParam->parentLayoutParameterName();
3610 if (
auto *lModel = widgetContext.
model() )
3613 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3614 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3618 mParentLayoutComboBox->addItem( definition->
description(), definition->
name() );
3619 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
3621 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3627 if ( mParentLayoutComboBox->count() == 0 && !initialParent.isEmpty() )
3630 mParentLayoutComboBox->addItem( initialParent, initialParent );
3631 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3634 vlayout->addWidget( mParentLayoutComboBox );
3638 setLayout( vlayout );
3642 auto param = std::make_unique<QgsProcessingParameterLayoutItem>( name, description, QVariant(), mParentLayoutComboBox->currentData().toString() );
3644 return param.release();
3652QWidget *QgsProcessingLayoutItemWidgetWrapper::createWidget()
3666 mComboBox->setAllowEmptyItem(
true );
3667 if ( layoutParam->
itemType() >= 0 )
3670 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3677 mLineEdit =
new QLineEdit();
3678 mLineEdit->setToolTip( tr(
"UUID or ID of an existing print layout item" ) );
3679 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
3686void QgsProcessingLayoutItemWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3711void QgsProcessingLayoutItemWidgetWrapper::setLayoutParameterValue(
const QVariant &value )
3717 std::unique_ptr<QgsProcessingContext> tmpContext;
3718 if ( mProcessingContextGenerator )
3719 context = mProcessingContextGenerator->processingContext();
3723 tmpContext = std::make_unique<QgsProcessingContext>();
3724 context = tmpContext.get();
3728 setLayout( layout );
3731void QgsProcessingLayoutItemWidgetWrapper::setLayout(
QgsPrintLayout *layout )
3734 mComboBox->setCurrentLayout( layout );
3737void QgsProcessingLayoutItemWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3741 if ( !value.isValid() )
3742 mComboBox->setItem(
nullptr );
3746 mComboBox->setItem( item );
3749 else if ( mLineEdit )
3752 mLineEdit->setText( v );
3756QVariant QgsProcessingLayoutItemWidgetWrapper::widgetValue()
const
3761 return i ? i->
uuid() : QVariant();
3763 else if ( mLineEdit )
3764 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3770QString QgsProcessingLayoutItemWidgetWrapper::modelerExpressionFormatString()
const
3772 return tr(
"string representing the UUID or ID of an existing print layout item" );
3775QString QgsProcessingLayoutItemWidgetWrapper::parameterType()
const
3782 return new QgsProcessingLayoutItemWidgetWrapper( parameter, type );
3789 return new QgsProcessingLayoutItemParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3796QgsProcessingPointMapTool::QgsProcessingPointMapTool(
QgsMapCanvas *canvas )
3800 mSnapIndicator = std::make_unique<QgsSnapIndicator>( canvas );
3803QgsProcessingPointMapTool::~QgsProcessingPointMapTool() =
default;
3805void QgsProcessingPointMapTool::deactivate()
3819 if ( e->button() == Qt::LeftButton )
3822 emit clicked( point );
3827void QgsProcessingPointMapTool::keyPressEvent( QKeyEvent *e )
3829 if ( e->key() == Qt::Key_Escape )
3842QgsProcessingPointPanel::QgsProcessingPointPanel( QWidget *parent )
3845 QHBoxLayout *l =
new QHBoxLayout();
3846 l->setContentsMargins( 0, 0, 0, 0 );
3848 mLineEdit->setShowClearButton(
false );
3849 l->addWidget( mLineEdit, 1 );
3850 mButton =
new QToolButton();
3851 mButton->setText( QString( QChar( 0x2026 ) ) );
3852 l->addWidget( mButton );
3855 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::changed );
3856 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::textChanged );
3857 connect( mButton, &QToolButton::clicked,
this, &QgsProcessingPointPanel::selectOnCanvas );
3858 mButton->setVisible(
false );
3861QgsProcessingPointPanel::~QgsProcessingPointPanel()
3863 if ( mCanvas && mPrevTool && mCanvas->mapTool() == mTool.get() )
3865 mCanvas->setMapTool( mPrevTool.get() );
3869void QgsProcessingPointPanel::setMapCanvas(
QgsMapCanvas *canvas )
3872 if ( mAllowSelectOnCanvas )
3874 mButton->setVisible(
true );
3877 mTool = std::make_unique<QgsProcessingPointMapTool>( mCanvas );
3878 connect( mTool.get(), &QgsProcessingPointMapTool::clicked,
this, &QgsProcessingPointPanel::updatePoint );
3879 connect( mTool.get(), &QgsProcessingPointMapTool::complete,
this, &QgsProcessingPointPanel::pointPicked );
3883void QgsProcessingPointPanel::setAllowNull(
bool allowNull )
3885 mLineEdit->setShowClearButton( allowNull );
3888void QgsProcessingPointPanel::setShowPointOnCanvas(
bool show )
3890 if ( mShowPointOnCanvas == show )
3893 mShowPointOnCanvas = show;
3894 if ( mShowPointOnCanvas )
3900 mMapPointRubberBand.reset();
3904void QgsProcessingPointPanel::setAllowSelectOnCanvas(
bool allow )
3906 mAllowSelectOnCanvas = allow;
3907 mButton->setVisible( mAllowSelectOnCanvas &&
static_cast<bool>( mTool ) );
3910QVariant QgsProcessingPointPanel::value()
const
3912 return mLineEdit->showClearButton() && mLineEdit->text().trimmed().isEmpty() ? QVariant() : QVariant( mLineEdit->text() );
3915void QgsProcessingPointPanel::clear()
3923 QString newText = u
"%1,%2"_s.arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) );
3926 if ( mCrs.isValid() )
3928 newText += u
" [%1]"_s.arg( mCrs.authid() );
3930 mLineEdit->setText( newText );
3934void QgsProcessingPointPanel::showEvent( QShowEvent * )
3939 if ( QWidget *parentWindow = window() )
3941 setAllowSelectOnCanvas( !parentWindow->isModal() );
3947void QgsProcessingPointPanel::selectOnCanvas()
3952 mPrevTool = mCanvas->mapTool();
3953 mCanvas->setMapTool( mTool.get() );
3955 emit toggleDialogVisibility(
false );
3958void QgsProcessingPointPanel::updatePoint(
const QgsPointXY &point )
3960 setValue( point, mCanvas->mapSettings().destinationCrs() );
3963void QgsProcessingPointPanel::pointPicked()
3968 mCanvas->setMapTool( mPrevTool );
3970 emit toggleDialogVisibility(
true );
3973void QgsProcessingPointPanel::textChanged(
const QString &text )
3975 const thread_local QRegularExpression rx( u
"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
3977 const QRegularExpressionMatch match = rx.match( text );
3978 if ( match.hasMatch() )
3981 const double x = match.captured( 1 ).toDouble( &xOk );
3983 const double y = match.captured( 2 ).toDouble( &yOk );
3990 if ( pointCrs.isValid() )
4008void QgsProcessingPointPanel::updateRubberBand()
4010 if ( !mShowPointOnCanvas || !mCanvas )
4013 if ( mPoint.isEmpty() )
4015 mMapPointRubberBand.reset();
4019 if ( !mMapPointRubberBand )
4022 mMapPointRubberBand->setZValue( 1000 );
4025 const double scaleFactor = mCanvas->fontMetrics().xHeight() * .4;
4026 mMapPointRubberBand->setWidth( scaleFactor );
4027 mMapPointRubberBand->setIconSize( scaleFactor * 5 );
4029 mMapPointRubberBand->setSecondaryStrokeColor( QColor( 255, 255, 255, 100 ) );
4030 mMapPointRubberBand->setColor( QColor( 200, 0, 200 ) );
4041QgsProcessingPointParameterDefinitionWidget::QgsProcessingPointParameterDefinitionWidget(
4046 QVBoxLayout *vlayout =
new QVBoxLayout();
4047 vlayout->setContentsMargins( 0, 0, 0, 0 );
4049 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4051 mDefaultLineEdit =
new QLineEdit();
4052 mDefaultLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
4053 mDefaultLineEdit->setPlaceholderText( tr(
"Point as 'x,y'" ) );
4057 mDefaultLineEdit->setText( u
"%1,%2"_s.arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) ) );
4060 vlayout->addWidget( mDefaultLineEdit );
4064 setLayout( vlayout );
4069 auto param = std::make_unique<QgsProcessingParameterPoint>( name, description, mDefaultLineEdit->text() );
4071 return param.release();
4078QWidget *QgsProcessingPointWidgetWrapper::createWidget()
4089 mPanel =
new QgsProcessingPointPanel(
nullptr );
4090 if ( widgetContext().mapCanvas() )
4091 mPanel->setMapCanvas( widgetContext().mapCanvas() );
4094 mPanel->setAllowNull(
true );
4097 mPanel->setShowPointOnCanvas(
true );
4099 mPanel->setToolTip( parameterDefinition()->toolTip() );
4101 connect( mPanel, &QgsProcessingPointPanel::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
4104 setDialog( mDialog );
4110 mLineEdit =
new QLineEdit();
4111 mLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
4112 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
4123 mPanel->setMapCanvas( context.
mapCanvas() );
4126void QgsProcessingPointWidgetWrapper::setDialog( QWidget *dialog )
4131 connect( mPanel, &QgsProcessingPointPanel::toggleDialogVisibility, mDialog, [
this](
bool visible ) {
4133 mDialog->showMinimized();
4136 mDialog->showNormal();
4138 mDialog->activateWindow();
4145void QgsProcessingPointWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4149 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) )
4155 mPanel->setValue( p, crs );
4158 else if ( mLineEdit )
4161 mLineEdit->setText( v );
4165QVariant QgsProcessingPointWidgetWrapper::widgetValue()
const
4169 return mPanel->value();
4171 else if ( mLineEdit )
4172 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
4177QString QgsProcessingPointWidgetWrapper::modelerExpressionFormatString()
const
4179 return tr(
"string of the format 'x,y' or a geometry value (centroid is used)" );
4182QString QgsProcessingPointWidgetWrapper::parameterType()
const
4189 return new QgsProcessingPointWidgetWrapper( parameter, type );
4196 return new QgsProcessingPointParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4205QgsProcessingGeometryParameterDefinitionWidget::QgsProcessingGeometryParameterDefinitionWidget(
4210 QVBoxLayout *vlayout =
new QVBoxLayout();
4211 vlayout->setContentsMargins( 0, 0, 0, 0 );
4213 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4225 vlayout->addWidget( mGeometryWidget );
4229 setLayout( vlayout );
4235 auto param = std::make_unique<QgsProcessingParameterGeometry>( name, description, geometry.
isEmpty() ? QVariant() : geometry.
asWkt() );
4237 return param.release();
4244QWidget *QgsProcessingGeometryWidgetWrapper::createWidget()
4253 mGeometryWidget->setToolTip( parameterDefinition()->toolTip() );
4255 return mGeometryWidget;
4261void QgsProcessingGeometryWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4263 if ( mGeometryWidget )
4272 mGeometryWidget->clearGeometry();
4277QVariant QgsProcessingGeometryWidgetWrapper::widgetValue()
const
4279 if ( mGeometryWidget )
4282 return geometry.
isEmpty() ? QVariant() : geometry.asWkt();
4290QString QgsProcessingGeometryWidgetWrapper::modelerExpressionFormatString()
const
4292 return tr(
"string in the Well-Known-Text format or a geometry value" );
4295QString QgsProcessingGeometryWidgetWrapper::parameterType()
const
4302 return new QgsProcessingGeometryWidgetWrapper( parameter, type );
4309 return new QgsProcessingGeometryParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4318QgsProcessingColorParameterDefinitionWidget::QgsProcessingColorParameterDefinitionWidget(
4323 QVBoxLayout *vlayout =
new QVBoxLayout();
4324 vlayout->setContentsMargins( 0, 0, 0, 0 );
4326 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4329 mDefaultColorButton->setShowNull(
true );
4330 mAllowOpacity =
new QCheckBox( tr(
"Allow opacity control" ) );
4336 mDefaultColorButton->setToNull();
4338 mDefaultColorButton->setColor(
c );
4339 mAllowOpacity->setChecked( colorParam->opacityEnabled() );
4343 mDefaultColorButton->setToNull();
4344 mAllowOpacity->setChecked(
true );
4350 vlayout->addWidget( mDefaultColorButton );
4351 vlayout->addWidget( mAllowOpacity );
4352 setLayout( vlayout );
4357 auto param = std::make_unique<QgsProcessingParameterColor>( name, description, mDefaultColorButton->color(), mAllowOpacity->isChecked() );
4359 return param.release();
4366QWidget *QgsProcessingColorWidgetWrapper::createWidget()
4379 mColorButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
4382 mColorButton->setShowNull(
true );
4385 mColorButton->setToolTip( parameterDefinition()->toolTip() );
4386 mColorButton->setColorDialogTitle( parameterDefinition()->description() );
4394 return mColorButton;
4400void QgsProcessingColorWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4404 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) || ( value.userType() == QMetaType::Type::QColor && !value.value<QColor>().isValid() ) )
4405 mColorButton->setToNull();
4409 if ( !
c.isValid() && mColorButton->showNull() )
4410 mColorButton->setToNull();
4412 mColorButton->setColor(
c );
4417QVariant QgsProcessingColorWidgetWrapper::widgetValue()
const
4420 return mColorButton->isNull() ? QVariant() : mColorButton->color();
4425QString QgsProcessingColorWidgetWrapper::modelerExpressionFormatString()
const
4427 return tr(
"color style string, e.g. #ff0000 or 255,0,0" );
4430QString QgsProcessingColorWidgetWrapper::parameterType()
const
4437 return new QgsProcessingColorWidgetWrapper( parameter, type );
4444 return new QgsProcessingColorParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4452QgsProcessingCoordinateOperationParameterDefinitionWidget::QgsProcessingCoordinateOperationParameterDefinitionWidget(
4457 QVBoxLayout *vlayout =
new QVBoxLayout();
4458 vlayout->setContentsMargins( 0, 0, 0, 0 );
4460 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4462 mDefaultLineEdit =
new QLineEdit();
4465 vlayout->addWidget( mDefaultLineEdit );
4469 mSourceParamComboBox =
new QComboBox();
4470 mDestParamComboBox =
new QComboBox();
4471 QString initialSource;
4472 QString initialDest;
4477 initialSource = itemParam->sourceCrsParameterName();
4478 initialDest = itemParam->destinationCrsParameterName();
4483 mSourceParamComboBox->addItem( QString(), QString() );
4484 mDestParamComboBox->addItem( QString(), QString() );
4485 if (
auto *lModel = widgetContext.
model() )
4488 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4489 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4491 if ( definition && it->parameterName() == definition->
name() )
4495 mSourceParamComboBox->addItem( it->parameterName(), it->parameterName() );
4496 mDestParamComboBox->addItem( it->parameterName(), it->parameterName() );
4497 if ( !initialSource.isEmpty() && initialSource == it->parameterName() )
4499 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
4501 if ( !initialDest.isEmpty() && initialDest == it->parameterName() )
4503 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
4508 if ( mSourceParamComboBox->count() == 1 && !initialSource.isEmpty() )
4511 mSourceParamComboBox->addItem( initialSource, initialSource );
4512 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
4514 if ( mDestParamComboBox->count() == 1 && !initialDest.isEmpty() )
4517 mDestParamComboBox->addItem( initialDest, initialDest );
4518 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
4521 vlayout->addWidget(
new QLabel( tr(
"Source CRS parameter" ) ) );
4522 vlayout->addWidget( mSourceParamComboBox );
4523 vlayout->addWidget(
new QLabel( tr(
"Destination CRS parameter" ) ) );
4524 vlayout->addWidget( mDestParamComboBox );
4531 mStaticSourceWidget->setCrs( sourceCrs );
4534 mStaticDestWidget->setCrs( destCrs );
4536 vlayout->addWidget(
new QLabel( tr(
"Static source CRS" ) ) );
4537 vlayout->addWidget( mStaticSourceWidget );
4538 vlayout->addWidget(
new QLabel( tr(
"Static destination CRS" ) ) );
4539 vlayout->addWidget( mStaticDestWidget );
4544 setLayout( vlayout );
4549 auto param = std::make_unique<QgsProcessingParameterCoordinateOperation>(
4552 mDefaultLineEdit->text(),
4553 mSourceParamComboBox->currentText(),
4554 mDestParamComboBox->currentText(),
4555 mStaticSourceWidget->crs().isValid() ? QVariant::fromValue( mStaticSourceWidget->crs() ) : QVariant(),
4556 mStaticDestWidget->crs().isValid() ? QVariant::fromValue( mStaticDestWidget->crs() ) : QVariant()
4559 return param.release();
4566QWidget *QgsProcessingCoordinateOperationWidgetWrapper::createWidget()
4580 mOperationWidget->setShowMakeDefault(
false );
4581 mOperationWidget->setShowFallbackOption(
false );
4582 mOperationWidget->setToolTip( parameterDefinition()->toolTip() );
4583 mOperationWidget->setSourceCrs( mSourceCrs );
4584 mOperationWidget->setDestinationCrs( mDestCrs );
4585 mOperationWidget->setMapCanvas( mCanvas );
4590 mOperationWidget->setSelectedOperation( deets );
4595 return mOperationWidget;
4601 mLineEdit =
new QLineEdit();
4602 QHBoxLayout *layout =
new QHBoxLayout();
4603 layout->addWidget( mLineEdit, 1 );
4604 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
4606 QToolButton *button =
new QToolButton();
4607 button->setText( QString( QChar( 0x2026 ) ) );
4608 connect( button, &QToolButton::clicked,
this, [
this, button] {
4609 QgsDatumTransformDialog dlg( mSourceCrs, mDestCrs,
false,
false,
false, qMakePair( -1, -1 ), button, Qt::WindowFlags(), mLineEdit->text(), mCanvas );
4612 mLineEdit->setText( dlg.selectedDatumTransform().proj );
4613 emit widgetValueHasChanged(
this );
4616 layout->addWidget( button );
4618 QWidget *w =
new QWidget();
4619 layout->setContentsMargins( 0, 0, 0, 0 );
4620 w->setLayout( layout );
4627void QgsProcessingCoordinateOperationWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
4659 if ( mOperationWidget )
4660 mOperationWidget->setMapCanvas( context.
mapCanvas() );
4663void QgsProcessingCoordinateOperationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
4665 if ( mOperationWidget )
4667 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString ) )
4670 deets.
proj = value.toString();
4671 mOperationWidget->setSelectedOperation( deets );
4676 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString ) )
4678 mLineEdit->setText( value.toString() );
4683QVariant QgsProcessingCoordinateOperationWidgetWrapper::widgetValue()
const
4685 if ( mOperationWidget )
4686 return mOperationWidget->selectedOperation().proj;
4687 else if ( mLineEdit )
4688 return mLineEdit->text();
4693QString QgsProcessingCoordinateOperationWidgetWrapper::modelerExpressionFormatString()
const
4695 return tr(
"Proj coordinate operation string, e.g. '+proj=pipeline +step +inv...'" );
4698void QgsProcessingCoordinateOperationWidgetWrapper::setSourceCrsParameterValue(
const QVariant &value )
4701 std::unique_ptr<QgsProcessingContext> tmpContext;
4702 if ( mProcessingContextGenerator )
4703 context = mProcessingContextGenerator->processingContext();
4707 tmpContext = std::make_unique<QgsProcessingContext>();
4708 context = tmpContext.get();
4712 if ( mOperationWidget )
4714 mOperationWidget->setSourceCrs( mSourceCrs );
4715 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4719void QgsProcessingCoordinateOperationWidgetWrapper::setDestinationCrsParameterValue(
const QVariant &value )
4722 std::unique_ptr<QgsProcessingContext> tmpContext;
4723 if ( mProcessingContextGenerator )
4724 context = mProcessingContextGenerator->processingContext();
4728 tmpContext = std::make_unique<QgsProcessingContext>();
4729 context = tmpContext.get();
4733 if ( mOperationWidget )
4735 mOperationWidget->setDestinationCrs( mDestCrs );
4736 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4740QString QgsProcessingCoordinateOperationWidgetWrapper::parameterType()
const
4747 return new QgsProcessingCoordinateOperationWidgetWrapper( parameter, type );
4754 return new QgsProcessingCoordinateOperationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4766 QHBoxLayout *hl =
new QHBoxLayout();
4767 hl->setContentsMargins( 0, 0, 0, 0 );
4769 mLineEdit =
new QLineEdit();
4770 mLineEdit->setEnabled(
false );
4771 hl->addWidget( mLineEdit, 1 );
4773 mToolButton =
new QToolButton();
4774 mToolButton->setText( QString( QChar( 0x2026 ) ) );
4775 hl->addWidget( mToolButton );
4781 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4784 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingFieldPanelWidget::showDialog );
4787void QgsProcessingFieldPanelWidget::setFields(
const QgsFields &fields )
4793 QVariantList availableFields;
4794 for (
const QgsField &field : std::as_const( mFields ) )
4796 availableFields << field.name();
4798 QList<QVariant>::iterator it = std::remove_if( mValue.begin(), mValue.end(), [&availableFields](
const QVariant &value ) { return !availableFields.contains( value ); } );
4799 mValue.erase( it, mValue.end() );
4801 updateSummaryText();
4805void QgsProcessingFieldPanelWidget::setValue(
const QVariant &value )
4807 if ( value.isValid() )
4808 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
4812 updateSummaryText();
4816void QgsProcessingFieldPanelWidget::showDialog()
4818 QVariantList availableOptions;
4819 availableOptions.reserve( mFields.size() );
4820 for (
const QgsField &field : std::as_const( mFields ) )
4822 availableOptions << field.name();
4828 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
4829 widget->setPanelTitle( mParam->description() );
4831 widget->setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
4833 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
4839 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
4841 dlg.setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
4844 setValue( dlg.selectedOptions() );
4849void QgsProcessingFieldPanelWidget::updateSummaryText()
4854 if ( mValue.empty() )
4856 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4861 values.reserve( mValue.size() );
4862 for (
const QVariant &val : std::as_const( mValue ) )
4864 values << val.toString();
4867 const QString concatenated = values.join( tr(
"," ) );
4868 if ( concatenated.length() < 100 )
4869 mLineEdit->setText( concatenated );
4871 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, mValue.count() ) );
4880QgsProcessingFieldParameterDefinitionWidget::QgsProcessingFieldParameterDefinitionWidget(
4885 QVBoxLayout *vlayout =
new QVBoxLayout();
4886 vlayout->setContentsMargins( 0, 0, 0, 0 );
4888 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
4889 mParentLayerComboBox =
new QComboBox();
4891 QString initialParent;
4893 initialParent = fieldParam->parentLayerParameterName();
4895 if (
auto *lModel = widgetContext.
model() )
4898 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4899 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4903 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4904 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4906 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4911 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4912 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4914 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4921 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4922 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4924 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4931 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
4934 mParentLayerComboBox->addItem( initialParent, initialParent );
4935 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4938 vlayout->addWidget( mParentLayerComboBox );
4941 vlayout->addWidget(
new QLabel( tr(
"Allowed data type" ) ) );
4942 mDataTypeComboBox =
new QComboBox();
4950 mDataTypeComboBox->setCurrentIndex( mDataTypeComboBox->findData(
static_cast<int>( fieldParam->dataType() ) ) );
4952 vlayout->addWidget( mDataTypeComboBox );
4955 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple fields" ) );
4957 mAllowMultipleCheckBox->setChecked( fieldParam->allowMultiple() );
4959 vlayout->addWidget( mAllowMultipleCheckBox );
4964 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all fields by default" ) );
4965 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
4967 mDefaultToAllCheckBox->setChecked( fieldParam->defaultToAllFields() );
4969 vlayout->addWidget( mDefaultToAllCheckBox );
4972 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [
this] { mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() ); } );
4974 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4976 mDefaultLineEdit =
new QLineEdit();
4977 mDefaultLineEdit->setToolTip( tr(
"Default field name, or ; separated list of field names for multiple field parameters" ) );
4981 mDefaultLineEdit->setText( fields.join(
';' ) );
4983 vlayout->addWidget( mDefaultLineEdit );
4987 setLayout( vlayout );
4994 QVariant defaultValue;
4995 if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
4997 defaultValue = mDefaultLineEdit->text();
4999 auto param = std::make_unique<
5000 QgsProcessingParameterField>( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), dataType, mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
5002 return param.release();
5009QWidget *QgsProcessingFieldWidgetWrapper::createWidget()
5022 mPanel =
new QgsProcessingFieldPanelWidget(
nullptr, fieldParam );
5023 mPanel->setToolTip( parameterDefinition()->toolTip() );
5024 connect( mPanel, &QgsProcessingFieldPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
5043 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5051 mLineEdit =
new QLineEdit();
5052 mLineEdit->setToolTip( QObject::tr(
"Name of field (separate field names with ; for multiple field parameters)" ) );
5053 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
5060void QgsProcessingFieldWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5072 setParentLayerWrapperValue( wrapper );
5089 std::unique_ptr<QgsProcessingContext> tmpContext;
5090 if ( mProcessingContextGenerator )
5091 context = mProcessingContextGenerator->processingContext();
5095 tmpContext = std::make_unique<QgsProcessingContext>();
5096 context = tmpContext.get();
5101 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
5111 bool valueSet =
false;
5115 if ( layers.count() > 1 )
5117 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layers.at( 0 ) );
5119 const QList<QgsMapLayer *> remainingLayers = layers.mid( 1 );
5125 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
5126 if ( !vlayer || !vlayer->
isValid() )
5132 for (
int fieldIdx = fields.
count() - 1; fieldIdx >= 0; fieldIdx-- )
5135 fields.
remove( fieldIdx );
5140 mComboBox->setFields( fields );
5142 mPanel->setFields( filterFields( fields ) );
5148 if ( !valueSet && !layers.isEmpty() && layers.at( 0 )->isValid() )
5150 QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( layers.at( 0 ) );
5154 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
5157 mParentLayer.reset( qobject_cast<QgsVectorLayer *>( ownedLayer.release() ) );
5158 layer = mParentLayer.get();
5166 mComboBox->setLayer( layer );
5168 mPanel->setFields( filterFields( layer->
fields() ) );
5178 const QgsFields fields = source->fields();
5180 mComboBox->setFields( fields );
5182 mPanel->setFields( filterFields( fields ) );
5191 mComboBox->setLayer(
nullptr );
5195 if ( value.isValid() && widgetContext().messageBar() )
5207 val.reserve( mPanel->fields().size() );
5208 for (
const QgsField &field : mPanel->fields() )
5209 val << field.name();
5210 setWidgetValue( val, *context );
5213 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5216void QgsProcessingFieldWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5220 if ( !value.isValid() )
5221 mComboBox->setField( QString() );
5225 mComboBox->setField( v );
5231 if ( value.isValid() )
5234 opts.reserve( v.size() );
5235 for (
const QString &i : v )
5239 mPanel->setValue( opts );
5241 else if ( mLineEdit )
5247 mLineEdit->setText( v.join(
';' ) );
5256QVariant QgsProcessingFieldWidgetWrapper::widgetValue()
const
5259 return mComboBox->currentField();
5261 return mPanel->value();
5262 else if ( mLineEdit )
5267 return mLineEdit->text().split(
';' );
5270 return mLineEdit->text();
5276QString QgsProcessingFieldWidgetWrapper::modelerExpressionFormatString()
const
5278 return tr(
"selected field names as an array of names, or semicolon separated string of options (e.g. 'fid;place_name')" );
5281const QgsVectorLayer *QgsProcessingFieldWidgetWrapper::linkedVectorLayer()
const
5283 if ( mComboBox && mComboBox->layer() )
5284 return mComboBox->layer();
5289QgsFields QgsProcessingFieldWidgetWrapper::filterFields(
const QgsFields &fields )
const
5302 if ( f.isNumeric() )
5307 if ( f.type() == QMetaType::Type::QString )
5312 if ( f.type() == QMetaType::Type::QDate || f.type() == QMetaType::Type::QTime || f.type() == QMetaType::Type::QDateTime )
5317 if ( f.type() == QMetaType::Type::QByteArray )
5322 if ( f.type() == QMetaType::Type::Bool )
5331QString QgsProcessingFieldWidgetWrapper::parameterType()
const
5338 return new QgsProcessingFieldWidgetWrapper( parameter, type );
5345 return new QgsProcessingFieldParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5353QgsProcessingMapThemeParameterDefinitionWidget::QgsProcessingMapThemeParameterDefinitionWidget(
5358 QVBoxLayout *vlayout =
new QVBoxLayout();
5359 vlayout->setContentsMargins( 0, 0, 0, 0 );
5361 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5363 mDefaultComboBox =
new QComboBox();
5364 mDefaultComboBox->addItem( QString(), QVariant( -1 ) );
5367 for (
const QString &theme : mapThemes )
5371 mDefaultComboBox->setEditable(
true );
5375 if ( themeParam->defaultValueForGui().isValid() )
5378 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
5381 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
5383 vlayout->addWidget( mDefaultComboBox );
5387 setLayout( vlayout );
5392 QVariant defaultVal;
5393 if ( mDefaultComboBox->currentText().isEmpty() )
5394 defaultVal = QVariant();
5396 defaultVal = mDefaultComboBox->currentText();
5397 auto param = std::make_unique<QgsProcessingParameterMapTheme>( name, description, defaultVal );
5399 return param.release();
5407QWidget *QgsProcessingMapThemeWidgetWrapper::createWidget()
5413 mComboBox =
new QComboBox();
5416 mComboBox->addItem( tr(
"[Not selected]" ), QVariant( -1 ) );
5419 for (
const QString &theme : mapThemes )
5431 mComboBox->setEditable(
true );
5435 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5436 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
5441void QgsProcessingMapThemeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5445 if ( !value.isValid() )
5446 mComboBox->setCurrentIndex( mComboBox->findData( QVariant( -1 ) ) );
5449 if ( mComboBox->isEditable() && mComboBox->findData( v ) == -1 )
5451 const QString prev = mComboBox->currentText();
5452 mComboBox->setCurrentText( v );
5454 emit widgetValueHasChanged(
this );
5457 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
5461QVariant QgsProcessingMapThemeWidgetWrapper::widgetValue()
const
5464 return mComboBox->currentData().toInt() == -1 ? QVariant()
5465 : !mComboBox->currentData().isValid() && mComboBox->isEditable() ? mComboBox->currentText().isEmpty() ? QVariant() : QVariant( mComboBox->currentText() )
5466 : mComboBox->currentData();
5471QString QgsProcessingMapThemeWidgetWrapper::modelerExpressionFormatString()
const
5473 return tr(
"map theme as a string value (e.g. 'base maps')" );
5476QString QgsProcessingMapThemeWidgetWrapper::parameterType()
const
5483 return new QgsProcessingMapThemeWidgetWrapper( parameter, type );
5490 return new QgsProcessingMapThemeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5499QgsProcessingDateTimeParameterDefinitionWidget::QgsProcessingDateTimeParameterDefinitionWidget(
5504 QVBoxLayout *vlayout =
new QVBoxLayout();
5505 vlayout->setContentsMargins( 0, 0, 0, 0 );
5507 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
5509 mTypeComboBox =
new QComboBox();
5514 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( datetimeParam->dataType() ) ) );
5516 mTypeComboBox->setCurrentIndex( 0 );
5517 vlayout->addWidget( mTypeComboBox );
5521 setLayout( vlayout );
5526 auto param = std::make_unique<QgsProcessingParameterDateTime>( name, description );
5529 return param.release();
5537QWidget *QgsProcessingDateTimeWidgetWrapper::createWidget()
5540 if ( !dateTimeParam )
5544 switch ( dateTimeParam->
dataType() )
5548 widget = mDateTimeEdit;
5573 widget->setToolTip( parameterDefinition()->toolTip() );
5575 if ( mDateTimeEdit )
5579 else if ( mDateEdit )
5583 else if ( mTimeEdit )
5595 return new QgsProcessingDateTimeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5598void QgsProcessingDateTimeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5600 if ( mDateTimeEdit )
5604 else if ( mDateEdit )
5608 else if ( mTimeEdit )
5614QVariant QgsProcessingDateTimeWidgetWrapper::widgetValue()
const
5616 if ( mDateTimeEdit )
5617 return !mDateTimeEdit->dateTime().isNull() && mDateTimeEdit->dateTime().isValid() ? QVariant( mDateTimeEdit->dateTime() ) : QVariant();
5618 else if ( mDateEdit )
5619 return !mDateEdit->date().isNull() && mDateEdit->date().isValid() ? QVariant( mDateEdit->date() ) : QVariant();
5620 else if ( mTimeEdit )
5621 return !mTimeEdit->time().isNull() && mTimeEdit->time().isValid() ? QVariant( mTimeEdit->time() ) : QVariant();
5626QString QgsProcessingDateTimeWidgetWrapper::modelerExpressionFormatString()
const
5629 if ( dateTimeParam )
5631 switch ( dateTimeParam->
dataType() )
5634 return tr(
"datetime value, or a ISO string representation of a datetime" );
5637 return tr(
"date value, or a ISO string representation of a date" );
5640 return tr(
"time value, or a ISO string representation of a time" );
5646QString QgsProcessingDateTimeWidgetWrapper::parameterType()
const
5653 return new QgsProcessingDateTimeWidgetWrapper( parameter, type );
5661QgsProcessingProviderConnectionParameterDefinitionWidget::QgsProcessingProviderConnectionParameterDefinitionWidget(
5668 QVBoxLayout *vlayout =
new QVBoxLayout();
5669 vlayout->setContentsMargins( 0, 0, 0, 0 );
5671 vlayout->addWidget(
new QLabel( tr(
"Provider" ) ) );
5672 mProviderComboBox =
new QComboBox();
5673 mProviderComboBox->addItem( QObject::tr(
"Postgres" ), u
"postgres"_s );
5674 mProviderComboBox->addItem( QObject::tr(
"GeoPackage" ), u
"ogr"_s );
5675 mProviderComboBox->addItem( QObject::tr(
"Spatialite" ), u
"spatialite"_s );
5677 vlayout->addWidget( mProviderComboBox );
5679 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5681 mDefaultEdit =
new QLineEdit();
5682 vlayout->addWidget( mDefaultEdit );
5683 setLayout( vlayout );
5685 if ( connectionParam )
5687 mProviderComboBox->setCurrentIndex( mProviderComboBox->findData( connectionParam->
providerId() ) );
5697 QVariant defaultVal;
5698 if ( mDefaultEdit->text().isEmpty() )
5699 defaultVal = QVariant();
5701 defaultVal = mDefaultEdit->text();
5702 auto param = std::make_unique<QgsProcessingParameterProviderConnection>( name, description, mProviderComboBox->currentData().toString(), defaultVal );
5704 return param.release();
5712QWidget *QgsProcessingProviderConnectionWidgetWrapper::createWidget()
5715 if ( !connectionParam )
5720 mProviderComboBox->setAllowEmptyConnection(
true );
5728 mProviderComboBox->setEditable(
true );
5732 mProviderComboBox->setToolTip( parameterDefinition()->toolTip() );
5733 connect( mProviderComboBox, &QgsProviderConnectionComboBox::currentTextChanged,
this, [
this](
const QString & ) {
5734 if ( mBlockSignals )
5737 emit widgetValueHasChanged(
this );
5740 return mProviderComboBox;
5747 return new QgsProcessingProviderConnectionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5750void QgsProcessingProviderConnectionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5754 if ( !value.isValid() )
5755 mProviderComboBox->setCurrentIndex( -1 );
5758 if ( mProviderComboBox->isEditable() )
5760 const QString prev = mProviderComboBox->currentText();
5762 mProviderComboBox->setConnection( v );
5763 mProviderComboBox->setCurrentText( v );
5767 emit widgetValueHasChanged(
this );
5770 mProviderComboBox->setConnection( v );
5774QVariant QgsProcessingProviderConnectionWidgetWrapper::widgetValue()
const
5776 if ( mProviderComboBox )
5777 if ( mProviderComboBox->isEditable() )
5778 return mProviderComboBox->currentText().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentText() );
5780 return mProviderComboBox->currentConnection().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentConnection() );
5785QString QgsProcessingProviderConnectionWidgetWrapper::modelerExpressionFormatString()
const
5787 return tr(
"connection name as a string value" );
5790QString QgsProcessingProviderConnectionWidgetWrapper::parameterType()
const
5797 return new QgsProcessingProviderConnectionWidgetWrapper( parameter, type );
5805QgsProcessingDatabaseSchemaParameterDefinitionWidget::QgsProcessingDatabaseSchemaParameterDefinitionWidget(
5812 QVBoxLayout *vlayout =
new QVBoxLayout();
5813 vlayout->setContentsMargins( 0, 0, 0, 0 );
5815 mConnectionParamComboBox =
new QComboBox();
5816 QString initialConnection;
5822 if (
auto *lModel = widgetContext.
model() )
5825 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
5826 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
5828 if ( definition && it->parameterName() == definition->
name() )
5834 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
5835 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5837 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5842 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
5845 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
5846 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5849 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
5850 vlayout->addWidget( mConnectionParamComboBox );
5854 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5856 mDefaultEdit =
new QLineEdit();
5857 vlayout->addWidget( mDefaultEdit );
5858 setLayout( vlayout );
5869 QVariant defaultVal;
5870 if ( mDefaultEdit->text().isEmpty() )
5871 defaultVal = QVariant();
5873 defaultVal = mDefaultEdit->text();
5874 auto param = std::make_unique<QgsProcessingParameterDatabaseSchema>( name, description, mConnectionParamComboBox->currentData().toString(), defaultVal );
5876 return param.release();
5884QWidget *QgsProcessingDatabaseSchemaWidgetWrapper::createWidget()
5892 mSchemaComboBox->setAllowEmptySchema(
true );
5900 mSchemaComboBox->comboBox()->setEditable(
true );
5904 mSchemaComboBox->setToolTip( parameterDefinition()->toolTip() );
5905 connect( mSchemaComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [
this](
const QString & ) {
5906 if ( mBlockSignals )
5909 emit widgetValueHasChanged( this );
5912 return mSchemaComboBox;
5919 return new QgsProcessingDatabaseSchemaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5926 std::unique_ptr<QgsProcessingContext> tmpContext;
5927 if ( mProcessingContextGenerator )
5928 context = mProcessingContextGenerator->processingContext();
5932 tmpContext = std::make_unique<QgsProcessingContext>();
5933 context = tmpContext.get();
5939 if ( mSchemaComboBox )
5940 mSchemaComboBox->setConnectionName( connection, qgis::down_cast<const QgsProcessingParameterProviderConnection *>( parentWrapper->
parameterDefinition() )->providerId() );
5944 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5947void QgsProcessingDatabaseSchemaWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5951 if ( !value.isValid() )
5952 mSchemaComboBox->comboBox()->setCurrentIndex( -1 );
5955 if ( mSchemaComboBox->comboBox()->isEditable() )
5957 const QString prev = mSchemaComboBox->comboBox()->currentText();
5959 mSchemaComboBox->setSchema( v );
5960 mSchemaComboBox->comboBox()->setCurrentText( v );
5964 emit widgetValueHasChanged(
this );
5967 mSchemaComboBox->setSchema( v );
5971QVariant QgsProcessingDatabaseSchemaWidgetWrapper::widgetValue()
const
5973 if ( mSchemaComboBox )
5974 if ( mSchemaComboBox->comboBox()->isEditable() )
5975 return mSchemaComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->comboBox()->currentText() );
5977 return mSchemaComboBox->currentSchema().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->currentSchema() );
5982QString QgsProcessingDatabaseSchemaWidgetWrapper::modelerExpressionFormatString()
const
5984 return tr(
"database schema name as a string value" );
5987QString QgsProcessingDatabaseSchemaWidgetWrapper::parameterType()
const
5994 return new QgsProcessingDatabaseSchemaWidgetWrapper( parameter, type );
5997void QgsProcessingDatabaseSchemaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6009 setParentConnectionWrapperValue( wrapper );
6027QgsProcessingDatabaseTableParameterDefinitionWidget::QgsProcessingDatabaseTableParameterDefinitionWidget(
6034 QVBoxLayout *vlayout =
new QVBoxLayout();
6035 vlayout->setContentsMargins( 0, 0, 0, 0 );
6037 mConnectionParamComboBox =
new QComboBox();
6038 mSchemaParamComboBox =
new QComboBox();
6039 QString initialConnection;
6040 QString initialSchema;
6047 if (
auto *lModel = widgetContext.
model() )
6050 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6051 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6053 if ( definition && it->parameterName() == definition->
name() )
6058 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
6059 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
6061 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
6066 mSchemaParamComboBox->addItem( it->parameterName(), it->parameterName() );
6067 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
6069 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
6075 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
6078 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
6079 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
6082 if ( mSchemaParamComboBox->count() == 0 && !initialSchema.isEmpty() )
6085 mSchemaParamComboBox->addItem( initialSchema, initialSchema );
6086 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
6089 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
6090 vlayout->addWidget( mConnectionParamComboBox );
6092 vlayout->addWidget(
new QLabel( tr(
"Database schema parameter" ) ) );
6093 vlayout->addWidget( mSchemaParamComboBox );
6098 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6100 mDefaultEdit =
new QLineEdit();
6101 vlayout->addWidget( mDefaultEdit );
6102 setLayout( vlayout );
6113 QVariant defaultVal;
6114 if ( mDefaultEdit->text().isEmpty() )
6115 defaultVal = QVariant();
6117 defaultVal = mDefaultEdit->text();
6118 auto param = std::make_unique<QgsProcessingParameterDatabaseTable>( name, description, mConnectionParamComboBox->currentData().toString(), mSchemaParamComboBox->currentData().toString(), defaultVal );
6120 return param.release();
6128QWidget *QgsProcessingDatabaseTableWidgetWrapper::createWidget()
6136 mTableComboBox->setAllowEmptyTable(
true );
6139 mTableComboBox->comboBox()->setEditable(
true );
6141 mTableComboBox->setToolTip( parameterDefinition()->toolTip() );
6142 connect( mTableComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [
this](
const QString & ) {
6143 if ( mBlockSignals )
6146 emit widgetValueHasChanged( this );
6149 return mTableComboBox;
6156 return new QgsProcessingDatabaseTableParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6163 std::unique_ptr<QgsProcessingContext> tmpContext;
6164 if ( mProcessingContextGenerator )
6165 context = mProcessingContextGenerator->processingContext();
6169 tmpContext = std::make_unique<QgsProcessingContext>();
6170 context = tmpContext.get();
6175 mProvider = qgis::down_cast<const QgsProcessingParameterProviderConnection *>( parentWrapper->
parameterDefinition() )->providerId();
6176 if ( mTableComboBox && !mSchema.isEmpty() )
6178 mTableComboBox->setSchema( mSchema );
6179 mTableComboBox->setConnectionName( mConnection, mProvider );
6183 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6191 std::unique_ptr<QgsProcessingContext> tmpContext;
6192 if ( mProcessingContextGenerator )
6193 context = mProcessingContextGenerator->processingContext();
6197 tmpContext = std::make_unique<QgsProcessingContext>();
6198 context = tmpContext.get();
6204 if ( mTableComboBox && !mSchema.isEmpty() && !mConnection.isEmpty() )
6206 mTableComboBox->setSchema( mSchema );
6207 mTableComboBox->setConnectionName( mConnection, mProvider );
6209 const QgsProcessingParameterDatabaseTable *tableParam = static_cast<const QgsProcessingParameterDatabaseTable *>( parameterDefinition() );
6210 if ( tableParam->defaultValueForGui().isValid() )
6211 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6215void QgsProcessingDatabaseTableWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6219 if ( !value.isValid() )
6220 mTableComboBox->comboBox()->setCurrentIndex( -1 );
6223 if ( mTableComboBox->comboBox()->isEditable() )
6225 const QString prev = mTableComboBox->comboBox()->currentText();
6227 mTableComboBox->setTable( v );
6228 mTableComboBox->comboBox()->setCurrentText( v );
6232 emit widgetValueHasChanged(
this );
6235 mTableComboBox->setTable( v );
6239QVariant QgsProcessingDatabaseTableWidgetWrapper::widgetValue()
const
6241 if ( mTableComboBox )
6242 if ( mTableComboBox->comboBox()->isEditable() )
6243 return mTableComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mTableComboBox->comboBox()->currentText() );
6245 return mTableComboBox->currentTable().isEmpty() ? QVariant() : QVariant( mTableComboBox->currentTable() );
6250QString QgsProcessingDatabaseTableWidgetWrapper::modelerExpressionFormatString()
const
6252 return tr(
"database table name as a string value" );
6255QString QgsProcessingDatabaseTableWidgetWrapper::parameterType()
const
6262 return new QgsProcessingDatabaseTableWidgetWrapper( parameter, type );
6265void QgsProcessingDatabaseTableWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6277 setParentConnectionWrapperValue( wrapper );
6282 setParentSchemaWrapperValue( wrapper );
6299QgsProcessingExtentParameterDefinitionWidget::QgsProcessingExtentParameterDefinitionWidget(
6304 QVBoxLayout *vlayout =
new QVBoxLayout();
6305 vlayout->setContentsMargins( 0, 0, 0, 0 );
6307 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6310 mDefaultWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
6313 if ( extentParam->defaultValueForGui().isValid() )
6317 mDefaultWidget->setCurrentExtent( rect, crs );
6318 mDefaultWidget->setOutputExtentFromCurrent();
6322 mDefaultWidget->clear();
6328 vlayout->addWidget( mDefaultWidget );
6329 setLayout( vlayout );
6334 const QString defaultVal = mDefaultWidget->isValid() ? u
"%1,%2,%3,%4%5"_s.arg(
6335 QString::number( mDefaultWidget->outputExtent().xMinimum(),
'f', 9 ),
6336 QString::number( mDefaultWidget->outputExtent().xMaximum(),
'f', 9 ),
6337 QString::number( mDefaultWidget->outputExtent().yMinimum(),
'f', 9 ),
6338 QString::number( mDefaultWidget->outputExtent().yMaximum(),
'f', 9 ),
6339 mDefaultWidget->outputCrs().isValid() ? u
" [%1]"_s.arg( mDefaultWidget->outputCrs().authid() ) : QString()
6342 auto param = std::make_unique<QgsProcessingParameterExtent>( name, description, !defaultVal.isEmpty() ? QVariant( defaultVal ) : QVariant() );
6344 return param.release();
6352QWidget *QgsProcessingExtentWidgetWrapper::createWidget()
6365 if ( widgetContext().mapCanvas() )
6366 mExtentWidget->setMapCanvas( widgetContext().mapCanvas() );
6369 mExtentWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
6371 mExtentWidget->setToolTip( parameterDefinition()->toolTip() );
6376 setDialog( mDialog );
6378 return mExtentWidget;
6388 mExtentWidget->setMapCanvas( context.
mapCanvas() );
6391void QgsProcessingExtentWidgetWrapper::setDialog( QWidget *dialog )
6398 mDialog->showMinimized();
6401 mDialog->showNormal();
6403 mDialog->activateWindow();
6410void QgsProcessingExtentWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6412 if ( mExtentWidget )
6414 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) )
6415 mExtentWidget->clear();
6420 mExtentWidget->setCurrentExtent( r, crs );
6421 mExtentWidget->setOutputExtentFromUser( r, crs );
6426QVariant QgsProcessingExtentWidgetWrapper::widgetValue()
const
6428 if ( mExtentWidget )
6430 const QString val = mExtentWidget->isValid() ? u
"%1,%2,%3,%4%5"_s.arg(
6431 QString::number( mExtentWidget->outputExtent().xMinimum(),
'f', 9 ),
6432 QString::number( mExtentWidget->outputExtent().xMaximum(),
'f', 9 ),
6433 QString::number( mExtentWidget->outputExtent().yMinimum(),
'f', 9 ),
6434 QString::number( mExtentWidget->outputExtent().yMaximum(),
'f', 9 ),
6435 mExtentWidget->outputCrs().isValid() ? u
" [%1]"_s.arg( mExtentWidget->outputCrs().authid() ) : QString()
6439 return val.isEmpty() ? QVariant() : QVariant( val );
6445QString QgsProcessingExtentWidgetWrapper::modelerExpressionFormatString()
const
6447 return tr(
"string of the format 'x min,x max,y min,y max' or a geometry value (bounding box is used)" );
6450QString QgsProcessingExtentWidgetWrapper::parameterType()
const
6457 return new QgsProcessingExtentWidgetWrapper( parameter, type );
6464 return new QgsProcessingExtentParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6472QgsProcessingMapLayerParameterDefinitionWidget::QgsProcessingMapLayerParameterDefinitionWidget(
6477 QVBoxLayout *vlayout =
new QVBoxLayout();
6478 vlayout->setContentsMargins( 0, 0, 0, 0 );
6480 vlayout->addWidget(
new QLabel( tr(
"Layer type" ) ) );
6496 for (
int i : layerParam->dataTypes() )
6498 mLayerTypeComboBox->setItemCheckState( mLayerTypeComboBox->findData( i ), Qt::Checked );
6502 vlayout->addWidget( mLayerTypeComboBox );
6506 setLayout( vlayout );
6511 QList<int> dataTypes;
6512 for (
const QVariant &v : mLayerTypeComboBox->checkedItemsData() )
6513 dataTypes << v.toInt();
6515 auto param = std::make_unique<QgsProcessingParameterMapLayer>( name, description );
6516 param->setDataTypes( dataTypes );
6518 return param.release();
6525QWidget *QgsProcessingMapLayerWidgetWrapper::createWidget()
6527 mComboBox =
new QgsProcessingMapLayerComboBox( parameterDefinition(), type() );
6535 mComboBox->setEditable(
true );
6539 mComboBox->setToolTip( parameterDefinition()->toolTip() );
6541 connect( mComboBox, &QgsProcessingMapLayerComboBox::valueChanged,
this, [
this]() {
6542 if ( mBlockSignals )
6545 emit widgetValueHasChanged(
this );
6548 setWidgetContext( widgetContext() );
6557 mComboBox->setWidgetContext( context );
6562 if ( !parameterDefinition()->defaultValueForGui().isValid() )
6568void QgsProcessingMapLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6571 mComboBox->setValue( value, context );
6574QVariant QgsProcessingMapLayerWidgetWrapper::widgetValue()
const
6576 return mComboBox ? mComboBox->value() : QVariant();
6579QString QgsProcessingMapLayerWidgetWrapper::modelerExpressionFormatString()
const
6581 return tr(
"path to a map layer" );
6598QString QgsProcessingMapLayerWidgetWrapper::parameterType()
const
6605 return new QgsProcessingMapLayerWidgetWrapper( parameter, type );
6612 return new QgsProcessingMapLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6621 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6624QString QgsProcessingRasterLayerWidgetWrapper::modelerExpressionFormatString()
const
6626 return tr(
"path to a raster layer" );
6629QString QgsProcessingRasterLayerWidgetWrapper::parameterType()
const
6636 return new QgsProcessingRasterLayerWidgetWrapper( parameter, type );
6643 Q_UNUSED( context );
6644 Q_UNUSED( widgetContext );
6645 Q_UNUSED( definition );
6656QgsProcessingVectorLayerParameterDefinitionWidget::QgsProcessingVectorLayerParameterDefinitionWidget(
6661 QVBoxLayout *vlayout =
new QVBoxLayout();
6662 vlayout->setContentsMargins( 0, 0, 0, 0 );
6664 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6674 for (
int i : vectorParam->dataTypes() )
6676 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6680 vlayout->addWidget( mGeometryTypeComboBox );
6684 setLayout( vlayout );
6689 QList<int> dataTypes;
6690 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6691 dataTypes << v.toInt();
6693 auto param = std::make_unique<QgsProcessingParameterVectorLayer>( name, description, dataTypes );
6695 return param.release();
6700 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6703QString QgsProcessingVectorLayerWidgetWrapper::modelerExpressionFormatString()
const
6705 return tr(
"path to a vector layer" );
6708QString QgsProcessingVectorLayerWidgetWrapper::parameterType()
const
6715 return new QgsProcessingVectorLayerWidgetWrapper( parameter, type );
6722 return new QgsProcessingVectorLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6730QgsProcessingFeatureSourceParameterDefinitionWidget::QgsProcessingFeatureSourceParameterDefinitionWidget(
6735 QVBoxLayout *vlayout =
new QVBoxLayout();
6736 vlayout->setContentsMargins( 0, 0, 0, 0 );
6738 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6748 for (
int i : sourceParam->dataTypes() )
6750 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6758 vlayout->addWidget( mGeometryTypeComboBox );
6761 setLayout( vlayout );
6766 QList<int> dataTypes;
6767 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6768 dataTypes << v.toInt();
6770 auto param = std::make_unique<QgsProcessingParameterFeatureSource>( name, description, dataTypes );
6772 return param.release();
6776 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6779QString QgsProcessingFeatureSourceWidgetWrapper::modelerExpressionFormatString()
const
6781 return tr(
"path to a vector layer" );
6784QString QgsProcessingFeatureSourceWidgetWrapper::parameterType()
const
6791 return new QgsProcessingFeatureSourceWidgetWrapper( parameter, type );
6798 return new QgsProcessingFeatureSourceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6806 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6809QString QgsProcessingMeshLayerWidgetWrapper::modelerExpressionFormatString()
const
6811 return tr(
"path to a mesh layer" );
6814QString QgsProcessingMeshLayerWidgetWrapper::parameterType()
const
6821 return new QgsProcessingMeshLayerWidgetWrapper( parameter, type );
6828 Q_UNUSED( context );
6829 Q_UNUSED( widgetContext );
6830 Q_UNUSED( definition );
6841QgsProcessingRasterBandPanelWidget::QgsProcessingRasterBandPanelWidget( QWidget *parent,
const QgsProcessingParameterBand *param )
6845 QHBoxLayout *hl =
new QHBoxLayout();
6846 hl->setContentsMargins( 0, 0, 0, 0 );
6848 mLineEdit =
new QLineEdit();
6849 mLineEdit->setEnabled(
false );
6850 hl->addWidget( mLineEdit, 1 );
6852 mToolButton =
new QToolButton();
6853 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6854 hl->addWidget( mToolButton );
6860 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, 0 ) );
6863 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingRasterBandPanelWidget::showDialog );
6866void QgsProcessingRasterBandPanelWidget::setBands(
const QList<int> &bands )
6871void QgsProcessingRasterBandPanelWidget::setBandNames(
const QHash<int, QString> &names )
6876void QgsProcessingRasterBandPanelWidget::setValue(
const QVariant &value )
6878 if ( value.isValid() )
6879 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
6883 updateSummaryText();
6887void QgsProcessingRasterBandPanelWidget::showDialog()
6889 QVariantList availableOptions;
6890 availableOptions.reserve( mBands.size() );
6891 for (
int band : std::as_const( mBands ) )
6893 availableOptions << band;
6899 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
6900 widget->setPanelTitle( mParam->description() );
6902 widget->setValueFormatter( [
this](
const QVariant &v ) -> QString {
6903 int band = v.toInt();
6904 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6907 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
6913 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
6915 dlg.setValueFormatter( [
this](
const QVariant &v ) -> QString {
6916 int band = v.toInt();
6917 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6921 setValue( dlg.selectedOptions() );
6926void QgsProcessingRasterBandPanelWidget::updateSummaryText()
6929 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, mValue.count() ) );
6937QgsProcessingBandParameterDefinitionWidget::QgsProcessingBandParameterDefinitionWidget(
6942 QVBoxLayout *vlayout =
new QVBoxLayout();
6943 vlayout->setContentsMargins( 0, 0, 0, 0 );
6945 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6947 mDefaultLineEdit =
new QLineEdit();
6948 mDefaultLineEdit->setToolTip( tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6953 for (
int b : bands )
6955 defVal << QString::number( b );
6958 mDefaultLineEdit->setText( defVal.join(
';' ) );
6960 vlayout->addWidget( mDefaultLineEdit );
6963 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
6964 mParentLayerComboBox =
new QComboBox();
6966 QString initialParent;
6968 initialParent = bandParam->parentLayerParameterName();
6970 if (
auto *lModel = widgetContext.
model() )
6973 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6974 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6978 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
6979 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
6981 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6987 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
6990 mParentLayerComboBox->addItem( initialParent, initialParent );
6991 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6995 vlayout->addWidget( mParentLayerComboBox );
6997 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Allow multiple" ) );
6999 mAllowMultipleCheckBox->setChecked( bandParam->allowMultiple() );
7002 vlayout->addWidget( mAllowMultipleCheckBox );
7003 setLayout( vlayout );
7009 = std::make_unique<QgsProcessingParameterBand>( name, description, mDefaultLineEdit->text().split(
';' ), mParentLayerComboBox->currentData().toString(),
false, mAllowMultipleCheckBox->isChecked() );
7011 return param.release();
7018QWidget *QgsProcessingBandWidgetWrapper::createWidget()
7031 mPanel =
new QgsProcessingRasterBandPanelWidget(
nullptr, bandParam );
7032 mPanel->setToolTip( parameterDefinition()->toolTip() );
7033 connect( mPanel, &QgsProcessingRasterBandPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7041 mComboBox->setToolTip( parameterDefinition()->toolTip() );
7049 mLineEdit =
new QLineEdit();
7050 mLineEdit->setToolTip( QObject::tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
7051 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7058void QgsProcessingBandWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
7070 setParentLayerWrapperValue( wrapper );
7087 std::unique_ptr<QgsProcessingContext> tmpContext;
7088 if ( mProcessingContextGenerator )
7089 context = mProcessingContextGenerator->processingContext();
7093 tmpContext = std::make_unique<QgsProcessingContext>();
7094 context = tmpContext.get();
7100 if ( layer && layer->
isValid() )
7104 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
7107 mParentLayer.reset( qobject_cast<QgsRasterLayer *>( ownedLayer.release() ) );
7108 layer = mParentLayer.get();
7116 mComboBox->setLayer( layer );
7120 if ( provider && layer->
isValid() )
7125 QHash<int, QString> bandNames;
7126 for (
int i = 1; i <= nBands; ++i )
7131 mPanel->setBands( bands );
7132 mPanel->setBandNames( bandNames );
7139 mComboBox->setLayer(
nullptr );
7141 mPanel->setBands( QList<int>() );
7143 if ( value.isValid() && widgetContext().messageBar() )
7150 if ( parameterDefinition()->defaultValueForGui().isValid() )
7151 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
7154void QgsProcessingBandWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7158 if ( !value.isValid() )
7159 mComboBox->setBand( -1 );
7163 mComboBox->setBand( v );
7169 if ( value.isValid() )
7172 opts.reserve( v.size() );
7177 mPanel->setValue( value.isValid() ? opts : QVariant() );
7179 else if ( mLineEdit )
7186 opts.reserve( v.size() );
7188 opts << QString::number( i );
7189 mLineEdit->setText( value.isValid() && !opts.empty() ? opts.join(
';' ) : QString() );
7193 if ( value.isValid() )
7201QVariant QgsProcessingBandWidgetWrapper::widgetValue()
const
7204 return mComboBox->currentBand() == -1 ? QVariant() : mComboBox->currentBand();
7206 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
7207 else if ( mLineEdit )
7212 const QStringList parts = mLineEdit->text().split(
';', Qt::SkipEmptyParts );
7214 res.reserve( parts.count() );
7215 for (
const QString &s : parts )
7218 int band = s.toInt( &ok );
7222 return res.
isEmpty() ? QVariant() : res;
7226 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
7233QString QgsProcessingBandWidgetWrapper::modelerExpressionFormatString()
const
7235 return tr(
"selected band numbers as an array of numbers, or semicolon separated string of options (e.g. '1;3')" );
7238QString QgsProcessingBandWidgetWrapper::parameterType()
const
7245 return new QgsProcessingBandWidgetWrapper( parameter, type );
7252 return new QgsProcessingBandParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
7263 setAcceptDrops(
true );
7266void QgsProcessingMultipleLayerLineEdit::dragEnterEvent( QDragEnterEvent *event )
7268 const QStringList uris = QgsProcessingMultipleInputPanelWidget::compatibleUrisFromMimeData( mParam, event->mimeData(), {} );
7269 if ( !uris.isEmpty() )
7271 event->setDropAction( Qt::CopyAction );
7273 setHighlighted(
true );
7281void QgsProcessingMultipleLayerLineEdit::dragLeaveEvent( QDragLeaveEvent *event )
7283 QgsHighlightableLineEdit::dragLeaveEvent( event );
7285 setHighlighted(
false );
7288void QgsProcessingMultipleLayerLineEdit::dropEvent( QDropEvent *event )
7290 const QStringList uris = QgsProcessingMultipleInputPanelWidget::compatibleUrisFromMimeData( mParam, event->mimeData(), {} );
7291 if ( !uris.isEmpty() )
7293 event->setDropAction( Qt::CopyAction );
7295 QVariantList uriList;
7296 uriList.reserve( uris.size() );
7297 for (
const QString &uri : uris )
7298 uriList.append( QVariant( uri ) );
7299 emit layersDropped( uriList );
7302 setHighlighted(
false );
7313 QHBoxLayout *hl =
new QHBoxLayout();
7314 hl->setContentsMargins( 0, 0, 0, 0 );
7316 mLineEdit =
new QgsProcessingMultipleLayerLineEdit(
nullptr, param );
7317 mLineEdit->setEnabled(
true );
7318 mLineEdit->setReadOnly(
true );
7320 hl->addWidget( mLineEdit, 1 );
7321 connect( mLineEdit, &QgsProcessingMultipleLayerLineEdit::layersDropped,
this, &QgsProcessingMultipleLayerPanelWidget::setValue );
7323 mToolButton =
new QToolButton();
7324 mToolButton->setText( QString( QChar( 0x2026 ) ) );
7325 hl->addWidget( mToolButton );
7331 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, 0 ) );
7334 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingMultipleLayerPanelWidget::showDialog );
7337void QgsProcessingMultipleLayerPanelWidget::setValue(
const QVariant &value )
7339 if ( value.isValid() )
7340 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
7344 updateSummaryText();
7348void QgsProcessingMultipleLayerPanelWidget::setProject(
QgsProject *project )
7354 if ( mValue.removeAll( layerId ) )
7356 updateSummaryText();
7363void QgsProcessingMultipleLayerPanelWidget::setModel( QgsProcessingModelAlgorithm *model,
const QString &modelChildAlgorithmID )
7369 switch ( mParam->layerType() )
7377 mModelSources = model->availableSourcesForChild(
7378 modelChildAlgorithmID,
7387 mModelSources = model->availableSourcesForChild(
7388 modelChildAlgorithmID,
7397 mModelSources = model->availableSourcesForChild(
7398 modelChildAlgorithmID,
7407 mModelSources = model->availableSourcesForChild(
7408 modelChildAlgorithmID,
7417 mModelSources = model->availableSourcesForChild(
7418 modelChildAlgorithmID,
7427 mModelSources = model->availableSourcesForChild(
7428 modelChildAlgorithmID,
7437 mModelSources = model->availableSourcesForChild(
7438 modelChildAlgorithmID,
7447 mModelSources = model->availableSourcesForChild(
7448 modelChildAlgorithmID,
7462 mModelSources = model->availableSourcesForChild(
7463 modelChildAlgorithmID,
7476 mModelSources = model->availableSourcesForChild(
7477 modelChildAlgorithmID,
7491 mModelSources = model->availableSourcesForChild(
7492 modelChildAlgorithmID,
7506 mModelSources = model->availableSourcesForChild(
7507 modelChildAlgorithmID,
7521 mModelSources = model->availableSourcesForChild(
7522 modelChildAlgorithmID,
7543void QgsProcessingMultipleLayerPanelWidget::showDialog()
7548 QgsProcessingMultipleInputPanelWidget *widget =
new QgsProcessingMultipleInputPanelWidget( mParam, mValue, mModelSources, mModel,
nullptr );
7549 widget->setPanelTitle( mParam->description() );
7550 widget->setProject( mProject );
7551 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
7557 QgsProcessingMultipleInputDialog dlg( mParam, mValue, mModelSources, mModel,
this, Qt::WindowFlags() );
7558 dlg.setProject( mProject );
7561 setValue( dlg.selectedOptions() );
7566void QgsProcessingMultipleLayerPanelWidget::updateSummaryText()
7569 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, mValue.count() ) );
7576QgsProcessingMultipleLayerParameterDefinitionWidget::QgsProcessingMultipleLayerParameterDefinitionWidget(
7581 QVBoxLayout *vlayout =
new QVBoxLayout();
7582 vlayout->setContentsMargins( 0, 0, 0, 0 );
7584 vlayout->addWidget(
new QLabel( tr(
"Allowed layer type" ) ) );
7585 mLayerTypeComboBox =
new QComboBox();
7599 mLayerTypeComboBox->setCurrentIndex( mLayerTypeComboBox->findData(
static_cast<int>( layersParam->layerType() ) ) );
7601 vlayout->addWidget( mLayerTypeComboBox );
7604 setLayout( vlayout );
7609 auto param = std::make_unique<QgsProcessingParameterMultipleLayers>( name, description,
static_cast<Qgis::ProcessingSourceType>( mLayerTypeComboBox->currentData().toInt() ) );
7611 return param.release();
7618QWidget *QgsProcessingMultipleLayerWidgetWrapper::createWidget()
7622 mPanel =
new QgsProcessingMultipleLayerPanelWidget(
nullptr, layerParam );
7623 mPanel->setToolTip( parameterDefinition()->toolTip() );
7624 mPanel->setProject( widgetContext().project() );
7626 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7627 connect( mPanel, &QgsProcessingMultipleLayerPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7636 mPanel->setProject( context.
project() );
7638 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7642void QgsProcessingMultipleLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7647 if ( value.isValid() )
7650 opts.reserve( v.size() );
7652 opts << l->source();
7655 for (
const QVariant &v : value.toList() )
7657 if ( v.userType() == qMetaTypeId<QgsProcessingModelChildParameterSource>() )
7659 const QgsProcessingModelChildParameterSource source = v.value<QgsProcessingModelChildParameterSource>();
7660 opts << QVariant::fromValue( source );
7665 mPanel->setValue( value.isValid() ? opts : QVariant() );
7669QVariant QgsProcessingMultipleLayerWidgetWrapper::widgetValue()
const
7672 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
7677QString QgsProcessingMultipleLayerWidgetWrapper::modelerExpressionFormatString()
const
7679 return tr(
"an array of layer paths, or semicolon separated string of layer paths" );
7682QString QgsProcessingMultipleLayerWidgetWrapper::parameterType()
const
7689 return new QgsProcessingMultipleLayerWidgetWrapper( parameter, type );
7696 return new QgsProcessingMultipleLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
7705 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
7708QString QgsProcessingPointCloudLayerWidgetWrapper::modelerExpressionFormatString()
const
7710 return tr(
"path to a point cloud layer" );
7713QString QgsProcessingPointCloudLayerWidgetWrapper::parameterType()
const
7720 return new QgsProcessingPointCloudLayerWidgetWrapper( parameter, type );
7727 Q_UNUSED( context );
7728 Q_UNUSED( widgetContext );
7729 Q_UNUSED( definition );
7744QString QgsProcessingAnnotationLayerWidgetWrapper::modelerExpressionFormatString()
const
7746 return tr(
"name of an annotation layer, or \"main\" for the main annotation layer" );
7749QString QgsProcessingAnnotationLayerWidgetWrapper::parameterType()
const
7756 return new QgsProcessingAnnotationLayerWidgetWrapper( parameter, type );
7763 Q_UNUSED( context );
7764 Q_UNUSED( widgetContext );
7765 Q_UNUSED( definition );
7776 if ( mWidgetContext.project() )
7777 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7781QWidget *QgsProcessingAnnotationLayerWidgetWrapper::createWidget()
7792 mComboBox->setEditable(
true );
7796 mComboBox->setToolTip( parameterDefinition()->toolTip() );
7798 if ( mWidgetContext.project() )
7799 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7802 mComboBox->setAllowEmptyLayer(
true );
7805 if ( mBlockSignals )
7808 emit widgetValueHasChanged(
this );
7811 setWidgetContext( widgetContext() );
7815void QgsProcessingAnnotationLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7821 mComboBox->setLayer(
nullptr );
7825 QVariant val = value;
7826 if ( val.userType() == qMetaTypeId<QgsProperty>() )
7838 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( val.value<QObject *>() );
7839 if ( !layer && val.userType() == QMetaType::Type::QString )
7846 mComboBox->setLayer( layer );
7851QVariant QgsProcessingAnnotationLayerWidgetWrapper::widgetValue()
const
7853 return mComboBox && mComboBox->currentLayer()
7854 ? ( mWidgetContext.project() ? ( mComboBox->currentLayer() == mWidgetContext.project()->mainAnnotationLayer() ? u
"main"_s : mComboBox->currentLayer()->id() )
7855 : mComboBox->currentLayer()->id() )
7868 QHBoxLayout *hl =
new QHBoxLayout();
7869 hl->setContentsMargins( 0, 0, 0, 0 );
7871 mLineEdit =
new QLineEdit();
7872 mLineEdit->setEnabled(
false );
7873 hl->addWidget( mLineEdit, 1 );
7875 mToolButton =
new QToolButton();
7876 mToolButton->setText( QString( QChar( 0x2026 ) ) );
7877 hl->addWidget( mToolButton );
7883 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, 0 ) );
7886 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingPointCloudAttributePanelWidget::showDialog );
7891 mAttributes = attributes;
7894void QgsProcessingPointCloudAttributePanelWidget::setValue(
const QVariant &value )
7896 if ( value.isValid() )
7897 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
7901 updateSummaryText();
7905void QgsProcessingPointCloudAttributePanelWidget::showDialog()
7907 QVariantList availableOptions;
7908 availableOptions.reserve( mAttributes.count() );
7909 const QVector<QgsPointCloudAttribute> attributes = mAttributes.attributes();
7912 availableOptions << attr.name();
7918 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
7919 widget->setPanelTitle( mParam->description() );
7921 widget->setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
7923 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
7929 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
7931 dlg.setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
7934 setValue( dlg.selectedOptions() );
7939void QgsProcessingPointCloudAttributePanelWidget::updateSummaryText()
7944 if ( mValue.empty() )
7946 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, 0 ) );
7951 values.reserve( mValue.size() );
7952 for (
const QVariant &val : std::as_const( mValue ) )
7954 values << val.toString();
7957 const QString concatenated = values.join( tr(
"," ) );
7958 if ( concatenated.length() < 100 )
7959 mLineEdit->setText( concatenated );
7961 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, mValue.count() ) );
7970QgsProcessingPointCloudAttributeParameterDefinitionWidget::QgsProcessingPointCloudAttributeParameterDefinitionWidget(
7975 QVBoxLayout *vlayout =
new QVBoxLayout();
7976 vlayout->setContentsMargins( 0, 0, 0, 0 );
7978 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
7979 mParentLayerComboBox =
new QComboBox();
7981 QString initialParent;
7983 initialParent = attrParam->parentLayerParameterName();
7985 if (
auto *lModel = widgetContext.
model() )
7988 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
7989 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
7993 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
7994 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
7996 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
8002 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
8005 mParentLayerComboBox->addItem( initialParent, initialParent );
8006 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
8009 vlayout->addWidget( mParentLayerComboBox );
8013 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple attributes" ) );
8015 mAllowMultipleCheckBox->setChecked( attrParam->allowMultiple() );
8017 vlayout->addWidget( mAllowMultipleCheckBox );
8020 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all attributes by default" ) );
8021 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
8023 mDefaultToAllCheckBox->setChecked( attrParam->defaultToAllAttributes() );
8027 vlayout->addWidget( mDefaultToAllCheckBox );
8029 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [
this] { mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() ); } );
8031 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
8033 mDefaultLineEdit =
new QLineEdit();
8034 mDefaultLineEdit->setToolTip( tr(
"Default attribute name, or ; separated list of attribute names for multiple attribute parameters" ) );
8038 mDefaultLineEdit->setText( attributes.join(
';' ) );
8040 vlayout->addWidget( mDefaultLineEdit );
8044 setLayout( vlayout );
8049 QVariant defaultValue;
8050 if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
8052 defaultValue = mDefaultLineEdit->text();
8054 auto param = std::make_unique<
8055 QgsProcessingParameterPointCloudAttribute>( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
8057 return param.release();
8064QWidget *QgsProcessingPointCloudAttributeWidgetWrapper::createWidget()
8077 mPanel =
new QgsProcessingPointCloudAttributePanelWidget(
nullptr, attrParam );
8078 mPanel->setToolTip( parameterDefinition()->toolTip() );
8079 connect( mPanel, &QgsProcessingPointCloudAttributePanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
8086 mComboBox->setToolTip( parameterDefinition()->toolTip() );
8094 mLineEdit =
new QLineEdit();
8095 mLineEdit->setToolTip( QObject::tr(
"Name of attribute (separate attribute names with ; for multiple attribute parameters)" ) );
8096 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
8103void QgsProcessingPointCloudAttributeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
8115 setParentLayerWrapperValue( wrapper );
8132 std::unique_ptr<QgsProcessingContext> tmpContext;
8133 if ( mProcessingContextGenerator )
8134 context = mProcessingContextGenerator->processingContext();
8138 tmpContext = std::make_unique<QgsProcessingContext>();
8139 context = tmpContext.get();
8145 if ( layer && layer->
isValid() )
8149 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
8152 mParentLayer.reset( qobject_cast<QgsPointCloudLayer *>( ownedLayer.release() ) );
8153 layer = mParentLayer.get();
8161 mComboBox->setLayer( layer );
8164 mPanel->setAttributes( layer->
attributes() );
8171 mComboBox->setLayer(
nullptr );
8176 if ( value.isValid() && widgetContext().messageBar() )
8187 val.reserve( mPanel->attributes().attributes().size() );
8190 setWidgetValue( val, *context );
8193 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
8196void QgsProcessingPointCloudAttributeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
8200 if ( !value.isValid() )
8201 mComboBox->setAttribute( QString() );
8205 mComboBox->setAttribute( v );
8211 if ( value.isValid() )
8214 opts.reserve( v.size() );
8215 for (
const QString &i : v )
8219 mPanel->setValue( opts );
8221 else if ( mLineEdit )
8227 mLineEdit->setText( v.join(
';' ) );
8236QVariant QgsProcessingPointCloudAttributeWidgetWrapper::widgetValue()
const
8239 return mComboBox->currentAttribute();
8241 return mPanel->value();
8242 else if ( mLineEdit )
8247 return mLineEdit->text().split(
';' );
8250 return mLineEdit->text();
8256QString QgsProcessingPointCloudAttributeWidgetWrapper::modelerExpressionFormatString()
const
8258 return tr(
"selected attribute names as an array of names, or semicolon separated string of options (e.g. 'X;Intensity')" );
8261QString QgsProcessingPointCloudAttributeWidgetWrapper::parameterType()
const
8268 return new QgsProcessingPointCloudAttributeWidgetWrapper( parameter, type );
8275 return new QgsProcessingPointCloudAttributeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
8287QWidget *QgsProcessingOutputWidgetWrapper::createWidget()
8295 mOutputWidget =
new QgsProcessingLayerOutputDestinationWidget( destParam,
false );
8296 if ( mProcessingContextGenerator )
8297 mOutputWidget->setContext( mProcessingContextGenerator->processingContext() );
8298 if ( mParametersGenerator )
8299 mOutputWidget->registerProcessingParametersGenerator( mParametersGenerator );
8300 mOutputWidget->setToolTip( parameterDefinition()->toolTip() );
8302 connect( mOutputWidget, &QgsProcessingLayerOutputDestinationWidget::destinationChanged,
this, [
this]() {
8303 if ( mBlockSignals )
8306 emit widgetValueHasChanged(
this );
8311 mOutputWidget->addOpenAfterRunningOption();
8313 return mOutputWidget;
8323void QgsProcessingOutputWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
8325 if ( mOutputWidget )
8326 mOutputWidget->setValue( value );
8329QVariant QgsProcessingOutputWidgetWrapper::widgetValue()
const
8331 if ( mOutputWidget )
8332 return mOutputWidget->value();
8337QVariantMap QgsProcessingOutputWidgetWrapper::customProperties()
const
8340 if ( mOutputWidget )
8341 res.insert( u
"OPEN_AFTER_RUNNING"_s, mOutputWidget->openAfterRunning() );
8350 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8353QString QgsProcessingFeatureSinkWidgetWrapper::parameterType()
const
8360 return new QgsProcessingFeatureSinkWidgetWrapper( parameter, type );
8363QString QgsProcessingFeatureSinkWidgetWrapper::modelerExpressionFormatString()
const
8365 return tr(
"path to layer destination" );
8373 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8376QString QgsProcessingVectorDestinationWidgetWrapper::parameterType()
const
8383 return new QgsProcessingVectorDestinationWidgetWrapper( parameter, type );
8386QString QgsProcessingVectorDestinationWidgetWrapper::modelerExpressionFormatString()
const
8388 return tr(
"path to layer destination" );
8396 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8399QString QgsProcessingRasterDestinationWidgetWrapper::parameterType()
const
8406 return new QgsProcessingRasterDestinationWidgetWrapper( parameter, type );
8409QString QgsProcessingRasterDestinationWidgetWrapper::modelerExpressionFormatString()
const
8411 return tr(
"path to layer destination" );
8419 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8422QString QgsProcessingPointCloudDestinationWidgetWrapper::parameterType()
const
8429 return new QgsProcessingPointCloudDestinationWidgetWrapper( parameter, type );
8432QString QgsProcessingPointCloudDestinationWidgetWrapper::modelerExpressionFormatString()
const
8434 return tr(
"path to layer destination" );
8442 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8445QString QgsProcessingFileDestinationWidgetWrapper::parameterType()
const
8452 return new QgsProcessingFileDestinationWidgetWrapper( parameter, type );
8456QString QgsProcessingFileDestinationWidgetWrapper::modelerExpressionFormatString()
const
8458 return tr(
"path to file destination" );
8466 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8469QString QgsProcessingFolderDestinationWidgetWrapper::parameterType()
const
8476 return new QgsProcessingFolderDestinationWidgetWrapper( parameter, type );
8480QString QgsProcessingFolderDestinationWidgetWrapper::modelerExpressionFormatString()
const
8482 return tr(
"path to folder destination" );
8490 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8493QString QgsProcessingVectorTileDestinationWidgetWrapper::parameterType()
const
8500 return new QgsProcessingPointCloudDestinationWidgetWrapper( parameter, type );
8503QString QgsProcessingVectorTileDestinationWidgetWrapper::modelerExpressionFormatString()
const
8505 return tr(
"path to layer destination" );
8513QgsHeatmapPixelSizeWidget::QgsHeatmapPixelSizeWidget( QWidget *parent )
8518 mCellXSpinBox->setShowClearButton(
false );
8519 mCellYSpinBox->setShowClearButton(
false );
8520 mRowsSpinBox->setShowClearButton(
false );
8521 mColumnsSpinBox->setShowClearButton(
false );
8523 connect( mCellYSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), mCellXSpinBox, &QgsDoubleSpinBox::setValue );
8524 connect( mCellXSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsHeatmapPixelSizeWidget::pixelSizeChanged );
8525 connect( mRowsSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, &QgsHeatmapPixelSizeWidget::rowsChanged );
8526 connect( mColumnsSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, &QgsHeatmapPixelSizeWidget::columnsChanged );
8533 mLayerBounds = mLayer->
extent();
8537 recalculateBounds();
8545void QgsHeatmapPixelSizeWidget::setRadius(
double radius )
8548 recalculateBounds();
8551void QgsHeatmapPixelSizeWidget::setRadiusField(
const QString &radiusField )
8553 mRadiusField = radiusField;
8554 recalculateBounds();
8557void QgsHeatmapPixelSizeWidget::recalculateBounds()
8559 mRasterBounds = mLayerBounds;
8563 double maxRadius = mRadius;
8564 if ( !mRadiusField.isEmpty() )
8566 const int idx = mLayer->fields().lookupField( mRadiusField );
8568 maxRadius = mLayer->maximumValue( idx ).toDouble();
8571 mRasterBounds.setXMinimum( mRasterBounds.xMinimum() - maxRadius );
8572 mRasterBounds.setYMinimum( mRasterBounds.yMinimum() - maxRadius );
8573 mRasterBounds.setXMaximum( mRasterBounds.xMaximum() + maxRadius );
8574 mRasterBounds.setYMaximum( mRasterBounds.yMaximum() + maxRadius );
8579void QgsHeatmapPixelSizeWidget::pixelSizeChanged()
8581 const double prevValue = value();
8582 const double cellSize = mCellXSpinBox->value();
8583 if ( cellSize <= 0 || mRasterBounds.isNull() )
8585 emit valueChanged();
8591 const int rows = std::max(
static_cast<int>( std::round( mRasterBounds.height() / cellSize ) ) + 1, 1 );
8592 const int cols = std::max(
static_cast<int>( std::round( mRasterBounds.width() / cellSize ) ) + 1, 1 );
8599 emit valueChanged();
8603void QgsHeatmapPixelSizeWidget::rowsChanged()
8605 const int rows = mRowsSpinBox->value();
8606 if ( rows <= 0 || mRasterBounds.isNull() )
8609 const double cellSize = mRasterBounds.height() / rows;
8610 if ( cellSize == 0 )
8613 const int cols = std::max(
static_cast<int>( std::round( mRasterBounds.width() / cellSize ) ) + 1, 1 );
8619 emit valueChanged();
8622void QgsHeatmapPixelSizeWidget::columnsChanged()
8624 const int cols = mColumnsSpinBox->value();
8625 if ( cols < 2 || mRasterBounds.isNull() )
8628 const double cellSize = mRasterBounds.width() / ( cols - 1 );
8629 if ( cellSize == 0 )
8632 const int rows = std::max(
static_cast<int>( std::round( mRasterBounds.height() / cellSize ) ), 1 );
8638 emit valueChanged();
8641double QgsHeatmapPixelSizeWidget::value()
const
8643 return mCellXSpinBox->value();
8646void QgsHeatmapPixelSizeWidget::setValue(
double value )
8648 mCellXSpinBox->setValue( value );
8649 mCellYSpinBox->setValue( value );
8660QString QgsProcessingHeatmapPixelSizeWidgetWrapper::parameterType()
const
8667 return new QgsProcessingHeatmapPixelSizeWidgetWrapper( parameter, type );
8677QWidget *QgsProcessingHeatmapPixelSizeWidgetWrapper::createWidget()
8683 mWidget =
new QgsHeatmapPixelSizeWidget();
8684 connect( mWidget, &QgsHeatmapPixelSizeWidget::valueChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
8692 mFallbackSpinBox->setShowClearButton(
false );
8693 mFallbackSpinBox->setMinimum( 0.0 );
8694 mFallbackSpinBox->setMaximum( 99999999999.0 );
8695 mFallbackSpinBox->setDecimals( 6 );
8696 mFallbackSpinBox->setToolTip( tr(
"Resolution of each pixel in output raster, in layer units" ) );
8697 connect( mFallbackSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
8698 return mFallbackSpinBox;
8704void QgsProcessingHeatmapPixelSizeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
8713 if ( !param || !mWidget )
8720 setParentLayerWrapperValue( wrapper );
8749 std::unique_ptr<QgsProcessingContext> tmpContext;
8750 if ( mProcessingContextGenerator )
8751 context = mProcessingContextGenerator->processingContext();
8755 tmpContext = std::make_unique<QgsProcessingContext>();
8756 context = tmpContext.get();
8760 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
8770 mWidget->setLayer(
nullptr );
8776 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
8779 mParentLayer = std::move( ownedLayer );
8787 mWidget->setLayer( layer );
8790void QgsProcessingHeatmapPixelSizeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
8793 mWidget->setValue( value.toDouble() );
8794 else if ( mFallbackSpinBox )
8795 mFallbackSpinBox->setValue( value.toDouble() );
8798QVariant QgsProcessingHeatmapPixelSizeWidgetWrapper::widgetValue()
const
8801 return mWidget->value();
8802 else if ( mFallbackSpinBox )
8803 return mFallbackSpinBox->value();
8807const QgsVectorLayer *QgsProcessingHeatmapPixelSizeWidgetWrapper::linkedVectorLayer()
const
8809 if ( mWidget && mWidget->layer() )
8810 return mWidget->layer();
8831QgsReliefColorsWidget::QgsReliefColorsWidget( QWidget *parent )
8836 connect( mButtonAdd, &QToolButton::clicked,
this, &QgsReliefColorsWidget::addClicked );
8837 connect( mButtonRemove, &QToolButton::clicked,
this, &QgsReliefColorsWidget::removeClicked );
8838 connect( mButtonUp, &QToolButton::clicked,
this, &QgsReliefColorsWidget::upClicked );
8839 connect( mButtonDown, &QToolButton::clicked,
this, &QgsReliefColorsWidget::downClicked );
8840 connect( mButtonLoad, &QToolButton::clicked,
this, &QgsReliefColorsWidget::loadClicked );
8841 connect( mButtonSave, &QToolButton::clicked,
this, &QgsReliefColorsWidget::saveClicked );
8842 connect( mButtonAuto, &QToolButton::clicked,
this, &QgsReliefColorsWidget::autoCalculate );
8843 connect( mReliefColorsWidget, &QTreeWidget::itemDoubleClicked,
this, &QgsReliefColorsWidget::itemDoubleClicked );
8853 return mLayer.data();
8856void QgsReliefColorsWidget::addClicked()
8858 auto item =
new QTreeWidgetItem();
8859 item->setText( 0, u
"0.00"_s );
8860 item->setText( 1, u
"0.00"_s );
8861 item->setBackground( 2, QBrush( QColor( 127, 127, 127 ) ) );
8862 mReliefColorsWidget->addTopLevelItem( item );
8863 emit valueChanged();
8866void QgsReliefColorsWidget::removeClicked()
8868 const QList<QTreeWidgetItem *> selectedItems = mReliefColorsWidget->selectedItems();
8869 for ( QTreeWidgetItem *item : std::as_const( selectedItems ) )
8873 emit valueChanged();
8876void QgsReliefColorsWidget::downClicked()
8878 const QList<QTreeWidgetItem *> selectedItems = mReliefColorsWidget->selectedItems();
8879 for ( QTreeWidgetItem *item : std::as_const( selectedItems ) )
8881 const int currentIndex = mReliefColorsWidget->indexOfTopLevelItem( item );
8882 if ( currentIndex >= 0 && currentIndex < mReliefColorsWidget->topLevelItemCount() - 1 )
8884 mReliefColorsWidget->takeTopLevelItem( currentIndex );
8885 mReliefColorsWidget->insertTopLevelItem( currentIndex + 1, item );
8886 mReliefColorsWidget->setCurrentItem( item );
8889 emit valueChanged();
8892void QgsReliefColorsWidget::upClicked()
8894 const QList<QTreeWidgetItem *> selectedItems = mReliefColorsWidget->selectedItems();
8895 for ( QTreeWidgetItem *item : std::as_const( selectedItems ) )
8897 const int currentIndex = mReliefColorsWidget->indexOfTopLevelItem( item );
8898 if ( currentIndex > 0 )
8900 mReliefColorsWidget->takeTopLevelItem( currentIndex );
8901 mReliefColorsWidget->insertTopLevelItem( currentIndex - 1, item );
8902 mReliefColorsWidget->setCurrentItem( item );
8905 emit valueChanged();
8908void QgsReliefColorsWidget::loadClicked()
8910 const QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Import Colors from XML" ), QDir::homePath(), tr(
"XML files (*.xml *.XML)" ) );
8911 if ( fileName.isEmpty() )
8914 QFile file( fileName );
8915 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
8919 if ( !doc.setContent( &file ) )
8921 QMessageBox::critical(
this, tr(
"Import Colors from XML" ), tr(
"The XML file could not be loaded" ) );
8925 mReliefColorsWidget->clear();
8926 const QDomNodeList reliefColorList = doc.elementsByTagName( u
"ReliefColor"_s );
8927 for (
int i = 0; i < reliefColorList.length(); ++i )
8929 const QDomElement elem = reliefColorList.at( i ).toElement();
8930 auto item =
new QTreeWidgetItem();
8931 item->setText( 0, elem.attribute( u
"MinElevation"_s ) );
8932 item->setText( 1, elem.attribute( u
"MaxElevation"_s ) );
8933 item->setBackground( 2, QBrush( QColor( elem.attribute( u
"red"_s ).toInt(), elem.attribute( u
"green"_s ).toInt(), elem.attribute( u
"blue"_s ).toInt() ) ) );
8934 mReliefColorsWidget->addTopLevelItem( item );
8936 emit valueChanged();
8939void QgsReliefColorsWidget::saveClicked()
8941 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Export Colors as XML" ), QDir::homePath(), tr(
"XML files (*.xml *.XML)" ) );
8942 if ( fileName.isEmpty() )
8948 QDomElement colorsElem = doc.createElement( u
"ReliefColors"_s );
8949 doc.appendChild( colorsElem );
8951 const QList<QgsRasterReliefColor> currentColors = colors();
8954 QDomElement elem = doc.createElement( u
"ReliefColor"_s );
8957 elem.setAttribute( u
"red"_s, QString::number(
c.color.red() ) );
8958 elem.setAttribute( u
"green"_s, QString::number(
c.color.green() ) );
8959 elem.setAttribute( u
"blue"_s, QString::number(
c.color.blue() ) );
8960 colorsElem.appendChild( elem );
8963 QFile file( fileName );
8964 if ( file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
8966 QTextStream out( &file );
8967 out << doc.toString( 2 );
8971void QgsReliefColorsWidget::autoCalculate()
8973 if ( !mLayer || !mLayer->isValid() )
8977 setColors( autoColors );
8978 emit valueChanged();
8981void QgsReliefColorsWidget::itemDoubleClicked( QTreeWidgetItem *item,
int column )
8989 const double d = QInputDialog::getDouble(
this, tr(
"Enter lower elevation class bound" ), tr(
"Elevation" ), item->text( 0 ).toDouble(), -2147483647, 2147483647, 2, &ok );
8992 item->setText( 0, QString::number( d ) );
8993 emit valueChanged();
8996 else if ( column == 1 )
8998 const double d = QInputDialog::getDouble(
this, tr(
"Enter upper elevation class bound" ), tr(
"Elevation" ), item->text( 1 ).toDouble(), -2147483647, 2147483647, 2, &ok );
9001 item->setText( 1, QString::number( d ) );
9002 emit valueChanged();
9005 else if ( column == 2 )
9007 const QColor
c = QColorDialog::getColor( item->background( 2 ).color(),
this, tr(
"Select color for relief class" ) );
9010 item->setBackground( 2, QBrush(
c ) );
9011 emit valueChanged();
9016QList<QgsRasterReliefColor> QgsReliefColorsWidget::colors()
const
9018 QList<QgsRasterReliefColor> colors;
9019 for (
int i = 0; i < mReliefColorsWidget->topLevelItemCount(); ++i )
9021 if ( QTreeWidgetItem *item = mReliefColorsWidget->topLevelItem( i ) )
9023 colors.append(
QgsRasterReliefColor( item->background( 2 ).color(), item->text( 0 ).toDouble(), item->text( 1 ).toDouble() ) );
9029void QgsReliefColorsWidget::setColors(
const QList<QgsRasterReliefColor> &colors )
9031 mReliefColorsWidget->clear();
9034 auto item =
new QTreeWidgetItem();
9037 item->setBackground( 2, QBrush(
c.color ) );
9038 mReliefColorsWidget->addTopLevelItem( item );
9040 emit valueChanged();
9051QString QgsProcessingReliefColorsWidgetWrapper::parameterType()
const
9058 return new QgsProcessingReliefColorsWidgetWrapper( parameter, type );
9068QWidget *QgsProcessingReliefColorsWidgetWrapper::createWidget()
9074 mWidget =
new QgsReliefColorsWidget();
9075 connect( mWidget, &QgsReliefColorsWidget::valueChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
9082 mFallbackLineEdit =
new QLineEdit();
9083 mFallbackLineEdit->setPlaceholderText( tr(
"Relief colors definition" ) );
9084 connect( mFallbackLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
9085 return mFallbackLineEdit;
9091void QgsProcessingReliefColorsWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
9100 if ( !param || !mWidget )
9107 setParentLayerWrapperValue( wrapper );
9126 std::unique_ptr<QgsProcessingContext> tmpContext;
9127 if ( mProcessingContextGenerator )
9128 context = mProcessingContextGenerator->processingContext();
9132 tmpContext = std::make_unique<QgsProcessingContext>();
9133 context = tmpContext.get();
9138 if ( layer && layer->
isValid() )
9142 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
9145 mParentLayer.reset( qobject_cast<QgsRasterLayer *>( ownedLayer.release() ) );
9146 layer = mParentLayer.get();
9154 mWidget->setLayer( layer );
9159 mWidget->setLayer(
nullptr );
9163void QgsProcessingReliefColorsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
9167 if ( mWidget && param )
9169 mWidget->setColors( param->valueAsReliefColors( value, context ) );
9171 else if ( mFallbackLineEdit )
9172 mFallbackLineEdit->setText( value.toString() );
9175QVariant QgsProcessingReliefColorsWidgetWrapper::widgetValue()
const
9179 else if ( mFallbackLineEdit )
9180 return mFallbackLineEdit->text();
9184QString QgsProcessingReliefColorsWidgetWrapper::modelerExpressionFormatString()
const
9186 return tr(
"string of the format 'min,max,red,green,blue' for each relief color, joined by a ; delimiter" );
9194QgsExecuteSqlWidget::QgsExecuteSqlWidget( QWidget *parent )
9197 QVBoxLayout *mainLayout =
new QVBoxLayout(
this );
9198 mainLayout->setContentsMargins( 0, 0, 0, 0 );
9200 mTextEdit =
new QPlainTextEdit(
this );
9201 mainLayout->addWidget( mTextEdit, 1 );
9203 QHBoxLayout *bottomLayout =
new QHBoxLayout();
9204 bottomLayout->setContentsMargins( 0, 0, 0, 0 );
9207 bottomLayout->addWidget( mExpressionWidget, 1 );
9209 mInsertButton =
new QPushButton( tr(
"Insert" ),
this );
9210 bottomLayout->addWidget( mInsertButton );
9212 mainLayout->addLayout( bottomLayout );
9214 connect( mInsertButton, &QPushButton::clicked,
this, &QgsExecuteSqlWidget::insertExpression );
9215 connect( mTextEdit, &QPlainTextEdit::textChanged,
this, &QgsExecuteSqlWidget::changed );
9218void QgsExecuteSqlWidget::insertExpression()
9220 if ( !mExpressionWidget->currentText().isEmpty() )
9222 const QString formattedExpression = u
"[% %1 %]"_s.arg( mExpressionWidget->currentText() );
9223 mTextEdit->insertPlainText( formattedExpression );
9227void QgsExecuteSqlWidget::setValue(
const QString &text )
9229 if ( text == value() )
9232 mTextEdit->setPlainText( text );
9235QString QgsExecuteSqlWidget::value()
const
9237 return mTextEdit->toPlainText();
9248QString QgsProcessingExecuteSqlWidgetWrapper::parameterType()
const
9250 return u
"executesql"_s;
9255 return new QgsProcessingExecuteSqlWidgetWrapper( parameter, type );
9258QWidget *QgsProcessingExecuteSqlWidgetWrapper::createWidget()
9260 mExecuteSqlWidget =
new QgsExecuteSqlWidget();
9261 mExecuteSqlWidget->expressionWidget()->registerExpressionContextGenerator(
this );
9263 if ( parameterDefinition() )
9265 mExecuteSqlWidget->setToolTip( parameterDefinition()->toolTip() );
9268 connect( mExecuteSqlWidget, &QgsExecuteSqlWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
9270 return mExecuteSqlWidget;
9273void QgsProcessingExecuteSqlWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
9275 if ( !mExecuteSqlWidget )
9281 mExecuteSqlWidget->setValue( sqlText );
9284QVariant QgsProcessingExecuteSqlWidgetWrapper::widgetValue()
const
9286 if ( !mExecuteSqlWidget )
9291 return mExecuteSqlWidget->value();
9298QgsInterpolationSourceWidget::QgsInterpolationSourceWidget( QWidget *parent )
9306 connect( btnAdd, &QToolButton::clicked,
this, &QgsInterpolationSourceWidget::addLayer );
9307 connect( btnRemove, &QToolButton::clicked,
this, &QgsInterpolationSourceWidget::removeLayer );
9314 layerChanged( qobject_cast< QgsVectorLayer * >( cmbLayers->currentLayer() ) );
9317void QgsInterpolationSourceWidget::addLayer()
9319 QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( cmbLayers->currentLayer() );
9325 const QString attribute = chkUseZCoordinate->isChecked() ? u
"Z_COORD"_s : cmbFields->currentField();
9326 addLayerData( layer, attribute );
9330void QgsInterpolationSourceWidget::removeLayer()
9332 QTreeWidgetItem *item = layersTree->currentItem();
9341void QgsInterpolationSourceWidget::layerChanged(
QgsVectorLayer *layer )
9343 chkUseZCoordinate->setEnabled(
false );
9344 chkUseZCoordinate->setChecked(
false );
9346 if ( !layer || !layer->
isValid() )
9353 chkUseZCoordinate->setEnabled(
true );
9356 cmbFields->setLayer( layer );
9359void QgsInterpolationSourceWidget::addLayerData(
QgsVectorLayer *layer,
const QString &attribute )
9361 QTreeWidgetItem *item =
new QTreeWidgetItem();
9362 item->setText( 0, layer->
name() );
9363 item->setText( 1, attribute );
9364 item->setData( 0, Qt::UserRole, layer->
source() );
9365 layersTree->addTopLevelItem( item );
9367 QComboBox *comboBox =
new QComboBox();
9371 comboBox->setCurrentIndex( 0 );
9372 layersTree->setItemWidget( item, 2, comboBox );
9375void QgsInterpolationSourceWidget::setValue(
const QVariant &value,
QgsProcessingContext &context )
9377 layersTree->clear();
9378 const QStringList rows = value.toString().split(
"::|::"_L1, Qt::SkipEmptyParts );
9380 for (
const QString &row : rows )
9382 const QStringList tokens = row.split(
"::~::"_L1 );
9383 if ( tokens.size() < 4 )
9388 const QString layerSource = tokens.at( 0 );
9390 if ( !layer || !layer->
isValid() )
9394 const int fieldIndexInt = tokens.at( 2 ).toInt( &isInt );
9395 if ( isInt && fieldIndexInt == -1 )
9397 addLayerData( layer, u
"Z_COORD"_s );
9401 addLayerData( layer, layer->
fields().
at( fieldIndexInt ).
name() );
9405 addLayerData( layer, tokens.at( 2 ) );
9409 QComboBox *comboBox = qobject_cast<QComboBox *>( layersTree->itemWidget( layersTree->topLevelItem( itemIndex ), 2 ) );
9412 comboBox->setCurrentIndex( comboBox->findData( QVariant::fromValue( sourceType ) ) );
9419QVariant QgsInterpolationSourceWidget::value()
const
9422 for (
int index = 0; index < layersTree->topLevelItemCount(); ++index )
9424 QTreeWidgetItem *item = layersTree->topLevelItem( index );
9430 const QString layerSource = item->data( 0, Qt::UserRole ).toString();
9431 QString interpolationAttribute = item->text( 1 );
9434 if ( interpolationAttribute ==
"Z_COORD"_L1 )
9437 interpolationAttribute = u
"-1"_s;
9440 QComboBox *comboBox = qobject_cast<QComboBox *>( layersTree->itemWidget( item, 2 ) );
9441 const int inputType = comboBox ?
static_cast< int >( comboBox->currentData().value< Qgis::InterpolationSourceType >() ) : 0;
9443 result << u
"%1::~::%2::~::%3::~::%4"_s.arg( layerSource ).arg( valueSource ).arg( interpolationAttribute ).arg( inputType );
9446 if ( result.isEmpty() )
9449 return result.join(
"::|::"_L1 );
9461QString QgsProcessingInterpolationSourceWidgetWrapper::parameterType()
const
9468 return new QgsProcessingInterpolationSourceWidgetWrapper( parameter, type );
9478QWidget *QgsProcessingInterpolationSourceWidgetWrapper::createWidget()
9480 mWidget =
new QgsInterpolationSourceWidget();
9481 if ( parameterDefinition() )
9483 mWidget->setToolTip( parameterDefinition()->toolTip() );
9486 connect( mWidget, &QgsInterpolationSourceWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
9490void QgsProcessingInterpolationSourceWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
9494 mWidget->setValue( value, context );
9498QVariant QgsProcessingInterpolationSourceWidgetWrapper::widgetValue()
const
9500 return mWidget ? mWidget->value() : QVariant();
9508QgsInterpolationPixelSizeWidget::QgsInterpolationPixelSizeWidget( QWidget *parent )
9513 mCellXSpinBox->setShowClearButton(
false );
9514 mCellYSpinBox->setShowClearButton(
false );
9515 mRowsSpinBox->setShowClearButton(
false );
9516 mColumnsSpinBox->setShowClearButton(
false );
9518 connect( mCellYSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), mCellXSpinBox, &QgsDoubleSpinBox::setValue );
9519 connect( mCellXSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsInterpolationPixelSizeWidget::pixelSizeChanged );
9520 connect( mRowsSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, &QgsInterpolationPixelSizeWidget::rowsChanged );
9521 connect( mColumnsSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, &QgsInterpolationPixelSizeWidget::columnsChanged );
9524void QgsInterpolationPixelSizeWidget::setSourceData(
const QString &sourceData,
QgsProcessingContext &context )
9527 const QStringList rows = sourceData.split(
"::|::"_L1, Qt::SkipEmptyParts );
9528 for (
const QString &row : rows )
9530 const QStringList tokens = row.split(
"::~::"_L1 );
9531 if ( tokens.isEmpty() )
9539 mExtent.combineExtentWith( source->sourceExtent() );
9546void QgsInterpolationPixelSizeWidget::setExtent(
const QgsRectangle &extent )
9552void QgsInterpolationPixelSizeWidget::pixelSizeChanged()
9554 const double prevValue = value();
9555 const double cellSize = mCellXSpinBox->value();
9558 emit valueChanged();
9564 const int rows = std::max(
static_cast<int>( std::round( mExtent.height() / cellSize ) ) + 1, 1 );
9565 const int cols = std::max(
static_cast<int>( std::round( mExtent.width() / cellSize ) ) + 1, 1 );
9572 emit valueChanged();
9576void QgsInterpolationPixelSizeWidget::rowsChanged()
9578 const int rows = mRowsSpinBox->value();
9579 if ( rows <= 0 || mExtent.isNull() )
9582 const double cellSize = mExtent.height() / rows;
9586 const int cols = std::max(
static_cast<int>( std::round( mExtent.width() / cellSize ) ) + 1, 1 );
9592 emit valueChanged();
9595void QgsInterpolationPixelSizeWidget::columnsChanged()
9597 const int cols = mColumnsSpinBox->value();
9598 if ( cols < 2 || mExtent.isNull() )
9601 const double cellSize = mExtent.width() / ( cols - 1 );
9605 const int rows = std::max(
static_cast<int>( std::round( mExtent.height() / cellSize ) ), 1 );
9611 emit valueChanged();
9614double QgsInterpolationPixelSizeWidget::value()
const
9616 return mCellXSpinBox->value();
9619void QgsInterpolationPixelSizeWidget::setValue(
double value )
9621 mCellXSpinBox->setValue( value );
9622 mCellYSpinBox->setValue( value );
9634QString QgsProcessingInterpolationPixelSizeWidgetWrapper::parameterType()
const
9641 return new QgsProcessingInterpolationPixelSizeWidgetWrapper( parameter, type );
9651QWidget *QgsProcessingInterpolationPixelSizeWidgetWrapper::createWidget()
9657 mWidget =
new QgsInterpolationPixelSizeWidget();
9658 connect( mWidget, &QgsInterpolationPixelSizeWidget::valueChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
9666 mFallbackSpinBox->setShowClearButton(
false );
9667 mFallbackSpinBox->setMinimum( 0.0 );
9668 mFallbackSpinBox->setMaximum( 99999999999.0 );
9669 mFallbackSpinBox->setDecimals( 6 );
9670 mFallbackSpinBox->setToolTip( tr(
"Resolution of each pixel in output raster" ) );
9671 connect( mFallbackSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
9672 return mFallbackSpinBox;
9678void QgsProcessingInterpolationPixelSizeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
9687 if ( !param || !mWidget )
9694 sourceChanged( wrapper );
9699 extentChanged( wrapper );
9711void QgsProcessingInterpolationPixelSizeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
9714 mWidget->setValue( value.toDouble() );
9715 else if ( mFallbackSpinBox )
9716 mFallbackSpinBox->setValue( value.toDouble() );
9719QVariant QgsProcessingInterpolationPixelSizeWidgetWrapper::widgetValue()
const
9722 return mWidget->value();
9723 else if ( mFallbackSpinBox )
9724 return mFallbackSpinBox->value();
9733 std::unique_ptr<QgsProcessingContext> tmpContext;
9734 if ( mProcessingContextGenerator )
9735 context = mProcessingContextGenerator->processingContext();
9739 tmpContext = std::make_unique<QgsProcessingContext>();
9740 context = tmpContext.get();
9743 mWidget->setSourceData( wrapper->
parameterValue().toString(), *context );
9752 std::unique_ptr<QgsProcessingContext> tmpContext;
9753 if ( mProcessingContextGenerator )
9754 context = mProcessingContextGenerator->processingContext();
9758 tmpContext = std::make_unique<QgsProcessingContext>();
9759 context = tmpContext.get();
9764 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 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 setFlags(Qgis::ProcessingParameterFlags flags)
Sets the flags associated with the parameter.
QVariantMap metadata() const
Returns the parameter's freeform metadata.
QString description() const
Returns the description for the parameter.
QVariant defaultValueForGui() const
Returns the default value to use for the parameter in a GUI.
virtual QString type() const =0
Unique parameter type name.
QString name() const
Returns the name of the parameter.
Qgis::ProcessingParameterFlags flags() const
Returns any flags associated with the parameter.
A double numeric parameter for distance values.
static QString typeName()
Returns the type name for the parameter class.
Qgis::DistanceUnit defaultUnit() const
Returns the default distance unit for the parameter.
A double numeric parameter for duration values.
Qgis::TemporalUnit defaultUnit() const
Returns the default duration unit for the parameter.
static QString typeName()
Returns the type name for the parameter class.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
bool allowMultiple() const
Returns true if the parameter allows multiple selected values.
QStringList options() const
Returns the list of acceptable options for the parameter.
bool usesStaticStrings() const
Returns true if the parameter uses static (non-translated) string values for its enumeration choice l...
static QString typeName()
Returns the type name for the parameter class.
An expression parameter for processing algorithms.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
static QString typeName()
Returns the type name for the parameter class.
Qgis::ExpressionType expressionType() const
Returns the parameter's expression type.
A rectangular map extent parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
An input feature source (such as vector layers) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A vector layer or feature source field parameter for processing algorithms.
Qgis::ProcessingFieldParameterDataType dataType() const
Returns the acceptable data type for the field.
bool allowMultiple() const
Returns whether multiple field selections are permitted.
bool defaultToAllFields() const
Returns whether a parameter which allows multiple selections (see allowMultiple()) should automatical...
static QString typeName()
Returns the type name for the parameter class.
void setDataType(Qgis::ProcessingFieldParameterDataType type)
Sets the acceptable data type for the field.
static QString typeName()
Returns the type name for the parameter class.
An input file or folder parameter for processing algorithms.
QString extension() const
Returns any specified file extension for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QString fileFilter() const
Returns the file filter string for file destinations compatible with this parameter.
Qgis::ProcessingFileParameterBehavior behavior() const
Returns the parameter behavior (e.g.
static QString typeName()
Returns the type name for the parameter class.
A geometry parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A parameter for the heatmap algorithm pixel size parameter.
static QString typeName()
Returns the type name for the parameter class.
A 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.
static QString typeName()
Returns the type name for the parameter class.
A vector layer (with or without geometry) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A double numeric parameter for volume values.
static QString typeName()
Returns the type name for the parameter class.
Qgis::VolumeUnit defaultUnit() const
Returns the default volume unit for the parameter.
Contains settings which reflect the context in which a Processing parameter widget is shown.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QgsProject * project() const
Returns the project associated with the widget.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
QgsProcessingModelAlgorithm * model() const
Returns the model which the parameter widget is associated with.
QgsMapLayer * activeLayer() const
Returns the current active layer.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a list of map layers.
static QTime parameterAsTime(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static time value.
static QgsRectangle parameterAsExtent(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent.
static QString parameterAsEnumString(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static enum string.
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
static QStringList parameterAsStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of strings (e.g.
static QList< int > parameterAsInts(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of integer values.
static QString parameterAsConnectionName(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a connection name string.
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
static QgsPointCloudLayer * parameterAsPointCloudLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a point cloud layer.
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
static QgsLayoutItem * parameterAsLayoutItem(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsPrintLayout *layout)
Evaluates the parameter with matching definition to a print layout item, taken from the specified lay...
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QColor parameterAsColor(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the color associated with an point parameter value, or an invalid color if the parameter was ...
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
static int parameterAsInt(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static integer value.
static QString parameterAsDatabaseTableName(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database table name.
static QString parameterAsSchema(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database schema name.
static QgsGeometry parameterAsGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a geometry.
static QString parameterAsExpression(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to an expression.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
static QgsRasterLayer * parameterAsRasterLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a raster layer.
static QList< int > parameterAsEnums(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of enum values.
static QStringList parameterAsEnumStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of static enum strings.
static QgsCoordinateReferenceSystem parameterAsExtentCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
static QDateTime parameterAsDateTime(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static datetime value.
static QDate parameterAsDate(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static date value.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
Utility functions for use with processing classes.
@ Annotation
Annotation layer type, since QGIS 3.22.
@ 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.