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

refactoring of QgsMapToolCapture to integrate shape map tools #46687

Merged
merged 66 commits into from
Feb 22, 2022

Conversation

3nids
Copy link
Member

@3nids 3nids commented Jan 4, 2022

This moves part of the code from QgsMapToolDigitizeFeature to QgsMapToolCapture so the tool can actually capture point, line and polygons. It's mainly the 'cadCanvasReleaseEvent` which has been transfered.

This is a preliminary work to support shape digitizing in more map tools (like add part, add ring, fill ring or anything else).

The idea is that QgsMapToolCapture should actually perform the digitization of point/line/polygon and let subclasses deal to what they want to do with it (create feature, add part, add ring, etc).

Then, QgsMapToolCapture will be able to digitize shapes (by adding a new enum entry CaptureTechnique::ShapeDigitizing). The idea is that the shape toolbar will be turned into a checkable choice so that QgsMapToolCapture will be able to perform any of the capture technique entries:

  • StraightSegments
  • CircularString
  • Streaming
  • Shapes

I'd like to get opinions of the map tools experts @lbartoletti @nyalldawson. If you consider I should open a QEP for this discussion, let me know.

@github-actions github-actions bot added this to the 3.24.0 milestone Jan 4, 2022
@nyalldawson
Copy link
Collaborator

I haven't looked at the code, but I fully support the design changes here. (I've wanted similar to allow the shape digitising for annotation items!). Great work @3nids!

@3nids 3nids added the Squash! Remember to squash this PR, instead of merging or rebasing label Jan 4, 2022
@m-kuhn m-kuhn added Changelog Items that are queued to appear in the visual changelog - remove after harvesting Feature labels Jan 4, 2022
@3nids 3nids force-pushed the capture-map-tool branch from 65aaad2 to 992e822 Compare January 4, 2022 15:15
@lbartoletti
Copy link
Member

I can't review it this week, but it's a big +1 for this design. Thanks @3nids !

@3nids 3nids force-pushed the capture-map-tool branch from 992e822 to f1edb07 Compare January 5, 2022 09:08
@3nids
Copy link
Member Author

3nids commented Jan 5, 2022

thanks @lbartoletti and @nyalldawson for the thumbs up

I have gone a bit furthe:

  • QgsMapToolCapture now has a capture technique defined
  • ground work to introduce the shape technique is done
  • add part has been turned to fully use QgsMapToolCapture (by using the parent cadCanvasReleaseEvent)

@3nids 3nids force-pushed the capture-map-tool branch 6 times, most recently from b5c145f to df6d2e1 Compare January 5, 2022 14:38
* Called when the geometry is captured
* \since QGIS 3.24
*/
virtual void geometryCaptured( const QgsGeometry &geometry ) {Q_UNUSED( geometry )} SIP_FORCE
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't these be protected in order to allow python subclasses of the tool to function correctly?

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 thought it was ok with forcing them with SIP_FORCE. Am I wrong?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure either way -- it just looks problematic to me when a protected method is guaranteed to work correctly

Copy link
Member Author

Choose a reason for hiding this comment

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

quoting https://stackoverflow.com/a/2170696/1548052

This lets the derived classes override the function to customize the behavior as needed, without further exposing the virtual functions directly by making them callable by derived classes (as would be possible if the functions were just protected). The point is that virtual functions exist to allow customization; unless they also need to be invoked directly from within derived classes' code, there's no need to ever make them anything

And if you consider the idea of the additional class to handle the avoidIntersections, we'll be dealing with the private handler on the geometry and it will be better to just not forward the specific handlers.

src/gui/qgsmaptoolcapture.h Show resolved Hide resolved
src/gui/qgsmaptoolcapture.cpp Outdated Show resolved Hide resolved
src/gui/qgsmaptoolcapture.cpp Show resolved Hide resolved
@3nids 3nids force-pushed the capture-map-tool branch 3 times, most recently from 4703779 to 24ccf65 Compare January 6, 2022 14:54
@3nids
Copy link
Member Author

3nids commented Jan 13, 2022

Some progress have been made:

Remains:

  • complete refactoring of shape tools
  • complete refactoring of capture map tools (add feature and add part are done for now, remains add/fill ring, etc.)
  • adapt existing shape tool tests to work with new code

I know this a big code change, but I would like if possible to merge it during this cycle.

@3nids 3nids removed the Squash! Remember to squash this PR, instead of merging or rebasing label Jan 13, 2022
@3nids 3nids force-pushed the capture-map-tool branch 2 times, most recently from 13b583b to 7a8dbb9 Compare January 13, 2022 20:44
@3nids
Copy link
Member Author

3nids commented Jan 13, 2022

Refactoring of existing shape tools is completed

@3nids
Copy link
Member Author

3nids commented Jan 13, 2022

And here are the curved rings:
image

@3nids
Copy link
Member Author

3nids commented Jan 13, 2022

ezgif-7-41239961b7

@3nids 3nids changed the title make QgsMapToolCapture capable of capturing point/line/polygons refactoring of QgsMapToolCapture to integrate shape map tools Jan 14, 2022
@3nids 3nids added the Digitizing Related to feature digitizing map tools or functionality label Jan 14, 2022
@3nids
Copy link
Member Author

3nids commented Feb 21, 2022

Thanks a loooooot for the review @nyalldawson.
Comments have been addressed.

Copy link
Member

@lbartoletti lbartoletti left a comment

Choose a reason for hiding this comment

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

Except for a few details, it's good for me.

@@ -0,0 +1,85 @@
/***************************************************************************
qgmaptoolcircle2points.cpp - map tool for adding circle
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
qgmaptoolcircle2points.cpp - map tool for adding circle
qgsmaptoolshapecircle2points.cpp - map tool for adding circle

Same for other files

{
if ( !mParentTool || mCircle.isEmpty() )
{
Copy link
Member

Choose a reason for hiding this comment

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

IMHO braces should be always present around statements even for one line if.

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 personally like the readability when there is only one line.
The coding guidelines are not super explicit about this, but there is an example with it https://docs.qgis.org/3.16/en/docs/developers_guide/codingstandards.html#put-commands-on-separate-lines

python/gui/auto_generated/qgisinterface.sip.in Outdated Show resolved Hide resolved
@github-actions
Copy link

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

Gustry added a commit to Gustry/QGIS that referenced this pull request Mar 17, 2022
Gustry added a commit to Gustry/QGIS that referenced this pull request Mar 17, 2022
Gustry added a commit to Gustry/QGIS that referenced this pull request Mar 17, 2022
@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 May 28, 2022
@agiudiceandrea
Copy link
Contributor

agiudiceandrea commented Oct 1, 2022

Hi @3nids, could you please have a look at the issue #49541 which it seems to me it is related to this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ChangelogHarvested This PR description has been harvested in the Changelog already. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants