TreeDataVisitorBase.h
Go to the documentation of this file.
1#pragma once
2
3#include <sstream>
4#include <stack>
5
6#include <QLabel>
7#include <QTreeWidget>
8
10
12{
13
15 {
16 public:
18 TreeDataVisitorBase(QTreeWidgetItem* root);
19 virtual ~TreeDataVisitorBase();
20
21 void setColumns(int key, int value, int type);
22
23
24 protected:
25 // Same for Dict and List
26 bool _visitEnter(const std::string& key, const std::string& type, size_t numChildren);
27 bool _visitExit();
28
29 template <class Navigator>
30 bool
31 addValueRow(const std::string& key, Navigator& n, const std::string& typeName)
32 {
33 if (items.size() > 0)
34 {
35 items.top()->addChild(
36 new QTreeWidgetItem(this->makeValueRowStrings(key, n, typeName)));
37 }
38 return true;
39 }
40
41 QStringList
42 makeValueRowStrings(const std::string& key,
43 const std::string& value,
44 const std::string& typeName) const
45 {
46 QStringList cols;
47 cols.insert(columnKey, QString::fromStdString(key));
48 cols.insert(columnValue, QString::fromStdString(value));
49 cols.insert(columnType, QString::fromStdString(typeName));
50 return cols;
51 }
52
53 template <class Navigator>
54 QStringList
55 makeValueRowStrings(const std::string& key, Navigator& n, const std::string& typeName) const
56 {
57 std::stringstream value;
58 streamValueText(n, value);
59 return makeValueRowStrings(key, value.str(), typeName);
60 }
61
62 template <class Navigator>
63 void
64 streamValueText(Navigator& n, std::stringstream& ss) const
65 {
66 ss << n.getValue();
67 }
68
69 void streamValueText(const aron::data::Bool& n, std::stringstream& ss) const;
70 void streamValueText(const aron::data::String& n, std::stringstream& ss) const;
71 void streamValueText(const aron::data::NDArray& n, std::stringstream& ss) const;
72
73
74 public:
75 std::stack<QTreeWidgetItem*> rootItems;
76 std::stack<QTreeWidgetItem*> items;
77
78 int columnKey = 0;
79 int columnValue = 1;
80 int columnType = 2;
81 };
82
83} // namespace armarx::armem::gui::instance
Brief description of class Navigator.
void streamValueText(Navigator &n, std::stringstream &ss) const
bool addValueRow(const std::string &key, Navigator &n, const std::string &typeName)
QStringList makeValueRowStrings(const std::string &key, const std::string &value, const std::string &typeName) const
bool _visitEnter(const std::string &key, const std::string &type, size_t numChildren)
QStringList makeValueRowStrings(const std::string &key, Navigator &n, const std::string &typeName) const