TreeWidget.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 
5 #include <QTreeWidget>
6 
8 
10 
11 
13 {
14 
15  class TreeWidget : public QTreeWidget
16  {
17  Q_OBJECT
18  using This = TreeWidget;
19 
20  public:
21 
22  TreeWidget();
23 
24  void update(const armem::wm::Memory& memory);
25  void update(const std::map<std::string, const armem::wm::Memory*>& memories);
26 
27  std::optional<MemoryID> selectedID() const;
28 
29 
30  signals:
31 
32  /// Tree contents have changed.
33  void updated();
34 
35  /// The selected item or its contents have changed.
36  void selectedItemChanged(const MemoryID& id);
37 
38  void itemSelected(const MemoryID& id);
39 
40  void memorySelected(const MemoryID& id);
41  void coreSegmentSelected(const MemoryID& id);
42  void providerSegmentSelected(const MemoryID& id);
43  void entitySelected(const MemoryID& id);
44  void snapshotSelected(const MemoryID& id);
45  void instanceSelected(const MemoryID& id);
46 
47  void actionsMenuRequested(const MemoryID& memoryID, QWidget* parent,
48  const QPoint& pos, QMenu* menu);
49 
50 
51  private slots:
52 
53  void handleSelection();
54 
55 
56  private:
57 
58  void initWidget();
59  void initBuilders();
60 
61  void updateChildren(const armem::wm::Memory& memory, QTreeWidget* tree);
62  void updateChildren(const std::map<std::string, const armem::wm::Memory*>& memories, QTreeWidget* tree);
63 
64  void updateChildren(const armem::wm::Memory& memory, QTreeWidgetItem* memoryItem);
65  void updateChildren(const armem::wm::CoreSegment& coreSeg, QTreeWidgetItem* coreSegItem);
66  void updateChildren(const armem::wm::ProviderSegment& provSeg, QTreeWidgetItem* provSegItem);
67  void updateChildren(const armem::wm::Entity& entity, QTreeWidgetItem* entityItem);
68  void updateChildren(const armem::wm::EntitySnapshot& snapshot, QTreeWidgetItem* snapshotItem);
69  void updateChildren(const armem::wm::EntityInstance& data, QTreeWidgetItem* parent);
70 
71  void prepareTreeContextMenu(const QPoint& pos);
72 
73  template <class MemoryItemT>
74  QTreeWidgetItem* makeItem(const std::string& key, const MemoryItemT& memoryItem);
75  QTreeWidgetItem* makeItem(const std::string& key, const std::string& levelName, const MemoryID& id);
76 
77  void updateItemItem(const armem::base::detail::MemoryItem& level, QTreeWidgetItem* item);
78  template <class ContainerT>
79  void updateContainerItem(const ContainerT& container, QTreeWidgetItem* item);
80 
81 
82  private:
83 
85  TreeWidgetBuilder<wm::CoreSegment> coreSegmentBuilder;
86  TreeWidgetBuilder<wm::ProviderSegment> provSegmentBuilder;
87  TreeWidgetBuilder<wm::Entity> entityBuilder;
90 
91  std::optional<MemoryID> _selectedID;
92  /// While this is false, do not handle selection updates.
93  bool handleSelections = true;
94 
95  enum class Columns
96  {
97  KEY = 0,
98  SIZE = 1,
99  TYPE = 2,
100  LEVEL = 3,
101  ID = 4,
102  NUM = 5
103  };
104  };
105 
106 }
107 
108 namespace armarx::armem::gui
109 {
111 }
armarx::armem::gui::memory
Definition: GroupBox.cpp:11
armarx::armem::wm::ProviderSegment
Client-side working memory provider segment.
Definition: memory_definitions.h:105
armarx::armem::gui::memory::TreeWidget::providerSegmentSelected
void providerSegmentSelected(const MemoryID &id)
armarx::armem::wm::EntityInstance
Client-side working entity instance.
Definition: memory_definitions.h:32
armarx::armem::gui::memory::TreeWidget::entitySelected
void entitySelected(const MemoryID &id)
armarx::armem::base::detail::MemoryItem
Base class of memory classes on different levels.
Definition: MemoryItem.h:14
armarx::MapTreeWidgetBuilder
A class to efficiently build and maintain sorted items of QTreeWidget or QTreeWidgetItem based on a m...
Definition: TreeWidgetBuilder.h:124
armarx::armem::gui::memory::TreeWidget
Definition: TreeWidget.h:15
TreeWidgetBuilder.h
armarx::memory
Brief description of class memory.
Definition: memory.h:39
armarx::armem::gui::memory::TreeWidget::instanceSelected
void instanceSelected(const MemoryID &id)
armarx::armem::gui::memory::TreeWidget::updated
void updated()
Tree contents have changed.
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::armem::wm::CoreSegment
Client-side working memory core segment.
Definition: memory_definitions.h:119
armarx::armem::wm::Memory
Client-side working memory.
Definition: memory_definitions.h:133
armarx::armem::gui::memory::TreeWidget::snapshotSelected
void snapshotSelected(const MemoryID &id)
armarx::TreeWidgetBuilder
A class to efficiently build and maintain sorted items of QTreeWidget or QTreeWidgetItem based on a s...
Definition: DataTreeBuilderBase.h:10
armarx::armem::wm::EntitySnapshot
Client-side working memory entity snapshot.
Definition: memory_definitions.h:80
armarx::armem::gui::memory::TreeWidget::actionsMenuRequested
void actionsMenuRequested(const MemoryID &memoryID, QWidget *parent, const QPoint &pos, QMenu *menu)
armarx::armem::gui::memory::TreeWidget::selectedID
std::optional< MemoryID > selectedID() const
Definition: TreeWidget.cpp:170
memory_definitions.h
armarx::armem::gui::memory::TreeWidget::memorySelected
void memorySelected(const MemoryID &id)
armarx::armem::gui
Definition: ActionsMenuBuilder.cpp:6
armarx::armem::index::memoryID
const MemoryID memoryID
Definition: memory_ids.cpp:29
armarx::armem::gui::memory::TreeWidget::selectedItemChanged
void selectedItemChanged(const MemoryID &id)
The selected item or its contents have changed.
armarx::armem::wm::Entity
Client-side working memory entity.
Definition: memory_definitions.h:93
armarx::armem::gui::memory::TreeWidget::coreSegmentSelected
void coreSegmentSelected(const MemoryID &id)
armarx::armem::gui::memory::TreeWidget::TreeWidget
TreeWidget()
Definition: TreeWidget.cpp:17
armarx::armem::gui::memory::TreeWidget::update
void update(const armem::wm::Memory &memory)
Definition: TreeWidget.cpp:153
armarx::armem::gui::memory::TreeWidget::itemSelected
void itemSelected(const MemoryID &id)