Skip to content

Commit 4a6923a

Browse files
author
morb_au
committedJul 14, 2006
When Stopping Editing and Saving Changes, if the commit was *unsuccessful*, retain the in-memory edits. Previously the in-memory edits would be erased anyway.
Note this is not a complete solution as commits are currently a 3- or 4-stage process, and if one stage fails the chain cannot always be rolled-back easily. If this is the case then a detailed error message is given to the user to assist their understanding of the discrepency. This commit should be a bug fix for trac #131, but I don't have the environment to test it fully - the bug submitter will have to assist there. Bonus feature: Tidied up some variable names in QgsVectorLayer - makes it clearer what they contain. git-svn-id: http://svn.osgeo.org/qgis/trunk@5591 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 57b9c34 commit 4a6923a

File tree

4 files changed

+241
-94
lines changed

4 files changed

+241
-94
lines changed
 

‎src/gui/qgsattributetable.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ void QgsAttributeTable::deleteAttribute(const QString& name)
369369
mEdited=true;
370370
}
371371

372+
373+
/* Deprecated: See QgisApp::editCopy() instead */
372374
void QgsAttributeTable::copySelectedRows()
373375
{
374376
// Copy selected rows to the clipboard
@@ -413,21 +415,23 @@ void QgsAttributeTable::copySelectedRows()
413415

414416
bool QgsAttributeTable::commitChanges(QgsVectorLayer* layer)
415417
{
416-
bool returnvalue=true;
417-
if(layer)
418-
{
419-
if(!layer->commitAttributeChanges(mDeletedAttributes, mAddedAttributes, mChangedValues))
420-
{
421-
returnvalue=false;
422-
}
423-
}
424-
else
425-
{
426-
returnvalue=false;
427-
}
418+
bool isSuccessful = FALSE;
419+
420+
if(layer)
421+
{
422+
isSuccessful = layer->commitAttributeChanges(
423+
mDeletedAttributes,
424+
mAddedAttributes,
425+
mChangedValues);
426+
}
427+
428+
if (isSuccessful)
429+
{
428430
mEdited=false;
429431
clearEditingStructures();
430-
return returnvalue;
432+
}
433+
434+
return isSuccessful;
431435
}
432436

433437
bool QgsAttributeTable::rollBack(QgsVectorLayer* layer)

‎src/gui/qgsattributetable.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,25 @@ class QgsAttributeTable:public Q3Table
7070
/**Deletes an attribute (but does not commit it)
7171
@param name attribute name*/
7272
void deleteAttribute(const QString& name);
73-
/**Copies the selected rows to the clipboard */
73+
74+
/** Copies the selected rows to the clipboard
75+
Deprecated: See QgisApp::editCopy() instead */
7476
void copySelectedRows();
75-
/**Delegates to QgsVectorLayer to decide, which changes
76-
belong to not commited features or to commited ones*/
77+
78+
/**
79+
Attempts to commit any changes to disk. Returns the result of the attempt.
80+
If a commit fails, the in-memory changes are left alone.
81+
82+
This allows editing to continue if the commit failed on e.g. a
83+
disallowed value in a Postgres database - the user can re-edit and try
84+
again.
85+
86+
Delegates to QgsVectorLayer to decide, which changes
87+
belong to not commited features or to commited ones.
88+
89+
*/
7790
bool commitChanges(QgsVectorLayer* layer);
91+
7892
/**Discard all changes and restore
7993
the state before editing was started*/
8094
bool rollBack(QgsVectorLayer* layer);

0 commit comments

Comments
 (0)