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] support direct connection from widget value change to upda… #58611

Merged
merged 6 commits into from
Sep 12, 2024

Conversation

3nids
Copy link
Member

@3nids 3nids commented Sep 8, 2024

…te setting value

This is useful to remember last used values for instance.

There is an API break in QgsSettingsEditorWidgetWrapper. I would prefer to make the method pure virtual from the beginning. Considering the recently solved ticket of settings unregistration from plugin (#58595), it is pretty sure no one ever implemented a custom QgsSettingsEditorWidgetWrapper in python.

For instance, this code will set a combobox to display options from an enum with translations and auto save the last used option:

const auto *QgsVectorTileConnectionDialog::settingsLastLoadingMode = new QgsSettingsEntryEnumFlag<QgsVectorTileConnectionDialog::LoadingMode>( QStringLiteral( "vector-tile-loading-mode" ), QgsGui::sTtreeWidgetLastUsedValues, QgsVectorTileConnectionDialog::LoadingMode::Url, QString() ) ;

…

auto *settingsWidgetWrapper = new QgsSettingsEnumEditorWidgetWrapper<QgsVectorTileConnectionDialog::LoadingMode>( this );
settingsWidgetWrapper->setDisplayStrings(
{
  {LoadingMode::Style, tr( "Load from style" )},
  {LoadingMode::Url, tr( "Load from URL" )},
} );
settingsWidgetWrapper->configureEditor( mModeComboBox, settingsLastLoadingMode );
settingsWidgetWrapper->enableAutomaticUpdate();

@github-actions github-actions bot added this to the 3.40.0 milestone Sep 8, 2024
Copy link

github-actions bot commented Sep 8, 2024

🪟 Windows builds ready!

Windows builds of this PR are available for testing here. Debug symbols for this build are available here.

(Built from commit 8ded78f)

@3nids 3nids added the Squash! Remember to squash this PR, instead of merging or rebasing label Sep 10, 2024
@3nids
Copy link
Member Author

3nids commented Sep 11, 2024

@nyalldawson now, you can give a dialog, so it saves on accept.

src/gui/settings/qgssettingseditorwidgetwrapper.h Outdated Show resolved Hide resolved
*
* \since QGIS 3.40
*/
void configureAutomaticUpdate( QDialog *dialog = nullptr );
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I think this would be a bit better in my humble opinion :)

(also, you'll need a sip update, so good reason to do a final name tweak ;) )

Suggested change
void configureAutomaticUpdate( QDialog *dialog = nullptr );
void configureUpdateBehavior( QDialog *dialog = nullptr );

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer configureAutomaticUpdate because it actually enables the auto update (not direct if dialog, direct if no dialog)

Copy link
Contributor

Choose a reason for hiding this comment

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

@3nids , I guess yeah automatic update in that it'll automatically take care of updates (live update vs dialog close update). OK.

Co-authored-by: Mathieu Pellerin <nirvn.asia@gmail.com>
@3nids 3nids merged commit 0c8aee0 into qgis:master Sep 12, 2024
27 of 28 checks passed
@3nids 3nids deleted the settings-auto branch September 12, 2024 14:32
velle pushed a commit to velle/QGIS that referenced this pull request Sep 17, 2024
qgis#58611)

* [settings] support direct connection from widget value change to update setting value

* support automatic setting update on dialog accept

* add settings entry

* better name + fix typo

* Update src/gui/settings/qgssettingseditorwidgetwrapper.h

Co-authored-by: Mathieu Pellerin <nirvn.asia@gmail.com>

* sipify

---------

Co-authored-by: Mathieu Pellerin <nirvn.asia@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Squash! Remember to squash this PR, instead of merging or rebasing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants