Skip to content
Permalink
Browse files

vector file writer fixes:

* don't apply un-overridden default options
* DGN: don't export attributes and fix layername to "elements"
  • Loading branch information
jef-n committed Jun 13, 2017
1 parent 145a512 commit 7634b0b759bc0cedba28f9e9199d6a81a498ec5a
Showing with 27 additions and 11 deletions.
  1. +13 −7 src/app/ogr/qgsvectorlayersaveasdialog.cpp
  2. +14 −4 src/core/qgsvectorfilewriter.cpp
@@ -351,7 +351,7 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx
mAttributesSelection->setEnabled( true );
selectAllFields = false;
}
else if ( sFormat == "DXF" )
else if ( sFormat == "DXF" || sFormat == "DGN" )
{
mAttributesSelection->setEnabled( false );
selectAllFields = false;
@@ -688,24 +688,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 << QString( "%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->itemData( cb->currentIndex() ).isNull() )
if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->defaultValue )
options << QString( "%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 << QString( "%1=%2" ).arg( it.key(), le->text() );
break;
}
@@ -740,24 +743,27 @@ QStringList QgsVectorLayerSaveAsDialog::layerOptions() const
{
case QgsVectorFileWriter::Int:
{
QgsVectorFileWriter::IntOption *opt = dynamic_cast<QgsVectorFileWriter::IntOption*>( *it );
QSpinBox* sb = mLayerOptionsGroupBox->findChild<QSpinBox*>( it.key() );
if ( sb )
if ( opt && sb && sb->value() != opt->defaultValue )
options << QString( "%1=%2" ).arg( it.key() ).arg( sb->value() );
break;
}

case QgsVectorFileWriter::Set:
{
QgsVectorFileWriter::SetOption *opt = dynamic_cast<QgsVectorFileWriter::SetOption*>( *it );
QComboBox* cb = mLayerOptionsGroupBox->findChild<QComboBox*>( it.key() );
if ( cb && !cb->itemData( cb->currentIndex() ).isNull() )
if ( opt && cb && cb->itemData( cb->currentIndex() ) != opt->defaultValue )
options << QString( "%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 << QString( "%1=%2" ).arg( it.key(), le->text() );
break;
}
@@ -306,6 +306,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;
@@ -410,6 +411,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;
@@ -418,10 +420,18 @@ void QgsVectorFileWriter::init( QString vectorFileName,
// disable encoding conversion of OGR Shapefile layer
CPLSetConfigOption( "SHAPE_ENCODING", "" );

if ( action == CreateOrOverwriteFile || action == CreateOrOverwriteLayer )
if ( driverName == "DGN" )
{
mLayer = OGR_DS_GetLayerByName( mDS, "elements" );
}
else if ( action == CreateOrOverwriteFile || action == CreateOrOverwriteLayer )
{
mLayer = OGR_DS_CreateLayer( mDS, TO8F( layerName ), mOgrRef, wkbType, options );
}
else
{
mLayer = OGR_DS_GetLayerByName( mDS, TO8F( layerName ) );
}

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

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

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

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

0 comments on commit 7634b0b

Please sign in to comment.
You can’t perform that action at this time.