chart2/qa/extras/PivotChartTest.cxx                     |   64 ++-
 chart2/qa/extras/charttest.hxx                          |   61 +++
 chart2/qa/extras/data/ods/PivotChart_PivotTableOnly.ods |binary
 dev/null                                                |binary
 offapi/UnoApi_offapi.mk                                 |    3 
 offapi/com/sun/star/table/XTablePivotChart.idl          |   31 +
 offapi/com/sun/star/table/XTablePivotCharts.idl         |   59 +++
 offapi/com/sun/star/table/XTablePivotChartsSupplier.idl |   40 ++
 sc/Library_sc.mk                                        |    3 
 sc/inc/ChartTools.hxx                                   |   50 ++
 sc/inc/TablePivotChart.hxx                              |   72 ++++
 sc/inc/TablePivotCharts.hxx                             |   77 ++++
 sc/inc/cellsuno.hxx                                     |    6 
 sc/source/ui/unoobj/ChartTools.cxx                      |  127 +++++++
 sc/source/ui/unoobj/TablePivotChart.cxx                 |   78 ++++
 sc/source/ui/unoobj/TablePivotCharts.cxx                |  279 ++++++++++++++++
 sc/source/ui/unoobj/cellsuno.cxx                        |   17 
 sc/source/ui/unoobj/chartuno.cxx                        |   48 --
 18 files changed, 951 insertions(+), 64 deletions(-)

New commits:
commit b0f0f3f727516ba8f9b39e20308d76edf3a63500
Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
Date:   Sun Apr 2 10:44:11 2017 +0200

    Add table pivot chart supplier API, update tests
    
    This adds the XTablePivotChartSupplier and related interfaces so
    we can access, create, delete pivot charts from UNO in a sheet
    document. With this we now distinguish between normal charts
    and pivot charts. This was mainly needed because we can't extend
    the "published" interfaces of TableChartSupplier.
    
    Updated the test framework in chart2 to use the new interfaces.
    
    Added an extensive test, which uses the API to create a new pivot
    chart when there was none, and checks that the pivot chart updates
    when the pivot table updates.
    
    Change-Id: I05891b44aac7bb780e04e31292eac244af0443d4

diff --git a/chart2/qa/extras/PivotChartTest.cxx 
b/chart2/qa/extras/PivotChartTest.cxx
index b54888ef2a2f..f0f5b8911222 100644
--- a/chart2/qa/extras/PivotChartTest.cxx
+++ b/chart2/qa/extras/PivotChartTest.cxx
@@ -17,6 +17,9 @@
 #include <com/sun/star/sheet/XSpreadsheet.hpp>
 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
 #include <com/sun/star/sheet/XSpreadsheets.hpp>
+#include <com/sun/star/table/XTablePivotChart.hpp>
+#include <com/sun/star/table/XTablePivotCharts.hpp>
+#include <com/sun/star/table/XTablePivotChartsSupplier.hpp>
 
 #include <rtl/strbuf.hxx>
 
@@ -73,6 +76,12 @@ bool lclCheckSequence(std::vector<double> const & reference,
     return true;
 }
 
+OUString lclGetLabel(Reference<chart2::XChartDocument> xChartDoc, sal_Int32 
nSeriesIndex)
+{
+    Reference<chart2::data::XDataSequence> xLabelDataSequence = 
getLabelDataSequenceFromDoc(xChartDoc, nSeriesIndex);
+    return xLabelDataSequence->getData()[0].get<OUString>();
+}
+
 void PivotChartTest::testRoundtrip()
 {
     uno::Sequence<uno::Any> xSequence;
@@ -80,7 +89,7 @@ void PivotChartTest::testRoundtrip()
 
     load("/chart2/qa/extras/data/ods/", "PivotChart.ods");
 
-    xChartDoc = Reference<chart2::XChartDocument>(getChartDocFromSheet(1, 
mxComponent), uno::UNO_QUERY);
+    xChartDoc = Reference<chart2::XChartDocument>(getPivotChartDocFromSheet(1, 
mxComponent), uno::UNO_QUERY);
 
     std::vector<double> aReference1 { 10162.033139, 16614.523063, 27944.146101 
};
     OUString aExpectedLabel1("Exp.");
@@ -114,7 +123,7 @@ void PivotChartTest::testRoundtrip()
 
     reload("calc8");
 
-    xChartDoc = Reference<chart2::XChartDocument>(getChartDocFromSheet(1, 
mxComponent), uno::UNO_QUERY);
+    xChartDoc = Reference<chart2::XChartDocument>(getPivotChartDocFromSheet(1, 
mxComponent), uno::UNO_QUERY);
     CPPUNIT_ASSERT(xChartDoc.is());
     {
         Reference<chart2::data::XDataSequence> xDataSequence = 
getDataSequenceFromDocByRole(xChartDoc, "values-y", 0);
@@ -140,17 +149,28 @@ void PivotChartTest::testRoundtrip()
     }
 }
 
-
 void PivotChartTest::testChangePivotTable()
 {
     uno::Sequence<uno::Any> xSequence;
     Reference<chart2::XChartDocument> xChartDoc;
 
-    load("/chart2/qa/extras/data/ods/", "PivotChart2.ods");
+    load("/chart2/qa/extras/data/ods/", "PivotChart_PivotTableOnly.ods");
+
+    // Check that we don't have any pivot chart in the document
+    uno::Reference<table::XTablePivotCharts> xTablePivotCharts = 
getTablePivotChartsFromSheet(1, mxComponent);
+    uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, 
UNO_QUERY_THROW);
+    CPPUNIT_ASSERT_EQUAL(0, xIndexAccess->getCount());
+
+    // Create a new pivot chart
+    xTablePivotCharts->addNewByName("Chart", awt::Rectangle{0, 0, 9000, 9000}, 
"DataPilot1");
+    CPPUNIT_ASSERT_EQUAL(1, xIndexAccess->getCount());
 
-    xChartDoc = Reference<chart2::XChartDocument>(getChartDocFromSheet(1, 
mxComponent), uno::UNO_QUERY);
+    // Get the pivot chart document so we ca access its data
+    xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
 
     CPPUNIT_ASSERT(xChartDoc.is());
+
+    // Check first data series
     {
         std::vector<double> aReference { 10162.033139, 16614.523063, 
27944.146101 };
         OUString aExpectedLabel("Exp.");
@@ -159,10 +179,10 @@ void PivotChartTest::testChangePivotTable()
         xSequence = xDataSequence->getData();
         CPPUNIT_ASSERT(lclCheckSequence(aReference, xSequence, 1E-4));
 
-        Reference<chart2::data::XDataSequence> xLabelDataSequence = 
getLabelDataSequenceFromDoc(xChartDoc, 0);
-        xSequence = xLabelDataSequence->getData();
-        CPPUNIT_ASSERT_EQUAL(aExpectedLabel, xSequence[0].get<OUString>());
+        CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 0));
     }
