bump product version to 6.4.0.3
[LibreOffice.git] / cui / source / dialogs / DiagramDialog.cxx
blobf3a4a069a19c96a879e69c4384de90f62358cc4c
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/.
8 */
10 #include <DiagramDialog.hxx>
12 #include <comphelper/dispatchcommand.hxx>
13 #include <svx/DiagramDataInterface.hxx>
14 #include <com/sun/star/beans/PropertyValue.hpp>
16 DiagramDialog::DiagramDialog(weld::Window* pWindow,
17 std::shared_ptr<DiagramDataInterface> pDiagramData)
18 : GenericDialogController(pWindow, "cui/ui/diagramdialog.ui", "DiagramDialog")
19 , mpDiagramData(pDiagramData)
20 , mpBtnOk(m_xBuilder->weld_button("btnOk"))
21 , mpBtnCancel(m_xBuilder->weld_button("btnCancel"))
22 , mpBtnAdd(m_xBuilder->weld_button("btnAdd"))
23 , mpBtnRemove(m_xBuilder->weld_button("btnRemove"))
24 , mpTreeDiagram(m_xBuilder->weld_tree_view("treeDiagram"))
25 , mpTextAdd(m_xBuilder->weld_text_view("textAdd"))
27 mpBtnAdd->connect_clicked(LINK(this, DiagramDialog, OnAddClick));
28 mpBtnRemove->connect_clicked(LINK(this, DiagramDialog, OnRemoveClick));
30 populateTree(nullptr, OUString());
32 // expand all items
33 weld::TreeView* pTreeDiagram = mpTreeDiagram.get();
34 pTreeDiagram->all_foreach([pTreeDiagram](weld::TreeIter& rEntry) {
35 pTreeDiagram->expand_row(rEntry);
36 return false;
37 });
40 IMPL_LINK_NOARG(DiagramDialog, OnAddClick, weld::Button&, void)
42 OUString sText = mpTextAdd->get_text();
43 if (!sText.isEmpty())
45 OUString sNodeId = mpDiagramData->addNode(sText);
46 std::unique_ptr<weld::TreeIter> pEntry(mpTreeDiagram->make_iterator());
47 mpTreeDiagram->insert(nullptr, -1, &sText, &sNodeId, nullptr, nullptr, nullptr, false,
48 pEntry.get());
49 mpTreeDiagram->select(*pEntry);
50 comphelper::dispatchCommand(".uno:RegenerateDiagram", {});
54 IMPL_LINK_NOARG(DiagramDialog, OnRemoveClick, weld::Button&, void)
56 std::unique_ptr<weld::TreeIter> pEntry(mpTreeDiagram->make_iterator());
57 if (mpTreeDiagram->get_selected(pEntry.get()))
59 if (mpDiagramData->removeNode(mpTreeDiagram->get_id(*pEntry)))
61 mpTreeDiagram->remove(*pEntry);
62 comphelper::dispatchCommand(".uno:RegenerateDiagram", {});
67 void DiagramDialog::populateTree(const weld::TreeIter* pParent, const OUString& rParentId)
69 auto aItems = mpDiagramData->getChildren(rParentId);
70 for (auto& aItem : aItems)
72 std::unique_ptr<weld::TreeIter> pEntry(mpTreeDiagram->make_iterator());
73 mpTreeDiagram->insert(pParent, -1, &aItem.second, &aItem.first, nullptr, nullptr, nullptr,
74 false, pEntry.get());
75 populateTree(pEntry.get(), aItem.first);
79 DiagramDialog::~DiagramDialog() {}
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */