Skip to content

Commit 146e1e2

Browse files
rouaultnyalldawson
authored andcommittedMay 19, 2020
QgsProcessingModelComponent: avoid cppcheck warnings about nullptr comment()
As base comment() implementation returns nullptr, and is virtual, it could be possible in theory that subclasses return during the first call a non-nullptr and then a nullptr...
1 parent 18a95c2 commit 146e1e2

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed
 

‎src/core/processing/models/qgsprocessingmodelcomponent.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ void QgsProcessingModelComponent::saveCommonProperties( QVariantMap &map ) const
115115
map.insert( QStringLiteral( "parameters_collapsed" ), mTopEdgeLinksCollapsed );
116116
map.insert( QStringLiteral( "outputs_collapsed" ), mBottomEdgeLinksCollapsed );
117117
map.insert( QStringLiteral( "color" ), mColor.isValid() ? QgsSymbolLayerUtils::encodeColor( mColor ) : QString() );
118-
if ( comment() )
119-
map.insert( QStringLiteral( "comment" ), comment()->toVariant() );
118+
const QgsProcessingModelComment *thisComment = comment();
119+
if ( thisComment )
120+
map.insert( QStringLiteral( "comment" ), thisComment->toVariant() );
120121
}
121122

122123
void QgsProcessingModelComponent::restoreCommonProperties( const QVariantMap &map )
@@ -131,8 +132,9 @@ void QgsProcessingModelComponent::restoreCommonProperties( const QVariantMap &ma
131132
mColor = map.value( QStringLiteral( "color" ) ).toString().isEmpty() ? QColor() : QgsSymbolLayerUtils::decodeColor( map.value( QStringLiteral( "color" ) ).toString() );
132133
mTopEdgeLinksCollapsed = map.value( QStringLiteral( "parameters_collapsed" ) ).toBool();
133134
mBottomEdgeLinksCollapsed = map.value( QStringLiteral( "outputs_collapsed" ) ).toBool();
134-
if ( comment() )
135-
comment()->loadVariant( map.value( QStringLiteral( "comment" ) ).toMap() );
135+
QgsProcessingModelComment *thisComment = comment();
136+
if ( thisComment )
137+
thisComment->loadVariant( map.value( QStringLiteral( "comment" ) ).toMap() );
136138
}
137139

138140
void QgsProcessingModelComponent::copyNonDefinitionProperties( const QgsProcessingModelComponent &other )
@@ -141,13 +143,15 @@ void QgsProcessingModelComponent::copyNonDefinitionProperties( const QgsProcessi
141143
setSize( other.size() );
142144
setLinksCollapsed( Qt::TopEdge, other.linksCollapsed( Qt::TopEdge ) );
143145
setLinksCollapsed( Qt::BottomEdge, other.linksCollapsed( Qt::BottomEdge ) );
144-
if ( comment() && other.comment() )
146+
QgsProcessingModelComment *thisComment = comment();
147+
const QgsProcessingModelComment *otherComment = other.comment();
148+
if ( thisComment && otherComment )
145149
{
146-
if ( !other.comment()->position().isNull() )
147-
comment()->setPosition( other.comment()->position() );
150+
if ( !otherComment->position().isNull() )
151+
thisComment->setPosition( otherComment->position() );
148152
else
149-
comment()->setPosition( other.position() + QPointF( size().width(), -1.5 * size().height() ) );
150-
comment()->setSize( other.comment()->size() );
153+
thisComment->setPosition( other.position() + QPointF( size().width(), -1.5 * size().height() ) );
154+
thisComment->setSize( otherComment->size() );
151155
}
152156
}
153157

0 commit comments

Comments
 (0)
Please sign in to comment.