Skip to content

Commit

Permalink
fix crash attribute table crash when attributes are added/removed byp…
Browse files Browse the repository at this point in the history
…assing vector layer (fixes #12477)

(cherry picked from commit 316210d)
  • Loading branch information
jef-n committed Jun 29, 2015
1 parent 1d2539f commit c1b74f8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
23 changes: 0 additions & 23 deletions src/gui/attributetable/qgsattributetableview.cpp
Expand Up @@ -65,30 +65,7 @@ QgsAttributeTableView::~QgsAttributeTableView()
{
delete mActionPopup;
}
#if 0
void QgsAttributeTableView::setCanvasAndLayerCache( QgsMapCanvas *canvas, QgsVectorLayerCache *layerCache )
{
QgsAttributeTableModel* oldModel = mMasterModel;
QgsAttributeTableFilterModel* filterModel = mFilterModel;

mMasterModel = new QgsAttributeTableModel( layerCache, this );

mLayerCache = layerCache;

mMasterModel->loadLayer();

mFilterModel = new QgsAttributeTableFilterModel( canvas, mMasterModel, mMasterModel );
setModel( mFilterModel );
delete mFeatureSelectionModel;
mFeatureSelectionModel = new QgsFeatureSelectionModel( mFilterModel, mFilterModel, new QgsVectorLayerSelectionManager( layerCache->layer(), mFilterModel ), mFilterModel );
connect( mFeatureSelectionModel, SIGNAL( requestRepaint( QModelIndexList ) ), this, SLOT( repaintRequested( QModelIndexList ) ) );
connect( mFeatureSelectionModel, SIGNAL( requestRepaint() ), this, SLOT( repaintRequested() ) );
setSelectionModel( mFeatureSelectionModel );

delete oldModel;
delete filterModel;
}
#endif
bool QgsAttributeTableView::eventFilter( QObject *object, QEvent *event )
{
if ( object == verticalHeader()->viewport() )
Expand Down
1 change: 1 addition & 0 deletions src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -79,6 +79,7 @@ void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const Qg
mAttributeForm->hideButtonBox();

connect( mAttributeForm, SIGNAL( attributeChanged( QString, QVariant ) ), this, SLOT( featureFormAttributeChanged() ) );
connect( mMasterModel, SIGNAL( modelChanged() ), mAttributeForm, SLOT( refreshFeature() ) );

if ( mFeatureListPreviewButton->defaultAction() )
mFeatureList->setDisplayExpression( mDisplayExpression );
Expand Down
14 changes: 14 additions & 0 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -299,6 +299,20 @@ void QgsAttributeForm::onAttributeDeleted( int idx )
setFeature( mFeature );
}

void QgsAttributeForm::refreshFeature()
{
if ( mLayer->isEditable() || !mFeature.isValid() )
return;

// reload feature if layer changed although not editable
// (datasource probably changed bypassing QgsVectorLayer)
if ( !mLayer->getFeatures( QgsFeatureRequest().setFilterFid( mFeature.id() ) ).nextFeature( mFeature ) )
return;

init();
setFeature( mFeature );
}

void QgsAttributeForm::synchronizeEnabledState()
{
bool isEditable = ( mFeature.isValid() || mIsAddDialog ) && mLayer->isEditable();
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsattributeform.h
Expand Up @@ -164,6 +164,11 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
*/
void resetValues();

/**
* reload current feature
*/
void refreshFeature();

private slots:
void onAttributeChanged( const QVariant& value );
void onAttributeAdded( int idx );
Expand Down

0 comments on commit c1b74f8

Please sign in to comment.