Skip to content
Permalink
Browse files

[needs-docs] keyboard shortcut to toggle snapping (S)

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 5176ecf597a510cb5f32973fa3723532cbbc52fe
@@ -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
@@ -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
@@ -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
@@ -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();

@@ -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() )
@@ -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();
@@ -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 )
@@ -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" ) );
@@ -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 )
@@ -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.
*
@@ -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
@@ -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.
@@ -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 )
@@ -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"
@@ -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

0 comments on commit 5176ecf

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