Skip to content

Commit

Permalink
vector file writer fixes:
Browse files Browse the repository at this point in the history
* don't apply un-overridden default options
* DGN: don't export attributes and fix layername to "elements"

(cherry picked from commit 7634b0b)
  • Loading branch information
jef-n committed Jun 13, 2017
1 parent 8d35a42 commit 9a6235d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
23 changes: 14 additions & 9 deletions src/app/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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() );

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson Jul 12, 2017

Collaborator

@jef-n was this line dropped accidentally?

This comment has been minimized.

Copy link
@nyalldawson

This comment has been minimized.

Copy link
@jef-n

jef-n Jul 13, 2017

Author Member

yes. it was removed accidentally. Re-added in fc7ac83. But in 2.18 it was still there, so the tickets - contrary to the commit what the commit message says - are unrelated to that line. QGIS' default settings probably don't match OGR's - in that case it's still this commit.

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;
}
Expand Down
14 changes: 12 additions & 2 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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
) );
Expand Down

0 comments on commit 9a6235d

Please sign in to comment.