13 changes: 13 additions & 0 deletions python/core/composer/qgscomposition.sip
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ class QgsComposition : QGraphicsScene
void setSnapToGridEnabled( bool b );
bool snapToGridEnabled() const;

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

/**Toggles state of smart guides*/
void setSmartGuidesEnabled( bool b );
/**Returns true if smart guides are enabled*/
bool smartGuidesEnabled() const;

/**Removes all snap lines*/
void clearSnapLines();

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

Expand Down Expand Up @@ -223,6 +234,8 @@ class QgsComposition : QGraphicsScene
// QGraphicsLineItem* nearestSnapLine( bool horizontal, double x, double y, double tolerance, QList< QPair< QgsComposerItem*, QgsComposerItem::ItemPositionMode > >& snappedItems );
/**Hides / shows custom snap lines*/
void setSnapLinesVisible( bool visible );
/**Returns visibility of custom snap lines*/
bool snapLinesVisible() const;

/**Allocates new item command and saves initial state in it
@param item target item
Expand Down
84 changes: 83 additions & 1 deletion src/app/composer/qgscomposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
mActionPan->setCheckable( true );
mActionAddArrow->setCheckable( true );

mActionShowGrid->setCheckable( true );
mActionSnapGrid->setCheckable( true );
mActionShowGuides->setCheckable( true );
mActionSnapGuides->setCheckable( true );
mActionSmartGuides->setCheckable( true );

#ifdef Q_WS_MAC
mActionQuit->setText( tr( "Close" ) );
mActionQuit->setShortcut( QKeySequence::Close );
Expand Down Expand Up @@ -252,6 +258,14 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
viewMenu->addAction( mActionZoomAll );
viewMenu->addSeparator();
viewMenu->addAction( mActionRefreshView );
viewMenu->addSeparator();
viewMenu->addAction( mActionShowGrid );
viewMenu->addAction( mActionSnapGrid );
viewMenu->addSeparator();
viewMenu->addAction( mActionShowGuides );
viewMenu->addAction( mActionSnapGuides );
viewMenu->addAction( mActionSmartGuides );
viewMenu->addAction( mActionClearGuides );

// Panel and toolbar submenus
mPanelMenu = new QMenu( tr( "Panels" ), this );
Expand Down Expand Up @@ -342,9 +356,9 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
connect( mComposition->undoStack(), SIGNAL( canRedoChanged( bool ) ), mActionRedo, SLOT( setEnabled( bool ) ) );
}

restoreGridSettings();
connectSlots();


mComposition->setParent( mView );
mView->setComposition( mComposition );

Expand Down Expand Up @@ -669,6 +683,60 @@ void QgsComposer::on_mActionRefreshView_triggered()
mComposition->update();
}

void QgsComposer::on_mActionShowGrid_triggered( bool checked )
{
//show or hide 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_mActionShowGuides_triggered( bool checked )
{
//show or hide guide lines
if ( mComposition )
{
mComposition->setSnapLinesVisible( checked );
}
}

void QgsComposer::on_mActionSnapGuides_triggered( bool checked )
{
//enable or disable snap items to guides
if ( mComposition )
{
mComposition->setAlignmentSnap( checked );
}
}

void QgsComposer::on_mActionSmartGuides_triggered( bool checked )
{
//enable or disable smart snapping guides
if ( mComposition )
{
mComposition->setSmartGuidesEnabled( checked );
}
}

void QgsComposer::on_mActionClearGuides_triggered()
{
//clear guide lines
if ( mComposition )
{
mComposition->clearSnapLines();
}
}

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

//restore grid settings
restoreGridSettings();

// look for world file composer map, if needed
// Note: this must be done after maps have been added by addItemsFromXML
if ( mComposition->generateWorldFile() )
Expand Down Expand Up @@ -2124,6 +2195,17 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
setSelectionTool();
}

void QgsComposer::restoreGridSettings()
{
//restore grid settings
mActionSnapGrid->setChecked( mComposition->snapToGridEnabled() );
mActionShowGrid->setChecked( mComposition->gridVisible() );
//restore guide settings
mActionShowGuides->setChecked( mComposition->snapLinesVisible() );
mActionSnapGuides->setChecked( mComposition->alignmentSnap() );
mActionSmartGuides->setChecked( mComposition->smartGuidesEnabled() );
}

void QgsComposer::deleteItemWidgets()
{
//delete all the items
Expand Down
21 changes: 21 additions & 0 deletions src/app/composer/qgscomposer.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,24 @@ 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 );

//!Show/hide guides
void on_mActionShowGuides_triggered( bool checked );

//!Enable or disable snap items to guides
void on_mActionSnapGuides_triggered( bool checked );

//!Enable or disable smart guides
void on_mActionSmartGuides_triggered( bool checked );

//!Clear guides
void on_mActionClearGuides_triggered();

//! Save window state
void saveWindowState();

Expand Down Expand Up @@ -376,6 +394,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Write a world file
void writeWorldFile( QString fileName, double a, double b, double c, double d, double e, double f ) const;

//! Updates the grid/guide action status based on compositions grid/guide settings
void restoreGridSettings();

/**Composer title*/
QString mTitle;

Expand Down
22 changes: 0 additions & 22 deletions src/app/composer/qgscompositionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c )
connect( mComposition, SIGNAL( composerMapAdded( QgsComposerMap* ) ), this, SLOT( onComposerMapAdded( QgsComposerMap* ) ) );
connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( onItemRemoved( QgsComposerItem* ) ) );


