Skip to content
Permalink
Browse files

Fix crash on add feature

  • Loading branch information
m-kuhn committed Dec 2, 2015
1 parent 02f8988 commit 25aa60e33804f1f138160b0fe5da25a96a62203d
Showing with 13 additions and 11 deletions.
  1. +11 −9 src/app/qgsfeatureaction.cpp
  2. +2 −2 src/app/qgsfeatureaction.h
@@ -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,15 +110,15 @@ bool QgsFeatureAction::editFeature( bool showModal )

QgsAttributeDialog *dialog = newDialog( false );

if ( !mFeature.isValid() )
if ( !mFeature->isValid() )
dialog->setIsAddDialog( true );

if ( 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;

@@ -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;

2 comments on commit 25aa60e

@3nids

This comment has been minimized.

Copy link
Member

@3nids 3nids replied Dec 3, 2015

thanks, fixed the problem!!!

@m-kuhn

This comment has been minimized.

Copy link
Member Author

@m-kuhn m-kuhn replied Dec 3, 2015

I did not check yet if it broke the add feature in N:M

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