Kaydet (Commit) ecb733da authored tarafından Miklos Vajna's avatar Miklos Vajna

oox smartart, cycle matrix: handle destination order in connections

It is possible to have connections from multiple data nodes to the same
presentation node with a presOf type. We use to order these based on as
they appear in the data XML, but we need to order them according to the
destOrd attribute.

Introduce an std::map for that, so get ordering automatically as we
iterate. Turn the std::pair into a struct to make the code a bit more
readable.

Change-Id: I3d2bb047ed3f171a194851f89151bd94071a8176
Reviewed-on: https://gerrit.libreoffice.org/68027Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
üst 92849660
......@@ -271,8 +271,7 @@ void Diagram::build( )
if( connection.mnType == XML_presOf )
{
DiagramData::StringMap::value_type::second_type& rVec=getData()->getPresOfNameMap()[connection.msDestId];
rVec.emplace_back(
connection.msSourceId,sal_Int32(0));
rVec[connection.mnDestOrder] = { connection.msSourceId, sal_Int32(0) };
}
}
......@@ -282,9 +281,8 @@ void Diagram::build( )
{
for (auto & elem : elemPresOf.second)
{
const sal_Int32 nDepth=calcDepth(elem.first,
getData()->getConnections());
elem.second = nDepth != 0 ? nDepth : -1;
const sal_Int32 nDepth = calcDepth(elem.second.msSourceId, getData()->getConnections());
elem.second.mnDepth = nDepth != 0 ? nDepth : -1;
if (nDepth > getData()->getMaxDepth())
getData()->setMaxDepth(nDepth);
}
......
......@@ -160,8 +160,14 @@ public:
typedef std::map< OUString,
std::vector<dgm::Point*> > PointsNameMap;
typedef std::map< OUString, const dgm::Connection* > ConnectionNameMap;
struct SourceIdAndDepth
{
OUString msSourceId;
sal_Int32 mnDepth = 0;
};
/// Tracks connections: destination id -> {destination order, details} map.
typedef std::map< OUString,
std::vector<std::pair<OUString,sal_Int32> > > StringMap;
std::map<sal_Int32, SourceIdAndDepth > > StringMap;
DiagramData();
FillPropertiesPtr & getFillProperties()
......
......@@ -1168,11 +1168,12 @@ bool LayoutNode::setupShape( const ShapePtr& rShape, const dgm::Point* pPresNode
pPresNode->msModelId);
if( aNodeName != mrDgm.getData()->getPresOfNameMap().end() )
{
for( const auto& rItem : aNodeName->second )
for (const auto& rPair : aNodeName->second)
{
const DiagramData::SourceIdAndDepth& rItem = rPair.second;
DiagramData::PointNameMap& rMap = mrDgm.getData()->getPointNameMap();
// pPresNode is the presentation node of the aDataNode2 data node.
DiagramData::PointNameMap::const_iterator aDataNode2 = rMap.find(rItem.first);
DiagramData::PointNameMap::const_iterator aDataNode2 = rMap.find(rItem.msSourceId);
if (aDataNode2 == rMap.end())
{
//busted, skip it
......@@ -1181,7 +1182,7 @@ bool LayoutNode::setupShape( const ShapePtr& rShape, const dgm::Point* pPresNode
rShape->setDataNodeType(aDataNode2->second->mnType);
if( rItem.second == 0 )
if (rItem.mnDepth == 0)
{
// grab shape attr from topmost element(s)
rShape->getShapeProperties() = aDataNode2->second->mpShape->getShapeProperties();
......@@ -1223,8 +1224,8 @@ bool LayoutNode::setupShape( const ShapePtr& rShape, const dgm::Point* pPresNode
for (const auto& pSourceParagraph : rSourceParagraphs)
{
TextParagraph& rPara = pTextBody->addParagraph();
if (rItem.second != -1)
rPara.getProperties().setLevel(rItem.second);
if (rItem.mnDepth != -1)
rPara.getProperties().setLevel(rItem.mnDepth);
for (const auto& pRun : pSourceParagraph->getRuns())
rPara.addRun(pRun);
......
......@@ -853,7 +853,9 @@ void SdImportTestSmartArt::testCycleMatrix()
uno::Reference<text::XText> xC2(getChildShape(getChildShape(getChildShape(xGroup, 0), 2), 1),
uno::UNO_QUERY);
CPPUNIT_ASSERT(xC2.is());
CPPUNIT_ASSERT_EQUAL(OUString("C2"), xC2->getString());
// Without the accompanying fix in place, this test would have failed, i.e. the order of the
// lines in the shape were wrong: C2-1\nC2-4\nC2-3\nC2-2.
CPPUNIT_ASSERT_EQUAL(OUString("C2-1\nC2-2\nC2-3\nC2-4"), xC2->getString());
uno::Reference<drawing::XShape> xC2Shape(xC2, uno::UNO_QUERY);
CPPUNIT_ASSERT(xC2Shape.is());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment