diff options
author | Armin Le Grand (Allotropia) <Armin.Le.Grand@me.com> | 2022-04-19 11:37:57 +0200 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@me.com> | 2022-04-20 09:32:52 +0200 |
commit | d9b3374b13108cf6b847f6eb92fb666194a68770 (patch) | |
tree | eba87516cdef9e68a15ef85fa834b1e89eec54ca /svx/source | |
parent | f22f83fbac3a0a419c2e95d7b725525fd02649e6 (diff) |
Advanced Diagram support: Use better association Model<->XShape
To have a more direct and more reliable association between the
XShape/oox::Shape and the model data svx::diagram::Point I added
optional usage of the Model-UUID for that at the oox::Shape.
Also added a 'fake' UUID to work with the BackgroundShape's
attributes. Changed all preserve/rescue code to work based on that.
Also cleanups/comments and preparations of some flags in the
Diagram ModelData to steer behaviour on re-ceration.
Change-Id: Ie30effdff34dcdbbc79a766de09157b2a3bd97d3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133168
Tested-by: Jenkins
Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
Diffstat (limited to 'svx/source')
-rw-r--r-- | svx/source/diagram/datamodel.cxx | 179 | ||||
-rw-r--r-- | svx/source/svdraw/svdogrp.cxx | 8 |
2 files changed, 14 insertions, 173 deletions
diff --git a/svx/source/diagram/datamodel.cxx b/svx/source/diagram/datamodel.cxx index 44e9977326a0..fd562645eaa0 100644 --- a/svx/source/diagram/datamodel.cxx +++ b/svx/source/diagram/datamodel.cxx @@ -23,15 +23,6 @@ #include <svx/diagram/datamodel.hxx> #include <comphelper/xmltools.hxx> -#include <com/sun/star/uno/Reference.hxx> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/beans/XPropertyState.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/drawing/FillStyle.hpp> -#include <com/sun/star/drawing/LineStyle.hpp> -#include <com/sun/star/text/XText.hpp> - -#include <editeng/unoprnms.hxx> #include <sal/log.hxx> namespace svx::diagram { @@ -44,7 +35,9 @@ Connection::Connection() } Point::Point() -: mnXMLType(XML_none) +: msTextBody(std::make_shared< TextBody >()) +, msPointStylePtr(std::make_shared< PointStyle >()) +, mnXMLType(XML_none) , mnMaxChildren(-1) , mnPreferredChildren(-1) , mnDirection(XML_norm) @@ -72,163 +65,6 @@ Point::Point() { } -static void addProperty(const OUString& rName, - const css::uno::Reference< css::beans::XPropertySetInfo >& xInfo, - std::vector< std::pair< OUString, css::uno::Any >>& rTarget, - const css::uno::Reference< css::beans::XPropertySet >& xPropSet ) -{ - if(xInfo->hasPropertyByName(rName)) - rTarget.push_back(std::pair(OUString(rName), xPropSet->getPropertyValue(rName))); -} - -void Point::securePropertiesFromXShape(const css::uno::Reference< css::drawing::XShape >& rXShape) -{ - if(!rXShape) - return; - -#ifdef DBG_UTIL - // to easier decide which additional properties may/should be preserved, - // create a full list of set properties to browse/decide (in debugger) - const css::uno::Reference< css::beans::XPropertyState > xAllPropStates(rXShape, css::uno::UNO_QUERY); - const css::uno::Reference< css::beans::XPropertySet > xAllPropSet( rXShape, css::uno::UNO_QUERY ); - const css::uno::Sequence< css::beans::Property > allSequence(xAllPropSet->getPropertySetInfo()->getProperties()); - std::vector< std::pair< OUString, css::uno::Any >> allSetProps; - for (auto& rProp : allSequence) - { - try - { - if (xAllPropStates->getPropertyState(rProp.Name) == css::beans::PropertyState::PropertyState_DIRECT_VALUE) - { - css::uno::Any aValue(xAllPropSet->getPropertyValue(rProp.Name)); - if(aValue.hasValue()) - allSetProps.push_back(std::pair(rProp.Name, aValue)); - } - } - catch (...) - { - } - } -#endif - - const css::uno::Reference< css::beans::XPropertySet > xPropSet( rXShape, css::uno::UNO_QUERY ); - if(!xPropSet) - return; - - const css::uno::Reference< css::lang::XServiceInfo > xServiceInfo( rXShape, css::uno::UNO_QUERY ); - if(!xServiceInfo) - return; - - const css::uno::Reference< css::beans::XPropertySetInfo > xInfo(xPropSet->getPropertySetInfo()); - if (!xInfo.is()) - return; - - if(!msPointStylePtr) - msPointStylePtr = std::make_shared< svx::diagram::PointStyle >(); - - // shortcut to target - std::vector< std::pair< OUString, css::uno::Any >>& rTarget(msPointStylePtr->maProperties); - - // Note: The Text may also be secured here, so it may also be possible to - // secure/store it at PointStyle instead of at TextBody, same maybe evaluated - // for the text attributes - where when securing here the attributes would be - // in our UNO API format already. - // if(xServiceInfo->supportsService("com.sun.star.drawing.Text")) - // { - // css::uno::Reference< css::text::XText > xText(rXShape, css::uno::UNO_QUERY); - // const OUString aText(xText->getString()); - // - // if(!aText.isEmpty()) - // { - // } - // } - - // Add all kinds of properties that are needed to re-create the XShape. - // For now this is a minimal example-selection, it will need to be extended - // over time for all kind of cases/properties - - // text properties - if(xServiceInfo->supportsService("com.sun.star.drawing.TextProperties")) - { - addProperty(UNO_NAME_CHAR_COLOR, xInfo, rTarget, xPropSet); - addProperty(UNO_NAME_CHAR_HEIGHT, xInfo, rTarget, xPropSet); - addProperty(UNO_NAME_CHAR_SHADOWED, xInfo, rTarget, xPropSet); - addProperty(UNO_NAME_CHAR_WEIGHT, xInfo, rTarget, xPropSet); - } - - // fill properties - if(xServiceInfo->supportsService("com.sun.star.drawing.FillProperties")) - { - css::drawing::FillStyle eFillStyle(css::drawing::FillStyle_NONE); - if (xInfo->hasPropertyByName(UNO_NAME_FILLSTYLE)) - xPropSet->getPropertyValue(UNO_NAME_FILLSTYLE) >>= eFillStyle; - - if(css::drawing::FillStyle_NONE != eFillStyle) - { - addProperty(UNO_NAME_FILLSTYLE, xInfo, rTarget, xPropSet); - - switch(eFillStyle) - { - case css::drawing::FillStyle_SOLID: - { - addProperty(UNO_NAME_FILLCOLOR, xInfo, rTarget, xPropSet); - break; - } - default: - case css::drawing::FillStyle_NONE: - case css::drawing::FillStyle_GRADIENT: - case css::drawing::FillStyle_HATCH: - case css::drawing::FillStyle_BITMAP: - break; - } - } - } - - // line properties - if(xServiceInfo->supportsService("com.sun.star.drawing.LineProperties")) - { - css::drawing::LineStyle eLineStyle(css::drawing::LineStyle_NONE); - if (xInfo->hasPropertyByName(UNO_NAME_LINESTYLE)) - xPropSet->getPropertyValue(UNO_NAME_LINESTYLE) >>= eLineStyle; - - if(css::drawing::LineStyle_NONE != eLineStyle) - { - addProperty(UNO_NAME_LINESTYLE, xInfo, rTarget, xPropSet); - addProperty(UNO_NAME_LINECOLOR, xInfo, rTarget, xPropSet); - addProperty(UNO_NAME_LINEWIDTH, xInfo, rTarget, xPropSet); - - switch(eLineStyle) - { - case css::drawing::LineStyle_SOLID: - break; - default: - case css::drawing::LineStyle_NONE: - case css::drawing::LineStyle_DASH: - break; - } - } - } -} - -void Point::restorePropertiesToXShape(const css::uno::Reference< css::drawing::XShape >& rXShape) const -{ - if(!msPointStylePtr) - return; - - if(!rXShape) - return; - - css::uno::Reference<css::beans::XPropertySet> xPropSet(rXShape, css::uno::UNO_QUERY); - if(!xPropSet) - return; - - std::vector< std::pair< OUString, css::uno::Any >>& rSource(msPointStylePtr->maProperties); - - for (auto const& prop : rSource) - { - xPropSet->setPropertyValue(prop.first, prop.second); - } -} - DiagramData::DiagramData() { } @@ -319,8 +155,7 @@ void DiagramData::getChildrenString( rBuf.append('\t'); rBuf.append('+'); rBuf.append(' '); - if(pPoint->msTextBody) - rBuf.append(pPoint->msTextBody->msText); + rBuf.append(pPoint->msTextBody->msText); rBuf.append('\n'); } @@ -353,7 +188,7 @@ std::vector<std::pair<OUString, OUString>> DiagramData::getChildren(const OUStri { aChildren[rCxn.mnSourceOrder] = std::make_pair( pChild->second->msModelId, - pChild->second->msTextBody ? pChild->second->msTextBody->msText : OUString()); + pChild->second->msTextBody->msText); } } @@ -381,7 +216,6 @@ OUString DiagramData::addNode(const OUString& rText) svx::diagram::Point aDataPoint; aDataPoint.mnXMLType = TypeConstant::XML_node; aDataPoint.msModelId = sNewNodeId; - aDataPoint.msTextBody = std::make_shared<TextBody>(); aDataPoint.msTextBody->msText = rText; OUString sDataSibling; @@ -482,6 +316,7 @@ void DiagramData::buildDiagramDataModel(bool /*bClearOoxShapes*/) maPointsPresNameMap.clear(); maConnectionNameMap.clear(); maPresOfNameMap.clear(); + msBackgroundShapeModelID.clear(); #ifdef DEBUG_OOX_DIAGRAM std::ofstream output("tree.dot"); @@ -522,7 +357,7 @@ void DiagramData::buildDiagramDataModel(bool /*bClearOoxShapes*/) #endif // does currpoint have any text set? - if(point.msTextBody && !point.msTextBody->msText.isEmpty()) + if(!point.msTextBody->msText.isEmpty()) { #ifdef DEBUG_OOX_DIAGRAM static sal_Int32 nCount=0; diff --git a/svx/source/svdraw/svdogrp.cxx b/svx/source/svdraw/svdogrp.cxx index 91e8174eea70..b1ad4b729e7e 100644 --- a/svx/source/svdraw/svdogrp.cxx +++ b/svx/source/svdraw/svdogrp.cxx @@ -34,7 +34,13 @@ #include <libxml/xmlwriter.h> #include <vcl/canvastools.hxx> -IDiagramHelper::IDiagramHelper() {} +IDiagramHelper::IDiagramHelper() +: mbUseDiagramThemeData(false) +, mbUseDiagramModelData(true) +, mbForceThemePtrReceation(false) +{ +} + IDiagramHelper::~IDiagramHelper() {} void IDiagramHelper::anchorToSdrObjGroup(SdrObjGroup& rTarget) |