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

New snapping modes: Centroid and middle of a segment (midpoint) #33622

Merged
merged 31 commits into from
Mar 2, 2020

Conversation

lbartoletti
Copy link
Member

Description

This PR is part of my proposal to improve snapping modes in QGIS by getting closer to the experience of CAD tools.

It proposes two new modes. Snapping on the center of a geometry (centroid) and the middle of a segment.

To allow the selection of these new modes, I changed the interface of the combo box allowing to select several modes at the same time.

image

I took the opportunity to display the snap on an area that was present in previous versions but not selectable.

On the code side, QgsSnappingConfig::SnappingType become flags. It also changes the project file. I added a control in QgsSnappingConfig::readProject

The order of preference for snapping is as follows:

  • Vertex, Intersection
  • Middle
  • Centroid
  • Edge
  • Area

snapmode-(2) webm

Sponsored by: Qwat group / Ville de Lausanne ( @ponceta @dsavary ) / Oslandia and some spare time

Checklist

  • Commit messages are descriptive and explain the rationale for changes
  • Commits which fix bugs include Fixes #11111 at the bottom of the commit message
  • I have read the QGIS Coding Standards and this PR complies with them
  • New unit tests have been added for core changes
  • I have run the scripts/prepare-commit.sh script before each commit
  • I have evaluated whether it is appropriate for this PR to be backported, backport requests are left as label or comment

@nyalldawson
Copy link
Collaborator

Very nice -- that's a welcome addition!

@nirvn
Copy link
Contributor

nirvn commented Jan 6, 2020

Nice. How does the advanced snapping mode's layers list widget looks like now?

@nirvn
Copy link
Contributor

nirvn commented Jan 6, 2020

@lbartoletti , if I wasn't clear, here's what I meant to refer to:
image

@lbartoletti
Copy link
Member Author

Nice. How does the advanced snapping mode's layers list widget looks like now?

I only change texts in hte combobox to "No snapping" or "Snapping active"

snapadvmode webm

@nirvn
Copy link
Contributor

nirvn commented Jan 6, 2020

@lbartoletti , could you replace "snapping active" with a list of active snapping types?

@lbartoletti
Copy link
Member Author

@lbartoletti , could you replace "snapping active" with a list of active snapping types?

@nirvn It was my first intentention, but I removed it becaus I thought that was a too long text when there is more than two For ex modes, "vertex, segment, middle, centroid". But I agree that it would be better than "active snapping". Do you have any ideas?

@nirvn
Copy link
Contributor

nirvn commented Jan 6, 2020

@lbartoletti , what about clipping the string list to two items if more than two are selected? For e.g., "vertex, segment, etc."

@lbartoletti
Copy link
Member Author

@lbartoletti , what about clipping the string list to two items if more than two are selected? For e.g., "vertex, segment, etc."

Done. Thanks.

snapadvmode_fixed webm

Copy link
Member

@3nids 3nids left a comment

Choose a reason for hiding this comment

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

Such a nice addition, love it :)
I am mainly commenting on the API and project.
I would let @wonder-sk look at the core snapping part.

I have some minor requests.

src/core/qgssnappingconfig.h Outdated Show resolved Hide resolved
src/core/qgssnappingconfig.h Outdated Show resolved Hide resolved
src/core/qgssnappingconfig.h Show resolved Hide resolved
src/app/qgsoptions.cpp Outdated Show resolved Hide resolved
src/app/qgssnappinglayertreemodel.cpp Outdated Show resolved Hide resolved
src/app/qgssnappinglayertreemodel.cpp Show resolved Hide resolved
src/core/qgssnappingconfig.h Outdated Show resolved Hide resolved
src/core/qgssnappingconfig.h Outdated Show resolved Hide resolved
@Saijin-Naib
Copy link

This is such an incredible quality-of-life improvement.

Thank you, so, so much!

python/core/auto_generated/qgssnappingconfig.sip.in Outdated Show resolved Hide resolved
python/core/auto_generated/qgspointlocator.sip.in Outdated Show resolved Hide resolved
@@ -238,6 +256,35 @@ This method is either blocking or non blocking according to ``relaxed`` paramete
.. versionadded:: 3.6
%End

MatchList centroidsInRect( const QgsRectangle &rect, QgsPointLocator::MatchFilter *filter = 0 );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
MatchList centroidsInRect( const QgsRectangle &rect, QgsPointLocator::MatchFilter *filter = 0 );
MatchList centroidsInRectangle( const QgsRectangle &rectangle, QgsPointLocator::MatchFilter *filter = 0 );

Copy link
Collaborator

Choose a reason for hiding this comment

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

(also with the other newly added methods)

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with you. But was to match with older methods, and I think it's better to be consistent with the old ways, isn't it? Maybe a note fore QGIS 4?

