Skip to content

Commit 25aa60e

Browse files
committed
Fix crash on add feature
1 parent 02f8988 commit 25aa60e

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/app/qgsfeatureaction.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
QgsFeatureAction::QgsFeatureAction( const QString &name, QgsFeature &f, QgsVectorLayer *layer, int action, int defaultAttr, QObject *parent )
3434
: QAction( name, parent )
3535
, mLayer( layer )
36-
, mFeature( f )
36+
, mFeature( &f )
3737
, mAction( action )
3838
, mIdx( defaultAttr )
3939
, mFeatureSaved( false )
@@ -42,12 +42,12 @@ QgsFeatureAction::QgsFeatureAction( const QString &name, QgsFeature &f, QgsVecto
4242

4343
void QgsFeatureAction::execute()
4444
{
45-
mLayer->actions()->doAction( mAction, mFeature, mIdx );
45+
mLayer->actions()->doAction( mAction, *mFeature, mIdx );
4646
}
4747

4848
QgsAttributeDialog *QgsFeatureAction::newDialog( bool cloneFeature )
4949
{
50-
QgsFeature *f = cloneFeature ? new QgsFeature( mFeature ) : &mFeature;
50+
QgsFeature *f = cloneFeature ? new QgsFeature( *mFeature ) : mFeature;
5151

5252
QgsAttributeEditorContext context;
5353

@@ -110,15 +110,15 @@ bool QgsFeatureAction::editFeature( bool showModal )
110110

111111
QgsAttributeDialog *dialog = newDialog( false );
112112

113-
if ( !mFeature.isValid() )
113+
if ( !mFeature->isValid() )
114114
dialog->setIsAddDialog( true );
115115

116116
if ( showModal )
117117
{
118118
dialog->setAttribute( Qt::WA_DeleteOnClose );
119119
int rv = dialog->exec();
120120

121-
mFeature.setAttributes( dialog->feature()->attributes() );
121+
mFeature->setAttributes( dialog->feature()->attributes() );
122122
return rv;
123123
}
124124
else
@@ -142,7 +142,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
142142

143143
// add the fields to the QgsFeature
144144
const QgsFields& fields = mLayer->fields();
145-
mFeature.initAttributes( fields.count() );
145+
mFeature->initAttributes( fields.count() );
146146
for ( int idx = 0; idx < fields.count(); ++idx )
147147
{
148148
QVariant v;
@@ -160,7 +160,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
160160
v = provider->defaultValue( idx );
161161
}
162162

163-
mFeature.setAttribute( idx, v );
163+
mFeature->setAttribute( idx, v );
164164
}
165165

166166
//show the dialog to enter attribute values
@@ -182,7 +182,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
182182
if ( isDisabledAttributeValuesDlg )
183183
{
184184
mLayer->beginEditCommand( text() );
185-
mFeatureSaved = mLayer->addFeature( mFeature );
185+
mFeatureSaved = mLayer->addFeature( *mFeature );
186186

187187
if ( mFeatureSaved )
188188
mLayer->endEditCommand();
@@ -201,6 +201,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
201201
{
202202
setParent( dialog ); // keep dialog until the dialog is closed and destructed
203203
dialog->show(); // will also delete the dialog on close (show() is overridden)
204+
mFeature = 0;
204205
return true;
205206
}
206207

@@ -219,7 +220,8 @@ void QgsFeatureAction::onFeatureSaved( const QgsFeature& feature )
219220
Q_ASSERT( form );
220221

221222
// Assign provider generated values
222-
mFeature = feature;
223+
if ( mFeature )
224+
*mFeature = feature;
223225

224226
mFeatureSaved = true;
225227

src/app/qgsfeatureaction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class APP_EXPORT QgsFeatureAction : public QAction
5858
private:
5959
QgsAttributeDialog *newDialog( bool cloneFeature );
6060

61-
QgsVectorLayer *mLayer;
62-
QgsFeature &mFeature;
61+
QgsVectorLayer* mLayer;
62+
QgsFeature* mFeature;
6363
int mAction;
6464
int mIdx;
6565

0 commit comments

Comments
 (0)