From ca6d879f765dad8471d42ec736b1f4235e5b8da4 Mon Sep 17 00:00:00 2001 From: "Armin Le Grand (Allotropia)" Date: Wed, 30 Mar 2022 11:48:08 +0200 Subject: Advanced Diagram support: Move class DiagramData to svx AFAP Splitted and moved parts of DiagramData class to svx as peparation to access from there. Done as pure virtual class so that no incarnations will be possible, also made the constructor protected. The derived class in oox hosts all functionality/data which involves usage/modification of oox::Shape class. That way we get closer to get the Diagram DataModel isloated/seperated. Not-yet moved is the String/Text holding data, it's still in oox. Moving that one will be next, that will allow to migrate quite some more functionalty to svx. Change-Id: I389dbf3ebf6171b8175cf30be7bbc8c20d9a38e1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132303 Tested-by: Jenkins Reviewed-by: Armin Le Grand --- svx/source/diagram/datamodel.cxx | 101 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 2 deletions(-) (limited to 'svx') diff --git a/svx/source/diagram/datamodel.cxx b/svx/source/diagram/datamodel.cxx index 4396ef90ba1f..11b71240b6ec 100644 --- a/svx/source/diagram/datamodel.cxx +++ b/svx/source/diagram/datamodel.cxx @@ -17,6 +17,9 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include +#include + #include #include @@ -26,7 +29,8 @@ Connection::Connection() : mnXMLType( XML_none ) , mnSourceOrder( 0 ) , mnDestOrder( 0 ) -{} +{ +} Point::Point() : mnXMLType(XML_none) @@ -54,7 +58,100 @@ Point::Point() , mbCustomVerticalFlip(false) , mbCustomText(false) , mbIsPlaceholder(false) -{} +{ +} + +DiagramData::DiagramData() +{ +} + +DiagramData::~DiagramData() +{ +} + +const Point* DiagramData::getRootPoint() const +{ + for (const auto & aCurrPoint : maPoints) + if (aCurrPoint.mnXMLType == TypeConstant::XML_doc) + return &aCurrPoint; + + SAL_WARN("svx.diagram", "No root point"); + return nullptr; +} + +OUString DiagramData::getString() const +{ + OUStringBuffer aBuf; + const Point* pPoint = getRootPoint(); + getChildrenString(aBuf, pPoint, 0); + return aBuf.makeStringAndClear(); +} + +bool DiagramData::removeNode(const OUString& rNodeId) +{ + // check if it doesn't have children + for (const auto& aCxn : maConnections) + if (aCxn.mnXMLType == TypeConstant::XML_parOf && aCxn.msSourceId == rNodeId) + { + SAL_WARN("svx.diagram", "Node has children - can't be removed"); + return false; + } + + Connection aParCxn; + for (const auto& aCxn : maConnections) + if (aCxn.mnXMLType == TypeConstant::XML_parOf && aCxn.msDestId == rNodeId) + aParCxn = aCxn; + + std::unordered_set aIdsToRemove; + aIdsToRemove.insert(rNodeId); + if (!aParCxn.msParTransId.isEmpty()) + aIdsToRemove.insert(aParCxn.msParTransId); + if (!aParCxn.msSibTransId.isEmpty()) + aIdsToRemove.insert(aParCxn.msSibTransId); + + for (const Point& rPoint : maPoints) + if (aIdsToRemove.count(rPoint.msPresentationAssociationId)) + aIdsToRemove.insert(rPoint.msModelId); + + // insert also transition nodes + for (const auto& aCxn : maConnections) + if (aIdsToRemove.count(aCxn.msSourceId) || aIdsToRemove.count(aCxn.msDestId)) + if (!aCxn.msPresId.isEmpty()) + aIdsToRemove.insert(aCxn.msPresId); + + // remove connections + maConnections.erase(std::remove_if(maConnections.begin(), maConnections.end(), + [aIdsToRemove](const Connection& rCxn) { + return aIdsToRemove.count(rCxn.msSourceId) || aIdsToRemove.count(rCxn.msDestId); + }), + maConnections.end()); + + // remove data and presentation nodes + maPoints.erase(std::remove_if(maPoints.begin(), maPoints.end(), + [aIdsToRemove](const Point& rPoint) { + return aIdsToRemove.count(rPoint.msModelId); + }), + maPoints.end()); + + // TODO: fix source/dest order + + build(true); + return true; +} + +void DiagramData::addConnection(svx::diagram::TypeConstant nType, const OUString& sSourceId, const OUString& sDestId) +{ + sal_Int32 nMaxOrd = -1; + for (const auto& aCxn : maConnections) + if (aCxn.mnXMLType == nType && aCxn.msSourceId == sSourceId) + nMaxOrd = std::max(nMaxOrd, aCxn.mnSourceOrder); + + svx::diagram::Connection& rCxn = maConnections.emplace_back(); + rCxn.mnXMLType = nType; + rCxn.msSourceId = sSourceId; + rCxn.msDestId = sDestId; + rCxn.mnSourceOrder = nMaxOrd + 1; +} } -- cgit