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

Save enum values as string in settings #6733

Merged
merged 6 commits into from
May 17, 2018
Merged

Conversation

3nids
Copy link
Member

@3nids 3nids commented Apr 2, 2018

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 as value 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.

@3nids 3nids requested a review from m-kuhn April 2, 2018 12:53
@nyalldawson
Copy link
Collaborator

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...

QMetaEnum metaEnum = QMetaEnum::fromType<T>();
if ( !metaEnum.isValid() )
{
QgsDebugMsg( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." );
Copy link
Member

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?

Copy link
Member

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." );
Copy link
Member

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.

@m-kuhn
Copy link
Member

m-kuhn commented Apr 3, 2018

Good job!

The more I think about it, the more I think we need some way to "register" settings

I agree an optional registration for settings would be great.

@m-kuhn m-kuhn closed this Apr 17, 2018
@m-kuhn m-kuhn reopened this Apr 17, 2018
@m-kuhn
Copy link
Member

m-kuhn commented May 4, 2018

@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'm not convinced we'll make our devs happier with this requirement.

I'd be in favor of proceeding this pull request as is, and then look at the other project as a follow up step.

3nids added 3 commits May 14, 2018 08:47
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
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.

4 participants