Kaydet (Commit) ec974965 authored tarafından Benjamin Ni's avatar Benjamin Ni Kaydeden (comit) Markus Mohrhard

Subformula evaluation in formula wizard tree

Change-Id: If4f6a608f261621e2e1ba40b36d71d39a137a453
üst 55ac455f
......@@ -1862,6 +1862,7 @@ const FormulaToken* FormulaCompiler::CreateStringFromToken( OUStringBuffer& rBuf
CreateStringFromDoubleRef( rBuffer, t);
break;
case svMatrix:
case svMatrixCell:
CreateStringFromMatrix( rBuffer, t );
break;
......
......@@ -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,
......
......@@ -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");
......
......@@ -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);
......
......@@ -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();
......
......@@ -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(); }
......
......@@ -4540,6 +4540,11 @@ StackVar ScInterpreter::Interpret()
return eType;
}
void ScInterpreter::AssertFormulaMatrix()
{
bMatrixFormula = true;
}
svl::SharedString ScInterpreter::GetStringResult() const
{
return xResult->GetString();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment