QGIS API Documentation  3.6.0-Noosa (5873452)
qgsprocessingwidgetwrapperimpl.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprocessingwidgetwrapperimpl.cpp
3  ---------------------
4  begin : August 2018
5  copyright : (C) 2018 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
20 #include "qgsprocessingoutputs.h"
23 #include "qgsspinbox.h"
24 #include "qgsdoublespinbox.h"
25 #include "qgsprocessingcontext.h"
26 #include "qgsauthconfigselect.h"
27 #include "qgsapplication.h"
28 #include "qgsfilewidget.h"
29 #include "qgssettings.h"
30 #include "qgsexpressionlineedit.h"
32 #include <QLabel>
33 #include <QHBoxLayout>
34 #include <QCheckBox>
35 #include <QComboBox>
36 #include <QLineEdit>
37 #include <QPlainTextEdit>
38 
40 
41 //
42 // QgsProcessingBooleanWidgetWrapper
43 //
44 
45 QgsProcessingBooleanWidgetWrapper::QgsProcessingBooleanWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type, QWidget *parent )
46  : QgsAbstractProcessingParameterWidgetWrapper( parameter, type, parent )
47 {
48 
49 }
50 
51 QWidget *QgsProcessingBooleanWidgetWrapper::createWidget()
52 {
53  switch ( type() )
54  {
56  {
57  QString description = parameterDefinition()->description();
58  if ( parameterDefinition()->flags() & QgsProcessingParameterDefinition::FlagOptional )
59  description = QObject::tr( "%1 [optional]" ).arg( description );
60 
61  mCheckBox = new QCheckBox( description );
62  mCheckBox->setToolTip( parameterDefinition()->toolTip() );
63 
64  connect( mCheckBox, &QCheckBox::toggled, this, [ = ]
65  {
66  emit widgetValueHasChanged( this );
67  } );
68  return mCheckBox;
69  };
70 
73  {
74  mComboBox = new QComboBox();
75  mComboBox->addItem( tr( "Yes" ), true );
76  mComboBox->addItem( tr( "No" ), false );
77  mComboBox->setToolTip( parameterDefinition()->toolTip() );
78 
79  connect( mComboBox, qgis::overload< int>::of( &QComboBox::currentIndexChanged ), this, [ = ]
80  {
81  emit widgetValueHasChanged( this );
82  } );
83 
84  return mComboBox;
85  }
86  }
87  return nullptr;
88 }
89 
90 QLabel *QgsProcessingBooleanWidgetWrapper::createLabel()
91 {
92  // avoid creating labels in standard dialogs
93  if ( type() == QgsProcessingGui::Standard )
94  return nullptr;
95  else
97 }
98 
99 void QgsProcessingBooleanWidgetWrapper::setWidgetValue( const QVariant &value, QgsProcessingContext &context )
100 {
101  switch ( type() )
102  {
104  {
105  const bool v = QgsProcessingParameters::parameterAsBool( parameterDefinition(), value, context );
106  mCheckBox->setChecked( v );
107  break;
108  }
109 
112  {
113  const bool v = QgsProcessingParameters::parameterAsBool( parameterDefinition(), value, context );
114  mComboBox->setCurrentIndex( mComboBox->findData( v ) );
115  break;
116  }
117  }
118 }
119 
120 QVariant QgsProcessingBooleanWidgetWrapper::widgetValue() const
121 {
122  switch ( type() )
123  {
125  return mCheckBox->isChecked();
126 
129  return mComboBox->currentData();
130  }
131  return QVariant();
132 }
133 
134 QStringList QgsProcessingBooleanWidgetWrapper::compatibleParameterTypes() const
135 {
136  //pretty much everything is compatible here and can be converted to a bool!
137  return QStringList() << QgsProcessingParameterBoolean::typeName()
149 }
150 
151 QStringList QgsProcessingBooleanWidgetWrapper::compatibleOutputTypes() const
152 {
153  return QStringList() << QgsProcessingOutputNumber::typeName()
159 }
160 
161 QList<int> QgsProcessingBooleanWidgetWrapper::compatibleDataTypes() const
162 {
163  return QList< int >();
164 }
165 
166 QString QgsProcessingBooleanWidgetWrapper::parameterType() const
167 {
169 }
170 
171 QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingBooleanWidgetWrapper::createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type )
172 {
173  return new QgsProcessingBooleanWidgetWrapper( parameter, type );
174 }
175 
176 
177 //
178 // QgsProcessingCrsWidgetWrapper
179 //
180 
181 QgsProcessingCrsWidgetWrapper::QgsProcessingCrsWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type, QWidget *parent )
182  : QgsAbstractProcessingParameterWidgetWrapper( parameter, type, parent )
183 {
184 
185 }
186 
187 QWidget *QgsProcessingCrsWidgetWrapper::createWidget()
188 {
189  mProjectionSelectionWidget = new QgsProjectionSelectionWidget();
190  mProjectionSelectionWidget->setToolTip( parameterDefinition()->toolTip() );
191 
192  if ( parameterDefinition()->flags() & QgsProcessingParameterDefinition::FlagOptional )
193  mProjectionSelectionWidget->setOptionVisible( QgsProjectionSelectionWidget::CrsNotSet, true );
194  else
195  mProjectionSelectionWidget->setOptionVisible( QgsProjectionSelectionWidget::CrsNotSet, false );
196 
197  connect( mProjectionSelectionWidget, &QgsProjectionSelectionWidget::crsChanged, this, [ = ]
198  {
199  emit widgetValueHasChanged( this );
200  } );
201 
202  switch ( type() )
203  {
206  {
207  return mProjectionSelectionWidget;
208  };
209 
211  {
212  QWidget *w = new QWidget();
213  w->setToolTip( parameterDefinition()->toolTip() );
214 
215  QVBoxLayout *vl = new QVBoxLayout();
216  vl->setMargin( 0 );
217  vl->setContentsMargins( 0, 0, 0, 0 );
218  w->setLayout( vl );
219 
220  mUseProjectCrsCheckBox = new QCheckBox( tr( "Use project CRS" ) );
221  mUseProjectCrsCheckBox->setToolTip( tr( "Always use the current project CRS when running the model" ) );
222  vl->addWidget( mUseProjectCrsCheckBox );
223  connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, mProjectionSelectionWidget, &QgsProjectionSelectionWidget::setDisabled );
224  connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, this, [ = ]
225  {
226  emit widgetValueHasChanged( this );
227  } );
228 
229  vl->addWidget( mProjectionSelectionWidget );
230 
231  return w;
232  }
233  }
234  return nullptr;
235 }
236 
237 void QgsProcessingCrsWidgetWrapper::setWidgetValue( const QVariant &value, QgsProcessingContext &context )
238 {
239  if ( mUseProjectCrsCheckBox )
240  {
241  if ( value.toString().compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
242  {
243  mUseProjectCrsCheckBox->setChecked( true );
244  return;
245  }
246  else
247  {
248  mUseProjectCrsCheckBox->setChecked( false );
249  }
250  }
251 
252  const QgsCoordinateReferenceSystem v = QgsProcessingParameters::parameterAsCrs( parameterDefinition(), value, context );
253  if ( mProjectionSelectionWidget )
254  mProjectionSelectionWidget->setCrs( v );
255 }
256 
257 QVariant QgsProcessingCrsWidgetWrapper::widgetValue() const
258 {
259  if ( mUseProjectCrsCheckBox && mUseProjectCrsCheckBox->isChecked() )
260  return QStringLiteral( "ProjectCrs" );
261  else if ( mProjectionSelectionWidget )
262  return mProjectionSelectionWidget->crs().isValid() ? mProjectionSelectionWidget->crs() : QVariant();
263  else
264  return QVariant();
265 }
266 
267 QStringList QgsProcessingCrsWidgetWrapper::compatibleParameterTypes() const
268 {
269  return QStringList()
277 }
278 
279 QStringList QgsProcessingCrsWidgetWrapper::compatibleOutputTypes() const
280 {
281  return QStringList() << QgsProcessingOutputVectorLayer::typeName()
285 }
286 
287 QList<int> QgsProcessingCrsWidgetWrapper::compatibleDataTypes() const
288 {
289  return QList< int >();
290 }
291 
292 QString QgsProcessingCrsWidgetWrapper::modelerExpressionFormatString() const
293 {
294  return tr( "string as EPSG code, WKT or PROJ format, or a string identifying a map layer" );
295 }
296 
297 QString QgsProcessingCrsWidgetWrapper::parameterType() const
298 {
300 }
301 
302 QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingCrsWidgetWrapper::createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type )
303 {
304  return new QgsProcessingCrsWidgetWrapper( parameter, type );
305 }
306 
307 
308 
309 //
310 // QgsProcessingStringWidgetWrapper
311 //
312 
313 QgsProcessingStringWidgetWrapper::QgsProcessingStringWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type, QWidget *parent )
314  : QgsAbstractProcessingParameterWidgetWrapper( parameter, type, parent )
315 {
316 
317 }
318 
319 QWidget *QgsProcessingStringWidgetWrapper::createWidget()
320 {
321  switch ( type() )
322  {
325  {
326  if ( static_cast< const QgsProcessingParameterString * >( parameterDefinition() )->multiLine() )
327  {
328  mPlainTextEdit = new QPlainTextEdit();
329  mPlainTextEdit->setToolTip( parameterDefinition()->toolTip() );
330 
331  connect( mPlainTextEdit, &QPlainTextEdit::textChanged, this, [ = ]
332  {
333  emit widgetValueHasChanged( this );
334  } );
335  return mPlainTextEdit;
336  }
337  else
338  {
339  mLineEdit = new QLineEdit();
340  mLineEdit->setToolTip( parameterDefinition()->toolTip() );
341 
342  connect( mLineEdit, &QLineEdit::textChanged, this, [ = ]
343  {
344  emit widgetValueHasChanged( this );
345  } );
346  return mLineEdit;
347  }
348  };
349 
351  {
352  mLineEdit = new QLineEdit();
353  mLineEdit->setToolTip( parameterDefinition()->toolTip() );
354 
355  connect( mLineEdit, &QLineEdit::textChanged, this, [ = ]
356  {
357  emit widgetValueHasChanged( this );
358  } );
359  return mLineEdit;
360  }
361  }
362  return nullptr;
363 }
364 
365 void QgsProcessingStringWidgetWrapper::setWidgetValue( const QVariant &value, QgsProcessingContext &context )
366 {
367  const QString v = QgsProcessingParameters::parameterAsString( parameterDefinition(), value, context );
368  if ( mLineEdit )
369  mLineEdit->setText( v );
370  if ( mPlainTextEdit )
371  mPlainTextEdit->setPlainText( v );
372 }
373 
374 QVariant QgsProcessingStringWidgetWrapper::widgetValue() const
375 {
376  if ( mLineEdit )
377  return mLineEdit->text();
378  else if ( mPlainTextEdit )
379  return mPlainTextEdit->toPlainText();
380  else
381  return QVariant();
382 }
383 
384 QStringList QgsProcessingStringWidgetWrapper::compatibleParameterTypes() const
385 {
386  return QStringList()
394 }
395 
396 QStringList QgsProcessingStringWidgetWrapper::compatibleOutputTypes() const
397 {
398  return QStringList() << QgsProcessingOutputNumber::typeName()
401 }
402 
403 QList<int> QgsProcessingStringWidgetWrapper::compatibleDataTypes() const
404 {
405  return QList< int >();
406 }
407 
408 QString QgsProcessingStringWidgetWrapper::parameterType() const
409 {
411 }
412 
413 QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingStringWidgetWrapper::createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type )
414 {
415  return new QgsProcessingStringWidgetWrapper( parameter, type );
416 }
417 
418 
419 
420 //
421 // QgsProcessingAuthConfigWidgetWrapper
422 //
423 
424 QgsProcessingAuthConfigWidgetWrapper::QgsProcessingAuthConfigWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type, QWidget *parent )
425  : QgsAbstractProcessingParameterWidgetWrapper( parameter, type, parent )
426 {
427 
428 }
429 
430 QWidget *QgsProcessingAuthConfigWidgetWrapper::createWidget()
431 {
432  switch ( type() )
433  {
437  {
438  mAuthConfigSelect = new QgsAuthConfigSelect();
439  mAuthConfigSelect->setToolTip( parameterDefinition()->toolTip() );
440 
441  connect( mAuthConfigSelect, &QgsAuthConfigSelect::selectedConfigIdChanged, this, [ = ]
442  {
443  emit widgetValueHasChanged( this );
444  } );
445  return mAuthConfigSelect;
446  };
447  }
448  return nullptr;
449 }
450 
451 void QgsProcessingAuthConfigWidgetWrapper::setWidgetValue( const QVariant &value, QgsProcessingContext &context )
452 {
453  const QString v = QgsProcessingParameters::parameterAsString( parameterDefinition(), value, context );
454  if ( mAuthConfigSelect )
455  mAuthConfigSelect->setConfigId( v );
456 }
457 
458 QVariant QgsProcessingAuthConfigWidgetWrapper::widgetValue() const
459 {
460  if ( mAuthConfigSelect )
461  return mAuthConfigSelect->configId();
462  else
463  return QVariant();
464 }
465 
466 QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleParameterTypes() const
467 {
468  return QStringList()
472 }
473 
474 QStringList QgsProcessingAuthConfigWidgetWrapper::compatibleOutputTypes() const
475 {
476  return QStringList() << QgsProcessingOutputString::typeName();
477 }
478 
479 QList<int> QgsProcessingAuthConfigWidgetWrapper::compatibleDataTypes() const
480 {
481  return QList< int >();
482 }
483 
484 QString QgsProcessingAuthConfigWidgetWrapper::parameterType() const
485 {
487 }
488 
489 QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingAuthConfigWidgetWrapper::createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type )
490 {
491  return new QgsProcessingAuthConfigWidgetWrapper( parameter, type );
492 }
493 
494 //
495 // QgsProcessingNumericWidgetWrapper
496 //
497 
498 QgsProcessingNumericWidgetWrapper::QgsProcessingNumericWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type, QWidget *parent )
499  : QgsAbstractProcessingParameterWidgetWrapper( parameter, type, parent )
500 {
501 
502 }
503 
504 QWidget *QgsProcessingNumericWidgetWrapper::createWidget()
505 {
506  const QgsProcessingParameterNumber *numberDef = static_cast< const QgsProcessingParameterNumber * >( parameterDefinition() );
507  const QVariantMap metadata = numberDef->metadata();
508  const int decimals = metadata.value( QStringLiteral( "widget_wrapper" ) ).toMap().value( QStringLiteral( "decimals" ), 6 ).toInt();
509  switch ( type() )
510  {
514  {
515  // lots of duplicate code here -- but there's no common interface between QSpinBox/QDoubleSpinBox which would allow us to avoid this
516  QAbstractSpinBox *spinBox = nullptr;
517  switch ( numberDef->dataType() )
518  {
520  mDoubleSpinBox = new QgsDoubleSpinBox();
521  mDoubleSpinBox->setExpressionsEnabled( true );
522  mDoubleSpinBox->setDecimals( decimals );
523 
524  // guess reasonable step value for double spin boxes
525  if ( !qgsDoubleNear( numberDef->maximum(), std::numeric_limits<double>::max() ) &&
526  !qgsDoubleNear( numberDef->minimum(), std::numeric_limits<double>::lowest() + 1 ) )
527  {
528  double singleStep = calculateStep( numberDef->minimum(), numberDef->maximum() );
529  singleStep = std::max( singleStep, std::pow( 10, -decimals ) );
530  mDoubleSpinBox->setSingleStep( singleStep );
531  }
532 
533  spinBox = mDoubleSpinBox;
534  break;
535 
537  mSpinBox = new QgsSpinBox();
538  mSpinBox->setExpressionsEnabled( true );
539  spinBox = mSpinBox;
540  break;
541  }
542  spinBox->setToolTip( parameterDefinition()->toolTip() );
543 
544  double max = 999999999;
545  if ( !qgsDoubleNear( numberDef->maximum(), std::numeric_limits<double>::max() ) )
546  {
547  max = numberDef->maximum();
548  }
549  double min = -999999999;
550  if ( !qgsDoubleNear( numberDef->minimum(), std::numeric_limits<double>::lowest() ) )
551  {
552  min = numberDef->minimum();
553  }
554  if ( mDoubleSpinBox )
555  {
556  mDoubleSpinBox->setMinimum( min );
557  mDoubleSpinBox->setMaximum( max );
558  }
559  else
560  {
561  mSpinBox->setMinimum( static_cast< int >( min ) );
562  mSpinBox->setMaximum( static_cast< int >( max ) );
563  }
564 
566  {
567  mAllowingNull = true;
568  if ( mDoubleSpinBox )
569  {
570  mDoubleSpinBox->setShowClearButton( true );
571  const double min = mDoubleSpinBox->minimum() - 1;
572  mDoubleSpinBox->setMinimum( min );
573  mDoubleSpinBox->setValue( min );
574  }
575  else
576  {
577  mSpinBox->setShowClearButton( true );
578  const int min = mSpinBox->minimum() - 1;
579  mSpinBox->setMinimum( min );
580  mSpinBox->setValue( min );
581  }
582  spinBox->setSpecialValueText( tr( "Not set" ) );
583  }
584  else
585  {
586  if ( numberDef->defaultValue().isValid() )
587  {
588  // if default value for parameter, we clear to that
589  bool ok = false;
590  if ( mDoubleSpinBox )
591  {
592  double defaultVal = numberDef->defaultValue().toDouble( &ok );
593  if ( ok )
594  mDoubleSpinBox->setClearValue( defaultVal );
595  }
596  else
597  {
598  int intVal = numberDef->defaultValue().toInt( &ok );
599  if ( ok )
600  mSpinBox->setClearValue( intVal );
601  }
602  }
603  else if ( !qgsDoubleNear( numberDef->minimum(), std::numeric_limits<double>::lowest() ) )
604  {
605  // otherwise we clear to the minimum, if it's set
606  if ( mDoubleSpinBox )
607  mDoubleSpinBox->setClearValue( numberDef->minimum() );
608  else
609  mSpinBox->setClearValue( static_cast< int >( numberDef->minimum() ) );
610  }
611  else
612  {
613  // last resort, we clear to 0
614  if ( mDoubleSpinBox )
615  {
616  mDoubleSpinBox->setValue( 0 );
617  mDoubleSpinBox->setClearValue( 0 );
618  }
619  else
620  {
621  mSpinBox->setValue( 0 );
622  mSpinBox->setClearValue( 0 );
623  }
624  }
625  }
626 
627  if ( mDoubleSpinBox )
628  connect( mDoubleSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ), this, [ = ] { emit widgetValueHasChanged( this ); } );
629  else if ( mSpinBox )
630  connect( mSpinBox, qgis::overload<int>::of( &QgsSpinBox::valueChanged ), this, [ = ] { emit widgetValueHasChanged( this ); } );
631 
632  return spinBox;
633  };
634  }
635  return nullptr;
636 }
637 
638 void QgsProcessingNumericWidgetWrapper::setWidgetValue( const QVariant &value, QgsProcessingContext &context )
639 {
640  if ( mDoubleSpinBox )
641  {
642  if ( mAllowingNull && !value.isValid() )
643  mDoubleSpinBox->clear();
644  else
645  {
646  const double v = QgsProcessingParameters::parameterAsDouble( parameterDefinition(), value, context );
647  mDoubleSpinBox->setValue( v );
648  }
649  }
650  else if ( mSpinBox )
651  {
652  if ( mAllowingNull && !value.isValid() )
653  mSpinBox->clear();
654  else
655  {
656  const int v = QgsProcessingParameters::parameterAsInt( parameterDefinition(), value, context );
657  mSpinBox->setValue( v );
658  }
659  }
660 }
661 
662 QVariant QgsProcessingNumericWidgetWrapper::widgetValue() const
663 {
664  if ( mDoubleSpinBox )
665  {
666  if ( mAllowingNull && qgsDoubleNear( mDoubleSpinBox->value(), mDoubleSpinBox->minimum() ) )
667  return QVariant();
668  else
669  return mDoubleSpinBox->value();
670  }
671  else if ( mSpinBox )
672  {
673  if ( mAllowingNull && mSpinBox->value() == mSpinBox->minimum() )
674  return QVariant();
675  else
676  return mSpinBox->value();
677  }
678  else
679  return QVariant();
680 }
681 
682 QStringList QgsProcessingNumericWidgetWrapper::compatibleParameterTypes() const
683 {
684  return QStringList()
688 }
689 
690 QStringList QgsProcessingNumericWidgetWrapper::compatibleOutputTypes() const
691 {
692  return QStringList() << QgsProcessingOutputNumber::typeName()
694 }
695 
696 QList<int> QgsProcessingNumericWidgetWrapper::compatibleDataTypes() const
697 {
698  return QList< int >();
699 }
700 
701 double QgsProcessingNumericWidgetWrapper::calculateStep( const double minimum, const double maximum )
702 {
703  const double valueRange = maximum - minimum;
704  if ( valueRange <= 1.0 )
705  {
706  const double step = valueRange / 10.0;
707  // round to 1 significant figure
708  return qgsRound( step, -std::floor( std::log( step ) ) );
709  }
710  else
711  {
712  return 1.0;
713  }
714 }
715 
716 QString QgsProcessingNumericWidgetWrapper::parameterType() const
717 {
719 }
720 
721 QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingNumericWidgetWrapper::createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type )
722 {
723  return new QgsProcessingNumericWidgetWrapper( parameter, type );
724 }
725 
726 //
727 // QgsProcessingDistanceWidgetWrapper
728 //
729 
730 QgsProcessingDistanceWidgetWrapper::QgsProcessingDistanceWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type, QWidget *parent )
731  : QgsProcessingNumericWidgetWrapper( parameter, type, parent )
732 {
733 
734 }
735 
736 QString QgsProcessingDistanceWidgetWrapper::parameterType() const
737 {
739 }
740 
741 QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingDistanceWidgetWrapper::createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type )
742 {
743  return new QgsProcessingDistanceWidgetWrapper( parameter, type );
744 }
745 
746 QWidget *QgsProcessingDistanceWidgetWrapper::createWidget()
747 {
748  const QgsProcessingParameterDistance *distanceDef = static_cast< const QgsProcessingParameterDistance * >( parameterDefinition() );
749 
750  QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
751  switch ( type() )
752  {
754  {
755  mLabel = new QLabel();
756  mUnitsCombo = new QComboBox();
757 
763 
764  const int labelMargin = static_cast< int >( std::round( mUnitsCombo->fontMetrics().width( 'X' ) ) );
765  QHBoxLayout *layout = new QHBoxLayout();
766  layout->addWidget( spin, 1 );
767  layout->insertSpacing( 1, labelMargin / 2 );
768  layout->insertWidget( 2, mLabel );
769  layout->insertWidget( 3, mUnitsCombo );
770 
771  // bit of fiddlyness here -- we want the initial spacing to only be visible
772  // when the warning label is shown, so it's embedded inside mWarningLabel
773  // instead of outside it
774  mWarningLabel = new QWidget();
775  QHBoxLayout *warningLayout = new QHBoxLayout();
776  warningLayout->setMargin( 0 );
777  warningLayout->setContentsMargins( 0, 0, 0, 0 );
778  QLabel *warning = new QLabel();
779  QIcon icon = QgsApplication::getThemeIcon( QStringLiteral( "mIconWarning.svg" ) );
780  const int size = static_cast< int >( std::max( 24.0, spin->minimumSize().height() * 0.5 ) );
781  warning->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
782  warning->setToolTip( tr( "Distance is in geographic degrees. Consider reprojecting to a projected local coordinate system for accurate results." ) );
783  warningLayout->insertSpacing( 0, labelMargin / 2 );
784  warningLayout->insertWidget( 1, warning );
785  mWarningLabel->setLayout( warningLayout );
786  layout->insertWidget( 4, mWarningLabel );
787 
788  setUnits( distanceDef->defaultUnit() );
789 
790  QWidget *w = new QWidget();
791  layout->setMargin( 0 );
792  layout->setContentsMargins( 0, 0, 0, 0 );
793  w->setLayout( layout );
794  return w;
795  }
796 
799  return spin;
800 
801  }
802  return nullptr;
803 }
804 
805 void QgsProcessingDistanceWidgetWrapper::postInitialize( const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
806 {
807  QgsProcessingNumericWidgetWrapper::postInitialize( wrappers );
808  switch ( type() )
809  {
811  {
812  for ( const QgsAbstractProcessingParameterWidgetWrapper *wrapper : wrappers )
813  {
814  if ( wrapper->parameterDefinition()->name() == static_cast< const QgsProcessingParameterDistance * >( parameterDefinition() )->parentParameterName() )
815  {
816  setUnitParameterValue( wrapper->parameterValue() );
818  {
819  setUnitParameterValue( wrapper->parameterValue() );
820  } );
821  break;
822  }
823  }
824  break;
825  }
826 
829  break;
830  }
831 }
832 
833 void QgsProcessingDistanceWidgetWrapper::setUnitParameterValue( const QVariant &value )
834 {
836 
837  // evaluate value to layer
838  QgsProcessingContext *context = nullptr;
839  std::unique_ptr< QgsProcessingContext > tmpContext;
840  if ( mProcessingContextGenerator )
841  context = mProcessingContextGenerator->processingContext();
842 
843  if ( !context )
844  {
845  tmpContext = qgis::make_unique< QgsProcessingContext >();
846  context = tmpContext.get();
847  }
848 
849  QgsCoordinateReferenceSystem crs = QgsProcessingParameters::parameterAsCrs( parameterDefinition(), value, *context );
850  if ( crs.isValid() )
851  {
852  units = crs.mapUnits();
853  }
854 
855  setUnits( units );
856 }
857 
858 void QgsProcessingDistanceWidgetWrapper::setUnits( const QgsUnitTypes::DistanceUnit units )
859 {
860  mLabel->setText( QgsUnitTypes::toString( units ) );
862  {
863  mUnitsCombo->hide();
864  mLabel->show();
865  }
866  else
867  {
868  mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( units ) );
869  mUnitsCombo->show();
870  mLabel->hide();
871  }
872  mWarningLabel->setVisible( units == QgsUnitTypes::DistanceDegrees );
873  mBaseUnit = units;
874 }
875 
876 QVariant QgsProcessingDistanceWidgetWrapper::widgetValue() const
877 {
878  const QVariant val = QgsProcessingNumericWidgetWrapper::widgetValue();
879  if ( val.type() == QVariant::Double && mUnitsCombo && mUnitsCombo->isVisible() )
880  {
881  QgsUnitTypes::DistanceUnit displayUnit = static_cast<QgsUnitTypes::DistanceUnit >( mUnitsCombo->currentData().toInt() );
882  return val.toDouble() * QgsUnitTypes::fromUnitToUnitFactor( displayUnit, mBaseUnit );
883  }
884  else
885  {
886  return val;
887  }
888 }
889 
890 
891 //
892 // QgsProcessingRangeWidgetWrapper
893 //
894 
895 QgsProcessingRangeWidgetWrapper::QgsProcessingRangeWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type, QWidget *parent )
896  : QgsAbstractProcessingParameterWidgetWrapper( parameter, type, parent )
897 {
898 
899 }
900 
901 QWidget *QgsProcessingRangeWidgetWrapper::createWidget()
902 {
903  const QgsProcessingParameterRange *rangeDef = static_cast< const QgsProcessingParameterRange * >( parameterDefinition() );
904  switch ( type() )
905  {
909  {
910  QHBoxLayout *layout = new QHBoxLayout();
911 
912  mMinSpinBox = new QgsDoubleSpinBox();
913  mMaxSpinBox = new QgsDoubleSpinBox();
914 
915  mMinSpinBox->setExpressionsEnabled( true );
916  mMinSpinBox->setShowClearButton( false );
917  mMaxSpinBox->setExpressionsEnabled( true );
918  mMaxSpinBox->setShowClearButton( false );
919 
920  QLabel *minLabel = new QLabel( tr( "Min" ) );
921  layout->addWidget( minLabel );
922  layout->addWidget( mMinSpinBox, 1 );
923 
924  QLabel *maxLabel = new QLabel( tr( "Max" ) );
925  layout->addWidget( maxLabel );
926  layout->addWidget( mMaxSpinBox, 1 );
927 
928  QWidget *w = new QWidget();
929  layout->setMargin( 0 );
930  layout->setContentsMargins( 0, 0, 0, 0 );
931  w->setLayout( layout );
932 
933  if ( rangeDef->dataType() == QgsProcessingParameterNumber::Double )
934  {
935  mMinSpinBox->setDecimals( 6 );
936  mMaxSpinBox->setDecimals( 6 );
937  }
938  else
939  {
940  mMinSpinBox->setDecimals( 0 );
941  mMaxSpinBox->setDecimals( 0 );
942  }
943 
944  mMinSpinBox->setMinimum( -99999999.999999 );
945  mMaxSpinBox->setMinimum( -99999999.999999 );
946  mMinSpinBox->setMaximum( 99999999.999999 );
947  mMaxSpinBox->setMaximum( 99999999.999999 );
948 
949  w->setToolTip( parameterDefinition()->toolTip() );
950 
951  connect( mMinSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( const double v )
952  {
953  mBlockChangedSignal++;
954  if ( v > mMaxSpinBox->value() )
955  mMaxSpinBox->setValue( v );
956  mBlockChangedSignal--;
957 
958  if ( !mBlockChangedSignal )
959  emit widgetValueHasChanged( this );
960  } );
961  connect( mMaxSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( const double v )
962  {
963  mBlockChangedSignal++;
964  if ( v < mMinSpinBox->value() )
965  mMinSpinBox->setValue( v );
966  mBlockChangedSignal--;
967 
968  if ( !mBlockChangedSignal )
969  emit widgetValueHasChanged( this );
970  } );
971 
972  return w;
973  };
974  }
975  return nullptr;
976 }
977 
978 void QgsProcessingRangeWidgetWrapper::setWidgetValue( const QVariant &value, QgsProcessingContext &context )
979 {
980  const QList< double > v = QgsProcessingParameters::parameterAsRange( parameterDefinition(), value, context );
981  if ( v.empty() )
982  return;
983 
984  mBlockChangedSignal++;
985  mMinSpinBox->setValue( v.at( 0 ) );
986  if ( v.count() >= 2 )
987  mMaxSpinBox->setValue( v.at( 1 ) );
988  mBlockChangedSignal--;
989 
990  if ( !mBlockChangedSignal )
991  emit widgetValueHasChanged( this );
992 }
993 
994 QVariant QgsProcessingRangeWidgetWrapper::widgetValue() const
995 {
996  return QStringLiteral( "%1,%2" ).arg( mMinSpinBox->value() ).arg( mMaxSpinBox->value() );
997 }
998 
999 QStringList QgsProcessingRangeWidgetWrapper::compatibleParameterTypes() const
1000 {
1001  return QStringList()
1004 }
1005 
1006 QStringList QgsProcessingRangeWidgetWrapper::compatibleOutputTypes() const
1007 {
1008  return QStringList() << QgsProcessingOutputString::typeName();
1009 }
1010 
1011 QList<int> QgsProcessingRangeWidgetWrapper::compatibleDataTypes() const
1012 {
1013  return QList< int >();
1014 }
1015 
1016 QString QgsProcessingRangeWidgetWrapper::modelerExpressionFormatString() const
1017 {
1018  return tr( "string as two comma delimited floats, e.g. '1,10'" );
1019 }
1020 
1021 QString QgsProcessingRangeWidgetWrapper::parameterType() const
1022 {
1024 }
1025 
1026 QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingRangeWidgetWrapper::createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type )
1027 {
1028  return new QgsProcessingRangeWidgetWrapper( parameter, type );
1029 }
1030 
1031 
1032 
1033 //
1034 // QgsProcessingMatrixWidgetWrapper
1035 //
1036 
1037 QgsProcessingMatrixWidgetWrapper::QgsProcessingMatrixWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type, QWidget *parent )
1038  : QgsAbstractProcessingParameterWidgetWrapper( parameter, type, parent )
1039 {
1040 
1041 }
1042 
1043 QWidget *QgsProcessingMatrixWidgetWrapper::createWidget()
1044 {
1045  mMatrixWidget = new QgsProcessingMatrixParameterPanel( nullptr, dynamic_cast< const QgsProcessingParameterMatrix *>( parameterDefinition() ) );
1046  mMatrixWidget->setToolTip( parameterDefinition()->toolTip() );
1047 
1048  connect( mMatrixWidget, &QgsProcessingMatrixParameterPanel::changed, this, [ = ]
1049  {
1050  emit widgetValueHasChanged( this );
1051  } );
1052 
1053  switch ( type() )
1054  {
1058  {
1059  return mMatrixWidget;
1060  };
1061  }
1062  return nullptr;
1063 }
1064 
1065 void QgsProcessingMatrixWidgetWrapper::setWidgetValue( const QVariant &value, QgsProcessingContext &context )
1066 {
1067  const QVariantList v = QgsProcessingParameters::parameterAsMatrix( parameterDefinition(), value, context );
1068  if ( mMatrixWidget )
1069  mMatrixWidget->setValue( v );
1070 }
1071 
1072 QVariant QgsProcessingMatrixWidgetWrapper::widgetValue() const
1073 {
1074  if ( mMatrixWidget )
1075  return mMatrixWidget->value().isEmpty() ? QVariant() : mMatrixWidget->value();
1076  else
1077  return QVariant();
1078 }
1079 
1080 QStringList QgsProcessingMatrixWidgetWrapper::compatibleParameterTypes() const
1081 {
1082  return QStringList()
1084 }
1085 
1086 QStringList QgsProcessingMatrixWidgetWrapper::compatibleOutputTypes() const
1087 {
1088  return QStringList();
1089 }
1090 
1091 QList<int> QgsProcessingMatrixWidgetWrapper::compatibleDataTypes() const
1092 {
1093  return QList< int >();
1094 }
1095 
1096 QString QgsProcessingMatrixWidgetWrapper::modelerExpressionFormatString() const
1097 {
1098  return tr( "comma delimited string of values, or an array of values" );
1099 }
1100 
1101 QString QgsProcessingMatrixWidgetWrapper::parameterType() const
1102 {
1104 }
1105 
1106 QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingMatrixWidgetWrapper::createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type )
1107 {
1108  return new QgsProcessingMatrixWidgetWrapper( parameter, type );
1109 }
1110 
1111 
1112 
1113 
1114 //
1115 // QgsProcessingFileWidgetWrapper
1116 //
1117 
1118 QgsProcessingFileWidgetWrapper::QgsProcessingFileWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type, QWidget *parent )
1119  : QgsAbstractProcessingParameterWidgetWrapper( parameter, type, parent )
1120 {
1121 
1122 }
1123 
1124 QWidget *QgsProcessingFileWidgetWrapper::createWidget()
1125 {
1126  const QgsProcessingParameterFile *fileParam = dynamic_cast< const QgsProcessingParameterFile *>( parameterDefinition() );
1127  switch ( type() )
1128  {
1132  {
1133  mFileWidget = new QgsFileWidget();
1134  mFileWidget->setToolTip( parameterDefinition()->toolTip() );
1135  mFileWidget->setDialogTitle( parameterDefinition()->description() );
1136 
1137  mFileWidget->setDefaultRoot( QgsSettings().value( QStringLiteral( "/Processing/LastInputPath" ), QDir::homePath() ).toString() );
1138 
1139  switch ( fileParam->behavior() )
1140  {
1142  mFileWidget->setStorageMode( QgsFileWidget::GetFile );
1143  if ( !fileParam->extension().isEmpty() )
1144  mFileWidget->setFilter( tr( "%1 files" ).arg( fileParam->extension().toUpper() ) + QStringLiteral( " (*." ) + fileParam->extension().toLower() + ')' );
1145  break;
1146 
1148  mFileWidget->setStorageMode( QgsFileWidget::GetDirectory );
1149  break;
1150  }
1151 
1152  connect( mFileWidget, &QgsFileWidget::fileChanged, this, [ = ]( const QString & path )
1153  {
1154  QgsSettings().setValue( QStringLiteral( "/Processing/LastInputPath" ), QFileInfo( path ).canonicalPath() );
1155  emit widgetValueHasChanged( this );
1156  } );
1157  return mFileWidget;
1158  };
1159  }
1160  return nullptr;
1161 }
1162 
1163 void QgsProcessingFileWidgetWrapper::setWidgetValue( const QVariant &value, QgsProcessingContext &context )
1164 {
1165  const QString v = QgsProcessingParameters::parameterAsString( parameterDefinition(), value, context );
1166  if ( mFileWidget )
1167  mFileWidget->setFilePath( v );
1168 }
1169 
1170 QVariant QgsProcessingFileWidgetWrapper::widgetValue() const
1171 {
1172  if ( mFileWidget )
1173  return mFileWidget->filePath();
1174  else
1175  return QVariant();
1176 }
1177 
1178 QStringList QgsProcessingFileWidgetWrapper::compatibleParameterTypes() const
1179 {
1180  return QStringList()
1183 }
1184 
1185 QStringList QgsProcessingFileWidgetWrapper::compatibleOutputTypes() const
1186 {
1187  return QStringList() << QgsProcessingOutputFile::typeName()
1192 }
1193 
1194 QList<int> QgsProcessingFileWidgetWrapper::compatibleDataTypes() const
1195 {
1196  return QList< int >();
1197 }
1198 
1199 QString QgsProcessingFileWidgetWrapper::modelerExpressionFormatString() const
1200 {
1201  return tr( "string representing a path to a file or folder" );
1202 }
1203 
1204 QString QgsProcessingFileWidgetWrapper::parameterType() const
1205 {
1207 }
1208 
1209 QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingFileWidgetWrapper::createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type )
1210 {
1211  return new QgsProcessingFileWidgetWrapper( parameter, type );
1212 }
1213 
1214 
1215 
1216 
1217 //
1218 // QgsProcessingExpressionWidgetWrapper
1219 //
1220 
1221 QgsProcessingExpressionWidgetWrapper::QgsProcessingExpressionWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type, QWidget *parent )
1222  : QgsAbstractProcessingParameterWidgetWrapper( parameter, type, parent )
1223 {
1224 
1225 }
1226 
1227 QWidget *QgsProcessingExpressionWidgetWrapper::createWidget()
1228 {
1229  const QgsProcessingParameterExpression *expParam = dynamic_cast< const QgsProcessingParameterExpression *>( parameterDefinition() );
1230  switch ( type() )
1231  {
1235  {
1236  if ( expParam->parentLayerParameterName().isEmpty() )
1237  {
1238  mExpLineEdit = new QgsExpressionLineEdit();
1239  mExpLineEdit->setToolTip( parameterDefinition()->toolTip() );
1240  mExpLineEdit->setExpressionDialogTitle( parameterDefinition()->description() );
1241  mExpLineEdit->registerExpressionContextGenerator( this );
1242  connect( mExpLineEdit, &QgsExpressionLineEdit::expressionChanged, this, [ = ]( const QString & )
1243  {
1244  emit widgetValueHasChanged( this );
1245  } );
1246  return mExpLineEdit;
1247  }
1248  else
1249  {
1250  mFieldExpWidget = new QgsFieldExpressionWidget();
1251  mFieldExpWidget->setToolTip( parameterDefinition()->toolTip() );
1252  mFieldExpWidget->setExpressionDialogTitle( parameterDefinition()->description() );
1253  mFieldExpWidget->registerExpressionContextGenerator( this );
1254  connect( mFieldExpWidget, static_cast < void ( QgsFieldExpressionWidget::* )( const QString & ) >( &QgsFieldExpressionWidget::fieldChanged ), this, [ = ]( const QString & )
1255  {
1256  emit widgetValueHasChanged( this );
1257  } );
1258  return mFieldExpWidget;
1259  }
1260  };
1261  }
1262  return nullptr;
1263 }
1264 
1265 void QgsProcessingExpressionWidgetWrapper::postInitialize( const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
1266 {
1268  switch ( type() )
1269  {
1272  {
1273  for ( const QgsAbstractProcessingParameterWidgetWrapper *wrapper : wrappers )
1274  {
1275  if ( wrapper->parameterDefinition()->name() == static_cast< const QgsProcessingParameterExpression * >( parameterDefinition() )->parentLayerParameterName() )
1276  {
1277  setParentLayerWrapperValue( wrapper );
1279  {
1280  setParentLayerWrapperValue( wrapper );
1281  } );
1282  break;
1283  }
1284  }
1285  break;
1286  }
1287 
1289  break;
1290  }
1291 }
1292 
1293 void QgsProcessingExpressionWidgetWrapper::setParentLayerWrapperValue( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper )
1294 {
1295  // evaluate value to layer
1296  QgsProcessingContext *context = nullptr;
1297  std::unique_ptr< QgsProcessingContext > tmpContext;
1298  if ( mProcessingContextGenerator )
1299  context = mProcessingContextGenerator->processingContext();
1300 
1301  if ( !context )
1302  {
1303  tmpContext = qgis::make_unique< QgsProcessingContext >();
1304  context = tmpContext.get();
1305  }
1306 
1307  QgsVectorLayer *layer = QgsProcessingParameters::parameterAsVectorLayer( parentWrapper->parameterDefinition(), parentWrapper->parameterValue(), *context );
1308  if ( !layer )
1309  {
1310  if ( mFieldExpWidget )
1311  mFieldExpWidget->setLayer( nullptr );
1312  else if ( mExpLineEdit )
1313  mExpLineEdit->setLayer( nullptr );
1314  return;
1315  }
1316 
1317  // need to grab ownership of layer if required - otherwise layer may be deleted when context
1318  // goes out of scope
1319  std::unique_ptr< QgsMapLayer > ownedLayer( context->takeResultLayer( layer->id() ) );
1320  if ( ownedLayer && ownedLayer->type() == QgsMapLayer::VectorLayer )
1321  {
1322  mParentLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
1323  layer = mParentLayer.get();
1324  }
1325  else
1326  {
1327  // don't need ownership of this layer - it wasn't owned by context (so e.g. is owned by the project)
1328  }
1329 
1330  if ( mFieldExpWidget )
1331  mFieldExpWidget->setLayer( layer );
1332  else if ( mExpLineEdit )
1333  mExpLineEdit->setLayer( layer );
1334 }
1335 
1336 void QgsProcessingExpressionWidgetWrapper::setWidgetValue( const QVariant &value, QgsProcessingContext &context )
1337 {
1338  const QString v = QgsProcessingParameters::parameterAsString( parameterDefinition(), value, context );
1339  if ( mFieldExpWidget )
1340  mFieldExpWidget->setExpression( v );
1341  else if ( mExpLineEdit )
1342  mExpLineEdit->setExpression( v );
1343 }
1344 
1345 QVariant QgsProcessingExpressionWidgetWrapper::widgetValue() const
1346 {
1347  if ( mFieldExpWidget )
1348  return mFieldExpWidget->expression();
1349  else if ( mExpLineEdit )
1350  return mExpLineEdit->expression();
1351  else
1352  return QVariant();
1353 }
1354 
1355 QStringList QgsProcessingExpressionWidgetWrapper::compatibleParameterTypes() const
1356 {
1357  return QStringList()
1362 }
1363 
1364 QStringList QgsProcessingExpressionWidgetWrapper::compatibleOutputTypes() const
1365 {
1366  return QStringList()
1369 }
1370 
1371 QList<int> QgsProcessingExpressionWidgetWrapper::compatibleDataTypes() const
1372 {
1373  return QList< int >();
1374 }
1375 
1376 QString QgsProcessingExpressionWidgetWrapper::modelerExpressionFormatString() const
1377 {
1378  return tr( "string representation of an expression" );
1379 }
1380 
1381 const QgsVectorLayer *QgsProcessingExpressionWidgetWrapper::linkedVectorLayer() const
1382 {
1383  if ( mFieldExpWidget && mFieldExpWidget->layer() )
1384  return mFieldExpWidget->layer();
1385 
1387 }
1388 
1389 QString QgsProcessingExpressionWidgetWrapper::parameterType() const
1390 {
1392 }
1393 
1394 QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingExpressionWidgetWrapper::createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type )
1395 {
1396  return new QgsProcessingExpressionWidgetWrapper( parameter, type );
1397 }
1398 
1399 
1401 
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, 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.
The QgsFieldExpressionWidget class reates a widget to choose fields and edit expressions It contains ...
An input file or folder parameter for processing algorithms.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
A widget wrapper for Processing parameter value widgets.
static QString typeName()
Returns the type name for the parameter class.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, 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.
void fileChanged(const QString &)
emitted as soon as the current file or directory is changed
static QString typeName()
Returns the type name for the output class.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:58
static QString typeName()
Returns the type name for the parameter class.
QVariantMap metadata() const
Returns the parameter&#39;s freeform metadata.
static QString typeName()
Returns the type name for the parameter class.
Select a single file.
Definition: qgsfilewidget.h:66
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)
Definition: qgis.h:265
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...
Definition: qgsspinbox.h:42
static QString typeName()
Returns the type name for the parameter class.
double minimum() const
Returns the minimum value acceptable by the parameter.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
virtual QLabel * createLabel()
Creates a new label to accompany widgets created by the wrapper.
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 QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
static QString typeName()
Returns the type name for the parameter class.
A numeric range parameter for processing algorithms.
virtual const QgsVectorLayer * linkedVectorLayer() const
Returns the optional vector layer associated with this widget wrapper, or nullptr if no vector layer ...
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...
QString id() const
Returns the layer&#39;s unique ID, which is used to access this layer from QgsProject.
The QgsFileWidget class creates a widget for selecting a file or a folder.
Definition: qgsfilewidget.h:35
Flags flags() const
Returns any flags associated with the parameter.
QVariant parameterValue() const
Returns the current value of the parameter.
static QString typeName()
Returns the type name for the parameter class.
QVariant defaultValue() const
Returns the default value for the parameter.
void widgetValueHasChanged(QgsAbstractProcessingParameterWidgetWrapper *wrapper)
Emitted whenever the parameter value (as defined by the wrapped widget) is changed.
A double numeric parameter for distance values.
virtual void postInitialize(const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers)
Called after all wrappers have been created within a particular dialog or context, allowing the wrapper to connect to the wrappers of other, related parameters.
static QString typeName()
Returns the type name for the output class.
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:62
const QgsProcessingParameterDefinition * parameterDefinition() const
Returns the parameter definition associated with this wrapper.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
A numeric parameter for processing algorithms.
void expressionChanged(const QString &expression)
Emitted when the expression is changed.
Behavior behavior() const
Returns the parameter behavior (e.g.
void fieldChanged(const QString &fieldName)
the signal is emitted when the currently selected field changes
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:54
A widget for selecting a projection.
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.
void selectedConfigIdChanged(const QString &authcfg)
Emitted when authentication config is changed or missing.
Unknown distance unit.
Definition: qgsunittypes.h:65
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
void crsChanged(const QgsCoordinateReferenceSystem &)
Emitted when the selected CRS is changed.
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...
Definition: qgis.h:304
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 &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
static int parameterAsInt(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static integer value.
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
Type dataType() const
Returns the acceptable data type for the parameter.
Terrestrial miles.
Definition: qgsunittypes.h:61
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
Represents a vector layer which manages a vector based data sets.
Contains information about the context in which a processing algorithm is executed.
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.
Definition: qgsunittypes.h:74
double maximum() const
Returns the maximum value acceptable by the parameter.
Selector widget for authentication configs.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Standard algorithm dialog.
Batch processing dialog.