Skip to content

Commit

Permalink
Continue loop of locked features after mouse move
Browse files Browse the repository at this point in the history
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 7831f3e
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -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
Expand All @@ -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 )
{
Expand Down

0 comments on commit 7831f3e

Please sign in to comment.