[Libreoffice-commits] core.git: Branch 'libreoffice-6-4' - chart2/qa oox/inc oox/source

Tünde Tóth (via logerrit) logerrit at kemper.freedesktop.org
Sat Dec 14 16:46:41 UTC 2019


 chart2/qa/extras/chart2import.cxx                    |   15 ++++++
 chart2/qa/extras/data/xlsx/deleted_legend_entry.xlsx |binary
 oox/inc/drawingml/chart/titlecontext.hxx             |   12 +++++
 oox/inc/drawingml/chart/titleconverter.hxx           |    3 +
 oox/inc/drawingml/chart/titlemodel.hxx               |   17 ++++++-
 oox/source/drawingml/chart/titlecontext.cxx          |   28 ++++++++++++
 oox/source/drawingml/chart/titleconverter.cxx        |   44 +++++++++++++++++++
 oox/source/drawingml/chart/titlemodel.cxx            |   10 ++++
 oox/source/token/properties.txt                      |    1 
 9 files changed, 127 insertions(+), 3 deletions(-)

New commits:
commit 92f96e41223ad174ff32901f71ce0d64b6a0eade
Author:     Tünde Tóth <tundeth at gmail.com>
AuthorDate: Wed Dec 4 16:17:09 2019 +0100
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Sat Dec 14 17:46:00 2019 +0100

    tdf#121991 Chart OOXML import: fix deleted legend entries
    
    The legend showed deleted legend entries too.
    
    Change-Id: I1e205cdfc4262c73d2bb189237d6bc316781931d
    Reviewed-on: https://gerrit.libreoffice.org/84516
    Reviewed-by: László Németh <nemeth at numbertext.org>
    Tested-by: László Németh <nemeth at numbertext.org>
    (cherry picked from commit cea1ae2a4f7abdcfc3874d714bdafef801910c1c)
    Reviewed-on: https://gerrit.libreoffice.org/85024
    Tested-by: Jenkins
    Reviewed-by: Tünde Tóth <tundeth at gmail.com>

diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx
index f4bfb53fbf34..be010f3b309f 100644
--- a/chart2/qa/extras/chart2import.cxx
+++ b/chart2/qa/extras/chart2import.cxx
@@ -148,6 +148,7 @@ public:
     void testXaxisValues();
     void testTdf123504();
     void testTdf122765();
+    void testTdf121991();
 
     CPPUNIT_TEST_SUITE(Chart2ImportTest);
     CPPUNIT_TEST(Fdo60083);
@@ -245,6 +246,7 @@ public:
     CPPUNIT_TEST(testXaxisValues);
     CPPUNIT_TEST(testTdf123504);
     CPPUNIT_TEST(testTdf122765);
+    CPPUNIT_TEST(testTdf121991);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -2281,6 +2283,19 @@ void Chart2ImportTest::testTdf122765()
     CPPUNIT_ASSERT_GREATER(sal_Int32(7000), aSlicePosition.X);
 }
 
+void Chart2ImportTest::testTdf121991()
+{
+    load("/chart2/qa/extras/data/xlsx/", "deleted_legend_entry.xlsx");
+    Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet(0, mxComponent);
+    CPPUNIT_ASSERT(xChartDoc.is());
+    Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 1));
+    CPPUNIT_ASSERT(xDataSeries.is());
+    Reference<beans::XPropertySet> xPropertySet(xDataSeries, uno::UNO_QUERY_THROW);
+    bool bShowLegendEntry = true;
+    CPPUNIT_ASSERT(xPropertySet->getPropertyValue("ShowLegendEntry") >>= bShowLegendEntry);
+    CPPUNIT_ASSERT(!bShowLegendEntry);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ImportTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/chart2/qa/extras/data/xlsx/deleted_legend_entry.xlsx b/chart2/qa/extras/data/xlsx/deleted_legend_entry.xlsx
new file mode 100644
index 000000000000..06a052646f1e
Binary files /dev/null and b/chart2/qa/extras/data/xlsx/deleted_legend_entry.xlsx differ
diff --git a/oox/inc/drawingml/chart/titlecontext.hxx b/oox/inc/drawingml/chart/titlecontext.hxx
index 2d52720ef7a4..8538d5ce2e56 100644
--- a/oox/inc/drawingml/chart/titlecontext.hxx
+++ b/oox/inc/drawingml/chart/titlecontext.hxx
@@ -55,6 +55,18 @@ public:
     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
 };
 
