Skip to content

Commit

Permalink
[processing] more consistent naming for class members, setters and
Browse files Browse the repository at this point in the history
getters
  • Loading branch information
alexbruy committed Aug 4, 2017
1 parent aad566e commit 9fe326d
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 82 deletions.
24 changes: 12 additions & 12 deletions python/core/processing/qgsprocessingparameters.sip
Original file line number Diff line number Diff line change
Expand Up @@ -1358,17 +1358,17 @@ class QgsProcessingParameterExpression : QgsProcessingParameterDefinition
virtual QStringList dependsOnOtherParameters() const;


QString parentLayerParameter() const;
QString parentLayerParameterName() const;
%Docstring
Returns the name of the parent layer parameter, or an empty string if this is not set.
.. seealso:: setParentLayerParameter()
.. seealso:: setParentLayerParameterName()
:rtype: str
%End

void setParentLayerParameter( const QString &parentLayerParameter );
void setParentLayerParameterName( const QString &parentLayerParameterName );
%Docstring
Sets the name of the parent layer parameter. Use an empty string if this is not required.
.. seealso:: parentLayerParameter()
.. seealso:: parentLayerParameterName()
%End

virtual QVariantMap toVariantMap() const;
Expand Down Expand Up @@ -1487,17 +1487,17 @@ class QgsProcessingParameterField : QgsProcessingParameterDefinition
virtual QStringList dependsOnOtherParameters() const;


QString parentLayerParameter() const;
QString parentLayerParameterName() const;
%Docstring
Returns the name of the parent layer parameter, or an empty string if this is not set.
.. seealso:: setParentLayerParameter()
.. seealso:: setParentLayerParameterName()
:rtype: str
%End

void setParentLayerParameter( const QString &parentLayerParameter );
void setParentLayerParameterName( const QString &parentLayerParameterName );
%Docstring
Sets the name of the parent layer parameter. Use an empty string if this is not required.
.. seealso:: parentLayerParameter()
.. seealso:: parentLayerParameterName()
%End

DataType dataType() const;
Expand Down Expand Up @@ -2006,17 +2006,17 @@ class QgsProcessingParameterBand : QgsProcessingParameterDefinition
virtual QStringList dependsOnOtherParameters() const;


QString parentLayerParameter() const;
QString parentLayerParameterName() const;
%Docstring
Returns the name of the parent layer parameter, or an empty string if this is not set.
.. seealso:: setParentLayerParameter()
.. seealso:: setParentLayerParameterName()
:rtype: str
%End

void setParentLayerParameter( const QString &parentLayerParameter );
void setParentLayerParameterName( const QString &parentLayerParameterName );
%Docstring
Sets the name of the parent layer parameter. Use an empty string if this is not required.
.. seealso:: parentLayerParameter()
.. seealso:: parentLayerParameterName()
%End

virtual QVariantMap toVariantMap() const;
Expand Down
10 changes: 4 additions & 6 deletions python/plugins/processing/gui/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ class ExpressionWidgetWrapper(WidgetWrapper):

def createWidget(self):
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
if self.param.parentLayerParameter():
if self.param.parentLayerParameterName():
widget = QgsFieldExpressionWidget()
else:
widget = QgsExpressionLineEdit()
Expand All @@ -1010,7 +1010,7 @@ def createWidget(self):

def postInitialize(self, wrappers):
for wrapper in wrappers:
if wrapper.param.name() == self.param.parentLayerParameter():
if wrapper.param.name() == self.param.parentLayerParameterName():
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
self.setLayer(wrapper.value())
wrapper.widgetValueHasChanged.connect(self.parentLayerChanged)
Expand Down Expand Up @@ -1187,7 +1187,7 @@ def createWidget(self):

def postInitialize(self, wrappers):
for wrapper in wrappers:
if wrapper.param.name() == self.param.parentLayerParameter():
if wrapper.param.name() == self.param.parentLayerParameterName():
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
self.setLayer(wrapper.value())
wrapper.widgetValueHasChanged.connect(self.parentValueChanged)
Expand Down Expand Up @@ -1282,10 +1282,8 @@ def createWidget(self):
return widget

