Skip to content

Commit

Permalink
Merge pull request #34887 from lbartoletti/backport-34797-to-release-…
Browse files Browse the repository at this point in the history
…3_12

[Backport 3.12] Backport 34797 to release 3 12
  • Loading branch information
m-kuhn committed Mar 10, 2020
2 parents 117da6e + 32f19a2 commit 8024089
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 50 deletions.
2 changes: 0 additions & 2 deletions python/gui/auto_generated/qgsmaptooldigitizefeature.sip.in
Expand Up @@ -32,8 +32,6 @@ QgsMapToolDigitizeFeature is a map tool to digitize a feature geometry
:param mode: type of geometry to capture (point/line/polygon), QgsMapToolCapture.CaptureNone to autodetect geometry
%End

virtual void keyPressEvent( QKeyEvent *e );

virtual void cadCanvasReleaseEvent( QgsMapMouseEvent *e );


Expand Down
41 changes: 1 addition & 40 deletions src/gui/qgsmaptooldigitizefeature.cpp
Expand Up @@ -92,45 +92,6 @@ void QgsMapToolDigitizeFeature::setCheckGeometryType( bool checkGeometryType )
mCheckGeometryType = checkGeometryType;
}

void QgsMapToolDigitizeFeature::keyPressEvent( QKeyEvent *e )
{
if ( e && e->key() == Qt::Key_C )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayer );
if ( !vlayer )
//if no given layer take the current from canvas
vlayer = currentVectorLayer();

if ( !vlayer )
{
notifyNotVectorLayer();
return;
}

QgsVectorDataProvider *provider = vlayer->dataProvider();

if ( !( provider->capabilities() & QgsVectorDataProvider::AddFeatures ) )
{
emit messageEmitted( tr( "The data provider for this layer does not support the addition of features." ), Qgis::Warning );
return;
}

if ( !vlayer->isEditable() )
{
notifyNotEditableLayer();
return;
}

if ( ( mode() == CaptureLine && vlayer->geometryType() == QgsWkbTypes::LineGeometry && mCheckGeometryType ) || ( mode() == CapturePolygon && vlayer->geometryType() == QgsWkbTypes::PolygonGeometry && mCheckGeometryType ) )
{
closePolygon();
QgsMapMouseEvent e2( mCanvas, QEvent::MouseButtonRelease, QPoint( ), Qt::RightButton );
cadCanvasReleaseEvent( &e2 );
}
}
else
QgsMapToolCapture::keyPressEvent( e );
}
void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayer );
Expand Down Expand Up @@ -313,7 +274,7 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
return;
}

if ( mode() == CapturePolygon )
if ( mode() == CapturePolygon || e->modifiers() == Qt::ShiftModifier )
{
closePolygon();
}
Expand Down
1 change: 0 additions & 1 deletion src/gui/qgsmaptooldigitizefeature.h
Expand Up @@ -42,7 +42,6 @@ class GUI_EXPORT QgsMapToolDigitizeFeature : public QgsMapToolCapture
*/
QgsMapToolDigitizeFeature( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode = QgsMapToolCapture::CaptureNone );

void keyPressEvent( QKeyEvent *e ) override;
void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/src/app/testqgsmaptooladdfeatureline.cpp
Expand Up @@ -499,7 +499,7 @@ void TestQgsMapToolAddFeatureLine::testCloseLine()
utils.mouseClick( 1, 1, Qt::LeftButton );
utils.mouseClick( 5, 1, Qt::LeftButton );
utils.mouseClick( 5, 5, Qt::LeftButton );
utils.keyClick( Qt::Key_C );
utils.mouseClick( 5, 5, Qt::RightButton, Qt::ShiftModifier );
QgsFeatureId newFid = utils.newFeatureId( oldFids );

QString wkt = "LineString (1 1, 5 1, 5 5, 1 1)";
Expand Down
12 changes: 6 additions & 6 deletions tests/src/app/testqgsmaptoolutils.h
Expand Up @@ -97,12 +97,12 @@ class TestQgsMapToolAdvancedDigitizingUtils
mouseRelease( mapX, mapY, button, stateKey, snap );
}

void keyClick( int key )
void keyClick( int key, Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers() )
{
QKeyEvent e1( QEvent::KeyPress, key, Qt::KeyboardModifiers() );
QKeyEvent e1( QEvent::KeyPress, key, stateKey );
mMapTool->keyPressEvent( &e1 );

QKeyEvent e2( QEvent::KeyRelease, key, Qt::KeyboardModifiers() );
QKeyEvent e2( QEvent::KeyRelease, key, stateKey );
mMapTool->keyReleaseEvent( &e2 );
}

Expand Down Expand Up @@ -183,12 +183,12 @@ class TestQgsMapToolUtils
mouseRelease( mapX, mapY, button, stateKey, snap );
}

void keyClick( int key )
void keyClick( int key, Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers() )
{
QKeyEvent e1( QEvent::KeyPress, key, Qt::KeyboardModifiers() );
QKeyEvent e1( QEvent::KeyPress, key, stateKey );
mMapTool->keyPressEvent( &e1 );

QKeyEvent e2( QEvent::KeyRelease, key, Qt::KeyboardModifiers() );
QKeyEvent e2( QEvent::KeyRelease, key, stateKey );
mMapTool->keyReleaseEvent( &e2 );
}

Expand Down

0 comments on commit 8024089

Please sign in to comment.