mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Use GDAL metadata to determine feature styles support
GDAL >= 2.3 only
This commit is contained in:
parent
73eec6f998
commit
83cdd8468b
@ -506,6 +506,16 @@ Filter string for file picker dialogs
|
|||||||
:rtype: list of str
|
:rtype: list of str
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
static bool supportsFeatureStyles( const QString &driverName );
|
||||||
|
%Docstring
|
||||||
|
Returns true if the specified ``driverName`` supports feature styles.
|
||||||
|
|
||||||
|
The ``driverName`` argument must be a valid GDAL driver name.
|
||||||
|
|
||||||
|
.. versionadded:: 3.0
|
||||||
|
:rtype: bool
|
||||||
|
%End
|
||||||
|
|
||||||
struct DriverDetails
|
struct DriverDetails
|
||||||
{
|
{
|
||||||
QString longName;
|
QString longName;
|
||||||
|
@ -112,6 +112,23 @@ QgsVectorFileWriter::QgsVectorFileWriter( const QString &vectorFileName,
|
|||||||
layerName, action );
|
layerName, action );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QgsVectorFileWriter::supportsFeatureStyles( const QString &driverName )
|
||||||
|
{
|
||||||
|
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,3,0)
|
||||||
|
GDALDriverH gdalDriver = GDALGetDriverByName( driverName.toLocal8Bit().constData() );
|
||||||
|
if ( !gdalDriver )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
char **driverMetadata = GDALGetMetadata( gdalDriver, nullptr );
|
||||||
|
if ( !driverMetadata )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return CSLFetchBoolean( driverMetadata, GDAL_DCAP_FEATURE_STYLES, false );
|
||||||
|
#else
|
||||||
|
return driverName == QLatin1String( "DXF" ) || driverName == QLatin1String( "KML" ) || driverName == QLatin1String( "MapInfo File" ) || driverName == QLatin1String( "MapInfo MIF" );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void QgsVectorFileWriter::init( QString vectorFileName,
|
void QgsVectorFileWriter::init( QString vectorFileName,
|
||||||
QString fileEncoding,
|
QString fileEncoding,
|
||||||
const QgsFields &fields,
|
const QgsFields &fields,
|
||||||
@ -2724,7 +2741,7 @@ QList< QgsVectorFileWriter::FilterFormatDetails > QgsVectorFileWriter::supported
|
|||||||
driverMetadata = GDALGetMetadata( gdalDriver, nullptr );
|
driverMetadata = GDALGetMetadata( gdalDriver, nullptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nonSpatialFormat = nonSpatialFormat = CSLFetchBoolean( driverMetadata, GDAL_DCAP_NONSPATIAL, false );
|
bool nonSpatialFormat = CSLFetchBoolean( driverMetadata, GDAL_DCAP_NONSPATIAL, false );
|
||||||
#else
|
#else
|
||||||
bool nonSpatialFormat = ( drvName == QLatin1String( "ODS" ) || drvName == QLatin1String( "XLSX" ) || drvName == QLatin1String( "XLS" ) );
|
bool nonSpatialFormat = ( drvName == QLatin1String( "ODS" ) || drvName == QLatin1String( "XLSX" ) || drvName == QLatin1String( "XLS" ) );
|
||||||
#endif
|
#endif
|
||||||
|
@ -538,6 +538,15 @@ class CORE_EXPORT QgsVectorFileWriter : public QgsFeatureSink
|
|||||||
*/
|
*/
|
||||||
static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
|
static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the specified \a driverName supports feature styles.
|
||||||
|
*
|
||||||
|
* The \a driverName argument must be a valid GDAL driver name.
|
||||||
|
*
|
||||||
|
* \since QGIS 3.0
|
||||||
|
*/
|
||||||
|
static bool supportsFeatureStyles( const QString &driverName );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Details of available driver formats.
|
* Details of available driver formats.
|
||||||
* \since QGIS 3.0
|
* \since QGIS 3.0
|
||||||
|
@ -388,7 +388,7 @@ void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Show symbology options only for some formats
|
// Show symbology options only for some formats
|
||||||
if ( sFormat == QLatin1String( "DXF" ) || sFormat == QLatin1String( "KML" ) || sFormat == QLatin1String( "MapInfo File" ) || sFormat == QLatin1String( "MapInfo MIF" ) )
|
if ( QgsVectorFileWriter::supportsFeatureStyles( sFormat ) )
|
||||||
{
|
{
|
||||||
mSymbologyExportLabel->setVisible( true );
|
mSymbologyExportLabel->setVisible( true );
|
||||||
mSymbologyExportComboBox->setVisible( true );
|
mSymbologyExportComboBox->setVisible( true );
|
||||||
|
@ -842,6 +842,14 @@ class TestQgsVectorFileWriter(unittest.TestCase):
|
|||||||
self.assertEqual(QgsVectorFileWriter.driverForExtension('not a format'), '')
|
self.assertEqual(QgsVectorFileWriter.driverForExtension('not a format'), '')
|
||||||
self.assertEqual(QgsVectorFileWriter.driverForExtension(''), '')
|
self.assertEqual(QgsVectorFileWriter.driverForExtension(''), '')
|
||||||
|
|
||||||
|
def testSupportsFeatureStyles(self):
|
||||||
|
self.assertFalse(QgsVectorFileWriter.supportsFeatureStyles('ESRI Shapefile'))
|
||||||
|
self.assertFalse(QgsVectorFileWriter.supportsFeatureStyles('not a driver'))
|
||||||
|
self.assertTrue(QgsVectorFileWriter.supportsFeatureStyles('DXF'))
|
||||||
|
self.assertTrue(QgsVectorFileWriter.supportsFeatureStyles('KML'))
|
||||||
|
self.assertTrue(QgsVectorFileWriter.supportsFeatureStyles('MapInfo File'))
|
||||||
|
self.assertTrue(QgsVectorFileWriter.supportsFeatureStyles('MapInfo MIF'))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user