Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[processing] Harmonize DXF Export app dialog and corresponding algorithm #39

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/PyQt6/core/auto_generated/dxf/qgsdxfexport.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Exports QGIS layers to the DXF format.

struct DxfLayer
{
DxfLayer( QgsVectorLayer *vl, int layerOutputAttributeIndex = -1, bool buildDDBlocks = true, int ddBlocksMaxNumberOfClasses = -1, QString overriddenName = QString() );
DxfLayer( QgsVectorLayer *vl, int layerOutputAttributeIndex = -1, bool buildDDBlocks = DEFAULT_DXF_DATA_DEFINED_BLOCKS, int ddBlocksMaxNumberOfClasses = -1, QString overriddenName = QString() );

QgsVectorLayer *layer() const;
%Docstring
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/dxf/qgsdxfexport.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Exports QGIS layers to the DXF format.

struct DxfLayer
{
DxfLayer( QgsVectorLayer *vl, int layerOutputAttributeIndex = -1, bool buildDDBlocks = true, int ddBlocksMaxNumberOfClasses = -1, QString overriddenName = QString() );
DxfLayer( QgsVectorLayer *vl, int layerOutputAttributeIndex = -1, bool buildDDBlocks = DEFAULT_DXF_DATA_DEFINED_BLOCKS, int ddBlocksMaxNumberOfClasses = -1, QString overriddenName = QString() );

QgsVectorLayer *layer() const;
%Docstring
Expand Down
52 changes: 44 additions & 8 deletions src/app/qgsdxfexportdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ QgsVectorLayerAndAttributeModel::QgsVectorLayerAndAttributeModel( QgsLayerTree *
const QgsVectorLayer *vLayer = qobject_cast< const QgsVectorLayer *>( QgsProject::instance()->mapLayer( id ) );
if ( vLayer )
{
mCreateDDBlockInfo[vLayer] = true;
mCreateDDBlockInfo[vLayer] = DEFAULT_DXF_DATA_DEFINED_BLOCKS;
mDDBlocksMaxNumberOfClasses[vLayer] = -1;
}
}
Expand Down Expand Up @@ -344,7 +344,7 @@ QVariant QgsVectorLayerAndAttributeModel::data( const QModelIndex &idx, int role
return QVariant();
}

bool checked = mCreateDDBlockInfo.contains( vl ) ? mCreateDDBlockInfo[vl] : true;
bool checked = mCreateDDBlockInfo.contains( vl ) ? mCreateDDBlockInfo[vl] : DEFAULT_DXF_DATA_DEFINED_BLOCKS;
if ( role == Qt::CheckStateRole )
{
return checked ? Qt::Checked : Qt::Unchecked;
Expand Down Expand Up @@ -474,7 +474,7 @@ QList< QgsDxfExport::DxfLayer > QgsVectorLayerAndAttributeModel::layers() const
layerIdx.insert( vl->id(), layers.size() );
layers << QgsDxfExport::DxfLayer( vl,
mAttributeIdx.value( vl, -1 ),
mCreateDDBlockInfo.value( vl, true ),
mCreateDDBlockInfo.value( vl, DEFAULT_DXF_DATA_DEFINED_BLOCKS ),
mDDBlocksMaxNumberOfClasses.value( vl, -1 ),
mOverriddenName.value( vl, QString() ) );
}
Expand All @@ -489,7 +489,7 @@ QList< QgsDxfExport::DxfLayer > QgsVectorLayerAndAttributeModel::layers() const
layerIdx.insert( vl->id(), layers.size() );
layers << QgsDxfExport::DxfLayer( vl,
mAttributeIdx.value( vl, -1 ),
mCreateDDBlockInfo.value( vl, true ),
mCreateDDBlockInfo.value( vl, DEFAULT_DXF_DATA_DEFINED_BLOCKS ),
mDDBlocksMaxNumberOfClasses.value( vl, -1 ),
mOverriddenName.value( vl, QString() ) );
}
Expand Down Expand Up @@ -585,15 +585,35 @@ void QgsVectorLayerAndAttributeModel::loadLayersOutputAttribute( QgsLayerTreeNod
QgsVectorLayer *vl = qobject_cast< QgsVectorLayer * >( QgsLayerTree::toLayer( child )->layer() );
if ( vl )
{
QModelIndex idx = node2index( child );

const int attributeIndex = vl->fields().lookupField( vl->customProperty( QStringLiteral( "lastDxfOutputAttribute" ), -1 ).toString() );
if ( attributeIndex > -1 )
{
mAttributeIdx[vl] = attributeIndex;

QModelIndex idx = node2index( child );
idx = index( idx.row(), 1, idx.parent() );
idx = index( idx.row(), OUTPUT_LAYER_ATTRIBUTE_COL, idx.parent() );
emit dataChanged( idx, idx, QVector<int>() << Qt::EditRole );
}

if ( vl->geometryType() == Qgis::GeometryType::Point )
{
const bool allowDataDefinedBlocks = vl->customProperty( QStringLiteral( "lastAllowDataDefinedBlocks" ), DEFAULT_DXF_DATA_DEFINED_BLOCKS ).toBool();

if ( allowDataDefinedBlocks != DEFAULT_DXF_DATA_DEFINED_BLOCKS )
{
mCreateDDBlockInfo[vl] = allowDataDefinedBlocks;
idx = index( idx.row(), ALLOW_DD_SYMBOL_BLOCKS_COL, idx.parent() );
emit dataChanged( idx, idx, QVector<int>() << Qt::CheckStateRole );
}

const int maximumNumberOfBlocks = vl->customProperty( QStringLiteral( "lastMaximumNumberOfBlocks" ), -1 ).toInt();
if ( maximumNumberOfBlocks > -1 )
{
mDDBlocksMaxNumberOfClasses[vl] = maximumNumberOfBlocks;
idx = index( idx.row(), MAXIMUM_DD_SYMBOL_BLOCKS_COL, idx.parent() );
emit dataChanged( idx, idx, QVector<int>() << Qt::EditRole );
}
}
}
}
else if ( QgsLayerTree::isGroup( child ) )
Expand All @@ -614,7 +634,7 @@ void QgsVectorLayerAndAttributeModel::saveLayersOutputAttribute( QgsLayerTreeNod
if ( vl )
{
QModelIndex idx = node2index( child );
const int attributeIndex = data( index( idx.row(), 1, idx.parent() ), Qt::EditRole ).toInt();
const int attributeIndex = data( index( idx.row(), OUTPUT_LAYER_ATTRIBUTE_COL, idx.parent() ), Qt::EditRole ).toInt();
const QgsFields fields = vl->fields();
if ( attributeIndex > -1 && attributeIndex < fields.count() )
{
Expand All @@ -624,6 +644,22 @@ void QgsVectorLayerAndAttributeModel::saveLayersOutputAttribute( QgsLayerTreeNod
{
vl->removeCustomProperty( QStringLiteral( "lastDxfOutputAttribute" ) );
}

if ( vl->geometryType() == Qgis::GeometryType::Point )
{
const bool allowDataDefinedBlocks = data( index( idx.row(), ALLOW_DD_SYMBOL_BLOCKS_COL, idx.parent() ), Qt::CheckStateRole ).toBool();
vl->setCustomProperty( QStringLiteral( "lastAllowDataDefinedBlocks" ), allowDataDefinedBlocks );

const int maximumNumberOfBlocks = data( index( idx.row(), MAXIMUM_DD_SYMBOL_BLOCKS_COL, idx.parent() ), Qt::DisplayRole ).toInt();
if ( maximumNumberOfBlocks > -1 )
{
vl->setCustomProperty( QStringLiteral( "lastMaximumNumberOfBlocks" ), maximumNumberOfBlocks );
}
else
{
vl->removeCustomProperty( QStringLiteral( "lastMaximumNumberOfBlocks" ) );
}
}
}
}
else if ( QgsLayerTree::isGroup( child ) )
Expand Down
7 changes: 5 additions & 2 deletions src/core/dxf/qgsdxfexport.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ namespace pal // SIP_SKIP
class CORE_EXPORT QgsDxfExport
{
#else

static const bool DEFAULT_DXF_DATA_DEFINED_BLOCKS = true;

class CORE_EXPORT QgsDxfExport : public QgsLabelSink
{
#endif
Expand All @@ -73,7 +76,7 @@ class CORE_EXPORT QgsDxfExport : public QgsLabelSink
*/
struct CORE_EXPORT DxfLayer
{
DxfLayer( QgsVectorLayer *vl, int layerOutputAttributeIndex = -1, bool buildDDBlocks = true, int ddBlocksMaxNumberOfClasses = -1, QString overriddenName = QString() )
DxfLayer( QgsVectorLayer *vl, int layerOutputAttributeIndex = -1, bool buildDDBlocks = DEFAULT_DXF_DATA_DEFINED_BLOCKS, int ddBlocksMaxNumberOfClasses = -1, QString overriddenName = QString() )
: mLayer( vl )
, mLayerOutputAttributeIndex( layerOutputAttributeIndex )
, mBuildDDBlocks( buildDDBlocks )
Expand Down Expand Up @@ -126,7 +129,7 @@ class CORE_EXPORT QgsDxfExport : public QgsLabelSink
/**
* \brief try to build data defined symbol blocks if necessary
*/
bool mBuildDDBlocks = false;
bool mBuildDDBlocks = DEFAULT_DXF_DATA_DEFINED_BLOCKS;

/**
* \brief Limit for the number of data defined symbol block classes (keep only the most used ones). -1 means no limit
Expand Down
16 changes: 13 additions & 3 deletions src/core/processing/qgsprocessingparameterdxflayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ bool QgsProcessingParameterDxfLayers::checkValueIsAcceptable( const QVariant &in
{
const QVariantMap layerMap = variantLayer.toMap();

if ( !layerMap.contains( QStringLiteral( "layer" ) ) && !layerMap.contains( QStringLiteral( "attributeIndex" ) ) && !layerMap.contains( QStringLiteral( "overriddenLayerName" ) ) )
if ( !layerMap.contains( QStringLiteral( "layer" ) ) &&
!layerMap.contains( QStringLiteral( "attributeIndex" ) ) &&
!layerMap.contains( QStringLiteral( "overriddenLayerName" ) ) &&
!layerMap.contains( QStringLiteral( "buildDataDefinedBlocks" ) ) &&
!layerMap.contains( QStringLiteral( "dataDefinedBlocksMaximumNumberOfClasses" ) ) )
return false;

if ( !context )
Expand Down Expand Up @@ -150,6 +154,10 @@ QString QgsProcessingParameterDxfLayers::valueAsPythonString( const QVariant &va

layerDefParts << QStringLiteral( "'overriddenLayerName': " ) + QgsProcessingUtils::stringToPythonLiteral( layer.overriddenName() );

layerDefParts << QStringLiteral( "'buildDataDefinedBlocks': " ) + QgsProcessingUtils::variantToPythonLiteral( layer.buildDataDefinedBlocks() );

layerDefParts << QStringLiteral( "'dataDefinedBlocksMaximumNumberOfClasses': " ) + QgsProcessingUtils::variantToPythonLiteral( layer.dataDefinedBlocksMaximumNumberOfClasses() );

const QString layerDef = QStringLiteral( "{%1}" ).arg( layerDefParts.join( ',' ) );
parts << layerDef;
}
Expand Down Expand Up @@ -244,8 +252,8 @@ QgsDxfExport::DxfLayer QgsProcessingParameterDxfLayers::variantMapAsLayer( const

QgsDxfExport::DxfLayer dxfLayer( inputLayer,
layerVariantMap[ QStringLiteral( "attributeIndex" ) ].toInt(),
false,
-1,
layerVariantMap[ QStringLiteral( "buildDataDefinedBlocks" ) ].toBool(),
layerVariantMap[ QStringLiteral( "dataDefinedBlocksMaximumNumberOfClasses" ) ].toInt(),
layerVariantMap[ QStringLiteral( "overriddenLayerName" ) ].toString() );
return dxfLayer;
}
Expand All @@ -259,5 +267,7 @@ QVariantMap QgsProcessingParameterDxfLayers::layerAsVariantMap( const QgsDxfExpo
vm[ QStringLiteral( "layer" )] = layer.layer()->id();
vm[ QStringLiteral( "attributeIndex" ) ] = layer.layerOutputAttributeIndex();
vm[ QStringLiteral( "overriddenLayerName" ) ] = layer.overriddenName();
vm[ QStringLiteral( "buildDataDefinedBlocks" ) ] = layer.buildDataDefinedBlocks();
vm[ QStringLiteral( "dataDefinedBlocksMaximumNumberOfClasses" ) ] = layer.dataDefinedBlocksMaximumNumberOfClasses();
return vm;
}
19 changes: 18 additions & 1 deletion src/gui/processing/qgsprocessingdxflayerswidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,31 @@ QgsProcessingDxfLayerDetailsWidget::QgsProcessingDxfLayerDetailsWidget( const QV

if ( mLayer->fields().exists( layer.layerOutputAttributeIndex() ) )
mFieldsComboBox->setField( mLayer->fields().at( layer.layerOutputAttributeIndex() ).name() );

mOverriddenName->setText( layer.overriddenName() );

if ( mLayer->geometryType() == Qgis::GeometryType::Point )
{
// Data defined blocks are only available for point layers
mGroupBoxBlocks->setVisible( true );
mGroupBoxBlocks->setChecked( layer.buildDataDefinedBlocks() );
mSpinBoxBlocks->setValue( layer.dataDefinedBlocksMaximumNumberOfClasses() );
}
else
{
mGroupBoxBlocks->setVisible( false );
}

connect( mFieldsComboBox, &QgsFieldComboBox::fieldChanged, this, &QgsPanelWidget::widgetChanged );
connect( mOverriddenName, &QLineEdit::textChanged, this, &QgsPanelWidget::widgetChanged );
connect( mGroupBoxBlocks, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
connect( mSpinBoxBlocks, &QSpinBox::textChanged, this, &QgsPanelWidget::widgetChanged );
}

QVariant QgsProcessingDxfLayerDetailsWidget::value() const
{
const int index = mLayer->fields().lookupField( mFieldsComboBox->currentField() );
const QgsDxfExport::DxfLayer layer( mLayer, index, false, -1, mOverriddenName->text().trimmed() );
const QgsDxfExport::DxfLayer layer( mLayer, index, mGroupBoxBlocks->isChecked(), mSpinBoxBlocks->value(), mOverriddenName->text().trimmed() );
return QgsProcessingParameterDxfLayers::layerAsVariantMap( layer );
}

Expand Down Expand Up @@ -107,6 +122,8 @@ QgsProcessingDxfLayersPanelWidget::QgsProcessingDxfLayersPanelWidget(
vm["layer"] = layer->id();
vm["attributeIndex"] = -1;
vm["overriddenLayerName"] = QString();
vm["buildDataDefinedBlocks"] = DEFAULT_DXF_DATA_DEFINED_BLOCKS;
vm["dataDefinedBlocksMaximumNumberOfClasses"] = -1;

const QString title = layer->name();
addOption( vm, title, false );
Expand Down
55 changes: 51 additions & 4 deletions src/ui/processing/qgsprocessingdxflayerdetailswidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@
<x>0</x>
<y>0</y>
<width>393</width>
<height>144</height>
<height>228</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1" colspan="2">
<widget class="QgsFieldComboBox" name="mFieldsComboBox"/>
</item>
<item row="3" column="2">
<item row="7" column="2">
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<item row="3" column="0" colspan="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
Expand All @@ -37,7 +40,7 @@
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Attribute</string>
<string>Output layer attribute</string>
</property>
</widget>
</item>
Expand All @@ -51,6 +54,50 @@
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="mOverriddenName"/>
</item>
<item row="2" column="0" rowspan="2" colspan="3">
<widget class="QGroupBox" name="mGroupBoxBlocks">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Allow data defined symbol blocks</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Maximum number of symbol blocks</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="mSpinBoxBlocks">
<property name="toolTip">
<string>A value of -1 means no limitation.</string>
</property>
<property name="minimum">
<number>-1</number>
</property>
<property name="value">
<number>-1</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
Expand Down
Loading
Loading