Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add map support to QgsProcessingUtils::variantToPythonLiteral
- Loading branch information
1 parent
a8de679
commit 95387cf
Showing
7 changed files
with
346 additions
and
0 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
python/core/auto_generated/processing/qgsprocessingparameterfieldmap.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,107 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/processing/qgsprocessingparameterfieldmap.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
class QgsProcessingParameterFieldMapping : QgsProcessingParameterDefinition | ||
{ | ||
%Docstring | ||
|
||
.. note:: | ||
|
||
This class is not a part of public API. | ||
|
||
.. versionadded:: 3.14 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsprocessingparameterfieldmap.h" | ||
%End | ||
public: | ||
QgsProcessingParameterFieldMapping( const QString &name, const QString &description = QString(), const QString &parentLayerParameterName = QString() ); | ||
%Docstring | ||
Constructor for QgsProcessingParameterFieldMapping. | ||
%End | ||
|
||
virtual QgsProcessingParameterDefinition *clone() const; | ||
|
||
virtual QString type() const; | ||
|
||
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context ) 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 ); | ||
|
||
|
||
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 QgsProcessingParameterTypeFieldMapping : QgsProcessingParameterType | ||
{ | ||
%Docstring | ||
Parameter type definition for QgsProcessingParameterFieldMapping. | ||
|
||
.. note:: | ||
|
||
This class is not a part of public API. | ||
|
||
.. versionadded:: 3.14 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsprocessingparameterfieldmap.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/qgsprocessingparameterfieldmap.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/*************************************************************************** | ||
qgsprocessingparameterfieldmap.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 "qgsprocessingparameterfieldmap.h" | ||
|
||
#include "qgsvectorlayer.h" | ||
|
||
|
||
QgsProcessingParameterFieldMapping::QgsProcessingParameterFieldMapping( const QString &name, const QString &description, const QString &parentLayerParameterName ) | ||
: QgsProcessingParameterDefinition( name, description, QVariant(), false ) | ||
, mParentLayerParameterName( parentLayerParameterName ) | ||
{ | ||
} | ||
|
||
QgsProcessingParameterDefinition *QgsProcessingParameterFieldMapping::clone() const | ||
{ | ||
return new QgsProcessingParameterFieldMapping( *this ); | ||
} | ||
|
||
QString QgsProcessingParameterFieldMapping::type() const | ||
{ | ||
return typeName(); | ||
} | ||
|
||
bool QgsProcessingParameterFieldMapping::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context ) 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( "expression" ) ) | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
QString QgsProcessingParameterFieldMapping::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const | ||
{ | ||
QStringList parts; | ||
|
||
// TODO | ||
|
||
return parts.join( ',' ).prepend( '[' ).append( ']' ); | ||
} | ||
|
||
QString QgsProcessingParameterFieldMapping::asPythonString( QgsProcessing::PythonOutputType outputType ) const | ||
{ | ||
switch ( outputType ) | ||
{ | ||
case QgsProcessing::PythonQgsProcessingAlgorithmSubclass: | ||
{ | ||
QString code = QStringLiteral( "QgsProcessingParameterVectorTileWriterLayers('%1', '%2')" ).arg( name(), description() ); | ||
return code; | ||
} | ||
} | ||
return QString(); | ||
} | ||
|
||
QVariantMap QgsProcessingParameterFieldMapping::toVariantMap() const | ||
{ | ||
|
||
} | ||
|
||
bool QgsProcessingParameterFieldMapping::fromVariantMap( const QVariantMap &map ) | ||
{ | ||
|
||
} | ||
|
||
QString QgsProcessingParameterFieldMapping::parentLayerParameterName() const | ||
{ | ||
return mParentLayerParameterName; | ||
} | ||
|
||
void QgsProcessingParameterFieldMapping::setParentLayerParameterName( const QString &name ) | ||
{ | ||
mParentLayerParameterName = name; | ||
} | ||
|
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,113 @@ | ||
/*************************************************************************** | ||
qgsprocessingparameterfieldmap.h | ||
------------------------- | ||
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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSPROCESSINGPARAMETERFIELDMAP_H | ||
#define QGSPROCESSINGPARAMETERFIELDMAP_H | ||
|
||
#include "qgsprocessingparameters.h" | ||
#include "qgsprocessingparametertype.h" | ||
#include "qgsvectortilewriter.h" | ||
|
||
|
||
/** | ||
* \ingroup core | ||
* \note This class is not a part of public API. | ||
* \since QGIS 3.14 | ||
*/ | ||
class CORE_EXPORT QgsProcessingParameterFieldMapping : public QgsProcessingParameterDefinition | ||
{ | ||
public: | ||
//! Constructor for QgsProcessingParameterFieldMapping. | ||
QgsProcessingParameterFieldMapping( const QString &name, const QString &description = QString(), const QString &parentLayerParameterName = QString() ); | ||
|
||
QgsProcessingParameterDefinition *clone() const override; | ||
QString type() const override; | ||
bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override; | ||
QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override; | ||
QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const override; | ||
QVariantMap toVariantMap() const override; | ||
bool fromVariantMap( const QVariantMap &map ) override; | ||
|
||
//! Returns the type name for the parameter class. | ||
static QString typeName() { return QStringLiteral( "fields_mapping" ); } | ||
|
||
/** | ||
* Returns the name of the parent layer parameter, or an empty string if this is not set. | ||
* \see setParentLayerParameterName() | ||
*/ | ||
QString parentLayerParameterName() const; | ||
|
||
/** | ||
* Sets the \a name of the parent layer parameter. Use an empty string if this is not required. | ||
* \see parentLayerParameterName() | ||
*/ | ||
void setParentLayerParameterName( const QString &name ); | ||
|
||
private: | ||
QString mParentLayerParameterName; | ||
|
||
}; | ||
|
||
///@cond PRIVATE | ||
|
||
/** | ||
* Parameter type definition for QgsProcessingParameterFieldMapping. | ||
* | ||
* \ingroup core | ||
* \note This class is not a part of public API. | ||
* \since QGIS 3.14 | ||
*/ | ||
class CORE_EXPORT QgsProcessingParameterTypeFieldMapping : public QgsProcessingParameterType | ||
{ | ||
public: | ||
QgsProcessingParameterDefinition *create( const QString &name ) const override SIP_FACTORY | ||
{ | ||
return new QgsProcessingParameterFieldMapping( name ); | ||
} | ||
|
||
QString description() const override | ||
{ | ||
return QCoreApplication::translate( "Processing", "A mapping of field names to field type definitions and expressions. Used for the refactor fields algorithm." ); | ||
} | ||
|
||
QString name() const override | ||
{ | ||
return QCoreApplication::translate( "Processing", "Fields Mapper" ); | ||
} | ||
|
||
QString id() const override | ||
{ | ||
return QgsProcessingParameterFieldMapping::typeName(); | ||
} | ||
|
||
QString pythonImportString() const override | ||
{ | ||
return QStringLiteral( "from qgis.core import QgsProcessingParameterFieldMapping" ); | ||
} | ||
|
||
QString className() const override | ||
{ | ||
return QStringLiteral( "QgsProcessingParameterFieldMapping" ); | ||
} | ||
|
||
QStringList acceptedPythonTypes() const override | ||
{ | ||
return QStringList() << QObject::tr( "list[dict]: list of field definitions as dictionaries" ); | ||
} | ||
}; | ||
|
||
///@endcond | ||
|
||
#endif // QGSPROCESSINGPARAMETERFIELDMAP_H |
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