Skip to content
Permalink
Browse files

handledLayers and handledFeatures in DeleteContext to be able to use …

…it in python as well
  • Loading branch information
signedav committed May 11, 2020
1 parent fd7edae commit f5d35dd18fa9fd5179629382d4b044144d4014c4
@@ -382,10 +382,8 @@ Constructor for LayerOptions.
Constructor for DeleteContext.
%End

QMap<QgsVectorLayer *, QgsFeatureIds> handledFeatures();
%Docstring
Returns all the layers on which features have been deleted
%End
QList<QgsVectorLayer *> handledLayers() const;
QgsFeatureIds handledFeatures( QgsVectorLayer *layer ) const;

bool cascade;
};
@@ -9033,12 +9033,12 @@ void QgisApp::deleteSelected( QgsMapLayer *layer, QWidget *parent, bool checkFea
else
{
//if it effected more than one layer, print feedback for all descendants
if ( context.handledFeatures().size() > 1 )
if ( context.mHandledFeatures.size() > 1 )
{
deletedCount = 0;
QString feedbackMessage;
QMap<QgsVectorLayer *, QgsFeatureIds>::const_iterator i;
for ( i = context.handledFeatures().begin(); i != context.handledFeatures().end(); ++i )
for ( i = context.mHandledFeatures.begin(); i != context.mHandledFeatures.end(); ++i )
{
feedbackMessage += tr( " %1 on layer %2." ).arg( i.value().size() ).arg( i.key()->name() );
deletedCount += i.value().size();
@@ -888,12 +888,12 @@ void QgsAttributeTableDialog::deleteFeature( const QgsFeatureId fid )
QgsVectorLayer::DeleteContext context { true };
mLayer->deleteFeature( fid, &context );
//if it effected more than one layer, print feedback for all descendants
if ( context.handledFeatures().size() > 1 )
if ( context.mHandledFeatures.size() > 1 )
{
int deletedCount = 0;
QString feedbackMessage;
QMap<QgsVectorLayer *, QgsFeatureIds>::const_iterator i;
for ( i = context.handledFeatures().begin(); i != context.handledFeatures().end(); ++i )
for ( i = context.mHandledFeatures.begin(); i != context.mHandledFeatures.end(); ++i )
{
feedbackMessage += tr( " %1 on layer %2." ).arg( i.value().size() ).arg( i.key()->name() );
deletedCount += i.value().size();
@@ -5529,3 +5529,17 @@ void QgsVectorLayer::onDirtyTransaction( const QString &sql, const QString &name
qobject_cast<QgsVectorLayerEditPassthrough *>( mEditBuffer )->update( tr, sql, name );
}
}

QList<QgsVectorLayer *> QgsVectorLayer::DeleteContext::handledLayers() const
{
QList<QgsVectorLayer *> layers;
QMap<QgsVectorLayer *, QgsFeatureIds>::const_iterator i;
for ( i = mHandledFeatures.begin(); i != mHandledFeatures.end(); ++i )
layers.append( i.key() );
return layers;
}

QgsFeatureIds QgsVectorLayer::DeleteContext::handledFeatures( QgsVectorLayer *layer ) const
{
return mHandledFeatures[layer];
}
@@ -516,10 +516,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*/
explicit DeleteContext( bool cascade = false ): cascade( cascade ) {}

/**
* Returns all the layers on which features have been deleted
*/
QMap<QgsVectorLayer *, QgsFeatureIds> handledFeatures() { return mHandledFeatures; }
QList<QgsVectorLayer *> handledLayers() const;
QgsFeatureIds handledFeatures( QgsVectorLayer *layer ) const;

QMap<QgsVectorLayer *, QgsFeatureIds> mHandledFeatures SIP_SKIP;
bool cascade;
@@ -752,12 +752,12 @@ void QgsRelationEditorWidget::deleteFeatures( const QgsFeatureIds &featureids )
{
QgsVectorLayer::DeleteContext context { true };
layer->deleteFeatures( featureids, &context );
if ( context.handledFeatures().size() > 1 )
if ( context.mHandledFeatures.size() > 1 )
{
int deletedCount = 0;
QString feedbackMessage;
QMap<QgsVectorLayer *, QgsFeatureIds>::const_iterator i;
for ( i = context.handledFeatures().begin(); i != context.handledFeatures().end(); ++i )
for ( i = context.mHandledFeatures.begin(); i != context.mHandledFeatures.end(); ++i )
{
feedbackMessage += tr( " %1 on layer %2." ).arg( i.value().size() ).arg( i.key()->name() );
deletedCount += i.value().size();

0 comments on commit f5d35dd

Please sign in to comment.
You can’t perform that action at this time.