diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-07-18 08:12:19 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-08-16 08:15:00 +0200 |
commit | 9d6ffcc0572cc7917651489c69ca4b3452e89a89 (patch) | |
tree | 3ff18216d78d614d51d680aa9846892bab02e646 /chart2/source | |
parent | 777f1dbb96fc4499e682f2f67969410408f53b50 (diff) |
chart2: Data table rendering of keys (legend symbols)
Change-Id: Iff13b188df18fe8f9919274869774f53f2ea323b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138299
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'chart2/source')
-rw-r--r-- | chart2/source/view/axes/VAxisBase.cxx | 3 | ||||
-rw-r--r-- | chart2/source/view/axes/VAxisBase.hxx | 5 | ||||
-rw-r--r-- | chart2/source/view/axes/VCartesianAxis.cxx | 5 | ||||
-rw-r--r-- | chart2/source/view/axes/VCartesianAxis.hxx | 4 | ||||
-rw-r--r-- | chart2/source/view/axes/VCartesianCoordinateSystem.cxx | 5 | ||||
-rw-r--r-- | chart2/source/view/axes/VCartesianCoordinateSystem.hxx | 3 | ||||
-rw-r--r-- | chart2/source/view/axes/VCoordinateSystem.cxx | 3 | ||||
-rw-r--r-- | chart2/source/view/axes/VPolarCoordinateSystem.cxx | 3 | ||||
-rw-r--r-- | chart2/source/view/axes/VPolarCoordinateSystem.hxx | 3 | ||||
-rw-r--r-- | chart2/source/view/charttypes/VSeriesPlotter.cxx | 139 | ||||
-rw-r--r-- | chart2/source/view/inc/DataTableView.hxx | 16 | ||||
-rw-r--r-- | chart2/source/view/inc/LegendEntryProvider.hxx | 9 | ||||
-rw-r--r-- | chart2/source/view/inc/VCoordinateSystem.hxx | 4 | ||||
-rw-r--r-- | chart2/source/view/inc/VSeriesPlotter.hxx | 11 | ||||
-rw-r--r-- | chart2/source/view/main/ChartView.cxx | 13 | ||||
-rw-r--r-- | chart2/source/view/main/DataTableView.cxx | 121 |
16 files changed, 299 insertions, 48 deletions
diff --git a/chart2/source/view/axes/VAxisBase.cxx b/chart2/source/view/axes/VAxisBase.cxx index 814d3afd7858..30aead187dcb 100644 --- a/chart2/source/view/axes/VAxisBase.cxx +++ b/chart2/source/view/axes/VAxisBase.cxx @@ -244,7 +244,8 @@ void VAxisBase::updateUnscaledValuesAtTicks( TickIter& rIter ) void VAxisBase::createDataTableView(std::vector<std::unique_ptr<VSeriesPlotter>>& /*rSeriesPlotterList*/, uno::Reference<util::XNumberFormatsSupplier> const& /*xNumberFormatsSupplier*/, - rtl::Reference<::chart::ChartModel> const& /*xChartDoc*/) + rtl::Reference<::chart::ChartModel> const& /*xChartDoc*/, + css::uno::Reference<css::uno::XComponentContext> const& /*rComponentContext*/) { } diff --git a/chart2/source/view/axes/VAxisBase.hxx b/chart2/source/view/axes/VAxisBase.hxx index 2c4123ba951d..4ee4f5e288ae 100644 --- a/chart2/source/view/axes/VAxisBase.hxx +++ b/chart2/source/view/axes/VAxisBase.hxx @@ -23,6 +23,7 @@ #include "Tickmarks.hxx" namespace com::sun::star::util { class XNumberFormatsSupplier; } +namespace com::sun::star::uno { class XComponentContext; } namespace chart { @@ -30,6 +31,7 @@ namespace chart class VSeriesPlotter; class DataTableView; class ChartModel; +class LegendEntryProvider; class VAxisBase : public VAxisOrGridBase { @@ -65,7 +67,8 @@ public: virtual void createDataTableView(std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList, css::uno::Reference<css::util::XNumberFormatsSupplier> const& xNumberFormatsSupplier, - rtl::Reference<::chart::ChartModel> const& xChartDoc); + rtl::Reference<::chart::ChartModel> const& xChartDoc, + css::uno::Reference<css::uno::XComponentContext> const& rComponentContext); std::shared_ptr<DataTableView> getDataTableView() { return m_pDataTableView; } diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx index d7e78d5d2e85..293d1f0479a8 100644 --- a/chart2/source/view/axes/VCartesianAxis.cxx +++ b/chart2/source/view/axes/VCartesianAxis.cxx @@ -1995,11 +1995,12 @@ void VCartesianAxis::createShapes() void VCartesianAxis::createDataTableView(std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList, Reference<util::XNumberFormatsSupplier> const& xNumberFormatsSupplier, - rtl::Reference<::chart::ChartModel> const& xChartDoc) + rtl::Reference<::chart::ChartModel> const& xChartDoc, + css::uno::Reference<css::uno::XComponentContext> const& rComponentContext) { if (m_aAxisProperties.m_bDisplayDataTable) { - m_pDataTableView.reset(new DataTableView(xChartDoc, m_aAxisProperties.m_xDataTableModel)); + m_pDataTableView.reset(new DataTableView(xChartDoc, m_aAxisProperties.m_xDataTableModel, rComponentContext)); m_pDataTableView->initializeValues(rSeriesPlotterList); m_xNumberFormatsSupplier = xNumberFormatsSupplier; } diff --git a/chart2/source/view/axes/VCartesianAxis.hxx b/chart2/source/view/axes/VCartesianAxis.hxx index a9baca907bdd..132887510eff 100644 --- a/chart2/source/view/axes/VCartesianAxis.hxx +++ b/chart2/source/view/axes/VCartesianAxis.hxx @@ -23,7 +23,6 @@ namespace chart { - class VCartesianAxis : public VAxisBase { // public methods @@ -101,7 +100,8 @@ public: void createDataTableView(std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList, css::uno::Reference<css::util::XNumberFormatsSupplier> const& xNumberFormatsSupplier, - rtl::Reference<::chart::ChartModel> const& xChartDoc) override; + rtl::Reference<::chart::ChartModel> const& xChartDoc, + css::uno::Reference<css::uno::XComponentContext> const& rComponentContext) override; private: //methods /** * Go through all tick label positions and decide which labels to display diff --git a/chart2/source/view/axes/VCartesianCoordinateSystem.cxx b/chart2/source/view/axes/VCartesianCoordinateSystem.cxx index 3ea42cb087a0..9f765223bf4d 100644 --- a/chart2/source/view/axes/VCartesianCoordinateSystem.cxx +++ b/chart2/source/view/axes/VCartesianCoordinateSystem.cxx @@ -104,7 +104,8 @@ void VCartesianCoordinateSystem::createVAxisList( const awt::Size& rFontReferenceSize, const awt::Rectangle& rMaximumSpaceForLabels, bool bLimitSpaceForLabels, - std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList) + std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList, + uno::Reference<uno::XComponentContext> const& rComponentContext) { // note: using xChartDoc itself as XNumberFormatsSupplier would cause // a leak from VCartesianAxis due to cyclic reference @@ -166,7 +167,7 @@ void VCartesianCoordinateSystem::createVAxisList( apVAxis->set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos ); apVAxis->initAxisLabelProperties(rFontReferenceSize,rMaximumSpaceForLabels); - apVAxis->createDataTableView(rSeriesPlotterList, xNumberFormatsSupplier, xChartDoc); + apVAxis->createDataTableView(rSeriesPlotterList, xNumberFormatsSupplier, xChartDoc, rComponentContext); } } } diff --git a/chart2/source/view/axes/VCartesianCoordinateSystem.hxx b/chart2/source/view/axes/VCartesianCoordinateSystem.hxx index 4b7acf227867..968d97a21099 100644 --- a/chart2/source/view/axes/VCartesianCoordinateSystem.hxx +++ b/chart2/source/view/axes/VCartesianCoordinateSystem.hxx @@ -35,7 +35,8 @@ public: const css::awt::Size& rFontReferenceSize, const css::awt::Rectangle& rMaximumSpaceForLabels, bool bLimitSpaceForLabels, - std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList) override; + std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList, + css::uno::Reference<css::uno::XComponentContext> const& rComponentContext) override; virtual void initVAxisInList() override; virtual void updateScalesAndIncrementsOnAxes() override; diff --git a/chart2/source/view/axes/VCoordinateSystem.cxx b/chart2/source/view/axes/VCoordinateSystem.cxx index 1dc9aaac91e4..f8d517fd008a 100644 --- a/chart2/source/view/axes/VCoordinateSystem.cxx +++ b/chart2/source/view/axes/VCoordinateSystem.cxx @@ -327,7 +327,8 @@ void VCoordinateSystem::createVAxisList( const awt::Size& /* rFontReferenceSize */, const awt::Rectangle& /* rMaximumSpaceForLabels */, bool /* bLimitSpaceForLabels */, - std::vector<std::unique_ptr<VSeriesPlotter>>& /*rSeriesPlotterList*/) + std::vector<std::unique_ptr<VSeriesPlotter>>& /*rSeriesPlotterList*/, + uno::Reference<uno::XComponentContext> const& /*rComponentContext*/) { } diff --git a/chart2/source/view/axes/VPolarCoordinateSystem.cxx b/chart2/source/view/axes/VPolarCoordinateSystem.cxx index 338a1c4ab7ed..600447dd19d5 100644 --- a/chart2/source/view/axes/VPolarCoordinateSystem.cxx +++ b/chart2/source/view/axes/VPolarCoordinateSystem.cxx @@ -72,7 +72,8 @@ void VPolarCoordinateSystem::createVAxisList( const awt::Size& rFontReferenceSize, const awt::Rectangle& rMaximumSpaceForLabels, bool /*bLimitSpaceForLabels*/, - std::vector<std::unique_ptr<VSeriesPlotter>>& /*rSeriesPlotterList*/) + std::vector<std::unique_ptr<VSeriesPlotter>>& /*rSeriesPlotterList*/, + css::uno::Reference<css::uno::XComponentContext> const& /*rComponentContext*/) { // note: using xChartDoc itself as XNumberFormatsSupplier would cause // a leak from VPolarAxis due to cyclic reference diff --git a/chart2/source/view/axes/VPolarCoordinateSystem.hxx b/chart2/source/view/axes/VPolarCoordinateSystem.hxx index ecfb2ce4d19d..a2ea0220f8bc 100644 --- a/chart2/source/view/axes/VPolarCoordinateSystem.hxx +++ b/chart2/source/view/axes/VPolarCoordinateSystem.hxx @@ -39,7 +39,8 @@ public: const css::awt::Size& rFontReferenceSize, const css::awt::Rectangle& rMaximumSpaceForLabels, bool bLimitSpaceForLabels, - std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList) override; + std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList, + css::uno::Reference<css::uno::XComponentContext> const& rComponentContext) override; virtual void initVAxisInList() override; virtual void updateScalesAndIncrementsOnAxes() override; diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx index fb93c6fd35fe..4b3295fed497 100644 --- a/chart2/source/view/charttypes/VSeriesPlotter.cxx +++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx @@ -2496,6 +2496,52 @@ std::vector< ViewLegendEntry > VSeriesPlotter::createLegendEntries( return aResult; } +std::vector<ViewLegendSymbol> VSeriesPlotter::createSymbols(const awt::Size& rEntryKeyAspectRatio + , const rtl::Reference<SvxShapeGroupAnyD>& xTarget + , const Reference<uno::XComponentContext>& xContext) +{ + std::vector<ViewLegendSymbol> aResult; + + if( xTarget.is() ) + { + bool bBreak = false; + bool bFirstSeries = true; + + for (std::vector<VDataSeriesGroup> const & rGroupVector : m_aZSlots) + { + for (VDataSeriesGroup const & rGroup : rGroupVector) + { + for (std::unique_ptr<VDataSeries> const & pSeries : rGroup.m_aSeriesVector) + { + if (!pSeries) + continue; + + if (!pSeries->getPropertiesOfSeries()->getPropertyValue("ShowLegendEntry").get<sal_Bool>()) + { + continue; + } + + std::vector<ViewLegendSymbol> aSeriesSymbols = createSymbolsForSeries(rEntryKeyAspectRatio, *pSeries, xTarget, xContext); + + //add series entries to the result now + + // use only the first series if VaryColorsByPoint is set for the first series + if (bFirstSeries && pSeries->isVaryColorsByPoint()) + bBreak = true; + + bFirstSeries = false; + + aResult.insert(aResult.end(), aSeriesSymbols.begin(), aSeriesSymbols.end()); + } + if (bBreak) + return aResult; + } + } + } + + return aResult; +} + namespace { bool lcl_HasVisibleLine( const uno::Reference< beans::XPropertySet >& xProps, bool& rbHasDashedLine ) @@ -2827,6 +2873,99 @@ std::vector< ViewLegendEntry > VSeriesPlotter::createLegendEntriesForSeries( return aResult; } +std::vector<ViewLegendSymbol> VSeriesPlotter::createSymbolsForSeries( + const awt::Size& rEntryKeyAspectRatio + , const VDataSeries& rSeries + , const rtl::Reference<SvxShapeGroupAnyD>& xTarget + , const Reference<uno::XComponentContext>& xContext) +{ + std::vector<ViewLegendSymbol> aResult; + + if (!(xTarget.is() && xContext.is())) + return aResult; + + try + { + ViewLegendSymbol aEntry; + bool bVaryColorsByPoint = rSeries.isVaryColorsByPoint(); + bool bIsPie = m_xChartTypeModel->getChartType().equalsIgnoreAsciiCase(CHART2_SERVICE_NAME_CHARTTYPE_PIE); + try + { + if (bIsPie) + { + bool bDonut = false; + if ((m_xChartTypeModel->getPropertyValue("UseRings") >>= bDonut) && bDonut) + bIsPie = false; + } + } + catch (const uno::Exception&) + { + } + + if (bVaryColorsByPoint || bIsPie) + { + Sequence< OUString > aCategoryNames; + if (m_pExplicitCategoriesProvider) + aCategoryNames = m_pExplicitCategoriesProvider->getSimpleCategories(); + Sequence<sal_Int32> deletedLegendEntries; + try + { + rSeries.getPropertiesOfSeries()->getPropertyValue("DeletedLegendEntries") >>= deletedLegendEntries; + } + catch (const uno::Exception&) + { + } + + for (sal_Int32 nIdx=0; nIdx < aCategoryNames.getLength(); ++nIdx) + { + bool deletedLegendEntry = false; + for (const auto& deletedLegendEntryIdx : std::as_const(deletedLegendEntries)) + { + if (nIdx == deletedLegendEntryIdx) + { + deletedLegendEntry = true; + break; + } + } + if (deletedLegendEntry) + continue; + + // symbol + rtl::Reference<SvxShapeGroup> xSymbolGroup(ShapeFactory::createGroup2D(xTarget)); + + // create the symbol + rtl::Reference<SvxShapeGroup> xShape = createLegendSymbolForPoint(rEntryKeyAspectRatio, rSeries, nIdx, xSymbolGroup); + + // set CID to symbol for selection + if (xShape.is()) + { + aEntry.xSymbol = xSymbolGroup; + } + } + } + else + { + // symbol + rtl::Reference<SvxShapeGroup> xSymbolGroup(ShapeFactory::createGroup2D(xTarget)); + + // create the symbol + rtl::Reference<SvxShapeGroup> xShape = createLegendSymbolForSeries(rEntryKeyAspectRatio, rSeries, xSymbolGroup ); + + // set CID to symbol for selection + if (xShape.is()) + { + aEntry.xSymbol = xSymbolGroup; + } + aResult.push_back(aEntry); + } + } + catch (const uno::Exception &) + { + DBG_UNHANDLED_EXCEPTION("chart2" ); + } + return aResult; +} + VSeriesPlotter* VSeriesPlotter::createSeriesPlotter( const rtl::Reference<ChartType>& xChartTypeModel , sal_Int32 nDimensionCount diff --git a/chart2/source/view/inc/DataTableView.hxx b/chart2/source/view/inc/DataTableView.hxx index 8a0f11bed772..3d00a9644ba3 100644 --- a/chart2/source/view/inc/DataTableView.hxx +++ b/chart2/source/view/inc/DataTableView.hxx @@ -12,6 +12,9 @@ #include <svx/unoshape.hxx> #include <svx/unodraw/SvxTableShape.hxx> #include <com/sun/star/awt/Rectangle.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> #include <DataTable.hxx> #include "VLineProperties.hxx" @@ -19,6 +22,7 @@ namespace chart { class VSeriesPlotter; class ChartModel; +class LegendEntryProvider; class DataTableView final { @@ -27,18 +31,24 @@ private: rtl::Reference<SvxShapeGroupAnyD> m_xTarget; rtl::Reference<SvxTableShape> m_xTableShape; rtl::Reference<DataTable> m_xDataTableModel; + css::uno::Reference<css::uno::XComponentContext> m_xComponentContext; VLineProperties m_aLineProperties; + std::vector<VSeriesPlotter*> m_pSeriesPlotterList; std::vector<OUString> m_aDataSeriesNames; std::vector<OUString> m_aXValues; std::vector<std::vector<OUString>> m_pDataSeriesValues; - void setCellDefaults(css::uno::Reference<css::beans::XPropertySet>& xPropertySet, bool bLeft, - bool bTop, bool bRight, bool bBottom); + void + setCellCharAndParagraphProperties(css::uno::Reference<css::beans::XPropertySet>& xPropertySet); + + void setCellProperties(css::uno::Reference<css::beans::XPropertySet>& xPropertySet, bool bLeft, + bool bTop, bool bRight, bool bBottom); public: DataTableView(rtl::Reference<::chart::ChartModel> const& xChartDoc, - rtl::Reference<DataTable> const& rDataTableModel); + rtl::Reference<DataTable> const& rDataTableModel, + css::uno::Reference<css::uno::XComponentContext> const& rComponentContext); void initializeShapes(const rtl::Reference<SvxShapeGroupAnyD>& xTarget); void initializeValues(std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList); void createShapes(basegfx::B2DVector const& rStart, basegfx::B2DVector const& rEnd, diff --git a/chart2/source/view/inc/LegendEntryProvider.hxx b/chart2/source/view/inc/LegendEntryProvider.hxx index e0133771cd27..d89447f38429 100644 --- a/chart2/source/view/inc/LegendEntryProvider.hxx +++ b/chart2/source/view/inc/LegendEntryProvider.hxx @@ -66,6 +66,15 @@ struct ViewLegendEntry css::uno::Reference< css::chart2::XFormattedString2 > > aLabel; }; + +struct ViewLegendSymbol +{ + /** The legend symbol that represents a data series or other + information contained in the legend + */ + rtl::Reference<SvxShapeGroup> xSymbol; +}; + class LegendEntryProvider { public: diff --git a/chart2/source/view/inc/VCoordinateSystem.hxx b/chart2/source/view/inc/VCoordinateSystem.hxx index 50d1cd9b2c4f..a9643bf967ad 100644 --- a/chart2/source/view/inc/VCoordinateSystem.hxx +++ b/chart2/source/view/inc/VCoordinateSystem.hxx @@ -39,6 +39,7 @@ namespace com::sun::star::chart2 { class XChartDocument; } namespace com::sun::star::chart2 { class XCoordinateSystem; } namespace com::sun::star::drawing { class XShapes; } namespace com::sun::star::lang { class XMultiServiceFactory; } +namespace com::sun::star::uno { class XComponentContext; } namespace chart { @@ -120,7 +121,8 @@ public: const css::awt::Size& rFontReferenceSize, const css::awt::Rectangle& rMaximumSpaceForLabels, bool bLimitSpaceForLabels, - std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList); + std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList, + css::uno::Reference<css::uno::XComponentContext> const& rComponentContext); virtual void initVAxisInList(); virtual void updateScalesAndIncrementsOnAxes(); diff --git a/chart2/source/view/inc/VSeriesPlotter.hxx b/chart2/source/view/inc/VSeriesPlotter.hxx index 50901bf64a5a..eaf27495d0ed 100644 --- a/chart2/source/view/inc/VSeriesPlotter.hxx +++ b/chart2/source/view/inc/VSeriesPlotter.hxx @@ -216,6 +216,17 @@ public: const css::uno::Reference< css::uno::XComponentContext >& xContext ); + std::vector<ViewLegendSymbol> createSymbols( + const css::awt::Size& rEntryKeyAspectRatio + , const rtl::Reference<SvxShapeGroupAnyD>& xTarget + , const css::uno::Reference<css::uno::XComponentContext>& xContext); + + std::vector<ViewLegendSymbol> createSymbolsForSeries( + const css::awt::Size& rEntryKeyAspectRatio + , const VDataSeries& rSeries + , const rtl::Reference<SvxShapeGroupAnyD>& xTarget + , const css::uno::Reference<css::uno::XComponentContext>& xContext); + std::vector<VDataSeries*> getAllSeries(); std::vector<VDataSeries const*> getAllSeries() const; diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index 14ec725cadd2..282e76611081 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -536,8 +536,8 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D CuboidPlanePosition eBottomPos( ThreeDHelper::getAutomaticCuboidPlanePositionForStandardBottom( xDiagram ) ); rpVCooSys->set3DWallPositions( eLeftWallPos, eBackWallPos, eBottomPos ); } - - rpVCooSys->createVAxisList(&mrChartModel, rPageSize, rParam.maRemainingSpace, rParam.mbUseFixedInnerSize, rSeriesPlotterList); + rpVCooSys->createVAxisList(&mrChartModel, rPageSize, rParam.maRemainingSpace, + rParam.mbUseFixedInnerSize, rSeriesPlotterList, getComponentContext()); } // - prepare list of all axis and how they are used @@ -1376,9 +1376,12 @@ void ChartView::createShapes() if(!mxRootShape.is()) mxRootShape = ShapeFactory::getOrCreateChartRootShape( m_xDrawPage ); - SdrPage* pPage = ChartView::getSdrPage(); - if(pPage) //it is necessary to use the implementation here as the uno page does not provide a propertyset + SdrPage* pPage = getSdrPage(); + + if (pPage) //it is necessary to use the implementation here as the uno page does not provide a propertyset + { pPage->SetSize(Size(aPageSize.Width,aPageSize.Height)); + } else { OSL_FAIL("could not set page size correctly"); @@ -1910,7 +1913,7 @@ void ChartView::createShapes2D( const awt::Size& rPageSize ) } lcl_createLegend( - LegendHelper::getLegend( mrChartModel ), mxRootShape, m_xCC, + LegendHelper::getLegend( mrChartModel ), mxRootShape, getComponentContext(), aParam.maRemainingSpace, rPageSize, mrChartModel, aParam.mpSeriesPlotterContainer->getLegendEntryProviderList(), lcl_getDefaultWritingModeFromPool( m_pDrawModelWrapper ) ); diff --git a/chart2/source/view/main/DataTableView.cxx b/chart2/source/view/main/DataTableView.cxx index 64c76e5da885..6f099bccf04c 100644 --- a/chart2/source/view/main/DataTableView.cxx +++ b/chart2/source/view/main/DataTableView.cxx @@ -28,6 +28,7 @@ #include <com/sun/star/drawing/LineStyle.hpp> #include <com/sun/star/util/XBroadcaster.hpp> #include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> #include <o3tl/unit_conversion.hxx> @@ -35,15 +36,6 @@ using namespace css; namespace chart { -DataTableView::DataTableView(rtl::Reference<::chart::ChartModel> const& xChartModel, - rtl::Reference<DataTable> const& rDataTableModel) - : m_xChartModel(xChartModel) - , m_xDataTableModel(rDataTableModel) -{ - uno::Reference<beans::XPropertySet> xProp(m_xDataTableModel); - m_aLineProperties.initFromPropertySet(xProp); -} - namespace { void setTopCell(uno::Reference<beans::XPropertySet>& xPropertySet) @@ -65,10 +57,22 @@ void copyProperty(uno::Reference<beans::XPropertySet>& xOut, { xOut->setPropertyValue(sPropertyName, xIn->getPropertyValue(sPropertyName)); } +} // end anonymous namespace + +DataTableView::DataTableView( + rtl::Reference<::chart::ChartModel> const& xChartModel, + rtl::Reference<DataTable> const& rDataTableModel, + css::uno::Reference<css::uno::XComponentContext> const& rComponentContext) + : m_xChartModel(xChartModel) + , m_xDataTableModel(rDataTableModel) + , m_xComponentContext(rComponentContext) +{ + uno::Reference<beans::XPropertySet> xProp(m_xDataTableModel); + m_aLineProperties.initFromPropertySet(xProp); } -void DataTableView::setCellDefaults(uno::Reference<beans::XPropertySet>& xPropertySet, bool bLeft, - bool bTop, bool bRight, bool bBottom) +void DataTableView::setCellCharAndParagraphProperties( + uno::Reference<beans::XPropertySet>& xPropertySet) { uno::Reference<beans::XPropertySet> xDataTableProperties(m_xDataTableModel); @@ -113,19 +117,27 @@ void DataTableView::setCellDefaults(uno::Reference<beans::XPropertySet>& xProper copyProperty(xPropertySet, xDataTableProperties, "CharWeightComplex"); copyProperty(xPropertySet, xDataTableProperties, "CharWordMode"); + xPropertySet->setPropertyValue("ParaAdjust", uno::Any(style::ParagraphAdjust_CENTER)); +} + +void DataTableView::setCellProperties(css::uno::Reference<beans::XPropertySet>& xPropertySet, + bool bLeft, bool bTop, bool bRight, bool bBottom) +{ + xPropertySet->setPropertyValue("FillColor", uno::Any(Color(0xFFFFFF))); + + uno::Reference<beans::XPropertySet> xDataTableProperties(m_xDataTableModel); float fFontHeight = 0.0; xDataTableProperties->getPropertyValue("CharHeight") >>= fFontHeight; fFontHeight = o3tl::convert(fFontHeight, o3tl::Length::pt, o3tl::Length::mm100); - uno::Any aXDistanceAny(sal_Int32(std::round(fFontHeight * 0.18f))); - uno::Any aYDistanceAny(sal_Int32(std::round(fFontHeight * 0.30f))); - xPropertySet->setPropertyValue("TextLeftDistance", aXDistanceAny); - xPropertySet->setPropertyValue("TextRightDistance", aXDistanceAny); - xPropertySet->setPropertyValue("TextUpperDistance", aYDistanceAny); - xPropertySet->setPropertyValue("TextLowerDistance", aYDistanceAny); + sal_Int32 nXDistance = std::round(fFontHeight * 0.18f); + sal_Int32 nYDistance = std::round(fFontHeight * 0.30f); + + xPropertySet->setPropertyValue("TextLeftDistance", uno::Any(nXDistance)); + xPropertySet->setPropertyValue("TextRightDistance", uno::Any(nXDistance)); + xPropertySet->setPropertyValue("TextUpperDistance", uno::Any(nYDistance)); + xPropertySet->setPropertyValue("TextLowerDistance", uno::Any(nYDistance)); - xPropertySet->setPropertyValue("FillColor", uno::Any(Color(0xFFFFFF))); xPropertySet->setPropertyValue("TextVerticalAdjust", uno::Any(drawing::TextVerticalAdjust_TOP)); - xPropertySet->setPropertyValue("ParaAdjust", uno::Any(style::ParagraphAdjust_CENTER)); drawing::LineStyle eStyle = drawing::LineStyle_NONE; m_aLineProperties.LineStyle >>= eStyle; @@ -218,13 +230,19 @@ void DataTableView::createShapes(basegfx::B2DVector const& rStart, basegfx::B2DV xBroadcaster->lockBroadcasts(); + auto* pTableObject = static_cast<sdr::table::SdrTableObj*>(m_xTableShape->GetSdrObject()); + bool bHBorder = false; bool bVBorder = false; bool bOutline = false; + bool bKeys = false; + + std::vector<ViewLegendSymbol> aSymbols; m_xDataTableModel->getPropertyValue("HBorder") >>= bHBorder; m_xDataTableModel->getPropertyValue("VBorder") >>= bVBorder; m_xDataTableModel->getPropertyValue("Outline") >>= bOutline; + m_xDataTableModel->getPropertyValue("Keys") >>= bKeys; sal_Int32 nColumnCount = m_aXValues.size(); uno::Reference<table::XTableColumns> xTableColumns = xTable->getColumns(); @@ -256,22 +274,50 @@ void DataTableView::createShapes(basegfx::B2DVector const& rStart, basegfx::B2DV { xCellTextRange->setString(rString); bool bLeft = bOutline || (bVBorder && nColumn > 1); - setCellDefaults(xPropertySet, bLeft, bOutline, bOutline, bOutline); + setCellProperties(xPropertySet, bLeft, bOutline, bOutline, bOutline); + setCellCharAndParagraphProperties(xPropertySet); } nColumn++; } + if (bKeys) + { + awt::Size aMaxSymbolExtent(300, 300); + for (VSeriesPlotter* pSeriesPlotter : m_pSeriesPlotterList) + { + if (pSeriesPlotter) + { + std::vector<ViewLegendSymbol> aNewEntries = pSeriesPlotter->createSymbols( + aMaxSymbolExtent, m_xTarget, m_xComponentContext); + aSymbols.insert(aSymbols.end(), aNewEntries.begin(), aNewEntries.end()); + } + } + } + nRow = 1; for (auto const& rSeriesName : m_aDataSeriesNames) { uno::Reference<table::XCell> xCell = xTable->getCellByPosition(0, nRow); - uno::Reference<beans::XPropertySet> xPropertySet(xCell, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xCellPropertySet(xCell, uno::UNO_QUERY); uno::Reference<text::XTextRange> xCellTextRange(xCell, uno::UNO_QUERY); if (xCellTextRange.is()) { bool bTop = bOutline || (bHBorder && nRow > 1); - xCellTextRange->setString(rSeriesName); - setCellDefaults(xPropertySet, bOutline, bTop, bOutline, bOutline); + setCellProperties(xCellPropertySet, bOutline, bTop, bOutline, bOutline); + + auto xText = xCellTextRange->getText(); + xText->insertString(xText->getStart(), rSeriesName, false); + uno::Reference<container::XEnumerationAccess> xEnumAccess(xText, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xEnumeration(xEnumAccess->createEnumeration()); + uno::Reference<text::XTextRange> xParagraph(xEnumeration->nextElement(), + uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xTextPropertySet(xParagraph, uno::UNO_QUERY); + + setCellCharAndParagraphProperties(xTextPropertySet); + + xCellPropertySet->setPropertyValue("ParaAdjust", uno::Any(style::ParagraphAdjust_LEFT)); + if (bKeys) + xCellPropertySet->setPropertyValue("ParaLeftMargin", uno::Any(500)); } nRow++; } @@ -306,7 +352,8 @@ void DataTableView::createShapes(basegfx::B2DVector const& rStart, basegfx::B2DV if (nColumn == nColumnCount && bOutline) bRight = true; - setCellDefaults(xPropertySet, bLeft, bTop, bRight, bBottom); + setCellProperties(xPropertySet, bLeft, bTop, bRight, bBottom); + setCellCharAndParagraphProperties(xPropertySet); } nColumn++; } @@ -315,21 +362,39 @@ void DataTableView::createShapes(basegfx::B2DVector const& rStart, basegfx::B2DV xBroadcaster->unlockBroadcasts(); - auto* pTableObject = static_cast<sdr::table::SdrTableObj*>(m_xTableShape->GetSdrObject()); pTableObject->DistributeColumns(0, nColumnCount - 1, true, true); + pTableObject->DistributeRows(0, nRowCount - 1, true, true); uno::Reference<beans::XPropertySet> xPropertySet(xTableColumns->getByIndex(0), uno::UNO_QUERY); sal_Int32 nWidth = 0; xPropertySet->getPropertyValue("Width") >>= nWidth; - m_xTableShape->setPosition( - { basegfx::fround(rStart.getX() - nWidth), basegfx::fround(rStart.getY()) }); + sal_Int32 nTableX = basegfx::fround(rStart.getX() - nWidth); + sal_Int32 nTableY = basegfx::fround(rStart.getY()); + m_xTableShape->setPosition({ nTableX, nTableY }); for (sal_Int32 i = 1; i < xTableColumns->getCount(); ++i) { xPropertySet.set(xTableColumns->getByIndex(i), uno::UNO_QUERY); xPropertySet->setPropertyValue("Width", uno::Any(nColumnWidth)); } + + if (bKeys) + { + sal_Int32 nTotalHeight = 0; + for (sal_Int32 i = 0; i < xTableRows->getCount(); i++) + { + xPropertySet.set(xTableRows->getByIndex(i), uno::UNO_QUERY); + sal_Int32 nHeight = 0; + xPropertySet->getPropertyValue("Height") >>= nHeight; + if (i > 0) + { + aSymbols[i - 1].xSymbol->setPosition( + { nTableX + 100, nTableY + nTotalHeight + 100 }); + } + nTotalHeight += nHeight; + } + } } void DataTableView::initializeShapes(const rtl::Reference<SvxShapeGroupAnyD>& xTarget) @@ -342,6 +407,8 @@ void DataTableView::initializeValues( { for (auto& rSeriesPlotter : rSeriesPlotterList) { + m_pSeriesPlotterList.push_back(rSeriesPlotter.get()); + for (auto const& rCategory : rSeriesPlotter->getExplicitCategoriesProvider()->getSimpleCategories()) { |