Skip to content
Permalink
Browse files

Merge pull request #981 from nyalldawson/composer_settings3

Add composer settings to QGIS options
  • Loading branch information
nyalldawson committed Nov 19, 2013
2 parents 944755a + 8f7b4c1 commit 039a4f5a334384099371c4e6d117a4dbdabdecb0
@@ -303,6 +303,9 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
layoutMenu->addAction( mActionLockItems );
layoutMenu->addAction( mActionUnlockAll );

QMenu *settingsMenu = menuBar()->addMenu( tr( "Settings" ) );
settingsMenu->addAction( mActionOptions );

#ifdef Q_WS_MAC
// this doesn't work on Mac anymore: menuBar()->addMenu( mQgis->windowMenu() );
// QgsComposer::populateWithOtherMenu should work recursively with submenus and regardless of Qt version
@@ -659,6 +662,11 @@ void QgsComposer::showItemOptions( QgsComposerItem* item )
mItemDock->setWidget( newWidget );
}

void QgsComposer::on_mActionOptions_triggered()
{
mQgis->showOptionsDialog( this, QString("mOptionsPageComposer") );
}

QgsMapCanvas *QgsComposer::mapCanvas( void )
{
return mQgis->mapCanvas();
@@ -306,6 +306,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//!Clear guides
void on_mActionClearGuides_triggered();

//!Show options dialog
void on_mActionOptions_triggered();

//! Save window state
void saveWindowState();

@@ -80,30 +80,6 @@ QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c )
mOffsetXSpinBox->setValue( mComposition->snapGridOffsetX() );
mOffsetYSpinBox->setValue( mComposition->snapGridOffsetY() );


//grid pen color
mGridColorButton->setColor( mComposition->gridPen().color() );
mGridColorButton->setColorDialogTitle( tr( "Select grid color" ) );
mGridColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );

mGridStyleComboBox->insertItem( 0, tr( "Solid" ) );
mGridStyleComboBox->insertItem( 1, tr( "Dots" ) );
mGridStyleComboBox->insertItem( 2, tr( "Crosses" ) );

QgsComposition::GridStyle snapGridStyle = mComposition->gridStyle();
if ( snapGridStyle == QgsComposition::Solid )
{
mGridStyleComboBox->setCurrentIndex( 0 );
}
else if ( snapGridStyle == QgsComposition::Dots )
{
mGridStyleComboBox->setCurrentIndex( 1 );
}
else
{
mGridStyleComboBox->setCurrentIndex( 2 );
}

mGridToleranceSpinBox->setValue( mComposition->snapGridTolerance() );
}
blockSignals( false );
@@ -520,37 +496,6 @@ void QgsCompositionWidget::on_mOffsetYSpinBox_valueChanged( double d )
}
}

void QgsCompositionWidget::on_mGridColorButton_colorChanged( const QColor &newColor )
{
if ( mComposition )
{
QPen pen = mComposition->gridPen();
pen.setColor( newColor );
mComposition->setGridPen( pen );
}
}

void QgsCompositionWidget::on_mGridStyleComboBox_currentIndexChanged( const QString& text )
{
Q_UNUSED( text );

if ( mComposition )
{
if ( mGridStyleComboBox->currentText() == tr( "Solid" ) )
{
mComposition->setGridStyle( QgsComposition::Solid );
}
else if ( mGridStyleComboBox->currentText() == tr( "Dots" ) )
{
mComposition->setGridStyle( QgsComposition::Dots );
}
else if ( mGridStyleComboBox->currentText() == tr( "Crosses" ) )
{
mComposition->setGridStyle( QgsComposition::Crosses );
}
}
}

void QgsCompositionWidget::on_mGridToleranceSpinBox_valueChanged( double d )
{
if ( mComposition )
@@ -580,8 +525,6 @@ void QgsCompositionWidget::blockSignals( bool block )
mGridResolutionSpinBox->blockSignals( block );
mOffsetXSpinBox->blockSignals( block );
mOffsetYSpinBox->blockSignals( block );
mGridColorButton->blockSignals( block );
mGridStyleComboBox->blockSignals( block );
mGridToleranceSpinBox->blockSignals( block );
mAlignmentToleranceSpinBox->blockSignals( block );
}
@@ -56,8 +56,6 @@ class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase
void on_mGridResolutionSpinBox_valueChanged( double d );
void on_mOffsetXSpinBox_valueChanged( double d );
void on_mOffsetYSpinBox_valueChanged( double d );
void on_mGridColorButton_colorChanged( const QColor &newColor );
void on_mGridStyleComboBox_currentIndexChanged( const QString& text );
void on_mGridToleranceSpinBox_valueChanged( double d );
void on_mAlignmentToleranceSpinBox_valueChanged( double d );

@@ -6839,8 +6839,12 @@ void QgisApp::customize()
QgsCustomization::instance()->openDialog( this );
}


