20 #include "processing/models/qgsprocessingmodelalgorithm.h" 45 #include <QToolButton> 47 #include <QHBoxLayout> 48 #include <QVBoxLayout> 52 #include <QPlainTextEdit> 53 #include <QRadioButton> 54 #include <QButtonGroup> 67 QVBoxLayout *vlayout =
new QVBoxLayout();
68 vlayout->setMargin( 0 );
69 vlayout->setContentsMargins( 0, 0, 0, 0 );
71 mDefaultCheckBox =
new QCheckBox( tr(
"Checked" ) );
75 mDefaultCheckBox->setChecked(
false );
76 vlayout->addWidget( mDefaultCheckBox );
80 QgsProcessingParameterDefinition *QgsProcessingBooleanParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const 82 auto param = qgis::make_unique< QgsProcessingParameterBoolean >( name, description, mDefaultCheckBox->isChecked() );
84 return param.release();
94 QWidget *QgsProcessingBooleanWidgetWrapper::createWidget()
100 QString description = parameterDefinition()->description();
102 description = QObject::tr(
"%1 [optional]" ).arg( description );
104 mCheckBox =
new QCheckBox( description );
105 mCheckBox->setToolTip( parameterDefinition()->toolTip() );
107 connect( mCheckBox, &QCheckBox::toggled,
this, [ = ]
109 emit widgetValueHasChanged(
this );
117 mComboBox =
new QComboBox();
118 mComboBox->addItem( tr(
"Yes" ),
true );
119 mComboBox->addItem( tr(
"No" ),
false );
120 mComboBox->setToolTip( parameterDefinition()->toolTip() );
122 connect( mComboBox, qgis::overload< int>::of( &QComboBox::currentIndexChanged ),
this, [ = ]
124 emit widgetValueHasChanged(
this );
133 QLabel *QgsProcessingBooleanWidgetWrapper::createLabel()
142 void QgsProcessingBooleanWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
149 mCheckBox->setChecked( v );
157 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
163 QVariant QgsProcessingBooleanWidgetWrapper::widgetValue()
const 168 return mCheckBox->isChecked();
172 return mComboBox->currentData();
177 QStringList QgsProcessingBooleanWidgetWrapper::compatibleParameterTypes()
const 195 QStringList QgsProcessingBooleanWidgetWrapper::compatibleOutputTypes()
const 206 QList<int> QgsProcessingBooleanWidgetWrapper::compatibleDataTypes()
const 208 return QList< int >();
211 QString QgsProcessingBooleanWidgetWrapper::parameterType()
const 218 return new QgsProcessingBooleanWidgetWrapper( parameter, type );
223 return new QgsProcessingBooleanParameterDefinitionWidget( context, widgetContext, definition, algorithm );
237 QWidget *QgsProcessingCrsWidgetWrapper::createWidget()
240 mProjectionSelectionWidget->setToolTip( parameterDefinition()->toolTip() );
249 emit widgetValueHasChanged(
this );
257 return mProjectionSelectionWidget;
262 QWidget *w =
new QWidget();
263 w->setToolTip( parameterDefinition()->toolTip() );
265 QVBoxLayout *vl =
new QVBoxLayout();
267 vl->setContentsMargins( 0, 0, 0, 0 );
270 mUseProjectCrsCheckBox =
new QCheckBox( tr(
"Use project CRS" ) );
271 mUseProjectCrsCheckBox->setToolTip( tr(
"Always use the current project CRS when running the model" ) );
272 vl->addWidget( mUseProjectCrsCheckBox );
273 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, mProjectionSelectionWidget, &QgsProjectionSelectionWidget::setDisabled );
274 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled,
this, [ = ]
276 emit widgetValueHasChanged(
this );
279 vl->addWidget( mProjectionSelectionWidget );
287 void QgsProcessingCrsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
289 if ( mUseProjectCrsCheckBox )
291 if ( value.toString().compare( QLatin1String(
"ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
293 mUseProjectCrsCheckBox->setChecked(
true );
298 mUseProjectCrsCheckBox->setChecked(
false );
303 if ( mProjectionSelectionWidget )
304 mProjectionSelectionWidget->setCrs( v );
307 QVariant QgsProcessingCrsWidgetWrapper::widgetValue()
const 309 if ( mUseProjectCrsCheckBox && mUseProjectCrsCheckBox->isChecked() )
310 return QStringLiteral(
"ProjectCrs" );
311 else if ( mProjectionSelectionWidget )
312 return mProjectionSelectionWidget->crs().isValid() ? mProjectionSelectionWidget->crs() : QVariant();
317 QStringList QgsProcessingCrsWidgetWrapper::compatibleParameterTypes()
const 329 QStringList QgsProcessingCrsWidgetWrapper::compatibleOutputTypes()
const 337 QList<int> QgsProcessingCrsWidgetWrapper::compatibleDataTypes()
const 339 return QList< int >();
342 QString QgsProcessingCrsWidgetWrapper::modelerExpressionFormatString()
const 344 return tr(
"string as EPSG code, WKT or PROJ format, or a string identifying a map layer" );
347 QString QgsProcessingCrsWidgetWrapper::parameterType()
const 354 return new QgsProcessingCrsWidgetWrapper( parameter, type );
367 QVBoxLayout *vlayout =
new QVBoxLayout();
368 vlayout->setMargin( 0 );
369 vlayout->setContentsMargins( 0, 0, 0, 0 );
371 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
373 mDefaultLineEdit =
new QLineEdit();
376 vlayout->addWidget( mDefaultLineEdit );
378 mMultiLineCheckBox =
new QCheckBox( tr(
"Multiline input" ) );
380 mMultiLineCheckBox->setChecked( stringParam->multiLine() );
381 vlayout->addWidget( mMultiLineCheckBox );
383 setLayout( vlayout );
386 QgsProcessingParameterDefinition *QgsProcessingStringParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const 388 auto param = qgis::make_unique< QgsProcessingParameterString >( name, description, mDefaultLineEdit->text(), mMultiLineCheckBox->isChecked() );
390 return param.release();
401 QWidget *QgsProcessingStringWidgetWrapper::createWidget()
408 if ( static_cast< const QgsProcessingParameterString * >( parameterDefinition() )->multiLine() )
410 mPlainTextEdit =
new QPlainTextEdit();
411 mPlainTextEdit->setToolTip( parameterDefinition()->toolTip() );
413 connect( mPlainTextEdit, &QPlainTextEdit::textChanged,
this, [ = ]
415 emit widgetValueHasChanged(
this );
417 return mPlainTextEdit;
421 mLineEdit =
new QLineEdit();
422 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
424 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
426 emit widgetValueHasChanged(
this );
434 mLineEdit =
new QLineEdit();
435 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
437 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
439 emit widgetValueHasChanged(
this );
447 void QgsProcessingStringWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
451 mLineEdit->setText( v );
452 if ( mPlainTextEdit )
453 mPlainTextEdit->setPlainText( v );
456 QVariant QgsProcessingStringWidgetWrapper::widgetValue()
const 459 return mLineEdit->text();
460 else if ( mPlainTextEdit )
461 return mPlainTextEdit->toPlainText();
466 QStringList QgsProcessingStringWidgetWrapper::compatibleParameterTypes()
const 479 QStringList QgsProcessingStringWidgetWrapper::compatibleOutputTypes()
const 486 QList<int> QgsProcessingStringWidgetWrapper::compatibleDataTypes()
const 488 return QList< int >();
491 QString QgsProcessingStringWidgetWrapper::parameterType()
const 498 return new QgsProcessingStringWidgetWrapper( parameter, type );
503 return new QgsProcessingStringParameterDefinitionWidget( context, widgetContext, definition, algorithm );
518 QWidget *QgsProcessingAuthConfigWidgetWrapper::createWidget()
526 mAuthConfigSelect =
new QgsAuthConfigSelect();
527 mAuthConfigSelect->setToolTip( parameterDefinition()->toolTip() );
531 emit widgetValueHasChanged(
this );
533 return mAuthConfigSelect;
539 void QgsProcessingAuthConfigWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
542 if ( mAuthConfigSelect )
543 mAuthConfigSelect->setConfigId( v );
546 QVariant QgsProcessingAuthConfigWidgetWrapper::widgetValue()
const 548 if ( mAuthConfigSelect )
549 return mAuthConfigSelect->configId();
554 QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleParameterTypes()
const 562 QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleOutputTypes()
const 567 QList<int> QgsProcessingAuthConfigWidgetWrapper::compatibleDataTypes()
const 569 return QList< int >();
572 QString QgsProcessingAuthConfigWidgetWrapper::parameterType()
const 579 return new QgsProcessingAuthConfigWidgetWrapper( parameter, type );
592 QWidget *QgsProcessingNumericWidgetWrapper::createWidget()
595 const QVariantMap metadata = numberDef->
metadata();
596 const int decimals = metadata.value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"decimals" ), 6 ).toInt();
604 QAbstractSpinBox *spinBox =
nullptr;
609 mDoubleSpinBox->setExpressionsEnabled(
true );
610 mDoubleSpinBox->setDecimals( decimals );
616 double singleStep = calculateStep( numberDef->
minimum(), numberDef->
maximum() );
617 singleStep = std::max( singleStep, std::pow( 10, -decimals ) );
618 mDoubleSpinBox->setSingleStep( singleStep );
621 spinBox = mDoubleSpinBox;
626 mSpinBox->setExpressionsEnabled(
true );
630 spinBox->setToolTip( parameterDefinition()->toolTip() );
632 double max = 999999999;
637 double min = -999999999;
642 if ( mDoubleSpinBox )
644 mDoubleSpinBox->setMinimum( min );
645 mDoubleSpinBox->setMaximum( max );
649 mSpinBox->setMinimum( static_cast< int >( min ) );
650 mSpinBox->setMaximum( static_cast< int >( max ) );
655 mAllowingNull =
true;
656 if ( mDoubleSpinBox )
658 mDoubleSpinBox->setShowClearButton(
true );
659 const double min = mDoubleSpinBox->minimum() - 1;
660 mDoubleSpinBox->setMinimum( min );
661 mDoubleSpinBox->setValue( min );
665 mSpinBox->setShowClearButton(
true );
666 const int min = mSpinBox->minimum() - 1;
667 mSpinBox->setMinimum( min );
668 mSpinBox->setValue( min );
670 spinBox->setSpecialValueText( tr(
"Not set" ) );
678 if ( mDoubleSpinBox )
680 double defaultVal = numberDef->
defaultValue().toDouble( &ok );
682 mDoubleSpinBox->setClearValue( defaultVal );
688 mSpinBox->setClearValue( intVal );
694 if ( mDoubleSpinBox )
695 mDoubleSpinBox->setClearValue( numberDef->
minimum() );
697 mSpinBox->setClearValue( static_cast< int >( numberDef->
minimum() ) );
702 if ( mDoubleSpinBox )
704 mDoubleSpinBox->setValue( 0 );
705 mDoubleSpinBox->setClearValue( 0 );
709 mSpinBox->setValue( 0 );
710 mSpinBox->setClearValue( 0 );
715 if ( mDoubleSpinBox )
716 connect( mDoubleSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
this, [ = ] { emit widgetValueHasChanged(
this ); } );
718 connect( mSpinBox, qgis::overload<int>::of( &QgsSpinBox::valueChanged ),
this, [ = ] { emit widgetValueHasChanged(
this ); } );
726 void QgsProcessingNumericWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
728 if ( mDoubleSpinBox )
730 if ( mAllowingNull && !value.isValid() )
731 mDoubleSpinBox->clear();
735 mDoubleSpinBox->setValue( v );
740 if ( mAllowingNull && !value.isValid() )
745 mSpinBox->setValue( v );
750 QVariant QgsProcessingNumericWidgetWrapper::widgetValue()
const 752 if ( mDoubleSpinBox )
754 if ( mAllowingNull &&
qgsDoubleNear( mDoubleSpinBox->value(), mDoubleSpinBox->minimum() ) )
757 return mDoubleSpinBox->value();
761 if ( mAllowingNull && mSpinBox->value() == mSpinBox->minimum() )
764 return mSpinBox->value();
770 QStringList QgsProcessingNumericWidgetWrapper::compatibleParameterTypes()
const 779 QStringList QgsProcessingNumericWidgetWrapper::compatibleOutputTypes()
const 785 QList<int> QgsProcessingNumericWidgetWrapper::compatibleDataTypes()
const 787 return QList< int >();
790 double QgsProcessingNumericWidgetWrapper::calculateStep(
const double minimum,
const double maximum )
792 const double valueRange = maximum - minimum;
793 if ( valueRange <= 1.0 )
795 const double step = valueRange / 10.0;
797 return qgsRound( step, -std::floor( std::log( step ) ) );
805 QString QgsProcessingNumericWidgetWrapper::parameterType()
const 812 return new QgsProcessingNumericWidgetWrapper( parameter, type );
820 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
825 QString QgsProcessingDistanceWidgetWrapper::parameterType()
const 832 return new QgsProcessingDistanceWidgetWrapper( parameter, type );
835 QWidget *QgsProcessingDistanceWidgetWrapper::createWidget()
839 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
844 mLabel =
new QLabel();
845 mUnitsCombo =
new QComboBox();
853 const int labelMargin =
static_cast< int >( std::round( mUnitsCombo->fontMetrics().width(
'X' ) ) );
854 QHBoxLayout *layout =
new QHBoxLayout();
855 layout->addWidget( spin, 1 );
856 layout->insertSpacing( 1, labelMargin / 2 );
857 layout->insertWidget( 2, mLabel );
858 layout->insertWidget( 3, mUnitsCombo );
863 mWarningLabel =
new QWidget();
864 QHBoxLayout *warningLayout =
new QHBoxLayout();
865 warningLayout->setMargin( 0 );
866 warningLayout->setContentsMargins( 0, 0, 0, 0 );
867 QLabel *warning =
new QLabel();
869 const int size =
static_cast< int >( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
870 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
871 warning->setToolTip( tr(
"Distance is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
872 warningLayout->insertSpacing( 0, labelMargin / 2 );
873 warningLayout->insertWidget( 1, warning );
874 mWarningLabel->setLayout( warningLayout );
875 layout->insertWidget( 4, mWarningLabel );
879 QWidget *w =
new QWidget();
880 layout->setMargin( 0 );
881 layout->setContentsMargins( 0, 0, 0, 0 );
882 w->setLayout( layout );
894 void QgsProcessingDistanceWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
896 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
903 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterDistance *
>( parameterDefinition() )->parentParameterName() )
905 setUnitParameterValue( wrapper->parameterValue() );
908 setUnitParameterValue( wrapper->parameterValue() );
922 void QgsProcessingDistanceWidgetWrapper::setUnitParameterValue(
const QVariant &value )
928 std::unique_ptr< QgsProcessingContext > tmpContext;
929 if ( mProcessingContextGenerator )
930 context = mProcessingContextGenerator->processingContext();
934 tmpContext = qgis::make_unique< QgsProcessingContext >();
935 context = tmpContext.get();
957 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( units ) );
965 QVariant QgsProcessingDistanceWidgetWrapper::widgetValue()
const 967 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
968 if ( val.type() == QVariant::Double && mUnitsCombo && mUnitsCombo->isVisible() )
984 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
989 QString QgsProcessingScaleWidgetWrapper::parameterType()
const 996 return new QgsProcessingScaleWidgetWrapper( parameter, type );
999 QWidget *QgsProcessingScaleWidgetWrapper::createWidget()
1011 mScaleWidget->setAllowNull(
true );
1013 mScaleWidget->setMapCanvas( widgetContext().mapCanvas() );
1014 mScaleWidget->setShowCurrentScaleButton(
true );
1016 mScaleWidget->setToolTip( parameterDefinition()->toolTip() );
1019 emit widgetValueHasChanged(
this );
1021 return mScaleWidget;
1030 mScaleWidget->setMapCanvas( context.
mapCanvas() );
1035 QVariant QgsProcessingScaleWidgetWrapper::widgetValue()
const 1037 return mScaleWidget && !mScaleWidget->isNull() ? QVariant( mScaleWidget->scale() ) : QVariant();
1040 void QgsProcessingScaleWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1044 if ( mScaleWidget->allowNull() && !value.isValid() )
1045 mScaleWidget->setNull();
1049 mScaleWidget->setScale( v );
1065 QWidget *QgsProcessingRangeWidgetWrapper::createWidget()
1074 QHBoxLayout *layout =
new QHBoxLayout();
1079 mMinSpinBox->setExpressionsEnabled(
true );
1080 mMinSpinBox->setShowClearButton(
false );
1081 mMaxSpinBox->setExpressionsEnabled(
true );
1082 mMaxSpinBox->setShowClearButton(
false );
1084 QLabel *minLabel =
new QLabel( tr(
"Min" ) );
1085 layout->addWidget( minLabel );
1086 layout->addWidget( mMinSpinBox, 1 );
1088 QLabel *maxLabel =
new QLabel( tr(
"Max" ) );
1089 layout->addWidget( maxLabel );
1090 layout->addWidget( mMaxSpinBox, 1 );
1092 QWidget *w =
new QWidget();
1093 layout->setMargin( 0 );
1094 layout->setContentsMargins( 0, 0, 0, 0 );
1095 w->setLayout( layout );
1099 mMinSpinBox->setDecimals( 6 );
1100 mMaxSpinBox->setDecimals( 6 );
1104 mMinSpinBox->setDecimals( 0 );
1105 mMaxSpinBox->setDecimals( 0 );
1108 mMinSpinBox->setMinimum( -99999999.999999 );
1109 mMaxSpinBox->setMinimum( -99999999.999999 );
1110 mMinSpinBox->setMaximum( 99999999.999999 );
1111 mMaxSpinBox->setMaximum( 99999999.999999 );
1113 w->setToolTip( parameterDefinition()->toolTip() );
1115 connect( mMinSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
const double v )
1117 mBlockChangedSignal++;
1118 if ( v > mMaxSpinBox->value() )
1119 mMaxSpinBox->setValue( v );
1120 mBlockChangedSignal--;
1122 if ( !mBlockChangedSignal )
1123 emit widgetValueHasChanged(
this );
1125 connect( mMaxSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
const double v )
1127 mBlockChangedSignal++;
1128 if ( v < mMinSpinBox->value() )
1129 mMinSpinBox->setValue( v );
1130 mBlockChangedSignal--;
1132 if ( !mBlockChangedSignal )
1133 emit widgetValueHasChanged(
this );
1142 void QgsProcessingRangeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1148 mBlockChangedSignal++;
1149 mMinSpinBox->setValue( v.at( 0 ) );
1150 if ( v.count() >= 2 )
1151 mMaxSpinBox->setValue( v.at( 1 ) );
1152 mBlockChangedSignal--;
1154 if ( !mBlockChangedSignal )
1155 emit widgetValueHasChanged(
this );
1158 QVariant QgsProcessingRangeWidgetWrapper::widgetValue()
const 1160 return QStringLiteral(
"%1,%2" ).arg( mMinSpinBox->value() ).arg( mMaxSpinBox->value() );
1163 QStringList QgsProcessingRangeWidgetWrapper::compatibleParameterTypes()
const 1165 return QStringList()
1170 QStringList QgsProcessingRangeWidgetWrapper::compatibleOutputTypes()
const 1175 QList<int> QgsProcessingRangeWidgetWrapper::compatibleDataTypes()
const 1177 return QList< int >();
1180 QString QgsProcessingRangeWidgetWrapper::modelerExpressionFormatString()
const 1182 return tr(
"string as two comma delimited floats, e.g. '1,10'" );
1185 QString QgsProcessingRangeWidgetWrapper::parameterType()
const 1192 return new QgsProcessingRangeWidgetWrapper( parameter, type );
1207 QWidget *QgsProcessingMatrixWidgetWrapper::createWidget()
1209 mMatrixWidget =
new QgsProcessingMatrixParameterPanel(
nullptr, dynamic_cast< const QgsProcessingParameterMatrix *>( parameterDefinition() ) );
1210 mMatrixWidget->setToolTip( parameterDefinition()->toolTip() );
1212 connect( mMatrixWidget, &QgsProcessingMatrixParameterPanel::changed,
this, [ = ]
1214 emit widgetValueHasChanged(
this );
1223 return mMatrixWidget;
1229 void QgsProcessingMatrixWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1232 if ( mMatrixWidget )
1233 mMatrixWidget->setValue( v );
1236 QVariant QgsProcessingMatrixWidgetWrapper::widgetValue()
const 1238 if ( mMatrixWidget )
1239 return mMatrixWidget->value().isEmpty() ? QVariant() : mMatrixWidget->value();
1244 QStringList QgsProcessingMatrixWidgetWrapper::compatibleParameterTypes()
const 1246 return QStringList()
1250 QStringList QgsProcessingMatrixWidgetWrapper::compatibleOutputTypes()
const 1252 return QStringList();
1255 QList<int> QgsProcessingMatrixWidgetWrapper::compatibleDataTypes()
const 1257 return QList< int >();
1260 QString QgsProcessingMatrixWidgetWrapper::modelerExpressionFormatString()
const 1262 return tr(
"comma delimited string of values, or an array of values" );
1265 QString QgsProcessingMatrixWidgetWrapper::parameterType()
const 1272 return new QgsProcessingMatrixWidgetWrapper( parameter, type );
1286 QVBoxLayout *vlayout =
new QVBoxLayout();
1287 vlayout->setMargin( 0 );
1288 vlayout->setContentsMargins( 0, 0, 0, 0 );
1290 vlayout->addWidget(
new QLabel( tr(
"Type" ) ) );
1292 mTypeComboBox =
new QComboBox();
1296 mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( fileParam->behavior() ) );
1298 mTypeComboBox->setCurrentIndex( 0 );
1299 vlayout->addWidget( mTypeComboBox );
1301 vlayout->addWidget(
new QLabel( tr(
"File filter" ) ) );
1303 mFilterComboBox =
new QComboBox();
1304 mFilterComboBox->setEditable(
true );
1306 mFilterComboBox->addItem( tr(
"All Files (*.*)" ) );
1307 mFilterComboBox->addItem( tr(
"CSV Files (*.csv)" ) );
1308 mFilterComboBox->addItem( tr(
"HTML Files (*.html *.htm)" ) );
1309 mFilterComboBox->addItem( tr(
"Text Files (*.txt)" ) );
1311 mFilterComboBox->setCurrentText( fileParam->fileFilter() );
1313 mFilterComboBox->setCurrentIndex( 0 );
1314 vlayout->addWidget( mFilterComboBox );
1316 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
1319 mDefaultFileWidget->lineEdit()->setShowClearButton(
true );
1323 mDefaultFileWidget->setFilePath( fileParam->defaultValue().toString() );
1327 vlayout->addWidget( mDefaultFileWidget );
1329 connect( mTypeComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
this, [ = ]
1335 mFilterComboBox->setEnabled( static_cast< QgsProcessingParameterFile::Behavior >( mTypeComboBox->currentData().toInt() ) ==
QgsProcessingParameterFile::File );
1338 setLayout( vlayout );
1341 QgsProcessingParameterDefinition *QgsProcessingFileParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const 1343 auto param = qgis::make_unique< QgsProcessingParameterFile >( name, description );
1344 param->setBehavior( static_cast< QgsProcessingParameterFile::Behavior>( mTypeComboBox->currentData().toInt() ) );
1346 param->setFileFilter( mFilterComboBox->currentText() );
1347 if ( !mDefaultFileWidget->filePath().isEmpty() )
1349 param->setFlags( flags );
1350 return param.release();
1360 QWidget *QgsProcessingFileWidgetWrapper::createWidget()
1370 mFileWidget->setToolTip( parameterDefinition()->toolTip() );
1371 mFileWidget->setDialogTitle( parameterDefinition()->description() );
1373 mFileWidget->setDefaultRoot(
QgsSettings().value( QStringLiteral(
"/Processing/LastInputPath" ), QDir::homePath() ).toString() );
1380 mFileWidget->setFilter( fileParam->
fileFilter() );
1381 else if ( !fileParam->
extension().isEmpty() )
1382 mFileWidget->setFilter( tr(
"%1 files" ).arg( fileParam->
extension().toUpper() ) + QStringLiteral(
" (*." ) + fileParam->
extension().toLower() +
')' );
1392 QgsSettings().
setValue( QStringLiteral(
"/Processing/LastInputPath" ), QFileInfo( path ).canonicalPath() );
1393 emit widgetValueHasChanged(
this );
1401 void QgsProcessingFileWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1405 mFileWidget->setFilePath( v );
1408 QVariant QgsProcessingFileWidgetWrapper::widgetValue()
const 1411 return mFileWidget->filePath();
1416 QStringList QgsProcessingFileWidgetWrapper::compatibleParameterTypes()
const 1418 return QStringList()
1423 QStringList QgsProcessingFileWidgetWrapper::compatibleOutputTypes()
const 1432 QList<int> QgsProcessingFileWidgetWrapper::compatibleDataTypes()
const 1434 return QList< int >();
1437 QString QgsProcessingFileWidgetWrapper::modelerExpressionFormatString()
const 1439 return tr(
"string representing a path to a file or folder" );
1442 QString QgsProcessingFileWidgetWrapper::parameterType()
const 1449 return new QgsProcessingFileWidgetWrapper( parameter, type );
1454 return new QgsProcessingFileParameterDefinitionWidget( context, widgetContext, definition, algorithm );
1470 QWidget *QgsProcessingExpressionWidgetWrapper::createWidget()
1482 mExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
1483 mExpLineEdit->setExpressionDialogTitle( parameterDefinition()->description() );
1484 mExpLineEdit->registerExpressionContextGenerator(
this );
1487 emit widgetValueHasChanged(
this );
1489 return mExpLineEdit;
1494 mFieldExpWidget->setToolTip( parameterDefinition()->toolTip() );
1495 mFieldExpWidget->setExpressionDialogTitle( parameterDefinition()->description() );
1496 mFieldExpWidget->registerExpressionContextGenerator(
this );
1499 emit widgetValueHasChanged(
this );
1501 return mFieldExpWidget;
1508 void QgsProcessingExpressionWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1518 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterExpression *
>( parameterDefinition() )->parentLayerParameterName() )
1520 setParentLayerWrapperValue( wrapper );
1523 setParentLayerWrapperValue( wrapper );
1540 std::unique_ptr< QgsProcessingContext > tmpContext;
1541 if ( mProcessingContextGenerator )
1542 context = mProcessingContextGenerator->processingContext();
1546 tmpContext = qgis::make_unique< QgsProcessingContext >();
1547 context = tmpContext.get();
1553 if ( mFieldExpWidget )
1554 mFieldExpWidget->setLayer(
nullptr );
1555 else if ( mExpLineEdit )
1556 mExpLineEdit->setLayer(
nullptr );
1562 std::unique_ptr< QgsMapLayer > ownedLayer( context->takeResultLayer( layer->
id() ) );
1565 mParentLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
1566 layer = mParentLayer.get();
1573 if ( mFieldExpWidget )
1574 mFieldExpWidget->setLayer( layer );
1575 else if ( mExpLineEdit )
1576 mExpLineEdit->setLayer( layer );
1579 void QgsProcessingExpressionWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1582 if ( mFieldExpWidget )
1583 mFieldExpWidget->setExpression( v );
1584 else if ( mExpLineEdit )
1585 mExpLineEdit->setExpression( v );
1588 QVariant QgsProcessingExpressionWidgetWrapper::widgetValue()
const 1590 if ( mFieldExpWidget )
1591 return mFieldExpWidget->expression();
1592 else if ( mExpLineEdit )
1593 return mExpLineEdit->expression();
1598 QStringList QgsProcessingExpressionWidgetWrapper::compatibleParameterTypes()
const 1600 return QStringList()
1608 QStringList QgsProcessingExpressionWidgetWrapper::compatibleOutputTypes()
const 1610 return QStringList()
1615 QList<int> QgsProcessingExpressionWidgetWrapper::compatibleDataTypes()
const 1617 return QList< int >();
1620 QString QgsProcessingExpressionWidgetWrapper::modelerExpressionFormatString()
const 1622 return tr(
"string representation of an expression" );
1625 const QgsVectorLayer *QgsProcessingExpressionWidgetWrapper::linkedVectorLayer()
const 1627 if ( mFieldExpWidget && mFieldExpWidget->layer() )
1628 return mFieldExpWidget->layer();
1633 QString QgsProcessingExpressionWidgetWrapper::parameterType()
const 1640 return new QgsProcessingExpressionWidgetWrapper( parameter, type );
1653 QHBoxLayout *hl =
new QHBoxLayout();
1655 hl->setContentsMargins( 0, 0, 0, 0 );
1657 mLineEdit =
new QLineEdit();
1658 mLineEdit->setEnabled(
false );
1659 hl->addWidget( mLineEdit, 1 );
1661 mToolButton =
new QToolButton();
1662 mToolButton->setText( QStringLiteral(
"…" ) );
1663 hl->addWidget( mToolButton );
1669 mLineEdit->setText( tr(
"%1 options selected" ).arg( 0 ) );
1672 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingEnumPanelWidget::showDialog );
1675 void QgsProcessingEnumPanelWidget::setValue(
const QVariant &value )
1677 if ( value.isValid() )
1678 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
1682 updateSummaryText();
1686 void QgsProcessingEnumPanelWidget::showDialog()
1688 QVariantList availableOptions;
1691 availableOptions.reserve( mParam->options().size() );
1692 for (
int i = 0; i < mParam->options().count(); ++i )
1693 availableOptions << i;
1696 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this,
nullptr );
1697 const QStringList options = mParam ? mParam->options() : QStringList();
1698 dlg.setValueFormatter( [options](
const QVariant & v ) -> QString
1700 const int i = v.toInt();
1701 return options.size() > i ? options.at( i ) : QString();
1705 setValue( dlg.selectedOptions() );
1709 void QgsProcessingEnumPanelWidget::updateSummaryText()
1712 mLineEdit->setText( tr(
"%1 options selected" ).arg( mValue.count() ) );
1719 QgsProcessingEnumCheckboxPanelWidget::QgsProcessingEnumCheckboxPanelWidget( QWidget *parent,
const QgsProcessingParameterEnum *param,
int columns )
1722 , mButtonGroup( new QButtonGroup( this ) )
1723 , mColumns( columns )
1725 mButtonGroup->setExclusive( !mParam->allowMultiple() );
1727 QGridLayout *l =
new QGridLayout();
1728 l->setContentsMargins( 0, 0, 0, 0 );
1731 int rows =
static_cast< int >( std::ceil( mParam->options().count() /
static_cast< double >( mColumns ) ) );
1732 for (
int i = 0; i < mParam->options().count(); ++i )
1734 QAbstractButton *button =
nullptr;
1735 if ( mParam->allowMultiple() )
1736 button =
new QCheckBox( mParam->options().at( i ) );
1738 button =
new QRadioButton( mParam->options().at( i ) );
1740 connect( button, &QAbstractButton::toggled,
this, [ = ]
1742 if ( !mBlockChangedSignal )
1746 mButtons.insert( i, button );
1747 mButtonGroup->addButton( button, i );
1748 l->addWidget( button, i % rows, i / rows );
1750 l->addItem(
new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, mColumns );
1753 if ( mParam->allowMultiple() )
1755 setContextMenuPolicy( Qt::CustomContextMenu );
1756 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsProcessingEnumCheckboxPanelWidget::showPopupMenu );
1760 QVariant QgsProcessingEnumCheckboxPanelWidget::value()
const 1762 if ( mParam->allowMultiple() )
1765 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
1767 if ( it.value()->isChecked() )
1768 value.append( it.key() );
1774 return mButtonGroup->checkedId() >= 0 ? mButtonGroup->checkedId() : QVariant();
1778 void QgsProcessingEnumCheckboxPanelWidget::setValue(
const QVariant &value )
1780 mBlockChangedSignal =
true;
1781 if ( mParam->allowMultiple() )
1783 QVariantList selected;
1784 if ( value.isValid() )
1785 selected = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
1786 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
1788 it.value()->setChecked( selected.contains( it.key() ) );
1794 if ( v.type() == QVariant::List )
1795 v = v.toList().value( 0 );
1796 if ( mButtons.contains( v ) )
1797 mButtons.value( v )->setChecked(
true );
1799 mBlockChangedSignal =
false;
1803 void QgsProcessingEnumCheckboxPanelWidget::showPopupMenu()
1806 QAction *selectAllAction =
new QAction( tr(
"Select All" ), &popupMenu );
1807 connect( selectAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::selectAll );
1808 QAction *clearAllAction =
new QAction( tr(
"Clear Selection" ), &popupMenu );
1809 connect( clearAllAction, &QAction::triggered,
this, &QgsProcessingEnumCheckboxPanelWidget::deselectAll );
1810 popupMenu.addAction( selectAllAction );
1811 popupMenu.addAction( clearAllAction );
1812 popupMenu.exec( QCursor::pos() );
1815 void QgsProcessingEnumCheckboxPanelWidget::selectAll()
1817 mBlockChangedSignal =
true;
1818 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
1819 it.value()->setChecked(
true );
1820 mBlockChangedSignal =
false;
1824 void QgsProcessingEnumCheckboxPanelWidget::deselectAll()
1826 mBlockChangedSignal =
true;
1827 for (
auto it = mButtons.constBegin(); it != mButtons.constEnd(); ++it )
1828 it.value()->setChecked(
false );
1829 mBlockChangedSignal =
false;
1844 QWidget *QgsProcessingEnumWidgetWrapper::createWidget()
1852 if ( expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"useCheckBoxes" ),
false ).toBool() )
1854 const int columns = expParam->
metadata().value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"columns" ), 2 ).toInt();
1855 mCheckboxPanel =
new QgsProcessingEnumCheckboxPanelWidget(
nullptr, expParam, columns );
1856 mCheckboxPanel->setToolTip( parameterDefinition()->toolTip() );
1857 connect( mCheckboxPanel, &QgsProcessingEnumCheckboxPanelWidget::changed,
this, [ = ]
1859 emit widgetValueHasChanged(
this );
1861 return mCheckboxPanel;
1870 mPanel =
new QgsProcessingEnumPanelWidget(
nullptr, expParam );
1871 mPanel->setToolTip( parameterDefinition()->toolTip() );
1872 connect( mPanel, &QgsProcessingEnumPanelWidget::changed,
this, [ = ]
1874 emit widgetValueHasChanged(
this );
1880 mComboBox =
new QComboBox();
1883 mComboBox->addItem( tr(
"[Not selected]" ), QVariant() );
1884 const QStringList options = expParam->
options();
1885 for (
int i = 0; i < options.count(); ++i )
1886 mComboBox->addItem( options.at( i ), i );
1888 mComboBox->setToolTip( parameterDefinition()->toolTip() );
1889 connect( mComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
1891 emit widgetValueHasChanged(
this );
1900 void QgsProcessingEnumWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
1904 if ( !value.isValid() )
1905 mComboBox->setCurrentIndex( mComboBox->findData( QVariant() ) );
1909 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
1912 else if ( mPanel || mCheckboxPanel )
1915 if ( value.isValid() )
1918 opts.reserve( v.size() );
1923 mPanel->setValue( opts );
1924 else if ( mCheckboxPanel )
1925 mCheckboxPanel->setValue( opts );
1929 QVariant QgsProcessingEnumWidgetWrapper::widgetValue()
const 1932 return mComboBox->currentData();
1934 return mPanel->value();
1935 else if ( mCheckboxPanel )
1936 return mCheckboxPanel->value();
1941 QStringList QgsProcessingEnumWidgetWrapper::compatibleParameterTypes()
const 1943 return QStringList()
1949 QStringList QgsProcessingEnumWidgetWrapper::compatibleOutputTypes()
const 1951 return QStringList()
1956 QList<int> QgsProcessingEnumWidgetWrapper::compatibleDataTypes()
const 1958 return QList<int>();
1961 QString QgsProcessingEnumWidgetWrapper::modelerExpressionFormatString()
const 1963 return tr(
"selected option index (starting from 0), array of indices, or comma separated string of options (e.g. '1,3')" );
1966 QString QgsProcessingEnumWidgetWrapper::parameterType()
const 1973 return new QgsProcessingEnumWidgetWrapper( parameter, type );
1986 QWidget *QgsProcessingLayoutWidgetWrapper::createWidget()
1995 mComboBox =
new QgsLayoutComboBox(
nullptr, widgetContext().project() ? widgetContext().project()->layoutManager() :
nullptr );
1997 mComboBox->setAllowEmptyLayout(
true );
2000 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2003 emit widgetValueHasChanged(
this );
2010 mLineEdit =
new QLineEdit();
2011 mLineEdit->setToolTip( tr(
"Name of an existing print layout" ) );
2012 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
2014 emit widgetValueHasChanged(
this );
2022 void QgsProcessingLayoutWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2026 if ( !value.isValid() )
2027 mComboBox->setCurrentLayout(
nullptr );
2031 mComboBox->setCurrentLayout( l );
2033 mComboBox->setCurrentLayout(
nullptr );
2036 else if ( mLineEdit )
2039 mLineEdit->setText( v );
2043 QVariant QgsProcessingLayoutWidgetWrapper::widgetValue()
const 2048 return l ? l->
name() : QVariant();
2050 else if ( mLineEdit )
2051 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
2056 QStringList QgsProcessingLayoutWidgetWrapper::compatibleParameterTypes()
const 2058 return QStringList()
2063 QStringList QgsProcessingLayoutWidgetWrapper::compatibleOutputTypes()
const 2065 return QStringList()
2069 QList<int> QgsProcessingLayoutWidgetWrapper::compatibleDataTypes()
const 2071 return QList<int>();
2074 QString QgsProcessingLayoutWidgetWrapper::modelerExpressionFormatString()
const 2076 return tr(
"string representing the name of an existing print layout" );
2079 QString QgsProcessingLayoutWidgetWrapper::parameterType()
const 2086 return new QgsProcessingLayoutWidgetWrapper( parameter, type );
2100 QVBoxLayout *vlayout =
new QVBoxLayout();
2101 vlayout->setMargin( 0 );
2102 vlayout->setContentsMargins( 0, 0, 0, 0 );
2104 vlayout->addWidget(
new QLabel( tr(
"Parent layout" ) ) );
2106 mParentLayoutComboBox =
new QComboBox();
2107 QString initialParent;
2109 initialParent = itemParam->parentLayoutParameterName();
2111 if ( widgetContext.
model() )
2114 const QMap<QString, QgsProcessingModelParameter> components = widgetContext.
model()->parameterComponents();
2115 for (
auto it = components.constBegin(); it != components.constEnd(); ++it )
2117 if (
const QgsProcessingParameterLayout *definition = dynamic_cast< const QgsProcessingParameterLayout * >( widgetContext.
model()->parameterDefinition( it.value().parameterName() ) ) )
2119 mParentLayoutComboBox-> addItem( definition->
description(), definition->
name() );
2120 if ( !initialParent.isEmpty() && initialParent == definition->
name() )
2122 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
2128 if ( mParentLayoutComboBox->count() == 0 && !initialParent.isEmpty() )
2131 mParentLayoutComboBox->addItem( initialParent, initialParent );
2132 mParentLayoutComboBox->setCurrentIndex( mParentLayoutComboBox->count() - 1 );
2135 vlayout->addWidget( mParentLayoutComboBox );
2136 setLayout( vlayout );
2138 QgsProcessingParameterDefinition *QgsProcessingLayoutItemParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const 2140 auto param = qgis::make_unique< QgsProcessingParameterLayoutItem >( name, description, QVariant(), mParentLayoutComboBox->currentData().toString() );
2142 return param.release();
2152 QWidget *QgsProcessingLayoutItemWidgetWrapper::createWidget()
2163 mComboBox->setAllowEmptyItem(
true );
2164 if ( layoutParam->
itemType() >= 0 )
2165 mComboBox->setItemType( static_cast< QgsLayoutItemRegistry::ItemType >( layoutParam->
itemType() ) );
2167 mComboBox->setToolTip( parameterDefinition()->toolTip() );
2170 emit widgetValueHasChanged(
this );
2177 mLineEdit =
new QLineEdit();
2178 mLineEdit->setToolTip( tr(
"UUID or ID of an existing print layout item" ) );
2179 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
2181 emit widgetValueHasChanged(
this );
2189 void QgsProcessingLayoutItemWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
2198 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterLayoutItem *
>( parameterDefinition() )->parentLayoutParameterName() )
2200 setLayoutParameterValue( wrapper->parameterValue() );
2203 setLayoutParameterValue( wrapper->parameterValue() );
2216 void QgsProcessingLayoutItemWidgetWrapper::setLayoutParameterValue(
const QVariant &value )
2222 std::unique_ptr< QgsProcessingContext > tmpContext;
2223 if ( mProcessingContextGenerator )
2224 context = mProcessingContextGenerator->processingContext();
2228 tmpContext = qgis::make_unique< QgsProcessingContext >();
2229 context = tmpContext.get();
2233 setLayout( layout );
2236 void QgsProcessingLayoutItemWidgetWrapper::setLayout(
QgsPrintLayout *layout )
2239 mComboBox->setCurrentLayout( layout );
2242 void QgsProcessingLayoutItemWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2246 if ( !value.isValid() )
2247 mComboBox->setItem(
nullptr );
2251 mComboBox->setItem( item );
2254 else if ( mLineEdit )
2257 mLineEdit->setText( v );
2261 QVariant QgsProcessingLayoutItemWidgetWrapper::widgetValue()
const 2266 return i ? i->
uuid() : QVariant();
2268 else if ( mLineEdit )
2269 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
2274 QStringList QgsProcessingLayoutItemWidgetWrapper::compatibleParameterTypes()
const 2276 return QStringList()
2281 QStringList QgsProcessingLayoutItemWidgetWrapper::compatibleOutputTypes()
const 2283 return QStringList()
2287 QList<int> QgsProcessingLayoutItemWidgetWrapper::compatibleDataTypes()
const 2289 return QList<int>();
2292 QString QgsProcessingLayoutItemWidgetWrapper::modelerExpressionFormatString()
const 2294 return tr(
"string representing the UUID or ID of an existing print layout item" );
2297 QString QgsProcessingLayoutItemWidgetWrapper::parameterType()
const 2304 return new QgsProcessingLayoutItemWidgetWrapper( parameter, type );
2309 return new QgsProcessingLayoutItemParameterDefinitionWidget( context, widgetContext, definition, algorithm );
2316 QgsProcessingPointMapTool::QgsProcessingPointMapTool(
QgsMapCanvas *canvas )
2323 QgsProcessingPointMapTool::~QgsProcessingPointMapTool() =
default;
2325 void QgsProcessingPointMapTool::deactivate()
2339 if ( e->button() == Qt::LeftButton )
2342 emit clicked( point );
2347 void QgsProcessingPointMapTool::keyPressEvent( QKeyEvent *e )
2349 if ( e->key() == Qt::Key_Escape )
2364 QgsProcessingPointPanel::QgsProcessingPointPanel( QWidget *parent )
2367 QHBoxLayout *l =
new QHBoxLayout();
2368 l->setContentsMargins( 0, 0, 0, 0 );
2371 mLineEdit->setShowClearButton(
false );
2372 l->addWidget( mLineEdit, 1 );
2373 mButton =
new QToolButton();
2374 mButton->setText( QStringLiteral(
"…" ) );
2375 l->addWidget( mButton );
2378 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsProcessingPointPanel::changed );
2379 connect( mButton, &QToolButton::clicked,
this, &QgsProcessingPointPanel::selectOnCanvas );
2380 mButton->setVisible(
false );
2383 void QgsProcessingPointPanel::setMapCanvas(
QgsMapCanvas *canvas )
2386 mButton->setVisible(
true );
2389 mTool = qgis::make_unique< QgsProcessingPointMapTool >( mCanvas );
2390 connect( mTool.get(), &QgsProcessingPointMapTool::clicked,
this, &QgsProcessingPointPanel::updatePoint );
2391 connect( mTool.get(), &QgsProcessingPointMapTool::complete,
this, &QgsProcessingPointPanel::pointPicked );
2394 void QgsProcessingPointPanel::setAllowNull(
bool allowNull )
2396 mLineEdit->setShowClearButton( allowNull );
2399 QVariant QgsProcessingPointPanel::value()
const 2401 return mLineEdit->showClearButton() && mLineEdit->text().trimmed().isEmpty() ? QVariant() : QVariant( mLineEdit->text() );
2404 void QgsProcessingPointPanel::clear()
2411 QString newText = QStringLiteral(
"%1,%2" )
2412 .arg( QString::number( point.
x(),
'f' ) )
2413 .arg( QString::number( point.
y(),
'f' ) );
2416 if ( mCrs.isValid() )
2418 newText += QStringLiteral(
" [%1]" ).arg( mCrs.authid() );
2420 mLineEdit->setText( newText );
2423 void QgsProcessingPointPanel::selectOnCanvas()
2428 mPrevTool = mCanvas->mapTool();
2429 mCanvas->setMapTool( mTool.get() );
2431 emit toggleDialogVisibility(
false );
2434 void QgsProcessingPointPanel::updatePoint(
const QgsPointXY &point )
2436 setValue( point, mCanvas->mapSettings().destinationCrs() );
2439 void QgsProcessingPointPanel::pointPicked()
2444 mCanvas->setMapTool( mPrevTool );
2446 emit toggleDialogVisibility(
true );
2462 QWidget *QgsProcessingPointWidgetWrapper::createWidget()
2470 mPanel =
new QgsProcessingPointPanel(
nullptr );
2471 if ( widgetContext().mapCanvas() )
2472 mPanel->setMapCanvas( widgetContext().mapCanvas() );
2475 mPanel->setAllowNull(
true );
2477 mPanel->setToolTip( parameterDefinition()->toolTip() );
2479 connect( mPanel, &QgsProcessingPointPanel::changed,
this, [ = ]
2481 emit widgetValueHasChanged(
this );
2485 setDialog( mDialog );
2491 mLineEdit =
new QLineEdit();
2492 mLineEdit->setToolTip( tr(
"Point as 'x,y'" ) );
2493 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString & )
2495 emit widgetValueHasChanged(
this );
2507 mPanel->setMapCanvas( context.
mapCanvas() );
2510 void QgsProcessingPointWidgetWrapper::setDialog( QDialog *dialog )
2515 connect( mPanel, &QgsProcessingPointPanel::toggleDialogVisibility, mDialog, [ = ](
bool visible )
2518 mDialog->showMinimized();
2521 mDialog->showNormal();
2523 mDialog->activateWindow();
2530 void QgsProcessingPointWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2534 if ( !value.isValid() || ( value.type() == QVariant::String && value.toString().isEmpty() ) )
2540 mPanel->setValue( p, crs );
2543 else if ( mLineEdit )
2546 mLineEdit->setText( v );
2550 QVariant QgsProcessingPointWidgetWrapper::widgetValue()
const 2554 return mPanel->value();
2556 else if ( mLineEdit )
2557 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
2562 QStringList QgsProcessingPointWidgetWrapper::compatibleParameterTypes()
const 2564 return QStringList()
2569 QStringList QgsProcessingPointWidgetWrapper::compatibleOutputTypes()
const 2571 return QStringList()
2575 QList<int> QgsProcessingPointWidgetWrapper::compatibleDataTypes()
const 2577 return QList<int>();
2580 QString QgsProcessingPointWidgetWrapper::modelerExpressionFormatString()
const 2582 return tr(
"string of the format 'x,y' or a geometry value (centroid is used)" );
2585 QString QgsProcessingPointWidgetWrapper::parameterType()
const 2592 return new QgsProcessingPointWidgetWrapper( parameter, type );
2606 QVBoxLayout *vlayout =
new QVBoxLayout();
2607 vlayout->setMargin( 0 );
2608 vlayout->setContentsMargins( 0, 0, 0, 0 );
2610 vlayout->addWidget(
new QLabel( tr(
"Default value" ) ) );
2613 mDefaultColorButton->setShowNull(
true );
2614 mAllowOpacity =
new QCheckBox( tr(
"Allow opacity control" ) );
2620 mDefaultColorButton->setToNull();
2622 mDefaultColorButton->setColor( c );
2623 mAllowOpacity->setChecked( colorParam->opacityEnabled() );
2627 mDefaultColorButton->setToNull();
2628 mAllowOpacity->setChecked(
true );
2631 vlayout->addWidget( mDefaultColorButton );
2632 vlayout->addWidget( mAllowOpacity );
2633 setLayout( vlayout );
2636 QgsProcessingParameterDefinition *QgsProcessingColorParameterDefinitionWidget::createParameter(
const QString &name,
const QString &description, QgsProcessingParameterDefinition::Flags flags )
const 2638 auto param = qgis::make_unique< QgsProcessingParameterColor >( name, description, mDefaultColorButton->color(), mAllowOpacity->isChecked() );
2640 return param.release();
2649 QWidget *QgsProcessingColorWidgetWrapper::createWidget()
2659 mColorButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
2662 mColorButton->setShowNull(
true );
2665 mColorButton->setToolTip( parameterDefinition()->toolTip() );
2666 mColorButton->setColorDialogTitle( parameterDefinition()->description() );
2667 if ( colorParam->
defaultValue().value< QColor >().isValid() )
2669 mColorButton->setDefaultColor( colorParam->
defaultValue().value< QColor >() );
2674 emit widgetValueHasChanged(
this );
2677 return mColorButton;
2683 void QgsProcessingColorWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
2687 if ( !value.isValid() ||
2688 ( value.type() == QVariant::String && value.toString().isEmpty() )
2689 || ( value.type() == QVariant::Color && !value.value< QColor >().isValid() ) )
2690 mColorButton->setToNull();
2694 if ( !c.isValid() && mColorButton->showNull() )
2695 mColorButton->setToNull();
2697 mColorButton->setColor( c );
2702 QVariant QgsProcessingColorWidgetWrapper::widgetValue()
const 2705 return mColorButton->isNull() ? QVariant() : mColorButton->color();
2710 QStringList QgsProcessingColorWidgetWrapper::compatibleParameterTypes()
const 2712 return QStringList()
2717 QStringList QgsProcessingColorWidgetWrapper::compatibleOutputTypes()
const 2719 return QStringList()
2723 QList<int> QgsProcessingColorWidgetWrapper::compatibleDataTypes()
const 2725 return QList<int>();
2728 QString QgsProcessingColorWidgetWrapper::modelerExpressionFormatString()
const 2730 return tr(
"color style string, e.g. #ff0000 or 255,0,0" );
2733 QString QgsProcessingColorWidgetWrapper::parameterType()
const 2740 return new QgsProcessingColorWidgetWrapper( parameter, type );
2745 return new QgsProcessingColorParameterDefinitionWidget( context, widgetContext, definition, algorithm );
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value...
A boolean parameter for processing algorithms.
int itemType() const
Returns the acceptable item type, or -1 if any item type is allowed.
static QString typeName()
Returns the type name for the parameter class.
An input file or folder parameter for processing algorithms.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
static QString typeName()
Returns the type name for the parameter class.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
Base class for graphical items within a QgsLayout.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
static QString typeName()
Returns the type name for the output class.
void layoutChanged(QgsMasterLayoutInterface *layout)
Emitted whenever the currently selected layout changes.
This class is a composition of two QSettings instances:
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap metadata() const
Returns the parameter's freeform metadata.
static QString typeName()
Returns the type name for the parameter class.
static QList< int > parameterAsEnums(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of enum values.
A print layout parameter, allowing users to select a print layout.
WidgetType
Types of dialogs which Processing widgets can be created for.
A class to represent a 2D point.
A color parameter for processing algorithms.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
An expression 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.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value...
static QString typeName()
Returns the type name for the parameter class.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
double minimum() const
Returns the minimum value acceptable by the parameter.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
static QString typeName()
Returns the type name for the parameter class.
bool allowMultiple() const
Returns true if the parameter allows multiple selected values.
void setFlags(Flags flags)
Sets the flags associated with the parameter.
QgsUnitTypes::DistanceUnit mapUnits
QgsUnitTypes::DistanceUnit defaultUnit() const
Returns the default distance 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.
const QgsCoordinateReferenceSystem & crs
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the output class.
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
Abstract base class for processing algorithms.
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
Map canvas is a class for displaying all GIS data types on a canvas.
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
static QString typeName()
Returns the type name for the parameter class.
A numeric range parameter for processing algorithms.
A double numeric parameter for map scale values.
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
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set...
The QgsLayoutItemComboBox class is a combo box which displays items of a matching type from a layout...
QString fileFilter() const
Returns the file filter string for file destinations compatible with this parameter.
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value. ...
static QString typeName()
Returns the type name for the parameter class.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
An enum based parameter for processing algorithms, allowing for selection from predefined values...
Flags flags() const
Returns any flags associated with the parameter.
static QString typeName()
Returns the type name for the parameter class.
bool opacityEnabled() const
Returns true if the parameter allows opacity control.
QVariant defaultValue() const
Returns the default value for the parameter.
A double numeric parameter for distance values.
static QString typeName()
Returns the type name for the output class.
Parameter is a single file.
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
Degrees, for planar geographic CRS distance measurements.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
void setDefaultValue(const QVariant &value)
Sets the default value for the parameter.
static QString typeName()
Returns the type name for the output class.
QStringList options() const
Returns the list of acceptable options for the parameter.
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 output class.
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
A numeric parameter for processing algorithms.
void itemChanged(QgsLayoutItem *item)
Emitted whenever the currently selected item changes.
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
QString name() const
Returns the name of the parameter.
void expressionChanged(const QString &expression)
Emitted when the expression is changed.
Behavior behavior() const
Returns the parameter behavior (e.g.
DistanceUnit
Units of distance.
static Q_INVOKABLE DistanceUnitType unitType(QgsUnitTypes::DistanceUnit unit)
Returns the type for a distance unit.
QString extension() const
Returns any specified file extension for the parameter.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
void selectedConfigIdChanged(const QString &authcfg)
Emitted when authentication config is changed or missing.
QgsPointLocator::Match mapPointMatch() const
Returns the matching data from the most recently snapped point.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingModelAlgorithm * model() const
Returns the model which the parameter widget is associated with.
A point parameter for processing algorithms.
Contains settings which reflect the context in which a Processing parameter widget is shown...
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to 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...
The QgsExpressionLineEdit widget includes a line edit for entering expressions together with a button...
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places...
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the parameter class.
virtual QString uuid() const
Returns the item identification string.
This class represents a coordinate reference system (CRS).
Base class for the definition of processing parameters.
Class that shows snapping marker on map canvas for the current snapping match.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
virtual QString name() const =0
Returns the layout's name.
static int parameterAsInt(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static integer value.
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
Behavior
Parameter behavior.
Type dataType() const
Returns the acceptable data type for the parameter.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Interface for master layout type objects, such as print layouts and reports.
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
QgsPointXY snapPoint()
snapPoint will snap the points using the map canvas snapping utils configuration
Represents a vector layer which manages a vector based data sets.
Contains information about the context in which a processing algorithm is executed.
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 ...
A string parameter for processing algorithms.
The QgsLayoutComboBox class is a combo box which displays available layouts from a QgsLayoutManager...
QString description() const
Returns the description for the parameter.
static QString typeName()
Returns the type name for the output class.
QgsProcessingParameterNumber::Type dataType() const
Returns the acceptable data type for the range.
Unit is a standard measurement unit.
static QString typeName()
Returns the type name for the parameter class.
double maximum() const
Returns the maximum value acceptable by the parameter.
static QString typeName()
Returns the type name for the parameter class.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Standard algorithm dialog.