@@ -1116,6 +1116,7 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
11161116 {
11171117 struct line_pnts *points = Vect_new_line_struct ();
11181118 struct line_cats *cats = Vect_new_cats_struct ();
1119+ int newCat = 0 ;
11191120
11201121 setPoints ( points, geometry );
11211122 // TODO: get also old type if it is feature previously deleted
@@ -1130,7 +1131,6 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
11301131 // resetting fid probably is not possible because it is stored in undo commands and used in buffer maps
11311132
11321133 QgsDebugMsg ( QString ( " get new cat for mCidxFieldIndex = %1" ).arg ( mCidxFieldIndex ) );
1133- int newCat = 0 ;
11341134 if ( mCidxFieldIndex == -1 )
11351135 {
11361136 // No features with this field yet in map
@@ -1142,6 +1142,12 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
11421142 }
11431143 QgsDebugMsg ( QString ( " newCat = %1" ).arg ( newCat ) );
11441144 Vect_cat_set ( cats, mLayerField , newCat );
1145+ QString error;
1146+ mLayer ->insertAttributes ( newCat, error );
1147+ if ( !error.isEmpty () )
1148+ {
1149+ QgsGrass::warning ( error );
1150+ }
11451151 }
11461152 }
11471153 else
@@ -1204,6 +1210,18 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
12041210 }
12051211 // TODO: create also centroid and add it to undo
12061212 }
1213+
1214+ if ( newCat > 0 )
1215+ {
1216+ if ( mLayer ->hasTable () )
1217+ {
1218+ addedFeatures[fid].setAttribute ( mLayer ->keyColumn (), newCat );
1219+ }
1220+ else
1221+ {
1222+ addedFeatures[fid].setAttribute ( 0 , newCat );
1223+ }
1224+ }
12071225 }
12081226 }
12091227
0 commit comments