diff options
author | Grzegorz Araminowicz <grzegorz.araminowicz@collabora.com> | 2019-07-02 16:53:40 +0200 |
---|---|---|
committer | Grzegorz Araminowicz <grzegorz.araminowicz@collabora.com> | 2019-07-02 18:16:22 +0200 |
commit | b21f84cc58d102ba0e9e99dffcbe5c9a8339308c (patch) | |
tree | 6d84b4bb623fddf545216cadb37b3b505d33feea /oox | |
parent | 9194eda9df01fb0ca04948e041caaa1a8d9db021 (diff) |
SmartArt: make if-node functions relative to current presentation node
* maxDepth calculates maximum depth of associated data node children
(instead of per-diagram max depth)
* cnt counts children of associated data node (instead of looking up presOf
node and if not found counting presentation node children)
Change-Id: Ifb50510acb9e6a3d2655197102060ec1c207075b
Reviewed-on: https://gerrit.libreoffice.org/75000
Tested-by: Jenkins
Reviewed-by: Grzegorz Araminowicz <grzegorz.araminowicz@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/drawingml/diagram/diagram.cxx | 5 | ||||
-rw-r--r-- | oox/source/drawingml/diagram/diagram.hxx | 5 | ||||
-rw-r--r-- | oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 51 | ||||
-rw-r--r-- | oox/source/drawingml/diagram/diagramlayoutatoms.hxx | 2 | ||||
-rw-r--r-- | oox/source/drawingml/diagram/layoutatomvisitorbase.cxx | 2 | ||||
-rw-r--r-- | oox/source/helper/attributelist.cxx | 13 |
6 files changed, 40 insertions, 38 deletions
diff --git a/oox/source/drawingml/diagram/diagram.cxx b/oox/source/drawingml/diagram/diagram.cxx index 2a5f2d054721..0edd94a874be 100644 --- a/oox/source/drawingml/diagram/diagram.cxx +++ b/oox/source/drawingml/diagram/diagram.cxx @@ -72,8 +72,7 @@ void Point::dump() const } // dgm namespace DiagramData::DiagramData() : - mpFillProperties( new FillProperties ), - mnMaxDepth(0) + mpFillProperties( new FillProperties ) { } @@ -328,8 +327,6 @@ void Diagram::build( ) { const sal_Int32 nDepth = calcDepth(elem.second.msSourceId, getData()->getConnections()); elem.second.mnDepth = nDepth != 0 ? nDepth : -1; - if (nDepth > getData()->getMaxDepth()) - getData()->setMaxDepth(nDepth); } } #ifdef DEBUG_OOX_DIAGRAM diff --git a/oox/source/drawingml/diagram/diagram.hxx b/oox/source/drawingml/diagram/diagram.hxx index e8839d1b0fe6..8e615ea5fd24 100644 --- a/oox/source/drawingml/diagram/diagram.hxx +++ b/oox/source/drawingml/diagram/diagram.hxx @@ -188,10 +188,6 @@ public: ::std::vector<OUString> &getExtDrawings() { return maExtDrawings; } const dgm::Point* getRootPoint() const; - sal_Int32 getMaxDepth() const - { return mnMaxDepth; } - void setMaxDepth(sal_Int32 nDepth) - { mnMaxDepth = nDepth; } void dump() const; private: ::std::vector<OUString> maExtDrawings; @@ -202,7 +198,6 @@ private: PointsNameMap maPointsPresNameMap; ConnectionNameMap maConnectionNameMap; StringMap maPresOfNameMap; - sal_Int32 mnMaxDepth; }; typedef std::shared_ptr< DiagramData > DiagramDataPtr; diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx index d4845c768331..6a8ffd2c4b3e 100644 --- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx +++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx @@ -176,8 +176,7 @@ void setHierChildConnPosSize(const oox::drawingml::ShapePtr& pShape) namespace oox { namespace drawingml { IteratorAttr::IteratorAttr( ) - : mnAxis( 0 ) - , mnCnt( -1 ) + : mnCnt( -1 ) , mbHideLastTrans( true ) , mnPtType( 0 ) , mnSt( 0 ) @@ -188,12 +187,15 @@ IteratorAttr::IteratorAttr( ) void IteratorAttr::loadFromXAttr( const Reference< XFastAttributeList >& xAttr ) { AttributeList attr( xAttr ); - mnAxis = xAttr->getOptionalValueToken( XML_axis, 0 ); + maAxis = attr.getTokenList(XML_axis); mnCnt = attr.getInteger( XML_cnt, -1 ); mbHideLastTrans = attr.getBool( XML_hideLastTrans, true ); - mnPtType = xAttr->getOptionalValueToken( XML_ptType, 0 ); mnSt = attr.getInteger( XML_st, 0 ); mnStep = attr.getInteger( XML_step, 1 ); + + // better to keep first token instead of error when multiple values + std::vector<sal_Int32> aPtTypes = attr.getTokenList(XML_ptType); + mnPtType = aPtTypes.empty() ? XML_all : aPtTypes.front(); } ConditionAttr::ConditionAttr() @@ -302,25 +304,26 @@ OUString navigate(const LayoutNode& rLayoutNode, sal_Int32 nType, const OUString return OUString(); } + +sal_Int32 calcMaxDepth(const OUString& rNodeName, const dgm::Connections& rConnections) +{ + sal_Int32 nMaxLength = 0; + for (auto const& aCxn : rConnections) + if (aCxn.mnType == XML_parOf && aCxn.msSourceId == rNodeName) + nMaxLength = std::max(nMaxLength, calcMaxDepth(aCxn.msDestId, rConnections) + 1); + + return nMaxLength; +} } sal_Int32 ConditionAtom::getNodeCount(const dgm::Point* pPresPoint) const { sal_Int32 nCount = 0; - OUString sNodeId = navigate(mrLayoutNode, XML_presOf, pPresPoint->msModelId, /*bSourceToDestination*/ false); + OUString sNodeId = pPresPoint->msPresentationAssociationId; - if (sNodeId.isEmpty()) - { - // The current layout node is not a presentation of anything. Look - // up the first presentation child of the layout node. - OUString sFirstPresChildId = navigate(mrLayoutNode, XML_presParOf, pPresPoint->msModelId, - /*bSourceToDestination*/ true); - if (!sFirstPresChildId.isEmpty()) - // It has a presentation child: is that a presentation of a - // model node? - sNodeId = navigate(mrLayoutNode, XML_presOf, sFirstPresChildId, - /*bSourceToDestination*/ false); - } + // HACK: special case - count children of first child + if (maIter.maAxis.size() == 2 && maIter.maAxis[0] == XML_ch && maIter.maAxis[1] == XML_ch) + sNodeId = navigate(mrLayoutNode, XML_parOf, sNodeId, /*bSourceToDestination*/ true); if (!sNodeId.isEmpty()) { @@ -328,14 +331,6 @@ sal_Int32 ConditionAtom::getNodeCount(const dgm::Point* pPresPoint) const if (aCxn.mnType == XML_parOf && aCxn.msSourceId == sNodeId) nCount++; } - else - { - // No presentation child is a presentation of a model node: just - // count presentation children. - for (const auto& aCxn : mrLayoutNode.getDiagram().getData()->getConnections()) - if (aCxn.mnType == XML_presParOf && aCxn.msSourceId == pPresPoint->msModelId) - nCount++; - } return nCount; } @@ -381,8 +376,10 @@ bool ConditionAtom::getDecision(const dgm::Point* pPresPoint) const return compareResult(maCond.mnOp, getNodeCount(pPresPoint), maCond.msVal.toInt32()); case XML_maxDepth: - // TODO: probably depth from current point - docs are unclear - return compareResult(maCond.mnOp, mrLayoutNode.getDiagram().getData()->getMaxDepth(), maCond.msVal.toInt32()); + { + sal_Int32 nMaxDepth = calcMaxDepth(pPresPoint->msPresentationAssociationId, mrLayoutNode.getDiagram().getData()->getConnections()); + return compareResult(maCond.mnOp, nMaxDepth, maCond.msVal.toInt32()); + } case XML_depth: case XML_pos: diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx index dc58fc4b8621..eafe8ce1f1ae 100644 --- a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx +++ b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx @@ -41,7 +41,7 @@ struct IteratorAttr // not sure this belong here, but wth void loadFromXAttr( const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttributes ); - sal_Int32 mnAxis; + std::vector<sal_Int32> maAxis; sal_Int32 mnCnt; bool mbHideLastTrans; sal_Int32 mnPtType; diff --git a/oox/source/drawingml/diagram/layoutatomvisitorbase.cxx b/oox/source/drawingml/diagram/layoutatomvisitorbase.cxx index 49b1d801bee9..c8761ffa3d67 100644 --- a/oox/source/drawingml/diagram/layoutatomvisitorbase.cxx +++ b/oox/source/drawingml/diagram/layoutatomvisitorbase.cxx @@ -60,7 +60,7 @@ void LayoutAtomVisitorBase::visit(ForEachAtom& rAtom) return; } - if (rAtom.iterator().mbHideLastTrans && rAtom.iterator().mnAxis == XML_followSib) + if (rAtom.iterator().mbHideLastTrans && !rAtom.iterator().maAxis.empty() && rAtom.iterator().maAxis[0] == XML_followSib) { // If last transition is hidden and the axis is the follow sibling, // then the last atom should not be visited. diff --git a/oox/source/helper/attributelist.cxx b/oox/source/helper/attributelist.cxx index 22aafdfcf70d..da58fc076672 100644 --- a/oox/source/helper/attributelist.cxx +++ b/oox/source/helper/attributelist.cxx @@ -310,6 +310,19 @@ util::DateTime AttributeList::getDateTime( sal_Int32 nAttrToken, const util::Dat return getDateTime( nAttrToken ).get( rDefault ); } +std::vector<sal_Int32> AttributeList::getTokenList(sal_Int32 nAttrToken) const +{ + std::vector<sal_Int32> aValues; + OUString sValue = getString(nAttrToken, ""); + sal_Int32 nIndex = 0; + do + { + aValues.push_back(AttributeConversion::decodeToken(sValue.getToken(0, ' ', nIndex))); + } while (nIndex >= 0); + + return aValues; +} + } // namespace oox /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |