Skip to content

Commit

Permalink
fix #3477 & #3778
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@15165 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Feb 13, 2011
1 parent 9c8a691 commit 6fb92df
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 72 deletions.
4 changes: 1 addition & 3 deletions src/app/ogr/qgsopenvectorlayerdialog.cpp
Expand Up @@ -98,13 +98,11 @@ QgsOpenVectorLayerDialog::~QgsOpenVectorLayerDialog()

QStringList QgsOpenVectorLayerDialog::openFile()
{

QStringList selectedFiles;
QgsDebugMsg( "Vector file filters: " + mVectorFileFilter );
QString enc = encoding();
QString title = tr( "Open an OGR Supported Vector Layer" );
QgisGui::openFilesRememberingFilter( "lastVectorFileFilter", mVectorFileFilter, selectedFiles, enc,
title );
QgisGui::openFilesRememberingFilter( "lastVectorFileFilter", mVectorFileFilter, selectedFiles, enc, title );

return selectedFiles;
}
Expand Down
23 changes: 15 additions & 8 deletions src/app/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -26,15 +26,15 @@
#include <QTextCodec>

QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QWidget* parent, Qt::WFlags fl )
: QDialog( parent, fl )
, mCRS( -1 )
: QDialog( parent, fl )
, mCRS( -1 )
{
setupUi( this );

QSettings settings;
QMap<QString, QString> map = QgsVectorFileWriter::ogrDriverList();
mFormatComboBox->blockSignals( true );
for( QMap< QString, QString>::const_iterator it = map.constBegin(); it != map.constEnd(); ++it )
for ( QMap< QString, QString>::const_iterator it = map.constBegin(); it != map.constEnd(); ++it )
{
mFormatComboBox->addItem( it.key(), it.value() );
}
Expand All @@ -47,7 +47,7 @@ QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QWidget* parent, Qt::WFl

QString enc = settings.value( "/UI/encoding", QString( "System" ) ).toString();
int idx = mEncodingComboBox->findText( enc );
if( idx < 0 )
if ( idx < 0 )
{
mEncodingComboBox->insertItem( 0, enc );
idx = 0;
Expand Down Expand Up @@ -77,14 +77,21 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx
browseFilename->setEnabled( true );
leFilename->setEnabled( true );

if( format() == "KML" )
if ( format() == "KML" )
{
mEncodingComboBox->setCurrentIndex( mEncodingComboBox->findText( "UTF-8" ) );
mEncodingComboBox->setDisabled( true );
mSkipAttributeCreation->setEnabled( true );
}
else if ( format() == "DXF" )
{
mSkipAttributeCreation->setChecked( true );
mSkipAttributeCreation->setDisabled( true );
}
else
{
mEncodingComboBox->setEnabled( true );
mSkipAttributeCreation->setEnabled( true );
}
}

Expand All @@ -94,7 +101,7 @@ void QgsVectorLayerSaveAsDialog::on_browseFilename_clicked()
QString dirName = leFilename->text().isEmpty() ? settings.value( "/UI/lastVectorFileFilterDir", "." ).toString() : leFilename->text();
QString filterString = QgsVectorFileWriter::filterForDriver( format() );
QString outputFile = QFileDialog::getSaveFileName( 0, tr( "Save layer as..." ), dirName, filterString );
if( !outputFile.isNull() )
if ( !outputFile.isNull() )
{
leFilename->setText( outputFile );
}
Expand All @@ -103,12 +110,12 @@ void QgsVectorLayerSaveAsDialog::on_browseFilename_clicked()
void QgsVectorLayerSaveAsDialog::on_browseCRS_clicked()
{
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector();
if( mCRS >= 0 )
if ( mCRS >= 0 )
mySelector->setSelectedCrsId( mCRS );
mySelector->setMessage( tr( "Select the coordinate reference system for the vector file. "
"The data points will be transformed from the layer coordinate reference system." ) );

if( mySelector->exec() )
if ( mySelector->exec() )
{
QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId );
mCRS = srs.srsid();
Expand Down
89 changes: 75 additions & 14 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -117,6 +117,18 @@ QgsVectorFileWriter::QgsVectorFileWriter(
}
else
{
QString longName;
QString trLongName;
QString glob;
QString ext;
if ( QgsVectorFileWriter::driverMetadata( driverName, longName, trLongName, glob, ext ) )
{
if ( !vectorFileName.endsWith( "." + ext, Qt::CaseInsensitive ) )
{
vectorFileName += "." + ext;
}
}

QFile::remove( vectorFileName );
}

Expand Down Expand Up @@ -730,11 +742,14 @@ QMap<QString, QString> QgsVectorFileWriter::ogrDriverList()
QString drvName = OGR_Dr_GetName( drv );
if ( OGR_Dr_TestCapability( drv, "CreateDataSource" ) != 0 )
{
QPair<QString, QString> p = nameAndGlob( drvName );
if ( p.first.isEmpty() )
continue;

resultMap.insert( p.first, drvName );
QString longName;
QString trLongName;
QString glob;
QString ext;
if ( QgsVectorFileWriter::driverMetadata( drvName, longName, trLongName, glob, ext ) && !trLongName.isEmpty() )
{
resultMap.insert( trLongName, drvName );
}
}
}
}
Expand All @@ -759,119 +774,165 @@ QString QgsVectorFileWriter::fileFilterString()

