33
33
QgsFeatureAction::QgsFeatureAction ( const QString &name, QgsFeature &f, QgsVectorLayer *layer, int action, int defaultAttr, QObject *parent )
34
34
: QAction( name, parent )
35
35
, mLayer( layer )
36
- , mFeature( f )
36
+ , mFeature( & f )
37
37
, mAction( action )
38
38
, mIdx( defaultAttr )
39
39
, mFeatureSaved( false )
@@ -42,12 +42,12 @@ QgsFeatureAction::QgsFeatureAction( const QString &name, QgsFeature &f, QgsVecto
42
42
43
43
void QgsFeatureAction::execute ()
44
44
{
45
- mLayer ->actions ()->doAction ( mAction , mFeature , mIdx );
45
+ mLayer ->actions ()->doAction ( mAction , * mFeature , mIdx );
46
46
}
47
47
48
48
QgsAttributeDialog *QgsFeatureAction::newDialog ( bool cloneFeature )
49
49
{
50
- QgsFeature *f = cloneFeature ? new QgsFeature ( mFeature ) : & mFeature ;
50
+ QgsFeature *f = cloneFeature ? new QgsFeature ( * mFeature ) : mFeature ;
51
51
52
52
QgsAttributeEditorContext context;
53
53
@@ -110,15 +110,15 @@ bool QgsFeatureAction::editFeature( bool showModal )
110
110
111
111
QgsAttributeDialog *dialog = newDialog ( false );
112
112
113
- if ( !mFeature . isValid () )
113
+ if ( !mFeature -> isValid () )
114
114
dialog->setIsAddDialog ( true );
115
115
116
116
if ( showModal )
117
117
{
118
118
dialog->setAttribute ( Qt::WA_DeleteOnClose );
119
119
int rv = dialog->exec ();
120
120
121
- mFeature . setAttributes ( dialog->feature ()->attributes () );
121
+ mFeature -> setAttributes ( dialog->feature ()->attributes () );
122
122
return rv;
123
123
}
124
124
else
@@ -142,7 +142,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
142
142
143
143
// add the fields to the QgsFeature
144
144
const QgsFields& fields = mLayer ->fields ();
145
- mFeature . initAttributes ( fields.count () );
145
+ mFeature -> initAttributes ( fields.count () );
146
146
for ( int idx = 0 ; idx < fields.count (); ++idx )
147
147
{
148
148
QVariant v;
@@ -160,7 +160,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
160
160
v = provider->defaultValue ( idx );
161
161
}
162
162
163
- mFeature . setAttribute ( idx, v );
163
+ mFeature -> setAttribute ( idx, v );
164
164
}
165
165
166
166
// show the dialog to enter attribute values
@@ -182,7 +182,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
182
182
if ( isDisabledAttributeValuesDlg )
183
183
{
184
184
mLayer ->beginEditCommand ( text () );
185
- mFeatureSaved = mLayer ->addFeature ( mFeature );
185
+ mFeatureSaved = mLayer ->addFeature ( * mFeature );
186
186
187
187
if ( mFeatureSaved )
188
188
mLayer ->endEditCommand ();
@@ -201,6 +201,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
201
201
{
202
202
setParent ( dialog ); // keep dialog until the dialog is closed and destructed
203
203
dialog->show (); // will also delete the dialog on close (show() is overridden)
204
+ mFeature = 0 ;
204
205
return true ;
205
206
}
206
207
@@ -219,7 +220,8 @@ void QgsFeatureAction::onFeatureSaved( const QgsFeature& feature )
219
220
Q_ASSERT ( form );
220
221
221
222
// Assign provider generated values
222
- mFeature = feature;
223
+ if ( mFeature )
224
+ *mFeature = feature;
223
225
224
226
mFeatureSaved = true ;
225
227
0 commit comments