Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdugge authored and nyalldawson committed Oct 5, 2020
1 parent ee4c841 commit 08062ba
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/core/qgslegendrenderer.cpp
Expand Up @@ -453,7 +453,7 @@ int QgsLegendRenderer::setColumns( QList<LegendComponentGroup> &componentGroups
if ( group.placeColumnBreakBeforeGroup )
forcedColumnBreaks++;
}
double averageGroupHeight = (totalHeight - totalSpaceAboveGroups) / componentGroups.size();
double averageGroupHeight = ( totalHeight - totalSpaceAboveGroups ) / componentGroups.size();

if ( mSettings.columnCount() == 0 && forcedColumnBreaks == 0 )
return 0;
Expand Down Expand Up @@ -495,11 +495,11 @@ int QgsLegendRenderer::setColumns( QList<LegendComponentGroup> &componentGroups

// Recalc average height for remaining columns including current
int numberRemainingColumns = numberAutoPlacedBreaks + 1 - autoPlacedBreaks;
double avgColumnHeight = ( currentHeight + numberRemainingGroups * averageGroupHeight + (numberRemainingGroups - numberRemainingColumns - 1) * averageSpaceAboveGroups ) / numberRemainingColumns;
double avgColumnHeight = ( currentHeight + numberRemainingGroups * averageGroupHeight + ( numberRemainingGroups - numberRemainingColumns - 1 ) * averageSpaceAboveGroups ) / numberRemainingColumns;
// Round up to the next full number of groups to put in one column
// This ensures that earlier columns contain more elements than later columns
int averageGroupsPerColumn = std::ceil(avgColumnHeight / (averageGroupHeight + averageSpaceAboveGroups));
avgColumnHeight = averageGroupsPerColumn * (averageGroupHeight + averageSpaceAboveGroups) - averageSpaceAboveGroups;
int averageGroupsPerColumn = std::ceil( avgColumnHeight / ( averageGroupHeight + averageSpaceAboveGroups ) );
avgColumnHeight = averageGroupsPerColumn * ( averageGroupHeight + averageSpaceAboveGroups ) - averageSpaceAboveGroups;

bool canCreateNewColumn = ( currentColumnGroupCount > 0 ) // do not leave empty column
&& ( currentColumn < targetNumberColumns - 1 ) // must not exceed max number of columns
Expand Down
2 changes: 2 additions & 0 deletions tests/src/core/testqgslegendrenderer.cpp
Expand Up @@ -934,6 +934,8 @@ void TestQgsLegendRenderer::testColumns_data()
QTest::newRow( "5 items, 3 columns" ) << "legend_5_by_3" << 5 << 3;
QTest::newRow( "6 items, 3 columns" ) << "legend_6_by_3" << 6 << 3;
QTest::newRow( "7 items, 3 columns" ) << "legend_7_by_3" << 7 << 3;
QTest::newRow( "27 items, 3 columns" ) << "legend_27_by_3" << 27 << 3;
QTest::newRow( "27 items, 9 columns" ) << "legend_27_by_9" << 27 << 9;
}

void TestQgsLegendRenderer::testColumns()
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 08062ba

Please sign in to comment.