diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2022-01-04 18:50:01 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-01-06 07:15:48 +0100 |
commit | 0b0934056b47485527442b6366d7fd3274a4601f (patch) | |
tree | a997a63ebdd694ad0d22a989a476a757ad11e64c /chart2/source/view | |
parent | ea545653e17e687c9069543897975b3726dc6a2b (diff) |
bypass SvxShape when creating rectangles in chart2
Change-Id: I461449959fffa8948bf4321a6c3114505d87a149
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127997
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'chart2/source/view')
-rw-r--r-- | chart2/source/view/charttypes/AreaChart.cxx | 20 | ||||
-rw-r--r-- | chart2/source/view/charttypes/BarChart.cxx | 42 | ||||
-rw-r--r-- | chart2/source/view/charttypes/NetChart.cxx | 12 | ||||
-rw-r--r-- | chart2/source/view/inc/PropertyMapper.hxx | 5 | ||||
-rw-r--r-- | chart2/source/view/inc/ShapeFactory.hxx | 5 | ||||
-rw-r--r-- | chart2/source/view/main/PropertyMapper.cxx | 125 | ||||
-rw-r--r-- | chart2/source/view/main/ShapeFactory.cxx | 36 |
7 files changed, 198 insertions, 47 deletions
diff --git a/chart2/source/view/charttypes/AreaChart.cxx b/chart2/source/view/charttypes/AreaChart.cxx index 3972aba068fd..e4864cca63f7 100644 --- a/chart2/source/view/charttypes/AreaChart.cxx +++ b/chart2/source/view/charttypes/AreaChart.cxx @@ -501,22 +501,26 @@ bool AreaChart::impl_createArea( VDataSeries* pSeries pPosHelper->transformScaledLogicToScene( aPoly ); //create area: - rtl::Reference< SvxShape > xShape; if(m_nDimension==3) { - xShape = ShapeFactory::createArea3D( xSeriesGroupShape_Shapes + rtl::Reference< SvxShape > xShape = ShapeFactory::createArea3D( xSeriesGroupShape_Shapes , aPoly, getTransformedDepth() ); + PropertyMapper::setMappedProperties( *xShape + , pSeries->getPropertiesOfSeries() + , PropertyMapper::getPropertyNameMapForFilledSeriesProperties() ); + //because of this name this line will be used for marking + ShapeFactory::setShapeName(xShape, "MarkHandles"); } else //m_nDimension!=3 { - xShape = ShapeFactory::createArea2D( xSeriesGroupShape_Shapes + SdrPathObj* pShape = ShapeFactory::createArea2D( xSeriesGroupShape_Shapes , aPoly ); + PropertyMapper::setPropertyNameMapForFilledSeriesProperties( + pShape + , pSeries->getPropertiesOfSeries()); + //because of this name this line will be used for marking + ShapeFactory::setShapeName(pShape, "MarkHandles"); } - PropertyMapper::setMappedProperties( *xShape - , pSeries->getPropertiesOfSeries() - , PropertyMapper::getPropertyNameMapForFilledSeriesProperties() ); - //because of this name this line will be used for marking - ::chart::ShapeFactory::setShapeName(xShape, "MarkHandles"); return true; } diff --git a/chart2/source/view/charttypes/BarChart.cxx b/chart2/source/view/charttypes/BarChart.cxx index 5fcd1bfc4203..a06303a310b3 100644 --- a/chart2/source/view/charttypes/BarChart.cxx +++ b/chart2/source/view/charttypes/BarChart.cxx @@ -788,7 +788,6 @@ void BarChart::createShapes() //create partial point if( !approxEqual(fLowerYValue,fUpperYValue) ) { - rtl::Reference< SvxShape > xShape; if( m_nDimension==3 ) { drawing::Position3D aLogicBottom (fLogicX,fLogicYStart,fLogicZ); @@ -823,9 +822,22 @@ void BarChart::createShapes() if( fTopHeight < 0 ) fTopHeight *= -1.0; - xShape = createDataPoint3D_Bar( + rtl::Reference< SvxShape > xShape = createDataPoint3D_Bar( xSeriesGroupShape_Shapes, aTransformedBottom, aSize, fTopHeight, nRotateZAngleHundredthDegree , xDataPointProperties, nGeometry3D ); + + if(bHasFillColorMapping) + { + double nPropVal = pSeries->getValueByProperty(nPointIndex, "FillColor"); + if(!std::isnan(nPropVal)) + { + xShape->setPropertyValue("FillColor", uno::Any(static_cast<sal_Int32>(nPropVal))); + } + } + //set name/classified ObjectID (CID) + ShapeFactory::setShapeName(xShape + , ObjectIdentifier::createPointCID( + pSeries->getPointCID_Stub(),nPointIndex) ); } else //m_nDimension!=3 { @@ -844,22 +856,22 @@ void BarChart::createShapes() AddPointToPoly( aPoly, aLeftUpperPoint ); AddPointToPoly( aPoly, drawing::Position3D( fLogicX-fLogicBarWidth/2.0,fLowerYValue,fLogicZ) ); pPosHelper->transformScaledLogicToScene( aPoly ); - xShape = ShapeFactory::createArea2D( xSeriesGroupShape_Shapes, aPoly ); - PropertyMapper::setMappedProperties( *xShape, xDataPointProperties, PropertyMapper::getPropertyNameMapForFilledSeriesProperties() ); - } - - if(bHasFillColorMapping) - { - double nPropVal = pSeries->getValueByProperty(nPointIndex, "FillColor"); - if(!std::isnan(nPropVal)) + std::optional<sal_Int32> xFillColor; + if(bHasFillColorMapping) { - xShape->setPropertyValue("FillColor", uno::Any(static_cast<sal_Int32>(nPropVal))); + double nPropVal = pSeries->getValueByProperty(nPointIndex, "FillColor"); + if(!std::isnan(nPropVal)) + xFillColor = static_cast<sal_Int32>(nPropVal); } + SdrPathObj* pShape = ShapeFactory::createArea2D( xSeriesGroupShape_Shapes, aPoly ); + PropertyMapper::setPropertyNameMapForFilledSeriesProperties(pShape, xDataPointProperties, xFillColor); + + //set name/classified ObjectID (CID) + ShapeFactory::setShapeName(pShape + , ObjectIdentifier::createPointCID( + pSeries->getPointCID_Stub(),nPointIndex) ); } - //set name/classified ObjectID (CID) - ShapeFactory::setShapeName(xShape - , ObjectIdentifier::createPointCID( - pSeries->getPointCID_Stub(),nPointIndex) ); + } //create error bar diff --git a/chart2/source/view/charttypes/NetChart.cxx b/chart2/source/view/charttypes/NetChart.cxx index cf99d3ab0dae..cd1b6eea193d 100644 --- a/chart2/source/view/charttypes/NetChart.cxx +++ b/chart2/source/view/charttypes/NetChart.cxx @@ -222,14 +222,12 @@ bool NetChart::impl_createArea( VDataSeries* pSeries pPosHelper->transformScaledLogicToScene( aPoly ); //create area: - rtl::Reference<SvxShapePolyPolygon> - xShape = ShapeFactory::createArea2D( xSeriesGroupShape_Shapes - , aPoly ); - PropertyMapper::setMappedProperties( *xShape - , pSeries->getPropertiesOfSeries() - , PropertyMapper::getPropertyNameMapForFilledSeriesProperties() ); + SdrPathObj* pShape = ShapeFactory::createArea2D( xSeriesGroupShape_Shapes + , aPoly ); + PropertyMapper::setPropertyNameMapForFilledSeriesProperties(pShape + , pSeries->getPropertiesOfSeries() ); //because of this name this line will be used for marking - ::chart::ShapeFactory::setShapeName(xShape, "MarkHandles"); + ::chart::ShapeFactory::setShapeName(pShape, "MarkHandles"); return true; } diff --git a/chart2/source/view/inc/PropertyMapper.hxx b/chart2/source/view/inc/PropertyMapper.hxx index 3f627aae3163..897876128429 100644 --- a/chart2/source/view/inc/PropertyMapper.hxx +++ b/chart2/source/view/inc/PropertyMapper.hxx @@ -20,6 +20,7 @@ #include <sal/config.h> +#include <optional> #include <unordered_map> #include <com/sun/star/uno/Sequence.h> @@ -27,6 +28,7 @@ namespace com::sun::star::beans { class XPropertySet; } class SvxShape; +class SdrPathObj; namespace chart { @@ -105,6 +107,9 @@ public: static const tPropertyNameMap& getPropertyNameMapForTextShapeProperties(); static const tPropertyNameMap& getPropertyNameMapForFilledSeriesProperties(); + static void setPropertyNameMapForFilledSeriesProperties(SdrPathObj* pShape, + const css::uno::Reference< css::beans::XPropertySet >& xSource, + std::optional<sal_Int32> xFillColor = {}); static const tPropertyNameMap& getPropertyNameMapForLineSeriesProperties(); static const tPropertyNameMap& getPropertyNameMapForTextLabelProperties(); diff --git a/chart2/source/view/inc/ShapeFactory.hxx b/chart2/source/view/inc/ShapeFactory.hxx index 6f9bc6e12ab4..e326b771b2e4 100644 --- a/chart2/source/view/inc/ShapeFactory.hxx +++ b/chart2/source/view/inc/ShapeFactory.hxx @@ -40,6 +40,7 @@ namespace com::sun::star::drawing { struct Position3D; } namespace com::sun::star::graphic { class XGraphic; } namespace com::sun::star::lang { class XMultiServiceFactory; } namespace com::sun::star::drawing { struct Direction3D; } +class SdrPathObj; namespace chart { @@ -154,7 +155,7 @@ public: , const css::drawing::PolyPolygonShape3D& rPolyPolygon , double fDepth); - static rtl::Reference<SvxShapePolyPolygon> + static SdrPathObj* createArea2D( const rtl::Reference<SvxShapeGroupAnyD>& xTarget , const css::drawing::PolyPolygonShape3D& rPolyPolygon); @@ -250,6 +251,8 @@ public: static void setShapeName( const rtl::Reference< SvxShape >& xShape , const OUString& rName ); + static void setShapeName( SdrPathObj* pPath + , const OUString& rName ); static OUString getShapeName( const css::uno::Reference< css::drawing::XShape >& xShape ); diff --git a/chart2/source/view/main/PropertyMapper.cxx b/chart2/source/view/main/PropertyMapper.cxx index e9e46998af7a..c54d15a8aa53 100644 --- a/chart2/source/view/main/PropertyMapper.cxx +++ b/chart2/source/view/main/PropertyMapper.cxx @@ -22,13 +22,34 @@ #include <com/sun/star/beans/XMultiPropertySet.hpp> #include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/drawing/BitmapMode.hpp> #include <com/sun/star/drawing/TextVerticalAdjust.hpp> #include <com/sun/star/drawing/TextHorizontalAdjust.hpp> +#include <com/sun/star/drawing/FillStyle.hpp> #include <com/sun/star/drawing/LineJoint.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> +#include <com/sun/star/drawing/RectanglePoint.hpp> #include <com/sun/star/style/ParagraphAdjust.hpp> #include <comphelper/sequence.hxx> #include <tools/diagnose_ex.h> #include <svx/unoshape.hxx> +#include <svx/svdopath.hxx> +#include <svx/xfillit0.hxx> +#include <svx/xflbckit.hxx> +#include <svx/xflbmpit.hxx> +#include <svx/xflbmsli.hxx> +#include <svx/xflbmsxy.hxx> +#include <svx/xflbmtit.hxx> +#include <svx/xflboxy.hxx> +#include <svx/xflbstit.hxx> +#include <svx/xflbtoxy.hxx> +#include <svx/xflclit.hxx> +#include <svx/xfltrit.hxx> +#include <svx/xlineit0.hxx> +#include <svx/xlncapit.hxx> +#include <svx/xlnclit.hxx> +#include <svx/xlntrit.hxx> +#include <svx/xlnwtit.hxx> namespace chart { @@ -478,6 +499,110 @@ const tPropertyNameMap& PropertyMapper::getPropertyNameMapForFilledSeriesPropert return s_aShapePropertyMapForFilledSeriesProperties; } +void PropertyMapper::setPropertyNameMapForFilledSeriesProperties(SdrPathObj* pShape + , const uno::Reference< beans::XPropertySet >& xSource + , std::optional<sal_Int32> xFillColor) +{ + //shape property -- chart model object property + static tPropertyNameMap s_aShapePropertyMapForFilledSeriesProperties{ + {"FillBackground", "FillBackground"}, + {"FillBitmapName", "FillBitmapName"}, + {"FillColor", "Color"}, + {"FillGradientName", "GradientName"}, + {"FillGradientStepCount", "GradientStepCount"}, + {"FillHatchName", "HatchName"}, + {"FillStyle", "FillStyle"}, + {"FillTransparence", "Transparency"}, + {"FillTransparenceGradientName", "TransparencyGradientName"}, + //bitmap properties + {"FillBitmapMode", "FillBitmapMode"}, + {"FillBitmapSizeX", "FillBitmapSizeX"}, + {"FillBitmapSizeY", "FillBitmapSizeY"}, + {"FillBitmapLogicalSize", "FillBitmapLogicalSize"}, + {"FillBitmapOffsetX", "FillBitmapOffsetX"}, + {"FillBitmapOffsetY", "FillBitmapOffsetY"}, + {"FillBitmapRectanglePoint", "FillBitmapRectanglePoint"}, + {"FillBitmapPositionOffsetX", "FillBitmapPositionOffsetX"}, + {"FillBitmapPositionOffsetY", "FillBitmapPositionOffsetY"}, + //line properties + {"LineColor", "BorderColor"}, + {"LineDashName", "BorderDashName"}, + {"LineStyle", "BorderStyle"}, + {"LineTransparence", "BorderTransparency"}, + {"LineWidth", "BorderWidth"}, + {"LineCap", "LineCap"}}; + std::optional<SfxItemSet> xOptionSet; + for (auto const& elem : s_aShapePropertyMapForFilledSeriesProperties) + { + const OUString & rSource = elem.second; + try + { + uno::Any aAny( xSource->getPropertyValue(rSource) ); + //do not set empty anys because of performance (otherwise SdrAttrObj::ItemChange will take much longer) + if( !aAny.hasValue() ) + continue; + if (!xOptionSet) + xOptionSet.emplace(pShape->GetObjectItemPool()); + if (rSource == "FillBackground") + xOptionSet->Put(XFillBackgroundItem(aAny.get<bool>())); + else if (rSource == "Color") + xOptionSet->Put(XFillColorItem(OUString(), Color(ColorTransparency, aAny.get<sal_Int32>()))); + else if (rSource == "FillStyle") + xOptionSet->Put(XFillStyleItem(aAny.get<css::drawing::FillStyle>())); + else if (rSource == "Transparency") + xOptionSet->Put(XFillTransparenceItem(aAny.get<sal_uInt16>())); + else if (rSource == "FillBitmapMode") + { + drawing::BitmapMode aMode; + aAny >>= aMode; + xOptionSet->Put( XFillBmpTileItem( aMode == drawing::BitmapMode_REPEAT ) ); + xOptionSet->Put( XFillBmpStretchItem( aMode == drawing::BitmapMode_STRETCH ) ); + } + else if (rSource == "FillBitmapSizeX") + xOptionSet->Put(XFillBmpSizeXItem(aAny.get<sal_Int32>())); + else if (rSource == "FillBitmapSizeY") + xOptionSet->Put(XFillBmpSizeYItem(aAny.get<sal_Int32>())); + else if (rSource == "FillBitmapLogicalSize") + xOptionSet->Put(XFillBmpSizeLogItem(aAny.get<bool>())); + else if (rSource == "FillBitmapPositionOffsetX") + xOptionSet->Put(XFillBmpPosOffsetXItem(aAny.get<sal_Int32>())); + else if (rSource == "FillBitmapPositionOffsetY") + xOptionSet->Put(XFillBmpPosOffsetYItem(aAny.get<sal_Int32>())); + else if (rSource == "FillBitmapRectanglePoint") + xOptionSet->Put(XFillBmpPosItem(static_cast<RectPoint>(aAny.get<css::drawing::RectanglePoint>()))); + else if (rSource == "FillBitmapOffsetX") + xOptionSet->Put(XFillBmpTileOffsetXItem(aAny.get<sal_Int32>())); + else if (rSource == "FillBitmapOffsetY") + xOptionSet->Put(XFillBmpTileOffsetYItem(aAny.get<sal_Int32>())); + else if (rSource == "BorderColor") + xOptionSet->Put(XLineColorItem(OUString(), Color(ColorTransparency, aAny.get<sal_Int32>()))); + else if (rSource == "BorderStyle") + xOptionSet->Put(XLineStyleItem(aAny.get<css::drawing::LineStyle>())); + else if (rSource == "BorderTransparency") + xOptionSet->Put(XLineTransparenceItem(aAny.get<sal_uInt16>())); + else if (rSource == "BorderWidth") + xOptionSet->Put(XLineWidthItem(aAny.get<sal_Int32>())); + else if (rSource == "LineCap") + xOptionSet->Put(XLineCapItem(aAny.get<css::drawing::LineCap>())); + else + SAL_WARN("chart2", "forgot this one " << rSource); + } + catch( const uno::Exception& ) + { + TOOLS_WARN_EXCEPTION("chart2", "" ); + } + } + if (xFillColor) + { + if (!xOptionSet) + xOptionSet.emplace(pShape->GetObjectItemPool()); + xOptionSet->Put(XFillColorItem(OUString(), Color(ColorTransparency, *xFillColor))); + } + if (xOptionSet) + pShape->SetMergedItemSet(*xOptionSet); + +} + void PropertyMapper::setMultiProperties( const tNameSequence& rNames , const tAnySequence& rValues diff --git a/chart2/source/view/main/ShapeFactory.cxx b/chart2/source/view/main/ShapeFactory.cxx index afcea1802274..efc7f0d90787 100644 --- a/chart2/source/view/main/ShapeFactory.cxx +++ b/chart2/source/view/main/ShapeFactory.cxx @@ -55,6 +55,8 @@ #include <basegfx/point/b2dpoint.hxx> #include <basegfx/matrix/b3dhommatrix.hxx> #include <svx/unoprov.hxx> +#include <svx/svdpage.hxx> +#include <svx/svdopath.hxx> #include <tools/diagnose_ex.h> #include <tools/helpers.hxx> #include <tools/UnitConversion.hxx> @@ -1080,7 +1082,7 @@ rtl::Reference<Svx3DExtrudeObject> } -rtl::Reference<SvxShapePolyPolygon> +SdrPathObj* ShapeFactory::createArea2D( const rtl::Reference<SvxShapeGroupAnyD>& xTarget , const drawing::PolyPolygonShape3D& rPolyPolygon ) { @@ -1088,30 +1090,24 @@ rtl::Reference<SvxShapePolyPolygon> return nullptr; //create shape - rtl::Reference<SvxShapePolyPolygon> xShape = new SvxShapePolyPolygon(nullptr); - xShape->setShapeKind(OBJ_POLY); - xTarget->add(uno::Reference<drawing::XShape>(xShape)); + SdrPathObj* pPath = new SdrPathObj(xTarget->GetSdrObject()->getSdrModelFromSdrObject(), OBJ_POLY); + // insert at ZOrder 0, an area should always be behind other shapes + xTarget->GetSdrObject()->GetSubList()->InsertObject(pPath, 0); //set properties try { - //UNO_NAME_POLYGON "Polygon" drawing::PointSequence* - drawing::PointSequenceSequence aPoints( PolyToPointSequence(rPolyPolygon) ); - - //Polygon - xShape->SvxShape::setPropertyValue( UNO_NAME_POLYPOLYGON - , uno::Any( aPoints ) ); - - //ZOrder - //an area should always be behind other shapes - xShape->SvxShape::setPropertyValue( UNO_NAME_MISC_OBJ_ZORDER - , uno::Any( sal_Int32(0) ) ); + // Polygon + basegfx::B2DPolyPolygon aNewPolyPolygon( PolyToB2DPolyPolygon(rPolyPolygon) ); + // tdf#117145 metric of SdrModel is app-specific, metric of UNO API is 100thmm + pPath->ForceMetricToItemPoolMetric(aNewPolyPolygon); + pPath->SetPathPoly(aNewPolyPolygon); } catch( const uno::Exception& ) { TOOLS_WARN_EXCEPTION("chart2", "" ); } - return xShape; + return pPath; } static drawing::PolyPolygonShape3D createPolyPolygon_Symbol( const drawing::Position3D& rPos @@ -2381,6 +2377,14 @@ void ShapeFactory::makeShapeInvisible( const rtl::Reference< SvxShape >& xShape // set a name/CID at a shape (is used for selection handling) +void ShapeFactory::setShapeName( SdrPathObj* pShape + , const OUString& rName ) +{ + if(!pShape) + return; + pShape->SetName(rName); +} + void ShapeFactory::setShapeName( const rtl::Reference< SvxShape >& xShape , const OUString& rName ) { |