Skip to content
Permalink
Browse files

[processing] port CRS parameter defintion widget to C++

  • Loading branch information
alexbruy committed Mar 18, 2020
1 parent 08e850d commit f4e4adbef84779a33febd13bf0c9ff672a51873c
@@ -39,7 +39,6 @@
QTextEdit)

from qgis.gui import (QgsExpressionLineEdit,
QgsProjectionSelectionWidget,
QgsProcessingLayerOutputDestinationWidget
)
from qgis.core import (QgsApplication,
@@ -91,7 +90,6 @@ def use_legacy_dialog(param=None, paramType=None):
parameters.PARAMETER_SCALE,
parameters.PARAMETER_EXPRESSION,
parameters.PARAMETER_POINT,
parameters.PARAMETER_CRS,
parameters.PARAMETER_ENUM,
parameters.PARAMETER_MATRIX,
parameters.PARAMETER_MAP_LAYER):
@@ -106,7 +104,6 @@ def use_legacy_dialog(param=None, paramType=None):
QgsProcessingParameterScale,
QgsProcessingParameterExpression,
QgsProcessingParameterPoint,
QgsProcessingParameterCrs,
QgsProcessingParameterEnum,
QgsProcessingParameterMatrix,
QgsProcessingParameterMapLayer,
@@ -339,15 +336,6 @@ def setupUi(self):
if self.param is not None:
self.defaultTextBox.setText(self.param.defaultValue())
self.verticalLayout.addWidget(self.defaultTextBox)
elif (self.paramType == parameters.PARAMETER_CRS
or isinstance(self.param, QgsProcessingParameterCrs)):
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
self.selector = QgsProjectionSelectionWidget()
if self.param is not None:
self.selector.setCrs(QgsCoordinateReferenceSystem(self.param.defaultValue()))
else:
self.selector.setCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
self.verticalLayout.addWidget(self.selector)
elif self.paramType == parameters.PARAMETER_ENUM or \
isinstance(self.param, QgsProcessingParameterEnum):
self.widget = EnumModelerWidget(self)
@@ -548,9 +536,6 @@ def accept(self):
or isinstance(self.param, QgsProcessingParameterPoint)):
self.param = QgsProcessingParameterPoint(name, description,
str(self.defaultTextBox.text()))
elif (self.paramType == parameters.PARAMETER_CRS
or isinstance(self.param, QgsProcessingParameterCrs)):
self.param = QgsProcessingParameterCrs(name, description, self.selector.crs().authid())
elif (self.paramType == parameters.PARAMETER_ENUM
or isinstance(self.param, QgsProcessingParameterEnum)):
self.param = QgsProcessingParameterEnum(name, description, self.widget.options(), self.widget.allowMultiple(), self.widget.defaultOptions())
@@ -238,6 +238,32 @@ QgsProcessingAbstractParameterDefinitionWidget *QgsProcessingBooleanWidgetWrappe
// QgsProcessingCrsWidgetWrapper
//

QgsProcessingCrsParameterDefinitionWidget::QgsProcessingCrsParameterDefinitionWidget( QgsProcessingContext &context, const QgsProcessingParameterWidgetContext &widgetContext, const QgsProcessingParameterDefinition *definition, const QgsProcessingAlgorithm *algorithm, QWidget *parent )
: QgsProcessingAbstractParameterDefinitionWidget( context, widgetContext, definition, algorithm, parent )
{
QVBoxLayout *vlayout = new QVBoxLayout();
vlayout->setMargin( 0 );
vlayout->setContentsMargins( 0, 0, 0, 0 );

vlayout->addWidget( new QLabel( tr( "Default value" ) ) );

mCrsSelector = new QgsProjectionSelectionWidget();
if ( const QgsProcessingParameterCrs *crsParam = dynamic_cast<const QgsProcessingParameterCrs *>( definition ) )
mCrsSelector->setCrs( QgsProcessingParameters::parameterAsCrs( crsParam, crsParam->defaultValue(), context ) );
else
mCrsSelector->setCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ) );

vlayout->addWidget( mCrsSelector );
setLayout( vlayout );
}

QgsProcessingParameterDefinition *QgsProcessingCrsParameterDefinitionWidget::createParameter( const QString &name, const QString &description, QgsProcessingParameterDefinition::Flags flags ) const
{
auto param = qgis::make_unique< QgsProcessingParameterCrs >( name, description, mCrsSelector->crs().authid() );
param->setFlags( flags );
return param.release();
}

QgsProcessingCrsWidgetWrapper::QgsProcessingCrsWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type, QWidget *parent )
: QgsAbstractProcessingParameterWidgetWrapper( parameter, type, parent )
{
@@ -364,6 +390,11 @@ QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingCrsWidgetWrapper::crea
return new QgsProcessingCrsWidgetWrapper( parameter, type );
}

QgsProcessingAbstractParameterDefinitionWidget *QgsProcessingCrsWidgetWrapper::createParameterDefinitionWidget( QgsProcessingContext &context, const QgsProcessingParameterWidgetContext &widgetContext, const QgsProcessingParameterDefinition *definition, const QgsProcessingAlgorithm *algorithm )
{
return new QgsProcessingCrsParameterDefinitionWidget( context, widgetContext, definition, algorithm );
}



//
@@ -118,6 +118,24 @@ class GUI_EXPORT QgsProcessingBooleanWidgetWrapper : public QgsAbstractProcessin
friend class TestProcessingGui;
};



class GUI_EXPORT QgsProcessingCrsParameterDefinitionWidget : public QgsProcessingAbstractParameterDefinitionWidget
{
Q_OBJECT
public:

QgsProcessingCrsParameterDefinitionWidget( QgsProcessingContext &context,
const QgsProcessingParameterWidgetContext &widgetContext,
const QgsProcessingParameterDefinition *definition = nullptr,
const QgsProcessingAlgorithm *algorithm = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
QgsProcessingParameterDefinition *createParameter( const QString &name, const QString &description, QgsProcessingParameterDefinition::Flags flags ) const override;

private:

QgsProjectionSelectionWidget *mCrsSelector = nullptr;
};

class GUI_EXPORT QgsProcessingCrsWidgetWrapper : public QgsAbstractProcessingParameterWidgetWrapper, public QgsProcessingParameterWidgetFactoryInterface
{
Q_OBJECT
@@ -130,6 +148,11 @@ class GUI_EXPORT QgsProcessingCrsWidgetWrapper : public QgsAbstractProcessingPar
// QgsProcessingParameterWidgetFactoryInterface
QString parameterType() const override;
QgsAbstractProcessingParameterWidgetWrapper *createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type ) override;
QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
QgsProcessingContext &context,
const QgsProcessingParameterWidgetContext &widgetContext,
const QgsProcessingParameterDefinition *definition = nullptr,
const QgsProcessingAlgorithm *algorithm = nullptr ) override;

// QgsProcessingParameterWidgetWrapper interface
QWidget *createWidget() override SIP_FACTORY;

0 comments on commit f4e4adb

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