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

Laurent Godard lgodard.libre at laposte.net
Mon Sep 30 05:20:27 PDT 2013


 sc/source/core/data/column.cxx |  136 +++++++++++++++++++++++++++++++----------
 1 file changed, 104 insertions(+), 32 deletions(-)

New commits:
commit dd55f14816f7488d9ba51f85de2f0fe70d485737
Author: Laurent Godard <lgodard.libre at laposte.net>
Date:   Mon Sep 30 14:19:03 2013 +0200

    refactor clipboard handlers loops for notes
    
    Change-Id: Id0198b4e957474afe78060bbaf79c8644d099572

diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 4bc37b4..d8ce48a 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1264,10 +1264,6 @@ class CopyToClipHandler
     sc::ColumnBlockPosition maDestPos;
     sc::ColumnBlockPosition* mpDestPos;
     bool mbCopyNotes;
-    SCCOL nDestCol;
-    SCTAB nDestTab;
-    SCCOL nSrcCol;
-    SCTAB nSrcTab;
 
     void setDefaultAttrsToDest(size_t nRow, size_t nSize)
     {
@@ -1308,6 +1304,50 @@ 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());
+    }
+
+/* ok
+    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(nDataSize);
@@ -1333,10 +1373,11 @@ class CopyToClipHandler
         }
         // set the cloned notes vector in its dest position
         sc::CellNoteStoreType maDestCellNotes = mrDestCol.GetCellNoteStore();
-        maDestCellNotes.set_empty(nStartRow, nRowMax);
+        maDestCellNotes.set_empty(nStartRow, nRowMax - 1);
         maDestPos.miCellNotePos = mrDestCol.GetCellNoteStore().set(
             maDestPos.miCellNotePos, nStartRow, vDestNotes.begin(), vDestNotes.end());
     }
+*/
 
 public:
     CopyToClipHandler(const ScColumn& rSrcCol, ScColumn& rDestCol, sc::ColumnBlockPosition* pDestPos, bool bCopyNotes) :
@@ -1346,11 +1387,6 @@ public:
             maDestPos = *mpDestPos;
         else
             mrDestCol.InitBlockPosition(maDestPos);
-
-    nDestCol = mrDestCol.GetCol();
-    nDestTab = mrDestCol.GetTab();
-    nSrcCol = mrSrcCol.GetCol();
-    nSrcTab = mrSrcCol.GetTab();
     }
 
     ~CopyToClipHandler()
@@ -1689,25 +1725,42 @@ class CopyAsLinkHandler
         setDefaultAttrsToDest(nTopRow, nDataSize);
     }
 
-    void duplicateNotes(SCROW nStartRow, size_t nDataSize ) // TODO : notes suboptimal
+    void duplicateNotes(SCROW nStartRow, size_t nDataSize )
     {
-        // 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();
+        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)
         {
-            ScPostIt* pSrcNote = maSrcCellNotes.get<ScPostIt*>(nRow);
-            if (pSrcNote)
+            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 aDestPos = ScAddress(mrDestCol.GetCol(), nRow, mrDestCol.GetTab());
-                ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab() ),
-                                 mrDestCol.GetDoc(),
-                                 aDestPos, true );
-                mrDestCol.GetDoc().ReleaseNote(aDestPos);
-                mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote);
+                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());
     }
 
 public:
@@ -1890,25 +1943,44 @@ class CopyByCloneHandler
         }
     }
 
-    void duplicateNotes(SCROW nStartRow, size_t nDataSize ) // TODO : notes suboptimal
+    void duplicateNotes(SCROW nStartRow, size_t nDataSize )
     {
-        sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore();
+        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)
         {
-            ScPostIt* pSrcNote = maSrcCellNotes.get<ScPostIt*>(nRow);
-            if (pSrcNote)
+            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 aDestPos = ScAddress(mrDestCol.GetCol(), nRow, mrDestCol.GetTab());
-                ScPostIt* pClonedNote = pSrcNote->Clone( ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab() ),
-                                 mrDestCol.GetDoc(),
-                                 aDestPos, true );
-                mrDestCol.GetDoc().ReleaseNote(aDestPos);
-                mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote);
-                pClonedNote->UpdateCaptionPos(aDestPos);
+                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());
     }
 
 public:


More information about the Libreoffice-commits mailing list