[Libreoffice-commits] core.git: Branch 'feature/pivot_median' - 3 commits - offapi/com offapi/type_reference sc/inc sc/qa sc/source

Tamás Zolnai zolnaitamas2000 at gmail.com
Sat Nov 19 21:28:28 UTC 2016


Rebased ref, commits from common ancestor:
commit adebb43093e67544810a52a51e91e24306f71996
Author: Tamás Zolnai <zolnaitamas2000 at gmail.com>
Date:   Sat Nov 19 21:34:16 2016 +0100

    PivotMedian: ODS import / export of pivot table median
    
    Change-Id: I3b018f5a76bb3d89bcb6cbc34e4cb2f2057248d5

diff --git a/sc/qa/unit/data/ods/pivot-table-median.ods b/sc/qa/unit/data/ods/pivot-table-median.ods
new file mode 100755
index 0000000..bb88170
Binary files /dev/null and b/sc/qa/unit/data/ods/pivot-table-median.ods differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index dbab3cc..8d8183b 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -149,6 +149,7 @@ public:
 
     void testPivotTableXLSX();
     void testPivotTableTwoDataFieldsXLSX();
+    void testPivotTableMedian();
 
     void testSwappedOutImageExport();
     void testLinkedGraphicRT();
@@ -238,6 +239,7 @@ public:
     CPPUNIT_TEST(testSheetProtection);
     CPPUNIT_TEST(testPivotTableXLSX);
     CPPUNIT_TEST(testPivotTableTwoDataFieldsXLSX);
+    CPPUNIT_TEST(testPivotTableMedian);
 #if !defined(_WIN32)
     CPPUNIT_TEST(testSupBookVirtualPath);
 #endif
@@ -2936,6 +2938,41 @@ void ScExportTest::testPivotTableTwoDataFieldsXLSX()
     xDocSh2->DoClose();
 }
 
+void ScExportTest::testPivotTableMedian()
+{
+    ScDocShellRef xDocSh = loadDoc("pivot-table-median.", FORMAT_ODS);
+    CPPUNIT_ASSERT_MESSAGE("Failed to load test document.", xDocSh.Is());
+
+    // Export the document and import again for a check
+    ScDocShellRef xDocSh2 = saveAndReload(xDocSh.get(), FORMAT_ODS);
+    xDocSh->DoClose();
+
+    // Check sheet
+    ScDocument& rDoc = xDocSh2->GetDocument();
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be exactly one sheet.", sal_Int16(1), rDoc.GetTableCount());
+
+    // Check pivot table
+    ScDPCollection* pDPs = rDoc.GetDPCollection();
+    CPPUNIT_ASSERT_MESSAGE("Failed to get a live ScDPCollection instance.", pDPs);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be one pivot table instance.", size_t(1), pDPs->GetCount());
+    const ScDPObject* pDPObj = &(*pDPs)[0];
+    CPPUNIT_ASSERT_MESSAGE("Failed to get pivot table object.", pDPObj);
+    const ScDPSaveData* pSaveData = pDPObj->GetSaveData();
+    CPPUNIT_ASSERT_MESSAGE("Failed to get ScDPSaveData instance.", pSaveData);
+
+    // Check the data field function.
+    std::vector<const ScDPSaveDimension*> aDims;
+    pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_DATA, aDims);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE(
+        "There should be exactly 1 data field.",
+        std::vector<ScDPSaveDimension const *>::size_type(1), aDims.size());
+
+    const ScDPSaveDimension* pDim = aDims.back();
+    CPPUNIT_ASSERT_EQUAL_MESSAGE(
+        "Function for the data field should be COUNT.",
+        sal_uInt16(sheet::GeneralFunction_MEDIAN), pDim->GetFunction());
+}
+
 void ScExportTest::testFunctionsExcel2010ODS()
 {
     //testFunctionsExcel2010(FORMAT_ODS);
diff --git a/sc/source/filter/xml/XMLConverter.cxx b/sc/source/filter/xml/XMLConverter.cxx
index 5a5c529..2ea2bb6 100644
--- a/sc/source/filter/xml/XMLConverter.cxx
+++ b/sc/source/filter/xml/XMLConverter.cxx
@@ -56,6 +56,8 @@ sheet::GeneralFunction ScXMLConverter::GetFunctionFromString( const OUString& sF
         return sheet::GeneralFunction_PRODUCT;
     if( IsXMLToken(sFunction, XML_AVERAGE ) )
         return sheet::GeneralFunction_AVERAGE;
+    if( IsXMLToken(sFunction, XML_MEDIAN ) )
+        return sheet::GeneralFunction_MEDIAN;
     if( IsXMLToken(sFunction, XML_MAX ) )
         return sheet::GeneralFunction_MAX;
     if( IsXMLToken(sFunction, XML_MIN ) )
@@ -107,6 +109,7 @@ void ScXMLConverter::GetStringFromFunction(
     {
         case sheet::GeneralFunction_AUTO:       sFuncStr = GetXMLToken( XML_AUTO );         break;
         case sheet::GeneralFunction_AVERAGE:    sFuncStr = GetXMLToken( XML_AVERAGE );      break;
+        case sheet::GeneralFunction_MEDIAN:     sFuncStr = GetXMLToken( XML_MEDIAN );       break;
         case sheet::GeneralFunction_COUNT:      sFuncStr = GetXMLToken( XML_COUNT );        break;
         case sheet::GeneralFunction_COUNTNUMS:  sFuncStr = GetXMLToken( XML_COUNTNUMS );    break;
         case sheet::GeneralFunction_MAX:        sFuncStr = GetXMLToken( XML_MAX );          break;
@@ -120,7 +123,7 @@ void ScXMLConverter::GetStringFromFunction(
         case sheet::GeneralFunction_VARP:       sFuncStr = GetXMLToken( XML_VARP );         break;
         default:
         {
-            // added to avoid warnings
+            assert(false);
         }
     }
     ScRangeStringConverter::AssignString( rString, sFuncStr, false );
commit 21847f84c8ff95137a53e8e7b2fd32b1851671d0
Author: Tamás Zolnai <zolnaitamas2000 at gmail.com>
Date:   Sat Nov 19 21:33:19 2016 +0100

    PivotMedian: Implement median as a new pivot table function
    
    Change-Id: Ife90c8f1c36980254de3cec6e395a6ba94d99fea

diff --git a/sc/inc/dpglobal.hxx b/sc/inc/dpglobal.hxx
index 7c82541..295af86 100644
--- a/sc/inc/dpglobal.hxx
+++ b/sc/inc/dpglobal.hxx
@@ -27,18 +27,19 @@ enum class PivotFunc {
     Sum          = 0x0001,
     Count        = 0x0002,
     Average      = 0x0004,
-    Max          = 0x0008,
-    Min          = 0x0010,
-    Product      = 0x0020,
-    CountNum     = 0x0040,
-    StdDev       = 0x0080,
-    StdDevP      = 0x0100,
-    StdVar       = 0x0200,
-    StdVarP      = 0x0400,
+    Median       = 0x0008,
+    Max          = 0x0010,
+    Min          = 0x0020,
+    Product      = 0x0040,
+    CountNum     = 0x0080,
+    StdDev       = 0x0100,
+    StdDevP      = 0x0200,
+    StdVar       = 0x0400,
+    StdVarP      = 0x0800,
     Auto         = 0x1000
 };
 namespace o3tl {
-    template<> struct typed_flags<PivotFunc> : is_typed_flags<PivotFunc, 0x17ff> {};
+    template<> struct typed_flags<PivotFunc> : is_typed_flags<PivotFunc, 0x11ff> {};
 }
 
 struct ScDPValue
diff --git a/sc/inc/dptabres.hxx b/sc/inc/dptabres.hxx
index 05efe99..65dbf5d 100644
--- a/sc/inc/dptabres.hxx
+++ b/sc/inc/dptabres.hxx
@@ -160,6 +160,7 @@ private:
     double          fAux;
     long            nCount;
     ScDPAggData*    pChild;
+    std::vector<double> mSortedValues;
 
 public:
             ScDPAggData() : fVal(0.0), fAux(0.0), nCount(SC_DPAGG_EMPTY), pChild(nullptr) {}
diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx
index a94b855..429a867 100644
--- a/sc/inc/global.hxx
+++ b/sc/inc/global.hxx
@@ -851,7 +851,8 @@ enum ScSubTotalFunc
         SUBTOTAL_FUNC_SUM   = 9,
         SUBTOTAL_FUNC_VAR   = 10,
         SUBTOTAL_FUNC_VARP  = 11,
-        SUBTOTAL_FUNC_SELECTION_COUNT = 12
+        SUBTOTAL_FUNC_MED   = 12,
+        SUBTOTAL_FUNC_SELECTION_COUNT = 13
     };
 
 enum ScAggregateFunc
diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index 5833436..e06d921 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -149,6 +149,7 @@
 #define STR_FUN_TEXT_SUM            108
 #define STR_FUN_TEXT_COUNT          109
 #define STR_FUN_TEXT_AVG            110
+#define STR_FUN_TEXT_MEDIAN         544
 #define STR_FUN_TEXT_MAX            111
 #define STR_FUN_TEXT_MIN            112
 #define STR_FUN_TEXT_PRODUCT        113
@@ -709,7 +710,7 @@
 #define STR_BOOLEAN_VALUE               542
 #define STR_TEXT                        543
 
-#define SC_GLOBSTR_STR_COUNT            544     /**< the count of permanently resident strings */
+#define SC_GLOBSTR_STR_COUNT            545     /**< the count of permanently resident strings */
 
 #endif
 
diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx
index ff6c2da..7124b51 100644
--- a/sc/source/core/data/dpoutput.cxx
+++ b/sc/source/core/data/dpoutput.cxx
@@ -1548,6 +1548,7 @@ OUString lcl_GetDataFieldName( const OUString& rSourceName, sheet::GeneralFuncti
         case sheet::GeneralFunction_COUNT:
         case sheet::GeneralFunction_COUNTNUMS:  nStrId = STR_FUN_TEXT_COUNT;    break;
         case sheet::GeneralFunction_AVERAGE:    nStrId = STR_FUN_TEXT_AVG;      break;
+        case sheet::GeneralFunction_MEDIAN:     nStrId = STR_FUN_TEXT_MEDIAN;   break;
         case sheet::GeneralFunction_MAX:        nStrId = STR_FUN_TEXT_MAX;      break;
         case sheet::GeneralFunction_MIN:        nStrId = STR_FUN_TEXT_MIN;      break;
         case sheet::GeneralFunction_PRODUCT:    nStrId = STR_FUN_TEXT_PRODUCT;  break;
@@ -1556,10 +1557,10 @@ OUString lcl_GetDataFieldName( const OUString& rSourceName, sheet::GeneralFuncti
         case sheet::GeneralFunction_VAR:
         case sheet::GeneralFunction_VARP:       nStrId = STR_FUN_TEXT_VAR;      break;
         case sheet::GeneralFunction_NONE:
-        case sheet::GeneralFunction_AUTO:
+        case sheet::GeneralFunction_AUTO:                                       break;
         default:
         {
-            OSL_FAIL("wrong function");
+            assert(false);
         }
     }
     if ( !nStrId )
diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx
index cba41fd..b9dcdf4 100644
--- a/sc/source/core/data/dptabres.cxx
+++ b/sc/source/core/data/dptabres.cxx
@@ -57,7 +57,7 @@ using ::com::sun::star::uno::Sequence;
 
 namespace {
 
-sal_uInt16 nFuncStrIds[12] =     // matching enum ScSubTotalFunc
+sal_uInt16 nFuncStrIds[] =     // matching enum ScSubTotalFunc
 {
     0,                              // SUBTOTAL_FUNC_NONE
     STR_FUN_TEXT_AVG,               // SUBTOTAL_FUNC_AVE
@@ -70,7 +70,9 @@ sal_uInt16 nFuncStrIds[12] =     // matching enum ScSubTotalFunc
     STR_FUN_TEXT_STDDEV,            // SUBTOTAL_FUNC_STDP
     STR_FUN_TEXT_SUM,               // SUBTOTAL_FUNC_SUM
     STR_FUN_TEXT_VAR,               // SUBTOTAL_FUNC_VAR
-    STR_FUN_TEXT_VAR                // SUBTOTAL_FUNC_VARP
+    STR_FUN_TEXT_VAR,               // SUBTOTAL_FUNC_VARP
+    0,                              // SUBTOTAL_FUNC_SELECTION_COUNT - not used for pivot table
+    STR_FUN_TEXT_MEDIAN             // SUBTOTAL_FUNC_MED
 };
 
 bool lcl_SearchMember( const std::vector <ScDPResultMember *>& list, SCROW nOrder, SCROW& rIndex)
@@ -439,6 +441,15 @@ void ScDPAggData::Update( const ScDPValue& rNext, ScSubTotalFunc eFunc, const Sc
                     nCount = -1;                            // -1 for error
             }
             break;
+        case SUBTOTAL_FUNC_MED:
+            {
+                auto aIter = std::upper_bound(mSortedValues.begin(), mSortedValues.end(), rNext.mfValue);
+                if (aIter == mSortedValues.end())
+                    mSortedValues.push_back(rNext.mfValue);
+                else
+                    mSortedValues.insert(aIter, rNext.mfValue);
+            }
+            break;
         default:
             OSL_FAIL("invalid function");
     }
@@ -475,6 +486,7 @@ void ScDPAggData::Calculate( ScSubTotalFunc eFunc, const ScDPSubTotalState& rSub
             break;
 
         case SUBTOTAL_FUNC_AVE:
+        case SUBTOTAL_FUNC_MED:
         case SUBTOTAL_FUNC_MAX:
         case SUBTOTAL_FUNC_MIN:
         case SUBTOTAL_FUNC_STDP:
@@ -534,6 +546,16 @@ void ScDPAggData::Calculate( ScSubTotalFunc eFunc, const ScDPSubTotalState& rSub
                 if ( nCount > 0 )
                     fResult = (fAux - fVal*fVal/(double)(nCount)) / (double)nCount;
                 break;
+            case SUBTOTAL_FUNC_MED:
+                if (mSortedValues.size() > 0)
+                {
+                    assert(mSortedValues.size() == static_cast<size_t>(nCount));
+                    if ((nCount % 2) == 1)
+                        fResult = mSortedValues[mSortedValues.size() / 2];
+                    else
+                        fResult = (mSortedValues[mSortedValues.size() / 2 - 1] + mSortedValues[mSortedValues.size() / 2]) / 2.0;
+                }
+                break;
             default:
                 OSL_FAIL("invalid function");
         }
@@ -816,6 +838,7 @@ OUString ScDPResultData::GetMeasureString(long nMeasure, bool bForce, ScSubTotal
     {
         //  for user-specified subtotal function with all measures,
         //  display only function name
+        assert(eForceFunc < SAL_N_ELEMENTS(nFuncStrIds));
         if ( eForceFunc != SUBTOTAL_FUNC_NONE )
             return ScGlobal::GetRscString(nFuncStrIds[eForceFunc]);
 
diff --git a/sc/source/core/data/dputil.cxx b/sc/source/core/data/dputil.cxx
index 93d79ed..f614d42 100644
--- a/sc/source/core/data/dputil.cxx
+++ b/sc/source/core/data/dputil.cxx
@@ -367,7 +367,7 @@ sal_Int32 ScDPUtil::getDatePartValue(
 
 namespace {
 
-sal_uInt16 nFuncStrIds[12] = {
+sal_uInt16 nFuncStrIds[] = {
     0,                              // SUBTOTAL_FUNC_NONE
     STR_FUN_TEXT_AVG,               // SUBTOTAL_FUNC_AVE
     STR_FUN_TEXT_COUNT,             // SUBTOTAL_FUNC_CNT
@@ -379,7 +379,9 @@ sal_uInt16 nFuncStrIds[12] = {
     STR_FUN_TEXT_STDDEV,            // SUBTOTAL_FUNC_STDP
     STR_FUN_TEXT_SUM,               // SUBTOTAL_FUNC_SUM
     STR_FUN_TEXT_VAR,               // SUBTOTAL_FUNC_VAR
-    STR_FUN_TEXT_VAR                // SUBTOTAL_FUNC_VARP
+    STR_FUN_TEXT_VAR,               // SUBTOTAL_FUNC_VARP
+    0,                              // SUBTOTAL_FUNC_SELECTION_COUNT - not used for pivot table
+    STR_FUN_TEXT_MEDIAN             // SUBTOTAL_FUNC_MED
 };
 
 }
@@ -387,6 +389,7 @@ sal_uInt16 nFuncStrIds[12] = {
 OUString ScDPUtil::getDisplayedMeasureName(const OUString& rName, ScSubTotalFunc eFunc)
 {
     OUStringBuffer aRet;
+    assert(eFunc < SAL_N_ELEMENTS(nFuncStrIds));
     sal_uInt16 nId = nFuncStrIds[eFunc];
     if (nId)
     {
@@ -400,13 +403,14 @@ OUString ScDPUtil::getDisplayedMeasureName(const OUString& rName, ScSubTotalFunc
 
 ScSubTotalFunc ScDPUtil::toSubTotalFunc(css::sheet::GeneralFunction eGenFunc)
 {
-    ScSubTotalFunc eSubTotal;
+    ScSubTotalFunc eSubTotal = SUBTOTAL_FUNC_NONE;
     switch (eGenFunc)
     {
         case sheet::GeneralFunction_NONE:       eSubTotal = SUBTOTAL_FUNC_NONE; break;
         case sheet::GeneralFunction_SUM:        eSubTotal = SUBTOTAL_FUNC_SUM;  break;
         case sheet::GeneralFunction_COUNT:      eSubTotal = SUBTOTAL_FUNC_CNT2; break;
         case sheet::GeneralFunction_AVERAGE:    eSubTotal = SUBTOTAL_FUNC_AVE;  break;
+        case sheet::GeneralFunction_MEDIAN:     eSubTotal = SUBTOTAL_FUNC_MED;  break;
         case sheet::GeneralFunction_MAX:        eSubTotal = SUBTOTAL_FUNC_MAX;  break;
         case sheet::GeneralFunction_MIN:        eSubTotal = SUBTOTAL_FUNC_MIN;  break;
         case sheet::GeneralFunction_PRODUCT:    eSubTotal = SUBTOTAL_FUNC_PROD; break;
@@ -415,9 +419,9 @@ ScSubTotalFunc ScDPUtil::toSubTotalFunc(css::sheet::GeneralFunction eGenFunc)
         case sheet::GeneralFunction_STDEVP:     eSubTotal = SUBTOTAL_FUNC_STDP; break;
         case sheet::GeneralFunction_VAR:        eSubTotal = SUBTOTAL_FUNC_VAR;  break;
         case sheet::GeneralFunction_VARP:       eSubTotal = SUBTOTAL_FUNC_VARP; break;
-        case sheet::GeneralFunction_AUTO:
+        case sheet::GeneralFunction_AUTO:       eSubTotal = SUBTOTAL_FUNC_NONE; break;
         default:
-            eSubTotal = SUBTOTAL_FUNC_NONE;
+            assert(false);
     }
     return eSubTotal;
 }
diff --git a/sc/source/ui/dbgui/PivotLayoutTreeListData.cxx b/sc/source/ui/dbgui/PivotLayoutTreeListData.cxx
index 401fa81..8eae041 100644
--- a/sc/source/ui/dbgui/PivotLayoutTreeListData.cxx
+++ b/sc/source/ui/dbgui/PivotLayoutTreeListData.cxx
@@ -35,6 +35,7 @@ OUString lclGetFunctionMaskName(const PivotFunc nFunctionMask)
         case PivotFunc::Sum:        nStrId = STR_FUN_TEXT_SUM;      break;
         case PivotFunc::Count:      nStrId = STR_FUN_TEXT_COUNT;    break;
         case PivotFunc::Average:    nStrId = STR_FUN_TEXT_AVG;      break;
+        case PivotFunc::Median:     nStrId = STR_FUN_TEXT_MEDIAN;   break;
         case PivotFunc::Max:        nStrId = STR_FUN_TEXT_MAX;      break;
         case PivotFunc::Min:        nStrId = STR_FUN_TEXT_MIN;      break;
         case PivotFunc::Product:    nStrId = STR_FUN_TEXT_PRODUCT;  break;
diff --git a/sc/source/ui/dbgui/pvfundlg.cxx b/sc/source/ui/dbgui/pvfundlg.cxx
index d947b51..5a9ad2b 100644
--- a/sc/source/ui/dbgui/pvfundlg.cxx
+++ b/sc/source/ui/dbgui/pvfundlg.cxx
@@ -100,6 +100,7 @@ static const PivotFunc spnFunctions[] =
     PivotFunc::Sum,
     PivotFunc::Count,
     PivotFunc::Average,
+    PivotFunc::Median,
     PivotFunc::Max,
     PivotFunc::Min,
     PivotFunc::Product,
@@ -189,6 +190,7 @@ void ScDPFunctionListBox::FillFunctionNames()
     ResStringArray aArr( ScResId( SCSTR_DPFUNCLISTBOX ) );
     for( sal_uInt16 nIndex = 0, nCount = sal::static_int_cast<sal_uInt16>(aArr.Count()); nIndex < nCount; ++nIndex )
         InsertEntry( aArr.GetString( nIndex ) );
+    assert(GetEntryCount() == SAL_N_ELEMENTS(spnFunctions));
 }
 
 ScDPFunctionDlg::ScDPFunctionDlg(
diff --git a/sc/source/ui/dbgui/pvfundlg.src b/sc/source/ui/dbgui/pvfundlg.src
index fe33cf8..0de9461 100644
--- a/sc/source/ui/dbgui/pvfundlg.src
+++ b/sc/source/ui/dbgui/pvfundlg.src
@@ -26,6 +26,7 @@ StringArray SCSTR_DPFUNCLISTBOX
         < "Sum" ; Default ; > ;
         < "Count" ; Default ; > ;
         < "Average" ; Default ; > ;
+        < "Median" ; Default ; > ;
         < "Max" ; Default ; > ;
         < "Min" ; Default ; > ;
         < "Product" ; Default ; > ;
diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src
index 241254b..0827a6a 100644
--- a/sc/source/ui/src/globstr.src
+++ b/sc/source/ui/src/globstr.src
@@ -658,6 +658,10 @@ Resource RID_GLOBSTR
     {
         Text [ en-US ] = "Average" ;
     };
+    String STR_FUN_TEXT_MEDIAN
+    {
+        Text [ en-US ] = "Median" ;
+    };
     String STR_FUN_TEXT_MAX
     {
         Text [ en-US ] = "Max" ;
diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx
index a6f7f58..fe2590b 100644
--- a/sc/source/ui/unoobj/dapiuno.cxx
+++ b/sc/source/ui/unoobj/dapiuno.cxx
@@ -184,6 +184,7 @@ GeneralFunction ScDataPilotConversion::FirstFunc( PivotFunc nBits )
     if ( nBits & PivotFunc::Sum )       return GeneralFunction_SUM;
     if ( nBits & PivotFunc::Count )     return GeneralFunction_COUNT;
     if ( nBits & PivotFunc::Average )   return GeneralFunction_AVERAGE;
+    if ( nBits & PivotFunc::Median )    return GeneralFunction_MEDIAN;
     if ( nBits & PivotFunc::Max )       return GeneralFunction_MAX;
     if ( nBits & PivotFunc::Min )       return GeneralFunction_MIN;
     if ( nBits & PivotFunc::Product )   return GeneralFunction_PRODUCT;
@@ -204,6 +205,7 @@ PivotFunc ScDataPilotConversion::FunctionBit( GeneralFunction eFunc )
         case GeneralFunction_SUM:       nRet = PivotFunc::Sum;       break;
         case GeneralFunction_COUNT:     nRet = PivotFunc::Count;     break;
         case GeneralFunction_AVERAGE:   nRet = PivotFunc::Average;   break;
+        case GeneralFunction_MEDIAN:    nRet = PivotFunc::Median;    break;
         case GeneralFunction_MAX:       nRet = PivotFunc::Max;       break;
         case GeneralFunction_MIN:       nRet = PivotFunc::Min;       break;
         case GeneralFunction_PRODUCT:   nRet = PivotFunc::Product;   break;
@@ -215,7 +217,7 @@ PivotFunc ScDataPilotConversion::FunctionBit( GeneralFunction eFunc )
         case GeneralFunction_AUTO:      nRet = PivotFunc::Auto;      break;
         default:
         {
-            // added to avoid warnings
+            assert(false);
         }
     }
     return nRet;
diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx
index 718af05..403bb6a4 100644
--- a/sc/source/ui/unoobj/datauno.cxx
+++ b/sc/source/ui/unoobj/datauno.cxx
@@ -144,6 +144,7 @@ sheet::GeneralFunction  ScDataUnoConversion::SubTotalToGeneral( ScSubTotalFunc e
         case SUBTOTAL_FUNC_AVE:  eGeneral = sheet::GeneralFunction_AVERAGE;   break;
         case SUBTOTAL_FUNC_CNT:  eGeneral = sheet::GeneralFunction_COUNTNUMS; break;
         case SUBTOTAL_FUNC_CNT2: eGeneral = sheet::GeneralFunction_COUNT;     break;
+        case SUBTOTAL_FUNC_MED:  eGeneral = sheet::GeneralFunction_MEDIAN;    break;
         case SUBTOTAL_FUNC_MAX:  eGeneral = sheet::GeneralFunction_MAX;       break;
         case SUBTOTAL_FUNC_MIN:  eGeneral = sheet::GeneralFunction_MIN;       break;
         case SUBTOTAL_FUNC_PROD: eGeneral = sheet::GeneralFunction_PRODUCT;   break;
commit 45f77402cb2ce379849fb4a85af196c6c86fde0d
Author: Tamás Zolnai <zolnaitamas2000 at gmail.com>
Date:   Sat Nov 19 22:27:20 2016 +0100

    [API Change] PivotMedian: Add median to pivot table function type
    
    Change-Id: I675e81b5c13832ac0ff893a6e080241e6f1c8fd5

diff --git a/offapi/com/sun/star/sheet/GeneralFunction.idl b/offapi/com/sun/star/sheet/GeneralFunction.idl
index ff9615c..726ae9d 100644
--- a/offapi/com/sun/star/sheet/GeneralFunction.idl
+++ b/offapi/com/sun/star/sheet/GeneralFunction.idl
@@ -56,6 +56,13 @@ published enum GeneralFunction
     AVERAGE,
 
 
+    /**
+    *   median of all numerical values is calculated.
+    *   @since LibreOffice 5.3
+    */
+    MEDIAN,
+
+
     /** maximum value of all numerical values is calculated.
      */
     MAX,
diff --git a/offapi/type_reference/offapi.idl b/offapi/type_reference/offapi.idl
index 1785f24..b939b24 100644
--- a/offapi/type_reference/offapi.idl
+++ b/offapi/type_reference/offapi.idl
@@ -11484,14 +11484,15 @@ module com {
      SUM = 2,
      COUNT = 3,
      AVERAGE = 4,
-     MAX = 5,
-     MIN = 6,
-     PRODUCT = 7,
-     COUNTNUMS = 8,
-     STDEV = 9,
-     STDEVP = 10,
-     VAR = 11,
-     VARP = 12
+     MEDIAN = 5,
+     MAX = 6,
+     MIN = 7,
+     PRODUCT = 8,
+     COUNTNUMS = 9,
+     STDEV = 10,
+     STDEVP = 11,
+     VAR = 12,
+     VARP = 13
     };
     /** @deprecated */ published interface XConsolidationDescriptor {
      interface ::com::sun::star::uno::XInterface;


More information about the Libreoffice-commits mailing list