File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -296,13 +296,19 @@ void QgsLegendRenderer::setColumns( QList<Atom>& atomList )
296296 currentHeight += spaceAboveAtom ( atom );
297297 currentHeight += atom.size .height ();
298298
299- // Recalc average height for remaining columns including current
300- avgColumnHeight = ( totalHeight - closedColumnsHeight ) / ( mSettings .columnCount () - currentColumn );
301- if (( currentHeight - avgColumnHeight ) > atom.size .height () / 2 // center of current atom is over average height
302- && currentColumnAtomCount > 0 // do not leave empty column
303- && currentHeight > maxAtomHeight // no sense to make smaller columns than max atom height
304- && currentHeight > maxColumnHeight // no sense to make smaller columns than max column already created
305- && currentColumn < mSettings .columnCount () - 1 ) // must not exceed max number of columns
299+ bool canCreateNewColumn = ( currentColumnAtomCount > 0 ) // do not leave empty column
300+ && ( currentColumn < mSettings .columnCount () - 1 ); // must not exceed max number of columns
301+
302+ bool shouldCreateNewColumn = ( currentHeight - avgColumnHeight ) > atom.size .height () / 2 // center of current atom is over average height
303+ && currentColumnAtomCount > 0 // do not leave empty column
304+ && currentHeight > maxAtomHeight // no sense to make smaller columns than max atom height
305+ && currentHeight > maxColumnHeight; // no sense to make smaller columns than max column already created
306+
307+ // also should create a new column if the number of items left < number of columns left
308+ // in this case we should spread the remaining items out over the remaining columns
309+ shouldCreateNewColumn |= ( atomList.size () - i < mSettings .columnCount () - currentColumn );
310+
311+ if ( canCreateNewColumn && shouldCreateNewColumn )
306312 {
307313 // New column
308314 currentColumn++;
You can’t perform that action at this time.
0 commit comments