[Libreoffice-commits] core.git: Branch 'libreoffice-4-4' - officecfg/registry sc/source

Tor Lillqvist tml at collabora.com
Mon Mar 9 05:14:18 PDT 2015


 officecfg/registry/schema/org/openoffice/Office/Calc.xcs |    3 
 sc/source/core/tool/calcconfig.cxx                       |   56 ++-------------
 sc/source/core/tool/formulaopt.cxx                       |    4 -
 3 files changed, 11 insertions(+), 52 deletions(-)

New commits:
commit 06079e88abb177979d355f7fa62bf206fba7cb53
Author: Tor Lillqvist <tml at collabora.com>
Date:   Fri Jan 23 12:47:52 2015 +0200

    Don't use configuration syntax that breaks when upgrading to 4.5
    
    Use symbolic (not numeric) opcodes in the registry for the OpenCL use
    subset. The opcode numeric values are not stable, and have in fact changed in
    master recently.
    
    Even if they were stable, storing them symbolically would be a good
    idea. Makes it easier to edit them manually directly in the registry files.
    (Something end-users are of course not expected to do, but admins or hackers
    may want to do.)
    
    I figured out how to do the mapping from symbolic names to enum values and
    back without an ScDocument, turned out it was not complicated after all.
    
    Change-Id: I062dbfa633668a645c6c308acacf0826b6459a93
    Reviewed-on: https://gerrit.libreoffice.org/14775
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
index 8748054..a2195df 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
@@ -1364,9 +1364,8 @@
             <desc>The list of operator and function opcodes for which to use OpenCL. If a
 	    formula contains only these operators and functions, it
 	    might be calculated using OpenCL.</desc>
-          <!-- numeric values correspond to +;-;*;/;RAND;SIN;COS;TAN;ATAN;EXP;LN;SQRT;NORMSDIST;NORMSINV;ROUND;POWER;SUMPRODUCT;MIN;MAX;SUM;PRODUCT;AVERAGE;COUNT;VAR;NORMDIST;CORREL;COVAR;PEARSON;SLOPE;SUMIFS -->
           </info>
-          <value>40;41;42;43;66;82;83;84;88;102;103;104;146;149;204;209;213;222;223;224;225;226;227;231;236;343;344;345;348;403</value>
+          <value>+;-;*;/;RAND;SIN;COS;TAN;ATAN;EXP;LN;SQRT;NORMSDIST;NORMSINV;ROUND;POWER;SUMPRODUCT;MIN;MAX;SUM;PRODUCT;AVERAGE;COUNT;VAR;NORMDIST;CORREL;COVAR;PEARSON;SLOPE;SUMIFS</value>
         </prop>
         <prop oor:name="OpenCLAutoSelect" oor:type="xs:boolean" oor:nillable="false">
           <!-- UIHints: Tools - Options  Spreadsheet  Formula -->
diff --git a/sc/source/core/tool/calcconfig.cxx b/sc/source/core/tool/calcconfig.cxx
index f1e7bf0..d9767bf 100644
--- a/sc/source/core/tool/calcconfig.cxx
+++ b/sc/source/core/tool/calcconfig.cxx
@@ -120,46 +120,11 @@ std::ostream& operator<<(std::ostream& rStream, const ScCalcConfig& rConfig)
     return rStream;
 }
 
