Commit 4cd91f8a authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink
Browse files

Fix problem that prevents depths of cells to be calculated properly when cells are edited.

This was especially a problem if they are changed from a formula to something that is not a formula.
Also fixes a problem with DependencyManager::Private::dump(), and fixes KoRTree API docs to match
the implementation (although it would be better to fix the implementation to match the docs).

BUGS=312981
parent 5220492e
......@@ -106,7 +106,7 @@ public:
/**
* @brief Find all data rectangles
* The order is guaranteed to be the same as that used by values().
* The order is NOT guaranteed to be the same as that used by values().
*
* @return a list containing all the data rectangles used in the tree
*/
......@@ -114,7 +114,7 @@ public:
/**
* @brief Find all data items
* The order is guaranteed to be the same as that used by keys().
* The order is NOT guaranteed to be the same as that used by keys().
*
* @return a list containing all the data used in the tree
*/
......
......@@ -46,8 +46,8 @@ using namespace Calligra::Sheets;
// gdb or from debug output to check that everything is set up ok.
void DependencyManager::Private::dump() const
{
QHash<Cell, Region>::ConstIterator mend(providers.end());
for (QHash<Cell, Region>::ConstIterator mit(providers.begin()); mit != mend; ++mit) {
QMap<Cell, Region>::ConstIterator mend(providers.end());
for (QMap<Cell, Region>::ConstIterator mit(providers.begin()); mit != mend; ++mit) {
Cell cell = mit.key();
QStringList debugStr;
......@@ -60,12 +60,11 @@ void DependencyManager::Private::dump() const
}
foreach(Sheet* sheet, consumers.keys()) {
QList<QRectF> keys = consumers[sheet]->keys();
QList<Cell> values = consumers[sheet]->values();
const QList< QPair<QRectF, Cell> > pairs = consumers[sheet]->intersectingPairs(QRect(1, 1, KS_colMax, KS_rowMax)).values();
QHash<QString, QString> table;
for (int i = 0; i < keys.count(); ++i) {
Region tmpRange(keys[i].toRect(), sheet);
table.insertMulti(tmpRange.name(), values[i].name());
for (int i = 0; i < pairs.count(); ++i) {
Region tmpRange(pairs[i].first.toRect(), sheet);
table.insertMulti(tmpRange.name(), pairs[i].second.name());
}
foreach(const QString &uniqueKey, table.uniqueKeys()) {
QStringList debugStr(table.values(uniqueKey));
......@@ -429,33 +428,13 @@ void DependencyManager::Private::generateDepths(const Region& region)
int bottom = range.bottom();
if (bottom > cells->rows()) bottom = cells->rows();
int right = range.right();
if (right > cells->columns()) right = cells->columns();
for (int row = range.top(); row <= bottom; ++row) {
int col = 0;
Formula formula = sheet->formulaStorage()->firstInRow(row, &col);
if (col > 0 && col < range.left())
formula = sheet->formulaStorage()->nextInRow(col, row, &col);
while (col != 0 && col <= range.right()) {
for (int col = range.left(); col <= right; ++col) {
Cell cell(sheet, col, row);
// compute the cell depth and automatically the depths of its providers
int depth = computeDepth(cell);
depths.insert(cell, depth);
// compute the consumers' depths
QHash<Sheet*, RTree<Cell>*>::ConstIterator cit = consumers.constFind(cell.sheet());
if (cit == consumers.constEnd()) {
formula = sheet->formulaStorage()->nextInRow(col, row, &col);
continue;
}
const QList<Cell> consumers = cit.value()->contains(cell.cellPosition());
foreach (const Cell &c, consumers) {
if (!region.contains(c.cellPosition(), c.sheet()))
generateDepths(c, computedDepths);
}
formula = sheet->formulaStorage()->nextInRow(col, row, &col);
generateDepths(cell, computedDepths);
}
}
}
......
......@@ -83,6 +83,31 @@ void TestDependencies::testCircles()
QCOMPARE(m_storage->value(1, 3), Value::errorCIRCLE());
}
void TestDependencies::testDepths()
{
Cell a1(m_sheet, 1, 1); a1.setUserInput("5");
Cell a2(m_sheet, 1, 2); a2.setUserInput("=A1");
Cell a3(m_sheet, 1, 3); a3.setUserInput("=A2");
Cell a4(m_sheet, 1, 4); a4.setUserInput("=A1 + A3");
QApplication::processEvents(); // handle Damages
QMap<Cell, int> depths = m_map->dependencyManager()->depths();
QCOMPARE(depths[a1], 0);
QCOMPARE(depths[a2], 1);
QCOMPARE(depths[a3], 2);
QCOMPARE(depths[a4], 3);
a2.setUserInput("");
QApplication::processEvents(); // handle Damages
depths = m_map->dependencyManager()->depths();
QCOMPARE(depths[a1], 0);
QCOMPARE(depths[a2], 0);
QCOMPARE(depths[a3], 1);
QCOMPARE(depths[a4], 2);
}
void TestDependencies::cleanupTestCase()
{
delete m_map;
......
......@@ -39,6 +39,7 @@ private Q_SLOTS:
void initTestCase();
void testCircleRemoval();
void testCircles();
void testDepths();
void cleanupTestCase();
private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment