Skip to content
Permalink
Browse files

[FEATURE] Move option to snap to grid to composer view menu, add inde…

…pendant option to show/hide grid
  • Loading branch information
nyalldawson authored and mhugent committed Oct 29, 2013
1 parent 025e453 commit 71b762bbb5f588ca9cbffc585cb6b52f2a3c8ead
@@ -50,6 +50,9 @@ class QgsComposition : QGraphicsScene
void setSnapToGridEnabled( bool b );
bool snapToGridEnabled() const;

void setGridVisible( bool b );
bool gridVisible() const;

void setSnapGridResolution( double r );
double snapGridResolution() const;

@@ -170,6 +170,9 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
mActionPan->setCheckable( true );
mActionAddArrow->setCheckable( true );

mActionShowGrid->setCheckable( true );
mActionSnapGrid->setCheckable( true );

#ifdef Q_WS_MAC
mActionQuit->setText( tr( "Close" ) );
mActionQuit->setShortcut( QKeySequence::Close );
@@ -252,6 +255,9 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
viewMenu->addAction( mActionZoomAll );
viewMenu->addSeparator();
viewMenu->addAction( mActionRefreshView );
viewMenu->addSeparator();
viewMenu->addAction( mActionShowGrid );
viewMenu->addAction( mActionSnapGrid );

// Panel and toolbar submenus
mPanelMenu = new QMenu( tr( "Panels" ), this );
@@ -669,6 +675,24 @@ void QgsComposer::on_mActionRefreshView_triggered()
mComposition->update();
}

void QgsComposer::on_mActionShowGrid_triggered( bool checked )
{
//enable or disable snap items to grid
if ( mComposition )
{
mComposition->setGridVisible( checked );
}
}

void QgsComposer::on_mActionSnapGrid_triggered( bool checked )
{
//enable or disable snap items to grid
if ( mComposition )
{
mComposition->setSnapToGridEnabled( checked );
}
}

void QgsComposer::on_mActionExportAsPDF_triggered()
{
if ( !mComposition || !mView )
@@ -2077,6 +2101,10 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
mComposition->addItemsFromXML( composerElem, doc, &mMapsToRestore );
}

//restore grid settings
mActionSnapGrid->setChecked( mComposition->snapToGridEnabled() );
mActionShowGrid->setChecked( mComposition->gridVisible() );

// look for world file composer map, if needed
// Note: this must be done after maps have been added by addItemsFromXML
if ( mComposition->generateWorldFile() )
@@ -285,6 +285,12 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//!Redo last composer change
void on_mActionRedo_triggered();

//!Show/hide grid
void on_mActionShowGrid_triggered( bool checked );

//!Enable or disable snap items to grid
void on_mActionSnapGrid_triggered( bool checked );

//! Save window state
void saveWindowState();

@@ -78,7 +78,6 @@ QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c )
mAlignmentToleranceSpinBox->setValue( mComposition->alignmentSnapTolerance() );

//snap grid
mSnapToGridGroupCheckBox->setChecked( mComposition->snapToGridEnabled() );
mGridResolutionSpinBox->setValue( mComposition->snapGridResolution() );
mOffsetXSpinBox->setValue( mComposition->snapGridOffsetX() );
mOffsetYSpinBox->setValue( mComposition->snapGridOffsetY() );
@@ -416,7 +415,6 @@ void QgsCompositionWidget::displaySnapingSettings()
return;
}

mSnapToGridGroupCheckBox->setChecked( mComposition->snapToGridEnabled() );
mGridResolutionSpinBox->setValue( mComposition->snapGridResolution() );
mOffsetXSpinBox->setValue( mComposition->snapGridOffsetX() );
mOffsetYSpinBox->setValue( mComposition->snapGridOffsetY() );
@@ -501,14 +499,6 @@ void QgsCompositionWidget::on_mWorldFileMapComboBox_currentIndexChanged( int ind
}
}

void QgsCompositionWidget::on_mSnapToGridGroupCheckBox_toggled( bool state )
{
if ( mComposition )
{
mComposition->setSnapToGridEnabled( state );
}
}

