Skip to content

Commit

Permalink
[ui] When an attribute table is docked to the main window, disable th…
Browse files Browse the repository at this point in the history
…e DEL keyboard shorcut (fixes #56262)
  • Loading branch information
nirvn authored and nyalldawson committed Feb 21, 2024
1 parent 93a9a1b commit 0506599
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
52 changes: 36 additions & 16 deletions src/app/qgsattributetabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "qgstransactiongroup.h"
#include "qgsdockablewidgethelper.h"
#include "qgsactionmenu.h"
#include "qgsdockwidget.h"

QgsExpressionContext QgsAttributeTableDialog::createExpressionContext() const
{
Expand Down Expand Up @@ -283,6 +284,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
connect( this, &QgsAttributeTableDialog::saveEdits, this, [ = ] { QgisApp::instance()->saveEdits(); } );

const bool isDocked = initiallyDocked ? *initiallyDocked : settings.value( QStringLiteral( "qgis/dockAttributeTable" ), false ).toBool();
toggleShortcuts( !isDocked );
mDockableWidgetHelper = new QgsDockableWidgetHelper( isDocked, windowTitle(), this, QgisApp::instance(),
Qt::BottomDockWidgetArea, QStringList(), !initiallyDocked, QStringLiteral( "Windows/BetterAttributeTable/geometry" ) );
connect( mDockableWidgetHelper, &QgsDockableWidgetHelper::closed, this, [ = ]()
Expand All @@ -293,24 +295,11 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
{
if ( docked )
{
// To prevent "QAction::event: Ambiguous shortcut overload"
QgsDebugMsgLevel( QStringLiteral( "Remove shortcuts from attribute table already defined in main window" ), 2 );
mActionZoomMapToSelectedRows->setShortcut( QKeySequence() );
mActionRemoveSelection->setShortcut( QKeySequence() );
// duplicated on Main Window, with different semantics
mActionPanMapToSelectedRows->setShortcut( QKeySequence() );
mActionSearchForm->setShortcut( QKeySequence() );
toggleShortcuts( mDockableWidgetHelper->dockWidget()->isFloating() );
}
else
{
// restore attribute table shortcuts in window mode
QgsDebugMsgLevel( QStringLiteral( "Restore attribute table dialog shortcuts in window mode" ), 2 );
// duplicated on Main Window
mActionZoomMapToSelectedRows->setShortcut( QStringLiteral( "Ctrl+J" ) );
mActionRemoveSelection->setShortcut( QStringLiteral( "Ctrl+Shift+A" ) );
// duplicated on Main Window, with different semantics
mActionPanMapToSelectedRows->setShortcut( QStringLiteral( "Ctrl+P" ) );
mActionSearchForm->setShortcut( QStringLiteral( "Ctrl+F" ) );
toggleShortcuts( true );
}
} );

Expand Down Expand Up @@ -489,7 +478,11 @@ void QgsAttributeTableDialog::keyPressEvent( QKeyEvent *event )

if ( ( event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete ) && mActionDeleteSelected->isEnabled() )
{
QgisApp::instance()->deleteSelected( mLayer, this );
// When docked, let the main window handle the key events
if ( !mDockableWidgetHelper->dockWidget() || mDockableWidgetHelper->dockWidget()->isFloating() )
{
QgisApp::instance()->deleteSelected( mLayer, this );
}
}
}

Expand Down Expand Up @@ -1109,3 +1102,30 @@ void QgsAttributeTableDialog::updateLayerModifiedActions()
}
mActionSaveEdits->setEnabled( saveEnabled );
}

void QgsAttributeTableDialog::toggleShortcuts( bool enable )
{
if ( !enable )
{
// To prevent "QAction::event: Ambiguous shortcut overload"
QgsDebugMsgLevel( QStringLiteral( "Remove shortcuts from attribute table already defined in main window" ), 2 );
mActionZoomMapToSelectedRows->setShortcut( QKeySequence() );
mActionRemoveSelection->setShortcut( QKeySequence() );
mActionDeleteSelected->setShortcut( QKeySequence() );
// duplicated on Main Window, with different semantics
mActionPanMapToSelectedRows->setShortcut( QKeySequence() );
mActionSearchForm->setShortcut( QKeySequence() );
}
else
{
// restore attribute table shortcuts in window mode
QgsDebugMsgLevel( QStringLiteral( "Restore attribute table dialog shortcuts in window mode" ), 2 );
// duplicated on Main Window
mActionZoomMapToSelectedRows->setShortcut( QStringLiteral( "Ctrl+J" ) );
mActionRemoveSelection->setShortcut( QStringLiteral( "Ctrl+Shift+A" ) );
mActionDeleteSelected->setShortcut( QStringLiteral( "Del" ) );
// duplicated on Main Window, with different semantics
mActionPanMapToSelectedRows->setShortcut( QStringLiteral( "Ctrl+P" ) );
mActionSearchForm->setShortcut( QStringLiteral( "Ctrl+F" ) );
}
}
1 change: 1 addition & 0 deletions src/app/qgsattributetabledialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
QPointer< QgsVectorLayer > mLayer = nullptr;
void updateMultiEditButtonState();
void deleteFeature( QgsFeatureId fid );
void toggleShortcuts( bool enable );

QList< QPointer< QgsVectorLayer> > mReferencingLayers;

Expand Down

0 comments on commit 0506599

Please sign in to comment.