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 7634b0b759bc0cedba28f9e9199d6a81a498ec5a)
This commit is contained in:
Juergen E. Fischer 2017-06-13 11:50:30 +02:00
parent 8d35a42b47
commit 9a6235dba7
2 changed files with 26 additions and 11 deletions

View File

@ -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<QgsVectorFileWriter::IntOption *>( *it );
QSpinBox *sb = mDatasourceOptionsGroupBox->findChild<QSpinBox *>( 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<QgsVectorFileWriter::SetOption *>( *it );
QComboBox *cb = mDatasourceOptionsGroupBox->findChild<QComboBox *>( 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<QgsVectorFileWriter::StringOption *>( *it );
QLineEdit *le = mDatasourceOptionsGroupBox->findChild<QLineEdit *>( 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<QgsVectorFileWriter::IntOption *>( *it );
QSpinBox *sb = mLayerOptionsGroupBox->findChild<QSpinBox *>( 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<QgsVectorFileWriter::SetOption *>( *it );
QComboBox *cb = mLayerOptionsGroupBox->findChild<QComboBox *>( 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<QgsVectorFileWriter::StringOption *>( *it );
QLineEdit *le = mLayerOptionsGroupBox->findChild<QLineEdit *>( it.key() );
if ( le && !le->text().isEmpty() )
if ( opt && le && le->text() != opt->defaultValue )
options << QStringLiteral( "%1=%2" ).arg( it.key(), le->text() );
break;
}

View File

@ -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<QString, QgsVectorFileWriter::MetaData> 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
) );