Skip to content

Commit 8d5862c

Browse files
committed
[composer] Set printer page orientation when composition page orientation changes (fix #3530)
1 parent 133af64 commit 8d5862c

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

src/app/composer/qgscomposer.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
473473
QgsCompositionWidget* compositionWidget = new QgsCompositionWidget( mGeneralDock, mComposition );
474474
connect( mComposition, SIGNAL( paperSizeChanged() ), compositionWidget, SLOT( displayCompositionWidthHeight() ) );
475475
connect( this, SIGNAL( printAsRasterChanged( bool ) ), compositionWidget, SLOT( setPrintAsRasterCheckBox( bool ) ) );
476+
connect( compositionWidget, SIGNAL( pageOrientationChanged( QString ) ), this, SLOT( setPrinterPageOrientation( QString ) ) );
476477
mGeneralDock->setWidget( compositionWidget );
477478

478479
//undo widget
@@ -514,6 +515,9 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
514515
connect( atlasMap, SIGNAL( toggled( bool ) ), this, SLOT( toggleAtlasControls( bool ) ) );
515516
connect( atlasMap, SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( updateAtlasMapLayerAction( QgsVectorLayer * ) ) );
516517

518+
//default printer page setup
519+
setPrinterPageDefaults();
520+
517521
// Create size grip (needed by Mac OS X for QMainWindow if QStatusBar is not visible)
518522
//should not be needed now that composer has a status bar?
519523
#if 0
@@ -2599,6 +2603,7 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
25992603
QgsCompositionWidget* compositionWidget = new QgsCompositionWidget( mGeneralDock, mComposition );
26002604
QObject::connect( mComposition, SIGNAL( paperSizeChanged() ), compositionWidget, SLOT( displayCompositionWidthHeight() ) );
26012605
QObject::connect( this, SIGNAL( printAsRasterChanged( bool ) ), compositionWidget, SLOT( setPrintAsRasterCheckBox( bool ) ) );
2606+
QObject::connect( compositionWidget, SIGNAL( pageOrientationChanged( QString ) ), this, SLOT( setPrinterPageOrientation( QString ) ) );
26022607
mGeneralDock->setWidget( compositionWidget );
26032608

26042609
//read and restore all the items
@@ -2672,6 +2677,9 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
26722677
connect( atlasMap, SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( updateAtlasMapLayerAction( QgsVectorLayer * ) ) );
26732678
updateAtlasMapLayerAction( atlasMap->enabled() );
26742679

2680+
//default printer page setup
2681+
setPrinterPageDefaults();
2682+
26752683
setSelectionTool();
26762684
}
26772685

@@ -3137,6 +3145,34 @@ void QgsComposer::updateAtlasMapLayerAction( QgsVectorLayer *coverageLayer )
31373145
}
31383146
}
31393147

3148+
void QgsComposer::setPrinterPageOrientation( QString orientation )
3149+
{
3150+
if ( orientation == tr( "Landscape" ) )
3151+
{
3152+
mPrinter.setOrientation( QPrinter::Landscape );
3153+
}
3154+
else
3155+
{
3156+
mPrinter.setOrientation( QPrinter::Portrait );
3157+
}
3158+
}
3159+
3160+
void QgsComposer::setPrinterPageDefaults()
3161+
{
3162+
double paperWidth = mComposition->paperWidth();
3163+
double paperHeight = mComposition->paperHeight();
3164+
3165+
//set printer page orientation
3166+
if ( paperWidth > paperHeight )
3167+
{
3168+
mPrinter.setOrientation( QPrinter::Landscape );
3169+
}
3170+
else
3171+
{
3172+
mPrinter.setOrientation( QPrinter::Portrait );
3173+
}
3174+
}
3175+
31403176
void QgsComposer::updateAtlasMapLayerAction( bool atlasEnabled )
31413177
{
31423178
if ( mAtlasFeatureAction )

src/app/composer/qgscomposer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
479479
//! Updates the "set as atlas feature" map layer action, removing it if atlas is disabled
480480
void updateAtlasMapLayerAction( bool atlasEnabled );
481481

482+
//! Set default settings for printer page settings based on composition paper size
483+
void setPrinterPageDefaults();
484+
482485
/**Composer title*/
483486
QString mTitle;
484487

@@ -557,6 +560,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
557560

558561
QgsMapLayerAction* mAtlasFeatureAction;
559562

563+
560564
signals:
561565
void printAsRasterChanged( bool state );
562566

@@ -592,6 +596,10 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
592596

593597
//! Updates the "set as atlas feature" map layer action when atlas coverage layer changes
594598
void updateAtlasMapLayerAction( QgsVectorLayer* coverageLayer );
599+
600+
//! Sets the printer page orientation when the page orientation changes
601+
void setPrinterPageOrientation( QString orientation );
602+
595603
};
596604

597605
#endif

src/app/composer/qgscompositionwidget.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,11 @@ void QgsCompositionWidget::adjustOrientation()
243243
setSize( mPaperWidthDoubleSpinBox, height );
244244
setSize( mPaperHeightDoubleSpinBox, width );
245245
}
246+
246247
mPaperWidthDoubleSpinBox->setEnabled( lineEditsEnabled );
247248
mPaperHeightDoubleSpinBox->setEnabled( lineEditsEnabled );
249+
250+
emit pageOrientationChanged( mPaperOrientationComboBox->currentText() );
248251
}
249252

250253
void QgsCompositionWidget::setSize( QDoubleSpinBox *spin, double v )

src/app/composer/qgscompositionwidget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase
6565
/**Sets Print as raster checkbox value*/
6666
void setPrintAsRasterCheckBox( bool state );
6767

68+
signals:
69+
/**Is emitted when page orientation changes*/
70+
void pageOrientationChanged( QString orientation );
71+
6872
private slots:
6973
/* when a new map is added */
7074
void onComposerMapAdded( QgsComposerMap* );

0 commit comments

Comments
 (0)