Skip to content

Commit

Permalink
[composer] Ensure that data defined page size and orientation is corr…
Browse files Browse the repository at this point in the history
…ectly set when printing directly from an atlas. (Note that mixed orientation prints are unsupported on some platforms/print drivers)
  • Loading branch information
nyalldawson committed Aug 12, 2014
1 parent ffd3f88 commit 692d0f5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/app/composer/qgscomposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1590,12 +1590,12 @@ void QgsComposer::printComposition( QgsComposer::OutputMode mode )
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( mode == QgsComposer::Single )
{
mComposition->print( mPrinter );
mComposition->print( mPrinter, true );
}
else
{

mComposition->beginPrint( mPrinter );
mComposition->beginPrint( mPrinter, true );
QPainter painter( &mPrinter );

loadAtlasPredefinedScalesFromProject();
Expand Down
14 changes: 11 additions & 3 deletions src/core/composer/qgscomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2507,19 +2507,27 @@ void QgsComposition::doPrint( QPrinter& printer, QPainter& p, bool startNewPage
}
}

void QgsComposition::beginPrint( QPrinter &printer )
void QgsComposition::beginPrint( QPrinter &printer, const bool evaluateDDPageSize )
{
//set resolution based on composer setting
printer.setFullPage( true );
printer.setColorMode( QPrinter::Color );

//set user-defined resolution
printer.setResolution( printResolution() );

if ( evaluateDDPageSize )
{
//set data defined page size
refreshPageSize();
printer.setPaperSize( QSizeF( paperWidth(), paperHeight() ), QPrinter::Millimeter );
printer.setOrientation( paperWidth() > paperHeight() ? QPrinter::Landscape : QPrinter::Portrait );
}
}

bool QgsComposition::print( QPrinter &printer )
bool QgsComposition::print( QPrinter &printer, const bool evaluateDDPageSize )
{
beginPrint( printer );
beginPrint( printer, evaluateDDPageSize );
QPainter p;
bool ready = p.begin( &printer );
if ( !ready )
Expand Down
4 changes: 2 additions & 2 deletions src/core/composer/qgscomposition.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
//printing

/** Prepare the printer for printing */
void beginPrint( QPrinter& printer );
void beginPrint( QPrinter& printer, const bool evaluateDDPageSize = false );
/** Prepare the printer for printing in a PDF */
void beginPrintAsPDF( QPrinter& printer, const QString& file );

Expand All @@ -503,7 +503,7 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
/**Convenience function that prepares the printer and prints
* @returns true if print was successful
*/
bool print( QPrinter &printer );
bool print( QPrinter &printer, const bool evaluateDDPageSize = false );

/**Convenience function that prepares the printer for printing in PDF and prints
* @returns true if export was successful
Expand Down

0 comments on commit 692d0f5

Please sign in to comment.