Skip to content

Commit 3dfb9ff

Browse files
nyalldawsonmhugent
authored andcommittedOct 29, 2013
[FEATURE] Move option to snap to guides to composer view menu, add indepenant toggles for showing guides and for enabling smart guides
1 parent 71b762b commit 3dfb9ff

File tree

9 files changed

+149
-50
lines changed

9 files changed

+149
-50
lines changed
 

‎src/app/composer/qgscomposer.cpp

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
172172

173173
mActionShowGrid->setCheckable( true );
174174
mActionSnapGrid->setCheckable( true );
175+
mActionShowGuides->setCheckable( true );
176+
mActionSnapGuides->setCheckable( true );
177+
mActionSmartGuides->setCheckable( true );
175178

176179
#ifdef Q_WS_MAC
177180
mActionQuit->setText( tr( "Close" ) );
@@ -258,6 +261,10 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
258261
viewMenu->addSeparator();
259262
viewMenu->addAction( mActionShowGrid );
260263
viewMenu->addAction( mActionSnapGrid );
264+
viewMenu->addSeparator();
265+
viewMenu->addAction( mActionShowGuides );
266+
viewMenu->addAction( mActionSnapGuides );
267+
viewMenu->addAction( mActionSmartGuides );
261268

262269
// Panel and toolbar submenus
263270
mPanelMenu = new QMenu( tr( "Panels" ), this );
@@ -348,9 +355,9 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
348355
connect( mComposition->undoStack(), SIGNAL( canRedoChanged( bool ) ), mActionRedo, SLOT( setEnabled( bool ) ) );
349356
}
350357

358+
restoreGridSettings();
351359
connectSlots();
352360

353-
354361
mComposition->setParent( mView );
355362
mView->setComposition( mComposition );
356363

@@ -677,7 +684,7 @@ void QgsComposer::on_mActionRefreshView_triggered()
677684

678685
void QgsComposer::on_mActionShowGrid_triggered( bool checked )
679686
{
680-
//enable or disable snap items to grid
687+
//show or hide grid
681688
if ( mComposition )
682689
{
683690
mComposition->setGridVisible( checked );
@@ -693,6 +700,33 @@ void QgsComposer::on_mActionSnapGrid_triggered( bool checked )
693700
}
694701
}
695702

703+
void QgsComposer::on_mActionShowGuides_triggered( bool checked )
704+
{
705+
//show or hide guide lines
706+
if ( mComposition )
707+
{
708+
mComposition->setSnapLinesVisible( checked );
709+
}
710+
}
711+
712+
void QgsComposer::on_mActionSnapGuides_triggered( bool checked )
713+
{
714+
//enable or disable snap items to guides
715+
if ( mComposition )
716+
{
717+
mComposition->setAlignmentSnap( checked );
718+
}
719+
}
720+
721+
void QgsComposer::on_mActionSmartGuides_triggered( bool checked )
722+
{
723+
//enable or disable smart snapping guides
724+
if ( mComposition )
725+
{
726+
mComposition->setSmartGuidesEnabled( checked );
727+
}
728+
}
729+
696730
void QgsComposer::on_mActionExportAsPDF_triggered()
697731
{
698732
if ( !mComposition || !mView )
@@ -2102,8 +2136,7 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
21022136
}
21032137

21042138
//restore grid settings
2105-
mActionSnapGrid->setChecked( mComposition->snapToGridEnabled() );
2106-
mActionShowGrid->setChecked( mComposition->gridVisible() );
2139+
restoreGridSettings();
21072140

21082141
// look for world file composer map, if needed
21092142
// Note: this must be done after maps have been added by addItemsFromXML
@@ -2152,6 +2185,17 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
21522185
setSelectionTool();
21532186
}
21542187

2188+
void QgsComposer::restoreGridSettings()
2189+
{
2190+
//restore grid settings
2191+
mActionSnapGrid->setChecked( mComposition->snapToGridEnabled() );
2192+
mActionShowGrid->setChecked( mComposition->gridVisible() );
2193+
//restore guide settings
2194+
mActionShowGuides->setChecked( mComposition->snapLinesVisible() );
2195+
mActionSnapGuides->setChecked( mComposition->alignmentSnap() );
2196+
mActionSmartGuides->setChecked( mComposition->smartGuidesEnabled() );
2197+
}
2198+
21552199
void QgsComposer::deleteItemWidgets()
21562200
{
21572201
//delete all the items

‎src/app/composer/qgscomposer.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,15 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
291291
//!Enable or disable snap items to grid
292292
void on_mActionSnapGrid_triggered( bool checked );
293293

294+
//!Show/hide guides
295+
void on_mActionShowGuides_triggered( bool checked );
296+
297+
//!Enable or disable snap items to guides
298+
void on_mActionSnapGuides_triggered( bool checked );
299+
300+
//!Enable or disable smart guides
301+
void on_mActionSmartGuides_triggered( bool checked );
302+
294303
//! Save window state
295304
void saveWindowState();
296305

@@ -382,6 +391,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
382391
//! Write a world file
383392
void writeWorldFile( QString fileName, double a, double b, double c, double d, double e, double f ) const;
384393

394+
//! Updates the grid/guide action status based on compositions grid/guide settings
395+
void restoreGridSettings();
396+
385397
/**Composer title*/
386398
QString mTitle;
387399

‎src/app/composer/qgscompositionwidget.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c )
7373
connect( mComposition, SIGNAL( composerMapAdded( QgsComposerMap* ) ), this, SLOT( onComposerMapAdded( QgsComposerMap* ) ) );
7474
connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( onItemRemoved( QgsComposerItem* ) ) );
7575

