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

Fix invalid attributes dialog on copy to another layer #33688

Merged
merged 10 commits into from
Jan 15, 2020

Conversation

signedav
Copy link
Contributor

@signedav signedav commented Jan 9, 2020

It's possible to copy features from one layer to another.
If there are the same fields in the destination layer, then the attributes for them are taken from the original feature. If not, the default value is taken. Otherwise the new attribute is null.

If the destination layer has constraints on the fields, these should be fulfilled now or disregarded on purpose. But not just copied invalid like it used to do.

That's why now the attributes are checked against the constraints. And for all the invalid features a dialog pops up.
copy-dialog_2

And on pasting only one feature, the options are reduced:
copy_paste_single

Maybe there could be added in future a multi edit function.

if ( !QgsVectorLayerUtils::validateAttribute( pasteVectorLayer, f, idx, errors, QgsFieldConstraints::ConstraintStrengthHard, QgsFieldConstraints::ConstraintOriginNotSet ) )
{
invalidFeatures << f;
validFeatures.removeOne( f );
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can't modify a qlist while iterating over it like this. You'd need to use a modifiable iterator instead and .erase the current entry.

// check constraints
QgsFeatureList validFeatures = newFeatures;
QgsFeatureList invalidFeatures;
for ( const QgsFeature &f : qgis::as_const( validFeatures ) )
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we skip this whole loop if no constraints are present? I'm concerned about a regression in paste time for huge numbers of features.

QgsFixAttributeDialog *dialog = new QgsFixAttributeDialog( pasteVectorLayer, invalidFeatures, this );
int feedback = dialog->exec();

if ( feedback == QgsFixAttributeDialog::VanishAll )
Copy link
Collaborator

Choose a reason for hiding this comment

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

Switch instead of if

void QgsFixAttributeDialog::init( QgsVectorLayer *layer )
{
QgsAttributeEditorContext context;
setWindowTitle( tr( "%1 - Fix Pastet Features" ).arg( layer->name() ) );
Copy link
Collaborator

Choose a reason for hiding this comment

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

"pasted"

layout()->addWidget( mAttributeForm );

QDialogButtonBox *buttonBox = mAttributeForm->findChild<QDialogButtonBox *>();
QPushButton *cancelAllBtn = new QPushButton( tr( "Cancel all" ) );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fix capitalisation for buttons (should be title case)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually these strings are a bit confusing. I'd go with "discard all", "discard all invalid features" and "paste all (including invalid)".

Copy link
Collaborator

Choose a reason for hiding this comment

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

@nirvn these buttons are very long - got any ideas on alternative ui?

* \since 3.12
*/

class GUI_EXPORT QgsFixAttributeDialog : public QDialog
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe leave in app for now?

*/
enum Feedback
{
VanishAll, //!< Feedback to cancel copy of all features (even valid ones)
Copy link
Collaborator

Choose a reason for hiding this comment

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

DIscardAll

@github-actions github-actions bot added this to the 3.12.0 milestone Jan 10, 2020
@signedav signedav added the Needs Documentation When merging a labeled PR, an issue will be created in the Doc repo. label Jan 13, 2020
@qgis-bot
Copy link
Collaborator

@signedav
This pull request has been tagged as requiring documentation.

A documentation ticket will be opened at https://github.com/qgis/QGIS-Documentation when this PR is merged.

Please update the description (not the comments) with helpful description and screenshot to help the work from documentors.
Also, any commit having [needs-doc] or [Needs Documentation] in will see its message pushed to the issue, so please be as verbose as you can.

Thank you!

@nyalldawson
Copy link
Collaborator

Looks good to me

@signedav signedav merged commit 993fa38 into qgis:master Jan 15, 2020
@signedav
Copy link
Contributor Author

Thanks @nyalldawson

@qgis-bot
Copy link
Collaborator

@signedav
A documentation ticket has been opened at qgis/QGIS-Documentation#4784
It is your responsibility to visit this ticket and add as much detail as possible for the documentation team to correctly document this change.
Thank you!

@timlinux timlinux added the Changelog Items that are queued to appear in the visual changelog - remove after harvesting label Mar 2, 2020
@qgis-bot
Copy link
Collaborator

qgis-bot commented Mar 2, 2020

@signedav
This pull request has been tagged as requiring documentation.

A documentation ticket will be opened at https://github.com/qgis/QGIS-Documentation when this PR is merged.

Please update the description (not the comments) with helpful description and screenshot to help the work from documentors.
Also, any commit having [needs-doc] or [Needs Documentation] in will see its message pushed to the issue, so please be as verbose as you can.

Thank you!

@qgis-bot
Copy link
Collaborator

qgis-bot commented Mar 2, 2020

@signedav
A documentation ticket has been opened at qgis/QGIS-Documentation#4952
It is your responsibility to visit this ticket and add as much detail as possible for the documentation team to correctly document this change.
Thank you!

@timlinux timlinux removed the Changelog Items that are queued to appear in the visual changelog - remove after harvesting label May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Needs Documentation When merging a labeled PR, an issue will be created in the Doc repo.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants