Skip to content

Commit 9a6235d

Browse files
committedJun 13, 2017
vector file writer fixes:
* don't apply un-overridden default options * DGN: don't export attributes and fix layername to "elements" (cherry picked from commit 7634b0b)
1 parent 8d35a42 commit 9a6235d

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed
 

‎src/app/ogr/qgsvectorlayersaveasdialog.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx
347347
bool fieldsAsDisplayedValues = false;
348348

349349
const QString sFormat( format() );
350-
if ( sFormat == QLatin1String( "DXF" ) )
350+
if ( sFormat == QLatin1String( "DXF" ) || sFormat == QLatin1String( "DGN" ) )
351351
{
352352
mAttributesSelection->setEnabled( false );
353353
selectAllFields = false;
@@ -686,24 +686,27 @@ QStringList QgsVectorLayerSaveAsDialog::datasourceOptions() const
686686
{
687687
case QgsVectorFileWriter::Int:
688688
{
689+
QgsVectorFileWriter::IntOption *opt = dynamic_cast<QgsVectorFileWriter::IntOption *>( *it );
689690
QSpinBox *sb = mDatasourceOptionsGroupBox->findChild<QSpinBox *>( it.key() );
690-
if ( sb )
691+
if ( opt && sb && sb->value() != opt->defaultValue )
691692
options << QStringLiteral( "%1=%2" ).arg( it.key() ).arg( sb->value() );
692693
break;
693694
}
694695

695696
case QgsVectorFileWriter::Set:
696697
{
698+
QgsVectorFileWriter::SetOption *opt = dynamic_cast<QgsVectorFileWriter::SetOption *>( *it );
697699
QComboBox *cb = mDatasourceOptionsGroupBox->findChild<QComboBox *>( it.key() );
698-
if ( cb && !cb->currentData().isNull() )
700+
if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->defaultValue )
699701
options << QStringLiteral( "%1=%2" ).arg( it.key(), cb->currentText() );
700702
break;
701703
}
702704

703705
case QgsVectorFileWriter::String:
704706
{
707+
QgsVectorFileWriter::StringOption *opt = dynamic_cast<QgsVectorFileWriter::StringOption *>( *it );
705708
QLineEdit *le = mDatasourceOptionsGroupBox->findChild<QLineEdit *>( it.key() );
706-
if ( le )
709+
if ( opt && le && le->text() != opt->defaultValue )
707710
options << QStringLiteral( "%1=%2" ).arg( it.key(), le->text() );
708711
break;
709712
}
@@ -738,24 +741,26 @@ QStringList QgsVectorLayerSaveAsDialog::layerOptions() const
738741
{
739742
case QgsVectorFileWriter::Int:
740743
{
744+
QgsVectorFileWriter::IntOption *opt = dynamic_cast<QgsVectorFileWriter::IntOption *>( *it );
741745
QSpinBox *sb = mLayerOptionsGroupBox->findChild<QSpinBox *>( it.key() );
742-
if ( sb )
743-
options << QStringLiteral( "%1=%2" ).arg( it.key() ).arg( sb->value() );
Code has comments. Press enter to view.
744-
break;
746+
if ( opt && sb && sb->value() != opt->defaultValue )
747+
break;
745748
}
746749

747750
case QgsVectorFileWriter::Set:
748751
{
752+
QgsVectorFileWriter::SetOption *opt = dynamic_cast<QgsVectorFileWriter::SetOption *>( *it );
749753
QComboBox *cb = mLayerOptionsGroupBox->findChild<QComboBox *>( it.key() );
750-
if ( cb && !cb->currentData().isNull() )
754+
if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->defaultValue )
751755
options << QStringLiteral( "%1=%2" ).arg( it.key(), cb->currentText() );
752756
break;
753757
}
754758

755759
case QgsVectorFileWriter::String:
756760
{
761+
QgsVectorFileWriter::StringOption *opt = dynamic_cast<QgsVectorFileWriter::StringOption *>( *it );
757762
QLineEdit *le = mLayerOptionsGroupBox->findChild<QLineEdit *>( it.key() );
758-
if ( le && !le->text().isEmpty() )
763+
if ( opt && le && le->text() != opt->defaultValue )
759764
options << QStringLiteral( "%1=%2" ).arg( it.key(), le->text() );
760765
break;
761766
}

‎src/core/qgsvectorfilewriter.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
270270
options = new char *[ datasourceOptions.size() + 1 ];
271271
for ( int i = 0; i < datasourceOptions.size(); i++ )
272272
{
273+
QgsDebugMsg( QString( "-dsco=%1" ).arg( datasourceOptions[i] ) );
273274
options[i] = CPLStrdup( datasourceOptions[i].toLocal8Bit().constData() );
274275
}
275276
options[ datasourceOptions.size()] = nullptr;
@@ -374,6 +375,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
374375
options = new char *[ layerOptions.size() + 1 ];
375376
for ( int i = 0; i < layerOptions.size(); i++ )
376377
{
378+
QgsDebugMsg( QString( "-lco=%1" ).arg( layerOptions[i] ) );
377379
options[i] = CPLStrdup( layerOptions[i].toLocal8Bit().constData() );
378380
}
379381
options[ layerOptions.size()] = nullptr;
@@ -382,10 +384,18 @@ void QgsVectorFileWriter::init( QString vectorFileName,
382384
// disable encoding conversion of OGR Shapefile layer
383385
CPLSetConfigOption( "SHAPE_ENCODING", "" );
384386

385-
if ( action == CreateOrOverwriteFile || action == CreateOrOverwriteLayer )
387+
if ( driverName == QLatin1String( "DGN" ) )
388+
{
389+
mLayer = OGR_DS_GetLayerByName( mDS, "elements" );
390+
}
391+
else if ( action == CreateOrOverwriteFile || action == CreateOrOverwriteLayer )
392+
{
386393
mLayer = OGR_DS_CreateLayer( mDS, layerName.toUtf8().constData(), mOgrRef, wkbType, options );
394+
}
387395
else
396+
{
388397
mLayer = OGR_DS_GetLayerByName( mDS, layerName.toUtf8().constData() );
398+
}
389399

390400
if ( options )
391401
{
@@ -1329,7 +1339,7 @@ QMap<QString, QgsVectorFileWriter::MetaData> QgsVectorFileWriter::initMetaData()
13291339
false // Default value
13301340
) );
13311341

1332-
datasetOptions.insert( QStringLiteral( "COPY_SEED_FILE_COLOR_TABLEE" ), new BoolOption(
1342+
datasetOptions.insert( QStringLiteral( "COPY_SEED_FILE_COLOR_TABLE" ), new BoolOption(
13331343
QObject::tr( "Indicates whether the color table should be copied from the seed file." ),
13341344
false // Default value
13351345
) );

0 commit comments

Comments
 (0)
Please sign in to comment.