Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if feature is rendered before displaying its map tips #38861

Merged
merged 3 commits into from
Oct 15, 2020

Conversation

pblottiere
Copy link
Member

Description

Fixes #37066

@pblottiere pblottiere added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Sep 18, 2020
@github-actions github-actions bot added this to the 3.16.0 milestone Sep 18, 2020
renderer.reset( vlayer->renderer()->clone() );
renderer->startRender( renderCtx, vlayer->fields() );
}

QgsFeatureIterator it = vlayer->getFeatures( request );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to optimise this request based on the renderer's visible features -- if the layer has a renderer, you can use QgsFeatureRenderer::filter to set a filter expression on the request to avoid fetching and testing some invisible features, which should speed this functionality up

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! I take a look. Thanks for your input Nyall 👍.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nyalldawson I think I took into account your comment. Let me know if it's not what you had in mind.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we also need:

request.setFilterExpression( renderer->filter( vlayer->fields() ));

in order to delegate the filter to the provider

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm... In my use case with a graduated renderer and a SHP, the renderer->filter( vlayer->fields() ) call returns an empty string so I get an "empty" iterator from vlayer->getFeatures( request ). So map tips are never displayed.

I can write a unit test to highlight this behavior if you want?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not implemented for the graduated renderer -- so if filter() returns an empty string, you don't set a filter expression on the iterator. It's implemented for categorized, rule based renderers only.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK good to know. The code is now updated.

@pblottiere
Copy link
Member Author

I'll merge this PR in the coming days if I don't have more comments in the meantime.

@pblottiere pblottiere merged commit b38ea53 into qgis:master Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Map tips should not appear for invisible features
2 participants