LayerInfoTree.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QTreeWidget>
4 
5 #include <SimoxUtility/json/json.hpp>
6 
8 
9 
10 namespace armarx
11 {
12 
13  /**
14  * @brief Manages the layer info `QTreeWidget`.
15  */
16  class LayerInfoTree : public QObject
17  {
18  Q_OBJECT
19 
20  public:
21 
22  LayerInfoTree();
23  virtual ~LayerInfoTree() = default;
24 
25  void setWidget(QTreeWidget* treeWidget);
28 
29  /**
30  * @brief Enable or disable the layer info tree.
31  *
32  * When enabled, the tree will be filled on the first update.
33  * When disabled, the tree is cleared and will not be updated.
34  */
35  void setEnabled(bool enabled);
36 
37  /// Set the selected layer.
39 
40  /// Update the currently expanded layer elements.
41  void update();
42 
43 
44  public:
45  signals:
46 
47 
48  public slots:
49 
50 
51  private:
52 
53  void clearLayerElements();
54 
55  /**
56  * @brief Updates the list of layer elements.
57  *
58  * Items are inserted, removed and updated accordingly.
59  */
60  void updateLayerElements(const std::vector<viz::CoinLayerElement>& elements);
61 
62  /// Insert a (top-level) layer element at `ìndex`.
63  QTreeWidgetItem* insertLayerElementItem(int index, const std::string& name, const viz::data::ElementPtr& element);
64  /// Update the layer element's item data. Does not update its children.
65  void updateLayerElementItem(QTreeWidgetItem* item, const viz::data::ElementPtr& element);
66 
67  /// Update the layer element's properties (children).
68  void updateLayerElementProperties(QTreeWidgetItem* item, const viz::data::ElementPtr& element);
69 
70 
71  /// Get `element`'s type name.
72  std::string getTypeName(const viz::data::ElementPtr& element) const;
73 
74  /// Serialize `element` to JSON. If `element`'s type is unknown, returns an empty object.
75  nlohmann::json serializeElement(const viz::data::ElementPtr& element) const;
76 
77 
78  /**
79  * @brief Updates `parent`'s children according to `json`.
80  *
81  * Items are added, deleted and updated accordingly.
82  *
83  * @param recursive If true,
84  */
85  void updateJsonChildren(QTreeWidgetItem* parent, const nlohmann::json& json, bool recursive = false);
86 
87  /// Adds a child item with `key` to `parent`.
88  QTreeWidgetItem* addJsonChild(QTreeWidgetItem* parent, const std::string& key);
89 
90  /**
91  * @brief Updates `item`'s key and value.
92  * @param recursive If true, also update its children.
93  */
94  void updateJsonItem(QTreeWidgetItem* item, const std::string& key, const nlohmann::json& value,
95  const nlohmann::json& parentMeta,
96  bool recursive = false);
97 
98  void updateJsonItemValue(QTreeWidgetItem* item, const std::string& key, const nlohmann::json& value,
99  const nlohmann::json& parentMeta);
100 
101 
102  QVariant getValuePreview(const nlohmann::json& json) const;
103  QWidget* getValueWidget(QTreeWidgetItem* item, const nlohmann::json& json) const;
104  void updateValueWidget(const nlohmann::json& json, QWidget* widget) const;
105 
106  static bool isMetaKey(const std::string&);
107 
108 
109  void addShowMoreItem();
110 
111 
112  private:
113 
114  QTreeWidget* widget = nullptr;
115  /// Connections to the current widget.
116  QVector<QMetaObject::Connection> widgetConnections;
117 
118  bool enabled = true;
119 
120  QTreeWidgetItem* showMoreItem = nullptr;
121  int maxElementCountDefault = 25;
122  int maxElementCount = maxElementCountDefault;
123 
124  viz::CoinLayerID layerID = {"", ""};
125  const viz::CoinLayerMap* layers = nullptr;
126 
127 
128 
129  };
130 }
armarx::LayerInfoTree::registerVisualizerCallbacks
void registerVisualizerCallbacks(viz::CoinVisualizer &visualizer)
Definition: LayerInfoTree.cpp:65
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::LayerInfoTree::setWidget
void setWidget(QTreeWidget *treeWidget)
Definition: LayerInfoTree.cpp:26
armarx::LayerInfoTree::LayerInfoTree
LayerInfoTree()
Definition: LayerInfoTree.cpp:22
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:267
armarx::LayerInfoTree::setSelectedLayer
void setSelectedLayer(viz::CoinLayerID id, viz::CoinLayerMap *layers)
Set the selected layer.
Definition: LayerInfoTree.cpp:98
armarx::LayerInfoTree::update
void update()
Update the currently expanded layer elements.
Definition: LayerInfoTree.cpp:112
armarx::LayerInfoTree
Manages the layer info QTreeWidget.
Definition: LayerInfoTree.h:16
armarx::LayerInfoTree::setEnabled
void setEnabled(bool enabled)
Enable or disable the layer info tree.
Definition: LayerInfoTree.cpp:82
armarx::LayerInfoTree::~LayerInfoTree
virtual ~LayerInfoTree()=default
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
Visualizer.h
armarx::viz::CoinVisualizer
Definition: Visualizer.h:198
armarx::LayerInfoTree::setMaxElementCountDefault
void setMaxElementCountDefault(int max)
Definition: LayerInfoTree.cpp:77
armarx::viz::CoinLayerMap
Definition: Visualizer.h:110
armarx::viz::CoinLayerID
std::pair< std::string, std::string > CoinLayerID
Definition: Visualizer.h:21
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28