[Libreoffice-commits] core.git: 2 commits - formula/source

Eike Rathke erack at redhat.com
Tue Jul 11 16:29:00 UTC 2017


 formula/source/ui/dlg/formula.cxx |   49 ++++++++++++++++++++++++++++++++------
 1 file changed, 42 insertions(+), 7 deletions(-)

New commits:
commit e3b82542f2454a78d2013d4bbab4c801625d11da
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Jul 11 18:22:40 2017 +0200

    Use proper non-/array context to calculate Structure tree
    
    Now that ScCompiler compiles ScTokenArray we can finally handle
    FormulaToken::IsInForceArray() as well.
    
    Still missing is the evaluation of the selected sub expression of a formula.
    
    Change-Id: I801859498569e4369db13144fe8ba08ca576350b

diff --git a/formula/source/ui/dlg/formula.cxx b/formula/source/ui/dlg/formula.cxx
index bf24fcd1342d..f2aa183cbf1d 100644
--- a/formula/source/ui/dlg/formula.cxx
+++ b/formula/source/ui/dlg/formula.cxx
@@ -565,6 +565,9 @@ bool FormulaDlg_Impl::CalcValue( const OUString& rStrExp, OUString& rStrResult,
 
 void FormulaDlg_Impl::UpdateValues( bool bForceRecalcStruct )
 {
+    /* TODO: this must take array context of the outer
+     * FormulaToken::IsInForceArray() into account. As is, this is just the
+     * currently selected formula text part. */
     OUString aStrResult;
     if ( pFuncDesc &&  CalcValue( pFuncDesc->getFormula( m_aArguments ), aStrResult ) )
         m_pWndResult->SetText( aStrResult );
@@ -693,7 +696,7 @@ void FormulaDlg_Impl::MakeTree( StructPage* _pTree, SvTreeListEntry* pParent, co
                     }
 
                     OUString aStr;
-                    if (CalcValue( aFormula, aStr))
+                    if (CalcValue( aFormula, aStr, _pToken->IsInForceArray()))
                         m_pWndResult->SetText( aStr );
                     aStr = m_pWndResult->GetText();
                     pStructPage->GetTlbStruct()->SetEntryText( pEntry, aResult + " = " + aStr);
@@ -712,17 +715,48 @@ void FormulaDlg_Impl::MakeTree( StructPage* _pTree, SvTreeListEntry* pParent, co
                 else if (eOp == ocPush)
                 {
                     // Interpret range reference in matrix context to resolve
-                    // as array elements.
-                    /* TODO: this should depend on parameter classification, if
-                     * a scalar value is expected matrix should not be forced.
-                     * */
-                    (void)pFuncToken;
+                    // as array elements. Depending on parameter classification
+                    // a scalar value (non-array context) is calculated first.
+                    OUString aUnforcedResult;
                     bool bForceMatrix = (!m_pBtnMatrix->IsChecked() &&
                             (_pToken->GetType() == svDoubleRef || _pToken->GetType() == svExternalDoubleRef));
+                    if (bForceMatrix && pFuncToken)
+                    {
+                        formula::ParamClass eParamClass = ParamClass::Reference;
+                        if (pFuncToken->IsInForceArray())
+                            eParamClass = ParamClass::ForceArray;
+                        else
+                        {
+                            std::shared_ptr<FormulaCompiler> pCompiler = m_pHelper->getCompiler();
+                            if (pCompiler)
+                                eParamClass = pCompiler->GetForceArrayParameter( pFuncToken, Count - 1);
+                        }
+                        switch (eParamClass)
+                        {
+                            case ParamClass::Unknown:
+                            case ParamClass::Bounds:
+                            case ParamClass::Value:
+                                if (CalcValue( "=" + aResult, aUnforcedResult, false) && aUnforcedResult != aResult)
+                                    aUnforcedResult += "  ";
+                                else
+                                    aUnforcedResult.clear();
+                            break;
+                            case ParamClass::Reference:
+                            case ParamClass::Array:
+                            case ParamClass::ForceArray:
+                            case ParamClass::ReferenceOrForceArray:
+                                ;   // nothing, only as array/matrix
+                            // no default to get compiler warning
+                        }
+                    }
                     OUString aCellResult;
                     if (CalcValue( "=" + aResult, aCellResult, bForceMatrix) && aCellResult != aResult)
+                    {
                         // Cell is a formula, print subformula.
-                        _pTree->InsertEntry( aResult + " = " + aCellResult, pParent, STRUCT_END, 0, _pToken);
+                        // With scalar values prints "A1:A3 = 2 {1;2;3}"
+                        _pTree->InsertEntry( aResult + " = " + aUnforcedResult + aCellResult,
+                                pParent, STRUCT_END, 0, _pToken);
+                    }
                     else
                         _pTree->InsertEntry( aResult, pParent, STRUCT_END, 0, _pToken);
                 }
commit 1772e5c6ecde26963f2af64680096605a7fa8545
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Jul 11 18:23:36 2017 +0200

    Revert "loplugin:casttovoid"
    
    This reverts commit ff10bc47abe0b04480c9fb5db025afbb5e402b4b.
    
        commit ff10bc47abe0b04480c9fb5db025afbb5e402b4b
        Date:   Tue Jul 11 10:24:51 2017 +0200
    
            loplugin:casttovoid
    
            ...as introduced with f6574be0e375e215e6f21830b9e09d77d01b5097
            "FormulaDlg_Impl::MakeTree: pass down current function/operator token: In
            preparation of better argument evaluation."
    
    That (void)pFuncToken was there to not break the build with unused parameter..
    and all work in progress.
    
    Commit actually using pFuncToken follows immediately, I'm just too lazy
    to resolve the merge conflict for an already ready patch.
    
    Change-Id: I572c3087a1cca9efa217e1e1818192d251e3345d

diff --git a/formula/source/ui/dlg/formula.cxx b/formula/source/ui/dlg/formula.cxx
index 9e66f7e663fb..bf24fcd1342d 100644
--- a/formula/source/ui/dlg/formula.cxx
+++ b/formula/source/ui/dlg/formula.cxx
@@ -622,7 +622,7 @@ bool FormulaDlg_Impl::CalcStruct( const OUString& rStrExp, bool bForceRecalcStru
 }
 
 
-void FormulaDlg_Impl::MakeTree( StructPage* _pTree, SvTreeListEntry* pParent, const FormulaToken* /*pFuncToken*/,
+void FormulaDlg_Impl::MakeTree( StructPage* _pTree, SvTreeListEntry* pParent, const FormulaToken* pFuncToken,
         const FormulaToken* _pToken, long Count )
 {
     if ( _pToken != nullptr && Count > 0 )
@@ -716,6 +716,7 @@ void FormulaDlg_Impl::MakeTree( StructPage* _pTree, SvTreeListEntry* pParent, co
                     /* TODO: this should depend on parameter classification, if
                      * a scalar value is expected matrix should not be forced.
                      * */
+                    (void)pFuncToken;
                     bool bForceMatrix = (!m_pBtnMatrix->IsChecked() &&
                             (_pToken->GetType() == svDoubleRef || _pToken->GetType() == svExternalDoubleRef));
                     OUString aCellResult;


More information about the Libreoffice-commits mailing list