Spreadsheet: Expressions using a spreadsheet cell address are now correctly renamed when rows/columns are removed/inserted.

This commit is contained in:
Eivind Kvedalen 2015-10-07 22:13:23 +02:00 committed by wmayer
parent 29695a8ae7
commit e2650860cc
2 changed files with 20 additions and 7 deletions

View File

@ -504,7 +504,7 @@ void PropertySheet::clear(CellAddress address)
rebuildDocDepList();
}
void PropertySheet::moveCell(CellAddress currPos, CellAddress newPos)
void PropertySheet::moveCell(CellAddress currPos, CellAddress newPos, std::map<App::ObjectIdentifier, App::ObjectIdentifier> & renames)
{
std::map<CellAddress, Cell*>::const_iterator i = data.find(currPos);
std::map<CellAddress, Cell*>::const_iterator j = data.find(newPos);
@ -528,6 +528,8 @@ void PropertySheet::moveCell(CellAddress currPos, CellAddress newPos)
addDependencies(newPos);
setDirty(newPos);
renames[ObjectIdentifier(owner, currPos.toString())] = ObjectIdentifier(owner, newPos.toString());
rebuildDocDepList();
}
}
@ -609,6 +611,7 @@ private:
void PropertySheet::insertRows(int row, int count)
{
std::vector<CellAddress> keys;
std::map<App::ObjectIdentifier, App::ObjectIdentifier> renames;
/* Copy all keys from cells map */
boost::copy( data | boost::adaptors::map_keys, std::back_inserter(keys));
@ -635,8 +638,10 @@ void PropertySheet::insertRows(int row, int count)
}
if (i->row() >= row)
moveCell(*i, CellAddress(i->row() + count, i->col()));
moveCell(*i, CellAddress(i->row() + count, i->col()), renames);
}
owner->getDocument()->renameObjectIdentifiers(renames);
}
/**
@ -654,6 +659,7 @@ bool PropertySheet::rowSortFunc(const CellAddress & a, const CellAddress & b) {
void PropertySheet::removeRows(int row, int count)
{
std::vector<CellAddress> keys;
std::map<App::ObjectIdentifier, App::ObjectIdentifier> renames;
/* Copy all keys from cells map */
boost::copy(data | boost::adaptors::map_keys, std::back_inserter(keys));
@ -682,14 +688,16 @@ void PropertySheet::removeRows(int row, int count)
if (i->row() >= row && i->row() < row + count)
clear(*i);
else if (i->row() >= row + count)
moveCell(*i, CellAddress(i->row() - count, i->col()));
moveCell(*i, CellAddress(i->row() - count, i->col()), renames);
}
owner->getDocument()->renameObjectIdentifiers(renames);
}
void PropertySheet::insertColumns(int col, int count)
{
std::vector<CellAddress> keys;
std::map<App::ObjectIdentifier, App::ObjectIdentifier> renames;
/* Copy all keys from cells map */
boost::copy(data | boost::adaptors::map_keys, std::back_inserter(keys));
@ -716,8 +724,10 @@ void PropertySheet::insertColumns(int col, int count)
}
if (i->col() >= col)
moveCell(*i, CellAddress(i->row(), i->col() + count));
moveCell(*i, CellAddress(i->row(), i->col() + count), renames);
}
owner->getDocument()->renameObjectIdentifiers(renames);
}
/**
@ -735,6 +745,7 @@ bool PropertySheet::colSortFunc(const CellAddress & a, const CellAddress & b) {
void PropertySheet::removeColumns(int col, int count)
{
std::vector<CellAddress> keys;
std::map<App::ObjectIdentifier, App::ObjectIdentifier> renames;
/* Copy all keys from cells map */
boost::copy(data | boost::adaptors::map_keys, std::back_inserter(keys));
@ -763,8 +774,10 @@ void PropertySheet::removeColumns(int col, int count)
if (i->col() >= col && i->col() < col + count)
clear(*i);
else if (i->col() >= col + count)
moveCell(*i, CellAddress(i->row(), i->col() - count));
moveCell(*i, CellAddress(i->row(), i->col() - count), renames);
}
owner->getDocument()->renameObjectIdentifiers(renames);
}
unsigned int PropertySheet::getMemSize() const

View File

@ -95,7 +95,7 @@ public:
bool isDirty() const { return dirty.size() > 0; }
void moveCell(CellAddress currPos, CellAddress newPos);
void moveCell(CellAddress currPos, CellAddress newPos, std::map<App::ObjectIdentifier, App::ObjectIdentifier> &renames);
void insertRows(int row, int count);