LibreOffice Module cui (master)  1
DiagramDialog.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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 */
9 
10 #include <DiagramDialog.hxx>
11 
14 #include <com/sun/star/beans/PropertyValue.hpp>
15 
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"))
26 {
27  mpBtnAdd->connect_clicked(LINK(this, DiagramDialog, OnAddClick));
28  mpBtnRemove->connect_clicked(LINK(this, DiagramDialog, OnRemoveClick));
29 
30  populateTree(nullptr, OUString());
31 
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  });
38 }
39 
41 {
42  OUString sText = mpTextAdd->get_text();
43  if (!sText.isEmpty())
44  {
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, false, pEntry.get());
48  mpTreeDiagram->select(*pEntry);
49  comphelper::dispatchCommand(".uno:RegenerateDiagram", {});
50  }
51 }
52 
54 {
55  std::unique_ptr<weld::TreeIter> pEntry(mpTreeDiagram->make_iterator());
56  if (mpTreeDiagram->get_selected(pEntry.get()))
57  {
58  if (mpDiagramData->removeNode(mpTreeDiagram->get_id(*pEntry)))
59  {
60  mpTreeDiagram->remove(*pEntry);
61  comphelper::dispatchCommand(".uno:RegenerateDiagram", {});
62  }
63  }
64 }
65 
66 void DiagramDialog::populateTree(const weld::TreeIter* pParent, const OUString& rParentId)
67 {
68  auto aItems = mpDiagramData->getChildren(rParentId);
69  for (auto& aItem : aItems)
70  {
71  std::unique_ptr<weld::TreeIter> pEntry(mpTreeDiagram->make_iterator());
72  mpTreeDiagram->insert(pParent, -1, &aItem.second, &aItem.first, nullptr, nullptr, false,
73  pEntry.get());
74  populateTree(pEntry.get(), aItem.first);
75  }
76 }
77 
79 
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void populateTree(const weld::TreeIter *pParent, const OUString &rParentId)
std::unique_ptr< weld::Button > mpBtnRemove
std::unique_ptr< weld::TreeView > mpTreeDiagram
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
std::unique_ptr< weld::Button > mpBtnAdd
virtual ~DiagramDialog() override
DiagramDialog(weld::Window *pWindow, std::shared_ptr< DiagramDataInterface > pDiagramData)
Edit Diagram dialog.
virtual void expand_row(const TreeIter &rIter)=0
virtual void all_foreach(const std::function< bool(TreeIter &)> &func)=0
std::shared_ptr< DiagramDataInterface > mpDiagramData
IMPL_LINK_NOARG(DiagramDialog, OnAddClick, weld::Button &, void)