[Libreoffice-commits] core.git: 6 commits - offapi/com offapi/type_reference sc/inc sc/qa sc/source

Tamás Zolnai zolnaitamas2000 at gmail.com
Sat Nov 19 23:43:35 UTC 2016


 offapi/com/sun/star/sheet/GeneralFunction.idl  |    7 +++
 offapi/type_reference/offapi.idl               |   17 ++++----
 sc/inc/dpglobal.hxx                            |   21 +++++-----
 sc/inc/dptabres.hxx                            |    1 
 sc/inc/global.hxx                              |    3 +
 sc/inc/globstr.hrc                             |   14 +------
 sc/qa/unit/data/ods/pivot-table-median.ods     |binary
 sc/qa/unit/subsequent_export-test.cxx          |   37 +++++++++++++++++++
 sc/source/core/data/dpoutput.cxx               |    5 +-
 sc/source/core/data/dptabres.cxx               |   27 +++++++++++++-
 sc/source/core/data/dputil.cxx                 |   14 ++++---
 sc/source/filter/xml/XMLConverter.cxx          |    8 +++-
 sc/source/ui/dbgui/PivotLayoutTreeListData.cxx |   31 +++++++++-------
 sc/source/ui/dbgui/pvfundlg.cxx                |    2 +
 sc/source/ui/dbgui/pvfundlg.src                |    1 
 sc/source/ui/src/globstr.src                   |   48 ++-----------------------
 sc/source/ui/unoobj/dapiuno.cxx                |    4 +-
 sc/source/ui/unoobj/datauno.cxx                |    1 
 18 files changed, 142 insertions(+), 99 deletions(-)

