[Libreoffice-commits] core.git: oox/source sd/qa

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Feb 19 18:36:56 UTC 2019


 oox/source/drawingml/diagram/diagram.cxx            |    8 +++-----
 oox/source/drawingml/diagram/diagram.hxx            |    8 +++++++-
 oox/source/drawingml/diagram/diagramlayoutatoms.cxx |   11 ++++++-----
 sd/qa/unit/data/pptx/smartart-cycle-matrix.pptx     |binary
 sd/qa/unit/import-tests-smartart.cxx                |    4 +++-
 5 files changed, 19 insertions(+), 12 deletions(-)

New commits:
commit ecb733da58b74714eb66d2063a2835ce5c471870
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Feb 19 17:58:42 2019 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Feb 19 19:36:31 2019 +0100

    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/68027
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/oox/source/drawingml/diagram/diagram.cxx b/oox/source/drawingml/diagram/diagram.cxx
index 64dc5dde6d91..97f967280631 100644
--- a/oox/source/drawingml/diagram/diagram.cxx
+++ b/oox/source/drawingml/diagram/diagram.cxx
@@ -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);
         }
diff --git a/oox/source/drawingml/diagram/diagram.hxx b/oox/source/drawingml/diagram/diagram.hxx
index 242ff09fa152..a0955b124230 100644
--- a/oox/source/drawingml/diagram/diagram.hxx
+++ b/oox/source/drawingml/diagram/diagram.hxx
@@ -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()
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index e57a0115e129..b26c32b6fb4b 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -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);
diff --git a/sd/qa/unit/data/pptx/smartart-cycle-matrix.pptx b/sd/qa/unit/data/pptx/smartart-cycle-matrix.pptx
index d154e7f64bc0..76b771644cbb 100644
Binary files a/sd/qa/unit/data/pptx/smartart-cycle-matrix.pptx and b/sd/qa/unit/data/pptx/smartart-cycle-matrix.pptx differ
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index 29b8ae2d7469..2138b2ccf33b 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -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());
 


More information about the Libreoffice-commits mailing list