Skip to content

Commit

Permalink
Merge pull request #49464 from elpaso/bugfix-gh47387
Browse files Browse the repository at this point in the history
Fix relation editor ESC and referenced save
  • Loading branch information
elpaso committed Jul 28, 2022
2 parents 2e622be + c12712e commit f5487ec
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
10 changes: 10 additions & 0 deletions python/gui/auto_generated/qgsmaptooldigitizefeature.sip.in
Expand Up @@ -52,6 +52,9 @@ Change the layer edited by the map tool
virtual void deactivate();


virtual void keyPressEvent( QKeyEvent *e );


signals:

void digitizingCompleted( const QgsFeature &feature );
Expand All @@ -65,6 +68,13 @@ Emitted whenever the digitizing has been successfully completed
%Docstring
Emitted whenever the digitizing has been ended without digitizing
any feature
%End

void digitizingCanceled();
%Docstring
Emitted when the digitizing process was interrupted by the user.

.. versionadded:: 3.28
%End

protected:
Expand Down
9 changes: 9 additions & 0 deletions src/gui/qgsmaptooldigitizefeature.cpp
Expand Up @@ -139,6 +139,15 @@ void QgsMapToolDigitizeFeature::deactivate()
emit digitizingFinished();
}

void QgsMapToolDigitizeFeature::keyPressEvent( QKeyEvent *e )
{
if ( e->key() == Qt::Key_Escape )
{
emit digitizingCanceled();
}
QgsMapToolCaptureLayerGeometry::keyPressEvent( e );
}

bool QgsMapToolDigitizeFeature::checkGeometryType() const
{
return mCheckGeometryType;
Expand Down
10 changes: 10 additions & 0 deletions src/gui/qgsmaptooldigitizefeature.h
Expand Up @@ -56,6 +56,9 @@ class GUI_EXPORT QgsMapToolDigitizeFeature : public QgsMapToolCaptureLayerGeomet
void activate() override;
void deactivate() override;

// Overridden to emit digitizingCanceled when ESC is pressed
void keyPressEvent( QKeyEvent *e ) override;

signals:

/**
Expand All @@ -70,6 +73,12 @@ class GUI_EXPORT QgsMapToolDigitizeFeature : public QgsMapToolCaptureLayerGeomet
*/
void digitizingFinished();

/**
* Emitted when the digitizing process was interrupted by the user.
* \since QGIS 3.28
*/
void digitizingCanceled();

protected:

/**
Expand Down Expand Up @@ -118,6 +127,7 @@ class GUI_EXPORT QgsMapToolDigitizeFeature : public QgsMapToolCaptureLayerGeomet
bool mCheckGeometryType;

friend class TestQgsRelationReferenceWidget;

};

#endif // QGSMAPTOOLDIGITIZEFEATURE_H
25 changes: 13 additions & 12 deletions src/gui/qgsrelationeditorwidget.cpp
Expand Up @@ -437,7 +437,8 @@ void QgsRelationEditorWidget::addFeatureGeometry()
setMapTool( mMapToolDigitize );

connect( mMapToolDigitize, &QgsMapToolDigitizeFeature::digitizingCompleted, this, &QgsRelationEditorWidget::onDigitizingCompleted );
connect( mEditorContext.mapCanvas(), &QgsMapCanvas::keyPressed, this, &QgsRelationEditorWidget::onKeyPressed );

connect( mMapToolDigitize, &QgsMapToolDigitizeFeature::digitizingCanceled, this, &QgsRelationEditorWidget::onDigitizingCanceled );

if ( auto *lMainMessageBar = mEditorContext.mainMessageBar() )
{
Expand All @@ -454,8 +455,7 @@ void QgsRelationEditorWidget::addFeatureGeometry()
void QgsRelationEditorWidget::onDigitizingCompleted( const QgsFeature &feature )
{
QgsAbstractRelationEditorWidget::addFeature( feature.geometry() );

unsetMapTool();
digitizingFinished();
}

void QgsRelationEditorWidget::multiEditItemSelectionChanged()
Expand Down Expand Up @@ -590,7 +590,6 @@ void QgsRelationEditorWidget::unsetMapTool()
// this will call mapToolDeactivated
mapCanvas->unsetMapTool( mMapToolDigitize );

disconnect( mapCanvas, &QgsMapCanvas::keyPressed, this, &QgsRelationEditorWidget::onKeyPressed );
disconnect( mMapToolDigitize, &QgsMapToolDigitizeFeature::digitizingCompleted, this, &QgsRelationEditorWidget::onDigitizingCompleted );
}

Expand Down Expand Up @@ -779,15 +778,17 @@ QTreeWidgetItem *QgsRelationEditorWidget::createMultiEditTreeWidgetItem( const Q
return treeWidgetItem;
}

void QgsRelationEditorWidget::onKeyPressed( QKeyEvent *e )
void QgsRelationEditorWidget::onDigitizingCanceled( )
{
if ( e->key() == Qt::Key_Escape )
{
window()->setVisible( true );
window()->raise();
window()->activateWindow();
unsetMapTool();
}
digitizingFinished();
}

void QgsRelationEditorWidget::digitizingFinished( )
{
window()->setVisible( true );
window()->raise();
window()->activateWindow();
unsetMapTool();
}

void QgsRelationEditorWidget::mapToolDeactivated()
Expand Down
5 changes: 3 additions & 2 deletions src/gui/qgsrelationeditorwidget.h
Expand Up @@ -207,13 +207,14 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsAbstractRelationEditorWidge
void toggleEditing( bool state );
void showContextMenu( QgsActionMenu *menu, QgsFeatureId fid );
void mapToolDeactivated();
void onKeyPressed( QKeyEvent *e );
void onDigitizingCompleted( const QgsFeature &feature );

void onDigitizingCanceled( );
void multiEditItemSelectionChanged();

private:

void digitizingFinished( );

enum class MultiEditFeatureType : int
{
Parent,
Expand Down

0 comments on commit f5487ec

Please sign in to comment.