Skip to content
Permalink
Browse files

[processing] Start porting Aggregates parameters to C++

Port parameter type to c++
  • Loading branch information
nyalldawson committed Jun 3, 2020
1 parent 2f36e18 commit 4fdfa949cffb11a491b62d46db28e59cb92546ff
@@ -0,0 +1,109 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessingparameteraggregate.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsProcessingParameterAggregate : QgsProcessingParameterDefinition
{
%Docstring
A parameter for "aggregate" configurations, which consist of a definition
of desired output fields, types, and aggregate used to populate then.

Designed for use with the "Aggregate" algorithm.

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgsprocessingparameteraggregate.h"
%End
public:
QgsProcessingParameterAggregate( const QString &name, const QString &description = QString(), const QString &parentLayerParameterName = QString(), bool optional = false );
%Docstring
Constructor for QgsProcessingParameterAggregate.
%End

virtual QgsProcessingParameterDefinition *clone() const;

virtual QString type() const;

virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );

virtual QStringList dependsOnOtherParameters() const;


static QString typeName();
%Docstring
Returns the type name for the parameter class.
%End

QString parentLayerParameterName() const;
%Docstring
Returns the name of the parent layer parameter, or an empty string if this is not set.

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

void setParentLayerParameterName( const QString &name );
%Docstring
Sets the ``name`` of the parent layer parameter. Use an empty string if this is not required.

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

};



class QgsProcessingParameterTypeAggregate : QgsProcessingParameterType
{
%Docstring
Parameter type definition for QgsProcessingParameterAggregate.

.. note::

This class is not a part of public API.

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgsprocessingparameteraggregate.h"
%End
public:
virtual QgsProcessingParameterDefinition *create( const QString &name ) const /Factory/;

virtual QString description() const;

virtual QString name() const;

virtual QString id() const;

virtual QString pythonImportString() const;

virtual QString className() const;

virtual QStringList acceptedPythonTypes() const;
};


/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessingparameteraggregate.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -451,6 +451,7 @@
%Include auto_generated/processing/qgsprocessingcontext.sip
%Include auto_generated/processing/qgsprocessingfeedback.sip
%Include auto_generated/processing/qgsprocessingoutputs.sip
%Include auto_generated/processing/qgsprocessingparameteraggregate.sip
%Include auto_generated/processing/qgsprocessingparameterfieldmap.sip
%Include auto_generated/processing/qgsprocessingparameters.sip
%Include auto_generated/processing/qgsprocessingparametertype.sip
@@ -35,6 +35,7 @@
QgsProcessingParameterExpression,
QgsProcessingParameterFeatureSink,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterAggregate,
QgsProcessingException,
QgsProcessingUtils,
QgsWkbTypes,
@@ -72,50 +73,8 @@ def initAlgorithm(self, config=None):
optional=False,
parentLayerParameterName=self.INPUT))

class ParameterAggregates(QgsProcessingParameterDefinition):

def __init__(self, name, description, parentLayerParameterName='INPUT'):
super().__init__(name, description)
self._parentLayerParameter = parentLayerParameterName

def clone(self):
copy = ParameterAggregates(self.name(), self.description(), self._parentLayerParameter)
return copy

def type(self):
return 'aggregates'

def checkValueIsAcceptable(self, value, context=None):
if not isinstance(value, list):
return False
for field_def in value:
if not isinstance(field_def, dict):
return False
if not field_def.get('input', False):
return False
if not field_def.get('aggregate', False):
return False
if not field_def.get('name', False):
return False
if not field_def.get('type', False):
return False
return True

def valueAsPythonString(self, value, context):
return str(value)

def asScriptCode(self):
raise NotImplementedError()

@classmethod
def fromScriptCode(cls, name, description, isOptional, definition):
raise NotImplementedError()

def parentLayerParameter(self):
return self._parentLayerParameter

