tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / oox / source / drawingml / diagram / layoutatomvisitors.cxx
blob482894ee159e4b950c89833cd0a8fb715313f644
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "layoutatomvisitors.hxx"
22 #include <drawingml/customshapeproperties.hxx>
24 #include <sal/log.hxx>
26 using namespace ::com::sun::star;
27 using namespace ::com::sun::star::xml::sax;
29 namespace oox::drawingml
31 void ShapeCreationVisitor::visit(ConstraintAtom& /*rAtom*/)
33 // stop processing
36 void ShapeCreationVisitor::visit(RuleAtom& /*rAtom*/)
38 // stop processing
41 void ShapeCreationVisitor::visit(AlgAtom& rAtom)
43 if (meLookFor == ALGORITHM)
45 mpParentShape->setAspectRatio(rAtom.getAspectRatio());
46 mpParentShape->setVerticalShapesCount(rAtom.getVerticalShapesCount(mpParentShape));
50 void ShapeCreationVisitor::visit(LayoutNode& rAtom)
52 if (meLookFor != LAYOUT_NODE)
53 return;
55 // stop processing if it's not a child of previous LayoutNode
57 const DiagramData::PointsNameMap::const_iterator aDataNode
58 = mrDgm.getData()->getPointsPresNameMap().find(rAtom.getName());
59 if (aDataNode == mrDgm.getData()->getPointsPresNameMap().end()
60 || mnCurrIdx >= static_cast<sal_Int32>(aDataNode->second.size()))
61 return;
63 const svx::diagram::Point* pNewNode = aDataNode->second.at(mnCurrIdx);
64 if (!mpCurrentNode || !pNewNode)
65 return;
67 bool bIsChild = false;
68 for (const auto& aConnection : mrDgm.getData()->getConnections())
69 if (aConnection.msSourceId == mpCurrentNode->msModelId
70 && aConnection.msDestId == pNewNode->msModelId)
71 bIsChild = true;
73 if (!bIsChild)
74 return;
76 ShapePtr xCurrParent(mpParentShape);
78 if (rAtom.getExistingShape())
80 // reuse existing shape
81 ShapePtr pShape = rAtom.getExistingShape();
82 if (rAtom.setupShape(pShape, pNewNode, mnCurrIdx))
84 pShape->setInternalName(rAtom.getName());
85 rAtom.addNodeShape(pShape);
86 mrDgm.getLayout()->getPresPointShapeMap()[pNewNode] = std::move(pShape);
89 else
91 ShapeTemplateVisitor aTemplateVisitor(mrDgm, pNewNode);
92 aTemplateVisitor.defaultVisit(rAtom);
93 ShapePtr pShape = aTemplateVisitor.getShapeCopy();
95 if (pShape)
97 SAL_INFO("oox.drawingml",
98 "processing shape type "
99 << (pShape->getCustomShapeProperties()->getShapePresetType()));
101 if (rAtom.setupShape(pShape, pNewNode, mnCurrIdx))
103 pShape->setInternalName(rAtom.getName());
104 xCurrParent->addChild(pShape);
105 xCurrParent = pShape;
106 rAtom.addNodeShape(pShape);
107 mrDgm.getLayout()->getPresPointShapeMap()[pNewNode] = std::move(pShape);
110 else
112 SAL_WARN("oox.drawingml",
113 "ShapeCreationVisitor::visit: no shape set while processing layoutnode named "
114 << rAtom.getName());
118 const svx::diagram::Point* pPreviousNode = mpCurrentNode;
119 mpCurrentNode = pNewNode;
121 // set new parent for children
122 ShapePtr xPreviousParent(mpParentShape);
123 mpParentShape = std::move(xCurrParent);
125 // process children
126 meLookFor = LAYOUT_NODE;
127 defaultVisit(rAtom);
129 meLookFor = ALGORITHM;
130 defaultVisit(rAtom);
131 meLookFor = LAYOUT_NODE;
133 // restore parent
134 mpParentShape = std::move(xPreviousParent);
135 mpCurrentNode = pPreviousNode;
138 void ShapeCreationVisitor::visit(ShapeAtom& /*rAtom*/)
140 // stop processing
143 void ShapeTemplateVisitor::visit(ConstraintAtom& /*rAtom*/)
145 // stop processing
148 void ShapeTemplateVisitor::visit(RuleAtom& /*rAtom*/)
150 // stop processing
153 void ShapeTemplateVisitor::visit(AlgAtom& /*rAtom*/)
155 // stop processing
158 void ShapeTemplateVisitor::visit(ForEachAtom& /*rAtom*/)
160 // stop processing
163 void ShapeTemplateVisitor::visit(LayoutNode& /*rAtom*/)
165 // stop processing - only traverse Condition/Choose atoms
168 void ShapeTemplateVisitor::visit(ShapeAtom& rAtom)
170 if (mpShape)
172 SAL_WARN("oox.drawingml", "multiple shapes encountered inside LayoutNode");
173 return;
176 const ShapePtr& pCurrShape(rAtom.getShapeTemplate());
178 // TODO(F3): cloned shape shares all properties by reference,
179 // don't change them!
180 mpShape = std::make_shared<Shape>(pCurrShape);
181 // Fill properties have to be changed as sometimes only the presentation node contains the blip
182 // fill, unshare those.
183 mpShape->cloneFillProperties();
185 // add/set ModelID from current node to allow later association
186 if (mpCurrentNode)
187 mpShape->setDiagramDataModelID(mpCurrentNode->msModelId);
190 void ShapeLayoutingVisitor::visit(ConstraintAtom& rAtom)
192 if (meLookFor == CONSTRAINT)
193 rAtom.parseConstraint(maConstraints, /*bRequireForName=*/true);
196 void ShapeLayoutingVisitor::visit(RuleAtom& rAtom)
198 if (meLookFor == RULE)
199 rAtom.parseRule(maRules);
202 void ShapeLayoutingVisitor::visit(AlgAtom& rAtom)
204 if (meLookFor == ALGORITHM)
206 const PresPointShapeMap aMap
207 = rAtom.getLayoutNode().getDiagram().getLayout()->getPresPointShapeMap();
208 auto pShape = aMap.find(mpCurrentNode);
209 if (pShape != aMap.end())
210 rAtom.layoutShape(pShape->second, maConstraints, maRules);
214 void ShapeLayoutingVisitor::visit(LayoutNode& rAtom)
216 if (meLookFor != LAYOUT_NODE)
217 return;
219 // stop processing if it's not a child of previous LayoutNode
221 const DiagramData::PointsNameMap::const_iterator aDataNode
222 = mrDgm.getData()->getPointsPresNameMap().find(rAtom.getName());
223 if (aDataNode == mrDgm.getData()->getPointsPresNameMap().end()
224 || mnCurrIdx >= static_cast<sal_Int32>(aDataNode->second.size()))
225 return;
227 const svx::diagram::Point* pNewNode = aDataNode->second.at(mnCurrIdx);
228 if (!mpCurrentNode || !pNewNode)
229 return;
231 bool bIsChild = false;
232 for (const auto& aConnection : mrDgm.getData()->getConnections())
233 if (aConnection.msSourceId == mpCurrentNode->msModelId
234 && aConnection.msDestId == pNewNode->msModelId)
235 bIsChild = true;
237 if (!bIsChild)
238 return;
240 size_t nParentConstraintsNumber = maConstraints.size();
242 const svx::diagram::Point* pPreviousNode = mpCurrentNode;
243 mpCurrentNode = pNewNode;
245 // process alg atoms first, nested layout nodes afterwards
246 meLookFor = CONSTRAINT;
247 defaultVisit(rAtom);
248 meLookFor = RULE;
249 defaultVisit(rAtom);
250 meLookFor = ALGORITHM;
251 defaultVisit(rAtom);
252 meLookFor = LAYOUT_NODE;
253 defaultVisit(rAtom);
255 mpCurrentNode = pPreviousNode;
257 // delete added constraints, keep parent constraints
258 maConstraints.erase(maConstraints.begin() + nParentConstraintsNumber, maConstraints.end());
261 void ShapeLayoutingVisitor::visit(ShapeAtom& /*rAtom*/)
263 // stop processing
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */