diff options
Diffstat (limited to 'oox/source/drawingml')
-rw-r--r-- | oox/source/drawingml/chart/titlecontext.cxx | 28 | ||||
-rw-r--r-- | oox/source/drawingml/chart/titleconverter.cxx | 44 | ||||
-rw-r--r-- | oox/source/drawingml/chart/titlemodel.cxx | 10 |
3 files changed, 82 insertions, 0 deletions
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 ) |