Kaydet (Commit) e3b91687 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Fix the horizontal cell iterator.

I got its logic totally wrong. Now it works.

Change-Id: I79e556da19c7c0b0d8cecbb4875d6d21d5ec4208
üst 2a5ea9ee
...@@ -410,8 +410,6 @@ public: ...@@ -410,8 +410,6 @@ public:
class ScHorizontalCellIterator // walk through all non empty cells in an area class ScHorizontalCellIterator // walk through all non empty cells in an area
{ // row by row { // row by row
typedef std::pair<sc::CellStoreType::const_iterator,size_t> PositionType;
struct ColParam struct ColParam
{ {
sc::CellStoreType::const_iterator maPos; sc::CellStoreType::const_iterator maPos;
......
...@@ -1672,7 +1672,7 @@ bool ScQueryCellIterator::BinarySearch() ...@@ -1672,7 +1672,7 @@ bool ScQueryCellIterator::BinarySearch()
ScHorizontalCellIterator::ScHorizontalCellIterator(ScDocument* pDocument, SCTAB nTable, ScHorizontalCellIterator::ScHorizontalCellIterator(ScDocument* pDocument, SCTAB nTable,
SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) : SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) :
maColPositions(nCol2-nCol2+1), maColPositions(nCol2-nCol1+1),
pDoc( pDocument ), pDoc( pDocument ),
mnTab( nTable ), mnTab( nTable ),
nStartCol( nCol1 ), nStartCol( nCol1 ),
...@@ -1768,35 +1768,74 @@ void ScHorizontalCellIterator::Advance() ...@@ -1768,35 +1768,74 @@ void ScHorizontalCellIterator::Advance()
} }
// Move to the next row that has at least one non-empty cell. // Move to the next row that has at least one non-empty cell.
size_t nMinRow = MAXROW+1; ++mnRow;
size_t nMinRowCol = maColPositions.size(); while (mnRow <= nEndRow)
for (size_t i = 0, n = maColPositions.size(); i < n; ++i)
{ {
ColParam& r = maColPositions[i]; size_t nRow = static_cast<size_t>(mnRow);
if (r.maPos == r.maEnd) size_t nNextRow = MAXROW+1;
// This column has ended. size_t nNextRowPos = 0;
continue; for (size_t i = nNextRowPos, n = maColPositions.size(); i < n; ++i)
{
ColParam& r = maColPositions[i];
if (r.maPos == r.maEnd)
// This column has ended.
continue;
// Move to the next block. if (nRow < r.maPos->position)
++r.maPos; {
// This block is ahread of the current row position. Skip it.
if (r.maPos->position < nNextRow)
{
nNextRow = r.maPos->position;
nNextRowPos = i;
}
continue;
}
if (r.maPos->position + r.maPos->size <= nRow)
{
// This block is behind the current row position. Advance the block.
for (++r.maPos; r.maPos != r.maEnd; ++r.maPos)
{
if (nRow < r.maPos->position + r.maPos->size)
break;
}
if (r.maPos != r.maEnd && r.maPos->position < nMinRow) if (r.maPos == r.maEnd)
// This column has ended.
continue;
}
if (r.maPos->type == sc::element_type_empty)
{
// Empty block. Move to the next block and try next column.
++r.maPos;
if (r.maPos->position < nNextRow)
{
nNextRow = r.maPos->position;
nNextRowPos = i;
}
continue;
}
// Found a non-empty cell block!
mnCol = i + nStartCol;
mnRow = nRow;
bMore = true;
return;
}
if (nNextRow > MAXROW)
{ {
nMinRow = r.maPos->position; // No more blocks to search.
nMinRowCol = i; bMore = false;
return;
} }
}
if (nMinRowCol == maColPositions.size() || static_cast<SCROW>(nMinRow) > nEndRow) mnRow = nNextRow; // move to the next non-empty row.
{
// No more cells found.
bMore = false;
return;
} }
mnCol = nMinRowCol + nStartCol; bMore = false;
mnRow = nMinRow;
bMore = true;
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
......
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