Skip to content

Commit

Permalink
Fix relation editor ESC and referenced save
Browse files Browse the repository at this point in the history
Fixes #47387 and another bug (unreported or #40549 ?)
where digitizing the referencing feature of a newly added
referenced feature (in transaction mode) failed due to the
form being closed and the reference feature not saved.

The new behavior is that the form is brought back after the
digitizing of the referencing feature has been completed or
user-interrupted, this way the referenced layer form can be
saved or dismissed as expected.

Funded by: ARPA Piemonte
  • Loading branch information
elpaso committed Jul 25, 2022
1 parent cf0e24d commit 5c7bf29
Show file tree
Hide file tree
Showing 5 changed files with 44 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
8 changes: 8 additions & 0 deletions src/gui/qgsmaptooldigitizefeature.cpp
Expand Up @@ -139,6 +139,14 @@ void QgsMapToolDigitizeFeature::deactivate()
emit digitizingFinished();
}

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

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 5c7bf29

Please sign in to comment.