void QgsCompositionWidget::on_mGridResolutionSpinBox_valueChanged( double d )
{
if ( mComposition )
@@ -606,7 +596,6 @@ void QgsCompositionWidget::blockSignals( bool block )
mPaperOrientationComboBox->blockSignals( block );
mResolutionSpinBox->blockSignals( block );
mPrintAsRasterCheckBox->blockSignals( block );
mSnapToGridGroupCheckBox->blockSignals( block );
mGridResolutionSpinBox->blockSignals( block );
mOffsetXSpinBox->blockSignals( block );
mOffsetYSpinBox->blockSignals( block );
@@ -53,7 +53,6 @@ class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase
void on_mGenerateWorldFileCheckBox_toggled( bool state );
void on_mWorldFileMapComboBox_currentIndexChanged( int index );

void on_mSnapToGridGroupCheckBox_toggled( bool state );
void on_mGridResolutionSpinBox_valueChanged( double d );
void on_mOffsetXSpinBox_valueChanged( double d );
void on_mOffsetYSpinBox_valueChanged( double d );
@@ -60,6 +60,7 @@ QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer )
, mUseAdvancedEffects( true )
, mSelectionTolerance( 0.0 )
, mSnapToGrid( false )
, mGridVisible( false )
, mSnapGridResolution( 10.0 )
, mSnapGridTolerance( 2 )
, mSnapGridOffsetX( 0.0 )
@@ -98,6 +99,7 @@ QgsComposition::QgsComposition()
mUseAdvancedEffects( true ),
mSelectionTolerance( 0.0 ),
mSnapToGrid( false ),
mGridVisible( false ),
mSnapGridResolution( 10.0 ),
mSnapGridTolerance( 2 ),
mSnapGridOffsetX( 0.0 ),
@@ -437,6 +439,14 @@ bool QgsComposition::writeXML( QDomElement& composerElem, QDomDocument& doc )
{
compositionElem.setAttribute( "snapping", "0" );
}
if ( mGridVisible )
{
compositionElem.setAttribute( "gridVisible", "1" );
}
else
{
compositionElem.setAttribute( "gridVisible", "0" );
}
compositionElem.setAttribute( "snapGridResolution", QString::number( mSnapGridResolution ) );
compositionElem.setAttribute( "snapGridTolerance", QString::number( mSnapGridTolerance ) );
compositionElem.setAttribute( "snapGridOffsetX", QString::number( mSnapGridOffsetX ) );
@@ -526,6 +536,14 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu
{
mSnapToGrid = true;
}
if ( compositionElem.attribute( "gridVisible" ) == "0" )
{
mGridVisible = false;
}
else
{
mGridVisible = true;
}
mSnapGridResolution = compositionElem.attribute( "snapGridResolution" ).toDouble();
mSnapGridTolerance = compositionElem.attribute( "snapGridTolerance", "2.0" ).toDouble();
mSnapGridOffsetX = compositionElem.attribute( "snapGridOffsetX" ).toDouble();
@@ -1548,6 +1566,13 @@ void QgsComposition::setSnapToGridEnabled( bool b )
saveSettings();
}

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

void QgsComposition::setSnapGridResolution( double r )
{
mSnapGridResolution = r;
@@ -111,6 +111,9 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
void setSnapToGridEnabled( bool b );
bool snapToGridEnabled() const {return mSnapToGrid;}

void setGridVisible( bool b );
bool gridVisible() const {return mGridVisible;}

void setSnapGridResolution( double r );
double snapGridResolution() const {return mSnapGridResolution;}

@@ -425,6 +428,7 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene

/**Parameters for snap to grid function*/
bool mSnapToGrid;
bool mGridVisible;
double mSnapGridResolution;
double mSnapGridTolerance;
double mSnapGridOffsetX;
@@ -43,7 +43,7 @@ void QgsPaperGrid::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
//draw grid
if ( mComposition )
{
if ( mComposition->snapToGridEnabled() && mComposition->plotStyle() == QgsComposition::Preview
if ( mComposition->gridVisible() && mComposition->plotStyle() == QgsComposition::Preview
&& mComposition->snapGridResolution() > 0 )
{
int gridMultiplyX = ( int )( mComposition->snapGridOffsetX() / mComposition->snapGridResolution() );
@@ -285,6 +285,28 @@
<string>Refresh view</string>
</property>
</action>
<action name="mActionShowGrid">
<property name="text">
<string>Show Grid</string>
</property>
<property name="toolTip">
<string>Show grid</string>
</property>
<property name="shortcut">
<string>Ctrl+'</string>
</property>
</action>
<action name="mActionSnapGrid">
<property name="text">
<string>Snap to Grid</string>
</property>
<property name="toolTip">
<string>Snap to grid</string>
</property>
<property name="shortcut">
<string>Ctrl+&quot;</string>
</property>
</action>
<action name="mActionAddImage">
<property name="icon">
<iconset resource="../../images/images.qrc">
@@ -688,7 +710,7 @@
<property name="shortcut">
<string>Ctrl+Alt+]</string>
</property>
</action>
</action>
<action name="mActionPan">
<property name="icon">
<iconset resource="../../images/images.qrc">
@@ -697,7 +719,7 @@
<property name="text">
<string>Pan Composer</string>
</property>
</action>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>
@@ -23,16 +23,7 @@
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>0</number>
</property>
<item>
@@ -320,10 +311,10 @@
<item>
<widget class="QgsCollapsibleGroupBoxBasic" name="mSnapToGridGroupCheckBox">
<property name="title">
<string>Snap to grid</string>
<string>Grid</string>
</property>
<property name="checkable">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="checked">
<bool>false</bool>

0 comments on commit 71b762b

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