Skip to content

Commit

Permalink
Merge pull request #40870 from elpaso/clazy-fixes
Browse files Browse the repository at this point in the history
Fix clazy warnings
  • Loading branch information
rouault committed Jan 6, 2021
2 parents fd7406c + 112810c commit 094985c
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 39 deletions.
@@ -1,4 +1,5 @@
# The following has been generated automatically from src/core/qgsabstractdatabaseproviderconnection.h
QgsAbstractDatabaseProviderConnection.TableFlag.baseClass = QgsAbstractDatabaseProviderConnection
QgsAbstractDatabaseProviderConnection.TableFlags.baseClass = QgsAbstractDatabaseProviderConnection
TableFlags = QgsAbstractDatabaseProviderConnection # dirty hack since SIP seems to introduce the flags in module
QgsAbstractDatabaseProviderConnection.Capability.baseClass = QgsAbstractDatabaseProviderConnection
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsabstractdatabaseproviderconnection.h
Expand Up @@ -63,7 +63,7 @@ class CORE_EXPORT QgsAbstractDatabaseProviderConnection : public QgsAbstractProv
Foreign = 1 << 6, //!< Foreign data wrapper
};

Q_ENUMS( TableFlag )
Q_ENUM( TableFlag )
Q_DECLARE_FLAGS( TableFlags, TableFlag )
Q_FLAG( TableFlags )

Expand Down
27 changes: 14 additions & 13 deletions src/providers/postgres/qgspostgresproviderconnection.cpp
Expand Up @@ -84,8 +84,7 @@ void QgsPostgresProviderConnection::setDefaultCapabilities()
void QgsPostgresProviderConnection::dropTablePrivate( const QString &schema, const QString &name ) const
{
executeSqlPrivate( QStringLiteral( "DROP TABLE %1.%2" )
.arg( QgsPostgresConn::quotedIdentifier( schema ) )
.arg( QgsPostgresConn::quotedIdentifier( name ) ) );
.arg( QgsPostgresConn::quotedIdentifier( schema ), QgsPostgresConn::quotedIdentifier( name ) ) );
}

void QgsPostgresProviderConnection::createVectorTable( const QString &schema,
Expand Down Expand Up @@ -151,9 +150,9 @@ void QgsPostgresProviderConnection::dropRasterTable( const QString &schema, cons
void QgsPostgresProviderConnection::renameTablePrivate( const QString &schema, const QString &name, const QString &newName ) const
{
executeSqlPrivate( QStringLiteral( "ALTER TABLE %1.%2 RENAME TO %3" )
.arg( QgsPostgresConn::quotedIdentifier( schema ) )
.arg( QgsPostgresConn::quotedIdentifier( name ) )
.arg( QgsPostgresConn::quotedIdentifier( newName ) ) );
.arg( QgsPostgresConn::quotedIdentifier( schema ),
QgsPostgresConn::quotedIdentifier( name ),
QgsPostgresConn::quotedIdentifier( newName ) ) );
}

void QgsPostgresProviderConnection::renameVectorTable( const QString &schema, const QString &name, const QString &newName ) const
Expand All @@ -180,16 +179,16 @@ void QgsPostgresProviderConnection::dropSchema( const QString &name, bool force
{
checkCapability( Capability::DropSchema );
executeSqlPrivate( QStringLiteral( "DROP SCHEMA %1 %2" )
.arg( QgsPostgresConn::quotedIdentifier( name ) )
.arg( force ? QStringLiteral( "CASCADE" ) : QString() ) );
.arg( QgsPostgresConn::quotedIdentifier( name ),
force ? QStringLiteral( "CASCADE" ) : QString() ) );
}

void QgsPostgresProviderConnection::renameSchema( const QString &name, const QString &newName ) const
{
checkCapability( Capability::RenameSchema );
executeSqlPrivate( QStringLiteral( "ALTER SCHEMA %1 RENAME TO %2" )
.arg( QgsPostgresConn::quotedIdentifier( name ) )
.arg( QgsPostgresConn::quotedIdentifier( newName ) ) );
.arg( QgsPostgresConn::quotedIdentifier( name ),
QgsPostgresConn::quotedIdentifier( newName ) ) );
}

QgsAbstractDatabaseProviderConnection::QueryResult QgsPostgresProviderConnection::execSql( const QString &sql, QgsFeedback *feedback ) const
Expand Down Expand Up @@ -606,8 +605,8 @@ QList<QgsPostgresProviderConnection::TableProperty> QgsPostgresProviderConnectio
ORDER BY CASE WHEN indisprimary THEN 1 ELSE 2 END LIMIT 1)
SELECT attname FROM pg_index,pg_attribute, pkrelid
WHERE indexrelid=pkrelid.idxri AND indrelid=attrelid AND pg_attribute.attnum=any(pg_index.indkey);
)" ).arg( QgsPostgresConn::quotedIdentifier( pr.schemaName ) )
.arg( QgsPostgresConn::quotedIdentifier( pr.tableName ) ) );
)" ).arg( QgsPostgresConn::quotedIdentifier( pr.schemaName ),
QgsPostgresConn::quotedIdentifier( pr.tableName ) ) );
QStringList pkNames;
for ( const auto &pk : qgis::as_const( pks ) )
{
Expand Down Expand Up @@ -761,14 +760,16 @@ QgsFields QgsPostgresProviderConnection::fields( const QString &schema, const QS
QgsDataSourceUri tUri { tableUri( schema, tableName ) };
if ( tableInfo.geometryColumnTypes().count( ) > 1 )
{
TableProperty::GeometryColumnType geomCol { tableInfo.geometryColumnTypes().first() };
const auto geomColTypes( tableInfo.geometryColumnTypes() );
TableProperty::GeometryColumnType geomCol { geomColTypes.first() };
tUri.setGeometryColumn( tableInfo.geometryColumn() );
tUri.setWkbType( geomCol.wkbType );
tUri.setSrid( QString::number( geomCol.crs.postgisSrid() ) );
}
if ( tableInfo.primaryKeyColumns().count() > 0 )
{
tUri.setKeyColumn( tableInfo.primaryKeyColumns().first() );
const auto constPkCols( tableInfo.primaryKeyColumns() );
tUri.setKeyColumn( constPkCols.first() );
}
tUri.setParam( QStringLiteral( "checkPrimaryKeyUnicity" ), QLatin1String( "0" ) );
QgsVectorLayer::LayerOptions options { false, true };
Expand Down
2 changes: 1 addition & 1 deletion src/server/qgis_mapserver.cpp
Expand Up @@ -372,7 +372,7 @@ int main( int argc, char *argv[] )
// Take Host header if defined
if ( headers.contains( QStringLiteral( "Host" ) ) )
{
url = QStringLiteral( "http://%1%2" ).arg( headers.value( QStringLiteral( "Host" ) ) ).arg( path );
url = QStringLiteral( "http://%1%2" ).arg( headers.value( QStringLiteral( "Host" ) ), path );
}
else
{
Expand Down
5 changes: 3 additions & 2 deletions src/server/qgsserverogcapi.cpp
Expand Up @@ -150,8 +150,9 @@ QString QgsServerOgcApi::contentTypeToExtension( const ContentType &ct )
QgsServerOgcApi::ContentType QgsServerOgcApi::contenTypeFromExtension( const std::string &extension )
{
const QString exts = QString::fromStdString( extension );
for ( auto it = QgsServerOgcApi::contentTypeMimes().constBegin();
it != QgsServerOgcApi::contentTypeMimes().constEnd();
const auto constMimeTypes( QgsServerOgcApi::contentTypeMimes() );
for ( auto it = constMimeTypes.constBegin();
it != constMimeTypes.constEnd();
++it )
{
const auto constValues = it.value();
Expand Down
13 changes: 8 additions & 5 deletions src/server/qgsserverogcapihandler.cpp
Expand Up @@ -67,7 +67,8 @@ QgsServerOgcApiHandler::~QgsServerOgcApiHandler()

QgsServerOgcApi::ContentType QgsServerOgcApiHandler::defaultContentType() const
{
return contentTypes().size() > 0 ? contentTypes().first() : QgsServerOgcApi::ContentType::JSON;
const auto constContentTypes( contentTypes() );
return constContentTypes.size() > 0 ? constContentTypes.first() : QgsServerOgcApi::ContentType::JSON;
}

QList<QgsServerOgcApi::ContentType> QgsServerOgcApiHandler::contentTypes() const
Expand All @@ -83,8 +84,9 @@ void QgsServerOgcApiHandler::handleRequest( const QgsServerApiContext &context )

QString QgsServerOgcApiHandler::contentTypeForAccept( const QString &accept ) const
{
for ( auto it = QgsServerOgcApi::contentTypeMimes().constBegin();
it != QgsServerOgcApi::contentTypeMimes().constEnd(); ++it )
const auto constContentTypes( QgsServerOgcApi::contentTypeMimes() );
for ( auto it = constContentTypes.constBegin();
it != constContentTypes.constEnd(); ++it )
{
const auto constValues = it.value();
for ( const auto &value : constValues )
Expand Down Expand Up @@ -452,8 +454,9 @@ QgsServerOgcApi::ContentType QgsServerOgcApiHandler::contentTypeFromRequest( con
const QString ctFromAccept { contentTypeForAccept( accept ) };
if ( ! ctFromAccept.isEmpty() )
{
auto it = QgsServerOgcApi::contentTypeMimes().constBegin();
while ( ! found && it != QgsServerOgcApi::contentTypeMimes().constEnd() )
const auto constContentTypes( QgsServerOgcApi::contentTypeMimes() );
auto it = constContentTypes.constBegin();
while ( ! found && it != constContentTypes.constEnd() )
{
int idx = it.value().indexOf( ctFromAccept );
if ( idx >= 0 )
Expand Down
18 changes: 12 additions & 6 deletions src/server/qgsserverparameters.cpp
Expand Up @@ -94,7 +94,8 @@ QList<QgsGeometry> QgsServerParameterDefinition::toGeomList( bool &ok, const cha
ok = true;
QList<QgsGeometry> geoms;

for ( const auto &wkt : toStringList( delimiter ) )
const auto constStringList( toStringList( delimiter ) );
for ( const auto &wkt : constStringList )
{
const QgsGeometry g( QgsGeometry::fromWkt( wkt ) );

Expand All @@ -117,7 +118,8 @@ QList<QColor> QgsServerParameterDefinition::toColorList( bool &ok, const char de
ok = true;
QList<QColor> colors;

for ( const auto &part : toStringList( delimiter ) )
const auto constStringList( toStringList( delimiter ) );
for ( const auto &part : constStringList )
{
QString cStr( part );
if ( !cStr.isEmpty() )
Expand Down Expand Up @@ -148,7 +150,8 @@ QList<int> QgsServerParameterDefinition::toIntList( bool &ok, const char delimit
ok = true;
QList<int> ints;

for ( const auto &part : toStringList( delimiter ) )
const auto constStringList( toStringList( delimiter ) );
for ( const auto &part : constStringList )
{
const int val = part.toInt( &ok );

Expand All @@ -168,7 +171,8 @@ QList<double> QgsServerParameterDefinition::toDoubleList( bool &ok, const char d
ok = true;
QList<double> vals;

for ( const auto &part : toStringList( delimiter ) )
const auto constStringList( toStringList( delimiter ) );
for ( const auto &part : constStringList )
{
const double val = part.toDouble( &ok );

Expand Down Expand Up @@ -439,7 +443,8 @@ QUrlQuery QgsServerParameters::urlQuery() const
{
query.clear();

for ( auto param : toMap().toStdMap() )
const auto constMap( toMap().toStdMap() );
for ( const auto &param : constMap )
{
query.addQueryItem( param.first, param.second );
}
Expand Down Expand Up @@ -553,7 +558,8 @@ void QgsServerParameters::load( const QUrlQuery &query )
cleanQuery.setQuery( query.query().replace( '+', QLatin1String( "%20" ) ) );

// load parameters
for ( const auto &item : cleanQuery.queryItems( QUrl::FullyDecoded ) )
const auto constQueryItems( cleanQuery.queryItems( QUrl::FullyDecoded ) );
for ( const auto &item : constQueryItems )
{
const QgsServerParameter::Name name = QgsServerParameter::name( item.first );
if ( name >= 0 )
Expand Down
4 changes: 3 additions & 1 deletion src/server/qgsserverplugins.cpp
Expand Up @@ -88,7 +88,9 @@ bool QgsServerPlugins::initPlugins( QgsServerInterface *interface )
//Init plugins: loads a list of installed plugins and filter them
//for "server" metadata
bool atLeastOneEnabled = false;
for ( const QString &pluginName : sPythonUtils->pluginList() )

const auto constPluginList( sPythonUtils->pluginList() );
for ( const QString &pluginName : constPluginList )
{
QString pluginService = sPythonUtils->getPluginMetadata( pluginName, QStringLiteral( "server" ) );
if ( pluginService == QLatin1String( "True" ) )
Expand Down
5 changes: 2 additions & 3 deletions src/server/qgsserverquerystringparameter.cpp
Expand Up @@ -95,15 +95,14 @@ QVariant QgsServerQueryStringParameter::value( const QgsServerApiContext &contex

if ( ! ok )
{
throw QgsServerApiBadRequestException( QStringLiteral( "Argument '%1' could not be converted to %2" ).arg( mName )
.arg( typeName( mType ) ) );
throw QgsServerApiBadRequestException( QStringLiteral( "Argument '%1' could not be converted to %2" ).arg( mName, typeName( mType ) ) );
}
}

// 4: check custom validation
if ( mCustomValidator && ! mCustomValidator( context, value ) )
{
throw QgsServerApiBadRequestException( QStringLiteral( "Argument '%1' is not valid. %2" ).arg( name() ).arg( description() ) );
throw QgsServerApiBadRequestException( QStringLiteral( "Argument '%1' is not valid. %2" ).arg( name(), description() ) );
}
}
return value;
Expand Down
5 changes: 3 additions & 2 deletions src/server/qgsserversettings.cpp
Expand Up @@ -356,7 +356,8 @@ void QgsServerSettings::loadQSettings( const QString &envOptPath ) const

void QgsServerSettings::prioritize( const QMap<QgsServerSettingsEnv::EnvVar, QString> &env )
{
for ( QgsServerSettingsEnv::EnvVar e : env.keys() )
const auto constKeys( env.keys() );
for ( const QgsServerSettingsEnv::EnvVar &e : constKeys )
{
Setting s = mSettings[ e ];

Expand Down Expand Up @@ -405,7 +406,7 @@ void QgsServerSettings::logSummary() const
const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );

QgsMessageLog::logMessage( "QGIS Server Settings: ", "Server", Qgis::Info );
for ( Setting s : mSettings )
for ( const Setting &s : qgis::as_const( mSettings ) )
{
const QString src = metaEnumSrc.valueToKey( s.src );
const QString var = name( s.envVar );
Expand Down
3 changes: 2 additions & 1 deletion src/server/qgsservicenativeloader.cpp
Expand Up @@ -67,7 +67,8 @@ void QgsServiceNativeLoader::loadModules( const QString &modulePath, QgsServiceR

// qDebug() << QString( "Checking %1 for native services modules" ).arg( moduleDir.path() );

for ( const QFileInfo &fi : moduleDir.entryInfoList() )
const auto constFiList( moduleDir.entryInfoList() );
for ( const QFileInfo &fi : constFiList )
{
QgsServiceModule *module = loadNativeModule( fi.filePath() );
if ( module )
Expand Down
7 changes: 4 additions & 3 deletions src/server/services/landingpage/qgslandingpageutils.cpp
Expand Up @@ -103,7 +103,7 @@ QMap<QString, QString> QgsLandingPageUtils::projects( const QgsServerSettings &s
}
else
{
QgsMessageLog::logMessage( QStringLiteral( "%1 entry '%2' was not found: skipping." ).arg( envDirName ).arg( path ), QStringLiteral( "Landing Page" ), Qgis::MessageLevel::Warning );
QgsMessageLog::logMessage( QStringLiteral( "%1 entry '%2' was not found: skipping." ).arg( envDirName, path ), QStringLiteral( "Landing Page" ), Qgis::MessageLevel::Warning );
}
}
else
Expand Down Expand Up @@ -135,7 +135,7 @@ QMap<QString, QString> QgsLandingPageUtils::projects( const QgsServerSettings &s
}
else
{
QgsMessageLog::logMessage( QStringLiteral( "%1 entry '%2' was not found or has not projects: skipping." ).arg( envPgName ).arg( connectionString ), QStringLiteral( "Landing Page" ), Qgis::MessageLevel::Warning );
QgsMessageLog::logMessage( QStringLiteral( "%1 entry '%2' was not found or has not projects: skipping." ).arg( envPgName, connectionString ), QStringLiteral( "Landing Page" ), Qgis::MessageLevel::Warning );
}
}
else
Expand Down Expand Up @@ -531,9 +531,10 @@ json QgsLandingPageUtils::projectInfo( const QString &projectUri, const QgsServe
// Keywords
json jKeywords = json::object();
const auto &cKw { md.keywords().keys() };
const auto &cVals { md.keywords() };
for ( const auto &k : cKw )
{
jKeywords[ k.toStdString() ] = jList( md.keywords()[ k ] );
jKeywords[ k.toStdString() ] = jList( cVals[ k ] );
}
layerMetadata[ "keywords" ] = jKeywords;
layerMetadata[ "language" ] = md.language( ).toStdString();
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_qgsserver.py
Expand Up @@ -141,7 +141,7 @@ def setUp(self):
os.environ["QGIS_SERVER_DISABLED_APIS"] = "Landing Page"

def tearDown(self):
""""Cleanup env"""
"""Cleanup env"""

super().tearDown()
try:
Expand Down

0 comments on commit 094985c

Please sign in to comment.