Skip to content

Commit c759740

Browse files
committedJan 8, 2013
Fix loading of Python Init method with unsaved features
1 parent 0ca96a8 commit c759740

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed
 

‎src/app/qgsattributedialog.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,19 +348,23 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
348348
.arg( vl->id() )
349349
.arg(( unsigned long ) vl );
350350

351-
QString feature = QString( "_qgis_feature_%1 = wrapinstance( %2, qgis.core.QgsFeature )" )
352-
.arg( mFeature->id() )
351+
// Generate the unique ID of this feature. We used to use feature ID but some providers
352+
// return a ID that is an invalid python variable when we have new unsaved features.
353+
QDateTime dt = QDateTime::currentDateTime();
354+
QString featurevarname = QString( "_qgis_feature_%1" ).arg( dt.toString( "yyyyMMddhhmmsszzz" ) );
355+
QString feature = QString( "%1 = wrapinstance( %2, qgis.core.QgsFeature )" )
356+
.arg( featurevarname )
353357
.arg(( unsigned long ) mFeature );
354358

355359
QgsPythonRunner::run( form );
356360
QgsPythonRunner::run( feature );
357361
QgsPythonRunner::run( layer );
358362

359-
QString expr = QString( "%1(_qgis_featureform_%2, _qgis_layer_%3, _qgis_feature_%4)" )
363+
QString expr = QString( "%1(_qgis_featureform_%2, _qgis_layer_%3, %4)" )
360364
.arg( vl->editFormInit() )
361365
.arg( mFormNr )
362366
.arg( vl->id() )
363-
.arg( mFeature->id() );
367+
.arg( featurevarname );
364368

365369
QgsDebugMsg( QString( "running featureForm init: %1" ).arg( expr ) );
366370
QgsPythonRunner::run( expr );

0 commit comments

Comments
 (0)
Please sign in to comment.