Fix crash on add feature

This commit is contained in:
Matthias Kuhn 2015-12-02 20:11:32 +01:00
parent 02f8988837
commit 25aa60e338
2 changed files with 13 additions and 11 deletions

View File

@ -33,7 +33,7 @@
QgsFeatureAction::QgsFeatureAction( const QString &name, QgsFeature &f, QgsVectorLayer *layer, int action, int defaultAttr, QObject *parent )
: QAction( name, parent )
, mLayer( layer )
, mFeature( f )
, mFeature( &f )
, mAction( action )
, mIdx( defaultAttr )
, mFeatureSaved( false )
@ -42,12 +42,12 @@ QgsFeatureAction::QgsFeatureAction( const QString &name, QgsFeature &f, QgsVecto
void QgsFeatureAction::execute()
{
mLayer->actions()->doAction( mAction, mFeature, mIdx );
mLayer->actions()->doAction( mAction, *mFeature, mIdx );
}
QgsAttributeDialog *QgsFeatureAction::newDialog( bool cloneFeature )
{
QgsFeature *f = cloneFeature ? new QgsFeature( mFeature ) : &mFeature;
QgsFeature *f = cloneFeature ? new QgsFeature( *mFeature ) : mFeature;
QgsAttributeEditorContext context;
@ -110,7 +110,7 @@ bool QgsFeatureAction::editFeature( bool showModal )
QgsAttributeDialog *dialog = newDialog( false );
if ( !mFeature.isValid() )
if ( !mFeature->isValid() )
dialog->setIsAddDialog( true );
if ( showModal )
@ -118,7 +118,7 @@ bool QgsFeatureAction::editFeature( bool showModal )
dialog->setAttribute( Qt::WA_DeleteOnClose );
int rv = dialog->exec();
mFeature.setAttributes( dialog->feature()->attributes() );
mFeature->setAttributes( dialog->feature()->attributes() );
return rv;
}
else
@ -142,7 +142,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
// add the fields to the QgsFeature
const QgsFields& fields = mLayer->fields();
mFeature.initAttributes( fields.count() );
mFeature->initAttributes( fields.count() );
for ( int idx = 0; idx < fields.count(); ++idx )
{
QVariant v;
@ -160,7 +160,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
v = provider->defaultValue( idx );
}
mFeature.setAttribute( idx, v );
mFeature->setAttribute( idx, v );
}
//show the dialog to enter attribute values
@ -182,7 +182,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
if ( isDisabledAttributeValuesDlg )
{
mLayer->beginEditCommand( text() );
mFeatureSaved = mLayer->addFeature( mFeature );
mFeatureSaved = mLayer->addFeature( *mFeature );
if ( mFeatureSaved )
mLayer->endEditCommand();
@ -201,6 +201,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
{
setParent( dialog ); // keep dialog until the dialog is closed and destructed
dialog->show(); // will also delete the dialog on close (show() is overridden)
mFeature = 0;
return true;
}
@ -219,7 +220,8 @@ void QgsFeatureAction::onFeatureSaved( const QgsFeature& feature )
Q_ASSERT( form );
// Assign provider generated values
mFeature = feature;
if ( mFeature )
*mFeature = feature;
mFeatureSaved = true;

View File

@ -58,8 +58,8 @@ class APP_EXPORT QgsFeatureAction : public QAction
private:
QgsAttributeDialog *newDialog( bool cloneFeature );
QgsVectorLayer *mLayer;
QgsFeature &mFeature;
QgsVectorLayer* mLayer;
QgsFeature* mFeature;
int mAction;
int mIdx;