def postInitialize(self, wrappers):
print(self.param)
print(self.param.parentLayerParameter)
for wrapper in wrappers:
if wrapper.param.name() == self.param.parentLayerParameter():
if wrapper.param.name() == self.param.parentLayerParameterName():
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
self.setLayer(wrapper.value())
wrapper.widgetValueHasChanged.connect(self.parentValueChanged)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def setupUi(self):
if isinstance(definition, (QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer)):
self.parentCombo.addItem(definition.description(), definition.name())
if self.param is not None:
if self.param.parentLayerParameter() == definition.name():
if self.param.parentLayerParameterName() == definition.name():
self.parentCombo.setCurrentIndex(idx)
idx += 1
self.verticalLayout.addWidget(self.parentCombo)
Expand Down Expand Up @@ -180,7 +180,7 @@ def setupUi(self):
if isinstance(definition, (QgsProcessingParameterRasterLayer)):
self.parentCombo.addItem(definition.description(), definition.name())
if self.param is not None:
if self.param.parentLayerParameter() == definition.name():
if self.param.parentLayerParameterName() == definition.name():
self.parentCombo.setCurrentIndex(idx)
idx += 1
self.verticalLayout.addWidget(self.parentCombo)
Expand Down Expand Up @@ -246,7 +246,7 @@ def setupUi(self):
if isinstance(definition, (QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer)):
self.parentCombo.addItem(definition.description(), definition.name())
if self.param is not None:
if self.param.parentLayerParameter() == definition.name():
if self.param.parentLayerParameterName() == definition.name():
self.parentCombo.setCurrentIndex(idx)
idx += 1
self.verticalLayout.addWidget(self.parentCombo)
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/modeler/ModelerScene.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def paintModel(self, model, controls=True):
for input_name in list(model.parameterComponents().keys()):
idx = 0
parameter_def = model.parameterDefinition(input_name)
if hasattr(parameter_def, 'parentLayerParameter') and parameter_def.parentLayerParameter():
parent_name = parameter_def.parentLayerParameter()
if hasattr(parameter_def, 'parentLayerParameterName') and parameter_def.parentLayerParameterName():
parent_name = parameter_def.parentLayerParameterName()
if input_name in self.paramItems and parent_name in self.paramItems:
input_item = self.paramItems[input_name]
parent_item = self.paramItems[parent_name]
Expand Down
58 changes: 29 additions & 29 deletions src/core/processing/qgsprocessingparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,7 @@ QgsProcessingParameterString *QgsProcessingParameterString::fromScriptCode( cons

QgsProcessingParameterExpression::QgsProcessingParameterExpression( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional )
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
, mParentLayerParameter( parentLayerParameterName )
, mParentLayerParameterName( parentLayerParameterName )
{

}
Expand All @@ -2066,32 +2066,32 @@ QString QgsProcessingParameterExpression::valueAsPythonString( const QVariant &v
QStringList QgsProcessingParameterExpression::dependsOnOtherParameters() const
{
QStringList depends;
if ( !mParentLayerParameter.isEmpty() )
depends << mParentLayerParameter;
if ( !mParentLayerParameterName.isEmpty() )
depends << mParentLayerParameterName;
return depends;
}

QString QgsProcessingParameterExpression::parentLayerParameter() const
QString QgsProcessingParameterExpression::parentLayerParameterName() const
{
return mParentLayerParameter;
return mParentLayerParameterName;
}

void QgsProcessingParameterExpression::setParentLayerParameter( const QString &parentLayerParameter )
void QgsProcessingParameterExpression::setParentLayerParameterName( const QString &parentLayerParameterName )
{
mParentLayerParameter = parentLayerParameter;
mParentLayerParameterName = parentLayerParameterName;
}

QVariantMap QgsProcessingParameterExpression::toVariantMap() const
{
QVariantMap map = QgsProcessingParameterDefinition::toVariantMap();
map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameter );
map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
return map;
}

bool QgsProcessingParameterExpression::fromVariantMap( const QVariantMap &map )
{
QgsProcessingParameterDefinition::fromVariantMap( map );
mParentLayerParameter = map.value( QStringLiteral( "parent_layer" ) ).toString();
mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
return true;
}

Expand Down Expand Up @@ -2188,7 +2188,7 @@ QgsProcessingParameterVectorLayer *QgsProcessingParameterVectorLayer::fromScript

QgsProcessingParameterField::QgsProcessingParameterField( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, DataType type, bool allowMultiple, bool optional )
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
, mParentLayerParameter( parentLayerParameterName )
, mParentLayerParameterName( parentLayerParameterName )
, mDataType( type )
, mAllowMultiple( allowMultiple )
{
Expand Down Expand Up @@ -2282,7 +2282,7 @@ QString QgsProcessingParameterField::asScriptCode() const
if ( mAllowMultiple )
code += QStringLiteral( "multiple " );

code += mParentLayerParameter + ' ';
code += mParentLayerParameterName + ' ';

code += mDefault.toString();
return code.trimmed();
Expand All @@ -2291,19 +2291,19 @@ QString QgsProcessingParameterField::asScriptCode() const
QStringList QgsProcessingParameterField::dependsOnOtherParameters() const
{
QStringList depends;
if ( !mParentLayerParameter.isEmpty() )
depends << mParentLayerParameter;
if ( !mParentLayerParameterName.isEmpty() )
depends << mParentLayerParameterName;
return depends;
}

QString QgsProcessingParameterField::parentLayerParameter() const
QString QgsProcessingParameterField::parentLayerParameterName() const
{
return mParentLayerParameter;
return mParentLayerParameterName;
}

void QgsProcessingParameterField::setParentLayerParameter( const QString &parentLayerParameter )
void QgsProcessingParameterField::setParentLayerParameterName( const QString &parentLayerParameterName )
{
mParentLayerParameter = parentLayerParameter;
mParentLayerParameterName = parentLayerParameterName;
}

QgsProcessingParameterField::DataType QgsProcessingParameterField::dataType() const
Expand All @@ -2329,7 +2329,7 @@ void QgsProcessingParameterField::setAllowMultiple( bool allowMultiple )
QVariantMap QgsProcessingParameterField::toVariantMap() const
{
QVariantMap map = QgsProcessingParameterDefinition::toVariantMap();
map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameter );
map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
map.insert( QStringLiteral( "data_type" ), mDataType );
map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
return map;
Expand All @@ -2338,7 +2338,7 @@ QVariantMap QgsProcessingParameterField::toVariantMap() const
bool QgsProcessingParameterField::fromVariantMap( const QVariantMap &map )
{
QgsProcessingParameterDefinition::fromVariantMap( map );
mParentLayerParameter = map.value( QStringLiteral( "parent_layer" ) ).toString();
mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
mDataType = static_cast< DataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
return true;
Expand Down Expand Up @@ -3152,7 +3152,7 @@ QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination

QgsProcessingParameterBand::QgsProcessingParameterBand( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional )
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
, mParentLayerParameter( parentLayerParameterName )
, mParentLayerParameterName( parentLayerParameterName )
{

}
Expand Down Expand Up @@ -3191,7 +3191,7 @@ QString QgsProcessingParameterBand::asScriptCode() const
code += QStringLiteral( "optional " );
code += QStringLiteral( "band " );

code += mParentLayerParameter + ' ';
code += mParentLayerParameterName + ' ';

code += mDefault.toString();
return code.trimmed();
Expand All @@ -3200,32 +3200,32 @@ QString QgsProcessingParameterBand::asScriptCode() const
QStringList QgsProcessingParameterBand::dependsOnOtherParameters() const
{
QStringList depends;
if ( !mParentLayerParameter.isEmpty() )
depends << mParentLayerParameter;
if ( !mParentLayerParameterName.isEmpty() )
depends << mParentLayerParameterName;
return depends;
}

QString QgsProcessingParameterBand::parentLayerParameter() const
QString QgsProcessingParameterBand::parentLayerParameterName() const
{
return mParentLayerParameter;
return mParentLayerParameterName;
}

void QgsProcessingParameterBand::setParentLayerParameter( const QString &parentLayerParameter )
void QgsProcessingParameterBand::setParentLayerParameterName( const QString &parentLayerParameterName )
{
mParentLayerParameter = parentLayerParameter;
mParentLayerParameterName = parentLayerParameterName;
}

QVariantMap QgsProcessingParameterBand::toVariantMap() const
{
QVariantMap map = QgsProcessingParameterDefinition::toVariantMap();
map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameter );
map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
return map;
}

bool QgsProcessingParameterBand::fromVariantMap( const QVariantMap &map )
{
QgsProcessingParameterDefinition::fromVariantMap( map );
mParentLayerParameter = map.value( QStringLiteral( "parent_layer" ) ).toString();
mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
return true;
}

Expand Down
Loading

0 comments on commit 9fe326d

Please sign in to comment.