@@ -426,10 +426,29 @@ bool QgsAttributeTable::commitChanges(QgsVectorLayer* layer)
426
426
{
427
427
deletedIds.insert (provider->indexFromFieldName (*it));
428
428
}
429
+
430
+ QgsChangedAttributesMap attributeChanges; // convert mChangedValues to QgsChangedAttributesMap
431
+ int fieldIndex;
432
+
433
+ QMap<int , QMap<QString, QString> >::const_iterator att_it = mChangedValues .constBegin ();
434
+ for (; att_it != mChangedValues .constEnd (); ++att_it)
435
+ {
436
+ QgsAttributeMap newAttMap;
437
+ QMap<QString, QString>::const_iterator record_it = att_it->constBegin ();
438
+ for (; record_it != att_it->constEnd (); ++record_it)
439
+ {
440
+ fieldIndex = provider->indexFromFieldName (record_it.key ());
441
+ if (fieldIndex != -1 )
442
+ {
443
+ newAttMap.insert (fieldIndex, record_it.value ());
444
+ }
445
+ }
446
+ attributeChanges.insert (att_it.key (), newAttMap);
447
+ }
429
448
430
449
isSuccessful = layer->commitAttributeChanges (deletedIds,
431
450
mAddedAttributes ,
432
- mChangedValues );
451
+ attributeChanges );
433
452
}
434
453
}
435
454
@@ -528,52 +547,23 @@ void QgsAttributeTable::putFeatureInTable(int row, QgsFeature& fet)
528
547
}
529
548
}
530
549
531
- int QgsAttributeTable::colIndexFromFieldIndex (int fieldId)
532
- {
533
- int colIndex = 1 ; // index 0 is feature ID
534
- QgsFieldMap::const_iterator it;
535
- for (it = mFields .begin (); it != mFields .end (); ++it, ++colIndex)
536
- {
537
- if (it.key () == fieldId)
538
- return colIndex;
539
- }
540
- return -1 ;
541
- }
542
-
543
- int QgsAttributeTable::fieldIndexFromColIndex (int colIndex)
544
- {
545
- colIndex--; // first one is feature ID
546
- QgsFieldMap::const_iterator it;
547
- for (it = mFields .begin (); it != mFields .end (); ++it, --colIndex)
548
- {
549
- if (colIndex == 0 )
550
- return it.key ();
551
- }
552
- return -1 ;
553
- }
554
-
555
550
void QgsAttributeTable::storeChangedValue (int row, int column)
556
551
{
557
- // id column is not editable
558
- if (column>0 )
552
+ // id column is not editable
553
+ if (column>0 )
559
554
{
560
- // find feature id
561
- int id=text (row,0 ).toInt ();
562
- int field = fieldIndexFromColIndex (column);
563
-
564
- QgsDebugMsg (" feature id: " + QString::number (id));
565
- QgsDebugMsg (" attribute: " + QString::number (field) + " : " + mFields [field].name ());
566
-
567
- // add empty map for feature if doesn't exist
568
- if (!mChangedValues .contains (id))
569
- {
570
- mChangedValues .insert (id, QgsAttributeMap ());
571
- }
572
-
573
- mChangedValues [id].insert (field, QVariant (text (row,column)) );
574
-
575
- QgsDebugMsg (" value: " + text (row,column));
576
- mEdited =true ;
555
+ // find feature id
556
+ int id=text (row,0 ).toInt ();
557
+ QString field = horizontalHeader ()->label (column);
558
+
559
+ // add empty map for feature if doesn't exist
560
+ if (!mChangedValues .contains (id))
561
+ {
562
+ mChangedValues .insert (id, QMap<QString, QString>());
563
+ }
564
+
565
+ mChangedValues [id].insert (field, text (row,column));
566
+ mEdited =true ;
577
567
}
578
568
}
579
569
0 commit comments