-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Save enum values as string in settings #6733
Conversation
Nice! The more I think about it, the more I think we need some way to "register" settings. Then we could provide a little descriptive text for them (shown in tooltips in the advanced settings editor) AND we could build off this PR to show combo-boxes for enum-type settings too (by registering the enum associated with the setting). We could then also generate the whole global settings ini through a script too... |
src/core/qgssettings.h
Outdated
QMetaEnum metaEnum = QMetaEnum::fromType<T>(); | ||
if ( !metaEnum.isValid() ) | ||
{ | ||
QgsDebugMsg( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be a Q_ASSERT
to prevent devs from using this the wrong way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or is the usage widespread throughout the code and we need this for legacy fallback?
} | ||
else | ||
{ | ||
QgsDebugMsg( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good to include key
and value
in the debug message.
Good job!
I agree an optional registration for settings would be great. |
@nyalldawson what's your opinion, would you say there needs to be a comprehensive registry and no settings are allowed to exist without being registered? I'd be in favor of proceeding this pull request as is, and then look at the other project as a follow up step. |
there is a small redundancy in code, but it makes it much nicer to read the calls: flagValue( key, default) instead of enumValue( key, default, NoSection, false )
and complete missing enumValue
This allows to save enum values as strings in the settings, making it clearer when looking into advanced panel.
There is no API break but this might cause issue in Python since one would need to use
enumValue
to get the enum value asvalue
would now return a string and not an integer anymore.From what I see, I think the main issue would be the snapping settings which might be used by plugin devs.
Python API still has to be made, just waiting for feedback if this is reasonable or not.
If not, we could introduce the API (for new enums) and do the switch in next major version.