Skip to content

Commit 6f574b4

Browse files
committed
[dualview] Remove attrs from feature dialog when deleted (Fix #8504)
1 parent a85d362 commit 6f574b4

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/gui/attributetable/qgsdualview.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ void QgsDualView::initLayerCache( QgsVectorLayer* layer )
214214

215215
mLayerCache->setFullCache( true );
216216
}
217+
218+
connect( layer, SIGNAL( attributeDeleted( int ) ), this, SLOT( attributeDeleted( int ) ) );
217219
}
218220

219221
void QgsDualView::initModels( QgsMapCanvas* mapCanvas )
@@ -380,6 +382,28 @@ void QgsDualView::previewExpressionChanged( const QString expression )
380382
mLayerCache->layer()->setDisplayExpression( expression );
381383
}
382384

385+
void QgsDualView::attributeDeleted( int attribute )
386+
{
387+
if ( mAttributeDialog && mAttributeDialog->dialog() )
388+
{
389+
// Let the dialog write the edited widget values to it's feature
390+
mAttributeDialog->accept();
391+
// Get the edited feature
392+
QgsFeature* feat = mAttributeDialog->feature();
393+
feat->deleteAttribute( attribute );
394+
395+
// Backup old dialog and delete only after creating the new dialog, so we can "hot-swap" the contained QgsFeature
396+
QgsAttributeDialog* oldDialog = mAttributeDialog;
397+
398+
mAttributeEditorLayout->removeWidget( mAttributeDialog->dialog() );
399+
400+
mAttributeDialog = new QgsAttributeDialog( mLayerCache->layer(), new QgsFeature( *feat ), true, mDistanceArea, this, false );
401+
mAttributeEditorLayout->addWidget( mAttributeDialog->dialog() );
402+
403+
delete oldDialog;
404+
}
405+
}
406+
383407
void QgsDualView::setFilteredFeatures( QgsFeatureIds filteredFeatures )
384408
{
385409
mFilterModel->setFilteredFeatures( filteredFeatures );

src/gui/attributetable/qgsdualview.h

+8
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
183183

184184
void previewExpressionChanged( const QString expression );
185185

186+
/**
187+
* If an attribute on this layer is deleted, close any open editors
188+
* (as long as the attribute dialog is not able to handle this problem)
189+
*
190+
* @param attribute The attribute being deleted
191+
*/
192+
void attributeDeleted( int attribute );
193+
186194
/**
187195
* Will be called periodically, when loading layers from slow data providers.
188196
*

src/gui/attributetable/qgsfeaturelistview.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class GUI_EXPORT QgsFeatureListView : public QListView
5353
/**
5454
* Destructor
5555
*/
56-
virtual ~QgsFeatureListView() {};
56+
virtual ~QgsFeatureListView() {}
5757

5858
/**
5959
* Returns the layer cache

0 commit comments

Comments
 (0)