@@ -836,17 +836,40 @@ void QgsGrassVectorMapLayer::insertAttributes( int cat, const QgsFeature &featur
836
836
names << mFieldInfo ->key ;
837
837
values << QString::number ( cat );
838
838
839
- if ( feature.isValid () && feature.fields () )
839
+ QList<QVariant> cacheValues;
840
+ cacheValues.reserve ( mAttributeFields .size () );
841
+ for ( int i = 0 ; i < mAttributeFields .size (); ++i )
842
+ {
843
+ cacheValues << QVariant ();
844
+ }
845
+
846
+ if ( feature.fields () )
840
847
{
841
848
// append feature attributes if not null
842
849
for ( int i = 0 ; i < feature.fields ()->size (); i++ )
843
850
{
844
851
QString name = feature.fields ()->at ( i ).name ();
852
+ QVariant valueVariant = feature.attributes ().value ( i );
853
+
854
+ if ( name != QgsGrassVectorMap::topoSymbolFieldName () )
855
+ {
856
+ int cacheIndex = mAttributeFields .indexFromName ( name );
857
+ if ( cacheIndex < 0 ) // should not happen
858
+ {
859
+ error = QString ( " Field %1 not found in cached attributes" ).arg ( name );
860
+ return ;
861
+ }
862
+ else
863
+ {
864
+ cacheValues[cacheIndex] = valueVariant;
865
+ }
866
+ }
867
+
845
868
if ( name == mFieldInfo ->key )
846
869
{
847
870
continue ;
848
871
}
849
- QVariant valueVariant = feature. attributes (). value ( i );
872
+
850
873
if ( !valueVariant.isNull () )
851
874
{
852
875
names << name;
@@ -860,13 +883,7 @@ void QgsGrassVectorMapLayer::insertAttributes( int cat, const QgsFeature &featur
860
883
executeSql ( query, error );
861
884
if ( error.isEmpty () )
862
885
{
863
- QList<QVariant> values;
864
- values.reserve ( mAttributeFields .size () );
865
- for ( int i = 0 ; i < mAttributeFields .size (); ++i )
866
- {
867
- values << QVariant ();
868
- }
869
- mAttributes [cat] = values;
886
+ mAttributes [cat] = cacheValues;
870
887
}
871
888
printCachedAttributes ();
872
889
}
0 commit comments