+struct LegendEntryModel;
+
+/** Handler for a chart legend entry context (c:legendEntry element).
+ */
+class LegendEntryContext : public ContextBase< LegendEntryModel >
+{
+public:
+    explicit            LegendEntryContext( ::oox::core::ContextHandler2Helper& rParent, LegendEntryModel& rModel );
+    virtual             ~LegendEntryContext() override;
+
+    virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
+};
 
 struct LegendModel;
 
diff --git a/oox/inc/drawingml/chart/titleconverter.hxx b/oox/inc/drawingml/chart/titleconverter.hxx
index 10f2f000d4aa..40b95d25d193 100644
--- a/oox/inc/drawingml/chart/titleconverter.hxx
+++ b/oox/inc/drawingml/chart/titleconverter.hxx
@@ -90,6 +90,9 @@ public:
     /** Creates a legend object and attaches it at the passed diagram. */
     void                convertFromModel(
                             const css::uno::Reference< css::chart2::XDiagram >& rxDiagram );
+
+private:
+    void                legendEntriesFormatting(const css::uno::Reference<css::chart2::XDiagram>& rxDiagram);
 };
 
 
diff --git a/oox/inc/drawingml/chart/titlemodel.hxx b/oox/inc/drawingml/chart/titlemodel.hxx
index dde078443869..f069c7697a60 100644
--- a/oox/inc/drawingml/chart/titlemodel.hxx
+++ b/oox/inc/drawingml/chart/titlemodel.hxx
@@ -57,12 +57,23 @@ struct TitleModel
                         ~TitleModel();
 };
 
