mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-08 00:05:09 -04:00
Fix more sorting issues in vector format lists
This commit is contained in:
parent
2ed547219a
commit
5cfa18ee9f
@ -2843,7 +2843,7 @@ QList< QgsVectorFileWriter::FilterFormatDetails > QgsVectorFileWriter::supported
|
|||||||
QStringList globs;
|
QStringList globs;
|
||||||
if ( driverMetadata( drvName, metadata ) && !metadata.glob.isEmpty() )
|
if ( driverMetadata( drvName, metadata ) && !metadata.glob.isEmpty() )
|
||||||
{
|
{
|
||||||
globs << metadata.glob.toLower();
|
globs = metadata.glob.toLower().split( ' ' );
|
||||||
}
|
}
|
||||||
|
|
||||||
FilterFormatDetails details;
|
FilterFormatDetails details;
|
||||||
@ -2870,7 +2870,7 @@ QList< QgsVectorFileWriter::FilterFormatDetails > QgsVectorFileWriter::supported
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return a.driverName.toLower().localeAwareCompare( b.driverName.toLower() ) < 0;
|
return a.filterString.toLower().localeAwareCompare( b.filterString.toLower() ) < 0;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
@ -2879,21 +2879,43 @@ QList< QgsVectorFileWriter::FilterFormatDetails > QgsVectorFileWriter::supported
|
|||||||
QStringList QgsVectorFileWriter::supportedFormatExtensions( const VectorFormatOptions options )
|
QStringList QgsVectorFileWriter::supportedFormatExtensions( const VectorFormatOptions options )
|
||||||
{
|
{
|
||||||
const auto formats = supportedFiltersAndFormats( options );
|
const auto formats = supportedFiltersAndFormats( options );
|
||||||
QStringList extensions;
|
QSet< QString > extensions;
|
||||||
|
|
||||||
QRegularExpression rx( QStringLiteral( "\\*\\.([a-zA-Z0-9]*)" ) );
|
const QRegularExpression rx( QStringLiteral( "\\*\\.(.*)$" ) );
|
||||||
|
|
||||||
for ( const FilterFormatDetails &format : formats )
|
for ( const FilterFormatDetails &format : formats )
|
||||||
{
|
{
|
||||||
QString ext = format.filterString;
|
for ( const QString &glob : format.globs )
|
||||||
QRegularExpressionMatch match = rx.match( ext );
|
{
|
||||||
|
const QRegularExpressionMatch match = rx.match( glob );
|
||||||
if ( !match.hasMatch() )
|
if ( !match.hasMatch() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
QString matched = match.captured( 1 );
|
const QString matched = match.captured( 1 );
|
||||||
extensions << matched;
|
extensions.insert( matched );
|
||||||
}
|
}
|
||||||
return extensions;
|
}
|
||||||
|
|
||||||
|
QStringList extensionList = extensions.toList();
|
||||||
|
|
||||||
|
std::sort( extensionList.begin(), extensionList.end(), [options]( const QString & a, const QString & b ) -> bool
|
||||||
|
{
|
||||||
|
if ( options & SortRecommended )
|
||||||
|
{
|
||||||
|
if ( a == QLatin1String( "gpkg" ) )
|
||||||
|
return true; // Make https://twitter.com/shapefiIe a sad little fellow
|
||||||
|
else if ( b == QLatin1String( "gpkg" ) )
|
||||||
|
return false;
|
||||||
|
else if ( a == QLatin1String( "shp" ) )
|
||||||
|
return true;
|
||||||
|
else if ( b == QLatin1String( "shp" ) )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return a.toLower().localeAwareCompare( b.toLower() ) < 0;
|
||||||
|
} );
|
||||||
|
|
||||||
|
return extensionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList< QgsVectorFileWriter::DriverDetails > QgsVectorFileWriter::ogrDriverList( const VectorFormatOptions options )
|
QList< QgsVectorFileWriter::DriverDetails > QgsVectorFileWriter::ogrDriverList( const VectorFormatOptions options )
|
||||||
|
@ -775,6 +775,9 @@ class TestQgsVectorFileWriter(unittest.TestCase):
|
|||||||
self.assertEqual(formats[1].globs, ['*.shp'])
|
self.assertEqual(formats[1].globs, ['*.shp'])
|
||||||
self.assertTrue('ODS' in [f.driverName for f in formats])
|
self.assertTrue('ODS' in [f.driverName for f in formats])
|
||||||
|
|
||||||
|
interlis_format = [f for f in formats if f.driverName == 'Interlis 2'][0]
|
||||||
|
self.assertEqual(interlis_format.globs, ['*.xtf', '*.xml', '*.ili'])
|
||||||
|
|
||||||
# alphabetical sorting
|
# alphabetical sorting
|
||||||
formats2 = QgsVectorFileWriter.supportedFiltersAndFormats(QgsVectorFileWriter.VectorFormatOptions())
|
formats2 = QgsVectorFileWriter.supportedFiltersAndFormats(QgsVectorFileWriter.VectorFormatOptions())
|
||||||
self.assertTrue(formats2[0].driverName < formats2[1].driverName)
|
self.assertTrue(formats2[0].driverName < formats2[1].driverName)
|
||||||
@ -818,12 +821,19 @@ class TestQgsVectorFileWriter(unittest.TestCase):
|
|||||||
self.assertEqual(formats[0], 'gpkg')
|
self.assertEqual(formats[0], 'gpkg')
|
||||||
self.assertEqual(formats[1], 'shp')
|
self.assertEqual(formats[1], 'shp')
|
||||||
self.assertTrue('ods' in formats)
|
self.assertTrue('ods' in formats)
|
||||||
|
self.assertTrue('xtf' in formats)
|
||||||
|
self.assertTrue('ili' in formats)
|
||||||
|
|
||||||
|
for i in range(2, len(formats) - 1):
|
||||||
|
self.assertLess(formats[i].lower(), formats[i + 1].lower())
|
||||||
|
|
||||||
# alphabetical sorting
|
# alphabetical sorting
|
||||||
formats2 = QgsVectorFileWriter.supportedFormatExtensions(QgsVectorFileWriter.VectorFormatOptions())
|
formats2 = QgsVectorFileWriter.supportedFormatExtensions(QgsVectorFileWriter.VectorFormatOptions())
|
||||||
self.assertTrue(formats2[0] < formats2[1])
|
self.assertTrue(formats2[0] < formats2[1])
|
||||||
self.assertCountEqual(formats, formats2)
|
self.assertCountEqual(formats, formats2)
|
||||||
self.assertNotEqual(formats2[0], 'gpkg')
|
self.assertNotEqual(formats2[0], 'gpkg')
|
||||||
|
for i in range(0, len(formats2) - 1):
|
||||||
|
self.assertLess(formats2[i].lower(), formats2[i + 1].lower())
|
||||||
|
|
||||||
formats = QgsVectorFileWriter.supportedFormatExtensions(QgsVectorFileWriter.SkipNonSpatialFormats)
|
formats = QgsVectorFileWriter.supportedFormatExtensions(QgsVectorFileWriter.SkipNonSpatialFormats)
|
||||||
self.assertFalse('ods' in formats)
|
self.assertFalse('ods' in formats)
|
||||||
@ -834,10 +844,16 @@ class TestQgsVectorFileWriter(unittest.TestCase):
|
|||||||
self.assertTrue('shp' in formats)
|
self.assertTrue('shp' in formats)
|
||||||
self.assertLess(formats.index('gpkg'), formats.index('shp'))
|
self.assertLess(formats.index('gpkg'), formats.index('shp'))
|
||||||
self.assertTrue('ods' in formats)
|
self.assertTrue('ods' in formats)
|
||||||
|
parts = formats.split(';;')
|
||||||
|
for i in range(2, len(parts) - 1):
|
||||||
|
self.assertLess(parts[i].lower(), parts[i + 1].lower())
|
||||||
|
|
||||||
# alphabetical sorting
|
# alphabetical sorting
|
||||||
formats2 = QgsVectorFileWriter.fileFilterString(QgsVectorFileWriter.VectorFormatOptions())
|
formats2 = QgsVectorFileWriter.fileFilterString(QgsVectorFileWriter.VectorFormatOptions())
|
||||||
self.assertNotEqual(formats.index('gpkg'), formats2.index('gpkg'))
|
self.assertNotEqual(formats.index('gpkg'), formats2.index('gpkg'))
|
||||||
|
parts = formats2.split(';;')
|
||||||
|
for i in range(len(parts) - 1):
|
||||||
|
self.assertLess(parts[i].lower(), parts[i + 1].lower())
|
||||||
|
|
||||||
# hide non spatial
|
# hide non spatial
|
||||||
formats = QgsVectorFileWriter.fileFilterString(QgsVectorFileWriter.SkipNonSpatialFormats)
|
formats = QgsVectorFileWriter.fileFilterString(QgsVectorFileWriter.SkipNonSpatialFormats)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user