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 
10 namespace armarx
11 {
13  QTreeWidgetItem* parent,
14  const aron::type::ObjectPtr& type,
15  const aron::data::DictPtr& data) :
16  parent(parent), tree(tree), type(type)
17  {
18  connect(tree,
19  SIGNAL(customContextMenuRequested(const QPoint&)),
20  this,
21  SLOT(ShowContextMenu(const QPoint&)));
22  connect(tree,
23  &QTreeWidget::itemDoubleClicked,
24  this,
25  &AronTreeWidgetController::onTreeWidgetItemDoubleClicked);
26 
27  if (type) // if there is a type set, we create a tree widget from the type
28  {
30  v.setTopLevelWidget(tree);
31  aron::type::visit(v, type);
32 
33  if (data) // check if there is a default argument set. Prefill the GUI with it
34  {
36  }
37  }
38  // there is no type but a default configuration. Prefill the GUI with the default arguments
39  else if (data)
40  {
41  // TODO: There is no visitor for that (yet)...
42  // create type from data, ...
43  }
44  else
45  {
46  new QTreeWidgetItem(parent, {QString::fromStdString("No args")});
47  }
48 
49  // connect change handling after args init
50  connect(tree,
51  &QTreeWidget::itemChanged,
52  this,
53  &AronTreeWidgetController::onTreeWidgetItemChanged);
54  }
55 
58  {
59  if (parent && type)
60  {
62  aron::type::visit(v, type);
63 
64  auto aron_args = aron::data::Dict::DynamicCastAndCheck(v.createdAron);
65  return aron_args;
66  }
67  return nullptr;
68  }
69 
70  void
72  {
73  if (parent)
74  {
75  AronTreeWidgetSetterVisitor v(parent, 0);
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  void
97  AronTreeWidgetController::onTreeWidgetItemDoubleClicked(QTreeWidgetItem* item, int column)
98  {
99  if (!item)
100  {
101  return;
102  }
103  tree->blockSignals(true);
104 
105  auto* aronItem = AronTreeWidgetItem::DynamicCast(item);
106  if (column == 1 && aronItem)
107  {
108 
109 
110  std::string name =
111  aronItem->text(aron_tree_widget::constantes::TREE_WIDGET_ITEM_NAME).toStdString();
112  // depending on aron type, create extra gui element.
113  AronTreeWidgetModalCreatorVisitor v(name, aronItem, tree);
114  aron::type::visit(v, aronItem->aronType);
115  auto modal = v.createdModal;
116 
117  // if no modal is created, we instead use the edit field directly
118  if (modal)
119  {
120  modal->exec();
121  }
122  else if (aronItem->col1Editable)
123  {
124  item->treeWidget()->editItem(item, column);
125  }
126  }
127  else if (column == 0 && aronItem && aronItem->col0Editable)
128  {
129  item->treeWidget()->editItem(item, column);
130  }
131 
132  tree->blockSignals(false);
133  }
134 
135  void
136  AronTreeWidgetController::onTreeWidgetItemChanged(QTreeWidgetItem* item, int column)
137  {
138  tree->blockSignals(true);
139 
140  auto* aronElem = AronTreeWidgetItem::DynamicCast(item);
141  if (aronElem)
142  {
143  aronElem->onUserChange(column);
144  }
145  // start conversion for entire tree -- this also sets the highlighting
146  if (parent->childCount() == 1)
147  {
148  auto* aronTreeRoot = AronTreeWidgetItem::DynamicCast(parent->child(0));
149  aronTreeRoot->resetError();
150  if (aronTreeRoot)
151  {
152  AronTreeWidgetConverterVisitor v(parent, 0);
153  aron::type::visit(v, type);
154  aronTreeRoot->setValueErrorState(v.hasDirectError(), v.onlyChildFailedConversion());
155  }
156  }
157  // else perhaps the GUI was stopped or died.
158 
159  tree->blockSignals(false);
160  }
161 
162 } // namespace armarx
armarx::AronTreeWidgetItem
Definition: AronTreeWidgetItem.h:19
armarx::aron::data::detail::SpecializedVariantBase< data::dto::Dict, Dict >::DynamicCastAndCheck
static PointerType DynamicCastAndCheck(const VariantPtr &n)
Definition: SpecializedVariant.h:135
armarx::AronTreeWidgetContextMenuVisitor
Definition: AronTreeWidgetContextMenu.h:20
armarx::AronTreeWidgetContextMenuVisitor::showMenuAndExecute
void showMenuAndExecute()
Definition: AronTreeWidgetContextMenu.cpp:215
AronTreeWidgetModalCreator.h
armarx::AronTreeWidgetController::setFromAron
void setFromAron(const aron::data::DictPtr &)
Definition: AronTreeWidgetController.cpp:71
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::AronTreeWidgetController::AronTreeWidgetController
AronTreeWidgetController(QTreeWidget *tree, QTreeWidgetItem *parent, const aron::type::ObjectPtr &type, const aron::data::DictPtr &data=nullptr)
Definition: AronTreeWidgetController.cpp:12
armarx::AronTreeWidgetCreatorVisitor
Definition: AronTreeWidgetCreator.h:35
armarx::AronTreeWidgetController::convertToAron
aron::data::DictPtr convertToAron() const
Definition: AronTreeWidgetController.cpp:57
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::AronTreeWidgetItem::DynamicCast
static AronTreeWidgetItem * DynamicCast(QTreeWidgetItem *)
Definition: AronTreeWidgetItem.cpp:15
armarx::AronTreeWidgetController::ShowContextMenu
void ShowContextMenu(const QPoint &)
Definition: AronTreeWidgetController.cpp:80
armarx::AronTreeWidgetSetterVisitor
Definition: AronTreeWidgetSetter.h:37
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_tree_widget::constantes::TREE_WIDGET_ITEM_NAME
const int TREE_WIDGET_ITEM_NAME
Definition: Data.h:7
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
AronTreeWidgetController.h
armarx::AronTreeWidgetConverterVisitor
Definition: AronTreeWidgetConverter.h:35
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::AronTreeWidgetItem::aronType
aron::type::VariantPtr aronType
Definition: AronTreeWidgetItem.h:30