Skip to content
Permalink
Browse files
[composer] Set printer page orientation when composition page orienta…
…tion changes (fix #3530)
  • Loading branch information
nyalldawson committed Feb 9, 2014
1 parent 133af64 commit 8d5862c8fd88ddd86c6ed748dbc3b40a1f975ac5
@@ -473,6 +473,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
QgsCompositionWidget* compositionWidget = new QgsCompositionWidget( mGeneralDock, mComposition );
connect( mComposition, SIGNAL( paperSizeChanged() ), compositionWidget, SLOT( displayCompositionWidthHeight() ) );
connect( this, SIGNAL( printAsRasterChanged( bool ) ), compositionWidget, SLOT( setPrintAsRasterCheckBox( bool ) ) );
connect( compositionWidget, SIGNAL( pageOrientationChanged( QString ) ), this, SLOT( setPrinterPageOrientation( QString ) ) );
mGeneralDock->setWidget( compositionWidget );

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

//default printer page setup
setPrinterPageDefaults();

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

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

//default printer page setup
setPrinterPageDefaults();

setSelectionTool();
}

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

void QgsComposer::setPrinterPageOrientation( QString orientation )
{
if ( orientation == tr( "Landscape" ) )
{
mPrinter.setOrientation( QPrinter::Landscape );
}
else
{
mPrinter.setOrientation( QPrinter::Portrait );
}
}

void QgsComposer::setPrinterPageDefaults()
{
double paperWidth = mComposition->paperWidth();
double paperHeight = mComposition->paperHeight();

//set printer page orientation
if ( paperWidth > paperHeight )
{
mPrinter.setOrientation( QPrinter::Landscape );
}
else
{
mPrinter.setOrientation( QPrinter::Portrait );
}
}

void QgsComposer::updateAtlasMapLayerAction( bool atlasEnabled )
{
if ( mAtlasFeatureAction )
@@ -479,6 +479,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Updates the "set as atlas feature" map layer action, removing it if atlas is disabled
void updateAtlasMapLayerAction( bool atlasEnabled );

//! Set default settings for printer page settings based on composition paper size
void setPrinterPageDefaults();

/**Composer title*/
QString mTitle;

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

QgsMapLayerAction* mAtlasFeatureAction;


signals:
void printAsRasterChanged( bool state );

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

//! Updates the "set as atlas feature" map layer action when atlas coverage layer changes
void updateAtlasMapLayerAction( QgsVectorLayer* coverageLayer );

//! Sets the printer page orientation when the page orientation changes
void setPrinterPageOrientation( QString orientation );

};

#endif
@@ -243,8 +243,11 @@ void QgsCompositionWidget::adjustOrientation()
setSize( mPaperWidthDoubleSpinBox, height );
setSize( mPaperHeightDoubleSpinBox, width );
}

mPaperWidthDoubleSpinBox->setEnabled( lineEditsEnabled );
mPaperHeightDoubleSpinBox->setEnabled( lineEditsEnabled );

emit pageOrientationChanged( mPaperOrientationComboBox->currentText() );
}

void QgsCompositionWidget::setSize( QDoubleSpinBox *spin, double v )
@@ -65,6 +65,10 @@ class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase
/**Sets Print as raster checkbox value*/
void setPrintAsRasterCheckBox( bool state );

signals:
/**Is emitted when page orientation changes*/
void pageOrientationChanged( QString orientation );

private slots:
/* when a new map is added */
void onComposerMapAdded( QgsComposerMap* );

0 comments on commit 8d5862c

Please sign in to comment.