Skip to content
Permalink
Browse files
Fixes parts of bug #763 'problem editing postgis table'. But it is st…
…ill a problem to add attributes and commit changes to the new attributes in one go

git-svn-id: http://svn.osgeo.org/qgis/trunk@7181 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Sep 7, 2007
1 parent e7d7722 commit b98fe380be6b7dc7ff04fb1dc3a9c60561a23a1f
Showing with 36 additions and 50 deletions.
  1. +34 −44 src/app/qgsattributetable.cpp
  2. +2 −6 src/app/qgsattributetable.h
@@ -426,10 +426,29 @@ bool QgsAttributeTable::commitChanges(QgsVectorLayer* layer)
{
deletedIds.insert(provider->indexFromFieldName(*it));
}

QgsChangedAttributesMap attributeChanges; //convert mChangedValues to QgsChangedAttributesMap
int fieldIndex;

QMap<int, QMap<QString, QString> >::const_iterator att_it = mChangedValues.constBegin();
for(; att_it != mChangedValues.constEnd(); ++att_it)
{
QgsAttributeMap newAttMap;
QMap<QString, QString>::const_iterator record_it = att_it->constBegin();
for(; record_it != att_it->constEnd(); ++record_it)
{
fieldIndex = provider->indexFromFieldName(record_it.key());
if(fieldIndex != -1)
{
newAttMap.insert(fieldIndex, record_it.value());
}
}
attributeChanges.insert(att_it.key(), newAttMap);
}

isSuccessful = layer->commitAttributeChanges(deletedIds,
mAddedAttributes,
mChangedValues);
attributeChanges);
}
}

@@ -528,52 +547,23 @@ void QgsAttributeTable::putFeatureInTable(int row, QgsFeature& fet)
}
}

int QgsAttributeTable::colIndexFromFieldIndex(int fieldId)
{
int colIndex = 1; // index 0 is feature ID
QgsFieldMap::const_iterator it;
for (it = mFields.begin(); it != mFields.end(); ++it, ++colIndex)
{
if (it.key() == fieldId)
return colIndex;
}
return -1;
}

int QgsAttributeTable::fieldIndexFromColIndex(int colIndex)
{
colIndex--; // first one is feature ID
QgsFieldMap::const_iterator it;
for (it = mFields.begin(); it != mFields.end(); ++it, --colIndex)
{
if (colIndex == 0)
return it.key();
}
return -1;
}

void QgsAttributeTable::storeChangedValue(int row, int column)
{
//id column is not editable
if(column>0)
//id column is not editable
if(column>0)
{
//find feature id
int id=text(row,0).toInt();
int field = fieldIndexFromColIndex(column);

QgsDebugMsg("feature id: " + QString::number(id));
QgsDebugMsg("attribute: " + QString::number(field) + ": " + mFields[field].name());

// add empty map for feature if doesn't exist
if (!mChangedValues.contains(id))
{
mChangedValues.insert(id, QgsAttributeMap());
}

mChangedValues[id].insert(field, QVariant(text(row,column)) );

QgsDebugMsg("value: " + text(row,column));
mEdited=true;
//find feature id
int id=text(row,0).toInt();
QString field = horizontalHeader()->label(column);

// add empty map for feature if doesn't exist
if (!mChangedValues.contains(id))
{
mChangedValues.insert(id, QMap<QString, QString>());
}

mChangedValues[id].insert(field, text(row,column));
mEdited=true;
}
}

@@ -133,7 +133,8 @@ class QgsAttributeTable:public Q3Table
QSet<QString> mDeletedAttributes;
/**Nested map containing the changed attribute values. The int is the feature id,
the first QString the attribute name and the second QString the new value*/
QgsChangedAttributesMap mChangedValues;
QMap<int, QMap<QString, QString> > mChangedValues;

/**Stors the numbers of the last selected rows. This is used to check for selection changes before emit repaintRequested()*/
std::set<int> mLastSelectedRows;

@@ -154,11 +155,6 @@ class QgsAttributeTable:public Q3Table
/**This function compares the current selection and the selection of the last repaint. Returns true if there are differences in the selection.
Also, mLastSelectedRows is updated*/
bool checkSelectionChanges();

/** returns column index for field index or -1 on invalid field index */
int colIndexFromFieldIndex(int fieldId);
/** returns field index for a column or -1 when on invalid column */
int fieldIndexFromColIndex(int colIndex);

signals:

0 comments on commit b98fe38

Please sign in to comment.