void QgisApp::options()
{
showOptionsDialog( this );
}

void QgisApp::showOptionsDialog( QWidget *parent, QString currentPage )
{
if ( mMapCanvas && mMapCanvas->isDrawing() )
{
@@ -6850,7 +6854,12 @@ void QgisApp::options()
QSettings mySettings;
QString oldScales = mySettings.value( "Map/scales", PROJECT_SCALES ).toString();

QgsOptions *optionsDialog = new QgsOptions( this );
QgsOptions *optionsDialog = new QgsOptions( parent );
if ( !currentPage.isEmpty() )
{
optionsDialog->setCurrentPage( currentPage );
}

if ( optionsDialog->exec() )
{
// set the theme if it changed
@@ -6863,6 +6872,17 @@ void QgisApp::options()
double zoomFactor = mySettings.value( "/qgis/zoom_factor", 2 ).toDouble();
mMapCanvas->setWheelAction(( QgsMapCanvas::WheelAction ) action, zoomFactor );

//update any open compositions so they reflect new composer settings
//we have to push the changes to the compositions here, because compositions
//have no access to qgisapp and accordingly can't listen in to changes
QSet<QgsComposer*> composers = instance()->printComposers();
QSet<QgsComposer*>::iterator composer_it = composers.begin();
for ( ; composer_it != composers.end(); ++composer_it )
{
QgsComposition* composition = ( *composer_it )->composition();
composition->updateSettings();
}

//do we need this? TS
mMapCanvas->refresh();

@@ -618,6 +618,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Update project menu with the project templates
void updateProjectFromTemplates();

//! Opens the options dialog
void showOptionsDialog( QWidget *parent = 0, QString currentPage = QString() );

protected:

//! Handle state changes (WindowTitleChange)
@@ -681,6 +681,65 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
}
}

//
// Composer settings
//

//default composer font
mComposerFontComboBox->blockSignals( true );

QString composerFontFamily = settings.value( "/Composer/defaultFont" ).toString();

QFont *tempComposerFont = new QFont( composerFontFamily );
// is exact family match returned from system?
if ( tempComposerFont->family() == composerFontFamily )
{
mComposerFontComboBox->setCurrentFont( *tempComposerFont );
}
delete tempComposerFont;

mComposerFontComboBox->blockSignals( false );

//default composer grid color
int gridRed, gridGreen, gridBlue, gridAlpha;
gridRed = settings.value( "/Composer/gridRed", 190 ).toInt();
gridGreen = settings.value( "/Composer/gridGreen", 190 ).toInt();
gridBlue = settings.value( "/Composer/gridBlue", 190 ).toInt();
gridAlpha = settings.value( "/Composer/gridAlpha", 100 ).toInt();
QColor gridColor = QColor( gridRed, gridGreen, gridBlue, gridAlpha );
mGridColorButton->setColor( gridColor );
mGridColorButton->setColorDialogTitle( tr( "Select grid color" ) );
mGridColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );

//default composer grid style
QString gridStyleString;
gridStyleString = settings.value( "/Composer/gridStyle", "Dots" ).toString();
mGridStyleComboBox->insertItem( 0, tr( "Solid" ) );
mGridStyleComboBox->insertItem( 1, tr( "Dots" ) );
mGridStyleComboBox->insertItem( 2, tr( "Crosses" ) );
if ( gridStyleString == "Solid" )
{
mGridStyleComboBox->setCurrentIndex( 0 );
}
else if ( gridStyleString == "Crosses" )
{
mGridStyleComboBox->setCurrentIndex( 2 );
}
else
{
//default grid is dots
mGridStyleComboBox->setCurrentIndex( 1 );
}

//grid defaults
mGridResolutionSpinBox->setValue( settings.value( "/Composer/defaultSnapGridResolution", 10.0 ).toDouble() );
mGridToleranceSpinBox->setValue( settings.value( "/Composer/defaultSnapGridTolerance", 2 ).toDouble() );
mOffsetXSpinBox->setValue( settings.value( "/Composer/defaultSnapGridOffsetX", 0 ).toDouble() );
mOffsetYSpinBox->setValue( settings.value( "/Composer/defaultSnapGridOffsetY", 0 ).toDouble() );

//guide defaults
mGuideToleranceSpinBox->setValue( settings.value( "/Composer/defaultSnapGuideTolerance", 2 ).toDouble() );

//
// Locale settings
//
@@ -796,6 +855,21 @@ QgsOptions::~QgsOptions()
{
}

void QgsOptions::setCurrentPage( QString pageWidgetName )
{
//find the page with a matching widget name
for ( int idx = 0; idx < mOptionsStackedWidget->count(); ++idx )
{
QWidget * currentPage = mOptionsStackedWidget->widget( idx );
if ( currentPage->objectName() == pageWidgetName )
{
//found the page, set it as current
mOptionsStackedWidget->setCurrentIndex( idx );
return;
}
}
}

