Skip to content

Commit c38e459

Browse files
committedNov 1, 2015
[GRASS] fixed new line attributes lost, fixes #13726
(cherry picked from commit 0ceeb51)
1 parent 6dcb134 commit c38e459

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed
 

‎src/providers/grass/qgsgrassvectormaplayer.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -836,17 +836,40 @@ void QgsGrassVectorMapLayer::insertAttributes( int cat, const QgsFeature &featur
836836
names << mFieldInfo->key;
837837
values << QString::number( cat );
838838

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() )
840847
{
841848
// append feature attributes if not null
842849
for ( int i = 0; i < feature.fields()->size(); i++ )
843850
{
844851
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+
845868
if ( name == mFieldInfo->key )
846869
{
847870
continue;
848871
}
849-
QVariant valueVariant = feature.attributes().value( i );
872+
850873
if ( !valueVariant.isNull() )
851874
{
852875
names << name;
@@ -860,13 +883,7 @@ void QgsGrassVectorMapLayer::insertAttributes( int cat, const QgsFeature &featur
860883
executeSql( query, error );
861884
if ( error.isEmpty() )
862885
{
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;
870887
}
871888
printCachedAttributes();
872889
}

0 commit comments

Comments
 (0)
Please sign in to comment.