Skip to content

Commit cf5de48

Browse files
author
mhugent
committedJun 5, 2010
Added code to fix bug #2755 also for Qt<4.6
git-svn-id: http://svn.osgeo.org/qgis/trunk@13658 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 63c8f24 commit cf5de48

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed
 

‎src/core/composer/qgscomposermap.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,8 +1415,9 @@ void QgsComposerMap::drawCanvasItems( QPainter* painter, const QStyleOptionGraph
14151415
{
14161416
return;
14171417
}
1418-
14191418
QGraphicsItem* currentItem = 0;
1419+
1420+
#if QT_VERSION >= 0x40600 //Qt 4.6 provides the items in visibility order
14201421
for ( int i = itemList.size() - 1; i >= 0; --i )
14211422
{
14221423
currentItem = itemList.at( i );
@@ -1427,6 +1428,42 @@ void QgsComposerMap::drawCanvasItems( QPainter* painter, const QStyleOptionGraph
14271428
}
14281429
drawCanvasItem( currentItem, painter, itemStyle );
14291430
}
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
14301467
}
14311468

14321469
void QgsComposerMap::drawCanvasItem( QGraphicsItem* item, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle )

0 commit comments

Comments
 (0)
Please sign in to comment.