DataTreeBuilder.cpp
Go to the documentation of this file.
1 #include "DataTreeBuilder.h"
2 
3 #include <QTreeWidgetItem>
4 
6 
7 
9 {
10 
12  {
13  }
14 
15  void DataTreeBuilder::updateTree(QTreeWidgetItem* parent, const aron::data::DictPtr& data)
16  {
17  DictBuilder builder = getDictBuilder();
18  builder.setUpdateItemFn([this, &data](const std::string & key, QTreeWidgetItem * item)
19  {
20  auto child = data->getElement(key);
21  this->update(item, key, child, data->getPath());
22  return true;
23  });
24 
25  builder.updateTreeWithContainer(parent, data->getAllKeys());
26  }
27 
28  void DataTreeBuilder::updateTree(QTreeWidgetItem* parent, const aron::data::ListPtr& data)
29  {
30 
31  ListBuilder builder = getListBuilder();
32  builder.setUpdateItemFn([this, &data](size_t key, QTreeWidgetItem * item)
33  {
34  auto child = data->getElement(key);
35  this->update(item, std::to_string(key), child, data->getPath());
36  return true;
37  });
38 
39  builder.updateTreeWithContainer(parent, getIndex(data->childrenSize()));
40  }
41 
42 
43  void
44  DataTreeBuilder::update(QTreeWidgetItem* item,
45  const std::string& key,
47  const aron::Path& parentPath)
48  {
49  if (data)
50  {
51  this->setRowTexts(item, key, data);
52 
54  {
55  updateTree(item, cast);
56  }
57  else if (auto cast = aron::data::List::DynamicCast(data))
58  {
59  updateTree(item, cast);
60  }
61  }
62  else
63  {
64  // Optional data?
65  this->setRowTexts(item, key, "(none)");
66  auto empty = std::make_shared<aron::data::Dict>(parentPath.withElement(key));
67  updateTree(item, empty);
68  }
69 
70  }
71 }
armarx::aron::Path::withElement
Path withElement(const std::string &, bool escape=false) const
Definition: Path.cpp:161
armarx::armem::gui::instance::DataTreeBuilderBase::setRowTexts
void setRowTexts(QTreeWidgetItem *item, const std::string &key, const std::string &value, const std::string &typeName="") const
Definition: DataTreeBuilderBase.cpp:46
armarx::conversions::cast
CvT cast(const auto &pt)
Definition: opencv.h:32
armarx::armem::gui::instance::DataTreeBuilder::DataTreeBuilder
DataTreeBuilder()
Definition: DataTreeBuilder.cpp:11
armarx::armem::gui::instance::DataTreeBuilderBase::getListBuilder
ListBuilder getListBuilder() const
Definition: DataTreeBuilderBase.cpp:80
armarx::armem::gui::instance::DataTreeBuilder::update
void update(QTreeWidgetItem *item, const std::string &key, const aron::data::VariantPtr &data, const aron::Path &parentPath)
Definition: DataTreeBuilder.cpp:44
TreeWidgetBuilder.h
cxxopts::empty
bool empty(const std::string &s)
Definition: cxxopts.hpp:255
armarx::aron::data::detail::SpecializedVariantBase< data::dto::Dict, Dict >::DynamicCast
static PointerType DynamicCast(const VariantPtr &n)
Definition: SpecializedVariant.h:117
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::data::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
DataTreeBuilder.h
armarx::TreeWidgetBuilder::updateTreeWithContainer
void updateTreeWithContainer(ParentT *parent, const ContainerT &elements)
Update the tree with the iterable container.
Definition: TreeWidgetBuilder.h:312
armarx::armem::gui::instance
Definition: AronDataView.cpp:2
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::TreeWidgetBuilder
A class to efficiently build and maintain sorted items of QTreeWidget or QTreeWidgetItem based on a s...
Definition: DataTreeBuilderBase.h:10
armarx::TreeWidgetBuilder::setUpdateItemFn
void setUpdateItemFn(UpdateItemFn updateItemFn)
Definition: TreeWidgetBuilder.h:57
armarx::armem::gui::instance::DataTreeBuilderBase::getDictBuilder
DictBuilder getDictBuilder() const
Definition: DataTreeBuilderBase.cpp:65
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::armem::gui::instance::DataTreeBuilder::updateTree
void updateTree(QTreeWidgetItem *parent, const aron::data::DictPtr &data)
Definition: DataTreeBuilder.cpp:15
armarx::aron::data::ListPtr
std::shared_ptr< List > ListPtr
Definition: List.h:40
armarx::armem::gui::instance::DataTreeBuilderBase::getIndex
std::vector< size_t > getIndex(size_t size) const
Definition: DataTreeBuilderBase.cpp:99