Skip to content
Permalink
Browse files
On add select all addded features
  • Loading branch information
domi4484 committed Nov 8, 2021
1 parent 20c79cd commit 3c5216b6a950d873b982bbee6c95814bfd01421d
@@ -186,7 +186,7 @@ Toggles editing state of the widget
Saves the current modifications in the relation
%End

void addFeature( const QgsGeometry &geometry = QgsGeometry() );
QgsFeatureIds addFeature( const QgsGeometry &geometry = QgsGeometry() );
%Docstring
Adds a new feature with given ``geometry``
%End
@@ -203,7 +203,7 @@ void QgsAbstractRelationEditorWidget::saveEdits()
mEditorContext.vectorLayerTools()->saveEdits( mNmRelation.referencedLayer() );
}

void QgsAbstractRelationEditorWidget::addFeature( const QgsGeometry &geometry )
QgsFeatureIds QgsAbstractRelationEditorWidget::addFeature( const QgsGeometry &geometry )
{
QgsAttributeMap keyAttrs;

@@ -212,6 +212,8 @@ void QgsAbstractRelationEditorWidget::addFeature( const QgsGeometry &geometry )
// Fields of the linking table
const QgsFields fields = mRelation.referencingLayer()->fields();

QgsFeatureIds addedFeatureIds;

// For generated relations insert the referenced layer field
if ( mRelation.type() == QgsRelation::Generated )
{
@@ -228,7 +230,9 @@ void QgsAbstractRelationEditorWidget::addFeature( const QgsGeometry &geometry )
// and autocreate a new linking feature.
QgsFeature finalFeature;
if ( !vlTools->addFeature( mNmRelation.referencedLayer(), QgsAttributeMap(), geometry, &finalFeature ) )
return;
return QgsFeatureIds();

addedFeatureIds.insert( finalFeature.id() );

// Expression context for the linking table
QgsExpressionContext context = mRelation.referencingLayer()->createExpressionContext();
@@ -264,7 +268,9 @@ void QgsAbstractRelationEditorWidget::addFeature( const QgsGeometry &geometry )

QgsFeature linkFeature;
if ( !vlTools->addFeature( mRelation.referencingLayer(), keyAttrs, geometry, &linkFeature ) )
return;
return QgsFeatureIds();

addedFeatureIds.insert( linkFeature.id() );

// In multiedit add to other features to but whitout dialog
for ( const QgsFeature &feature : mFeatureList )
@@ -277,10 +283,13 @@ void QgsAbstractRelationEditorWidget::addFeature( const QgsGeometry &geometry )
linkFeature.setAttribute( fields.indexFromName( fieldPair.referencingField() ), feature.attribute( fieldPair.referencedField() ) );

mRelation.referencingLayer()->addFeature( linkFeature );
addedFeatureIds.insert( linkFeature.id() );
}
}

updateUi();

return addedFeatureIds;
}

void QgsAbstractRelationEditorWidget::deleteFeature( const QgsFeatureId fid )
@@ -199,7 +199,7 @@ class GUI_EXPORT QgsAbstractRelationEditorWidget : public QWidget
/**
* Adds a new feature with given \a geometry
*/
void addFeature( const QgsGeometry &geometry = QgsGeometry() );
QgsFeatureIds addFeature( const QgsGeometry &geometry = QgsGeometry() );

/**
* Delete a feature with given \a fid
@@ -231,7 +231,7 @@ QgsRelationEditorWidget::QgsRelationEditorWidget( const QVariantMap &config, QWi
#endif
connect( mToggleEditingButton, &QAbstractButton::clicked, this, &QgsRelationEditorWidget::toggleEditing );
connect( mSaveEditsButton, &QAbstractButton::clicked, this, &QgsRelationEditorWidget::saveEdits );
connect( mAddFeatureButton, &QAbstractButton::clicked, this, [this]() { addFeature(); } );
connect( mAddFeatureButton, &QAbstractButton::clicked, this, &QgsRelationEditorWidget::addFeature );
connect( mAddFeatureGeometryButton, &QAbstractButton::clicked, this, &QgsRelationEditorWidget::addFeatureGeometry );
connect( mDuplicateFeatureButton, &QAbstractButton::clicked, this, &QgsRelationEditorWidget::duplicateSelectedFeatures );
connect( mDeleteFeatureButton, &QAbstractButton::clicked, this, &QgsRelationEditorWidget::deleteSelectedFeatures );
@@ -382,6 +382,29 @@ void QgsRelationEditorWidget::updateButtons()
mZoomToFeatureButton->setVisible( mButtonsVisibility.testFlag( QgsRelationEditorWidget::Button::ZoomToChildFeature ) && mEditorContext.mapCanvas() && spatial );
}

void QgsRelationEditorWidget::addFeature()
{
const QgsFeatureIds addedFeatures = QgsAbstractRelationEditorWidget::addFeature();

if ( !multiEditModeActive() )
return;

QTreeWidgetItemIterator treeWidgetItemIterator( mMultiEditTreeWidget );
while ( *treeWidgetItemIterator )
{
if ( ( *treeWidgetItemIterator )->data( 0, static_cast<int>( MultiEditTreeWidgetRole::FeatureType ) ).toInt() != static_cast<int>( MultiEditFeatureType::Child ) )
{
++treeWidgetItemIterator;
continue;
}

if ( addedFeatures.contains( ( *treeWidgetItemIterator )->data( 0, static_cast<int>( MultiEditTreeWidgetRole::FeatureId ) ).toInt() ) )
( *treeWidgetItemIterator )->setSelected( true );

++treeWidgetItemIterator;
}
}

void QgsRelationEditorWidget::addFeatureGeometry()
{
if ( multiEditModeActive() )
@@ -419,7 +442,7 @@ void QgsRelationEditorWidget::addFeatureGeometry()

void QgsRelationEditorWidget::onDigitizingCompleted( const QgsFeature &feature )
{
addFeature( feature.geometry() );
QgsAbstractRelationEditorWidget::addFeature( feature.geometry() );

unsetMapTool();
}
@@ -201,6 +201,7 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsAbstractRelationEditorWidge
void setViewMode( int mode ) {setViewMode( static_cast<QgsDualView::ViewMode>( mode ) );}
void updateButtons();

void addFeature();
void addFeatureGeometry();
void toggleEditing( bool state );
void showContextMenu( QgsActionMenu *menu, QgsFeatureId fid );

0 comments on commit 3c5216b

Please sign in to comment.