Skip to content

Commit

Permalink
[dualview] Remove attrs from feature dialog when deleted (Fix #8504)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Aug 23, 2013
1 parent a85d362 commit 6f574b4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/gui/attributetable/qgsdualview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ void QgsDualView::initLayerCache( QgsVectorLayer* layer )

mLayerCache->setFullCache( true );
}

connect( layer, SIGNAL( attributeDeleted( int ) ), this, SLOT( attributeDeleted( int ) ) );
}

void QgsDualView::initModels( QgsMapCanvas* mapCanvas )
Expand Down Expand Up @@ -380,6 +382,28 @@ void QgsDualView::previewExpressionChanged( const QString expression )
mLayerCache->layer()->setDisplayExpression( expression );
}

void QgsDualView::attributeDeleted( int attribute )
{
if ( mAttributeDialog && mAttributeDialog->dialog() )
{
// Let the dialog write the edited widget values to it's feature
mAttributeDialog->accept();
// Get the edited feature
QgsFeature* feat = mAttributeDialog->feature();
feat->deleteAttribute( attribute );

// Backup old dialog and delete only after creating the new dialog, so we can "hot-swap" the contained QgsFeature
QgsAttributeDialog* oldDialog = mAttributeDialog;

mAttributeEditorLayout->removeWidget( mAttributeDialog->dialog() );

mAttributeDialog = new QgsAttributeDialog( mLayerCache->layer(), new QgsFeature( *feat ), true, mDistanceArea, this, false );
mAttributeEditorLayout->addWidget( mAttributeDialog->dialog() );

delete oldDialog;
}
}

void QgsDualView::setFilteredFeatures( QgsFeatureIds filteredFeatures )
{
mFilterModel->setFilteredFeatures( filteredFeatures );
Expand Down
8 changes: 8 additions & 0 deletions src/gui/attributetable/qgsdualview.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas

void previewExpressionChanged( const QString expression );

/**
* If an attribute on this layer is deleted, close any open editors
* (as long as the attribute dialog is not able to handle this problem)
*
* @param attribute The attribute being deleted
*/
void attributeDeleted( int attribute );

/**
* Will be called periodically, when loading layers from slow data providers.
*
Expand Down
2 changes: 1 addition & 1 deletion src/gui/attributetable/qgsfeaturelistview.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class GUI_EXPORT QgsFeatureListView : public QListView
/**
* Destructor
*/
virtual ~QgsFeatureListView() {};
virtual ~QgsFeatureListView() {}

/**
* Returns the layer cache
Expand Down

0 comments on commit 6f574b4

Please sign in to comment.