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

Settings registry qep124 #42239

Closed
wants to merge 377 commits into from
Closed

Conversation

domi4484
Copy link
Contributor

@domi4484 domi4484 commented Mar 15, 2021

As of Enhancement proposal #124 and as followup to closed pr #41830 the goals of this pull request are to make the usage of settings less prone to errors.

In this proposed solution a new class QgsSettingsEntry is introduced. One instance will correspond to a single settings entry (or key) in QSettings.

The idea is to declare settings by subclassing QgsSettingsEntry in the class of appartenance of the settings like this for QgsLayout.h:

struct Settings
{
  struct SearchPathForTemplates : public QgsSettingsEntryStringList
  {
    //                                                     Settings key,                     Section,           Default value,              Description,      ... Other metadata like limits, gui hints, ...
    SearchPathForTemplates() : QgsSettingsEntryStringList( "Layout/searchPathsForTemplates", QgsSettings::Core, QStringList(), QObject::tr( "Search path for templates" ) ) {}
  };
};

and used like this:

QgsLayout::Settings::SearchPathForTemplates().setValue( QStringList() << "/path1" << "/path2" );

The declaration will be shortened with a macro:

QGS_SETTING_ENTRY_STRINGLIST( SearchPathForTemplates, QStringLiteral( "Layout/searchPathsForTemplates" ), QgsSettings::Core, QStringList(), tr( "Search path for templates" ) )

For settings with a dynamic key a placeholder can be inserted in the key:

struct Settings
{
  QGS_SETTING_ENTRY_BOOL( LocatorFilterEnabled, QStringLiteral( "locator_filters/enabled_%" ), QgsSettings::Gui, true, tr( "Enabled" ) )
  QGS_SETTING_ENTRY_BOOL( LocatorFilterDefault, QStringLiteral( "locator_filters/default_%" ), QgsSettings::Gui, false, tr( "Default value" ) )
  QGS_SETTING_ENTRY_STRING( LocatorFilterPrefix, QStringLiteral( "locator_filters/prefix_%" ), QgsSettings::Gui, QString(), tr( "Locator filter prefix" ) )
};

and can be accessed providing the dynamic part of the key as argument:

QgsLocator::Settings::LocatorFilterEnabled().setValue( it.value(), filter->name() );

The settings registry in this solution would be needed only for introspection and it is simply implemented as a list of QgsSettingsEntry instances. Each module or plugin would have his own registry and add the settings to the main registry on load/startup.

This approach is more flexible as the one proposed in pr #41830 as it permit to keep the key and section as they are now. No migration will be needed as result of this work. Nonetheless it addresses all the issues exposed in the QEP.

@domi4484 domi4484 marked this pull request as draft March 15, 2021 08:25
@domi4484
Copy link
Contributor Author

Hello @elpaso and @nyalldawson , could you please take a look at this new proposed solution and let me know your thoughts? Thank you!

@github-actions github-actions bot added this to the 3.20.0 milestone Mar 15, 2021
@3nids
Copy link
Member

3nids commented Mar 24, 2021

gentle ping @nyalldawson and @elpaso
Time is getting short for the grants, and we'd like to move on here.

@elpaso
Copy link
Contributor

elpaso commented Mar 25, 2021

@3nids @domi4484 sorry for the delay.

I like the new approach.

I don't have time for an in-depth review so my only comment for now is that if you can avoid the macro: do we have an alternative (maybe a template)?

nirvn and others added 25 commits March 31, 2021 14:05
This means, someone still cares.
We will still need to take care of manually removing the "feedback" label
shape out into a new class so that it can be reused elsewhere
Renders a nice cartographically pleasing curved line between the
labels and features.

Options include selecting a specific curve orientation (clockwise
or counterclockwise), or an automatic orientation option which
determines optimal orientation for each individual label. Users
also have control over the amount of curvature applied to the
callout lines.
- Remove extra indentation of code blocks that made copy'n'pasting ugly
	- Probably fixed in indentation bug for `~/.config/QtProject/qtlogging.ini`
- Some homogenization of code markup, didn't look through all parts of the document though
- Turn inline comments into actual `#` comments
- In Server part:
  - Use "example.com" for example domains
  - Be more explicite about paths
- I also tried to fix some formatting markup
m-kuhn and others added 26 commits March 31, 2021 14:06
for QTextStream and QSettings
QgsAbstractRelationEditorWidget need to update/insert the referenced
layer field also when an nm relation is used. This was not the case
for addFeature and linkFeature methods.
Replace deprecated QgsCodeEditor setMarginVisible() with setLineNumbersVisible() for SQL dialog windows
The compile flag prevents the Qt plugins from being loaded in the debug
build. The flag is automatically set by the Qt cmake module for release
builds.
show a combo box for the default date choice instead of a free-form
date widget

This makes it easier for users to pick a valid default date for
the layer, corresponding to a value where data actually exists...
QgsMapToolExtent

Otherwise plugins have no way to remove this from the canvas
Co-authored-by: Nyall Dawson <nyall.dawson@gmail.com>
Unfortunately QgsVectorFileWriter::writeAsVectorFormatV2 is missing
SIP_OUT arguments necessary to get the desired output arguments,
and it's not possible to add these now without breaking existing PyQGIS
code.

Solution = v3!
@domi4484
Copy link
Contributor Author

Sorry I screwed up my git branch and opened a new clean pr here: #42597

@domi4484 domi4484 closed this Mar 31, 2021
@domi4484 domi4484 deleted the settingsRegistryQep124 branch April 29, 2021 10:56
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.