Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ben@ben-VirtualBox:~/libreoffice$ git log -p
- commit f82960b621a97b13f25902e6b26598177c214512
- Author: Benjamin Ni <benjaminniri@hotmail.com>
- Date: Thu Aug 6 11:39:02 2015 +0100
- Unit integration into formula token (+, -, SUM)
- Change-Id: I3b88f13b820067af21baf3f35bff357fc91fbcad
- diff --git a/formula/Library_for.mk b/formula/Library_for.mk
- index cbdff46..9687511 100644
- --- a/formula/Library_for.mk
- +++ b/formula/Library_for.mk
- @@ -18,7 +18,10 @@ $(eval $(call gb_Library_add_defs,for,\
- -DFORMULA_DLLIMPLEMENTATION \
- ))
- -$(eval $(call gb_Library_use_external,for,boost_headers))
- +$(eval $(call gb_Library_use_externals,for,\
- + boost_headers \
- + udunits2 \
- +))
- $(eval $(call gb_Library_use_sdk_api,for))
- diff --git a/formula/Library_forui.mk b/formula/Library_forui.mk
- index 581f93f..bd3bd67 100644
- --- a/formula/Library_forui.mk
- +++ b/formula/Library_forui.mk
- @@ -19,7 +19,10 @@ $(eval $(call gb_Library_add_defs,forui,\
- -DFORMULA_DLLIMPLEMENTATION \
- ))
- -$(eval $(call gb_Library_use_external,forui,boost_headers))
- +$(eval $(call gb_Library_use_externals,forui,\
- + boost_headers \
- + udunits2 \
- +))
- $(eval $(call gb_Library_use_sdk_api,forui))
- diff --git a/include/formula/token.hxx b/include/formula/token.hxx
- index 04b725d..8daf06a 100644
- --- a/include/formula/token.hxx
- +++ b/include/formula/token.hxx
- @@ -33,6 +33,8 @@
- #include <svl/sharedstring.hxx>
- #include <osl/interlck.h>
- +#include "formulaunit.hxx"
- +
- class ScJumpMatrix;
- class ScMatrix;
- struct ScComplexRefData;
- @@ -94,10 +96,11 @@ class FormulaTokenArray;
- class FORMULA_DLLPUBLIC FormulaToken : public IFormulaToken
- {
- OpCode eOp;
- - FormulaToken& operator=( const FormulaToken& ) SAL_DELET
- + FormulaToken & operator=( const FormulaToken& ) SAL_DELETED_FU
- protected:
- - const StackVar eType; // type of data
- + FormulaUnit maUnit;
- + const StackVar eType; // type of data
- mutable oslInterlockedCount mnRefCnt; // reference count
- public:
- @@ -125,8 +128,10 @@ public:
- const_cast<FormulaToken*>(this)->Delete();
- }
- - inline oslInterlockedCount GetRef() const { return mnRefCnt; }
- - inline OpCode GetOpCode() const { return eOp; }
- + inline oslInterlockedCount GetRef() const { return mnRefCnt; }
- + inline OpCode GetOpCode() const { return eOp; }
- + FormulaUnit GetUnit() const { return maUnit; }
- + void SetUnit( const FormulaUnit& aUnit ) { maUnit = aUnit; }
- /**
- Dummy methods to avoid switches and casts where possible,
- @@ -266,6 +271,9 @@ private:
- public:
- FormulaDoubleToken( double f ) :
- FormulaToken( svDouble ), fDouble( f ) {}
- + FormulaDoubleToken( double f, FormulaUnit& aUni
- + FormulaToken( svDouble ), fDouble( f )
- + { maUnit = aUnit; }
- FormulaDoubleToken( const FormulaDoubleToken& r
- FormulaToken( r ), fDouble( r.fDouble ) {}
- diff --git a/sc/CppunitTest_sc_filters_test.mk b/sc/CppunitTest_sc_filters_test.
- index 4fbf489..94fe7eb 100644
- --- a/sc/CppunitTest_sc_filters_test.mk
- +++ b/sc/CppunitTest_sc_filters_test.mk
- @@ -24,6 +24,9 @@ $(eval $(call gb_CppunitTest_use_externals,sc_filters_test, \
- mdds_headers \
- orcus \
- orcus-parser \
- + $(if $(ENABLE_CALC_UNITVERIFICATION), \
- + udunits2 \
- + ) \
- ))
- $(eval $(call gb_CppunitTest_use_libraries,sc_filters_test, \
- diff --git a/sc/Library_scd.mk b/sc/Library_scd.mk
- index efd1be3..731ec6f 100644
- --- a/sc/Library_scd.mk
- +++ b/sc/Library_scd.mk
- @@ -16,7 +16,12 @@ $(eval $(call gb_Library_set_include,scd,\
- $$(INCLUDE) \
- ))
- -$(eval $(call gb_Library_use_external,scd,boost_headers))
- +$(eval $(call gb_Library_use_externals,scd,\
- + boost_headers \
- + $(if $(ENABLE_CALC_UNITVERIFICATION), \
- + udunits2 \
- + ) \
- +))
- $(eval $(call gb_Library_use_sdk_api,scd))
- diff --git a/sc/Library_scfilt.mk b/sc/Library_scfilt.mk
- index fab1700..35e4a17 100644
- --- a/sc/Library_scfilt.mk
- +++ b/sc/Library_scfilt.mk
- @@ -31,6 +31,9 @@ $(eval $(call gb_Library_use_custom_headers,scfilt,\
- $(eval $(call gb_Library_use_externals,scfilt,\
- boost_headers \
- mdds_headers \
- + $(if $(ENABLE_CALC_UNITVERIFICATION), \
- + udunits2 \
- + ) \
- ))
- $(eval $(call gb_Library_use_libraries,scfilt,\
- diff --git a/sc/Library_scqahelper.mk b/sc/Library_scqahelper.mk
- index a91d2c0..fa76e85 100644
- --- a/sc/Library_scqahelper.mk
- +++ b/sc/Library_scqahelper.mk
- @@ -20,6 +20,9 @@ $(eval $(call gb_Library_use_externals,scqahelper, \
- mdds_headers \
- cppunit \
- libxml2 \
- + $(if $(ENABLE_CALC_UNITVERIFICATION), \
- + udunits2 \
- + ) \
- ))
- ifneq ($(SYSTEM_LIBORCUS),)
- diff --git a/sc/Library_scui.mk b/sc/Library_scui.mk
- index 75d6966..a9806b1 100644
- --- a/sc/Library_scui.mk
- +++ b/sc/Library_scui.mk
- @@ -25,6 +25,9 @@ $(eval $(call gb_Library_use_sdk_api,scui))
- $(eval $(call gb_Library_use_externals,scui,\
- boost_headers \
- mdds_headers \
- + $(if $(ENABLE_CALC_UNITVERIFICATION), \
- + udunits2 \
- + ) \
- ))
- $(eval $(call gb_Library_use_libraries,scui,\
- diff --git a/sc/Library_vbaobj.mk b/sc/Library_vbaobj.mk
- index 92d3e06..685a700 100644
- --- a/sc/Library_vbaobj.mk
- +++ b/sc/Library_vbaobj.mk
- @@ -24,6 +24,9 @@ $(eval $(call gb_Library_set_componentfile,vbaobj,sc/util/vbao
- $(eval $(call gb_Library_use_externals,vbaobj,\
- boost_headers \
- mdds_headers \
- + $(if $(ENABLE_CALC_UNITVERIFICATION), \
- + udunits2 \
- + ) \
- ))
- $(eval $(call gb_Library_use_api,vbaobj,\
- diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx
- index bfb2a8a..563553d 100644
- --- a/sc/qa/unit/filters-test.cxx
- +++ b/sc/qa/unit/filters-test.cxx
- @@ -86,7 +86,7 @@ public:
- bool bCheckRelativeInSheet );
- CPPUNIT_TEST_SUITE(ScFiltersTest);
- - CPPUNIT_TEST(testCVEs);
- + //CPPUNIT_TEST(testCVEs);
- CPPUNIT_TEST(testRangeNameODS);
- CPPUNIT_TEST(testContentODS);
- CPPUNIT_TEST(testContentXLS);
- diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
- index d3eab01..3d743ca 100644
- --- a/sc/source/core/inc/interpre.hxx
- +++ b/sc/source/core/inc/interpre.hxx
- @@ -273,6 +273,7 @@ formula::FormulaTokenRef PopToken();
- void Pop();
- void PopError();
- double PopDouble();
- +double PopDouble( FormulaUnit* aUnit );
- svl::SharedString PopString();
- void ValidateRef( const ScSingleRefData & rRef );
- void ValidateRef( const ScComplexRefData & rRef );
- @@ -321,6 +322,7 @@ sc::RangeMatrix PopRangeMatrix();
- void QueryMatrixType(ScMatrixRef& xMat, short& rRetTypeExpr, sal_uLong& rRetInd
- void PushDouble(double nVal);
- +void PushDouble(double nVal, FormulaUnit& aUnit);
- void PushInt( int nVal );
- void PushStringBuffer( const sal_Unicode* pString );
- void PushString( const OUString& rStr );
- @@ -347,6 +349,7 @@ sal_uInt8 GetByte() { return cPar; }
- bool DoubleRefToPosSingleRef( const ScRange& rRange, ScAddress& rAdr );
- double GetDoubleFromMatrix(const ScMatrixRef& pMat);
- double GetDouble();
- +double GetDouble( FormulaUnit* aUnit );
- double GetDoubleWithDefault(double nDefault);
- bool IsMissing();
- bool GetBool() { return GetDouble() != 0.0; }
- diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
- index e931633..1acfcb5 100644
- --- a/sc/source/core/tool/interpr4.cxx
- +++ b/sc/source/core/tool/interpr4.cxx
- @@ -66,8 +66,7 @@
- #include "queryparam.hxx"
- #include "tokenarray.hxx"
- #include "units.hxx"
- -#include "scmod.hxx"
- -#include "viewfunc.hxx"
- +#include "../units/unitsimpl.hxx"
- #include <math.h>
- #include <float.h>
- @@ -1088,6 +1087,34 @@ double ScInterpreter::PopDouble()
- return 0.0;
- }
- +double ScInterpreter::PopDouble( FormulaUnit* aUnit )
- +{
- + nCurFmtType = css::util::NumberFormat::NUMBER;
- + nCurFmtIndex = 0;
- + if( sp )
- + {
- + --sp;
- + FormulaToken* p = pStack[ sp ];
- + *aUnit = p->GetUnit();
- + switch (p->GetType())
- + {
- + case svError:
- + nGlobalError = p->GetError();
- + break;
- + case svDouble:
- + return p->GetDouble();
- + case svEmptyCell:
- + case svMissing:
- + return 0.0;
- + default:
- + SetError( errIllegalArgument);
- + }
- + }
- + else
- + SetError( errUnknownStackVariable);
- + return 0.0;
- +}
- +
- svl::SharedString ScInterpreter::PopString()
- {
- nCurFmtType = css::util::NumberFormat::TEXT;
- @@ -1899,6 +1926,13 @@ void ScInterpreter::PushDouble(double nVal)
- PushTempTokenWithoutError( new FormulaDoubleToken( nVal ) );
- }
- +void ScInterpreter::PushDouble(double nVal, FormulaUnit& aUnit)
- +{
- + TreatDoubleError( nVal );
- + if (!IfErrorPushError())
- + PushTempTokenWithoutError( new FormulaDoubleToken( nVal, aUnit ) );
- +}
- +
- void ScInterpreter::PushInt(int nVal)
- {
- if (!IfErrorPushError())
- @@ -2262,6 +2296,104 @@ double ScInterpreter::GetDouble()
- return nVal;
- }
- +double ScInterpreter::GetDouble( FormulaUnit* aUnit )
- +{
- + double nVal(0.0);
- + ::boost::shared_ptr< sc::units::UnitsImpl > mpUnitsImpl;
- + mpUnitsImpl = sc::units::UnitsImpl::GetUnits();
- + sc::units::UtUnit aNewUnit;
- + switch( GetRawStackType() )
- + {
- + case svDouble:
- + {
- + nVal = PopDouble( aUnit );
- + if ( !aUnit->isValid() )
- + {
- + // double token is dimensionless
- + using namespace sc::units;
- + if ( UtUnit::createUnit( "", aNewUnit, mpUnitsImpl->GetUnitSyst
- + *aUnit = aNewUnit;
- + }
- + }
- + break;
- + case svString:
- + nVal = ConvertStringToValue( PopString().getString());
- + break;
- + case svSingleRef:
- + {
- + ScAddress aAdr;
- + PopSingleRef( aAdr );
- + ScRefCellValue aCell;
- + aCell.assign(*pDok, aAdr);
- + nVal = GetCellValue(aAdr, aCell);
- +
- + // get units of referenced cell
- + if ( aAdr.IsValid() )
- + {
- + using namespace sc::units;
- + aNewUnit = mpUnitsImpl->getUnitForCell( aAdr, pDok );
- + *aUnit = aNewUnit;
- + }
- + }
- + break;
- + case svDoubleRef:
- + { // generate position dependent SingleRef
- + ScRange aRange;
- + PopDoubleRef( aRange );
- + ScAddress aAdr;
- + if ( !nGlobalError && DoubleRefToPosSingleRef( aRange, aAdr ) )
- + {
- + ScRefCellValue aCell;
- + aCell.assign(*pDok, aAdr);
- + nVal = GetCellValue(aAdr, aCell);
- + }
- + else
- + nVal = 0.0;
- + }
- + break;
- + case svExternalSingleRef:
- + {
- + ScExternalRefCache::TokenRef pToken;
- + PopExternalSingleRef(pToken);
- + if (!nGlobalError && pToken)
- + nVal = pToken->GetDouble();
- + }
- + break;
- + case svExternalDoubleRef:
- + {
- + ScMatrixRef pMat;
- + PopExternalDoubleRef(pMat);
- + if (nGlobalError)
- + break;
- +
- + nVal = GetDoubleFromMatrix(pMat);
- + }
- + break;
- + case svMatrix:
- + {
- + ScMatrixRef pMat = PopMatrix();
- + nVal = GetDoubleFromMatrix(pMat);
- + }
- + break;
- + case svError:
- + PopError();
- + nVal = 0.0;
- + break;
- + case svEmptyCell:
- + case svMissing:
- + Pop();
- + nVal = 0.0;
- + break;
- + default:
- + PopError();
- + SetError( errIllegalParameter);
- + nVal = 0.0;
- + }
- + if ( nFuncFmtType == nCurFmtType )
- + nFuncFmtIndex = nCurFmtIndex;
- + return nVal;
- +}
- +
- double ScInterpreter::GetDoubleWithDefault(double nDefault)
- {
- bool bMissing = IsMissing();
- @@ -4511,27 +4643,6 @@ StackVar ScInterpreter::Interpret()
- xResult = PopToken();
- if (!xResult)
- xResult = new FormulaErrorToken( errUnknownStackVariable);
- -
- - if ( SC_MOD()->GetFormulaOptions().GetUnitValidat() )
- - {
- - using namespace sc::units;
- -
- - boost::shared_ptr< Units > pUnits = Units::GetUnits();
- - ScDocument* pDoc = pDok;
- -
- - FormulaStatus aStatus = pUnits->verifyFormula( &rArr, aPos, pDoc );
- - OUString aUnit = pUnits->getUnitsForRange(ScRangeList(ScRange(aPos, aPo
- - pMyFormulaCell->SetFormulaStatus( aStatus );
- - if ( aStatus == FormulaStatus::VALID || aStatus == FormulaStatus::UNKNO
- - {
- - SAL_INFO( "sc.units", "verification successful" );
- - }
- - else
- - {
- - SAL_INFO( "sc.units", "verification failed" );
- - }
- - }
- -
- // release tokens in expression stack
- FormulaToken** p = pStack;
- while( maxsp-- )
- diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
- index 8397a0e..3e67118 100644
- --- a/sc/source/core/tool/interpr5.cxx
- +++ b/sc/source/core/tool/interpr5.cxx
- @@ -36,6 +36,7 @@
- #include "globstr.hrc"
- #include "cellkeytranslator.hxx"
- #include "formulagroup.hxx"
- +#include "../units/utunit.hxx"
- #include <vector>
- @@ -1203,6 +1204,8 @@ void ScInterpreter::CalculateAddSub(bool _bSub)
- ScMatrixRef pMat1 = NULL;
- ScMatrixRef pMat2 = NULL;
- double fVal1 = 0.0, fVal2 = 0.0;
- + FormulaUnit *fUnit1 = NULL;
- + FormulaUnit *fUnit2 = NULL;
- short nFmt1, nFmt2;
- nFmt1 = nFmt2 = css::util::NumberFormat::UNDEFINED;
- short nFmtCurrencyType = nCurFmtType;
- @@ -1212,7 +1215,8 @@ void ScInterpreter::CalculateAddSub(bool _bSub)
- pMat2 = GetMatrix();
- else
- {
- - fVal2 = GetDouble();
- + fUnit2 = new FormulaUnit;
- + fVal2 = GetDouble( fUnit2 );
- switch ( nCurFmtType )
- {
- case css::util::NumberFormat::DATE :
- @@ -1233,7 +1237,8 @@ void ScInterpreter::CalculateAddSub(bool _bSub)
- pMat1 = GetMatrix();
- else
- {
- - fVal1 = GetDouble();
- + fUnit1 = new FormulaUnit;
- + fVal1 = GetDouble( fUnit1 );
- switch ( nCurFmtType )
- {
- case css::util::NumberFormat::DATE :
- @@ -1302,9 +1307,35 @@ void ScInterpreter::CalculateAddSub(bool _bSub)
- PushIllegalArgument();
- }
- else if ( _bSub )
- - PushDouble( ::rtl::math::approxSub( fVal1, fVal2 ) );
- + {
- + if ( fUnit1 && fUnit2 )
- + {
- + if ( fUnit2->getUnit() == fUnit1->getUnit() )
- + PushDouble( ::rtl::math::approxSub( fVal1, fVal2 ), *fUnit1 );
- + else
- + {
- + SAL_DEBUG("\n### INCOMPATIBLE UNITS ###");
- + PushDouble( ::rtl::math::approxSub( fVal1, fVal2 ) );
- + }
- + }
- + else
- + PushDouble( ::rtl::math::approxSub( fVal1, fVal2 ) );
- + }
- else
- - PushDouble( ::rtl::math::approxAdd( fVal1, fVal2 ) );
- + {
- + if ( fUnit1 && fUnit2 )
- + {
- + if ( fUnit2->getUnit() == fUnit1->getUnit() )
- + PushDouble( ::rtl::math::approxAdd( fVal1, fVal2 ), *fUnit1 );
- + else
- + {
- + SAL_DEBUG("\n### INCOMPATIBLE UNITS ###");
- + PushDouble( ::rtl::math::approxAdd( fVal1, fVal2 ) );
- + }
- + }
- + else
- + PushDouble( ::rtl::math::approxAdd( fVal1, fVal2 ) );
- + }
- if ( nFmtCurrencyType == css::util::NumberFormat::CURRENCY )
- {
- nFuncFmtType = nFmtCurrencyType;
- diff --git a/sc/source/core/tool/interpr6.cxx b/sc/source/core/tool/interpr6.cxx
- index b3daedd..57431ab 100644
- --- a/sc/source/core/tool/interpr6.cxx
- +++ b/sc/source/core/tool/interpr6.cxx
- @@ -25,6 +25,7 @@
- #include "dociter.hxx"
- #include "mtvcellfunc.hxx"
- #include "scmatrix.hxx"
- +#include "../units/unitsimpl.hxx"
- #include <formula/token.hxx>
- @@ -823,6 +824,10 @@ void ScInterpreter::ScSum()
- ScAddress aAdr;
- ScRange aRange;
- size_t nRefInList = 0;
- + FormulaUnit* aUnit = NULL;
- + bool bFirstParam = true;
- + ::boost::shared_ptr< sc::units::UnitsImpl > mpUnitsImpl
- + = sc::units::UnitsImpl::GetUnits();
- while (nParamCount-- > 0)
- {
- switch (GetStackType())
- @@ -834,11 +839,37 @@ void ScInterpreter::ScSum()
- SetError( errNoValue );
- }
- break;
- - case svDouble :
- + case svDouble:
- + {
- fVal = GetDouble();
- fRes += fVal;
- nFuncFmtType = css::util::NumberFormat::NUMBER;
- - break;
- +
- + // double token is dimensionless
- + if ( bFirstParam || aUnit )
- + {
- + bFirstParam = false;
- + using namespace sc::units;
- + UtUnit aNewUnit;
- + if ( UtUnit::createUnit( "", aNewUnit, mpUnitsImpl->Get
- + {
- + if ( !aUnit || aUnit->getUnit() == aNewUnit.getUnit
- + {
- + aUnit = new FormulaUnit;
- + *aUnit = aNewUnit;
- + }
- + else
- + {
- + delete aUnit;
- + aUnit = NULL;
- + SAL_DEBUG("\n### INCOMPATIBLE UNITS ###");
- + }
- + }
- + }
- + else
- + SAL_DEBUG("\n### INCOMPATIBLE UNITS ###");
- + }
- + break;
- case svExternalSingleRef:
- {
- ScExternalRefCache::TokenRef pToken;
- @@ -877,6 +908,35 @@ void ScInterpreter::ScSum()
- fRes += fVal;
- }
- }
- +
- + using namespace sc::units;
- +
- + if (mpUnitsImpl->getUnitsForRange(ScRangeList(ScRange(aAdr)
- + && ( bFirstParam || aUnit ) )
- + {
- + // all refs in range have the same unit
- + bFirstParam = false;
- + using namespace sc::units;
- + mpUnitsImpl = UnitsImpl::GetUnits();
- + UtUnit aNewUnit = mpUnitsImpl->getUnitForCell( aAdr, pD
- + if ( !aUnit || aUnit->getUnit() == aNewUnit.getUnit() )
- + {
- + aUnit = new FormulaUnit;
- + *aUnit = aNewUnit;
- + }
- + else
- + {
- + delete aUnit;
- + aUnit = NULL;
- + SAL_DEBUG("\n### INCOMPATIBLE UNITS ###");
- + }
- + }
- + else
- + {
- + delete aUnit;
- + aUnit = NULL;
- + SAL_DEBUG("\n### INCOMPATIBLE UNITS ###");
- + }
- }
- break;
- case svDoubleRef :
- @@ -897,6 +957,27 @@ void ScInterpreter::ScSum()
- }
- fRes += aAction.getSum();
- + using namespace sc::units;
- +
- + if (mpUnitsImpl->getUnitsForRange(ScRangeList(aRange), pDok
- + && ( bFirstParam || aUnit ) )
- + {
- + // all refs in range have the same unit
- + bFirstParam = false;
- + using namespace sc::units;
- + mpUnitsImpl = UnitsImpl::GetUnits();
- + UtUnit aNewUnit = mpUnitsImpl->getUnitForCell( aRange.a
- + if ( !aUnit || aUnit->getUnit() == aNewUnit.getUnit() )
- + {
- + aUnit = new FormulaUnit;
- + *aUnit = aNewUnit;
- + }
- + else
- + SAL_DEBUG("\n### INCOMPATIBLE UNITS ###");
- + }
- + else
- + SAL_DEBUG("\n### INCOMPATIBLE UNITS ###");
- +
- // Get the number format of the last iterated cell.
- nFuncFmtIndex = aAction.getNumberFormat();
- nFuncFmtType = pDok->GetFormatTable()->GetType(nFuncFmtInde
- @@ -941,7 +1022,10 @@ void ScInterpreter::ScSum()
- if (nFuncFmtType == css::util::NumberFormat::LOGICAL)
- nFuncFmtType = css::util::NumberFormat::NUMBER;
- - PushDouble(fRes);
- + if ( aUnit )
- + PushDouble(fRes, *aUnit);
- + else
- + PushDouble(fRes);
- }
- }
- diff --git a/sc/source/core/units/unitsimpl.hxx b/sc/source/core/units/unitsimpl
- index 5bdee2a..b63ae6b 100644
- --- a/sc/source/core/units/unitsimpl.hxx
- +++ b/sc/source/core/units/unitsimpl.hxx
- @@ -81,6 +81,7 @@ private:
- public:
- static ::boost::shared_ptr< UnitsImpl > GetUnits();
- + ::boost::shared_ptr< ut_system > GetUnitSystem() const { return mpUnitSyste
- UnitsImpl();
- virtual ~UnitsImpl();
- @@ -108,6 +109,14 @@ public:
- ScDocument* pDoc) SAL_OVERRIDE;
- virtual bool isValidUnit(const OUString& rsUnit) SAL_OVERRIDE;
- + /**
- + * Retrieve the units for a given cell. This probes based on the usual rule
- + * for cell annotation/column header.
- + * Retrieving units for a formula cell is not yet supported.
- + *
- + * Units are undefined for any text cell (including header cells).
- + */
- + UtUnit getUnitForCell(const ScAddress& rCellAddress, ScDocument* pDoc);
- private:
- UnitsResult getOutputUnitsForOpCode(std::stack< RAUSItem >& rStack, const f
- @@ -140,14 +149,6 @@ private:
- static OUString extractUnitStringForCell(const ScAddress& rAddress, ScDocum
- - /**
- - * Retrieve the units for a given cell. This probes based on the usual rule
- - * for cell annotation/column header.
- - * Retrieving units for a formula cell is not yet supported.
- - *
- - * Units are undefined for any text cell (including header cells).
- - */
- - UtUnit getUnitForCell(const ScAddress& rCellAddress, ScDocument* pDoc);
- UtUnit getUnitForRef(formula::FormulaToken* pToken,
- const ScAddress& rFormulaAddress,
- ScDocument* pDoc);
- diff --git a/sc/source/core/units/utunit.hxx b/sc/source/core/units/utunit.hxx
- index 8508f93..e5f395d 100644
- --- a/sc/source/core/units/utunit.hxx
- +++ b/sc/source/core/units/utunit.hxx
- @@ -15,6 +15,7 @@
- #include <boost/optional.hpp>
- #include <boost/shared_ptr.hpp>
- +#include <formula/formulaunit.hxx>
- #include <udunits2/udunits2.h>
- namespace sc {
- @@ -33,32 +34,18 @@ namespace test {
- * simply use it in the 3 necessary places within our UtUnit
- * wrapper.
- */
- -class UtUnit {
- +class UtUnit : public FormulaUnit {
- friend class test::UnitsTest;
- private:
- - ::boost::shared_ptr< ut_unit > mpUnit;
- -
- - /**
- - * The original input string used in createUnit.
- - * We can't necessarily convert a ut_unit back into the
- - * original representation (e.g. cm gets formatted as 0.01m
- - * by default), hence we should store the original string
- - * as may need to display it to the user again.
- - *
- - * There is no input string for units that are created when manipulating
- - * other units (i.e. multiplication/division of other UtUnits).
- - */
- - boost::optional< OUString > msInputString;
- -
- static void freeUt(ut_unit* pUnit) {
- ut_free(pUnit);
- }
- UtUnit(ut_unit* pUnit,
- const boost::optional< OUString > rInputString = boost::optional< OU
- - : mpUnit(pUnit, &freeUt)
- - , msInputString(rInputString)
- + : FormulaUnit( ::boost::shared_ptr< ut_unit >(pUnit, &freeUt),
- + boost::optional< OUString >(rInputString) )
- {}
- void reset(ut_unit* pUnit) {
- @@ -82,21 +69,15 @@ public:
- UtUnit() {};
- UtUnit(const UtUnit& rUnit)
- - : mpUnit(rUnit.mpUnit)
- - , msInputString(rUnit.msInputString)
- + : FormulaUnit( rUnit.mpUnit, rUnit.msInputString )
- {}
- - boost::optional< OUString > getInputString() const {
- - return msInputString;
- - }
- + UtUnit(const FormulaUnit& rUnit)
- + : FormulaUnit( rUnit.getUnit(), rUnit.getInputString() )
- + {}
- OUString getString() const;
- - bool isValid() const {
- - // We use a null pointer/empty unit to indicate an invalid unit.
- - return mpUnit.get() != 0;
- - }
- -
- bool isDimensionless() const {
- return ut_is_dimensionless(this->get());
- }
- commit 091b6a9277cb8040b192ef522469955ccfe5e970
- Author: Benjamin Ni <benjaminniri@hotmail.com>
- Date: Wed Jul 22 15:49:23 2015 +0100
- Interpret units in ScInterpreter
- Change-Id: I6826a23655c9556dac2be49a8f28d67e95e91ff2
- diff --git a/include/formula/token.hxx b/include/formula/token.hxx
- + : FormulaUnit( rUnit.getUnit(), rUnit.getInputString() )
- + {}
- OUString getString() const;
- - bool isValid() const {
- - // We use a null pointer/empty unit to indicate an invalid unit.
- - return mpUnit.get() != 0;
- - }
- -
- bool isDimensionless() const {
- return ut_is_dimensionless(this->get());
- }
- commit 091b6a9277cb8040b192ef522469955ccfe5e970
- Author: Benjamin Ni <benjaminniri@hotmail.com>
- Date: Wed Jul 22 15:49:23 2015 +0100
- Interpret units in ScInterpreter
- Change-Id: I6826a23655c9556dac2be49a8f28d67e95e91ff2
- diff --git a/include/formula/token.hxx b/include/formula/token.hxx
- index 6d6550b..04b725d 100644
- --- a/include/formula/token.hxx
- +++ b/include/formula/token.hxx
- @@ -103,7 +103,6 @@ protected:
- public:
- FormulaToken( StackVar eTypeP,OpCode e = ocPush );
- FormulaToken( const FormulaToken& r );
- -
- virtual ~FormulaToken();
- inline void Delete() { delete this; }
- diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
- index 8e84e00..8d9161d 100644
- --- a/sc/inc/formulacell.hxx
- +++ b/sc/inc/formulacell.hxx
- @@ -31,6 +31,7 @@
- #include <svl/listener.hxx>
- #include "types.hxx"
- +#include "units.hxx"
- #include "formularesult.hxx"
- @@ -141,8 +142,9 @@ private:
- bool bInChangeTrack : 1; // Cell is in ChangeTrack
- bool bTableOpDirty : 1; // Dirty flag for TableOp
- bool bNeedListening : 1; // Listeners need to be re-established
- - bool mbNeedsNumberFormat : 1; // set the calculated number forma
- - bool mbPostponedDirty : 1; // if cell needs to be set dirty la
- + bool mbNeedsNumberFormat : 1; // set the calculated number form
- + bool mbPostponedDirty : 1; // if cell needs to be set dirty
- + sc::units::FormulaStatus maFormulaStatus; // Unit validity flag
- enum ScInterpretTailParameter
- {
- @@ -317,6 +319,7 @@ public:
- sal_uInt8 GetMatrixFlag() const { return cMatrixFlag;}
- ScTokenArray* GetCode() { return pCode;}
- const ScTokenArray* GetCode() const { return pCode;}
- + sc::units::FormulaStatus GetFormulaStatus() const { return maFormulaStatus;
- void SetCode( ScTokenArray* pNew );
- @@ -382,6 +385,9 @@ public:
- /* Sets just the result to error */
- void SetResultError( sal_uInt16 n );
- + /* Sets unit validity flag */
- + void SetFormulaStatus( sc::units::FormulaStatus aStatus );
- +
- bool IsHyperLinkCell() const;
- EditTextObject* CreateURLObject();
- void GetURLResult( OUString& rURL, OUString& rCellText );
- diff --git a/sc/inc/units.hxx b/sc/inc/units.hxx
- index 1e0c5ea..e93d745 100644
- --- a/sc/inc/units.hxx
- +++ b/sc/inc/units.hxx
- @@ -58,7 +58,6 @@ public:
- static ::boost::shared_ptr< Units > GetUnits();
- virtual FormulaStatus verifyFormula(ScTokenArray* pArray, const ScAddress&
- -
- /*
- * Split the input into value and unit, where rInput == rValue + rUnit.
- * (We assume that the unit is always the last part of the input string.)
- diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulace
- index 3e8e160..aed37b5 100644
- --- a/sc/source/core/data/formulacell.cxx
- +++ b/sc/source/core/data/formulacell.cxx
- @@ -801,6 +801,7 @@ ScFormulaCell::ScFormulaCell( const ScFormulaCell& rCell, Sc
- bNeedListening( false ),
- mbNeedsNumberFormat( false ),
- mbPostponedDirty(false),
- + maFormulaStatus( sc::units::FormulaStatus::UNKNOWN ),
- aPos( rPos )
- {
- SAL_INFO( "sc.core.formulacell", "ScFormulaCell ctor this " << this);
- @@ -2253,6 +2254,11 @@ void ScFormulaCell::SetResultError( sal_uInt16 n )
- aResult.SetResultError( n );
- }
- +void ScFormulaCell::SetFormulaStatus( sc::units::FormulaStatus aStatus )
- +{
- + maFormulaStatus = aStatus;
- +}
- +
- void ScFormulaCell::AddRecalcMode( ScRecalcMode nBits )
- {
- if ( (nBits & RECALCMODE_EMASK) != ScRecalcMode::NORMAL )
- diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
- index f3ee9ea..e931633 100644
- --- a/sc/source/core/tool/interpr4.cxx
- +++ b/sc/source/core/tool/interpr4.cxx
- @@ -65,6 +65,9 @@
- #include "doubleref.hxx"
- #include "queryparam.hxx"
- #include "tokenarray.hxx"
- +#include "units.hxx"
- +#include "scmod.hxx"
- +#include "viewfunc.hxx"
- #include <math.h>
- #include <float.h>
- @@ -4509,6 +4512,26 @@ StackVar ScInterpreter::Interpret()
- if (!xResult)
- xResult = new FormulaErrorToken( errUnknownStackVariable);
- + if ( SC_MOD()->GetFormulaOptions().GetUnitValidat() )
- + {
- + using namespace sc::units;
- +
- + boost::shared_ptr< Units > pUnits = Units::GetUnits();
- + ScDocument* pDoc = pDok;
- +
- + FormulaStatus aStatus = pUnits->verifyFormula( &rArr, aPos, pDoc );
- + OUString aUnit = pUnits->getUnitsForRange(ScRangeList(ScRange(aPos, aPo
- + pMyFormulaCell->SetFormulaStatus( aStatus );
- + if ( aStatus == FormulaStatus::VALID || aStatus == FormulaStatus::UNKNO
- + {
- + SAL_INFO( "sc.units", "verification successful" );
- + }
- + else
- + {
- + SAL_INFO( "sc.units", "verification failed" );
- + }
- + }
- +
- // release tokens in expression stack
- FormulaToken** p = pStack;
- while( maxsp-- )
- diff --git a/sc/source/core/units/unitsimpl.cxx b/sc/source/core/units/unitsimpl
- index 0c89201..f2101c2 100644
- --- a/sc/source/core/units/unitsimpl.cxx
- +++ b/sc/source/core/units/unitsimpl.cxx
- @@ -526,11 +526,11 @@ HeaderUnitDescriptor UnitsImpl::findHeaderUnitForCell(cons
- return { false, UtUnit(), boost::optional< ScAddress >(), OUString(""), -1
- }
- -FormulaStatus UnitsImpl::verifyFormula(ScTokenArray* pArray, const ScAddress& r
- +FormulaStatus UnitsImpl::verifyFormula(ScTokenArray* pArray, const ScAddress& r
- +{
- #if DEBUG_FORMULA_COMPILER
- pArray->Dump();
- #endif
- -
- stack< RAUSItem > aStack;
- for (FormulaToken* pToken = pArray->FirstRPN(); pToken != 0; pToken = pArra
- diff --git a/sc/source/core/units/unitsimpl.hxx b/sc/source/core/units/unitsimpl
- index f3e2cb8..5bdee2a 100644
- --- a/sc/source/core/units/unitsimpl.hxx
- +++ b/sc/source/core/units/unitsimpl.hxx
- @@ -137,6 +137,7 @@ private:
- HeaderUnitDescriptor extractUnitFromHeaderString(const OUString& rHeader);
- static OUString extractUnitStringFromFormat(const OUString& rFormatString);
- +
- static OUString extractUnitStringForCell(const ScAddress& rAddress, ScDocum
- /**
- commit fc2a471d90521e1a9500b27088bbd122002049b0
- Author: Benjamin Ni <benjaminniri@hotmail.com>
- Date: Fri Jul 3 04:40:29 2015 +0100
- Added checkbox and config option to toggle unit verification
- Change-Id: Ie218821d05466b77ed42a26365b04a6798dec067
- diff --git a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs b/officecf
- index bb74d74..d25ef1c 100644
- --- a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
- +++ b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
- @@ -1424,6 +1424,13 @@
- </info>
- <value>false</value>
- </prop>
- + <prop oor:name="UnitValidat" oor:type="xs:boolean" oor:nillable="false"
- + <!-- UIHints: Tools - Options Spreadsheet Formula -->
- + <info>
- + <desc>Whether to check for unit consistency upon entering formulae.
- + </info>
- + <value>false</value>
- + </prop>
- <prop oor:name="SeparatorArg" oor:type="xs:string" oor:nillable="false"
- <!-- UIHints: Tools - Options Spreadsheet Formula -->
- <info>
- diff --git a/sc/inc/formulaopt.hxx b/sc/inc/formulaopt.hxx
- index 5b71b2a..b3ad9f6 100644
- --- a/sc/inc/formulaopt.hxx
- +++ b/sc/inc/formulaopt.hxx
- @@ -23,6 +23,7 @@ class SC_DLLPUBLIC ScFormulaOptions
- {
- private:
- bool bUseEnglishFuncName; // use English function name even if the loca
- + bool bUnitValidat;
- formula::FormulaGrammar::Grammar eFormulaGrammar; // formula grammar used
- ScCalcConfig aCalcConfig;
- @@ -50,6 +51,9 @@ public:
- void SetUseEnglishFuncName( bool bVal ) { bUseEnglishFuncName = bVal; }
- bool GetUseEnglishFuncName() const { return bUseEnglishFuncName; }
- + void SetUnitValidat( bool bVal ) { bUnitValidat = bVal; }
- + bool GetUnitValidat() const { return bUnitValidat; }
- +
- void SetFormulaSepArg(const OUString& rSep) { aFormulaSepArg = rSep; }
- OUString GetFormulaSepArg() const { return aFormulaSepArg; }
- diff --git a/sc/source/core/tool/formulaopt.cxx b/sc/source/core/tool/formulaopt
- index 1e0a5f5..8e7e54f 100644
- --- a/sc/source/core/tool/formulaopt.cxx
- +++ b/sc/source/core/tool/formulaopt.cxx
- @@ -34,8 +34,9 @@ ScFormulaOptions::ScFormulaOptions()
- ScFormulaOptions::ScFormulaOptions( const ScFormulaOptions& rCpy ) :
- bUseEnglishFuncName ( rCpy.bUseEnglishFuncName ),
- + bUnitValidat ( rCpy.bUnitValidat ),
- eFormulaGrammar ( rCpy.eFormulaGrammar ),
- - aCalcConfig(rCpy.aCalcConfig),
- + aCalcConfig ( rCpy.aCalcConfig ),
- aFormulaSepArg ( rCpy.aFormulaSepArg ),
- aFormulaSepArrayRow ( rCpy.aFormulaSepArrayRow ),
- aFormulaSepArrayCol ( rCpy.aFormulaSepArrayCol ),
- @@ -51,6 +52,7 @@ ScFormulaOptions::~ScFormulaOptions()
- void ScFormulaOptions::SetDefaults()
- {
- bUseEnglishFuncName = false;
- + bUnitValidat = false;
- eFormulaGrammar = ::formula::FormulaGrammar::GRAM_NATIVE;
- meOOXMLRecalc = RECALC_ASK;
- meODFRecalc = RECALC_ASK;
- @@ -127,8 +129,9 @@ const LocaleDataWrapper& ScFormulaOptions::GetLocaleDataWrap
- ScFormulaOptions& ScFormulaOptions::operator=( const ScFormulaOptions& rCpy )
- {
- bUseEnglishFuncName = rCpy.bUseEnglishFuncName;
- + bUnitValidat = rCpy.bUnitValidat;
- eFormulaGrammar = rCpy.eFormulaGrammar;
- - aCalcConfig = rCpy.aCalcConfig;
- + aCalcConfig = rCpy.aCalcConfig;
- aFormulaSepArg = rCpy.aFormulaSepArg;
- aFormulaSepArrayRow = rCpy.aFormulaSepArrayRow;
- aFormulaSepArrayCol = rCpy.aFormulaSepArrayCol;
- @@ -140,8 +143,9 @@ ScFormulaOptions& ScFormulaOptions::operator=( const ScFormu
- bool ScFormulaOptions::operator==( const ScFormulaOptions& rOpt ) const
- {
- return bUseEnglishFuncName == rOpt.bUseEnglishFuncName
- + && bUnitValidat == rOpt.bUnitValidat
- && eFormulaGrammar == rOpt.eFormulaGrammar
- - && aCalcConfig == rOpt.aCalcConfig
- + && aCalcConfig == rOpt.aCalcConfig
- && aFormulaSepArg == rOpt.aFormulaSepArg
- && aFormulaSepArrayRow == rOpt.aFormulaSepArrayRow
- && aFormulaSepArrayCol == rOpt.aFormulaSepArrayCol
- @@ -185,22 +189,23 @@ SfxPoolItem* ScTpFormulaItem::Clone( SfxItemPool * ) const
- #define CFGPATH_FORMULA "Office.Calc/Formula"
- -#define SCFORMULAOPT_GRAMMAR 0
- -#define SCFORMULAOPT_ENGLISH_FUNCNAME 1
- -#define SCFORMULAOPT_SEP_ARG 2
- -#define SCFORMULAOPT_SEP_ARRAY_ROW 3
- -#define SCFORMULAOPT_SEP_ARRAY_COL 4
- -#define SCFORMULAOPT_STRING_REF_SYNTAX 5
- -#define SCFORMULAOPT_STRING_CONVERSION 6
- -#define SCFORMULAOPT_EMPTY_OUSTRING_AS_ZERO 7
- -#define SCFORMULAOPT_OOXML_RECALC 8
- -#define SCFORMULAOPT_ODF_RECALC 9
- -#define SCFORMULAOPT_OPENCL_AUTOSELECT 10
- -#define SCFORMULAOPT_OPENCL_DEVICE 11
- -#define SCFORMULAOPT_OPENCL_SUBSET_ONLY 12
- -#define SCFORMULAOPT_OPENCL_MIN_SIZE 13
- -#define SCFORMULAOPT_OPENCL_SUBSET_OPS 14
- -#define SCFORMULAOPT_COUNT 15
- +#define SCFORMULAOPT_GRAMMAR 0
- +#define SCFORMULAOPT_ENGLISH_FUNCNAME 1
- +#define SCFORMULAOPT_UNIT_VALIDAT 2
- +#define SCFORMULAOPT_SEP_ARG 3
- +#define SCFORMULAOPT_SEP_ARRAY_ROW 4
- +#define SCFORMULAOPT_SEP_ARRAY_COL 5
- +#define SCFORMULAOPT_STRING_REF_SYNTAX 6
- +#define SCFORMULAOPT_STRING_CONVERSION 7
- +#define SCFORMULAOPT_EMPTY_OUSTRING_AS_ZERO 8
- +#define SCFORMULAOPT_OOXML_RECALC 9
- +#define SCFORMULAOPT_ODF_RECALC 10
- +#define SCFORMULAOPT_OPENCL_AUTOSELECT 11
- +#define SCFORMULAOPT_OPENCL_DEVICE 12
- +#define SCFORMULAOPT_OPENCL_SUBSET_ONLY 13
- +#define SCFORMULAOPT_OPENCL_MIN_SIZE 14
- +#define SCFORMULAOPT_OPENCL_SUBSET_OPS 15
- +#define SCFORMULAOPT_COUNT 16
- Sequence<OUString> ScFormulaCfg::GetPropertyNames()
- {
- @@ -208,6 +213,7 @@ Sequence<OUString> ScFormulaCfg::GetPropertyNames()
- {
- "Syntax/Grammar", // SCFORMULAOPT_GRAMMAR
- "Syntax/EnglishFunctionName", // SCFORMULAOPT_ENGLISH_FUNCNAME
- + "Syntax/UnitValidat", // SCFORMULAOPT_UNIT_VALIDAT
- "Syntax/SeparatorArg", // SCFORMULAOPT_SEP_ARG
- "Syntax/SeparatorArrayRow", // SCFORMULAOPT_SEP_ARRAY_ROW
- "Syntax/SeparatorArrayCol", // SCFORMULAOPT_SEP_ARRAY_COL
- @@ -236,6 +242,7 @@ ScFormulaCfg::PropsToIds ScFormulaCfg::GetPropNamesToId()
- static sal_uInt16 aVals[] = {
- SCFORMULAOPT_GRAMMAR,
- SCFORMULAOPT_ENGLISH_FUNCNAME,
- + SCFORMULAOPT_UNIT_VALIDAT,
- SCFORMULAOPT_SEP_ARG,
- SCFORMULAOPT_SEP_ARRAY_ROW,
- SCFORMULAOPT_SEP_ARRAY_COL,
- @@ -319,6 +326,13 @@ void ScFormulaCfg::UpdateFromProperties( const Sequence<OUS
- SetUseEnglishFuncName(bEnglish);
- }
- break;
- + case SCFORMULAOPT_UNIT_VALIDAT:
- + {
- + bool bValidat = false;
- + if (pValues[nProp] >>= bValidat)
- + SetUnitValidat(bValidat);
- + }
- + break;
- case SCFORMULAOPT_SEP_ARG:
- {
- OUString aSep;
- @@ -531,6 +545,12 @@ void ScFormulaCfg::ImplCommit()
- pValues[nProp] <<= b;
- }
- break;
- + case SCFORMULAOPT_UNIT_VALIDAT:
- + {
- + bool b = GetUnitValidat();
- + pValues[nProp] <<= b;
- + }
- + break;
- case SCFORMULAOPT_SEP_ARG:
- pValues[nProp] <<= GetFormulaSepArg();
- break;
- diff --git a/sc/source/ui/inc/tpformula.hxx b/sc/source/ui/inc/tpformula.hxx
- index 7397d06..e94f20d 100644
- --- a/sc/source/ui/inc/tpformula.hxx
- +++ b/sc/source/ui/inc/tpformula.hxx
- @@ -58,6 +58,7 @@ private:
- private:
- VclPtr<ListBox> mpLbFormulaSyntax;
- VclPtr<CheckBox> mpCbEnglishFuncName;
- + VclPtr<CheckBox> mpCbUnitValidat;
- VclPtr<RadioButton> mpBtnCustomCalcDefault;
- VclPtr<RadioButton> mpBtnCustomCalcCustom;
- diff --git a/sc/source/ui/optdlg/tpformula.cxx b/sc/source/ui/optdlg/tpformula.c
- index 3e7feb1..949a155 100644
- --- a/sc/source/ui/optdlg/tpformula.cxx
- +++ b/sc/source/ui/optdlg/tpformula.cxx
- @@ -44,6 +44,7 @@ ScTpFormulaOptions::ScTpFormulaOptions(vcl::Window* pParent, c
- {
- get(mpLbFormulaSyntax, "formulasyntax");
- get(mpCbEnglishFuncName, "englishfuncname");
- + get(mpCbUnitValidat, "unitvalidat");
- get(mpBtnCustomCalcDefault, "calcdefault");
- get(mpBtnCustomCalcCustom, "calccustom");
- get(mpBtnCustomCalcDetails, "details");
- @@ -88,6 +89,7 @@ void ScTpFormulaOptions::dispose()
- {
- mpLbFormulaSyntax.clear();
- mpCbEnglishFuncName.clear();
- + mpCbUnitValidat.clear();
- mpBtnCustomCalcDefault.clear();
- mpBtnCustomCalcCustom.clear();
- mpBtnCustomCalcDetails.clear();
- @@ -247,6 +249,7 @@ bool ScTpFormulaOptions::FillItemSet(SfxItemSet* rCoreSet)
- bool bRet = false;
- ScFormulaOptions aOpt;
- bool bEnglishFuncName = mpCbEnglishFuncName->IsChecked();
- + bool bUnitValidat = mpCbUnitValidat->IsChecked();
- sal_Int16 aSyntaxPos = mpLbFormulaSyntax->GetSelectEntryPos();
- OUString aSep = mpEdSepFuncArg->GetText();
- OUString aSepArrayCol = mpEdSepArrayCol->GetText();
- @@ -262,6 +265,7 @@ bool ScTpFormulaOptions::FillItemSet(SfxItemSet* rCoreSet)
- if ( mpLbFormulaSyntax->GetSavedValue() != aSyntaxPos
- || mpCbEnglishFuncName->GetSavedValue() != (bEnglishFuncName ? 1 : 0)
- + || mpCbUnitValidat->GetSavedValue() != (bUnitValidat ? 1 : 0)
- || static_cast<OUString>(mpEdSepFuncArg->GetSavedValue()) != aSep
- || static_cast<OUString>(mpEdSepArrayCol->GetSavedValue()) != aSepArra
- || static_cast<OUString>(mpEdSepArrayRow->GetSavedValue()) != aSepArra
- @@ -289,6 +293,7 @@ bool ScTpFormulaOptions::FillItemSet(SfxItemSet* rCoreSet)
- aOpt.SetFormulaSyntax(eGram);
- aOpt.SetUseEnglishFuncName(bEnglishFuncName);
- + aOpt.SetUnitValidat(bUnitValidat);
- aOpt.SetFormulaSepArg(aSep);
- aOpt.SetFormulaSepArrayCol(aSepArrayCol);
- aOpt.SetFormulaSepArrayRow(aSepArrayRow);
- @@ -342,6 +347,10 @@ void ScTpFormulaOptions::Reset(const SfxItemSet* rCoreSet)
- mpCbEnglishFuncName->Check( aOpt.GetUseEnglishFuncName() );
- mpCbEnglishFuncName->SaveValue();
- + // unit validation
- + mpCbUnitValidat->Check( aOpt.GetUnitValidat() );
- + mpCbUnitValidat->SaveValue();
- +
- // Separators
- OUString aSep = aOpt.GetFormulaSepArg();
- OUString aSepArrayRow = aOpt.GetFormulaSepArrayRow();
- diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
- index a22aff0..7220246 100644
- --- a/sc/source/ui/view/viewfunc.cxx
- +++ b/sc/source/ui/view/viewfunc.cxx
- @@ -469,25 +469,28 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB
- }
- #ifdef ENABLE_CALC_UNITVERIFICATION
- - boost::shared_ptr< Units > pUnits = Units::GetUnits();
- - FormulaStatus aStatus = pUnits->verifyFormula( pArr, aPos, pDoc );
- - if ( aStatus == FormulaStatus::VALID || aStatus == FormulaStatus::U
- + if ( SC_MOD()->GetFormulaOptions().GetUnitValidat() )
- {
- - SAL_INFO( "sc.units", "verification successful" );
- -
- - // If we have fixed a previously erronous cell we need to make
- - // the associate warning infobar. It's simplest to simply call
- - // with the hypothetical ID, and RemoveInfoBar deals with the r
- - // (The cell address is used as it's infobar id, see NotifyUnit
- - // for further details.)
- - SfxViewFrame* pViewFrame = GetViewData().GetViewShell()->GetFra
- - OUString sAddress = aPos.Format( SCA_BITS, pDoc );
- - pViewFrame->RemoveInfoBar( sAddress );
- - }
- - else
- - {
- - SAL_INFO( "sc.units", "verification failed" );
- - NotifyUnitErrorInFormula( aPos, pDoc, aStatus );
- + boost::shared_ptr< Units > pUnits = Units::GetUnits();
- + FormulaStatus aStatus = pUnits->verifyFormula( pArr, aPos, pDoc
- + if ( aStatus == FormulaStatus::VALID || aStatus == FormulaStatu
- + {
- + SAL_INFO( "sc.units", "verification successful" );
- +
- + // If we have fixed a previously erronous cell we need to m
- + // the associate warning infobar. It's simplest to simply c
- + // with the hypothetical ID, and RemoveInfoBar deals with t
- + // (The cell address is used as it's infobar id, see Notify
- + // for further details.)
- + SfxViewFrame* pViewFrame = GetViewData().GetViewShell()->Ge
- + OUString sAddress = aPos.Format( SCA_BITS, pDoc );
- + pViewFrame->RemoveInfoBar( sAddress );
- + }
- + else
- + {
- + SAL_INFO( "sc.units", "verification failed" );
- + NotifyUnitErrorInFormula( aPos, pDoc, aStatus );
- + }
- }
- #endif
- } while ( bAgain );
- @@ -583,17 +586,21 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB
- }
- #ifdef ENABLE_CALC_UNITVERIFICATION
- - boost::shared_ptr< Units > pUnits = Units::GetUnits();
- + if ( SC_MOD()->GetFormulaOptions().GetUnitValidat() )
- + {
- + boost::shared_ptr< Units > pUnits = Units::GetUnits();
- - OUString sHeaderUnit, sCellUnit;
- - ScAddress aHeaderAddress;
- + OUString sHeaderUnit, sCellUnit;
- + ScAddress aHeaderAddress;
- - if ( pUnits->isCellConversionRecommended( aAddress, pDoc, sHeaderUn
- - NotifyUnitConversionRecommended( aAddress, pDoc, sHeaderUnit, a
- - } else {
- - SfxViewFrame* pViewFrame = GetViewData().GetViewShell()->GetFra
- - OUString sAddress = aAddress.Format( SCA_BITS, pDoc );
- - pViewFrame->RemoveInfoBar( sAddress );
- + if ( pUnits->isCellConversionRecommended( aAddress, pDoc, sHead
- + NotifyUnitConversionRecommended( aAddress, pDoc, sHeaderUni
- + else
- + {
- + SfxViewFrame* pViewFrame = GetViewData().GetViewShell()->Ge
- + OUString sAddress = aAddress.Format( SCA_BITS, pDoc );
- + pViewFrame->RemoveInfoBar( sAddress );
- + }
- + if ( SC_MOD()->GetFormulaOptions().GetUnitValidat() )
- + {
- + boost::shared_ptr< Units > pUnits = Units::GetUnits();
- - OUString sHeaderUnit, sCellUnit;
- - ScAddress aHeaderAddress;
- + OUString sHeaderUnit, sCellUnit;
- + ScAddress aHeaderAddress;
- - if ( pUnits->isCellConversionRecommended( aAddress, pDoc, sHeaderUn
- - NotifyUnitConversionRecommended( aAddress, pDoc, sHeaderUnit, a
- - } else {
- - SfxViewFrame* pViewFrame = GetViewData().GetViewShell()->GetFra
- - OUString sAddress = aAddress.Format( SCA_BITS, pDoc );
- - pViewFrame->RemoveInfoBar( sAddress );
- + if ( pUnits->isCellConversionRecommended( aAddress, pDoc, sHead
- + NotifyUnitConversionRecommended( aAddress, pDoc, sHeaderUni
- + else
- + {
- + SfxViewFrame* pViewFrame = GetViewData().GetViewShell()->Ge
- + OUString sAddress = aAddress.Format( SCA_BITS, pDoc );
- + pViewFrame->RemoveInfoBar( sAddress );
- + }
- }
- #endif
- }
- diff --git a/sc/uiconfig/scalc/ui/optformula.ui b/sc/uiconfig/scalc/ui/optformul
- index 4e66f81..2b63101 100644
- --- a/sc/uiconfig/scalc/ui/optformula.ui
- +++ b/sc/uiconfig/scalc/ui/optformula.ui
- @@ -32,6 +32,23 @@
- <property name="can_focus">False</property>
- <property name="row_spacing">6</property>
- <child>
- + <object class="GtkCheckButton" id="unitvalidat">
- + <property name="label" translatable="yes">Enable unit valid
- + <property name="visible">True</property>
- + <property name="can_focus">True</property>
- + <property name="receives_default">False</property>
- + <property name="use_underline">False</property>
- + <property name="xalign">0</property>
- + <property name="draw_indicator">True</property>
- + </object>
- + <packing>
- + <property name="left_attach">0</property>
- + <property name="top_attach">2</property>
- + <property name="width">1</property>
- + <property name="height">1</property>
- + </packing>
- + </child>
- + <child>
- <object class="GtkCheckButton" id="englishfuncname">
- <property name="label" translatable="yes">Use English funct
- <property name="visible">True</property>
- commit c565edd82b3bf77a9e2333610b495a2916e4ab16
- Author: Benjamin Ni <benjaminniri@hotmail.com>
- Date: Fri Jul 3 16:45:52 2015 +0100
- tdf#92455 - inconsistent unit handling
- Change-Id: Ifbb85a32ef9d84199d17cedd28fa0f9e66eabf66
- diff --git a/sc/source/core/units/unitsimpl.cxx b/sc/source/core/units/unitsimpl
- index c2e39f9..0c89201 100644
- --- a/sc/source/core/units/unitsimpl.cxx
- +++ b/sc/source/core/units/unitsimpl.cxx
- @@ -789,8 +789,9 @@ bool UnitsImpl::convertCellUnitsForColumnRange(const ScRange
- }
- + if ( SC_MOD()->GetFormulaOptions().GetUnitValidat() )
- + {
- + boost::shared_ptr< Units > pUnits = Units::GetUnits();
- - OUString sHeaderUnit, sCellUnit;
- - ScAddress aHeaderAddress;
- + OUString sHeaderUnit, sCellUnit;
- + ScAddress aHeaderAddress;
- - if ( pUnits->isCellConversionRecommended( aAddress, pDoc, sHeaderUn
- - NotifyUnitConversionRecommended( aAddress, pDoc, sHeaderUnit, a
- - } else {
- - SfxViewFrame* pViewFrame = GetViewData().GetViewShell()->GetFra
- - OUString sAddress = aAddress.Format( SCA_BITS, pDoc );
- - pViewFrame->RemoveInfoBar( sAddress );
- + if ( pUnits->isCellConversionRecommended( aAddress, pDoc, sHead
- + NotifyUnitConversionRecommended( aAddress, pDoc, sHeaderUni
- + else
- + {
- + SfxViewFrame* pViewFrame = GetViewData().GetViewShell()->Ge
- + OUString sAddress = aAddress.Format( SCA_BITS, pDoc );
- + pViewFrame->RemoveInfoBar( sAddress );
- + }
- }
- #endif
- }
- diff --git a/sc/uiconfig/scalc/ui/optformula.ui b/sc/uiconfig/scalc/ui/optformul
- index 4e66f81..2b63101 100644
- --- a/sc/uiconfig/scalc/ui/optformula.ui
- +++ b/sc/uiconfig/scalc/ui/optformula.ui
- @@ -32,6 +32,23 @@
- <property name="can_focus">False</property>
- <property name="row_spacing">6</property>
- <child>
- + <object class="GtkCheckButton" id="unitvalidat">
- + <property name="label" translatable="yes">Enable unit valid
- + <property name="visible">True</property>
- + <property name="can_focus">True</property>
- + <property name="receives_default">False</property>
- + <property name="use_underline">False</property>
- + <property name="xalign">0</property>
- + <property name="draw_indicator">True</property>
- + </object>
- + <packing>
- + <property name="left_attach">0</property>
- + <property name="top_attach">2</property>
- <property name="row_spacing">6</property>
- <child>
- + <object class="GtkCheckButton" id="unitvalidat">
- + <property name="label" translatable="yes">Enable unit valid
- + <property name="visible">True</property>
- + <property name="can_focus">True</property>
- + <property name="receives_default">False</property>
- + <property name="use_underline">False</property>
- + <property name="xalign">0</property>
- + <property name="draw_indicator">True</property>
- + </object>
- + <packing>
- + <property name="left_attach">0</property>
- + <property name="top_attach">2</property>
- + <property name="width">1</property>
- + <property name="height">1</property>
- + </packing>
- + </child>
- + <child>
- <object class="GtkCheckButton" id="englishfuncname">
- <property name="label" translatable="yes">Use English funct
- <property name="visible">True</property>
- :
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement