44
44
45
45
int QgsAttributeDialog::smFormCounter = 0 ;
46
46
47
- QgsAttributeDialog::QgsAttributeDialog ( QgsVectorLayer *vl, QgsFeature *thepFeature )
47
+ QgsAttributeDialog::QgsAttributeDialog ( QgsVectorLayer *vl, QgsFeature *thepFeature, bool featureOwner )
48
48
: mDialog( 0 )
49
49
, mSettingsPath( " /Windows/AttributeDialog/" )
50
50
, mLayer( vl )
51
- , mpFeature( thepFeature )
51
+ , mFeature( thepFeature )
52
+ , mFeatureOwner( featureOwner )
52
53
, mRubberBand( 0 )
53
54
, mFormNr( -1 )
54
55
{
55
- if ( mpFeature == NULL || vl->dataProvider () == NULL )
56
+ if ( ! mFeature || ! vl->dataProvider () )
56
57
return ;
57
58
58
59
const QgsFieldMap &theFieldMap = vl->pendingFields ();
59
60
if ( theFieldMap.isEmpty () )
60
61
return ;
61
62
62
- QgsAttributeMap myAttributes = mpFeature ->attributeMap ();
63
+ QgsAttributeMap myAttributes = mFeature ->attributeMap ();
63
64
64
65
QDialogButtonBox *buttonBox = NULL ;
65
66
@@ -243,7 +244,7 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
243
244
mFormNr = smFormCounter++;
244
245
QgisApp::instance ()->runPythonString ( QString ( " _qgis_featureform_%1 = wrapinstance( %2, QtGui.QDialog )" ).arg ( mFormNr ).arg (( unsigned long ) mDialog ) );
245
246
246
- QString expr = QString ( " %1(_qgis_featureform_%2,'%3',%4)" ).arg ( vl->editFormInit () ).arg ( mFormNr ).arg ( vl->getLayerID () ).arg ( mpFeature ->id () );
247
+ QString expr = QString ( " %1(_qgis_featureform_%2,'%3',%4)" ).arg ( vl->editFormInit () ).arg ( mFormNr ).arg ( vl->getLayerID () ).arg ( mFeature ->id () );
247
248
QgsDebugMsg ( QString ( " running featureForm init: %1" ).arg ( expr ) );
248
249
QgisApp::instance ()->runPythonString ( expr );
249
250
}
@@ -260,6 +261,11 @@ QgsAttributeDialog::~QgsAttributeDialog()
260
261
delete mRubberBand ;
261
262
}
262
263
264
+ if ( mFeatureOwner )
265
+ {
266
+ delete mFeature ;
267
+ }
268
+
263
269
saveGeometry ();
264
270
265
271
if ( mDialog )
@@ -270,19 +276,19 @@ QgsAttributeDialog::~QgsAttributeDialog()
270
276
271
277
void QgsAttributeDialog::accept ()
272
278
{
273
- if ( !mLayer ->isEditable () )
279
+ if ( !mLayer ->isEditable () || ! mFeature )
274
280
return ;
275
281
276
282
// write the new values back to the feature
277
- QgsAttributeMap myAttributes = mpFeature ->attributeMap ();
283
+ QgsAttributeMap myAttributes = mFeature ->attributeMap ();
278
284
int myIndex = 0 ;
279
285
for ( QgsAttributeMap::const_iterator it = myAttributes.begin (); it != myAttributes.end (); ++it )
280
286
{
281
287
QVariant value;
282
288
283
289
int idx = mpIndizes.value ( myIndex );
284
290
if ( QgsAttributeEditor::retrieveValue ( mpWidgets.value ( myIndex ), mLayer , idx, value ) )
285
- mpFeature ->changeAttribute ( idx, value );
291
+ mFeature ->changeAttribute ( idx, value );
286
292
287
293
++myIndex;
288
294
}
0 commit comments