Skip to content
Permalink
Browse files
Relation editor in multiedit multi-select same child feature
  • Loading branch information
domi4484 committed Nov 8, 2021
1 parent 3c5216b commit ed7d3f96d0048f6eed336d556705a13c8d706c6a
Showing with 56 additions and 17 deletions.
  1. +7 −13 src/gui/qgsabstractrelationeditorwidget.cpp
  2. +44 −4 src/gui/qgsrelationeditorwidget.cpp
  3. +5 −0 src/gui/qgsrelationeditorwidget.h
@@ -304,12 +304,6 @@ void QgsAbstractRelationEditorWidget::deleteFeatures( const QgsFeatureIds &fids
QgsVectorLayer *layer;
if ( mNmRelation.isValid() )
{
if ( multiEditModeActive() )
{
QgsLogger::warning( tr( "Deleting of features not supported in multiple edit mode for n:m relations" ) );
return;
}

// only normal relations support m:n relation
Q_ASSERT( mNmRelation.type() == QgsRelation::Normal );

@@ -571,12 +565,6 @@ void QgsAbstractRelationEditorWidget::unlinkFeatures( const QgsFeatureIds &fids
{
if ( mNmRelation.isValid() )
{
if ( multiEditModeActive() )
{
QgsLogger::warning( tr( "Unlinking of features not supported in multiple edit mode for n:m relations" ) );
return;
}

// only normal relations support m:n relation
Q_ASSERT( mNmRelation.type() == QgsRelation::Normal );

@@ -594,8 +582,14 @@ void QgsAbstractRelationEditorWidget::unlinkFeatures( const QgsFeatureIds &fids
filters << '(' + mNmRelation.getRelatedFeaturesRequest( f ).filterExpression()->expression() + ')';
}

QStringList featureFilters;
for ( const QgsFeature &editingFeature : std::as_const( mFeatureList ) )
{
featureFilters.append( mRelation.getRelatedFeaturesRequest( editingFeature ).filterExpression()->expression() );
}

const QString filter = QStringLiteral( "(%1) AND (%2)" ).arg(
mRelation.getRelatedFeaturesRequest( mFeatureList.first() ).filterExpression()->expression(),
featureFilters.join( QLatin1String( " OR " ) ),
filters.join( QLatin1String( " OR " ) ) );

QgsFeatureIterator linkedIterator = mRelation.referencingLayer()->getFeatures( QgsFeatureRequest()
@@ -238,7 +238,7 @@ QgsRelationEditorWidget::QgsRelationEditorWidget( const QVariantMap &config, QWi
connect( mLinkFeatureButton, &QAbstractButton::clicked, this, &QgsRelationEditorWidget::linkFeature );
connect( mUnlinkFeatureButton, &QAbstractButton::clicked, this, &QgsRelationEditorWidget::unlinkSelectedFeatures );
connect( mZoomToFeatureButton, &QAbstractButton::clicked, this, &QgsRelationEditorWidget::zoomToSelectedFeatures );
connect( mMultiEditTreeWidget, &QTreeWidget::itemSelectionChanged, this, &QgsRelationEditorWidget::updateButtons );
connect( mMultiEditTreeWidget, &QTreeWidget::itemSelectionChanged, this, &QgsRelationEditorWidget::multiEditItemSelectionChanged );

// Set initial state for add/remove etc. buttons
updateButtons();
@@ -344,13 +344,10 @@ void QgsRelationEditorWidget::updateButtons()

canAddGeometry = false;

canRemove = canRemove && !nmRelation().isValid();
canRemove = canRemove && multieditLinkedChildSelected;

// In 1:n relations an element can be linked only to 1 feature
canLink = canLink && mNmRelation.isValid();

canUnlink = canUnlink && !mNmRelation.isValid();
canUnlink = canUnlink && multieditLinkedChildSelected;
}
else
@@ -389,6 +386,7 @@ void QgsRelationEditorWidget::addFeature()
if ( !multiEditModeActive() )
return;

mMultiEditTreeWidget->blockSignals( true );
QTreeWidgetItemIterator treeWidgetItemIterator( mMultiEditTreeWidget );
while ( *treeWidgetItemIterator )
{
@@ -403,6 +401,7 @@ void QgsRelationEditorWidget::addFeature()

++treeWidgetItemIterator;
}
mMultiEditTreeWidget->blockSignals( false );
}

void QgsRelationEditorWidget::addFeatureGeometry()
@@ -447,6 +446,47 @@ void QgsRelationEditorWidget::onDigitizingCompleted( const QgsFeature &feature )
unsetMapTool();
}

void QgsRelationEditorWidget::multiEditItemSelectionChanged()
{
const QList<QTreeWidgetItem *> selectedItems = mMultiEditTreeWidget->selectedItems();

if ( ! mNmRelation.isValid() )
{
updateButtons();
return;
}

// Select all items pointing to the same feature
// but only if we are not deselecting.
if ( selectedItems.size() == 1
&& mMultiEditPreviousSelectedItems.size() <= 1 )
{
if ( selectedItems.first()->data( 0, static_cast<int>( MultiEditTreeWidgetRole::FeatureType ) ).toInt() == static_cast<int>( MultiEditFeatureType::Child ) )
{
QgsFeatureId featureId = selectedItems.first()->data( 0, static_cast<int>( MultiEditTreeWidgetRole::FeatureId ) ).toInt();

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

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

++treeWidgetItemIterator;
}
mMultiEditTreeWidget->blockSignals( false );
}
}
mMultiEditPreviousSelectedItems = selectedItems;
updateButtons();
}

void QgsRelationEditorWidget::toggleEditing( bool state )
{
QgsAbstractRelationEditorWidget::toggleEditing( state );
@@ -33,6 +33,7 @@
#include "qgis_gui.h"

class QTreeWidget;
class QTreeWidgetItem;
class QgsFeature;
class QgsVectorLayer;
class QgsVectorLayerTools;
@@ -209,6 +210,8 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsAbstractRelationEditorWidge
void onKeyPressed( QKeyEvent *e );
void onDigitizingCompleted( const QgsFeature &feature );

void multiEditItemSelectionChanged();

private:
void initDualView( QgsVectorLayer *layer, const QgsFeatureRequest &request );
void setMapTool( QgsMapTool *mapTool );
@@ -251,6 +254,8 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsAbstractRelationEditorWidge

Buttons mButtonsVisibility = Button::AllButtons;
bool mShowFirstFeature = true;

QList<QTreeWidgetItem *> mMultiEditPreviousSelectedItems;
};


0 comments on commit ed7d3f9

Please sign in to comment.