@@ -2806,9 +2806,6 @@ QList< QgsVectorFileWriter::FilterFormatDetails > QgsVectorFileWriter::supported
28062806 QgsApplication::registerOgrDrivers ();
28072807 int const drvCount = OGRGetDriverCount ();
28082808
2809- FilterFormatDetails shapeFormat;
2810- FilterFormatDetails gpkgFormat;
2811-
28122809 for ( int i = 0 ; i < drvCount; ++i )
28132810 {
28142811 OGRSFDriverH drv = OGRGetDriver ( i );
@@ -2846,41 +2843,27 @@ QList< QgsVectorFileWriter::FilterFormatDetails > QgsVectorFileWriter::supported
28462843 details.driverName = drvName;
28472844 details.filterString = filterString;
28482845
2849- if ( options & SortRecommended )
2850- {
2851- if ( drvName == QLatin1String ( " ESRI Shapefile" ) )
2852- {
2853- shapeFormat = details;
2854- continue ;
2855- }
2856- else if ( drvName == QLatin1String ( " GPKG" ) )
2857- {
2858- gpkgFormat = details;
2859- continue ;
2860- }
2861- }
2862-
28632846 results << details;
28642847 }
28652848 }
28662849 }
28672850
2868- std::sort ( results.begin (), results.end (), []( const FilterFormatDetails & a, const FilterFormatDetails & b ) -> bool
2851+ std::sort ( results.begin (), results.end (), [options ]( const FilterFormatDetails & a, const FilterFormatDetails & b ) -> bool
28692852 {
2870- return a.driverName < b.driverName ;
2871- } );
2872-
2873- if ( options & SortRecommended )
2874- {
2875- if ( !shapeFormat.filterString .isEmpty () )
2876- {
2877- results.insert ( 0 , shapeFormat );
2878- }
2879- if ( !gpkgFormat.filterString .isEmpty () )
2853+ if ( options & SortRecommended )
28802854 {
2881- results.insert ( 0 , gpkgFormat );
2855+ if ( a.driverName == QLatin1String ( " GPKG" ) )
2856+ return true ; // Make https://twitter.com/shapefiIe a sad little fellow
2857+ else if ( b.driverName == QLatin1String ( " GPKG" ) )
2858+ return false ;
2859+ else if ( a.driverName == QLatin1String ( " ESRI Shapefile" ) )
2860+ return true ;
2861+ else if ( b.driverName == QLatin1String ( " ESRI Shapefile" ) )
2862+ return false ;
28822863 }
2883- }
2864+
2865+ return a.driverName .toLower ().localeAwareCompare ( b.driverName .toLower () ) < 0 ;
2866+ } );
28842867
28852868 return results;
28862869}
@@ -2966,23 +2949,8 @@ QList< QgsVectorFileWriter::DriverDetails > QgsVectorFileWriter::ogrDriverList(
29662949 }
29672950 }
29682951 }
2969- std::sort ( writableDrivers.begin (), writableDrivers.end () );
2970- if ( options & SortRecommended )
2971- {
2972- // recommended order sorting, so we shift certain formats to the top
2973- if ( writableDrivers.contains ( QStringLiteral ( " ESRI Shapefile" ) ) )
2974- {
2975- writableDrivers.removeAll ( QStringLiteral ( " ESRI Shapefile" ) );
2976- writableDrivers.insert ( 0 , QStringLiteral ( " ESRI Shapefile" ) );
2977- }
2978- if ( writableDrivers.contains ( QStringLiteral ( " GPKG" ) ) )
2979- {
2980- // Make https://twitter.com/shapefiIe a sad little fellow
2981- writableDrivers.removeAll ( QStringLiteral ( " GPKG" ) );
2982- writableDrivers.insert ( 0 , QStringLiteral ( " GPKG" ) );
2983- }
2984- }
29852952
2953+ results.reserve ( writableDrivers.count () );
29862954 for ( const QString &drvName : qgis::as_const ( writableDrivers ) )
29872955 {
29882956 MetaData metadata;
@@ -2994,6 +2962,23 @@ QList< QgsVectorFileWriter::DriverDetails > QgsVectorFileWriter::ogrDriverList(
29942962 results << details;
29952963 }
29962964 }
2965+
2966+ std::sort ( results.begin (), results.end (), [options]( const DriverDetails & a, const DriverDetails & b ) -> bool
2967+ {
2968+ if ( options & SortRecommended )
2969+ {
2970+ if ( a.driverName == QLatin1String ( " GPKG" ) )
2971+ return true ; // Make https://twitter.com/shapefiIe a sad little fellow
2972+ else if ( b.driverName == QLatin1String ( " GPKG" ) )
2973+ return false ;
2974+ else if ( a.driverName == QLatin1String ( " ESRI Shapefile" ) )
2975+ return true ;
2976+ else if ( b.driverName == QLatin1String ( " ESRI Shapefile" ) )
2977+ return false ;
2978+ }
2979+
2980+ return a.longName .toLower ().localeAwareCompare ( b.longName .toLower () ) < 0 ;
2981+ } );
29972982 return results;
29982983}
29992984
0 commit comments