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