Fix a bunch of clazy warnings in QgsVectorFileWriter

This commit is contained in:
Nyall Dawson 2021-03-29 13:07:00 +10:00
parent 62ad6e3106
commit 705259e2d9
3 changed files with 14 additions and 15 deletions

View File

@ -461,7 +461,7 @@ Create a new vector file writer.
const QgsVectorFileWriter::SaveVectorOptions &options, const QgsVectorFileWriter::SaveVectorOptions &options,
QString *newFilename = 0, QString *newFilename = 0,
QString *newLayer = 0, QString *newLayer = 0,
QString *errorMessage /Out/ = 0 ); QString *errorMessage /Out/ = 0 ) /Deprecated/;
%Docstring %Docstring
Writes a layer out to a vector file. Writes a layer out to a vector file.

View File

@ -67,7 +67,7 @@ static OGRDataSourceH myOGROpen( const char *pszName, int bUpdate, OGRSFDriverH
if ( hDS && bUpdate ) if ( hDS && bUpdate )
{ {
QString drvName = OGR_Dr_GetName( hDriver ); QString drvName = OGR_Dr_GetName( hDriver );
if ( drvName == "BNA" ) if ( drvName == QLatin1String( "BNA" ) )
{ {
OGR_DS_Destroy( hDS ); OGR_DS_Destroy( hDS );
if ( phDriver ) if ( phDriver )
@ -108,7 +108,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
SymbologyExport symbologyExport, SymbologyExport symbologyExport,
QgsFeatureSink::SinkFlags sinkFlags, QgsFeatureSink::SinkFlags sinkFlags,
QString *newLayer, QString *newLayer,
QgsCoordinateTransformContext transformContext, const QgsCoordinateTransformContext &transformContext,
FieldNameSource fieldNameSource FieldNameSource fieldNameSource
) )
: mError( NoError ) : mError( NoError )
@ -136,7 +136,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
const QString &layerName, const QString &layerName,
ActionOnExistingFile action, ActionOnExistingFile action,
QString *newLayer, QString *newLayer,
QgsCoordinateTransformContext transformContext, const QgsCoordinateTransformContext &transformContext,
QgsFeatureSink::SinkFlags sinkFlags, QgsFeatureSink::SinkFlags sinkFlags,
FieldNameSource fieldNameSource FieldNameSource fieldNameSource
) )
@ -2112,7 +2112,7 @@ class QgsVectorFileWriterMetadataContainer
QStringList() QStringList()
<< QStringLiteral( "CRLF" ) << QStringLiteral( "CRLF" )
<< QStringLiteral( "LF" ), << QStringLiteral( "LF" ),
QString( "LF" ), // Default value QStringLiteral( "LF" ), // Default value
false // Allow None false // Allow None
) ); ) );
@ -2174,7 +2174,7 @@ class QgsVectorFileWriterMetadataContainer
layerOptions.insert( QStringLiteral( "POSTGIS_VERSION" ), new QgsVectorFileWriter::StringOption( layerOptions.insert( QStringLiteral( "POSTGIS_VERSION" ), new QgsVectorFileWriter::StringOption(
QObject::tr( "Can be set to 2.0 or 2.2 for PostGIS 2.0/2.2 compatibility. " QObject::tr( "Can be set to 2.0 or 2.2 for PostGIS 2.0/2.2 compatibility. "
"Important to set it correctly if using non-linear geometry types" ), "Important to set it correctly if using non-linear geometry types" ),
QString( "2.2" ) // Default value QStringLiteral( "2.2" ) // Default value
) ); ) );
driverMetadata.insert( QStringLiteral( "PGDUMP" ), driverMetadata.insert( QStringLiteral( "PGDUMP" ),
@ -2502,7 +2502,7 @@ gdal::ogr_feature_unique_ptr QgsVectorFileWriter::createFeature( const QgsFeatur
if ( count > 0 ) if ( count > 0 )
{ {
int pos = 0; int pos = 0;
for ( QString string : list ) for ( const QString &string : list )
{ {
lst[pos] = mCodec->fromUnicode( string ).data(); lst[pos] = mCodec->fromUnicode( string ).data();
pos++; pos++;
@ -2962,7 +2962,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormatV2( Pre
// Special rules for OGR layers // Special rules for OGR layers
if ( details.providerType == QLatin1String( "ogr" ) && !details.dataSourceUri.isEmpty() ) if ( details.providerType == QLatin1String( "ogr" ) && !details.dataSourceUri.isEmpty() )
{ {
QString srcFileName( details.providerUriParams.value( QLatin1String( "path" ) ).toString() ); QString srcFileName( details.providerUriParams.value( QStringLiteral( "path" ) ).toString() );
if ( QFile::exists( srcFileName ) && QFileInfo( fileName ).canonicalFilePath() == QFileInfo( srcFileName ).canonicalFilePath() ) if ( QFile::exists( srcFileName ) && QFileInfo( fileName ).canonicalFilePath() == QFileInfo( srcFileName ).canonicalFilePath() )
{ {
// Check the layer name too if it's a GPKG/SpatiaLite/SQLite OGR driver (pay attention: camel case in layerName) // Check the layer name too if it's a GPKG/SpatiaLite/SQLite OGR driver (pay attention: camel case in layerName)
@ -2970,7 +2970,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormatV2( Pre
if ( !( ( options.driverName == QLatin1String( "GPKG" ) || if ( !( ( options.driverName == QLatin1String( "GPKG" ) ||
options.driverName == QLatin1String( "SpatiaLite" ) || options.driverName == QLatin1String( "SpatiaLite" ) ||
options.driverName == QLatin1String( "SQLite" ) ) && options.driverName == QLatin1String( "SQLite" ) ) &&
options.layerName != details.providerUriParams.value( QLatin1String( "layerName" ) ) ) ) options.layerName != details.providerUriParams.value( QStringLiteral( "layerName" ) ) ) )
{ {
if ( errorMessage ) if ( errorMessage )
*errorMessage = QObject::tr( "Cannot overwrite a OGR layer in place" ); *errorMessage = QObject::tr( "Cannot overwrite a OGR layer in place" );
@ -3204,10 +3204,9 @@ bool QgsVectorFileWriter::deleteShapeFile( const QString &fileName )
QDir dir = fi.dir(); QDir dir = fi.dir();
QStringList filter; QStringList filter;
const char *suffixes[] = { ".shp", ".shx", ".dbf", ".prj", ".qix", ".qpj", ".cpg", ".sbn", ".sbx", ".idm", ".ind" }; for ( const char *suffix : { ".shp", ".shx", ".dbf", ".prj", ".qix", ".qpj", ".cpg", ".sbn", ".sbx", ".idm", ".ind" } )
for ( std::size_t i = 0; i < sizeof( suffixes ) / sizeof( *suffixes ); i++ )
{ {
filter << fi.completeBaseName() + suffixes[i]; filter << fi.completeBaseName() + suffix;
} }
bool ok = true; bool ok = true;

View File

@ -587,7 +587,7 @@ class CORE_EXPORT QgsVectorFileWriter : public QgsFeatureSink
QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags() QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags()
#ifndef SIP_RUN #ifndef SIP_RUN
, QString *newLayer = nullptr, , QString *newLayer = nullptr,
QgsCoordinateTransformContext transformContext = QgsCoordinateTransformContext(), const QgsCoordinateTransformContext &transformContext = QgsCoordinateTransformContext(),
FieldNameSource fieldNameSource = Original FieldNameSource fieldNameSource = Original
#endif #endif
) SIP_DEPRECATED; ) SIP_DEPRECATED;
@ -628,7 +628,7 @@ class CORE_EXPORT QgsVectorFileWriter : public QgsFeatureSink
const QString &layerName, const QString &layerName,
QgsVectorFileWriter::ActionOnExistingFile action, QgsVectorFileWriter::ActionOnExistingFile action,
QString *newLayer = nullptr, QString *newLayer = nullptr,
QgsCoordinateTransformContext transformContext = QgsCoordinateTransformContext(), const QgsCoordinateTransformContext &transformContext = QgsCoordinateTransformContext(),
QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(), QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
FieldNameSource fieldNameSource = Original FieldNameSource fieldNameSource = Original
) SIP_SKIP; ) SIP_SKIP;