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

Implementation of labeling engine rules #58580

Merged
merged 20 commits into from
Sep 10, 2024

Conversation

nyalldawson
Copy link
Collaborator

@nyalldawson nyalldawson commented Sep 5, 2024

See qgis/QGIS-Enhancement-Proposals#299

Implements the API framework for setting advanced labeling engine rules for a project, and implements 4 initial rule types:

  • QgsLabelingEngineRuleMinimumDistanceLabelToFeature: prevents labels being placed too close to features from a different layer
  • QgsLabelingEngineRuleMaximumDistanceLabelToFeature: prevents labels being placed too far from features from a different layer
  • QgsLabelingEngineRuleMinimumDistanceLabelToLabel: prevents labels being placed too close to labels from a different layer
  • QgsLabelingEngineRuleAvoidLabelOverlapWithFeature: prevents labels being placed overlapping features from a different layer

(note that the first 3 rules require a build based on GEOS >= 3.10, they are not available for older GEOS builds)

Also implements a registry for storing available rule classes, and serialization of rules and configuration in QGIS projects

Now with GUI:

Peek.2024-09-06.13-06.mp4

Sponsored by Rubicon Concierge Real Estate

@nyalldawson nyalldawson added the API API improvement only, no visible user interface changes label Sep 5, 2024
@github-actions github-actions bot added this to the 3.40.0 milestone Sep 5, 2024
Copy link

github-actions bot commented Sep 5, 2024

🪟 Windows builds ready!

Windows builds of this PR are available for testing here. Debug symbols for this build are available here.

(Built from commit 9a909a0)

@nyalldawson nyalldawson changed the title [api] Implementation of labeling engine rules Implementation of labeling engine rules Sep 6, 2024
@nyalldawson nyalldawson added Feature Labeling Related to QGIS map labeling Needs Documentation When merging a labeled PR, an issue will be created in the Doc repo. Changelog Items that are queued to appear in the visual changelog - remove after harvesting labels Sep 6, 2024
@qgis-bot
Copy link
Collaborator

qgis-bot commented Sep 6, 2024

@nyalldawson
This pull request has been tagged as requiring documentation.

A documentation ticket will be opened at https://github.com/qgis/QGIS-Documentation when this PR is merged.

Please update the description (not the comments) with helpful description and screenshot to help the work from documentors.
Also, any commit having [needs-doc] or [Needs Documentation] in will see its message pushed to the issue, so please be as verbose as you can.

Thank you!

@qgis-bot
Copy link
Collaborator

qgis-bot commented Sep 6, 2024

@nyalldawson

This pull request has been tagged for the changelog.

  • The description will be harvested so please provide a "nearly-ready" text for the final changelog
  • If possible, add a nice illustration of the feature. Only the first one in the description will be harvested (GIF accepted as well)
  • If you can, it's better to give credits to your sponsor, see below for different formats.

You can edit the description.

Format available for credits
  • Funded by NAME
  • Funded by URL
  • Funded by NAME URL
  • Sponsored by NAME
  • Sponsored by URL
  • Sponsored by NAME URL

Thank you!

@nyalldawson
Copy link
Collaborator Author

Now with GUI, this is ready for review...

@DelazJ
Copy link
Contributor

DelazJ commented Sep 6, 2024

Nice @nyalldawson! What about showing involved layers next to the rule in the "Labeling rules" list? It might help to quickly identify the rule you want to update...

@nyalldawson
Copy link
Collaborator Author

@DelazJ you can set your own name for rules, which is used in that list. I was thinking that could be better for rule identification.

Maybe we could show a summary including involved layers in a tooltip for the list item?

@DelazJ
Copy link
Contributor

DelazJ commented Sep 6, 2024

Ah, great! I only watched the screencast which didn't showcase that.

Maybe we could show a summary including involved layers in a tooltip for the list item?

+1 from me. When you are out of inspiration for rules naming, this could be handful 😄

@nyalldawson
Copy link
Collaborator Author

@DelazJ
here you go:

Peek.2024-09-09.11-11.mp4

*
* The default implementation returns FALSE.
*/
virtual bool candidateIsIllegal( const pal::LabelPosition *candidate, QgsLabelingEngineContext &context ) const SIP_SKIP;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why but I don't like the word 'illegal' here. What about candidateIsForbidden, candiateIsProhibited, candidateIsDisallowed, candidateIsBanned ? We're breaching rules not laws 😉

Copy link
Collaborator Author

@nyalldawson nyalldawson Sep 10, 2024

Choose a reason for hiding this comment

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

Hmm... we have QgsAbstractDatabaseProviderConnection::illegalFieldNames, but nothing in current api with forbidden/prohibited/disallowed/banned. Is one other method enough to set the precedent?

Copy link
Contributor

Choose a reason for hiding this comment

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

@nyalldawson , ideally we'd change illegalFieldNames to prohibited/forbiddenFileNames but that API is exposed to bindings so it's frozen right?

Seems like settling for what preexisting keyword is a good argument enough then.

src/core/labeling/rules/qgslabelingenginerule_impl.cpp Outdated Show resolved Hide resolved
src/core/labeling/rules/qgslabelingenginerule_impl.cpp Outdated Show resolved Hide resolved
src/core/labeling/rules/qgslabelingengineruleregistry.cpp Outdated Show resolved Hide resolved
src/core/pal/pal.cpp Show resolved Hide resolved
src/core/pal/pal.h Show resolved Hide resolved
See qgis/QGIS-Enhancement-Proposals#299

Implements the API framework for setting advanced labeling engine
rules for a project, and implements 4 initial rule types:

- QgsLabelingEngineRuleMinimumDistanceLabelToFeature: prevents labels
  being placed too *close* to features from a different layer
- QgsLabelingEngineRuleMaximumDistanceLabelToFeature: prevents labels
  being placed too *far* from features from a different layer
- QgsLabelingEngineRuleMinimumDistanceLabelToLabel: prevents labels
  being placed too close to labels from a different layer
- QgsLabelingEngineRuleAvoidLabelOverlapWithFeature: prevents labels
  being placed overlapping features from a different layer

(note that the first 3 rules require a build based on GEOS >= 3.10,
they are not available for older GEOS builds)

Also implements a registry for storing available rule classes,
and serialization of rules and configuration in QGIS projects
Adds the necessary hooks into the pal classes to give engine rules
a chance to implement their logic
@nyalldawson nyalldawson merged commit 569da98 into qgis:master Sep 10, 2024
30 checks passed
@nyalldawson nyalldawson deleted the advanced_label_rules_squash branch September 10, 2024 16:06
@qgis-bot
Copy link
Collaborator

@nyalldawson
A documentation ticket has been opened at qgis/QGIS-Documentation#9244
It is your responsibility to visit this ticket and add as much detail as possible for the documentation team to correctly document this change.
Thank you!

@zacharlie zacharlie added ChangelogHarvested This PR description has been harvested in the Changelog already. and removed Changelog Items that are queued to appear in the visual changelog - remove after harvesting labels Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API API improvement only, no visible user interface changes ChangelogHarvested This PR description has been harvested in the Changelog already. Feature Labeling Related to QGIS map labeling Needs Documentation When merging a labeled PR, an issue will be created in the Doc repo.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants