DataTreeBuilder.cpp
Go to the documentation of this file.
1#include "DataTreeBuilder.h"
2
3#include <QTreeWidgetItem>
4
6
8{
9
13
14 void
15 DataTreeBuilder::updateTree(QTreeWidgetItem* parent, const aron::data::DictPtr& data)
16 {
17 DictBuilder builder = getDictBuilder();
18 builder.setUpdateItemFn(
19 [this, &data](const std::string& key, QTreeWidgetItem* item)
20 {
21 auto child = data->getElement(key);
22 this->update(item, key, child, data->getPath());
23 return true;
24 });
25
26 builder.updateTreeWithContainer(parent, data->getAllKeys());
27 }
28
29 void
30 DataTreeBuilder::updateTree(QTreeWidgetItem* parent, const aron::data::ListPtr& data)
31 {
32
33 ListBuilder builder = getListBuilder();
34 builder.setUpdateItemFn(
35 [this, &data](size_t key, QTreeWidgetItem* item)
36 {
37 auto child = data->getElement(key);
38 this->update(item, std::to_string(key), child, data->getPath());
39 return true;
40 });
41
42 builder.updateTreeWithContainer(parent, getIndex(data->childrenSize()));
43 }
44
45 void
46 DataTreeBuilder::update(QTreeWidgetItem* item,
47 const std::string& key,
49 const aron::Path& parentPath)
50 {
51 if (data)
52 {
53 this->setRowTexts(item, key, data);
54
55 if (auto cast = aron::data::Dict::DynamicCast(data))
56 {
57 updateTree(item, cast);
58 }
59 else if (auto cast = aron::data::List::DynamicCast(data))
60 {
61 updateTree(item, cast);
62 }
63 }
64 else
65 {
66 // Optional data?
67 this->setRowTexts(item, key, "(none)");
68 auto empty = std::make_shared<aron::data::Dict>(parentPath.withElement(key));
69 updateTree(item, empty);
70 }
71 }
72} // namespace armarx::armem::gui::instance
std::vector< size_t > getIndex(size_t size) const
armarx::TreeWidgetBuilder< std::string > DictBuilder
armarx::TreeWidgetBuilder< size_t > ListBuilder
void setRowTexts(QTreeWidgetItem *item, const std::string &key, const std::string &value, const std::string &typeName="") const
void updateTree(QTreeWidgetItem *parent, const aron::data::DictPtr &data)
void update(QTreeWidgetItem *item, const std::string &key, const aron::data::VariantPtr &data, const aron::Path &parentPath)
The Path class.
Definition Path.h:36
Path withElement(const std::string &, bool escape=false) const
Definition Path.cpp:163
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
std::shared_ptr< List > ListPtr
Definition List.h:41
std::shared_ptr< Variant > VariantPtr
void setUpdateItemFn(UpdateItemFn updateItemFn)
void updateTreeWithContainer(ParentT *parent, const ContainerT &elements)
Update the tree with the iterable container.