76-
77-
mAlignmentSnapGroupCheckBox->setChecked( mComposition->alignmentSnap() );
7876
mAlignmentToleranceSpinBox->setValue( mComposition->alignmentSnapTolerance() );
7977

8078
//snap grid
@@ -570,14 +568,6 @@ void QgsCompositionWidget::on_mSelectionToleranceSpinBox_valueChanged( double d
570568
}
571569
}
572570

573-
void QgsCompositionWidget::on_mAlignmentSnapGroupCheckBox_toggled( bool state )
574-
{
575-
if ( mComposition )
576-
{
577-
mComposition->setAlignmentSnap( state );
578-
}
579-
}
580-
581571
void QgsCompositionWidget::on_mAlignmentToleranceSpinBox_valueChanged( double d )
582572
{
583573
if ( mComposition )
@@ -603,6 +593,5 @@ void QgsCompositionWidget::blockSignals( bool block )
603593
mGridStyleComboBox->blockSignals( block );
604594
mGridToleranceSpinBox->blockSignals( block );
605595
mSelectionToleranceSpinBox->blockSignals( block );
606-
mAlignmentSnapGroupCheckBox->blockSignals( block );
607596
mAlignmentToleranceSpinBox->blockSignals( block );
608597
}

‎src/app/composer/qgscompositionwidget.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase
6060
void on_mGridStyleComboBox_currentIndexChanged( const QString& text );
6161
void on_mGridToleranceSpinBox_valueChanged( double d );
6262
void on_mSelectionToleranceSpinBox_valueChanged( double d );
63-
void on_mAlignmentSnapGroupCheckBox_toggled( bool state );
6463
void on_mAlignmentToleranceSpinBox_valueChanged( double d );
6564

6665
/**Sets GUI elements to width/height from composition*/

‎src/core/composer/qgscomposermousehandles.cpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ QPointF QgsComposerMouseHandles::snapPoint( const QPointF& point, QgsComposerMou
805805
}
806806

807807
//align item
808-
if ( !mComposition->alignmentSnap() )
808+
if ( !mComposition->alignmentSnap() && !mComposition->smartGuidesEnabled() )
809809
{
810810
return point;
811811
}
@@ -985,38 +985,43 @@ void QgsComposerMouseHandles::collectAlignCoordinates( QMap< double, const QgsCo
985985
alignCoordsX.clear();
986986
alignCoordsY.clear();
987987

988-
QList<QGraphicsItem *> itemList = mComposition->items();
989-
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
990-
for ( ; itemIt != itemList.end(); ++itemIt )
988+
if ( mComposition->smartGuidesEnabled() )
991989
{
992-
const QgsComposerItem* currentItem = dynamic_cast<const QgsComposerItem *>( *itemIt );
993-
//don't snap to selected items, since they're the ones that will be snapping to something else
994-
if ( !currentItem || currentItem->selected() )
990+
QList<QGraphicsItem *> itemList = mComposition->items();
991+
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
992+
for ( ; itemIt != itemList.end(); ++itemIt )
995993
{
996-
continue;
994+
const QgsComposerItem* currentItem = dynamic_cast<const QgsComposerItem *>( *itemIt );
995+
//don't snap to selected items, since they're the ones that will be snapping to something else
996+
if ( !currentItem || currentItem->selected() )
997+
{
998+
continue;
999+
}
1000+
alignCoordsX.insert( currentItem->transform().dx(), currentItem );
1001+
alignCoordsX.insert( currentItem->transform().dx() + currentItem->rect().width(), currentItem );
1002+
alignCoordsX.insert( currentItem->transform().dx() + currentItem->rect().center().x(), currentItem );
1003+
alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().top(), currentItem );
1004+
alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().center().y(), currentItem );
1005+
alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().bottom(), currentItem );
9971006
}
998-
alignCoordsX.insert( currentItem->transform().dx(), currentItem );
999-
alignCoordsX.insert( currentItem->transform().dx() + currentItem->rect().width(), currentItem );
1000-
alignCoordsX.insert( currentItem->transform().dx() + currentItem->rect().center().x(), currentItem );
1001-
alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().top(), currentItem );
1002-
alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().center().y(), currentItem );
1003-
alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().bottom(), currentItem );
1004-
10051007
}
10061008

