Skip to content

Commit 039a4f5

Browse files
committed
Merge pull request #981 from nyalldawson/composer_settings3
Add composer settings to QGIS options
2 parents 944755a + 8f7b4c1 commit 039a4f5

18 files changed

+503
-153
lines changed

src/app/composer/qgscomposer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
303303
layoutMenu->addAction( mActionLockItems );
304304
layoutMenu->addAction( mActionUnlockAll );
305305

306+
QMenu *settingsMenu = menuBar()->addMenu( tr( "Settings" ) );
307+
settingsMenu->addAction( mActionOptions );
308+
306309
#ifdef Q_WS_MAC
307310
// this doesn't work on Mac anymore: menuBar()->addMenu( mQgis->windowMenu() );
308311
// QgsComposer::populateWithOtherMenu should work recursively with submenus and regardless of Qt version
@@ -659,6 +662,11 @@ void QgsComposer::showItemOptions( QgsComposerItem* item )
659662
mItemDock->setWidget( newWidget );
660663
}
661664

665+
void QgsComposer::on_mActionOptions_triggered()
666+
{
667+
mQgis->showOptionsDialog( this, QString("mOptionsPageComposer") );
668+
}
669+
662670
QgsMapCanvas *QgsComposer::mapCanvas( void )
663671
{
664672
return mQgis->mapCanvas();

src/app/composer/qgscomposer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
306306
//!Clear guides
307307
void on_mActionClearGuides_triggered();
308308

309+
//!Show options dialog
310+
void on_mActionOptions_triggered();
311+
309312
//! Save window state
310313
void saveWindowState();
311314

src/app/composer/qgscompositionwidget.cpp

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -80,30 +80,6 @@ QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c )
8080
mOffsetXSpinBox->setValue( mComposition->snapGridOffsetX() );
8181
mOffsetYSpinBox->setValue( mComposition->snapGridOffsetY() );
8282

83-
84-
//grid pen color
85-
mGridColorButton->setColor( mComposition->gridPen().color() );
86-
mGridColorButton->setColorDialogTitle( tr( "Select grid color" ) );
87-
mGridColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
88-
89-
mGridStyleComboBox->insertItem( 0, tr( "Solid" ) );
90-
mGridStyleComboBox->insertItem( 1, tr( "Dots" ) );
91-
mGridStyleComboBox->insertItem( 2, tr( "Crosses" ) );
92-
93-
QgsComposition::GridStyle snapGridStyle = mComposition->gridStyle();
94-
if ( snapGridStyle == QgsComposition::Solid )
95-
{
96-
mGridStyleComboBox->setCurrentIndex( 0 );
97-
}
98-
else if ( snapGridStyle == QgsComposition::Dots )
99-
{
100-
mGridStyleComboBox->setCurrentIndex( 1 );
101-
}
102-
else
103-
{
104-
mGridStyleComboBox->setCurrentIndex( 2 );
105-
}
106-
10783
mGridToleranceSpinBox->setValue( mComposition->snapGridTolerance() );
10884
}
10985
blockSignals( false );
@@ -520,37 +496,6 @@ void QgsCompositionWidget::on_mOffsetYSpinBox_valueChanged( double d )
520496
}
521497
}
522498

523-
void QgsCompositionWidget::on_mGridColorButton_colorChanged( const QColor &newColor )
524-
{
525-
if ( mComposition )
526-
{
527-
QPen pen = mComposition->gridPen();
528-
pen.setColor( newColor );
529-
mComposition->setGridPen( pen );
530-
}
531-
}
532-
533-
void QgsCompositionWidget::on_mGridStyleComboBox_currentIndexChanged( const QString& text )
534-
{
535-
Q_UNUSED( text );
536-
537-
if ( mComposition )
538-
{
539-
if ( mGridStyleComboBox->currentText() == tr( "Solid" ) )
540-
{
541-
mComposition->setGridStyle( QgsComposition::Solid );
542-
}
543-
else if ( mGridStyleComboBox->currentText() == tr( "Dots" ) )
544-
{
545-
mComposition->setGridStyle( QgsComposition::Dots );
546-
}
547-
else if ( mGridStyleComboBox->currentText() == tr( "Crosses" ) )
548-
{
549-
mComposition->setGridStyle( QgsComposition::Crosses );
550-
}
551-
}
552-
}
553-
554499
void QgsCompositionWidget::on_mGridToleranceSpinBox_valueChanged( double d )
555500
{
556501
if ( mComposition )
@@ -580,8 +525,6 @@ void QgsCompositionWidget::blockSignals( bool block )
580525
mGridResolutionSpinBox->blockSignals( block );
581526
mOffsetXSpinBox->blockSignals( block );
582527
mOffsetYSpinBox->blockSignals( block );
583-
mGridColorButton->blockSignals( block );
584-
mGridStyleComboBox->blockSignals( block );
585528
mGridToleranceSpinBox->blockSignals( block );
586529
mAlignmentToleranceSpinBox->blockSignals( block );
587530
}

