84#include <QButtonGroup>
89#include <QInputDialog>
94#include <QPlainTextEdit>
95#include <QRadioButton>
100#include "moc_qgsprocessingwidgetwrapperimpl.cpp"
102using namespace Qt::StringLiterals;
111QgsProcessingBooleanParameterDefinitionWidget::QgsProcessingBooleanParameterDefinitionWidget(
116 QVBoxLayout *vlayout =
new QVBoxLayout();
117 vlayout->setContentsMargins( 0, 0, 0, 0 );
119 mDefaultCheckBox =
new QCheckBox( tr(
"Checked" ) );
123 mDefaultCheckBox->setChecked(
false );
124 vlayout->addWidget( mDefaultCheckBox );
127 setLayout( vlayout );
132 auto param = std::make_unique<QgsProcessingParameterBoolean>( name, description, mDefaultCheckBox->isChecked() );
133 param->setFlags( flags );
134 return param.release();
142QWidget *QgsProcessingBooleanWidgetWrapper::createWidget()
148 QString description = parameterDefinition()->description();
150 description = QObject::tr(
"%1 [optional]" ).arg( description );
152 mCheckBox =
new QCheckBox( description );
153 mCheckBox->setToolTip( parameterDefinition()->toolTip() );
155 connect( mCheckBox, &QCheckBox::toggled,
this, [
this] { emit widgetValueHasChanged(
this ); } );
162 mComboBox =
new QComboBox();
163 mComboBox->addItem( tr(
"Yes" ),
true );
164 mComboBox->addItem( tr(
"No" ),
false );
165 mComboBox->setToolTip( parameterDefinition()->toolTip() );
167 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
175QLabel *QgsProcessingBooleanWidgetWrapper::createLabel()
184void QgsProcessingBooleanWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
191 mCheckBox->setChecked( v );
199 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
205QVariant QgsProcessingBooleanWidgetWrapper::widgetValue()
const
210 return mCheckBox->isChecked();
214 return mComboBox->currentData();
219QString QgsProcessingBooleanWidgetWrapper::parameterType()
const
226 return new QgsProcessingBooleanWidgetWrapper( parameter, type );
233 return new QgsProcessingBooleanParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
241QgsProcessingCrsParameterDefinitionWidget::QgsProcessingCrsParameterDefinitionWidget(
246 QVBoxLayout *vlayout =
new QVBoxLayout();
247 vlayout->setContentsMargins( 0, 0, 0, 0 );
249 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
254 mCrsSelector->setShowAccuracyWarnings(
true );
261 vlayout->addWidget( mCrsSelector );
262 setLayout( vlayout );
267 auto param = std::make_unique<QgsProcessingParameterCrs>( name, description, mCrsSelector->crs().authid() );
268 param->setFlags( flags );
269 return param.release();
276QWidget *QgsProcessingCrsWidgetWrapper::createWidget()
278 Q_ASSERT( mProjectionSelectionWidget ==
nullptr );
280 mProjectionSelectionWidget->setToolTip( parameterDefinition()->toolTip() );
294 return mProjectionSelectionWidget;
299 QWidget *w =
new QWidget();
300 w->setToolTip( parameterDefinition()->toolTip() );
302 QVBoxLayout *vl =
new QVBoxLayout();
303 vl->setContentsMargins( 0, 0, 0, 0 );
306 mUseProjectCrsCheckBox =
new QCheckBox( tr(
"Use project CRS" ) );
307 mUseProjectCrsCheckBox->setToolTip( tr(
"Always use the current project CRS when running the model" ) );
308 vl->addWidget( mUseProjectCrsCheckBox );
309 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, mProjectionSelectionWidget, &QgsProjectionSelectionWidget::setDisabled );
310 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled,
this, [
this] { emit widgetValueHasChanged(
this ); } );
312 vl->addWidget( mProjectionSelectionWidget );
320void QgsProcessingCrsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
322 if ( mUseProjectCrsCheckBox )
324 if ( value.toString().compare(
"ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
326 mUseProjectCrsCheckBox->setChecked(
true );
331 mUseProjectCrsCheckBox->setChecked(
false );
336 if ( mProjectionSelectionWidget )
337 mProjectionSelectionWidget->setCrs( v );
340QVariant QgsProcessingCrsWidgetWrapper::widgetValue()
const
342 if ( mUseProjectCrsCheckBox && mUseProjectCrsCheckBox->isChecked() )
343 return u
"ProjectCrs"_s;
344 else if ( mProjectionSelectionWidget )
345 return mProjectionSelectionWidget->crs().isValid() ? mProjectionSelectionWidget->crs() : QVariant();
350QString QgsProcessingCrsWidgetWrapper::modelerExpressionFormatString()
const
352 return tr(
"string as EPSG code, WKT or PROJ format, or a string identifying a map layer" );
355QString QgsProcessingCrsWidgetWrapper::parameterType()
const
362 return new QgsProcessingCrsWidgetWrapper( parameter, type );
369 return new QgsProcessingCrsParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
378QgsProcessingStringParameterDefinitionWidget::QgsProcessingStringParameterDefinitionWidget(
383 QVBoxLayout *vlayout =
new QVBoxLayout();
384 vlayout->setContentsMargins( 0, 0, 0, 0 );
386 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
388 mDefaultLineEdit =
new QLineEdit();
391 vlayout->addWidget( mDefaultLineEdit );
395 mMultiLineCheckBox =
new QCheckBox( tr(
"Multiline input" ) );
397 mMultiLineCheckBox->setChecked( stringParam->multiLine() );
398 vlayout->addWidget( mMultiLineCheckBox );
402 setLayout( vlayout );
407 auto param = std::make_unique<QgsProcessingParameterString>( name, description, mDefaultLineEdit->text(), mMultiLineCheckBox->isChecked() );
408 param->setFlags( flags );
409 return param.release();
417QWidget *QgsProcessingStringWidgetWrapper::createWidget()
419 const QVariantMap metadata = parameterDefinition()->metadata();
420 const QVariant valueHintsVariant = metadata.value( u
"widget_wrapper"_s ).toMap().value( u
"value_hints"_s );
422 if ( valueHintsVariant.isValid() )
424 const QVariantList valueList = valueHintsVariant.toList();
425 mComboBox =
new QComboBox();
426 mComboBox->setToolTip( parameterDefinition()->toolTip() );
430 mComboBox->addItem( QString() );
432 for (
const QVariant &entry : valueList )
434 mComboBox->addItem( entry.toString(), entry.toString() );
436 mComboBox->setCurrentIndex( 0 );
438 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
450 mPlainTextEdit =
new QPlainTextEdit();
451 mPlainTextEdit->setToolTip( parameterDefinition()->toolTip() );
453 connect( mPlainTextEdit, &QPlainTextEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
454 return mPlainTextEdit;
458 mLineEdit =
new QLineEdit();
459 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
461 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
468 mLineEdit =
new QLineEdit();
469 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
471 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
480void QgsProcessingStringWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
484 mLineEdit->setText( v );
485 if ( mPlainTextEdit )
486 mPlainTextEdit->setPlainText( v );
490 if ( !value.isValid() )
491 index = mComboBox->findData( QVariant() );
493 index = mComboBox->findData( v );
496 mComboBox->setCurrentIndex( index );
498 mComboBox->setCurrentIndex( 0 );
502QVariant QgsProcessingStringWidgetWrapper::widgetValue()
const
505 return mLineEdit->text();
506 else if ( mPlainTextEdit )
507 return mPlainTextEdit->toPlainText();
508 else if ( mComboBox )
509 return mComboBox->currentData();
514QString QgsProcessingStringWidgetWrapper::parameterType()
const
521 return new QgsProcessingStringWidgetWrapper( parameter, type );
528 return new QgsProcessingStringParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
540QWidget *QgsProcessingAuthConfigWidgetWrapper::createWidget()
549 mAuthConfigSelect->setToolTip( parameterDefinition()->toolTip() );
552 return mAuthConfigSelect;
558void QgsProcessingAuthConfigWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
561 if ( mAuthConfigSelect )
562 mAuthConfigSelect->setConfigId( v );
565QVariant QgsProcessingAuthConfigWidgetWrapper::widgetValue()
const
567 if ( mAuthConfigSelect )
568 return mAuthConfigSelect->configId();
573QString QgsProcessingAuthConfigWidgetWrapper::parameterType()
const
580 return new QgsProcessingAuthConfigWidgetWrapper( parameter, type );
587QgsProcessingNumberParameterDefinitionWidget::QgsProcessingNumberParameterDefinitionWidget(
592 QVBoxLayout *vlayout =
new QVBoxLayout();
593 vlayout->setContentsMargins( 0, 0, 0, 0 );
595 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
597 mTypeComboBox =
new QComboBox();
600 vlayout->addWidget( mTypeComboBox );
602 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
603 mMinLineEdit =
new QLineEdit();
604 vlayout->addWidget( mMinLineEdit );
606 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
607 mMaxLineEdit =
new QLineEdit();
608 vlayout->addWidget( mMaxLineEdit );
610 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
611 mDefaultLineEdit =
new QLineEdit();
612 vlayout->addWidget( mDefaultLineEdit );
616 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( numberParam->dataType() ) ) );
618 if ( !
qgsDoubleNear( numberParam->maximum(), std::numeric_limits<double>::max() ) )
620 mMaxLineEdit->setText( QLocale().toString( numberParam->maximum() ) );
624 mMaxLineEdit->clear();
627 if ( !
qgsDoubleNear( numberParam->minimum(), std::numeric_limits<double>::lowest() ) )
629 mMinLineEdit->setText( QLocale().toString( numberParam->minimum() ) );
633 mMinLineEdit->clear();
636 mDefaultLineEdit->setText( numberParam->defaultValueForGui().toString() );
644 setLayout( vlayout );
653 auto param = std::make_unique<QgsProcessingParameterNumber>( name, description, dataType, ok ? val : QVariant() );
655 if ( !mMinLineEdit->text().trimmed().isEmpty() )
660 param->setMinimum( val );
664 if ( !mMaxLineEdit->text().trimmed().isEmpty() )
669 param->setMaximum( val );
673 param->setFlags( flags );
674 return param.release();
681QWidget *QgsProcessingNumericWidgetWrapper::createWidget()
684 const QVariantMap metadata = numberDef->
metadata();
685 const int decimals = metadata.value( u
"widget_wrapper"_s ).toMap().value( u
"decimals"_s, 6 ).toInt();
693 QAbstractSpinBox *spinBox =
nullptr;
698 mDoubleSpinBox->setExpressionsEnabled(
true );
699 mDoubleSpinBox->setDecimals( decimals );
704 double singleStep = calculateStep( numberDef->
minimum(), numberDef->
maximum() );
705 singleStep = std::max( singleStep, std::pow( 10, -decimals ) );
706 mDoubleSpinBox->setSingleStep( singleStep );
709 spinBox = mDoubleSpinBox;
714 mSpinBox->setExpressionsEnabled(
true );
718 spinBox->setToolTip( parameterDefinition()->toolTip() );
720 double max = 999999999;
725 double min = -999999999;
730 if ( mDoubleSpinBox )
732 mDoubleSpinBox->setMinimum( min );
733 mDoubleSpinBox->setMaximum( max );
737 mSpinBox->setMinimum(
static_cast<int>( min ) );
738 mSpinBox->setMaximum(
static_cast<int>( max ) );
743 mAllowingNull =
true;
744 if ( mDoubleSpinBox )
746 mDoubleSpinBox->setShowClearButton(
true );
747 const double min = mDoubleSpinBox->minimum() - mDoubleSpinBox->singleStep();
748 mDoubleSpinBox->setMinimum( min );
749 mDoubleSpinBox->setValue( min );
753 mSpinBox->setShowClearButton(
true );
754 const int min = mSpinBox->minimum() - 1;
755 mSpinBox->setMinimum( min );
756 mSpinBox->setValue( min );
758 spinBox->setSpecialValueText( tr(
"Not set" ) );
766 if ( mDoubleSpinBox )
770 mDoubleSpinBox->setClearValue( defaultVal );
776 mSpinBox->setClearValue( intVal );
782 if ( mDoubleSpinBox )
783 mDoubleSpinBox->setClearValue( numberDef->
minimum() );
785 mSpinBox->setClearValue(
static_cast<int>( numberDef->
minimum() ) );
790 if ( mDoubleSpinBox )
792 mDoubleSpinBox->setValue( 0 );
793 mDoubleSpinBox->setClearValue( 0 );
797 mSpinBox->setValue( 0 );
798 mSpinBox->setClearValue( 0 );
803 if ( mDoubleSpinBox )
804 connect( mDoubleSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
806 connect( mSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
814void QgsProcessingNumericWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
816 if ( mDoubleSpinBox )
818 if ( mAllowingNull && !value.isValid() )
819 mDoubleSpinBox->clear();
823 mDoubleSpinBox->setValue( v );
828 if ( mAllowingNull && !value.isValid() )
833 mSpinBox->setValue( v );
838QVariant QgsProcessingNumericWidgetWrapper::widgetValue()
const
840 if ( mDoubleSpinBox )
842 if ( mAllowingNull &&
qgsDoubleNear( mDoubleSpinBox->value(), mDoubleSpinBox->minimum() ) )
845 return mDoubleSpinBox->value();
849 if ( mAllowingNull && mSpinBox->value() == mSpinBox->minimum() )
852 return mSpinBox->value();
858double QgsProcessingNumericWidgetWrapper::calculateStep(
const double minimum,
const double maximum )
860 const double valueRange = maximum - minimum;
861 if ( valueRange <= 1.0 )
863 const double step = valueRange / 10.0;
865 return qgsRound( step, -std::floor( std::log( step ) ) );
873QString QgsProcessingNumericWidgetWrapper::parameterType()
const
880 return new QgsProcessingNumericWidgetWrapper( parameter, type );
887 return new QgsProcessingNumberParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
894QgsProcessingDistanceParameterDefinitionWidget::QgsProcessingDistanceParameterDefinitionWidget(
899 QVBoxLayout *vlayout =
new QVBoxLayout();
900 vlayout->setContentsMargins( 0, 0, 0, 0 );
902 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
904 mParentLayerComboBox =
new QComboBox();
906 QString initialParent;
908 initialParent = distParam->parentParameterName();
910 if (
auto *lModel = widgetContext.
model() )
913 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
914 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
918 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
919 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
921 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
926 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
927 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
929 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
934 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
935 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
937 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
942 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
943 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
945 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
951 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
954 mParentLayerComboBox->addItem( initialParent, initialParent );
955 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
958 vlayout->addWidget( mParentLayerComboBox );
961 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
962 mMinLineEdit =
new QLineEdit();
963 vlayout->addWidget( mMinLineEdit );
965 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
966 mMaxLineEdit =
new QLineEdit();
967 vlayout->addWidget( mMaxLineEdit );
969 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
970 mDefaultLineEdit =
new QLineEdit();
971 vlayout->addWidget( mDefaultLineEdit );
975 mMinLineEdit->setText( QLocale().toString( distParam->minimum() ) );
976 mMaxLineEdit->setText( QLocale().toString( distParam->maximum() ) );
977 mDefaultLineEdit->setText( distParam->defaultValueForGui().toString() );
983 setLayout( vlayout );
991 auto param = std::make_unique<QgsProcessingParameterDistance>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
996 param->setMinimum( val );
1002 param->setMaximum( val );
1005 param->setFlags( flags );
1006 return param.release();
1010 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1013QString QgsProcessingDistanceWidgetWrapper::parameterType()
const
1020 return new QgsProcessingDistanceWidgetWrapper( parameter, type );
1023QWidget *QgsProcessingDistanceWidgetWrapper::createWidget()
1027 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1032 mLabel =
new QLabel();
1033 mUnitsCombo =
new QComboBox();
1045 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1046 QHBoxLayout *layout =
new QHBoxLayout();
1047 layout->addWidget( spin, 1 );
1048 layout->insertSpacing( 1, labelMargin / 2 );
1049 layout->insertWidget( 2, mLabel );
1050 layout->insertWidget( 3, mUnitsCombo );
1055 mWarningLabel =
new QWidget();
1056 QHBoxLayout *warningLayout =
new QHBoxLayout();
1057 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1058 QLabel *warning =
new QLabel();
1060 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1061 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1062 warning->setToolTip( tr(
"Distance is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1063 warningLayout->insertSpacing( 0, labelMargin / 2 );
1064 warningLayout->insertWidget( 1, warning );
1065 mWarningLabel->setLayout( warningLayout );
1066 layout->insertWidget( 4, mWarningLabel );
1068 QWidget *w =
new QWidget();
1069 layout->setContentsMargins( 0, 0, 0, 0 );
1070 w->setLayout( layout );
1084void QgsProcessingDistanceWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1086 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1093 if ( wrapper->parameterDefinition()->name() ==
static_cast<const QgsProcessingParameterDistance *
>( parameterDefinition() )->parentParameterName() )
1095 setUnitParameterValue( wrapper->parameterValue(), wrapper );
1115 std::unique_ptr<QgsProcessingContext> tmpContext;
1116 if ( mProcessingContextGenerator )
1117 context = mProcessingContextGenerator->processingContext();
1121 tmpContext = std::make_unique<QgsProcessingContext>();
1122 context = tmpContext.get();
1129 units = crs.mapUnits();
1140 mUnitsCombo->hide();
1148 if ( mBaseUnit != units )
1150 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( units ) ) );
1153 mUnitsCombo->show();
1160QVariant QgsProcessingDistanceWidgetWrapper::widgetValue()
const
1162 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1163 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1178 return new QgsProcessingDistanceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1186QgsProcessingAreaParameterDefinitionWidget::QgsProcessingAreaParameterDefinitionWidget(
1191 QVBoxLayout *vlayout =
new QVBoxLayout();
1192 vlayout->setContentsMargins( 0, 0, 0, 0 );
1194 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
1196 mParentLayerComboBox =
new QComboBox();
1198 QString initialParent;
1200 initialParent = areaParam->parentParameterName();
1202 if (
auto *lModel = widgetContext.
model() )
1205 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
1206 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
1210 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1211 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1213 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1218 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1219 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1221 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1226 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1227 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1229 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1234 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1235 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1237 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1243 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
1246 mParentLayerComboBox->addItem( initialParent, initialParent );
1247 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1252 vlayout->addWidget( mParentLayerComboBox );
1254 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1255 mMinLineEdit =
new QLineEdit();
1256 vlayout->addWidget( mMinLineEdit );
1258 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1259 mMaxLineEdit =
new QLineEdit();
1260 vlayout->addWidget( mMaxLineEdit );
1262 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1263 mDefaultLineEdit =
new QLineEdit();
1264 vlayout->addWidget( mDefaultLineEdit );
1268 mMinLineEdit->setText( QLocale().toString( areaParam->minimum() ) );
1269 mMaxLineEdit->setText( QLocale().toString( areaParam->maximum() ) );
1270 mDefaultLineEdit->setText( areaParam->defaultValueForGui().toString() );
1277 setLayout( vlayout );
1285 auto param = std::make_unique<QgsProcessingParameterArea>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1290 param->setMinimum( val );
1296 param->setMaximum( val );
1299 param->setFlags( flags );
1300 return param.release();
1309 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1312QString QgsProcessingAreaWidgetWrapper::parameterType()
const
1319 return new QgsProcessingAreaWidgetWrapper( parameter, type );
1322QWidget *QgsProcessingAreaWidgetWrapper::createWidget()
1326 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1331 mLabel =
new QLabel();
1332 mUnitsCombo =
new QComboBox();
1347 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1348 QHBoxLayout *layout =
new QHBoxLayout();
1349 layout->addWidget( spin, 1 );
1350 layout->insertSpacing( 1, labelMargin / 2 );
1351 layout->insertWidget( 2, mLabel );
1352 layout->insertWidget( 3, mUnitsCombo );
1357 mWarningLabel =
new QWidget();
1358 QHBoxLayout *warningLayout =
new QHBoxLayout();
1359 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1360 QLabel *warning =
new QLabel();
1362 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1363 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1364 warning->setToolTip( tr(
"Area is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1365 warningLayout->insertSpacing( 0, labelMargin / 2 );
1366 warningLayout->insertWidget( 1, warning );
1367 mWarningLabel->setLayout( warningLayout );
1368 layout->insertWidget( 4, mWarningLabel );
1370 QWidget *w =
new QWidget();
1371 layout->setContentsMargins( 0, 0, 0, 0 );
1372 w->setLayout( layout );
1386void QgsProcessingAreaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1388 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1417 std::unique_ptr<QgsProcessingContext> tmpContext;
1418 if ( mProcessingContextGenerator )
1419 context = mProcessingContextGenerator->processingContext();
1423 tmpContext = std::make_unique<QgsProcessingContext>();
1424 context = tmpContext.get();
1431 units = QgsUnitTypes::distanceToAreaUnit( crs.mapUnits() );
1437void QgsProcessingAreaWidgetWrapper::setUnits(
Qgis::AreaUnit units )
1442 mUnitsCombo->hide();
1447 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QVariant::fromValue( units ) ) );
1448 mUnitsCombo->show();
1455QVariant QgsProcessingAreaWidgetWrapper::widgetValue()
const
1457 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1458 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1473 return new QgsProcessingAreaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1481QgsProcessingVolumeParameterDefinitionWidget::QgsProcessingVolumeParameterDefinitionWidget(
1486 QVBoxLayout *vlayout =
new QVBoxLayout();
1487 vlayout->setContentsMargins( 0, 0, 0, 0 );
1489 vlayout->addWidget(
new QLabel( tr(
"Linked input" ) ) );
1491 mParentLayerComboBox =
new QComboBox();
1493 QString initialParent;
1495 initialParent = volumeParam->parentParameterName();
1497 if (
auto *lModel = widgetContext.
model() )
1500 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
1501 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
1505 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1506 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1508 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1513 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1514 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1516 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1521 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1522 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1524 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1529 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
1530 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
1532 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1538 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
1541 mParentLayerComboBox->addItem( initialParent, initialParent );
1542 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
1545 vlayout->addWidget( mParentLayerComboBox );
1547 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1548 mMinLineEdit =
new QLineEdit();
1549 vlayout->addWidget( mMinLineEdit );
1551 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1552 mMaxLineEdit =
new QLineEdit();
1553 vlayout->addWidget( mMaxLineEdit );
1555 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1556 mDefaultLineEdit =
new QLineEdit();
1557 vlayout->addWidget( mDefaultLineEdit );
1561 mMinLineEdit->setText( QLocale().toString( volumeParam->minimum() ) );
1562 mMaxLineEdit->setText( QLocale().toString( volumeParam->maximum() ) );
1563 mDefaultLineEdit->setText( volumeParam->defaultValueForGui().toString() );
1571 setLayout( vlayout );
1579 auto param = std::make_unique<QgsProcessingParameterVolume>( name, description, ok ? val : QVariant(), mParentLayerComboBox->currentData().toString() );
1584 param->setMinimum( val );
1590 param->setMaximum( val );
1593 param->setFlags( flags );
1594 return param.release();
1603 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1606QString QgsProcessingVolumeWidgetWrapper::parameterType()
const
1613 return new QgsProcessingVolumeWidgetWrapper( parameter, type );
1616QWidget *QgsProcessingVolumeWidgetWrapper::createWidget()
1620 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1625 mLabel =
new QLabel();
1626 mUnitsCombo =
new QComboBox();
1639 const int labelMargin =
static_cast<int>( std::round( mUnitsCombo->fontMetrics().horizontalAdvance(
'X' ) ) );
1640 QHBoxLayout *layout =
new QHBoxLayout();
1641 layout->addWidget( spin, 1 );
1642 layout->insertSpacing( 1, labelMargin / 2 );
1643 layout->insertWidget( 2, mLabel );
1644 layout->insertWidget( 3, mUnitsCombo );
1649 mWarningLabel =
new QWidget();
1650 QHBoxLayout *warningLayout =
new QHBoxLayout();
1651 warningLayout->setContentsMargins( 0, 0, 0, 0 );
1652 QLabel *warning =
new QLabel();
1654 const int size =
static_cast<int>( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
1655 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
1656 warning->setToolTip( tr(
"Volume is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
1657 warningLayout->insertSpacing( 0, labelMargin / 2 );
1658 warningLayout->insertWidget( 1, warning );
1659 mWarningLabel->setLayout( warningLayout );
1660 layout->insertWidget( 4, mWarningLabel );
1662 QWidget *w =
new QWidget();
1663 layout->setContentsMargins( 0, 0, 0, 0 );
1664 w->setLayout( layout );
1678void QgsProcessingVolumeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1680 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
1709 std::unique_ptr<QgsProcessingContext> tmpContext;
1710 if ( mProcessingContextGenerator )
1711 context = mProcessingContextGenerator->processingContext();
1715 tmpContext = std::make_unique<QgsProcessingContext>();
1716 context = tmpContext.get();
1723 units = QgsUnitTypes::distanceToVolumeUnit( crs.mapUnits() );
1734 mUnitsCombo->hide();
1739 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QVariant::fromValue( units ) ) );
1740 mUnitsCombo->show();
1747QVariant QgsProcessingVolumeWidgetWrapper::widgetValue()
const
1749 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1750 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo && mUnitsCombo->isVisible() )
1765 return new QgsProcessingVolumeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1773QgsProcessingDurationParameterDefinitionWidget::QgsProcessingDurationParameterDefinitionWidget(
1778 QVBoxLayout *vlayout =
new QVBoxLayout();
1779 vlayout->setContentsMargins( 0, 0, 0, 0 );
1781 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
1782 mMinLineEdit =
new QLineEdit();
1783 vlayout->addWidget( mMinLineEdit );
1785 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
1786 mMaxLineEdit =
new QLineEdit();
1787 vlayout->addWidget( mMaxLineEdit );
1789 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1790 mDefaultLineEdit =
new QLineEdit();
1791 vlayout->addWidget( mDefaultLineEdit );
1793 vlayout->addWidget(
new QLabel( tr(
"Default unit type" ) ) );
1795 mUnitsCombo =
new QComboBox();
1805 vlayout->addWidget( mUnitsCombo );
1811 mMinLineEdit->setText( QLocale().toString( durationParam->minimum() ) );
1812 mMaxLineEdit->setText( QLocale().toString( durationParam->maximum() ) );
1813 mDefaultLineEdit->setText( durationParam->defaultValueForGui().toString() );
1814 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( durationParam->defaultUnit() ) ) );
1820 setLayout( vlayout );
1828 auto param = std::make_unique<QgsProcessingParameterDuration>( name, description, ok ? val : QVariant() );
1833 param->setMinimum( val );
1839 param->setMaximum( val );
1842 param->setDefaultUnit(
static_cast<Qgis::TemporalUnit>( mUnitsCombo->currentData().toInt() ) );
1844 param->setFlags( flags );
1845 return param.release();
1849 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1852QString QgsProcessingDurationWidgetWrapper::parameterType()
const
1859 return new QgsProcessingDurationWidgetWrapper( parameter, type );
1862QWidget *QgsProcessingDurationWidgetWrapper::createWidget()
1866 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
1871 mUnitsCombo =
new QComboBox();
1883 QHBoxLayout *layout =
new QHBoxLayout();
1884 layout->addWidget( spin, 1 );
1885 layout->insertWidget( 1, mUnitsCombo );
1887 QWidget *w =
new QWidget();
1888 layout->setContentsMargins( 0, 0, 0, 0 );
1889 w->setLayout( layout );
1891 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData(
static_cast<int>( durationDef->
defaultUnit() ) ) );
1892 mUnitsCombo->show();
1904QLabel *QgsProcessingDurationWidgetWrapper::createLabel()
1916QVariant QgsProcessingDurationWidgetWrapper::widgetValue()
const
1918 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
1919 if ( val.userType() == QMetaType::Type::Double && mUnitsCombo )
1930void QgsProcessingDurationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1936 QgsProcessingNumericWidgetWrapper::setWidgetValue( val, context );
1940 QgsProcessingNumericWidgetWrapper::setWidgetValue( value, context );
1948 return new QgsProcessingDurationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
1955QgsProcessingScaleParameterDefinitionWidget::QgsProcessingScaleParameterDefinitionWidget(
1960 QVBoxLayout *vlayout =
new QVBoxLayout();
1961 vlayout->setContentsMargins( 0, 0, 0, 0 );
1963 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1965 mDefaultLineEdit =
new QLineEdit();
1969 mDefaultLineEdit->setText( scaleParam->defaultValueForGui().toString() );
1972 vlayout->addWidget( mDefaultLineEdit );
1975 setLayout( vlayout );
1981 double val = mDefaultLineEdit->text().toDouble( &ok );
1982 auto param = std::make_unique<QgsProcessingParameterScale>( name, description, ok ? val : QVariant() );
1983 param->setFlags( flags );
1984 return param.release();
1988 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
1991QString QgsProcessingScaleWidgetWrapper::parameterType()
const
1998 return new QgsProcessingScaleWidgetWrapper( parameter, type );
2001QWidget *QgsProcessingScaleWidgetWrapper::createWidget()
2013 mScaleWidget->setAllowNull(
true );
2015 mScaleWidget->setMapCanvas( widgetContext().mapCanvas() );
2016 mScaleWidget->setShowCurrentScaleButton(
true );
2018 mScaleWidget->setToolTip( parameterDefinition()->toolTip() );
2020 return mScaleWidget;
2029 mScaleWidget->setMapCanvas( context.
mapCanvas() );
2034QVariant QgsProcessingScaleWidgetWrapper::widgetValue()
const
2036 return mScaleWidget && !mScaleWidget->isNull() ? QVariant( mScaleWidget->scale() ) : QVariant();
2039void QgsProcessingScaleWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2043 if ( mScaleWidget->allowNull() && !value.isValid() )
2044 mScaleWidget->setNull();
2048 mScaleWidget->setScale( v );
2057 return new QgsProcessingScaleParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2065QgsProcessingRangeParameterDefinitionWidget::QgsProcessingRangeParameterDefinitionWidget(
2070 QVBoxLayout *vlayout =
new QVBoxLayout();
2071 vlayout->setContentsMargins( 0, 0, 0, 0 );
2073 vlayout->addWidget(
new QLabel( tr(
"Number type" ) ) );
2075 mTypeComboBox =
new QComboBox();
2078 vlayout->addWidget( mTypeComboBox );
2080 vlayout->addWidget(
new QLabel( tr(
"Minimum value" ) ) );
2081 mMinLineEdit =
new QLineEdit();
2082 vlayout->addWidget( mMinLineEdit );
2084 vlayout->addWidget(
new QLabel( tr(
"Maximum value" ) ) );
2085 mMaxLineEdit =
new QLineEdit();
2086 vlayout->addWidget( mMaxLineEdit );
2090 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( rangeParam->dataType() ) ) );
2092 mMinLineEdit->setText( QLocale().toString( range.at( 0 ) ) );
2093 mMaxLineEdit->setText( QLocale().toString( range.at( 1 ) ) );
2100 setLayout( vlayout );
2105 QString defaultValue;
2106 if ( mMinLineEdit->text().isEmpty() )
2108 defaultValue = u
"None"_s;
2116 defaultValue = u
"None"_s;
2120 if ( mMaxLineEdit->text().isEmpty() )
2122 defaultValue +=
",None"_L1;
2128 defaultValue += u
",%1"_s.arg( ok ? QString::number( val ) :
"None"_L1 );
2132 auto param = std::make_unique<QgsProcessingParameterRange>( name, description, dataType, defaultValue );
2133 param->setFlags( flags );
2134 return param.release();
2142QWidget *QgsProcessingRangeWidgetWrapper::createWidget()
2151 QHBoxLayout *layout =
new QHBoxLayout();
2156 mMinSpinBox->setExpressionsEnabled(
true );
2157 mMinSpinBox->setShowClearButton(
false );
2158 mMaxSpinBox->setExpressionsEnabled(
true );
2159 mMaxSpinBox->setShowClearButton(
false );
2161 QLabel *minLabel =
new QLabel( tr(
"Min" ) );
2162 layout->addWidget( minLabel );
2163 layout->addWidget( mMinSpinBox, 1 );
2165 QLabel *maxLabel =
new QLabel( tr(
"Max" ) );
2166 layout->addWidget( maxLabel );
2167 layout->addWidget( mMaxSpinBox, 1 );
2169 QWidget *w =
new QWidget();
2170 layout->setContentsMargins( 0, 0, 0, 0 );
2171 w->setLayout( layout );
2175 mMinSpinBox->setDecimals( 6 );
2176 mMaxSpinBox->setDecimals( 6 );
2180 mMinSpinBox->setDecimals( 0 );
2181 mMaxSpinBox->setDecimals( 0 );
2184 mMinSpinBox->setMinimum( -99999999.999999 );
2185 mMaxSpinBox->setMinimum( -99999999.999999 );
2186 mMinSpinBox->setMaximum( 99999999.999999 );
2187 mMaxSpinBox->setMaximum( 99999999.999999 );
2191 mAllowingNull =
true;
2193 const double min = mMinSpinBox->minimum() - 1;
2194 mMinSpinBox->setMinimum( min );
2195 mMaxSpinBox->setMinimum( min );
2196 mMinSpinBox->setValue( min );
2197 mMaxSpinBox->setValue( min );
2199 mMinSpinBox->setShowClearButton(
true );
2200 mMaxSpinBox->setShowClearButton(
true );
2201 mMinSpinBox->setSpecialValueText( tr(
"Not set" ) );
2202 mMaxSpinBox->setSpecialValueText( tr(
"Not set" ) );
2205 w->setToolTip( parameterDefinition()->toolTip() );
2207 connect( mMinSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this](
const double v ) {
2208 mBlockChangedSignal++;
2209 if ( !mAllowingNull && v > mMaxSpinBox->value() )
2210 mMaxSpinBox->setValue( v );
2211 mBlockChangedSignal--;
2213 if ( !mBlockChangedSignal )
2214 emit widgetValueHasChanged(
this );
2216 connect( mMaxSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this](
const double v ) {
2217 mBlockChangedSignal++;
2218 if ( !mAllowingNull && v < mMinSpinBox->value() )
2219 mMinSpinBox->setValue( v );
2220 mBlockChangedSignal--;
2222 if ( !mBlockChangedSignal )
2223 emit widgetValueHasChanged(
this );
2232void QgsProcessingRangeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2235 if ( mAllowingNull && v.empty() )
2237 mMinSpinBox->clear();
2238 mMaxSpinBox->clear();
2245 if ( mAllowingNull )
2247 mBlockChangedSignal++;
2248 if ( std::isnan( v.at( 0 ) ) )
2249 mMinSpinBox->clear();
2251 mMinSpinBox->setValue( v.at( 0 ) );
2253 if ( v.count() >= 2 )
2255 if ( std::isnan( v.at( 1 ) ) )
2256 mMaxSpinBox->clear();
2258 mMaxSpinBox->setValue( v.at( 1 ) );
2260 mBlockChangedSignal--;
2264 mBlockChangedSignal++;
2265 mMinSpinBox->setValue( v.at( 0 ) );
2266 if ( v.count() >= 2 )
2267 mMaxSpinBox->setValue( v.at( 1 ) );
2268 mBlockChangedSignal--;
2272 if ( !mBlockChangedSignal )
2273 emit widgetValueHasChanged(
this );
2276QVariant QgsProcessingRangeWidgetWrapper::widgetValue()
const
2278 if ( mAllowingNull )
2281 if (
qgsDoubleNear( mMinSpinBox->value(), mMinSpinBox->minimum() ) )
2284 value = QString::number( mMinSpinBox->value() );
2286 if (
qgsDoubleNear( mMaxSpinBox->value(), mMaxSpinBox->minimum() ) )
2287 value +=
",None"_L1;
2289 value += u
",%1"_s.arg( mMaxSpinBox->value() );
2294 return u
"%1,%2"_s.arg( mMinSpinBox->value() ).arg( mMaxSpinBox->value() );
2297QString QgsProcessingRangeWidgetWrapper::modelerExpressionFormatString()
const
2299 return tr(
"string as two comma delimited floats, e.g. '1,10'" );
2302QString QgsProcessingRangeWidgetWrapper::parameterType()
const
2309 return new QgsProcessingRangeWidgetWrapper( parameter, type );
2316 return new QgsProcessingRangeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2324QgsProcessingMatrixParameterDefinitionWidget::QgsProcessingMatrixParameterDefinitionWidget(
2329 QVBoxLayout *vlayout =
new QVBoxLayout();
2330 vlayout->setContentsMargins( 0, 0, 0, 0 );
2332 mMatrixWidget =
new QgsProcessingMatrixModelerWidget();
2335 mMatrixWidget->setValue( matrixParam->headers(), matrixParam->defaultValueForGui() );
2336 mMatrixWidget->setFixedRows( matrixParam->hasFixedNumberRows() );
2338 vlayout->addWidget( mMatrixWidget );
2342 setLayout( vlayout );
2347 auto param = std::make_unique<QgsProcessingParameterMatrix>( name, description, 1, mMatrixWidget->fixedRows(), mMatrixWidget->headers(), mMatrixWidget->value() );
2348 param->setFlags( flags );
2349 return param.release();
2357QWidget *QgsProcessingMatrixWidgetWrapper::createWidget()
2359 mMatrixWidget =
new QgsProcessingMatrixParameterPanel(
nullptr,
dynamic_cast<const QgsProcessingParameterMatrix *
>( parameterDefinition() ) );
2360 mMatrixWidget->setToolTip( parameterDefinition()->toolTip() );
2362 connect( mMatrixWidget, &QgsProcessingMatrixParameterPanel::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
2370 return mMatrixWidget;
2376void QgsProcessingMatrixWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2379 if ( mMatrixWidget )
2380 mMatrixWidget->setValue( v );
2383QVariant QgsProcessingMatrixWidgetWrapper::widgetValue()
const
2385 if ( mMatrixWidget )
2386 return mMatrixWidget->value().isEmpty() ? QVariant() : mMatrixWidget->value();
2391QString QgsProcessingMatrixWidgetWrapper::modelerExpressionFormatString()
const
2393 return tr(
"comma delimited string of values, or an array of values" );
2396QString QgsProcessingMatrixWidgetWrapper::parameterType()
const
2403 return new QgsProcessingMatrixWidgetWrapper( parameter, type );
2410 return new QgsProcessingMatrixParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2419QgsProcessingFileParameterDefinitionWidget::QgsProcessingFileParameterDefinitionWidget(
2424 QVBoxLayout *vlayout =
new QVBoxLayout();
2425 vlayout->setContentsMargins( 0, 0, 0, 0 );
2427 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
2429 mTypeComboBox =
new QComboBox();
2433 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( fileParam->behavior() ) ) );
2435 mTypeComboBox->setCurrentIndex( 0 );
2436 vlayout->addWidget( mTypeComboBox );
2440 vlayout->addWidget(
new QLabel( tr(
"File filter" ) ) );
2442 mFilterComboBox =
new QComboBox();
2443 mFilterComboBox->setEditable(
true );
2445 mFilterComboBox->addItem( tr(
"All Files (*.*)" ) );
2446 mFilterComboBox->addItem( tr(
"CSV Files (*.csv)" ) );
2447 mFilterComboBox->addItem( tr(
"HTML Files (*.html *.htm)" ) );
2448 mFilterComboBox->addItem( tr(
"Text Files (*.txt)" ) );
2450 mFilterComboBox->setCurrentText( fileParam->fileFilter() );
2452 mFilterComboBox->setCurrentIndex( 0 );
2453 vlayout->addWidget( mFilterComboBox );
2457 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2460 mDefaultFileWidget->lineEdit()->setShowClearButton(
true );
2464 mDefaultFileWidget->setFilePath( fileParam->defaultValueForGui().toString() );
2468 vlayout->addWidget( mDefaultFileWidget );
2471 connect( mTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this] {
2479 setLayout( vlayout );
2484 auto param = std::make_unique<QgsProcessingParameterFile>( name, description );
2487 param->setFileFilter( mFilterComboBox->currentText() );
2488 if ( !mDefaultFileWidget->filePath().isEmpty() )
2489 param->setDefaultValue( mDefaultFileWidget->filePath() );
2490 param->setFlags( flags );
2491 return param.release();
2499QWidget *QgsProcessingFileWidgetWrapper::createWidget()
2512 mFileWidget->setToolTip( parameterDefinition()->toolTip() );
2513 mFileWidget->setDialogTitle( parameterDefinition()->description() );
2515 mFileWidget->setDefaultRoot(
QgsSettings().value( u
"/Processing/LastInputPath"_s, QDir::homePath() ).toString() );
2522 mFileWidget->setFilter( fileParam->
fileFilter() );
2523 else if ( !fileParam->
extension().isEmpty() )
2524 mFileWidget->setFilter( tr(
"%1 files" ).arg( fileParam->
extension().toUpper() ) + u
" (*."_s + fileParam->
extension().toLower() +
')' );
2533 QgsSettings().
setValue( u
"/Processing/LastInputPath"_s, QFileInfo( path ).canonicalPath() );
2534 emit widgetValueHasChanged(
this );
2542void QgsProcessingFileWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2546 mFileWidget->setFilePath( v );
2549QVariant QgsProcessingFileWidgetWrapper::widgetValue()
const
2552 return mFileWidget->filePath();
2557QString QgsProcessingFileWidgetWrapper::modelerExpressionFormatString()
const
2559 return tr(
"string representing a path to a file or folder" );
2562QString QgsProcessingFileWidgetWrapper::parameterType()
const
2569 return new QgsProcessingFileWidgetWrapper( parameter, type );
2576 return new QgsProcessingFileParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
2584QgsProcessingExpressionParameterDefinitionWidget::QgsProcessingExpressionParameterDefinitionWidget(
2589 QVBoxLayout *vlayout =
new QVBoxLayout();
2590 vlayout->setContentsMargins( 0, 0, 0, 0 );
2591 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2594 mDefaultQgisLineEdit->registerExpressionContextGenerator(
this );
2596 mDefaultPointCloudLineEdit =
new QgsProcessingPointCloudExpressionLineEdit();
2597 mDefaultRasterCalculatorLineEdit =
new QgsProcessingRasterCalculatorExpressionLineEdit();
2599 QStackedWidget *stackedWidget =
new QStackedWidget();
2600 stackedWidget->addWidget( mDefaultQgisLineEdit );
2601 stackedWidget->addWidget( mDefaultPointCloudLineEdit );
2602 stackedWidget->addWidget( mDefaultRasterCalculatorLineEdit );
2603 vlayout->addWidget( stackedWidget );
2612 mDefaultQgisLineEdit->setExpression( expr );
2613 mDefaultPointCloudLineEdit->setExpression( expr );
2616 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
2618 mParentLayerComboBox =
new QComboBox();
2619 vlayout->addWidget( mParentLayerComboBox );
2621 vlayout->addWidget(
new QLabel( tr(
"Expression type" ) ) );
2622 mExpressionTypeComboBox =
new QComboBox();
2627 connect( mExpressionTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [
this, stackedWidget, definition, widgetContext](
int ) {
2628 mParentLayerComboBox->clear();
2629 mParentLayerComboBox->addItem( tr(
"None" ), QVariant() );
2631 stackedWidget->setCurrentIndex( mExpressionTypeComboBox->currentIndex() > 0 ? mExpressionTypeComboBox->currentIndex() : 0 );
2633 QString initialParent;
2635 initialParent = expParam->parentLayerParameterName();
2639 if ( QgsProcessingModelAlgorithm *model = widgetContext.
model() )
2642 const QMap<QString, QgsProcessingModelParameter> components = model->parameterComponents();
2643 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
2650 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2651 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2653 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2658 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2659 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2661 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2668 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2669 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2671 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2682 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
2683 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2685 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2693 if ( mParentLayerComboBox->count() == 1 && !initialParent.isEmpty() )
2696 mParentLayerComboBox->addItem( initialParent, initialParent );
2697 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
2701 mExpressionTypeComboBox->setCurrentIndex( -1 );
2703 mExpressionTypeComboBox->setCurrentIndex( mExpressionTypeComboBox->findData(
static_cast<int>( expParam->expressionType() ) ) );
2705 mExpressionTypeComboBox->setCurrentIndex( 0 );
2707 vlayout->addWidget( mExpressionTypeComboBox );
2712 setLayout( vlayout );
2719 switch ( expressionType )
2722 expression = mDefaultQgisLineEdit->expression();
2725 expression = mDefaultPointCloudLineEdit->expression();
2728 expression = mDefaultRasterCalculatorLineEdit->expression();
2731 auto param = std::make_unique<QgsProcessingParameterExpression>( name, description, expression, mParentLayerComboBox->currentData().toString(),
false, expressionType );
2732 param->setFlags( flags );
2733 return param.release();
2740QWidget *QgsProcessingExpressionWidgetWrapper::createWidget()
2755 mExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2756 mExpLineEdit->setExpressionDialogTitle( parameterDefinition()->description() );
2757 mExpLineEdit->registerExpressionContextGenerator(
this );
2759 return mExpLineEdit;
2765 mPointCloudExpLineEdit =
new QgsProcessingPointCloudExpressionLineEdit();
2766 mPointCloudExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2767 connect( mPointCloudExpLineEdit, &QgsProcessingPointCloudExpressionLineEdit::expressionChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
2768 return mPointCloudExpLineEdit;
2773 mRasterCalculatorExpLineEdit =
new QgsProcessingRasterCalculatorExpressionLineEdit();
2774 mRasterCalculatorExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
2777 mRasterCalculatorExpLineEdit->setLayers( QVariantList() <<
"A" <<
"B" <<
"C" <<
"D" <<
"E" <<
"F" <<
"G" );
2779 connect( mRasterCalculatorExpLineEdit, &QgsProcessingRasterCalculatorExpressionLineEdit::expressionChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
2780 return mRasterCalculatorExpLineEdit;
2784 if ( expParam->
metadata().value( u
"inlineEditor"_s ).toBool() )
2787 mExpBuilderWidget->setToolTip( parameterDefinition()->toolTip() );
2788 mExpBuilderWidget->init( createExpressionContext() );
2790 Q_UNUSED( changed );
2791 emit widgetValueHasChanged(
this );
2793 return mExpBuilderWidget;
2798 mFieldExpWidget->setToolTip( parameterDefinition()->toolTip() );
2799 mFieldExpWidget->setExpressionDialogTitle( parameterDefinition()->description() );
2800 mFieldExpWidget->registerExpressionContextGenerator(
this );
2802 mFieldExpWidget->setAllowEmptyFieldName(
true );
2805 emit widgetValueHasChanged(
this );
2807 return mFieldExpWidget;
2815void QgsProcessingExpressionWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
2827 setParentLayerWrapperValue( wrapper );
2843 if ( mExpBuilderWidget )
2846 mExpBuilderWidget->setExpressionContext( createExpressionContext() );
2854 std::unique_ptr<QgsProcessingContext> tmpContext;
2855 if ( mProcessingContextGenerator )
2856 context = mProcessingContextGenerator->processingContext();
2860 tmpContext = std::make_unique<QgsProcessingContext>();
2861 context = tmpContext.get();
2874 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2884 if ( mFieldExpWidget )
2885 mFieldExpWidget->setLayer(
nullptr );
2886 else if ( mExpBuilderWidget )
2887 mExpBuilderWidget->setLayer(
nullptr );
2888 else if ( mExpLineEdit )
2889 mExpLineEdit->setLayer(
nullptr );
2895 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
2898 mParentLayer = std::move( ownedLayer );
2906 if ( mFieldExpWidget )
2907 mFieldExpWidget->setLayer( layer );
2908 if ( mExpBuilderWidget )
2909 mExpBuilderWidget->setLayer( layer );
2910 else if ( mExpLineEdit )
2911 mExpLineEdit->setLayer( layer );
2920 if ( mPointCloudExpLineEdit )
2921 mPointCloudExpLineEdit->setLayer(
nullptr );
2927 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
2930 mParentLayer = std::move( ownedLayer );
2938 if ( mPointCloudExpLineEdit )
2939 mPointCloudExpLineEdit->setLayer( layer );
2946 if ( layers.isEmpty() )
2948 if ( mRasterCalculatorExpLineEdit )
2950 mRasterCalculatorExpLineEdit->setLayers( val.userType() == QMetaType::Type::QVariantList ? val.toList() : QVariantList() << val );
2955 if ( mRasterCalculatorExpLineEdit )
2957 QVariantList layersList;
2960 layersList << layer->
name();
2962 mRasterCalculatorExpLineEdit->setLayers( layersList );
2970void QgsProcessingExpressionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2973 if ( mFieldExpWidget )
2974 mFieldExpWidget->setExpression( v );
2975 else if ( mExpBuilderWidget )
2976 mExpBuilderWidget->setExpressionText( v );
2977 else if ( mExpLineEdit )
2978 mExpLineEdit->setExpression( v );
2979 else if ( mPointCloudExpLineEdit )
2980 mPointCloudExpLineEdit->setExpression( v );
2981 else if ( mRasterCalculatorExpLineEdit )
2982 mRasterCalculatorExpLineEdit->setExpression( v );
2985QVariant QgsProcessingExpressionWidgetWrapper::widgetValue()
const
2987 if ( mFieldExpWidget )
2988 return mFieldExpWidget->expression();
2989 if ( mExpBuilderWidget )
2990 return mExpBuilderWidget->expressionText();
2991 else if ( mExpLineEdit )
2992 return mExpLineEdit->expression();
2993 else if ( mPointCloudExpLineEdit )
2994 return mPointCloudExpLineEdit->expression();
2995 else if ( mRasterCalculatorExpLineEdit )
2996 return mRasterCalculatorExpLineEdit->expression();
3001QString QgsProcessingExpressionWidgetWrapper::modelerExpressionFormatString()
const
3003 return tr(
"string representation of an expression" );
3006const QgsVectorLayer *QgsProcessingExpressionWidgetWrapper::linkedVectorLayer()
const
3008 if ( mFieldExpWidget && mFieldExpWidget->layer() )
3009 return mFieldExpWidget->layer();
3011 if ( mExpBuilderWidget && mExpBuilderWidget->layer() )
3012 return mExpBuilderWidget->layer();
3017QString QgsProcessingExpressionWidgetWrapper::parameterType()
const
3024 return new QgsProcessingExpressionWidgetWrapper( parameter, type );
3031 return new QgsProcessingExpressionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3043 QHBoxLayout *hl =
new QHBoxLayout();
3044 hl->setContentsMargins( 0, 0, 0, 0 );
3046 mLineEdit =
new QLineEdit();
3047 mLineEdit->setEnabled(
false );
3048 hl->addWidget( mLineEdit, 1 );
3050 mToolButton =
new QToolButton();
3051 mToolButton->setText( QString( QChar( 0x2026 ) ) );
3052 hl->addWidget( mToolButton );
3058 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
3061 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingEnumPanelWidget::showDialog );
3064void QgsProcessingEnumPanelWidget::setValue(
const QVariant &value )
3066 if ( value.isValid() )
3068 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
3070 if ( mParam->usesStaticStrings() && mValue.count() == 1 && mValue.at( 0 ).toString().isEmpty() )
3076 updateSummaryText();
3080void QgsProcessingEnumPanelWidget::showDialog()
3082 QVariantList availableOptions;
3085 availableOptions.reserve( mParam->options().size() );
3087 if ( mParam->usesStaticStrings() )
3089 for ( QString o : mParam->options() )
3091 availableOptions << o;
3096 for (
int i = 0; i < mParam->options().count(); ++i )
3097 availableOptions << i;
3101 const QStringList options = mParam ? mParam->options() : QStringList();
3105 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
3106 widget->setPanelTitle( mParam->description() );
3108 if ( mParam->usesStaticStrings() )
3110 widget->setValueFormatter( [options](
const QVariant &v ) -> QString {
3111 const QString i = v.toString();
3112 return options.contains( i ) ? i : QString();
3117 widget->setValueFormatter( [options](
const QVariant &v ) -> QString {
3118 const int i = v.toInt();
3119 return options.size() > i ? options.at( i ) : QString();
3123 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
3129 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
3131 dlg.setValueFormatter( [options](
const QVariant &v ) -> QString {
3132 const int i = v.toInt();
3133 return options.size() > i ? options.at( i ) : QString();
3137 setValue( dlg.selectedOptions() );
3142void QgsProcessingEnumPanelWidget::updateSummaryText()
3147 if ( mValue.empty() )
3149 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
3154 values.reserve( mValue.size() );
3155 if ( mParam->usesStaticStrings() )
3157 for (
const QVariant &val : std::as_const( mValue ) )
3159 values << val.toString();
3164 const QStringList options = mParam->options();
3165 for (
const QVariant &val : std::as_const( mValue ) )
3167 const int i = val.toInt();
3168 values << ( options.size() > i ? options.at( i ) : QString() );
3172 const QString concatenated = values.join( tr(
"," ) );
3173 if ( concatenated.length() < 100 )
3174 mLineEdit->setText( concatenated );
3176 mLineEdit->setText( tr(
"%n option(s) selected",
nullptr, mValue.count() ) );
3184QgsProcessingEnumCheckboxPanelWidget::QgsProcessingEnumCheckboxPanelWidget( QWidget *parent,
const QgsProcessingParameterEnum *param,
int columns )
3187 , mButtonGroup( new QButtonGroup( this ) )
3188 , mColumns( columns )
3190 mButtonGroup->setExclusive( !mParam->allowMultiple() );
3192 QGridLayout *l =
new QGridLayout();
3193 l->setContentsMargins( 0, 0, 0, 0 );
3195 int rows =
static_cast<int>( std::ceil( mParam->options().count() /
static_cast<double>( mColumns ) ) );
3196 for (
int i = 0; i < mParam->options().count(); ++i )
3198 QAbstractButton *button =
nullptr;
3199 if ( mParam->allowMultiple() )
3200 button =
new QCheckBox( mParam->options().at( i ) );
3202 button =
new QRadioButton( mParam->options().at( i ) );
3204 connect( button, &QAbstractButton::toggled,
this, [
this] {
3205 if ( !mBlockChangedSignal )
3209 mButtons.insert( i, button );
3211 mButtonGroup->addButton( button, i );
3212 l->addWidget( button, i % rows, i / rows );
3214 l->addItem(
new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, mColumns );
3217 if ( mParam->allowMultiple() )
3219 setContextMenuPolicy( Qt::CustomContextMenu );
3220 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsProcessingEnumCheckboxPanelWidget::showPopupMenu );
3224QVariant QgsProcessingEnumCheckboxPanelWidget::value()
const
3226 if ( mParam->allowMultiple() )
3229 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3231 if ( it.value()->isChecked() )
3232 value.append( mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key() );
3238 if ( mParam->usesStaticStrings() )
3239 return mButtonGroup->checkedId() >= 0 ? mParam->options().at( mButtonGroup->checkedId() ) : QVariant();
3241 return mButtonGroup->checkedId() >= 0 ? mButtonGroup->checkedId() : QVariant();
3245void QgsProcessingEnumCheckboxPanelWidget::setValue(
const QVariant &value )
3247 mBlockChangedSignal =
true;
3248 if ( mParam->allowMultiple() )
3250 QVariantList selected;
3251 if ( value.isValid() )
3252 selected = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
3253 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3255 QVariant v = mParam->usesStaticStrings() ? mParam->options().at( it.key().toInt() ) : it.key();
3256 it.value()->setChecked( selected.contains( v ) );
3262 if ( v.userType() == QMetaType::Type::QVariantList )
3263 v = v.toList().value( 0 );
3265 v = mParam->usesStaticStrings() ?
static_cast< int >( mParam->options().indexOf( v.toString() ) ) : v;
3266 if ( mButtons.contains( v ) )
3267 mButtons.value( v )->setChecked(
true );
3269 mBlockChangedSignal =
false;
3273void QgsProcessingEnumCheckboxPanelWidget::showPopupMenu()
3276 QAction *selectAllAction =
new QAction( tr(
"Select All" ), &popupMenu );
3277 connect( selectAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::selectAll );
3278 QAction *clearAllAction =
new QAction( tr(
"Clear Selection" ), &popupMenu );
3279 connect( clearAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::deselectAll );
3280 popupMenu.addAction( selectAllAction );
3281 popupMenu.addAction( clearAllAction );
3282 popupMenu.exec( QCursor::pos() );
3285void QgsProcessingEnumCheckboxPanelWidget::selectAll()
3287 mBlockChangedSignal =
true;
3288 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3289 it.value()->setChecked(
true );
3290 mBlockChangedSignal =
false;
3294void QgsProcessingEnumCheckboxPanelWidget::deselectAll()
3296 mBlockChangedSignal =
true;
3297 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
3298 it.value()->setChecked(
false );
3299 mBlockChangedSignal =
false;
3308QgsProcessingEnumParameterDefinitionWidget::QgsProcessingEnumParameterDefinitionWidget(
3313 QVBoxLayout *vlayout =
new QVBoxLayout();
3314 vlayout->setContentsMargins( 0, 0, 0, 0 );
3316 mEnumWidget =
new QgsProcessingEnumModelerWidget();
3319 mEnumWidget->setAllowMultiple( enumParam->allowMultiple() );
3320 mEnumWidget->setOptions( enumParam->options() );
3321 mEnumWidget->setDefaultOptions( enumParam->defaultValueForGui() );
3323 vlayout->addWidget( mEnumWidget );
3327 setLayout( vlayout );
3332 auto param = std::make_unique<QgsProcessingParameterEnum>( name, description, mEnumWidget->options(), mEnumWidget->allowMultiple(), mEnumWidget->defaultOptions() );
3334 return param.release();
3342QWidget *QgsProcessingEnumWidgetWrapper::createWidget()
3353 if ( expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"useCheckBoxes"_s,
false ).toBool() )
3355 const int columns = expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"columns"_s, 2 ).toInt();
3356 mCheckboxPanel =
new QgsProcessingEnumCheckboxPanelWidget(
nullptr, expParam, columns );
3357 mCheckboxPanel->setToolTip( parameterDefinition()->toolTip() );
3358 connect( mCheckboxPanel, &QgsProcessingEnumCheckboxPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
3359 return mCheckboxPanel;
3368 mPanel =
new QgsProcessingEnumPanelWidget(
nullptr, expParam );
3369 mPanel->setToolTip( parameterDefinition()->toolTip() );
3370 connect( mPanel, &QgsProcessingEnumPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
3375 mComboBox =
new QComboBox();
3378 mComboBox->addItem( tr(
"[Not selected]" ), QVariant() );
3379 const QStringList options = expParam->
options();
3380 const QVariantList iconList = expParam->
metadata().value( u
"widget_wrapper"_s ).toMap().value( u
"icons"_s ).toList();
3381 for (
int i = 0; i < options.count(); ++i )
3383 const QIcon icon = iconList.value( i ).value<QIcon>();
3386 mComboBox->addItem( icon, options.at( i ), options.at( i ) );
3388 mComboBox->addItem( icon, options.at( i ), i );
3391 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3392 mComboBox->setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon );
3393 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
3401void QgsProcessingEnumWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3405 if ( !value.isValid() )
3406 mComboBox->setCurrentIndex( mComboBox->findData( QVariant() ) );
3412 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
3417 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
3421 else if ( mPanel || mCheckboxPanel )
3424 if ( value.isValid() )
3429 opts.reserve( v.size() );
3430 for ( QString i : v )
3436 opts.reserve( v.size() );
3442 mPanel->setValue( opts );
3443 else if ( mCheckboxPanel )
3444 mCheckboxPanel->setValue( opts );
3448QVariant QgsProcessingEnumWidgetWrapper::widgetValue()
const
3451 return mComboBox->currentData();
3453 return mPanel->value();
3454 else if ( mCheckboxPanel )
3455 return mCheckboxPanel->value();
3460QString QgsProcessingEnumWidgetWrapper::modelerExpressionFormatString()
const
3462 return tr(
"selected option index (starting from 0), array of indices, or comma separated string of options (e.g. '1,3')" );
3465QString QgsProcessingEnumWidgetWrapper::parameterType()
const
3472 return new QgsProcessingEnumWidgetWrapper( parameter, type );
3479 return new QgsProcessingEnumParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3490QWidget *QgsProcessingLayoutWidgetWrapper::createWidget()
3502 mComboBox =
new QgsLayoutComboBox(
nullptr, widgetContext().project() ? widgetContext().project()->layoutManager() :
nullptr );
3504 mComboBox->setAllowEmptyLayout(
true );
3507 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3514 mPlainComboBox =
new QComboBox();
3515 mPlainComboBox->setEditable(
true );
3516 mPlainComboBox->setToolTip( tr(
"Name of an existing print layout" ) );
3517 if ( widgetContext().project() )
3521 mPlainComboBox->addItem( layout->name() );
3524 connect( mPlainComboBox, &QComboBox::currentTextChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
3525 return mPlainComboBox;
3531void QgsProcessingLayoutWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3535 if ( !value.isValid() )
3536 mComboBox->setCurrentLayout(
nullptr );
3540 mComboBox->setCurrentLayout( l );
3542 mComboBox->setCurrentLayout(
nullptr );
3545 else if ( mPlainComboBox )
3548 mPlainComboBox->setCurrentText( v );
3552QVariant QgsProcessingLayoutWidgetWrapper::widgetValue()
const
3557 return l ? l->
name() : QVariant();
3559 else if ( mPlainComboBox )
3560 return mPlainComboBox->currentText().isEmpty() ? QVariant() : mPlainComboBox->currentText();
3568 if ( mPlainComboBox && context.
project() )
3572 mPlainComboBox->addItem( layout->name() );
3576QString QgsProcessingLayoutWidgetWrapper::modelerExpressionFormatString()
const
3578 return tr(
"string representing the name of an existing print layout" );
3581QString QgsProcessingLayoutWidgetWrapper::parameterType()
const
3588 return new QgsProcessingLayoutWidgetWrapper( parameter, type );
3597QgsProcessingLayoutItemParameterDefinitionWidget::QgsProcessingLayoutItemParameterDefinitionWidget(
3602 QVBoxLayout *vlayout =
new QVBoxLayout();
3603 vlayout->setContentsMargins( 0, 0, 0, 0 );
3605 vlayout->addWidget(
new QLabel( tr(
"Parent layout" ) ) );
3607 mParentLayoutComboBox =
new QComboBox();
3608 QString initialParent;
3610 initialParent = itemParam->parentLayoutParameterName();
3612 if (
auto *lModel = widgetContext.
model() )
3615 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
3616 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
3620 mParentLayoutComboBox->addItem( definition->
description(), definition->
name() );
3621 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
3623 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3629 if ( mParentLayoutComboBox->count() == 0 && !initialParent.isEmpty() )
3632 mParentLayoutComboBox->addItem( initialParent, initialParent );
3633 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
3636 vlayout->addWidget( mParentLayoutComboBox );
3640 setLayout( vlayout );
3644 auto param = std::make_unique<QgsProcessingParameterLayoutItem>( name, description, QVariant(), mParentLayoutComboBox->currentData().toString() );
3646 return param.release();
3654QWidget *QgsProcessingLayoutItemWidgetWrapper::createWidget()
3668 mComboBox->setAllowEmptyItem(
true );
3669 if ( layoutParam->
itemType() >= 0 )
3672 mComboBox->setToolTip( parameterDefinition()->toolTip() );
3679 mLineEdit =
new QLineEdit();
3680 mLineEdit->setToolTip( tr(
"UUID or ID of an existing print layout item" ) );
3681 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
3688void QgsProcessingLayoutItemWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
3713void QgsProcessingLayoutItemWidgetWrapper::setLayoutParameterValue(
const QVariant &value )
3719 std::unique_ptr<QgsProcessingContext> tmpContext;
3720 if ( mProcessingContextGenerator )
3721 context = mProcessingContextGenerator->processingContext();
3725 tmpContext = std::make_unique<QgsProcessingContext>();
3726 context = tmpContext.get();
3730 setLayout( layout );
3733void QgsProcessingLayoutItemWidgetWrapper::setLayout(
QgsPrintLayout *layout )
3736 mComboBox->setCurrentLayout( layout );
3739void QgsProcessingLayoutItemWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
3743 if ( !value.isValid() )
3744 mComboBox->setItem(
nullptr );
3748 mComboBox->setItem( item );
3751 else if ( mLineEdit )
3754 mLineEdit->setText( v );
3758QVariant QgsProcessingLayoutItemWidgetWrapper::widgetValue()
const
3763 return i ? i->
uuid() : QVariant();
3765 else if ( mLineEdit )
3766 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
3772QString QgsProcessingLayoutItemWidgetWrapper::modelerExpressionFormatString()
const
3774 return tr(
"string representing the UUID or ID of an existing print layout item" );
3777QString QgsProcessingLayoutItemWidgetWrapper::parameterType()
const
3784 return new QgsProcessingLayoutItemWidgetWrapper( parameter, type );
3791 return new QgsProcessingLayoutItemParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
3798QgsProcessingPointMapTool::QgsProcessingPointMapTool(
QgsMapCanvas *canvas )
3802 mSnapIndicator = std::make_unique<QgsSnapIndicator>( canvas );
3805QgsProcessingPointMapTool::~QgsProcessingPointMapTool() =
default;
3807void QgsProcessingPointMapTool::deactivate()
3821 if ( e->button() == Qt::LeftButton )
3824 emit clicked( point );
3829void QgsProcessingPointMapTool::keyPressEvent( QKeyEvent *e )
3831 if ( e->key() == Qt::Key_Escape )
3844QgsProcessingPointPanel::QgsProcessingPointPanel( QWidget *parent )
3847 QHBoxLayout *l =
new QHBoxLayout();
3848 l->setContentsMargins( 0, 0, 0, 0 );
3850 mLineEdit->setShowClearButton(
false );
3851 l->addWidget( mLineEdit, 1 );
3852 mButton =
new QToolButton();
3853 mButton->setText( QString( QChar( 0x2026 ) ) );
3854 l->addWidget( mButton );
3857 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::changed );
3858 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::textChanged );
3859 connect( mButton, &QToolButton::clicked,
this, &QgsProcessingPointPanel::selectOnCanvas );
3860 mButton->setVisible(
false );
3863QgsProcessingPointPanel::~QgsProcessingPointPanel()
3865 if ( mCanvas && mPrevTool && mCanvas->mapTool() == mTool.get() )
3867 mCanvas->setMapTool( mPrevTool.get() );
3871void QgsProcessingPointPanel::setMapCanvas(
QgsMapCanvas *canvas )
3874 if ( mAllowSelectOnCanvas )
3876 mButton->setVisible(
true );
3879 mTool = std::make_unique<QgsProcessingPointMapTool>( mCanvas );
3880 connect( mTool.get(), &QgsProcessingPointMapTool::clicked,
this, &QgsProcessingPointPanel::updatePoint );
3881 connect( mTool.get(), &QgsProcessingPointMapTool::complete,
this, &QgsProcessingPointPanel::pointPicked );
3885void QgsProcessingPointPanel::setAllowNull(
bool allowNull )
3887 mLineEdit->setShowClearButton( allowNull );
3890void QgsProcessingPointPanel::setShowPointOnCanvas(
bool show )
3892 if ( mShowPointOnCanvas == show )
3895 mShowPointOnCanvas = show;
3896 if ( mShowPointOnCanvas )
3902 mMapPointRubberBand.reset();
3906void QgsProcessingPointPanel::setAllowSelectOnCanvas(
bool allow )
3908 mAllowSelectOnCanvas = allow;
3909 mButton->setVisible( mAllowSelectOnCanvas &&
static_cast<bool>( mTool ) );
3912QVariant QgsProcessingPointPanel::value()
const
3914 return mLineEdit->showClearButton() && mLineEdit->text().trimmed().isEmpty() ? QVariant() : QVariant( mLineEdit->text() );
3917void QgsProcessingPointPanel::clear()
3925 QString newText = u
"%1,%2"_s.arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) );
3928 if ( mCrs.isValid() )
3930 newText += u
" [%1]"_s.arg( mCrs.authid() );
3932 mLineEdit->setText( newText );
3936void QgsProcessingPointPanel::showEvent( QShowEvent * )
3941 if ( QWidget *parentWindow = window() )
3943 setAllowSelectOnCanvas( !parentWindow->isModal() );
3949void QgsProcessingPointPanel::selectOnCanvas()
3954 mPrevTool = mCanvas->mapTool();
3955 mCanvas->setMapTool( mTool.get() );
3957 emit toggleDialogVisibility(
false );
3960void QgsProcessingPointPanel::updatePoint(
const QgsPointXY &point )
3962 setValue( point, mCanvas->mapSettings().destinationCrs() );
3965void QgsProcessingPointPanel::pointPicked()
3970 mCanvas->setMapTool( mPrevTool );
3972 emit toggleDialogVisibility(
true );
3975void QgsProcessingPointPanel::textChanged(
const QString &text )
3977 const thread_local QRegularExpression rx( u
"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
3979 const QRegularExpressionMatch match = rx.match( text );
3980 if ( match.hasMatch() )
3983 const double x = match.captured( 1 ).toDouble( &xOk );
3985 const double y = match.captured( 2 ).toDouble( &yOk );
3992 if ( pointCrs.isValid() )
4010void QgsProcessingPointPanel::updateRubberBand()
4012 if ( !mShowPointOnCanvas || !mCanvas )
4015 if ( mPoint.isEmpty() )
4017 mMapPointRubberBand.reset();
4021 if ( !mMapPointRubberBand )
4024 mMapPointRubberBand->setZValue( 1000 );
4027 const double scaleFactor = mCanvas->fontMetrics().xHeight() * .4;
4028 mMapPointRubberBand->setWidth( scaleFactor );
4029 mMapPointRubberBand->setIconSize( scaleFactor * 5 );
4031 mMapPointRubberBand->setSecondaryStrokeColor( QColor( 255, 255, 255, 100 ) );
4032 mMapPointRubberBand->setColor( QColor( 200, 0, 200 ) );
4043QgsProcessingPointParameterDefinitionWidget::QgsProcessingPointParameterDefinitionWidget(
4048 QVBoxLayout *vlayout =
new QVBoxLayout();
4049 vlayout->setContentsMargins( 0, 0, 0, 0 );
4051 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4053 mDefaultLineEdit =
new QLineEdit();
4054 mDefaultLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
4055 mDefaultLineEdit->setPlaceholderText( tr(
"Point as 'x,y'" ) );
4059 mDefaultLineEdit->setText( u
"%1,%2"_s.arg( QString::number( point.
x(),
'f' ), QString::number( point.
y(),
'f' ) ) );
4062 vlayout->addWidget( mDefaultLineEdit );
4066 setLayout( vlayout );
4071 auto param = std::make_unique<QgsProcessingParameterPoint>( name, description, mDefaultLineEdit->text() );
4073 return param.release();
4080QWidget *QgsProcessingPointWidgetWrapper::createWidget()
4091 mPanel =
new QgsProcessingPointPanel(
nullptr );
4092 if ( widgetContext().mapCanvas() )
4093 mPanel->setMapCanvas( widgetContext().mapCanvas() );
4096 mPanel->setAllowNull(
true );
4099 mPanel->setShowPointOnCanvas(
true );
4101 mPanel->setToolTip( parameterDefinition()->toolTip() );
4103 connect( mPanel, &QgsProcessingPointPanel::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
4106 setDialog( mDialog );
4112 mLineEdit =
new QLineEdit();
4113 mLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
4114 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this](
const QString & ) { emit widgetValueHasChanged(
this ); } );
4125 mPanel->setMapCanvas( context.
mapCanvas() );
4128void QgsProcessingPointWidgetWrapper::setDialog( QWidget *dialog )
4133 connect( mPanel, &QgsProcessingPointPanel::toggleDialogVisibility, mDialog, [
this](
bool visible ) {
4135 mDialog->showMinimized();
4138 mDialog->showNormal();
4140 mDialog->activateWindow();
4147void QgsProcessingPointWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4151 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) )
4157 mPanel->setValue( p, crs );
4160 else if ( mLineEdit )
4163 mLineEdit->setText( v );
4167QVariant QgsProcessingPointWidgetWrapper::widgetValue()
const
4171 return mPanel->value();
4173 else if ( mLineEdit )
4174 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
4179QString QgsProcessingPointWidgetWrapper::modelerExpressionFormatString()
const
4181 return tr(
"string of the format 'x,y' or a geometry value (centroid is used)" );
4184QString QgsProcessingPointWidgetWrapper::parameterType()
const
4191 return new QgsProcessingPointWidgetWrapper( parameter, type );
4198 return new QgsProcessingPointParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4207QgsProcessingGeometryParameterDefinitionWidget::QgsProcessingGeometryParameterDefinitionWidget(
4212 QVBoxLayout *vlayout =
new QVBoxLayout();
4213 vlayout->setContentsMargins( 0, 0, 0, 0 );
4215 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4227 vlayout->addWidget( mGeometryWidget );
4231 setLayout( vlayout );
4237 auto param = std::make_unique<QgsProcessingParameterGeometry>( name, description, geometry.
isEmpty() ? QVariant() : geometry.
asWkt() );
4239 return param.release();
4246QWidget *QgsProcessingGeometryWidgetWrapper::createWidget()
4255 mGeometryWidget->setToolTip( parameterDefinition()->toolTip() );
4257 return mGeometryWidget;
4263void QgsProcessingGeometryWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4265 if ( mGeometryWidget )
4274 mGeometryWidget->clearGeometry();
4279QVariant QgsProcessingGeometryWidgetWrapper::widgetValue()
const
4281 if ( mGeometryWidget )
4284 return geometry.
isEmpty() ? QVariant() : geometry.asWkt();
4292QString QgsProcessingGeometryWidgetWrapper::modelerExpressionFormatString()
const
4294 return tr(
"string in the Well-Known-Text format or a geometry value" );
4297QString QgsProcessingGeometryWidgetWrapper::parameterType()
const
4304 return new QgsProcessingGeometryWidgetWrapper( parameter, type );
4311 return new QgsProcessingGeometryParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4320QgsProcessingColorParameterDefinitionWidget::QgsProcessingColorParameterDefinitionWidget(
4325 QVBoxLayout *vlayout =
new QVBoxLayout();
4326 vlayout->setContentsMargins( 0, 0, 0, 0 );
4328 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4331 mDefaultColorButton->setShowNull(
true );
4332 mAllowOpacity =
new QCheckBox( tr(
"Allow opacity control" ) );
4338 mDefaultColorButton->setToNull();
4340 mDefaultColorButton->setColor(
c );
4341 mAllowOpacity->setChecked( colorParam->opacityEnabled() );
4345 mDefaultColorButton->setToNull();
4346 mAllowOpacity->setChecked(
true );
4352 vlayout->addWidget( mDefaultColorButton );
4353 vlayout->addWidget( mAllowOpacity );
4354 setLayout( vlayout );
4359 auto param = std::make_unique<QgsProcessingParameterColor>( name, description, mDefaultColorButton->color(), mAllowOpacity->isChecked() );
4361 return param.release();
4368QWidget *QgsProcessingColorWidgetWrapper::createWidget()
4381 mColorButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
4384 mColorButton->setShowNull(
true );
4387 mColorButton->setToolTip( parameterDefinition()->toolTip() );
4388 mColorButton->setColorDialogTitle( parameterDefinition()->description() );
4396 return mColorButton;
4402void QgsProcessingColorWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
4406 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) || ( value.userType() == QMetaType::Type::QColor && !value.value<QColor>().isValid() ) )
4407 mColorButton->setToNull();
4411 if ( !
c.isValid() && mColorButton->showNull() )
4412 mColorButton->setToNull();
4414 mColorButton->setColor(
c );
4419QVariant QgsProcessingColorWidgetWrapper::widgetValue()
const
4422 return mColorButton->isNull() ? QVariant() : mColorButton->color();
4427QString QgsProcessingColorWidgetWrapper::modelerExpressionFormatString()
const
4429 return tr(
"color style string, e.g. #ff0000 or 255,0,0" );
4432QString QgsProcessingColorWidgetWrapper::parameterType()
const
4439 return new QgsProcessingColorWidgetWrapper( parameter, type );
4446 return new QgsProcessingColorParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4454QgsProcessingCoordinateOperationParameterDefinitionWidget::QgsProcessingCoordinateOperationParameterDefinitionWidget(
4459 QVBoxLayout *vlayout =
new QVBoxLayout();
4460 vlayout->setContentsMargins( 0, 0, 0, 0 );
4462 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4464 mDefaultLineEdit =
new QLineEdit();
4467 vlayout->addWidget( mDefaultLineEdit );
4471 mSourceParamComboBox =
new QComboBox();
4472 mDestParamComboBox =
new QComboBox();
4473 QString initialSource;
4474 QString initialDest;
4479 initialSource = itemParam->sourceCrsParameterName();
4480 initialDest = itemParam->destinationCrsParameterName();
4485 mSourceParamComboBox->addItem( QString(), QString() );
4486 mDestParamComboBox->addItem( QString(), QString() );
4487 if (
auto *lModel = widgetContext.
model() )
4490 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4491 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4493 if ( definition && it->parameterName() == definition->
name() )
4497 mSourceParamComboBox->addItem( it->parameterName(), it->parameterName() );
4498 mDestParamComboBox->addItem( it->parameterName(), it->parameterName() );
4499 if ( !initialSource.isEmpty() && initialSource == it->parameterName() )
4501 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
4503 if ( !initialDest.isEmpty() && initialDest == it->parameterName() )
4505 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
4510 if ( mSourceParamComboBox->count() == 1 && !initialSource.isEmpty() )
4513 mSourceParamComboBox->addItem( initialSource, initialSource );
4514 mSourceParamComboBox->setCurrentIndex( mSourceParamComboBox->count() - 1 );
4516 if ( mDestParamComboBox->count() == 1 && !initialDest.isEmpty() )
4519 mDestParamComboBox->addItem( initialDest, initialDest );
4520 mDestParamComboBox->setCurrentIndex( mDestParamComboBox->count() - 1 );
4523 vlayout->addWidget(
new QLabel( tr(
"Source CRS parameter" ) ) );
4524 vlayout->addWidget( mSourceParamComboBox );
4525 vlayout->addWidget(
new QLabel( tr(
"Destination CRS parameter" ) ) );
4526 vlayout->addWidget( mDestParamComboBox );
4533 mStaticSourceWidget->setCrs( sourceCrs );
4536 mStaticDestWidget->setCrs( destCrs );
4538 vlayout->addWidget(
new QLabel( tr(
"Static source CRS" ) ) );
4539 vlayout->addWidget( mStaticSourceWidget );
4540 vlayout->addWidget(
new QLabel( tr(
"Static destination CRS" ) ) );
4541 vlayout->addWidget( mStaticDestWidget );
4546 setLayout( vlayout );
4551 auto param = std::make_unique<QgsProcessingParameterCoordinateOperation>(
4554 mDefaultLineEdit->text(),
4555 mSourceParamComboBox->currentText(),
4556 mDestParamComboBox->currentText(),
4557 mStaticSourceWidget->crs().isValid() ? QVariant::fromValue( mStaticSourceWidget->crs() ) : QVariant(),
4558 mStaticDestWidget->crs().isValid() ? QVariant::fromValue( mStaticDestWidget->crs() ) : QVariant()
4561 return param.release();
4568QWidget *QgsProcessingCoordinateOperationWidgetWrapper::createWidget()
4582 mOperationWidget->setShowMakeDefault(
false );
4583 mOperationWidget->setShowFallbackOption(
false );
4584 mOperationWidget->setToolTip( parameterDefinition()->toolTip() );
4585 mOperationWidget->setSourceCrs( mSourceCrs );
4586 mOperationWidget->setDestinationCrs( mDestCrs );
4587 mOperationWidget->setMapCanvas( mCanvas );
4592 mOperationWidget->setSelectedOperation( deets );
4597 return mOperationWidget;
4603 mLineEdit =
new QLineEdit();
4604 QHBoxLayout *layout =
new QHBoxLayout();
4605 layout->addWidget( mLineEdit, 1 );
4606 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
4608 QToolButton *button =
new QToolButton();
4609 button->setText( QString( QChar( 0x2026 ) ) );
4610 connect( button, &QToolButton::clicked,
this, [
this, button] {
4611 QgsDatumTransformDialog dlg( mSourceCrs, mDestCrs,
false,
false,
false, qMakePair( -1, -1 ), button, Qt::WindowFlags(), mLineEdit->text(), mCanvas );
4614 mLineEdit->setText( dlg.selectedDatumTransform().proj );
4615 emit widgetValueHasChanged(
this );
4618 layout->addWidget( button );
4620 QWidget *w =
new QWidget();
4621 layout->setContentsMargins( 0, 0, 0, 0 );
4622 w->setLayout( layout );
4629void QgsProcessingCoordinateOperationWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
4661 if ( mOperationWidget )
4662 mOperationWidget->setMapCanvas( context.
mapCanvas() );
4665void QgsProcessingCoordinateOperationWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
4667 if ( mOperationWidget )
4669 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString ) )
4672 deets.
proj = value.toString();
4673 mOperationWidget->setSelectedOperation( deets );
4678 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString ) )
4680 mLineEdit->setText( value.toString() );
4685QVariant QgsProcessingCoordinateOperationWidgetWrapper::widgetValue()
const
4687 if ( mOperationWidget )
4688 return mOperationWidget->selectedOperation().proj;
4689 else if ( mLineEdit )
4690 return mLineEdit->text();
4695QString QgsProcessingCoordinateOperationWidgetWrapper::modelerExpressionFormatString()
const
4697 return tr(
"Proj coordinate operation string, e.g. '+proj=pipeline +step +inv...'" );
4700void QgsProcessingCoordinateOperationWidgetWrapper::setSourceCrsParameterValue(
const QVariant &value )
4703 std::unique_ptr<QgsProcessingContext> tmpContext;
4704 if ( mProcessingContextGenerator )
4705 context = mProcessingContextGenerator->processingContext();
4709 tmpContext = std::make_unique<QgsProcessingContext>();
4710 context = tmpContext.get();
4714 if ( mOperationWidget )
4716 mOperationWidget->setSourceCrs( mSourceCrs );
4717 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4721void QgsProcessingCoordinateOperationWidgetWrapper::setDestinationCrsParameterValue(
const QVariant &value )
4724 std::unique_ptr<QgsProcessingContext> tmpContext;
4725 if ( mProcessingContextGenerator )
4726 context = mProcessingContextGenerator->processingContext();
4730 tmpContext = std::make_unique<QgsProcessingContext>();
4731 context = tmpContext.get();
4735 if ( mOperationWidget )
4737 mOperationWidget->setDestinationCrs( mDestCrs );
4738 mOperationWidget->setSelectedOperationUsingContext( context->
transformContext() );
4742QString QgsProcessingCoordinateOperationWidgetWrapper::parameterType()
const
4749 return new QgsProcessingCoordinateOperationWidgetWrapper( parameter, type );
4756 return new QgsProcessingCoordinateOperationParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
4768 QHBoxLayout *hl =
new QHBoxLayout();
4769 hl->setContentsMargins( 0, 0, 0, 0 );
4771 mLineEdit =
new QLineEdit();
4772 mLineEdit->setEnabled(
false );
4773 hl->addWidget( mLineEdit, 1 );
4775 mToolButton =
new QToolButton();
4776 mToolButton->setText( QString( QChar( 0x2026 ) ) );
4777 hl->addWidget( mToolButton );
4783 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4786 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingFieldPanelWidget::showDialog );
4789void QgsProcessingFieldPanelWidget::setFields(
const QgsFields &fields )
4795 QVariantList availableFields;
4796 for (
const QgsField &field : std::as_const( mFields ) )
4798 availableFields << field.name();
4800 QList<QVariant>::iterator it = std::remove_if( mValue.begin(), mValue.end(), [&availableFields](
const QVariant &value ) { return !availableFields.contains( value ); } );
4801 mValue.erase( it, mValue.end() );
4803 updateSummaryText();
4807void QgsProcessingFieldPanelWidget::setValue(
const QVariant &value )
4809 if ( value.isValid() )
4810 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
4814 updateSummaryText();
4818void QgsProcessingFieldPanelWidget::showDialog()
4820 QVariantList availableOptions;
4821 availableOptions.reserve( mFields.size() );
4822 for (
const QgsField &field : std::as_const( mFields ) )
4824 availableOptions << field.name();
4830 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
4831 widget->setPanelTitle( mParam->description() );
4833 widget->setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
4835 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
4841 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
4843 dlg.setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
4846 setValue( dlg.selectedOptions() );
4851void QgsProcessingFieldPanelWidget::updateSummaryText()
4856 if ( mValue.empty() )
4858 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, 0 ) );
4863 values.reserve( mValue.size() );
4864 for (
const QVariant &val : std::as_const( mValue ) )
4866 values << val.toString();
4869 const QString concatenated = values.join( tr(
"," ) );
4870 if ( concatenated.length() < 100 )
4871 mLineEdit->setText( concatenated );
4873 mLineEdit->setText( tr(
"%n field(s) selected",
nullptr, mValue.count() ) );
4882QgsProcessingFieldParameterDefinitionWidget::QgsProcessingFieldParameterDefinitionWidget(
4887 QVBoxLayout *vlayout =
new QVBoxLayout();
4888 vlayout->setContentsMargins( 0, 0, 0, 0 );
4890 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
4891 mParentLayerComboBox =
new QComboBox();
4893 QString initialParent;
4895 initialParent = fieldParam->parentLayerParameterName();
4897 if (
auto *lModel = widgetContext.
model() )
4900 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
4901 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
4905 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4906 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4908 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4913 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4914 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4916 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4923 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
4924 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
4926 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4933 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
4936 mParentLayerComboBox->addItem( initialParent, initialParent );
4937 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
4940 vlayout->addWidget( mParentLayerComboBox );
4943 vlayout->addWidget(
new QLabel( tr(
"Allowed data type" ) ) );
4944 mDataTypeComboBox =
new QComboBox();
4952 mDataTypeComboBox->setCurrentIndex( mDataTypeComboBox->findData(
static_cast<int>( fieldParam->dataType() ) ) );
4954 vlayout->addWidget( mDataTypeComboBox );
4957 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple fields" ) );
4959 mAllowMultipleCheckBox->setChecked( fieldParam->allowMultiple() );
4961 vlayout->addWidget( mAllowMultipleCheckBox );
4966 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all fields by default" ) );
4967 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
4969 mDefaultToAllCheckBox->setChecked( fieldParam->defaultToAllFields() );
4971 vlayout->addWidget( mDefaultToAllCheckBox );
4974 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [
this] { mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() ); } );
4976 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
4978 mDefaultLineEdit =
new QLineEdit();
4979 mDefaultLineEdit->setToolTip( tr(
"Default field name, or ; separated list of field names for multiple field parameters" ) );
4983 mDefaultLineEdit->setText( fields.join(
';' ) );
4985 vlayout->addWidget( mDefaultLineEdit );
4989 setLayout( vlayout );
4996 QVariant defaultValue;
4997 if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
4999 defaultValue = mDefaultLineEdit->text();
5001 auto param = std::make_unique<
5002 QgsProcessingParameterField>( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), dataType, mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
5004 return param.release();
5011QWidget *QgsProcessingFieldWidgetWrapper::createWidget()
5024 mPanel =
new QgsProcessingFieldPanelWidget(
nullptr, fieldParam );
5025 mPanel->setToolTip( parameterDefinition()->toolTip() );
5026 connect( mPanel, &QgsProcessingFieldPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
5045 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5053 mLineEdit =
new QLineEdit();
5054 mLineEdit->setToolTip( QObject::tr(
"Name of field (separate field names with ; for multiple field parameters)" ) );
5055 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
5062void QgsProcessingFieldWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
5074 setParentLayerWrapperValue( wrapper );
5091 std::unique_ptr<QgsProcessingContext> tmpContext;
5092 if ( mProcessingContextGenerator )
5093 context = mProcessingContextGenerator->processingContext();
5097 tmpContext = std::make_unique<QgsProcessingContext>();
5098 context = tmpContext.get();
5103 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
5113 bool valueSet =
false;
5117 if ( layers.count() > 1 )
5119 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layers.at( 0 ) );
5121 const QList<QgsMapLayer *> remainingLayers = layers.mid( 1 );
5127 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
5128 if ( !vlayer || !vlayer->
isValid() )
5134 for (
int fieldIdx = fields.
count() - 1; fieldIdx >= 0; fieldIdx-- )
5137 fields.
remove( fieldIdx );
5142 mComboBox->setFields( fields );
5144 mPanel->setFields( filterFields( fields ) );
5150 if ( !valueSet && !layers.isEmpty() && layers.at( 0 )->isValid() )
5152 QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( layers.at( 0 ) );
5156 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
5159 mParentLayer.reset( qobject_cast<QgsVectorLayer *>( ownedLayer.release() ) );
5160 layer = mParentLayer.get();
5168 mComboBox->setLayer( layer );
5170 mPanel->setFields( filterFields( layer->
fields() ) );
5180 const QgsFields fields = source->fields();
5182 mComboBox->setFields( fields );
5184 mPanel->setFields( filterFields( fields ) );
5193 mComboBox->setLayer(
nullptr );
5197 if ( value.isValid() && widgetContext().messageBar() )
5209 val.reserve( mPanel->fields().size() );
5210 for (
const QgsField &field : mPanel->fields() )
5211 val << field.name();
5212 setWidgetValue( val, *context );
5215 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5218void QgsProcessingFieldWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5222 if ( !value.isValid() )
5223 mComboBox->setField( QString() );
5227 mComboBox->setField( v );
5233 if ( value.isValid() )
5236 opts.reserve( v.size() );
5237 for (
const QString &i : v )
5241 mPanel->setValue( opts );
5243 else if ( mLineEdit )
5249 mLineEdit->setText( v.join(
';' ) );
5258QVariant QgsProcessingFieldWidgetWrapper::widgetValue()
const
5261 return mComboBox->currentField();
5263 return mPanel->value();
5264 else if ( mLineEdit )
5269 return mLineEdit->text().split(
';' );
5272 return mLineEdit->text();
5278QString QgsProcessingFieldWidgetWrapper::modelerExpressionFormatString()
const
5280 return tr(
"selected field names as an array of names, or semicolon separated string of options (e.g. 'fid;place_name')" );
5283const QgsVectorLayer *QgsProcessingFieldWidgetWrapper::linkedVectorLayer()
const
5285 if ( mComboBox && mComboBox->layer() )
5286 return mComboBox->layer();
5291QgsFields QgsProcessingFieldWidgetWrapper::filterFields(
const QgsFields &fields )
const
5304 if ( f.isNumeric() )
5309 if ( f.type() == QMetaType::Type::QString )
5314 if ( f.type() == QMetaType::Type::QDate || f.type() == QMetaType::Type::QTime || f.type() == QMetaType::Type::QDateTime )
5319 if ( f.type() == QMetaType::Type::QByteArray )
5324 if ( f.type() == QMetaType::Type::Bool )
5333QString QgsProcessingFieldWidgetWrapper::parameterType()
const
5340 return new QgsProcessingFieldWidgetWrapper( parameter, type );
5347 return new QgsProcessingFieldParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5355QgsProcessingMapThemeParameterDefinitionWidget::QgsProcessingMapThemeParameterDefinitionWidget(
5360 QVBoxLayout *vlayout =
new QVBoxLayout();
5361 vlayout->setContentsMargins( 0, 0, 0, 0 );
5363 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5365 mDefaultComboBox =
new QComboBox();
5366 mDefaultComboBox->addItem( QString(), QVariant( -1 ) );
5369 for (
const QString &theme : mapThemes )
5373 mDefaultComboBox->setEditable(
true );
5377 if ( themeParam->defaultValueForGui().isValid() )
5380 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
5383 mDefaultComboBox->setCurrentIndex( mDefaultComboBox->findData( -1 ) );
5385 vlayout->addWidget( mDefaultComboBox );
5389 setLayout( vlayout );
5394 QVariant defaultVal;
5395 if ( mDefaultComboBox->currentText().isEmpty() )
5396 defaultVal = QVariant();
5398 defaultVal = mDefaultComboBox->currentText();
5399 auto param = std::make_unique<QgsProcessingParameterMapTheme>( name, description, defaultVal );
5401 return param.release();
5409QWidget *QgsProcessingMapThemeWidgetWrapper::createWidget()
5415 mComboBox =
new QComboBox();
5418 mComboBox->addItem( tr(
"[Not selected]" ), QVariant( -1 ) );
5421 for (
const QString &theme : mapThemes )
5433 mComboBox->setEditable(
true );
5437 mComboBox->setToolTip( parameterDefinition()->toolTip() );
5438 connect( mComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { emit widgetValueHasChanged(
this ); } );
5443void QgsProcessingMapThemeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5447 if ( !value.isValid() )
5448 mComboBox->setCurrentIndex( mComboBox->findData( QVariant( -1 ) ) );
5451 if ( mComboBox->isEditable() && mComboBox->findData( v ) == -1 )
5453 const QString prev = mComboBox->currentText();
5454 mComboBox->setCurrentText( v );
5456 emit widgetValueHasChanged(
this );
5459 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
5463QVariant QgsProcessingMapThemeWidgetWrapper::widgetValue()
const
5466 return mComboBox->currentData().toInt() == -1 ? QVariant()
5467 : !mComboBox->currentData().isValid() && mComboBox->isEditable() ? mComboBox->currentText().isEmpty() ? QVariant() : QVariant( mComboBox->currentText() )
5468 : mComboBox->currentData();
5473QString QgsProcessingMapThemeWidgetWrapper::modelerExpressionFormatString()
const
5475 return tr(
"map theme as a string value (e.g. 'base maps')" );
5478QString QgsProcessingMapThemeWidgetWrapper::parameterType()
const
5485 return new QgsProcessingMapThemeWidgetWrapper( parameter, type );
5492 return new QgsProcessingMapThemeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5501QgsProcessingDateTimeParameterDefinitionWidget::QgsProcessingDateTimeParameterDefinitionWidget(
5506 QVBoxLayout *vlayout =
new QVBoxLayout();
5507 vlayout->setContentsMargins( 0, 0, 0, 0 );
5509 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
5511 mTypeComboBox =
new QComboBox();
5516 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData(
static_cast<int>( datetimeParam->dataType() ) ) );
5518 mTypeComboBox->setCurrentIndex( 0 );
5519 vlayout->addWidget( mTypeComboBox );
5523 setLayout( vlayout );
5528 auto param = std::make_unique<QgsProcessingParameterDateTime>( name, description );
5531 return param.release();
5539QWidget *QgsProcessingDateTimeWidgetWrapper::createWidget()
5542 if ( !dateTimeParam )
5546 switch ( dateTimeParam->
dataType() )
5550 widget = mDateTimeEdit;
5575 widget->setToolTip( parameterDefinition()->toolTip() );
5577 if ( mDateTimeEdit )
5581 else if ( mDateEdit )
5585 else if ( mTimeEdit )
5597 return new QgsProcessingDateTimeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5600void QgsProcessingDateTimeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5602 if ( mDateTimeEdit )
5606 else if ( mDateEdit )
5610 else if ( mTimeEdit )
5616QVariant QgsProcessingDateTimeWidgetWrapper::widgetValue()
const
5618 if ( mDateTimeEdit )
5619 return !mDateTimeEdit->dateTime().isNull() && mDateTimeEdit->dateTime().isValid() ? QVariant( mDateTimeEdit->dateTime() ) : QVariant();
5620 else if ( mDateEdit )
5621 return !mDateEdit->date().isNull() && mDateEdit->date().isValid() ? QVariant( mDateEdit->date() ) : QVariant();
5622 else if ( mTimeEdit )
5623 return !mTimeEdit->time().isNull() && mTimeEdit->time().isValid() ? QVariant( mTimeEdit->time() ) : QVariant();
5628QString QgsProcessingDateTimeWidgetWrapper::modelerExpressionFormatString()
const
5631 if ( dateTimeParam )
5633 switch ( dateTimeParam->
dataType() )
5636 return tr(
"datetime value, or a ISO string representation of a datetime" );
5639 return tr(
"date value, or a ISO string representation of a date" );
5642 return tr(
"time value, or a ISO string representation of a time" );
5648QString QgsProcessingDateTimeWidgetWrapper::parameterType()
const
5655 return new QgsProcessingDateTimeWidgetWrapper( parameter, type );
5663QgsProcessingProviderConnectionParameterDefinitionWidget::QgsProcessingProviderConnectionParameterDefinitionWidget(
5670 QVBoxLayout *vlayout =
new QVBoxLayout();
5671 vlayout->setContentsMargins( 0, 0, 0, 0 );
5673 vlayout->addWidget(
new QLabel( tr(
"Provider" ) ) );
5674 mProviderComboBox =
new QComboBox();
5675 mProviderComboBox->addItem( QObject::tr(
"Postgres" ), u
"postgres"_s );
5676 mProviderComboBox->addItem( QObject::tr(
"GeoPackage" ), u
"ogr"_s );
5677 mProviderComboBox->addItem( QObject::tr(
"Spatialite" ), u
"spatialite"_s );
5679 vlayout->addWidget( mProviderComboBox );
5681 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5683 mDefaultEdit =
new QLineEdit();
5684 vlayout->addWidget( mDefaultEdit );
5685 setLayout( vlayout );
5687 if ( connectionParam )
5689 mProviderComboBox->setCurrentIndex( mProviderComboBox->findData( connectionParam->
providerId() ) );
5699 QVariant defaultVal;
5700 if ( mDefaultEdit->text().isEmpty() )
5701 defaultVal = QVariant();
5703 defaultVal = mDefaultEdit->text();
5704 auto param = std::make_unique<QgsProcessingParameterProviderConnection>( name, description, mProviderComboBox->currentData().toString(), defaultVal );
5706 return param.release();
5714QWidget *QgsProcessingProviderConnectionWidgetWrapper::createWidget()
5717 if ( !connectionParam )
5722 mProviderComboBox->setAllowEmptyConnection(
true );
5730 mProviderComboBox->setEditable(
true );
5734 mProviderComboBox->setToolTip( parameterDefinition()->toolTip() );
5735 connect( mProviderComboBox, &QgsProviderConnectionComboBox::currentTextChanged,
this, [
this](
const QString & ) {
5736 if ( mBlockSignals )
5739 emit widgetValueHasChanged(
this );
5742 return mProviderComboBox;
5749 return new QgsProcessingProviderConnectionParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5752void QgsProcessingProviderConnectionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5756 if ( !value.isValid() )
5757 mProviderComboBox->setCurrentIndex( -1 );
5760 if ( mProviderComboBox->isEditable() )
5762 const QString prev = mProviderComboBox->currentText();
5764 mProviderComboBox->setConnection( v );
5765 mProviderComboBox->setCurrentText( v );
5769 emit widgetValueHasChanged(
this );
5772 mProviderComboBox->setConnection( v );
5776QVariant QgsProcessingProviderConnectionWidgetWrapper::widgetValue()
const
5778 if ( mProviderComboBox )
5779 if ( mProviderComboBox->isEditable() )
5780 return mProviderComboBox->currentText().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentText() );
5782 return mProviderComboBox->currentConnection().isEmpty() ? QVariant() : QVariant( mProviderComboBox->currentConnection() );
5787QString QgsProcessingProviderConnectionWidgetWrapper::modelerExpressionFormatString()
const
5789 return tr(
"connection name as a string value" );
5792QString QgsProcessingProviderConnectionWidgetWrapper::parameterType()
const
5799 return new QgsProcessingProviderConnectionWidgetWrapper( parameter, type );
5807QgsProcessingDatabaseSchemaParameterDefinitionWidget::QgsProcessingDatabaseSchemaParameterDefinitionWidget(
5814 QVBoxLayout *vlayout =
new QVBoxLayout();
5815 vlayout->setContentsMargins( 0, 0, 0, 0 );
5817 mConnectionParamComboBox =
new QComboBox();
5818 QString initialConnection;
5824 if (
auto *lModel = widgetContext.
model() )
5827 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
5828 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
5830 if ( definition && it->parameterName() == definition->
name() )
5836 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
5837 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
5839 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5844 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
5847 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
5848 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
5851 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
5852 vlayout->addWidget( mConnectionParamComboBox );
5856 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
5858 mDefaultEdit =
new QLineEdit();
5859 vlayout->addWidget( mDefaultEdit );
5860 setLayout( vlayout );
5871 QVariant defaultVal;
5872 if ( mDefaultEdit->text().isEmpty() )
5873 defaultVal = QVariant();
5875 defaultVal = mDefaultEdit->text();
5876 auto param = std::make_unique<QgsProcessingParameterDatabaseSchema>( name, description, mConnectionParamComboBox->currentData().toString(), defaultVal );
5878 return param.release();
5886QWidget *QgsProcessingDatabaseSchemaWidgetWrapper::createWidget()
5894 mSchemaComboBox->setAllowEmptySchema(
true );
5902 mSchemaComboBox->comboBox()->setEditable(
true );
5906 mSchemaComboBox->setToolTip( parameterDefinition()->toolTip() );
5907 connect( mSchemaComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [
this](
const QString & ) {
5908 if ( mBlockSignals )
5911 emit widgetValueHasChanged( this );
5914 return mSchemaComboBox;
5921 return new QgsProcessingDatabaseSchemaParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
5928 std::unique_ptr<QgsProcessingContext> tmpContext;
5929 if ( mProcessingContextGenerator )
5930 context = mProcessingContextGenerator->processingContext();
5934 tmpContext = std::make_unique<QgsProcessingContext>();
5935 context = tmpContext.get();
5941 if ( mSchemaComboBox )
5942 mSchemaComboBox->setConnectionName( connection, qgis::down_cast<const QgsProcessingParameterProviderConnection *>( parentWrapper->
parameterDefinition() )->providerId() );
5946 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
5949void QgsProcessingDatabaseSchemaWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
5953 if ( !value.isValid() )
5954 mSchemaComboBox->comboBox()->setCurrentIndex( -1 );
5957 if ( mSchemaComboBox->comboBox()->isEditable() )
5959 const QString prev = mSchemaComboBox->comboBox()->currentText();
5961 mSchemaComboBox->setSchema( v );
5962 mSchemaComboBox->comboBox()->setCurrentText( v );
5966 emit widgetValueHasChanged(
this );
5969 mSchemaComboBox->setSchema( v );
5973QVariant QgsProcessingDatabaseSchemaWidgetWrapper::widgetValue()
const
5975 if ( mSchemaComboBox )
5976 if ( mSchemaComboBox->comboBox()->isEditable() )
5977 return mSchemaComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->comboBox()->currentText() );
5979 return mSchemaComboBox->currentSchema().isEmpty() ? QVariant() : QVariant( mSchemaComboBox->currentSchema() );
5984QString QgsProcessingDatabaseSchemaWidgetWrapper::modelerExpressionFormatString()
const
5986 return tr(
"database schema name as a string value" );
5989QString QgsProcessingDatabaseSchemaWidgetWrapper::parameterType()
const
5996 return new QgsProcessingDatabaseSchemaWidgetWrapper( parameter, type );
5999void QgsProcessingDatabaseSchemaWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6011 setParentConnectionWrapperValue( wrapper );
6029QgsProcessingDatabaseTableParameterDefinitionWidget::QgsProcessingDatabaseTableParameterDefinitionWidget(
6036 QVBoxLayout *vlayout =
new QVBoxLayout();
6037 vlayout->setContentsMargins( 0, 0, 0, 0 );
6039 mConnectionParamComboBox =
new QComboBox();
6040 mSchemaParamComboBox =
new QComboBox();
6041 QString initialConnection;
6042 QString initialSchema;
6049 if (
auto *lModel = widgetContext.
model() )
6052 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6053 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6055 if ( definition && it->parameterName() == definition->
name() )
6060 mConnectionParamComboBox->addItem( it->parameterName(), it->parameterName() );
6061 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
6063 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
6068 mSchemaParamComboBox->addItem( it->parameterName(), it->parameterName() );
6069 if ( !initialConnection.isEmpty() && initialConnection == it->parameterName() )
6071 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
6077 if ( mConnectionParamComboBox->count() == 0 && !initialConnection.isEmpty() )
6080 mConnectionParamComboBox->addItem( initialConnection, initialConnection );
6081 mConnectionParamComboBox->setCurrentIndex( mConnectionParamComboBox->count() - 1 );
6084 if ( mSchemaParamComboBox->count() == 0 && !initialSchema.isEmpty() )
6087 mSchemaParamComboBox->addItem( initialSchema, initialSchema );
6088 mSchemaParamComboBox->setCurrentIndex( mSchemaParamComboBox->count() - 1 );
6091 vlayout->addWidget(
new QLabel( tr(
"Provider connection parameter" ) ) );
6092 vlayout->addWidget( mConnectionParamComboBox );
6094 vlayout->addWidget(
new QLabel( tr(
"Database schema parameter" ) ) );
6095 vlayout->addWidget( mSchemaParamComboBox );
6100 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6102 mDefaultEdit =
new QLineEdit();
6103 vlayout->addWidget( mDefaultEdit );
6104 setLayout( vlayout );
6115 QVariant defaultVal;
6116 if ( mDefaultEdit->text().isEmpty() )
6117 defaultVal = QVariant();
6119 defaultVal = mDefaultEdit->text();
6120 auto param = std::make_unique<QgsProcessingParameterDatabaseTable>( name, description, mConnectionParamComboBox->currentData().toString(), mSchemaParamComboBox->currentData().toString(), defaultVal );
6122 return param.release();
6130QWidget *QgsProcessingDatabaseTableWidgetWrapper::createWidget()
6138 mTableComboBox->setAllowEmptyTable(
true );
6141 mTableComboBox->comboBox()->setEditable(
true );
6143 mTableComboBox->setToolTip( parameterDefinition()->toolTip() );
6144 connect( mTableComboBox->comboBox(), &QComboBox::currentTextChanged,
this, [
this](
const QString & ) {
6145 if ( mBlockSignals )
6148 emit widgetValueHasChanged( this );
6151 return mTableComboBox;
6158 return new QgsProcessingDatabaseTableParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6165 std::unique_ptr<QgsProcessingContext> tmpContext;
6166 if ( mProcessingContextGenerator )
6167 context = mProcessingContextGenerator->processingContext();
6171 tmpContext = std::make_unique<QgsProcessingContext>();
6172 context = tmpContext.get();
6177 mProvider = qgis::down_cast<const QgsProcessingParameterProviderConnection *>( parentWrapper->
parameterDefinition() )->providerId();
6178 if ( mTableComboBox && !mSchema.isEmpty() )
6180 mTableComboBox->setSchema( mSchema );
6181 mTableComboBox->setConnectionName( mConnection, mProvider );
6185 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6193 std::unique_ptr<QgsProcessingContext> tmpContext;
6194 if ( mProcessingContextGenerator )
6195 context = mProcessingContextGenerator->processingContext();
6199 tmpContext = std::make_unique<QgsProcessingContext>();
6200 context = tmpContext.get();
6206 if ( mTableComboBox && !mSchema.isEmpty() && !mConnection.isEmpty() )
6208 mTableComboBox->setSchema( mSchema );
6209 mTableComboBox->setConnectionName( mConnection, mProvider );
6211 const QgsProcessingParameterDatabaseTable *tableParam = static_cast<const QgsProcessingParameterDatabaseTable *>( parameterDefinition() );
6212 if ( tableParam->defaultValueForGui().isValid() )
6213 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
6217void QgsProcessingDatabaseTableWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6221 if ( !value.isValid() )
6222 mTableComboBox->comboBox()->setCurrentIndex( -1 );
6225 if ( mTableComboBox->comboBox()->isEditable() )
6227 const QString prev = mTableComboBox->comboBox()->currentText();
6229 mTableComboBox->setTable( v );
6230 mTableComboBox->comboBox()->setCurrentText( v );
6234 emit widgetValueHasChanged(
this );
6237 mTableComboBox->setTable( v );
6241QVariant QgsProcessingDatabaseTableWidgetWrapper::widgetValue()
const
6243 if ( mTableComboBox )
6244 if ( mTableComboBox->comboBox()->isEditable() )
6245 return mTableComboBox->comboBox()->currentText().isEmpty() ? QVariant() : QVariant( mTableComboBox->comboBox()->currentText() );
6247 return mTableComboBox->currentTable().isEmpty() ? QVariant() : QVariant( mTableComboBox->currentTable() );
6252QString QgsProcessingDatabaseTableWidgetWrapper::modelerExpressionFormatString()
const
6254 return tr(
"database table name as a string value" );
6257QString QgsProcessingDatabaseTableWidgetWrapper::parameterType()
const
6264 return new QgsProcessingDatabaseTableWidgetWrapper( parameter, type );
6267void QgsProcessingDatabaseTableWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
6279 setParentConnectionWrapperValue( wrapper );
6284 setParentSchemaWrapperValue( wrapper );
6301QgsProcessingExtentParameterDefinitionWidget::QgsProcessingExtentParameterDefinitionWidget(
6306 QVBoxLayout *vlayout =
new QVBoxLayout();
6307 vlayout->setContentsMargins( 0, 0, 0, 0 );
6309 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6312 mDefaultWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
6315 if ( extentParam->defaultValueForGui().isValid() )
6319 mDefaultWidget->setCurrentExtent( rect, crs );
6320 mDefaultWidget->setOutputExtentFromCurrent();
6324 mDefaultWidget->clear();
6330 vlayout->addWidget( mDefaultWidget );
6331 setLayout( vlayout );
6336 const QString defaultVal = mDefaultWidget->isValid() ? u
"%1,%2,%3,%4%5"_s.arg(
6337 QString::number( mDefaultWidget->outputExtent().xMinimum(),
'f', 9 ),
6338 QString::number( mDefaultWidget->outputExtent().xMaximum(),
'f', 9 ),
6339 QString::number( mDefaultWidget->outputExtent().yMinimum(),
'f', 9 ),
6340 QString::number( mDefaultWidget->outputExtent().yMaximum(),
'f', 9 ),
6341 mDefaultWidget->outputCrs().isValid() ? u
" [%1]"_s.arg( mDefaultWidget->outputCrs().authid() ) : QString()
6344 auto param = std::make_unique<QgsProcessingParameterExtent>( name, description, !defaultVal.isEmpty() ? QVariant( defaultVal ) : QVariant() );
6346 return param.release();
6354QWidget *QgsProcessingExtentWidgetWrapper::createWidget()
6367 if ( widgetContext().mapCanvas() )
6368 mExtentWidget->setMapCanvas( widgetContext().mapCanvas() );
6371 mExtentWidget->setNullValueAllowed(
true, tr(
"Not set" ) );
6373 mExtentWidget->setToolTip( parameterDefinition()->toolTip() );
6378 setDialog( mDialog );
6380 return mExtentWidget;
6390 mExtentWidget->setMapCanvas( context.
mapCanvas() );
6393void QgsProcessingExtentWidgetWrapper::setDialog( QWidget *dialog )
6400 mDialog->showMinimized();
6403 mDialog->showNormal();
6405 mDialog->activateWindow();
6412void QgsProcessingExtentWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6414 if ( mExtentWidget )
6416 if ( !value.isValid() || ( value.userType() == QMetaType::Type::QString && value.toString().isEmpty() ) )
6417 mExtentWidget->clear();
6422 mExtentWidget->setCurrentExtent( r, crs );
6423 mExtentWidget->setOutputExtentFromUser( r, crs );
6428QVariant QgsProcessingExtentWidgetWrapper::widgetValue()
const
6430 if ( mExtentWidget )
6432 const QString val = mExtentWidget->isValid() ? u
"%1,%2,%3,%4%5"_s.arg(
6433 QString::number( mExtentWidget->outputExtent().xMinimum(),
'f', 9 ),
6434 QString::number( mExtentWidget->outputExtent().xMaximum(),
'f', 9 ),
6435 QString::number( mExtentWidget->outputExtent().yMinimum(),
'f', 9 ),
6436 QString::number( mExtentWidget->outputExtent().yMaximum(),
'f', 9 ),
6437 mExtentWidget->outputCrs().isValid() ? u
" [%1]"_s.arg( mExtentWidget->outputCrs().authid() ) : QString()
6441 return val.isEmpty() ? QVariant() : QVariant( val );
6447QString QgsProcessingExtentWidgetWrapper::modelerExpressionFormatString()
const
6449 return tr(
"string of the format 'x min,x max,y min,y max' or a geometry value (bounding box is used)" );
6452QString QgsProcessingExtentWidgetWrapper::parameterType()
const
6459 return new QgsProcessingExtentWidgetWrapper( parameter, type );
6466 return new QgsProcessingExtentParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6474QgsProcessingMapLayerParameterDefinitionWidget::QgsProcessingMapLayerParameterDefinitionWidget(
6479 QVBoxLayout *vlayout =
new QVBoxLayout();
6480 vlayout->setContentsMargins( 0, 0, 0, 0 );
6482 vlayout->addWidget(
new QLabel( tr(
"Layer type" ) ) );
6498 for (
int i : layerParam->dataTypes() )
6500 mLayerTypeComboBox->setItemCheckState( mLayerTypeComboBox->findData( i ), Qt::Checked );
6504 vlayout->addWidget( mLayerTypeComboBox );
6508 setLayout( vlayout );
6513 QList<int> dataTypes;
6514 for (
const QVariant &v : mLayerTypeComboBox->checkedItemsData() )
6515 dataTypes << v.toInt();
6517 auto param = std::make_unique<QgsProcessingParameterMapLayer>( name, description );
6518 param->setDataTypes( dataTypes );
6520 return param.release();
6527QWidget *QgsProcessingMapLayerWidgetWrapper::createWidget()
6529 mComboBox =
new QgsProcessingMapLayerComboBox( parameterDefinition(), type() );
6537 mComboBox->setEditable(
true );
6541 mComboBox->setToolTip( parameterDefinition()->toolTip() );
6543 connect( mComboBox, &QgsProcessingMapLayerComboBox::valueChanged,
this, [
this]() {
6544 if ( mBlockSignals )
6547 emit widgetValueHasChanged(
this );
6550 setWidgetContext( widgetContext() );
6559 mComboBox->setWidgetContext( context );
6564 if ( !parameterDefinition()->defaultValueForGui().isValid() )
6570void QgsProcessingMapLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
6573 mComboBox->setValue( value, context );
6576QVariant QgsProcessingMapLayerWidgetWrapper::widgetValue()
const
6578 return mComboBox ? mComboBox->value() : QVariant();
6581QString QgsProcessingMapLayerWidgetWrapper::modelerExpressionFormatString()
const
6583 return tr(
"path to a map layer" );
6600QString QgsProcessingMapLayerWidgetWrapper::parameterType()
const
6607 return new QgsProcessingMapLayerWidgetWrapper( parameter, type );
6614 return new QgsProcessingMapLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6623 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6626QString QgsProcessingRasterLayerWidgetWrapper::modelerExpressionFormatString()
const
6628 return tr(
"path to a raster layer" );
6631QString QgsProcessingRasterLayerWidgetWrapper::parameterType()
const
6638 return new QgsProcessingRasterLayerWidgetWrapper( parameter, type );
6645 Q_UNUSED( context );
6646 Q_UNUSED( widgetContext );
6647 Q_UNUSED( definition );
6658QgsProcessingVectorLayerParameterDefinitionWidget::QgsProcessingVectorLayerParameterDefinitionWidget(
6663 QVBoxLayout *vlayout =
new QVBoxLayout();
6664 vlayout->setContentsMargins( 0, 0, 0, 0 );
6666 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6676 for (
int i : vectorParam->dataTypes() )
6678 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6682 vlayout->addWidget( mGeometryTypeComboBox );
6686 setLayout( vlayout );
6691 QList<int> dataTypes;
6692 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6693 dataTypes << v.toInt();
6695 auto param = std::make_unique<QgsProcessingParameterVectorLayer>( name, description, dataTypes );
6697 return param.release();
6702 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6705QString QgsProcessingVectorLayerWidgetWrapper::modelerExpressionFormatString()
const
6707 return tr(
"path to a vector layer" );
6710QString QgsProcessingVectorLayerWidgetWrapper::parameterType()
const
6717 return new QgsProcessingVectorLayerWidgetWrapper( parameter, type );
6724 return new QgsProcessingVectorLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6732QgsProcessingFeatureSourceParameterDefinitionWidget::QgsProcessingFeatureSourceParameterDefinitionWidget(
6737 QVBoxLayout *vlayout =
new QVBoxLayout();
6738 vlayout->setContentsMargins( 0, 0, 0, 0 );
6740 vlayout->addWidget(
new QLabel( tr(
"Geometry type" ) ) );
6750 for (
int i : sourceParam->dataTypes() )
6752 mGeometryTypeComboBox->setItemCheckState( mGeometryTypeComboBox->findData( i ), Qt::Checked );
6760 vlayout->addWidget( mGeometryTypeComboBox );
6763 setLayout( vlayout );
6768 QList<int> dataTypes;
6769 for (
const QVariant &v : mGeometryTypeComboBox->checkedItemsData() )
6770 dataTypes << v.toInt();
6772 auto param = std::make_unique<QgsProcessingParameterFeatureSource>( name, description, dataTypes );
6774 return param.release();
6778 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6781QString QgsProcessingFeatureSourceWidgetWrapper::modelerExpressionFormatString()
const
6783 return tr(
"path to a vector layer" );
6786QString QgsProcessingFeatureSourceWidgetWrapper::parameterType()
const
6793 return new QgsProcessingFeatureSourceWidgetWrapper( parameter, type );
6800 return new QgsProcessingFeatureSourceParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
6808 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
6811QString QgsProcessingMeshLayerWidgetWrapper::modelerExpressionFormatString()
const
6813 return tr(
"path to a mesh layer" );
6816QString QgsProcessingMeshLayerWidgetWrapper::parameterType()
const
6823 return new QgsProcessingMeshLayerWidgetWrapper( parameter, type );
6830 Q_UNUSED( context );
6831 Q_UNUSED( widgetContext );
6832 Q_UNUSED( definition );
6843QgsProcessingRasterBandPanelWidget::QgsProcessingRasterBandPanelWidget( QWidget *parent,
const QgsProcessingParameterBand *param )
6847 QHBoxLayout *hl =
new QHBoxLayout();
6848 hl->setContentsMargins( 0, 0, 0, 0 );
6850 mLineEdit =
new QLineEdit();
6851 mLineEdit->setEnabled(
false );
6852 hl->addWidget( mLineEdit, 1 );
6854 mToolButton =
new QToolButton();
6855 mToolButton->setText( QString( QChar( 0x2026 ) ) );
6856 hl->addWidget( mToolButton );
6862 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, 0 ) );
6865 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingRasterBandPanelWidget::showDialog );
6868void QgsProcessingRasterBandPanelWidget::setBands(
const QList<int> &bands )
6873void QgsProcessingRasterBandPanelWidget::setBandNames(
const QHash<int, QString> &names )
6878void QgsProcessingRasterBandPanelWidget::setValue(
const QVariant &value )
6880 if ( value.isValid() )
6881 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
6885 updateSummaryText();
6889void QgsProcessingRasterBandPanelWidget::showDialog()
6891 QVariantList availableOptions;
6892 availableOptions.reserve( mBands.size() );
6893 for (
int band : std::as_const( mBands ) )
6895 availableOptions << band;
6901 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
6902 widget->setPanelTitle( mParam->description() );
6904 widget->setValueFormatter( [
this](
const QVariant &v ) -> QString {
6905 int band = v.toInt();
6906 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6909 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
6915 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
6917 dlg.setValueFormatter( [
this](
const QVariant &v ) -> QString {
6918 int band = v.toInt();
6919 return mBandNames.contains( band ) ? mBandNames.value( band ) : v.toString();
6923 setValue( dlg.selectedOptions() );
6928void QgsProcessingRasterBandPanelWidget::updateSummaryText()
6931 mLineEdit->setText( tr(
"%n band(s) selected",
nullptr, mValue.count() ) );
6939QgsProcessingBandParameterDefinitionWidget::QgsProcessingBandParameterDefinitionWidget(
6944 QVBoxLayout *vlayout =
new QVBoxLayout();
6945 vlayout->setContentsMargins( 0, 0, 0, 0 );
6947 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
6949 mDefaultLineEdit =
new QLineEdit();
6950 mDefaultLineEdit->setToolTip( tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
6955 for (
int b : bands )
6957 defVal << QString::number( b );
6960 mDefaultLineEdit->setText( defVal.join(
';' ) );
6962 vlayout->addWidget( mDefaultLineEdit );
6965 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
6966 mParentLayerComboBox =
new QComboBox();
6968 QString initialParent;
6970 initialParent = bandParam->parentLayerParameterName();
6972 if (
auto *lModel = widgetContext.
model() )
6975 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
6976 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
6980 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
6981 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
6983 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6989 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
6992 mParentLayerComboBox->addItem( initialParent, initialParent );
6993 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
6997 vlayout->addWidget( mParentLayerComboBox );
6999 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Allow multiple" ) );
7001 mAllowMultipleCheckBox->setChecked( bandParam->allowMultiple() );
7004 vlayout->addWidget( mAllowMultipleCheckBox );
7005 setLayout( vlayout );
7011 = std::make_unique<QgsProcessingParameterBand>( name, description, mDefaultLineEdit->text().split(
';' ), mParentLayerComboBox->currentData().toString(),
false, mAllowMultipleCheckBox->isChecked() );
7013 return param.release();
7020QWidget *QgsProcessingBandWidgetWrapper::createWidget()
7033 mPanel =
new QgsProcessingRasterBandPanelWidget(
nullptr, bandParam );
7034 mPanel->setToolTip( parameterDefinition()->toolTip() );
7035 connect( mPanel, &QgsProcessingRasterBandPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7043 mComboBox->setToolTip( parameterDefinition()->toolTip() );
7051 mLineEdit =
new QLineEdit();
7052 mLineEdit->setToolTip( QObject::tr(
"Band number (separate bands with ; for multiple band parameters)" ) );
7053 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7060void QgsProcessingBandWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
7072 setParentLayerWrapperValue( wrapper );
7089 std::unique_ptr<QgsProcessingContext> tmpContext;
7090 if ( mProcessingContextGenerator )
7091 context = mProcessingContextGenerator->processingContext();
7095 tmpContext = std::make_unique<QgsProcessingContext>();
7096 context = tmpContext.get();
7102 if ( layer && layer->
isValid() )
7106 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
7109 mParentLayer.reset( qobject_cast<QgsRasterLayer *>( ownedLayer.release() ) );
7110 layer = mParentLayer.get();
7118 mComboBox->setLayer( layer );
7122 if ( provider && layer->
isValid() )
7127 QHash<int, QString> bandNames;
7128 for (
int i = 1; i <= nBands; ++i )
7133 mPanel->setBands( bands );
7134 mPanel->setBandNames( bandNames );
7141 mComboBox->setLayer(
nullptr );
7143 mPanel->setBands( QList<int>() );
7145 if ( value.isValid() && widgetContext().messageBar() )
7152 if ( parameterDefinition()->defaultValueForGui().isValid() )
7153 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
7156void QgsProcessingBandWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7160 if ( !value.isValid() )
7161 mComboBox->setBand( -1 );
7165 mComboBox->setBand( v );
7171 if ( value.isValid() )
7174 opts.reserve( v.size() );
7179 mPanel->setValue( value.isValid() ? opts : QVariant() );
7181 else if ( mLineEdit )
7188 opts.reserve( v.size() );
7190 opts << QString::number( i );
7191 mLineEdit->setText( value.isValid() && !opts.empty() ? opts.join(
';' ) : QString() );
7195 if ( value.isValid() )
7203QVariant QgsProcessingBandWidgetWrapper::widgetValue()
const
7206 return mComboBox->currentBand() == -1 ? QVariant() : mComboBox->currentBand();
7208 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
7209 else if ( mLineEdit )
7214 const QStringList parts = mLineEdit->text().split(
';', Qt::SkipEmptyParts );
7216 res.reserve( parts.count() );
7217 for (
const QString &s : parts )
7220 int band = s.toInt( &ok );
7224 return res.
isEmpty() ? QVariant() : res;
7228 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
7235QString QgsProcessingBandWidgetWrapper::modelerExpressionFormatString()
const
7237 return tr(
"selected band numbers as an array of numbers, or semicolon separated string of options (e.g. '1;3')" );
7240QString QgsProcessingBandWidgetWrapper::parameterType()
const
7247 return new QgsProcessingBandWidgetWrapper( parameter, type );
7254 return new QgsProcessingBandParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
7265 setAcceptDrops(
true );
7268void QgsProcessingMultipleLayerLineEdit::dragEnterEvent( QDragEnterEvent *event )
7270 const QStringList uris = QgsProcessingMultipleInputPanelWidget::compatibleUrisFromMimeData( mParam, event->mimeData(), {} );
7271 if ( !uris.isEmpty() )
7273 event->setDropAction( Qt::CopyAction );
7275 setHighlighted(
true );
7283void QgsProcessingMultipleLayerLineEdit::dragLeaveEvent( QDragLeaveEvent *event )
7285 QgsHighlightableLineEdit::dragLeaveEvent( event );
7287 setHighlighted(
false );
7290void QgsProcessingMultipleLayerLineEdit::dropEvent( QDropEvent *event )
7292 const QStringList uris = QgsProcessingMultipleInputPanelWidget::compatibleUrisFromMimeData( mParam, event->mimeData(), {} );
7293 if ( !uris.isEmpty() )
7295 event->setDropAction( Qt::CopyAction );
7297 QVariantList uriList;
7298 uriList.reserve( uris.size() );
7299 for (
const QString &uri : uris )
7300 uriList.append( QVariant( uri ) );
7301 emit layersDropped( uriList );
7304 setHighlighted(
false );
7315 QHBoxLayout *hl =
new QHBoxLayout();
7316 hl->setContentsMargins( 0, 0, 0, 0 );
7318 mLineEdit =
new QgsProcessingMultipleLayerLineEdit(
nullptr, param );
7319 mLineEdit->setEnabled(
true );
7320 mLineEdit->setReadOnly(
true );
7322 hl->addWidget( mLineEdit, 1 );
7323 connect( mLineEdit, &QgsProcessingMultipleLayerLineEdit::layersDropped,
this, &QgsProcessingMultipleLayerPanelWidget::setValue );
7325 mToolButton =
new QToolButton();
7326 mToolButton->setText( QString( QChar( 0x2026 ) ) );
7327 hl->addWidget( mToolButton );
7333 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, 0 ) );
7336 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingMultipleLayerPanelWidget::showDialog );
7339void QgsProcessingMultipleLayerPanelWidget::setValue(
const QVariant &value )
7341 if ( value.isValid() )
7342 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
7346 updateSummaryText();
7350void QgsProcessingMultipleLayerPanelWidget::setProject(
QgsProject *project )
7356 if ( mValue.removeAll( layerId ) )
7358 updateSummaryText();
7365void QgsProcessingMultipleLayerPanelWidget::setModel( QgsProcessingModelAlgorithm *model,
const QString &modelChildAlgorithmID )
7371 switch ( mParam->layerType() )
7379 mModelSources = model->availableSourcesForChild(
7380 modelChildAlgorithmID,
7389 mModelSources = model->availableSourcesForChild(
7390 modelChildAlgorithmID,
7399 mModelSources = model->availableSourcesForChild(
7400 modelChildAlgorithmID,
7409 mModelSources = model->availableSourcesForChild(
7410 modelChildAlgorithmID,
7419 mModelSources = model->availableSourcesForChild(
7420 modelChildAlgorithmID,
7429 mModelSources = model->availableSourcesForChild(
7430 modelChildAlgorithmID,
7439 mModelSources = model->availableSourcesForChild(
7440 modelChildAlgorithmID,
7449 mModelSources = model->availableSourcesForChild(
7450 modelChildAlgorithmID,
7464 mModelSources = model->availableSourcesForChild(
7465 modelChildAlgorithmID,
7478 mModelSources = model->availableSourcesForChild(
7479 modelChildAlgorithmID,
7493 mModelSources = model->availableSourcesForChild(
7494 modelChildAlgorithmID,
7508 mModelSources = model->availableSourcesForChild(
7509 modelChildAlgorithmID,
7523 mModelSources = model->availableSourcesForChild(
7524 modelChildAlgorithmID,
7547void QgsProcessingMultipleLayerPanelWidget::showDialog()
7552 QgsProcessingMultipleInputPanelWidget *widget =
new QgsProcessingMultipleInputPanelWidget( mParam, mValue, mModelSources, mModel,
nullptr );
7553 widget->setPanelTitle( mParam->description() );
7554 widget->setProject( mProject );
7555 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
7561 QgsProcessingMultipleInputDialog dlg( mParam, mValue, mModelSources, mModel,
this, Qt::WindowFlags() );
7562 dlg.setProject( mProject );
7565 setValue( dlg.selectedOptions() );
7570void QgsProcessingMultipleLayerPanelWidget::updateSummaryText()
7573 mLineEdit->setText( tr(
"%n input(s) selected",
nullptr, mValue.count() ) );
7580QgsProcessingMultipleLayerParameterDefinitionWidget::QgsProcessingMultipleLayerParameterDefinitionWidget(
7585 QVBoxLayout *vlayout =
new QVBoxLayout();
7586 vlayout->setContentsMargins( 0, 0, 0, 0 );
7588 vlayout->addWidget(
new QLabel( tr(
"Allowed layer type" ) ) );
7589 mLayerTypeComboBox =
new QComboBox();
7603 mLayerTypeComboBox->setCurrentIndex( mLayerTypeComboBox->findData(
static_cast<int>( layersParam->layerType() ) ) );
7605 vlayout->addWidget( mLayerTypeComboBox );
7608 setLayout( vlayout );
7613 auto param = std::make_unique<QgsProcessingParameterMultipleLayers>( name, description,
static_cast<Qgis::ProcessingSourceType>( mLayerTypeComboBox->currentData().toInt() ) );
7615 return param.release();
7622QWidget *QgsProcessingMultipleLayerWidgetWrapper::createWidget()
7626 mPanel =
new QgsProcessingMultipleLayerPanelWidget(
nullptr, layerParam );
7627 mPanel->setToolTip( parameterDefinition()->toolTip() );
7628 mPanel->setProject( widgetContext().project() );
7630 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7631 connect( mPanel, &QgsProcessingMultipleLayerPanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
7640 mPanel->setProject( context.
project() );
7642 mPanel->setModel( widgetContext().model(), widgetContext().modelChildAlgorithmId() );
7755void QgsProcessingMultipleLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7760 if ( value.isValid() )
7763 opts.reserve( v.size() );
7765 opts << l->source();
7768 for (
const QVariant &v : value.toList() )
7770 if ( v.userType() == qMetaTypeId<QgsProcessingModelChildParameterSource>() )
7772 const QgsProcessingModelChildParameterSource source = v.value<QgsProcessingModelChildParameterSource>();
7773 opts << QVariant::fromValue( source );
7778 mPanel->setValue( value.isValid() ? opts : QVariant() );
7782QVariant QgsProcessingMultipleLayerWidgetWrapper::widgetValue()
const
7785 return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
7790QString QgsProcessingMultipleLayerWidgetWrapper::modelerExpressionFormatString()
const
7792 return tr(
"an array of layer paths, or semicolon separated string of layer paths" );
7795QString QgsProcessingMultipleLayerWidgetWrapper::parameterType()
const
7802 return new QgsProcessingMultipleLayerWidgetWrapper( parameter, type );
7809 return new QgsProcessingMultipleLayerParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
7818 : QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
7821QString QgsProcessingPointCloudLayerWidgetWrapper::modelerExpressionFormatString()
const
7823 return tr(
"path to a point cloud layer" );
7826QString QgsProcessingPointCloudLayerWidgetWrapper::parameterType()
const
7833 return new QgsProcessingPointCloudLayerWidgetWrapper( parameter, type );
7840 Q_UNUSED( context );
7841 Q_UNUSED( widgetContext );
7842 Q_UNUSED( definition );
7857QString QgsProcessingAnnotationLayerWidgetWrapper::modelerExpressionFormatString()
const
7859 return tr(
"name of an annotation layer, or \"main\" for the main annotation layer" );
7862QString QgsProcessingAnnotationLayerWidgetWrapper::parameterType()
const
7869 return new QgsProcessingAnnotationLayerWidgetWrapper( parameter, type );
7876 Q_UNUSED( context );
7877 Q_UNUSED( widgetContext );
7878 Q_UNUSED( definition );
7889 if ( mWidgetContext.project() )
7890 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7894QWidget *QgsProcessingAnnotationLayerWidgetWrapper::createWidget()
7905 mComboBox->setEditable(
true );
7909 mComboBox->setToolTip( parameterDefinition()->toolTip() );
7911 if ( mWidgetContext.project() )
7912 mComboBox->setAdditionalLayers( { mWidgetContext.project()->mainAnnotationLayer() } );
7915 mComboBox->setAllowEmptyLayer(
true );
7918 if ( mBlockSignals )
7921 emit widgetValueHasChanged(
this );
7924 setWidgetContext( widgetContext() );
7928void QgsProcessingAnnotationLayerWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
7934 mComboBox->setLayer(
nullptr );
7938 QVariant val = value;
7939 if ( val.userType() == qMetaTypeId<QgsProperty>() )
7951 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( val.value<QObject *>() );
7952 if ( !layer && val.userType() == QMetaType::Type::QString )
7959 mComboBox->setLayer( layer );
7964QVariant QgsProcessingAnnotationLayerWidgetWrapper::widgetValue()
const
7966 return mComboBox && mComboBox->currentLayer()
7967 ? ( mWidgetContext.project() ? ( mComboBox->currentLayer() == mWidgetContext.project()->mainAnnotationLayer() ? u
"main"_s : mComboBox->currentLayer()->id() )
7968 : mComboBox->currentLayer()->id() )
7981 QHBoxLayout *hl =
new QHBoxLayout();
7982 hl->setContentsMargins( 0, 0, 0, 0 );
7984 mLineEdit =
new QLineEdit();
7985 mLineEdit->setEnabled(
false );
7986 hl->addWidget( mLineEdit, 1 );
7988 mToolButton =
new QToolButton();
7989 mToolButton->setText( QString( QChar( 0x2026 ) ) );
7990 hl->addWidget( mToolButton );
7996 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, 0 ) );
7999 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingPointCloudAttributePanelWidget::showDialog );
8004 mAttributes = attributes;
8007void QgsProcessingPointCloudAttributePanelWidget::setValue(
const QVariant &value )
8009 if ( value.isValid() )
8010 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
8014 updateSummaryText();
8018void QgsProcessingPointCloudAttributePanelWidget::showDialog()
8020 QVariantList availableOptions;
8021 availableOptions.reserve( mAttributes.count() );
8022 const QVector<QgsPointCloudAttribute> attributes = mAttributes.attributes();
8025 availableOptions << attr.name();
8031 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
8032 widget->setPanelTitle( mParam->description() );
8034 widget->setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
8036 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() { setValue( widget->selectedOptions() ); } );
8042 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
8044 dlg.setValueFormatter( [](
const QVariant &v ) -> QString {
return v.toString(); } );
8047 setValue( dlg.selectedOptions() );
8052void QgsProcessingPointCloudAttributePanelWidget::updateSummaryText()
8057 if ( mValue.empty() )
8059 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, 0 ) );
8064 values.reserve( mValue.size() );
8065 for (
const QVariant &val : std::as_const( mValue ) )
8067 values << val.toString();
8070 const QString concatenated = values.join( tr(
"," ) );
8071 if ( concatenated.length() < 100 )
8072 mLineEdit->setText( concatenated );
8074 mLineEdit->setText( tr(
"%n attribute(s) selected",
nullptr, mValue.count() ) );
8083QgsProcessingPointCloudAttributeParameterDefinitionWidget::QgsProcessingPointCloudAttributeParameterDefinitionWidget(
8088 QVBoxLayout *vlayout =
new QVBoxLayout();
8089 vlayout->setContentsMargins( 0, 0, 0, 0 );
8091 vlayout->addWidget(
new QLabel( tr(
"Parent layer" ) ) );
8092 mParentLayerComboBox =
new QComboBox();
8094 QString initialParent;
8096 initialParent = attrParam->parentLayerParameterName();
8098 if (
auto *lModel = widgetContext.
model() )
8101 const QMap<QString, QgsProcessingModelParameter> components = lModel->parameterComponents();
8102 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
8106 mParentLayerComboBox->addItem( definition->
description(), definition->
name() );
8107 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
8109 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
8115 if ( mParentLayerComboBox->count() == 0 && !initialParent.isEmpty() )
8118 mParentLayerComboBox->addItem( initialParent, initialParent );
8119 mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 );
8122 vlayout->addWidget( mParentLayerComboBox );
8126 mAllowMultipleCheckBox =
new QCheckBox( tr(
"Accept multiple attributes" ) );
8128 mAllowMultipleCheckBox->setChecked( attrParam->allowMultiple() );
8130 vlayout->addWidget( mAllowMultipleCheckBox );
8133 mDefaultToAllCheckBox =
new QCheckBox( tr(
"Select all attributes by default" ) );
8134 mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() );
8136 mDefaultToAllCheckBox->setChecked( attrParam->defaultToAllAttributes() );
8140 vlayout->addWidget( mDefaultToAllCheckBox );
8142 connect( mAllowMultipleCheckBox, &QCheckBox::stateChanged,
this, [
this] { mDefaultToAllCheckBox->setEnabled( mAllowMultipleCheckBox->isChecked() ); } );
8144 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
8146 mDefaultLineEdit =
new QLineEdit();
8147 mDefaultLineEdit->setToolTip( tr(
"Default attribute name, or ; separated list of attribute names for multiple attribute parameters" ) );
8151 mDefaultLineEdit->setText( attributes.join(
';' ) );
8153 vlayout->addWidget( mDefaultLineEdit );
8157 setLayout( vlayout );
8162 QVariant defaultValue;
8163 if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
8165 defaultValue = mDefaultLineEdit->text();
8167 auto param = std::make_unique<
8168 QgsProcessingParameterPointCloudAttribute>( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), mAllowMultipleCheckBox->isChecked(),
false, mDefaultToAllCheckBox->isChecked() );
8170 return param.release();
8177QWidget *QgsProcessingPointCloudAttributeWidgetWrapper::createWidget()
8190 mPanel =
new QgsProcessingPointCloudAttributePanelWidget(
nullptr, attrParam );
8191 mPanel->setToolTip( parameterDefinition()->toolTip() );
8192 connect( mPanel, &QgsProcessingPointCloudAttributePanelWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
8199 mComboBox->setToolTip( parameterDefinition()->toolTip() );
8207 mLineEdit =
new QLineEdit();
8208 mLineEdit->setToolTip( QObject::tr(
"Name of attribute (separate attribute names with ; for multiple attribute parameters)" ) );
8209 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
8216void QgsProcessingPointCloudAttributeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
8228 setParentLayerWrapperValue( wrapper );
8245 std::unique_ptr<QgsProcessingContext> tmpContext;
8246 if ( mProcessingContextGenerator )
8247 context = mProcessingContextGenerator->processingContext();
8251 tmpContext = std::make_unique<QgsProcessingContext>();
8252 context = tmpContext.get();
8258 if ( layer && layer->
isValid() )
8262 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
8265 mParentLayer.reset( qobject_cast<QgsPointCloudLayer *>( ownedLayer.release() ) );
8266 layer = mParentLayer.get();
8274 mComboBox->setLayer( layer );
8277 mPanel->setAttributes( layer->
attributes() );
8284 mComboBox->setLayer(
nullptr );
8289 if ( value.isValid() && widgetContext().messageBar() )
8300 val.reserve( mPanel->attributes().attributes().size() );
8303 setWidgetValue( val, *context );
8306 setWidgetValue( parameterDefinition()->defaultValueForGui(), *context );
8309void QgsProcessingPointCloudAttributeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
8313 if ( !value.isValid() )
8314 mComboBox->setAttribute( QString() );
8318 mComboBox->setAttribute( v );
8324 if ( value.isValid() )
8327 opts.reserve( v.size() );
8328 for (
const QString &i : v )
8332 mPanel->setValue( opts );
8334 else if ( mLineEdit )
8340 mLineEdit->setText( v.join(
';' ) );
8349QVariant QgsProcessingPointCloudAttributeWidgetWrapper::widgetValue()
const
8352 return mComboBox->currentAttribute();
8354 return mPanel->value();
8355 else if ( mLineEdit )
8360 return mLineEdit->text().split(
';' );
8363 return mLineEdit->text();
8369QString QgsProcessingPointCloudAttributeWidgetWrapper::modelerExpressionFormatString()
const
8371 return tr(
"selected attribute names as an array of names, or semicolon separated string of options (e.g. 'X;Intensity')" );
8374QString QgsProcessingPointCloudAttributeWidgetWrapper::parameterType()
const
8381 return new QgsProcessingPointCloudAttributeWidgetWrapper( parameter, type );
8388 return new QgsProcessingPointCloudAttributeParameterDefinitionWidget( context, widgetContext, definition,
algorithm );
8395QgsProcessingDestinationParameterDefinitionWidget::QgsProcessingDestinationParameterDefinitionWidget(
8396 const QString &type,
8407 mType = definition->
type();
8408 mExistingDestinationParameter.reset( qgis::down_cast< QgsProcessingDestinationParameter * >( definition->
clone() ) );
8414 Q_ASSERT( parameterTypeMetadata );
8415 mExistingDestinationParameter.reset( qgis::down_cast< QgsProcessingDestinationParameter * >( parameterTypeMetadata->
create( u
"OUTPUT"_s ) ) );
8421 QVBoxLayout *vlayout =
new QVBoxLayout();
8422 vlayout->setContentsMargins( 0, 0, 0, 0 );
8424 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
8426 mDestinationWidget =
new QgsProcessingLayerOutputDestinationWidget( mExistingDestinationParameter.get(),
true );
8427 vlayout->addWidget( mDestinationWidget );
8431 setLayout( vlayout );
8437 std::unique_ptr< QgsProcessingParameterDefinition > param( mExistingDestinationParameter->clone() );
8443 return param.release();
8454QWidget *QgsProcessingOutputWidgetWrapper::createWidget()
8462 mOutputWidget =
new QgsProcessingLayerOutputDestinationWidget( destParam,
false );
8463 if ( mProcessingContextGenerator )
8464 mOutputWidget->setContext( mProcessingContextGenerator->processingContext() );
8465 if ( mParametersGenerator )
8466 mOutputWidget->registerProcessingParametersGenerator( mParametersGenerator );
8467 mOutputWidget->setToolTip( parameterDefinition()->toolTip() );
8469 connect( mOutputWidget, &QgsProcessingLayerOutputDestinationWidget::destinationChanged,
this, [
this]() {
8470 if ( mBlockSignals )
8473 emit widgetValueHasChanged(
this );
8478 mOutputWidget->addOpenAfterRunningOption();
8480 return mOutputWidget;
8490void QgsProcessingOutputWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
8492 if ( mOutputWidget )
8493 mOutputWidget->setValue( value );
8496QVariant QgsProcessingOutputWidgetWrapper::widgetValue()
const
8498 if ( mOutputWidget )
8499 return mOutputWidget->value();
8504QVariantMap QgsProcessingOutputWidgetWrapper::customProperties()
const
8507 if ( mOutputWidget )
8508 res.insert( u
"OPEN_AFTER_RUNNING"_s, mOutputWidget->openAfterRunning() );
8516 return new QgsProcessingDestinationParameterDefinitionWidget( parameterType(), context, widgetContext, qgis::down_cast< const QgsProcessingDestinationParameter * >( definition ),
algorithm );
8525 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8528QString QgsProcessingFeatureSinkWidgetWrapper::parameterType()
const
8535 return new QgsProcessingFeatureSinkWidgetWrapper( parameter, type );
8538QString QgsProcessingFeatureSinkWidgetWrapper::modelerExpressionFormatString()
const
8540 return tr(
"path to layer destination" );
8548 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8551QString QgsProcessingVectorDestinationWidgetWrapper::parameterType()
const
8558 return new QgsProcessingVectorDestinationWidgetWrapper( parameter, type );
8561QString QgsProcessingVectorDestinationWidgetWrapper::modelerExpressionFormatString()
const
8563 return tr(
"path to layer destination" );
8571 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8574QString QgsProcessingRasterDestinationWidgetWrapper::parameterType()
const
8581 return new QgsProcessingRasterDestinationWidgetWrapper( parameter, type );
8584QString QgsProcessingRasterDestinationWidgetWrapper::modelerExpressionFormatString()
const
8586 return tr(
"path to layer destination" );
8594 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8597QString QgsProcessingPointCloudDestinationWidgetWrapper::parameterType()
const
8604 return new QgsProcessingPointCloudDestinationWidgetWrapper( parameter, type );
8607QString QgsProcessingPointCloudDestinationWidgetWrapper::modelerExpressionFormatString()
const
8609 return tr(
"path to layer destination" );
8617 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8620QString QgsProcessingFileDestinationWidgetWrapper::parameterType()
const
8627 return new QgsProcessingFileDestinationWidgetWrapper( parameter, type );
8631QString QgsProcessingFileDestinationWidgetWrapper::modelerExpressionFormatString()
const
8633 return tr(
"path to file destination" );
8641 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8644QString QgsProcessingFolderDestinationWidgetWrapper::parameterType()
const
8651 return new QgsProcessingFolderDestinationWidgetWrapper( parameter, type );
8655QString QgsProcessingFolderDestinationWidgetWrapper::modelerExpressionFormatString()
const
8657 return tr(
"path to folder destination" );
8665 : QgsProcessingOutputWidgetWrapper( parameter, type, parent )
8668QString QgsProcessingVectorTileDestinationWidgetWrapper::parameterType()
const
8675 return new QgsProcessingPointCloudDestinationWidgetWrapper( parameter, type );
8678QString QgsProcessingVectorTileDestinationWidgetWrapper::modelerExpressionFormatString()
const
8680 return tr(
"path to layer destination" );
8688QgsHeatmapPixelSizeWidget::QgsHeatmapPixelSizeWidget( QWidget *parent )
8693 mCellXSpinBox->setShowClearButton(
false );
8694 mCellYSpinBox->setShowClearButton(
false );
8695 mRowsSpinBox->setShowClearButton(
false );
8696 mColumnsSpinBox->setShowClearButton(
false );
8698 connect( mCellYSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), mCellXSpinBox, &QgsDoubleSpinBox::setValue );
8699 connect( mCellXSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsHeatmapPixelSizeWidget::pixelSizeChanged );
8700 connect( mRowsSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, &QgsHeatmapPixelSizeWidget::rowsChanged );
8701 connect( mColumnsSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, &QgsHeatmapPixelSizeWidget::columnsChanged );
8708 mLayerBounds = mLayer->
extent();
8712 recalculateBounds();
8720void QgsHeatmapPixelSizeWidget::setRadius(
double radius )
8723 recalculateBounds();
8726void QgsHeatmapPixelSizeWidget::setRadiusField(
const QString &radiusField )
8728 mRadiusField = radiusField;
8729 recalculateBounds();
8732void QgsHeatmapPixelSizeWidget::recalculateBounds()
8734 mRasterBounds = mLayerBounds;
8738 double maxRadius = mRadius;
8739 if ( !mRadiusField.isEmpty() )
8741 const int idx = mLayer->fields().lookupField( mRadiusField );
8743 maxRadius = mLayer->maximumValue( idx ).toDouble();
8746 mRasterBounds.setXMinimum( mRasterBounds.xMinimum() - maxRadius );
8747 mRasterBounds.setYMinimum( mRasterBounds.yMinimum() - maxRadius );
8748 mRasterBounds.setXMaximum( mRasterBounds.xMaximum() + maxRadius );
8749 mRasterBounds.setYMaximum( mRasterBounds.yMaximum() + maxRadius );
8754void QgsHeatmapPixelSizeWidget::pixelSizeChanged()
8756 const double prevValue = value();
8757 const double cellSize = mCellXSpinBox->value();
8758 if ( cellSize <= 0 || mRasterBounds.isNull() )
8760 emit valueChanged();
8766 const int rows = std::max(
static_cast<int>( std::round( mRasterBounds.height() / cellSize ) ) + 1, 1 );
8767 const int cols = std::max(
static_cast<int>( std::round( mRasterBounds.width() / cellSize ) ) + 1, 1 );
8774 emit valueChanged();
8778void QgsHeatmapPixelSizeWidget::rowsChanged()
8780 const int rows = mRowsSpinBox->value();
8781 if ( rows <= 0 || mRasterBounds.isNull() )
8784 const double cellSize = mRasterBounds.height() / rows;
8785 if ( cellSize == 0 )
8788 const int cols = std::max(
static_cast<int>( std::round( mRasterBounds.width() / cellSize ) ) + 1, 1 );
8794 emit valueChanged();
8797void QgsHeatmapPixelSizeWidget::columnsChanged()
8799 const int cols = mColumnsSpinBox->value();
8800 if ( cols < 2 || mRasterBounds.isNull() )
8803 const double cellSize = mRasterBounds.width() / ( cols - 1 );
8804 if ( cellSize == 0 )
8807 const int rows = std::max(
static_cast<int>( std::round( mRasterBounds.height() / cellSize ) ), 1 );
8813 emit valueChanged();
8816double QgsHeatmapPixelSizeWidget::value()
const
8818 return mCellXSpinBox->value();
8821void QgsHeatmapPixelSizeWidget::setValue(
double value )
8823 mCellXSpinBox->setValue( value );
8824 mCellYSpinBox->setValue( value );
8835QString QgsProcessingHeatmapPixelSizeWidgetWrapper::parameterType()
const
8842 return new QgsProcessingHeatmapPixelSizeWidgetWrapper( parameter, type );
8852QWidget *QgsProcessingHeatmapPixelSizeWidgetWrapper::createWidget()
8858 mWidget =
new QgsHeatmapPixelSizeWidget();
8859 connect( mWidget, &QgsHeatmapPixelSizeWidget::valueChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
8867 mFallbackSpinBox->setShowClearButton(
false );
8868 mFallbackSpinBox->setMinimum( 0.0 );
8869 mFallbackSpinBox->setMaximum( 99999999999.0 );
8870 mFallbackSpinBox->setDecimals( 6 );
8871 mFallbackSpinBox->setToolTip( tr(
"Resolution of each pixel in output raster, in layer units" ) );
8872 connect( mFallbackSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
8873 return mFallbackSpinBox;
8879void QgsProcessingHeatmapPixelSizeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
8888 if ( !param || !mWidget )
8895 setParentLayerWrapperValue( wrapper );
8924 std::unique_ptr<QgsProcessingContext> tmpContext;
8925 if ( mProcessingContextGenerator )
8926 context = mProcessingContextGenerator->processingContext();
8930 tmpContext = std::make_unique<QgsProcessingContext>();
8931 context = tmpContext.get();
8935 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
8945 mWidget->setLayer(
nullptr );
8951 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
8954 mParentLayer = std::move( ownedLayer );
8962 mWidget->setLayer( layer );
8965void QgsProcessingHeatmapPixelSizeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
8968 mWidget->setValue( value.toDouble() );
8969 else if ( mFallbackSpinBox )
8970 mFallbackSpinBox->setValue( value.toDouble() );
8973QVariant QgsProcessingHeatmapPixelSizeWidgetWrapper::widgetValue()
const
8976 return mWidget->value();
8977 else if ( mFallbackSpinBox )
8978 return mFallbackSpinBox->value();
8982const QgsVectorLayer *QgsProcessingHeatmapPixelSizeWidgetWrapper::linkedVectorLayer()
const
8984 if ( mWidget && mWidget->layer() )
8985 return mWidget->layer();
9006QgsReliefColorsWidget::QgsReliefColorsWidget( QWidget *parent )
9011 connect( mButtonAdd, &QToolButton::clicked,
this, &QgsReliefColorsWidget::addClicked );
9012 connect( mButtonRemove, &QToolButton::clicked,
this, &QgsReliefColorsWidget::removeClicked );
9013 connect( mButtonUp, &QToolButton::clicked,
this, &QgsReliefColorsWidget::upClicked );
9014 connect( mButtonDown, &QToolButton::clicked,
this, &QgsReliefColorsWidget::downClicked );
9015 connect( mButtonLoad, &QToolButton::clicked,
this, &QgsReliefColorsWidget::loadClicked );
9016 connect( mButtonSave, &QToolButton::clicked,
this, &QgsReliefColorsWidget::saveClicked );
9017 connect( mButtonAuto, &QToolButton::clicked,
this, &QgsReliefColorsWidget::autoCalculate );
9018 connect( mReliefColorsWidget, &QTreeWidget::itemDoubleClicked,
this, &QgsReliefColorsWidget::itemDoubleClicked );
9028 return mLayer.data();
9031void QgsReliefColorsWidget::addClicked()
9033 auto item =
new QTreeWidgetItem();
9034 item->setText( 0, u
"0.00"_s );
9035 item->setText( 1, u
"0.00"_s );
9036 item->setBackground( 2, QBrush( QColor( 127, 127, 127 ) ) );
9037 mReliefColorsWidget->addTopLevelItem( item );
9038 emit valueChanged();
9041void QgsReliefColorsWidget::removeClicked()
9043 const QList<QTreeWidgetItem *> selectedItems = mReliefColorsWidget->selectedItems();
9044 for ( QTreeWidgetItem *item : std::as_const( selectedItems ) )
9048 emit valueChanged();
9051void QgsReliefColorsWidget::downClicked()
9053 const QList<QTreeWidgetItem *> selectedItems = mReliefColorsWidget->selectedItems();
9054 for ( QTreeWidgetItem *item : std::as_const( selectedItems ) )
9056 const int currentIndex = mReliefColorsWidget->indexOfTopLevelItem( item );
9057 if ( currentIndex >= 0 && currentIndex < mReliefColorsWidget->topLevelItemCount() - 1 )
9059 mReliefColorsWidget->takeTopLevelItem( currentIndex );
9060 mReliefColorsWidget->insertTopLevelItem( currentIndex + 1, item );
9061 mReliefColorsWidget->setCurrentItem( item );
9064 emit valueChanged();
9067void QgsReliefColorsWidget::upClicked()
9069 const QList<QTreeWidgetItem *> selectedItems = mReliefColorsWidget->selectedItems();
9070 for ( QTreeWidgetItem *item : std::as_const( selectedItems ) )
9072 const int currentIndex = mReliefColorsWidget->indexOfTopLevelItem( item );
9073 if ( currentIndex > 0 )
9075 mReliefColorsWidget->takeTopLevelItem( currentIndex );
9076 mReliefColorsWidget->insertTopLevelItem( currentIndex - 1, item );
9077 mReliefColorsWidget->setCurrentItem( item );
9080 emit valueChanged();
9083void QgsReliefColorsWidget::loadClicked()
9085 const QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Import Colors from XML" ), QDir::homePath(), tr(
"XML files (*.xml *.XML)" ) );
9086 if ( fileName.isEmpty() )
9089 QFile file( fileName );
9090 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
9094 if ( !doc.setContent( &file ) )
9096 QMessageBox::critical(
this, tr(
"Import Colors from XML" ), tr(
"The XML file could not be loaded" ) );
9100 mReliefColorsWidget->clear();
9101 const QDomNodeList reliefColorList = doc.elementsByTagName( u
"ReliefColor"_s );
9102 for (
int i = 0; i < reliefColorList.length(); ++i )
9104 const QDomElement elem = reliefColorList.at( i ).toElement();
9105 auto item =
new QTreeWidgetItem();
9106 item->setText( 0, elem.attribute( u
"MinElevation"_s ) );
9107 item->setText( 1, elem.attribute( u
"MaxElevation"_s ) );
9108 item->setBackground( 2, QBrush( QColor( elem.attribute( u
"red"_s ).toInt(), elem.attribute( u
"green"_s ).toInt(), elem.attribute( u
"blue"_s ).toInt() ) ) );
9109 mReliefColorsWidget->addTopLevelItem( item );
9111 emit valueChanged();
9114void QgsReliefColorsWidget::saveClicked()
9116 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Export Colors as XML" ), QDir::homePath(), tr(
"XML files (*.xml *.XML)" ) );
9117 if ( fileName.isEmpty() )
9123 QDomElement colorsElem = doc.createElement( u
"ReliefColors"_s );
9124 doc.appendChild( colorsElem );
9126 const QList<QgsRasterReliefColor> currentColors = colors();
9129 QDomElement elem = doc.createElement( u
"ReliefColor"_s );
9132 elem.setAttribute( u
"red"_s, QString::number(
c.color.red() ) );
9133 elem.setAttribute( u
"green"_s, QString::number(
c.color.green() ) );
9134 elem.setAttribute( u
"blue"_s, QString::number(
c.color.blue() ) );
9135 colorsElem.appendChild( elem );
9138 QFile file( fileName );
9139 if ( file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
9141 QTextStream out( &file );
9142 out << doc.toString( 2 );
9146void QgsReliefColorsWidget::autoCalculate()
9148 if ( !mLayer || !mLayer->isValid() )
9152 setColors( autoColors );
9153 emit valueChanged();
9156void QgsReliefColorsWidget::itemDoubleClicked( QTreeWidgetItem *item,
int column )
9164 const double d = QInputDialog::getDouble(
this, tr(
"Enter lower elevation class bound" ), tr(
"Elevation" ), item->text( 0 ).toDouble(), -2147483647, 2147483647, 2, &ok );
9167 item->setText( 0, QString::number( d ) );
9168 emit valueChanged();
9171 else if ( column == 1 )
9173 const double d = QInputDialog::getDouble(
this, tr(
"Enter upper elevation class bound" ), tr(
"Elevation" ), item->text( 1 ).toDouble(), -2147483647, 2147483647, 2, &ok );
9176 item->setText( 1, QString::number( d ) );
9177 emit valueChanged();
9180 else if ( column == 2 )
9182 const QColor
c = QColorDialog::getColor( item->background( 2 ).color(),
this, tr(
"Select color for relief class" ) );
9185 item->setBackground( 2, QBrush(
c ) );
9186 emit valueChanged();
9191QList<QgsRasterReliefColor> QgsReliefColorsWidget::colors()
const
9193 QList<QgsRasterReliefColor> colors;
9194 for (
int i = 0; i < mReliefColorsWidget->topLevelItemCount(); ++i )
9196 if ( QTreeWidgetItem *item = mReliefColorsWidget->topLevelItem( i ) )
9198 colors.append(
QgsRasterReliefColor( item->background( 2 ).color(), item->text( 0 ).toDouble(), item->text( 1 ).toDouble() ) );
9204void QgsReliefColorsWidget::setColors(
const QList<QgsRasterReliefColor> &colors )
9206 mReliefColorsWidget->clear();
9209 auto item =
new QTreeWidgetItem();
9212 item->setBackground( 2, QBrush(
c.color ) );
9213 mReliefColorsWidget->addTopLevelItem( item );
9215 emit valueChanged();
9226QString QgsProcessingReliefColorsWidgetWrapper::parameterType()
const
9233 return new QgsProcessingReliefColorsWidgetWrapper( parameter, type );
9243QWidget *QgsProcessingReliefColorsWidgetWrapper::createWidget()
9249 mWidget =
new QgsReliefColorsWidget();
9250 connect( mWidget, &QgsReliefColorsWidget::valueChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
9257 mFallbackLineEdit =
new QLineEdit();
9258 mFallbackLineEdit->setPlaceholderText( tr(
"Relief colors definition" ) );
9259 connect( mFallbackLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
9260 return mFallbackLineEdit;
9266void QgsProcessingReliefColorsWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
9275 if ( !param || !mWidget )
9282 setParentLayerWrapperValue( wrapper );
9301 std::unique_ptr<QgsProcessingContext> tmpContext;
9302 if ( mProcessingContextGenerator )
9303 context = mProcessingContextGenerator->processingContext();
9307 tmpContext = std::make_unique<QgsProcessingContext>();
9308 context = tmpContext.get();
9313 if ( layer && layer->
isValid() )
9317 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
9320 mParentLayer.reset( qobject_cast<QgsRasterLayer *>( ownedLayer.release() ) );
9321 layer = mParentLayer.get();
9329 mWidget->setLayer( layer );
9334 mWidget->setLayer(
nullptr );
9338void QgsProcessingReliefColorsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
9342 if ( mWidget && param )
9344 mWidget->setColors( param->valueAsReliefColors( value, context ) );
9346 else if ( mFallbackLineEdit )
9347 mFallbackLineEdit->setText( value.toString() );
9350QVariant QgsProcessingReliefColorsWidgetWrapper::widgetValue()
const
9354 else if ( mFallbackLineEdit )
9355 return mFallbackLineEdit->text();
9359QString QgsProcessingReliefColorsWidgetWrapper::modelerExpressionFormatString()
const
9361 return tr(
"string of the format 'min,max,red,green,blue' for each relief color, joined by a ; delimiter" );
9369QgsExecuteSqlWidget::QgsExecuteSqlWidget( QWidget *parent )
9372 QVBoxLayout *mainLayout =
new QVBoxLayout(
this );
9373 mainLayout->setContentsMargins( 0, 0, 0, 0 );
9375 mTextEdit =
new QPlainTextEdit(
this );
9376 mainLayout->addWidget( mTextEdit, 1 );
9378 QHBoxLayout *bottomLayout =
new QHBoxLayout();
9379 bottomLayout->setContentsMargins( 0, 0, 0, 0 );
9382 bottomLayout->addWidget( mExpressionWidget, 1 );
9384 mInsertButton =
new QPushButton( tr(
"Insert" ),
this );
9385 bottomLayout->addWidget( mInsertButton );
9387 mainLayout->addLayout( bottomLayout );
9389 connect( mInsertButton, &QPushButton::clicked,
this, &QgsExecuteSqlWidget::insertExpression );
9390 connect( mTextEdit, &QPlainTextEdit::textChanged,
this, &QgsExecuteSqlWidget::changed );
9393void QgsExecuteSqlWidget::insertExpression()
9395 if ( !mExpressionWidget->currentText().isEmpty() )
9397 const QString formattedExpression = u
"[% %1 %]"_s.arg( mExpressionWidget->currentText() );
9398 mTextEdit->insertPlainText( formattedExpression );
9402void QgsExecuteSqlWidget::setValue(
const QString &text )
9404 if ( text == value() )
9407 mTextEdit->setPlainText( text );
9410QString QgsExecuteSqlWidget::value()
const
9412 return mTextEdit->toPlainText();
9423QString QgsProcessingExecuteSqlWidgetWrapper::parameterType()
const
9425 return u
"executesql"_s;
9430 return new QgsProcessingExecuteSqlWidgetWrapper( parameter, type );
9433QWidget *QgsProcessingExecuteSqlWidgetWrapper::createWidget()
9435 mExecuteSqlWidget =
new QgsExecuteSqlWidget();
9436 mExecuteSqlWidget->expressionWidget()->registerExpressionContextGenerator(
this );
9438 if ( parameterDefinition() )
9440 mExecuteSqlWidget->setToolTip( parameterDefinition()->toolTip() );
9443 connect( mExecuteSqlWidget, &QgsExecuteSqlWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
9445 return mExecuteSqlWidget;
9448void QgsProcessingExecuteSqlWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
9450 if ( !mExecuteSqlWidget )
9456 mExecuteSqlWidget->setValue( sqlText );
9459QVariant QgsProcessingExecuteSqlWidgetWrapper::widgetValue()
const
9461 if ( !mExecuteSqlWidget )
9466 return mExecuteSqlWidget->value();
9473QgsInterpolationSourceWidget::QgsInterpolationSourceWidget( QWidget *parent )
9481 connect( btnAdd, &QToolButton::clicked,
this, &QgsInterpolationSourceWidget::addLayer );
9482 connect( btnRemove, &QToolButton::clicked,
this, &QgsInterpolationSourceWidget::removeLayer );
9489 connect( chkUseZCoordinate, &QCheckBox::toggled,
this, [
this](
bool checked ) {
9490 cmbFields->setEnabled( !checked );
9491 updateAddButtonState();
9494 layerChanged( qobject_cast< QgsVectorLayer * >( cmbLayers->currentLayer() ) );
9497bool QgsInterpolationSourceWidget::canAddLayer()
const
9499 return chkUseZCoordinate->isChecked() || !cmbFields->currentField().isEmpty();
9502void QgsInterpolationSourceWidget::addLayer()
9504 QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( cmbLayers->currentLayer() );
9505 if ( !layer || !canAddLayer() )
9510 const QString attribute = chkUseZCoordinate->isChecked() ? u
"Z_COORD"_s : cmbFields->currentField();
9511 addLayerData( layer, attribute );
9515void QgsInterpolationSourceWidget::removeLayer()
9517 QTreeWidgetItem *item = layersTree->currentItem();
9526void QgsInterpolationSourceWidget::layerChanged(
QgsVectorLayer *layer )
9528 chkUseZCoordinate->setEnabled(
false );
9529 chkUseZCoordinate->setChecked(
false );
9531 if ( !layer || !layer->
isValid() )
9533 cmbFields->setLayer(
nullptr );
9534 updateAddButtonState();
9540 chkUseZCoordinate->setEnabled(
true );
9543 cmbFields->setLayer( layer );
9544 updateAddButtonState();
9547void QgsInterpolationSourceWidget::updateAddButtonState()
9549 const bool hasLayer = cmbFields->layer();
9550 const bool layerValid = hasLayer && canAddLayer();
9552 btnAdd->setEnabled( layerValid );
9553 const QString toolTip = layerValid ? QString() : tr(
"Select a numeric attribute or use the Z coordinate." );
9554 btnAdd->setToolTip( toolTip );
9557void QgsInterpolationSourceWidget::addLayerData(
QgsVectorLayer *layer,
const QString &attribute )
9559 QTreeWidgetItem *item =
new QTreeWidgetItem();
9560 item->setText( 0, layer->
name() );
9561 item->setText( 1, attribute );
9562 item->setData( 0, Qt::UserRole, layer->
source() );
9563 layersTree->addTopLevelItem( item );
9565 QComboBox *comboBox =
new QComboBox();
9569 comboBox->setCurrentIndex( 0 );
9570 layersTree->setItemWidget( item, 2, comboBox );
9573void QgsInterpolationSourceWidget::setValue(
const QVariant &value,
QgsProcessingContext &context )
9575 layersTree->clear();
9576 const QStringList rows = value.toString().split(
"::|::"_L1, Qt::SkipEmptyParts );
9578 for (
const QString &row : rows )
9580 const QStringList tokens = row.split(
"::~::"_L1 );
9581 if ( tokens.size() < 4 )
9586 const QString layerSource = tokens.at( 0 );
9588 if ( !layer || !layer->
isValid() )
9592 const int fieldIndexInt = tokens.at( 2 ).toInt( &isInt );
9593 if ( isInt && fieldIndexInt == -1 )
9595 addLayerData( layer, u
"Z_COORD"_s );
9599 addLayerData( layer, layer->
fields().
at( fieldIndexInt ).
name() );
9603 addLayerData( layer, tokens.at( 2 ) );
9607 QComboBox *comboBox = qobject_cast<QComboBox *>( layersTree->itemWidget( layersTree->topLevelItem( itemIndex ), 2 ) );
9610 comboBox->setCurrentIndex( comboBox->findData( QVariant::fromValue( sourceType ) ) );
9617QVariant QgsInterpolationSourceWidget::value()
const
9620 for (
int index = 0; index < layersTree->topLevelItemCount(); ++index )
9622 QTreeWidgetItem *item = layersTree->topLevelItem( index );
9628 const QString layerSource = item->data( 0, Qt::UserRole ).toString();
9629 QString interpolationAttribute = item->text( 1 );
9632 if ( interpolationAttribute ==
"Z_COORD"_L1 )
9635 interpolationAttribute = u
"-1"_s;
9638 QComboBox *comboBox = qobject_cast<QComboBox *>( layersTree->itemWidget( item, 2 ) );
9639 const int inputType = comboBox ?
static_cast< int >( comboBox->currentData().value< Qgis::InterpolationSourceType >() ) : 0;
9641 result << u
"%1::~::%2::~::%3::~::%4"_s.arg( layerSource ).arg( valueSource ).arg( interpolationAttribute ).arg( inputType );
9644 if ( result.isEmpty() )
9647 return result.join(
"::|::"_L1 );
9659QString QgsProcessingInterpolationSourceWidgetWrapper::parameterType()
const
9666 return new QgsProcessingInterpolationSourceWidgetWrapper( parameter, type );
9676QWidget *QgsProcessingInterpolationSourceWidgetWrapper::createWidget()
9678 mWidget =
new QgsInterpolationSourceWidget();
9679 if ( parameterDefinition() )
9681 mWidget->setToolTip( parameterDefinition()->toolTip() );
9684 connect( mWidget, &QgsInterpolationSourceWidget::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
9688void QgsProcessingInterpolationSourceWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
9692 mWidget->setValue( value, context );
9696QVariant QgsProcessingInterpolationSourceWidgetWrapper::widgetValue()
const
9698 return mWidget ? mWidget->value() : QVariant();
9706QgsInterpolationPixelSizeWidget::QgsInterpolationPixelSizeWidget( QWidget *parent )
9711 mCellXSpinBox->setShowClearButton(
false );
9712 mCellYSpinBox->setShowClearButton(
false );
9713 mRowsSpinBox->setShowClearButton(
false );
9714 mColumnsSpinBox->setShowClearButton(
false );
9716 connect( mCellYSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), mCellXSpinBox, &QgsDoubleSpinBox::setValue );
9717 connect( mCellXSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsInterpolationPixelSizeWidget::pixelSizeChanged );
9718 connect( mRowsSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, &QgsInterpolationPixelSizeWidget::rowsChanged );
9719 connect( mColumnsSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ),
this, &QgsInterpolationPixelSizeWidget::columnsChanged );
9722void QgsInterpolationPixelSizeWidget::setSourceData(
const QString &sourceData,
QgsProcessingContext &context )
9725 const QStringList rows = sourceData.split(
"::|::"_L1, Qt::SkipEmptyParts );
9726 for (
const QString &row : rows )
9728 const QStringList tokens = row.split(
"::~::"_L1 );
9729 if ( tokens.isEmpty() )
9737 mExtent.combineExtentWith( source->sourceExtent() );
9744void QgsInterpolationPixelSizeWidget::setExtent(
const QgsRectangle &extent )
9750void QgsInterpolationPixelSizeWidget::pixelSizeChanged()
9752 const double prevValue = value();
9753 const double cellSize = mCellXSpinBox->value();
9756 emit valueChanged();
9762 const int rows = std::max(
static_cast<int>( std::round( mExtent.height() / cellSize ) ) + 1, 1 );
9763 const int cols = std::max(
static_cast<int>( std::round( mExtent.width() / cellSize ) ) + 1, 1 );
9770 emit valueChanged();
9774void QgsInterpolationPixelSizeWidget::rowsChanged()
9776 const int rows = mRowsSpinBox->value();
9777 if ( rows <= 0 || mExtent.isNull() )
9780 const double cellSize = mExtent.height() / rows;
9784 const int cols = std::max(
static_cast<int>( std::round( mExtent.width() / cellSize ) ) + 1, 1 );
9790 emit valueChanged();
9793void QgsInterpolationPixelSizeWidget::columnsChanged()
9795 const int cols = mColumnsSpinBox->value();
9796 if ( cols < 2 || mExtent.isNull() )
9799 const double cellSize = mExtent.width() / ( cols - 1 );
9803 const int rows = std::max(
static_cast<int>( std::round( mExtent.height() / cellSize ) ), 1 );
9809 emit valueChanged();
9812double QgsInterpolationPixelSizeWidget::value()
const
9814 return mCellXSpinBox->value();
9817void QgsInterpolationPixelSizeWidget::setValue(
double value )
9819 mCellXSpinBox->setValue( value );
9820 mCellYSpinBox->setValue( value );
9832QString QgsProcessingInterpolationPixelSizeWidgetWrapper::parameterType()
const
9839 return new QgsProcessingInterpolationPixelSizeWidgetWrapper( parameter, type );
9849QWidget *QgsProcessingInterpolationPixelSizeWidgetWrapper::createWidget()
9855 mWidget =
new QgsInterpolationPixelSizeWidget();
9856 connect( mWidget, &QgsInterpolationPixelSizeWidget::valueChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
9864 mFallbackSpinBox->setShowClearButton(
false );
9865 mFallbackSpinBox->setMinimum( 0.0 );
9866 mFallbackSpinBox->setMaximum( 99999999999.0 );
9867 mFallbackSpinBox->setDecimals( 6 );
9868 mFallbackSpinBox->setToolTip( tr(
"Resolution of each pixel in output raster" ) );
9869 connect( mFallbackSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this] { emit widgetValueHasChanged(
this ); } );
9870 return mFallbackSpinBox;
9876void QgsProcessingInterpolationPixelSizeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
9885 if ( !param || !mWidget )
9892 sourceChanged( wrapper );
9897 extentChanged( wrapper );
9909void QgsProcessingInterpolationPixelSizeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext & )
9912 mWidget->setValue( value.toDouble() );
9913 else if ( mFallbackSpinBox )
9914 mFallbackSpinBox->setValue( value.toDouble() );
9917QVariant QgsProcessingInterpolationPixelSizeWidgetWrapper::widgetValue()
const
9920 return mWidget->value();
9921 else if ( mFallbackSpinBox )
9922 return mFallbackSpinBox->value();
9931 std::unique_ptr<QgsProcessingContext> tmpContext;
9932 if ( mProcessingContextGenerator )
9933 context = mProcessingContextGenerator->processingContext();
9937 tmpContext = std::make_unique<QgsProcessingContext>();
9938 context = tmpContext.get();
9941 mWidget->setSourceData( wrapper->
parameterValue().toString(), *context );
9950 std::unique_ptr<QgsProcessingContext> tmpContext;
9951 if ( mProcessingContextGenerator )
9952 context = mProcessingContextGenerator->processingContext();
9956 tmpContext = std::make_unique<QgsProcessingContext>();
9957 context = tmpContext.get();
9962 mWidget->setExtent( extent );
9977 QFontMetrics fm( font() );
9978 mRegionsWidget->setColumnWidth( 0, fm.horizontalAdvance(
'X' ) * 20 );
9979 mRegionsWidget->header()->setStretchLastSection(
true );
9981 connect( mButtonAdd, &QToolButton::clicked,
this, &QgsTileExtentMaxZoomWidget::addClicked );
9982 connect( mButtonRemove, &QToolButton::clicked,
this, &QgsTileExtentMaxZoomWidget::removeClicked );
9983 connect( mRegionsWidget, &QTreeWidget::itemDoubleClicked,
this, &QgsTileExtentMaxZoomWidget::itemDoubleClicked );
9986QgsTileExtentMaxZoomWidget::~QgsTileExtentMaxZoomWidget() =
default;
9988void QgsTileExtentMaxZoomWidget::addClicked()
9992 mMapToolPrevious = mMapCanvas->mapTool();
9993 if ( !mMapToolExtent )
9995 mMapToolExtent = std::make_unique<QgsMapToolExtent>( mMapCanvas );
9997 connect( mMapToolExtent.get(), &
QgsMapTool::deactivated,
this, &QgsTileExtentMaxZoomWidget::mapToolDeactivated );
9999 mMapCanvas->setMapTool( mMapToolExtent.get() );
10001 emit toggleDialogVisibility(
false );
10005void QgsTileExtentMaxZoomWidget::extentDrawn(
const QgsRectangle &extent )
10009 mMapCanvas->setMapTool( mMapToolPrevious );
10010 emit toggleDialogVisibility(
true );
10011 mMapToolPrevious =
nullptr;
10013 auto item =
new QTreeWidgetItem();
10014 item->setText( 0, u
"15"_s );
10015 item->setText( 1, regionToString( newExtent ) );
10016 mRegionsWidget->addTopLevelItem( item );
10017 emit valueChanged();
10020void QgsTileExtentMaxZoomWidget::mapToolDeactivated()
10022 emit toggleDialogVisibility(
true );
10023 mMapToolPrevious =
nullptr;
10028 return u
"%1,%3,%2,%4 [%5]"_s
10032void QgsTileExtentMaxZoomWidget::removeClicked()
10034 const QList<QTreeWidgetItem *> selectedItems = mRegionsWidget->selectedItems();
10035 for ( QTreeWidgetItem *item : std::as_const( selectedItems ) )
10039 emit valueChanged();
10042void QgsTileExtentMaxZoomWidget::itemDoubleClicked( QTreeWidgetItem *item,
int column )
10050 const int d = QInputDialog::getInt(
this, tr(
"Maximum Zoom Level" ), tr(
"Enter maximum zoom level for region" ), item->text( 0 ).toInt(), 0, 20, 1, &ok );
10053 item->setText( 0, QString::number( d ) );
10054 emit valueChanged();
10059QList<QgsTileExtentMaxZoomRegion> QgsTileExtentMaxZoomWidget::regions()
const
10061 QList<QgsTileExtentMaxZoomRegion> regions;
10063 for (
int i = 0; i < mRegionsWidget->topLevelItemCount(); ++i )
10065 if ( QTreeWidgetItem *item = mRegionsWidget->topLevelItem( i ) )
10067 const QgsTileExtentMaxZoomRegion region = mParam->regionFromVariant( u
"%1:%2"_s.arg( item->text( 0 ), item->text( 1 ) ), context );
10071 regions.append( region );
10077void QgsTileExtentMaxZoomWidget::setRegions(
const QList<QgsTileExtentMaxZoomRegion> ®ions )
10079 mRegionsWidget->clear();
10082 auto item =
new QTreeWidgetItem();
10083 item->setText( 0, QString::number( r.maxZoom ) );
10084 item->setText( 1, regionToString( r.extent ) );
10085 mRegionsWidget->addTopLevelItem( item );
10087 emit valueChanged();
10090void QgsTileExtentMaxZoomWidget::setMapCanvas(
QgsMapCanvas *canvas )
10092 mMapCanvas = canvas;
10101 : QWidget( nullptr )
10104 QHBoxLayout *hl =
new QHBoxLayout();
10105 hl->setContentsMargins( 0, 0, 0, 0 );
10107 mLineEdit =
new QLineEdit();
10108 mLineEdit->setEnabled(
false );
10109 hl->addWidget( mLineEdit, 1 );
10111 mToolButton =
new QToolButton();
10112 mToolButton->setText( QString( QChar( 0x2026 ) ) );
10113 hl->addWidget( mToolButton );
10117 mLineEdit->setText( tr(
"No regions defined" ) );
10119 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingTileExtentMaxZoomParameterPanel::showDialog );
10122QVariant QgsProcessingTileExtentMaxZoomParameterPanel::value()
const
10125 if ( mPanelWidget )
10131void QgsProcessingTileExtentMaxZoomParameterPanel::setValue(
const QVariant &value,
QgsProcessingContext &context )
10133 const QList<QgsTileExtentMaxZoomRegion> regions = mParam->parameterAsRegionList( value, context );
10134 setRegions( regions );
10137void QgsProcessingTileExtentMaxZoomParameterPanel::setRegions(
const QList<QgsTileExtentMaxZoomRegion> ®ions )
10139 mRegions = regions;
10140 if ( mPanelWidget )
10142 mPanelWidget->setRegions( regions );
10145 updateSummaryText();
10149void QgsProcessingTileExtentMaxZoomParameterPanel::setMapCanvas(
QgsMapCanvas *canvas )
10151 mMapCanvas = canvas;
10152 if ( mPanelWidget )
10154 mPanelWidget->setMapCanvas( mMapCanvas );
10158void QgsProcessingTileExtentMaxZoomParameterPanel::showDialog()
10162 mPanelWidget =
new QgsTileExtentMaxZoomWidget( mParam );
10164 mPanelWidget->setPanelTitle( mParam->description() );
10165 mPanelWidget->setRegions( mRegions );
10166 mPanelWidget->setMapCanvas( mMapCanvas );
10170 connect( mPanelWidget, &QgsTileExtentMaxZoomWidget::toggleDialogVisibility,
this, &QgsProcessingTileExtentMaxZoomParameterPanel::toggleDialogVisibility );
10172 connect( mPanelWidget, &QgsTileExtentMaxZoomWidget::valueChanged,
this, [
this] {
10173 mRegions = mPanelWidget->regions();
10174 updateSummaryText();
10180void QgsProcessingTileExtentMaxZoomParameterPanel::updateSummaryText()
10182 mLineEdit->setText( tr(
"%1 regions defined" ).arg( mRegions.count() ) );
10194QString QgsProcessingTileExtentMaxZoomWidgetWrapper::parameterType()
const
10201 return new QgsProcessingTileExtentMaxZoomWidgetWrapper( parameter, type );
10211QWidget *QgsProcessingTileExtentMaxZoomWidgetWrapper::createWidget()
10218 mWidget =
new QgsProcessingTileExtentMaxZoomParameterPanel( param );
10220 if ( widgetContext().mapCanvas() )
10221 mWidget->setMapCanvas( widgetContext().mapCanvas() );
10223 connect( mWidget, &QgsProcessingTileExtentMaxZoomParameterPanel::changed,
this, [
this] { emit widgetValueHasChanged(
this ); } );
10226 setDialog( mDialog );
10234 mFallbackLineEdit =
new QLineEdit();
10235 mFallbackLineEdit->setPlaceholderText( tr(
"Tile extent max zoom level definition" ) );
10236 connect( mFallbackLineEdit, &QLineEdit::textChanged,
this, [
this] { emit widgetValueHasChanged(
this ); } );
10237 return mFallbackLineEdit;
10247 mWidget->setMapCanvas( context.
mapCanvas() );
10250void QgsProcessingTileExtentMaxZoomWidgetWrapper::setDialog( QWidget *dialog )
10255 connect( mWidget, &QgsProcessingTileExtentMaxZoomParameterPanel::toggleDialogVisibility, mDialog, [
this](
bool visible ) {
10258 mDialog->showMinimized();
10262 mDialog->showNormal();
10264 mDialog->activateWindow();
10271void QgsProcessingTileExtentMaxZoomWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
10275 if ( mWidget && param )
10277 mWidget->setValue( value, context );
10279 else if ( mFallbackLineEdit )
10282 mFallbackLineEdit->setText( param->
valueAsString( value, context, ok ) );
10286QVariant QgsProcessingTileExtentMaxZoomWidgetWrapper::widgetValue()
const
10290 return mWidget->value();
10292 else if ( mFallbackLineEdit )
10294 return mFallbackLineEdit->text();
10299QString QgsProcessingTileExtentMaxZoomWidgetWrapper::modelerExpressionFormatString()
const
10301 return tr(
"string of the format 'zoom:xmin,ymin,xmax,ymax [crs]', joined by a '::|::' delimiter" );
@ Standard
Unit is a standard measurement unit.
ProcessingSourceType
Processing data source types.
@ File
Files (i.e. non map layer sources, such as text files).
@ TiledScene
Tiled scene layers.
@ Annotation
Annotation layers.
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ VectorTile
Vector tile layers.
@ MapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer).
@ VectorAnyGeometry
Any vector layer with geometry.
@ VectorPoint
Vector point layers.
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
@ PointCloud
Point cloud layers.
ProcessingFileParameterBehavior
Flags which dictate the behavior of QgsProcessingParameterFile.
@ File
Parameter is a single file.
@ Folder
Parameter is a folder.
ExpressionType
Expression types.
@ RasterCalculator
Raster calculator expression.
@ Qgis
Native QGIS expression.
@ PointCloud
Point cloud expression.
InterpolationSourceType
Interpolation source types.
@ StructureLines
Structure lines.
@ Z
Use feature's geometry Z values for interpolation.
@ Attribute
Take value from feature's attribute.
ProcessingMode
Types of modes which Processing widgets can be created for.
@ Batch
Batch processing mode.
@ Standard
Standard (single-run) algorithm mode.
DistanceUnit
Units of distance.
@ Centimeters
Centimeters.
@ Millimeters
Millimeters.
@ Miles
Terrestrial miles.
@ Unknown
Unknown distance unit.
@ Degrees
Degrees, for planar geographic CRS distance measurements.
@ NauticalMiles
Nautical miles.
ProcessingFieldParameterDataType
Processing field parameter data types.
@ String
Accepts string fields.
@ Boolean
Accepts boolean fields, since QGIS 3.34.
@ Binary
Accepts binary fields, since QGIS 3.34.
@ Numeric
Accepts numeric fields.
@ DateTime
Accepts datetime fields.
@ SquareCentimeters
Square centimeters.
@ SquareInches
Square inches.
@ SquareNauticalMiles
Square nautical miles.
@ SquareMillimeters
Square millimeters.
@ SquareYards
Square yards.
@ SquareKilometers
Square kilometers.
@ SquareMeters
Square meters.
@ Unknown
Unknown areal unit.
@ SquareDegrees
Square degrees, for planar geographic CRS area measurements.
@ SquareMiles
Square miles.
@ Info
Information message.
@ AnnotationLayer
QgsAnnotationLayer.
TemporalUnit
Temporal units.
@ Milliseconds
Milliseconds.
@ CrossX
A cross is used to highlight points (x).
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
QFlags< ProcessingParameterFlag > ProcessingParameterFlags
Flags which dictate the behavior of Processing parameters.
VolumeUnit
Units of volume.
@ CubicMeters
Cubic meters.
@ CubicDegrees
Cubic degrees, for planar geographic CRS volume measurements.
@ CubicDecimeter
Cubic decimeters.
@ Unknown
Unknown volume unit.
@ CubicCentimeter
Cubic Centimeters.
ProcessingModelChildParameterSource
Processing model child parameter sources.
@ ModelParameter
Parameter value is taken from a parent model parameter.
@ StaticValue
Parameter value is a static value.
@ Optional
Parameter is optional.
ProcessingDateTimeParameterDataType
Processing date time parameter data types.
@ DateTime
Datetime values.
ProcessingNumberParameterType
Processing numeric parameter data types.
@ Double
Double/float values.
static QgsProcessingRegistry * processingRegistry()
Returns the application's processing registry, used for managing processing providers,...
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
@ CapturePoint
Select and capture a point or a feature.
Selector widget for authentication configs.
void selectedConfigIdChanged(const QString &authcfg)
Emitted when authentication config is changed or missing.
QComboBox subclass which allows selecting multiple items.
void checkedItemsChanged(const QStringList &items)
Emitted whenever the checked items list changed.
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
A combo box which displays the list of schemas for a specific database connection.
A combobox which displays the list of tables for a specific database connection.
A QDateEdit widget with the capability of setting/reading null dates.
void dateValueChanged(const QDate &date)
Signal emitted whenever the date changes.
A QDateTimeEdit with the capability of setting/reading null date/times.
void setAllowNull(bool allowNull)
Determines if the widget allows setting null date/time.
void setNullRepresentation(const QString &null)
Sets the widget's null representation, which defaults to QgsApplication::nullRepresentation().
void valueChanged(const QDateTime &date)
Signal emitted whenever the value changes.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
static double toDouble(const QString &input, bool *ok)
Converts input string to double value.
A widget which includes a line edit for entering expressions together with a button to open the expre...
void expressionChanged(const QString &expression)
Emitted when the expression is changed.
A combobox which displays the list of fields of a given layer.
void fieldChanged(const QString &fieldName)
Emitted when the currently selected field changes.
@ DateTime
Datetime fields.
@ Date
Date or datetime fields.
@ Binary
Binary fields, since QGIS 3.34.
@ Boolean
Boolean fields, since QGIS 3.34.
@ Numeric
All numeric fields.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
void remove(int fieldIdx)
Removes the field with the given index.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
static QString ensureFileNameHasExtension(const QString &fileName, const QStringList &extensions)
Ensures that a fileName ends with an extension from the provided list of extensions.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
A geometry is the spatial representation of a feature.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
Q_INVOKABLE QString asWkt(int precision=17) const
Exports the geometry to WKT.
A QgsFilterLineEdit subclass with the ability to "highlight" the edges of the widget.
A combobox which displays available layouts from a QgsLayoutManager.
void layoutChanged(QgsMasterLayoutInterface *layout)
Emitted whenever the currently selected layout changes.
A combo box which displays items of a matching type from a layout.
void itemChanged(QgsLayoutItem *item)
Emitted whenever the currently selected item changes.
Base class for graphical items within a QgsLayout.
virtual QString uuid() const
Returns the item identification string.
@ FilterPrintLayouts
Includes print layouts.
QList< QgsPrintLayout * > printLayouts() const
Returns a list of all print layouts contained in the manager.
Map canvas is a class for displaying all GIS data types on a canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
A combobox which displays a dynamic list of layers from a QGIS project.
void layerChanged(QgsMapLayer *layer)
Emitted whenever the currently selected layer changes.
Base class for all map layer types.
QString source() const
Returns the source for the layer.
A mouse event which is the result of a user interaction with a QgsMapCanvas.
QgsPointLocator::Match mapPointMatch() const
Returns the matching data from the most recently snapped point.
QgsPointXY snapPoint()
snapPoint will snap the points using the map canvas snapping utils configuration
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
Interface for master layout type objects, such as print layouts and reports.
virtual QString name() const =0
Returns the layout's name.
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::MessageLevel::Info, int duration=-1)
A convenience method for pushing a message with the specified text to the bar.
bool clearWidgets()
Removes all items from the bar.
A collection of point cloud attributes.
A combobox which displays the list of attributes of a given point cloud layer.
void attributeChanged(const QString &name)
Emitted when the currently selected attribute changes.
Attribute for point cloud data pair of name and size in bytes.
Represents a map layer supporting display of point clouds.
QgsPointCloudAttributeCollection attributes() const
Returns the attributes available from the layer.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Abstract base class for processing algorithms.
An interface for objects which can create Processing contexts.
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
QgsMapLayer * takeResultLayer(const QString &id)
Takes the result map layer with matching id from the context and transfers ownership of it back to th...
Base class for all parameter definitions which represent file or layer destinations,...
Encapsulates settings relating to a feature source input to a processing algorithm.
QgsProperty source
Source definition.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the parameter class.
A double numeric parameter for area values.
Qgis::AreaUnit defaultUnit() const
Returns the default area unit for the parameter.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A raster band parameter for Processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
bool allowMultiple() const
Returns whether multiple band selections are permitted.
A boolean parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A color parameter for processing algorithms.
bool opacityEnabled() const
Returns true if the parameter allows opacity control.
static QString typeName()
Returns the type name for the parameter class.
A coordinate operation parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
QVariant sourceCrs() const
Returns the static source CRS, or an invalid value if this is not set.
QVariant destinationCrs() const
Returns the static destination CRS, or an invalid value if this is not set.
A coordinate reference system parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A database schema parameter for processing algorithms, allowing users to select from existing schemas...
static QString typeName()
Returns the type name for the parameter class.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
A database table name parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
QString parentSchemaParameterName() const
Returns the name of the parent schema parameter, or an empty string if this is not set.
bool allowNewTableNames() const
Returns true if the parameter allows users to enter names for a new (non-existing) tables.
A datetime (or pure date or time) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
Qgis::ProcessingDateTimeParameterDataType dataType() const
Returns the acceptable data type for the parameter.
Base class for the definition of processing parameters.
void setDefaultValue(const QVariant &value)
Sets the default value for the parameter.
void setFlags(Qgis::ProcessingParameterFlags flags)
Sets the flags associated with the parameter.
QVariantMap metadata() const
Returns the parameter's freeform metadata.
QString description() const
Returns the description for the parameter.
QVariant defaultValueForGui() const
Returns the default value to use for the parameter in a GUI.
void setDescription(const QString &description)
Sets the description for the parameter.
void setName(const QString &name)
Sets the name of the parameter.
virtual QgsProcessingParameterDefinition * clone() const =0
Creates a clone of the parameter definition.
virtual QString type() const =0
Unique parameter type name.
QString name() const
Returns the name of the parameter.
Qgis::ProcessingParameterFlags flags() const
Returns any flags associated with the parameter.
A double numeric parameter for distance values.
static QString typeName()
Returns the type name for the parameter class.
Qgis::DistanceUnit defaultUnit() const
Returns the default distance unit for the parameter.
A double numeric parameter for duration values.
Qgis::TemporalUnit defaultUnit() const
Returns the default duration unit for the parameter.
static QString typeName()
Returns the type name for the parameter class.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
bool allowMultiple() const
Returns true if the parameter allows multiple selected values.
QStringList options() const
Returns the list of acceptable options for the parameter.
bool usesStaticStrings() const
Returns true if the parameter uses static (non-translated) string values for its enumeration choice l...
static QString typeName()
Returns the type name for the parameter class.
An expression parameter for processing algorithms.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
static QString typeName()
Returns the type name for the parameter class.
Qgis::ExpressionType expressionType() const
Returns the parameter's expression type.
A rectangular map extent parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
An input feature source (such as vector layers) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A vector layer or feature source field parameter for processing algorithms.
Qgis::ProcessingFieldParameterDataType dataType() const
Returns the acceptable data type for the field.
bool allowMultiple() const
Returns whether multiple field selections are permitted.
bool defaultToAllFields() const
Returns whether a parameter which allows multiple selections (see allowMultiple()) should automatical...
static QString typeName()
Returns the type name for the parameter class.
void setDataType(Qgis::ProcessingFieldParameterDataType type)
Sets the acceptable data type for the field.
static QString typeName()
Returns the type name for the parameter class.
An input file or folder parameter for processing algorithms.
QString extension() const
Returns any specified file extension for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QString fileFilter() const
Returns the file filter string for file destinations compatible with this parameter.
Qgis::ProcessingFileParameterBehavior behavior() const
Returns the parameter behavior (e.g.
static QString typeName()
Returns the type name for the parameter class.
A geometry parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A parameter for the heatmap algorithm pixel size parameter.
static QString typeName()
Returns the type name for the parameter class.
A parameter for the interpolation algorithm pixel size parameter.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A print layout item parameter, allowing users to select a particular item from a print layout.
static QString typeName()
Returns the type name for the parameter class.
int itemType() const
Returns the acceptable item type, or -1 if any item type is allowed.
A print layout parameter, allowing users to select a print layout.
static QString typeName()
Returns the type name for the parameter class.
A map layer parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
A map theme parameter for processing algorithms, allowing users to select an existing map theme from ...
static QString typeName()
Returns the type name for the parameter class.
A table (matrix) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A parameter for processing algorithms which accepts multiple map layers.
Qgis::ProcessingSourceType layerType() const
Returns the layer type for layers acceptable by the parameter.
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.
A Processing algorithm parameter for defining a list of spatial extents, each with an associated maxi...
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
static QVariant toVariant(const QList< QgsTileExtentMaxZoomRegion > ®ions)
Converts a list of regions to variant value.
static QString typeName()
Returns the type name for the parameter class.
Makes metadata of processing parameters available.
virtual QgsProcessingParameterDefinition * create(const QString &name) const =0
Creates a new parameter of this type.
static QString typeName()
Returns the type name for the parameter class.
A vector layer (with or without geometry) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A double numeric parameter for volume values.
static QString typeName()
Returns the type name for the parameter class.
Qgis::VolumeUnit defaultUnit() const
Returns the default volume unit for the parameter.
Contains settings which reflect the context in which a Processing parameter widget is shown.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QgsProject * project() const
Returns the project associated with the widget.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
QgsProcessingModelAlgorithm * model() const
Returns the model which the parameter widget is associated with.
QgsMapLayer * activeLayer() const
Returns the current active layer.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a list of map layers.
static QTime parameterAsTime(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static time value.
static QgsRectangle parameterAsExtent(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent.
static QString parameterAsEnumString(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static enum string.
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
static QStringList parameterAsStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of strings (e.g.
static QList< int > parameterAsInts(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of integer values.
static QString parameterAsConnectionName(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a connection name string.
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
static QgsPointCloudLayer * parameterAsPointCloudLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a point cloud layer.
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
static QgsLayoutItem * parameterAsLayoutItem(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsPrintLayout *layout)
Evaluates the parameter with matching definition to a print layout item, taken from the specified lay...
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QColor parameterAsColor(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the color associated with an point parameter value, or an invalid color if the parameter was ...
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
static int parameterAsInt(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static integer value.
static QString parameterAsDatabaseTableName(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database table name.
static QString parameterAsSchema(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database schema name.
static QgsGeometry parameterAsGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a geometry.
static QString parameterAsExpression(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to an expression.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
static QgsRasterLayer * parameterAsRasterLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a raster layer.
static QList< int > parameterAsEnums(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of enum values.
static QStringList parameterAsEnumStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of static enum strings.
static QgsCoordinateReferenceSystem parameterAsExtentCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
static QDateTime parameterAsDateTime(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static datetime value.
static QDate parameterAsDate(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static date value.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
QgsProcessingParameterType * parameterType(const QString &id) const
Returns the parameter type registered for id.
Utility functions for use with processing classes.
@ Annotation
Annotation layer type, since QGIS 3.22.
@ Vector
Vector layer type.
static QgsProcessingFeatureSource * variantToSource(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a new feature source.
static QgsCoordinateReferenceSystem variantToCrs(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a coordinate reference system.
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, QgsProcessingUtils::LayerHint typeHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Interprets a string as a map layer within the supplied context.
@ SkipIndexGeneration
Do not generate index when creating a layer. Makes sense only for point cloud layers.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsMapThemeCollection * mapThemeCollection
const QgsLayoutManager * layoutManager() const
Returns the project's layout manager, which manages print layouts, atlases and reports within the pro...
void layerRemoved(const QString &layerId)
Emitted after a layer was removed from the registry.
A store for object properties.
Qgis::PropertyType propertyType() const
Returns the property type.
A combo box which displays the list of connections registered for a given provider.
A combobox widget which displays the bands present in a raster layer.
void bandChanged(int band)
Emitted when the currently selected band changes.
static QString displayBandName(QgsRasterDataProvider *provider, int band)
Returns a user-friendly band name for the specified band.
Base class for raster data providers.
virtual int bandCount() const =0
Gets number of bands.
static QList< QgsRasterReliefColor > calculateOptimizedReliefClasses(QgsRasterDataProvider *provider, int band)
Calculates optimized relief class breaks according with the method of Buenzli (2011) using an iterati...
Represents a raster layer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Defines elevation range and color for raster relief coloring.
A rectangle specified with double values.
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
A QgsGeometry with associated coordinate reference system.
A QgsRectangle 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.
Represents a spatial region paired with a custom maximum zoom level.
QgsReferencedRectangle extent
Bounding box extent and associated CRS.