Skip to content

Commit 4f91399

Browse files
committed
[composer] Move guidelines to correct position on page when paper size changes, fix lines drawing with incorrect width and height
1 parent bb21b4a commit 4f91399

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/core/composer/qgscomposition.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ QRectF QgsComposition::compositionBounds() const
220220

221221
void QgsComposition::setPaperSize( double width, double height )
222222
{
223+
//update item positions
223224
QList<QGraphicsItem *> itemList = items();
224225
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
225226
for ( ; itemIt != itemList.end(); ++itemIt )
@@ -230,6 +231,28 @@ void QgsComposition::setPaperSize( double width, double height )
230231
composerItem->updatePagePos( width, height );
231232
}
232233
}
234+
//update guide positions and size
235+
QList< QGraphicsLineItem* >* guides = snapLines();
236+
QList< QGraphicsLineItem* >::iterator guideIt = guides->begin();
237+
double totalHeight = ( height + spaceBetweenPages() ) * ( numPages() - 1 ) + height;
238+
for ( ; guideIt != guides->end(); ++guideIt )
239+
{
240+
QLineF line = ( *guideIt )->line();
241+
if ( line.dx() == 0 )
242+
{
243+
//vertical line, change height of line
244+
( *guideIt )->setLine( line.x1(), 0, line.x1(), totalHeight );
245+
}
246+
else
247+
{
248+
//horizontal line
249+
//move to new vertical position and change width of line
250+
QPointF curPagePos = positionOnPage( line.p1() );
251+
int curPage = pageNumberForPoint( line.p1() ) - 1;
252+
double newY = curPage * ( height + spaceBetweenPages() ) + curPagePos.y();
253+
( *guideIt )->setLine( 0, newY, width, newY );
254+
}
255+
}
233256

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

301+
//update vertical guide height
302+
QList< QGraphicsLineItem* >* guides = snapLines();
303+
QList< QGraphicsLineItem* >::iterator guideIt = guides->begin();
304+
double totalHeight = ( mPageHeight + spaceBetweenPages() ) * ( pages - 1 ) + mPageHeight;
305+
for ( ; guideIt != guides->end(); ++guideIt )
306+
{
307+
QLineF line = ( *guideIt )->line();
308+
if ( line.dx() == 0 )
309+
{
310+
//vertical line, change height of line
311+
( *guideIt )->setLine( line.x1(), 0, line.x1(), totalHeight );
312+
}
313+
}
314+
278315
//update the corresponding variable
279316
QgsExpression::setSpecialColumn( "$numpages", QVariant(( int )numPages() ) );
280317

0 commit comments

Comments
 (0)