mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Avoid use of QPair and instead use a struct
This commit is contained in:
parent
d855f7f3f4
commit
a4ef7e42c7
@ -2672,6 +2672,7 @@ for consistency with other parts of the QGIS API.
|
||||
- The addFeature which takes a renderer argument was renamed to addFeatureWithStyle.
|
||||
- static `writeAsVectorFormat` calls no longer take a errorMessage argument in
|
||||
python and instead return a `(errorCode, errorMessage)` tuple.
|
||||
- ogrDriverList now returns a list of QgsVectorFileWriter.DriverDetails structs, instead of a map
|
||||
|
||||
|
||||
QgsWMSLegendNode {#qgis_api_break_3_0_QgsWMSLegendNode}
|
||||
|
@ -491,18 +491,31 @@ Create a new vector file writer
|
||||
:rtype: list of str
|
||||
%End
|
||||
|
||||
static QList< QPair< QString, QString > > ogrDriverList( VectorFormatOptions options = SortRecommended );
|
||||
struct DriverDetails
|
||||
{
|
||||
QString longName;
|
||||
%Docstring
|
||||
Returns driver list that can be used for dialogs. It contains all OGR drivers
|
||||
Descriptive, user friendly name for the driver
|
||||
%End
|
||||
|
||||
QString driverName;
|
||||
%Docstring
|
||||
Unique driver name
|
||||
%End
|
||||
};
|
||||
|
||||
static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
|
||||
%Docstring
|
||||
Returns the driver list that can be used for dialogs. It contains all OGR drivers
|
||||
plus some additional internal QGIS driver names to distinguish between more
|
||||
supported formats of the same OGR driver.
|
||||
|
||||
The returned list consists of pairs of driver long name (e.g. user-friendly
|
||||
display name for the format) to internal driver short name.
|
||||
The returned list consists of structs containing the driver long name (e.g. user-friendly
|
||||
display name for the format) and internal driver short name.
|
||||
|
||||
The ``options`` argument can be used to control the sorting and filtering of
|
||||
returned drivers.
|
||||
:rtype: list of QPair< str, QString >
|
||||
:rtype: list of QgsVectorFileWriter.DriverDetails
|
||||
%End
|
||||
|
||||
static QString driverForExtension( const QString &extension );
|
||||
|
@ -2762,12 +2762,12 @@ QStringList QgsVectorFileWriter::supportedFormatExtensions( const VectorFormatOp
|
||||
return extensions;
|
||||
}
|
||||
|
||||
QList< QPair< QString, QString> > QgsVectorFileWriter::ogrDriverList( const VectorFormatOptions options )
|
||||
QList< QgsVectorFileWriter::DriverDetails > QgsVectorFileWriter::ogrDriverList( const VectorFormatOptions options )
|
||||
{
|
||||
QList< QPair< QString, QString> > resultMap;
|
||||
QList< QgsVectorFileWriter::DriverDetails > results;
|
||||
|
||||
QgsApplication::registerOgrDrivers();
|
||||
int const drvCount = OGRGetDriverCount();
|
||||
const int drvCount = OGRGetDriverCount();
|
||||
|
||||
QStringList writableDrivers;
|
||||
for ( int i = 0; i < drvCount; ++i )
|
||||
@ -2836,10 +2836,13 @@ QList< QPair< QString, QString> > QgsVectorFileWriter::ogrDriverList( const Vect
|
||||
MetaData metadata;
|
||||
if ( driverMetadata( drvName, metadata ) && !metadata.trLongName.isEmpty() )
|
||||
{
|
||||
resultMap << qMakePair( metadata.trLongName, drvName );
|
||||
DriverDetails details;
|
||||
details.driverName = drvName;
|
||||
details.longName = metadata.trLongName;
|
||||
results << details;
|
||||
}
|
||||
}
|
||||
return resultMap;
|
||||
return results;
|
||||
}
|
||||
|
||||
QString QgsVectorFileWriter::driverForExtension( const QString &extension )
|
||||
|
@ -528,17 +528,30 @@ class CORE_EXPORT QgsVectorFileWriter : public QgsFeatureSink
|
||||
static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
|
||||
|
||||
/**
|
||||
* Returns driver list that can be used for dialogs. It contains all OGR drivers
|
||||
* Details of available driver formats.
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
struct DriverDetails
|
||||
{
|
||||
//! Descriptive, user friendly name for the driver
|
||||
QString longName;
|
||||
|
||||
//! Unique driver name
|
||||
QString driverName;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the driver list that can be used for dialogs. It contains all OGR drivers
|
||||
* plus some additional internal QGIS driver names to distinguish between more
|
||||
* supported formats of the same OGR driver.
|
||||
*
|
||||
* The returned list consists of pairs of driver long name (e.g. user-friendly
|
||||
* display name for the format) to internal driver short name.
|
||||
* The returned list consists of structs containing the driver long name (e.g. user-friendly
|
||||
* display name for the format) and internal driver short name.
|
||||
*
|
||||
* The \a options argument can be used to control the sorting and filtering of
|
||||
* returned drivers.
|
||||
*/
|
||||
static QList< QPair< QString, QString > > ogrDriverList( VectorFormatOptions options = SortRecommended );
|
||||
static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
|
||||
|
||||
/**
|
||||
* Returns the OGR driver name for a specified file \a extension. E.g. the
|
||||
|
@ -87,11 +87,11 @@ void QgsVectorLayerSaveAsDialog::setup()
|
||||
QgsSettings settings;
|
||||
restoreGeometry( settings.value( QStringLiteral( "Windows/VectorLayerSaveAs/geometry" ) ).toByteArray() );
|
||||
|
||||
const QList< QPair< QString, QString > > map = QgsVectorFileWriter::ogrDriverList();
|
||||
const QList< QgsVectorFileWriter::DriverDetails > drivers = QgsVectorFileWriter::ogrDriverList();
|
||||
mFormatComboBox->blockSignals( true );
|
||||
for ( auto it = map.constBegin(); it != map.constEnd(); ++it )
|
||||
for ( const QgsVectorFileWriter::DriverDetails &driver : drivers )
|
||||
{
|
||||
mFormatComboBox->addItem( it->first, it->second );
|
||||
mFormatComboBox->addItem( driver.longName, driver.driverName );
|
||||
}
|
||||
|
||||
QString format = settings.value( QStringLiteral( "UI/lastVectorFormat" ), "GPKG" ).toString();
|
||||
|
@ -737,13 +737,15 @@ class TestQgsVectorFileWriter(unittest.TestCase):
|
||||
def testOgrDriverList(self):
|
||||
# test with drivers in recommended order
|
||||
drivers = QgsVectorFileWriter.ogrDriverList(QgsVectorFileWriter.SortRecommended)
|
||||
self.assertEqual(drivers[0], ('GeoPackage', 'GPKG'))
|
||||
self.assertEqual(drivers[1], ('ESRI Shapefile', 'ESRI Shapefile'))
|
||||
self.assertEqual(drivers[0].longName, 'GeoPackage')
|
||||
self.assertEqual(drivers[0].driverName, 'GPKG')
|
||||
self.assertEqual(drivers[1].longName, 'ESRI Shapefile')
|
||||
self.assertEqual(drivers[1].driverName, 'ESRI Shapefile')
|
||||
# alphabetical sorting
|
||||
drivers2 = QgsVectorFileWriter.ogrDriverList(QgsVectorFileWriter.VectorFormatOptions())
|
||||
self.assertTrue(drivers2[0][0] < drivers2[1][0])
|
||||
self.assertCountEqual(drivers, drivers2)
|
||||
self.assertNotEqual(drivers2[0], ('GeoPackage', 'GPKG'))
|
||||
self.assertTrue(drivers2[0].longName < drivers2[1].longName)
|
||||
self.assertCountEqual([d.driverName for d in drivers], [d.driverName for d in drivers2])
|
||||
self.assertNotEqual(drivers2[0].driverName, 'GPKG')
|
||||
|
||||
def testSupportedFormatExtensions(self):
|
||||
formats = QgsVectorFileWriter.supportedFormatExtensions()
|
||||
|
Loading…
x
Reference in New Issue
Block a user