Skip to content

Commit b3555ab

Browse files
authoredMay 22, 2019
Merge pull request #10021 from 3nids/itembrowser_shortcut
add shortcuts to browse feature list
2 parents d3ce0a0 + 23b1580 commit b3555ab

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,20 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
14101410
QgsGui::shortcutsManager()->registerAllChildren( this );
14111411
QgsGui::shortcutsManager()->registerAllChildren( mSnappingWidget );
14121412

1413+
// register additional action
1414+
auto registerShortcuts = [ = ]( const QString & sequence, const QString & objectName, const QString & whatsThis )
1415+
{
1416+
QShortcut *sc = new QShortcut( QKeySequence( sequence ), this );
1417+
sc->setContext( Qt::ApplicationShortcut );
1418+
sc->setObjectName( objectName );
1419+
sc->setWhatsThis( whatsThis );
1420+
QgsGui::shortcutsManager()->registerShortcut( sc, sequence );
1421+
};
1422+
registerShortcuts( QStringLiteral( "Ctrl+Alt+{" ), QStringLiteral( "mAttributeTableFirstEditedFeature" ), tr( "Edit first feature in attribute table" ) );
1423+
registerShortcuts( QStringLiteral( "Ctrl+Alt+[" ), QStringLiteral( "mAttributeTablePreviousEditedFeature" ), tr( "Edit previous feature in attribute table" ) );
1424+
registerShortcuts( QStringLiteral( "Ctrl+Alt+]" ), QStringLiteral( "mAttributeTableNextEditedFeature" ), tr( "Edit next feature in attribute table" ) );
1425+
registerShortcuts( QStringLiteral( "Ctrl+Alt+}" ), QStringLiteral( "mAttributeTableLastEditedFeature" ), tr( "Edit last feature in attribute table" ) );
1426+
14131427
QgsProviderRegistry::instance()->registerGuis( this );
14141428

14151429
setupLayoutManagerConnections();

‎src/gui/attributetable/qgsdualview.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <QGroupBox>
2222
#include <QInputDialog>
2323
#include <QTimer>
24+
#include <QShortcut>
2425

2526
#include "qgsapplication.h"
2627
#include "qgsactionmanager.h"
@@ -40,6 +41,7 @@
4041
#include "qgsscrollarea.h"
4142
#include "qgsgui.h"
4243
#include "qgsexpressioncontextutils.h"
44+
#include "qgsshortcutsmanager.h"
4345

4446

4547
QgsDualView::QgsDualView( QWidget *parent )
@@ -62,11 +64,23 @@ QgsDualView::QgsDualView( QWidget *parent )
6264
connect( mActionExpressionPreview, &QAction::triggered, this, &QgsDualView::previewExpressionBuilder );
6365
connect( mFeatureListView, &QgsFeatureListView::displayExpressionChanged, this, &QgsDualView::previewExpressionChanged );
6466

67+
// browsing toolbar
6568
connect( mNextFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editNextFeature );
6669
connect( mPreviousFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editPreviousFeature );
6770
connect( mFirstFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editFirstFeature );
6871
connect( mLastFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editLastFeature );
6972

73+
auto createShortcuts = [ = ]( const QString & objectName, void ( QgsFeatureListView::* slot )() )
74+
{
75+
QShortcut *sc = QgsGui::shortcutsManager()->shortcutByName( objectName );
76+
Q_ASSERT( sc ); // the shortcut must have been registered in the shortcuts manager
77+
connect( sc, &QShortcut::activated, mFeatureListView, slot );
78+
};
79+
createShortcuts( QStringLiteral( "mAttributeTableFirstEditedFeature" ), &QgsFeatureListView::editFirstFeature );
80+
createShortcuts( QStringLiteral( "mAttributeTablePreviousEditedFeature" ), &QgsFeatureListView::editPreviousFeature );
81+
createShortcuts( QStringLiteral( "mAttributeTableNextEditedFeature" ), &QgsFeatureListView::editNextFeature );
82+
createShortcuts( QStringLiteral( "mAttributeTableLastEditedFeature" ), &QgsFeatureListView::editLastFeature );
83+
7084
QButtonGroup *buttonGroup = new QButtonGroup( this );
7185
buttonGroup->setExclusive( false );
7286
buttonGroup->addButton( mFlashButton, FlashFeature );

‎src/gui/attributetable/qgsfeaturelistview.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ class GUI_EXPORT QgsFeatureListView : public QListView
246246
QItemSelectionModel::SelectionFlags mCtrlDragSelectionFlag;
247247

248248
QTimer mUpdateEditSelectionTimer;
249+
250+
friend class QgsDualView;
249251
};
250252

251253
#endif

‎src/gui/qgsshortcutsmanager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ bool QgsShortcutsManager::registerAction( QAction *action, const QString &defaul
102102

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

107107
return true;
108108
}

0 commit comments

Comments
 (0)
Please sign in to comment.