10071009
//arbitrary snap lines
1008-
QList< QGraphicsLineItem* >::const_iterator sIt = mComposition->snapLines()->constBegin();
1009-
for ( ; sIt != mComposition->snapLines()->constEnd(); ++sIt )
1010+
if ( mComposition->alignmentSnap() )
10101011
{
1011-
double x = ( *sIt )->line().x1();
1012-
double y = ( *sIt )->line().y1();
1013-
if ( qgsDoubleNear( y, 0.0 ) )
1014-
{
1015-
alignCoordsX.insert( x, 0 );
1016-
}
1017-
else
1012+
QList< QGraphicsLineItem* >::const_iterator sIt = mComposition->snapLines()->constBegin();
1013+
for ( ; sIt != mComposition->snapLines()->constEnd(); ++sIt )
10181014
{
1019-
alignCoordsY.insert( y, 0 );
1015+
double x = ( *sIt )->line().x1();
1016+
double y = ( *sIt )->line().y1();
1017+
if ( qgsDoubleNear( y, 0.0 ) )
1018+
{
1019+
alignCoordsX.insert( x, 0 );
1020+
}
1021+
else
1022+
{
1023+
alignCoordsY.insert( y, 0 );
1024+
}
10201025
}
10211026
}
10221027
}

‎src/core/composer/qgscomposition.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer )
6666
, mSnapGridOffsetX( 0.0 )
6767
, mSnapGridOffsetY( 0.0 )
6868
, mAlignmentSnap( true )
69+
, mGuidesVisible( true )
70+
, mSmartGuides( true )
6971
, mAlignmentSnapTolerance( 2 )
7072
, mSelectionHandles( 0 )
7173
, mActiveItemCommand( 0 )
@@ -105,6 +107,8 @@ QgsComposition::QgsComposition()
105107
mSnapGridOffsetX( 0.0 ),
106108
mSnapGridOffsetY( 0.0 ),
107109
mAlignmentSnap( true ),
110+
mGuidesVisible( true ),
111+
mSmartGuides( true ),
108112
mAlignmentSnapTolerance( 2 ),
109113
mSelectionHandles( 0 ),
110114
mActiveItemCommand( 0 ),
@@ -475,6 +479,8 @@ bool QgsComposition::writeXML( QDomElement& composerElem, QDomDocument& doc )
475479
}
476480

477481
compositionElem.setAttribute( "alignmentSnap", mAlignmentSnap ? 1 : 0 );
482+
compositionElem.setAttribute( "guidesVisible", mGuidesVisible ? 1 : 0 );
483+
compositionElem.setAttribute( "smartGuides", mSmartGuides ? 1 : 0 );
478484
compositionElem.setAttribute( "alignmentSnapTolerance", mAlignmentSnapTolerance );
479485

480486
//save items except paper items and frame items (they are saved with the corresponding multiframe)
@@ -549,6 +555,11 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu
549555
mSnapGridOffsetX = compositionElem.attribute( "snapGridOffsetX" ).toDouble();
550556
mSnapGridOffsetY = compositionElem.attribute( "snapGridOffsetY" ).toDouble();
551557

558+
mAlignmentSnap = compositionElem.attribute( "alignmentSnap", "1" ).toInt() == 0 ? false : true;
559+
mGuidesVisible = compositionElem.attribute( "guidesVisible", "1" ).toInt() == 0 ? false : true;
560+
mSmartGuides = compositionElem.attribute( "smartGuides", "1" ).toInt() == 0 ? false : true;
561+
mAlignmentSnapTolerance = compositionElem.attribute( "alignmentSnapTolerance", "2.0" ).toDouble();
562+
552563
//custom snap lines
553564
QDomNodeList snapLineNodes = compositionElem.elementsByTagName( "SnapLine" );
554565
for ( int i = 0; i < snapLineNodes.size(); ++i )
@@ -562,9 +573,6 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu
562573
snapItem->setLine( x1, y1, x2, y2 );
563574
}
564575

565-
mAlignmentSnap = compositionElem.attribute( "alignmentSnap", "1" ).toInt() == 0 ? false : true;
566-
mAlignmentSnapTolerance = compositionElem.attribute( "alignmentSnapTolerance", "2.0" ).toDouble();
567-
568576
mPrintAsRaster = compositionElem.attribute( "printAsRaster" ).toInt();
569577
mPrintResolution = compositionElem.attribute( "printResolution", "300" ).toInt();
570578

