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