-namespace {
-
-formula::FormulaCompiler::OpCodeMapPtr setup()
-{
-    SfxObjectShell* pObjShell = SfxObjectShell::Current();
-    ScDocShell* pScDocShell = PTR_CAST(ScDocShell, pObjShell);
-
-    if (pScDocShell)
-    {
-        ScDocument& rDoc(pScDocShell->GetDocument());
-        ScCompiler* pComp(new ScCompiler(&rDoc, ScAddress()));
-        return pComp->GetOpCodeMap(css::sheet::FormulaLanguage::NATIVE);
-    }
-
-    return nullptr;
-}
-
-} // anonymous namespace
-
-OUString ScOpCodeSetToNumberString(const ScCalcConfig::OpCodeSet& rOpCodes)
-{
-    OUStringBuffer result;
-
-    for (auto i = rOpCodes.cbegin(); i != rOpCodes.cend(); ++i)
-    {
-        if (i != rOpCodes.cbegin())
-            result.append(';');
-        result.append(static_cast<sal_Int32>(*i));
-    }
-
-    return result.toString();
-}
-
 OUString ScOpCodeSetToSymbolicString(const ScCalcConfig::OpCodeSet& rOpCodes)
 {
     OUStringBuffer result;
-    formula::FormulaCompiler::OpCodeMapPtr pOpCodeMap(setup());
-
-    if (!pOpCodeMap)
-        return ScOpCodeSetToNumberString(rOpCodes);
+    formula::FormulaCompiler aCompiler;
+    formula::FormulaCompiler::OpCodeMapPtr pOpCodeMap(aCompiler.GetOpCodeMap(css::sheet::FormulaLanguage::ENGLISH));
 
     for (auto i = rOpCodes.cbegin(); i != rOpCodes.cend(); ++i)
     {
@@ -174,16 +139,15 @@ OUString ScOpCodeSetToSymbolicString(const ScCalcConfig::OpCodeSet& rOpCodes)
 ScCalcConfig::OpCodeSet ScStringToOpCodeSet(const OUString& rOpCodes)
 {
     ScCalcConfig::OpCodeSet result;
-    formula::FormulaCompiler::OpCodeMapPtr pOpCodeMap(setup());
+    formula::FormulaCompiler aCompiler;
+    formula::FormulaCompiler::OpCodeMapPtr pOpCodeMap(aCompiler.GetOpCodeMap(css::sheet::FormulaLanguage::ENGLISH));
 
-    OUString s(rOpCodes + ";");
-
-    const formula::OpCodeHashMap *pHashMap(nullptr);
-    if (pOpCodeMap)
-        pHashMap = pOpCodeMap->getHashMap();
+    const formula::OpCodeHashMap *pHashMap(pOpCodeMap->getHashMap());
 
     sal_Int32 fromIndex(0);
     sal_Int32 semicolon;
+    OUString s(rOpCodes + ";");
+
     while ((semicolon = s.indexOf(';', fromIndex)) >= 0)
     {
         if (semicolon > fromIndex)
@@ -192,7 +156,7 @@ ScCalcConfig::OpCodeSet ScStringToOpCodeSet(const OUString& rOpCodes)
             sal_Int32 n = element.toInt32();
             if (n > 0 || (n == 0 && element == "0"))
                 result.insert(static_cast<OpCodeEnum>(n));
-            else if (pHashMap)
+            else
             {
                 auto opcode(pHashMap->find(element));
                 if (opcode != pHashMap->end())
@@ -200,10 +164,6 @@ ScCalcConfig::OpCodeSet ScStringToOpCodeSet(const OUString& rOpCodes)
                 else
                     SAL_WARN("sc.opencl", "Unrecognized OpCode " << element << " in OpCode set string");
             }
-            else
-            {
-                SAL_WARN("sc.opencl", "No current doc, can't convert from OpCode name to value");
-            }
         }
         fromIndex = semicolon+1;
     }
diff --git a/sc/source/core/tool/formulaopt.cxx b/sc/source/core/tool/formulaopt.cxx
index 5da7b01..5038055 100644
--- a/sc/source/core/tool/formulaopt.cxx
+++ b/sc/source/core/tool/formulaopt.cxx
@@ -496,7 +496,7 @@ void ScFormulaCfg::UpdateFromProperties( const Sequence<OUString>& aNames )
                 break;
                 case SCFORMULAOPT_OPENCL_SUBSET_OPS:
                 {
-                    OUString sVal = ScOpCodeSetToNumberString(GetCalcConfig().maOpenCLSubsetOpCodes);
+                    OUString sVal = ScOpCodeSetToSymbolicString(GetCalcConfig().maOpenCLSubsetOpCodes);
                     pValues[nProp] >>= sVal;
                     GetCalcConfig().maOpenCLSubsetOpCodes = ScStringToOpCodeSet(sVal);
                 }
@@ -643,7 +643,7 @@ void ScFormulaCfg::Commit()
             break;
             case SCFORMULAOPT_OPENCL_SUBSET_OPS:
             {
-                OUString sVal = ScOpCodeSetToNumberString(GetCalcConfig().maOpenCLSubsetOpCodes);
+                OUString sVal = ScOpCodeSetToSymbolicString(GetCalcConfig().maOpenCLSubsetOpCodes);
                 pValues[nProp] <<= sVal;
             }
             break;


More information about the Libreoffice-commits mailing list