[Libreoffice-commits] core.git: Branch 'feature/sc-notes-storage' - sc/inc sc/source

Laurent Godard lgodard.libre at laposte.net
Wed Oct 2 01:29:17 PDT 2013


Rebased ref, commits from common ancestor:
commit 1fe2ce4edf6cb1cc37422dbd62d6c3cca00d55df
Author: Laurent Godard <lgodard.libre at laposte.net>
Date:   Wed Oct 2 10:22:04 2013 +0200

    refactor notes copy/paste handlers
    
    Change-Id: Ibbf8921fee8d514bdd41c2996b665aa027e2a79d

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 55cd4cd..d73e97a 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -495,6 +495,9 @@ public:
     void DeleteCellNote( SCROW nRow );
     bool HasCellNotes() const;
     void SetCellNote( SCROW nRow, ScPostIt* pNote);
+    // cell notes
+    void CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol, SCROW nRowOffsetDest=0);
+    void DuplicateNotes(SCROW nStartRow, size_t nDataSize, ScColumn& rDestCol, sc::ColumnBlockPosition& maDestBlockPos, SCROW nRowOffsetDest=0 ) const;
 
     void InterpretDirtyCells( SCROW nRow1, SCROW nRow2 );
 
@@ -544,7 +547,6 @@ private:
     void SwapCellTextAttrs( SCROW nRow1, SCROW nRow2 );
 
     // cell notes
-    void CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol) const;
     void SwapCellNotes( SCROW nRow1, SCROW nRow2 );
 
 };
diff --git a/sc/inc/postit.hxx b/sc/inc/postit.hxx
index 0fc1c2e..9a7c60a 100644
--- a/sc/inc/postit.hxx
+++ b/sc/inc/postit.hxx
@@ -242,15 +242,7 @@ public:
                             const OUString& rNoteText, bool bShown,
                             bool bAlwaysCreateCaption );
 
-    /** Duplicate notes using mdds - copy/paste manipulations
-    void                DuplicateNotes(
-                            const ScColumn& mrSrcCol, ScColumn& mrDestCol,
-                            SCROW nStartRow, size_t nDataSize,
-                            ColumnBlockPosition& maDestPos );
-
-*/
 };
 
 #endif
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index ab26769..a9d0c18 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1304,40 +1304,7 @@ class CopyToClipHandler
 
     void duplicateNotes(SCROW nStartRow, size_t nDataSize )
     {
-        SCCOL nDestCol = mrDestCol.GetCol();
-        SCTAB nDestTab = mrDestCol.GetTab();
-        SCCOL nSrcCol = mrSrcCol.GetCol();
-        SCTAB nSrcTab = mrSrcCol.GetTab();
-
-        SCROW nRowMax = nStartRow + nDataSize;
-
-        std::vector<ScPostIt*> vDestNotes;
-        vDestNotes.reserve(nDataSize);
-
-        sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore();
-        sc::CellNoteStoreType::iterator posSrc = maSrcCellNotes.begin();
-
-        for (SCROW nRow = nStartRow; nRow < nRowMax; ++nRow)
-        {
-            sc::CellNoteStoreType::position_type curPosObj = maSrcCellNotes.position(posSrc, nRow);
-            posSrc = curPosObj.first;
-            size_t offset = curPosObj.second;
-            if (posSrc->type == sc::element_type_cellnote)
-            {
-                ScAddress aDestAddress = ScAddress(nDestCol, nRow, nDestTab);
-                ScAddress aSrcAddress = ScAddress(nSrcCol, nRow, nSrcTab );
-
-                ScPostIt* pSrcNote = sc::cellnote_block::at(*posSrc->data, offset);
-                ScPostIt* pClonedNote = pSrcNote->Clone(aSrcAddress, mrDestCol.GetDoc(), aDestAddress, true );
-
-                vDestNotes.push_back(pClonedNote);
-            }
-        }
-        // set the cloned notes vector in its dest position
-        sc::CellNoteStoreType maDestCellNotes = mrDestCol.GetCellNoteStore();
-        maDestCellNotes.set_empty(nStartRow, nRowMax - 1);
-        maDestPos.miCellNotePos = mrDestCol.GetCellNoteStore().set(
-            maDestPos.miCellNotePos, nStartRow, vDestNotes.begin(), vDestNotes.end());
+        mrSrcCol.DuplicateNotes(nStartRow, nDataSize, mrDestCol, maDestPos);
     }
 
 public:
