Skip to content
Permalink
Browse files

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.
  • Loading branch information
wonder-sk committed Feb 21, 2019
1 parent 6fd21c2 commit 7831f3ef236b644ce2a48c503e43a613b30cc028
Showing with 15 additions and 9 deletions.
  1. +15 −9 src/app/vertextool/qgsvertextool.cpp
@@ -931,7 +931,7 @@ void QgsVertexTool::tryToSelectFeature( QgsMapMouseEvent *e )

mSelectedFeatureAlternatives.reset( new SelectedFeatureAlternatives );
mSelectedFeatureAlternatives->screenPoint = e->pos();
mSelectedFeatureAlternatives->index = 0;
mSelectedFeatureAlternatives->index = -1;
if ( m.isValid() )
{
// ideally the feature that would get normally highlighted should be also the first choice
@@ -942,17 +942,23 @@ void QgsVertexTool::tryToSelectFeature( QgsMapMouseEvent *e )
alternatives.remove( firstChoice );
}
mSelectedFeatureAlternatives->alternatives.append( alternatives.toList() );

if ( mSelectedFeature )
{
// in case there is already a feature locked, continue in the loop from it
QPair<QgsVectorLayer *, QgsFeatureId> currentSelection( mSelectedFeature->layer(), mSelectedFeature->featureId() );
int currentIndex = mSelectedFeatureAlternatives->alternatives.indexOf( currentSelection );
if ( currentIndex != -1 )
mSelectedFeatureAlternatives->index = currentIndex;
}
}
}

// move to the next alternative
if ( mSelectedFeatureAlternatives->index < mSelectedFeatureAlternatives->alternatives.count() - 1 )
++mSelectedFeatureAlternatives->index;
else
{
// we have had right-click before on this mouse location - so let's just cycle in our alternatives
// move to the next alternative
if ( mSelectedFeatureAlternatives->index < mSelectedFeatureAlternatives->alternatives.count() - 1 )
++mSelectedFeatureAlternatives->index;
else
mSelectedFeatureAlternatives->index = -1;
}
mSelectedFeatureAlternatives->index = -1;

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

0 comments on commit 7831f3e

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