Skip to content

Commit

Permalink
limit max number of raster symbol items in legend (may be very slow),…
Browse files Browse the repository at this point in the history
… resolves slow loading of rasters with large color tables
  • Loading branch information
blazek committed May 1, 2013
1 parent 3c68312 commit 2e446a8
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/app/legend/qgslegendlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,30 @@ void QgsLegendLayer::rasterLayerSymbology( QgsRasterLayer* layer )
SymbologyList itemList;
QList< QPair< QString, QColor > > rasterItemList = layer->legendSymbologyItems();
QList< QPair< QString, QColor > >::const_iterator itemIt = rasterItemList.constBegin();
#if QT_VERSION >= 0x40700
itemList.reserve( rasterItemList.size() );
#endif
// Paletted raster may have many colors, for example UInt16 may have 65536 colors
// and it is very slow, so we limit max count
QSize iconSize = treeWidget()->iconSize();
int count = 0;
int max_count = 1000;
for ( ; itemIt != rasterItemList.constEnd(); ++itemIt )
{
QPixmap itemPixmap( treeWidget()->iconSize() );
QPixmap itemPixmap( iconSize );
itemPixmap.fill( itemIt->second );
// This is very slow, not clear why, it should not be, probably realloc,
// but it seems to be non linear
itemList.append( qMakePair( itemIt->first, itemPixmap ) );
count++;
if ( count == max_count )
{
itemPixmap = QPixmap( iconSize );
itemPixmap.fill( Qt::transparent );
QString label = tr( "following %1 items\nnot displayed" ).arg( rasterItemList.size() - max_count );
itemList.append( qMakePair( label, itemPixmap ) );
break;
}
}
changeSymbologySettings( layer, itemList );
}
Expand Down

0 comments on commit 2e446a8

Please sign in to comment.