+struct LegendEntryModel
+{
+    sal_Int32           mnLegendEntryIdx;   /// Legend entry index.
+    bool                mbLabelDeleted;     /// True = legend label deleted.
+
+                        LegendEntryModel();
+                        ~LegendEntryModel();
+};
+
 struct LegendModel
 {
-    typedef ModelRef< Shape >       ShapeRef;
-    typedef ModelRef< TextBody >    TextBodyRef;
-    typedef ModelRef< LayoutModel > LayoutRef;
+    typedef ModelVector< LegendEntryModel > LegendEntryVector;
+    typedef ModelRef< Shape >               ShapeRef;
+    typedef ModelRef< TextBody >            TextBodyRef;
+    typedef ModelRef< LayoutModel >         LayoutRef;
 
+    LegendEntryVector   maLegendEntries;    /// Legend entries formatting.
     ShapeRef            mxShapeProp;        /// Legend shape formatting.
     TextBodyRef         mxTextProp;         /// Legend text formatting.
     LayoutRef           mxLayout;           /// Layout/position of the legend.
diff --git a/oox/source/drawingml/chart/titlecontext.cxx b/oox/source/drawingml/chart/titlecontext.cxx
index 042b12553483..2dbbaac69746 100644
--- a/oox/source/drawingml/chart/titlecontext.cxx
+++ b/oox/source/drawingml/chart/titlecontext.cxx
@@ -114,6 +114,31 @@ ContextHandlerRef TitleContext::onCreateContext( sal_Int32 nElement, const Attri
     return nullptr;
 }
 
+LegendEntryContext::LegendEntryContext( ContextHandler2Helper& rParent, LegendEntryModel& rModel ) :
+    ContextBase< LegendEntryModel >( rParent, rModel )
+{
+}
+
+LegendEntryContext::~LegendEntryContext()
+{
+}
+
+ContextHandlerRef LegendEntryContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
+{
+    // this context handler is used for <c:legendEntry> only
+    switch( nElement )
+    {
+        case C_TOKEN( idx ):
+            mrModel.mnLegendEntryIdx = rAttribs.getInteger( XML_val, -1 );
+            return nullptr;
+
+        case C_TOKEN( delete ):
+            mrModel.mbLabelDeleted = rAttribs.getBool( XML_val, true );
+            return nullptr;
+    }
+    return nullptr;
+}
+
 LegendContext::LegendContext( ContextHandler2Helper& rParent, LegendModel& rModel ) :
     ContextBase< LegendModel >( rParent, rModel )
 {
@@ -136,6 +161,9 @@ ContextHandlerRef LegendContext::onCreateContext( sal_Int32 nElement, const Attr
             mrModel.mnPosition = rAttribs.getToken( XML_val, XML_r );
             return nullptr;
 
+        case C_TOKEN( legendEntry ):
+            return new LegendEntryContext( *this, mrModel.maLegendEntries.create() );
+
         case C_TOKEN( overlay ):
             mrModel.mbOverlay = rAttribs.getBool( XML_val, !bMSO2007Doc );
             return nullptr;
diff --git a/oox/source/drawingml/chart/titleconverter.cxx b/oox/source/drawingml/chart/titleconverter.cxx
index 4f700c32725a..c41a794763b1 100644
--- a/oox/source/drawingml/chart/titleconverter.cxx
+++ b/oox/source/drawingml/chart/titleconverter.cxx
@@ -26,6 +26,9 @@
 #include <com/sun/star/chart2/XLegend.hpp>
 #include <com/sun/star/chart2/XTitle.hpp>
 #include <com/sun/star/chart2/XTitled.hpp>
+#include <com/sun/star/chart2/XChartTypeContainer.hpp>
+#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
+#include <com/sun/star/chart2/XDataSeriesContainer.hpp>
 #include <osl/diagnose.h>
 #include <drawingml/textbody.hxx>
 #include <drawingml/textparagraph.hxx>
@@ -249,12 +252,53 @@ void LegendConverter::convertFromModel( const Reference< XDiagram >& rxDiagram )
 
         if(eLegendPos == LegendPosition_CUSTOM && bTopRight && !bManualLayout)
             aPropSet.setProperty( PROP_RelativePosition , makeAny(eRelPos));
+        if (mrModel.maLegendEntries.size() > 0)
+            legendEntriesFormatting(rxDiagram);
     }
     catch( Exception& )
     {
     }
 }
 
+void LegendConverter::legendEntriesFormatting(const Reference<XDiagram>& rxDiagram)
+{
+    Reference<XCoordinateSystemContainer> xCooSysContainer(rxDiagram, UNO_QUERY_THROW);
+    const Sequence<Reference<XCoordinateSystem>> xCooSysSequence(xCooSysContainer->getCoordinateSystems());
+    if (!xCooSysSequence.hasElements())
+        return;
+
+    sal_Int32 nIndex = 0;
+    for (const auto& rCooSysSequence : xCooSysSequence)
+    {
+        Reference<XChartTypeContainer> xChartTypeContainer(rCooSysSequence, UNO_QUERY_THROW);
+        const Sequence<Reference<XChartType>> xChartTypeSequence(xChartTypeContainer->getChartTypes());
+        if (!xChartTypeSequence.hasElements())
+            continue;
+
+        for (const auto& rCT : xChartTypeSequence)
+        {
+            Reference<XDataSeriesContainer> xDSCont(rCT, UNO_QUERY);
+            if (!xDSCont.is())
+                continue;
+
+            const Sequence<Reference<XDataSeries>> aDataSeriesSeq = xDSCont->getDataSeries();
+            for (const auto& rDataSeries : aDataSeriesSeq)
+            {
+                PropertySet aSeriesProp(rDataSeries);
+                for (const auto& rLegendEntry : mrModel.maLegendEntries)
+                {
+                    if (nIndex == rLegendEntry->mnLegendEntryIdx)
+                    {
+                        aSeriesProp.setProperty(PROP_ShowLegendEntry, !rLegendEntry->mbLabelDeleted);
+                        break;
+                    }
+                }
+                nIndex++;
+            }
+        }
+    }
+}
+
 } // namespace chart
 } // namespace drawingml
 } // namespace oox
diff --git a/oox/source/drawingml/chart/titlemodel.cxx b/oox/source/drawingml/chart/titlemodel.cxx
index f866297ca406..846ec218b5bf 100644
--- a/oox/source/drawingml/chart/titlemodel.cxx
+++ b/oox/source/drawingml/chart/titlemodel.cxx
@@ -42,6 +42,16 @@ TitleModel::~TitleModel()
 {
 }
 
+LegendEntryModel::LegendEntryModel() :
+    mnLegendEntryIdx( -1 ),
+    mbLabelDeleted( false )
+{
+}
+
+LegendEntryModel::~LegendEntryModel()
+{
+}
+
 LegendModel::LegendModel(bool bMSO2007Doc) :
     mnPosition( XML_r ),
     mbOverlay( !bMSO2007Doc )
diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt
index db44e176ef33..f53b73f8b79e 100644
--- a/oox/source/token/properties.txt
+++ b/oox/source/token/properties.txt
@@ -461,6 +461,7 @@ ShowFormulas
 ShowGrid
 ShowHighLow
 ShowInputMessage
+ShowLegendEntry
 ShowList
 ShowNegativeError
 ShowObjects


More information about the Libreoffice-commits mailing list