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

Kohei Yoshida kohei.yoshida at gmail.com
Wed Mar 20 13:25:31 PDT 2013


 sc/inc/column.hxx                 |    4 +++-
 sc/inc/document.hxx               |    5 ++++-
 sc/inc/table.hxx                  |    5 ++++-
 sc/source/core/data/column3.cxx   |   20 +++++++++++++-------
 sc/source/core/data/documen2.cxx  |   12 ++++++++++++
 sc/source/core/data/document.cxx  |   12 ++++++++++--
 sc/source/core/data/table2.cxx    |   23 +++++++++++++++++++++--
 sc/source/ui/docshell/docfunc.cxx |    6 +++---
 sc/source/ui/inc/undocell.hxx     |    4 ++--
 sc/source/ui/undo/undocell.cxx    |    6 +++---
 10 files changed, 75 insertions(+), 22 deletions(-)

New commits:
commit 384667a40c005b32cb78ba89cd35e0e94bfcf685
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 20 16:27:39 2013 -0400

    Do the same for formula cells.
    
    Change-Id: Ia17079042ee4e17fb5b6abe8ae18b7838b68c7c1

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index edfa5f4..83a5530 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -264,6 +264,7 @@ public:
     void SetEditText( SCROW nRow, EditTextObject* pEditText );
     void SetFormula( SCROW nRow, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram );
     void SetFormula( SCROW nRow, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram );
+    void SetFormulaCell( SCROW nRow, ScFormulaCell* pCell );
 
     void        SetValue( SCROW nRow, const double& rVal);
     void        SetError( SCROW nRow, const sal_uInt16 nError);
@@ -273,7 +274,8 @@ public:
     double      GetValue( SCROW nRow ) const;
     const EditTextObject* GetEditText( SCROW nRow ) const;
     void        GetFormula( SCROW nRow, rtl::OUString& rFormula ) const;
-    const ScTokenArray* GetFormula( SCROW nRow ) const;
+    const ScTokenArray* GetFormulaTokens( SCROW nRow ) const;
+    const ScFormulaCell* GetFormulaCell( SCROW nRow ) const;
     CellType    GetCellType( SCROW nRow ) const;
     SCSIZE      GetCellCount() const;
     sal_uInt32 GetWeightedCount() const;
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 22fdec6..0f49166 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -787,6 +787,8 @@ public:
         const ScAddress& rPos, const OUString& rFormula,
         formula::FormulaGrammar::Grammar eGram = formula::FormulaGrammar::GRAM_DEFAULT );
 
