Skip to content

Commit

Permalink
[needs-docs] keyboard shortcut to toggle snapping (S)
Browse files Browse the repository at this point in the history
Pressing the key "S" will toggle snapping. This helps to quickly
enable/disable snapping while digitizing.
  • Loading branch information
3nids authored and m-kuhn committed Feb 28, 2017
1 parent f0489c9 commit 5176ecf
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 24 deletions.
2 changes: 1 addition & 1 deletion python/core/qgsproject.sip
Expand Up @@ -539,7 +539,7 @@ class QgsProject : QObject, QgsExpressionContextGenerator
void homePathChanged();

//! emitted whenever the configuration for snapping has changed
void snappingConfigChanged();
void snappingConfigChanged( const QgsSnappingConfig& config );

/** Emitted whenever the expression variables stored in the project have been changed.
* @note added in QGIS 3.0
Expand Down
8 changes: 7 additions & 1 deletion python/core/qgssnappingutils.sip
Expand Up @@ -89,16 +89,22 @@ class QgsSnappingUtils : QObject
*/
QgsSnappingConfig config() const;

public slots:
/**
* The snapping configuration controls the behavior of this object
*/
void setConfig( const QgsSnappingConfig& snappingConfig );

/**
* Toggles the state of snapping
*/
void toggleEnabled();

signals:
/**
* Emitted when the snapping settings object changes.
*/
void configChanged();
void configChanged( const QgsSnappingConfig& snappingConfig );

protected:
//! Called when starting to index - can be overridden and e.g. progress dialog can be provided
Expand Down
2 changes: 1 addition & 1 deletion scripts/sipdiff
Expand Up @@ -53,7 +53,7 @@ for file in $*; do
${GP}sed -i -r '/^\s*Q_(OBJECT|ENUMS|PROPERTY).*?$/d' $tempfile

# Remove function definition in header
${GP}sed -i -r 's/^(\s*)?(virtual |static )?(inline )?(void|bool|int|double|Q\w+)(\s+[^ ]*?\(.*?\)( const)?)\s*\{.*?\}$/\1\2\4\5;/g' $tempfile
${GP}sed -i -r 's/^(\s*)?(virtual |static )?(inline )?(void|bool|int|double|Q\w+)(\*?)(\s+[^ ]*?\(.*?\)( const)?)\s*\{.*?\}$/\1\2\4\5\6;/g' $tempfile

# Remove nullptr
${GP}sed -i 's/nullptr/0/g' $tempfile
Expand Down
17 changes: 12 additions & 5 deletions src/app/qgisapp.cpp
Expand Up @@ -772,7 +772,9 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
startProfile( QStringLiteral( "Snapping utils" ) );
mSnappingUtils = new QgsMapCanvasSnappingUtils( mMapCanvas, this );
mMapCanvas->setSnappingUtils( mSnappingUtils );
connect( QgsProject::instance(), &QgsProject::snappingConfigChanged, this, &QgisApp::onSnappingConfigChanged );
connect( QgsProject::instance(), &QgsProject::snappingConfigChanged, mSnappingUtils, &QgsSnappingUtils::setConfig );
connect( mSnappingUtils, &QgsSnappingUtils::configChanged, QgsProject::instance(), &QgsProject::setSnappingConfig );


endProfile();

Expand Down Expand Up @@ -1077,21 +1079,26 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
QShortcut* zoomInShortCut = new QShortcut( QKeySequence( tr( "Ctrl++" ) ), this );
connect( zoomInShortCut, &QShortcut::activated, mMapCanvas, &QgsMapCanvas::zoomIn );
zoomInShortCut->setObjectName( QStringLiteral( "ZoomInToCanvas" ) );
zoomInShortCut->setWhatsThis( QStringLiteral( "Zoom in to canvas" ) );
zoomInShortCut->setWhatsThis( tr( "Zoom in to canvas" ) );
QShortcut* zoomShortCut2 = new QShortcut( QKeySequence( tr( "Ctrl+=" ) ), this );
connect( zoomShortCut2, &QShortcut::activated, mMapCanvas, &QgsMapCanvas::zoomIn );
zoomShortCut2->setObjectName( QStringLiteral( "ZoomInToCanvas2" ) );
zoomShortCut2->setWhatsThis( QStringLiteral( "Zoom in to canvas (secondary)" ) );
zoomShortCut2->setWhatsThis( tr( "Zoom in to canvas (secondary)" ) );
QShortcut* zoomOutShortCut = new QShortcut( QKeySequence( tr( "Ctrl+-" ) ), this );
connect( zoomOutShortCut, &QShortcut::activated, mMapCanvas, &QgsMapCanvas::zoomOut );
zoomOutShortCut->setObjectName( QStringLiteral( "ZoomOutOfCanvas" ) );
zoomOutShortCut->setWhatsThis( QStringLiteral( "Zoom out of canvas" ) );
zoomOutShortCut->setWhatsThis( tr( "Zoom out of canvas" ) );

//also make ctrl+alt+= a shortcut to switch to zoom in map tool
QShortcut* zoomInToolShortCut = new QShortcut( QKeySequence( tr( "Ctrl+Alt+=" ) ), this );
connect( zoomInToolShortCut, SIGNAL( activated() ), this, SLOT( zoomIn() ) );
zoomInToolShortCut->setObjectName( QStringLiteral( "ZoomIn2" ) );
zoomInToolShortCut->setWhatsThis( QStringLiteral( "Zoom in (secondary)" ) );
zoomInToolShortCut->setWhatsThis( tr( "Zoom in (secondary)" ) );

