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
9namespace armarx
10{
11
12 /**
13 * @brief Manages the layer info `QTreeWidget`.
14 */
15 class LayerInfoTree : public QObject
16 {
17 Q_OBJECT
18
19 public:
21 virtual ~LayerInfoTree() = default;
22
23 void setWidget(QTreeWidget* treeWidget);
26
27 /**
28 * @brief Enable or disable the layer info tree.
29 *
30 * When enabled, the tree will be filled on the first update.
31 * When disabled, the tree is cleared and will not be updated.
32 */
33 void setEnabled(bool enabled);
34
35 /// Set the selected layer.
37
38 /// Update the currently expanded layer elements.
39 void update();
40
41
42 public:
43 signals:
44
45
46 public slots:
47
48
49 private:
50 void clearLayerElements();
51
52 /**
53 * @brief Updates the list of layer elements.
54 *
55 * Items are inserted, removed and updated accordingly.
56 */
57 void updateLayerElements(const std::vector<viz::CoinLayerElement>& elements);
58
59 /// Insert a (top-level) layer element at `ìndex`.
60 QTreeWidgetItem* insertLayerElementItem(int index,
61 const std::string& name,
62 const viz::data::ElementPtr& element);
63 /// Update the layer element's item data. Does not update its children.
64 void updateLayerElementItem(QTreeWidgetItem* item, const viz::data::ElementPtr& element);
65
66 /// Update the layer element's properties (children).
67 void updateLayerElementProperties(QTreeWidgetItem* item,
68 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,
86 const nlohmann::json& json,
87 bool recursive = false);
88
89 /// Adds a child item with `key` to `parent`.
90 QTreeWidgetItem* addJsonChild(QTreeWidgetItem* parent, const std::string& key);
91
92 /**
93 * @brief Updates `item`'s key and value.
94 * @param recursive If true, also update its children.
95 */
96 void updateJsonItem(QTreeWidgetItem* item,
97 const std::string& key,
98 const nlohmann::json& value,
99 const nlohmann::json& parentMeta,
100 bool recursive = false);
101
102 void updateJsonItemValue(QTreeWidgetItem* item,
103 const std::string& key,
104 const nlohmann::json& value,
105 const nlohmann::json& parentMeta);
106
107
108 QVariant getValuePreview(const nlohmann::json& json) const;
109 QWidget* getValueWidget(QTreeWidgetItem* item, const nlohmann::json& json) const;
110 void updateValueWidget(const nlohmann::json& json, QWidget* widget) const;
111
112 static bool isMetaKey(const std::string&);
113
114
115 void addShowMoreItem();
116
117
118 private:
119 QTreeWidget* widget = nullptr;
120 /// Connections to the current widget.
121 QVector<QMetaObject::Connection> widgetConnections;
122
123 bool enabled = true;
124
125 QTreeWidgetItem* showMoreItem = nullptr;
126 int maxElementCountDefault = 25;
127 int maxElementCount = maxElementCountDefault;
128
129 viz::CoinLayerID layerID = {"", ""};
130 const viz::CoinLayerMap* layers = nullptr;
131 };
132} // namespace armarx
uint8_t index
virtual ~LayerInfoTree()=default
void setEnabled(bool enabled)
Enable or disable the layer info tree.
void registerVisualizerCallbacks(viz::CoinVisualizer &visualizer)
void setMaxElementCountDefault(int max)
void setWidget(QTreeWidget *treeWidget)
void update()
Update the currently expanded layer elements.
void setSelectedLayer(viz::CoinLayerID id, viz::CoinLayerMap *layers)
Set the selected layer.
std::pair< std::string, std::string > CoinLayerID
Definition Visualizer.h:20
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)