Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 7634b0b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
20 changes: 13 additions & 7 deletions src/app/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
18 changes: 14 additions & 4 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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
) );
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7634b0b

Please sign in to comment.