@@ -1459,6 +1426,7 @@ void ScColumn::CopyToClip(
     pAttrArray->CopyArea( nRow1, nRow2, 0, *rColumn.pAttrArray,
                           rCxt.isKeepScenarioFlags() ? (SC_MF_ALL & ~SC_MF_SCENARIO) : SC_MF_ALL );
 
+  //  CopyToClipHandler aFunc(*this, rColumn, rCxt.getBlockPosition(rColumn.nTab, rColumn.nCol), rCxt.isCloneNotes());
     CopyToClipHandler aFunc(*this, rColumn, rCxt.getBlockPosition(rColumn.nTab, rColumn.nCol), rCxt.isCloneNotes());
     sc::ParseBlock(maCells.begin(), maCells, aFunc, nRow1, nRow2);
 
@@ -1688,40 +1656,7 @@ class CopyAsLinkHandler
 
     void duplicateNotes(SCROW nStartRow, size_t nDataSize )
     {
-        SCCOL nDestCol = mrDestCol.GetCol();
-        SCTAB nDestTab = mrDestCol.GetTab();
-        SCCOL nSrcCol = mrSrcCol.GetCol();
-        SCTAB nSrcTab = mrSrcCol.GetTab();
-
-        SCROW nRowMax = nStartRow + nDataSize;
-
-        std::vector<ScPostIt*> vDestNotes;
-        vDestNotes.reserve(nDataSize);
-
-        sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore();
-        sc::CellNoteStoreType::iterator posSrc = maSrcCellNotes.begin();
-
-        for (SCROW nRow = nStartRow; nRow < nRowMax; ++nRow)
-        {
-            sc::CellNoteStoreType::position_type curPosObj = maSrcCellNotes.position(posSrc, nRow);
-            posSrc = curPosObj.first;
-            size_t offset = curPosObj.second;
-            if (posSrc->type == sc::element_type_cellnote)
-            {
-                ScAddress aDestAddress = ScAddress(nDestCol, nRow, nDestTab);
-                ScAddress aSrcAddress = ScAddress(nSrcCol, nRow, nSrcTab );
-
-                ScPostIt* pSrcNote = sc::cellnote_block::at(*posSrc->data, offset);
-                ScPostIt* pClonedNote = pSrcNote->Clone(aSrcAddress, mrDestCol.GetDoc(), aDestAddress, true );
-
-                vDestNotes.push_back(pClonedNote);
-            }
-        }
-        // set the cloned notes vector in its dest position
-        sc::CellNoteStoreType maDestCellNotes = mrDestCol.GetCellNoteStore();
-        maDestCellNotes.set_empty(nStartRow, nRowMax-1);
-        maDestPos.miCellNotePos = maDestCellNotes.set(
-            maDestPos.miCellNotePos, nStartRow, vDestNotes.begin(), vDestNotes.end());
+        mrSrcCol.DuplicateNotes(nStartRow, nDataSize, mrDestCol, maDestPos);
     }
 
 public:
@@ -1906,42 +1841,7 @@ class CopyByCloneHandler
 
     void duplicateNotes(SCROW nStartRow, size_t nDataSize )
     {
-        SCCOL nDestCol = mrDestCol.GetCol();
-        SCTAB nDestTab = mrDestCol.GetTab();
-        SCCOL nSrcCol = mrSrcCol.GetCol();
-        SCTAB nSrcTab = mrSrcCol.GetTab();
-
-        SCROW nRowMax = nStartRow + nDataSize;
-
-        std::vector<ScPostIt*> vDestNotes;
-        vDestNotes.reserve(nDataSize);
-
-        sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore();
-        sc::CellNoteStoreType::iterator posSrc = maSrcCellNotes.begin();
-
-        for (SCROW nRow = nStartRow; nRow < nRowMax; ++nRow)
-        {
-            sc::CellNoteStoreType::position_type curPosObj = maSrcCellNotes.position(posSrc, nRow);
-            posSrc = curPosObj.first;
-            size_t offset = curPosObj.second;
-            if (posSrc->type == sc::element_type_cellnote)
-            {
-                ScAddress aDestAddress = ScAddress(nDestCol, nRow, nDestTab);
-                ScAddress aSrcAddress = ScAddress(nSrcCol, nRow, nSrcTab );
-
-                ScPostIt* pSrcNote = sc::cellnote_block::at(*posSrc->data, offset);
-                if (pSrcNote) // needed ?
-                {
-                    ScPostIt* pClonedNote = pSrcNote->Clone(aSrcAddress, mrDestCol.GetDoc(), aDestAddress, true );
-                    vDestNotes.push_back(pClonedNote);
-                }
-            }
-        }
-        // set the cloned notes vector in its dest position
-        sc::CellNoteStoreType maDestCellNotes = mrDestCol.GetCellNoteStore();
-        maDestCellNotes.set_empty(nStartRow, nRowMax-1);
-        maDestPos.miCellNotePos = mrDestCol.GetCellNoteStore().set(
-            maDestPos.miCellNotePos, nStartRow, vDestNotes.begin(), vDestNotes.end());
+        mrSrcCol.DuplicateNotes(nStartRow, nDataSize, mrDestCol, maDestPos);
     }
 
 public:
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index ee8e94f..56de103 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1475,13 +1475,6 @@ void ScColumn::CellStorageModified()
         abort();
     }
 
