Skip to content
Permalink
Browse files

Fix guide positioning when multiple pages are present

  • Loading branch information
nyalldawson committed Dec 18, 2017
1 parent a1128a5 commit 200669aefae44a6bdc4e1b4481f3f987f2c51e1c
@@ -89,7 +89,7 @@ void QgsLayoutGuide::update()
}
else
{
mLineItem->setLine( 0, layoutPos, mPage->rect().width(), layoutPos );
mLineItem->setLine( 0, layoutPos + mPage->y(), mPage->rect().width(), layoutPos + mPage->y() );
mLineItem->setVisible( showGuide );
}

@@ -102,7 +102,7 @@ void QgsLayoutGuide::update()
}
else
{
mLineItem->setLine( layoutPos, 0, layoutPos, mPage->rect().height() );
mLineItem->setLine( layoutPos, mPage->y(), layoutPos, mPage->y() + mPage->rect().height() );
mLineItem->setVisible( showGuide );
}

@@ -95,6 +95,7 @@ void QgsLayoutPageCollection::reflow()
currentY += mLayout->convertToLayoutUnits( page->pageSize() ).height() + spaceBetweenPages();
p.setY( currentY );
}
mLayout->guides().update();
mLayout->updateBounds();
emit changed();
}
@@ -193,7 +194,8 @@ int QgsLayoutPageCollection::predictPageNumberForPoint( QPointF point ) const

QgsLayoutItemPage *QgsLayoutPageCollection::pageAtPoint( QPointF point ) const
{
Q_FOREACH ( QGraphicsItem *item, mLayout->items( point ) )
const QList< QGraphicsItem * > items = mLayout->items( point );
for ( QGraphicsItem *item : items )
{
if ( item->type() == QgsLayoutItemRegistry::LayoutPage )
{
@@ -65,6 +65,11 @@ def testUpdateGuide(self):
p = QgsProject()
l = QgsLayout(p)
l.initializeDefaults() # add a page
# add a second page
page2 = QgsLayoutItemPage(l)
page2.setPageSize('A5')
l.pageCollection().addPage(page2)

g = QgsLayoutGuide(Qt.Horizontal, QgsLayoutMeasurement(5, QgsUnitTypes.LayoutCentimeters), l.pageCollection().page(0))
g.setLayout(l)
g.update()
@@ -85,6 +90,19 @@ def testUpdateGuide(self):
self.assertEqual(g.item().line().y2(), 15)
self.assertEqual(g.layoutPosition(), 15)

# guide on page2
g1 = QgsLayoutGuide(Qt.Horizontal, QgsLayoutMeasurement(5, QgsUnitTypes.LayoutCentimeters), l.pageCollection().page(1))
g1.setLayout(l)
g1.update()
g1.setPosition(QgsLayoutMeasurement(15, QgsUnitTypes.LayoutMillimeters))
g1.update()
self.assertTrue(g1.item().isVisible())
self.assertEqual(g1.item().line().x1(), 0)
self.assertEqual(g1.item().line().y1(), 235)
self.assertEqual(g1.item().line().x2(), 148)
self.assertEqual(g1.item().line().y2(), 235)
self.assertEqual(g1.layoutPosition(), 235)

# vertical guide
g2 = QgsLayoutGuide(Qt.Vertical, QgsLayoutMeasurement(5, QgsUnitTypes.LayoutCentimeters), l.pageCollection().page(0))
g2.setLayout(l)
@@ -109,6 +127,17 @@ def testUpdateGuide(self):
g.update()
self.assertFalse(g.item().isVisible())

# guide on page2
g3 = QgsLayoutGuide(Qt.Vertical, QgsLayoutMeasurement(5, QgsUnitTypes.LayoutCentimeters), l.pageCollection().page(1))
g3.setLayout(l)
g3.update()
self.assertTrue(g3.item().isVisible())
self.assertEqual(g3.item().line().x1(), 50)
self.assertEqual(g3.item().line().y1(), 220)
self.assertEqual(g3.item().line().x2(), 50)
self.assertEqual(g3.item().line().y2(), 430)
self.assertEqual(g3.layoutPosition(), 50)

def testCollection(self):
p = QgsProject()
l = QgsLayout(p)

0 comments on commit 200669a

Please sign in to comment.
You can’t perform that action at this time.