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

Kohei Yoshida kohei.yoshida at gmail.com
Fri May 17 13:46:45 PDT 2013


 sc/inc/clipcontext.hxx              |   20 ++++-------
 sc/source/core/data/clipcontext.cxx |   64 ++++++++++--------------------------
 sc/source/core/data/column.cxx      |    2 -
 sc/source/core/data/documen2.cxx    |    2 -
 sc/source/core/data/document.cxx    |   13 -------
 sc/source/core/data/table2.cxx      |    1 
 6 files changed, 27 insertions(+), 75 deletions(-)

New commits:
commit 8d71db3c08c1295c2df98fccba8529a5e55d1af1
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri May 17 16:48:25 2013 -0400

    A bit of a cleanup.
    
    Change-Id: Iaa7003cabee4630e4fbb8fb1cd114d04b4e9e33c

diff --git a/sc/inc/clipcontext.hxx b/sc/inc/clipcontext.hxx
index 599da6e..84b1fcc 100644
--- a/sc/inc/clipcontext.hxx
+++ b/sc/inc/clipcontext.hxx
@@ -22,13 +22,7 @@ namespace sc {
 
 class ClipContextBase
 {
-    typedef boost::unordered_map<SCCOL, ColumnBlockPosition> ColumnsType;
-    typedef std::vector<ColumnsType> TablesType;
-
-    ScDocument& mrDoc;
-    TablesType maTables;
-    SCTAB mnTabStart;
-    SCTAB mnTabEnd;
+    sc::ColumnBlockPositionSet maSet;
 
     ClipContextBase(); // disabled
 
@@ -36,16 +30,13 @@ public:
     ClipContextBase(ScDocument& rDoc);
     virtual ~ClipContextBase();
 
-    void setTabRange(SCTAB nStart, SCTAB nEnd);
-
-    SCTAB getTabStart() const;
-    SCTAB getTabEnd() const;
-
     ColumnBlockPosition* getBlockPosition(SCTAB nTab, SCCOL nCol);
 };
 
 class CopyFromClipContext : public ClipContextBase
 {
+    SCTAB mnTabStart;
+    SCTAB mnTabEnd;
     ScDocument* mpRefUndoDoc;
     ScDocument* mpClipDoc;
     sal_uInt16  mnInsertFlag;
@@ -61,6 +52,11 @@ public:
 
     virtual ~CopyFromClipContext();
 
+    void setTabRange(SCTAB nStart, SCTAB nEnd);
+
+    SCTAB getTabStart() const;
+    SCTAB getTabEnd() const;
+
     ScDocument* getUndoDoc();
     ScDocument* getClipDoc();
     sal_uInt16 getInsertFlag() const;
diff --git a/sc/source/core/data/clipcontext.cxx b/sc/source/core/data/clipcontext.cxx
index 2c7abdf..2b51076 100644
--- a/sc/source/core/data/clipcontext.cxx
+++ b/sc/source/core/data/clipcontext.cxx
@@ -13,62 +13,20 @@
 namespace sc {
 
 ClipContextBase::ClipContextBase(ScDocument& rDoc) :
-    mrDoc(rDoc), mnTabStart(-1), mnTabEnd(-1) {}
+    maSet(rDoc) {}
 
 ClipContextBase::~ClipContextBase() {}
 
-void ClipContextBase::setTabRange(SCTAB nStart, SCTAB nEnd)
-{
-    mnTabStart = nStart;
-    mnTabEnd = nEnd;
-}
-
-SCTAB ClipContextBase::getTabStart() const
-{
-    return mnTabStart;
-}
-
-SCTAB ClipContextBase::getTabEnd() const
-{
-    return mnTabEnd;
-}
-
 ColumnBlockPosition* ClipContextBase::getBlockPosition(SCTAB nTab, SCCOL nCol)
 {
-    if (mnTabStart < 0 || mnTabEnd < 0 || mnTabStart > mnTabEnd)
-        return NULL;
-
-    size_t nTabIndex = nTab - mnTabStart;
-    if (nTabIndex >= maTables.size())
-        maTables.resize(nTabIndex+1);
-
-    ColumnsType& rCols = maTables[nTabIndex];
-
-    ColumnsType::iterator it = rCols.find(nCol);
-    if (it != rCols.end())
-        // Block position for this column has already been fetched.
-        return &it->second;
-
-    std::pair<ColumnsType::iterator,bool> r =
-        rCols.insert(
-            ColumnsType::value_type(nCol, ColumnBlockPosition()));
-
-    if (!r.second)
-        // insertion failed.
-        return NULL;
-
-    it = r.first;
-
-    if (!mrDoc.InitColumnBlockPosition(it->second, nTab, nCol))
-        return NULL;
-
-    return &it->second;
+    return maSet.getBlockPosition(nTab, nCol);
 }
 
 CopyFromClipContext::CopyFromClipContext(ScDocument& rDoc,
     ScDocument* pRefUndoDoc, ScDocument* pClipDoc, sal_uInt16 nInsertFlag,
     bool bAsLink, bool bSkipAttrForEmptyCells) :
     ClipContextBase(rDoc),
+    mnTabStart(-1), mnTabEnd(-1),
     mpRefUndoDoc(pRefUndoDoc), mpClipDoc(pClipDoc), mnInsertFlag(nInsertFlag),
     mbAsLink(bAsLink), mbSkipAttrForEmptyCells(bSkipAttrForEmptyCells) {}
 
@@ -76,6 +34,22 @@ CopyFromClipContext::~CopyFromClipContext()
 {
 }
 
+void CopyFromClipContext::setTabRange(SCTAB nStart, SCTAB nEnd)
+{
+    mnTabStart = nStart;
+    mnTabEnd = nEnd;
+}
+
+SCTAB CopyFromClipContext::getTabStart() const
+{
+    return mnTabStart;
+}
+
+SCTAB CopyFromClipContext::getTabEnd() const
+{
+    return mnTabEnd;
+}
+
 ScDocument* CopyFromClipContext::getUndoDoc()
 {
     return mpRefUndoDoc;
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 94cd257..10d36b6 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1514,7 +1514,6 @@ void ScColumn::CopyScenarioFrom( const ScColumn& rSrcCol )
 {
     //  This is the scenario table, the data is copied into it
     sc::CopyToDocContext aCxt(*pDocument);
-    aCxt.setTabRange(nTab, nTab);
     ScAttrIterator aAttrIter( pAttrArray, 0, MAXROW );
     SCROW nStart = -1, nEnd = -1;
     const ScPatternAttr* pPattern = aAttrIter.Next( nStart, nEnd );
@@ -1546,7 +1545,6 @@ void ScColumn::CopyScenarioTo( ScColumn& rDestCol ) const
 {
     //  This is the scenario table, the data is copied to the other
     sc::CopyToDocContext aCxt(*rDestCol.pDocument);
-    aCxt.setTabRange(rDestCol.nTab, rDestCol.nTab);
     ScAttrIterator aAttrIter( pAttrArray, 0, MAXROW );
     SCROW nStart = -1, nEnd = -1;
     const ScPatternAttr* pPattern = aAttrIter.Next( nStart, nEnd );
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 0229c52..dcdae98 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -857,7 +857,6 @@ bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyM
     if (bValid)
     {
         sc::CopyToDocContext aCxt(*this);
-        aCxt.setTabRange(nNewPos, nNewPos);
         SetNoListening( true );     // noch nicht bei CopyToTable/Insert
         maTabs[nOldPos]->CopyToTable(aCxt, 0, 0, MAXCOL, MAXROW, IDF_ALL, (pOnlyMarked != NULL),
                                         maTabs[nNewPos], pOnlyMarked );
@@ -965,7 +964,6 @@ sal_uLong ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos,
             NumFmtMergeHandler aNumFmtMergeHdl(this, pSrcDoc);
 
             sc::CopyToDocContext aCxt(*this);
-            aCxt.setTabRange(nDestPos, nDestPos);
             nDestPos = std::min(nDestPos, (SCTAB)(GetTableCount() - 1));
             {   // scope for bulk broadcast
                 ScBulkBroadcast aBulkBroadcast( pBASM);
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index decaae9..54b7414 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -1843,7 +1843,6 @@ void ScDocument::CopyToDocument(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
     if (ValidTab(nTab1) && ValidTab(nTab2))
     {
         sc::CopyToDocContext aCxt(*pDestDoc);
-        aCxt.setTabRange(nTab1, nTab2);
         bool bOldAutoCalc = pDestDoc->GetAutoCalc();
         pDestDoc->SetAutoCalc( false );     // avoid multiple calculations
         for (SCTAB i = nTab1; i <= nTab2 && i < static_cast<SCTAB>(maTabs.size()); i++)
@@ -1874,7 +1873,6 @@ void ScDocument::UndoToDocument(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
             CopyToDocument( 0,0,0, MAXCOL,MAXROW,nTab1-1, IDF_FORMULA, false, pDestDoc, pMarks );
 
         sc::CopyToDocContext aCxt(*pDestDoc);
-        aCxt.setTabRange(nTab1, nTab2);
         OSL_ASSERT( nTab2 < static_cast<SCTAB>(maTabs.size()) && nTab2 < static_cast<SCTAB>(pDestDoc->maTabs.size()));
         for (SCTAB i = nTab1; i <= nTab2; i++)
         {
@@ -1903,7 +1901,6 @@ void ScDocument::CopyToDocument(const ScRange& rRange,
     pDestDoc->SetAutoCalc( false );     // avoid multiple calculations
 
     sc::CopyToDocContext aCxt(*pDestDoc);
-    aCxt.setTabRange(aNewRange.aStart.Tab(), aNewRange.aEnd.Tab());
     for (SCTAB i = aNewRange.aStart.Tab(); i <= aNewRange.aEnd.Tab() && i < static_cast<SCTAB>(maTabs.size()); i++)
     {
         if (!TableExists(i) || !pDestDoc->TableExists(i))
@@ -1930,7 +1927,6 @@ void ScDocument::UndoToDocument(const ScRange& rRange,
     bool bOldAutoCalc = pDestDoc->GetAutoCalc();
     pDestDoc->SetAutoCalc( false );     // avoid multiple calculations
     sc::CopyToDocContext aCxt(*pDestDoc);
-    aCxt.setTabRange(nTab1, nTab2);
     if (nTab1 > 0)
         CopyToDocument( 0,0,0, MAXCOL,MAXROW,nTab1-1, IDF_FORMULA, false, pDestDoc, pMarks );
 
@@ -2007,7 +2003,6 @@ void ScDocument::CopyToClip(const ScClipParam& rClipParam,
         pClipDoc->ResetClip(this, pMarks);
 
     sc::CopyToClipContext aCxt(*pClipDoc, bKeepScenarioFlags, bCloneNoteCaptions);
-    aCxt.setTabRange(i, nEndTab-1);
     CopyRangeNamesToClip(pClipDoc, aClipRange, pMarks, bAllTabs);
 
     for ( ; i < nEndTab; ++i)
@@ -2105,7 +2100,6 @@ void ScDocument::CopyTabToClip(SCCOL nCol1, SCROW nRow1,
         pClipDoc->ResetClip( this, nTab );
 
         sc::CopyToClipContext aCxt(*pClipDoc, false, true);
-        aCxt.setTabRange(nTab, nTab);
         if (nTab < static_cast<SCTAB>(maTabs.size()) && nTab < static_cast<SCTAB>(pClipDoc->maTabs.size()))
             if (maTabs[nTab] && pClipDoc->maTabs[nTab])
                 maTabs[nTab]->CopyToClip(aCxt, nCol1, nRow1, nCol2, nRow2, pClipDoc->maTabs[nTab]);
@@ -2863,7 +2857,6 @@ void ScDocument::MixDocument( const ScRange& rRange, sal_uInt16 nFunction, bool
     SCTAB nTab1 = rRange.aStart.Tab();
     SCTAB nTab2 = rRange.aEnd.Tab();
     sc::MixDocContext aCxt(*this);
-    aCxt.setTabRange(nTab1, nTab2);
     for (SCTAB i = nTab1; i <= nTab2 && i < static_cast<SCTAB>(maTabs.size()); i++)
     {
         ScTable* pTab = FetchTable(i);
@@ -2901,9 +2894,7 @@ void ScDocument::FillTab( const ScRange& rSrcArea, const ScMarkData& rMark,
         SetAutoCalc( false );                   // avoid multiple calculations
 
         sc::CopyToDocContext aCxt(*this);
-        aCxt.setTabRange(rMark.GetFirstSelected(), rMark.GetLastSelected());
         sc::MixDocContext aMixDocCxt(*this);
-        aMixDocCxt.setTabRange(rMark.GetFirstSelected(), rMark.GetLastSelected());
 
         SCTAB nCount = static_cast<SCTAB>(maTabs.size());
         ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
@@ -2923,7 +2914,6 @@ void ScDocument::FillTab( const ScRange& rSrcArea, const ScMarkData& rMark,
 
                     // context used for copying content to the temporary mix document.
                     sc::CopyToDocContext aMixCxt(*pMixDoc);
-                    aMixCxt.setTabRange(i, i);
                     maTabs[i]->CopyToTable(aMixCxt, nStartCol,nStartRow, nEndCol,nEndRow,
                                             IDF_CONTENTS, false, pMixDoc->maTabs[i] );
                 }
@@ -2969,9 +2959,7 @@ void ScDocument::FillTabMarked( SCTAB nSrcTab, const ScMarkData& rMark,
         SCROW nEndRow = aArea.aEnd.Row();
 
         sc::CopyToDocContext aCxt(*this);
-        aCxt.setTabRange(rMark.GetFirstSelected(), rMark.GetLastSelected());
         sc::MixDocContext aMixDocCxt(*this);
-        aMixDocCxt.setTabRange(rMark.GetFirstSelected(), rMark.GetLastSelected());
         SCTAB nCount = static_cast<SCTAB>(maTabs.size());
         ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
         for (; itr != itrEnd && *itr < nCount; ++itr)
@@ -2989,7 +2977,6 @@ void ScDocument::FillTabMarked( SCTAB nSrcTab, const ScMarkData& rMark,
                         pMixDoc->AddUndoTab( i, i );
 
                     sc::CopyToDocContext aMixCxt(*pMixDoc);
-                    aMixCxt.setTabRange(i, i);
                     maTabs[i]->CopyToTable(aMixCxt, nStartCol,nStartRow, nEndCol,nEndRow,
                                             IDF_CONTENTS, true, pMixDoc->maTabs[i], &rMark );
                 }
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 4af76be..51801af 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -407,7 +407,6 @@ void ScTable::InsertCol( SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE
         nWhichArray[2] = 0;
 
         sc::CopyToDocContext aCxt(*pDocument);
-        aCxt.setTabRange(nTab, nTab);
         for (SCSIZE i=0; i<nSize; i++)
         {
             aCol[nStartCol-1].CopyToColumn(aCxt, nStartRow, nEndRow, IDF_ATTRIB,


More information about the Libreoffice-commits mailing list