Skip to content

Commit

Permalink
Fix for zList sort problem and added call to composer item readXML in…
Browse files Browse the repository at this point in the history
… composer arrow

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13585 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 29, 2010
1 parent b86f859 commit c092e6e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 47 deletions.
20 changes: 10 additions & 10 deletions src/core/composer/qgscomposerarrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ bool QgsComposerArrow::writeXML( QDomElement& elem, QDomDocument & doc ) const
composerArrowElem.appendChild( stopPointElem );

elem.appendChild( composerArrowElem );
return true;
return _writeXML( composerArrowElem, doc );
}

bool QgsComposerArrow::readXML( const QDomElement& itemElem, const QDomDocument& doc )
Expand All @@ -325,6 +325,15 @@ bool QgsComposerArrow::readXML( const QDomElement& itemElem, const QDomDocument&
mArrowColor = QColor( red, green, blue, alpha );
}

//restore general composer item properties
//needs to be before start point / stop point because setSceneRect()
QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
if ( composerItemList.size() > 0 )
{
QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
_readXML( composerItemElem, doc );
}

//start point
QDomNodeList startPointList = itemElem.elementsByTagName( "StartPoint" );
if ( startPointList.size() > 0 )
Expand All @@ -343,15 +352,6 @@ bool QgsComposerArrow::readXML( const QDomElement& itemElem, const QDomDocument&
mStopPoint.setY( stopPointElem.attribute( "y", "0.0" ).toDouble() );
}


//restore general composer item properties
QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
if ( composerItemList.size() > 0 )
{
QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
_readXML( composerItemElem, doc );
}

adaptItemSceneRect();
return true;
}
52 changes: 15 additions & 37 deletions src/core/composer/qgscomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,11 @@ void QgsComposition::updateZValues()

void QgsComposition::sortZList()
{
if ( mItemZList.size() < 2 )
{
return;
}

#ifdef QGISDEBUG
//debug: list before sorting
QgsDebugMsg( "before sorting" );
Expand All @@ -547,51 +552,24 @@ void QgsComposition::sortZList()
}
#endif

QMutableLinkedListIterator<QgsComposerItem*> it( mItemZList );
int previousZ, afterZ; //z values of items before and after
QgsComposerItem* previousItem;
QgsComposerItem* afterItem;
QLinkedList<QgsComposerItem*>::const_iterator lIt = mItemZList.constBegin();
QLinkedList<QgsComposerItem*> sortedList;

while ( it.hasNext() )
for ( ; lIt != mItemZList.constEnd(); ++lIt )
{
previousItem = it.next();
if ( previousItem )
{
previousZ = previousItem->zValue();
}
else
{
previousZ = -1;
}

if ( !it.hasNext() )
QLinkedList<QgsComposerItem*>::iterator insertIt = sortedList.begin();
for ( ; insertIt != sortedList.end(); ++insertIt )
{
break; //this is the end...
}
afterItem = it.peekNext();

if ( afterItem )
{
afterZ = afterItem->zValue();
}
else
{
afterZ = -1;
}

if ( previousZ > afterZ )
{
//swap items
if ( previousItem && afterItem )
if (( *lIt )->zValue() < ( *insertIt )->zValue() )
{
it.remove();
it.next();
it.insert( previousItem );
it.previous();
break;
}
}
sortedList.insert( insertIt, ( *lIt ) );
}

mItemZList = sortedList;

#ifdef QGISDEBUG
//debug: list after sorting
//debug: list before sorting
Expand Down

0 comments on commit c092e6e

Please sign in to comment.