Skip to content

Commit 578914a

Browse files
author
jef
committed
fix #3477 & #3778
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15165 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e67fc5e commit 578914a

File tree

5 files changed

+132
-72
lines changed

5 files changed

+132
-72
lines changed

src/app/ogr/qgsopenvectorlayerdialog.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,11 @@ QgsOpenVectorLayerDialog::~QgsOpenVectorLayerDialog()
9898

9999
QStringList QgsOpenVectorLayerDialog::openFile()
100100
{
101-
102101
QStringList selectedFiles;
103102
QgsDebugMsg( "Vector file filters: " + mVectorFileFilter );
104103
QString enc = encoding();
105104
QString title = tr( "Open an OGR Supported Vector Layer" );
106-
QgisGui::openFilesRememberingFilter( "lastVectorFileFilter", mVectorFileFilter, selectedFiles, enc,
107-
title );
105+
QgisGui::openFilesRememberingFilter( "lastVectorFileFilter", mVectorFileFilter, selectedFiles, enc, title );
108106

109107
return selectedFiles;
110108
}

src/app/ogr/qgsvectorlayersaveasdialog.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
#include <QTextCodec>
2727

2828
QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QWidget* parent, Qt::WFlags fl )
29-
: QDialog( parent, fl )
30-
, mCRS( -1 )
29+
: QDialog( parent, fl )
30+
, mCRS( -1 )
3131
{
3232
setupUi( this );
3333

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

4848
QString enc = settings.value( "/UI/encoding", QString( "System" ) ).toString();
4949
int idx = mEncodingComboBox->findText( enc );
50-
if( idx < 0 )
50+
if ( idx < 0 )
5151
{
5252
mEncodingComboBox->insertItem( 0, enc );
5353
idx = 0;
@@ -77,14 +77,21 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx
7777
browseFilename->setEnabled( true );
7878
leFilename->setEnabled( true );
7979

80-
if( format() == "KML" )
80+
if ( format() == "KML" )
8181
{
8282
mEncodingComboBox->setCurrentIndex( mEncodingComboBox->findText( "UTF-8" ) );
8383
mEncodingComboBox->setDisabled( true );
84+
mSkipAttributeCreation->setEnabled( true );
85+
}
86+
else if ( format() == "DXF" )
87+
{
88+
mSkipAttributeCreation->setChecked( true );
89+
mSkipAttributeCreation->setDisabled( true );
8490
}
8591
else
8692
{
8793
mEncodingComboBox->setEnabled( true );
94+
mSkipAttributeCreation->setEnabled( true );
8895
}
8996
}
9097

@@ -94,7 +101,7 @@ void QgsVectorLayerSaveAsDialog::on_browseFilename_clicked()
94101
QString dirName = leFilename->text().isEmpty() ? settings.value( "/UI/lastVectorFileFilterDir", "." ).toString() : leFilename->text();
95102
QString filterString = QgsVectorFileWriter::filterForDriver( format() );
96103
QString outputFile = QFileDialog::getSaveFileName( 0, tr( "Save layer as..." ), dirName, filterString );
97-
if( !outputFile.isNull() )
104+
if ( !outputFile.isNull() )
98105
{
99106
leFilename->setText( outputFile );
100107
}
@@ -103,12 +110,12 @@ void QgsVectorLayerSaveAsDialog::on_browseFilename_clicked()
103110
void QgsVectorLayerSaveAsDialog::on_browseCRS_clicked()
104111
{
105112
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector();
106-
if( mCRS >= 0 )
113+
if ( mCRS >= 0 )
107114
mySelector->setSelectedCrsId( mCRS );
108115
mySelector->setMessage( tr( "Select the coordinate reference system for the vector file. "
109116
"The data points will be transformed from the layer coordinate reference system." ) );
110117

111-
if( mySelector->exec() )
118+
if ( mySelector->exec() )
112119
{
113120
QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId );
114121
mCRS = srs.srsid();

src/core/qgsvectorfilewriter.cpp

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ QgsVectorFileWriter::QgsVectorFileWriter(
117117
}
118118
else
119119
{
120+
QString longName;
121+
QString trLongName;
122+
QString glob;
123+
QString ext;
124+
if ( QgsVectorFileWriter::driverMetadata( driverName, longName, trLongName, glob, ext ) )
125+
{
126+
if ( !vectorFileName.endsWith( "." + ext, Qt::CaseInsensitive ) )
127+
{
128+
vectorFileName += "." + ext;
129+
}
130+
}
131+
120132
QFile::remove( vectorFileName );
121133
}
122134

@@ -730,11 +742,14 @@ QMap<QString, QString> QgsVectorFileWriter::ogrDriverList()
730742
QString drvName = OGR_Dr_GetName( drv );
731743
if ( OGR_Dr_TestCapability( drv, "CreateDataSource" ) != 0 )
732744
{
733-
QPair<QString, QString> p = nameAndGlob( drvName );
734-
if ( p.first.isEmpty() )
735-
continue;
736-
737-
resultMap.insert( p.first, drvName );
745+
QString longName;
746+
QString trLongName;
747+
QString glob;
748+
QString ext;
749+
if ( QgsVectorFileWriter::driverMetadata( drvName, longName, trLongName, glob, ext ) && !trLongName.isEmpty() )
750+
{
751+
resultMap.insert( trLongName, drvName );
752+
}
738753
}
739754
}
740755
}
@@ -759,119 +774,165 @@ QString QgsVectorFileWriter::fileFilterString()
759774

