diff options
author | Benjamin Ni <benjaminniri@hotmail.com> | 2015-07-03 04:40:29 +0100 |
---|---|---|
committer | Andrzej Hunt <andrzej@ahunt.org> | 2015-10-21 10:23:41 +0200 |
commit | 31ac44715883c3c41c71fadae248f7a0ce8851d8 (patch) | |
tree | 3dce894afe3100d3a1736533897a57c136bc2a26 | |
parent | ff257403fed69615080515a68c41e7c8f697f456 (diff) |
Added checkbox and config option to toggle unit verification
Change-Id: Ie218821d05466b77ed42a26365b04a6798dec067
-rw-r--r-- | officecfg/registry/schema/org/openoffice/Office/Calc.xcs | 7 | ||||
-rw-r--r-- | sc/inc/formulaopt.hxx | 3 | ||||
-rw-r--r-- | sc/source/core/tool/formulaopt.cxx | 60 | ||||
-rw-r--r-- | sc/source/ui/inc/tpformula.hxx | 1 | ||||
-rw-r--r-- | sc/source/ui/optdlg/tpformula.cxx | 9 | ||||
-rw-r--r-- | sc/source/ui/view/viewfunc.cxx | 61 | ||||
-rw-r--r-- | sc/uiconfig/scalc/ui/optformula.ui | 17 |
7 files changed, 111 insertions, 47 deletions
diff --git a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs index 8e1200ef5cbc..db39071137f5 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 8a903d22c95e..f6d9e690e9c7 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; bool mbWriteCalcConfig; @@ -53,6 +54,8 @@ public: void SetWriteCalcConfig( bool bVal ) { mbWriteCalcConfig = bVal; } bool GetWriteCalcConfig() const { return mbWriteCalcConfig; } + 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 db1bc0bbc6cf..08555449ddf2 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 ), mbWriteCalcConfig (rCpy.mbWriteCalcConfig), aFormulaSepArg ( rCpy.aFormulaSepArg ), aFormulaSepArrayRow ( rCpy.aFormulaSepArrayRow ), @@ -52,6 +53,7 @@ ScFormulaOptions::~ScFormulaOptions() void ScFormulaOptions::SetDefaults() { bUseEnglishFuncName = false; + bUnitValidat = false; eFormulaGrammar = ::formula::FormulaGrammar::GRAM_NATIVE; mbWriteCalcConfig = true; meOOXMLRecalc = RECALC_ASK; @@ -129,9 +131,10 @@ const LocaleDataWrapper& ScFormulaOptions::GetLocaleDataWrapper() ScFormulaOptions& ScFormulaOptions::operator=( const ScFormulaOptions& rCpy ) { bUseEnglishFuncName = rCpy.bUseEnglishFuncName; + bUnitValidat = rCpy.bUnitValidat; eFormulaGrammar = rCpy.eFormulaGrammar; - aCalcConfig = rCpy.aCalcConfig; - mbWriteCalcConfig = rCpy.mbWriteCalcConfig; + aCalcConfig = rCpy.aCalcConfig; + mbWriteCalcConfig = rCpy.mbWriteCalcConfig; aFormulaSepArg = rCpy.aFormulaSepArg; aFormulaSepArrayRow = rCpy.aFormulaSepArrayRow; aFormulaSepArrayCol = rCpy.aFormulaSepArrayCol; @@ -143,8 +146,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 && mbWriteCalcConfig == rOpt.mbWriteCalcConfig && aFormulaSepArg == rOpt.aFormulaSepArg && aFormulaSepArrayRow == rOpt.aFormulaSepArrayRow @@ -189,22 +193,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() { @@ -212,6 +217,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 @@ -240,6 +246,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, @@ -323,6 +330,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; @@ -542,6 +556,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 3c7ed8cae00a..e9a4c417e4e5 100644 --- a/sc/source/ui/inc/tpformula.hxx +++ b/sc/source/ui/inc/tpformula.hxx @@ -60,6 +60,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 789555d2ad0a..d9eb16dc724a 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"); @@ -92,6 +93,7 @@ void ScTpFormulaOptions::dispose() { mpLbFormulaSyntax.clear(); mpCbEnglishFuncName.clear(); + mpCbUnitValidat.clear(); mpBtnCustomCalcDefault.clear(); mpBtnCustomCalcCustom.clear(); mpBtnCustomCalcDetails.clear(); @@ -246,6 +248,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(); @@ -261,6 +264,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); @@ -345,6 +350,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 402c5740082b..125fe9d0c7a9 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -471,25 +471,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 ); @@ -585,17 +588,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 4e66f81c7809..2b63101065ae 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> |