[Spreadsheet] Remove alias from dynamic properties on removeRows/Columns
When removing a row in a spreadsheet which has an assigned alias, the alias will not be removed from the list of dynamic properties. This makes it impossible to create a new alias which uses the same name even if the original was removed (using removeRows/removeColumns) Fixes #4492
This commit is contained in:
@@ -741,6 +741,18 @@ bool PropertySheet::rowSortFunc(const CellAddress & a, const CellAddress & b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<CellAddress> PropertySheet::getRows(int row, int count) const
|
||||
{
|
||||
std::vector<CellAddress> keys;
|
||||
|
||||
for (const auto &i : data) {
|
||||
auto key = i.first;
|
||||
if (key.row() >= row && key.row() < row + count)
|
||||
keys.push_back(key);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
void PropertySheet::removeRows(int row, int count)
|
||||
{
|
||||
std::vector<CellAddress> keys;
|
||||
@@ -849,6 +861,18 @@ bool PropertySheet::colSortFunc(const CellAddress & a, const CellAddress & b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<CellAddress> PropertySheet::getColumns(int column, int count) const
|
||||
{
|
||||
std::vector<CellAddress> keys;
|
||||
|
||||
for (const auto &i : data) {
|
||||
auto key = i.first;
|
||||
if (key.col() >= column && key.col() < column + count)
|
||||
keys.push_back(key);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
void PropertySheet::removeColumns(int col, int count)
|
||||
{
|
||||
std::vector<CellAddress> keys;
|
||||
|
||||
@@ -130,10 +130,14 @@ public:
|
||||
|
||||
void insertRows(int row, int count);
|
||||
|
||||
std::vector<App::CellAddress> getRows(int row, int count) const;
|
||||
|
||||
void removeRows(int row, int count);
|
||||
|
||||
void insertColumns(int col, int count);
|
||||
|
||||
std::vector<App::CellAddress> getColumns(int column, int count) const;
|
||||
|
||||
void removeColumns(int col, int count);
|
||||
|
||||
virtual unsigned int getMemSize (void) const override;
|
||||
|
||||
@@ -1135,6 +1135,14 @@ void Sheet::insertColumns(int col, int count)
|
||||
|
||||
void Sheet::removeColumns(int col, int count)
|
||||
{
|
||||
// Remove aliases, if defined
|
||||
for (auto address : cells.getColumns(col, count)) {
|
||||
auto cell = getCell(address);
|
||||
std::string aliasStr;
|
||||
if (cell && cell->getAlias(aliasStr))
|
||||
removeDynamicProperty(aliasStr.c_str());
|
||||
}
|
||||
|
||||
cells.removeColumns(col, count);
|
||||
updateColumnsOrRows(true,col,-count);
|
||||
}
|
||||
@@ -1163,6 +1171,14 @@ void Sheet::insertRows(int row, int count)
|
||||
|
||||
void Sheet::removeRows(int row, int count)
|
||||
{
|
||||
// Remove aliases, if defined
|
||||
for (auto address : cells.getRows(row, count)) {
|
||||
auto cell = getCell(address);
|
||||
std::string aliasStr;
|
||||
if (cell && cell->getAlias(aliasStr))
|
||||
removeDynamicProperty(aliasStr.c_str());
|
||||
}
|
||||
|
||||
cells.removeRows(row, count);
|
||||
updateColumnsOrRows(false,row,-count);
|
||||
}
|
||||
|
||||
@@ -1073,6 +1073,14 @@ class SpreadsheetCases(unittest.TestCase):
|
||||
self.doc.recompute()
|
||||
self.assertEqual(sheet.A3, 3)
|
||||
|
||||
def testRemoveRowsAliasReuseName(self):
|
||||
""" Regression test for issue 4492; deleted aliases remains in database"""
|
||||
sheet = self.doc.addObject('Spreadsheet::Sheet','Spreadsheet')
|
||||
sheet.setAlias('B2', 'test')
|
||||
self.doc.recompute()
|
||||
sheet.removeRows('2', 1)
|
||||
sheet.setAlias('B3','test')
|
||||
|
||||
def testRemoveColumnsAlias(self):
|
||||
""" Regression test for issue 4429; remove columns from sheet with aliases"""
|
||||
sheet = self.doc.addObject('Spreadsheet::Sheet','Spreadsheet')
|
||||
@@ -1086,6 +1094,14 @@ class SpreadsheetCases(unittest.TestCase):
|
||||
self.doc.recompute()
|
||||
self.assertEqual(sheet.C1, 3)
|
||||
|
||||
def testRemoveColumnsAliasReuseName(self):
|
||||
""" Regression test for issue 4492; deleted aliases remains in database"""
|
||||
sheet = self.doc.addObject('Spreadsheet::Sheet','Spreadsheet')
|
||||
sheet.setAlias('B2', 'test')
|
||||
self.doc.recompute()
|
||||
sheet.removeColumns('B', 1)
|
||||
sheet.setAlias('C3','test')
|
||||
|
||||
def tearDown(self):
|
||||
#closing doc
|
||||
FreeCAD.closeDocument(self.doc.Name)
|
||||
|
||||
Reference in New Issue
Block a user