[Libreoffice-commits] core.git: Branch 'feature/sc-notes-storage' - sc/source
Laurent Godard
lgodard.libre at laposte.net
Thu Oct 3 07:41:01 PDT 2013
sc/source/core/data/column2.cxx | 128 ++++++++++------------------------------
1 file changed, 35 insertions(+), 93 deletions(-)
New commits:
commit 465ce2106cf99eb48d9020c2e85be91ddb278809
Author: Laurent Godard <lgodard.libre at laposte.net>
Date: Thu Oct 3 16:39:31 2013 +0200
unify copy/paste, notes duplications with cloning
Change-Id: Iaa83cb4b13e3e4add913ddd79f844a58be88aa59
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index c42ef05..31e7cdf 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1616,20 +1616,19 @@ void ScColumn::CopyCellTextAttrsToDocument(SCROW nRow1, SCROW nRow2, ScColumn& r
}
}
-void ScColumn::CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol, SCROW nRowOffsetDest) const // TODO : notes promising factorisation
+void ScColumn::CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol, SCROW nRowOffsetDest) const
{
-
SCCOL nDestCol = rDestCol.GetCol();
SCTAB nDestTab = rDestCol.GetTab();
- rDestCol.maCellNotes.set_empty(nRow1, nRow2); // Empty the destination range first.
+ rDestCol.maCellNotes.set_empty(nRow1 + nRowOffsetDest, nRow2 + nRowOffsetDest); // Empty the destination range first.
sc::CellNoteStoreType::const_iterator itBlk = maCellNotes.begin(), itBlkEnd = maCellNotes.end();
// Locate the top row position.
size_t nOffsetInBlock = 0;
size_t nBlockStart = 0, nBlockEnd = 0, nRowPos = static_cast<size_t>(nRow1);
- for (; itBlk != itBlkEnd; ++itBlk)
+ for (; itBlk != itBlkEnd; ++itBlk, nBlockStart = nBlockEnd)
{
nBlockEnd = nBlockStart + itBlk->size;
if (nBlockStart <= nRowPos && nRowPos < nBlockEnd)
@@ -1651,33 +1650,39 @@ void ScColumn::CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDest
for (; itBlk != itBlkEnd; ++itBlk, nBlockStart = nBlockEnd, nOffsetInBlock = 0)
{
nBlockEnd = nBlockStart + itBlk->size;
- if (!itBlk->data)
- {
- // Empty block.
- if (nBlockStart <= nRowPos && nRowPos < nBlockEnd)
- // This block contains the end row.
- rDestCol.maCellNotes.set_empty(nBlockStart + nOffsetInBlock + nRowOffsetDest, nRowPos);
- else
- rDestCol.maCellNotes.set_empty(nBlockStart + nOffsetInBlock + nRowOffsetDest, nBlockEnd-1);
- continue;
- }
+ if (itBlk->data) // Non-empty block.
+ {
+ itData = sc::cellnote_block::begin(*itBlk->data);
+ itDataEnd = sc::cellnote_block::end(*itBlk->data);
+ std::advance(itData, nOffsetInBlock);
- // Non-empty block.
- itData = sc::cellnote_block::begin(*itBlk->data);
- itDataEnd = sc::cellnote_block::end(*itBlk->data);
- std::advance(itData, nOffsetInBlock);
+ if (nBlockStart <= nRowPos && nRowPos < nBlockEnd)
+ {
+ // This block contains the end row. Only copy partially.
+ size_t nOffset = nRowPos - nBlockStart + 1;
+ itDataEnd = sc::cellnote_block::begin(*itBlk->data);
+ std::advance(itDataEnd, nOffset);
+ // need to clone notes
+ std::vector<ScPostIt*> vCloned;
+ vCloned.reserve(nOffset);
+ SCROW curRow = nBlockStart + nOffsetInBlock;
+ for (; itData != itDataEnd; ++itData, ++curRow)
+ {
+ ScPostIt* pSrcNote = *itData;
+ ScAddress aDestAddress = ScAddress(nDestCol, curRow + nRowOffsetDest, nDestTab);
+ ScAddress aSrcAddress = ScAddress(nCol, curRow, nTab );
+ ScPostIt* pClonedNote = pSrcNote->Clone(aSrcAddress, rDestCol.GetDoc(), aDestAddress, true );
+ vCloned.push_back(pClonedNote);
+ }
- if (nBlockStart <= nRowPos && nRowPos < nBlockEnd)
- {
- // This block contains the end row. Only copy partially.
- size_t nOffset = nRowPos - nBlockStart + 1;
- itDataEnd = sc::cellnote_block::begin(*itBlk->data);
- std::advance(itDataEnd, nOffset);
+ rDestCol.maCellNotes.set(rDestCol.maCellNotes.begin(), nBlockStart + nOffsetInBlock + nRowOffsetDest, vCloned.begin(), vCloned.end());
+ break;
+ }
// need to clone notes
std::vector<ScPostIt*> vCloned;
- vCloned.reserve(nOffset);
- SCROW curRow = nBlockStart;
+ vCloned.reserve(itBlk->size - nOffsetInBlock);
+ SCROW curRow = nBlockStart + nOffsetInBlock;
for (; itData != itDataEnd; ++itData, ++curRow)
{
ScPostIt* pSrcNote = *itData;
@@ -1686,79 +1691,16 @@ void ScColumn::CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDest
ScPostIt* pClonedNote = pSrcNote->Clone(aSrcAddress, rDestCol.GetDoc(), aDestAddress, true );
vCloned.push_back(pClonedNote);
}
+ rDestCol.maCellNotes.set(rDestCol.maCellNotes.begin(), nBlockStart + nOffsetInBlock + nRowOffsetDest, vCloned.begin(), vCloned.end());
- rDestCol.maCellNotes.set(nBlockStart + nOffsetInBlock + nRowOffsetDest, vCloned.begin(), vCloned.end());
- // rDestCol.maCellNotes.set(nBlockStart + nOffsetInBlock + nRowOffsetDest, vCloned.begin(), vCloned.end());
- break;
- }
- // need to clone notes
- std::vector<ScPostIt*> vCloned;
- vCloned.reserve(itBlk->size);
- SCROW curRow = nBlockStart;
- for (; itData != itDataEnd; ++itData, ++curRow)
- {
- ScPostIt* pSrcNote = *itData;
- ScAddress aDestAddress = ScAddress(nDestCol, curRow + nRowOffsetDest, nDestTab);
- ScAddress aSrcAddress = ScAddress(nCol, curRow, nTab );
- ScPostIt* pClonedNote = pSrcNote->Clone(aSrcAddress, rDestCol.GetDoc(), aDestAddress, true );
- vCloned.push_back(pClonedNote);
}
- rDestCol.maCellNotes.set(nBlockStart + nOffsetInBlock + nRowOffsetDest, vCloned.begin(), vCloned.end());
-// rDestCol.maCellNotes.set(nBlockStart + nOffsetInBlock + nRowOffsetDest, vCloned.begin(), vCloned.end());
}
-
-/*
- // TODO : notes suboptimal
- ScDocument& destDoc = rDestCol.GetDoc();
- for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
- {
- ScPostIt* pSrcNote = maCellNotes.get<ScPostIt*>(nRow);
- if (pSrcNote)
- {
- ScAddress aDestPos = ScAddress(rDestCol.GetCol(), nRow, rDestCol.GetTab());
- ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(nCol, nRow, nTab ),
- destDoc,
- aDestPos, true );
- destDoc.SetNote(aDestPos, pClonedNote);
- pClonedNote->UpdateCaptionPos(ScAddress(rDestCol.nCol, nRow, rDestCol.nTab));
- }
- }
-*/
}
void ScColumn::DuplicateNotes(SCROW nStartRow, size_t nDataSize, ScColumn& rDestCol, sc::ColumnBlockPosition& maDestBlockPos, SCROW nRowOffsetDest ) const
{
-
- SCCOL nDestCol = rDestCol.GetCol(); // no more needed
- SCTAB nDestTab = rDestCol.GetTab();
-
- SCROW nRowMax = nStartRow + nDataSize;
-
- std::vector<ScPostIt*> vDestNotes;
- vDestNotes.reserve(nDataSize);
-
- sc::CellNoteStoreType::const_iterator posSrc = maCellNotes.begin();
-
- for (SCROW nRow = nStartRow; nRow < nRowMax; ++nRow)
- {
- sc::CellNoteStoreType::const_position_type curPosObj = maCellNotes.position(posSrc, nRow);
- posSrc = curPosObj.first;
- size_t offset = curPosObj.second;
- if (posSrc->type == sc::element_type_cellnote)
- {
- ScAddress aDestAddress = ScAddress(nDestCol, nRow + nRowOffsetDest, nDestTab);
- ScAddress aSrcAddress = ScAddress(nCol, nRow, nTab );
-
- ScPostIt* pSrcNote = sc::cellnote_block::at(*posSrc->data, offset);
- ScPostIt* pClonedNote = pSrcNote->Clone(aSrcAddress, rDestCol.GetDoc(), aDestAddress, true );
-
- vDestNotes.push_back(pClonedNote);
- }
- }
- // set the cloned notes vector in its dest position
- rDestCol.maCellNotes.set_empty(nStartRow + nRowOffsetDest, nRowMax - 1 + nRowOffsetDest);
- maDestBlockPos.miCellNotePos = rDestCol.maCellNotes.set(
- maDestBlockPos.miCellNotePos, nStartRow + nRowOffsetDest, vDestNotes.begin(), vDestNotes.end());
+ CopyCellNotesToDocument(nStartRow, nStartRow + nDataSize -1, rDestCol, nRowOffsetDest);
+ maDestBlockPos.miCellNotePos = rDestCol.maCellNotes.begin();
}
void ScColumn::SwapCellTextAttrs( SCROW nRow1, SCROW nRow2 )
@@ -1864,7 +1806,7 @@ void ScColumn::SwapCellNotes( SCROW nRow1, SCROW nRow2 )
}
// row 1 is non-empty while row 2 is empty.
- ScPostIt* pVal1 = sc::cellnote_block::at(*it1->data, aPos1.second); // make a copy.
+ ScPostIt* pVal1 = sc::cellnote_block::at(*it1->data, aPos1.second); // TODO notes : make a copy.
it1 = maCellNotes.set_empty(it1, nRow1, nRow1);
maCellNotes.set(it1, nRow2, pVal1);
More information about the Libreoffice-commits
mailing list