void QgsComposerMultiFrame::handlePageChange() { if ( mComposition->numPages() < 1 ) { return; } if ( mResizeMode != RepeatOnEveryPage ) { return; } //remove items beginning on non-existing pages for ( int i = mFrameItems.size() - 1; i >= 0; --i ) { QgsComposerFrame* frame = mFrameItems[i]; int page = frame->pos().y() / ( mComposition->paperHeight() + mComposition->spaceBetweenPages() ); if ( page > ( mComposition->numPages() - 1 ) ) { removeFrame( i ); } } //page number of the last item QgsComposerFrame* lastFrame = mFrameItems.last(); int lastItemPage = lastFrame->pos().y() / ( mComposition->paperHeight() + mComposition->spaceBetweenPages() ); for ( int i = lastItemPage + 1; i < mComposition->numPages(); ++i ) { //copy last frame to current page QgsComposerFrame* newFrame = new QgsComposerFrame( mComposition, this, lastFrame->pos().x(), lastFrame->pos().y() + mComposition->paperHeight() + mComposition->spaceBetweenPages(), lastFrame->rect().width(), lastFrame->rect().height() ); addFrame( newFrame, false ); lastFrame = newFrame; } recalculateFrameSizes(); update(); }
void QgsComposerMultiFrame::recalculateFrameSizes() { if ( mFrameItems.size() < 1 ) { return; } QSizeF size = totalSize(); double totalHeight = size.height(); if ( totalHeight < 1 ) { return; } double currentY = 0; double currentHeight = 0; QgsComposerFrame* currentItem = 0; for ( int i = 0; i < mFrameItems.size(); ++i ) { if ( currentY >= totalHeight ) { if ( mResizeMode == ExtendToNextPage ) //remove unneeded frames in extent mode { for ( int j = mFrameItems.size(); j > i; --j ) { removeFrame( j - 1 ); } } return; } currentItem = mFrameItems.value( i ); currentHeight = currentItem->rect().height(); currentItem->setContentSection( QRectF( 0, currentY, currentItem->rect().width(), currentHeight ) ); currentItem->update(); currentY += currentHeight; } //at end of frames but there is still content left. Add other pages if ResizeMode == if ( mResizeMode == ExtendToNextPage ) { while ( currentY < totalHeight ) { //find out on which page the lower left point of the last frame is int page = currentItem->transform().dy() / ( mComposition->paperHeight() + mComposition->spaceBetweenPages() ); //add new pages if necessary if ( mComposition->numPages() < ( page + 2 ) ) { mComposition->setNumPages( page + 2 ); } //copy last frame QgsComposerFrame* newFrame = new QgsComposerFrame( mComposition, this, currentItem->transform().dx(), currentItem->transform().dy() + mComposition->paperHeight() + mComposition->spaceBetweenPages(), currentItem->rect().width(), currentItem->rect().height() ); newFrame->setContentSection( QRectF( 0, currentY, newFrame->rect().width(), newFrame->rect().height() ) ); currentY += newFrame->rect().height(); currentItem = newFrame; addFrame( newFrame, false ); } } }
void QgsComposerMultiFrame::recalculateFrameSizes() { if ( mFrameItems.empty() ) { return; } QSizeF size = totalSize(); double totalHeight = size.height(); if ( totalHeight < 1 ) { return; } double currentY = 0; double currentHeight = 0; QgsComposerFrame *currentItem = nullptr; for ( int i = 0; i < mFrameItems.size(); ++i ) { if ( mResizeMode != RepeatOnEveryPage && currentY >= totalHeight ) { if ( mResizeMode == RepeatUntilFinished || mResizeMode == ExtendToNextPage ) //remove unneeded frames in extent mode { bool removingPages = true; for ( int j = mFrameItems.size(); j > i; --j ) { int numPagesBefore = mComposition->numPages(); removeFrame( j - 1, removingPages ); //if removing the frame didn't also remove the page, then stop removing pages removingPages = removingPages && ( mComposition->numPages() < numPagesBefore ); } return; } } currentItem = mFrameItems.value( i ); currentHeight = currentItem->rect().height(); if ( mResizeMode == RepeatOnEveryPage ) { currentItem->setContentSection( QRectF( 0, 0, currentItem->rect().width(), currentHeight ) ); } else { currentHeight = findNearbyPageBreak( currentY + currentHeight ) - currentY; currentItem->setContentSection( QRectF( 0, currentY, currentItem->rect().width(), currentHeight ) ); } currentItem->update(); currentY += currentHeight; } //at end of frames but there is still content left. Add other pages if ResizeMode == if ( mResizeMode != UseExistingFrames ) { while ( ( mResizeMode == RepeatOnEveryPage ) || currentY < totalHeight ) { //find out on which page the lower left point of the last frame is int page = std::floor( ( currentItem->pos().y() + currentItem->rect().height() ) / ( mComposition->paperHeight() + mComposition->spaceBetweenPages() ) ) + 1; if ( mResizeMode == RepeatOnEveryPage ) { if ( page >= mComposition->numPages() ) { break; } } else { //add an extra page if required if ( mComposition->numPages() < ( page + 1 ) ) { mComposition->setNumPages( page + 1 ); } } double frameHeight = 0; if ( mResizeMode == RepeatUntilFinished || mResizeMode == RepeatOnEveryPage ) { frameHeight = currentItem->rect().height(); } else //mResizeMode == ExtendToNextPage { frameHeight = ( currentY + mComposition->paperHeight() ) > totalHeight ? totalHeight - currentY : mComposition->paperHeight(); } double newFrameY = page * ( mComposition->paperHeight() + mComposition->spaceBetweenPages() ); if ( mResizeMode == RepeatUntilFinished || mResizeMode == RepeatOnEveryPage ) { newFrameY += currentItem->pos().y() - ( page - 1 ) * ( mComposition->paperHeight() + mComposition->spaceBetweenPages() ); } //create new frame QgsComposerFrame *newFrame = createNewFrame( currentItem, QPointF( currentItem->pos().x(), newFrameY ), QSizeF( currentItem->rect().width(), frameHeight ) ); if ( mResizeMode == RepeatOnEveryPage ) { newFrame->setContentSection( QRectF( 0, 0, newFrame->rect().width(), newFrame->rect().height() ) ); currentY += frameHeight; } else { double contentHeight = findNearbyPageBreak( currentY + newFrame->rect().height() ) - currentY; newFrame->setContentSection( QRectF( 0, currentY, newFrame->rect().width(), contentHeight ) ); currentY += contentHeight; } currentItem = newFrame; } } }
void QgsComposerMultiFrame::recalculateFrameSizes() { if ( mFrameItems.size() < 1 ) { return; } QSizeF size = totalSize(); double totalHeight = size.height(); if ( totalHeight < 1 ) { return; } double currentY = 0; double currentHeight = 0; QgsComposerFrame* currentItem = 0; for ( int i = 0; i < mFrameItems.size(); ++i ) { if ( mResizeMode != RepeatOnEveryPage && currentY >= totalHeight ) { if ( mResizeMode == RepeatUntilFinished || mResizeMode == ExtendToNextPage ) //remove unneeded frames in extent mode { for ( int j = mFrameItems.size(); j > i; --j ) { removeFrame( j - 1 ); } } return; } currentItem = mFrameItems.value( i ); currentHeight = currentItem->rect().height(); if ( mResizeMode == RepeatOnEveryPage ) { currentItem->setContentSection( QRectF( 0, 0, currentItem->rect().width(), currentHeight ) ); } else { currentItem->setContentSection( QRectF( 0, currentY, currentItem->rect().width(), currentHeight ) ); } currentItem->update(); currentY += currentHeight; } //at end of frames but there is still content left. Add other pages if ResizeMode == if ( mResizeMode != UseExistingFrames ) { while (( mResizeMode == RepeatOnEveryPage ) || currentY < totalHeight ) { //find out on which page the lower left point of the last frame is int page = currentItem->pos().y() / ( mComposition->paperHeight() + mComposition->spaceBetweenPages() ); if ( mResizeMode == RepeatOnEveryPage ) { if ( page > mComposition->numPages() - 2 ) { break; } } else { if ( mComposition->numPages() < ( page + 2 ) ) { mComposition->setNumPages( page + 2 ); } } double frameHeight = 0; if ( mResizeMode == RepeatUntilFinished || mResizeMode == RepeatOnEveryPage ) { frameHeight = currentItem->rect().height(); } else //mResizeMode == ExtendToNextPage { frameHeight = ( currentY + mComposition->paperHeight() ) > totalHeight ? totalHeight - currentY : mComposition->paperHeight(); } double newFrameY = ( page + 1 ) * ( mComposition->paperHeight() + mComposition->spaceBetweenPages() ); if ( mResizeMode == RepeatUntilFinished || mResizeMode == RepeatOnEveryPage ) { newFrameY += currentItem->pos().y() - page * ( mComposition->paperHeight() + mComposition->spaceBetweenPages() ); } QgsComposerFrame* newFrame = new QgsComposerFrame( mComposition, this, currentItem->pos().x(), newFrameY, currentItem->rect().width(), frameHeight ); if ( mResizeMode == RepeatOnEveryPage ) { newFrame->setContentSection( QRectF( 0, 0, newFrame->rect().width(), newFrame->rect().height() ) ); } else { newFrame->setContentSection( QRectF( 0, currentY, newFrame->rect().width(), newFrame->rect().height() ) ); } currentY += frameHeight; currentItem = newFrame; addFrame( newFrame, false ); } } }