760775
QString QgsVectorFileWriter::filterForDriver( const QString& driverName )
761776
{
762-
QPair<QString, QString> p = nameAndGlob( driverName );
763-
764-
if ( p.first.isEmpty() || p.second.isEmpty() )
777+
QString longName;
778+
QString trLongName;
779+
QString glob;
780+
QString ext;
781+
if ( !QgsVectorFileWriter::driverMetadata( driverName, longName, trLongName, glob, ext )
782+
|| trLongName.isEmpty()
783+
|| glob.isEmpty()
784+
)
765785
return "";
766786

767-
return "[OGR] " + p.first + " (" + p.second.toLower() + " " + p.second.toUpper() + ")";
787+
return trLongName + " [OGR] (" + glob.toLower() + " " + glob.toUpper() + ")";
768788
}
769789

770-
QPair<QString, QString> QgsVectorFileWriter::nameAndGlob( QString driverName )
790+
bool QgsVectorFileWriter::driverMetadata( QString driverName, QString &longName, QString &trLongName, QString &glob, QString &ext )
771791
{
772-
QString longName;
773-
QString glob;
774-
775792
if ( driverName.startsWith( "AVCE00" ) )
776793
{
777794
longName = "Arc/Info ASCII Coverage";
795+
trLongName = QObject::tr( "Arc/Info ASCII Coverage" );
778796
glob = "*.e00";
797+
ext = "e00";
779798
}
780799
else if ( driverName.startsWith( "BNA" ) )
781800
{
782801
longName = "Atlas BNA";
802+
trLongName = QObject::tr( "Atlas BNA" );
783803
glob = "*.bna";
804+
ext = "bna";
784805
}
785806
else if ( driverName.startsWith( "CSV" ) )
786807
{
787808
longName = "Comma Separated Value";
809+
trLongName = QObject::tr( "Comma Separated Value" );
788810
glob = "*.csv";
811+
ext = "*.bna";
789812
}
790813
else if ( driverName.startsWith( "ESRI" ) )
791814
{
792815
longName = "ESRI Shapefile";
816+
trLongName = QObject::tr( "ESRI Shapefile" );
793817
glob = "*.shp";
818+
ext = "shp";
794819
}
795820
else if ( driverName.startsWith( "FMEObjects Gateway" ) )
796821
{
797822
longName = "FMEObjects Gateway";
823+
trLongName = QObject::tr( "FMEObjects Gateway" );
798824
glob = "*.fdd";
825+
ext = "fdd";
799826
}
800827
else if ( driverName.startsWith( "GeoJSON" ) )
801828
{
802829
longName = "GeoJSON";
830+
trLongName = QObject::tr( "GeoJSON" );
803831
glob = "*.geojson";
832+
ext = "geojson";
804833
}
805834
else if ( driverName.startsWith( "GeoRSS" ) )
806835
{
807836
longName = "GeoRSS";
837+
trLongName = QObject::tr( "GeoRSS" );
808838
glob = "*.xml";
839+
ext = "xml";
809840
}
810841
else if ( driverName.startsWith( "GML" ) )
811842
{
812843
longName = "Geography Markup Language (GML)";
844+
trLongName = QObject::tr( "Geography Markup Language (GML)" );
813845
glob = "*.gml";
846+
ext = "gml";
814847
}
815848
else if ( driverName.startsWith( "GMT" ) )
816849
{
817850
longName = "Generic Mapping Tools (GMT)";
851+
trLongName = QObject::tr( "Generic Mapping Tools (GMT)" );
818852
glob = "*.gmt";
853+
ext = "gmt";
819854
}
820855
else if ( driverName.startsWith( "GPX" ) )
821856
{
822857
longName = "GPS eXchange Format";
858+
trLongName = QObject::tr( "GPS eXchange Format" );
823859
glob = "*.gpx";
860+
ext = "gpx";
824861
}
825862
else if ( driverName.startsWith( "Interlis 1" ) )
826863
{
827864
longName = "INTERLIS 1";
865+
trLongName = QObject::tr( "INTERLIS 1" );
828866
glob = "*.itf *.xml *.ili";
867+
ext = "ili";
829868
}
830869
else if ( driverName.startsWith( "Interlis 2" ) )
831870
{
832871
longName = "INTERLIS 2";
872+
trLongName = QObject::tr( "INTERLIS 2" );
833873
glob = "*.itf *.xml *.ili";
874+
ext = "ili";
834875
}
835876
else if ( driverName.startsWith( "KML" ) )
836877
{
837878
longName = "Keyhole Markup Language (KML)";
879+
trLongName = QObject::tr( "Keyhole Markup Language (KML)" );
838880
glob = "*.kml" ;
881+
ext = "kml" ;
839882
}
840883
else if ( driverName.startsWith( "MapInfo File" ) )
841884
{
842885
longName = "Mapinfo File";
886+
trLongName = QObject::tr( "Mapinfo File" );
843887
glob = "*.mif *.tab";
888+
ext = "mif" ;
844889
}
845890
else if ( driverName.startsWith( "DGN" ) )
846891
{
847892
longName = "Microstation DGN";
893+
trLongName = QObject::tr( "Microstation DGN" );
848894
glob = "*.dgn";
895+
ext = "dgn";
849896
}
850897
else if ( driverName.startsWith( "S57" ) )
851898
{
852899
longName = "S-57 Base file";
900+
trLongName = QObject::tr( "S-57 Base file" );
853901
glob = "*.000";
902+
ext = "000";
854903
}
855904
else if ( driverName.startsWith( "SDTS" ) )
856905
{
857906
longName = "Spatial Data Transfer Standard (SDTS)";
907+
trLongName = QObject::tr( "Spatial Data Transfer Standard (SDTS)" );
858908
glob = "*catd.ddf";
909+
ext = "ddf";
859910
}
860911
else if ( driverName.startsWith( "SQLite" ) )
861912
{
862913
longName = "SQLite";
914+
trLongName = QObject::tr( "SQLite" );
863915
glob = "*.sqlite";
916+
ext = "sqlite";
864917
}
865918
else if ( driverName.startsWith( "DXF" ) )
866919
{
867920
longName = "AutoCAD DXF";
921+
trLongName = QObject::tr( "AutoCAD DXF" );
868922
glob = "*.dxf";
923+
ext = "dxf";
869924
}
870925
else if ( driverName.startsWith( "Geoconcept" ) )
871926
{
872927
longName = "Geoconcept";
928+
trLongName = QObject::tr( "Geoconcept" );
873929
glob = "*.gxt *.txt";
930+
ext = "gxt";
931+
}
932+
else
933+
{
934+
return false;
874935
}
875936

876-
return QPair<QString, QString>( longName, glob );
937+
return true;
877938
}

src/core/qgsvectorfilewriter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class CORE_EXPORT QgsVectorFileWriter
148148
QMap<int, int> mAttrIdxToOgrIdx;
149149

150150
private:
151-
static QPair<QString, QString> nameAndGlob( QString driverName );
151+
static bool driverMetadata( QString driverName, QString &longName, QString &trLongName, QString &glob, QString &ext );
152152
};
153153

154154
#endif

0 commit comments

Comments
 (0)