Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #36836 from rouault/cppcheck_fixes2
Browse files Browse the repository at this point in the history
Another batch of cppcheck fixes
  • Loading branch information
rouault committed Jun 1, 2020
2 parents f26d319 + 5dd4af7 commit a8de679
Show file tree
Hide file tree
Showing 64 changed files with 279 additions and 210 deletions.
Expand Up @@ -11,7 +11,7 @@



class QgsGraphBuilder : QgsGraphBuilderInterface
class QgsGraphBuilder : QgsGraphBuilderInterface /NoDefaultCtors/
{
%Docstring
This class used for making the QgsGraph object
Expand Down
2 changes: 1 addition & 1 deletion src/3d/symbols/qgsmesh3dsymbol_p.cpp
Expand Up @@ -115,7 +115,7 @@ Qt3DRender::QGeometryRenderer *QgsMesh3DSymbolEntityNode::renderer( const Qgs3DM
}

const QgsTriangularMesh *mesh = layer->triangularMesh();
if ( layer && mesh )
if ( mesh )
{
const QVector<QgsMeshFace> &triangles = mesh->triangles();
const QVector<QgsMeshVertex> &vertices = mesh->vertices();
Expand Down
4 changes: 4 additions & 0 deletions src/analysis/interpolation/NormVecDecorator.h
Expand Up @@ -80,6 +80,10 @@ class ANALYSIS_EXPORT NormVecDecorator: public TriDecorator
QVector<PointState> *mPointState;
//! Sets the state (BreakLine, Normal, EndPoint) of a point
void setState( int pointno, PointState s );

private:
NormVecDecorator( const NormVecDecorator & ) = delete;
NormVecDecorator &operator=( const NormVecDecorator & ) = delete;
};

#ifndef SIP_RUN
Expand Down
5 changes: 4 additions & 1 deletion src/analysis/network/qgsgraphbuilder.h
Expand Up @@ -32,7 +32,7 @@ class QgsGraph;
* \brief This class used for making the QgsGraph object
*/

class ANALYSIS_EXPORT QgsGraphBuilder : public QgsGraphBuilderInterface
class ANALYSIS_EXPORT QgsGraphBuilder : public QgsGraphBuilderInterface SIP_NODEFAULTCTORS
{
public:

Expand All @@ -58,6 +58,9 @@ class ANALYSIS_EXPORT QgsGraphBuilder : public QgsGraphBuilderInterface
private:

QgsGraph *mGraph = nullptr;

QgsGraphBuilder( const QgsGraphBuilder & ) = delete;
QgsGraphBuilder &operator=( const QgsGraphBuilder & ) = delete;
};

// clazy:excludeall=qstring-allocations
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmjoinwithlines.cpp
Expand Up @@ -116,7 +116,7 @@ QVariantMap QgsJoinWithLinesAlgorithm::processAlgorithm( const QVariantMap &para
throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "HUBS" ) ) );

std::unique_ptr< QgsProcessingFeatureSource > spokeSource( parameterAsSource( parameters, QStringLiteral( "SPOKES" ), context ) );
if ( !hubSource || !spokeSource )
if ( !spokeSource )
throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "SPOKES" ) ) );

QString fieldHubName = parameterAsString( parameters, QStringLiteral( "HUB_FIELD" ), context );
Expand Down
Expand Up @@ -47,6 +47,9 @@ class ANALYSIS_EXPORT QgsGeometryFollowBoundariesCheck : public QgsGeometryCheck
enum ResolutionMethod { NoChange };
QgsVectorLayer *mCheckLayer;
QgsSpatialIndex *mIndex = nullptr;

QgsGeometryFollowBoundariesCheck( const QgsGeometryFollowBoundariesCheck & ) = delete;
QgsGeometryFollowBoundariesCheck &operator=( const QgsGeometryFollowBoundariesCheck & ) = delete;
};

#endif // QGSGEOMETRYFOLLOWBOUNDARIESCHECK_H
4 changes: 2 additions & 2 deletions src/app/qgsvariantdelegate.cpp
Expand Up @@ -361,12 +361,12 @@ QVariant::Type QgsVariantDelegate::type( const QVariant &value )

// is this an int?
// perhaps we should treat as double for more flexibility
str.toInt( &ok );
( void ) str.toInt( &ok );
if ( ok )
return QVariant::Int;

// is this a double?
str.toDouble( &ok );
( void ) str.toDouble( &ok );
if ( ok )
return QVariant::Double;

