Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processing] Start porting Aggregates parameters to C++
Port parameter type to c++
- Loading branch information
1 parent
2f36e18
commit 4fdfa94
Showing
8 changed files
with
427 additions
and
44 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
python/core/auto_generated/processing/qgsprocessingparameteraggregate.sip.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/core/processing/qgsprocessingparameteraggregate.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
Oops, something went wrong.