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

Pressing the key "S" will toggle snapping. This helps to quickly
enable/disable snapping while digitizing.
This commit is contained in:
Denis Rouzaud 2017-02-27 14:36:15 +01:00 committed by Matthias Kuhn
parent f0489c9fc6
commit 5176ecf597
8 changed files with 52 additions and 24 deletions

View File

@ -539,7 +539,7 @@ class QgsProject : QObject, QgsExpressionContextGenerator
void homePathChanged(); void homePathChanged();
//! emitted whenever the configuration for snapping has changed //! 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. /** Emitted whenever the expression variables stored in the project have been changed.
* @note added in QGIS 3.0 * @note added in QGIS 3.0

View File

@ -89,16 +89,22 @@ class QgsSnappingUtils : QObject
*/ */
QgsSnappingConfig config() const; QgsSnappingConfig config() const;
public slots:
/** /**
* The snapping configuration controls the behavior of this object * The snapping configuration controls the behavior of this object
*/ */
void setConfig( const QgsSnappingConfig& snappingConfig ); void setConfig( const QgsSnappingConfig& snappingConfig );
/**
* Toggles the state of snapping
*/
void toggleEnabled();
signals: signals:
/** /**
* Emitted when the snapping settings object changes. * Emitted when the snapping settings object changes.
*/ */
void configChanged(); void configChanged( const QgsSnappingConfig& snappingConfig );
protected: protected:
//! Called when starting to index - can be overridden and e.g. progress dialog can be provided //! Called when starting to index - can be overridden and e.g. progress dialog can be provided

View File

@ -53,7 +53,7 @@ for file in $*; do
${GP}sed -i -r '/^\s*Q_(OBJECT|ENUMS|PROPERTY).*?$/d' $tempfile ${GP}sed -i -r '/^\s*Q_(OBJECT|ENUMS|PROPERTY).*?$/d' $tempfile
# Remove function definition in header # 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 # Remove nullptr
${GP}sed -i 's/nullptr/0/g' $tempfile ${GP}sed -i 's/nullptr/0/g' $tempfile

View File

@ -772,7 +772,9 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
startProfile( QStringLiteral( "Snapping utils" ) ); startProfile( QStringLiteral( "Snapping utils" ) );
mSnappingUtils = new QgsMapCanvasSnappingUtils( mMapCanvas, this ); mSnappingUtils = new QgsMapCanvasSnappingUtils( mMapCanvas, this );
mMapCanvas->setSnappingUtils( mSnappingUtils ); 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(); endProfile();
@ -1077,21 +1079,26 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
QShortcut* zoomInShortCut = new QShortcut( QKeySequence( tr( "Ctrl++" ) ), this ); QShortcut* zoomInShortCut = new QShortcut( QKeySequence( tr( "Ctrl++" ) ), this );
connect( zoomInShortCut, &QShortcut::activated, mMapCanvas, &QgsMapCanvas::zoomIn ); connect( zoomInShortCut, &QShortcut::activated, mMapCanvas, &QgsMapCanvas::zoomIn );
zoomInShortCut->setObjectName( QStringLiteral( "ZoomInToCanvas" ) ); 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 ); QShortcut* zoomShortCut2 = new QShortcut( QKeySequence( tr( "Ctrl+=" ) ), this );
connect( zoomShortCut2, &QShortcut::activated, mMapCanvas, &QgsMapCanvas::zoomIn ); connect( zoomShortCut2, &QShortcut::activated, mMapCanvas, &QgsMapCanvas::zoomIn );
zoomShortCut2->setObjectName( QStringLiteral( "ZoomInToCanvas2" ) ); 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 ); QShortcut* zoomOutShortCut = new QShortcut( QKeySequence( tr( "Ctrl+-" ) ), this );
connect( zoomOutShortCut, &QShortcut::activated, mMapCanvas, &QgsMapCanvas::zoomOut ); connect( zoomOutShortCut, &QShortcut::activated, mMapCanvas, &QgsMapCanvas::zoomOut );
zoomOutShortCut->setObjectName( QStringLiteral( "ZoomOutOfCanvas" ) ); 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 //also make ctrl+alt+= a shortcut to switch to zoom in map tool
QShortcut* zoomInToolShortCut = new QShortcut( QKeySequence( tr( "Ctrl+Alt+=" ) ), this ); QShortcut* zoomInToolShortCut = new QShortcut( QKeySequence( tr( "Ctrl+Alt+=" ) ), this );
connect( zoomInToolShortCut, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); connect( zoomInToolShortCut, SIGNAL( activated() ), this, SLOT( zoomIn() ) );
zoomInToolShortCut->setObjectName( QStringLiteral( "ZoomIn2" ) ); 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 // Show a nice tip of the day
if ( settings.value( QStringLiteral( "/qgis/showTips%1" ).arg( Qgis::QGIS_VERSION_INT / 100 ), true ).toBool() ) if ( settings.value( QStringLiteral( "/qgis/showTips%1" ).arg( Qgis::QGIS_VERSION_INT / 100 ), true ).toBool() )

