Skip to content

Commit

Permalink
QgsProcessingModelComponent: avoid cppcheck warnings about nullptr co…
Browse files Browse the repository at this point in the history
…mment()

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...
  • Loading branch information
rouault authored and nyalldawson committed May 19, 2020
1 parent 18a95c2 commit 146e1e2
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/core/processing/models/qgsprocessingmodelcomponent.cpp
Expand Up @@ -115,8 +115,9 @@ void QgsProcessingModelComponent::saveCommonProperties( QVariantMap &map ) const
map.insert( QStringLiteral( "parameters_collapsed" ), mTopEdgeLinksCollapsed );
map.insert( QStringLiteral( "outputs_collapsed" ), mBottomEdgeLinksCollapsed );
map.insert( QStringLiteral( "color" ), mColor.isValid() ? QgsSymbolLayerUtils::encodeColor( mColor ) : QString() );
if ( comment() )
map.insert( QStringLiteral( "comment" ), comment()->toVariant() );
const QgsProcessingModelComment *thisComment = comment();
if ( thisComment )
map.insert( QStringLiteral( "comment" ), thisComment->toVariant() );
}

void QgsProcessingModelComponent::restoreCommonProperties( const QVariantMap &map )
Expand All @@ -131,8 +132,9 @@ void QgsProcessingModelComponent::restoreCommonProperties( const QVariantMap &ma
mColor = map.value( QStringLiteral( "color" ) ).toString().isEmpty() ? QColor() : QgsSymbolLayerUtils::decodeColor( map.value( QStringLiteral( "color" ) ).toString() );
mTopEdgeLinksCollapsed = map.value( QStringLiteral( "parameters_collapsed" ) ).toBool();
mBottomEdgeLinksCollapsed = map.value( QStringLiteral( "outputs_collapsed" ) ).toBool();
if ( comment() )
comment()->loadVariant( map.value( QStringLiteral( "comment" ) ).toMap() );
QgsProcessingModelComment *thisComment = comment();
if ( thisComment )
thisComment->loadVariant( map.value( QStringLiteral( "comment" ) ).toMap() );
}

void QgsProcessingModelComponent::copyNonDefinitionProperties( const QgsProcessingModelComponent &other )
Expand All @@ -141,13 +143,15 @@ void QgsProcessingModelComponent::copyNonDefinitionProperties( const QgsProcessi
setSize( other.size() );
setLinksCollapsed( Qt::TopEdge, other.linksCollapsed( Qt::TopEdge ) );
setLinksCollapsed( Qt::BottomEdge, other.linksCollapsed( Qt::BottomEdge ) );
if ( comment() && other.comment() )
QgsProcessingModelComment *thisComment = comment();
const QgsProcessingModelComment *otherComment = other.comment();
if ( thisComment && otherComment )
{
if ( !other.comment()->position().isNull() )
comment()->setPosition( other.comment()->position() );
if ( !otherComment->position().isNull() )
thisComment->setPosition( otherComment->position() );
else
comment()->setPosition( other.position() + QPointF( size().width(), -1.5 * size().height() ) );
comment()->setSize( other.comment()->size() );
thisComment->setPosition( other.position() + QPointF( size().width(), -1.5 * size().height() ) );
thisComment->setSize( otherComment->size() );
}
}

Expand Down

0 comments on commit 146e1e2

Please sign in to comment.