Skip to content

Commit

Permalink
followup rename
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Feb 25, 2019
1 parent dbad206 commit 5b7cb3f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
52 changes: 26 additions & 26 deletions src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -217,26 +217,26 @@ class MatchCollectingFilter : public QgsPointLocator::MatchFilter
* If we do not encounter any selected feature within tolerance, we use the best match as usual.
*
* There are two kinds of "selected" features... if we have a "locked" feature in vertex tool,
* we get a non-null QgsSelectedFeature which has feature's layer and feature id. In such case we
* we get a non-null QgsLockedFeature which has feature's layer and feature id. In such case we
* only allow matches from that feature. The other kind is if some features within layer are
* in the layer's list of selected features - in that case we accept any match from those features
* (but only if we do not have "locked" feature)
*/
class SelectedMatchFilter : public QgsPointLocator::MatchFilter
{
public:
explicit SelectedMatchFilter( double tol, QgsSelectedFeature *selectedFeature )
explicit SelectedMatchFilter( double tol, QgsLockedFeature *selectedFeature )
: mTolerance( tol )
, mSelectedFeature( selectedFeature ) {}
, mLockedFeature( selectedFeature ) {}

bool acceptMatch( const QgsPointLocator::Match &match ) override
{
if ( match.distance() <= mTolerance && match.layer() )
{
// option 1: we have "locked" feature - we consider just a match from that feature
// option 2: we do not have "locked" feature - we consider matches from any selected feature
if ( ( mSelectedFeature && mSelectedFeature->layer() == match.layer() && mSelectedFeature->featureId() == match.featureId() )
|| ( !mSelectedFeature && match.layer()->selectedFeatureIds().contains( match.featureId() ) ) )
if ( ( mLockedFeature && mLockedFeature->layer() == match.layer() && mLockedFeature->featureId() == match.featureId() )
|| ( !mLockedFeature && match.layer()->selectedFeatureIds().contains( match.featureId() ) ) )
{
if ( !mBestSelectedMatch.isValid() || match.distance() < mBestSelectedMatch.distance() )
mBestSelectedMatch = match;
Expand All @@ -250,7 +250,7 @@ class SelectedMatchFilter : public QgsPointLocator::MatchFilter

private:
double mTolerance;
QgsSelectedFeature *mSelectedFeature; // not null in case of selected (locked) feature
QgsLockedFeature *mLockedFeature; // not null in case of selected (locked) feature
QgsPointLocator::Match mBestSelectedMatch;
};

Expand Down Expand Up @@ -609,11 +609,11 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

void QgsVertexTool::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
if ( mSelectedFeatureAlternatives && ( e->pos() - mSelectedFeatureAlternatives->screenPoint ).manhattanLength() >= QApplication::startDragDistance() )
if ( mLockedFeatureAlternatives && ( e->pos() - mLockedFeatureAlternatives->screenPoint ).manhattanLength() >= QApplication::startDragDistance() )
{
// as soon as the mouse moves more than just a tiny bit, previously stored alternatives info
// is probably not valid anymore and will need to be re-calculated
mSelectedFeatureAlternatives.reset();
mLockedFeatureAlternatives.reset();
}

if ( mSelectionMethod == SelectionRange )
Expand Down Expand Up @@ -753,7 +753,7 @@ QgsPointLocator::Match QgsVertexTool::snapToEditableLayer( QgsMapMouseEvent *e )
}

snapUtils->setConfig( config );
SelectedMatchFilter filter( tol, mSelectedFeature.get() );
SelectedMatchFilter filter( tol, mLockedFeature.get() );
m = snapUtils->snapToMap( mapPoint, &filter );

// we give priority to snap matches that are from selected features
Expand All @@ -780,7 +780,7 @@ QgsPointLocator::Match QgsVertexTool::snapToEditableLayer( QgsMapMouseEvent *e )
}

snapUtils->setConfig( config );
SelectedMatchFilter filter( tol, mSelectedFeature.get() );
SelectedMatchFilter filter( tol, mLockedFeature.get() );
m = snapUtils->snapToMap( mapPoint, &filter );

// we give priority to snap matches that are from selected features
Expand Down Expand Up @@ -928,7 +928,7 @@ QSet<QPair<QgsVectorLayer *, QgsFeatureId> > QgsVertexTool::findAllEditableFeatu

void QgsVertexTool::tryToSelectFeature( QgsMapMouseEvent *e )
{
if ( !mSelectedFeatureAlternatives )
if ( !mLockedFeatureAlternatives )
{
// this is the first right-click on this location so we currently do not have information
// about editable features at this mouse location - let's build the alternatives info
Expand All @@ -942,44 +942,44 @@ void QgsVertexTool::tryToSelectFeature( QgsMapMouseEvent *e )
m = snapToPolygonInterior( e );
}

mSelectedFeatureAlternatives.reset( new SelectedFeatureAlternatives );
mSelectedFeatureAlternatives->screenPoint = e->pos();
mSelectedFeatureAlternatives->index = -1;
mLockedFeatureAlternatives.reset( new LockedFeatureAlternatives );
mLockedFeatureAlternatives->screenPoint = e->pos();
mLockedFeatureAlternatives->index = -1;
if ( m.isValid() )
{
// ideally the feature that would get normally highlighted should be also the first choice
// because as user moves mouse, different features are highlighted, so the highlighted feature
// should be first to get selected
QPair<QgsVectorLayer *, QgsFeatureId> firstChoice( m.layer(), m.featureId() );
mSelectedFeatureAlternatives->alternatives.append( firstChoice );
mLockedFeatureAlternatives->alternatives.append( firstChoice );
alternatives.remove( firstChoice );
}
mSelectedFeatureAlternatives->alternatives.append( alternatives.toList() );
mLockedFeatureAlternatives->alternatives.append( alternatives.toList() );

if ( mSelectedFeature )
if ( mLockedFeature )
{
// 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 );
QPair<QgsVectorLayer *, QgsFeatureId> currentSelection( mLockedFeature->layer(), mLockedFeature->featureId() );
int currentIndex = mLockedFeatureAlternatives->alternatives.indexOf( currentSelection );
if ( currentIndex != -1 )
mSelectedFeatureAlternatives->index = currentIndex;
mLockedFeatureAlternatives->index = currentIndex;
}
}
}