Copy link
Member

Choose a reason for hiding this comment

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

I'd say better do it now in this case, less refactoring is not bad :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but it's an API break?

src/app/qgsoptions.cpp Outdated Show resolved Hide resolved
src/core/qgspointlocator.cpp Outdated Show resolved Hide resolved
QgsGeometry *geom = mLocator->mGeoms.value( id );
QgsPointXY pt;
int afterVertex;
double sqrDist = geom->closestSegmentWithContext( mSrcPoint, pt, afterVertex, nullptr, POINT_LOC_EPSILON );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm -- the closest segment won't necessarily equate to the closest segment's midpoint, will it? (Think a close but very long segment vs a slightly more distant but very short segment)

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so, All my manuals tests worked well (tm)
But I'm interested in exploring it further if it comes to be confirmed.

src/core/qgspointlocator.h Show resolved Hide resolved
src/core/qgspointlocator.h Outdated Show resolved Hide resolved
src/core/qgssnappingutils.cpp Outdated Show resolved Hide resolved
@NathanW2
Copy link
Member

NathanW2 commented Jan 6, 2020

image

Copy link
Member

@wonder-sk wonder-sk left a comment

Choose a reason for hiding this comment

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

I am wondering what is the meaning of snapping to area - is it actually useful to have it as an option? Do I understand correctly that it would snap to any point within a polygon?

src/core/qgspointlocator.h Outdated Show resolved Hide resolved
src/core/qgspointlocator.h Outdated Show resolved Hide resolved
src/core/qgspointlocator.h Outdated Show resolved Hide resolved
@lbartoletti
Copy link
Member Author

I am wondering what is the meaning of snapping to area - is it actually useful to have it as an option? Do I understand correctly that it would snap to any point within a polygon?

Honnestyl, I discover it when I started to work on this feature... Yes it snaps to any point within a polygon.
Since it was there, I made it visible. There's no reason to remove it either.

@m-kuhn
Copy link
Member

m-kuhn commented Jan 16, 2020

One use case I can see for snap to area is the possibility to draw a line or point on(to) a polygon and use attributes from this polygon in the default value expression trough @snapping_results.

@lbartoletti lbartoletti added Squash! Remember to squash this PR, instead of merging or rebasing Digitizing Related to feature digitizing map tools or functionality Needs Documentation When merging a labeled PR, an issue will be created in the Doc repo. labels Jan 17, 2020
@qgis-bot
Copy link
Collaborator

@lbartoletti
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!

@lbartoletti
Copy link
Member Author

@nyalldawson it's too late to be merged in 3.12?

@nyalldawson
Copy link
Collaborator

@lbartoletti that's not my decision to make -- you'll need to ask @jef-n

@3nids 3nids mentioned this pull request Feb 18, 2020
@stale
Copy link

stale bot commented Feb 21, 2020

The QGIS project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 14 days and is being automatically marked as "stale". If you think this pull request should be merged, please check

  • that all unit tests are passing

  • that all comments by reviewers have been addressed

  • that there is enough information for reviewers, in particular

    • link to any issues which this pull request fixes

    • add a description of workflows which this pull request fixes

    • add screenshots if applicable

  • that you have written unit tests where possible
    In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this pull request.
    If there is no further activity on this pull request, it will be closed in a week.

@stale stale bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Feb 21, 2020
@lbartoletti lbartoletti removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Feb 21, 2020
@lbartoletti lbartoletti modified the milestones: 3.12.0, 3.14.0 Feb 21, 2020
@lbartoletti
Copy link
Member Author

@3nids Denis, please, can you remove the "requested changes" since I can use scoped enum with QT 5.9?

@3nids @nyalldawson I bumped the version in my last commit but I'm not sure if it's OK if we want to merge it now?

@3nids
Copy link
Member

3nids commented Feb 25, 2020

for the parts I was involved, I'm for a merge.

@lbartoletti
Copy link
Member Author

Thanks Denis.
Someone to push the merge button? ;)

@qgis-bot
Copy link
Collaborator

qgis-bot commented Mar 2, 2020

@lbartoletti
A documentation ticket has been opened at qgis/QGIS-Documentation#4950
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!

@mhugo
Copy link

mhugo commented Mar 2, 2020

@lbartoletti I've pushed the button, thanks for your work !

@lbartoletti lbartoletti deleted the snap_centroid branch March 2, 2020 08:07
@timlinux timlinux added Changelog Items that are queued to appear in the visual changelog - remove after harvesting and removed Changelog Items that are queued to appear in the visual changelog - remove after harvesting labels May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Digitizing Related to feature digitizing map tools or functionality Feature Needs Documentation When merging a labeled PR, an issue will be created in the Doc repo. Squash! Remember to squash this PR, instead of merging or rebasing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet