Skip to content
Permalink
Browse files

[dualview] Fix crash when removing features

  • Loading branch information
m-kuhn committed Sep 4, 2013
1 parent f28462a commit c0659b98c90de59276a48376bc884b26ab885d76
Showing with 34 additions and 2 deletions.
  1. +26 −2 src/gui/attributetable/qgsdualview.cpp
  2. +8 −0 src/gui/attributetable/qgsdualview.h
@@ -23,6 +23,7 @@
#include "qgsexpressionbuilderdialog.h"
#include "qgsattributeaction.h"
#include "qgsvectordataprovider.h"
#include "qgsmessagelog.h"

#include <QDialog>
#include <QMenu>
@@ -229,6 +230,7 @@ void QgsDualView::initLayerCache( QgsVectorLayer* layer )
connect( layer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );
connect( layer, SIGNAL( attributeAdded( int ) ), this, SLOT( attributeAdded( int ) ) );
connect( layer, SIGNAL( attributeDeleted( int ) ), this, SLOT( attributeDeleted( int ) ) );
connect( layer, SIGNAL( featureDeleted( QgsFeatureId ) ), this, SLOT( featureDeleted( QgsFeatureId ) ) );
}

void QgsDualView::initModels( QgsMapCanvas* mapCanvas )
@@ -255,7 +257,7 @@ void QgsDualView::on_mFeatureList_currentEditSelectionChanged( const QgsFeature
// Backup old dialog and delete only after creating the new dialog, so we can "hot-swap" the contained QgsFeature
QgsAttributeDialog* oldDialog = mAttributeDialog;

if ( mAttributeDialog->dialog() )
if ( mAttributeDialog && mAttributeDialog->dialog() )
{
saveEditChanges();
mAttributeEditorLayout->removeWidget( mAttributeDialog->dialog() );
@@ -290,6 +292,12 @@ void QgsDualView::saveEditChanges()
// Get the edited feature
const QgsAttributes &dst = mAttributeDialog->feature()->attributes();

if ( src.count() != dst.count() )
{
// bail out
return;
}

mLayerCache->layer()->beginEditCommand( tr( "Attributes changed" ) );

for ( int i = 0; i < dst.count(); ++i )
@@ -348,7 +356,7 @@ void QgsDualView::previewColumnChanged( QObject* action )
void QgsDualView::editingToggled()
{
// Reload the attribute dialog widget and commit changes if any
if ( mAttributeDialog->dialog() && mAttributeDialog->feature() )
if ( mAttributeDialog && mAttributeDialog->dialog() && mAttributeDialog->feature() )
{
on_mFeatureList_currentEditSelectionChanged( *mAttributeDialog->feature() );
}
@@ -457,6 +465,22 @@ void QgsDualView::attributeAdded( int attribute )
}
}

void QgsDualView::featureDeleted( QgsFeatureId fid )
{
if ( mAttributeDialog && mAttributeDialog->dialog() )
{
QgsFeature* feat = mAttributeDialog->feature();
if ( feat )
{
if ( fid == feat->id() )
{
delete( mAttributeDialog );
mAttributeDialog = NULL;
}
}
}
}

void QgsDualView::reloadAttribute( const int& idx )
{
if ( mAttributeDialog && mAttributeDialog->dialog() )
@@ -206,6 +206,14 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
*/
void attributeAdded( int attribute );

/**
* Gets called when a feature is deleted.
* So it can be removed from the feature form if required.
*
* @param fid The feature being deleted
*/
void featureDeleted( QgsFeatureId fid );

/**
* Will be called periodically, when loading layers from slow data providers.
*

0 comments on commit c0659b9

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