if ( mSelectedFeatureAlternatives )
if ( mLockedFeatureAlternatives )
{
// move to the next alternative
if ( mSelectedFeatureAlternatives->index < mSelectedFeatureAlternatives->alternatives.count() - 1 )
++mSelectedFeatureAlternatives->index;
if ( mLockedFeatureAlternatives->index < mLockedFeatureAlternatives->alternatives.count() - 1 )
++mLockedFeatureAlternatives->index;
else
mSelectedFeatureAlternatives->index = -1;
mLockedFeatureAlternatives->index = -1;
}

if ( mSelectedFeatureAlternatives && mSelectedFeatureAlternatives->index != -1 )
if ( mLockedFeatureAlternatives && mLockedFeatureAlternatives->index != -1 )
{
// we have a feature to select
QPair<QgsVectorLayer *, QgsFeatureId> alternative = mSelectedFeatureAlternatives->alternatives.at( mSelectedFeatureAlternatives->index );
QPair<QgsVectorLayer *, QgsFeatureId> alternative = mLockedFeatureAlternatives->alternatives.at( mLockedFeatureAlternatives->index );
updateVertexEditor( alternative.first, alternative.second );
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/app/vertextool/qgsvertextool.h
Expand Up @@ -445,15 +445,15 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
* This is used when user clicks with right mouse button multiple times in one location
* to easily switch to the desired feature.
*/
struct SelectedFeatureAlternatives
struct LockedFeatureAlternatives
{
QPoint screenPoint;
QList< QPair<QgsVectorLayer *, QgsFeatureId> > alternatives;
int index = -1;
};

//! Keeps information about other possible features to select with right click. Null if no info is currently held.
std::unique_ptr<SelectedFeatureAlternatives> mSelectedFeatureAlternatives;
std::unique_ptr<LockedFeatureAlternatives> mLockedFeatureAlternatives;

// support for validation of geometries

Expand Down

0 comments on commit 5b7cb3f

Please sign in to comment.