Skip to content
Permalink
Browse files

Merge pull request #5925 from signedav/duplicateChildsRelation

[FEATURE] Duplicate child feature in releationwidget of attributeform
  • Loading branch information
m-kuhn committed Jan 8, 2018
2 parents 8dfb17d + 7d4290d commit 886e7bf8d3c901d53f78f21ff209657127e81052
Showing with 24 additions and 0 deletions.
  1. +22 −0 src/gui/qgsrelationeditorwidget.cpp
  2. +2 −0 src/gui/qgsrelationeditorwidget.h
@@ -66,6 +66,13 @@ QgsRelationEditorWidget::QgsRelationEditorWidget( QWidget *parent )
mAddFeatureButton->setToolTip( tr( "Add child feature" ) );
mAddFeatureButton->setObjectName( QStringLiteral( "mAddFeatureButton" ) );
buttonLayout->addWidget( mAddFeatureButton );
// duplicate feature
mDuplicateFeatureButton = new QToolButton( this );
mDuplicateFeatureButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionDuplicateFeature.svg" ) ) );
mDuplicateFeatureButton->setText( tr( "Duplicate child feature" ) );
mDuplicateFeatureButton->setToolTip( tr( "Duplicate child feature" ) );
mDuplicateFeatureButton->setObjectName( QStringLiteral( "mDuplicateFeatureButton" ) );
buttonLayout->addWidget( mDuplicateFeatureButton );
// delete feature
mDeleteFeatureButton = new QToolButton( this );
mDeleteFeatureButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionDeleteSelected.svg" ) ) );
@@ -130,6 +137,7 @@ QgsRelationEditorWidget::QgsRelationEditorWidget( QWidget *parent )
connect( mToggleEditingButton, &QAbstractButton::clicked, this, &QgsRelationEditorWidget::toggleEditing );
connect( mSaveEditsButton, &QAbstractButton::clicked, this, &QgsRelationEditorWidget::saveEdits );
connect( mAddFeatureButton, &QAbstractButton::clicked, this, &QgsRelationEditorWidget::addFeature );
connect( mDuplicateFeatureButton, &QAbstractButton::clicked, this, &QgsRelationEditorWidget::duplicateFeature );
connect( mDeleteFeatureButton, &QAbstractButton::clicked, this, &QgsRelationEditorWidget::deleteFeature );
connect( mLinkFeatureButton, &QAbstractButton::clicked, this, &QgsRelationEditorWidget::linkFeature );
connect( mUnlinkFeatureButton, &QAbstractButton::clicked, this, &QgsRelationEditorWidget::unlinkFeature );
@@ -286,6 +294,7 @@ void QgsRelationEditorWidget::updateButtons()
}

mAddFeatureButton->setEnabled( editable );
mDuplicateFeatureButton->setEnabled( editable && selectionNotEmpty );
mLinkFeatureButton->setEnabled( linkable );
mDeleteFeatureButton->setEnabled( editable && selectionNotEmpty );
mUnlinkFeatureButton->setEnabled( linkable && selectionNotEmpty );
@@ -425,6 +434,19 @@ void QgsRelationEditorWidget::linkFeature()
}
}

void QgsRelationEditorWidget::duplicateFeature()
{
QgsVectorLayer *layer = mRelation.referencingLayer();

QgsFeatureIterator fit = layer->getFeatures( QgsFeatureRequest().setFilterFids( mFeatureSelectionMgr->selectedFeatureIds() ) );
QgsFeature f;
while ( fit.nextFeature( f ) )
{
QgsVectorLayerUtils::QgsDuplicateFeatureContext duplicatedFeatureContext;
QgsVectorLayerUtils::duplicateFeature( layer, f, QgsProject::instance(), 0, duplicatedFeatureContext );
}
}

void QgsRelationEditorWidget::deleteFeature()
{
QgsVectorLayer *layer = nullptr;
@@ -146,6 +146,7 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsCollapsibleGroupBox
void updateButtons();

void addFeature();
void duplicateFeature();
void linkFeature();
void deleteFeature();
void unlinkFeature();
@@ -167,6 +168,7 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsCollapsibleGroupBox
QToolButton *mToggleEditingButton = nullptr;
QToolButton *mSaveEditsButton = nullptr;
QToolButton *mAddFeatureButton = nullptr;
QToolButton *mDuplicateFeatureButton = nullptr;
QToolButton *mDeleteFeatureButton = nullptr;
QToolButton *mLinkFeatureButton = nullptr;
QToolButton *mUnlinkFeatureButton = nullptr;

0 comments on commit 886e7bf

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