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

Move cell notes too when sorting.

Change-Id: Ibb330aa6f515d756c5578296fd9c83aa235a59fd
üst bac1e2dd
...@@ -526,6 +526,7 @@ public: ...@@ -526,6 +526,7 @@ public:
// cell notes // cell notes
ScPostIt* GetCellNote( SCROW nRow ); ScPostIt* GetCellNote( SCROW nRow );
const ScPostIt* GetCellNote( SCROW nRow ) const; const ScPostIt* GetCellNote( SCROW nRow ) const;
const ScPostIt* GetCellNote( sc::ColumnBlockConstPosition& rBlockPos, SCROW nRow ) const;
void DeleteCellNotes( sc::ColumnBlockPosition& rBlockPos, SCROW nRow1, SCROW nRow2 ); void DeleteCellNotes( sc::ColumnBlockPosition& rBlockPos, SCROW nRow1, SCROW nRow2 );
bool HasCellNotes() const; bool HasCellNotes() const;
void SetCellNote( SCROW nRow, ScPostIt* pNote); void SetCellNote( SCROW nRow, ScPostIt* pNote);
...@@ -548,7 +549,8 @@ public: ...@@ -548,7 +549,8 @@ public:
void DuplicateNotes(SCROW nStartRow, size_t nDataSize, ScColumn& rDestCol, void DuplicateNotes(SCROW nStartRow, size_t nDataSize, ScColumn& rDestCol,
sc::ColumnBlockPosition& maDestBlockPos, bool bCloneCaption = true, SCROW nRowOffsetDest=0 ) const; sc::ColumnBlockPosition& maDestBlockPos, bool bCloneCaption = true, SCROW nRowOffsetDest=0 ) const;
void UpdateNoteCaptions();
void UpdateNoteCaptions( SCROW nRow1, SCROW nRow2 );
void InterpretDirtyCells( SCROW nRow1, SCROW nRow2 ); void InterpretDirtyCells( SCROW nRow1, SCROW nRow2 );
......
...@@ -2234,34 +2234,25 @@ void resetColumnPosition(sc::CellStoreType& rCells, SCCOL nCol) ...@@ -2234,34 +2234,25 @@ void resetColumnPosition(sc::CellStoreType& rCells, SCCOL nCol)
} }
} }
} class NoteCaptionUpdater
void ScColumn::UpdateNoteCaptions()
{ {
sc::CellNoteStoreType::const_iterator itBlk = maCellNotes.begin(), itBlkEnd = maCellNotes.end(); SCCOL mnCol;
sc::cellnote_block::const_iterator itData, itDataEnd; SCTAB mnTab;
public:
NoteCaptionUpdater( SCCOL nCol, SCTAB nTab ) : mnCol(nCol), mnTab(nTab) {}
SCROW curRow = 0; void operator() ( size_t nRow, ScPostIt* p )
for (;itBlk!=itBlkEnd;++itBlk)
{ {
if (itBlk->data) p->UpdateCaptionPos(ScAddress(mnCol,nRow,mnTab));
{
// non empty block
itData = sc::cellnote_block::begin(*itBlk->data);
itDataEnd = sc::cellnote_block::end(*itBlk->data);
for(;itData!=itDataEnd; ++itData)
{
ScPostIt* pNote = *itData;
pNote->UpdateCaptionPos(ScAddress(nCol, curRow, nTab));
curRow +=1;
}
}
else
{
// empty block
curRow += itBlk->size;
}
} }
};
}
void ScColumn::UpdateNoteCaptions( SCROW nRow1, SCROW nRow2 )
{
NoteCaptionUpdater aFunc(nCol, nTab);
sc::ProcessNote(maCellNotes.begin(), maCellNotes, nRow1, nRow2, aFunc);
} }
void ScColumn::SwapCol(ScColumn& rCol) void ScColumn::SwapCol(ScColumn& rCol)
...@@ -2272,8 +2263,8 @@ void ScColumn::SwapCol(ScColumn& rCol) ...@@ -2272,8 +2263,8 @@ void ScColumn::SwapCol(ScColumn& rCol)
maCellNotes.swap(rCol.maCellNotes); maCellNotes.swap(rCol.maCellNotes);
// notes update caption // notes update caption
UpdateNoteCaptions(); UpdateNoteCaptions(0, MAXROW);
rCol.UpdateNoteCaptions(); rCol.UpdateNoteCaptions(0, MAXROW);
ScAttrArray* pTempAttr = rCol.pAttrArray; ScAttrArray* pTempAttr = rCol.pAttrArray;
rCol.pAttrArray = pAttrArray; rCol.pAttrArray = pAttrArray;
...@@ -2322,7 +2313,7 @@ void ScColumn::MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol) ...@@ -2322,7 +2313,7 @@ void ScColumn::MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol)
// move the notes to the destination column // move the notes to the destination column
maCellNotes.transfer(nStartRow, nEndRow, rCol.maCellNotes, nStartRow); maCellNotes.transfer(nStartRow, nEndRow, rCol.maCellNotes, nStartRow);
UpdateNoteCaptions(); UpdateNoteCaptions(0, MAXROW);
// Re-group transferred formula cells. // Re-group transferred formula cells.
aPos = rCol.maCells.position(nStartRow); aPos = rCol.maCells.position(nStartRow);
......
...@@ -1848,6 +1848,17 @@ const ScPostIt* ScColumn::GetCellNote(SCROW nRow) const ...@@ -1848,6 +1848,17 @@ const ScPostIt* ScColumn::GetCellNote(SCROW nRow) const
return maCellNotes.get<ScPostIt*>(nRow); return maCellNotes.get<ScPostIt*>(nRow);
} }
const ScPostIt* ScColumn::GetCellNote( sc::ColumnBlockConstPosition& rBlockPos, SCROW nRow ) const
{
sc::CellNoteStoreType::const_position_type aPos = maCellNotes.position(rBlockPos.miCellNotePos, nRow);
rBlockPos.miCellNotePos = aPos.first;
if (aPos.first->type != sc::element_type_cellnote)
return NULL;
return sc::cellnote_block::at(*aPos.first->data, aPos.second);
}
void ScColumn::SetCellNote(SCROW nRow, ScPostIt* pNote) void ScColumn::SetCellNote(SCROW nRow, ScPostIt* pNote)
{ {
//pNote->UpdateCaptionPos(ScAddress(nCol, nRow, nTab)); // TODO notes usefull ? slow import with many notes //pNote->UpdateCaptionPos(ScAddress(nCol, nRow, nTab)); // TODO notes usefull ? slow import with many notes
......
...@@ -228,8 +228,9 @@ public: ...@@ -228,8 +228,9 @@ public:
ScRefCellValue maCell; ScRefCellValue maCell;
const sc::CellTextAttr* mpAttr; const sc::CellTextAttr* mpAttr;
const SvtBroadcaster* mpBroadcaster; const SvtBroadcaster* mpBroadcaster;
const ScPostIt* mpNote;
Cell() : mpAttr(NULL), mpBroadcaster(NULL) {} Cell() : mpAttr(NULL), mpBroadcaster(NULL), mpNote(NULL) {}
}; };
typedef std::vector<Cell> RowType; typedef std::vector<Cell> RowType;
...@@ -356,6 +357,7 @@ ScSortInfoArray* ScTable::CreateSortInfoArray( SCCOLROW nInd1, SCCOLROW nInd2 ) ...@@ -356,6 +357,7 @@ ScSortInfoArray* ScTable::CreateSortInfoArray( SCCOLROW nInd1, SCCOLROW nInd2 )
rCell.maCell = rCol.GetCellValue(aBlockPos, nRow); rCell.maCell = rCol.GetCellValue(aBlockPos, nRow);
rCell.mpAttr = rCol.GetCellTextAttr(aBlockPos, nRow); rCell.mpAttr = rCol.GetCellTextAttr(aBlockPos, nRow);
rCell.mpBroadcaster = rCol.GetBroadcaster(aBlockPos, nRow); rCell.mpBroadcaster = rCol.GetBroadcaster(aBlockPos, nRow);
rCell.mpNote = rCol.GetCellNote(aBlockPos, nRow);
} }
} }
} }
...@@ -383,11 +385,13 @@ struct SortedColumn : boost::noncopyable ...@@ -383,11 +385,13 @@ struct SortedColumn : boost::noncopyable
sc::CellStoreType maCells; sc::CellStoreType maCells;
sc::CellTextAttrStoreType maCellTextAttrs; sc::CellTextAttrStoreType maCellTextAttrs;
sc::BroadcasterStoreType maBroadcasters; sc::BroadcasterStoreType maBroadcasters;
sc::CellNoteStoreType maCellNotes;
SortedColumn( size_t nTopEmptyRows ) : SortedColumn( size_t nTopEmptyRows ) :
maCells(nTopEmptyRows), maCells(nTopEmptyRows),
maCellTextAttrs(nTopEmptyRows), maCellTextAttrs(nTopEmptyRows),
maBroadcasters(nTopEmptyRows) {} maBroadcasters(nTopEmptyRows),
maCellNotes(nTopEmptyRows) {}
}; };
} }
...@@ -512,6 +516,13 @@ void ScTable::SortReorder( ScSortInfoArray* pArray, ScProgress* pProgress ) ...@@ -512,6 +516,13 @@ void ScTable::SortReorder( ScSortInfoArray* pArray, ScProgress* pProgress )
rBCStore.push_back(const_cast<SvtBroadcaster*>(rCell.mpBroadcaster)); rBCStore.push_back(const_cast<SvtBroadcaster*>(rCell.mpBroadcaster));
else else
rBCStore.push_back_empty(); rBCStore.push_back_empty();
// The same with cell note instances ...
sc::CellNoteStoreType& rNoteStore = aSortedCols.at(j).maCellNotes;
if (rCell.mpNote)
rNoteStore.push_back(const_cast<ScPostIt*>(rCell.mpNote));
else
rNoteStore.push_back_empty();
} }
if (pProgress) if (pProgress)
...@@ -535,14 +546,24 @@ void ScTable::SortReorder( ScSortInfoArray* pArray, ScProgress* pProgress ) ...@@ -535,14 +546,24 @@ void ScTable::SortReorder( ScSortInfoArray* pArray, ScProgress* pProgress )
} }
{ {
sc::BroadcasterStoreType& rBCDest = aCol[nThisCol].maBroadcasters; sc::BroadcasterStoreType& rSrc = aSortedCols[i].maBroadcasters;
sc::BroadcasterStoreType& rDest = aCol[nThisCol].maBroadcasters;
// Release current broadcasters first, to prevent them from getting deleted. // Release current broadcasters first, to prevent them from getting deleted.
rBCDest.release_range(nRow1, aSortParam.nRow2); rDest.release_range(nRow1, aSortParam.nRow2);
// Transfer sorted broadcaster segment to the document. // Transfer sorted broadcaster segment to the document.
sc::BroadcasterStoreType& rBCSrc = aSortedCols[i].maBroadcasters; rSrc.transfer(nRow1, aSortParam.nRow2, rDest, nRow1);
rBCSrc.transfer(nRow1, aSortParam.nRow2, rBCDest, nRow1); }
{
sc::CellNoteStoreType& rSrc = aSortedCols[i].maCellNotes;
sc::CellNoteStoreType& rDest = aCol[nThisCol].maCellNotes;
// Do the same as broadcaster storage transfer (to prevent double deletion).
rDest.release_range(nRow1, aSortParam.nRow2);
rSrc.transfer(nRow1, aSortParam.nRow2, rDest, nRow1);
aCol[nThisCol].UpdateNoteCaptions(nRow1, aSortParam.nRow2);
} }
aCol[nThisCol].CellStorageModified(); aCol[nThisCol].CellStorageModified();
......
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