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

[forms] Allow users to copy and paste form widget configurations from one field to another #46

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

gacarrillor
Copy link
Owner

@gacarrillor gacarrillor commented Nov 9, 2024

When configuring forms using the Drag and Drop Designer in layers with multiple fields, chances are we want to set similar or even the same configurations for a number of them. This process is currently manual, which ends up being a bit tedious and error prone.

This PR adds a handy context menu (in the Vector properties dialog, Attributes Form tab, Available Widgets tree, Fields category, :) ), allowing users to copy widget configurations between fields, and thus, saving time and making sure of not missing a particular setting by mistake.

Implementation details:

  • Copy&paste of widget configuration can be done between fields of the same layer, between fields from different layers in the QGIS project, or between fields from layers in different QGIS instances.
  • Pasted widget configuration overwrites the target one, but is not applied automatically, so that users can see the pasted configuration and possibly tune it and apply it or avoid saving it by cancelling the dialog or just selecting another field.
  • We avoid copying aliases and comments. The target field ones are respected.
  • We only paste "editor widget configs" when the target field supports the source editor widget type. Otherwise, we leave the target editor widget type and config intact.
  • Target provider constraints are kept, we only paste constraints with layer origin.

Fix 58971

Funded by (?)

…y and paste configuration actions: copy form config to clipboard and paste form config from clipboard (partial)
@gacarrillor
Copy link
Owner Author

gacarrillor commented Nov 9, 2024

@3nids, before showing this to the world, could you please have a look at this PR?

Do we need QGIS_PROTECT_QOBJECT_THREAD_ACCESS in both copy and paste slots?

Note: I'll still tweak pasting constraints, since the use case of pasting an unset constraint on an already set one is currently missing. Done.

Copy link

github-actions bot commented Nov 9, 2024

🪟 Windows builds

Download Windows builds of this PR for testing.
Debug symbols for this build are available here.
(Built from commit 74fb263)

…a forceWidgetRefresh param and passing it as true when pasting; note we've respected the previous behavior (i.e., other calls still don't force a refresh) because it seems to be handy to switch between editor widget types (via GUI) without losing the config
… layout; since we only update GUI widgets (and don't automatically store pasted settings into tree item data nor in the field settings themselves), we've added handy methods to edit them
@3nids
Copy link

3nids commented Nov 11, 2024

Looking good!


void QgsAttributesFormProperties::copyWidgetConfiguration()
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
Copy link

Choose a reason for hiding this comment

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

I would say they're not requires in these slots.


const QgsField field = mLayer->fields().field( index );

// We won't copy field aliases nor comments
Copy link

Choose a reason for hiding this comment

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

I would discuss about aliases. I would say it's quite common to have the field in english and have the translated alias. So that would make sense to me to also copy it.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Please post this in the original issue to discuss it with A. Poncet.

Actually, I've already used this copy&paste functionality (because it was handy for migrating a QGIS project for the Siemens project) and keeping the aliases intact seemed like a good idea. But, let's see what A. Poncet says about the use case you're mentioning.


// Only paste if source editor widget type is supported by target field
const QgsEditorWidgetFactory *factory = QgsGui::editorWidgetRegistry()->factory( widgetType );
if ( factory->supportsField( mLayer, fieldIndex ) )
Copy link

Choose a reason for hiding this comment

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

could we get a form of user feedback on the reason it fails?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Sure, I'd thought of just logging it so that it's shown in the QGIS log window.

What would be your preferred way?

Copy link

Choose a reason for hiding this comment

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

There is the message bar available.

But I thought there would be a message bar in the dialog, that might be worth adding one like in QgsAttributeForm.

…traints can be both added and removed from the target field
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.

2 participants