Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
On add select all addded features
  • Loading branch information
domi4484 committed Nov 8, 2021
1 parent 20c79cd commit 3c5216b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions src/gui/qgsabstractrelationeditorwidget.cpp
Expand Up @@ -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;

Expand All @@ -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 )
{
Expand All @@ -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();
Expand Down Expand Up @@ -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 )
Expand All @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsabstractrelationeditorwidget.h
Expand Up @@ -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
Expand Down
27 changes: 25 additions & 2 deletions src/gui/qgsrelationeditorwidget.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -419,7 +442,7 @@ void QgsRelationEditorWidget::addFeatureGeometry()

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

unsetMapTool();
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsrelationeditorwidget.h
Expand Up @@ -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 );
Expand Down

0 comments on commit 3c5216b

Please sign in to comment.