Skip to content
Permalink
Browse files

Add tests

  • Loading branch information
jdugge authored and nyalldawson committed Oct 5, 2020
1 parent ee4c841 commit 08062ba95d7151a0eae03b65b4e1bd16da860d13
@@ -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;
@@ -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
@@ -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()
Binary file not shown.
Binary file not shown.

0 comments on commit 08062ba

Please sign in to comment.
You can’t perform that action at this time.