From dd6757bbb8c3d984ca7d3c0be1d7588e57771f49 Mon Sep 17 00:00:00 2001 From: Eivind Kvedalen Date: Sat, 4 Nov 2017 20:05:31 +0100 Subject: [PATCH] Spreadsheet: Fix for issue #3225. Done by adding a selector function to Document::renameObjectIdentifiers(...) to ensure that the Spreadsheet document object is not rewritten twice. --- src/App/Document.cpp | 5 +++-- src/App/Document.h | 3 ++- src/Mod/Spreadsheet/App/PropertySheet.cpp | 12 ++++++++---- src/Mod/Spreadsheet/TestSpreadsheet.py | 8 ++++++++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 50991a1fb9..87faad5e77 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -2029,7 +2029,7 @@ std::vector Document::getDependencyList(const std::vector< * @param paths Map with current and new names */ -void Document::renameObjectIdentifiers(const std::map &paths) +void Document::renameObjectIdentifiers(const std::map &paths, const std::function & selector) { std::map extendedPaths; @@ -2040,7 +2040,8 @@ void Document::renameObjectIdentifiers(const std::map::iterator it = d->objectArray.begin(); it != d->objectArray.end(); ++it) - (*it)->renameObjectIdentifiers(extendedPaths); + if (selector(*it)) + (*it)->renameObjectIdentifiers(extendedPaths); } #ifdef USE_OLD_DAG diff --git a/src/App/Document.h b/src/App/Document.h index b88985f476..2cd3b9bdfc 100644 --- a/src/App/Document.h +++ b/src/App/Document.h @@ -35,6 +35,7 @@ #include #include #include +#include #include @@ -338,7 +339,7 @@ public: //@} /// Function called to signal that an object identifier has been renamed - void renameObjectIdentifiers(const std::map & paths); + void renameObjectIdentifiers(const std::map & paths, const std::function &selector = [](const App::DocumentObject *) { return true; }); virtual PyObject *getPyObject(void); diff --git a/src/Mod/Spreadsheet/App/PropertySheet.cpp b/src/Mod/Spreadsheet/App/PropertySheet.cpp index 3e743f9ade..051834d183 100644 --- a/src/Mod/Spreadsheet/App/PropertySheet.cpp +++ b/src/Mod/Spreadsheet/App/PropertySheet.cpp @@ -678,7 +678,8 @@ void PropertySheet::insertRows(int row, int count) moveCell(*i, CellAddress(i->row() + count, i->col()), renames); } - owner->getDocument()->renameObjectIdentifiers(renames); + const App::DocumentObject * docObj = static_cast(getContainer()); + owner->getDocument()->renameObjectIdentifiers(renames, [docObj](const App::DocumentObject * obj) { return obj != docObj; }); } /** @@ -728,7 +729,8 @@ void PropertySheet::removeRows(int row, int count) moveCell(*i, CellAddress(i->row() - count, i->col()), renames); } - owner->getDocument()->renameObjectIdentifiers(renames); + const App::DocumentObject * docObj = static_cast(getContainer()); + owner->getDocument()->renameObjectIdentifiers(renames, [docObj](const App::DocumentObject * obj) { return obj != docObj; }); } void PropertySheet::insertColumns(int col, int count) @@ -764,7 +766,8 @@ void PropertySheet::insertColumns(int col, int count) moveCell(*i, CellAddress(i->row(), i->col() + count), renames); } - owner->getDocument()->renameObjectIdentifiers(renames); + const App::DocumentObject * docObj = static_cast(getContainer()); + owner->getDocument()->renameObjectIdentifiers(renames, [docObj](const App::DocumentObject * obj) { return obj != docObj; }); } /** @@ -814,7 +817,8 @@ void PropertySheet::removeColumns(int col, int count) moveCell(*i, CellAddress(i->row(), i->col() - count), renames); } - owner->getDocument()->renameObjectIdentifiers(renames); + const App::DocumentObject * docObj = static_cast(getContainer()); + owner->getDocument()->renameObjectIdentifiers(renames, [docObj](const App::DocumentObject * obj) { return obj != docObj; } ); } unsigned int PropertySheet::getMemSize() const diff --git a/src/Mod/Spreadsheet/TestSpreadsheet.py b/src/Mod/Spreadsheet/TestSpreadsheet.py index b3880b5b27..11d41a5afc 100644 --- a/src/Mod/Spreadsheet/TestSpreadsheet.py +++ b/src/Mod/Spreadsheet/TestSpreadsheet.py @@ -660,6 +660,14 @@ class SpreadsheetCases(unittest.TestCase): sheet.insertRows('2', 1) self.assertEqual(sheet.getContents("B1"),"=B3") + def testIssue3225(self): + """ Inserting rows -- check renaming of internal cells """ + sheet = self.doc.addObject('Spreadsheet::Sheet','Spreadsheet') + sheet.set('B2', '25') + sheet.set('B3', '=B2') + sheet.insertRows('2', 1) + self.assertEqual(sheet.getContents("B4"),"=B3") + def testRenameAlias(self): """ Test renaming of alias1 to alias2 in a spreadsheet """ sheet = self.doc.addObject('Spreadsheet::Sheet','Spreadsheet')