+    void SetFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell );
+
     SC_DLLPUBLIC void           InsertMatrixFormula(SCCOL nCol1, SCROW nRow1,
                                         SCCOL nCol2, SCROW nRow2,
                                         const ScMarkData& rMark,
@@ -820,7 +822,8 @@ public:
     SC_DLLPUBLIC void           GetNumberFormatInfo( short& nType, sal_uLong& nIndex,
                         const ScAddress& rPos, const ScBaseCell* pCell ) const;
     void            GetFormula( SCCOL nCol, SCROW nRow, SCTAB nTab, String& rFormula ) const;
-    const ScTokenArray* GetFormula( const ScAddress& rPos ) const;
+    const ScTokenArray* GetFormulaTokens( const ScAddress& rPos ) const;
+    const ScFormulaCell* GetFormulaCell( const ScAddress& rPos ) const;
     SC_DLLPUBLIC void           GetFormula( SCCOL nCol, SCROW nRow, SCTAB nTab, rtl::OUString& rFormula ) const;
     SC_DLLPUBLIC void           GetCellType( SCCOL nCol, SCROW nRow, SCTAB nTab, CellType& rCellType ) const;
     SC_DLLPUBLIC CellType       GetCellType( const ScAddress& rPos ) const;
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 84b5e0c..aebe9c0 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -311,6 +311,8 @@ public:
     void SetFormula(
         SCCOL nCol, SCROW nRow, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram );
 
+    void SetFormulaCell( SCCOL nCol, SCROW nRow, ScFormulaCell* pCell );
+
     void        SetValue( SCCOL nCol, SCROW nRow, const double& rVal );
     void        SetError( SCCOL nCol, SCROW nRow, sal_uInt16 nError);
 
@@ -325,7 +327,8 @@ public:
     double      GetValue( SCCOL nCol, SCROW nRow ) const;
     const EditTextObject* GetEditText( SCCOL nCol, SCROW nRow ) const;
     void GetFormula( SCCOL nCol, SCROW nRow, rtl::OUString& rFormula ) const;
-    const ScTokenArray* GetFormula( SCCOL nCol, SCROW nRow ) const;
+    const ScTokenArray* GetFormulaTokens( SCCOL nCol, SCROW nRow ) const;
+    const ScFormulaCell* GetFormulaCell( SCCOL nCol, SCROW nRow ) const;
 
     CellType    GetCellType( const ScAddress& rPos ) const
                     {
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index e914344..fedb528 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1500,6 +1500,11 @@ void ScColumn::SetFormula( SCROW nRow, const OUString& rFormula, formula::Formul
     Insert(nRow, new ScFormulaCell(pDocument, aPos, rFormula, eGram));
 }
 
+void ScColumn::SetFormulaCell( SCROW nRow, ScFormulaCell* pCell )
+{
+    Insert(nRow, pCell);
+}
+
 void ScColumn::GetFilterEntries(SCROW nStartRow, SCROW nEndRow, std::vector<ScTypedStrData>& rStrings, bool& rHasDates)
 {
     bool bHasDates = false;
@@ -1823,17 +1828,18 @@ void ScColumn::GetFormula( SCROW nRow, rtl::OUString& rFormula ) const
         rFormula = rtl::OUString();
 }
 
-const ScTokenArray* ScColumn::GetFormula( SCROW nRow ) const
+const ScTokenArray* ScColumn::GetFormulaTokens( SCROW nRow ) const
 {
-    SCSIZE nIndex;
-    if (!Search(nRow, nIndex))
+    const ScFormulaCell* pCell = FetchFormulaCell(nRow);
+    if (!pCell)
         return NULL;
 
-    const ScBaseCell* pCell = maItems[nIndex].pCell;
-    if (pCell->GetCellType() != CELLTYPE_FORMULA)
-        return NULL;
+    return pCell->GetCode();
+}
 
-    return static_cast<const ScFormulaCell*>(pCell)->GetCode();
+const ScFormulaCell* ScColumn::GetFormulaCell( SCROW nRow ) const
+{
+    return FetchFormulaCell(nRow);
 }
 
 CellType ScColumn::GetCellType( SCROW nRow ) const
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 3151053..90cc920 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -84,6 +84,7 @@
 #include "formulaparserpool.hxx"
 #include "clipparam.hxx"
 #include "macromgr.hxx"
+#include "cell.hxx"
 
 using namespace com::sun::star;
 
@@ -1056,6 +1057,17 @@ void ScDocument::SetFormula(
     maTabs[rPos.Tab()]->SetFormula(rPos.Col(), rPos.Row(), rFormula, eGram);
 }
 
+void ScDocument::SetFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell )
+{
+    if (!TableExists(rPos.Tab()))
+    {
+        pCell->Delete();
+        return;
+    }
+
+    maTabs[rPos.Tab()]->SetFormulaCell(rPos.Col(), rPos.Row(), pCell);
+}
+
 void ScDocument::SetConsolidateDlgData( const ScConsolidateParam* pData )
 {
     delete pConsolidateDlgData;
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index e798256..5ccd2bc 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -3242,12 +3242,20 @@ void ScDocument::GetFormula( SCCOL nCol, SCROW nRow, SCTAB nTab, String& rFormul
     rFormula = aString;
 }
 
-const ScTokenArray* ScDocument::GetFormula( const ScAddress& rPos ) const
+const ScTokenArray* ScDocument::GetFormulaTokens( const ScAddress& rPos ) const
 {
     if (!TableExists(rPos.Tab()))
         return NULL;
 
-    return maTabs[rPos.Tab()]->GetFormula(rPos.Col(), rPos.Row());
+    return maTabs[rPos.Tab()]->GetFormulaTokens(rPos.Col(), rPos.Row());
+}
+
+const ScFormulaCell* ScDocument::GetFormulaCell( const ScAddress& rPos ) const
+{
+    if (!TableExists(rPos.Tab()))
+        return NULL;
+
+    return maTabs[rPos.Tab()]->GetFormulaCell(rPos.Col(), rPos.Row());
 }
 
 CellType ScDocument::GetCellType( const ScAddress& rPos ) const
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index aab3235..0306f2c 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1360,6 +1360,17 @@ void ScTable::SetFormula(
     aCol[nCol].SetFormula(nRow, rFormula, eGram);
 }
 
+void ScTable::SetFormulaCell( SCCOL nCol, SCROW nRow, ScFormulaCell* pCell )
+{
+    if (!ValidColRow(nCol, nRow))
+    {
+        pCell->Delete();
+        return;
+    }
+
+    aCol[nCol].SetFormulaCell(nRow, pCell);
+}
+
 void ScTable::SetValue( SCCOL nCol, SCROW nRow, const double& rVal )
 {
     if (ValidColRow(nCol, nRow))
@@ -1408,12 +1419,20 @@ void ScTable::GetFormula( SCCOL nCol, SCROW nRow, rtl::OUString& rFormula ) cons
         rFormula = rtl::OUString();
 }
 
-const ScTokenArray* ScTable::GetFormula( SCCOL nCol, SCROW nRow ) const
+const ScTokenArray* ScTable::GetFormulaTokens( SCCOL nCol, SCROW nRow ) const
+{
+    if (!ValidColRow(nCol, nRow))
+        return NULL;
+
+    return aCol[nCol].GetFormulaTokens(nRow);
+}
+
+const ScFormulaCell* ScTable::GetFormulaCell( SCCOL nCol, SCROW nRow ) const
 {
     if (!ValidColRow(nCol, nRow))
         return NULL;
 
-    return aCol[nCol].GetFormula(nRow);
+    return aCol[nCol].GetFormulaCell(nRow);
 }
 
 ScNotes* ScTable::GetNotes()
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index b3df393..08c96e3 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -842,9 +842,9 @@ void pushUndoSetCell( ScDocShell& rDocShell, ScDocument* pDoc, const ScAddress&
         break;
         case CELLTYPE_FORMULA:
         {
-            const ScTokenArray* pTokens = pDoc->GetFormula(rPos);
-            if (pTokens)
-                pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, *pTokens, rNewVal));
+            const ScFormulaCell* pCell = pDoc->GetFormulaCell(rPos);
+            if (pCell)
+                pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, *pCell, rNewVal));
         }
         break;
         default:
