Skip to content
Permalink
Browse files
[composer] Move guidelines to correct position on page when paper siz…
…e changes, fix lines drawing with incorrect width and height
  • Loading branch information
nyalldawson committed Jun 12, 2014
1 parent bb21b4a commit 4f91399145ef4dca67ca6b74d5f9c26e1a5147ce
Showing with 37 additions and 0 deletions.
  1. +37 −0 src/core/composer/qgscomposition.cpp
@@ -220,6 +220,7 @@ QRectF QgsComposition::compositionBounds() const

void QgsComposition::setPaperSize( double width, double height )
{
//update item positions
QList<QGraphicsItem *> itemList = items();
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
for ( ; itemIt != itemList.end(); ++itemIt )
@@ -230,6 +231,28 @@ void QgsComposition::setPaperSize( double width, double height )
composerItem->updatePagePos( width, height );
}
}
//update guide positions and size
QList< QGraphicsLineItem* >* guides = snapLines();
QList< QGraphicsLineItem* >::iterator guideIt = guides->begin();
double totalHeight = ( height + spaceBetweenPages() ) * ( numPages() - 1 ) + height;
for ( ; guideIt != guides->end(); ++guideIt )
{
QLineF line = ( *guideIt )->line();
if ( line.dx() == 0 )
{
//vertical line, change height of line
( *guideIt )->setLine( line.x1(), 0, line.x1(), totalHeight );
}
else
{
//horizontal line
//move to new vertical position and change width of line
QPointF curPagePos = positionOnPage( line.p1() );
int curPage = pageNumberForPoint( line.p1() ) - 1;
double newY = curPage * ( height + spaceBetweenPages() ) + curPagePos.y();
( *guideIt )->setLine( 0, newY, width, newY );
}
}

mPageWidth = width;
mPageHeight = height;
@@ -275,6 +298,20 @@ void QgsComposition::setNumPages( int pages )
}
}

//update vertical guide height
QList< QGraphicsLineItem* >* guides = snapLines();
QList< QGraphicsLineItem* >::iterator guideIt = guides->begin();
double totalHeight = ( mPageHeight + spaceBetweenPages() ) * ( pages - 1 ) + mPageHeight;
for ( ; guideIt != guides->end(); ++guideIt )
{
QLineF line = ( *guideIt )->line();
if ( line.dx() == 0 )
{
//vertical line, change height of line
( *guideIt )->setLine( line.x1(), 0, line.x1(), totalHeight );
}
}

//update the corresponding variable
QgsExpression::setSpecialColumn( "$numpages", QVariant(( int )numPages() ) );

0 comments on commit 4f91399

Please sign in to comment.