[Libreoffice-commits] core.git: Branch 'private/kohei/calc-sort-fix' - sc/inc sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Mon Apr 21 13:34:39 PDT 2014


 sc/inc/column.hxx               |    4 ++-
 sc/source/core/data/column.cxx  |   45 ++++++++++++++++------------------------
 sc/source/core/data/column2.cxx |   11 +++++++++
 sc/source/core/data/table3.cxx  |   33 ++++++++++++++++++++++++-----
 4 files changed, 59 insertions(+), 34 deletions(-)

New commits:
commit ec57e7ef4c91aaf467ecd7a4096323242fd4d78e
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Mon Apr 21 16:34:00 2014 -0400

    Move cell notes too when sorting.
    
    Change-Id: Ibb330aa6f515d756c5578296fd9c83aa235a59fd

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 62bb4c6..94795d3 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -526,6 +526,7 @@ public:
     // cell notes
     ScPostIt* GetCellNote( SCROW nRow );
     const ScPostIt* GetCellNote( SCROW nRow ) const;
+    const ScPostIt* GetCellNote( sc::ColumnBlockConstPosition& rBlockPos, SCROW nRow ) const;
     void DeleteCellNotes( sc::ColumnBlockPosition& rBlockPos, SCROW nRow1, SCROW nRow2 );
     bool HasCellNotes() const;
     void SetCellNote( SCROW nRow, ScPostIt* pNote);
@@ -548,7 +549,8 @@ public:
 
     void DuplicateNotes(SCROW nStartRow, size_t nDataSize, ScColumn& rDestCol,
                             sc::ColumnBlockPosition& maDestBlockPos, bool bCloneCaption = true, SCROW nRowOffsetDest=0 ) const;
-    void UpdateNoteCaptions();
+
+    void UpdateNoteCaptions( SCROW nRow1, SCROW nRow2 );
 
     void InterpretDirtyCells( SCROW nRow1, SCROW nRow2 );
 
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 192aa5b..de9f65e 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -2234,34 +2234,25 @@ void resetColumnPosition(sc::CellStoreType& rCells, SCCOL nCol)
     }
 }
 
-}
-
-void ScColumn::UpdateNoteCaptions()
+class NoteCaptionUpdater
 {
-    sc::CellNoteStoreType::const_iterator itBlk = maCellNotes.begin(), itBlkEnd = maCellNotes.end();
-    sc::cellnote_block::const_iterator itData, itDataEnd;
+    SCCOL mnCol;
+    SCTAB mnTab;
+public:
+    NoteCaptionUpdater( SCCOL nCol, SCTAB nTab ) : mnCol(nCol), mnTab(nTab) {}
 
-    SCROW curRow = 0;
-    for (;itBlk!=itBlkEnd;++itBlk)
+    void operator() ( size_t nRow, ScPostIt* p )
     {
-        if (itBlk->data)
-        {
-            // non empty block
-            itData = sc::cellnote_block::begin(*itBlk->data);
-            itDataEnd = sc::cellnote_block::end(*itBlk->data);
-            for(;itData!=itDataEnd; ++itData)
-            {
-                ScPostIt* pNote = *itData;
-                pNote->UpdateCaptionPos(ScAddress(nCol, curRow, nTab));
-                curRow +=1;
-            }
-        }
-        else
-        {
-            // empty block
-            curRow += itBlk->size;
-        }
+        p->UpdateCaptionPos(ScAddress(mnCol,nRow,mnTab));
     }
+};
+
+}
+
+void ScColumn::UpdateNoteCaptions( SCROW nRow1, SCROW nRow2 )
+{
+    NoteCaptionUpdater aFunc(nCol, nTab);
+    sc::ProcessNote(maCellNotes.begin(), maCellNotes, nRow1, nRow2, aFunc);
 }
 
 void ScColumn::SwapCol(ScColumn& rCol)
@@ -2272,8 +2263,8 @@ void ScColumn::SwapCol(ScColumn& rCol)
     maCellNotes.swap(rCol.maCellNotes);
 
     // notes update caption
-    UpdateNoteCaptions();
-    rCol.UpdateNoteCaptions();
+    UpdateNoteCaptions(0, MAXROW);
+    rCol.UpdateNoteCaptions(0, MAXROW);
 
     ScAttrArray* pTempAttr = rCol.pAttrArray;
     rCol.pAttrArray = pAttrArray;
@@ -2322,7 +2313,7 @@ void ScColumn::MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol)
 
     // move the notes to the destination column
     maCellNotes.transfer(nStartRow, nEndRow, rCol.maCellNotes, nStartRow);
-    UpdateNoteCaptions();
+    UpdateNoteCaptions(0, MAXROW);
 
     // Re-group transferred formula cells.
     aPos = rCol.maCells.position(nStartRow);
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index ecdb50d..1238c78 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1848,6 +1848,17 @@ const ScPostIt* ScColumn::GetCellNote(SCROW nRow) const
     return maCellNotes.get<ScPostIt*>(nRow);
 }
 