Expand Down
1 change: 1 addition & 0 deletions src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -2418,6 +2418,7 @@ void QgsVertexTool::setHighlightedVertices( const QList<Vertex> &listVertices, H
for ( const Vertex &vertex : qgis::as_const( mSelectedVertices ) )
{
// we should never be able to select vertices that are not from the locked feature
// cppcheck-suppress assertWithSideEffect
Q_ASSERT( mLockedFeature->featureId() == vertex.fid && mLockedFeature->layer() == vertex.layer );
mLockedFeature->selectVertex( vertex.vertexId );
}
Expand Down
31 changes: 7 additions & 24 deletions src/auth/basic/qgsauthbasicmethod.cpp
Expand Up @@ -154,13 +154,8 @@ bool QgsAuthBasicMethod::updateDataSourceUriItems( QStringList &connectionItems,
uri.chop( 1 );
chopped = true;
}
if ( !username.isEmpty() )
{
uri += QStringLiteral( " user='%1'" ).arg( username );

if ( !password.isEmpty() )
uri += QStringLiteral( " password='%1'" ).arg( password );
}
uri += QStringLiteral( " user='%1'" ).arg( username );
uri += QStringLiteral( " password='%1'" ).arg( password );
// add extra CAs
if ( ! caparam.isEmpty() )
{
Expand All @@ -182,30 +177,25 @@ bool QgsAuthBasicMethod::updateDataSourceUriItems( QStringList &connectionItems,
chopped = true;
}
uri += QStringLiteral( " user=%1" ).arg( username );
if ( !password.isEmpty() )
uri += QStringLiteral( " pass=%1" ).arg( password );
uri += QStringLiteral( " pass=%1" ).arg( password );
if ( chopped )
uri += '"';
}
else if ( uri.startsWith( QLatin1String( "@driver=ingres" ) ) )
{
uri += QStringLiteral( ",userid=%1" ).arg( username );
if ( !password.isEmpty() )
uri += QStringLiteral( ",password=%1" ).arg( password );
uri += QStringLiteral( ",password=%1" ).arg( password );
}
else if ( uri.startsWith( QLatin1String( "MySQL:" ) ) )
{
uri += QStringLiteral( ",user=%1" ).arg( username );
if ( !password.isEmpty() )
uri += QStringLiteral( ",password=%1" ).arg( password );
uri += QStringLiteral( ",password=%1" ).arg( password );
}
else if ( uri.startsWith( QLatin1String( "MSSQL:" ) ) )
{
uri += QStringLiteral( ";uid=%1" ).arg( username );
uri = uri.replace( QLatin1String( ";trusted_connection=yes" ), QString() );

if ( !password.isEmpty() )
uri += QStringLiteral( ";pwd=%1" ).arg( password );
uri += QStringLiteral( ";pwd=%1" ).arg( password );
}
else if ( uri.startsWith( QLatin1String( "OCI:" ) ) )
{
Expand All @@ -214,14 +204,7 @@ bool QgsAuthBasicMethod::updateDataSourceUriItems( QStringList &connectionItems,
}
else if ( uri.startsWith( QLatin1String( "ODBC:" ) ) )
{
if ( password.isEmpty() )
{
uri = uri.replace( QRegExp( "^ODBC:@?" ), "ODBC:" + username + '@' );
}
else
{
uri = uri.replace( QRegExp( "^ODBC:@?" ), "ODBC:" + username + '/' + password + '@' );
}
uri = uri.replace( QRegExp( "^ODBC:@?" ), "ODBC:" + username + '/' + password + '@' );
}
else if ( uri.startsWith( QLatin1String( "couchdb" ) )
|| uri.startsWith( QLatin1String( "DODS" ) )
Expand Down
9 changes: 3 additions & 6 deletions src/core/auth/qgsauthmanager.cpp
Expand Up @@ -84,14 +84,11 @@ const QString QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME( "Password Manag

QgsAuthManager *QgsAuthManager::instance()
{
static QMutex sMutex;
QMutexLocker locker( &sMutex );
if ( !sInstance )
{
static QMutex sMutex;
QMutexLocker locker( &sMutex );
if ( !sInstance )
{
sInstance = new QgsAuthManager( );
}
sInstance = new QgsAuthManager( );
}
return sInstance;
}
Expand Down
126 changes: 65 additions & 61 deletions src/core/dxf/qgsdxfexport_p.h
Expand Up @@ -30,83 +30,87 @@
*/
struct DxfLayerJob
{
DxfLayerJob( QgsVectorLayer *vl, const QString &layerStyleOverride, QgsRenderContext &renderContext, QgsDxfExport *dxfExport, const QString &splitLayerAttribute )
: renderContext( renderContext )
, styleOverride( vl )
, featureSource( vl )
, dxfExport( dxfExport )
, crs( vl->crs() )
, layerName( vl->name() )
, splitLayerAttribute( splitLayerAttribute )
, layerTitle( vl->title().isEmpty() ? vl->name() : vl->title() )
{
fields = vl->fields();
renderer.reset( vl->renderer()->clone() );
renderContext.expressionContext().appendScope( QgsExpressionContextUtils::layerScope( vl ) );

if ( !layerStyleOverride.isNull() )
DxfLayerJob( QgsVectorLayer *vl, const QString &layerStyleOverride, QgsRenderContext &renderContext, QgsDxfExport *dxfExport, const QString &splitLayerAttribute )
: renderContext( renderContext )
, styleOverride( vl )
, featureSource( vl )
, dxfExport( dxfExport )
, crs( vl->crs() )
, layerName( vl->name() )
, splitLayerAttribute( splitLayerAttribute )
, layerTitle( vl->title().isEmpty() ? vl->name() : vl->title() )
{
styleOverride.setOverrideStyle( layerStyleOverride );
}
fields = vl->fields();
renderer.reset( vl->renderer()->clone() );
renderContext.expressionContext().appendScope( QgsExpressionContextUtils::layerScope( vl ) );

labeling.reset( vl->labelsEnabled() ? vl->labeling()->clone() : nullptr );
if ( !layerStyleOverride.isNull() )
{
styleOverride.setOverrideStyle( layerStyleOverride );
}

attributes = renderer->usedAttributes( renderContext );
if ( !splitLayerAttribute.isNull() )
{
attributes << splitLayerAttribute;
}
labeling.reset( vl->labelsEnabled() ? vl->labeling()->clone() : nullptr );

if ( labeling )
{
QgsLabelingEngine *labelingEngine = renderContext.labelingEngine();
if ( const QgsRuleBasedLabeling *rbl = dynamic_cast<const QgsRuleBasedLabeling *>( labeling.get() ) )
attributes = renderer->usedAttributes( renderContext );
if ( !splitLayerAttribute.isNull() )
{
ruleBasedLabelProvider = new QgsRuleBasedLabelSinkProvider( *rbl, vl, dxfExport );
labelingEngine->addProvider( ruleBasedLabelProvider );

if ( !ruleBasedLabelProvider->prepare( renderContext, attributes ) )
{
labelingEngine->removeProvider( ruleBasedLabelProvider );
ruleBasedLabelProvider = nullptr;
}
attributes << splitLayerAttribute;
}
else

if ( labeling )
{
QgsPalLayerSettings settings = labeling->settings();
labelProvider = new QgsLabelSinkProvider( vl, QString(), dxfExport, &settings );
labelingEngine->addProvider( labelProvider );
QgsLabelingEngine *labelingEngine = renderContext.labelingEngine();
if ( const QgsRuleBasedLabeling *rbl = dynamic_cast<const QgsRuleBasedLabeling *>( labeling.get() ) )
{
ruleBasedLabelProvider = new QgsRuleBasedLabelSinkProvider( *rbl, vl, dxfExport );
labelingEngine->addProvider( ruleBasedLabelProvider );

if ( !labelProvider->prepare( renderContext, attributes ) )
if ( !ruleBasedLabelProvider->prepare( renderContext, attributes ) )
{
labelingEngine->removeProvider( ruleBasedLabelProvider );
ruleBasedLabelProvider = nullptr;
}
}
else
{
labelingEngine->removeProvider( labelProvider );
labelProvider = nullptr;
QgsPalLayerSettings settings = labeling->settings();
labelProvider = new QgsLabelSinkProvider( vl, QString(), dxfExport, &settings );
labelingEngine->addProvider( labelProvider );

if ( !labelProvider->prepare( renderContext, attributes ) )
{
labelingEngine->removeProvider( labelProvider );
labelProvider = nullptr;
}
}
}
}

// This will need to be started in a separate thread, if threaded somewhere else to
renderer->startRender( renderContext, fields );
};
// This will need to be started in a separate thread, if threaded somewhere else to
renderer->startRender( renderContext, fields );
};

QgsRenderContext renderContext;
QgsFields fields;
QgsMapLayerStyleOverride styleOverride;
QgsVectorLayerFeatureSource featureSource;
std::unique_ptr< QgsFeatureRenderer > renderer;
std::unique_ptr<QgsAbstractVectorLayerLabeling> labeling;
QgsDxfExport *dxfExport = nullptr;
QgsCoordinateReferenceSystem crs;
QString layerName;
QgsLabelSinkProvider *labelProvider = nullptr;
QgsRuleBasedLabelSinkProvider *ruleBasedLabelProvider = nullptr;
QString splitLayerAttribute;
QString layerTitle;
QSet<QString> attributes;

QgsRenderContext renderContext;
QgsFields fields;
QgsMapLayerStyleOverride styleOverride;
QgsVectorLayerFeatureSource featureSource;
std::unique_ptr< QgsFeatureRenderer > renderer;
std::unique_ptr<QgsAbstractVectorLayerLabeling> labeling;
QgsDxfExport *dxfExport = nullptr;
QgsCoordinateReferenceSystem crs;
QString layerName;
QgsLabelSinkProvider *labelProvider = nullptr;
QgsRuleBasedLabelSinkProvider *ruleBasedLabelProvider = nullptr;
QString splitLayerAttribute;
QString layerTitle;
QSet<QString> attributes;
private:
DxfLayerJob( const DxfLayerJob & ) = delete;
DxfLayerJob &operator=( const DxfLayerJob & ) = delete;
};

// dxf color palette
static int sDxfColors[][3] =
static const int sDxfColors[][3] =
{
{ 255, 255, 255 },
{ 255, 0, 0 },
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsgeometry.cpp
Expand Up @@ -81,8 +81,8 @@ QgsGeometry::QgsGeometry( std::unique_ptr<QgsAbstractGeometry> geom )
}

QgsGeometry::QgsGeometry( const QgsGeometry &other )
: d( other.d )
{
d = other.d;
mLastError = other.mLastError;
d->ref.ref();
}
Expand Down

0 comments on commit a8de679

Please sign in to comment.