Skip to content

Commit 7831f3e

Browse files
committed
Continue loop of locked features after mouse move
A small UX improvement: after right click in a location with feature A and B, we would do a loop A - B - nothing - A - B - nothing ... But if after first click to get A locked user would move the mouse a bit, the loop would get broken and would end up with A - nothing - B - nothing - A - B - nothing The fix is to identify where we are in the cycle and set the index correctly after mouse move.
1 parent 6fd21c2 commit 7831f3e

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/app/vertextool/qgsvertextool.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ void QgsVertexTool::tryToSelectFeature( QgsMapMouseEvent *e )
931931

932932
mSelectedFeatureAlternatives.reset( new SelectedFeatureAlternatives );
933933
mSelectedFeatureAlternatives->screenPoint = e->pos();
934-
mSelectedFeatureAlternatives->index = 0;
934+
mSelectedFeatureAlternatives->index = -1;
935935
if ( m.isValid() )
936936
{
937937
// ideally the feature that would get normally highlighted should be also the first choice
@@ -942,17 +942,23 @@ void QgsVertexTool::tryToSelectFeature( QgsMapMouseEvent *e )
942942
alternatives.remove( firstChoice );
943943
}
944944
mSelectedFeatureAlternatives->alternatives.append( alternatives.toList() );
945+
946+
if ( mSelectedFeature )
947+
{
948+
// in case there is already a feature locked, continue in the loop from it
949+
QPair<QgsVectorLayer *, QgsFeatureId> currentSelection( mSelectedFeature->layer(), mSelectedFeature->featureId() );
950+
int currentIndex = mSelectedFeatureAlternatives->alternatives.indexOf( currentSelection );
951+
if ( currentIndex != -1 )
952+
mSelectedFeatureAlternatives->index = currentIndex;
953+
}
945954
}
946955
}
956+
957+
// move to the next alternative
958+
if ( mSelectedFeatureAlternatives->index < mSelectedFeatureAlternatives->alternatives.count() - 1 )
959+
++mSelectedFeatureAlternatives->index;
947960
else
948-
{
949-
// we have had right-click before on this mouse location - so let's just cycle in our alternatives
950-
// move to the next alternative
951-
if ( mSelectedFeatureAlternatives->index < mSelectedFeatureAlternatives->alternatives.count() - 1 )
952-
++mSelectedFeatureAlternatives->index;
953-
else
954-
mSelectedFeatureAlternatives->index = -1;
955-
}
961+
mSelectedFeatureAlternatives->index = -1;
956962

957963
if ( mSelectedFeatureAlternatives && mSelectedFeatureAlternatives->index != -1 )
958964
{

0 commit comments

Comments
 (0)