officecfg/registry/schema/org/openoffice/Office/Calc.xcs | 7 + sc/inc/formulaopt.hxx | 4 sc/source/core/tool/formulaopt.cxx | 58 +++++++++----- sc/source/ui/inc/tpformula.hxx | 1 sc/source/ui/optdlg/tpformula.cxx | 9 ++ sc/source/ui/view/viewfunc.cxx | 61 ++++++++------- sc/uiconfig/scalc/ui/optformula.ui | 17 ++++ 7 files changed, 111 insertions(+), 46 deletions(-)
New commits: commit fc2a471d90521e1a9500b27088bbd122002049b0 Author: Benjamin Ni <benjaminn...@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/officecfg/registry/schema/org/openoffice/Office/Calc.xcs 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.</desc> + </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 locale is not English. + bool bUnitValidat; formula::FormulaGrammar::Grammar eFormulaGrammar; // formula grammar used to switch different formula syntax 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.cxx 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::GetLocaleDataWrapper() 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 ScFormulaOptions& rCpy ) 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<OUString>& aNames ) 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.cxx 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, const SfxItemSet& r { 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()) != aSepArrayCol || static_cast<OUString>(mpEdSepArrayRow->GetSavedValue()) != aSepArrayRow @@ -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 nTab, } #ifdef ENABLE_CALC_UNITVERIFICATION - boost::shared_ptr< Units > pUnits = Units::GetUnits(); - FormulaStatus aStatus = pUnits->verifyFormula( pArr, aPos, pDoc ); - if ( aStatus == FormulaStatus::VALID || aStatus == FormulaStatus::UNKNOWN ) + if ( SC_MOD()->GetFormulaOptions().GetUnitValidat() ) { - SAL_INFO( "sc.units", "verification successful" ); - - // If we have fixed a previously erronous cell we need to make sure we remove - // the associate warning infobar. It's simplest to simply call RemoveInfoBar - // with the hypothetical ID, and RemoveInfoBar deals with the remaning details. - // (The cell address is used as it's infobar id, see NotifyUnitErrorInFormula - // for further details.) - SfxViewFrame* pViewFrame = GetViewData().GetViewShell()->GetFrame(); - 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 == FormulaStatus::UNKNOWN ) + { + SAL_INFO( "sc.units", "verification successful" ); + + // If we have fixed a previously erronous cell we need to make sure we remove + // the associate warning infobar. It's simplest to simply call RemoveInfoBar + // with the hypothetical ID, and RemoveInfoBar deals with the remaning details. + // (The cell address is used as it's infobar id, see NotifyUnitErrorInFormula + // for further details.) + SfxViewFrame* pViewFrame = GetViewData().GetViewShell()->GetFrame(); + 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 nTab, } #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, sHeaderUnit, aHeaderAddress, sCellUnit ) ) { - NotifyUnitConversionRecommended( aAddress, pDoc, sHeaderUnit, aHeaderAddress, sCellUnit, pDocSh ); - } else { - SfxViewFrame* pViewFrame = GetViewData().GetViewShell()->GetFrame(); - OUString sAddress = aAddress.Format( SCA_BITS, pDoc ); - pViewFrame->RemoveInfoBar( sAddress ); + if ( pUnits->isCellConversionRecommended( aAddress, pDoc, sHeaderUnit, aHeaderAddress, sCellUnit ) ) + NotifyUnitConversionRecommended( aAddress, pDoc, sHeaderUnit, aHeaderAddress, sCellUnit, pDocSh ); + else + { + SfxViewFrame* pViewFrame = GetViewData().GetViewShell()->GetFrame(); + 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/optformula.ui 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 validation check</property> + <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 function names</property> <property name="visible">True</property> _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits