AronTreeWidgetController.cpp
Go to the documentation of this file.
2
4
8
10{
12 QTreeWidgetItem* parent,
13 const aron::type::ObjectPtr& type,
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
140 tree->blockSignals(true);
141
142 auto* aronElem = AronTreeWidgetItem::DynamicCast(item);
143 if (aronElem)
144 {
145 aronElem->onUserChange(column);
146 }
147
148 // start conversion for entire tree -- this also sets the highlighting
149 if (parent->childCount() == 1)
150 {
151 auto* aronTreeRoot = AronTreeWidgetItem::DynamicCast(parent->child(0));
152 if (aronTreeRoot)
153 {
154 aronTreeRoot->resetError();
155 AronTreeWidgetConverterVisitor v(parent, 0);
156 aron::type::visit(v, type);
157 aronTreeRoot->setValueErrorState(v.hasDirectError(), v.onlyChildFailedConversion());
158 }
159 }
160 // else perhaps the GUI was stopped or died.
161
162 tree->blockSignals(false);
163 }
164
165} // namespace armarx::skills::gui
AronTreeWidgetController(QTreeWidget *tree, QTreeWidgetItem *parent, const aron::type::ObjectPtr &type, const aron::data::DictPtr &data=nullptr)
static AronTreeWidgetItem * DynamicCast(QTreeWidgetItem *)
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
void visit(VisitorImplementation &v, typename VisitorImplementation::Input &o)
Definition Visitor.h:136
void visit(VisitorImplementation &v, typename VisitorImplementation::Input &t)
The visit function.
Definition Visitor.h:39
std::shared_ptr< Object > ObjectPtr
Definition Object.h:36
double v(double t, double v0, double a0, double j)
Definition CtrlUtil.h:39