Skip to content

Commit

Permalink
Fix crash on add feature
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Dec 2, 2015
1 parent 02f8988 commit 25aa60e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions src/app/qgsfeatureaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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;
}

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

Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsfeatureaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

2 comments on commit 25aa60e

@3nids
Copy link
Member

@3nids 3nids commented on 25aa60e Dec 3, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, fixed the problem!!!

@m-kuhn
Copy link
Member Author

@m-kuhn m-kuhn commented on 25aa60e Dec 3, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.