Sheet: modernize C++: use range-based for loop
This commit is contained in:
@@ -57,13 +57,10 @@ TYPESYSTEM_SOURCE(Spreadsheet::PropertySheet , App::PropertyExpressionContainer)
|
||||
|
||||
void PropertySheet::clear()
|
||||
{
|
||||
std::map<CellAddress, Cell* >::iterator i = data.begin();
|
||||
|
||||
/* Clear cells */
|
||||
while (i != data.end()) {
|
||||
delete i->second;
|
||||
setDirty(i->first);
|
||||
++i;
|
||||
for (auto & it : data) {
|
||||
delete it.second;
|
||||
setDirty(it.first);
|
||||
}
|
||||
|
||||
/* Clear from map */
|
||||
@@ -188,9 +185,9 @@ std::vector<CellAddress> PropertySheet::getUsedCells() const
|
||||
{
|
||||
std::vector<CellAddress> usedSet;
|
||||
|
||||
for (std::map<CellAddress, Cell*>::const_iterator i = data.begin(); i != data.end(); ++i) {
|
||||
if (i->second->isUsed())
|
||||
usedSet.push_back(i->first);
|
||||
for (const auto& i : data) {
|
||||
if (i.second->isUsed())
|
||||
usedSet.push_back(i.first);
|
||||
}
|
||||
|
||||
return usedSet;
|
||||
@@ -207,10 +204,10 @@ std::vector<CellAddress> PropertySheet::getNonEmptyCells() const
|
||||
std::vector<CellAddress> usedSet;
|
||||
|
||||
std::string str;
|
||||
for (std::map<CellAddress, Cell*>::const_iterator i = data.begin(); i != data.end(); ++i) {
|
||||
for (const auto& i : data) {
|
||||
str.clear();
|
||||
if (i->second->isUsed() && i->second->getStringContent(str) && !str.empty())
|
||||
usedSet.push_back(i->first);
|
||||
if (i.second->isUsed() && i.second->getStringContent(str) && !str.empty())
|
||||
usedSet.push_back(i.first);
|
||||
}
|
||||
|
||||
return usedSet;
|
||||
@@ -927,16 +924,16 @@ void PropertySheet::removeRows(int row, int count)
|
||||
AtomicPropertyChange signaller(*this);
|
||||
|
||||
// move all the aliases first so dependencies can be calculated correctly
|
||||
for (std::vector<CellAddress>::const_iterator i = keys.begin(); i != keys.end(); ++i) {
|
||||
if (i->row() >= row && i->row() < row + count)
|
||||
clearAlias(*i);
|
||||
else if (i->row() >= row + count)
|
||||
moveAlias(*i, CellAddress(i->row() - count, i->col()));
|
||||
for (const auto& key : keys) {
|
||||
if (key.row() >= row && key.row() < row + count)
|
||||
clearAlias(key);
|
||||
else if (key.row() >= row + count)
|
||||
moveAlias(key, CellAddress(key.row() - count, key.col()));
|
||||
}
|
||||
|
||||
int spanRows, spanCols;
|
||||
for (std::vector<CellAddress>::const_iterator i = keys.begin(); i != keys.end(); ++i) {
|
||||
std::map<CellAddress, Cell*>::iterator j = data.find(*i);
|
||||
for (const auto& key : keys) {
|
||||
std::map<CellAddress, Cell*>::iterator j = data.find(key);
|
||||
|
||||
assert(j != data.end());
|
||||
|
||||
@@ -946,19 +943,19 @@ void PropertySheet::removeRows(int row, int count)
|
||||
visitor.reset();
|
||||
cell->visit(visitor);
|
||||
if (visitor.changed()) {
|
||||
setDirty(*i);
|
||||
recomputeDependencies(*i);
|
||||
setDirty(key);
|
||||
recomputeDependencies(key);
|
||||
}
|
||||
|
||||
if (i->row() >= row && i->row() < row + count)
|
||||
clear(*i, false); // aliases were cleared earlier
|
||||
else if (i->row() >= row + count)
|
||||
moveCell(*i, CellAddress(i->row() - count, i->col()), renames);
|
||||
else if (cell->getSpans(spanRows, spanCols) && i->row() + spanRows >= row) {
|
||||
if (i->row() + spanRows >= row + count)
|
||||
if (key.row() >= row && key.row() < row + count)
|
||||
clear(key, false); // aliases were cleared earlier
|
||||
else if (key.row() >= row + count)
|
||||
moveCell(key, CellAddress(key.row() - count, key.col()), renames);
|
||||
else if (cell->getSpans(spanRows, spanCols) && key.row() + spanRows >= row) {
|
||||
if (key.row() + spanRows >= row + count)
|
||||
spanRows -= count;
|
||||
else
|
||||
spanRows = i->row() - row;
|
||||
spanRows = key.row() - row;
|
||||
mergeCells(j->first, CellAddress(j->first.row()+spanRows-1, j->first.col()+spanCols-1));
|
||||
}
|
||||
}
|
||||
@@ -1055,16 +1052,16 @@ void PropertySheet::removeColumns(int col, int count)
|
||||
AtomicPropertyChange signaller(*this);
|
||||
|
||||
// move all the aliases first so dependencies can be calculated correctly
|
||||
for (std::vector<CellAddress>::const_iterator i = keys.begin(); i != keys.end(); ++i) {
|
||||
if (i->col() >= col && i->col() < col + count)
|
||||
clearAlias(*i);
|
||||
else if (i->col() >= col + count)
|
||||
moveAlias(*i, CellAddress(i->row(), i->col() - count));
|
||||
for (const auto& key : keys) {
|
||||
if (key.col() >= col && key.col() < col + count)
|
||||
clearAlias(key);
|
||||
else if (key.col() >= col + count)
|
||||
moveAlias(key, CellAddress(key.row(), key.col() - count));
|
||||
}
|
||||
|
||||
int spanRows, spanCols;
|
||||
for (std::vector<CellAddress>::const_iterator i = keys.begin(); i != keys.end(); ++i) {
|
||||
std::map<CellAddress, Cell*>::iterator j = data.find(*i);
|
||||
for (const auto& key : keys) {
|
||||
std::map<CellAddress, Cell*>::iterator j = data.find(key);
|
||||
|
||||
assert(j != data.end());
|
||||
|
||||
@@ -1074,19 +1071,19 @@ void PropertySheet::removeColumns(int col, int count)
|
||||
visitor.reset();
|
||||
cell->visit(visitor);
|
||||
if (visitor.changed()) {
|
||||
setDirty(*i);
|
||||
recomputeDependencies(*i);
|
||||
setDirty(key);
|
||||
recomputeDependencies(key);
|
||||
}
|
||||
|
||||
if (i->col() >= col && i->col() < col + count)
|
||||
clear(*i, false); // aliases were cleared earlier
|
||||
else if (i->col() >= col + count)
|
||||
moveCell(*i, CellAddress(i->row(), i->col() - count), renames);
|
||||
else if (cell->getSpans(spanRows, spanCols) && i->col() + spanCols >= col) {
|
||||
if (i->col() + spanCols >= col + count)
|
||||
if (key.col() >= col && key.col() < col + count)
|
||||
clear(key, false); // aliases were cleared earlier
|
||||
else if (key.col() >= col + count)
|
||||
moveCell(key, CellAddress(key.row(), key.col() - count), renames);
|
||||
else if (cell->getSpans(spanRows, spanCols) && key.col() + spanCols >= col) {
|
||||
if (key.col() + spanCols >= col + count)
|
||||
spanCols -= count;
|
||||
else
|
||||
spanCols = i->col() - col;
|
||||
spanCols = key.col() - col;
|
||||
mergeCells(j->first, CellAddress(j->first.row()+spanRows-1, j->first.col()+spanCols-1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,16 +106,18 @@ void Sheet::clearAll()
|
||||
|
||||
std::vector<std::string> propNames = props.getDynamicPropertyNames();
|
||||
|
||||
for (std::vector<std::string>::const_iterator i = propNames.begin(); i != propNames.end(); ++i)
|
||||
this->removeDynamicProperty((*i).c_str());
|
||||
for (const auto & propName : propNames) {
|
||||
this->removeDynamicProperty(propName.c_str());
|
||||
}
|
||||
|
||||
propAddress.clear();
|
||||
cellErrors.clear();
|
||||
columnWidths.clear();
|
||||
rowHeights.clear();
|
||||
|
||||
for (ObserverMap::iterator i = observers.begin(); i != observers.end(); ++i)
|
||||
delete i->second;
|
||||
for (auto & observer : observers) {
|
||||
delete observer.second;
|
||||
}
|
||||
observers.clear();
|
||||
}
|
||||
|
||||
@@ -230,8 +232,7 @@ bool Sheet::importFromFile(const std::string &filename, char delimiter, char quo
|
||||
|
||||
static void writeEscaped(std::string const& s, char quoteChar, char escapeChar, std::ostream & out) {
|
||||
out << quoteChar;
|
||||
for (std::string::const_iterator i = s.begin(), end = s.end(); i != end; ++i) {
|
||||
unsigned char c = *i;
|
||||
for (unsigned char c : s) {
|
||||
if (c != quoteChar)
|
||||
out << c;
|
||||
else {
|
||||
@@ -909,9 +910,9 @@ DocumentObjectExecReturn *Sheet::execute()
|
||||
std::set<CellAddress> dirtyCells = cells.getDirty();
|
||||
|
||||
// Always recompute cells that have failed
|
||||
for (std::set<CellAddress>::const_iterator i = cellErrors.begin(); i != cellErrors.end(); ++i) {
|
||||
cells.recomputeDependencies(*i);
|
||||
dirtyCells.insert(*i);
|
||||
for (auto cellError : cellErrors) {
|
||||
cells.recomputeDependencies(cellError);
|
||||
dirtyCells.insert(cellError);
|
||||
}
|
||||
|
||||
DependencyList graph;
|
||||
@@ -1033,14 +1034,15 @@ DocumentObjectExecReturn *Sheet::execute()
|
||||
// Signal update of column widths
|
||||
const std::set<int> & dirtyColumns = columnWidths.getDirty();
|
||||
|
||||
for (std::set<int>::const_iterator i = dirtyColumns.begin(); i != dirtyColumns.end(); ++i)
|
||||
columnWidthChanged(*i, columnWidths.getValue(*i));
|
||||
for (int dirtyColumn : dirtyColumns) {
|
||||
columnWidthChanged(dirtyColumn, columnWidths.getValue(dirtyColumn));
|
||||
}
|
||||
|
||||
// Signal update of row heights
|
||||
const std::set<int> & dirtyRows = rowHeights.getDirty();
|
||||
|
||||
for (std::set<int>::const_iterator i = dirtyRows.begin(); i != dirtyRows.end(); ++i)
|
||||
rowHeightChanged(*i, rowHeights.getValue(*i));
|
||||
for (int dirtyRow : dirtyRows)
|
||||
rowHeightChanged(dirtyRow, rowHeights.getValue(dirtyRow));
|
||||
|
||||
//cells.clearDirty();
|
||||
rowHeights.clearDirty();
|
||||
@@ -1460,8 +1462,9 @@ void Sheet::providesTo(CellAddress address, std::set<std::string> & result) cons
|
||||
std::string fullName = getFullName() + ".";
|
||||
std::set<CellAddress> tmpResult = cells.getDeps(fullName + address.toString());
|
||||
|
||||
for (std::set<CellAddress>::const_iterator i = tmpResult.begin(); i != tmpResult.end(); ++i)
|
||||
result.insert(fullName + i->toString());
|
||||
for (const auto& i : tmpResult) {
|
||||
result.insert(fullName + i.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -367,8 +367,9 @@ PyObject* SheetPy::setStyle(PyObject *args)
|
||||
if (cell)
|
||||
cell->getStyle(oldStyle);
|
||||
|
||||
for (std::set<std::string>::const_iterator it = oldStyle.begin(); it != oldStyle.end(); ++it)
|
||||
style.insert(*it);
|
||||
for (const auto & it : oldStyle) {
|
||||
style.insert(it);
|
||||
}
|
||||
|
||||
// Set new style
|
||||
getSheetPtr()->setStyle(*rangeIter, style);
|
||||
@@ -385,8 +386,9 @@ PyObject* SheetPy::setStyle(PyObject *args)
|
||||
if (cell)
|
||||
cell->getStyle(oldStyle);
|
||||
|
||||
for (std::set<std::string>::const_iterator it = style.begin(); it != style.end(); ++it)
|
||||
oldStyle.erase(*it);
|
||||
for (const auto & it : style) {
|
||||
oldStyle.erase(it);
|
||||
}
|
||||
|
||||
// Set new style
|
||||
getSheetPtr()->setStyle(*rangeIter, oldStyle);
|
||||
@@ -406,13 +408,15 @@ PyObject* SheetPy::setStyle(PyObject *args)
|
||||
newStyle = oldStyle;
|
||||
}
|
||||
|
||||
for (std::set<std::string>::const_iterator i = style.begin(); i != style.end(); ++i) {
|
||||
if (oldStyle.find(*i) == oldStyle.end())
|
||||
for (const auto & i : style) {
|
||||
if (oldStyle.find(i) == oldStyle.end()) {
|
||||
// Not found in oldstyle; add it to newStyle
|
||||
newStyle.insert(*i);
|
||||
else
|
||||
newStyle.insert(i);
|
||||
}
|
||||
else {
|
||||
// Found in oldStyle, remove it from newStyle
|
||||
newStyle.erase(*i);
|
||||
newStyle.erase(i);
|
||||
}
|
||||
}
|
||||
|
||||
// Set new style
|
||||
@@ -449,8 +453,9 @@ PyObject* SheetPy::getStyle(PyObject *args)
|
||||
if (cell && cell->getStyle(style)) {
|
||||
PyObject * s = PySet_New(nullptr);
|
||||
|
||||
for (std::set<std::string>::const_iterator i = style.begin(); i != style.end(); ++i)
|
||||
PySet_Add(s, PyUnicode_FromString((*i).c_str()));
|
||||
for (const auto & i : style) {
|
||||
PySet_Add(s, PyUnicode_FromString(i.c_str()));
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user