Skip to content
Permalink
Browse files

Move composer grid style settings to options dialog

  • Loading branch information
nyalldawson committed Nov 19, 2013
1 parent c4e125a commit a013a3a47a24234e18c51ae21e2088ad71fdec90
@@ -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 );

@@ -6863,6 +6863,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();

@@ -684,6 +684,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
//
// Composer settings
//

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

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

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 );
}

//
// Locale settings
//
@@ -1231,9 +1264,31 @@ void QgsOptions::saveOptions()
//
// 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" );
}

//
// Locale settings
//
@@ -1608,41 +1608,35 @@ void QgsComposition::setSnapToGridEnabled( bool b )
{
mSnapToGrid = b;
updatePaperItems();
saveSettings();
}

void QgsComposition::setGridVisible( bool b )
{
mGridVisible = b;
updatePaperItems();
saveSettings();
}

void QgsComposition::setSnapGridResolution( double r )
{
mSnapGridResolution = r;
updatePaperItems();
saveSettings();
}

void QgsComposition::setSnapGridTolerance( double tolerance )
{
mSnapGridTolerance = tolerance;
saveSettings();
}

void QgsComposition::setSnapGridOffsetX( double offset )
{
mSnapGridOffsetX = offset;
updatePaperItems();
saveSettings();
}

void QgsComposition::setSnapGridOffsetY( double offset )
{
mSnapGridOffsetY = offset;
updatePaperItems();
saveSettings();
}

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

void QgsComposition::setGridStyle( GridStyle s )
{
mGridStyle = s;
updatePaperItems();
saveSettings();
}

void QgsComposition::updateSettings()
{
//load new composer setting values
loadSettings();
//update any paper items to reflect new settings
updatePaperItems();
}

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

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

gridStyleString = s.value( "/qgis/composerGridStyle", "Dots" ).toString();
red = s.value( "/qgis/composerGridRed", 0 ).toInt();
green = s.value( "/qgis/composerGridGreen", 0 ).toInt();
blue = s.value( "/qgis/composerGridBlue", 0 ).toInt();
int gridRed, gridGreen, gridBlue, gridAlpha;
gridRed = s.value( "/Composer/gridRed", 190 ).toInt();
gridGreen = s.value( "/Composer/gridGreen", 190 ).toInt();
gridBlue = s.value( "/Composer/gridBlue", 190 ).toInt();
gridAlpha = s.value( "/Composer/gridAlpha", 100 ).toInt();
QColor gridColor = QColor( gridRed, gridGreen, gridBlue, gridAlpha );

mGridPen.setColor( QColor( red, green, blue ) );
mGridPen.setColor( gridColor );
mGridPen.setWidthF( 0 );

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

void QgsComposition::saveSettings()
{
//store grid appearance settings
QSettings s;
s.setValue( "/qgis/composerGridRed", mGridPen.color().red() );
s.setValue( "/qgis/composerGridGreen", mGridPen.color().green() );
s.setValue( "/qgis/composerGridBlue", mGridPen.color().blue() );

if ( mGridStyle == Solid )
{
s.setValue( "/qgis/composerGridStyle", "Solid" );
}
else if ( mGridStyle == Dots )
{
s.setValue( "/qgis/composerGridStyle", "Dots" );
}
else if ( mGridStyle == Crosses )
{
s.setValue( "/qgis/composerGridStyle", "Crosses" );
}
}

void QgsComposition::beginCommand( QgsComposerItem* item, const QString& commandText, QgsComposerMergeCommand::Context c )
{
delete mActiveItemCommand;
@@ -123,6 +123,10 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
*/
void setStatusMessage( const QString & message );

/**Refreshes the composition when composer related options change
*Note: added in version 2.1*/
void updateSettings();

void setSnapToGridEnabled( bool b );
bool snapToGridEnabled() const {return mSnapToGrid;}

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

void loadSettings();
void saveSettings();

void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );

@@ -361,29 +361,6 @@
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mGridStyleLabel">
<property name="text">
<string>Grid style</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="buddy">
<cstring>mGridStyleComboBox</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="mGridStyleComboBox"/>
</item>
<item row="3" column="1">
<widget class="QgsColorButton" name="mGridColorButton">
<property name="text">
<string>Color...</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Tolerance</string>
@@ -393,7 +370,7 @@
</property>
</widget>
</item>
<item row="4" column="1">
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="mGridToleranceSpinBox">
<property name="prefix">
<string/>
@@ -471,11 +448,6 @@
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsColorButton</class>
<extends>QPushButton</extends>
<header>qgscolorbutton.h</header>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBoxBasic</class>
<extends>QGroupBox</extends>

0 comments on commit a013a3a

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