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

Set display expression when adding fields through attribute table (fix #28353) #46978

Merged
merged 1 commit into from
Jan 27, 2022
Merged

Set display expression when adding fields through attribute table (fix #28353) #46978

merged 1 commit into from
Jan 27, 2022

Conversation

alexbruy
Copy link
Contributor

Description

If vector layer created without any attributes and then new fields are added via attributes table then display expression is not set. As a result "Features in All layers" locator filter shows [Please define preview text] instead of the real values.

Fixes #28353.

@github-actions github-actions bot added this to the 3.24.0 milestone Jan 24, 2022
@@ -890,14 +890,18 @@ void QgsAttributeTableDialog::mActionAddAttribute_triggered()
if ( mLayer->addAttribute( dialog.field() ) )
{
mLayer->endEditCommand();

if ( mLayer->displayExpression() == QStringLiteral( "'[Please define preview text]'" ) )
Copy link
Member

Choose a reason for hiding this comment

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

Is this working?
Normally the dual view shouldn't be setting the layer display expression from there directly.
Otherwise the code should be adapted in dual view too.

At the same time, it would be worth making the text translated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I can see, this text is set as a display expression in the dual view https://github.com/qgis/QGIS/blob/master/src/gui/attributetable/qgsdualview.cpp#L222 and it is not translated.

Copy link
Member

Choose a reason for hiding this comment

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

yes as display expression for the dual view, but I am not sure it's set back on the layer
It depends on what QgsFeatureListModel::setDisplayExpression returns. This needs to be tested.

Copy link
Member

Choose a reason for hiding this comment

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

thanks to the changes in #47016 you can now test if it is empty

Suggested change
if ( mLayer->displayExpression() == QStringLiteral( "'[Please define preview text]'" ) )
if ( mLayer->displayExpression().isEmpty() )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, changed.

@3nids 3nids merged commit 46307f7 into qgis:master Jan 27, 2022
@alexbruy alexbruy deleted the display-expression branch January 27, 2022 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display name in layer properties is not automatically filled
2 participants