Skip to content

Commit 7634b0b

Browse files
committed
vector file writer fixes:
* don't apply un-overridden default options * DGN: don't export attributes and fix layername to "elements"
1 parent 145a512 commit 7634b0b

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/app/ogr/qgsvectorlayersaveasdialog.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx
351351
mAttributesSelection->setEnabled( true );
352352
selectAllFields = false;
353353
}
354-
else if ( sFormat == "DXF" )
354+
else if ( sFormat == "DXF" || sFormat == "DGN" )
355355
{
356356
mAttributesSelection->setEnabled( false );
357357
selectAllFields = false;
@@ -688,24 +688,27 @@ QStringList QgsVectorLayerSaveAsDialog::datasourceOptions() const
688688
{
689689
case QgsVectorFileWriter::Int:
690690
{
691+
QgsVectorFileWriter::IntOption *opt = dynamic_cast<QgsVectorFileWriter::IntOption*>( *it );
691692
QSpinBox* sb = mDatasourceOptionsGroupBox->findChild<QSpinBox*>( it.key() );
692-
if ( sb )
693+
if ( opt && sb && sb->value() != opt->defaultValue )
693694
options << QString( "%1=%2" ).arg( it.key() ).arg( sb->value() );
694695
break;
695696
}
696697

697698
case QgsVectorFileWriter::Set:
698699
{
700+
QgsVectorFileWriter::SetOption *opt = dynamic_cast<QgsVectorFileWriter::SetOption*>( *it );
699701
QComboBox* cb = mDatasourceOptionsGroupBox->findChild<QComboBox*>( it.key() );
700-
if ( cb && !cb->itemData( cb->currentIndex() ).isNull() )
702+
if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->defaultValue )
701703
options << QString( "%1=%2" ).arg( it.key(), cb->currentText() );
702704
break;
703705
}
704706

705707
case QgsVectorFileWriter::String:
706708
{
709+
QgsVectorFileWriter::StringOption *opt = dynamic_cast<QgsVectorFileWriter::StringOption*>( *it );
707710
QLineEdit* le = mDatasourceOptionsGroupBox->findChild<QLineEdit*>( it.key() );
708-
if ( le )
711+
if ( opt && le && le->text() != opt->defaultValue )
709712
options << QString( "%1=%2" ).arg( it.key(), le->text() );
710713
break;
711714
}
@@ -740,24 +743,27 @@ QStringList QgsVectorLayerSaveAsDialog::layerOptions() const
740743
{
741744
case QgsVectorFileWriter::Int:
742745
{
746+
QgsVectorFileWriter::IntOption *opt = dynamic_cast<QgsVectorFileWriter::IntOption*>( *it );
743747
QSpinBox* sb = mLayerOptionsGroupBox->findChild<QSpinBox*>( it.key() );
744-
if ( sb )
748+
if ( opt && sb && sb->value() != opt->defaultValue )
745749
options << QString( "%1=%2" ).arg( it.key() ).arg( sb->value() );
746750
break;
747751
}
748752

749753
case QgsVectorFileWriter::Set:
750754
{
755+
QgsVectorFileWriter::SetOption *opt = dynamic_cast<QgsVectorFileWriter::SetOption*>( *it );
751756
QComboBox* cb = mLayerOptionsGroupBox->findChild<QComboBox*>( it.key() );
752-
if ( cb && !cb->itemData( cb->currentIndex() ).isNull() )
757+
if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->defaultValue )
753758
options << QString( "%1=%2" ).arg( it.key(), cb->currentText() );
754759
break;
755760
}
756761

757762
case QgsVectorFileWriter::String:
758763
{
764+
QgsVectorFileWriter::StringOption *opt = dynamic_cast<QgsVectorFileWriter::StringOption*>( *it );
759765
QLineEdit* le = mLayerOptionsGroupBox->findChild<QLineEdit*>( it.key() );
760-
if ( le && !le->text().isEmpty() )
766+
if ( opt && le && le->text() != opt->defaultValue )
761767
options << QString( "%1=%2" ).arg( it.key(), le->text() );
762768
break;
763769
}

src/core/qgsvectorfilewriter.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
306306
options = new char *[ datasourceOptions.size()+1 ];
307307
for ( int i = 0; i < datasourceOptions.size(); i++ )
308308
{
309+
QgsDebugMsg( QString( "-dsco=%1" ).arg( datasourceOptions[i] ) );
309310
options[i] = CPLStrdup( datasourceOptions[i].toLocal8Bit().constData() );
310311
}
311312
options[ datasourceOptions.size()] = nullptr;
@@ -410,6 +411,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
410411
options = new char *[ layerOptions.size()+1 ];
411412
for ( int i = 0; i < layerOptions.size(); i++ )
412413
{
414+
QgsDebugMsg( QString( "-lco=%1" ).arg( layerOptions[i] ) );
413415
options[i] = CPLStrdup( layerOptions[i].toLocal8Bit().constData() );
414416
}
415417
options[ layerOptions.size()] = nullptr;
@@ -418,10 +420,18 @@ void QgsVectorFileWriter::init( QString vectorFileName,
418420
// disable encoding conversion of OGR Shapefile layer
419421
CPLSetConfigOption( "SHAPE_ENCODING", "" );
420422

421-
if ( action == CreateOrOverwriteFile || action == CreateOrOverwriteLayer )
423+
if ( driverName == "DGN" )
424+
{
425+
mLayer = OGR_DS_GetLayerByName( mDS, "elements" );
426+
}
427+
else if ( action == CreateOrOverwriteFile || action == CreateOrOverwriteLayer )
428+
{
422429
mLayer = OGR_DS_CreateLayer( mDS, TO8F( layerName ), mOgrRef, wkbType, options );
430+
}
423431
else
432+
{
424433
mLayer = OGR_DS_GetLayerByName( mDS, TO8F( layerName ) );
434+
}
425435

426436
if ( options )
427437
{
@@ -1392,7 +1402,7 @@ QMap<QString, QgsVectorFileWriter::MetaData> QgsVectorFileWriter::initMetaData()
13921402
false // Default value
13931403
) );
13941404

1395-
datasetOptions.insert( "COPY_SEED_FILE_COLOR_TABLEE", new BoolOption(
1405+
datasetOptions.insert( "COPY_SEED_FILE_COLOR_TABLE", new BoolOption(
13961406
QObject::tr( "Indicates whether the color table should be copied from the seed file." ),
13971407
false // Default value
13981408
) );
@@ -1633,14 +1643,14 @@ QMap<QString, QgsVectorFileWriter::MetaData> QgsVectorFileWriter::initMetaData()
16331643
) );
16341644

16351645
layerOptions.insert( "SPATIAL_INDEX", new BoolOption(
1636-
QObject::tr( "If the database is of the SpatiaLite flavour, and if OGR is linked "
1646+
QObject::tr( "If the database is of the SpatiaLite flavor, and if OGR is linked "
16371647
"against libspatialite, this option can be used to control if a spatial "
16381648
"index must be created." ),
16391649
true // Default value
16401650
) );
16411651

16421652
layerOptions.insert( "COMPRESS_GEOM", new BoolOption(
1643-
QObject::tr( "If the format of the geometry BLOB is of the SpatiaLite flavour, "
1653+
QObject::tr( "If the format of the geometry BLOB is of the SpatiaLite flavor, "
16441654
"this option can be used to control if the compressed format for "
16451655
"geometries (LINESTRINGs, POLYGONs) must be used" ),
16461656
false // Default value

0 commit comments

Comments
 (0)