+
+    // Check second data series
     {
         std::vector<double> aReference { 101879.458079, 178636.929704, 
314626.484864 };
         OUString aExpectedLabel("Rev.");
@@ -171,13 +191,10 @@ void PivotChartTest::testChangePivotTable()
         xSequence = xDataSequence->getData();
         CPPUNIT_ASSERT(lclCheckSequence(aReference, xSequence, 1E-4));
 
-        Reference<chart2::data::XDataSequence> xLabelDataSequence = 
getLabelDataSequenceFromDoc(xChartDoc, 1);
-        xSequence = xLabelDataSequence->getData();
-        CPPUNIT_ASSERT_EQUAL(aExpectedLabel, xSequence[0].get<OUString>());
+        CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 1));
     }
 
-    // modify the pivot table
-
+    // Modify the pivot table
     {
         uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, 
UNO_QUERY_THROW);
         uno::Reference<container::XIndexAccess> 
xSheetIndexAccess(xDoc->getSheets(), UNO_QUERY_THROW);
@@ -194,10 +211,11 @@ void PivotChartTest::testChangePivotTable()
         lclModifyOrientation(xDataPilotDescriptor, "Rev.", 
sheet::DataPilotFieldOrientation_HIDDEN);
     }
 
-    // check again
+    // Check the pivot chart again as we expect it has been updated when we 
updated the pivot table
 
-    xChartDoc = Reference<chart2::XChartDocument>(getChartDocFromSheet(1, 
mxComponent), uno::UNO_QUERY);
     CPPUNIT_ASSERT(xChartDoc.is());
+
+    // Check the first data series
     {
         std::vector<double> aReference { 2855.559, 1780.326, 2208.713, 
2130.064, 1187.371 };
         OUString aExpectedLabel("Big");
@@ -206,10 +224,10 @@ void PivotChartTest::testChangePivotTable()
         xSequence = xDataSequence->getData();
         CPPUNIT_ASSERT(lclCheckSequence(aReference, xSequence, 1E-3));
 
-        Reference<chart2::data::XDataSequence> xLabelDataSequence = 
getLabelDataSequenceFromDoc(xChartDoc, 0);
-        xSequence = xLabelDataSequence->getData();
-        CPPUNIT_ASSERT_EQUAL(aExpectedLabel, xSequence[0].get<OUString>());
+        CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 0));
     }
+
+    // Check the second data series
     {
         std::vector<double> aReference { 4098.908, 2527.286, 4299.716, 
2362.225, 3326.389 };
         OUString aExpectedLabel("Medium");
@@ -218,10 +236,10 @@ void PivotChartTest::testChangePivotTable()
         xSequence = xDataSequence->getData();
         CPPUNIT_ASSERT(lclCheckSequence(aReference, xSequence, 1E-3));
 
-        Reference<chart2::data::XDataSequence> xLabelDataSequence = 
getLabelDataSequenceFromDoc(xChartDoc, 1);
-        xSequence = xLabelDataSequence->getData();
-        CPPUNIT_ASSERT_EQUAL(aExpectedLabel, xSequence[0].get<OUString>());
+        CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 1));
     }
+
+    // Check the third data series
     {
         std::vector<double> aReference { 4926.303, 5684.060, 4201.398, 
7290.795, 5841.591 };
         OUString aExpectedLabel("Small");
@@ -230,9 +248,7 @@ void PivotChartTest::testChangePivotTable()
         xSequence = xDataSequence->getData();
         CPPUNIT_ASSERT(lclCheckSequence(aReference, xSequence, 1E-3));
 
-        Reference<chart2::data::XDataSequence> xLabelDataSequence = 
getLabelDataSequenceFromDoc(xChartDoc, 2);
-        xSequence = xLabelDataSequence->getData();
-        CPPUNIT_ASSERT_EQUAL(aExpectedLabel, xSequence[0].get<OUString>());
+        CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 2));
     }
 }
 
diff --git a/chart2/qa/extras/charttest.hxx b/chart2/qa/extras/charttest.hxx
index 1d2f4afe9150..e121664a9581 100644
--- a/chart2/qa/extras/charttest.hxx
+++ b/chart2/qa/extras/charttest.hxx
@@ -24,6 +24,9 @@
 #include <com/sun/star/table/XTableChartsSupplier.hpp>
 #include <com/sun/star/table/XTableCharts.hpp>
 #include <com/sun/star/table/XTableChart.hpp>
+#include <com/sun/star/table/XTablePivotChartsSupplier.hpp>
+#include <com/sun/star/table/XTablePivotCharts.hpp>
+#include <com/sun/star/table/XTablePivotChart.hpp>
 #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/frame/XStorable.hpp>
@@ -213,6 +216,64 @@ Reference< chart2::XChartDocument > getChartDocFromSheet( 
sal_Int32 nSheet, uno:
     return xChartDoc;
 }
 
