diff --git a/src/app/ogr/qgsvectorlayersaveasdialog.cpp b/src/app/ogr/qgsvectorlayersaveasdialog.cpp index 1530535e896..625385a9b4b 100644 --- a/src/app/ogr/qgsvectorlayersaveasdialog.cpp +++ b/src/app/ogr/qgsvectorlayersaveasdialog.cpp @@ -347,7 +347,7 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx bool fieldsAsDisplayedValues = false; const QString sFormat( format() ); - if ( sFormat == QLatin1String( "DXF" ) ) + if ( sFormat == QLatin1String( "DXF" ) || sFormat == QLatin1String( "DGN" ) ) { mAttributesSelection->setEnabled( false ); selectAllFields = false; @@ -686,24 +686,27 @@ QStringList QgsVectorLayerSaveAsDialog::datasourceOptions() const { case QgsVectorFileWriter::Int: { + QgsVectorFileWriter::IntOption *opt = dynamic_cast( *it ); QSpinBox *sb = mDatasourceOptionsGroupBox->findChild( it.key() ); - if ( sb ) + if ( opt && sb && sb->value() != opt->defaultValue ) options << QStringLiteral( "%1=%2" ).arg( it.key() ).arg( sb->value() ); break; } case QgsVectorFileWriter::Set: { + QgsVectorFileWriter::SetOption *opt = dynamic_cast( *it ); QComboBox *cb = mDatasourceOptionsGroupBox->findChild( it.key() ); - if ( cb && !cb->currentData().isNull() ) + if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->defaultValue ) options << QStringLiteral( "%1=%2" ).arg( it.key(), cb->currentText() ); break; } case QgsVectorFileWriter::String: { + QgsVectorFileWriter::StringOption *opt = dynamic_cast( *it ); QLineEdit *le = mDatasourceOptionsGroupBox->findChild( it.key() ); - if ( le ) + if ( opt && le && le->text() != opt->defaultValue ) options << QStringLiteral( "%1=%2" ).arg( it.key(), le->text() ); break; } @@ -738,24 +741,26 @@ QStringList QgsVectorLayerSaveAsDialog::layerOptions() const { case QgsVectorFileWriter::Int: { + QgsVectorFileWriter::IntOption *opt = dynamic_cast( *it ); QSpinBox *sb = mLayerOptionsGroupBox->findChild( it.key() ); - if ( sb ) - options << QStringLiteral( "%1=%2" ).arg( it.key() ).arg( sb->value() ); - break; + if ( opt && sb && sb->value() != opt->defaultValue ) + break; } case QgsVectorFileWriter::Set: { + QgsVectorFileWriter::SetOption *opt = dynamic_cast( *it ); QComboBox *cb = mLayerOptionsGroupBox->findChild( it.key() ); - if ( cb && !cb->currentData().isNull() ) + if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->defaultValue ) options << QStringLiteral( "%1=%2" ).arg( it.key(), cb->currentText() ); break; } case QgsVectorFileWriter::String: { + QgsVectorFileWriter::StringOption *opt = dynamic_cast( *it ); QLineEdit *le = mLayerOptionsGroupBox->findChild( it.key() ); - if ( le && !le->text().isEmpty() ) + if ( opt && le && le->text() != opt->defaultValue ) options << QStringLiteral( "%1=%2" ).arg( it.key(), le->text() ); break; } diff --git a/src/core/qgsvectorfilewriter.cpp b/src/core/qgsvectorfilewriter.cpp index 3bc2c365710..2b2a7a79815 100644 --- a/src/core/qgsvectorfilewriter.cpp +++ b/src/core/qgsvectorfilewriter.cpp @@ -270,6 +270,7 @@ void QgsVectorFileWriter::init( QString vectorFileName, options = new char *[ datasourceOptions.size() + 1 ]; for ( int i = 0; i < datasourceOptions.size(); i++ ) { + QgsDebugMsg( QString( "-dsco=%1" ).arg( datasourceOptions[i] ) ); options[i] = CPLStrdup( datasourceOptions[i].toLocal8Bit().constData() ); } options[ datasourceOptions.size()] = nullptr; @@ -374,6 +375,7 @@ void QgsVectorFileWriter::init( QString vectorFileName, options = new char *[ layerOptions.size() + 1 ]; for ( int i = 0; i < layerOptions.size(); i++ ) { + QgsDebugMsg( QString( "-lco=%1" ).arg( layerOptions[i] ) ); options[i] = CPLStrdup( layerOptions[i].toLocal8Bit().constData() ); } options[ layerOptions.size()] = nullptr; @@ -382,10 +384,18 @@ void QgsVectorFileWriter::init( QString vectorFileName, // disable encoding conversion of OGR Shapefile layer CPLSetConfigOption( "SHAPE_ENCODING", "" ); - if ( action == CreateOrOverwriteFile || action == CreateOrOverwriteLayer ) + if ( driverName == QLatin1String( "DGN" ) ) + { + mLayer = OGR_DS_GetLayerByName( mDS, "elements" ); + } + else if ( action == CreateOrOverwriteFile || action == CreateOrOverwriteLayer ) + { mLayer = OGR_DS_CreateLayer( mDS, layerName.toUtf8().constData(), mOgrRef, wkbType, options ); + } else + { mLayer = OGR_DS_GetLayerByName( mDS, layerName.toUtf8().constData() ); + } if ( options ) { @@ -1329,7 +1339,7 @@ QMap QgsVectorFileWriter::initMetaData() false // Default value ) ); - datasetOptions.insert( QStringLiteral( "COPY_SEED_FILE_COLOR_TABLEE" ), new BoolOption( + datasetOptions.insert( QStringLiteral( "COPY_SEED_FILE_COLOR_TABLE" ), new BoolOption( QObject::tr( "Indicates whether the color table should be copied from the seed file." ), false // Default value ) );