sc/inc/column.hxx | 7 ++- sc/qa/unit/ucalc.cxx | 12 ++++- sc/source/core/data/column.cxx | 5 ++ sc/source/core/data/column2.cxx | 81 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 4 deletions(-)
New commits: commit 10ec9481234014749328f760a1f066a15ab23477 Author: Laurent Godard <lgodard.li...@laposte.net> Date: Mon Sep 23 15:23:44 2013 +0200 notes transport on copying sheet to another document Change-Id: If38b25fc384414eb905b9c9d7b6b7562b462b338 diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 6c01bb2..55cd4cd 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -495,7 +495,6 @@ public: void DeleteCellNote( SCROW nRow ); bool HasCellNotes() const; void SetCellNote( SCROW nRow, ScPostIt* pNote); - void SwapCellNotes( SCROW nRow1, SCROW nRow2 ); void InterpretDirtyCells( SCROW nRow1, SCROW nRow2 ); @@ -542,8 +541,12 @@ private: void CellStorageModified(); void CopyCellTextAttrsToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol) const; - void SwapCellTextAttrs( SCROW nRow1, SCROW nRow2 ); + + // cell notes + void CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol) const; + void SwapCellNotes( SCROW nRow1, SCROW nRow2 ); + }; #endif diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 4ae5732..fb0d07f 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -513,7 +513,10 @@ void Test::testCopyToDocument() m_pDoc->SetString(0, 4, 0, "=4/2"); m_pDoc->CalcAll(); - //TODO : notes + //note on A1 + ScAddress aAdrA1 (0, 0, 0); // numerical cell content + OUString aHelloA1("Hello world in A1"); + m_pDoc->GetOrCreateNote(aAdrA1); // Copy statically to another document. @@ -529,6 +532,11 @@ void Test::testCopyToDocument() CPPUNIT_ASSERT_EQUAL(m_pDoc->GetString(0,3,0), aDestDoc.GetString(0,3,0)); CPPUNIT_ASSERT_EQUAL(m_pDoc->GetString(0,4,0), aDestDoc.GetString(0,4,0)); + // verify note + CPPUNIT_ASSERT_MESSAGE("There should be a note in A1 destDocument", aDestDoc.HasNote(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT_MESSAGE("The notes content should be the same on both documents", + aDestDoc.GetNote(ScAddress(0, 0, 0))->GetText() == m_pDoc->GetNote(ScAddress(0, 0, 0))->GetText()); + m_pDoc->DeleteTab(0); } @@ -3004,7 +3012,7 @@ void Test::testCopyPasteTranspose() m_pDoc->SetString(2, 0, 0, OUString("test")); // add notes to A1:C1 - ScAddress aAdrA1 (0, 0, 0); // empty cell content + ScAddress aAdrA1 (0, 0, 0); // numerical cell content OUString aHelloA1("Hello world in A1"); ScPostIt *pNoteA1 = m_pDoc->GetOrCreateNote(aAdrA1); pNoteA1->SetText(aAdrA1, aHelloA1); diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index aea68e0..193c8d3 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -1454,6 +1454,7 @@ void ScColumn::CopyStaticToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol sc::ColumnBlockPosition aDestPos; CopyCellTextAttrsToDocument(nRow1, nRow2, rDestCol); + CopyCellNotesToDocument(nRow1, nRow2, rDestCol); // First, clear the destination column for the specified row range. rDestCol.maCells.set_empty(nRow1, nRow2); @@ -1597,10 +1598,14 @@ void ScColumn::CopyCellToDocument( SCROW nSrcRow, SCROW nDestRow, ScColumn& rDes if (bSet) { rDestCol.maCellTextAttrs.set(nDestRow, maCellTextAttrs.get<sc::CellTextAttr>(nSrcRow)); + ScPostIt* pNote = maCellNotes.get<ScPostIt*>(nSrcRow); + rDestCol.maCellNotes.set(nDestRow, pNote); + pNote->UpdateCaptionPos(ScAddress(rDestCol.nCol, nDestRow, rDestCol.nTab)); } else { rDestCol.maCellTextAttrs.set_empty(nDestRow, nDestRow); + rDestCol.maCellNotes.set_empty(nDestRow, nDestRow); } rDestCol.CellStorageModified(); diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index f38ce5a..eab3076 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -1657,6 +1657,87 @@ void ScColumn::CopyCellTextAttrsToDocument(SCROW nRow1, SCROW nRow2, ScColumn& r } } +void ScColumn::CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol) const +{ + rDestCol.maCellNotes.set_empty(nRow1, nRow2); // 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) + { + nBlockEnd = nBlockStart + itBlk->size; + if (nBlockStart <= nRowPos && nRowPos < nBlockEnd) + { + // Found. + nOffsetInBlock = nRowPos - nBlockStart; + break; + } + } + + if (itBlk == itBlkEnd) + // Specified range not found. Bail out. + return; + + nRowPos = static_cast<size_t>(nRow2); // End row position. + + // Keep copying until we hit the end row position. + sc::cellnote_block::const_iterator itData, itDataEnd; + 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, nRowPos); + else + rDestCol.maCellNotes.set_empty(nBlockStart + nOffsetInBlock, nBlockEnd-1); + + continue; + } + + // 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); + + rDestCol.maCellNotes.set(nBlockStart + nOffsetInBlock, itData, itDataEnd); + break; + } + + rDestCol.maCellNotes.set(nBlockStart + nOffsetInBlock, itData, itDataEnd); + } + +/* + // 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::SwapCellTextAttrs( SCROW nRow1, SCROW nRow2 ) { if (nRow1 == nRow2) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits