Skip to content

Commit c1b74f8

Browse files
committedJun 29, 2015
fix crash attribute table crash when attributes are added/removed bypassing vector layer (fixes #12477)
(cherry picked from commit 316210d)
1 parent 1d2539f commit c1b74f8

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed
 

‎src/gui/attributetable/qgsattributetableview.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,7 @@ QgsAttributeTableView::~QgsAttributeTableView()
6565
{
6666
delete mActionPopup;
6767
}
68-
#if 0
69-
void QgsAttributeTableView::setCanvasAndLayerCache( QgsMapCanvas *canvas, QgsVectorLayerCache *layerCache )
70-
{
71-
QgsAttributeTableModel* oldModel = mMasterModel;
72-
QgsAttributeTableFilterModel* filterModel = mFilterModel;
73-
74-
mMasterModel = new QgsAttributeTableModel( layerCache, this );
75-
76-
mLayerCache = layerCache;
77-
78-
mMasterModel->loadLayer();
7968

80-
mFilterModel = new QgsAttributeTableFilterModel( canvas, mMasterModel, mMasterModel );
81-
setModel( mFilterModel );
82-
delete mFeatureSelectionModel;
83-
mFeatureSelectionModel = new QgsFeatureSelectionModel( mFilterModel, mFilterModel, new QgsVectorLayerSelectionManager( layerCache->layer(), mFilterModel ), mFilterModel );
84-
connect( mFeatureSelectionModel, SIGNAL( requestRepaint( QModelIndexList ) ), this, SLOT( repaintRequested( QModelIndexList ) ) );
85-
connect( mFeatureSelectionModel, SIGNAL( requestRepaint() ), this, SLOT( repaintRequested() ) );
86-
setSelectionModel( mFeatureSelectionModel );
87-
88-
delete oldModel;
89-
delete filterModel;
90-
}
91-
#endif
9269
bool QgsAttributeTableView::eventFilter( QObject *object, QEvent *event )
9370
{
9471
if ( object == verticalHeader()->viewport() )

‎src/gui/attributetable/qgsdualview.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const Qg
7979
mAttributeForm->hideButtonBox();
8080

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

8384
if ( mFeatureListPreviewButton->defaultAction() )
8485
mFeatureList->setDisplayExpression( mDisplayExpression );

‎src/gui/qgsattributeform.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,20 @@ void QgsAttributeForm::onAttributeDeleted( int idx )
299299
setFeature( mFeature );
300300
}
301301

302+
void QgsAttributeForm::refreshFeature()
303+
{
304+
if ( mLayer->isEditable() || !mFeature.isValid() )
305+
return;
306+
307+
// reload feature if layer changed although not editable
308+
// (datasource probably changed bypassing QgsVectorLayer)
309+
if ( !mLayer->getFeatures( QgsFeatureRequest().setFilterFid( mFeature.id() ) ).nextFeature( mFeature ) )
310+
return;
311+
312+
init();
313+
setFeature( mFeature );
314+
}
315+
302316
void QgsAttributeForm::synchronizeEnabledState()
303317
{
304318
bool isEditable = ( mFeature.isValid() || mIsAddDialog ) && mLayer->isEditable();

‎src/gui/qgsattributeform.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
164164
*/
165165
void resetValues();
166166

167+
/**
168+
* reload current feature
169+
*/
170+
void refreshFeature();
171+
167172
private slots:
168173
void onAttributeChanged( const QVariant& value );
169174
void onAttributeAdded( int idx );

0 commit comments

Comments
 (0)