self.addParameter(ParameterAggregates(self.AGGREGATES,
description=self.tr('Aggregates')))
self.addParameter(QgsProcessingParameterAggregate(self.AGGREGATES,
description=self.tr('Aggregates'), parentLayerParameterName='INPUT'))
self.parameterDefinition(self.AGGREGATES).setMetadata({
'widget_wrapper': 'processing.algs.qgis.ui.AggregatesPanel.AggregatesWidgetWrapper'
})
@@ -147,6 +147,7 @@ SET(QGIS_CORE_SRCS
processing/qgsprocessingcontext.cpp
processing/qgsprocessingfeedback.cpp
processing/qgsprocessingoutputs.cpp
processing/qgsprocessingparameteraggregate.cpp
processing/qgsprocessingparameterfieldmap.cpp
processing/qgsprocessingparameters.cpp
processing/qgsprocessingparametertype.cpp
@@ -1270,6 +1271,7 @@ SET(QGIS_CORE_HDRS
processing/qgsprocessingcontext.h
processing/qgsprocessingfeedback.h
processing/qgsprocessingoutputs.h
processing/qgsprocessingparameteraggregate.h
processing/qgsprocessingparameterfieldmap.h
processing/qgsprocessingparameters.h
processing/qgsprocessingparametertype.h
@@ -0,0 +1,121 @@
/***************************************************************************
qgsprocessingparameteraggregate.cpp
-------------------------
begin : June 2020
copyright : (C) 2020 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsprocessingparameteraggregate.h"

#include "qgsvectorlayer.h"


QgsProcessingParameterAggregate::QgsProcessingParameterAggregate( const QString &name, const QString &description, const QString &parentLayerParameterName, bool optional )
: QgsProcessingParameterDefinition( name, description, QVariant(), optional )
, mParentLayerParameterName( parentLayerParameterName )
{
}

QgsProcessingParameterDefinition *QgsProcessingParameterAggregate::clone() const
{
return new QgsProcessingParameterAggregate( *this );
}

QString QgsProcessingParameterAggregate::type() const
{
return typeName();
}

bool QgsProcessingParameterAggregate::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const
{
if ( !input.isValid() )
return mFlags & FlagOptional;

if ( input.type() != QVariant::List )
return false;

const QVariantList inputList = input.toList();
for ( const QVariant &inputItem : inputList )
{
if ( inputItem.type() != QVariant::Map )
return false;

const QVariantMap inputItemMap = inputItem.toMap();

if ( !inputItemMap.contains( "name" ) )
return false;
if ( !inputItemMap.contains( "type" ) )
return false;
if ( !inputItemMap.contains( "input" ) )
return false;
if ( !inputItemMap.contains( "aggregate" ) )
return false;
}

return true;
}

QString QgsProcessingParameterAggregate::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
{
return QgsProcessingUtils::variantToPythonLiteral( value );
}

QString QgsProcessingParameterAggregate::asPythonString( QgsProcessing::PythonOutputType outputType ) const
{
switch ( outputType )
{
case QgsProcessing::PythonQgsProcessingAlgorithmSubclass:
{
QString code = QStringLiteral( "QgsProcessingParameterAggregate('%1', '%2'" ).arg( name(), description() );
if ( !mParentLayerParameterName.isEmpty() )
code += QStringLiteral( ", parentLayerParameterName=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( mParentLayerParameterName ) );

if ( mFlags & FlagOptional )
code += QStringLiteral( ", optional=True" );
code += ')';
return code;
}
}
return QString();
}

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

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

QStringList QgsProcessingParameterAggregate::dependsOnOtherParameters() const
{
QStringList depends;
if ( !mParentLayerParameterName.isEmpty() )
depends << mParentLayerParameterName;
return depends;
}

QString QgsProcessingParameterAggregate::parentLayerParameterName() const
{
return mParentLayerParameterName;
}

void QgsProcessingParameterAggregate::setParentLayerParameterName( const QString &name )
{
mParentLayerParameterName = name;
}

0 comments on commit 4fdfa94

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