mAlignmentSnapGroupCheckBox->setChecked( mComposition->alignmentSnap() );
mAlignmentToleranceSpinBox->setValue( mComposition->alignmentSnapTolerance() );

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

mSnapToGridGroupCheckBox->setChecked( mComposition->snapToGridEnabled() );
mGridResolutionSpinBox->setValue( mComposition->snapGridResolution() );
mOffsetXSpinBox->setValue( mComposition->snapGridOffsetX() );
mOffsetYSpinBox->setValue( mComposition->snapGridOffsetY() );
Expand Down Expand Up @@ -501,14 +497,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 )
Expand Down Expand Up @@ -580,14 +568,6 @@ void QgsCompositionWidget::on_mSelectionToleranceSpinBox_valueChanged( double d
}
}

void QgsCompositionWidget::on_mAlignmentSnapGroupCheckBox_toggled( bool state )
{
if ( mComposition )
{
mComposition->setAlignmentSnap( state );
}
}

void QgsCompositionWidget::on_mAlignmentToleranceSpinBox_valueChanged( double d )
{
if ( mComposition )
Expand All @@ -606,14 +586,12 @@ 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 );
mGridColorButton->blockSignals( block );
mGridStyleComboBox->blockSignals( block );
mGridToleranceSpinBox->blockSignals( block );
mSelectionToleranceSpinBox->blockSignals( block );
mAlignmentSnapGroupCheckBox->blockSignals( block );
mAlignmentToleranceSpinBox->blockSignals( block );
}
2 changes: 0 additions & 2 deletions src/app/composer/qgscompositionwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ 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 );
void on_mGridColorButton_colorChanged( const QColor &newColor );
void on_mGridStyleComboBox_currentIndexChanged( const QString& text );
void on_mGridToleranceSpinBox_valueChanged( double d );
void on_mSelectionToleranceSpinBox_valueChanged( double d );
void on_mAlignmentSnapGroupCheckBox_toggled( bool state );
void on_mAlignmentToleranceSpinBox_valueChanged( double d );

/**Sets GUI elements to width/height from composition*/
Expand Down
55 changes: 30 additions & 25 deletions src/core/composer/qgscomposermousehandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ QPointF QgsComposerMouseHandles::snapPoint( const QPointF& point, QgsComposerMou
}

//align item
if ( !mComposition->alignmentSnap() )
if ( !mComposition->alignmentSnap() && !mComposition->smartGuidesEnabled() )
{
return point;
}
Expand Down Expand Up @@ -985,38 +985,43 @@ void QgsComposerMouseHandles::collectAlignCoordinates( QMap< double, const QgsCo
alignCoordsX.clear();
alignCoordsY.clear();

QList<QGraphicsItem *> itemList = mComposition->items();
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
for ( ; itemIt != itemList.end(); ++itemIt )
if ( mComposition->smartGuidesEnabled() )
{
const QgsComposerItem* currentItem = dynamic_cast<const QgsComposerItem *>( *itemIt );
//don't snap to selected items, since they're the ones that will be snapping to something else
if ( !currentItem || currentItem->selected() )
QList<QGraphicsItem *> itemList = mComposition->items();
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
for ( ; itemIt != itemList.end(); ++itemIt )
{
continue;
const QgsComposerItem* currentItem = dynamic_cast<const QgsComposerItem *>( *itemIt );
//don't snap to selected items, since they're the ones that will be snapping to something else
if ( !currentItem || currentItem->selected() )
{
continue;
}
alignCoordsX.insert( currentItem->transform().dx(), currentItem );
alignCoordsX.insert( currentItem->transform().dx() + currentItem->rect().width(), currentItem );
alignCoordsX.insert( currentItem->transform().dx() + currentItem->rect().center().x(), currentItem );
alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().top(), currentItem );
alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().center().y(), currentItem );
alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().bottom(), currentItem );
}
alignCoordsX.insert( currentItem->transform().dx(), currentItem );
alignCoordsX.insert( currentItem->transform().dx() + currentItem->rect().width(), currentItem );
alignCoordsX.insert( currentItem->transform().dx() + currentItem->rect().center().x(), currentItem );
alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().top(), currentItem );
alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().center().y(), currentItem );
alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().bottom(), currentItem );

}

//arbitrary snap lines
QList< QGraphicsLineItem* >::const_iterator sIt = mComposition->snapLines()->constBegin();
for ( ; sIt != mComposition->snapLines()->constEnd(); ++sIt )
if ( mComposition->alignmentSnap() )
{
double x = ( *sIt )->line().x1();
double y = ( *sIt )->line().y1();
if ( qgsDoubleNear( y, 0.0 ) )
{
alignCoordsX.insert( x, 0 );
}
else
QList< QGraphicsLineItem* >::const_iterator sIt = mComposition->snapLines()->constBegin();
for ( ; sIt != mComposition->snapLines()->constEnd(); ++sIt )
{
alignCoordsY.insert( y, 0 );
double x = ( *sIt )->line().x1();
double y = ( *sIt )->line().y1();
if ( qgsDoubleNear( y, 0.0 ) )
{
alignCoordsX.insert( x, 0 );
}
else
{
alignCoordsY.insert( y, 0 );
}
}
}
}
Expand Down
Loading