-    if (maCellNotes.size() != MAXROWCOUNT)
-    {
-        cout << "ScColumn::CellStorageModified: Size of the cell note array is incorrect." << endl;
-        cout.flush();
-        abort();
-    }
-
     // Make sure that these two containers are synchronized wrt empty segments.
     sc::CellStoreType::const_iterator itCell = maCells.begin();
     sc::CellTextAttrStoreType::const_iterator itAttr = maCellTextAttrs.begin();
@@ -1516,41 +1509,6 @@ void ScColumn::CellStorageModified()
             ++itAttr;
     }
 
-    // Make sure that these two containers are synchronized wrt empty segments.
-    sc::CellStoreType::const_iterator itCell = maCells.begin();
-    sc::CellNoteStoreType::const_iterator itNote = maCellNotes.begin();
-
-    // Move to the first empty blocks.
-    while (itCell != maCells.end() && itCell->type != sc::element_type_empty)
-        ++itCell;
-
-    while (itNote != maCellNotes.end() && itNote->type != sc::element_type_empty)
-        ++itNote;
-
-    while (itCell != maCells.end())
-    {
-        if (itCell->position != itNote->position || itCell->size != itNote->size)
-        {
-            cout << "ScColumn::CellStorageModified: Cell array and cell notes array are out of sync." << endl;
-            cout << "-- cell array" << endl;
-            maCells.dump_blocks(cout);
-            cout << "-- cell notes array" << endl;
-            maCellNotes.dump_blocks(cout);
-            cout.flush();
-            abort();
-        }
-
-        // Move to the next empty blocks.
-        ++itCell;
-        while (itCell != maCells.end() && itCell->type != sc::element_type_empty)
-            ++itCell;
-
-        ++itNote;
-        while (itNote != maCellNotes.end() && itNote->type != sc::element_type_empty)
-            ++itNote;
-    }
-
-
 #endif
 }
 
@@ -1594,6 +1552,7 @@ void ScColumn::DumpFormulaGroups() const
 }
 #endif
 
+
 void ScColumn::CopyCellTextAttrsToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol) const
 {
     rDestCol.maCellTextAttrs.set_empty(nRow1, nRow2); // Empty the destination range first.
@@ -1657,7 +1616,8 @@ 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) const
+void ScColumn::CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol, SCROW nRowOffsetDest) // TODO : notes promising factorisation
 {
     rDestCol.maCellNotes.set_empty(nRow1, nRow2); // Empty the destination range first.
 
@@ -1693,9 +1653,9 @@ void ScColumn::CopyCellNotesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDest
             // Empty block.
             if (nBlockStart <= nRowPos && nRowPos < nBlockEnd)
                 // This block contains the end row.
-                rDestCol.maCellNotes.set_empty(nBlockStart + nOffsetInBlock, nRowPos);
+                rDestCol.maCellNotes.set_empty(nBlockStart + nOffsetInBlock + nRowOffsetDest, nRowPos);
             else
-                rDestCol.maCellNotes.set_empty(nBlockStart + nOffsetInBlock, nBlockEnd-1);
+                rDestCol.maCellNotes.set_empty(nBlockStart + nOffsetInBlock + nRowOffsetDest, nBlockEnd-1);
 
             continue;
         }
@@ -1711,12 +1671,12 @@ 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);
-
-            rDestCol.maCellNotes.set(nBlockStart + nOffsetInBlock, itData, itDataEnd);
+            // TODO : notes need to duplicate notes
+            rDestCol.maCellNotes.set(nBlockStart + nOffsetInBlock + nRowOffsetDest, itData, itDataEnd);
             break;
         }
