37 if ( !input.isValid() )
47 if ( input.userType() == QMetaType::Type::QString )
49 if ( input.toString().isEmpty() )
58 else if ( input.userType() == QMetaType::Type::QVariantList )
60 if ( input.toList().isEmpty() )
63 const QVariantList layerList = input.toList();
64 for (
const QVariant &variantLayer : layerList )
75 if ( variantLayer.userType() == QMetaType::Type::QString )
84 else if ( variantLayer.userType() == QMetaType::Type::QVariantMap )
86 const QVariantMap layerMap = variantLayer.toMap();
88 if ( !layerMap.contains( QStringLiteral(
"layer" ) ) &&
89 !layerMap.contains( QStringLiteral(
"attributeIndex" ) ) &&
90 !layerMap.contains( QStringLiteral(
"overriddenLayerName" ) ) &&
91 !layerMap.contains( QStringLiteral(
"buildDataDefinedBlocks" ) ) &&
92 !layerMap.contains( QStringLiteral(
"dataDefinedBlocksMaximumNumberOfClasses" ) ) )
107 if ( layerMap.value( QStringLiteral(
"attributeIndex" ) ).toInt() >= vectorLayer->
fields().
count() )
117 else if ( input.userType() == QMetaType::Type::QStringList )
119 const auto constToStringList = input.toStringList();
120 if ( constToStringList.isEmpty() )
126 for (
const QString &v : constToStringList )
146 const QList<QgsDxfExport::DxfLayer> layers =
parameterAsLayers( value, context );
149 QStringList layerDefParts;
152 if ( layer.layerOutputAttributeIndex() >= -1 )
161 const QString layerDef = QStringLiteral(
"{%1}" ).arg( layerDefParts.join(
',' ) );
164 return parts.join(
',' ).prepend(
'[' ).append(
']' );
169 switch ( outputType )
173 QString code = QStringLiteral(
"QgsProcessingParameterDxfLayers('%1', %2)" )
193 QList<QgsDxfExport::DxfLayer> layers;
195 if (
QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( layersVariant ) ) )
200 if ( layersVariant.userType() == QMetaType::Type::QString )
203 layers << QgsDxfExport::DxfLayer( static_cast<QgsVectorLayer *>( mapLayer ) );
205 else if ( layersVariant.userType() == QMetaType::Type::QVariantList )
207 const QVariantList layersVariantList = layersVariant.toList();
208 for (
const QVariant &layerItem : layersVariantList )
210 if ( layerItem.userType() == QMetaType::Type::QVariantMap )
212 const QVariantMap layerVariantMap = layerItem.toMap();
215 else if ( layerItem.userType() == QMetaType::Type::QString )
218 layers << QgsDxfExport::DxfLayer( static_cast<QgsVectorLayer *>( mapLayer ) );
222 else if ( layersVariant.userType() == QMetaType::Type::QStringList )
224 const auto layersStringList = layersVariant.toStringList();
225 for (
const QString &layerItem : layersStringList )
228 layers << QgsDxfExport::DxfLayer( static_cast<QgsVectorLayer *>( mapLayer ) );
237 const QVariant layerVariant = layerVariantMap[ QStringLiteral(
"layer" ) ];
240 if ( ( inputLayer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( layerVariant ) ) ) )
254 layerVariantMap[ QStringLiteral(
"attributeIndex" ) ].toInt(),
255 layerVariantMap[ QStringLiteral(
"buildDataDefinedBlocks" ) ].toBool(),
256 layerVariantMap[ QStringLiteral(
"dataDefinedBlocksMaximumNumberOfClasses" ) ].toInt(),
257 layerVariantMap[ QStringLiteral(
"overriddenLayerName" ) ].toString() );
264 if ( !layer.
layer() )
267 vm[ QStringLiteral(
"layer" )] = layer.
layer()->
id();
269 vm[ QStringLiteral(
"overriddenLayerName" ) ] = layer.
overriddenName();
@ Optional
Parameter is optional.
Base class for all map layer types.
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
Contains information about the context in which a processing algorithm is executed.
Base class for the definition of processing parameters.
QString valueAsStringPrivate(const QVariant &value, QgsProcessingContext &context, bool &ok, ValueAsStringFlags flags) const
Internal method for evaluating values as string.
Qgis::ProcessingParameterFlags mFlags
Parameter flags.
@ AllowMapLayerValues
Enable map layer value handling.
QString description() const
Returns the description for the parameter.
QString name() const
Returns the name of the parameter.
QVariant valueAsJsonObjectPrivate(const QVariant &value, QgsProcessingContext &context, ValueAsStringFlags flags) const
Internal method for evaluating values as JSON objects.
A parameter for Processing algorithms that need a list of input vector layers to export as DXF file -...
static QVariantMap layerAsVariantMap(const QgsDxfExport::DxfLayer &layer)
Converts a single input layer to QVariant representation (a QVariantMap)
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterDxfLayers(const QString &name, const QString &description=QString())
Constructor for QgsProcessingParameterDxfLayers.
QString type() const override
Unique parameter type name.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QgsDxfExport::DxfLayer variantMapAsLayer(const QVariantMap &layerVariantMap, QgsProcessingContext &context)
Converts a QVariant value (a QVariantMap) to a single input layer.
static QString typeName()
Returns the type name for the parameter class.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
static QList< QgsDxfExport::DxfLayer > parameterAsLayers(const QVariant &layersVariant, QgsProcessingContext &context)
Converts a QVariant value (a QVariantList) to a list of input layers.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
static QString stringToPythonLiteral(const QString &string)
Converts a string to a Python string literal.
static QString normalizeLayerSource(const QString &source)
Normalizes a layer source string for safe comparison across different operating system environments.
static QString variantToPythonLiteral(const QVariant &value)
Converts a variant to a Python literal.
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, QgsProcessingUtils::LayerHint typeHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Interprets a string as a map layer within the supplied context.
PythonOutputType
Available Python output types.
@ PythonQgsProcessingAlgorithmSubclass
Full Python QgsProcessingAlgorithm subclass.
Represents a vector layer which manages a vector based data sets.
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
Layers and optional attribute index to split into multiple layers using attribute value as layer name...
QString overriddenName() const
Returns the overridden layer name to be used in the exported DXF.
bool buildDataDefinedBlocks() const
Flag if data defined point block symbols should be created.
QgsVectorLayer * layer() const
Returns the layer.
int dataDefinedBlocksMaximumNumberOfClasses() const
Returns the maximum number of data defined symbol classes for which blocks are created.
int layerOutputAttributeIndex() const
Returns the attribute index used to split into multiple layers.