Skip to content

Commit

Permalink
Merge pull request #10021 from 3nids/itembrowser_shortcut
Browse files Browse the repository at this point in the history
add shortcuts to browse feature list
  • Loading branch information
3nids committed May 22, 2019
2 parents d3ce0a0 + 23b1580 commit b3555ab
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
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
14 changes: 14 additions & 0 deletions src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -21,6 +21,7 @@
#include <QGroupBox>
#include <QInputDialog>
#include <QTimer>
#include <QShortcut>

#include "qgsapplication.h"
#include "qgsactionmanager.h"
Expand All @@ -40,6 +41,7 @@
#include "qgsscrollarea.h"
#include "qgsgui.h"
#include "qgsexpressioncontextutils.h"
#include "qgsshortcutsmanager.h"


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

// browsing toolbar
connect( mNextFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editNextFeature );
connect( mPreviousFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editPreviousFeature );
connect( mFirstFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editFirstFeature );
connect( mLastFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editLastFeature );

auto createShortcuts = [ = ]( const QString & objectName, void ( QgsFeatureListView::* slot )() )
{
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( "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 );
buttonGroup->addButton( mFlashButton, FlashFeature );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/attributetable/qgsfeaturelistview.h
Expand Up @@ -246,6 +246,8 @@ class GUI_EXPORT QgsFeatureListView : public QListView
QItemSelectionModel::SelectionFlags mCtrlDragSelectionFlag;

QTimer mUpdateEditSelectionTimer;

friend class QgsDualView;
};

#endif
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 b3555ab

Please sign in to comment.