AronTreeWidgetController.cpp
Go to the documentation of this file.
2 
4 
5 #include "visitors/AronTreeWidgetContextMenu.h"
6 #include "visitors/AronTreeWidgetConverter.h"
7 #include "visitors/AronTreeWidgetSetter.h"
8 
9 namespace armarx::skills::gui
10 {
12  QTreeWidgetItem* parent,
13  const aron::type::ObjectPtr& type,
14  const aron::data::DictPtr& data) :
15  parent(parent), tree(tree), type(type)
16  {
17  connect(tree,
18  SIGNAL(customContextMenuRequested(const QPoint&)),
19  this,
20  SLOT(ShowContextMenu(const QPoint&)));
21  connect(tree,
22  &QTreeWidget::itemDoubleClicked,
23  this,
24  &AronTreeWidgetController::onTreeWidgetItemDoubleClicked);
25 
26  if (type) // if there is a type set, we create a tree widget from the type
27  {
29  v.setTopLevelWidget(tree);
30  aron::type::visit(v, type);
31 
32  if (data) // check if there is a default argument set. Prefill the GUI with it
33  {
35  }
36  }
37  // there is no type but a default configuration. Prefill the GUI with the default arguments
38  else if (data)
39  {
40  // TODO: There is no visitor for that (yet)...
41  // create type from data, ...
42  }
43  else
44  {
45  new QTreeWidgetItem(parent, {QString::fromStdString("No args")});
46  }
47 
48  // connect change handling after args init
49  connect(tree,
50  &QTreeWidget::itemChanged,
51  this,
52  &AronTreeWidgetController::onTreeWidgetItemChanged);
53  }
54 
57  {
58  if (parent && type)
59  {
61  aron::type::visit(v, type);
62 
63  auto aron_args = aron::data::Dict::DynamicCastAndCheck(v.createdAron);
64  return aron_args;
65  }
66  return nullptr;
67  }
68 
69  void
71  {
72  if (parent)
73  {
74  AronTreeWidgetSetterVisitor v(parent, 0);
76  }
77  }
78 
79  void
81  {
82  tree->blockSignals(true);
83 
84  auto idx = tree->indexAt(pos);
85  AronTreeWidgetItem* clickedItem = AronTreeWidgetItem::DynamicCast(tree->itemAt(pos));
86  if (clickedItem)
87  {
88  AronTreeWidgetContextMenuVisitor visitor(clickedItem, pos, tree, idx.row());
89 
90  aron::type::visit(visitor, clickedItem->aronType);
91  visitor.showMenuAndExecute();
92  }
93 
94  tree->blockSignals(false);
95  }
96 
97  void
98  AronTreeWidgetController::onTreeWidgetItemDoubleClicked(QTreeWidgetItem* item, int column)
99  {
100  if (!item)
101  {
102  return;
103  }
104  tree->blockSignals(true);
105 
106  auto* aronItem = AronTreeWidgetItem::DynamicCast(item);
107  if (column == 1 && aronItem)
108  {
109 
110 
111  std::string name =
112  aronItem->text(aron_tree_widget::constantes::TREE_WIDGET_ITEM_NAME).toStdString();
113  // depending on aron type, create extra gui element.
115  aron::type::visit(v, aronItem->aronType);
116  auto modal = v.createdModal;
117 
118  // if no modal is created, we instead use the edit field directly
119  if (modal)
120  {
121  modal->exec();
122  }
123  else if (aronItem->col1Editable)
124  {
125  item->treeWidget()->editItem(item, column);
126  }
127  }
128  else if (column == 0 && aronItem && aronItem->col0Editable)
129  {
130  item->treeWidget()->editItem(item, column);
131  }
132 
133  tree->blockSignals(false);
134  }
135 
136  void
137  AronTreeWidgetController::onTreeWidgetItemChanged(QTreeWidgetItem* item, int column)
138  {
139  tree->blockSignals(true);
140 
141  auto* aronElem = AronTreeWidgetItem::DynamicCast(item);
142  if (aronElem)
143  {
144  aronElem->onUserChange(column);
145  }
146  // start conversion for entire tree -- this also sets the highlighting
147  if (parent->childCount() == 1)
148  {
149  auto* aronTreeRoot = AronTreeWidgetItem::DynamicCast(parent->child(0));
150  aronTreeRoot->resetError();
151  if (aronTreeRoot)
152  {
153  AronTreeWidgetConverterVisitor v(parent, 0);
154  aron::type::visit(v, type);
155  aronTreeRoot->setValueErrorState(v.hasDirectError(), v.onlyChildFailedConversion());
156  }
157  }
158  // else perhaps the GUI was stopped or died.
159 
160  tree->blockSignals(false);
161  }
162 
163 } // namespace armarx::skills::gui
armarx::skills::gui::AronTreeWidgetController::convertToAron
aron::data::DictPtr convertToAron() const
Definition: AronTreeWidgetController.cpp:56
armarx::skills::gui::AronTreeWidgetSetterVisitor
Definition: AronTreeWidgetSetter.h:37
armarx::skills::gui::AronTreeWidgetConverterVisitor
Definition: AronTreeWidgetConverter.h:34
armarx::skills::gui::AronTreeWidgetContextMenuVisitor::showMenuAndExecute
void showMenuAndExecute()
Definition: AronTreeWidgetContextMenu.cpp:214
armarx::skills::gui::AronTreeWidgetController::setFromAron
void setFromAron(const aron::data::DictPtr &)
Definition: AronTreeWidgetController.cpp:70
armarx::skills::gui::aron_tree_widget::constantes::TREE_WIDGET_ITEM_NAME
const int TREE_WIDGET_ITEM_NAME
Definition: Data.h:7
AronTreeWidgetModalCreator.h
armarx::aron::data::detail::SpecializedVariantBase< data::dto::Dict, Dict >::DynamicCastAndCheck
static PointerType DynamicCastAndCheck(const VariantPtr &n)
Definition: SpecializedVariant.h:135
armarx::skills::gui::AronTreeWidgetController::AronTreeWidgetController
AronTreeWidgetController(QTreeWidget *tree, QTreeWidgetItem *parent, const aron::type::ObjectPtr &type, const aron::data::DictPtr &data=nullptr)
Definition: AronTreeWidgetController.cpp:11
armarx::skills::gui::AronTreeWidgetItem::aronType
aron::type::VariantPtr aronType
Definition: AronTreeWidgetItem.h:30
armarx::skills::gui::AronTreeWidgetItem::DynamicCast
static AronTreeWidgetItem * DynamicCast(QTreeWidgetItem *)
Definition: AronTreeWidgetItem.cpp:15
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
AronTreeWidgetController.h
armarx::skills::gui
Definition: PeriodicUpdateWidget.cpp:11
armarx::skills::gui::AronTreeWidgetModalCreatorVisitor
Definition: AronTreeWidgetModalCreator.h:35
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::skills::gui::AronTreeWidgetCreatorVisitor
Definition: AronTreeWidgetCreator.h:35
armarx::aron::data::visit
requires isVisitor< VisitorImplementation, typename VisitorImplementation::Input > void visit(VisitorImplementation &v, typename VisitorImplementation::Input &o)
Definition: Visitor.h:124
armarx::aron::type::visit
void visit(VisitorImplementation &v, typename VisitorImplementation::Input &t)
The visit function.
Definition: Visitor.h:42
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
armarx::skills::gui::AronTreeWidgetItem
Definition: AronTreeWidgetItem.h:19
armarx::skills::gui::AronTreeWidgetController::ShowContextMenu
void ShowContextMenu(const QPoint &)
Definition: AronTreeWidgetController.cpp:80
armarx::skills::gui::AronTreeWidgetContextMenuVisitor
Definition: AronTreeWidgetContextMenu.h:20