Skip to content
Permalink
Browse files

Fix crash when deleting a field in attribute table (fixes #12930)

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 6215f773e22cb55dac694ae6b213cd1f9ac39c53
@@ -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 )
@@ -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();
}

@@ -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()
@@ -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 );
}

0 comments on commit 6215f77

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