3 #include <QTreeWidgetItem>
5 #include <RobotAPI/libraries/armem/aron/MemoryID.aron.generated.h>
31 [
this, &childType, &
data](
const std::string& key, QTreeWidgetItem* item)
33 auto childData =
data.getElement(key);
51 [
this, &
data](
const std::string& key, QTreeWidgetItem* item)
53 auto childData =
data.getElement(key);
71 [
this, &type](
const std::string& key) -> QTreeWidgetItem*
76 MemoryIDTreeWidgetItem* item =
77 new MemoryIDTreeWidgetItem({QString::fromStdString(key)});
78 item->addKeyChildren();
86 builder.setUpdateItemFn(
87 [
this, &type, &
data](
const std::string& key, QTreeWidgetItem* item)
89 auto childData =
data.getElement(key);
93 if (type.hasMemberType(key))
95 this->updateDispatch(item, key, type.getMemberType(key), childData);
99 this->updateDispatch(item, key,
nullptr, childData);
104 builder.updateTreeWithContainer(parent,
data.getAllKeys());
108 TypedDataTreeBuilder::updateTree(QTreeWidgetItem* parent,
113 auto children =
data.getChildren();
117 [
this, &children, &childType](
size_t key, QTreeWidgetItem* item)
119 if (
auto childData = children.at(key))
121 this->updateDispatch(item, std::to_string(key), childType, childData);
130 TypedDataTreeBuilder::updateTree(QTreeWidgetItem* parent,
139 [
this, &
data, &childTypes](
size_t i, QTreeWidgetItem* item)
141 auto childType = i == 0 ? childTypes.first : childTypes.second;
142 auto childData =
data.getElement(
static_cast<unsigned int>(i));
144 this->updateDispatch(item,
std::to_string(i), childType, childData);
152 TypedDataTreeBuilder::updateTree(QTreeWidgetItem* parent,
163 [
this, &
data, &childTypes](
size_t i, QTreeWidgetItem* item)
165 auto childType = (i < childTypes.size()) ? childTypes.at(i) :
nullptr;
166 auto childData =
data.getElement(
static_cast<unsigned int>(i));
168 this->updateDispatch(item,
std::to_string(i), childType, childData);
180 TypedDataTreeBuilder::updateDispatch(QTreeWidgetItem* item,
181 const std::string& key,
197 const std::string& key,
201 using namespace aron;
203 const std::string
value =
206 std::string typeName;
209 typeName = enumType->getEnumName();
213 typeName = type->getFullName();
216 switch (type->getMaybe())
218 case aron::type::Maybe::OPTIONAL:
219 typeName =
"Optional[" + typeName +
"]";
225 setRowTexts(item, key,
value, typeName);
227 item->setData(columnKey,
230 item->setData(columnType, Qt::UserRole,
static_cast<int>(type->getDescriptor()));
236 if (memoryIDItem && dictData)
240 dto.fromAron(dictData);
242 MemoryID id = aron::fromAron<MemoryID>(dto);
252 const auto t = type::Object::DynamicCast(type))
254 _updateTree(item, *t, d ? *d : emptyDict);
257 const auto t = type::Dict::DynamicCast(type))
259 _updateTree(item, *t, d ? *d : emptyDict);
262 const auto t = type::List::DynamicCast(type))
264 _updateTree(item, *t, d ? *d : emptyList);
267 const auto t = type::Pair::DynamicCast(type))
269 _updateTree(item, *t, d ? *d : emptyList);
272 const auto t = type::Tuple::DynamicCast(type))
274 _updateTree(item, *t, d ? *d : emptyList);
277 const auto t = type::AnyObject::DynamicCast(type))
279 _updateTree(item, *t, d ? *d : emptyDict);
285 const std::string& key,
290 this->setRowTexts(item, key,
data);
292 item->setData(columnKey,
309 this->setRowTexts(item, key,
"(none)");
313 template <
class DataT,
class TypeT>
315 TypedDataTreeBuilder::_updateTree(QTreeWidgetItem* item, TypeT& type, DataT&
data)
317 updateTree(item, type,
data);