Skip to content

Commit d2e3755

Browse files
committed
Fix Ctrl shortcut handling for advanced digitizing dock
1 parent 73fd83f commit d2e3755

File tree

1 file changed

+47
-28
lines changed

1 file changed

+47
-28
lines changed

src/gui/qgsadvanceddigitizingdockwidget.cpp

+47-28
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,7 @@ void QgsAdvancedDigitizingDockWidget::setPoints( const QList<QgsPointXY> &points
782782
bool QgsAdvancedDigitizingDockWidget::eventFilter( QObject *obj, QEvent *event )
783783
{
784784
// event for line edits
785-
Q_UNUSED( obj );
786-
if ( event->type() != QEvent::KeyPress )
785+
if ( !cadEnabled() || ( event->type() != QEvent::ShortcutOverride && event->type() != QEvent::KeyPress ) )
787786
{
788787
return QgsDockWidget::eventFilter( obj, event );
789788
}
@@ -797,115 +796,135 @@ bool QgsAdvancedDigitizingDockWidget::eventFilter( QObject *obj, QEvent *event )
797796

798797
bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
799798
{
799+
QEvent::Type type = e->type();
800800
switch ( e->key() )
801801
{
802802
case Qt::Key_X:
803803
{
804-
if ( e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ControlModifier )
804+
if ( type == QEvent::ShortcutOverride && ( e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ControlModifier ) )
805805
{
806806
mXConstraint->toggleLocked();
807807
emit pointChanged( mCadPointList.value( 0 ) );
808+
e->accept();
808809
}
809-
else if ( e->modifiers() == Qt::ShiftModifier )
810+
else if ( type == QEvent::ShortcutOverride && e->modifiers() == Qt::ShiftModifier )
810811
{
811812
if ( mCapacities.testFlag( RelativeCoordinates ) )
812813
{
813814
mXConstraint->toggleRelative();
814815
emit pointChanged( mCadPointList.value( 0 ) );
816+
e->accept();
815817
}
816818
}
817-
else
819+
else if ( type == QEvent::KeyPress )
818820
{
819821
mXLineEdit->setFocus();
820822
mXLineEdit->selectAll();
823+
e->accept();
821824
}
822825
break;
823826
}
824827
case Qt::Key_Y:
825828
{
826-
if ( e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ControlModifier )
829+
if ( type == QEvent::ShortcutOverride && ( e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ControlModifier ) )
827830
{
828831
mYConstraint->toggleLocked();
829832
emit pointChanged( mCadPointList.value( 0 ) );
833+
e->accept();
830834
}
831-
else if ( e->modifiers() == Qt::ShiftModifier )
835+
else if ( type == QEvent::ShortcutOverride && e->modifiers() == Qt::ShiftModifier )
832836
{
833837
if ( mCapacities.testFlag( RelativeCoordinates ) )
834838
{
835839
mYConstraint->toggleRelative();
836840
emit pointChanged( mCadPointList.value( 0 ) );
841+
e->accept();
837842
}
838843
}
839-
else
844+
else if ( type == QEvent::KeyPress )
840845
{
841846
mYLineEdit->setFocus();
842847
mYLineEdit->selectAll();
848+
e->accept();
843849
}
844850
break;
845851
}
846852
case Qt::Key_A:
847853
{
848-
if ( e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ControlModifier )
854+
if ( type == QEvent::ShortcutOverride && ( e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ControlModifier ) )
849855
{
850856
if ( mCapacities.testFlag( AbsoluteAngle ) )
851857
{
852858
mAngleConstraint->toggleLocked();
853859
emit pointChanged( mCadPointList.value( 0 ) );
860+
e->accept();
854861
}
855862
}
856-
else if ( e->modifiers() == Qt::ShiftModifier )
863+
else if ( type == QEvent::ShortcutOverride && e->modifiers() == Qt::ShiftModifier )
857864
{
858865
if ( mCapacities.testFlag( RelativeAngle ) )
859866
{
860867
mAngleConstraint->toggleRelative();
861868
emit pointChanged( mCadPointList.value( 0 ) );
869+
e->accept();
862870
}
863871
}
864-
else
872+
else if ( type == QEvent::KeyPress )
865873
{
866874
mAngleLineEdit->setFocus();
867875
mAngleLineEdit->selectAll();
876+
e->accept();
868877
}
869878
break;
870879
}
871880
case Qt::Key_D:
872881
{
873-
if ( e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ControlModifier )
882+
if ( type == QEvent::ShortcutOverride && ( e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ControlModifier ) )
874883
{
875884
if ( mCapacities.testFlag( RelativeCoordinates ) )
876885
{
877886
mDistanceConstraint->toggleLocked();
878887
emit pointChanged( mCadPointList.value( 0 ) );
888+
e->accept();
879889
}
880890
}
881-
else
891+
else if ( type == QEvent::KeyPress )
882892
{
883893
mDistanceLineEdit->setFocus();
884894
mDistanceLineEdit->selectAll();
895+
e->accept();
885896
}
886897
break;
887898
}
888899
case Qt::Key_C:
889900
{
890-
setConstructionMode( !mConstructionMode );
901+
if ( type == QEvent::KeyPress )
902+
{
903+
setConstructionMode( !mConstructionMode );
904+
e->accept();
905+
}
891906
break;
892907
}
893908
case Qt::Key_P:
894909
{
895-
bool parallel = mParallelButton->isChecked();
896-
bool perpendicular = mPerpendicularButton->isChecked();
897-
898-
if ( !parallel && !perpendicular )
910+
if ( type == QEvent::KeyPress )
899911
{
900-
lockAdditionalConstraint( Perpendicular );
901-
}
902-
else if ( perpendicular )
903-
{
904-
lockAdditionalConstraint( Parallel );
905-
}
906-
else
907-
{
908-
lockAdditionalConstraint( NoConstraint );
912+
bool parallel = mParallelButton->isChecked();
913+
bool perpendicular = mPerpendicularButton->isChecked();
914+
915+
if ( !parallel && !perpendicular )
916+
{
917+
lockAdditionalConstraint( Perpendicular );
918+
}
919+
else if ( perpendicular )
920+
{
921+
lockAdditionalConstraint( Parallel );
922+
}
923+
else
924+
{
925+
lockAdditionalConstraint( NoConstraint );
926+
}
927+
e->accept();
909928
}
910929
break;
911930
}
@@ -914,7 +933,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
914933
return false; // continues
915934
}
916935
}
917-
return true; // stop the event
936+
return e->isAccepted();
918937
}
919938

920939
void QgsAdvancedDigitizingDockWidget::enable()

0 commit comments

Comments
 (0)