View File

@ -459,7 +459,7 @@ void QgsProject::clear()
mRelationManager->clear(); mRelationManager->clear();
mAnnotationManager->clear(); mAnnotationManager->clear();
mSnappingConfig.reset(); mSnappingConfig.reset();
emit snappingConfigChanged(); emit snappingConfigChanged( mSnappingConfig );
mMapThemeCollection.reset( new QgsMapThemeCollection( this ) ); mMapThemeCollection.reset( new QgsMapThemeCollection( this ) );
emit mapThemeCollectionChanged(); emit mapThemeCollectionChanged();
@ -610,7 +610,7 @@ void QgsProject::setSnappingConfig( const QgsSnappingConfig& snappingConfig )
mSnappingConfig = snappingConfig; mSnappingConfig = snappingConfig;
setDirty(); setDirty();
emit snappingConfigChanged(); emit snappingConfigChanged( mSnappingConfig );
} }
bool QgsProject::_getMapLayers( const QDomDocument& doc, QList<QDomNode>& brokenNodes ) bool QgsProject::_getMapLayers( const QDomDocument& doc, QList<QDomNode>& brokenNodes )
@ -897,7 +897,7 @@ bool QgsProject::read()
} }
mSnappingConfig.readProject( *doc ); mSnappingConfig.readProject( *doc );
emit snappingConfigChanged(); emit snappingConfigChanged( mSnappingConfig );
//add variables defined in project file //add variables defined in project file
QStringList variableNames = readListEntry( QStringLiteral( "Variables" ), QStringLiteral( "/variableNames" ) ); QStringList variableNames = readListEntry( QStringLiteral( "Variables" ), QStringLiteral( "/variableNames" ) );
@ -1081,13 +1081,13 @@ void QgsProject::onMapLayersAdded( const QList<QgsMapLayer*>& layers )
} }
if ( mSnappingConfig.addLayers( layers ) ) if ( mSnappingConfig.addLayers( layers ) )
emit snappingConfigChanged(); emit snappingConfigChanged( mSnappingConfig );
} }
void QgsProject::onMapLayersRemoved( const QList<QgsMapLayer*>& layers ) void QgsProject::onMapLayersRemoved( const QList<QgsMapLayer*>& layers )
{ {
if ( mSnappingConfig.removeLayers( layers ) ) if ( mSnappingConfig.removeLayers( layers ) )
emit snappingConfigChanged(); emit snappingConfigChanged( mSnappingConfig );
} }
void QgsProject::cleanTransactionGroups( bool force ) void QgsProject::cleanTransactionGroups( bool force )

View File

@ -468,13 +468,6 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/ */
QgsSnappingConfig snappingConfig() const; 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. * A list of layers with which intersections should be avoided.
* *
@ -749,7 +742,7 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
void homePathChanged(); void homePathChanged();
//! emitted whenever the configuration for snapping has changed //! 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. /** Emitted whenever the expression variables stored in the project have been changed.
* @note added in QGIS 3.0 * @note added in QGIS 3.0
@ -894,6 +887,13 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
public slots: 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 * 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. * be asked to save changes to the project before closing the current project.

View File

@ -418,7 +418,14 @@ void QgsSnappingUtils::setConfig( const QgsSnappingConfig& config )
onIndividualLayerSettingsChanged( config.individualLayerSettings() ); onIndividualLayerSettingsChanged( config.individualLayerSettings() );
mSnappingConfig = config; 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 ) QgsPointLocator::Match QgsSnappingUtils::snapToCurrentLayer( QPoint point, int type, QgsPointLocator::MatchFilter* filter )

View File

@ -75,7 +75,6 @@ class CORE_EXPORT QgsSnappingUtils : public QObject
//! The current layer used if mode is SnapCurrentLayer //! The current layer used if mode is SnapCurrentLayer
QgsVectorLayer* currentLayer() const { return mCurrentLayer; } QgsVectorLayer* currentLayer() const { return mCurrentLayer; }
// configuration // configuration
//! modes for "snap to background" //! modes for "snap to background"
@ -162,17 +161,26 @@ class CORE_EXPORT QgsSnappingUtils : public QObject
*/ */
QgsSnappingConfig config() const; QgsSnappingConfig config() const;
public slots:
/** /**
* The snapping configuration controls the behavior of this object * The snapping configuration controls the behavior of this object
*/ */
void setConfig( const QgsSnappingConfig& snappingConfig ); void setConfig( const QgsSnappingConfig& snappingConfig );
/**
* Toggles the state of snapping
*
* @note Added in QGIS 3.0
*/
void toggleEnabled();
signals: signals:
/** /**
* Emitted when the snapping settings object changes. * Emitted when the snapping settings object changes.
*/ */
void configChanged(); void configChanged( const QgsSnappingConfig& snappingConfig );
protected: protected:
//! Called when starting to index - can be overridden and e.g. progress dialog can be provided //! Called when starting to index - can be overridden and e.g. progress dialog can be provided