@@ -36,6 +36,7 @@ QgsFeatureAction::QgsFeatureAction( const QString &name, QgsFeature &f, QgsVecto
36
36
, mFeature( f )
37
37
, mAction( action )
38
38
, mIdx( defaultAttr )
39
+ , mFeatureSaved( false )
39
40
{
40
41
}
41
42
@@ -176,10 +177,6 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes )
176
177
}
177
178
}
178
179
179
- bool res = false ;
180
-
181
-
182
-
183
180
// show the dialog to enter attribute values
184
181
bool isDisabledAttributeValuesDlg = settings.value ( " /qgis/digitizing/disable_enter_attribute_values_dialog" , false ).toBool ();
185
182
// override application-wide setting with any layer setting
@@ -197,46 +194,51 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes )
197
194
if ( isDisabledAttributeValuesDlg )
198
195
{
199
196
mLayer ->beginEditCommand ( text () );
200
- res = mLayer ->addFeature ( mFeature );
197
+ mFeatureSaved = mLayer ->addFeature ( mFeature );
201
198
202
- if ( res )
199
+ if ( mFeatureSaved )
203
200
mLayer ->endEditCommand ();
204
201
else
205
202
mLayer ->destroyEditCommand ();
206
203
}
207
204
else
208
205
{
209
- QgsAttributes origValues;
210
- if ( reuseLastValues )
211
- origValues = mFeature .attributes ();
212
-
213
206
QgsAttributeDialog *dialog = newDialog ( false );
214
207
dialog->setIsAddDialog ( true );
215
208
dialog->setEditCommandMessage ( text () );
209
+
210
+ connect ( dialog->attributeForm (), SIGNAL ( featureSaved ( QgsFeature ) ), this , SLOT ( onFeatureSaved ( QgsFeature ) ) );
211
+
216
212
dialog->exec ();
217
- if ( reuseLastValues )
218
- {
219
- connect ( dialog->dialog (), SIGNAL ( featureSaved ( const QgsFeature& feature ) ), this , SLOT ( updateLastUsedValues ( const QgsFeature& feature ) ) );
220
- }
221
213
}
222
214
223
- return res;
215
+ // Will be set in the onFeatureSaved SLOT
216
+ return mFeatureSaved ;
224
217
}
225
218
226
- void QgsFeatureAction::updateLastUsedValues ( const QgsFeature& feature )
219
+ void QgsFeatureAction::onFeatureSaved ( const QgsFeature& feature )
227
220
{
228
221
QgsAttributeForm* form = qobject_cast<QgsAttributeForm*>( sender () );
229
222
Q_ASSERT ( form );
230
223
231
- QgsFields fields = mLayer ->pendingFields ();
232
- for ( int idx = 0 ; idx < fields.count (); ++idx )
224
+ mFeatureSaved = true ;
225
+
226
+ QSettings settings;
227
+ bool reuseLastValues = settings.value ( " /qgis/digitizing/reuseLastValues" , false ).toBool ();
228
+ QgsDebugMsg ( QString ( " reuseLastValues: %1" ).arg ( reuseLastValues ) );
229
+
230
+ if ( reuseLastValues )
233
231
{
234
- const QgsAttributes &newValues = feature.attributes ();
235
- QgsAttributeMap origValues = sLastUsedValues [ mLayer ];
236
- if ( origValues[idx] != newValues[idx] )
232
+ QgsFields fields = mLayer ->pendingFields ();
233
+ for ( int idx = 0 ; idx < fields.count (); ++idx )
237
234
{
238
- QgsDebugMsg ( QString ( " saving %1 for %2" ).arg ( sLastUsedValues [ mLayer ][idx].toString () ).arg ( idx ) );
239
- sLastUsedValues [ mLayer ][idx] = newValues[idx];
235
+ const QgsAttributes &newValues = feature.attributes ();
236
+ QgsAttributeMap origValues = sLastUsedValues [ mLayer ];
237
+ if ( origValues[idx] != newValues[idx] )
238
+ {
239
+ QgsDebugMsg ( QString ( " saving %1 for %2" ).arg ( sLastUsedValues [ mLayer ][idx].toString () ).arg ( idx ) );
240
+ sLastUsedValues [ mLayer ][idx] = newValues[idx];
241
+ }
240
242
}
241
243
}
242
244
}
0 commit comments