[Libreoffice-commits] core.git: cui/source cui/uiconfig include/svx oox/source

Grzegorz Araminowicz (via logerrit) logerrit at kemper.freedesktop.org
Tue Aug 27 13:07:00 UTC 2019


 cui/source/dialogs/DiagramDialog.cxx     |   23 +++++++++++++++++++++--
 cui/source/inc/DiagramDialog.hxx         |    4 +++-
 cui/uiconfig/ui/diagramdialog.ui         |    7 ++++++-
 include/svx/DiagramDataInterface.hxx     |    9 +++++++++
 oox/source/drawingml/diagram/diagram.cxx |   18 ++++++++++++++++++
 oox/source/drawingml/diagram/diagram.hxx |    1 +
 6 files changed, 58 insertions(+), 4 deletions(-)

New commits:
commit fae4eb717427f542305d2978f5fa78cbf27eaafa
Author:     Grzegorz Araminowicz <grzegorz.araminowicz at collabora.com>
AuthorDate: Tue Aug 27 08:47:26 2019 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Aug 27 15:05:24 2019 +0200

    SmartArt edit UI: change plain text widget to tree view
    
    Added getChildren() data interface method, so that it's possible to
    recursively fill tree view with (id, text) pairs
    
    Change-Id: Ic100ded3a3e125bf79f5caa421cd8f91e5210954
    Reviewed-on: https://gerrit.libreoffice.org/78169
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/cui/source/dialogs/DiagramDialog.cxx b/cui/source/dialogs/DiagramDialog.cxx
index f93b3bbdf28b..c48e8f58089d 100644
--- a/cui/source/dialogs/DiagramDialog.cxx
+++ b/cui/source/dialogs/DiagramDialog.cxx
@@ -17,9 +17,28 @@ DiagramDialog::DiagramDialog(weld::Window* pWindow,
     , mpDiagramData(pDiagramData)
     , mpBtnOk(m_xBuilder->weld_button("btnOk"))
     , mpBtnCancel(m_xBuilder->weld_button("btnCancel"))
-    , mpTextDiagram(m_xBuilder->weld_text_view("textDiagram"))
+    , mpTreeDiagram(m_xBuilder->weld_tree_view("treeDiagram"))
 {
-    mpTextDiagram->set_text(mpDiagramData->getString());
+    populateTree(nullptr, OUString());
+
+    // expand all items
+    weld::TreeView* pTreeDiagram = mpTreeDiagram.get();
+    pTreeDiagram->all_foreach([pTreeDiagram](weld::TreeIter& rEntry) {
+        pTreeDiagram->expand_row(rEntry);
+        return false;
+    });
+}
+
+void DiagramDialog::populateTree(weld::TreeIter* pParent, const OUString& rParentId)
+{
+    auto aItems = mpDiagramData->getChildren(rParentId);
+    for (auto& aItem : aItems)
+    {
+        std::unique_ptr<weld::TreeIter> pEntry(mpTreeDiagram->make_iterator());
+        mpTreeDiagram->insert(pParent, -1, &aItem.second, &aItem.first, nullptr, nullptr, nullptr,
+                              false, pEntry.get());
+        populateTree(pEntry.get(), aItem.first);
+    }
 }
 
 DiagramDialog::~DiagramDialog() {}
diff --git a/cui/source/inc/DiagramDialog.hxx b/cui/source/inc/DiagramDialog.hxx
index 55a948c15cc4..ec47de6414bd 100644
--- a/cui/source/inc/DiagramDialog.hxx
+++ b/cui/source/inc/DiagramDialog.hxx
@@ -26,7 +26,9 @@ private:
     std::shared_ptr<DiagramDataInterface> mpDiagramData;
     std::unique_ptr<weld::Button> mpBtnOk;
     std::unique_ptr<weld::Button> mpBtnCancel;
-    std::unique_ptr<weld::TextView> mpTextDiagram;
+    std::unique_ptr<weld::TreeView> mpTreeDiagram;
+
+    void populateTree(weld::TreeIter* pParent, const OUString& rParentId);
 };
 
 #endif // INCLUDED_CUI_SOURCE_INC_DIAGRAMDIALOG_HXX
