Skip to content
Permalink
Browse files

Merge pull request #34797 from lbartoletti/fix_key_conflict_for_close…

…_editing_line

Use a different key sequence for close editing line. Fixes #34793
  • Loading branch information
m-kuhn committed Mar 5, 2020
2 parents caf69cf + c9bdd13 commit 923dabd86afa78a890342f9848ec00a87f65dd03
@@ -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 );


@@ -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 );
@@ -313,7 +274,7 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
return;
}

if ( mode() == CapturePolygon )
if ( mode() == CapturePolygon || e->modifiers() == Qt::ShiftModifier )
{
closePolygon();
}
@@ -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;

/**
@@ -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)";
@@ -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 );
}

@@ -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 );
}

0 comments on commit 923dabd

Please sign in to comment.
You can’t perform that action at this time.