void QgsOptions::on_cbxProjectDefaultNew_toggled( bool checked )
{
if ( checked )
@@ -1211,6 +1285,43 @@ void QgsOptions::saveOptions()
}
settings.setValue( "Map/scales", myPaths );

//
// Composer settings
//

//default font
QString composerFont = mComposerFontComboBox->currentFont().family();
settings.setValue( "/Composer/defaultFont", composerFont );

//grid color
settings.setValue( "/Composer/gridRed", mGridColorButton->color().red() );
settings.setValue( "/Composer/gridGreen", mGridColorButton->color().green() );
settings.setValue( "/Composer/gridBlue", mGridColorButton->color().blue() );
settings.setValue( "/Composer/gridAlpha", mGridColorButton->color().alpha() );

//grid style
if ( mGridStyleComboBox->currentText() == tr( "Solid" ) )
{
settings.setValue( "/Composer/gridStyle", "Solid" );
}
else if ( mGridStyleComboBox->currentText() == tr( "Dots" ) )
{
settings.setValue( "/Composer/gridStyle", "Dots" );
}
else if ( mGridStyleComboBox->currentText() == tr( "Crosses" ) )
{
settings.setValue( "/Composer/gridStyle", "Crosses" );
}

//grid defaults
settings.setValue( "/Composer/defaultSnapGridResolution", mGridResolutionSpinBox->value() );
settings.setValue( "/Composer/defaultSnapGridTolerance", mGridToleranceSpinBox->value() );
settings.setValue( "/Composer/defaultSnapGridOffsetX", mOffsetXSpinBox->value() );
settings.setValue( "/Composer/defaultSnapGridOffsetY", mOffsetYSpinBox->value() );

//guide defaults
settings.setValue( "/Composer/defaultSnapGuideTolerance", mGuideToleranceSpinBox->value() );

//
// Locale settings
//
@@ -1598,7 +1709,7 @@ void QgsOptions::on_mOptionsStackedWidget_currentChanged( int theIndx )
{
Q_UNUSED( theIndx );
// load gdal driver list when gdal tab is first opened
if ( mOptionsStackedWidget->currentWidget()->objectName() == QString( "mOptionsPage_02" )
if ( mOptionsStackedWidget->currentWidget()->objectName() == QString( "mOptionsPageGDAL" )
&& ! mLoadedGdalDriverList )
{
loadGdalDriverList();
@@ -52,6 +52,11 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
*/
QString theme();

/** Sets the page with the specified widget name as the current page
* @note added in QGIS 2.1
*/
void setCurrentPage( QString pageWidgetName );

public slots:
void on_cbxProjectDefaultNew_toggled( bool checked );
void on_pbnProjectDefaultSetCurrent_clicked();
@@ -33,8 +33,18 @@ QgsComposerLabel::QgsComposerLabel( QgsComposition *composition ):
mExpressionFeature( 0 ), mExpressionLayer( 0 )
{
mHtmlUnitsToMM = htmlUnitsToMM();
//default font size is 10 point

//get default composer font from settings
QSettings settings;
QString defaultFontString = settings.value( "/Composer/defaultFont" ).toString();
if ( !defaultFontString.isEmpty() )
{
mFont.setFamily( defaultFontString );
}

//default to a 10 point font size
mFont.setPointSizeF( 10 );

}

QgsComposerLabel::~QgsComposerLabel()
@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgscomposerlegendstyle.h"
#include "qgscomposition.h"
#include <QFont>
#include <QMap>
#include <QString>
@@ -25,6 +26,13 @@

QgsComposerLegendStyle::QgsComposerLegendStyle()
{
//get default composer font from settings
QSettings settings;
QString defaultFontString = settings.value( "/Composer/defaultFont" ).toString();
if ( !defaultFontString.isEmpty() )
{
mFont.setFamily( defaultFontString );
}
}

QgsComposerLegendStyle::~QgsComposerLegendStyle()
@@ -72,6 +72,14 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
mXOffset = 0.0;
mYOffset = 0.0;

//get default composer font from settings
QSettings settings;
QString defaultFontString = settings.value( "/Composer/defaultFont" ).toString();
if ( !defaultFontString.isEmpty() )
{
mGridAnnotationFont.setFamily( defaultFontString );
}

connectUpdateSlot();

//calculate mExtent based on width/height ratio and map canvas extent
@@ -235,6 +235,13 @@ void QgsComposerScaleBar::applyDefaultSettings()
mBrush.setColor( QColor( 0, 0, 0 ) );
mBrush.setStyle( Qt::SolidPattern );

//get default composer font from settings
QSettings settings;
QString defaultFontString = settings.value( "/Composer/defaultFont" ).toString();
if ( !defaultFontString.isEmpty() )
{
mFont.setFamily( defaultFontString );
}
mFont.setPointSizeF( 12.0 );
mFontColor = QColor( 0, 0, 0 );

0 comments on commit 039a4f5

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