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

Add a save button in layer style panel #52037

Merged
merged 3 commits into from
Apr 13, 2023
Merged

Conversation

Djedouas
Copy link
Member

Description

Saving layer style QML file is already available at 2 places in QGIS, with code duplication:

  • The contextual menu of the layer in the layer tree view (code in qgisapp.cpp)
    image
  • Each of the dedicated layer properties classes, for the layer properties dialogs
    image

For the purpose of #51515 a third place of code duplication was going to appear:

  • in the layer style panel
    image

To remove code duplication, I had to choose between:

  • putting the loading methods of each layer properties classes as public
  • putting the classes that need to use this method as friend

I propose the friend option because looking into the code of the style panel, I was able to remove dupllicate code for the saving, saving as default, and open buttons, which mean more methods to change to public, where I just needed to add one friend statement. This is debatable, and I ask for opinions.

Testing

I spent time on writing a unit test, but on GUI it's terribly difficult here because it's all about pop-up, and I ended with using QTimers and singleShots to mock user clicks, but it's really unstable (crashes QGIS when the test fails... and stops all the unit test run...).

Here the addition relies on calling code from the layer properties, which is tested, so I think that it's sufficient.

Other QGIS crash found and fixed

To reproduce:

  • Add a new style
  • Delete a style
  • QGIS crashes

image

Reason: the item of the QStandardItemModel was removed twice.

@github-actions github-actions bot added this to the 3.30.0 milestone Feb 27, 2023
Copy link
Contributor

@troopa81 troopa81 left a comment

Choose a reason for hiding this comment

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

Thanks for removing duplicate code 👍

Did you check that every piece of removed code was really equivalent?

I propose the friend option because looking into the code of the style panel, I was able to remove dupllicate code for the saving, saving as default, and open buttons, which mean more methods to change to public, where I just needed to add one friend statement. This is debatable, and I ask for opinions.

I prefer to keep friend keyword for really specific edge cases (test classes which need to access everything for instance) and in this particular scenario, I would prefer to make the needed method public.

I think it would be interesting to have an interface that define the different methods (savedefault, saveas, loadStyle) to avoid switch on type, and each properties class would implement it. What do you think?

break;

// Not available for these
case Qgis::LayerType::PointCloud:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not pointcloud ? we have a saveDefaultStyle.

@nyalldawson nyalldawson modified the milestones: 3.30.0, 3.32 (feature) Mar 6, 2023
@YoannQDQ YoannQDQ modified the milestones: 3.32 (feature), 3.32.0 Mar 6, 2023
@github-actions
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 Mar 21, 2023
@Djedouas Djedouas removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Mar 21, 2023
@Djedouas Djedouas force-pushed the fix-51515 branch 2 times, most recently from da358e5 to c7f29ca Compare April 4, 2023 07:24
@Djedouas
Copy link
Member Author

Djedouas commented Apr 4, 2023

@troopa81

I chose to homogenize the behaviors when loading a style, it is applied.

The methods are no longer private with friend keyword, but public.

Thanks for the review.

The unsuccessful check (cppcheck_18_04) is not related to this PR.

@troopa81
Copy link
Contributor

Did you see my comment about point cloud? There is a call to saveStyleAs when it comes to PointCloud but any other other methods is not called. Is it normal?

@Djedouas
Copy link
Member Author

Did you see my comment about point cloud? There is a call to saveStyleAs when it comes to PointCloud but any other other methods is not called. Is it normal?

Yes, it's normal, point cloud was not supporting loading/saving layer styles with the panel before, I don't want to risk to go further than the bugfix here, which is to add the save button to layer types already supporting this section of the style panel.

BUT the save style for point cloud was used in qgisapp code so I included point cloud in the minor refactoring of removing code duplucation.

@troopa81 troopa81 merged commit ea84b6a into qgis:master Apr 13, 2023
@Djedouas Djedouas deleted the fix-51515 branch June 23, 2023 08:45
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.

None yet

4 participants