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

added possibility to add custom actions for the group-nodes in the layer tree #59585

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

notguiltyspark
Copy link
Contributor

@notguiltyspark notguiltyspark commented Nov 25, 2024

Description

Currently, you can create a custom action in the context menu of layer-tree only for different types of layers. This PR provides public API to add an action for groups of layers.

Two functions are added to public API of QGisInterface:

  • Add action to context menu for all group-nodes in the layer tree.

virtual void addCustomActionForGroups( QAction *action, const QString &menu ) = 0;

  • Remove action from the context menu for all group-nodes in the layer tree previously added with addCustomActionForGroups().

virtual bool removeCustomActionForGroups( QAction *action ) = 0;

add_action_to_group
remove_action_from_group

Fixes #53692

@github-actions github-actions bot added this to the 3.42.0 milestone Nov 25, 2024
Copy link

github-actions bot commented Nov 25, 2024

🪟 Windows builds

Download Windows builds of this PR for testing.
Debug symbols for this build are available here.
(Built from commit 3f172e6)

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
(Built from commit 3f172e6)

@jbp35
Copy link
Contributor

jbp35 commented Nov 26, 2024

It would be great to be able to add a custom action in the default menu (right click in blank area of layer tree).

@notguiltyspark notguiltyspark force-pushed the add_custom_group_action branch from cce776c to 9ae57b3 Compare December 9, 2024 18:59
@notguiltyspark
Copy link
Contributor Author

It would be great to be able to add a custom action in the default menu (right click in blank area of layer tree).

I agree, though i think it would be better to create a separate issue.

Copy link

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.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Dec 24, 2024
@notguiltyspark notguiltyspark force-pushed the add_custom_group_action branch from 9ae57b3 to 7d49dd4 Compare December 25, 2024 22:49
@github-actions github-actions bot removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Dec 25, 2024
@notguiltyspark notguiltyspark force-pushed the add_custom_group_action branch from 7d49dd4 to 1b99119 Compare January 1, 2025 21:18
Copy link

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.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Jan 16, 2025
@Rusty-JonesBMT
Copy link

Would love to see this implemented.

If there was a way to upvote or something, that would be great. I'm hoping that by commenting, it attracts attention.

@github-actions github-actions bot removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Jan 16, 2025
@notguiltyspark notguiltyspark force-pushed the add_custom_group_action branch from 1b99119 to bfba646 Compare January 19, 2025 21:26
@notguiltyspark
Copy link
Contributor Author

@rouault Could you please check if i need to add anything here or is it good to go?

@rouault
Copy link
Contributor

rouault commented Jan 20, 2025

It's fine by me, but I'd welcome the ACK from another core committer more familiar than me with that part of the application

@notguiltyspark
Copy link
Contributor Author

Ah, i see! Should i tag someone specific or we just wait for someone to come and review it when they have time?

@nyalldawson
Copy link
Collaborator

I'm personally -1 to this approach. I think that what you're trying to achieve can already be done by connecting to the contextMenuAboutToShow signal in iface.layerTreeView().

Copy link

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.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Feb 12, 2025
@notguiltyspark
Copy link
Contributor Author

@nyalldawson
Ah, i see! While this signal certainly presents possibility to customize menu, group-functionality seems to go under "general" category, meaning that different components potentially may be interested in already existing mechanism, such as, for example, already prepared interface to add layer-type-specific actions.

In other words, adding it to the interface of menu provider (extending it) allows it to be encapsulated in object-oriented sense, keeping general functionality in one place and particular customization - in the other (through the means of the handling signal).

There is also a moment of where custom menus/actions are being added in context menu. If we catch menu via signal - by default addition appends them to the end, which is often reserved to the export options in terms of user experience. But in manager it is potentially customizable (api can be extended to use some kind of priority)

@github-actions github-actions bot removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Feb 12, 2025
@nyalldawson
Copy link
Collaborator

@notguiltyspark

There is also a moment of where custom menus/actions are being added in context menu. If we catch menu via signal - by default addition appends them to the end, which is often reserved to the export options in terms of user experience. But in manager it is potentially customizable (api can be extended to use some kind of priority)

Actually the signal gives MORE flexibility, because you have access to the full (already populated) menu in the argument. So your code can decide exactly where to insert actions/submenus, as you can find an inbuilt action and then insert your action/menu before it. You also get a lot more flexibility in handling submenus then the API proposed in this pull request, as you could nest submenus, add to other submenus, etc.

In short, the proposed API is adding a lot of complexity for quite a rigid API, when there's already a much more flexible API available in current versions which allows you to achieve the same result.

Copy link

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.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Feb 27, 2025
…ternal components during its population process
@notguiltyspark notguiltyspark force-pushed the add_custom_group_action branch from bfba646 to 3f172e6 Compare March 5, 2025 14:44
@github-actions github-actions bot removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Mar 5, 2025
@notguiltyspark
Copy link
Contributor Author

@nyalldawson

Understood!
I removed commits with unsuitable api and instead added one with named separators to help in customization process - this way one can get easier to the place in menu for custom action insertion. What do you think?

@@ -38,7 +38,7 @@ QMenu *QgsLayoutAppMenuProvider::createContextMenu( QWidget *parent, QgsLayout *
//undo/redo
menu->addAction( layout->undoStack()->stack()->createUndoAction( menu ) );
menu->addAction( layout->undoStack()->stack()->createRedoAction( menu ) );
menu->addSeparator();
menu->addSeparator()->setText( QLatin1String( "UndoRedoSeparator" ) );
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be:

Suggested change
menu->addSeparator()->setText( QLatin1String( "UndoRedoSeparator" ) );
menu->addSeparator()->setObjectName( QLatin1String( "UndoRedoSeparator" ) );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add method "addCustomActionForGroup" for QgisInterface
5 participants