@@ -1415,8 +1415,9 @@ void QgsComposerMap::drawCanvasItems( QPainter* painter, const QStyleOptionGraph
1415
1415
{
1416
1416
return ;
1417
1417
}
1418
-
1419
1418
QGraphicsItem* currentItem = 0 ;
1419
+
1420
+ #if QT_VERSION >= 0x40600 // Qt 4.6 provides the items in visibility order
1420
1421
for ( int i = itemList.size () - 1 ; i >= 0 ; --i )
1421
1422
{
1422
1423
currentItem = itemList.at ( i );
@@ -1427,6 +1428,42 @@ void QgsComposerMap::drawCanvasItems( QPainter* painter, const QStyleOptionGraph
1427
1428
}
1428
1429
drawCanvasItem ( currentItem, painter, itemStyle );
1429
1430
}
1431
+ #else // Qt <4.6 provides the items in random order
1432
+ QMultiMap<int , QGraphicsItem*> topLevelItems;
1433
+ QMultiMap<QGraphicsItem*, QGraphicsItem*> childItems; // QMultiMap<parentItem, childItem>
1434
+
1435
+ for ( int i = 0 ; i < itemList.size (); ++i )
1436
+ {
1437
+ currentItem = itemList.at ( i );
1438
+ // don't draw mapcanvasmap (has z value -10)
1439
+ if ( !currentItem || currentItem->zValue () == -10 )
1440
+ {
1441
+ continue ;
1442
+ }
1443
+ if ( currentItem->parentItem () )
1444
+ {
1445
+ childItems.insert ( currentItem->parentItem (), currentItem );
1446
+ }
1447
+ else
1448
+ {
1449
+ topLevelItems.insert ( currentItem->zValue (), currentItem );
1450
+ }
1451
+ }
1452
+
1453
+ QMultiMap<int , QGraphicsItem*>::iterator topLevelIt = topLevelItems.begin ();
1454
+ for ( ; topLevelIt != topLevelItems.end (); ++topLevelIt )
1455
+ {
1456
+ drawCanvasItem ( topLevelIt.value (), painter, itemStyle );
1457
+ // Draw children. They probably should be sorted according to z-order, but we don't do it because this code is only
1458
+ // there for backward compatibility. And currently, having several embedded children is not used in QGIS
1459
+ QMap<QGraphicsItem*, QGraphicsItem*>::iterator childIt = childItems.find ( topLevelIt.value () );
1460
+ while ( childIt != childItems.end () && childIt.key () == topLevelIt.value () )
1461
+ {
1462
+ drawCanvasItem ( childIt.value (), painter, itemStyle );
1463
+ ++childIt;
1464
+ }
1465
+ }
1466
+ #endif
1430
1467
}
1431
1468
1432
1469
void QgsComposerMap::drawCanvasItem ( QGraphicsItem* item, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle )
0 commit comments