[Libreoffice-commits] core.git: Branch 'feature/sc-notes-storage' - sc/qa sc/source
sc/qa/unit/ucalc.cxx|2 - sc/source/core/data/column2.cxx | 41 +++- sc/source/core/data/column3.cxx | 11 -- 3 files changed, 37 insertions(+), 17 deletions(-) New commits: commit 863c34d033d1e43aebe32445afdc4f0619cea292 Author: Laurent Godard lgodard.li...@laposte.net Date: Thu Oct 3 12:55:24 2013 +0200 clone notes in CopyCellNotesToDocument Change-Id: I804746be0ed74ff36fce5897fcb5d49ada0dfd1b diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index de49739..7dec2ac 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -3103,7 +3103,7 @@ void Test::testMoveBlock() ScDocFunc rDocFunc = getDocShell().GetDocFunc(); bool bMoveDone = rDocFunc.MoveBlock(ScRange(0, 0 ,0 ,2 ,0 ,0), ScAddress(1, 0, 0), bCut, false, false, false); -std::cout B1 note after moveblock: m_pDoc-GetNote(aAddrB1)-GetText() std::endl; + // std::cout B1 note after moveblock: m_pDoc-GetNote(aAddrB1)-GetText() std::endl; CPPUNIT_ASSERT_MESSAGE(Cells not moved, bMoveDone); diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index 7c2c565..93887c7 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -1616,9 +1616,12 @@ void ScColumn::CopyCellTextAttrsToDocument(SCROW nRow1, SCROW nRow2, ScColumn r } } -//void ScColumn::CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn rDestCol) const void ScColumn::CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn rDestCol, SCROW nRowOffsetDest) const // TODO : notes promising factorisation { + +SCCOL nDestCol = rDestCol.GetCol(); +SCTAB nDestTab = rDestCol.GetTab(); + rDestCol.maCellNotes.set_empty(nRow1, nRow2); // Empty the destination range first. sc::CellNoteStoreType::const_iterator itBlk = maCellNotes.begin(), itBlkEnd = maCellNotes.end(); @@ -1671,12 +1674,39 @@ void ScColumn::CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn rDest size_t nOffset = nRowPos - nBlockStart + 1; itDataEnd = sc::cellnote_block::begin(*itBlk-data); std::advance(itDataEnd, nOffset); -// TODO : notes need to duplicate notes -rDestCol.maCellNotes.set(nBlockStart + nOffsetInBlock + nRowOffsetDest, itData, itDataEnd); +// need to clone notes +std::vectorScPostIt* vCloned; +vCloned.reserve(nOffset); +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()); + // sc::CellNoteStoreType maDestCellNotes = rDestCol.GetCellNoteStore(); + // maDestCellNotes.set(nBlockStart + nOffsetInBlock + nRowOffsetDest, vCloned.begin(), vCloned.end()); break; } -// TODO : notes need to duplicate notes -rDestCol.maCellNotes.set(nBlockStart + nOffsetInBlock + nRowOffsetDest, itData, itDataEnd); +// need to clone notes +std::vectorScPostIt* 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()); +//sc::CellNoteStoreType maDestCellNotes = rDestCol.GetCellNoteStore(); +//maDestCellNotes.set(nBlockStart + nOffsetInBlock + nRowOffsetDest, vCloned.begin(), vCloned.end()); } /* @@ -1700,6 +1730,7 @@ void ScColumn::CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn rDest 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(); diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 5c46c9b..a7dee56 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -1633,8 +1633,6 @@ void
[Libreoffice-commits] core.git: Branch 'feature/sc-notes-storage' - sc/qa sc/source
Rebased ref, commits from common ancestor: commit 117ea65d6e5586e8c1c0805481ca81a1e15049ac Author: Laurent Godard lgodard.li...@laposte.net Date: Mon Sep 23 18:08:42 2013 +0200 transport attached notes when moving a block of cell Change-Id: I608be1197cf4177aa67870ff34b61cf1fd67204c diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index fb0d07f..df95270 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -2915,15 +2915,15 @@ void Test::testCopyPaste() // add notes to A1:C1 ScAddress aAdrA1 (0, 0, 0); // empty cell content OUString aHelloA1(Hello world in A1); -ScPostIt *pNoteA1 = m_pDoc-GetOrCreateNote(aAdrA1); +ScPostIt* pNoteA1 = m_pDoc-GetOrCreateNote(aAdrA1); pNoteA1-SetText(aAdrA1, aHelloA1); ScAddress aAdrB1 (1, 0, 0); // formula cell content OUString aHelloB1(Hello world in B1); -ScPostIt *pNoteB1 = m_pDoc-GetOrCreateNote(aAdrB1); +ScPostIt* pNoteB1 = m_pDoc-GetOrCreateNote(aAdrB1); pNoteB1-SetText(aAdrB1, aHelloB1); ScAddress aAdrC1 (2, 0, 0); // string cell content OUString aHelloC1(Hello world in C1); -ScPostIt *pNoteC1 = m_pDoc-GetOrCreateNote(aAdrC1); +ScPostIt* pNoteC1 = m_pDoc-GetOrCreateNote(aAdrC1); pNoteC1-SetText(aAdrC1, aHelloC1); //copy Sheet1.A1:C1 to Sheet2.A2:C2 @@ -3014,15 +3014,15 @@ void Test::testCopyPasteTranspose() // add notes to A1:C1 ScAddress aAdrA1 (0, 0, 0); // numerical cell content OUString aHelloA1(Hello world in A1); -ScPostIt *pNoteA1 = m_pDoc-GetOrCreateNote(aAdrA1); +ScPostIt* pNoteA1 = m_pDoc-GetOrCreateNote(aAdrA1); pNoteA1-SetText(aAdrA1, aHelloA1); ScAddress aAdrB1 (1, 0, 0); // formula cell content OUString aHelloB1(Hello world in B1); -ScPostIt *pNoteB1 = m_pDoc-GetOrCreateNote(aAdrB1); +ScPostIt* pNoteB1 = m_pDoc-GetOrCreateNote(aAdrB1); pNoteB1-SetText(aAdrB1, aHelloB1); ScAddress aAdrC1 (2, 0, 0); // string cell content OUString aHelloC1(Hello world in C1); -ScPostIt *pNoteC1 = m_pDoc-GetOrCreateNote(aAdrC1); +ScPostIt* pNoteC1 = m_pDoc-GetOrCreateNote(aAdrC1); pNoteC1-SetText(aAdrC1, aHelloC1); // transpose clipboard, paste and check on Sheet2 @@ -3068,6 +3068,73 @@ void Test::testCopyPasteTranspose() } +void Test::testMoveBlock() +{ + +ScDocument* pDoc = getDocShell().GetDocument(); + +pDoc-InsertTab(0, SheetNotes); + +pDoc-SetValue(0, 0, 0, 1); +pDoc-SetString(1, 0, 0, OUString(=A1+1)); +pDoc-SetString(2, 0, 0, OUString(test)); + +// add notes to A1:C1 +ScAddress aAddrA1 (0, 0, 0); +OUString aHelloA1(Hello world in A1); +ScPostIt* pNoteA1 = pDoc-GetOrCreateNote(aAddrA1); +pNoteA1-SetText(aAddrA1, aHelloA1); +ScAddress aAddrB1 (1, 0, 0); +OUString aHelloB1(Hello world in B1); +ScPostIt* pNoteB1 = pDoc-GetOrCreateNote(aAddrB1); +pNoteB1-SetText(aAddrB1, aHelloB1); +ScAddress aAddrC1 (2, 0, 0); +OUString aHelloC1(Hello world in C1); +ScPostIt* pNoteC1 = pDoc-GetOrCreateNote(aAddrC1); +pNoteC1-SetText(aAddrC1, aHelloC1); +ScAddress aAddrD1 (3, 0, 0); + +std::cout B1 note before moveblock: pNoteB1-GetText() std::endl; +std::cout B1 note before moveblock should be: aHelloB1 std::endl; + +// previous tests on cell note content are ok. this one fails !!! :( +CPPUNIT_ASSERT_MESSAGE(Note content in B1, pNoteB1-GetText() == aHelloB1); + +// move notes to B1:D1 +bool bCut = true; +ScDocFunc rDocFunc = getDocShell().GetDocFunc(); +bool bMoveDone = rDocFunc.MoveBlock(ScRange(0, 0 ,0 ,2 ,0 ,0), ScAddress(1, 0, 0), bCut, false, false, false); + +std::cout B1 note after moveblock: pDoc-GetNote(aAddrB1)-GetText() std::endl; + +CPPUNIT_ASSERT_MESSAGE(Cells not moved, bMoveDone); + +//check cell content +OUString aString = pDoc-GetString(3, 0, 0); +CPPUNIT_ASSERT_MESSAGE(Cell D1 should contain: test, aString.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(test))); +m_pDoc-GetFormula(2, 0, 0, aString); +CPPUNIT_ASSERT_MESSAGE(Cell C1 should contain an updated formula, aString.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(=B1+1))); +double fValue = pDoc-GetValue(aAddrB1); +ASSERT_DOUBLES_EQUAL_MESSAGE(Cell B1 should contain 1, fValue, 1); + +// cell notes has been moved 1 cell right (event when overlapping) +CPPUNIT_ASSERT_MESSAGE(There should be NO note on A1, !pDoc-HasNote(aAddrA1)); +CPPUNIT_ASSERT_MESSAGE(There should be a note on B1, pDoc-HasNote(aAddrB1)); +CPPUNIT_ASSERT_MESSAGE(There should be a note on C1, pDoc-HasNote(aAddrC1)); +CPPUNIT_ASSERT_MESSAGE(There should be a note on D1, pDoc-HasNote(aAddrD1)); +// still failing, wrong content ??? +OUString sNoteText; +sNoteText = pDoc-GetNote(aAddrB1)-GetText(); +CPPUNIT_ASSERT_MESSAGE(Note content in B1, sNoteText == aHelloA1); +sNoteText = pDoc-GetNote(aAddrC1)-GetText(); +CPPUNIT_ASSERT_MESSAGE(Note content in C1, sNoteText
[Libreoffice-commits] core.git: Branch 'feature/sc-notes-storage' - sc/qa sc/source
sc/qa/unit/ucalc.cxx | 53 ++ sc/qa/unit/ucalc.hxx |2 + sc/source/core/data/column.cxx|9 -- sc/source/ui/docshell/docfunc.cxx | 18 +--- 4 files changed, 68 insertions(+), 14 deletions(-) New commits: commit 6ce4e50fe452ded99dac075eeaacc7ac03daf383 Author: Laurent Godard lgodard.li...@laposte.net Date: Mon Sep 23 18:08:42 2013 +0200 transport attached notes when moving a block of cell Change-Id: I608be1197cf4177aa67870ff34b61cf1fd67204c diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index fb0d07f..de928da 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -3067,6 +3067,59 @@ void Test::testCopyPasteTranspose() m_pDoc-DeleteTab(0); } +void Test::testMoveBlock() +{ +m_pDoc-InsertTab(0, Sheet1); + +m_pDoc-SetValue(0, 0, 0, 1); +m_pDoc-SetString(1, 0, 0, OUString(=A1+1)); +m_pDoc-SetString(2, 0, 0, OUString(test)); + +// add notes to A1:C1 +ScAddress aAdrA1 (0, 0, 0); // numerical cell content +OUString aHelloA1(Hello world in A1); +ScPostIt *pNoteA1 = m_pDoc-GetOrCreateNote(aAdrA1); +pNoteA1-SetText(aAdrA1, aHelloA1); +ScAddress aAdrB1 (1, 0, 0); // formula cell content +OUString aHelloB1(Hello world in B1); +ScPostIt *pNoteB1 = m_pDoc-GetOrCreateNote(aAdrB1); +pNoteB1-SetText(aAdrB1, aHelloB1); +ScAddress aAdrC1 (2, 0, 0); // string cell content +OUString aHelloC1(Hello world in C1); +ScPostIt *pNoteC1 = m_pDoc-GetOrCreateNote(aAdrC1); +pNoteC1-SetText(aAdrC1, aHelloC1); + +// move notes to B1:D1 +bool bCut = true; +ScDocFunc rDocFunc = getDocShell().GetDocFunc(); +bool bMoveDone = rDocFunc.MoveBlock(ScRange(0,0,0,2,0,0), ScAddress( 1, 0, 0), bCut, false, false, false); + +CPPUNIT_ASSERT_MESSAGE(Cells not moved, bMoveDone); + +//check cell content +OUString aString = m_pDoc-GetString(3, 0, 0); +CPPUNIT_ASSERT_MESSAGE(Cell D1 should contain: test, aString.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(test))); +m_pDoc-GetFormula(2, 0, 0, aString); +CPPUNIT_ASSERT_MESSAGE(Cell C1 should contain an updated formula, aString.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(=B1+1))); +double fValue = m_pDoc-GetValue(ScAddress(1, 0, 0)); +ASSERT_DOUBLES_EQUAL_MESSAGE(Cell B1 should contain 1, fValue, 1); + +// cell notes has been moved 1 cell right (event when overlapping) +CPPUNIT_ASSERT_MESSAGE(There should be NO note on A1, !m_pDoc-HasNote(ScAddress(0, 0, 0))); +CPPUNIT_ASSERT_MESSAGE(There should be a note on B1, m_pDoc-HasNote(ScAddress(1, 0, 0))); +CPPUNIT_ASSERT_MESSAGE(There should be a note on C1, m_pDoc-HasNote(ScAddress(2, 0, 0))); +CPPUNIT_ASSERT_MESSAGE(There should be a note on D1, m_pDoc-HasNote(ScAddress(3, 0, 0))); +/* still failing, wrong content ??? +OUString sNoteText; +sNoteText = m_pDoc-GetNote(ScAddress(1, 0, 0))-GetText(); +CPPUNIT_ASSERT_MESSAGE(Note content in B1, sNoteText == aHelloA1); +sNoteText = m_pDoc-GetNote(ScAddress(2, 0, 0))-GetText(); +CPPUNIT_ASSERT_MESSAGE(Note content in C1, sNoteText == aHelloB1); +sNoteText = m_pDoc-GetNote(ScAddress(3, 0, 0))-GetText(); +CPPUNIT_ASSERT_MESSAGE(Note content in D1, sNoteText == aHelloC1); +*/ +m_pDoc-DeleteTab(0); +} void Test::testCopyPasteRelativeFormula() { diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 1273241..0a141a3 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -215,6 +215,7 @@ public: void testAutofilter(); void testCopyPaste(); void testCopyPasteTranspose(); +void testMoveBlock(); void testCopyPasteRelativeFormula(); void testMergedCells(); void testUpdateReference(); @@ -348,6 +349,7 @@ public: CPPUNIT_TEST(testAutofilter); CPPUNIT_TEST(testCopyPaste); CPPUNIT_TEST(testCopyPasteTranspose); +CPPUNIT_TEST(testMoveBlock); CPPUNIT_TEST(testCopyPasteRelativeFormula); CPPUNIT_TEST(testMergedCells); CPPUNIT_TEST(testUpdateReference); diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index 193c8d3..70df4d0 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -1670,7 +1670,7 @@ class CopyAsLinkHandler void duplicateNotes(SCROW nStartRow, size_t nDataSize ) // TODO : notes suboptimal { -// the link status is only for cell content as it is not possible to un-link a note +// the link status is only for cell content as it is not possible to un-link a note -- the note is copied sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore(); SCROW nRowMax = nStartRow + nDataSize; @@ -1885,6 +1885,7 @@ class CopyByCloneHandler aDestPos, true ); mrDestCol.GetDoc().ReleaseNote(aDestPos); mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote); +