[Libreoffice-commits] core.git: 4 commits - formula/source sc/inc sc/qa sc/source
Markus Mohrhard
markus.mohrhard at googlemail.com
Sun Jun 28 22:49:12 PDT 2015
formula/source/core/api/FormulaCompiler.cxx | 1 +
formula/source/ui/dlg/formula.cxx | 11 ++++++++++-
sc/inc/simpleformulacalc.hxx | 3 +++
sc/qa/unit/ucalc.cxx | 16 ++++++++++++++++
sc/qa/unit/ucalc.hxx | 2 ++
sc/source/core/data/simpleformulacalc.cxx | 25 ++++++++++++++++++++++---
sc/source/core/inc/interpre.hxx | 1 +
sc/source/core/tool/interpr4.cxx | 5 +++++
8 files changed, 60 insertions(+), 4 deletions(-)
New commits:
commit efc66942f29c0127691d30a9d4f31b684443b672
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Mon Jun 29 07:47:47 2015 +0200
no need to recompile the formula again
Change-Id: I03b72bd6a0b341ec89e0995f7b53287449ce9f61
diff --git a/sc/inc/simpleformulacalc.hxx b/sc/inc/simpleformulacalc.hxx
index 33ad37b..b701468 100644
--- a/sc/inc/simpleformulacalc.hxx
+++ b/sc/inc/simpleformulacalc.hxx
@@ -30,7 +30,6 @@ private:
ScAddress maAddr;
ScDocument* mpDoc;
ScFormulaResult maResult;
- const OUString maFormula;
formula::FormulaGrammar::Grammar maGram;
bool bIsMatrix;
OUString maMatrixFormulaResult;
diff --git a/sc/source/core/data/simpleformulacalc.cxx b/sc/source/core/data/simpleformulacalc.cxx
index 69719ad..5a08e68 100644
--- a/sc/source/core/data/simpleformulacalc.cxx
+++ b/sc/source/core/data/simpleformulacalc.cxx
@@ -20,7 +20,6 @@ ScSimpleFormulaCalculator::ScSimpleFormulaCalculator( ScDocument* pDoc, const Sc
, mbCalculated(false)
, maAddr(rAddr)
, mpDoc(pDoc)
- , maFormula(rFormula)
, maGram(eGram)
, bIsMatrix(false)
{
@@ -48,15 +47,13 @@ void ScSimpleFormulaCalculator::Calculate()
formula::StackVar aIntType = aInt.Interpret();
if ( aIntType == formula::svMatrixCell )
{
- OUStringBuffer aStr;
ScCompiler aComp(mpDoc, maAddr);
aComp.SetGrammar(maGram);
- mpCode.reset(aComp.CompileString(maFormula));
- if(!mpCode->GetCodeError() && mpCode->GetLen())
- aComp.CompileTokenArray();
- aComp.CreateStringFromToken( aStr, aInt.GetResultToken().get(), true );
+ OUStringBuffer aStr;
+ aComp.CreateStringFromToken(aStr, aInt.GetResultToken().get(), false);
+
bIsMatrix = true;
- maMatrixFormulaResult = aStr.toString();
+ maMatrixFormulaResult = aStr.makeStringAndClear();
}
mnFormatType = aInt.GetRetFormatType();
mnFormatIndex = aInt.GetRetFormatIndex();
@@ -69,6 +66,7 @@ bool ScSimpleFormulaCalculator::IsValue()
if (bIsMatrix)
return false;
+
return maResult.IsValue();
}
commit cbbf58761cb18c5167fb4e32164ad0b8d80214ac
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Mon Jun 29 07:45:23 2015 +0200
use a prefix instead of p
Change-Id: I629be0a71861b97e4a0f9ba3d9c8d6ab9ee28b25
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index f729a08..190f522 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -6479,9 +6479,9 @@ void Test::testFormulaWizardSubformula()
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 pFCell( m_pDoc, ScAddress(0,0,0), "" );
- if ( pFCell.GetErrCode() == 0 )
- CPPUNIT_ASSERT_EQUAL( OUString("{1, #DIV/0!, #NAME!}"), pFCell.GetString().getString() );
+ 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->DeleteTab(0);
}
commit ec97496525f82ffaf7eea65eb76462100fa66092
Author: Benjamin Ni <benjaminniri at hotmail.com>
Date: Mon Jun 22 21:54:53 2015 +0100
Subformula evaluation in formula wizard tree
Change-Id: If4f6a608f261621e2e1ba40b36d71d39a137a453
diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index dc24f45..f0ed8c2 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -1862,6 +1862,7 @@ const FormulaToken* FormulaCompiler::CreateStringFromToken( OUStringBuffer& rBuf
CreateStringFromDoubleRef( rBuffer, t);
break;
case svMatrix:
+ case svMatrixCell:
CreateStringFromMatrix( rBuffer, t );
break;
diff --git a/sc/inc/simpleformulacalc.hxx b/sc/inc/simpleformulacalc.hxx
index 4d4e962..33ad37b 100644
--- a/sc/inc/simpleformulacalc.hxx
+++ b/sc/inc/simpleformulacalc.hxx
@@ -30,6 +30,10 @@ private:
ScAddress maAddr;
ScDocument* mpDoc;
ScFormulaResult maResult;
+ const OUString maFormula;
+ formula::FormulaGrammar::Grammar maGram;
+ bool bIsMatrix;
+ OUString maMatrixFormulaResult;
public:
ScSimpleFormulaCalculator(ScDocument* pDoc, const ScAddress& rAddr,
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index f00e3a0..f729a08 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -17,6 +17,7 @@
#include "scdll.hxx"
#include "formulacell.hxx"
+#include "simpleformulacalc.hxx"
#include "stringutil.hxx"
#include "scmatrix.hxx"
#include "drwlayer.hxx"
@@ -6470,6 +6471,21 @@ void Test::testMixData()
m_pDoc->DeleteTab(0);
}
+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 pFCell( m_pDoc, ScAddress(0,0,0), "" );
+ if ( pFCell.GetErrCode() == 0 )
+ CPPUNIT_ASSERT_EQUAL( OUString("{1, #DIV/0!, #NAME!}"), pFCell.GetString().getString() );
+
+ m_pDoc->DeleteTab(0);
+}
+
void Test::testSetStringAndNote()
{
m_pDoc->InsertTab(0, "Test");
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 6e65771..7403179 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -341,6 +341,7 @@ public:
void testSharedFormulaUnshareAreaListeners();
void testSharedFormulaListenerDeleteArea();
void testFormulaPosition();
+ void testFormulaWizardSubformula();
void testMixData();
@@ -593,6 +594,7 @@ public:
CPPUNIT_TEST(testSharedFormulaUnshareAreaListeners);
CPPUNIT_TEST(testSharedFormulaListenerDeleteArea);
CPPUNIT_TEST(testFormulaPosition);
+ CPPUNIT_TEST(testFormulaWizardSubformula);
CPPUNIT_TEST(testMixData);
CPPUNIT_TEST(testJumpToPrecedentsDependents);
CPPUNIT_TEST(testSetBackgroundColor);
diff --git a/sc/source/core/data/simpleformulacalc.cxx b/sc/source/core/data/simpleformulacalc.cxx
index c17313d..69719ad 100644
--- a/sc/source/core/data/simpleformulacalc.cxx
+++ b/sc/source/core/data/simpleformulacalc.cxx
@@ -20,9 +20,12 @@ ScSimpleFormulaCalculator::ScSimpleFormulaCalculator( ScDocument* pDoc, const Sc
, mbCalculated(false)
, maAddr(rAddr)
, mpDoc(pDoc)
+ , maFormula(rFormula)
+ , maGram(eGram)
+ , bIsMatrix(false)
{
// compile already here
- ScCompiler aComp(pDoc, rAddr);
+ ScCompiler aComp(mpDoc, maAddr);
aComp.SetGrammar(eGram);
mpCode.reset(aComp.CompileString(rFormula));
if(!mpCode->GetCodeError() && mpCode->GetLen())
@@ -40,8 +43,21 @@ void ScSimpleFormulaCalculator::Calculate()
mbCalculated = true;
ScInterpreter aInt(NULL, mpDoc, maAddr, *mpCode.get());
- aInt.Interpret();
-
+ aInt.AssertFormulaMatrix();
+
+ formula::StackVar aIntType = aInt.Interpret();
+ if ( aIntType == formula::svMatrixCell )
+ {
+ OUStringBuffer aStr;
+ ScCompiler aComp(mpDoc, maAddr);
+ aComp.SetGrammar(maGram);
+ mpCode.reset(aComp.CompileString(maFormula));
+ if(!mpCode->GetCodeError() && mpCode->GetLen())
+ aComp.CompileTokenArray();
+ aComp.CreateStringFromToken( aStr, aInt.GetResultToken().get(), true );
+ bIsMatrix = true;
+ maMatrixFormulaResult = aStr.toString();
+ }
mnFormatType = aInt.GetRetFormatType();
mnFormatIndex = aInt.GetRetFormatIndex();
maResult.SetToken(aInt.GetResultToken().get());
@@ -51,6 +67,8 @@ bool ScSimpleFormulaCalculator::IsValue()
{
Calculate();
+ if (bIsMatrix)
+ return false;
return maResult.IsValue();
}
@@ -79,6 +97,9 @@ svl::SharedString ScSimpleFormulaCalculator::GetString()
{
Calculate();
+ if (bIsMatrix)
+ return maMatrixFormulaResult;
+
if ((!mpCode->GetCodeError() || mpCode->GetCodeError() == errDoubleRef) &&
!maResult.GetResultError())
return maResult.GetString();
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index aea7c5f..df87bda 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -890,6 +890,7 @@ public:
void SetError(sal_uInt16 nError)
{ if (nError && !nGlobalError) nGlobalError = nError; }
+ void AssertFormulaMatrix();
sal_uInt16 GetError() const { return nGlobalError; }
formula::StackVar GetResultType() const { return xResult->GetType(); }
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 793b752..e9612a5 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -4540,6 +4540,11 @@ StackVar ScInterpreter::Interpret()
return eType;
}
+void ScInterpreter::AssertFormulaMatrix()
+{
+ bMatrixFormula = true;
+}
+
svl::SharedString ScInterpreter::GetStringResult() const
{
return xResult->GetString();
commit 55ac455f2a06ef45edcd8a8a151f5ff9e39f22c5
Author: Benjamin Ni <benjaminniri at hotmail.com>
Date: Fri Jun 12 18:09:20 2015 +0100
Subformula check in formula wizard
Change-Id: I843b6886925f389ee1f351d73c6692ff3ceb3b9f
diff --git a/formula/source/ui/dlg/formula.cxx b/formula/source/ui/dlg/formula.cxx
index 7fcb6bd..4827f9d 100644
--- a/formula/source/ui/dlg/formula.cxx
+++ b/formula/source/ui/dlg/formula.cxx
@@ -597,7 +597,6 @@ bool FormulaDlg_Impl::CalcValue( const OUString& rStrExp, OUString& rStrResult )
void FormulaDlg_Impl::UpdateValues()
{
OUString aStrResult;
-
if ( CalcValue( pFuncDesc->getFormula( m_aArguments ), aStrResult ) )
m_pWndResult->SetText( aStrResult );
@@ -706,6 +705,16 @@ void FormulaDlg_Impl::MakeTree(IStructHelper* _pTree,SvTreeListEntry* pParent,Fo
{
_pTree->InsertEntry(aResult,pParent,STRUCT_ERROR,0,_pToken);
}
+ else if (eOp==ocPush)
+ {
+ OUString aCellResult;
+ OUString aEquals(" = ");
+ 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);
+ }
else
{
_pTree->InsertEntry(aResult,pParent,STRUCT_END,0,_pToken);
More information about the Libreoffice-commits
mailing list