Skip to content
Permalink
Browse files

fix crash attribute table crash when attributes are added/removed byp…

…assing vector layer (fixes #12477)
  • Loading branch information
jef-n committed Jun 4, 2015
1 parent c22ad17 commit 316210d62255729600edfe0ab8b3b43312725be5
@@ -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() )
@@ -78,6 +78,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 );
@@ -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();
@@ -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 );

0 comments on commit 316210d

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