New commits:
commit 92c1128fb80b4e38df219ce60f018cfb1522b20a
Author: Tamás Zolnai <zolnaitamas2000 at gmail.com>
Date:   Sat Nov 19 22:47:06 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..9cd60bb 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 ) )
@@ -83,6 +85,8 @@ ScSubTotalFunc ScXMLConverter::GetSubTotalFuncFromString( const OUString& sFunct
         return SUBTOTAL_FUNC_PROD;
     if( IsXMLToken(sFunction, XML_AVERAGE ) )
         return SUBTOTAL_FUNC_AVE;
+    if( IsXMLToken(sFunction, XML_MEDIAN ) )
+        return SUBTOTAL_FUNC_MED;
     if( IsXMLToken(sFunction, XML_MAX ) )
         return SUBTOTAL_FUNC_MAX;
     if( IsXMLToken(sFunction, XML_MIN ) )
@@ -107,6 +111,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 +125,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 );
@@ -134,6 +139,7 @@ void ScXMLConverter::GetStringFromFunction(
     switch( eFunction )
     {
         case SUBTOTAL_FUNC_AVE:     sFuncStr = GetXMLToken( XML_AVERAGE );      break;
+        case SUBTOTAL_FUNC_MED:     sFuncStr = GetXMLToken( XML_MEDIAN );       break;
         case SUBTOTAL_FUNC_CNT:     sFuncStr = GetXMLToken( XML_COUNT );        break;
         case SUBTOTAL_FUNC_CNT2:    sFuncStr = GetXMLToken( XML_COUNTNUMS );    break;
         case SUBTOTAL_FUNC_MAX:     sFuncStr = GetXMLToken( XML_MAX );          break;
commit 298ee50676b849020a8a5042e8612f71379ecf3b
Author: Tamás Zolnai <zolnaitamas2000 at gmail.com>
Date:   Sat Nov 19 23:59:49 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..233329c 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
+    STR_FUN_TEXT_MEDIAN,            // SUBTOTAL_FUNC_MED
+    0                               // SUBTOTAL_FUNC_SELECTION_COUNT - not used for pivot table
 };
 
 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 ((mSortedValues.size() % 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..b0f868f 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
+    STR_FUN_TEXT_MEDIAN,            // SUBTOTAL_FUNC_MED
+    0                               // SUBTOTAL_FUNC_SELECTION_COUNT - not used for pivot table
 };
 
 }
@@ -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 eb27a63a38ee7d15292dc40520b0605e4c2228e2
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;
commit 99dbbecb1c0838494b095e8338dc7e6b00ab2cb6
Author: Tamás Zolnai <zolnaitamas2000 at gmail.com>
Date:   Thu Nov 3 11:33:24 2016 +0100

    Display localized function names in Pivot Layout dialog
    
    Same names which are displayed for pivot table
    placed on a sheet.
    
    Change-Id: Ic05d0dddea7d17101f253874dff15b8a49b87287

diff --git a/sc/source/ui/dbgui/PivotLayoutTreeListData.cxx b/sc/source/ui/dbgui/PivotLayoutTreeListData.cxx
index 85f04c5..401fa81 100644
--- a/sc/source/ui/dbgui/PivotLayoutTreeListData.cxx
+++ b/sc/source/ui/dbgui/PivotLayoutTreeListData.cxx
@@ -16,6 +16,7 @@
 #include <svtools/treelistentry.hxx>
 #include "pivot.hxx"
 #include "scabstdlg.hxx"
+#include "globstr.hrc"
 
 using namespace std;
 
@@ -28,23 +29,28 @@ namespace
 
 OUString lclGetFunctionMaskName(const PivotFunc nFunctionMask)
 {
+    sal_uInt16 nStrId = 0;
     switch (nFunctionMask)
     {
-        case PivotFunc::Sum:       return OUString("Sum");
-        case PivotFunc::Count:     return OUString("Count");
-        case PivotFunc::Average:   return OUString("Mean");
-        case PivotFunc::Max:       return OUString("Max");
-        case PivotFunc::Min:       return OUString("Min");
-        case PivotFunc::Product:   return OUString("Product");
-        case PivotFunc::CountNum: return OUString("Count");
-        case PivotFunc::StdDev:   return OUString("StDev");
-        case PivotFunc::StdDevP:  return OUString("StDevP");
-        case PivotFunc::StdVar:   return OUString("Var");
-        case PivotFunc::StdVarP:  return OUString("VarP");
+        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::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;
+        case PivotFunc::CountNum:   nStrId = STR_FUN_TEXT_COUNT;    break;
+        case PivotFunc::StdDev:     nStrId = STR_FUN_TEXT_STDDEV;   break;
+        case PivotFunc::StdDevP:    nStrId = STR_FUN_TEXT_STDDEV;   break;
+        case PivotFunc::StdVar:     nStrId = STR_FUN_TEXT_VAR;      break;
+        case PivotFunc::StdVarP:    nStrId = STR_FUN_TEXT_VAR;      break;
         default:
+            assert(false);
             break;
     }
-    return OUString();
+    if (nStrId != 0)
+        return ScGlobal::GetRscString(nStrId);
+    else
+        return OUString();
 }
 
 OUString lclCreateDataItemName(const PivotFunc nFunctionMask, const OUString& rName, const sal_uInt8 nDuplicationCount)
commit d6cc082b2ca129ea79ab336b45efdfed12123a82
Author: Tamás Zolnai <zolnaitamas2000 at gmail.com>
Date:   Thu Nov 3 11:32:25 2016 +0100

    Remove some unused resource strings
    
    Change-Id: I8529aa491d37aef5e732909357ddf93372dde6d2

diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index 9c94a7c..5833436 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -106,17 +106,6 @@
 #define STR_BOX_YNI                 66
 #define STR_NO_REF_TABLE            67
 
-#define STR_PIVOTFUNC_SUM           68  // pivot.cxx
-#define STR_PIVOTFUNC_COUNT         69
-#define STR_PIVOTFUNC_AVG           70
-#define STR_PIVOTFUNC_MAX           71
-#define STR_PIVOTFUNC_MIN           72
-#define STR_PIVOTFUNC_PROD          73
-#define STR_PIVOTFUNC_COUNT2        74
-#define STR_PIVOTFUNC_STDDEV        75
-#define STR_PIVOTFUNC_STDDEV2       76
-#define STR_PIVOTFUNC_VAR           77
-#define STR_PIVOTFUNC_VAR2          78
 #define STR_PIVOT_TOTAL             79
 #define STR_PIVOT_DATA              80
 
diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src
index 27ef036..241254b 100644
--- a/sc/source/ui/src/globstr.src
+++ b/sc/source/ui/src/globstr.src
@@ -533,50 +533,6 @@ Resource RID_GLOBSTR
     {
         Text [ en-US ] = "Group" ;
     };
-    String STR_PIVOTFUNC_SUM
-    {
-        Text [ en-US ] = "SUM" ;
-    };
-    String STR_PIVOTFUNC_COUNT
-    {
-        Text [ en-US ] = "COUNT" ;
-    };
-    String STR_PIVOTFUNC_AVG
-    {
-        Text [ en-US ] = "AVERAGE" ;
-    };
-    String STR_PIVOTFUNC_MAX
-    {
-        Text [ en-US ] = "MAX" ;
-    };
-    String STR_PIVOTFUNC_MIN
-    {
-        Text [ en-US ] = "MIN" ;
-    };
-    String STR_PIVOTFUNC_PROD
-    {
-        Text [ en-US ] = "PRODUCT" ;
-    };
-    String STR_PIVOTFUNC_COUNT2
-    {
-        Text [ en-US ] = "COUNTA" ;
-    };
-    String STR_PIVOTFUNC_STDDEV
-    {
-        Text [ en-US ] = "STDEV" ;
-    };
-    String STR_PIVOTFUNC_STDDEV2
-    {
-        Text [ en-US ] = "STDEVP" ;
-    };
-    String STR_PIVOTFUNC_VAR
-    {
-        Text [ en-US ] = "VAR" ;
-    };
-    String STR_PIVOTFUNC_VAR2
-    {
-        Text [ en-US ] = "VARP" ;
-    };
     String STR_TABLE
     {
         Text [ en-US ] = "Sheet" ;
commit 31bc7ce07ac8e6d0c0ad4c9bbf9e41a2b79f17b4
Author: Tamás Zolnai <zolnaitamas2000 at gmail.com>
Date:   Thu Nov 3 02:05:46 2016 +0100

    Remove unused macro
    
    Change-Id: I407217703d285fc858208cbcdfae0fe84a30fcee

diff --git a/sc/inc/dpglobal.hxx b/sc/inc/dpglobal.hxx
index e6ca2c2..7c82541 100644
--- a/sc/inc/dpglobal.hxx
+++ b/sc/inc/dpglobal.hxx
@@ -22,8 +22,6 @@
 
 #include <o3tl/typed_flags_set.hxx>
 
-#define     PIVOT_MAXFUNC           11
-
 enum class PivotFunc {
     NONE         = 0x0000,
     Sum          = 0x0001,


More information about the Libreoffice-commits mailing list