Skip to content

Commit a013a3a

Browse files
committedNov 19, 2013
Move composer grid style settings to options dialog
1 parent c4e125a commit a013a3a

File tree

8 files changed

+132
-140
lines changed

8 files changed

+132
-140
lines changed
 

‎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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6863,6 +6863,17 @@ void QgisApp::options()
68636863
double zoomFactor = mySettings.value( "/qgis/zoom_factor", 2 ).toDouble();
68646864
mMapCanvas->setWheelAction(( QgsMapCanvas::WheelAction ) action, zoomFactor );
68656865

6866+
//update any open compositions so they reflect new composer settings
6867+
//we have to push the changes to the compositions here, because compositions
6868+
//have no access to qgisapp and accordingly can't listen in to changes
6869+
QSet<QgsComposer*> composers = instance()->printComposers();
6870+
QSet<QgsComposer*>::iterator composer_it = composers.begin();
6871+
for ( ; composer_it != composers.end(); ++composer_it )
6872+
{
6873+
QgsComposition* composition = ( *composer_it )->composition();
6874+
composition->updateSettings();
6875+
}
6876+
68666877
//do we need this? TS
68676878
mMapCanvas->refresh();
68686879

‎src/app/qgsoptions.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
684684
//
685685
// Composer settings
686686
//
687+
688+
//default composer font
687689
mComposerFontComboBox->blockSignals( true );
688690

689691
QString composerFontFamily = settings.value( "/Composer/defaultFont" ).toString();
@@ -698,6 +700,37 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
698700

699701
mComposerFontComboBox->blockSignals( false );
700702

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+
701734
//
702735
// Locale settings
703736
//
@@ -1231,9 +1264,31 @@ void QgsOptions::saveOptions()
12311264
//
12321265
// Composer settings
12331266
//
1267+
1268+
//default font
12341269
QString composerFont = mComposerFontComboBox->currentFont().family();
12351270
settings.setValue( "/Composer/defaultFont", composerFont );
12361271

1272+
//grid color
1273+
settings.setValue( "/Composer/gridRed", mGridColorButton->color().red() );
1274+
settings.setValue( "/Composer/gridGreen", mGridColorButton->color().green() );
1275+
settings.setValue( "/Composer/gridBlue", mGridColorButton->color().blue() );
1276+
settings.setValue( "/Composer/gridAlpha", mGridColorButton->color().alpha() );
1277+
1278+
//grid style
1279+
if ( mGridStyleComboBox->currentText() == tr( "Solid" ) )
1280+
{
1281+
settings.setValue( "/Composer/gridStyle", "Solid" );
1282+
}
1283+
else if ( mGridStyleComboBox->currentText() == tr( "Dots" ) )
1284+
{
1285+
settings.setValue( "/Composer/gridStyle", "Dots" );
1286+
}
1287+
else if ( mGridStyleComboBox->currentText() == tr( "Crosses" ) )
1288+
{
1289+
settings.setValue( "/Composer/gridStyle", "Crosses" );
1290+
}
1291+
12371292
//
12381293
// Locale settings
12391294
//

‎src/core/composer/qgscomposition.cpp

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,41 +1608,35 @@ void QgsComposition::setSnapToGridEnabled( bool b )
16081608
{
16091609
mSnapToGrid = b;
16101610
updatePaperItems();
1611-
saveSettings();
16121611
}
16131612

16141613
void QgsComposition::setGridVisible( bool b )
16151614
{
16161615
mGridVisible = b;
16171616
updatePaperItems();
1618-
saveSettings();
16191617
}
16201618

16211619
void QgsComposition::setSnapGridResolution( double r )
16221620
{
16231621
mSnapGridResolution = r;
16241622
updatePaperItems();
1625-
saveSettings();
16261623
}
16271624

16281625
void QgsComposition::setSnapGridTolerance( double tolerance )
16291626
{
16301627
mSnapGridTolerance = tolerance;
1631-
saveSettings();
16321628
}
16331629

16341630
void QgsComposition::setSnapGridOffsetX( double offset )
16351631
{
16361632
mSnapGridOffsetX = offset;
16371633
updatePaperItems();
1638-
saveSettings();
16391634
}
16401635

16411636
void QgsComposition::setSnapGridOffsetY( double offset )
16421637
{
16431638
mSnapGridOffsetY = offset;
16441639
updatePaperItems();
1645-
saveSettings();
16461640
}
16471641

16481642
void QgsComposition::setGridPen( const QPen& p )
@@ -1651,14 +1645,20 @@ void QgsComposition::setGridPen( const QPen& p )
16511645
//make sure grid is drawn using a zero-width cosmetic pen
16521646
mGridPen.setWidthF( 0 );
16531647
updatePaperItems();
1654-
saveSettings();
16551648
}
16561649

16571650
void QgsComposition::setGridStyle( GridStyle s )
16581651
{
16591652
mGridStyle = s;
16601653
updatePaperItems();
1661-
saveSettings();
1654+
}
1655+
1656+
void QgsComposition::updateSettings()
1657+
{
1658+
//load new composer setting values
1659+
loadSettings();
1660+
//update any paper items to reflect new settings
1661+
updatePaperItems();
16621662
}
16631663

