37 if ( !input.isValid() )
40 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
45 if ( input.type() == QVariant::String )
47 if ( input.toString().isEmpty() )
56 else if ( input.type() == QVariant::List )
58 if ( input.toList().isEmpty() )
61 const QVariantList layerList = input.toList();
62 for (
const QVariant &variantLayer : layerList )
64 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( variantLayer ) ) )
67 if ( variantLayer.type() == QVariant::String )
76 else if ( variantLayer.type() == QVariant::Map )
78 const QVariantMap layerMap = variantLayer.toMap();
80 if ( !layerMap.contains( QStringLiteral(
"layer" ) ) && !layerMap.contains( QStringLiteral(
"attributeIndex" ) ) )
95 if ( layerMap.value( QStringLiteral(
"attributeIndex" ) ).toInt() >= vectorLayer->
fields().
count() )
105 else if ( input.type() == QVariant::StringList )
107 const auto constToStringList = input.toStringList();
108 if ( constToStringList.isEmpty() )
114 for (
const QString &v : constToStringList )
128 const QList<QgsDxfExport::DxfLayer> layers =
parameterAsLayers( value, context );
131 QStringList layerDefParts;
133 if ( layer.layerOutputAttributeIndex() >= -1 )
136 const QString layerDef = QStringLiteral(
"{%1}" ).arg( layerDefParts.join(
',' ) );
139 return parts.join(
',' ).prepend(
'[' ).append(
']' );
144 switch ( outputType )
148 QString code = QStringLiteral(
"QgsProcessingParameterDxfLayers('%1', %2)" )
168 QList<QgsDxfExport::DxfLayer> layers;
170 if (
QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( layersVariant ) ) )
175 if ( layersVariant.type() == QVariant::String )
178 layers << QgsDxfExport::DxfLayer( static_cast<QgsVectorLayer *>( mapLayer ) );
180 else if ( layersVariant.type() == QVariant::List )
182 const QVariantList layersVariantList = layersVariant.toList();
183 for (
const QVariant &layerItem : layersVariantList )
185 if ( layerItem.type() == QVariant::Map )
187 const QVariantMap layerVariantMap = layerItem.toMap();
190 else if ( layerItem.type() == QVariant::String )
193 layers << QgsDxfExport::DxfLayer( static_cast<QgsVectorLayer *>( mapLayer ) );
197 else if ( layersVariant.type() == QVariant::StringList )
199 const auto layersStringList = layersVariant.toStringList();
200 for (
const QString &layerItem : layersStringList )
203 layers << QgsDxfExport::DxfLayer( static_cast<QgsVectorLayer *>( mapLayer ) );
212 const QVariant layerVariant = layerVariantMap[ QStringLiteral(
"layer" ) ];
215 if ( ( inputLayer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( layerVariant ) ) ) )
228 QgsDxfExport::DxfLayer dxfLayer( inputLayer, layerVariantMap[ QStringLiteral(
"attributeIndex" ) ].toInt() );
235 if ( !layer.
layer() )
238 vm[ QStringLiteral(
"layer" )] = layer.
layer()->
id();
@ Optional
Parameter is optional.
int count() const
Returns number of items.
Base class for all map layer types.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
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.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Layers and optional attribute index to split into multiple layers using attribute value as layer name...
QgsVectorLayer * layer() const
Returns the layer.
int layerOutputAttributeIndex() const
Returns the attribute index used to split into multiple layers.