Skip to content
Permalink
Browse files

Fix drawing of rulers with multipage layouts

  • Loading branch information
nyalldawson committed Jul 21, 2017
1 parent 4cf9827 commit 416e1e4bbff90fb5c3bd488122b1ab3d9ac17092
@@ -137,6 +137,13 @@ Size of page shadow, in layout coordinates
:rtype: float
%End

signals:

void changed();
%Docstring
Emitted when pages are added or removed from the collection.
%End

};

/************************************************************************
@@ -186,6 +186,8 @@ class QgsLayoutView: QGraphicsView

virtual void resizeEvent( QResizeEvent *event );

virtual void scrollContentsBy( int dx, int dy );


};

@@ -257,15 +257,10 @@ void QgsLayoutDesignerDialog::open()
{
show();
activate();
mView->zoomFull(); // zoomFull() does not work properly until we have called show()

#if 0 // TODO

if ( mView )
{
mView->updateRulers();
mView->zoomFull(); // zoomFull() does not work properly until we have called show()
}
#endif
}

void QgsLayoutDesignerDialog::activate()
@@ -52,6 +52,7 @@ void QgsLayoutPageCollection::reflow()
p.setY( currentY );
}
mLayout->updateBounds();
emit changed();
}

double QgsLayoutPageCollection::maximumPageWidth() const
@@ -145,6 +145,13 @@ class CORE_EXPORT QgsLayoutPageCollection : public QObject
*/
double maximumPageWidth() const;

signals:

/**
* Emitted when pages are added or removed from the collection.
*/
void changed();

private:

QgsLayout *mLayout = nullptr;
@@ -66,9 +66,8 @@ void QgsLayoutRuler::paintEvent( QPaintEvent *event )
{
return;
}
#if 0

QgsLayout *layout = mView->currentLayout();
#endif
QPainter p( this );

QTransform t = mTransform.inverted();
@@ -137,14 +136,23 @@ void QgsLayoutRuler::paintEvent( QPaintEvent *event )
double startY = t.map( QPointF( 0, 0 ) ).y(); //start position in mm (total including space between pages)
double endY = t.map( QPointF( 0, height() ) ).y(); //stop position in mm (total including space between pages)

#if 0 // TODO
int startPage = ( int )( startY / ( layout->paperHeight() + layout->spaceBetweenPages() ) );
#endif

// work out start page
int startPage = 0;
if ( startPage < 0 )
int endPage = 0;
double currentY = 0;
double currentPageY = 0;
for ( int page = 0; page < layout->pageCollection()->pageCount(); ++page )
{
startPage = 0;
if ( currentY < startY )
{
startPage = page;
currentPageY = currentY;
}
endPage = page;

currentY += layout->pageCollection()->page( startPage )->rect().height() + layout->pageCollection()->SPACE_BETWEEN_PAGES;
if ( currentY > endY )
break;
}

if ( startY < 0 )
@@ -177,30 +185,21 @@ void QgsLayoutRuler::paintEvent( QPaintEvent *event )
drawSmallDivisions( &p, beforePageCoord + mmDisplay, numSmallDivisions, -mmDisplay, startY );
}

#if 0 //TODO
int endPage = ( int )( endY / ( layout->paperHeight() + layout->spaceBetweenPages() ) );
if ( endPage > ( mLayout->numPages() - 1 ) )
{
endPage = mLayout->numPages() - 1;
}
#endif
int endPage = 0;

double nextPageStartPos = 0;
int nextPageStartPixel = 0;

for ( int i = startPage; i <= endPage; ++i )
{
double pageCoord = 0; //page coordinate in mm
//total (composition) coordinate in mm, including space between pages
#if 0 //TODO
double totalCoord = i * ( layout->paperHeight() + layout->spaceBetweenPages() );

double totalCoord = currentPageY;

//position of next page
if ( i < endPage )
{
//not the last page
nextPageStartPos = ( i + 1 ) * ( layout->paperHeight() + layout->spaceBetweenPages() );
nextPageStartPos = currentPageY + layout->pageCollection()->page( i )->rect().height() + layout->pageCollection()->SPACE_BETWEEN_PAGES;
nextPageStartPixel = mTransform.map( QPointF( 0, nextPageStartPos ) ).y();
}
else
@@ -209,8 +208,7 @@ void QgsLayoutRuler::paintEvent( QPaintEvent *event )
nextPageStartPos = 0;
nextPageStartPixel = 0;
}
#endif
double totalCoord = 0;

while ( ( totalCoord < nextPageStartPos ) || ( ( nextPageStartPos == 0 ) && ( totalCoord <= endY ) ) )
{
double pixelCoord = mTransform.map( QPointF( 0, totalCoord ) ).y();
@@ -232,6 +230,7 @@ void QgsLayoutRuler::paintEvent( QPaintEvent *event )
pageCoord += mmDisplay;
totalCoord += mmDisplay;
}
currentPageY += layout->pageCollection()->page( i )->rect().height() + layout->pageCollection()->SPACE_BETWEEN_PAGES;
}
break;
}
@@ -407,10 +406,6 @@ int QgsLayoutRuler::optimumNumberDivisions( double rulerScale, int scaleMultiple

void QgsLayoutRuler::setSceneTransform( const QTransform &transform )
{
#if 0
QString debug = QString::number( transform.dx() ) + ',' + QString::number( transform.dy() ) + ','
+ QString::number( transform.m11() ) + ',' + QString::number( transform.m22() );
#endif
mTransform = transform;
update();
}
@@ -53,6 +53,9 @@ void QgsLayoutView::setCurrentLayout( QgsLayout *layout )
{
setScene( layout );

connect( layout->pageCollection(), &QgsLayoutPageCollection::changed, this, &QgsLayoutView::updateRulers );
updateRulers();

//emit layoutSet, so that designer dialogs can update for the new layout
emit layoutSet( layout );
}
@@ -131,6 +134,7 @@ void QgsLayoutView::setVerticalRuler( QgsLayoutRuler *ruler )
void QgsLayoutView::zoomFull()
{
fitInView( scene()->sceneRect(), Qt::KeepAspectRatio );
updateRulers();
emit zoomLevelChanged();
}

@@ -305,6 +309,12 @@ void QgsLayoutView::resizeEvent( QResizeEvent *event )
emit zoomLevelChanged();
}

void QgsLayoutView::scrollContentsBy( int dx, int dy )
{
QGraphicsView::scrollContentsBy( dx, dy );
updateRulers();
}

void QgsLayoutView::updateRulers()
{
if ( mHorizontalRuler )
@@ -209,6 +209,7 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
void keyPressEvent( QKeyEvent *event ) override;
void keyReleaseEvent( QKeyEvent *event ) override;
void resizeEvent( QResizeEvent *event ) override;
void scrollContentsBy( int dx, int dy ) override;

private slots:

0 comments on commit 416e1e4

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