+const ScPostIt* ScColumn::GetCellNote( sc::ColumnBlockConstPosition& rBlockPos, SCROW nRow ) const
+{
+    sc::CellNoteStoreType::const_position_type aPos = maCellNotes.position(rBlockPos.miCellNotePos, nRow);
+    rBlockPos.miCellNotePos = aPos.first;
+
+    if (aPos.first->type != sc::element_type_cellnote)
+        return NULL;
+
+    return sc::cellnote_block::at(*aPos.first->data, aPos.second);
+}
+
 void ScColumn::SetCellNote(SCROW nRow, ScPostIt* pNote)
 {
     //pNote->UpdateCaptionPos(ScAddress(nCol, nRow, nTab)); // TODO notes usefull ? slow import with many notes
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index dfca524..9caae2b 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -228,8 +228,9 @@ public:
         ScRefCellValue maCell;
         const sc::CellTextAttr* mpAttr;
         const SvtBroadcaster* mpBroadcaster;
+        const ScPostIt* mpNote;
 
-        Cell() : mpAttr(NULL), mpBroadcaster(NULL) {}
+        Cell() : mpAttr(NULL), mpBroadcaster(NULL), mpNote(NULL) {}
     };
 
     typedef std::vector<Cell> RowType;
@@ -356,6 +357,7 @@ ScSortInfoArray* ScTable::CreateSortInfoArray( SCCOLROW nInd1, SCCOLROW nInd2 )
                 rCell.maCell = rCol.GetCellValue(aBlockPos, nRow);
                 rCell.mpAttr = rCol.GetCellTextAttr(aBlockPos, nRow);
                 rCell.mpBroadcaster = rCol.GetBroadcaster(aBlockPos, nRow);
+                rCell.mpNote = rCol.GetCellNote(aBlockPos, nRow);
             }
         }
     }
@@ -383,11 +385,13 @@ struct SortedColumn : boost::noncopyable
     sc::CellStoreType maCells;
     sc::CellTextAttrStoreType maCellTextAttrs;
     sc::BroadcasterStoreType maBroadcasters;
+    sc::CellNoteStoreType maCellNotes;
 
     SortedColumn( size_t nTopEmptyRows ) :
         maCells(nTopEmptyRows),
         maCellTextAttrs(nTopEmptyRows),
-        maBroadcasters(nTopEmptyRows) {}
+        maBroadcasters(nTopEmptyRows),
+        maCellNotes(nTopEmptyRows) {}
 };
 
 }
@@ -512,6 +516,13 @@ void ScTable::SortReorder( ScSortInfoArray* pArray, ScProgress* pProgress )
                     rBCStore.push_back(const_cast<SvtBroadcaster*>(rCell.mpBroadcaster));
                 else
                     rBCStore.push_back_empty();
+
+                // The same with cell note instances ...
+                sc::CellNoteStoreType& rNoteStore = aSortedCols.at(j).maCellNotes;
+                if (rCell.mpNote)
+                    rNoteStore.push_back(const_cast<ScPostIt*>(rCell.mpNote));
+                else
+                    rNoteStore.push_back_empty();
             }
 
             if (pProgress)
@@ -535,14 +546,24 @@ void ScTable::SortReorder( ScSortInfoArray* pArray, ScProgress* pProgress )
             }
 
             {
-                sc::BroadcasterStoreType& rBCDest = aCol[nThisCol].maBroadcasters;
+                sc::BroadcasterStoreType& rSrc = aSortedCols[i].maBroadcasters;
+                sc::BroadcasterStoreType& rDest = aCol[nThisCol].maBroadcasters;
 
                 // Release current broadcasters first, to prevent them from getting deleted.
-                rBCDest.release_range(nRow1, aSortParam.nRow2);
+                rDest.release_range(nRow1, aSortParam.nRow2);
 
                 // Transfer sorted broadcaster segment to the document.
-                sc::BroadcasterStoreType& rBCSrc = aSortedCols[i].maBroadcasters;
-                rBCSrc.transfer(nRow1, aSortParam.nRow2, rBCDest, nRow1);
+                rSrc.transfer(nRow1, aSortParam.nRow2, rDest, nRow1);
+            }
+
+            {
+                sc::CellNoteStoreType& rSrc = aSortedCols[i].maCellNotes;
+                sc::CellNoteStoreType& rDest = aCol[nThisCol].maCellNotes;
+
+                // Do the same as broadcaster storage transfer (to prevent double deletion).
+                rDest.release_range(nRow1, aSortParam.nRow2);
+                rSrc.transfer(nRow1, aSortParam.nRow2, rDest, nRow1);
+                aCol[nThisCol].UpdateNoteCaptions(nRow1, aSortParam.nRow2);
             }
 
             aCol[nThisCol].CellStorageModified();


More information about the Libreoffice-commits mailing list