Skip to content

Commit

Permalink
Fix crash when deleting a field in attribute table (fixes #12930)
Browse files Browse the repository at this point in the history
Also fixes:
- multiple reloads of table (due to additional connections to cache invalidation)
- crash in attribute form (on redo of deleted field when it was not the last)
- crash in editor widget wrapper (during table reload)
  • Loading branch information
wonder-sk committed Jun 19, 2015
1 parent 5e4841d commit 6215f77
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -336,6 +336,13 @@ void QgsAttributeTableModel::loadAttributes()
void QgsAttributeTableModel::loadLayer()
{
QgsDebugMsg( "entered." );

// make sure attributes are properly updated before caching the data
// (emit of progress() signal may enter event loop and thus attribute
// table view may be updated with inconsistent model which may assume
// wrong number of attributes)
loadAttributes();

beginResetModel();

if ( rowCount() != 0 )
Expand Down Expand Up @@ -370,9 +377,8 @@ void QgsAttributeTableModel::loadLayer()

emit finished();

connect( mLayerCache, SIGNAL( invalidated() ), this, SLOT( loadLayer() ) );
connect( mLayerCache, SIGNAL( invalidated() ), this, SLOT( loadLayer() ), Qt::UniqueConnection );

mFieldCount = mAttributes.size();
endResetModel();
}

Expand Down
5 changes: 4 additions & 1 deletion src/gui/editorwidgets/core/qgseditorwidgetwrapper.cpp
Expand Up @@ -33,7 +33,10 @@ int QgsEditorWidgetWrapper::fieldIdx()

QgsField QgsEditorWidgetWrapper::field()
{
return layer()->pendingFields()[mFieldIdx];
if ( mFieldIdx < layer()->pendingFields().count() )
return layer()->pendingFields()[mFieldIdx];
else
return QgsField();
}

QVariant QgsEditorWidgetWrapper::defaultValue()
Expand Down
3 changes: 1 addition & 2 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -277,8 +277,7 @@ void QgsAttributeForm::onAttributeAdded( int idx )
if ( mFeature.isValid() )
{
QgsAttributes attrs = mFeature.attributes();
Q_ASSERT( attrs.size() == idx );
attrs.append( QVariant( layer()->pendingFields()[idx].type() ) );
attrs.insert( idx, QVariant( layer()->pendingFields()[idx].type() ) );
mFeature.setFields( layer()->pendingFields() );
mFeature.setAttributes( attrs );
}
Expand Down

0 comments on commit 6215f77

Please sign in to comment.