diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-05-20 23:55:45 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-07-21 09:01:27 +0200 |
commit | 6c24f112ad86df77f2de27a31742bca01ed56bdf (patch) | |
tree | 5e761c8c60e1b085066a97a5859709f693983d79 | |
parent | 7a076dd9a6d11aef547f657f525ec0c27a50db58 (diff) |
chart2: apply line props. to borders when rendering a data table
This sets the color, line width, line style to the borders of
the table when rendering the data table. We also need the
ChartModel inside DataTableView, so we can access the needed
line dashes.
Change-Id: Id3bef23b75e88517d6569ad87a716f178ed64343
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137158
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | chart2/source/view/axes/VAxisBase.cxx | 3 | ||||
-rw-r--r-- | chart2/source/view/axes/VAxisBase.hxx | 4 | ||||
-rw-r--r-- | chart2/source/view/axes/VCartesianAxis.cxx | 6 | ||||
-rw-r--r-- | chart2/source/view/axes/VCartesianAxis.hxx | 3 | ||||
-rw-r--r-- | chart2/source/view/axes/VCartesianCoordinateSystem.cxx | 2 | ||||
-rw-r--r-- | chart2/source/view/inc/DataTableView.hxx | 11 | ||||
-rw-r--r-- | chart2/source/view/main/DataTableView.cxx | 94 |
7 files changed, 96 insertions, 27 deletions
diff --git a/chart2/source/view/axes/VAxisBase.cxx b/chart2/source/view/axes/VAxisBase.cxx index 95125beed1cf..7d985051a4a7 100644 --- a/chart2/source/view/axes/VAxisBase.cxx +++ b/chart2/source/view/axes/VAxisBase.cxx @@ -243,7 +243,8 @@ void VAxisBase::updateUnscaledValuesAtTicks( TickIter& rIter ) } void VAxisBase::createDataTableView(std::vector<std::unique_ptr<VSeriesPlotter>>& /*rSeriesPlotterList*/, - uno::Reference<util::XNumberFormatsSupplier> const& /*xNumberFormatsSupplier*/) + uno::Reference<util::XNumberFormatsSupplier> const& /*xNumberFormatsSupplier*/, + rtl::Reference<::chart::ChartModel> const& /*xChartDoc*/) { } diff --git a/chart2/source/view/axes/VAxisBase.hxx b/chart2/source/view/axes/VAxisBase.hxx index 4da1936a452b..2c4123ba951d 100644 --- a/chart2/source/view/axes/VAxisBase.hxx +++ b/chart2/source/view/axes/VAxisBase.hxx @@ -29,6 +29,7 @@ namespace chart class VSeriesPlotter; class DataTableView; +class ChartModel; class VAxisBase : public VAxisOrGridBase { @@ -63,7 +64,8 @@ public: void setExtraLinePositionAtOtherAxis( double fCrossingAt ); virtual void createDataTableView(std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList, - css::uno::Reference<css::util::XNumberFormatsSupplier> const& xNumberFormatsSupplier); + css::uno::Reference<css::util::XNumberFormatsSupplier> const& xNumberFormatsSupplier, + rtl::Reference<::chart::ChartModel> const& xChartDoc); 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 096586279454..d7e78d5d2e85 100644 --- a/chart2/source/view/axes/VCartesianAxis.cxx +++ b/chart2/source/view/axes/VCartesianAxis.cxx @@ -37,6 +37,7 @@ #include <svx/unoshtxt.hxx> #include <VSeriesPlotter.hxx> #include <DataTableView.hxx> +#include <ChartModel.hxx> #include <comphelper/scopeguard.hxx> @@ -1993,11 +1994,12 @@ void VCartesianAxis::createShapes() } void VCartesianAxis::createDataTableView(std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList, - Reference<util::XNumberFormatsSupplier> const& xNumberFormatsSupplier) + Reference<util::XNumberFormatsSupplier> const& xNumberFormatsSupplier, + rtl::Reference<::chart::ChartModel> const& xChartDoc) { if (m_aAxisProperties.m_bDisplayDataTable) { - m_pDataTableView.reset(new DataTableView(m_aAxisProperties.m_xDataTableModel)); + m_pDataTableView.reset(new DataTableView(xChartDoc, m_aAxisProperties.m_xDataTableModel)); m_pDataTableView->initializeValues(rSeriesPlotterList); m_xNumberFormatsSupplier = xNumberFormatsSupplier; } diff --git a/chart2/source/view/axes/VCartesianAxis.hxx b/chart2/source/view/axes/VCartesianAxis.hxx index 9f396fef43b8..a9baca907bdd 100644 --- a/chart2/source/view/axes/VCartesianAxis.hxx +++ b/chart2/source/view/axes/VCartesianAxis.hxx @@ -100,7 +100,8 @@ public: }; void createDataTableView(std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList, - css::uno::Reference<css::util::XNumberFormatsSupplier> const& xNumberFormatsSupplier) override; + css::uno::Reference<css::util::XNumberFormatsSupplier> const& xNumberFormatsSupplier, + rtl::Reference<::chart::ChartModel> const& xChartDoc) 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 cd0d49188a1c..3ea42cb087a0 100644 --- a/chart2/source/view/axes/VCartesianCoordinateSystem.cxx +++ b/chart2/source/view/axes/VCartesianCoordinateSystem.cxx @@ -166,7 +166,7 @@ void VCartesianCoordinateSystem::createVAxisList( apVAxis->set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos ); apVAxis->initAxisLabelProperties(rFontReferenceSize,rMaximumSpaceForLabels); - apVAxis->createDataTableView(rSeriesPlotterList, xNumberFormatsSupplier); + apVAxis->createDataTableView(rSeriesPlotterList, xNumberFormatsSupplier, xChartDoc); } } } diff --git a/chart2/source/view/inc/DataTableView.hxx b/chart2/source/view/inc/DataTableView.hxx index 3f4d97629035..8a0f11bed772 100644 --- a/chart2/source/view/inc/DataTableView.hxx +++ b/chart2/source/view/inc/DataTableView.hxx @@ -13,23 +13,32 @@ #include <svx/unodraw/SvxTableShape.hxx> #include <com/sun/star/awt/Rectangle.hpp> #include <DataTable.hxx> +#include "VLineProperties.hxx" namespace chart { class VSeriesPlotter; +class ChartModel; class DataTableView final { +private: + rtl::Reference<::chart::ChartModel> m_xChartModel; rtl::Reference<SvxShapeGroupAnyD> m_xTarget; rtl::Reference<SvxTableShape> m_xTableShape; rtl::Reference<DataTable> m_xDataTableModel; + VLineProperties m_aLineProperties; 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); + public: - DataTableView(rtl::Reference<DataTable> const& rDataTableModel); + DataTableView(rtl::Reference<::chart::ChartModel> const& xChartDoc, + rtl::Reference<DataTable> const& rDataTableModel); 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/main/DataTableView.cxx b/chart2/source/view/main/DataTableView.cxx index 7b7fb60132ef..55a3b8628c50 100644 --- a/chart2/source/view/main/DataTableView.cxx +++ b/chart2/source/view/main/DataTableView.cxx @@ -12,6 +12,7 @@ #include <VSeriesPlotter.hxx> #include <ShapeFactory.hxx> #include <ExplicitCategoriesProvider.hxx> +#include <ChartModel.hxx> #include <svx/svdotable.hxx> @@ -19,10 +20,14 @@ #include <com/sun/star/table/BorderLine.hpp> #include <com/sun/star/table/BorderLine2.hpp> #include <com/sun/star/table/TableBorder.hpp> +#include <com/sun/star/table/BorderLineStyle.hpp> #include <com/sun/star/style/ParagraphAdjust.hpp> #include <com/sun/star/drawing/TextHorizontalAdjust.hpp> #include <com/sun/star/drawing/TextVerticalAdjust.hpp> +#include <com/sun/star/drawing/LineDash.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> #include <com/sun/star/util/XBroadcaster.hpp> +#include <com/sun/star/container/XNameContainer.hpp> #include <o3tl/unit_conversion.hxx> @@ -30,48 +35,97 @@ using namespace css; namespace chart { -DataTableView::DataTableView(rtl::Reference<DataTable> const& rDataTableModel) - : m_xDataTableModel(rDataTableModel) +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 setCellDefaults(uno::Reference<beans::XPropertySet>& xPropertySet, bool bLeft, bool bTop, - bool bRight, bool bBottom) +void setTopCell(uno::Reference<beans::XPropertySet>& xPropertySet) { xPropertySet->setPropertyValue("FillColor", uno::Any(Color(0xFFFFFF))); xPropertySet->setPropertyValue("TextVerticalAdjust", uno::Any(drawing::TextVerticalAdjust_TOP)); xPropertySet->setPropertyValue("ParaAdjust", uno::Any(style::ParagraphAdjust_CENTER)); table::BorderLine2 aBorderLine; - aBorderLine.LineWidth = o3tl::convert(0.5, o3tl::Length::pt, o3tl::Length::mm100); + aBorderLine.LineWidth = 0; aBorderLine.Color = 0x000000; - if (bLeft) - xPropertySet->setPropertyValue("LeftBorder", uno::Any(aBorderLine)); - if (bTop) - xPropertySet->setPropertyValue("TopBorder", uno::Any(aBorderLine)); - if (bRight) - xPropertySet->setPropertyValue("RightBorder", uno::Any(aBorderLine)); - if (bBottom) - xPropertySet->setPropertyValue("BottomBorder", uno::Any(aBorderLine)); + xPropertySet->setPropertyValue("TopBorder", uno::Any(aBorderLine)); + xPropertySet->setPropertyValue("LeftBorder", uno::Any(aBorderLine)); +} } -void setTopCell(uno::Reference<beans::XPropertySet>& xPropertySet) +void DataTableView::setCellDefaults(uno::Reference<beans::XPropertySet>& xPropertySet, bool bLeft, + bool bTop, bool bRight, bool bBottom) { xPropertySet->setPropertyValue("FillColor", uno::Any(Color(0xFFFFFF))); xPropertySet->setPropertyValue("TextVerticalAdjust", uno::Any(drawing::TextVerticalAdjust_TOP)); xPropertySet->setPropertyValue("ParaAdjust", uno::Any(style::ParagraphAdjust_CENTER)); - table::BorderLine2 aBorderLine; - aBorderLine.LineWidth = 0; - aBorderLine.Color = 0x000000; + drawing::LineStyle eStyle = drawing::LineStyle_NONE; + m_aLineProperties.LineStyle >>= eStyle; - xPropertySet->setPropertyValue("TopBorder", uno::Any(aBorderLine)); - xPropertySet->setPropertyValue("LeftBorder", uno::Any(aBorderLine)); -} + if (eStyle != drawing::LineStyle_NONE) + { + table::BorderLine2 aBorderLine; + + sal_Int32 nWidth = 0; + m_aLineProperties.Width >>= nWidth; + aBorderLine.LineWidth = o3tl::convert(nWidth, o3tl::Length::mm100, o3tl::Length::twip); + + sal_Int32 nColor = 0; + m_aLineProperties.Color >>= nColor; + aBorderLine.Color = nColor; + + aBorderLine.LineStyle = table::BorderLineStyle::SOLID; + + if (eStyle == drawing::LineStyle_DASH) + { + OUString aDashName; + m_aLineProperties.DashName >>= aDashName; + if (!aDashName.isEmpty() && m_xChartModel.is()) + { + uno::Reference<container::XNameContainer> xDashTable( + m_xChartModel->createInstance("com.sun.star.drawing.DashTable"), + uno::UNO_QUERY); + if (xDashTable.is() && xDashTable->hasByName(aDashName)) + { + drawing::LineDash aLineDash; + xDashTable->getByName(aDashName) >>= aLineDash; + + if (aLineDash.Dots == 0 && aLineDash.Dashes == 0) + aBorderLine.LineStyle = table::BorderLineStyle::SOLID; + else if (aLineDash.Dots == 1 && aLineDash.Dashes == 0) + aBorderLine.LineStyle = table::BorderLineStyle::DOTTED; + else if (aLineDash.Dots == 0 && aLineDash.Dashes == 1) + aBorderLine.LineStyle = table::BorderLineStyle::DASHED; + else if (aLineDash.Dots == 1 && aLineDash.Dashes == 1) + aBorderLine.LineStyle = table::BorderLineStyle::DASH_DOT; + else if (aLineDash.Dots == 2 && aLineDash.Dashes == 1) + aBorderLine.LineStyle = table::BorderLineStyle::DASH_DOT_DOT; + else + aBorderLine.LineStyle = table::BorderLineStyle::DASHED; + } + } + } + + if (bLeft) + xPropertySet->setPropertyValue("LeftBorder", uno::Any(aBorderLine)); + if (bTop) + xPropertySet->setPropertyValue("TopBorder", uno::Any(aBorderLine)); + if (bRight) + xPropertySet->setPropertyValue("RightBorder", uno::Any(aBorderLine)); + if (bBottom) + xPropertySet->setPropertyValue("BottomBorder", uno::Any(aBorderLine)); + } } + void DataTableView::createShapes(basegfx::B2DVector const& rStart, basegfx::B2DVector const& rEnd, sal_Int32 nColumnWidth) { |