QString QgsVectorFileWriter::filterForDriver( const QString& driverName )
{
QPair<QString, QString> p = nameAndGlob( driverName );

if ( p.first.isEmpty() || p.second.isEmpty() )
QString longName;
QString trLongName;
QString glob;
QString ext;
if ( !QgsVectorFileWriter::driverMetadata( driverName, longName, trLongName, glob, ext )
|| trLongName.isEmpty()
|| glob.isEmpty()
)
return "";

return "[OGR] " + p.first + " (" + p.second.toLower() + " " + p.second.toUpper() + ")";
return trLongName + " [OGR] (" + glob.toLower() + " " + glob.toUpper() + ")";
}

QPair<QString, QString> QgsVectorFileWriter::nameAndGlob( QString driverName )
bool QgsVectorFileWriter::driverMetadata( QString driverName, QString &longName, QString &trLongName, QString &glob, QString &ext )
{
QString longName;
QString glob;

if ( driverName.startsWith( "AVCE00" ) )
{
longName = "Arc/Info ASCII Coverage";
trLongName = QObject::tr( "Arc/Info ASCII Coverage" );
glob = "*.e00";
ext = "e00";
}
else if ( driverName.startsWith( "BNA" ) )
{
longName = "Atlas BNA";
trLongName = QObject::tr( "Atlas BNA" );
glob = "*.bna";
ext = "bna";
}
else if ( driverName.startsWith( "CSV" ) )
{
longName = "Comma Separated Value";
trLongName = QObject::tr( "Comma Separated Value" );
glob = "*.csv";
ext = "*.bna";
}
else if ( driverName.startsWith( "ESRI" ) )
{
longName = "ESRI Shapefile";
trLongName = QObject::tr( "ESRI Shapefile" );
glob = "*.shp";
ext = "shp";
}
else if ( driverName.startsWith( "FMEObjects Gateway" ) )
{
longName = "FMEObjects Gateway";
trLongName = QObject::tr( "FMEObjects Gateway" );
glob = "*.fdd";
ext = "fdd";
}
else if ( driverName.startsWith( "GeoJSON" ) )
{
longName = "GeoJSON";
trLongName = QObject::tr( "GeoJSON" );
glob = "*.geojson";
ext = "geojson";
}
else if ( driverName.startsWith( "GeoRSS" ) )
{
longName = "GeoRSS";
trLongName = QObject::tr( "GeoRSS" );
glob = "*.xml";
ext = "xml";
}
else if ( driverName.startsWith( "GML" ) )
{
longName = "Geography Markup Language (GML)";
trLongName = QObject::tr( "Geography Markup Language (GML)" );
glob = "*.gml";
ext = "gml";
}
else if ( driverName.startsWith( "GMT" ) )
{
longName = "Generic Mapping Tools (GMT)";
trLongName = QObject::tr( "Generic Mapping Tools (GMT)" );
glob = "*.gmt";
ext = "gmt";
}
else if ( driverName.startsWith( "GPX" ) )
{
longName = "GPS eXchange Format";
trLongName = QObject::tr( "GPS eXchange Format" );
glob = "*.gpx";
ext = "gpx";
}
else if ( driverName.startsWith( "Interlis 1" ) )
{
longName = "INTERLIS 1";
trLongName = QObject::tr( "INTERLIS 1" );
glob = "*.itf *.xml *.ili";
ext = "ili";
}
else if ( driverName.startsWith( "Interlis 2" ) )
{
longName = "INTERLIS 2";
trLongName = QObject::tr( "INTERLIS 2" );
glob = "*.itf *.xml *.ili";
ext = "ili";
}
else if ( driverName.startsWith( "KML" ) )
{
longName = "Keyhole Markup Language (KML)";
trLongName = QObject::tr( "Keyhole Markup Language (KML)" );
glob = "*.kml" ;
ext = "kml" ;
}
else if ( driverName.startsWith( "MapInfo File" ) )
{
longName = "Mapinfo File";
trLongName = QObject::tr( "Mapinfo File" );
glob = "*.mif *.tab";
ext = "mif" ;
}
else if ( driverName.startsWith( "DGN" ) )
{
longName = "Microstation DGN";
trLongName = QObject::tr( "Microstation DGN" );
glob = "*.dgn";
ext = "dgn";
}
else if ( driverName.startsWith( "S57" ) )
{
longName = "S-57 Base file";
trLongName = QObject::tr( "S-57 Base file" );
glob = "*.000";
ext = "000";
}
else if ( driverName.startsWith( "SDTS" ) )
{
longName = "Spatial Data Transfer Standard (SDTS)";
trLongName = QObject::tr( "Spatial Data Transfer Standard (SDTS)" );
glob = "*catd.ddf";
ext = "ddf";
}
else if ( driverName.startsWith( "SQLite" ) )
{
longName = "SQLite";
trLongName = QObject::tr( "SQLite" );
glob = "*.sqlite";
ext = "sqlite";
}
else if ( driverName.startsWith( "DXF" ) )
{
longName = "AutoCAD DXF";
trLongName = QObject::tr( "AutoCAD DXF" );
glob = "*.dxf";
ext = "dxf";
}
else if ( driverName.startsWith( "Geoconcept" ) )
{
longName = "Geoconcept";
trLongName = QObject::tr( "Geoconcept" );
glob = "*.gxt *.txt";
ext = "gxt";
}
else
{
return false;
}

return QPair<QString, QString>( longName, glob );
return true;
}
2 changes: 1 addition & 1 deletion src/core/qgsvectorfilewriter.h
Expand Up @@ -148,7 +148,7 @@ class CORE_EXPORT QgsVectorFileWriter
QMap<int, int> mAttrIdxToOgrIdx;

private:
static QPair<QString, QString> nameAndGlob( QString driverName );
static bool driverMetadata( QString driverName, QString &longName, QString &trLongName, QString &glob, QString &ext );
};

#endif

0 comments on commit 6fb92df

Please sign in to comment.