QShortcut* toggleSnapping = new QShortcut( QKeySequence( tr( "S" ) ), this );
toggleSnapping->setObjectName( "toggleSnapping" );
toggleSnapping->setWhatsThis( tr( "Toggle snapping" ) );
connect( toggleSnapping, &QShortcut::activated, mSnappingUtils, &QgsSnappingUtils::toggleEnabled );

// Show a nice tip of the day
if ( settings.value( QStringLiteral( "/qgis/showTips%1" ).arg( Qgis::QGIS_VERSION_INT / 100 ), true ).toBool() )
Expand Down
10 changes: 5 additions & 5 deletions src/core/qgsproject.cpp
Expand Up @@ -459,7 +459,7 @@ void QgsProject::clear()
mRelationManager->clear();
mAnnotationManager->clear();
mSnappingConfig.reset();
emit snappingConfigChanged();
emit snappingConfigChanged( mSnappingConfig );

mMapThemeCollection.reset( new QgsMapThemeCollection( this ) );
emit mapThemeCollectionChanged();
Expand Down Expand Up @@ -610,7 +610,7 @@ void QgsProject::setSnappingConfig( const QgsSnappingConfig& snappingConfig )

mSnappingConfig = snappingConfig;
setDirty();
emit snappingConfigChanged();
emit snappingConfigChanged( mSnappingConfig );
}

bool QgsProject::_getMapLayers( const QDomDocument& doc, QList<QDomNode>& brokenNodes )
Expand Down Expand Up @@ -897,7 +897,7 @@ bool QgsProject::read()
}

mSnappingConfig.readProject( *doc );
emit snappingConfigChanged();
emit snappingConfigChanged( mSnappingConfig );

//add variables defined in project file
QStringList variableNames = readListEntry( QStringLiteral( "Variables" ), QStringLiteral( "/variableNames" ) );
Expand Down Expand Up @@ -1081,13 +1081,13 @@ void QgsProject::onMapLayersAdded( const QList<QgsMapLayer*>& layers )
}

if ( mSnappingConfig.addLayers( layers ) )
emit snappingConfigChanged();
emit snappingConfigChanged( mSnappingConfig );
}

void QgsProject::onMapLayersRemoved( const QList<QgsMapLayer*>& layers )
{
if ( mSnappingConfig.removeLayers( layers ) )
emit snappingConfigChanged();
emit snappingConfigChanged( mSnappingConfig );
}

void QgsProject::cleanTransactionGroups( bool force )
Expand Down
16 changes: 8 additions & 8 deletions src/core/qgsproject.h
Expand Up @@ -468,13 +468,6 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
QgsSnappingConfig snappingConfig() const;

/**
* The snapping configuration for this project.
*
* @note Added in QGIS 3.0
*/
void setSnappingConfig( const QgsSnappingConfig& snappingConfig );

/**
* A list of layers with which intersections should be avoided.
*
Expand Down Expand Up @@ -749,7 +742,7 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
void homePathChanged();

//! emitted whenever the configuration for snapping has changed
void snappingConfigChanged();
void snappingConfigChanged( const QgsSnappingConfig& config );

/** Emitted whenever the expression variables stored in the project have been changed.
* @note added in QGIS 3.0
Expand Down Expand Up @@ -894,6 +887,13 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera

public slots:

/**
* The snapping configuration for this project.
*
* @note Added in QGIS 3.0
*/
void setSnappingConfig( const QgsSnappingConfig& snappingConfig );

/**
* Flag the project as dirty (modified). If this flag is set, the user will
* be asked to save changes to the project before closing the current project.
Expand Down
9 changes: 8 additions & 1 deletion src/core/qgssnappingutils.cpp
Expand Up @@ -418,7 +418,14 @@ void QgsSnappingUtils::setConfig( const QgsSnappingConfig& config )
onIndividualLayerSettingsChanged( config.individualLayerSettings() );

mSnappingConfig = config;
emit configChanged();

emit configChanged( mSnappingConfig );
}

void QgsSnappingUtils::toggleEnabled()
{
mSnappingConfig.setEnabled( !mSnappingConfig.enabled() );
emit configChanged( mSnappingConfig );
}

QgsPointLocator::Match QgsSnappingUtils::snapToCurrentLayer( QPoint point, int type, QgsPointLocator::MatchFilter* filter )
Expand Down
12 changes: 10 additions & 2 deletions src/core/qgssnappingutils.h
Expand Up @@ -75,7 +75,6 @@ class CORE_EXPORT QgsSnappingUtils : public QObject
//! The current layer used if mode is SnapCurrentLayer
QgsVectorLayer* currentLayer() const { return mCurrentLayer; }


// configuration

//! modes for "snap to background"
Expand Down Expand Up @@ -162,17 +161,26 @@ class CORE_EXPORT QgsSnappingUtils : public QObject
*/
QgsSnappingConfig config() const;

public slots:

/**
* The snapping configuration controls the behavior of this object
*/
void setConfig( const QgsSnappingConfig& snappingConfig );

/**
* Toggles the state of snapping
*
* @note Added in QGIS 3.0
*/
void toggleEnabled();

signals:

/**
* Emitted when the snapping settings object changes.
*/
void configChanged();
void configChanged( const QgsSnappingConfig& snappingConfig );

protected:
//! Called when starting to index - can be overridden and e.g. progress dialog can be provided
Expand Down

0 comments on commit 5176ecf

Please sign in to comment.