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

Refactor settings #5273

Open
wants to merge 48 commits into
base: master
Choose a base branch
from

Conversation

superenginegit
Copy link

This PR is for issue #5201.

What I have done so far:

  • Added file SettingsDescription.h where the Settings are described in structs. It is possible to set the xmlName, default value, an optional comment to go into the settings file and three functions for import, export and validation (I expanded the approach from here)
  • Adapted the current Settings to work with the new data structure

What I think could still be done:

  • It would be possible to remove the setters and getters from the Settings.h and Settings.cpp files and replace their usage with set<setting-name>(), but this would probably be too much to add it to this PR as it is already a lot of changes

I'd appreciate any feedback on this

Copy link
Contributor

@bhennion bhennion left a comment

Choose a reason for hiding this comment

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

Here are a couple of comments. Mainly use SFINAO to default most members of the Setting<> specializations.

Also, there are quite a bit of clang-format changes in parts that you did not edit. Could you please remove those changes? They clutter the diff making the reviewing process more complicated and increase the number of conflicts you'll get if you ever need to rebase on a more up to date master branch.
Running git clang-format (as opposed to asking your IDE to apply clang-format) does exactly that: only apply clang-format to the chunks you modified.

src/core/control/settings/SettingsDescription.h Outdated Show resolved Hide resolved
src/core/plugin/luapi_application.h Outdated Show resolved Hide resolved
src/core/control/settings/SettingsDescription.h Outdated Show resolved Hide resolved
@superenginegit
Copy link
Author

Thanks for your comments, I'll incorporate them.

@superenginegit superenginegit marked this pull request as ready for review November 5, 2023 18:04
@rolandlo rolandlo mentioned this pull request Nov 7, 2023
Copy link
Contributor

@bhennion bhennion left a comment

Choose a reason for hiding this comment

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

That's a lot of work! Thanks!!
Here is a partial review. I'll come back for more (but that's a lot to review).
One question: shouldn't SElement be modified to have the same structure as the main Settings class (i.e. not being a std::map but rathen a template)?

src/core/control/settings/SettingsDescription.h Outdated Show resolved Hide resolved
src/core/control/settings/SettingsDescription.h Outdated Show resolved Hide resolved
src/core/control/settings/SettingsDescription.h Outdated Show resolved Hide resolved
src/core/control/settings/Settings.h Outdated Show resolved Hide resolved
@superenginegit
Copy link
Author

One question: shouldn't SElement be modified to have the same structure as the main Settings class (i.e. not being a std::map but rathen a template)?

I considered doing this, but I ultimately decided not to, as SElement is currently a very customizable container. Recreating it as a template would be very complicated, and I don't think it would be the best option for most of the settings currently using it.

I think it would be better to rework those settings and give them their own, unique type. For example lastUsedPageBgColor would work well as a vector I think, The touch nested setting should probably be just a struct (or maybe a class if necessary). Just for tools a nested structure would make sense, but that could be done similarly to how the buttonconfig or deviceclasses are currently implemented.

But I would rather do this in another PR as this one is already really big, and reworking those settings would create a lot of changes in additional files.

For this PR I would keep the SElement, and fix the issue with the const& you mentioned in Settings.h.

Copy link
Contributor

@bhennion bhennion left a comment

Choose a reason for hiding this comment

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

Here are some more comments.

Overall, I'm a bit confused about various declarations/definitions. For instance, the importProperty/exportProperty specializations feels misplaced. There are two kinds of such: "generic" specializations, e.g. importProperty, that are used by numerous settings and whose location is alright, and very specific specializations (e.g. importProperty(xmlNodePtr node, std::map<std::string, std::pair<InputDeviceTypeOption, GdkInputSource>>& var)) which should go directly as IMPORT_FN of the corresponding setting.

TBH, I'm a bit confused at the moment as to why it compiles and links properly while those importProperty<> specializations are only defined in the .cpp file but used in other units.

In addition:

  1. There are a couple of
    if (foo)
        bar()
    
    where braces should be added, to match our coding conventions.
  2. There are some C-style casts which should be replaced with static_cast.

src/core/control/settings/SettingsDescription.h Outdated Show resolved Hide resolved
src/core/control/settings/SettingsDescription.h Outdated Show resolved Hide resolved
src/core/control/settings/SettingsDescription.h Outdated Show resolved Hide resolved
src/core/control/settings/SettingsDescription.h Outdated Show resolved Hide resolved
src/core/control/settings/SettingsDescription.cpp Outdated Show resolved Hide resolved
src/core/control/settings/SettingsDescription.h Outdated Show resolved Hide resolved
src/core/control/settings/Settings.h Outdated Show resolved Hide resolved
src/core/control/settings/Settings.h Outdated Show resolved Hide resolved
src/core/control/settings/Settings.h Outdated Show resolved Hide resolved
src/core/control/settings/Settings.h Outdated Show resolved Hide resolved
@superenginegit
Copy link
Author

Thanks for the review, I have now addressed all of the points you mentioned.

  • Mainly I moved the import and export functions to a file of their own
  • Same for the getter_return, comment, etc. structs
  • I improved the comment, making it hopefully easier to understand
  • I removed the function array and map from the SettingsContainer class as members, the map is still generated in a member function, but is only allocated for the load function, the export functions are in a static loop
  • I also replaced c-style casts with static_cast, and I added braces to if statements (hope I didn't miss anything here)

@rolandlo
Copy link
Member

@superenginegit Can you please rebase on current master and solve the merge conflicts, so we can see if there are any (new) warnings on different platforms?

superenginegit and others added 20 commits November 29, 2023 14:52
added descriptions for settings
added needed import/export functions
added code that handles the new settings
adjusted some existing functions and classes
    in order to work with the new code
core/plugin/luapi_application.h modified to receive const XojFont&
Co-authored-by: Benjamin Hennion <17818041+bhennion@users.noreply.github.com>
Use getter_return_t to replace Setting::getter_return_type
Importer struct replaces most IMPORT_FN elements in
Settings that use the default importer for their type
Exporter struct replaces type default EXPORT_FN definitions
@rolandlo
Copy link
Member

The clang format should be fixed. I have found the following warning (just one), that should be fixed, too:

2023-11-29T18:31:02.1823240Z /Users/runner/work/1/s/src/core/control/settings/SettingsImExporters.cpp:706:33: warning: implicit conversion changes signedness: 'int' to 'std::array::size_type' (aka 'unsigned long') [-Wsign-conversion]
2023-11-29T18:31:02.1923240Z const auto& cfg = value[i];
2023-11-29T18:31:02.2001240Z ~~~~~ ^
2023-11-29T18:31:02.2101880Z 1 warning generated.

@superenginegit
Copy link
Author

@bhennion What do you think about the current status of this? Would you like to see any more changes?

@bhennion
Copy link
Contributor

Sorry for the delay. To be perfectly candid, I've been wondering whether this simplifies maintainability or not. It seems to me that we still need to edit in a lot of places to e.g. add a new setting.
Let me play around with it and I'll get back to you.

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

3 participants