diff --git a/sc/source/ui/inc/undocell.hxx b/sc/source/ui/inc/undocell.hxx
index a99f05e..19bdee5 100644
--- a/sc/source/ui/inc/undocell.hxx
+++ b/sc/source/ui/inc/undocell.hxx
@@ -168,14 +168,14 @@ public:
             double mfValue;
             OUString* mpString;
             EditTextObject* mpEditText;
-            ScTokenArray* mpFormula;
+            ScFormulaCell* mpFormula;
         };
 
         Value();
         Value( double fValue );
         Value( const OUString& rString );
         Value( const EditTextObject& rEditText );
-        Value( const ScTokenArray& rFormula );
+        Value( const ScFormulaCell& rFormula );
         Value( const Value& r );
         ~Value();
     };
diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx
index e7fb68a..878a077 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -502,7 +502,7 @@ ScUndoSetCell::Value::Value() : meType(CELLTYPE_NONE), mfValue(0.0) {}
 ScUndoSetCell::Value::Value( double fValue ) : meType(CELLTYPE_VALUE), mfValue(fValue) {}
 ScUndoSetCell::Value::Value( const OUString& rString ) : meType(CELLTYPE_STRING), mpString(new OUString(rString)) {}
 ScUndoSetCell::Value::Value( const EditTextObject& rEditText ) : meType(CELLTYPE_EDIT), mpEditText(rEditText.Clone()) {}
-ScUndoSetCell::Value::Value( const ScTokenArray& rFormula ) : meType(CELLTYPE_FORMULA), mpFormula(rFormula.Clone()) {}
+ScUndoSetCell::Value::Value( const ScFormulaCell& rFormula ) : meType(CELLTYPE_FORMULA), mpFormula(rFormula.Clone()) {}
 
 ScUndoSetCell::Value::Value( const Value& r ) : meType(r.meType), mfValue(r.mfValue)
 {
@@ -531,7 +531,7 @@ ScUndoSetCell::Value::~Value()
         case CELLTYPE_EDIT:
             delete mpEditText;
         case CELLTYPE_FORMULA:
-            delete mpFormula;
+            mpFormula->Delete();
         default:
             ;
     }
@@ -594,7 +594,7 @@ void ScUndoSetCell::SetValue( const Value& rVal )
             pDoc->SetEditText(maPos, rVal.mpEditText->Clone());
         break;
         case CELLTYPE_FORMULA:
-            pDoc->SetFormula(maPos, *rVal.mpFormula);
+            pDoc->SetFormulaCell(maPos, rVal.mpFormula->Clone());
         break;
         default:
             ;


More information about the Libreoffice-commits mailing list