diff --git a/cui/uiconfig/ui/diagramdialog.ui b/cui/uiconfig/ui/diagramdialog.ui
index 6b6c888808df..000f340f028a 100644
--- a/cui/uiconfig/ui/diagramdialog.ui
+++ b/cui/uiconfig/ui/diagramdialog.ui
@@ -53,9 +53,14 @@
           </packing>
         </child>
         <child>
-          <object class="GtkTextView" id="textDiagram">
+          <object class="GtkTreeView" id="treeDiagram">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
+            <property name="headers_visible">False</property>
+            <property name="show_expanders">True</property>
+            <child internal-child="selection">
+              <object class="GtkTreeSelection"/>
+            </child>
           </object>
           <packing>
             <property name="expand">True</property>
diff --git a/include/svx/DiagramDataInterface.hxx b/include/svx/DiagramDataInterface.hxx
index 439f2efeefdb..9174a2b2fefe 100644
--- a/include/svx/DiagramDataInterface.hxx
+++ b/include/svx/DiagramDataInterface.hxx
@@ -22,6 +22,9 @@
 #include <rtl/ustring.h>
 #include <sal/types.h>
 
+#include <utility>
+#include <vector>
+
 /// Interface class to access diagram data for UI
 class SAL_NO_VTABLE SAL_DLLPUBLIC_RTTI DiagramDataInterface
 {
@@ -29,6 +32,12 @@ public:
     // get text representation of data tree
     virtual OUString getString() const = 0;
 
+    // get children of provided data node
+    // use empty string for top-level nodes
+    // returns vector of (id, text)
+    virtual std::vector<std::pair<OUString, OUString>>
+    getChildren(const OUString& rParentId) const = 0;
+
 protected:
     ~DiagramDataInterface() throw() {}
 };
diff --git a/oox/source/drawingml/diagram/diagram.cxx b/oox/source/drawingml/diagram/diagram.cxx
index d690cdc40991..4fcfbe760699 100644
--- a/oox/source/drawingml/diagram/diagram.cxx
+++ b/oox/source/drawingml/diagram/diagram.cxx
@@ -138,6 +138,24 @@ OUString DiagramData::getString() const
     return aBuf.makeStringAndClear();
 }
 
+std::vector<std::pair<OUString, OUString>> DiagramData::getChildren(const OUString& rParentId) const
+{
+    const OUString sModelId = rParentId.isEmpty() ? getRootPoint()->msModelId : rParentId;
+    std::vector<std::pair<OUString, OUString>> aChildren;
+    for (const auto& rCxn : maConnections)
+        if (rCxn.mnType == XML_parOf && rCxn.msSourceId == sModelId)
+        {
+            if (rCxn.mnSourceOrder >= static_cast<sal_Int32>(aChildren.size()))
+                aChildren.resize(rCxn.mnSourceOrder + 1);
+            const auto pChild = maPointNameMap.find(rCxn.msDestId);
+            if (pChild != maPointNameMap.end())
+                aChildren[rCxn.mnSourceOrder] = std::make_pair(
+                    pChild->second->msModelId,
+                    pChild->second->mpShape->getTextBody()->getParagraphs().front()->getRuns().front()->getText());
+        }
+    return aChildren;
+}
+
 #ifdef DEBUG_OOX_DIAGRAM
 OString normalizeDotName( const OUString& rStr )
 {
diff --git a/oox/source/drawingml/diagram/diagram.hxx b/oox/source/drawingml/diagram/diagram.hxx
index 62609b39fab1..66b57b145c3b 100644
--- a/oox/source/drawingml/diagram/diagram.hxx
+++ b/oox/source/drawingml/diagram/diagram.hxx
@@ -193,6 +193,7 @@ public:
     const dgm::Point* getRootPoint() const;
     void dump() const;
     OUString getString() const override;
+    std::vector<std::pair<OUString, OUString>> getChildren(const OUString& rParentId) const override;
 
 private:
     void getChildrenString(OUStringBuffer& rBuf, const dgm::Point* pPoint, sal_Int32 nLevel) const;


More information about the Libreoffice-commits mailing list