+uno::Reference<table::XTablePivotCharts> 
getTablePivotChartsFromSheet(sal_Int32 nSheet, uno::Reference<lang::XComponent> 
const & xComponent)
+{
+    uno::Reference<sheet::XSpreadsheetDocument> xDoc(xComponent, 
UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xDoc.is());
+
+    uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), 
UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xIA.is());
+
+    uno::Reference<table::XTablePivotChartsSupplier> 
xChartSupplier(xIA->getByIndex(nSheet), UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xChartSupplier.is());
+
+    uno::Reference<table::XTablePivotCharts> xTablePivotCharts = 
xChartSupplier->getPivotCharts();
+    CPPUNIT_ASSERT(xTablePivotCharts.is());
+
+    return xTablePivotCharts;
+}
+
+Reference<lang::XComponent> getPivotChartCompFromSheet(sal_Int32 nSheet, 
uno::Reference<lang::XComponent> const & xComponent)
+{
+    uno::Reference<table::XTablePivotCharts> xTablePivotCharts = 
getTablePivotChartsFromSheet(nSheet, xComponent);
+
+    uno::Reference<container::XIndexAccess> xIACharts(xTablePivotCharts, 
UNO_QUERY_THROW);
+    uno::Reference<table::XTablePivotChart> 
xTablePivotChart(xIACharts->getByIndex(0), UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xTablePivotChart.is());
+
+    uno::Reference<document::XEmbeddedObjectSupplier> 
xEmbObjectSupplier(xTablePivotChart, UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xEmbObjectSupplier.is());
+
+    uno::Reference<lang::XComponent> 
xChartComp(xEmbObjectSupplier->getEmbeddedObject(), UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xChartComp.is());
+
+    return xChartComp;
+}
+
+Reference<chart2::XChartDocument> getPivotChartDocFromSheet(sal_Int32 nSheet, 
uno::Reference<lang::XComponent> const & xComponent)
+{
+    uno::Reference<chart2::XChartDocument> 
xChartDoc(getPivotChartCompFromSheet(nSheet, xComponent), UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xChartDoc.is());
+    return xChartDoc;
+}
+
+Reference<chart2::XChartDocument> 
getPivotChartDocFromSheet(uno::Reference<table::XTablePivotCharts> 
xTablePivotCharts, sal_Int32 nIndex)
+{
+    uno::Reference<container::XIndexAccess> xIACharts(xTablePivotCharts, 
UNO_QUERY_THROW);
+    uno::Reference<table::XTablePivotChart> 
xTablePivotChart(xIACharts->getByIndex(nIndex), UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xTablePivotChart.is());
+
+    uno::Reference<document::XEmbeddedObjectSupplier> 
xEmbObjectSupplier(xTablePivotChart, UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xEmbObjectSupplier.is());
+
+    uno::Reference<lang::XComponent> 
xChartComp(xEmbObjectSupplier->getEmbeddedObject(), UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xChartComp.is());
+
+    uno::Reference<chart2::XChartDocument> xChartDoc(xChartComp, 
UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xChartDoc.is());
+    return xChartDoc;
+}
+
 Reference< chart2::XChartType > getChartTypeFromDoc( Reference< 
chart2::XChartDocument > const & xChartDoc,
                                                                 sal_Int32 
nChartType, sal_Int32 nCooSys = 0 )
 {
diff --git a/chart2/qa/extras/data/ods/PivotChart2.ods 
b/chart2/qa/extras/data/ods/PivotChart2.ods
deleted file mode 100644
index c34521e0bc52..000000000000
Binary files a/chart2/qa/extras/data/ods/PivotChart2.ods and /dev/null differ
diff --git a/chart2/qa/extras/data/ods/PivotChart_PivotTableOnly.ods 
b/chart2/qa/extras/data/ods/PivotChart_PivotTableOnly.ods
new file mode 100644
index 000000000000..bc8df8170208
Binary files /dev/null and 
b/chart2/qa/extras/data/ods/PivotChart_PivotTableOnly.ods differ
diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index f38e6e56408d..72c34971fc7f 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -3639,6 +3639,9 @@ $(eval $(call 
gb_UnoApi_add_idlfiles,offapi,com/sun/star/table,\
        XTableChart \
        XTableCharts \
        XTableChartsSupplier \
+       XTablePivotChart \
+       XTablePivotCharts \
+       XTablePivotChartsSupplier \
        XTableColumns \
        XTableRows \
 ))
diff --git a/offapi/com/sun/star/table/XTablePivotChart.idl 
b/offapi/com/sun/star/table/XTablePivotChart.idl
new file mode 100644
index 000000000000..17ab22f9a631
--- /dev/null
+++ b/offapi/com/sun/star/table/XTablePivotChart.idl
@@ -0,0 +1,31 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef __com_sun_star_table_XTablePivotChart_idl__
+#define __com_sun_star_table_XTablePivotChart_idl__
+
+#include <com/sun/star/uno/XInterface.idl>
+
+module com {  module sun {  module star {  module table {
+
+
+/** provides access to the settings of a pivot chart object in a
+    table or spreadsheet.
+ */
+interface XTablePivotChart: com::sun::star::uno::XInterface
+{
+
+};
+
+}; }; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/offapi/com/sun/star/table/XTablePivotCharts.idl 
b/offapi/com/sun/star/table/XTablePivotCharts.idl
new file mode 100644
index 000000000000..28c84a70a3fd
--- /dev/null
+++ b/offapi/com/sun/star/table/XTablePivotCharts.idl
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef __com_sun_star_table_XTablePivotCharts_idl__
+#define __com_sun_star_table_XTablePivotCharts_idl__
+
+#include <com/sun/star/container/XNameAccess.idl>
+#include <com/sun/star/awt/Rectangle.idl>
+
+
+module com {  module sun {  module star {  module table {
+
+
+/** provides methods to access pivot charts via name and to insert
+    and remove pivot charts.
+
+    @see com::sun::star::table::TablePivotCharts
+ */
+interface XTablePivotCharts: com::sun::star::container::XNameAccess
+{
+
+    /** creates a pivot chart and adds it to the collection.
+
+        @param aName
+            is the name of the chart. This name is used to reference the
+            chart in the collection.
+
+        @param aRect
+            contains the rectangular location of the chart within the table
+            (in 1/100th mm).
+
+        @param aPivotTableName
+            the name of the pivot table (data pilot) to associate the pivot 
chart with
+     */
+    void addNewByName(
+            [in] string aName,
+            [in] com::sun::star::awt::Rectangle aRect,
+            [in] string aPivotTableName);
+
+
+    /** removes a pivot chart from the collection.
+
+        @param aName
+            is the name of the chart to remove.
+     */
+    void removeByName([in] string aName);
+};
+
+}; }; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/offapi/com/sun/star/table/XTablePivotChartsSupplier.idl 
b/offapi/com/sun/star/table/XTablePivotChartsSupplier.idl
new file mode 100644
index 000000000000..712638c13ceb
--- /dev/null
+++ b/offapi/com/sun/star/table/XTablePivotChartsSupplier.idl
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef __com_sun_star_table_XTablePivotChartsSupplier_idl__
+#define __com_sun_star_table_XTablePivotChartsSupplier_idl__
+
+#include <com/sun/star/uno/XInterface.idl>
+#include <com/sun/star/table/XTablePivotCharts.idl>
+
+
+module com {  module sun {  module star {  module table {
+
+
+/** provides a method to access a collection of pivot charts in a table
+    or spreadsheet.
+ */
+interface XTablePivotChartsSupplier: com::sun::star::uno::XInterface
+{
+
+    /** returns the collection of pivot charts.
+
+        @see com::sun::star::table::TablePivotCharts
+     */
+    com::sun::star::table::XTablePivotCharts getPivotCharts();
+
+};
+
+
+}; }; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 14ddec0d0edc..e2a4af8c6be2 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -576,6 +576,9 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
     sc/source/ui/unoobj/PivotChartDataProvider \
     sc/source/ui/unoobj/PivotChartDataSource \
     sc/source/ui/unoobj/PivotChartDataSequence \
+    sc/source/ui/unoobj/TablePivotCharts \
+    sc/source/ui/unoobj/TablePivotChart \
+    sc/source/ui/unoobj/ChartTools \
     sc/source/ui/unoobj/servuno \
     sc/source/ui/unoobj/shapeuno \
     sc/source/ui/unoobj/srchuno \
diff --git a/sc/inc/ChartTools.hxx b/sc/inc/ChartTools.hxx
new file mode 100644
index 000000000000..dc9a5c52fb5b
--- /dev/null
+++ b/sc/inc/ChartTools.hxx
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_SC_INC_CHARTTOOLS_HXX
+#define INCLUDED_SC_INC_CHARTTOOLS_HXX
+
+#include <svx/svdoole2.hxx>
+#include <svx/svditer.hxx>
+
+#include "docsh.hxx"
+#include "drwlayer.hxx"
+
+namespace sc {
+namespace tools {
+
+enum class ChartSourceType
+{
+    CELL_RANGE,
+    PIVOT_TABLE
+};
+
+class ChartIterator
+{
+private:
+    std::unique_ptr<SdrObjListIter> m_pIterator;
+    ChartSourceType m_eChartSourceType;
+public:
+    ChartIterator(ScDocShell* pDocShell, SCTAB nTab, ChartSourceType 
eChartSourceType);
+    SdrOle2Obj* next();
+};
+
+SdrOle2Obj* findChartsByName(ScDocShell* pDocShell, SCTAB nTab,
+                             OUString const & rName,
+                             ChartSourceType eChartSourceType);
+
+SdrOle2Obj* getChartByIndex(ScDocShell* pDocShell, SCTAB nTab,
+                            long nIndex, ChartSourceType eChartSourceType);
+
+}} // end sc::tools
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/TablePivotChart.hxx b/sc/inc/TablePivotChart.hxx
new file mode 100644
index 000000000000..d699f7323883
--- /dev/null
+++ b/sc/inc/TablePivotChart.hxx
@@ -0,0 +1,72 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_SC_INC_TABLEPIVOTCHART_HXX
+#define INCLUDED_SC_INC_TABLEPIVOTCHART_HXX
+
+#include <com/sun/star/table/XTablePivotChart.hpp>
+#include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/container/XNamed.hpp>
+
+#include <svl/lstner.hxx>
+#include <cppuhelper/compbase.hxx>
+#include <cppuhelper/implbase.hxx>
+
+#include "types.hxx"
+
+class ScDocShell;
+
+namespace sc
+{
+
+typedef cppu::WeakComponentImplHelper<css::table::XTablePivotChart,
+                                      css::document::XEmbeddedObjectSupplier,
+                                      css::container::XNamed,
+                                      css::lang::XServiceInfo>
+        TablePivotChart_Base;
+
+class TablePivotChart : public cppu::BaseMutex,
+                        public TablePivotChart_Base,
+                        public SfxListener
+{
+private:
+    ScDocShell* m_pDocShell;
+    SCTAB m_nTab; // Charts are per sheet
+    OUString m_aChartName;
+
+public:
+    TablePivotChart(ScDocShell* pDocSh, SCTAB nTab, OUString const & rName);
+    virtual ~TablePivotChart() override;
+
+    virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
+
+    // XComponent
+    using TablePivotChart_Base::disposing;
+
+    // XEmbeddedObjectSupplier
+    virtual css::uno::Reference<css::lang::XComponent> SAL_CALL
+        getEmbeddedObject() override;
+
+    // XNamed
+    virtual OUString SAL_CALL getName() override;
+    virtual void SAL_CALL setName(OUString const & aName) override;
+
+    // XServiceInfo
+    virtual OUString SAL_CALL getImplementationName() override;
+    virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) 
override;
+    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() 
override;
+};
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/TablePivotCharts.hxx b/sc/inc/TablePivotCharts.hxx
new file mode 100644
index 000000000000..13e941481277
--- /dev/null
+++ b/sc/inc/TablePivotCharts.hxx
@@ -0,0 +1,77 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_SC_INC_TABLEPIVOTCHARTS_HXX
+#define INCLUDED_SC_INC_TABLEPIVOTCHARTS_HXX
+
+#include <com/sun/star/table/XTablePivotCharts.hpp>
+#include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/container/XEnumerationAccess.hpp>
+#include <com/sun/star/container/XIndexAccess.hpp>
+
+#include <svl/lstner.hxx>
+#include <cppuhelper/compbase.hxx>
+#include <cppuhelper/implbase.hxx>
+
+#include "types.hxx"
+
+class ScDocShell;
+
+namespace sc
+{
+typedef cppu::WeakImplHelper<css::table::XTablePivotCharts,
+                             css::container::XIndexAccess,
+                             css::lang::XServiceInfo>
+        TablePivotCharts_Base;
+
+class TablePivotCharts : public TablePivotCharts_Base, public SfxListener
+{
+private:
+    ScDocShell* m_pDocShell;
+    SCTAB m_nTab;
+
+public:
+    TablePivotCharts(ScDocShell* pDocSh, SCTAB nTab);
+
+    virtual ~TablePivotCharts() override;
+
+    virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
+
+    // XTablePivotCharts
+    virtual void SAL_CALL addNewByName(OUString const & aName,
+                                       const css::awt::Rectangle& aRect,
+                                       OUString const & aDataPilotName) 
override;
+    virtual void SAL_CALL removeByName(OUString const & aName) override;
+
+    // XNameAccess
+    virtual css::uno::Any SAL_CALL getByName(OUString const & aName) override;
+    virtual css::uno::Sequence<OUString> SAL_CALL getElementNames() override;
+    virtual sal_Bool SAL_CALL hasByName(OUString const & aName) override;
+
+    // XIndexAccess
+    virtual sal_Int32 SAL_CALL getCount() override;
+    virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override;
+
+    // XElementAccess
+    virtual css::uno::Type SAL_CALL getElementType() override;
+    virtual sal_Bool SAL_CALL hasElements() override;
+
+    // XServiceInfo
+    virtual OUString SAL_CALL getImplementationName() override;
+    virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) 
override;
+    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() 
override;
+};
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/cellsuno.hxx b/sc/inc/cellsuno.hxx
index aded180f3f69..95cef41b70f2 100644
--- a/sc/inc/cellsuno.hxx
+++ b/sc/inc/cellsuno.hxx
@@ -31,6 +31,7 @@
 #include <svl/listener.hxx>
 #include <svl/itemprop.hxx>
 #include <com/sun/star/table/XTableChartsSupplier.hpp>
+#include <com/sun/star/table/XTablePivotChartsSupplier.hpp>
 #include <com/sun/star/chart/XChartDataArray.hpp>
 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
@@ -771,6 +772,7 @@ class ScTableSheetObj : public ScCellRangeObj,
                         public css::sheet::XSheetPageBreak,
                         public css::sheet::XCellRangeMovement,
                         public css::table::XTableChartsSupplier,
+                        public css::table::XTablePivotChartsSupplier,
                         public css::sheet::XDataPilotTablesSupplier,
                         public css::sheet::XScenariosSupplier,
                         public css::sheet::XSheetAnnotationsSupplier,
@@ -856,6 +858,10 @@ public:
     virtual css::uno::Reference< css::table::XTableCharts > SAL_CALL
                             getCharts() override;
 
+                            // XTablePivotChartsSupplier
+    virtual css::uno::Reference<css::table::XTablePivotCharts> SAL_CALL
+                            getPivotCharts() override;
+
                             // XDataPilotTablesSupplier
     virtual css::uno::Reference< css::sheet::XDataPilotTables > SAL_CALL
                             getDataPilotTables() override;
diff --git a/sc/source/ui/unoobj/ChartTools.cxx 
b/sc/source/ui/unoobj/ChartTools.cxx
new file mode 100644
index 000000000000..12d6478f69c9
--- /dev/null
+++ b/sc/source/ui/unoobj/ChartTools.cxx
@@ -0,0 +1,127 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include "ChartTools.hxx"
+
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/chart2/data/XPivotChartDataProvider.hpp>
+
+#include <svx/svditer.hxx>
+#include <svx/svdpage.hxx>
+#include <svx/svdundo.hxx>
+#include <sfx2/app.hxx>
+#include <unotools/moduleoptions.hxx>
+#include <comphelper/classids.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <tools/globname.hxx>
+#include <svx/charthelper.hxx>
+#include <svtools/embedhlp.hxx>
+
+using namespace css;
+
+namespace sc {
+namespace tools {
+
+ChartIterator::ChartIterator(ScDocShell* pDocShell, SCTAB nTab, 
ChartSourceType eChartSourceType)
+    : m_eChartSourceType(eChartSourceType)
+{
+    if (!pDocShell)
+        return;
+    ScDocument& rDoc = pDocShell->GetDocument();
+    ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
+    if (!pDrawLayer)
+        return;
+    SdrPage* pPage = pDrawLayer->GetPage(sal_uInt16(nTab));
+    if (!pPage)
+        return;
+    m_pIterator.reset(new SdrObjListIter(*pPage, SdrIterMode::DeepNoGroups));
+}
+
+SdrOle2Obj* ChartIterator::next()
+{
+    if (!m_pIterator)
+        return nullptr;
+
+    SdrObject* pObject = m_pIterator->Next();
+    while (pObject)
+    {
+        if (pObject->GetObjIdentifier() == OBJ_OLE2 && 
ScDocument::IsChart(pObject))
+        {
+            SdrOle2Obj* pOleObject = static_cast<SdrOle2Obj*>(pObject);
+            uno::Reference<embed::XEmbeddedObject> xObject = 
pOleObject->GetObjRef();
+            if (xObject.is())
+            {
+                uno::Reference<chart2::XChartDocument> 
xChartDoc(xObject->getComponent(), uno::UNO_QUERY);
+                if (xChartDoc.is())
+                {
+                    uno::Reference<chart2::data::XPivotChartDataProvider> 
xPivotChartDataProvider(xChartDoc->getDataProvider(), uno::UNO_QUERY);
+                    if (xPivotChartDataProvider.is() && m_eChartSourceType == 
ChartSourceType::PIVOT_TABLE)
+                    {
+                        return pOleObject;
+                    }
+                    else if (!xPivotChartDataProvider.is() && 
m_eChartSourceType == ChartSourceType::CELL_RANGE)
+                    {
+                        return pOleObject;
+                    }
+                }
+            }
+        }
+        pObject = m_pIterator->Next();
+    }
+    return nullptr;
+}
+
+SdrOle2Obj* findChartsByName(ScDocShell* pDocShell, SCTAB nTab, OUString const 
& rName, ChartSourceType eChartSourceType)
+{
+    if (!pDocShell)
+        return nullptr;
+
+    ChartIterator aIterator(pDocShell, nTab, eChartSourceType);
+
+    SdrOle2Obj* pObject = aIterator.next();
+    while (pObject)
+    {
+        uno::Reference<embed::XEmbeddedObject> xObject = pObject->GetObjRef();
+        if (xObject.is())
+        {
+            OUString aObjectName = 
pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName(xObject);
+            if (aObjectName == rName)
+                return pObject;
+        }
+        pObject = aIterator.next();
+    }
+    return nullptr;
+}
+
+SdrOle2Obj* getChartByIndex(ScDocShell* pDocShell, SCTAB nTab, long nIndex, 
ChartSourceType eChartSourceType)
+{
+    if (!pDocShell)
+        return nullptr;
+
+    ChartIterator aIterator(pDocShell, nTab, eChartSourceType);
+
+    SdrOle2Obj* pObject = aIterator.next();
+    long i = 0;
+    while (pObject)
+    {
+        if (i == nIndex)
+        {
+            return pObject;
+        }
+
+        i++;
+        pObject = aIterator.next();
+    }
+    return nullptr;
+}
+
+}} // end sc::tools
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/unoobj/TablePivotChart.cxx 
b/sc/source/ui/unoobj/TablePivotChart.cxx
new file mode 100644
index 000000000000..976190d0fe42
--- /dev/null
+++ b/sc/source/ui/unoobj/TablePivotChart.cxx
@@ -0,0 +1,78 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <svx/charthelper.hxx>
+#include <svtools/embedhlp.hxx>
+
+#include "miscuno.hxx"
+#include "docsh.hxx"
+
+#include "TablePivotChart.hxx"
+#include "ChartTools.hxx"
+
+using namespace css;
+
+namespace sc
+{
+
+SC_SIMPLE_SERVICE_INFO(TablePivotChart, "TablePivotChart", 
"com.sun.star.table.TablePivotChart")
+
+TablePivotChart::TablePivotChart(ScDocShell* pDocShell, SCTAB nTab, const 
OUString& rName)
+    : TablePivotChart_Base(m_aMutex)
+    , m_pDocShell(pDocShell)
+    , m_nTab(nTab)
+    , m_aChartName(rName)
+{
+    if (m_pDocShell)
+        m_pDocShell->GetDocument().AddUnoObject(*this);
+}
+
+TablePivotChart::~TablePivotChart()
+{
+    SolarMutexGuard aGuard;
+
+    if (m_pDocShell)
+        m_pDocShell->GetDocument().RemoveUnoObject(*this);
+}
+
+void TablePivotChart::Notify(SfxBroadcaster&, const SfxHint& rHint)
+{
+    if (rHint.GetId() == SfxHintId::Dying)
+        m_pDocShell = nullptr;
+}
+
+// XEmbeddedObjectSupplier
+
+uno::Reference<lang::XComponent> SAL_CALL TablePivotChart::getEmbeddedObject()
+{
+    SolarMutexGuard aGuard;
+    SdrOle2Obj* pObject = sc::tools::findChartsByName(m_pDocShell, m_nTab, 
m_aChartName, sc::tools::ChartSourceType::PIVOT_TABLE);
+    if (pObject && 
svt::EmbeddedObjectRef::TryRunningState(pObject->GetObjRef()))
+        return 
uno::Reference<lang::XComponent>(pObject->GetObjRef()->getComponent(), 
uno::UNO_QUERY);
+    return nullptr;
+}
+
+// XNamed
+
+OUString SAL_CALL TablePivotChart::getName()
+{
+    SolarMutexGuard aGuard;
+    return m_aChartName;
+}
+
+void SAL_CALL TablePivotChart::setName(OUString const & /* aName */)
+{
+    SolarMutexGuard aGuard;
+    throw uno::RuntimeException(); // name cannot be changed
+}
+
+} // end sc namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/unoobj/TablePivotCharts.cxx 
b/sc/source/ui/unoobj/TablePivotCharts.cxx
new file mode 100644
index 000000000000..91fcebd88c20
--- /dev/null
+++ b/sc/source/ui/unoobj/TablePivotCharts.cxx
@@ -0,0 +1,279 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <com/sun/star/embed/Aspects.hpp>
+#include <com/sun/star/awt/Size.hpp>
+#include <com/sun/star/chart/ChartDataRowSource.hpp>
+#include <com/sun/star/chart2/data/XDataReceiver.hpp>
+#include <com/sun/star/chart2/XChartDocument.hpp>
+#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
+
+#include <svx/svditer.hxx>
+#include <svx/svdoole2.hxx>
+#include <svx/svdpage.hxx>
+#include <svx/svdundo.hxx>
+#include <svx/charthelper.hxx>
+#include <sfx2/app.hxx>
+#include <unotools/moduleoptions.hxx>
+#include <comphelper/classids.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <tools/globname.hxx>
+#include <svtools/embedhlp.hxx>
+#include <comphelper/sequence.hxx>
+
+#include "TablePivotChart.hxx"
+#include "TablePivotCharts.hxx"
+#include "PivotChartDataProvider.hxx"
+#include "ChartTools.hxx"
+
+#include "miscuno.hxx"
+#include "docsh.hxx"
+#include "drwlayer.hxx"
+#include "undodat.hxx"
+#include "convuno.hxx"
+
+using namespace css;
+
+namespace sc
+{
+
+SC_SIMPLE_SERVICE_INFO(TablePivotCharts, "TablePivotCharts", 
"com.sun.star.table.TablePivotCharts")
+
+TablePivotCharts::TablePivotCharts(ScDocShell* pDocShell, SCTAB nTab)
+    : m_pDocShell(pDocShell)
+    , m_nTab(nTab)
+{
+    m_pDocShell->GetDocument().AddUnoObject(*this);
+}
+
+TablePivotCharts::~TablePivotCharts()
+{
+    SolarMutexGuard aGuard;
+
+    if (m_pDocShell)
+        m_pDocShell->GetDocument().RemoveUnoObject(*this);
+}
+
+void TablePivotCharts::Notify( SfxBroadcaster&, const SfxHint& rHint )
+{
+    if (rHint.GetId() == SfxHintId::Dying)
+        m_pDocShell = nullptr;
+}
+
+// XTablePivotCharts
+void SAL_CALL TablePivotCharts::addNewByName(OUString const & rName,
+                                             const awt::Rectangle& aRect,
+                                             OUString const & rDataPilotName)
+{
+    SolarMutexGuard aGuard;
+
+    if (!m_pDocShell)
+        return;
+
+    ScDocument& rDoc = m_pDocShell->GetDocument();
+    ScDrawLayer* pModel = m_pDocShell->MakeDrawLayer();
+    SdrPage* pPage = pModel->GetPage(sal_uInt16(m_nTab));
+    if (!pPage)
+        return;
+
+    //  chart can't be inserted if any ole object with that name exists on any 
table
+    //  (empty string: generate valid name)
+
+    OUString aName = rName;
+    SCTAB nDummy;
+    if (!aName.isEmpty() && pModel->GetNamedObject(aName, OBJ_OLE2, nDummy))
+    {
+        //  object exists - only RuntimeException is specified
+        throw uno::RuntimeException();
+    }
+
+    uno::Reference<embed::XEmbeddedObject> xObject;
+
+    if (SvtModuleOptions().IsChart())
+        xObject = 
m_pDocShell->GetEmbeddedObjectContainer().CreateEmbeddedObject(SvGlobalName(SO3_SCH_CLASSID).GetByteSequence(),
 aName);
+
+    if (xObject.is())
+    {
+            Point aRectPos(aRect.X, aRect.Y);
+            bool bLayoutRTL = rDoc.IsLayoutRTL(m_nTab);
+            if ((aRectPos.X() < 0 && !bLayoutRTL) || (aRectPos.X() > 0 && 
bLayoutRTL))
+                aRectPos.X() = 0;
+
+            if (aRectPos.Y() < 0)
+                aRectPos.Y() = 0;
+
+            Size aRectSize(aRect.Width, aRect.Height);
+            if (aRectSize.Width() <= 0)
+                aRectSize.Width() = 5000; // default size
+
+            if (aRectSize.Height() <= 0)
+                aRectSize.Height() = 5000;
+
+            Rectangle aInsRect(aRectPos, aRectSize);
+
+            sal_Int64 nAspect(embed::Aspects::MSOLE_CONTENT);
+            MapUnit 
aMapUnit(VCLUnoHelper::UnoEmbed2VCLMapUnit(xObject->getMapUnit(nAspect)));
+            Size aSize(aInsRect.GetSize());
+            aSize = vcl::Window::LogicToLogic(aSize, 
MapMode(MapUnit::Map100thMM), MapMode(aMapUnit));
+            awt::Size aAwtSize;
+            aAwtSize.Width = aSize.Width();
+            aAwtSize.Height = aSize.Height();
+
+            std::unique_ptr<sc::PivotChartDataProvider> 
pPivotTableDataProvider(new sc::PivotChartDataProvider(&rDoc));
+            pPivotTableDataProvider->setPivotTableName(rDataPilotName);
+
+            uno::Reference<chart2::data::XDataProvider> 
xDataProvider(pPivotTableDataProvider.release());
+
+            uno::Reference<chart2::data::XDataReceiver> xReceiver;
+            uno::Reference<embed::XComponentSupplier> xCompSupp(xObject, 
uno::UNO_QUERY);
+
+            if (xCompSupp.is())
+                xReceiver.set(xCompSupp->getComponent(), uno::UNO_QUERY);
+
+            if (xReceiver.is())
+            {
+                xReceiver->attachDataProvider(xDataProvider);
+
+                uno::Reference<util::XNumberFormatsSupplier> 
xNumberFormatsSupplier(m_pDocShell->GetModel(), uno::UNO_QUERY);
+                xReceiver->attachNumberFormatsSupplier(xNumberFormatsSupplier);
+
+                uno::Sequence<beans::PropertyValue> aArgs(3);
+                aArgs[0] = beans::PropertyValue("CellRangeRepresentation", -1, 
uno::makeAny(OUString(rDataPilotName)), beans::PropertyState_DIRECT_VALUE);
+                aArgs[1] = beans::PropertyValue("HasCategories", -1, 
uno::makeAny(true), beans::PropertyState_DIRECT_VALUE);
+                aArgs[2] = beans::PropertyValue("DataRowSource", -1, 
uno::makeAny(chart::ChartDataRowSource_COLUMNS), 
beans::PropertyState_DIRECT_VALUE);
+                xReceiver->setArguments(aArgs);
+            }
+
+            SdrOle2Obj* pObject = new 
SdrOle2Obj(svt::EmbeddedObjectRef(xObject, embed::Aspects::MSOLE_CONTENT),
+                                                 aName, aInsRect);
+
+            if (xObject.is())
+                xObject->setVisualAreaSize(nAspect, aAwtSize);
+
+            pPage->InsertObject(pObject);
+            pModel->AddUndo(new SdrUndoInsertObj(*pObject));
+    }
+}
+
+void SAL_CALL TablePivotCharts::removeByName(const OUString& rName)
+{
+    SolarMutexGuard aGuard;
+    SdrOle2Obj* pObject = sc::tools::findChartsByName(m_pDocShell, m_nTab, 
rName, sc::tools::ChartSourceType::PIVOT_TABLE);
+    if (pObject)
+    {
+        ScDocument& rDoc = m_pDocShell->GetDocument();
+        ScDrawLayer* pModel = rDoc.GetDrawLayer();
+        SdrPage* pPage = pModel->GetPage(sal_uInt16(m_nTab));
+        pModel->AddUndo(new SdrUndoDelObj(*pObject));
+        pPage->RemoveObject(pObject->GetOrdNum());
+    }
+}
+
+// XIndexAccess
+sal_Int32 SAL_CALL TablePivotCharts::getCount()
+{
+    SolarMutexGuard aGuard;
+    sal_Int32 nCount = 0;
+
+    if (!m_pDocShell)
+        return nCount;
+
+    sc::tools::ChartIterator aIterator(m_pDocShell, m_nTab, 
sc::tools::ChartSourceType::PIVOT_TABLE);
+
+    SdrOle2Obj* pOleObject = aIterator.next();
+    while (pOleObject)
+    {
+        if (pOleObject->GetObjRef().is())
+            nCount++;
+        pOleObject = aIterator.next();
+    }
+    return nCount;
+}
+
+uno::Any SAL_CALL TablePivotCharts::getByIndex(sal_Int32 nIndex)
+{
+    SolarMutexGuard aGuard;
+    SdrOle2Obj* pObject = sc::tools::getChartByIndex(m_pDocShell, m_nTab, 
nIndex,
+                                                     
sc::tools::ChartSourceType::PIVOT_TABLE);
+    if (!pObject)
+        throw lang::IndexOutOfBoundsException();
+
+    OUString aName;
+    uno::Reference<embed::XEmbeddedObject> xObject = pObject->GetObjRef();
+    if (xObject.is())
+        aName = 
m_pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName(xObject);
+
+    if (aName.isEmpty())
+        throw lang::IndexOutOfBoundsException();
+
+    uno::Reference<table::XTablePivotChart> xChart(new 
TablePivotChart(m_pDocShell, m_nTab, aName));
+    if (xChart.is())
+        return uno::makeAny(xChart);
+    else
+        throw lang::IndexOutOfBoundsException();
+}
+
+uno::Type SAL_CALL TablePivotCharts::getElementType()
+{
+    SolarMutexGuard aGuard;
+    return cppu::UnoType<table::XTablePivotChart>::get();
+}
+
+sal_Bool SAL_CALL TablePivotCharts::hasElements()
+{
+    SolarMutexGuard aGuard;
+    return getCount() != 0;
+}
+
+uno::Any SAL_CALL TablePivotCharts::getByName(OUString const & rName)
+{
+    SolarMutexGuard aGuard;
+
+    if (!sc::tools::findChartsByName(m_pDocShell, m_nTab, rName, 
sc::tools::ChartSourceType::PIVOT_TABLE))
+        throw container::NoSuchElementException();
+
+    uno::Reference<table::XTablePivotChart> xChart(new 
TablePivotChart(m_pDocShell, m_nTab, rName));
+    if (xChart.is())
+        return uno::makeAny(xChart);
+    else
+        throw container::NoSuchElementException();
+}
+
+uno::Sequence<OUString> SAL_CALL TablePivotCharts::getElementNames()
+{
+    SolarMutexGuard aGuard;
+
+    std::vector<OUString> aElements;
+    sc::tools::ChartIterator aIterator(m_pDocShell, m_nTab, 
sc::tools::ChartSourceType::PIVOT_TABLE);
+
+    SdrOle2Obj* pOleObject = aIterator.next();
+    while (pOleObject)
+    {
+        uno::Reference<embed::XEmbeddedObject> xObject = 
pOleObject->GetObjRef();
+        if (xObject.is())
+        {
+            OUString aName = 
m_pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName(xObject);
+            aElements.push_back(aName);
+        }
+        pOleObject = aIterator.next();
+    }
+    return comphelper::containerToSequence(aElements);
+}
+
+sal_Bool SAL_CALL TablePivotCharts::hasByName(OUString const & rName)
+{
+    SolarMutexGuard aGuard;
+
+    return sc::tools::findChartsByName(m_pDocShell, m_nTab, rName, 
sc::tools::ChartSourceType::PIVOT_TABLE) != nullptr;
+}
+
+} // end sc namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index c2ce3570f501..b0efa0fcb873 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -130,6 +130,7 @@
 #include "dputil.hxx"
 #include <sortparam.hxx>
 #include "condformatuno.hxx"
+#include "TablePivotCharts.hxx"
 
 #include <list>
 #include <memory>
@@ -6729,6 +6730,7 @@ uno::Any SAL_CALL ScTableSheetObj::queryInterface( const 
uno::Type& rType )
     SC_QUERYINTERFACE( sheet::XSheetLinkable )
     SC_QUERYINTERFACE( sheet::XExternalSheetName )
     SC_QUERYINTERFACE( document::XEventsSupplier )
+    SC_QUERYINTERFACE( table::XTablePivotChartsSupplier )
 
     return ScCellRangeObj::queryInterface( rType );
 }
@@ -6752,7 +6754,8 @@ uno::Sequence<uno::Type> SAL_CALL 
ScTableSheetObj::getTypes()
         long nParentLen = aParentTypes.getLength();
         const uno::Type* pParentPtr = aParentTypes.getConstArray();
 
-        aTypes.realloc( nParentLen + 18 );
+        aTypes.realloc(nParentLen + 19);
+
         uno::Type* pPtr = aTypes.getArray();
         pPtr[nParentLen + 0] = cppu::UnoType<sheet::XSpreadsheet>::get();
         pPtr[nParentLen + 1] = cppu::UnoType<container::XNamed>::get();
@@ -6772,6 +6775,7 @@ uno::Sequence<uno::Type> SAL_CALL 
ScTableSheetObj::getTypes()
         pPtr[nParentLen +15] = cppu::UnoType<sheet::XSheetLinkable>::get();
         pPtr[nParentLen +16] = cppu::UnoType<sheet::XExternalSheetName>::get();
         pPtr[nParentLen +17] = cppu::UnoType<document::XEventsSupplier>::get();
+        pPtr[nParentLen +18] = 
cppu::UnoType<table::XTablePivotChartsSupplier>::get();
 
         for (long i=0; i<nParentLen; i++)
             pPtr[i] = pParentPtr[i];                // parent types first
@@ -6811,6 +6815,17 @@ uno::Reference<table::XTableCharts> SAL_CALL 
ScTableSheetObj::getCharts()
     return nullptr;
 }
 
+uno::Reference<table::XTablePivotCharts> SAL_CALL 
ScTableSheetObj::getPivotCharts()
+{
+    SolarMutexGuard aGuard;
+    ScDocShell* pDocSh = GetDocShell();
+    if (pDocSh)
+        return new sc::TablePivotCharts(pDocSh, GetTab_Impl());
+
+    OSL_FAIL("no Document");
+    return nullptr;
+}
+
 uno::Reference<sheet::XDataPilotTables> SAL_CALL 
ScTableSheetObj::getDataPilotTables()
 {
     SolarMutexGuard aGuard;
diff --git a/sc/source/ui/unoobj/chartuno.cxx b/sc/source/ui/unoobj/chartuno.cxx
index b0b2da480e7d..35c8e877f2ab 100644
--- a/sc/source/ui/unoobj/chartuno.cxx
+++ b/sc/source/ui/unoobj/chartuno.cxx
@@ -38,6 +38,7 @@
 #include <svx/charthelper.hxx>
 #include <svtools/embedhlp.hxx>
 
+#include "ChartTools.hxx"
 #include "chartuno.hxx"
 #include "miscuno.hxx"
 #include "docsh.hxx"
@@ -48,47 +49,13 @@
 #include "chart2uno.hxx"
 #include "convuno.hxx"
 
-using namespace com::sun::star;
+using namespace css;
 
 #define PROP_HANDLE_RELATED_CELLRANGES  1
 
 SC_SIMPLE_SERVICE_INFO( ScChartObj, "ScChartObj", 
"com.sun.star.table.TableChart" )
 SC_SIMPLE_SERVICE_INFO( ScChartsObj, "ScChartsObj", 
"com.sun.star.table.TableCharts" )
 
-static SdrOle2Obj* lcl_FindChartObj( ScDocShell* pDocShell, SCTAB nTab, const 
OUString& rName )
-{
-    if (pDocShell)
-    {
-        ScDocument& rDoc = pDocShell->GetDocument();
-        ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
-        if (pDrawLayer)
-        {
-            SdrPage* pPage = 
pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
-            OSL_ENSURE(pPage, "Page nicht gefunden");
-            if (pPage)
-            {
-                SdrObjListIter aIter( *pPage, SdrIterMode::DeepNoGroups );
-                SdrObject* pObject = aIter.Next();
-                while (pObject)
-                {
-                    if ( pObject->GetObjIdentifier() == OBJ_OLE2 && 
ScDocument::IsChart(pObject) )
-                    {
-                        uno::Reference < embed::XEmbeddedObject > xObj = 
static_cast<SdrOle2Obj*>(pObject)->GetObjRef();
-                        if ( xObj.is() )
-                        {
-                            OUString aObjName = 
pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
-                            if ( aObjName == rName )
-                                return static_cast<SdrOle2Obj*>(pObject);
-                        }
-                    }
-                    pObject = aIter.Next();
-                }
-            }
-        }
-    }
-    return nullptr;
-}
-
 ScChartsObj::ScChartsObj(ScDocShell* pDocSh, SCTAB nT) :
     pDocShell( pDocSh ),
     nTab( nT )
@@ -156,7 +123,7 @@ ScChartObj* ScChartsObj::GetObjectByIndex_Impl(long nIndex) 
const
 
 ScChartObj* ScChartsObj::GetObjectByName_Impl(const OUString& aName) const
 {
-    if ( lcl_FindChartObj( pDocShell, nTab, aName ) )
+    if (sc::tools::findChartsByName(pDocShell, nTab, aName, 
sc::tools::ChartSourceType::CELL_RANGE))
         return new ScChartObj( pDocShell, nTab, aName );
     return nullptr;
 }
@@ -297,7 +264,7 @@ void SAL_CALL ScChartsObj::addNewByName( const OUString& 
rName,
 void SAL_CALL ScChartsObj::removeByName( const OUString& aName )
 {
     SolarMutexGuard aGuard;
-    SdrOle2Obj* pObj = lcl_FindChartObj( pDocShell, nTab, aName );
+    SdrOle2Obj* pObj = sc::tools::findChartsByName(pDocShell, nTab, aName, 
sc::tools::ChartSourceType::CELL_RANGE);
     if (pObj)
     {
         ScDocument& rDoc = pDocShell->GetDocument();
@@ -429,7 +396,9 @@ uno::Sequence<OUString> SAL_CALL 
ScChartsObj::getElementNames()
 sal_Bool SAL_CALL ScChartsObj::hasByName( const OUString& aName )
 {
     SolarMutexGuard aGuard;
-    return ( lcl_FindChartObj( pDocShell, nTab, aName ) != nullptr );
+    SdrOle2Obj* aOle2Obj = sc::tools::findChartsByName(pDocShell, nTab, aName,
+                                                       
sc::tools::ChartSourceType::CELL_RANGE);
+    return aOle2Obj != nullptr;
 }
 
 ScChartObj::ScChartObj(ScDocShell* pDocSh, SCTAB nT, const OUString& rN)
@@ -742,7 +711,8 @@ void SAL_CALL ScChartObj::setRanges( const 
uno::Sequence<table::CellRangeAddress
 uno::Reference<lang::XComponent> SAL_CALL ScChartObj::getEmbeddedObject()
 {
     SolarMutexGuard aGuard;
-    SdrOle2Obj* pObject = lcl_FindChartObj( pDocShell, nTab, aChartName );
+    SdrOle2Obj* pObject = sc::tools::findChartsByName(pDocShell, nTab, 
aChartName,
+                                                      
sc::tools::ChartSourceType::CELL_RANGE);
     if ( pObject && svt::EmbeddedObjectRef::TryRunningState( 
pObject->GetObjRef() ) )
     {
         //TODO/LATER: is it OK that something is returned for *all* objects, 
not only own objects?
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to