@@ -1407,6 +1415,7 @@ QGraphicsLineItem* QgsComposition::addSnapLine()
14071415
linePen.setWidthF( 0 );
14081416
item->setPen( linePen );
14091417
item->setZValue( 100 );
1418+
item->setVisible( mGuidesVisible );
14101419
addItem( item );
14111420
mSnapLines.push_back( item );
14121421
return item;
@@ -1421,6 +1430,7 @@ void QgsComposition::removeSnapLine( QGraphicsLineItem* line )
14211430

14221431
void QgsComposition::setSnapLinesVisible( bool visible )
14231432
{
1433+
mGuidesVisible = visible;
14241434
QList< QGraphicsLineItem* >::iterator it = mSnapLines.begin();
14251435
for ( ; it != mSnapLines.end(); ++it )
14261436
{

‎src/core/composer/qgscomposition.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
114114
void setGridVisible( bool b );
115115
bool gridVisible() const {return mGridVisible;}
116116

117+
/**Hides / shows custom snap lines*/
118+
void setSnapLinesVisible( bool visible );
119+
bool snapLinesVisible() const {return mGuidesVisible;}
120+
121+
void setAlignmentSnap( bool s ) { mAlignmentSnap = s; }
122+
bool alignmentSnap() const { return mAlignmentSnap; }
123+
124+
void setSmartGuidesEnabled( bool b ) { mSmartGuides = b; };
125+
bool smartGuidesEnabled() const {return mSmartGuides;}
126+
117127
void setSnapGridResolution( double r );
118128
double snapGridResolution() const {return mSnapGridResolution;}
119129

@@ -132,9 +142,6 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
132142
void setGridStyle( GridStyle s );
133143
GridStyle gridStyle() const {return mGridStyle;}
134144

135-
void setAlignmentSnap( bool s ) { mAlignmentSnap = s; }
136-
bool alignmentSnap() const { return mAlignmentSnap; }
137-
138145
void setAlignmentSnapTolerance( double t ) { mAlignmentSnapTolerance = t; }
139146
double alignmentSnapTolerance() const { return mAlignmentSnapTolerance; }
140147

@@ -310,8 +317,6 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
310317
* @note not available in python bindings
311318
*/
312319
QGraphicsLineItem* nearestSnapLine( bool horizontal, double x, double y, double tolerance, QList< QPair< QgsComposerItem*, QgsComposerItem::ItemPositionMode > >& snappedItems );
313-
/**Hides / shows custom snap lines*/
314-
void setSnapLinesVisible( bool visible );
315320

316321
/**Allocates new item command and saves initial state in it
317322
@param item target item
@@ -438,6 +443,8 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
438443

439444
/**Parameters for alignment snap*/
440445
bool mAlignmentSnap;
446+
bool mGuidesVisible;
447+
bool mSmartGuides;
441448
double mAlignmentSnapTolerance;
442449

443450
/**Arbitraty snap lines (horizontal and vertical)*/

‎src/ui/qgscomposerbase.ui

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,39 @@
307307
<string>Ctrl+&quot;</string>
308308
</property>
309309
</action>
310+
<action name="mActionShowGuides">
311+
<property name="text">
312+
<string>Show Guides</string>
313+
</property>
314+
<property name="toolTip">
315+
<string>Show guides</string>
316+
</property>
317+
<property name="shortcut">
318+
<string>Ctrl+;</string>
319+
</property>
320+
</action>
321+
<action name="mActionSnapGuides">
322+
<property name="text">
323+
<string>Snap to Guides</string>
324+
</property>
325+
<property name="toolTip">
326+
<string>Snap to guides</string>
327+
</property>
328+
<property name="shortcut">
329+
<string>Ctrl+:</string>
330+
</property>
331+
</action>
332+
<action name="mActionSmartGuides">
333+
<property name="text">
334+
<string>Smart Guides</string>
335+
</property>
336+
<property name="toolTip">
337+
<string>Smart guides</string>
338+
</property>
339+
<property name="shortcut">
340+
<string>Ctrl+Alt+;</string>
341+
</property>
342+
</action>
310343
<action name="mActionAddImage">
311344
<property name="icon">
312345
<iconset resource="../../images/images.qrc">

‎src/ui/qgscompositionwidgetbase.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@
447447
<string>Snap to alignments</string>
448448
</property>
449449
<property name="checkable">
450-
<bool>true</bool>
450+
<bool>false</bool>
451451
</property>
452452
<property name="syncGroup" stdset="0">
453453
<string notr="true">composeritem</string>

0 commit comments

Comments
 (0)
Please sign in to comment.