[Libreoffice-commits] core.git: 3 commits - formula/source sc/inc sc/qa sc/source

Benjamin Ni benjaminniri at hotmail.com
Mon Jul 27 11:03:03 PDT 2015


 formula/source/ui/dlg/formula.cxx         |   50 +++++++++++++++++++++++++++---
 formula/source/ui/dlg/structpg.hxx        |    2 +
 sc/inc/simpleformulacalc.hxx              |    3 +
 sc/qa/unit/ucalc.cxx                      |   29 +++++++++--------
 sc/source/core/data/simpleformulacalc.cxx |   23 +++++++++++++
 sc/source/ui/formdlg/formula.cxx          |    2 +
 6 files changed, 92 insertions(+), 17 deletions(-)

New commits:
commit 774085dbe5c332f2be757f5f6a0324280dd72651
Author: Benjamin Ni <benjaminniri at hotmail.com>
Date:   Mon Jul 27 19:59:28 2015 +0200

    tdf#92548, limit number of characters shown in formula wizard
    
    Change-Id: I5c322140d40e1ec31e8664a6f731e57b9b3defdb

diff --git a/formula/source/ui/dlg/formula.cxx b/formula/source/ui/dlg/formula.cxx
index 90dfb5b..7399e06 100644
--- a/formula/source/ui/dlg/formula.cxx
+++ b/formula/source/ui/dlg/formula.cxx
@@ -723,7 +723,7 @@ void FormulaDlg_Impl::MakeTree(IStructHelper* _pTree,SvTreeListEntry* pParent,Fo
                         const IFunctionDescription* pDesc =pFuncPage->GetFuncDesc( pFuncPage->GetFunction() );
                         if(pDesc==pFuncDesc || !pFuncPage->IsVisible())
                         {
-//                             EditNextFunc(false);
+                            EditNextFunc(false);
                         }
                     }
 
diff --git a/sc/inc/simpleformulacalc.hxx b/sc/inc/simpleformulacalc.hxx
index 2d20f6d..f12e261 100644
--- a/sc/inc/simpleformulacalc.hxx
+++ b/sc/inc/simpleformulacalc.hxx
@@ -33,6 +33,7 @@ private:
     formula::FormulaGrammar::Grammar maGram;
     bool bIsMatrix;
     OUString maMatrixFormulaResult;
+    bool mbLimitString;
 
 public:
     ScSimpleFormulaCalculator(ScDocument* pDoc, const ScAddress& rAddr,
@@ -50,6 +51,8 @@ public:
     bool HasColRowName();
 
     ScTokenArray* GetCode();
+
+    void SetLimitString(bool bLimitString);
 };
 
 #endif
diff --git a/sc/source/core/data/simpleformulacalc.cxx b/sc/source/core/data/simpleformulacalc.cxx
index d359667..a931551 100644
--- a/sc/source/core/data/simpleformulacalc.cxx
+++ b/sc/source/core/data/simpleformulacalc.cxx
@@ -13,6 +13,8 @@
 #include "interpre.hxx"
 #include "compiler.hxx"
 
+#define DISPLAY_LEN 15
+
 ScSimpleFormulaCalculator::ScSimpleFormulaCalculator( ScDocument* pDoc, const ScAddress& rAddr,
         const OUString& rFormula, formula::FormulaGrammar::Grammar eGram )
     : mnFormatType(0)
@@ -22,6 +24,7 @@ ScSimpleFormulaCalculator::ScSimpleFormulaCalculator( ScDocument* pDoc, const Sc
     , mpDoc(pDoc)
     , maGram(eGram)
     , bIsMatrix(false)
+    , mbLimitString(false)
 {
     // compile already here
     ScCompiler aComp(mpDoc, maAddr);
@@ -53,6 +56,21 @@ void ScSimpleFormulaCalculator::Calculate()
         aComp.CreateStringFromToken(aStr, aInt.GetResultToken().get(), false);
 
         bIsMatrix = true;
+
+        if (mbLimitString)
+        {
+            size_t n = aStr.getLength();
+            for (size_t i = DISPLAY_LEN; i < n; ++i)
+            {
+                if (aStr[i] == ',' || aStr[i] == ';')
+                {
+                    aStr.truncate(i);
+                    aStr.append("...");
+                    break;
+                }
+            }
+        }
+
         maMatrixFormulaResult = aStr.makeStringAndClear();
     }
     mnFormatType = aInt.GetRetFormatType();
@@ -121,4 +139,9 @@ ScTokenArray* ScSimpleFormulaCalculator::GetCode()
     return mpCode.get();
 }
 
+void ScSimpleFormulaCalculator::SetLimitString(bool bLimitString)
+{
+    mbLimitString = bLimitString;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/formdlg/formula.cxx b/sc/source/ui/formdlg/formula.cxx
index 4160619..d6c1b17 100644
--- a/sc/source/ui/formdlg/formula.cxx
+++ b/sc/source/ui/formdlg/formula.cxx
@@ -308,6 +308,7 @@ bool ScFormulaDlg::Close()
 bool ScFormulaDlg::calculateValue( const OUString& rStrExp, OUString& rStrResult )
 {
     boost::scoped_ptr<ScSimpleFormulaCalculator> pFCell( new ScSimpleFormulaCalculator( pDoc, aCursorPos, rStrExp ) );
+    pFCell->SetLimitString(true);
 
     // HACK! to avoid neither #REF! from ColRowNames
     // if a name is added as actually range in the overall formula,
@@ -324,6 +325,7 @@ bool ScFormulaDlg::calculateValue( const OUString& rStrExp, OUString& rStrResult
             aBraced.append(rStrExp);
             aBraced.append(')');
             pFCell.reset( new ScSimpleFormulaCalculator( pDoc, aCursorPos, aBraced.makeStringAndClear() ) );
+            pFCell->SetLimitString(true);
         }
         else
             bColRowName = false;
commit f82d89f35207fc1cfc00ad5cd914b74c55c3e3d2
Author: Benjamin Ni <benjaminniri at hotmail.com>
Date:   Sun Jul 12 15:41:55 2015 +0100

    tdf#92546 show results for sub-expressions in formula wizard
    
    Change-Id: I1d5ba707d8dce69abc15ec1de7bec4728bd93adb

diff --git a/formula/source/ui/dlg/formula.cxx b/formula/source/ui/dlg/formula.cxx
index 8581e8f..90dfb5b 100644
--- a/formula/source/ui/dlg/formula.cxx
+++ b/formula/source/ui/dlg/formula.cxx
@@ -90,7 +90,7 @@ namespace formula
         void            UpdateTokenArray( const OUString& rStrExp);
         OUString        RepairFormula(const OUString& aFormula);
         void            FillDialog(bool nFlag=true);
-        void            EditNextFunc( bool bForward, sal_Int32 nFStart=NOT_FOUND );
+        bool            EditNextFunc( bool bForward, sal_Int32 nFStart=NOT_FOUND );
         void            EditThisFunc(sal_Int32 nFStart);
 
         void            StoreFormEditData(FormEditData* pEditData);
@@ -198,6 +198,7 @@ namespace formula
         OString    aOldUnique;
         OString    aActivWinId;
         bool            bIsShutDown;
+        bool            bMakingTree; //in method of constructing tree
 
         vcl::Font       aFntBold;
         vcl::Font       aFntLight;
@@ -243,6 +244,7 @@ FormulaDlg_Impl::FormulaDlg_Impl(Dialog* pParent
     aTxtEnd         ( ModuleRes( STR_END ) ),
     m_aFormulaHelper(_pFunctionMgr),
     bIsShutDown     (false),
+    bMakingTree     (false),
     nEdFocus        (0),
     pFuncDesc       (NULL),
     nArgs           (0)
@@ -600,6 +602,8 @@ void FormulaDlg_Impl::UpdateValues()
     if ( CalcValue( pFuncDesc->getFormula( m_aArguments ), aStrResult ) )
         m_pWndResult->SetText( aStrResult );
 
+    if (bMakingTree) return;
+
     aStrResult.clear();
     if ( CalcValue(m_pHelper->getCurrentFormula(), aStrResult ) )
         m_pWndFormResult->SetText( aStrResult );
@@ -674,6 +678,7 @@ void FormulaDlg_Impl::MakeTree(IStructHelper* _pTree,SvTreeListEntry* pParent,Fo
             {
                 SvTreeListEntry* pEntry;
 
+                bool bCalcSubformula = false;
                 OUString aTest=_pTree->GetEntryText(pParent);
 
                 if(aTest==aResult &&
@@ -688,6 +693,12 @@ void FormulaDlg_Impl::MakeTree(IStructHelper* _pTree,SvTreeListEntry* pParent,Fo
                     {
                         pEntry=_pTree->InsertEntry(aResult,pParent,STRUCT_ERROR,0,_pToken);
                     }
+
+                    else if ( eOp<ocAdd || eOp>ocNegSub ) // not ideal coding
+                    {
+                        bCalcSubformula = true;
+                        pEntry=_pTree->InsertEntry(aResult,pParent,STRUCT_FOLDER,0,_pToken);
+                    }
                     else
                     {
                         pEntry=_pTree->InsertEntry(aResult,pParent,STRUCT_FOLDER,0,_pToken);
@@ -695,6 +706,33 @@ void FormulaDlg_Impl::MakeTree(IStructHelper* _pTree,SvTreeListEntry* pParent,Fo
                 }
 
                 MakeTree(_pTree,pEntry,m_pTokenArray->PrevRPN(),nParas);
+
+                if (bCalcSubformula)
+                {
+                    OUString aStr;
+                    OUString aEquals(" = ");
+
+                    if (!bMakingTree)
+                    { // gets the last subformula result
+                        bMakingTree = true;
+                        EditThisFunc(0);
+                        while ( EditNextFunc(true) ) {}
+                    }
+                    else
+                    { // gets subsequent subformula results (from the back)
+                        const IFunctionDescription* pDesc =pFuncPage->GetFuncDesc( pFuncPage->GetFunction() );
+                        if(pDesc==pFuncDesc || !pFuncPage->IsVisible())
+                        {
+//                             EditNextFunc(false);
+                        }
+                    }
+
+                    if ( CalcValue( pFuncDesc->getFormula( m_aArguments ), aStr ) )
+                        m_pWndResult->SetText( aStr );
+                    aStr = m_pWndResult->GetText();
+                    pStructPage->GetTlbStruct()->SetEntryText(pEntry,aResult + aEquals + aStr);
+                }
+
                 --Count;
                 m_pTokenArray->NextRPN();
                 MakeTree(_pTree,pParent,m_pTokenArray->PrevRPN(),Count);
@@ -709,7 +747,8 @@ void FormulaDlg_Impl::MakeTree(IStructHelper* _pTree,SvTreeListEntry* pParent,Fo
                 {
                     OUString aCellResult;
                     OUString aEquals(" = ");
-                    if (CalcValue( "=" + aResult, aCellResult) && aCellResult != aResult) // cell is a formula, print subformula
+                    CalcValue( "=" + aResult, aCellResult);
+                    if (aCellResult != aResult) // cell is a formula, print subformula
                         _pTree->InsertEntry(aResult + aEquals + aCellResult,pParent,STRUCT_END,0,_pToken);
                     else
                         _pTree->InsertEntry(aResult,pParent,STRUCT_END,0,_pToken);
@@ -737,6 +776,7 @@ void FormulaDlg_Impl::fillTree(IStructHelper* _pTree)
     if( pToken != NULL)
     {
         MakeTree(_pTree,NULL,pToken,1);
+        bMakingTree = false;
     }
 }
 void FormulaDlg_Impl::UpdateTokenArray( const OUString& rStrExp)
@@ -1136,11 +1176,11 @@ void FormulaDlg_Impl::EditThisFunc(sal_Int32 nFStart)
     }
 }
 
-void FormulaDlg_Impl::EditNextFunc( bool bForward, sal_Int32 nFStart )
+bool FormulaDlg_Impl::EditNextFunc( bool bForward, sal_Int32 nFStart )
 {
     FormEditData* pData = m_pHelper->getFormEditData();
     if (!pData)
-        return;
+        return false;
 
     OUString aFormula = m_pHelper->getCurrentFormula();
 
@@ -1173,6 +1213,8 @@ void FormulaDlg_Impl::EditNextFunc( bool bForward, sal_Int32 nFStart )
         sal_Int32 PrivStart, PrivEnd;
         SetData(nFStart, nNextFStart, nNextFEnd, PrivStart, PrivEnd);
     }
+
+    return bFound;
 }
 
 void FormulaDlg_Impl::SaveArg( sal_uInt16 nEd )
diff --git a/formula/source/ui/dlg/structpg.hxx b/formula/source/ui/dlg/structpg.hxx
index cd0bf60..4305365 100644
--- a/formula/source/ui/dlg/structpg.hxx
+++ b/formula/source/ui/dlg/structpg.hxx
@@ -100,6 +100,8 @@ public:
     virtual OUString            GetEntryText(SvTreeListEntry* pEntry) const SAL_OVERRIDE;
 
     void            SetSelectionHdl( const Link<>& rLink ) { aSelLink = rLink; }
+
+    StructListBox*  GetTlbStruct() const { return m_pTlbStruct; }
 };
 
 } // formula
commit 3cb68ecffa507eb839552e3d55369faf915fae81
Author: Benjamin Ni <benjaminniri at hotmail.com>
Date:   Mon Jul 27 19:33:24 2015 +0200

    fix test for tdf#92547
    
    Change-Id: Ifa4b338f067bd398c0e4d0e533980a255484dc90

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index dcdc40d..99f5bb9 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -6514,19 +6514,22 @@ void Test::testFormulaWizardSubformula()
 {
     m_pDoc->InsertTab(0, "Test");
 
-    m_pDoc->SetString(ScAddress(0,0,0), "=B0:B2");
-    m_pDoc->SetString(ScAddress(0,1,0), "=1");          // B0
-    m_pDoc->SetString(ScAddress(1,1,0), "=1/0");        // B1
-    m_pDoc->SetString(ScAddress(2,1,0), "=gibberish");  // B2
-    ScSimpleFormulaCalculator aFCell( m_pDoc, ScAddress(0,0,0), "" );
-    if ( aFCell.GetErrCode() == 0 )
-        CPPUNIT_ASSERT_EQUAL( OUString("{1, #DIV/0!, #NAME!}"), aFCell.GetString().getString() );
-
-    m_pDoc->SetString(ScAddress(0,1,0), "=NA()");       // B0
-    m_pDoc->SetString(ScAddress(1,1,0), "2");           // B1
-    m_pDoc->SetString(ScAddress(2,1,0), "=1+2");        // B2
-    if ( aFCell.GetErrCode() == 0 )
-        CPPUNIT_ASSERT_EQUAL(OUString("{#N/A, 2, 3}"), aFCell.GetString().getString());
+    m_pDoc->SetString(ScAddress(1,0,0), "=1");          // B1
+    m_pDoc->SetString(ScAddress(1,1,0), "=1/0");        // B2
+    m_pDoc->SetString(ScAddress(1,2,0), "=gibberish");  // B3
+
+    ScSimpleFormulaCalculator pFCell1( m_pDoc, ScAddress(0,0,0), "=B1:B3" );
+    sal_uInt16 nErrCode = pFCell1.GetErrCode();
+    CPPUNIT_ASSERT( nErrCode == 0 || pFCell1.IsMatrix() );
+    CPPUNIT_ASSERT_EQUAL( OUString("{1;#DIV/0!;#NAME?}"), pFCell1.GetString().getString() );
+
+    m_pDoc->SetString(ScAddress(1,0,0), "=NA()");       // B1
+    m_pDoc->SetString(ScAddress(1,1,0), "2");           // B2
+    m_pDoc->SetString(ScAddress(1,2,0), "=1+2");        // B3
+    ScSimpleFormulaCalculator pFCell2( m_pDoc, ScAddress(0,0,0), "=B1:B3" );
+    nErrCode = pFCell2.GetErrCode();
+    CPPUNIT_ASSERT( nErrCode == 0 || pFCell2.IsMatrix() );
+    CPPUNIT_ASSERT_EQUAL( OUString("{#N/A;2;3}"), pFCell2.GetString().getString() );
 
     m_pDoc->DeleteTab(0);
 }


More information about the Libreoffice-commits mailing list