Skip to content

Commit

Permalink
register shortcuts globally
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed May 22, 2019
1 parent 1e695c4 commit 23b1580
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
14 changes: 14 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -1410,6 +1410,20 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
QgsGui::shortcutsManager()->registerAllChildren( this );
QgsGui::shortcutsManager()->registerAllChildren( mSnappingWidget );

// register additional action
auto registerShortcuts = [ = ]( const QString & sequence, const QString & objectName, const QString & whatsThis )
{
QShortcut *sc = new QShortcut( QKeySequence( sequence ), this );
sc->setContext( Qt::ApplicationShortcut );
sc->setObjectName( objectName );
sc->setWhatsThis( whatsThis );
QgsGui::shortcutsManager()->registerShortcut( sc, sequence );
};
registerShortcuts( QStringLiteral( "Ctrl+Alt+{" ), QStringLiteral( "mAttributeTableFirstEditedFeature" ), tr( "Edit first feature in attribute table" ) );
registerShortcuts( QStringLiteral( "Ctrl+Alt+[" ), QStringLiteral( "mAttributeTablePreviousEditedFeature" ), tr( "Edit previous feature in attribute table" ) );
registerShortcuts( QStringLiteral( "Ctrl+Alt+]" ), QStringLiteral( "mAttributeTableNextEditedFeature" ), tr( "Edit next feature in attribute table" ) );
registerShortcuts( QStringLiteral( "Ctrl+Alt+}" ), QStringLiteral( "mAttributeTableLastEditedFeature" ), tr( "Edit last feature in attribute table" ) );

QgsProviderRegistry::instance()->registerGuis( this );

setupLayoutManagerConnections();
Expand Down
31 changes: 9 additions & 22 deletions src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -41,6 +41,7 @@
#include "qgsscrollarea.h"
#include "qgsgui.h"
#include "qgsexpressioncontextutils.h"
#include "qgsshortcutsmanager.h"


QgsDualView::QgsDualView( QWidget *parent )
Expand Down Expand Up @@ -69,30 +70,16 @@ QgsDualView::QgsDualView( QWidget *parent )
connect( mFirstFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editFirstFeature );
connect( mLastFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editLastFeature );

auto createShortcuts = [ = ]( const QString & sequence, QgsFeatureListView::PositionInList change )
auto createShortcuts = [ = ]( const QString & objectName, void ( QgsFeatureListView::* slot )() )
{
QShortcut *sc = new QShortcut( QKeySequence( sequence ), this );
sc->setContext( Qt::ApplicationShortcut );
switch ( change )
{
case QgsFeatureListView::First:
connect( sc, &QShortcut::activated, mFeatureListView, &QgsFeatureListView::editFirstFeature );
break;
case QgsFeatureListView::Previous:
connect( sc, &QShortcut::activated, mFeatureListView, &QgsFeatureListView::editPreviousFeature );
break;
case QgsFeatureListView::Next:
connect( sc, &QShortcut::activated, mFeatureListView, &QgsFeatureListView::editNextFeature );
break;
case QgsFeatureListView::Last:
connect( sc, &QShortcut::activated, mFeatureListView, &QgsFeatureListView::editLastFeature );
break;
}
QShortcut *sc = QgsGui::shortcutsManager()->shortcutByName( objectName );
Q_ASSERT( sc ); // the shortcut must have been registered in the shortcuts manager
connect( sc, &QShortcut::activated, mFeatureListView, slot );
};
createShortcuts( QStringLiteral( "Ctrl+Alt+{" ), QgsFeatureListView::First );
createShortcuts( QStringLiteral( "Ctrl+Alt+[" ), QgsFeatureListView::Previous );
createShortcuts( QStringLiteral( "Ctrl+Alt+]" ), QgsFeatureListView::Next );
createShortcuts( QStringLiteral( "Ctrl+Alt+}" ), QgsFeatureListView::Last );
createShortcuts( QStringLiteral( "mAttributeTableFirstEditedFeature" ), &QgsFeatureListView::editFirstFeature );
createShortcuts( QStringLiteral( "mAttributeTablePreviousEditedFeature" ), &QgsFeatureListView::editPreviousFeature );
createShortcuts( QStringLiteral( "mAttributeTableNextEditedFeature" ), &QgsFeatureListView::editNextFeature );
createShortcuts( QStringLiteral( "mAttributeTableLastEditedFeature" ), &QgsFeatureListView::editLastFeature );

QButtonGroup *buttonGroup = new QButtonGroup( this );
buttonGroup->setExclusive( false );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsshortcutsmanager.cpp
Expand Up @@ -102,7 +102,7 @@ bool QgsShortcutsManager::registerAction( QAction *action, const QString &defaul

action->setShortcut( sequence );
action->setToolTip( "<b>" + action->toolTip() + "</b>" );
this->updateActionToolTip( action, sequence );
updateActionToolTip( action, sequence );

return true;
}
Expand Down

0 comments on commit 23b1580

Please sign in to comment.