Skip to content
Permalink
Browse files

Consider multipages in print

  • Loading branch information
mhugent committed Jul 16, 2012
1 parent 4b3355f commit b8932afe52916a577ff31db383093cb172b173ed
Showing with 42 additions and 4 deletions.
  1. +12 −1 src/app/composer/qgscomposer.cpp
  2. +27 −3 src/core/composer/qgscomposition.cpp
  3. +3 −0 src/core/composer/qgscomposition.h
@@ -640,7 +640,18 @@ void QgsComposer::print( QPrinter &printer )
QRectF paperRectPixel = printer.pageRect( QPrinter::DevicePixel );

mView->setPaintingEnabled( false );
mComposition->render( &p, paperRectPixel, paperRectMM );
for ( int i = 0; i < mComposition->numPages(); ++i )
{
if ( i > 0 )
{
if ( !printer.newPage() )
{
return;
}
}
mComposition->renderPage( &p, i );
}
//mComposition->render( &p, paperRectPixel, paperRectMM );
mView->setPaintingEnabled( true );
}

@@ -30,10 +30,11 @@
#include <QDomDocument>
#include <QDomElement>
#include <QGraphicsRectItem>
#include <QPainter>
#include <QSettings>

QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer ):
QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mPrintAsRaster( false ), mSelectionTolerance( 0.0 ),
QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mSpaceBetweenPages( 10 ), mPrintAsRaster( false ), mSelectionTolerance( 0.0 ),
mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 )
{
setBackgroundBrush( Qt::gray );
@@ -44,7 +45,7 @@ QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer ):
}

QgsComposition::QgsComposition():
QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mPrintAsRaster( false ),
QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mSpaceBetweenPages( 10 ), mPrintAsRaster( false ),
mSelectionTolerance( 0.0 ), mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 )
{
loadSettings();
@@ -1213,7 +1214,7 @@ void QgsComposition::addPaperItem()
{
double paperHeight = this->paperHeight();
double paperWidth = this->paperWidth();
double currentY = paperHeight * mPages.size();
double currentY = paperHeight * mPages.size() + mPages.size() * mSpaceBetweenPages; //add 10mm visible space between pages
QgsPaperItem* paperItem = new QgsPaperItem( 0, currentY, paperWidth, paperHeight, this ); //default size A4
paperItem->setBrush( Qt::white );
addItem( paperItem );
@@ -1229,3 +1230,26 @@ void QgsComposition::removePaperItems()
}
mPages.clear();
}

void QgsComposition::renderPage( QPainter* p, int page )
{
if ( mPages.size() <= page )
{
return;
}

QgsPaperItem* paperItem = mPages[page];
if ( !paperItem )
{
return;
}

QPaintDevice* paintDevice = p->device();
if ( !paintDevice )
{
return;
}

QRectF paperRect = QRectF( paperItem->transform().dx(), paperItem->transform().dy(), paperItem->rect().width(), paperItem->rect().height() );
render( p, QRectF( 0, 0, paintDevice->width(), paintDevice->height() ), paperRect );
}
@@ -217,6 +217,8 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
/**Convenience function to create a QgsAddRemoveItemCommand, connect its signals and push it to the undo stack*/
void pushAddRemoveCommand( QgsComposerItem* item, const QString& text, QgsAddRemoveItemCommand::State state = QgsAddRemoveItemCommand::Added );

void renderPage( QPainter* p, int page );

public slots:
/**Casts object to the proper subclass type and calls corresponding itemAdded signal*/
void sendItemAddedSignal( QgsComposerItem* item );
@@ -228,6 +230,7 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
double mPageWidth;
double mPageHeight;
QList< QgsPaperItem* > mPages;
double mSpaceBetweenPages; //space in preview between pages

/**Maintains z-Order of items. Starts with item at position 1 (position 0 is always paper item)*/
QLinkedList<QgsComposerItem*> mItemZList;

0 comments on commit b8932af

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