-
-        rDestCol.maCellNotes.set(nBlockStart + nOffsetInBlock, itData, itDataEnd);
+        // TODO : notes need to duplicate notes
+        rDestCol.maCellNotes.set(nBlockStart + nOffsetInBlock + nRowOffsetDest, itData, itDataEnd);
     }
 
 /*
@@ -1738,6 +1698,41 @@ 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();
+
+        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
+        sc::CellNoteStoreType maDestCellNotes = rDestCol.GetCellNoteStore();
+        maDestCellNotes.set_empty(nStartRow + nRowOffsetDest, nRowMax - 1 + nRowOffsetDest);
+        maDestBlockPos.miCellNotePos = rDestCol.GetCellNoteStore().set(
+            maDestBlockPos.miCellNotePos, nStartRow + nRowOffsetDest, vDestNotes.begin(), vDestNotes.end());
+}
+
 void ScColumn::SwapCellTextAttrs( SCROW nRow1, SCROW nRow2 )
 {
     if (nRow1 == nRow2)
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 0a1127a..5c46c9b 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -697,27 +697,9 @@ class CopyCellsFromClipHandler
             maDestBlockPos, nDestRow, new ScFormulaCell(&mrDestCol.GetDoc(), aDestPos, &aArr));
     }
 
-    void duplicateNotes(SCROW nStartRow, size_t nDataSize ) // TODO : notes suboptimal
+    void duplicateNotes(SCROW nStartRow, size_t nDataSize )
     {
-        sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore();
-
-        SCROW nRowMax = nStartRow + nDataSize;
-
-        for (SCROW nRow = nStartRow; nRow < nRowMax; ++nRow)
-        {
-
-            ScAddress aDestPos = ScAddress(mrDestCol.GetCol(), nRow+mnRowOffset, mrDestCol.GetTab());
-            mrDestCol.GetDoc().ReleaseNote(aDestPos);
-
-            ScPostIt* pSrcNote = maSrcCellNotes.get<ScPostIt*>(nRow);
-            if (pSrcNote)
-            {
-                ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab() ),
-                                 mrDestCol.GetDoc(),
-                                 aDestPos, true );
-                mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote);
-            }
-        }
+        mrSrcCol.DuplicateNotes(nStartRow, nDataSize, mrDestCol, maDestBlockPos, mnRowOffset);
     }
 
 public:
diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx
index 0278921..ba2d5f5 100644
--- a/sc/source/core/data/postit.cxx
+++ b/sc/source/core/data/postit.cxx
@@ -937,43 +937,4 @@ ScPostIt* ScNoteUtil::CreateNoteFromString(
     }
     return pNote;
 }
-/*
-void ScNoteUtil::DuplicateNotes(const ScColumn& mrSrcCol, ScColumn& mrDestCol, SCROW nStartRow, size_t nDataSize, sc::ColumnBlockPosition& maDestPos )
-{
-        SCCOL nDestCol = mrDestCol.GetCol();
-        SCTAB nDestTab = mrDestCol.GetTab();
-        SCCOL nSrcCol = mrSrcCol.GetCol();
-        SCTAB nSrcTab = mrSrcCol.GetTab();
-
-        SCROW nRowMax = nStartRow + nDataSize;
-
-        std::vector<ScPostIt*> vDestNotes(nDataSize);
-
-        sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore();
-        sc::CellNoteStoreType::iterator posSrc = maSrcCellNotes.begin();
-
-        for (SCROW nRow = nStartRow; nRow < nRowMax; ++nRow)
-        {
-            sc::CellNoteStoreType::position_type curPosObj = maSrcCellNotes.position(posSrc, nRow);
-            posSrc = curPosObj.first;
-            size_t offset = curPosObj.second;
-            if (posSrc->type == sc::element_type_cellnote)
-            {
-                ScAddress aDestAddress = ScAddress(nDestCol, nRow, nDestTab);
-                ScAddress aSrcAddress = ScAddress(nSrcCol, nRow, nSrcTab );
-
-                ScPostIt* pSrcNote = sc::cellnote_block::at(*posSrc->data, offset);
-                ScPostIt* pClonedNote = pSrcNote->Clone(aSrcAddress, mrDestCol.GetDoc(), aDestAddress, true );
-
-                vDestNotes[nRow-nStartRow] = pClonedNote;
-            }
-        }
-        // set the cloned notes vector in its dest position
-        sc::CellNoteStoreType maDestCellNotes = mrDestCol.GetCellNoteStore();
-        maDestCellNotes.set_empty(nStartRow, nRowMax-1);
-        maDestPos.miCellNotePos = maDestCellNotes.set(
-            maDestPos.miCellNotePos, nStartRow, vDestNotes.begin(), vDestNotes.end());
-
-}
-*/
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list