Skip to content

Commit

Permalink
[composer] Move guidelines to correct position on page when paper siz…
Browse files Browse the repository at this point in the history
…e changes, fix lines drawing with incorrect width and height
  • Loading branch information
nyalldawson committed Jun 12, 2014
1 parent bb21b4a commit 4f91399
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/core/composer/qgscomposition.cpp
Expand Up @@ -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 )
Expand All @@ -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;
Expand Down Expand Up @@ -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() ) );

Expand Down

0 comments on commit 4f91399

Please sign in to comment.