src/app/composer/qgscompositionwidget.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase
5656
void on_mGridResolutionSpinBox_valueChanged( double d );
5757
void on_mOffsetXSpinBox_valueChanged( double d );
5858
void on_mOffsetYSpinBox_valueChanged( double d );
59-
void on_mGridColorButton_colorChanged( const QColor &newColor );
60-
void on_mGridStyleComboBox_currentIndexChanged( const QString& text );
6159
void on_mGridToleranceSpinBox_valueChanged( double d );
6260
void on_mAlignmentToleranceSpinBox_valueChanged( double d );
6361

src/app/qgisapp.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6839,8 +6839,12 @@ void QgisApp::customize()
68396839
QgsCustomization::instance()->openDialog( this );
68406840
}
68416841

6842-
68436842
void QgisApp::options()
6843+
{
6844+
showOptionsDialog( this );
6845+
}
6846+
6847+
void QgisApp::showOptionsDialog( QWidget *parent, QString currentPage )
68446848
{
68456849
if ( mMapCanvas && mMapCanvas->isDrawing() )
68466850
{
@@ -6850,7 +6854,12 @@ void QgisApp::options()
68506854
QSettings mySettings;
68516855
QString oldScales = mySettings.value( "Map/scales", PROJECT_SCALES ).toString();
68526856

6853-
QgsOptions *optionsDialog = new QgsOptions( this );
6857+
QgsOptions *optionsDialog = new QgsOptions( parent );
6858+
if ( !currentPage.isEmpty() )
6859+
{
6860+
optionsDialog->setCurrentPage( currentPage );
6861+
}
6862+
68546863
if ( optionsDialog->exec() )
68556864
{
68566865
// set the theme if it changed
@@ -6863,6 +6872,17 @@ void QgisApp::options()
68636872
double zoomFactor = mySettings.value( "/qgis/zoom_factor", 2 ).toDouble();
68646873
mMapCanvas->setWheelAction(( QgsMapCanvas::WheelAction ) action, zoomFactor );
68656874

6875+
//update any open compositions so they reflect new composer settings
6876+
//we have to push the changes to the compositions here, because compositions
6877+
//have no access to qgisapp and accordingly can't listen in to changes
6878+
QSet<QgsComposer*> composers = instance()->printComposers();
6879+
QSet<QgsComposer*>::iterator composer_it = composers.begin();
6880+
for ( ; composer_it != composers.end(); ++composer_it )
6881+
{
6882+
QgsComposition* composition = ( *composer_it )->composition();
6883+
composition->updateSettings();
6884+
}
6885+
68666886
//do we need this? TS
68676887
mMapCanvas->refresh();
68686888

src/app/qgisapp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
618618
//! Update project menu with the project templates
619619
void updateProjectFromTemplates();
620620

621+
//! Opens the options dialog
622+
void showOptionsDialog( QWidget *parent = 0, QString currentPage = QString() );
623+
621624
protected:
622625

623626
//! Handle state changes (WindowTitleChange)

src/app/qgsoptions.cpp

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,65 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
681681
}
682682
}
683683

684+
//
685+
// Composer settings
686+
//
687+
688+
//default composer font
689+
mComposerFontComboBox->blockSignals( true );
690+
691+
QString composerFontFamily = settings.value( "/Composer/defaultFont" ).toString();
692+
693+
QFont *tempComposerFont = new QFont( composerFontFamily );
694+
// is exact family match returned from system?
695+
if ( tempComposerFont->family() == composerFontFamily )
696+
{
697+
mComposerFontComboBox->setCurrentFont( *tempComposerFont );
698+
}
699+
delete tempComposerFont;
700+
701+
mComposerFontComboBox->blockSignals( false );
702+
703+
//default composer grid color
704+
int gridRed, gridGreen, gridBlue, gridAlpha;
705+
gridRed = settings.value( "/Composer/gridRed", 190 ).toInt();
706+
gridGreen = settings.value( "/Composer/gridGreen", 190 ).toInt();
707+
gridBlue = settings.value( "/Composer/gridBlue", 190 ).toInt();
708+
gridAlpha = settings.value( "/Composer/gridAlpha", 100 ).toInt();
709+
QColor gridColor = QColor( gridRed, gridGreen, gridBlue, gridAlpha );
710+
mGridColorButton->setColor( gridColor );
711+
mGridColorButton->setColorDialogTitle( tr( "Select grid color" ) );
712+
mGridColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
713+
714+
//default composer grid style
715+
QString gridStyleString;
716+
gridStyleString = settings.value( "/Composer/gridStyle", "Dots" ).toString();
717+
mGridStyleComboBox->insertItem( 0, tr( "Solid" ) );
718+
mGridStyleComboBox->insertItem( 1, tr( "Dots" ) );
719+
mGridStyleComboBox->insertItem( 2, tr( "Crosses" ) );
720+
if ( gridStyleString == "Solid" )
721+
{
722+
mGridStyleComboBox->setCurrentIndex( 0 );
723+
}
724+
else if ( gridStyleString == "Crosses" )
725+
{
726+
mGridStyleComboBox->setCurrentIndex( 2 );
727+
}
728+
else
729+
{
730+
//default grid is dots
731+
mGridStyleComboBox->setCurrentIndex( 1 );
732+
}
733+
734+
//grid defaults
735+
mGridResolutionSpinBox->setValue( settings.value( "/Composer/defaultSnapGridResolution", 10.0 ).toDouble() );
736+
mGridToleranceSpinBox->setValue( settings.value( "/Composer/defaultSnapGridTolerance", 2 ).toDouble() );
737+
mOffsetXSpinBox->setValue( settings.value( "/Composer/defaultSnapGridOffsetX", 0 ).toDouble() );
738+
mOffsetYSpinBox->setValue( settings.value( "/Composer/defaultSnapGridOffsetY", 0 ).toDouble() );
739+
740+
//guide defaults
741+
mGuideToleranceSpinBox->setValue( settings.value( "/Composer/defaultSnapGuideTolerance", 2 ).toDouble() );
742+
684743
//
685744
// Locale settings
686745
//
@@ -796,6 +855,21 @@ QgsOptions::~QgsOptions()
796855
{
797856
}
798857

858+
void QgsOptions::setCurrentPage( QString pageWidgetName )
859+
{
860+
//find the page with a matching widget name
861+
for ( int idx = 0; idx < mOptionsStackedWidget->count(); ++idx )
862+
{
863+
QWidget * currentPage = mOptionsStackedWidget->widget( idx );
864+
if ( currentPage->objectName() == pageWidgetName )
865+
{
866+
//found the page, set it as current
867+
mOptionsStackedWidget->setCurrentIndex( idx );
868+
return;
869+
}
870+
}
871+
}
872+
799873
void QgsOptions::on_cbxProjectDefaultNew_toggled( bool checked )
800874
{
801875
if ( checked )
@@ -1211,6 +1285,43 @@ void QgsOptions::saveOptions()
12111285
}
12121286
settings.setValue( "Map/scales", myPaths );
12131287

1288+
//
1289+
// Composer settings
1290+
//
1291+
1292+
//default font
1293+
QString composerFont = mComposerFontComboBox->currentFont().family();
1294+
settings.setValue( "/Composer/defaultFont", composerFont );
1295+
1296+
//grid color
1297+
settings.setValue( "/Composer/gridRed", mGridColorButton->color().red() );
1298+
settings.setValue( "/Composer/gridGreen", mGridColorButton->color().green() );
1299+
settings.setValue( "/Composer/gridBlue", mGridColorButton->color().blue() );
1300+
settings.setValue( "/Composer/gridAlpha", mGridColorButton->color().alpha() );
1301+
1302+
//grid style
1303+
if ( mGridStyleComboBox->currentText() == tr( "Solid" ) )
1304+
{
1305+
settings.setValue( "/Composer/gridStyle", "Solid" );
1306+
}
1307+
else if ( mGridStyleComboBox->currentText() == tr( "Dots" ) )
1308+
{
1309+
settings.setValue( "/Composer/gridStyle", "Dots" );
1310+
}
1311+
else if ( mGridStyleComboBox->currentText() == tr( "Crosses" ) )
1312+
{
1313+
settings.setValue( "/Composer/gridStyle", "Crosses" );
1314+
}
1315+
1316+
//grid defaults
1317+
settings.setValue( "/Composer/defaultSnapGridResolution", mGridResolutionSpinBox->value() );
1318+
settings.setValue( "/Composer/defaultSnapGridTolerance", mGridToleranceSpinBox->value() );
1319+
settings.setValue( "/Composer/defaultSnapGridOffsetX", mOffsetXSpinBox->value() );
1320+
settings.setValue( "/Composer/defaultSnapGridOffsetY", mOffsetYSpinBox->value() );
1321+
1322+
//guide defaults
1323+
settings.setValue( "/Composer/defaultSnapGuideTolerance", mGuideToleranceSpinBox->value() );
1324+
12141325
//
12151326
// Locale settings
12161327
//
@@ -1598,7 +1709,7 @@ void QgsOptions::on_mOptionsStackedWidget_currentChanged( int theIndx )
15981709
{
15991710
Q_UNUSED( theIndx );
16001711
// load gdal driver list when gdal tab is first opened
1601-
if ( mOptionsStackedWidget->currentWidget()->objectName() == QString( "mOptionsPage_02" )
1712+
if ( mOptionsStackedWidget->currentWidget()->objectName() == QString( "mOptionsPageGDAL" )
16021713
&& ! mLoadedGdalDriverList )
16031714
{
16041715
loadGdalDriverList();

src/app/qgsoptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
5252
*/
5353
QString theme();
5454

55+
/** Sets the page with the specified widget name as the current page
56+
* @note added in QGIS 2.1
57+
*/
58+
void setCurrentPage( QString pageWidgetName );
59+
5560
public slots:
5661
void on_cbxProjectDefaultNew_toggled( bool checked );
5762
void on_pbnProjectDefaultSetCurrent_clicked();

src/core/composer/qgscomposerlabel.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,18 @@ QgsComposerLabel::QgsComposerLabel( QgsComposition *composition ):
3333
mExpressionFeature( 0 ), mExpressionLayer( 0 )
3434
{
3535
mHtmlUnitsToMM = htmlUnitsToMM();
36-
//default font size is 10 point
36+
37+
//get default composer font from settings
38+
QSettings settings;
39+
QString defaultFontString = settings.value( "/Composer/defaultFont" ).toString();
40+
if ( !defaultFontString.isEmpty() )
41+
{
42+
mFont.setFamily( defaultFontString );
43+
}
44+
45+
//default to a 10 point font size
3746
mFont.setPointSizeF( 10 );
47+
3848
}
3949

4050
QgsComposerLabel::~QgsComposerLabel()

src/core/composer/qgscomposerlegendstyle.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
***************************************************************************/
1717

1818
#include "qgscomposerlegendstyle.h"
19+
#include "qgscomposition.h"
1920
#include <QFont>
2021
#include <QMap>
2122
#include <QString>
@@ -25,6 +26,13 @@
2526

2627
QgsComposerLegendStyle::QgsComposerLegendStyle()
2728
{
29+
//get default composer font from settings
30+
QSettings settings;
31+
QString defaultFontString = settings.value( "/Composer/defaultFont" ).toString();
32+
if ( !defaultFontString.isEmpty() )
33+
{
34+
mFont.setFamily( defaultFontString );
35+
}
2836
}
2937

3038
QgsComposerLegendStyle::~QgsComposerLegendStyle()

src/core/composer/qgscomposermap.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
7272
mXOffset = 0.0;
7373
mYOffset = 0.0;
7474

75+
//get default composer font from settings
76+
QSettings settings;
77+
QString defaultFontString = settings.value( "/Composer/defaultFont" ).toString();
78+
if ( !defaultFontString.isEmpty() )
79+
{
80+
mGridAnnotationFont.setFamily( defaultFontString );
81+
}
82+
7583
connectUpdateSlot();
7684

7785
//calculate mExtent based on width/height ratio and map canvas extent

src/core/composer/qgscomposerscalebar.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ void QgsComposerScaleBar::applyDefaultSettings()
235235
mBrush.setColor( QColor( 0, 0, 0 ) );
236236
mBrush.setStyle( Qt::SolidPattern );
237237

238+
//get default composer font from settings
239+
QSettings settings;
240+
QString defaultFontString = settings.value( "/Composer/defaultFont" ).toString();
241+
if ( !defaultFontString.isEmpty() )
242+
{
243+
mFont.setFamily( defaultFontString );
244+
}
238245
mFont.setPointSizeF( 12.0 );
239246
mFontColor = QColor( 0, 0, 0 );
240247

0 commit comments

Comments
 (0)