16641664
void QgsComposition::loadSettings()
@@ -1667,14 +1667,16 @@ void QgsComposition::loadSettings()
16671667
QSettings s;
16681668

16691669
QString gridStyleString;
1670-
int red, green, blue;
1670+
gridStyleString = s.value( "/Composer/gridStyle", "Dots" ).toString();
16711671

1672-
gridStyleString = s.value( "/qgis/composerGridStyle", "Dots" ).toString();
1673-
red = s.value( "/qgis/composerGridRed", 0 ).toInt();
1674-
green = s.value( "/qgis/composerGridGreen", 0 ).toInt();
1675-
blue = s.value( "/qgis/composerGridBlue", 0 ).toInt();
1672+
int gridRed, gridGreen, gridBlue, gridAlpha;
1673+
gridRed = s.value( "/Composer/gridRed", 190 ).toInt();
1674+
gridGreen = s.value( "/Composer/gridGreen", 190 ).toInt();
1675+
gridBlue = s.value( "/Composer/gridBlue", 190 ).toInt();
1676+
gridAlpha = s.value( "/Composer/gridAlpha", 100 ).toInt();
1677+
QColor gridColor = QColor( gridRed, gridGreen, gridBlue, gridAlpha );
16761678

1677-
mGridPen.setColor( QColor( red, green, blue ) );
1679+
mGridPen.setColor( gridColor );
16781680
mGridPen.setWidthF( 0 );
16791681

16801682
if ( gridStyleString == "Dots" )
@@ -1691,28 +1693,6 @@ void QgsComposition::loadSettings()
16911693
}
16921694
}
16931695

1694-
void QgsComposition::saveSettings()
1695-
{
1696-
//store grid appearance settings
1697-
QSettings s;
1698-
s.setValue( "/qgis/composerGridRed", mGridPen.color().red() );
1699-
s.setValue( "/qgis/composerGridGreen", mGridPen.color().green() );
1700-
s.setValue( "/qgis/composerGridBlue", mGridPen.color().blue() );
1701-
1702-
if ( mGridStyle == Solid )
1703-
{
1704-
s.setValue( "/qgis/composerGridStyle", "Solid" );
1705-
}
1706-
else if ( mGridStyle == Dots )
1707-
{
1708-
s.setValue( "/qgis/composerGridStyle", "Dots" );
1709-
}
1710-
else if ( mGridStyle == Crosses )
1711-
{
1712-
s.setValue( "/qgis/composerGridStyle", "Crosses" );
1713-
}
1714-
}
1715-
17161696
void QgsComposition::beginCommand( QgsComposerItem* item, const QString& commandText, QgsComposerMergeCommand::Context c )
17171697
{
17181698
delete mActiveItemCommand;

‎src/core/composer/qgscomposition.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
123123
*/
124124
void setStatusMessage( const QString & message );
125125

126+
/**Refreshes the composition when composer related options change
127+
*Note: added in version 2.1*/
128+
void updateSettings();
129+
126130
void setSnapToGridEnabled( bool b );
127131
bool snapToGridEnabled() const {return mSnapToGrid;}
128132

@@ -482,7 +486,6 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
482486
int boundingRectOfSelectedItems( QRectF& bRect );
483487

484488
void loadSettings();
485-
void saveSettings();
486489

487490
void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );
488491

‎src/ui/qgscompositionwidgetbase.ui

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -361,29 +361,6 @@
361361
</layout>
362362
</item>
363363
<item row="2" column="0">
364-
<widget class="QLabel" name="mGridStyleLabel">
365-
<property name="text">
366-
<string>Grid style</string>
367-
</property>
368-
<property name="wordWrap">
369-
<bool>true</bool>
370-
</property>
371-
<property name="buddy">
372-
<cstring>mGridStyleComboBox</cstring>
373-
</property>
374-
</widget>
375-
</item>
376-
<item row="2" column="1">
377-
<widget class="QComboBox" name="mGridStyleComboBox"/>
378-
</item>
379-
<item row="3" column="1">
380-
<widget class="QgsColorButton" name="mGridColorButton">
381-
<property name="text">
382-
<string>Color...</string>
383-
</property>
384-
</widget>
385-
</item>
386-
<item row="4" column="0">
387364
<widget class="QLabel" name="label_4">
388365
<property name="text">
389366
<string>Tolerance</string>
@@ -393,7 +370,7 @@
393370
</property>
394371
</widget>
395372
</item>
396-
<item row="4" column="1">
373+
<item row="2" column="1">
397374
<widget class="QDoubleSpinBox" name="mGridToleranceSpinBox">
398375
<property name="prefix">
399376
<string/>
@@ -471,11 +448,6 @@
471448
</widget>
472449
<layoutdefault spacing="6" margin="11"/>
473450
<customwidgets>
474-
<customwidget>
475-
<class>QgsColorButton</class>
476-
<extends>QPushButton</extends>
477-
<header>qgscolorbutton.h</header>
478-
</customwidget>
479451
<customwidget>
480452
<class>QgsCollapsibleGroupBoxBasic</class>
481453
<extends>QGroupBox</extends>

0 commit comments

Comments
 (0)
Please sign in to comment.