27 #include <QHBoxLayout> 31 #include <QPlainTextEdit> 45 QWidget *QgsProcessingBooleanWidgetWrapper::createWidget()
51 QString description = parameterDefinition()->description();
53 description = QObject::tr(
"%1 [optional]" ).arg( description );
55 mCheckBox =
new QCheckBox( description );
56 mCheckBox->setToolTip( parameterDefinition()->toolTip() );
58 connect( mCheckBox, &QCheckBox::toggled,
this, [ = ]
60 emit widgetValueHasChanged(
this );
68 mComboBox =
new QComboBox();
69 mComboBox->addItem( tr(
"Yes" ),
true );
70 mComboBox->addItem( tr(
"No" ),
false );
71 mComboBox->setToolTip( parameterDefinition()->toolTip() );
73 connect( mComboBox, qgis::overload< int>::of( &QComboBox::currentIndexChanged ),
this, [ = ]
75 emit widgetValueHasChanged(
this );
84 QLabel *QgsProcessingBooleanWidgetWrapper::createLabel()
93 void QgsProcessingBooleanWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
100 mCheckBox->setChecked( v );
108 mComboBox->setCurrentIndex( mComboBox->findData( v ) );
114 QVariant QgsProcessingBooleanWidgetWrapper::widgetValue()
const 119 return mCheckBox->isChecked();
123 return mComboBox->currentData();
128 QStringList QgsProcessingBooleanWidgetWrapper::compatibleParameterTypes()
const 144 QStringList QgsProcessingBooleanWidgetWrapper::compatibleOutputTypes()
const 154 QList<int> QgsProcessingBooleanWidgetWrapper::compatibleDataTypes()
const 156 return QList< int >();
159 QString QgsProcessingBooleanWidgetWrapper::parameterType()
const 166 return new QgsProcessingBooleanWidgetWrapper( parameter, type );
180 QWidget *QgsProcessingCrsWidgetWrapper::createWidget()
183 mProjectionSelectionWidget->setToolTip( parameterDefinition()->toolTip() );
192 emit widgetValueHasChanged(
this );
200 return mProjectionSelectionWidget;
205 QWidget *w =
new QWidget();
206 w->setToolTip( parameterDefinition()->toolTip() );
208 QVBoxLayout *vl =
new QVBoxLayout();
210 vl->setContentsMargins( 0, 0, 0, 0 );
213 mUseProjectCrsCheckBox =
new QCheckBox( tr(
"Use project CRS" ) );
214 mUseProjectCrsCheckBox->setToolTip( tr(
"Always use the current project CRS when running the model" ) );
215 vl->addWidget( mUseProjectCrsCheckBox );
216 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, mProjectionSelectionWidget, &QgsProjectionSelectionWidget::setDisabled );
217 connect( mUseProjectCrsCheckBox, &QCheckBox::toggled,
this, [ = ]
219 emit widgetValueHasChanged(
this );
222 vl->addWidget( mProjectionSelectionWidget );
230 void QgsProcessingCrsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
232 if ( mUseProjectCrsCheckBox )
234 if ( value.toString().compare( QLatin1String(
"ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
236 mUseProjectCrsCheckBox->setChecked(
true );
241 mUseProjectCrsCheckBox->setChecked(
false );
246 if ( mProjectionSelectionWidget )
247 mProjectionSelectionWidget->setCrs( v );
250 QVariant QgsProcessingCrsWidgetWrapper::widgetValue()
const 252 if ( mUseProjectCrsCheckBox && mUseProjectCrsCheckBox->isChecked() )
253 return QStringLiteral(
"ProjectCrs" );
254 else if ( mProjectionSelectionWidget )
255 return mProjectionSelectionWidget->crs().isValid() ? mProjectionSelectionWidget->crs() : QVariant();
260 QStringList QgsProcessingCrsWidgetWrapper::compatibleParameterTypes()
const 271 QStringList QgsProcessingCrsWidgetWrapper::compatibleOutputTypes()
const 279 QList<int> QgsProcessingCrsWidgetWrapper::compatibleDataTypes()
const 281 return QList< int >();
284 QString QgsProcessingCrsWidgetWrapper::modelerExpressionFormatString()
const 286 return tr(
"string as EPSG code, WKT or PROJ format, or a string identifying a map layer" );
289 QString QgsProcessingCrsWidgetWrapper::parameterType()
const 296 return new QgsProcessingCrsWidgetWrapper( parameter, type );
311 QWidget *QgsProcessingStringWidgetWrapper::createWidget()
318 if ( static_cast< const QgsProcessingParameterString * >( parameterDefinition() )->multiLine() )
320 mPlainTextEdit =
new QPlainTextEdit();
321 mPlainTextEdit->setToolTip( parameterDefinition()->toolTip() );
323 connect( mPlainTextEdit, &QPlainTextEdit::textChanged,
this, [ = ]
325 emit widgetValueHasChanged(
this );
327 return mPlainTextEdit;
331 mLineEdit =
new QLineEdit();
332 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
334 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
336 emit widgetValueHasChanged(
this );
344 mLineEdit =
new QLineEdit();
345 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
347 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ]
349 emit widgetValueHasChanged(
this );
357 void QgsProcessingStringWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
361 mLineEdit->setText( v );
362 if ( mPlainTextEdit )
363 mPlainTextEdit->setPlainText( v );
366 QVariant QgsProcessingStringWidgetWrapper::widgetValue()
const 369 return mLineEdit->text();
370 else if ( mPlainTextEdit )
371 return mPlainTextEdit->toPlainText();
376 QStringList QgsProcessingStringWidgetWrapper::compatibleParameterTypes()
const 387 QStringList QgsProcessingStringWidgetWrapper::compatibleOutputTypes()
const 394 QList<int> QgsProcessingStringWidgetWrapper::compatibleDataTypes()
const 396 return QList< int >();
399 QString QgsProcessingStringWidgetWrapper::parameterType()
const 406 return new QgsProcessingStringWidgetWrapper( parameter, type );
421 QWidget *QgsProcessingNumericWidgetWrapper::createWidget()
424 const QVariantMap metadata = numberDef->
metadata();
425 const int decimals = metadata.value( QStringLiteral(
"widget_wrapper" ) ).toMap().value( QStringLiteral(
"decimals" ), 6 ).toInt();
433 QAbstractSpinBox *spinBox =
nullptr;
438 mDoubleSpinBox->setExpressionsEnabled(
true );
439 mDoubleSpinBox->setDecimals( decimals );
445 double singleStep = calculateStep( numberDef->
minimum(), numberDef->
maximum() );
446 singleStep = std::max( singleStep, std::pow( 10, -decimals ) );
447 mDoubleSpinBox->setSingleStep( singleStep );
450 spinBox = mDoubleSpinBox;
455 mSpinBox->setExpressionsEnabled(
true );
459 spinBox->setToolTip( parameterDefinition()->toolTip() );
461 double max = 999999999;
466 double min = -999999999;
471 if ( mDoubleSpinBox )
473 mDoubleSpinBox->setMinimum( min );
474 mDoubleSpinBox->setMaximum( max );
478 mSpinBox->setMinimum( static_cast< int >( min ) );
479 mSpinBox->setMaximum( static_cast< int >( max ) );
484 mAllowingNull =
true;
485 if ( mDoubleSpinBox )
487 mDoubleSpinBox->setShowClearButton(
true );
488 const double min = mDoubleSpinBox->minimum() - 1;
489 mDoubleSpinBox->setMinimum( min );
490 mDoubleSpinBox->setValue( min );
494 mSpinBox->setShowClearButton(
true );
495 const int min = mSpinBox->minimum() - 1;
496 mSpinBox->setMinimum( min );
497 mSpinBox->setValue( min );
499 spinBox->setSpecialValueText( tr(
"Not set" ) );
507 if ( mDoubleSpinBox )
509 double defaultVal = numberDef->
defaultValue().toDouble( &ok );
511 mDoubleSpinBox->setClearValue( defaultVal );
517 mSpinBox->setClearValue( intVal );
523 if ( mDoubleSpinBox )
524 mDoubleSpinBox->setClearValue( numberDef->
minimum() );
526 mSpinBox->setClearValue( static_cast< int >( numberDef->
minimum() ) );
531 if ( mDoubleSpinBox )
533 mDoubleSpinBox->setValue( 0 );
534 mDoubleSpinBox->setClearValue( 0 );
538 mSpinBox->setValue( 0 );
539 mSpinBox->setClearValue( 0 );
544 if ( mDoubleSpinBox )
545 connect( mDoubleSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
this, [ = ] { emit widgetValueHasChanged(
this ); } );
547 connect( mSpinBox, qgis::overload<int>::of( &QgsSpinBox::valueChanged ),
this, [ = ] { emit widgetValueHasChanged(
this ); } );
555 void QgsProcessingNumericWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
557 if ( mDoubleSpinBox )
559 if ( mAllowingNull && !value.isValid() )
560 mDoubleSpinBox->clear();
564 mDoubleSpinBox->setValue( v );
569 if ( mAllowingNull && !value.isValid() )
574 mSpinBox->setValue( v );
579 QVariant QgsProcessingNumericWidgetWrapper::widgetValue()
const 581 if ( mDoubleSpinBox )
583 if ( mAllowingNull &&
qgsDoubleNear( mDoubleSpinBox->value(), mDoubleSpinBox->minimum() ) )
586 return mDoubleSpinBox->value();
590 if ( mAllowingNull && mSpinBox->value() == mSpinBox->minimum() )
593 return mSpinBox->value();
599 QStringList QgsProcessingNumericWidgetWrapper::compatibleParameterTypes()
const 607 QStringList QgsProcessingNumericWidgetWrapper::compatibleOutputTypes()
const 613 QList<int> QgsProcessingNumericWidgetWrapper::compatibleDataTypes()
const 615 return QList< int >();
618 double QgsProcessingNumericWidgetWrapper::calculateStep(
const double minimum,
const double maximum )
620 const double valueRange = maximum - minimum;
621 if ( valueRange <= 1.0 )
623 const double step = valueRange / 10.0;
625 return qgsRound( step, -std::floor( std::log( step ) ) );
633 QString QgsProcessingNumericWidgetWrapper::parameterType()
const 640 return new QgsProcessingNumericWidgetWrapper( parameter, type );
648 : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
653 QString QgsProcessingDistanceWidgetWrapper::parameterType()
const 660 return new QgsProcessingDistanceWidgetWrapper( parameter, type );
663 QWidget *QgsProcessingDistanceWidgetWrapper::createWidget()
667 QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
672 mLabel =
new QLabel();
673 mUnitsCombo =
new QComboBox();
681 const int labelMargin =
static_cast< int >( std::round( mUnitsCombo->fontMetrics().width(
'X' ) ) );
682 QHBoxLayout *layout =
new QHBoxLayout();
683 layout->addWidget( spin, 1 );
684 layout->insertSpacing( 1, labelMargin / 2 );
685 layout->insertWidget( 2, mLabel );
686 layout->insertWidget( 3, mUnitsCombo );
691 mWarningLabel =
new QWidget();
692 QHBoxLayout *warningLayout =
new QHBoxLayout();
693 warningLayout->setMargin( 0 );
694 warningLayout->setContentsMargins( 0, 0, 0, 0 );
695 QLabel *warning =
new QLabel();
697 const int size =
static_cast< int >( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
698 warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
699 warning->setToolTip( tr(
"Distance is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
700 warningLayout->insertSpacing( 0, labelMargin / 2 );
701 warningLayout->insertWidget( 1, warning );
702 mWarningLabel->setLayout( warningLayout );
703 layout->insertWidget( 4, mWarningLabel );
707 QWidget *w =
new QWidget();
708 layout->setMargin( 0 );
709 layout->setContentsMargins( 0, 0, 0, 0 );
710 w->setLayout( layout );
722 void QgsProcessingDistanceWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
724 QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
731 if ( wrapper->parameterDefinition()->name() ==
static_cast< const QgsProcessingParameterDistance *
>( parameterDefinition() )->parentParameterName() )
733 setUnitParameterValue( wrapper->parameterValue() );
736 setUnitParameterValue( wrapper->parameterValue() );
750 void QgsProcessingDistanceWidgetWrapper::setUnitParameterValue(
const QVariant &value )
756 std::unique_ptr< QgsProcessingContext > tmpContext;
757 if ( mProcessingContextGenerator )
758 context = mProcessingContextGenerator->processingContext();
762 tmpContext = qgis::make_unique< QgsProcessingContext >();
763 context = tmpContext.get();
785 mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( units ) );
793 QVariant QgsProcessingDistanceWidgetWrapper::widgetValue()
const 795 const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
796 if ( val.type() == QVariant::Double && mUnitsCombo && mUnitsCombo->isVisible() )
818 QWidget *QgsProcessingRangeWidgetWrapper::createWidget()
827 QHBoxLayout *layout =
new QHBoxLayout();
832 mMinSpinBox->setExpressionsEnabled(
true );
833 mMinSpinBox->setShowClearButton(
false );
834 mMaxSpinBox->setExpressionsEnabled(
true );
835 mMaxSpinBox->setShowClearButton(
false );
837 QLabel *minLabel =
new QLabel( tr(
"Min" ) );
838 layout->addWidget( minLabel );
839 layout->addWidget( mMinSpinBox, 1 );
841 QLabel *maxLabel =
new QLabel( tr(
"Max" ) );
842 layout->addWidget( maxLabel );
843 layout->addWidget( mMaxSpinBox, 1 );
845 QWidget *w =
new QWidget();
846 layout->setMargin( 0 );
847 layout->setContentsMargins( 0, 0, 0, 0 );
848 w->setLayout( layout );
852 mMinSpinBox->setDecimals( 6 );
853 mMaxSpinBox->setDecimals( 6 );
857 mMinSpinBox->setDecimals( 0 );
858 mMaxSpinBox->setDecimals( 0 );
861 mMinSpinBox->setMinimum( -99999999.999999 );
862 mMaxSpinBox->setMinimum( -99999999.999999 );
863 mMinSpinBox->setMaximum( 99999999.999999 );
864 mMaxSpinBox->setMaximum( 99999999.999999 );
866 w->setToolTip( parameterDefinition()->toolTip() );
868 connect( mMinSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
const double v )
870 mBlockChangedSignal++;
871 if ( v > mMaxSpinBox->value() )
872 mMaxSpinBox->setValue( v );
873 mBlockChangedSignal--;
875 if ( !mBlockChangedSignal )
876 emit widgetValueHasChanged(
this );
878 connect( mMaxSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
const double v )
880 mBlockChangedSignal++;
881 if ( v < mMinSpinBox->value() )
882 mMinSpinBox->setValue( v );
883 mBlockChangedSignal--;
885 if ( !mBlockChangedSignal )
886 emit widgetValueHasChanged(
this );
895 void QgsProcessingRangeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
901 mBlockChangedSignal++;
902 mMinSpinBox->setValue( v.at( 0 ) );
903 if ( v.count() >= 2 )
904 mMaxSpinBox->setValue( v.at( 1 ) );
905 mBlockChangedSignal--;
907 if ( !mBlockChangedSignal )
908 emit widgetValueHasChanged(
this );
911 QVariant QgsProcessingRangeWidgetWrapper::widgetValue()
const 913 return QStringLiteral(
"%1,%2" ).arg( mMinSpinBox->value() ).arg( mMaxSpinBox->value() );
916 QStringList QgsProcessingRangeWidgetWrapper::compatibleParameterTypes()
const 923 QStringList QgsProcessingRangeWidgetWrapper::compatibleOutputTypes()
const 928 QList<int> QgsProcessingRangeWidgetWrapper::compatibleDataTypes()
const 930 return QList< int >();
933 QString QgsProcessingRangeWidgetWrapper::modelerExpressionFormatString()
const 935 return tr(
"string as two comma delimited floats, e.g. '1,10'" );
938 QString QgsProcessingRangeWidgetWrapper::parameterType()
const 945 return new QgsProcessingRangeWidgetWrapper( parameter, type );
960 QWidget *QgsProcessingMatrixWidgetWrapper::createWidget()
962 mMatrixWidget =
new QgsProcessingMatrixParameterPanel(
nullptr, dynamic_cast< const QgsProcessingParameterMatrix *>( parameterDefinition() ) );
963 mMatrixWidget->setToolTip( parameterDefinition()->toolTip() );
965 connect( mMatrixWidget, &QgsProcessingMatrixParameterPanel::changed,
this, [ = ]
967 emit widgetValueHasChanged(
this );
976 return mMatrixWidget;
982 void QgsProcessingMatrixWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
986 mMatrixWidget->setValue( v );
989 QVariant QgsProcessingMatrixWidgetWrapper::widgetValue()
const 992 return mMatrixWidget->value().isEmpty() ? QVariant() : mMatrixWidget->value();
997 QStringList QgsProcessingMatrixWidgetWrapper::compatibleParameterTypes()
const 1003 QStringList QgsProcessingMatrixWidgetWrapper::compatibleOutputTypes()
const 1005 return QStringList();
1008 QList<int> QgsProcessingMatrixWidgetWrapper::compatibleDataTypes()
const 1010 return QList< int >();
1013 QString QgsProcessingMatrixWidgetWrapper::modelerExpressionFormatString()
const 1015 return tr(
"comma delimited string of values, or an array of values" );
1018 QString QgsProcessingMatrixWidgetWrapper::parameterType()
const 1025 return new QgsProcessingMatrixWidgetWrapper( parameter, type );
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...
static QString typeName()
Returns the type name for the parameter class.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
static QString typeName()
Returns the type name for the parameter class.
double maximum() const
Returns the maximum value acceptable by the parameter.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
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.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
WidgetType
Types of dialogs which Processing widgets can be created for.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
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.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
QgsUnitTypes::DistanceUnit mapUnits
static QString typeName()
Returns the type name for the parameter class.
Type dataType() const
Returns the acceptable data type for the parameter.
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.
QgsProcessingParameterNumber::Type dataType() const
Returns the acceptable data type for the range.
double minimum() const
Returns the minimum value acceptable by the parameter.
A numeric range 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.
static QString typeName()
Returns the type name for the parameter class.
Flags 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 output class.
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.
static QString typeName()
Returns the type name for the output class.
QgsUnitTypes::DistanceUnit defaultUnit() const
Returns the default distance unit for the parameter.
static QString typeName()
Returns the type name for the output class.
A numeric parameter for processing algorithms.
QVariantMap metadata() const
Returns the parameter's freeform metadata.
DistanceUnit
Units of distance.
static Q_INVOKABLE DistanceUnitType unitType(QgsUnitTypes::DistanceUnit unit)
Returns the type for a distance unit.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
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.
This class represents a coordinate reference system (CRS).
Base class for the definition of processing parameters.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
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.
QVariant defaultValue() const
Returns the default value for the parameter.
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
Contains information about the context in which a processing algorithm is executed.
static QString typeName()
Returns the type name for the output class.
Unit is a standard measurement unit.
Standard algorithm dialog.