Skip to content
Permalink
Browse files

[processing] Port point widget wrapper to new API

And switch to a snapping canvas tool when selecting points from canvas
  • Loading branch information
nyalldawson committed Mar 14, 2019
1 parent 37faa0d commit 719a225bcae4033fdbdd1303fb88ad4d78761761
@@ -875,6 +875,15 @@ If ``crs`` is set then the point will be automatically reprojected so that it is
Returns the coordinate reference system associated with an point parameter value.

.. seealso:: :py:func:`parameterAsPoint`
%End

static QgsCoordinateReferenceSystem parameterAsPointCrs( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
%Docstring
Returns the coordinate reference system associated with an point parameter value.

.. seealso:: :py:func:`parameterAsPoint`

.. versionadded:: 3.8
%End

static QString parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
@@ -119,6 +119,13 @@ Sets the current ``value`` for the parameter.
Returns the current value of the parameter.

.. seealso:: :py:func:`setWidgetValue`
%End

void setDialog( QDialog *dialog );
%Docstring
Sets the parent ``dialog`` in which the widget is shown.

.. versionadded:: 3.8
%End

virtual QgsExpressionContext createExpressionContext() const;
@@ -263,6 +263,13 @@ allowing the wrapper to connect to the wrappers of other, related parameters.
virtual QgsExpressionContext createExpressionContext() const;


virtual void setDialog( QDialog *dialog );
%Docstring
Sets the parent ``dialog`` in which the wrapper is shown.

.. versionadded:: 3.8
%End

signals:


@@ -1848,6 +1848,7 @@ def create_wrapper(param, dialog, row=0, col=0):
QgsProcessingGui.Standard)
wrapper = QgsGui.processingGuiRegistry().createParameterWidgetWrapper(param, dialog_type)
if wrapper is not None:
wrapper.setDialog(dialog)
return wrapper

# fallback to Python registry
@@ -1189,10 +1189,14 @@ QgsPointXY QgsProcessingParameters::parameterAsPoint( const QgsProcessingParamet
QgsCoordinateReferenceSystem QgsProcessingParameters::parameterAsPointCrs( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
{
QVariant val = parameters.value( definition->name() );
return parameterAsPointCrs( definition, val, context );
}

if ( val.canConvert< QgsReferencedPointXY >() )
QgsCoordinateReferenceSystem QgsProcessingParameters::parameterAsPointCrs( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
{
if ( value.canConvert< QgsReferencedPointXY >() )
{
QgsReferencedPointXY rr = val.value<QgsReferencedPointXY>();
QgsReferencedPointXY rr = value.value<QgsReferencedPointXY>();
if ( rr.crs().isValid() )
{
return rr.crs();
@@ -1201,7 +1205,7 @@ QgsCoordinateReferenceSystem QgsProcessingParameters::parameterAsPointCrs( const

QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );

QString valueAsString = parameterAsString( definition, parameters, context );
QString valueAsString = parameterAsString( definition, value, context );
QRegularExpressionMatch match = rx.match( valueAsString );
if ( match.hasMatch() )
{
@@ -936,6 +936,14 @@ class CORE_EXPORT QgsProcessingParameters
*/
static QgsCoordinateReferenceSystem parameterAsPointCrs( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );

/**
* Returns the coordinate reference system associated with an point parameter value.
*
* \see parameterAsPoint()
* \since QGIS 3.8
*/
static QgsCoordinateReferenceSystem parameterAsPointCrs( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );

/**
* Evaluates the parameter with matching \a definition to a file/folder name.
*/
@@ -41,6 +41,7 @@ QgsProcessingGuiRegistry::QgsProcessingGuiRegistry()
addParameterWidgetFactory( new QgsProcessingEnumWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingLayoutWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingLayoutItemWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingPointWidgetWrapper() );
}

QgsProcessingGuiRegistry::~QgsProcessingGuiRegistry()
@@ -180,6 +180,12 @@ QgsProcessingModelChildParameterSource QgsProcessingModelerParameterWidget::valu
return QgsProcessingModelChildParameterSource();
}

void QgsProcessingModelerParameterWidget::setDialog( QDialog *dialog )
{
if ( mStaticWidgetWrapper )
mStaticWidgetWrapper->setDialog( dialog );
}

QgsExpressionContext QgsProcessingModelerParameterWidget::createExpressionContext() const
{
QgsExpressionContext c = mContext.expressionContext();
@@ -148,6 +148,13 @@ class GUI_EXPORT QgsProcessingModelerParameterWidget : public QWidget, public Qg
*/
virtual QgsProcessingModelChildParameterSource value() const;

/**
* Sets the parent \a dialog in which the widget is shown.
*
* \since QGIS 3.8
*/
void setDialog( QDialog *dialog );

QgsExpressionContext createExpressionContext() const override;

private slots:
@@ -238,6 +238,11 @@ QgsExpressionContext QgsAbstractProcessingParameterWidgetWrapper::createExpressi
return QgsProcessingGuiUtils::createExpressionContext( mProcessingContextGenerator, mWidgetContext, mParameterDefinition ? mParameterDefinition->algorithm() : nullptr, linkedVectorLayer() );
}

void QgsAbstractProcessingParameterWidgetWrapper::setDialog( QDialog * )
{

}

void QgsAbstractProcessingParameterWidgetWrapper::parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper )
{
if ( wrapper )
@@ -303,6 +303,13 @@ class GUI_EXPORT QgsAbstractProcessingParameterWidgetWrapper : public QObject, p

QgsExpressionContext createExpressionContext() const override;

/**
* Sets the parent \a dialog in which the wrapper is shown.
*
* \since QGIS 3.8
*/
virtual void setDialog( QDialog *dialog );

signals:

// TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,

0 comments on commit 719a225

Please sign in to comment.
You can’t perform that action at this time.