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

When loading a QLR, try to match the layer name if id does not #30151

Conversation

elpaso
Copy link
Contributor

@elpaso elpaso commented Jun 10, 2019

Fixes #30115

@elpaso elpaso added backport release-3_4 Bug Either a bug report, or a bug fix. Let's hope for the latter! labels Jun 10, 2019
@@ -70,6 +71,23 @@ QVariantMap QgsValueRelationConfigDlg::config()
void QgsValueRelationConfigDlg::setConfig( const QVariantMap &config )
{
QgsVectorLayer *lyr = QgsProject::instance()->mapLayer<QgsVectorLayer *>( config.value( QStringLiteral( "Layer" ) ).toString() );
// If layer is null, let's try to match it against name and provider
if ( ! lyr )
Copy link
Collaborator

Choose a reason for hiding this comment

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

Look into QgsVectorLayerRef, and QgsMapLayerRef::resolveWeakly. It's designed to encapsulate all this logic for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked into that, I don't think it fits here, we don't want to check for datasource and provider type, there is a strong use case for layers migrated into a DB where datasource and provided type have changed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm - so we need a "resolveSuperWeakly" method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe, I would probably prefer to have a template based getLayersByName and get the first element out of the results if not empty.

@elpaso elpaso force-pushed the bugfix-gh30115-value-relation-widget-match-name-if-id-fails branch from f9977e9 to 0328a23 Compare June 10, 2019 15:49
@elpaso elpaso force-pushed the bugfix-gh30115-value-relation-widget-match-name-if-id-fails branch from 0328a23 to 103ef76 Compare June 10, 2019 15:58
@nyalldawson
Copy link
Collaborator

Nice, I really like the latest iteration

@elpaso elpaso merged commit e740688 into qgis:master Jun 11, 2019
@backporting
Copy link
Contributor

backporting bot commented Jun 11, 2019

The backport to release-3_4 failed:

Commits ["f02b1ee1d1199788112babd5498ee029b9e31fb9","dcc779a62d2b6126e3ff468c7d9ec0991ad0b829","f9b50b5b386ceb573b7ffbb54c0cd817d83859d9","a2957010231bc0634fda626ace16f83010fea0ba","a45a82e8d744c353e23effc24c5e0ce0df3042a7","103ef762ca7247b013df61e149516e50b40e5214","fc20e31fa397da8af39dc70bd31b76121e62477f","6bd5c51dfcf1860c93565ee566156f259ca05bc0","2d45ba8d68dd6ef56c25bfb6d0e107d6435f0e9e"] could not be cherry-picked on top of release-3_4

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub.
git fetch
# Create new working tree.
git worktree add .worktrees/backport release-3_4
# Navigate to the new directory.
cd .worktrees/backport
# Cherry-pick all the commits of this pull request and resolve the likely conflicts.
git cherry-pick f02b1ee1d1199788112babd5498ee029b9e31fb9 dcc779a62d2b6126e3ff468c7d9ec0991ad0b829 f9b50b5b386ceb573b7ffbb54c0cd817d83859d9 a2957010231bc0634fda626ace16f83010fea0ba a45a82e8d744c353e23effc24c5e0ce0df3042a7 103ef762ca7247b013df61e149516e50b40e5214 fc20e31fa397da8af39dc70bd31b76121e62477f 6bd5c51dfcf1860c93565ee566156f259ca05bc0 2d45ba8d68dd6ef56c25bfb6d0e107d6435f0e9e
# Create a new branch with these backported commits.
git checkout -b backport-30151-to-release-3_4
# Push it to GitHub.
git push --set-upstream origin backport-30151-to-release-3_4
# Go back to the original working tree.
cd ../..
# Delete the working tree.
git worktree remove .worktrees/backport

Then, create a pull request where the base branch is release-3_4 and the compare/head branch is backport-30151-to-release-3_4.

@elpaso elpaso deleted the bugfix-gh30115-value-relation-widget-match-name-if-id-fails branch July 8, 2019 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Value relation widget settings lost on import of layer definition file
3 participants