Skip to content

Commit

Permalink
QgsAbstractReportSection::next(): replace switch/case with many fall …
Browse files Browse the repository at this point in the history
…through by simpler if() based logic, to avoid cppcheck confusion
  • Loading branch information
rouault committed Jun 1, 2020
1 parent 46d3c44 commit ec3b7b7
Showing 1 changed file with 69 additions and 80 deletions.
149 changes: 69 additions & 80 deletions src/core/layout/qgsabstractreportsection.cpp
Expand Up @@ -248,112 +248,101 @@ bool QgsAbstractReportSection::next()
{
mSectionNumber++;

switch ( mNextSection )
if ( mNextSection == Header )
{
case Header:
{
// regardless of whether we have a header or not, the next section will be the body
mNextSection = Body;
// regardless of whether we have a header or not, the next section will be the body
mNextSection = Body;

// if we have a header, then the current section will be the header
if ( mHeaderEnabled && mHeader )
// if we have a header, then the current section will be the header
if ( mHeaderEnabled && mHeader )
{
if ( prepareHeader() )
{
if ( prepareHeader() )
{
mCurrentLayout = mHeader.get();
return true;
}
mCurrentLayout = mHeader.get();
return true;
}

// but if not, then the current section is a body
mNextSection = Body;
FALLTHROUGH
}

case Body:
{
mNextSection = Children;
// but if not, then the current section is a body
mNextSection = Body;
}

bool ok = false;
// if we have a next body available, use it
QgsLayout *body = nextBody( ok );
if ( body )
{
mNextChild = 0;
mCurrentLayout = body;
return true;
}
if ( mNextSection == Body )
{
mNextSection = Children;

FALLTHROUGH
bool ok = false;
// if we have a next body available, use it
QgsLayout *body = nextBody( ok );
if ( body )
{
mNextChild = 0;
mCurrentLayout = body;
return true;
}
}

case Children:
if ( mNextSection == Children )
{
bool bodiesAvailable = false;
do
{
bool bodiesAvailable = false;
do
// we iterate through all the section's children...
while ( mNextChild < mChildren.count() )
{
// we iterate through all the section's children...
while ( mNextChild < mChildren.count() )
// ... staying on the current child only while it still has content for us
if ( mChildren.at( mNextChild )->next() )
{
// ... staying on the current child only while it still has content for us
if ( mChildren.at( mNextChild )->next() )
{
mCurrentLayout = mChildren.at( mNextChild )->layout();
return true;
}
else
{
// no more content for this child, so move to next child
mNextChild++;
}
mCurrentLayout = mChildren.at( mNextChild )->layout();
return true;
}

// used up all the children
// if we have a next body available, use it
QgsLayout *body = nextBody( bodiesAvailable );
if ( bodiesAvailable )
else
{
mNextChild = 0;

for ( QgsAbstractReportSection *section : qgis::as_const( mChildren ) )
{
section->reset();
}
// no more content for this child, so move to next child
mNextChild++;
}
if ( body )
}

// used up all the children
// if we have a next body available, use it
QgsLayout *body = nextBody( bodiesAvailable );
if ( bodiesAvailable )
{
mNextChild = 0;

for ( QgsAbstractReportSection *section : qgis::as_const( mChildren ) )
{
mCurrentLayout = body;
return true;
section->reset();
}
}
while ( bodiesAvailable );

// all children and bodies have spent their content, so move to the footer
mNextSection = Footer;
FALLTHROUGH
if ( body )
{
mCurrentLayout = body;
return true;
}
}
while ( bodiesAvailable );

case Footer:
{
// regardless of whether we have a footer or not, this is the last section
mNextSection = End;
// all children and bodies have spent their content, so move to the footer
mNextSection = Footer;
}

// if we have a footer, then the current section will be the footer
if ( mFooterEnabled && mFooter )
if ( mNextSection == Footer )
{
// regardless of whether we have a footer or not, this is the last section
mNextSection = End;

// if we have a footer, then the current section will be the footer
if ( mFooterEnabled && mFooter )
{
if ( prepareFooter() )
{
if ( prepareFooter() )
{
mCurrentLayout = mFooter.get();
return true;
}
mCurrentLayout = mFooter.get();
return true;
}

// if not, then we're all done
FALLTHROUGH
}

case End:
break;
// if not, then we're all done
}

mCurrentLayout = nullptr;
Expand Down

0 comments on commit ec3b7b7

Please sign in to comment.